Skip to content

Commit

Permalink
Check no phi allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmoses committed Feb 13, 2021
1 parent 263b544 commit 559ec97
Show file tree
Hide file tree
Showing 7 changed files with 288 additions and 143 deletions.
3 changes: 2 additions & 1 deletion enzyme/Enzyme/AdjointGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@ class AdjointGenerator
//! pass
if (!type->isEmptyTy() && !type->isFPOrFPVectorTy() &&
TR.query(&LI).Inner0().isPossiblePointer()) {
Instruction *placeholder = cast<Instruction>(gutils->invertedPointers[&LI]);
Instruction *placeholder =
cast<Instruction>(gutils->invertedPointers[&LI]);
assert(placeholder->getType() == type);
gutils->invertedPointers.erase(&LI);

Expand Down
35 changes: 18 additions & 17 deletions enzyme/Enzyme/CacheUtility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,18 +582,16 @@ bool CacheUtility::getContext(BasicBlock *BB, LoopContext &loopContext) {
loopContexts[L].maxLimit = LimitVar;
} else {
DebugLoc loc = L->getHeader()->begin()->getDebugLoc();
for(auto &I : *L->getHeader()) {
if (loc) break;
for (auto &I : *L->getHeader()) {
if (loc)
break;
loc = I.getDebugLoc();
}
EmitWarning("NoLimit",
loc,
newFunc,
L->getHeader(),
"SE could not compute loop limit of ",
L->getHeader()->getName(), " of ",
L->getHeader()->getParent()->getName(),
"lim: ", *Limit, " maxlim: ", *MaxIterations);
EmitWarning("NoLimit", loc, newFunc, L->getHeader(),
"SE could not compute loop limit of ",
L->getHeader()->getName(), " of ",
L->getHeader()->getParent()->getName(), "lim: ", *Limit,
" maxlim: ", *MaxIterations);

LimitVar = createCacheForScope(LimitContext(loopContexts[L].preheader),
CanonicalIV->getType(), "loopLimit",
Expand Down Expand Up @@ -650,7 +648,7 @@ AllocaInst *CacheUtility::createCacheForScope(LimitContext ctx, Type *T,
assert(ctx.Block);
assert(T);

auto sublimits = getSubLimits(/*inForwardPass*/true, nullptr, ctx);
auto sublimits = getSubLimits(/*inForwardPass*/ true, nullptr, ctx);

// List of types stored in the cache for each Loop-Chunk
// This is stored from innner-most chunk to outermost
Expand Down Expand Up @@ -905,7 +903,7 @@ Value *CacheUtility::computeIndexOfChunk(

indices.push_back(var);
Value *lim = pair.second; //, v, available,
//UnwrapMode::AttemptFullUnwrapWithLookup);
// UnwrapMode::AttemptFullUnwrapWithLookup);
assert(lim);
if (limits.size() == 0) {
limits.push_back(lim);
Expand Down Expand Up @@ -937,7 +935,9 @@ Value *CacheUtility::computeIndexOfChunk(
/// For every loop, this returns pair of the LoopContext and the limit of that
/// loop Both the vector of Chunks and vector of Loops within a Chunk go from
/// innermost loop to outermost loop.
CacheUtility::SubLimitType CacheUtility::getSubLimits(bool inForwardPass, IRBuilder<> *RB, LimitContext ctx) {
CacheUtility::SubLimitType CacheUtility::getSubLimits(bool inForwardPass,
IRBuilder<> *RB,
LimitContext ctx) {
// Given a ``SingleIteration'' Limit Context, return a chunking of
// one loop with size 1, and header/preheader of the BasicBlock
// This is done to create a context for a block outside a loop
Expand Down Expand Up @@ -1053,7 +1053,6 @@ CacheUtility::SubLimitType CacheUtility::getSubLimits(bool inForwardPass, IRBuil
}
assert(limitMinus1 != nullptr);


ValueToValueMapTy reverseMap;
// Iterate from outermost loop down
for (int j = contexts.size() - 1;; --j) {
Expand All @@ -1064,7 +1063,8 @@ CacheUtility::SubLimitType CacheUtility::getSubLimits(bool inForwardPass, IRBuil
// map
if (allocationPreheaders[i] != contexts[j].preheader) {
if (!inForwardPass) {
reverseMap[contexts[j].var] = RB->CreateLoad(contexts[j].antivaralloc);
reverseMap[contexts[j].var] =
RB->CreateLoad(contexts[j].antivaralloc);
}
} else {
break;
Expand All @@ -1083,7 +1083,8 @@ CacheUtility::SubLimitType CacheUtility::getSubLimits(bool inForwardPass, IRBuil
if (inForwardPass)
limits[i] = LimitCache[cidx];
else {
Value* lim = unwrapM(contexts[i].maxLimit, *RB, reverseMap, UnwrapMode::AttemptFullUnwrapWithLookup);
Value *lim = unwrapM(contexts[i].maxLimit, *RB, reverseMap,
UnwrapMode::AttemptFullUnwrapWithLookup);
if (!lim) {
llvm::errs() << *newFunc << "\n";
llvm::errs() << *contexts[i].maxLimit << "\n";
Expand Down Expand Up @@ -1111,7 +1112,7 @@ CacheUtility::SubLimitType CacheUtility::getSubLimits(bool inForwardPass, IRBuil
size = limits[i];
} else if (!inForwardPass) {
size = RB->CreateMul(size, limits[i], "",
/*NUW*/ true, /*NSW*/ true);
/*NUW*/ true, /*NSW*/ true);
} else {
// Otherwise new size = old size * limits[i];
auto cidx = std::make_tuple(size, limits[i], allocationPreheaders[i]);
Expand Down
31 changes: 16 additions & 15 deletions enzyme/Enzyme/CacheUtility.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,20 @@ enum class UnwrapMode {
AttemptSingleUnwrap,
};

static llvm::raw_ostream& operator<<(llvm::raw_ostream& os, UnwrapMode mode) {
switch(mode) {
case UnwrapMode::LegalFullUnwrap:
os << "LegalFullUnwrap";
break;
case UnwrapMode::AttemptFullUnwrapWithLookup:
os << "AttemptFullUnwrapWithLookup";
break;
case UnwrapMode::AttemptFullUnwrap:
os << "AttemptFullUnwrap";
break;
case UnwrapMode::AttemptSingleUnwrap:
os << "AttemptSingleUnwrap";
break;
static llvm::raw_ostream &operator<<(llvm::raw_ostream &os, UnwrapMode mode) {
switch (mode) {
case UnwrapMode::LegalFullUnwrap:
os << "LegalFullUnwrap";
break;
case UnwrapMode::AttemptFullUnwrapWithLookup:
os << "AttemptFullUnwrapWithLookup";
break;
case UnwrapMode::AttemptFullUnwrap:
os << "AttemptFullUnwrap";
break;
case UnwrapMode::AttemptSingleUnwrap:
os << "AttemptSingleUnwrap";
break;
}
return os;
}
Expand Down Expand Up @@ -210,7 +210,8 @@ class CacheUtility {
/*sublimit*/ llvm::Value *,
/*loop limits*/ std::vector<std::pair<LoopContext, llvm::Value *>>>>
SubLimitType;
SubLimitType getSubLimits(bool inForwardPass, llvm::IRBuilder<>* RB, LimitContext ctx);
SubLimitType getSubLimits(bool inForwardPass, llvm::IRBuilder<> *RB,
LimitContext ctx);

private:
/// Internal data structure used by getSubLimit to avoid computing the same
Expand Down
Loading

0 comments on commit 559ec97

Please sign in to comment.