@@ -134,7 +134,7 @@ static TargetTransformInfo::UnrollingPreferences gatherUnrollingPreferences(
134134 Loop *L, ScalarEvolution &SE, const TargetTransformInfo &TTI, int OptLevel,
135135 Optional<unsigned > UserThreshold, Optional<unsigned > UserCount,
136136 Optional<bool > UserAllowPartial, Optional<bool > UserRuntime,
137- Optional<bool > UserUpperBound) {
137+ Optional<bool > UserUpperBound, Optional< bool > UserAllowPeeling ) {
138138 TargetTransformInfo::UnrollingPreferences UP;
139139
140140 // Set up the defaults
@@ -201,6 +201,8 @@ static TargetTransformInfo::UnrollingPreferences gatherUnrollingPreferences(
201201 UP.Runtime = *UserRuntime;
202202 if (UserUpperBound.hasValue ())
203203 UP.UpperBound = *UserUpperBound;
204+ if (UserAllowPeeling.hasValue ())
205+ UP.AllowPeeling = *UserAllowPeeling;
204206
205207 return UP;
206208}
@@ -927,15 +929,13 @@ static bool computeUnrollCount(
927929 return ExplicitUnroll;
928930}
929931
930- static bool tryToUnrollLoop (Loop *L, DominatorTree &DT, LoopInfo *LI,
931- ScalarEvolution &SE, const TargetTransformInfo &TTI,
932- AssumptionCache &AC, OptimizationRemarkEmitter &ORE,
933- bool PreserveLCSSA, int OptLevel,
934- Optional<unsigned > ProvidedCount,
935- Optional<unsigned > ProvidedThreshold,
936- Optional<bool > ProvidedAllowPartial,
937- Optional<bool > ProvidedRuntime,
938- Optional<bool > ProvidedUpperBound) {
932+ static bool tryToUnrollLoop (
933+ Loop *L, DominatorTree &DT, LoopInfo *LI, ScalarEvolution &SE,
934+ const TargetTransformInfo &TTI, AssumptionCache &AC,
935+ OptimizationRemarkEmitter &ORE, bool PreserveLCSSA, int OptLevel,
936+ Optional<unsigned > ProvidedCount, Optional<unsigned > ProvidedThreshold,
937+ Optional<bool > ProvidedAllowPartial, Optional<bool > ProvidedRuntime,
938+ Optional<bool > ProvidedUpperBound, Optional<bool > ProvidedAllowPeeling) {
939939 DEBUG (dbgs () << " Loop Unroll: F[" << L->getHeader ()->getParent ()->getName ()
940940 << " ] Loop %" << L->getHeader ()->getName () << " \n " );
941941 if (HasUnrollDisablePragma (L))
@@ -951,7 +951,8 @@ static bool tryToUnrollLoop(Loop *L, DominatorTree &DT, LoopInfo *LI,
951951 bool Convergent;
952952 TargetTransformInfo::UnrollingPreferences UP = gatherUnrollingPreferences (
953953 L, SE, TTI, OptLevel, ProvidedThreshold, ProvidedCount,
954- ProvidedAllowPartial, ProvidedRuntime, ProvidedUpperBound);
954+ ProvidedAllowPartial, ProvidedRuntime, ProvidedUpperBound,
955+ ProvidedAllowPeeling);
955956 // Exit early if unrolling is disabled.
956957 if (UP.Threshold == 0 && (!UP.Partial || UP.PartialThreshold == 0 ))
957958 return false ;
@@ -1053,10 +1054,12 @@ class LoopUnroll : public LoopPass {
10531054 LoopUnroll (int OptLevel = 2 , Optional<unsigned > Threshold = None,
10541055 Optional<unsigned > Count = None,
10551056 Optional<bool > AllowPartial = None, Optional<bool > Runtime = None,
1056- Optional<bool > UpperBound = None)
1057+ Optional<bool > UpperBound = None,
1058+ Optional<bool > AllowPeeling = None)
10571059 : LoopPass(ID), OptLevel(OptLevel), ProvidedCount(std::move(Count)),
10581060 ProvidedThreshold (Threshold), ProvidedAllowPartial(AllowPartial),
1059- ProvidedRuntime(Runtime), ProvidedUpperBound(UpperBound) {
1061+ ProvidedRuntime(Runtime), ProvidedUpperBound(UpperBound),
1062+ ProvidedAllowPeeling(AllowPeeling) {
10601063 initializeLoopUnrollPass (*PassRegistry::getPassRegistry ());
10611064 }
10621065
@@ -1066,6 +1069,7 @@ class LoopUnroll : public LoopPass {
10661069 Optional<bool > ProvidedAllowPartial;
10671070 Optional<bool > ProvidedRuntime;
10681071 Optional<bool > ProvidedUpperBound;
1072+ Optional<bool > ProvidedAllowPeeling;
10691073
10701074 bool runOnLoop (Loop *L, LPPassManager &) override {
10711075 if (skipLoop (L))
@@ -1088,7 +1092,7 @@ class LoopUnroll : public LoopPass {
10881092 return tryToUnrollLoop (L, DT, LI, SE, TTI, AC, ORE, PreserveLCSSA, OptLevel,
10891093 ProvidedCount, ProvidedThreshold,
10901094 ProvidedAllowPartial, ProvidedRuntime,
1091- ProvidedUpperBound);
1095+ ProvidedUpperBound, ProvidedAllowPeeling );
10921096 }
10931097
10941098 // / This transformation requires natural loop information & requires that
@@ -1112,8 +1116,8 @@ INITIALIZE_PASS_DEPENDENCY(TargetTransformInfoWrapperPass)
11121116INITIALIZE_PASS_END(LoopUnroll, " loop-unroll" , " Unroll loops" , false , false )
11131117
11141118Pass *llvm::createLoopUnrollPass(int OptLevel, int Threshold, int Count,
1115- int AllowPartial, int Runtime,
1116- int UpperBound ) {
1119+ int AllowPartial, int Runtime, int UpperBound,
1120+ int AllowPeeling ) {
11171121 // TODO: It would make more sense for this function to take the optionals
11181122 // directly, but that's dangerous since it would silently break out of tree
11191123 // callers.
@@ -1122,11 +1126,12 @@ Pass *llvm::createLoopUnrollPass(int OptLevel, int Threshold, int Count,
11221126 Count == -1 ? None : Optional<unsigned >(Count),
11231127 AllowPartial == -1 ? None : Optional<bool >(AllowPartial),
11241128 Runtime == -1 ? None : Optional<bool >(Runtime),
1125- UpperBound == -1 ? None : Optional<bool >(UpperBound));
1129+ UpperBound == -1 ? None : Optional<bool >(UpperBound),
1130+ AllowPeeling == -1 ? None : Optional<bool >(AllowPeeling));
11261131}
11271132
11281133Pass *llvm::createSimpleLoopUnrollPass (int OptLevel) {
1129- return llvm::createLoopUnrollPass (OptLevel, -1 , -1 , 0 , 0 , 0 );
1134+ return llvm::createLoopUnrollPass (OptLevel, -1 , -1 , 0 , 0 , 0 , 0 );
11301135}
11311136
11321137PreservedAnalyses LoopFullUnrollPass::run (Loop &L, LoopAnalysisManager &AM,
@@ -1156,7 +1161,8 @@ PreservedAnalyses LoopFullUnrollPass::run(Loop &L, LoopAnalysisManager &AM,
11561161 tryToUnrollLoop (&L, AR.DT , &AR.LI , AR.SE , AR.TTI , AR.AC , *ORE,
11571162 /* PreserveLCSSA*/ true , OptLevel, /* Count*/ None,
11581163 /* Threshold*/ None, /* AllowPartial*/ false ,
1159- /* Runtime*/ false , /* UpperBound*/ false );
1164+ /* Runtime*/ false , /* UpperBound*/ false ,
1165+ /* AllowPeeling*/ false );
11601166 if (!Changed)
11611167 return PreservedAnalyses::all ();
11621168
@@ -1278,7 +1284,8 @@ PreservedAnalyses LoopUnrollPass::run(Function &F,
12781284 bool CurChanged = tryToUnrollLoop (
12791285 &L, DT, &LI, SE, TTI, AC, ORE,
12801286 /* PreserveLCSSA*/ true , OptLevel, /* Count*/ None,
1281- /* Threshold*/ None, AllowPartialParam, RuntimeParam, UpperBoundParam);
1287+ /* Threshold*/ None, AllowPartialParam, RuntimeParam, UpperBoundParam,
1288+ /* AllowPeeling*/ None);
12821289 Changed |= CurChanged;
12831290
12841291 // The parent must not be damaged by unrolling!
0 commit comments