diff options
author | Sanjoy Das <sanjoy@playingwithpointers.com> | 2016-05-21 02:52:13 +0000 |
---|---|---|
committer | Sanjoy Das <sanjoy@playingwithpointers.com> | 2016-05-21 02:52:13 +0000 |
commit | c5b1169de22fa6ffd0f2b730638e3ede3f8f55f6 (patch) | |
tree | 5488660b77ebc3d1a56b4e3fc34cff446756fab7 /llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp | |
parent | 59776734a3f6ba2b732be18bacd25c73aeae657a (diff) | |
download | llvm-c5b1169de22fa6ffd0f2b730638e3ede3f8f55f6.zip llvm-c5b1169de22fa6ffd0f2b730638e3ede3f8f55f6.tar.gz llvm-c5b1169de22fa6ffd0f2b730638e3ede3f8f55f6.tar.bz2 |
[IRCE] Don't use an allocator for range checks; NFC
The InductiveRangeCheck struct is only five words long; so passing these
around value is fine. The allocator makes the code look more complex
than it is.
llvm-svn: 270309
Diffstat (limited to 'llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp')
-rw-r--r-- | llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp | 65 |
1 files changed, 28 insertions, 37 deletions
diff --git a/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp b/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp index 984b4c4..5b4b6c1 100644 --- a/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp +++ b/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp @@ -179,8 +179,6 @@ public: const SCEV *getEnd() const { return End; } }; - typedef SpecificBumpPtrAllocator<InductiveRangeCheck> AllocatorTy; - /// This is the value the condition of the branch needs to evaluate to for the /// branch to take the hot successor (see (1) above). bool getPassingDirection() { return true; } @@ -191,16 +189,13 @@ public: Optional<Range> computeSafeIterationSpace(ScalarEvolution &SE, const SCEVAddRecExpr *IndVar) const; - /// Create an inductive range check out of BI if possible, else return - /// nullptr. - static InductiveRangeCheck *create(AllocatorTy &Alloc, BranchInst *BI, - Loop *L, ScalarEvolution &SE, - BranchProbabilityInfo &BPI); + /// Create an inductive range check out of BI if possible, else return None. + static Optional<InductiveRangeCheck> create(BranchInst *BI, Loop *L, + ScalarEvolution &SE, + BranchProbabilityInfo &BPI); }; class InductiveRangeCheckElimination : public LoopPass { - InductiveRangeCheck::AllocatorTy Allocator; - public: static char ID; InductiveRangeCheckElimination() : LoopPass(ID) { @@ -376,19 +371,17 @@ InductiveRangeCheck::parseRangeCheck(Loop *L, ScalarEvolution &SE, return InductiveRangeCheck::RANGE_CHECK_UNKNOWN; } - -InductiveRangeCheck * -InductiveRangeCheck::create(InductiveRangeCheck::AllocatorTy &A, BranchInst *BI, - Loop *L, ScalarEvolution &SE, +Optional<InductiveRangeCheck> +InductiveRangeCheck::create(BranchInst *BI, Loop *L, ScalarEvolution &SE, BranchProbabilityInfo &BPI) { if (BI->isUnconditional() || BI->getParent() == L->getLoopLatch()) - return nullptr; + return None; BranchProbability LikelyTaken(15, 16); if (BPI.getEdgeProbability(BI->getParent(), (unsigned) 0) < LikelyTaken) - return nullptr; + return None; Value *Length = nullptr; const SCEV *IndexSCEV = nullptr; @@ -397,7 +390,7 @@ InductiveRangeCheck::create(InductiveRangeCheck::AllocatorTy &A, BranchInst *BI, IndexSCEV, Length); if (RCKind == InductiveRangeCheck::RANGE_CHECK_UNKNOWN) - return nullptr; + return None; assert(IndexSCEV && "contract with SplitRangeCheckCondition!"); assert((!(RCKind & InductiveRangeCheck::RANGE_CHECK_UPPER) || Length) && @@ -408,14 +401,14 @@ InductiveRangeCheck::create(InductiveRangeCheck::AllocatorTy &A, BranchInst *BI, IndexAddRec && (IndexAddRec->getLoop() == L) && IndexAddRec->isAffine(); if (!IsAffineIndex) - return nullptr; - - InductiveRangeCheck *IRC = new (A.Allocate()) InductiveRangeCheck; - IRC->Length = Length; - IRC->Offset = IndexAddRec->getStart(); - IRC->Scale = IndexAddRec->getStepRecurrence(SE); - IRC->Branch = BI; - IRC->Kind = RCKind; + return None; + + InductiveRangeCheck IRC; + IRC.Length = Length; + IRC.Offset = IndexAddRec->getStart(); + IRC.Scale = IndexAddRec->getStepRecurrence(SE); + IRC.Branch = BI; + IRC.Kind = RCKind; return IRC; } @@ -1396,17 +1389,15 @@ bool InductiveRangeCheckElimination::runOnLoop(Loop *L, LPPassManager &LPM) { } LLVMContext &Context = Preheader->getContext(); - InductiveRangeCheck::AllocatorTy IRCAlloc; - SmallVector<InductiveRangeCheck *, 16> RangeChecks; + SmallVector<InductiveRangeCheck, 16> RangeChecks; ScalarEvolution &SE = getAnalysis<ScalarEvolutionWrapperPass>().getSE(); BranchProbabilityInfo &BPI = getAnalysis<BranchProbabilityInfoWrapperPass>().getBPI(); for (auto BBI : L->getBlocks()) if (BranchInst *TBI = dyn_cast<BranchInst>(BBI->getTerminator())) - if (InductiveRangeCheck *IRC = - InductiveRangeCheck::create(IRCAlloc, TBI, L, SE, BPI)) - RangeChecks.push_back(IRC); + if (auto MaybeIRC = InductiveRangeCheck::create(TBI, L, SE, BPI)) + RangeChecks.push_back(*MaybeIRC); if (RangeChecks.empty()) return false; @@ -1415,8 +1406,8 @@ bool InductiveRangeCheckElimination::runOnLoop(Loop *L, LPPassManager &LPM) { OS << "irce: looking at loop "; L->print(OS); OS << "irce: loop has " << RangeChecks.size() << " inductive range checks: \n"; - for (InductiveRangeCheck *IRC : RangeChecks) - IRC->print(OS); + for (InductiveRangeCheck &IRC : RangeChecks) + IRC.print(OS); }; DEBUG(PrintRecognizedRangeChecks(dbgs())); @@ -1442,11 +1433,11 @@ bool InductiveRangeCheckElimination::runOnLoop(Loop *L, LPPassManager &LPM) { Optional<InductiveRangeCheck::Range> SafeIterRange; Instruction *ExprInsertPt = Preheader->getTerminator(); - SmallVector<InductiveRangeCheck *, 4> RangeChecksToEliminate; + SmallVector<InductiveRangeCheck, 4> RangeChecksToEliminate; IRBuilder<> B(ExprInsertPt); - for (InductiveRangeCheck *IRC : RangeChecks) { - auto Result = IRC->computeSafeIterationSpace(SE, IndVar); + for (InductiveRangeCheck &IRC : RangeChecks) { + auto Result = IRC.computeSafeIterationSpace(SE, IndVar); if (Result.hasValue()) { auto MaybeSafeIterRange = IntersectRange(SE, SafeIterRange, Result.getValue()); @@ -1479,11 +1470,11 @@ bool InductiveRangeCheckElimination::runOnLoop(Loop *L, LPPassManager &LPM) { // Optimize away the now-redundant range checks. - for (InductiveRangeCheck *IRC : RangeChecksToEliminate) { - ConstantInt *FoldedRangeCheck = IRC->getPassingDirection() + for (InductiveRangeCheck &IRC : RangeChecksToEliminate) { + ConstantInt *FoldedRangeCheck = IRC.getPassingDirection() ? ConstantInt::getTrue(Context) : ConstantInt::getFalse(Context); - IRC->getBranch()->setCondition(FoldedRangeCheck); + IRC.getBranch()->setCondition(FoldedRangeCheck); } } |