Skip to content

Commit 8faf3b4

Browse files
authored
Enable Ompopt (rust-lang#480)
* Enable openmpopt * build omp only on 13+
1 parent 036df28 commit 8faf3b4

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

enzyme/Enzyme/Enzyme.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464

6565
#if LLVM_VERSION_MAJOR >= 13
6666
#include "llvm/Transforms/IPO/Attributor.h"
67+
#include "llvm/Transforms/IPO/OpenMPOpt.h"
6768
#endif
6869

6970
#include "CApi.h"
@@ -80,6 +81,10 @@ llvm::cl::opt<bool>
8081
llvm::cl::opt<bool> EnzymeAttributor("enzyme-attributor", cl::init(false),
8182
cl::Hidden,
8283
cl::desc("Run attributor post Enzyme"));
84+
85+
llvm::cl::opt<bool> EnzymeOMPOpt("enzyme-omp-opt", cl::init(true), cl::Hidden,
86+
cl::desc("Whether to enable openmp opt"));
87+
8388
#if LLVM_VERSION_MAJOR >= 14
8489
#define addAttribute addAttributeAtIndex
8590
#endif
@@ -1736,6 +1741,14 @@ class Enzyme : public ModulePass {
17361741
I->eraseFromParent();
17371742
}
17381743
}
1744+
1745+
#if LLVM_VERSION_MAJOR >= 13
1746+
if (PostOpt && EnzymeOMPOpt) {
1747+
OpenMPOptPass().run(M, Logic.PPC.MAM);
1748+
changed = true;
1749+
}
1750+
#endif
1751+
17391752
std::set<Function *> done;
17401753
for (Function &F : M) {
17411754
if (F.empty())
@@ -1794,6 +1807,13 @@ class Enzyme : public ModulePass {
17941807
changed = true;
17951808
}
17961809

1810+
#if LLVM_VERSION_MAJOR >= 13
1811+
if (PostOpt && EnzymeOMPOpt) {
1812+
OpenMPOptPass().run(M, Logic.PPC.MAM);
1813+
changed = true;
1814+
}
1815+
#endif
1816+
17971817
Logic.clear();
17981818
return changed;
17991819
}

enzyme/Enzyme/FunctionUtils.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,7 @@ PreProcessCache::PreProcessCache() {
920920
FAM.registerPass([] { return OptimizationRemarkEmitterAnalysis(); });
921921
FAM.registerPass([] { return LazyValueAnalysis(); });
922922
#if LLVM_VERSION_MAJOR >= 8
923+
MAM.registerPass([] { return PassInstrumentationAnalysis(); });
923924
FAM.registerPass([] { return PassInstrumentationAnalysis(); });
924925
#endif
925926

enzyme/Enzyme/TypeAnalysis/TypeAnalysis.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,22 @@ void TypeAnalyzer::considerTBAA() {
842842
updateAnalysis(call->getOperand(0), update, call);
843843
updateAnalysis(call->getOperand(1), update, call);
844844
continue;
845+
} else if (call->getCalledFunction() &&
846+
(call->getCalledFunction()->getIntrinsicID() ==
847+
Intrinsic::memset)) {
848+
int64_t copySize = 1;
849+
for (auto val : fntypeinfo.knownIntegralValues(call->getOperand(2),
850+
DT, intseen, SE)) {
851+
copySize = max(copySize, val);
852+
}
853+
TypeTree update =
854+
vdptr
855+
.ShiftIndices(DL, /*init offset*/ 0,
856+
/*max size*/ copySize, /*new offset*/ 0)
857+
.Only(-1);
858+
859+
updateAnalysis(call->getOperand(0), update, call);
860+
continue;
845861
} else if (call->getCalledFunction() &&
846862
call->getCalledFunction()->getIntrinsicID() ==
847863
Intrinsic::masked_gather) {

0 commit comments

Comments
 (0)