Skip to content

Commit

Permalink
add md for instruction inactivity
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmoses committed Oct 11, 2023
1 parent bdb9555 commit a929b96
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions enzyme/Enzyme/ActivityAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,22 @@ bool ActivityAnalyzer::isConstantValue(TypeResults const &TR, Value *Val) {
return false;
}

if (auto I = dyn_cast<Instruction>(Val)) {
if (hasMetadata(I, "enzyme_active") ||
hasMetadata(I, "enzyme_active_val")) {
if (EnzymePrintActivity)
llvm::errs() << "forced active val (MD)" << *Val << "\n";
InsertConstantValue(TR, Val);
return true;
}
if (hasMetadata(I, "enzyme_inactive") ||
hasMetadata(I, "enzyme_inactive_val")) {
if (EnzymePrintActivity)
llvm::errs() << "forced inactive val (MD)" << *Val << "\n";
InsertConstantValue(TR, Val);
return true;
}
}
if (auto CI = dyn_cast<CallInst>(Val)) {
if (CI->hasFnAttr("enzyme_active") || CI->hasFnAttr("enzyme_active_val") ||
CI->hasRetAttr("enzyme_active")) {
Expand Down Expand Up @@ -1400,7 +1416,8 @@ bool ActivityAnalyzer::isConstantValue(TypeResults const &TR, Value *Val) {
}
} else if (auto op = dyn_cast<CallInst>(TmpOrig)) {
if (op->hasFnAttr("enzyme_inactive") ||
op->hasFnAttr("enzyme_inactive_val")) {
op->hasFnAttr("enzyme_inactive_val") ||
op->hasRetAttr("enzyme_inactive")) {
InsertConstantValue(TR, Val);
insertConstantsFrom(TR, *UpHypothesis);
return true;
Expand All @@ -1410,7 +1427,16 @@ bool ActivityAnalyzer::isConstantValue(TypeResults const &TR, Value *Val) {
StringRef funcName = getFuncNameFromCall(op);

if (called && (called->hasFnAttribute("enzyme_inactive") ||
called->hasFnAttribute("enzyme_inactive_val"))) {
called->hasFnAttribute("enzyme_inactive_val")
#if LLVM_VERSION_MAJOR >= 14
|| called->hasRetAttribute("enzyme_inactive")
#else
||
called->getAttributes().hasAttribute(
llvm::AttributeList::ReturnIndex, "enzyme_inactive")
#endif

)) {
InsertConstantValue(TR, Val);
insertConstantsFrom(TR, *UpHypothesis);
return true;
Expand Down

0 comments on commit a929b96

Please sign in to comment.