Skip to content

Commit

Permalink
fix missing debug info (#1290)
Browse files Browse the repository at this point in the history
  • Loading branch information
tgymnich authored Jun 20, 2023
1 parent a19313d commit 11a9451
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 38 deletions.
74 changes: 37 additions & 37 deletions enzyme/Enzyme/AdjointGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ class AdjointGenerator
switch (Mode) {
case DerivativeMode::ReverseModeCombined:
case DerivativeMode::ReverseModeGradient: {
IRBuilder<> Builder2(inst.getParent());
IRBuilder<> Builder2(&inst);
getReverseBuilder(Builder2);

auto rule = [&](Value *idiff) { return Builder2.CreateFreeze(idiff); };
Expand Down Expand Up @@ -395,7 +395,7 @@ class AdjointGenerator
switch (Mode) {
case DerivativeMode::ReverseModeCombined:
case DerivativeMode::ReverseModeGradient: {
IRBuilder<> Builder2(inst.getParent());
IRBuilder<> Builder2(&inst);
getReverseBuilder(Builder2);

auto rule = [&](Value *idiff) { return Builder2.CreateFNeg(idiff); };
Expand Down Expand Up @@ -776,7 +776,7 @@ class AdjointGenerator
case DerivativeMode::ReverseModeGradient:
case DerivativeMode::ReverseModeCombined: {

IRBuilder<> Builder2(parent);
IRBuilder<> Builder2(&I);
getReverseBuilder(Builder2);

Value *prediff = nullptr;
Expand Down Expand Up @@ -1224,7 +1224,7 @@ class AdjointGenerator
break;
case DerivativeMode::ReverseModeGradient:
case DerivativeMode::ReverseModeCombined: {
IRBuilder<> Builder2(I.getParent());
IRBuilder<> Builder2(&I);
getReverseBuilder(Builder2);

if (constantval) {
Expand Down Expand Up @@ -1454,7 +1454,7 @@ class AdjointGenerator
Value *orig_op0 = I.getOperand(0);
Value *op0 = gutils->getNewFromOriginal(orig_op0);

IRBuilder<> Builder2(I.getParent());
IRBuilder<> Builder2(&I);
getReverseBuilder(Builder2);

if (!gutils->isConstantValue(orig_op0)) {
Expand Down Expand Up @@ -1552,7 +1552,7 @@ class AdjointGenerator
Value *op2 = gutils->getNewFromOriginal(orig_op2);

// TODO fix all the reverse builders
IRBuilder<> Builder2(SI.getParent());
IRBuilder<> Builder2(&SI);
getReverseBuilder(Builder2);

Value *dif1 = nullptr;
Expand Down Expand Up @@ -1667,7 +1667,7 @@ class AdjointGenerator
case DerivativeMode::ReverseModeCombined: {
if (gutils->isConstantInstruction(&EEI))
return;
IRBuilder<> Builder2(EEI.getParent());
IRBuilder<> Builder2(&EEI);
getReverseBuilder(Builder2);

Value *orig_vec = EEI.getVectorOperand();
Expand Down Expand Up @@ -1712,7 +1712,7 @@ class AdjointGenerator
case DerivativeMode::ReverseModeCombined: {
if (gutils->isConstantInstruction(&IEI))
return;
IRBuilder<> Builder2(IEI.getParent());
IRBuilder<> Builder2(&IEI);
getReverseBuilder(Builder2);

Value *dif1 = diffe(&IEI, Builder2);
Expand Down Expand Up @@ -1777,7 +1777,7 @@ class AdjointGenerator
case DerivativeMode::ReverseModeCombined: {
if (gutils->isConstantInstruction(&SVI))
return;
IRBuilder<> Builder2(SVI.getParent());
IRBuilder<> Builder2(&SVI);
getReverseBuilder(Builder2);

auto loaded = diffe(&SVI, Builder2);
Expand Down Expand Up @@ -1842,7 +1842,7 @@ class AdjointGenerator
return;
if (EVI.getType()->isPointerTy())
return;
IRBuilder<> Builder2(EVI.getParent());
IRBuilder<> Builder2(&EVI);
getReverseBuilder(Builder2);

Value *orig_op0 = EVI.getOperand(0);
Expand Down Expand Up @@ -1958,7 +1958,7 @@ class AdjointGenerator
return;
case DerivativeMode::ReverseModeCombined:
case DerivativeMode::ReverseModeGradient: {
IRBuilder<> Builder2(IVI.getParent());
IRBuilder<> Builder2(&IVI);
getReverseBuilder(Builder2);

Value *orig_inserted = IVI.getInsertedValueOperand();
Expand Down Expand Up @@ -2140,7 +2140,7 @@ class AdjointGenerator
void createBinaryOperatorAdjoint(llvm::BinaryOperator &BO) {
using namespace llvm;

IRBuilder<> Builder2(BO.getParent());
IRBuilder<> Builder2(&BO);
getReverseBuilder(Builder2);

Value *orig_op0 = BO.getOperand(0);
Expand Down Expand Up @@ -3687,7 +3687,7 @@ class AdjointGenerator
break;
case DerivativeMode::ReverseModeGradient:
case DerivativeMode::ReverseModeCombined: {
IRBuilder<> Builder2(FI.getParent());
IRBuilder<> Builder2(&FI);
getReverseBuilder(Builder2);
auto order = FI.getOrdering();
switch (order) {
Expand Down Expand Up @@ -3852,7 +3852,7 @@ class AdjointGenerator
case DerivativeMode::ReverseModeCombined:
case DerivativeMode::ReverseModeGradient: {

IRBuilder<> Builder2(I.getParent());
IRBuilder<> Builder2(&I);
getReverseBuilder(Builder2);

Value *vdiff = nullptr;
Expand Down Expand Up @@ -4129,7 +4129,7 @@ class AdjointGenerator
pre_args.push_back(argi);

if (Mode != DerivativeMode::ReverseModePrimal) {
IRBuilder<> Builder2(call.getParent());
IRBuilder<> Builder2(&call);
getReverseBuilder(Builder2);
args.push_back(lookup(argi, Builder2));
}
Expand All @@ -4145,7 +4145,7 @@ class AdjointGenerator

if (argTy == DIFFE_TYPE::DUP_ARG || argTy == DIFFE_TYPE::DUP_NONEED) {
if (Mode != DerivativeMode::ReverseModePrimal) {
IRBuilder<> Builder2(call.getParent());
IRBuilder<> Builder2(&call);
getReverseBuilder(Builder2);
args.push_back(
lookup(gutils->invertPointerM(call.getArgOperand(i), Builder2),
Expand Down Expand Up @@ -4388,7 +4388,7 @@ class AdjointGenerator

if (Mode == DerivativeMode::ReverseModeGradient ||
Mode == DerivativeMode::ReverseModeCombined) {
IRBuilder<> Builder2(call.getParent());
IRBuilder<> Builder2(&call);
getReverseBuilder(Builder2);

if (Mode == DerivativeMode::ReverseModeGradient) {
Expand Down Expand Up @@ -4898,7 +4898,7 @@ class AdjointGenerator
}
if (Mode == DerivativeMode::ReverseModeGradient ||
Mode == DerivativeMode::ReverseModeCombined) {
IRBuilder<> Builder2(call.getParent());
IRBuilder<> Builder2(&call);
getReverseBuilder(Builder2);

Type *statusType = nullptr;
Expand Down Expand Up @@ -5146,7 +5146,7 @@ class AdjointGenerator
}
if (Mode == DerivativeMode::ReverseModeGradient ||
Mode == DerivativeMode::ReverseModeCombined) {
IRBuilder<> Builder2(call.getParent());
IRBuilder<> Builder2(&call);
getReverseBuilder(Builder2);

assert(!gutils->isConstantValue(call.getOperand(0)));
Expand Down Expand Up @@ -5290,7 +5290,7 @@ class AdjointGenerator
}
if (Mode == DerivativeMode::ReverseModeGradient ||
Mode == DerivativeMode::ReverseModeCombined) {
IRBuilder<> Builder2(call.getParent());
IRBuilder<> Builder2(&call);
getReverseBuilder(Builder2);

assert(!gutils->isConstantValue(call.getOperand(1)));
Expand Down Expand Up @@ -6984,7 +6984,7 @@ class AdjointGenerator
if (funcName == "MPI_Barrier") {
if (Mode == DerivativeMode::ReverseModeGradient ||
Mode == DerivativeMode::ReverseModeCombined) {
IRBuilder<> Builder2(call.getParent());
IRBuilder<> Builder2(&call);
getReverseBuilder(Builder2);
#if LLVM_VERSION_MAJOR >= 11
auto callval = call.getCalledOperand();
Expand Down Expand Up @@ -7014,7 +7014,7 @@ class AdjointGenerator
if (commFound != MPIInactiveCommAllocators.end()) {
if (Mode == DerivativeMode::ReverseModeGradient ||
Mode == DerivativeMode::ReverseModeCombined) {
IRBuilder<> Builder2(call.getParent());
IRBuilder<> Builder2(&call);
getReverseBuilder(Builder2);

Value *args[] = {lookup(call.getOperand(commFound->second), Builder2)};
Expand Down Expand Up @@ -7447,7 +7447,7 @@ class AdjointGenerator
pre_args.push_back(prearg);

if (Mode != DerivativeMode::ReverseModePrimal) {
IRBuilder<> Builder2(call.getParent());
IRBuilder<> Builder2(&call);
getReverseBuilder(Builder2);

if (call.isByValArgument(i)) {
Expand Down Expand Up @@ -7516,7 +7516,7 @@ class AdjointGenerator
}
}
if (Mode != DerivativeMode::ReverseModePrimal) {
IRBuilder<> Builder2(call.getParent());
IRBuilder<> Builder2(&call);
getReverseBuilder(Builder2);

Value *darg = nullptr;
Expand Down Expand Up @@ -8015,7 +8015,7 @@ class AdjointGenerator
return;
}

IRBuilder<> Builder2(call.getParent());
IRBuilder<> Builder2(&call);
getReverseBuilder(Builder2);

Value *newcalled = nullptr;
Expand Down Expand Up @@ -8388,7 +8388,7 @@ class AdjointGenerator
Mode == DerivativeMode::ReverseModeGradient) {
auto found = customCallHandlers.find(funcName);
if (found != customCallHandlers.end()) {
IRBuilder<> Builder2(call.getParent());
IRBuilder<> Builder2(&call);
if (Mode == DerivativeMode::ReverseModeGradient ||
Mode == DerivativeMode::ReverseModeCombined)
getReverseBuilder(Builder2);
Expand Down Expand Up @@ -8537,7 +8537,7 @@ class AdjointGenerator
funcName == "__kmpc_for_static_init_4u" ||
funcName == "__kmpc_for_static_init_8" ||
funcName == "__kmpc_for_static_init_8u") {
IRBuilder<> Builder2(call.getParent());
IRBuilder<> Builder2(&call);
getReverseBuilder(Builder2);
auto fini = called->getParent()->getFunction("__kmpc_for_static_fini");
assert(fini);
Expand Down Expand Up @@ -8599,7 +8599,7 @@ class AdjointGenerator
funcName == "__kmpc_for_static_init_8" ||
funcName == "__kmpc_for_static_init_8u") {
if (Mode != DerivativeMode::ReverseModePrimal) {
IRBuilder<> Builder2(call.getParent());
IRBuilder<> Builder2(&call);
getReverseBuilder(Builder2);
auto fini =
called->getParent()->getFunction("__kmpc_for_static_fini");
Expand All @@ -8626,7 +8626,7 @@ class AdjointGenerator
if (funcName == "__kmpc_barrier") {
if (Mode == DerivativeMode::ReverseModeGradient ||
Mode == DerivativeMode::ReverseModeCombined) {
IRBuilder<> Builder2(call.getParent());
IRBuilder<> Builder2(&call);
getReverseBuilder(Builder2);
#if LLVM_VERSION_MAJOR >= 11
auto callval = call.getCalledOperand();
Expand All @@ -8642,7 +8642,7 @@ class AdjointGenerator
}
if (funcName == "__kmpc_critical") {
if (Mode != DerivativeMode::ReverseModePrimal) {
IRBuilder<> Builder2(call.getParent());
IRBuilder<> Builder2(&call);
getReverseBuilder(Builder2);
auto crit2 = called->getParent()->getFunction("__kmpc_end_critical");
assert(crit2);
Expand All @@ -8661,7 +8661,7 @@ class AdjointGenerator
}
if (funcName == "__kmpc_end_critical") {
if (Mode != DerivativeMode::ReverseModePrimal) {
IRBuilder<> Builder2(call.getParent());
IRBuilder<> Builder2(&call);
getReverseBuilder(Builder2);
auto crit2 = called->getParent()->getFunction("__kmpc_critical");
assert(crit2);
Expand Down Expand Up @@ -9338,7 +9338,7 @@ class AdjointGenerator
(Mode == DerivativeMode::ReverseModeGradient && shouldFree()) ||
(Mode == DerivativeMode::ForwardModeSplit && shouldFree())) &&
!isAlloca) {
IRBuilder<> Builder2(call.getParent());
IRBuilder<> Builder2(&call);
getReverseBuilder(Builder2);
assert(anti);
Value *tofree = lookup(anti, Builder2);
Expand Down Expand Up @@ -9556,7 +9556,7 @@ class AdjointGenerator
if (Mode == DerivativeMode::ReverseModeGradient ||
Mode == DerivativeMode::ReverseModeCombined ||
Mode == DerivativeMode::ForwardModeSplit) {
IRBuilder<> Builder2(call.getParent());
IRBuilder<> Builder2(&call);
getReverseBuilder(Builder2);
auto dbgLoc = gutils->getNewFromOriginal(call.getDebugLoc());
freeKnownAllocation(Builder2, lookup(newCall, Builder2), funcName,
Expand Down Expand Up @@ -9653,7 +9653,7 @@ class AdjointGenerator
((Mode == DerivativeMode::ReverseModeGradient && shouldFree()) ||
Mode == DerivativeMode::ReverseModeCombined ||
(Mode == DerivativeMode::ForwardModeSplit && shouldFree()))) {
IRBuilder<> Builder2(call.getParent());
IRBuilder<> Builder2(&call);
getReverseBuilder(Builder2);
auto dbgLoc = gutils->getNewFromOriginal(call.getDebugLoc());
freeKnownAllocation(Builder2, lookup(nop, Builder2), funcName, dbgLoc,
Expand Down Expand Up @@ -9858,7 +9858,7 @@ class AdjointGenerator
}
if (Mode == DerivativeMode::ReverseModeGradient ||
Mode == DerivativeMode::ReverseModeCombined) {
IRBuilder<> Builder2(call.getParent());
IRBuilder<> Builder2(&call);
getReverseBuilder(Builder2);
val = gutils->lookupM(val, Builder2);
auto FreeFunc = gutils->newFunc->getParent()->getOrInsertFunction(
Expand All @@ -9879,7 +9879,7 @@ class AdjointGenerator
if (funcName == "cuStreamSynchronize") {
if (Mode == DerivativeMode::ReverseModeGradient ||
Mode == DerivativeMode::ReverseModeCombined) {
IRBuilder<> Builder2(call.getParent());
IRBuilder<> Builder2(&call);
getReverseBuilder(Builder2);
Value *nargs[] = {gutils->lookupM(
gutils->getNewFromOriginal(call.getOperand(0)), Builder2)};
Expand Down Expand Up @@ -10034,7 +10034,7 @@ class AdjointGenerator
if (Mode == DerivativeMode::ReverseModeCombined ||
Mode == DerivativeMode::ReverseModeGradient) {
if (shouldFree()) {
IRBuilder<> Builder2(call.getParent());
IRBuilder<> Builder2(&call);
getReverseBuilder(Builder2);
Value *tofree = gutils->lookupM(val, Builder2, ValueToValueMapTy(),
/*tryLegalRecompute*/ false);
Expand Down
2 changes: 1 addition & 1 deletion enzyme/tools/enzyme-tblgen/caching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ void emit_cache_for_reverse(const TGPattern &pattern, raw_ostream &os) {


os
<< " IRBuilder<> Builder2(call.getParent());\n"
<< " IRBuilder<> Builder2(&call);\n"
<< " switch (Mode) {\n"
<< " case DerivativeMode::ReverseModeCombined:\n"
<< " case DerivativeMode::ReverseModeGradient:\n"
Expand Down

0 comments on commit 11a9451

Please sign in to comment.