From a929b96187f0519bce7af142bbff1dfeb1aa31df Mon Sep 17 00:00:00 2001 From: "William S. Moses" Date: Wed, 11 Oct 2023 02:08:50 -0400 Subject: [PATCH] add md for instruction inactivity --- enzyme/Enzyme/ActivityAnalysis.cpp | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/enzyme/Enzyme/ActivityAnalysis.cpp b/enzyme/Enzyme/ActivityAnalysis.cpp index 53ccd2a63f7a..a935c4609039 100644 --- a/enzyme/Enzyme/ActivityAnalysis.cpp +++ b/enzyme/Enzyme/ActivityAnalysis.cpp @@ -1198,6 +1198,22 @@ bool ActivityAnalyzer::isConstantValue(TypeResults const &TR, Value *Val) { return false; } + if (auto I = dyn_cast(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(Val)) { if (CI->hasFnAttr("enzyme_active") || CI->hasFnAttr("enzyme_active_val") || CI->hasRetAttr("enzyme_active")) { @@ -1400,7 +1416,8 @@ bool ActivityAnalyzer::isConstantValue(TypeResults const &TR, Value *Val) { } } else if (auto op = dyn_cast(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; @@ -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;