Skip to content

Commit 318e268

Browse files
authored
Faster activity datastructures and handle version breaking flang (rust-lang#458)
1 parent f379fc4 commit 318e268

7 files changed

+22
-8
lines changed

enzyme/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ message("LLVM_INCLUDE_DIRS: ${LLVM_INCLUDE_DIRS}")
6666
message("found llvm definitions " ${LLVM_DEFINITIONS})
6767
message("found llvm version " ${LLVM_VERSION_MAJOR})
6868

69+
option(ENZYME_FLANG "Build for non-version compliant FLANG" OFF)
70+
add_definitions(-DFLANG=1)
6971

7072
# Offer the user the choice of overriding the installation directories
7173
set(INSTALL_INCLUDE_DIR include CACHE PATH "Installation directory for header files")

enzyme/Enzyme/ActivityAnalysis.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,12 @@ class ActivityAnalyzer {
122122
bool isConstantValue(TypeResults &TR, llvm::Value *val);
123123

124124
private:
125-
std::map<llvm::Instruction *, std::set<llvm::Value *>>
125+
llvm::DenseMap<llvm::Instruction *, llvm::SmallPtrSet<llvm::Value *, 4>>
126126
ReEvaluateValueIfInactiveInst;
127-
std::map<llvm::Value *, std::set<llvm::Value *>>
127+
llvm::DenseMap<llvm::Value *, llvm::SmallPtrSet<llvm::Value *, 4>>
128128
ReEvaluateValueIfInactiveValue;
129129

130-
std::map<llvm::Value *, std::set<llvm::Instruction *>>
130+
llvm::DenseMap<llvm::Value *, llvm::SmallPtrSet<llvm::Instruction *, 4>>
131131
ReEvaluateInstIfInactiveValue;
132132

133133
void InsertConstantInstruction(TypeResults &TR, llvm::Instruction *I);

enzyme/Enzyme/CacheUtility.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,11 @@ AllocaInst *CacheUtility::createCacheForScope(LimitContext ctx, Type *T,
893893
#if LLVM_VERSION_MAJOR >= 14
894894
malloccall->addDereferenceableRetAttr(
895895
ci->getLimitedValue() * byteSizeOfType->getLimitedValue());
896+
#ifndef FLANG
896897
AttrBuilder B(ci->getContext());
898+
#else
899+
AttrBuilder B;
900+
#endif
897901
B.addDereferenceableOrNullAttr(ci->getLimitedValue() *
898902
byteSizeOfType->getLimitedValue());
899903
malloccall->setAttributes(

enzyme/Enzyme/Enzyme.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1619,7 +1619,7 @@ class Enzyme : public ModulePass {
16191619
// code left here to re-enable upon Attributor patch
16201620
Logic.PPC.FAM.clear(F, F.getName());
16211621

1622-
#if LLVM_VERSION_MAJOR >= 13
1622+
#if LLVM_VERSION_MAJOR >= 13 && !defined(FLANG)
16231623

16241624
AnalysisGetter AG(Logic.PPC.FAM);
16251625
SetVector<Function *> Functions;

enzyme/Enzyme/EnzymeLogic.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2180,7 +2180,11 @@ const AugmentedReturn &EnzymeLogic::CreateAugmentedPrimal(
21802180
}
21812181
#if LLVM_VERSION_MAJOR >= 14
21822182
malloccall->addDereferenceableRetAttr(size->getLimitedValue());
2183+
#ifndef FLANG
21832184
AttrBuilder B(malloccall->getContext());
2185+
#else
2186+
AttrBuilder B;
2187+
#endif
21842188
B.addDereferenceableOrNullAttr(size->getLimitedValue());
21852189
malloccall->setAttributes(malloccall->getAttributes().addRetAttributes(
21862190
malloccall->getContext(), B));

enzyme/Enzyme/FunctionUtils.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,7 +1433,7 @@ Function *PreProcessCache::preprocessForClone(Function *F,
14331433
}
14341434

14351435
{
1436-
#if LLVM_VERSION_MAJOR >= 14
1436+
#if LLVM_VERSION_MAJOR >= 14 && !defined(FLANG)
14371437
auto PA = SROAPass().run(*NewF, FAM);
14381438
#else
14391439
auto PA = SROA().run(*NewF, FAM);
@@ -1444,7 +1444,7 @@ Function *PreProcessCache::preprocessForClone(Function *F,
14441444
ReplaceReallocs(NewF);
14451445

14461446
{
1447-
#if LLVM_VERSION_MAJOR >= 14
1447+
#if LLVM_VERSION_MAJOR >= 14 && !defined(FLANG)
14481448
auto PA = SROAPass().run(*NewF, FAM);
14491449
#else
14501450
auto PA = SROA().run(*NewF, FAM);
@@ -1973,12 +1973,12 @@ void SelectOptimization(Function *F) {
19731973
}
19741974
void PreProcessCache::optimizeIntermediate(Function *F) {
19751975
PromotePass().run(*F, FAM);
1976-
#if LLVM_VERSION_MAJOR >= 14
1976+
#if LLVM_VERSION_MAJOR >= 14 && !defined(FLANG)
19771977
GVNPass().run(*F, FAM);
19781978
#else
19791979
GVN().run(*F, FAM);
19801980
#endif
1981-
#if LLVM_VERSION_MAJOR >= 14
1981+
#if LLVM_VERSION_MAJOR >= 14 && !defined(FLANG)
19821982
SROAPass().run(*F, FAM);
19831983
#else
19841984
SROA().run(*F, FAM);

enzyme/Enzyme/GradientUtils.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,11 @@ class GradientUtils : public CacheUtility {
749749
#if LLVM_VERSION_MAJOR >= 14
750750
cast<CallInst>(anti)->addDereferenceableRetAttr(ci->getLimitedValue());
751751
cal->addDereferenceableRetAttr(ci->getLimitedValue());
752+
#ifndef FLANG
752753
AttrBuilder B(Fn->getContext());
754+
#else
755+
AttrBuilder B;
756+
#endif
753757
B.addDereferenceableOrNullAttr(ci->getLimitedValue());
754758
cast<CallInst>(anti)->setAttributes(
755759
cast<CallInst>(anti)->getAttributes().addRetAttributes(

0 commit comments

Comments
 (0)