Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intsecretpointerpartialfix #31

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
0d34872
cache of in progress dynamic loops
wsmoses Oct 25, 2019
53f4c98
Basic modref analysis, few more steps needed
timkaler Oct 25, 2019
014ed6b
replaced dynamic cache generator
wsmoses Oct 29, 2019
be9df59
full implementation (untested) of dynamic loops
wsmoses Oct 29, 2019
959827f
enable func c test
wsmoses Oct 29, 2019
26cbf8a
fix insert not to assume fail
wsmoses Oct 29, 2019
ddd9da4
fixed dyn loop bug
wsmoses Oct 30, 2019
c370dc5
Fix indexing and c tests pass
wsmoses Oct 30, 2019
99febd1
cache almost all loads
timkaler Oct 30, 2019
d0e4be0
Messy, but working, selective caching of reads
timkaler Oct 31, 2019
40773f7
add missing files and fix minor bugs
timkaler Oct 31, 2019
447c17e
all enzyme-check tests work except the badcall tests
timkaler Oct 31, 2019
dbff5fd
modify the badcall tests so that they pass
timkaler Oct 31, 2019
4b604b0
cleanup
timkaler Oct 31, 2019
4781b0d
cleanup
timkaler Oct 31, 2019
b6fcaf1
fix compiler warnings
timkaler Oct 31, 2019
5f8c9be
make insertsort.ll expected fail again
timkaler Oct 31, 2019
0ff1932
put in the more strict/correct logic for ordering instructions in sin…
timkaler Nov 1, 2019
a1715c3
Check whether a loaded value is needed --- only at the top level for …
timkaler Nov 1, 2019
9cdb1ed
bugfix. still unsure if the logic used at topLevel for detecting when…
timkaler Nov 1, 2019
5417992
Merge branch 'selective-cachereads-rebase' of https://github.com/wsmo…
timkaler Nov 1, 2019
f568641
preliminary changes, but with bugs
timkaler Nov 2, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 55 additions & 5 deletions enzyme/Enzyme/ActiveVariable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ bool isIntASecretFloat(Value* val) {
if (auto inst = dyn_cast<Instruction>(val)) {
bool floatingUse = false;
bool pointerUse = false;
bool intUse = false;
SmallPtrSet<Value*, 4> seen;

std::function<void(Value*)> trackPointer = [&](Value* v) {
Expand Down Expand Up @@ -126,12 +127,50 @@ bool isIntASecretFloat(Value* val) {
if (auto si = dyn_cast<StoreInst>(use)) {
assert(inst == si->getValueOperand());

if (MDNode* md = si->getMetadata(LLVMContext::MD_tbaa)) {
llvm::errs() << "TFKDEBUG MDNode " << *md << " Inst is " << *inst << " " << *si <<"\n";
if (md->getNumOperands() == 3) {
const MDOperand& accessType = md->getOperand(1);
Metadata* metadata = accessType.get();
if (auto mda = dyn_cast<MDNode>(metadata)) {
if (mda->getNumOperands() > 0) {
const MDOperand& underlyingType = mda->getOperand(0);
Metadata* metadata2 = underlyingType.get();
if (auto typeName = dyn_cast<MDString>(metadata2)) {
auto typeNameStringRef = typeName->getString();
if (typeNameStringRef == "long") {
intUse = true;
}
}
}
}
}
}
trackPointer(si->getPointerOperand());
}
}

if (auto li = dyn_cast<LoadInst>(inst)) {
trackPointer(li->getOperand(0));
if (MDNode* md = li->getMetadata(LLVMContext::MD_tbaa)) {
llvm::errs() << "TFKDEBUG MDNode " << *md << " Inst is " << *inst << " " << *li <<"\n";
if (md->getNumOperands() == 3) {
const MDOperand& accessType = md->getOperand(1);
Metadata* metadata = accessType.get();
if (auto mda = dyn_cast<MDNode>(metadata)) {
if (mda->getNumOperands() > 0) {
const MDOperand& underlyingType = mda->getOperand(0);
Metadata* metadata2 = underlyingType.get();
if (auto typeName = dyn_cast<MDString>(metadata2)) {
auto typeNameStringRef = typeName->getString();
if (typeNameStringRef == "long") {
intUse = true;
}
}
}
}
}
}
trackPointer(li->getOperand(0));
}

if (auto ci = dyn_cast<BitCastInst>(inst)) {
Expand All @@ -147,11 +186,11 @@ bool isIntASecretFloat(Value* val) {
if (isa<PtrToIntInst>(inst)) {
pointerUse = true;
}

if (pointerUse && !floatingUse) return false;
if (!pointerUse && floatingUse) return true;
if (intUse && !pointerUse && !floatingUse) return false;
if (!intUse && pointerUse && !floatingUse) return false;
if (!intUse && !pointerUse && floatingUse) return true;
llvm::errs() << *inst->getParent()->getParent() << "\n";
llvm::errs() << " val:" << *val << " pointer:" << pointerUse << " floating:" << floatingUse << "\n";
llvm::errs() << " val:" << *val << " pointer:" << pointerUse << " floating:" << floatingUse << " intuse: " << intUse << "\n";
assert(0 && "ambiguous unsure if constant or not");
}

Expand Down Expand Up @@ -296,6 +335,17 @@ bool isconstantM(Instruction* inst, SmallPtrSetImpl<Value*> &constants, SmallPtr
}
}
}

if (auto op = dyn_cast<BinaryOperator>(inst)) {
switch(op->getOpcode()) {
//case BinaryOperator::Add:
case BinaryOperator::Mul:
constants.insert(inst);
return true;
default:
break;
}
}

if (auto op = dyn_cast<IntrinsicInst>(inst)) {
switch(op->getIntrinsicID()) {
Expand Down
3 changes: 2 additions & 1 deletion enzyme/Enzyme/Enzyme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ void HandleAutoDiff(CallInst *CI, TargetLibraryInfo &TLI, AAResults &AA) {//, Lo

bool differentialReturn = cast<Function>(fn)->getReturnType()->isFPOrFPVectorTy();

auto newFunc = CreatePrimalAndGradient(cast<Function>(fn), constants, TLI, AA, /*should return*/false, differentialReturn, /*topLevel*/true, /*addedType*/nullptr);//, LI, DT);
std::set<unsigned> volatile_args;
auto newFunc = CreatePrimalAndGradient(cast<Function>(fn), constants, TLI, AA, /*should return*/false, differentialReturn, /*topLevel*/true, /*addedType*/nullptr, volatile_args);//, LI, DT);

if (differentialReturn)
args.push_back(ConstantFP::get(cast<Function>(fn)->getReturnType(), 1.0));
Expand Down
Loading