diff --git a/enzyme/CMakeLists.txt b/enzyme/CMakeLists.txt index 2d9f4da058d25..92079d1c16c34 100644 --- a/enzyme/CMakeLists.txt +++ b/enzyme/CMakeLists.txt @@ -66,6 +66,8 @@ message("LLVM_INCLUDE_DIRS: ${LLVM_INCLUDE_DIRS}") message("found llvm definitions " ${LLVM_DEFINITIONS}) message("found llvm version " ${LLVM_VERSION_MAJOR}) +option(ENZYME_FLANG "Build for non-version compliant FLANG" OFF) +add_definitions(-DFLANG=1) # Offer the user the choice of overriding the installation directories set(INSTALL_INCLUDE_DIR include CACHE PATH "Installation directory for header files") diff --git a/enzyme/Enzyme/ActivityAnalysis.h b/enzyme/Enzyme/ActivityAnalysis.h index c11bdb6448a65..708d1bb0335be 100644 --- a/enzyme/Enzyme/ActivityAnalysis.h +++ b/enzyme/Enzyme/ActivityAnalysis.h @@ -122,12 +122,12 @@ class ActivityAnalyzer { bool isConstantValue(TypeResults &TR, llvm::Value *val); private: - std::map> + llvm::DenseMap> ReEvaluateValueIfInactiveInst; - std::map> + llvm::DenseMap> ReEvaluateValueIfInactiveValue; - std::map> + llvm::DenseMap> ReEvaluateInstIfInactiveValue; void InsertConstantInstruction(TypeResults &TR, llvm::Instruction *I); diff --git a/enzyme/Enzyme/CacheUtility.cpp b/enzyme/Enzyme/CacheUtility.cpp index 76c04bfe97f9c..8a354a226a026 100644 --- a/enzyme/Enzyme/CacheUtility.cpp +++ b/enzyme/Enzyme/CacheUtility.cpp @@ -893,7 +893,11 @@ AllocaInst *CacheUtility::createCacheForScope(LimitContext ctx, Type *T, #if LLVM_VERSION_MAJOR >= 14 malloccall->addDereferenceableRetAttr( ci->getLimitedValue() * byteSizeOfType->getLimitedValue()); +#ifndef FLANG AttrBuilder B(ci->getContext()); +#else + AttrBuilder B; +#endif B.addDereferenceableOrNullAttr(ci->getLimitedValue() * byteSizeOfType->getLimitedValue()); malloccall->setAttributes( diff --git a/enzyme/Enzyme/Enzyme.cpp b/enzyme/Enzyme/Enzyme.cpp index bd286732948a0..9b1fa5d93ffec 100644 --- a/enzyme/Enzyme/Enzyme.cpp +++ b/enzyme/Enzyme/Enzyme.cpp @@ -1619,7 +1619,7 @@ class Enzyme : public ModulePass { // code left here to re-enable upon Attributor patch Logic.PPC.FAM.clear(F, F.getName()); -#if LLVM_VERSION_MAJOR >= 13 +#if LLVM_VERSION_MAJOR >= 13 && !defined(FLANG) AnalysisGetter AG(Logic.PPC.FAM); SetVector Functions; diff --git a/enzyme/Enzyme/EnzymeLogic.cpp b/enzyme/Enzyme/EnzymeLogic.cpp index ee4f08bcfe418..c50626c5d8a1a 100644 --- a/enzyme/Enzyme/EnzymeLogic.cpp +++ b/enzyme/Enzyme/EnzymeLogic.cpp @@ -2180,7 +2180,11 @@ const AugmentedReturn &EnzymeLogic::CreateAugmentedPrimal( } #if LLVM_VERSION_MAJOR >= 14 malloccall->addDereferenceableRetAttr(size->getLimitedValue()); +#ifndef FLANG AttrBuilder B(malloccall->getContext()); +#else + AttrBuilder B; +#endif B.addDereferenceableOrNullAttr(size->getLimitedValue()); malloccall->setAttributes(malloccall->getAttributes().addRetAttributes( malloccall->getContext(), B)); diff --git a/enzyme/Enzyme/FunctionUtils.cpp b/enzyme/Enzyme/FunctionUtils.cpp index e4974f7cb744d..6eca9fd47cfc4 100644 --- a/enzyme/Enzyme/FunctionUtils.cpp +++ b/enzyme/Enzyme/FunctionUtils.cpp @@ -1433,7 +1433,7 @@ Function *PreProcessCache::preprocessForClone(Function *F, } { -#if LLVM_VERSION_MAJOR >= 14 +#if LLVM_VERSION_MAJOR >= 14 && !defined(FLANG) auto PA = SROAPass().run(*NewF, FAM); #else auto PA = SROA().run(*NewF, FAM); @@ -1444,7 +1444,7 @@ Function *PreProcessCache::preprocessForClone(Function *F, ReplaceReallocs(NewF); { -#if LLVM_VERSION_MAJOR >= 14 +#if LLVM_VERSION_MAJOR >= 14 && !defined(FLANG) auto PA = SROAPass().run(*NewF, FAM); #else auto PA = SROA().run(*NewF, FAM); @@ -1973,12 +1973,12 @@ void SelectOptimization(Function *F) { } void PreProcessCache::optimizeIntermediate(Function *F) { PromotePass().run(*F, FAM); -#if LLVM_VERSION_MAJOR >= 14 +#if LLVM_VERSION_MAJOR >= 14 && !defined(FLANG) GVNPass().run(*F, FAM); #else GVN().run(*F, FAM); #endif -#if LLVM_VERSION_MAJOR >= 14 +#if LLVM_VERSION_MAJOR >= 14 && !defined(FLANG) SROAPass().run(*F, FAM); #else SROA().run(*F, FAM); diff --git a/enzyme/Enzyme/GradientUtils.h b/enzyme/Enzyme/GradientUtils.h index 2e51e96ffabc0..19cc47293a5fe 100644 --- a/enzyme/Enzyme/GradientUtils.h +++ b/enzyme/Enzyme/GradientUtils.h @@ -749,7 +749,11 @@ class GradientUtils : public CacheUtility { #if LLVM_VERSION_MAJOR >= 14 cast(anti)->addDereferenceableRetAttr(ci->getLimitedValue()); cal->addDereferenceableRetAttr(ci->getLimitedValue()); +#ifndef FLANG AttrBuilder B(Fn->getContext()); +#else + AttrBuilder B; +#endif B.addDereferenceableOrNullAttr(ci->getLimitedValue()); cast(anti)->setAttributes( cast(anti)->getAttributes().addRetAttributes(