Index: llvm/include/llvm/Transforms/IPO/IROutliner.h =================================================================== --- llvm/include/llvm/Transforms/IPO/IROutliner.h +++ llvm/include/llvm/Transforms/IPO/IROutliner.h @@ -119,9 +119,6 @@ /// Used to create an outlined function. CodeExtractor *CE = nullptr; - /// Used to create an outlined function. - CodeExtractorAnalysisCache *CEAC = nullptr; - /// The call site of the extracted region. CallInst *Call = nullptr; @@ -336,8 +333,6 @@ /// that Value, back to its original Value. DenseMap OutputMappings; - DenseMap CEACs; - /// IRSimilarityIdentifier lambda to retrieve IRSimilarityIdentifier. function_ref getIRSI; @@ -347,9 +342,6 @@ /// The memory allocator used to allocate the CodeExtractors. SpecificBumpPtrAllocator ExtractorAllocator; - /// The memory allocator used to allocate the CodeExtractors. - SpecificBumpPtrAllocator CEACAllocator; - /// The memory allocator used to allocate the OutlinableRegions. SpecificBumpPtrAllocator RegionAllocator; Index: llvm/include/llvm/Transforms/Utils/CodeExtractor.h =================================================================== --- llvm/include/llvm/Transforms/Utils/CodeExtractor.h +++ llvm/include/llvm/Transforms/Utils/CodeExtractor.h @@ -53,20 +53,12 @@ /// Blocks which contain instructions which may have unknown side-effects /// on memory. DenseSet SideEffectingBlocks; - - /// The set of Instructions that have side effects, and the BasicBlock they - /// were initially in. - DenseMap SideEffectingInstructions; void findSideEffectInfoForBlock(BasicBlock &BB); public: CodeExtractorAnalysisCache(Function &F); - void TestAndAddSideEffectingBlock(BasicBlock *OldBlock, BasicBlock *NewBlock); - - void TestAndRemoveSideEffectingBlock(BasicBlock *RemovedBlock); - /// Get the allocas in the function at the time the analysis was created. /// Note that some of these allocas may no longer be present in the function, /// due to \ref CodeExtractor::extractCodeRegion. Index: llvm/lib/Transforms/IPO/IROutliner.cpp =================================================================== --- llvm/lib/Transforms/IPO/IROutliner.cpp +++ llvm/lib/Transforms/IPO/IROutliner.cpp @@ -354,19 +354,12 @@ if (PHIPredBlock) PrevBB->replaceSuccessorsPhiUsesWith(PHIPredBlock, PrevBB); - CEAC->TestAndAddSideEffectingBlock(PrevBB, StartBB); - CandidateSplit = true; if (!BackInst->isTerminator()) { EndBB = EndInst->getParent(); FollowBB = EndBB->splitBasicBlock(EndInst, OriginalName + "_after_outline"); EndBB->replaceSuccessorsPhiUsesWith(EndBB, FollowBB); FollowBB->replaceSuccessorsPhiUsesWith(PrevBB, FollowBB); - - if (EndBB == StartBB) - CEAC->TestAndAddSideEffectingBlock(PrevBB, FollowBB); - else - CEAC->TestAndAddSideEffectingBlock(EndBB, FollowBB); } else { EndBB = BackInst->getParent(); EndsInBranch = true; @@ -437,7 +430,6 @@ } moveBBContents(*StartBB, *PrevBB); - CEAC->TestAndRemoveSideEffectingBlock(StartBB); BasicBlock *PlacementBB = PrevBB; if (StartBB != EndBB) @@ -447,7 +439,6 @@ assert(PlacementBB->getTerminator() && "Terminator removed from EndBB!"); PlacementBB->getTerminator()->eraseFromParent(); moveBBContents(*FollowBB, *PlacementBB); - CEAC->TestAndRemoveSideEffectingBlock(FollowBB); PlacementBB->replaceSuccessorsPhiUsesWith(FollowBB, PlacementBB); FollowBB->eraseFromParent(); } @@ -894,6 +885,11 @@ // allocas or removing llvm.assumes. CodeExtractor *CE = Region.CE; CE->findInputsOutputs(OverallInputs, DummyOutputs, SinkCands); + assert(Region.StartBB && "Region must have a start BasicBlock!"); + Function *OrigF = Region.StartBB->getParent(); + CodeExtractorAnalysisCache CEAC(*OrigF); + BasicBlock *Dummy = nullptr; + // The region may be ineligible due to VarArgs in the parent function. In this // case we ignore the region. if (!CE->isEligible()) { @@ -901,11 +897,8 @@ return; } - assert(Region.StartBB && "Region must have a start BasicBlock!"); - BasicBlock *Dummy = nullptr; - // Find if any values are going to be sunk into the function when extracted - CE->findAllocas(*Region.CEAC, SinkCands, HoistCands, Dummy); + CE->findAllocas(CEAC, SinkCands, HoistCands, Dummy); CE->findInputsOutputs(PremappedInputs, Outputs, SinkCands); // TODO: Support regions with sunken allocas: values whose lifetimes are @@ -2712,8 +2705,10 @@ SetVector ArgInputs, Outputs, SinkCands; assert(Region.StartBB && "StartBB for the OutlinableRegion is nullptr!"); BasicBlock *InitialStart = Region.StartBB; + Function *OrigF = Region.StartBB->getParent(); + CodeExtractorAnalysisCache CEAC(*OrigF); Region.ExtractedFunction = - Region.CE->extractCodeRegion(*Region.CEAC, ArgInputs, Outputs); + Region.CE->extractCodeRegion(CEAC, ArgInputs, Outputs); // If the extraction was successful, find the BasicBlock, and reassign the // OutlinableRegion blocks @@ -2835,19 +2830,6 @@ // types for the Aggregate Outlining Function. OutlinedRegions.clear(); for (OutlinableRegion *OS : CurrentGroup.Regions) { - Function *OrigF = OS->Candidate->getStartBB()->getParent(); - DenseMap::iterator CEACIt = - CEACs.find(OrigF); - if (CEACIt == CEACs.end()) { - bool Inserted = false; - CodeExtractorAnalysisCache *CEAC = - new (CEACAllocator.Allocate()) CodeExtractorAnalysisCache(*OrigF); - std::tie(CEACIt, Inserted) = CEACs.insert(std::make_pair(OrigF, CEAC)); - } - assert(CEACIt != CEACs.end() && - "Could not find a CodeExtractorAnalysisCache for function!"); - OS->CEAC = CEACIt->second; - // Break the outlinable region out of its parent BasicBlock into its own // BasicBlocks (see function implementation). OS->splitCandidate(); Index: llvm/lib/Transforms/Utils/CodeExtractor.cpp =================================================================== --- llvm/lib/Transforms/Utils/CodeExtractor.cpp +++ llvm/lib/Transforms/Utils/CodeExtractor.cpp @@ -317,30 +317,6 @@ } } -void CodeExtractorAnalysisCache::TestAndAddSideEffectingBlock( - BasicBlock *OldBlock, BasicBlock *NewBlock) { - if (BaseMemAddrs.find(OldBlock) != BaseMemAddrs.end()) { - findSideEffectInfoForBlock(*NewBlock); - return; - } - - if (SideEffectingBlocks.find(OldBlock) == SideEffectingBlocks.end()) - return; - - findSideEffectInfoForBlock(*NewBlock); -} - -void CodeExtractorAnalysisCache::TestAndRemoveSideEffectingBlock( - BasicBlock *RemovedBlock) { - if (BaseMemAddrs.find(RemovedBlock) != BaseMemAddrs.end()) - BaseMemAddrs.erase(RemovedBlock); - - if (SideEffectingBlocks.find(RemovedBlock) == SideEffectingBlocks.end()) - return; - - SideEffectingBlocks.erase(RemovedBlock); -} - void CodeExtractorAnalysisCache::findSideEffectInfoForBlock(BasicBlock &BB) { for (Instruction &II : BB.instructionsWithoutDebug()) { unsigned Opcode = II.getOpcode(); @@ -361,7 +337,6 @@ Value *Base = MemAddr->stripInBoundsConstantOffsets(); if (!isa(Base)) { SideEffectingBlocks.insert(&BB); - SideEffectingInstructions.insert(std::make_pair(&BB, &II)); return; } BaseMemAddrs[&BB].insert(Base); @@ -373,13 +348,11 @@ if (IntrInst->isLifetimeStartOrEnd()) break; SideEffectingBlocks.insert(&BB); - SideEffectingInstructions.insert(std::make_pair(&BB, &II)); return; } // Treat all the other cases conservatively if it has side effects. if (II.mayHaveSideEffects()) { SideEffectingBlocks.insert(&BB); - SideEffectingInstructions.insert(std::make_pair(&BB, &II)); return; } }