@@ -2070,42 +2070,16 @@ void SelectOptimization(Function *F) {
2070
2070
}
2071
2071
}
2072
2072
}
2073
- void PreProcessCache::optimizeIntermediate (Function *F) {
2074
- PromotePass ().run (*F, FAM);
2075
- #if LLVM_VERSION_MAJOR >= 14 && !defined(FLANG)
2076
- GVNPass ().run (*F, FAM);
2077
- #else
2078
- GVN ().run (*F, FAM);
2079
- #endif
2080
- #if LLVM_VERSION_MAJOR >= 14 && !defined(FLANG)
2081
- SROAPass ().run (*F, FAM);
2082
- #else
2083
- SROA ().run (*F, FAM);
2084
- #endif
2085
2073
2086
- if (EnzymeSelectOpt) {
2087
- #if LLVM_VERSION_MAJOR >= 12
2088
- SimplifyCFGOptions scfgo;
2089
- #else
2090
- SimplifyCFGOptions scfgo (
2091
- /* unsigned BonusThreshold=*/ 1 , /* bool ForwardSwitchCond=*/ false ,
2092
- /* bool SwitchToLookup=*/ false , /* bool CanonicalLoops=*/ true ,
2093
- /* bool SinkCommon=*/ true , /* AssumptionCache *AssumpCache=*/ nullptr );
2094
- #endif
2095
- SimplifyCFGPass (scfgo).run (*F, FAM);
2096
- CorrelatedValuePropagationPass ().run (*F, FAM);
2097
- SelectOptimization (F);
2098
- }
2099
- // EarlyCSEPass(/*memoryssa*/ true).run(*F, FAM);
2100
-
2101
- for (Function &Impl : *F->getParent ()) {
2074
+ void ReplaceFunctionImplementation (Module &M) {
2075
+ for (Function &Impl : M) {
2102
2076
for (auto attr : {" implements" , " implements2" }) {
2103
2077
if (!Impl.hasFnAttribute (attr))
2104
2078
continue ;
2105
2079
const Attribute &A = Impl.getFnAttribute (attr);
2106
2080
2107
2081
const StringRef SpecificationName = A.getValueAsString ();
2108
- Function *Specification = F-> getParent ()-> getFunction (SpecificationName);
2082
+ Function *Specification = M. getFunction (SpecificationName);
2109
2083
if (!Specification) {
2110
2084
LLVM_DEBUG (dbgs () << " Found implementation '" << Impl.getName ()
2111
2085
<< " ' but no matching specification with name '"
@@ -2139,10 +2113,41 @@ void PreProcessCache::optimizeIntermediate(Function *F) {
2139
2113
}
2140
2114
}
2141
2115
}
2116
+ }
2117
+
2118
+ void PreProcessCache::optimizeIntermediate (Function *F) {
2119
+ PromotePass ().run (*F, FAM);
2120
+ #if LLVM_VERSION_MAJOR >= 14 && !defined(FLANG)
2121
+ GVNPass ().run (*F, FAM);
2122
+ #else
2123
+ GVN ().run (*F, FAM);
2124
+ #endif
2125
+ #if LLVM_VERSION_MAJOR >= 14 && !defined(FLANG)
2126
+ SROAPass ().run (*F, FAM);
2127
+ #else
2128
+ SROA ().run (*F, FAM);
2129
+ #endif
2130
+
2131
+ if (EnzymeSelectOpt) {
2132
+ #if LLVM_VERSION_MAJOR >= 12
2133
+ SimplifyCFGOptions scfgo;
2134
+ #else
2135
+ SimplifyCFGOptions scfgo (
2136
+ /* unsigned BonusThreshold=*/ 1 , /* bool ForwardSwitchCond=*/ false ,
2137
+ /* bool SwitchToLookup=*/ false , /* bool CanonicalLoops=*/ true ,
2138
+ /* bool SinkCommon=*/ true , /* AssumptionCache *AssumpCache=*/ nullptr );
2139
+ #endif
2140
+ SimplifyCFGPass (scfgo).run (*F, FAM);
2141
+ CorrelatedValuePropagationPass ().run (*F, FAM);
2142
+ SelectOptimization (F);
2143
+ }
2144
+ // EarlyCSEPass(/*memoryssa*/ true).run(*F, FAM);
2142
2145
2143
2146
if (EnzymeCoalese)
2144
2147
CoaleseTrivialMallocs (*F, FAM.getResult <DominatorTreeAnalysis>(*F));
2145
2148
2149
+ ReplaceFunctionImplementation (*F->getParent ());
2150
+
2146
2151
PreservedAnalyses PA;
2147
2152
FAM.invalidate (*F, PA);
2148
2153
// TODO actually run post optimizations.
0 commit comments