/// Gather the various unrolling parameters based on the defaults, compiler /// flags, TTI overrides and user specified parameters. static TargetTransformInfo::UnrollingPreferences gatherUnrollingPreferences( Loop *L, const TargetTransformInfo &TTI, Optional<unsigned> UserThreshold, Optional<unsigned> UserCount, Optional<bool> UserAllowPartial, Optional<bool> UserRuntime) { TargetTransformInfo::UnrollingPreferences UP; // Set up the defaults UP.Threshold = 150; UP.PercentDynamicCostSavedThreshold = 50; UP.DynamicCostSavingsDiscount = 100; UP.OptSizeThreshold = 0; UP.PartialThreshold = UP.Threshold; UP.PartialOptSizeThreshold = 0; UP.Count = 0; UP.MaxCount = UINT_MAX; UP.FullUnrollMaxCount = UINT_MAX; UP.Partial = false; UP.Runtime = false; UP.AllowRemainder = true; UP.AllowExpensiveTripCount = false; UP.Force = false; // Override with any target specific settings TTI.getUnrollingPreferences(L, UP); // Apply size attributes if (L->getHeader()->getParent()->optForSize()) { UP.Threshold = UP.OptSizeThreshold; UP.PartialThreshold = UP.PartialOptSizeThreshold; } // Apply any user values specified by cl::opt if (UnrollThreshold.getNumOccurrences() > 0) { UP.Threshold = UnrollThreshold; UP.PartialThreshold = UnrollThreshold; } if (UnrollPercentDynamicCostSavedThreshold.getNumOccurrences() > 0) UP.PercentDynamicCostSavedThreshold = UnrollPercentDynamicCostSavedThreshold; if (UnrollDynamicCostSavingsDiscount.getNumOccurrences() > 0) UP.DynamicCostSavingsDiscount = UnrollDynamicCostSavingsDiscount; if (UnrollMaxCount.getNumOccurrences() > 0) UP.MaxCount = UnrollMaxCount; if (UnrollFullMaxCount.getNumOccurrences() > 0) UP.FullUnrollMaxCount = UnrollFullMaxCount; if (UnrollAllowPartial.getNumOccurrences() > 0) UP.Partial = UnrollAllowPartial; if (UnrollAllowRemainder.getNumOccurrences() > 0) UP.AllowRemainder = UnrollAllowRemainder; if (UnrollRuntime.getNumOccurrences() > 0) UP.Runtime = UnrollRuntime; // Apply user values provided by argument if (UserThreshold.hasValue()) { UP.Threshold = *UserThreshold; UP.PartialThreshold = *UserThreshold; } if (UserCount.hasValue()) UP.Count = *UserCount; if (UserAllowPartial.hasValue()) UP.Partial = *UserAllowPartial; if (UserRuntime.hasValue()) UP.Runtime = *UserRuntime; return UP; }
/// Gather the various unrolling parameters based on the defaults, compiler /// flags, TTI overrides, pragmas, and user specified parameters. static TargetTransformInfo::UnrollingPreferences gatherUnrollingPreferences( Loop *L, const TargetTransformInfo &TTI, Optional<unsigned> UserThreshold, Optional<unsigned> UserCount, Optional<bool> UserAllowPartial, Optional<bool> UserRuntime, unsigned PragmaCount, bool PragmaFullUnroll, bool PragmaEnableUnroll, unsigned TripCount) { TargetTransformInfo::UnrollingPreferences UP; // Set up the defaults UP.Threshold = 150; UP.PercentDynamicCostSavedThreshold = 20; UP.DynamicCostSavingsDiscount = 2000; UP.OptSizeThreshold = 0; UP.PartialThreshold = UP.Threshold; UP.PartialOptSizeThreshold = 0; UP.Count = 0; UP.MaxCount = UINT_MAX; UP.FullUnrollMaxCount = UINT_MAX; UP.Partial = false; UP.Runtime = false; UP.AllowExpensiveTripCount = false; // Override with any target specific settings TTI.getUnrollingPreferences(L, UP); // Apply size attributes if (L->getHeader()->getParent()->optForSize()) { UP.Threshold = UP.OptSizeThreshold; UP.PartialThreshold = UP.PartialOptSizeThreshold; } // Apply unroll count pragmas if (PragmaCount) UP.Count = PragmaCount; else if (PragmaFullUnroll) UP.Count = TripCount; // Apply any user values specified by cl::opt if (UnrollThreshold.getNumOccurrences() > 0) { UP.Threshold = UnrollThreshold; UP.PartialThreshold = UnrollThreshold; } if (UnrollPercentDynamicCostSavedThreshold.getNumOccurrences() > 0) UP.PercentDynamicCostSavedThreshold = UnrollPercentDynamicCostSavedThreshold; if (UnrollDynamicCostSavingsDiscount.getNumOccurrences() > 0) UP.DynamicCostSavingsDiscount = UnrollDynamicCostSavingsDiscount; if (UnrollCount.getNumOccurrences() > 0) UP.Count = UnrollCount; if (UnrollMaxCount.getNumOccurrences() > 0) UP.MaxCount = UnrollMaxCount; if (UnrollFullMaxCount.getNumOccurrences() > 0) UP.FullUnrollMaxCount = UnrollFullMaxCount; if (UnrollAllowPartial.getNumOccurrences() > 0) UP.Partial = UnrollAllowPartial; if (UnrollRuntime.getNumOccurrences() > 0) UP.Runtime = UnrollRuntime; // Apply user values provided by argument if (UserThreshold.hasValue()) { UP.Threshold = *UserThreshold; UP.PartialThreshold = *UserThreshold; } if (UserCount.hasValue()) UP.Count = *UserCount; if (UserAllowPartial.hasValue()) UP.Partial = *UserAllowPartial; if (UserRuntime.hasValue()) UP.Runtime = *UserRuntime; if (PragmaCount > 0 || ((PragmaFullUnroll || PragmaEnableUnroll) && TripCount != 0)) { // If the loop has an unrolling pragma, we want to be more aggressive with // unrolling limits. Set thresholds to at least the PragmaTheshold value // which is larger than the default limits. if (UP.Threshold != NoThreshold) UP.Threshold = std::max<unsigned>(UP.Threshold, PragmaUnrollThreshold); if (UP.PartialThreshold != NoThreshold) UP.PartialThreshold = std::max<unsigned>(UP.PartialThreshold, PragmaUnrollThreshold); } return UP; }