From 5b477f0c08c01109dc0e67985ea38e263babf14e Mon Sep 17 00:00:00 2001 From: Philip Reames Date: Fri, 20 Feb 2015 22:39:41 +0000 Subject: [PATCH] [RewriteStatepointsForGC] Cleanup - replace std::vector usage [NFC] Migrate std::vector usage to a combination of SmallVector and ArrayRef. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@230079 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../Scalar/RewriteStatepointsForGC.cpp | 78 +++++++++---------- 1 file changed, 38 insertions(+), 40 deletions(-) diff --git a/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp b/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp index baa49e3472c..041f405ca48 100644 --- a/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp +++ b/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp @@ -1065,11 +1065,11 @@ static void fixupLiveness(DominatorTree &DT, const CallSite &CS, static void fixupLiveReferences( Function &F, DominatorTree &DT, Pass *P, const std::set &allInsertedDefs, - std::vector &toUpdate, - std::vector &records) { + ArrayRef toUpdate, + MutableArrayRef records) { for (size_t i = 0; i < records.size(); i++) { struct PartiallyConstructedSafepointRecord &info = records[i]; - CallSite &CS = toUpdate[i]; + const CallSite &CS = toUpdate[i]; fixupLiveness(DT, CS, allInsertedDefs, info); } } @@ -1097,7 +1097,7 @@ static BasicBlock *normalizeBBForInvokeSafepoint(BasicBlock *BB, return ret; } -static int find_index(const SmallVectorImpl &livevec, Value *val) { +static int find_index(ArrayRef livevec, Value *val) { auto itr = std::find(livevec.begin(), livevec.end(), val); assert(livevec.end() != itr); size_t index = std::distance(livevec.begin(), itr); @@ -1147,14 +1147,13 @@ static AttributeSet legalizeCallAttributes(AttributeSet AS) { /// statepointToken - statepoint instruction to which relocates should be /// bound. /// Builder - Llvm IR builder to be used to construct new calls. -/// Returns array with newly created relocates. -static std::vector -CreateGCRelocates(const SmallVectorImpl &liveVariables, - const int liveStart, - const SmallVectorImpl &basePtrs, - Instruction *statepointToken, IRBuilder<> Builder) { +void CreateGCRelocates(ArrayRef liveVariables, + const int liveStart, + ArrayRef basePtrs, + Instruction *statepointToken, IRBuilder<> Builder) { - std::vector newDefs; + SmallVector NewDefs; + NewDefs.reserve(liveVariables.size()); Module *M = statepointToken->getParent()->getParent()->getParent(); @@ -1163,7 +1162,7 @@ CreateGCRelocates(const SmallVectorImpl &liveVariables, // combination. This results is some blow up the function declarations in // the IR, but removes the need for argument bitcasts which shrinks the IR // greatly and makes it much more readable. - std::vector types; // one per 'any' type + SmallVector types; // one per 'any' type types.push_back(liveVariables[i]->getType()); // result type Value *gc_relocate_decl = Intrinsic::getDeclaration( M, Intrinsic::experimental_gc_relocate, types); @@ -1185,12 +1184,10 @@ CreateGCRelocates(const SmallVectorImpl &liveVariables, // fake call. cast(reloc)->setCallingConv(CallingConv::Cold); - newDefs.push_back(cast(reloc)); + NewDefs.push_back(cast(reloc)); } - assert(newDefs.size() == liveVariables.size() && + assert(NewDefs.size() == liveVariables.size() && "missing or extra redefinition at safepoint"); - - return newDefs; } static void @@ -1223,7 +1220,7 @@ makeStatepointExplicitImpl(const CallSite &CS, /* to replace */ IRBuilder<> Builder(insertBefore); // Copy all of the arguments from the original statepoint - this includes the // target, call args, and deopt args - std::vector args; + SmallVector args; args.insert(args.end(), CS.arg_begin(), CS.arg_end()); // TODO: Clear the 'needs rewrite' flag @@ -1444,8 +1441,8 @@ insertRelocationStores(iterator_range gcRelocs, /// do all the relocation update via allocas and mem2reg static void relocationViaAlloca( - Function &F, DominatorTree &DT, const std::vector &live, - const std::vector &records) { + Function &F, DominatorTree &DT, ArrayRef live, + ArrayRef records) { #ifndef NDEBUG int initialAllocaNum = 0; @@ -1613,14 +1610,16 @@ static void relocationViaAlloca( /// Implement a unique function which doesn't require we sort the input /// vector. Doing so has the effect of changing the output of a couple of /// tests in ways which make them less useful in testing fused safepoints. -template static void unique_unsorted(std::vector &vec) { - DenseSet seen; - std::vector tmp; - vec.reserve(vec.size()); - std::swap(tmp, vec); - for (auto V : tmp) { - if (seen.insert(V).second) { - vec.push_back(V); +template static void unique_unsorted(SmallVectorImpl &Vec) { + DenseSet Seen; + SmallVector TempVec; + TempVec.reserve(Vec.size()); + for (auto Element : Vec) + TempVec.push_back(Element); + Vec.clear(); + for (auto V : TempVec) { + if (Seen.insert(V).second) { + Vec.push_back(V); } } } @@ -1635,7 +1634,7 @@ static Function *getUseHolder(Module &M) { /// Insert holders so that each Value is obviously live through the entire /// liftetime of the call. static void insertUseHolderAfter(CallSite &CS, const ArrayRef Values, - std::vector &holders) { + SmallVectorImpl &holders) { Module *M = CS.getInstruction()->getParent()->getParent()->getParent(); Function *Func = getUseHolder(*M); if (CS.isCall()) { @@ -1659,11 +1658,11 @@ static void insertUseHolderAfter(CallSite &CS, const ArrayRef Values, } static void findLiveReferences( - Function &F, DominatorTree &DT, Pass *P, std::vector &toUpdate, - std::vector &records) { + Function &F, DominatorTree &DT, Pass *P, ArrayRef toUpdate, + MutableArrayRef records) { for (size_t i = 0; i < records.size(); i++) { struct PartiallyConstructedSafepointRecord &info = records[i]; - CallSite &CS = toUpdate[i]; + const CallSite &CS = toUpdate[i]; analyzeParsePointLiveness(DT, CS, info); } } @@ -1698,7 +1697,7 @@ static void addBasesAsLiveValues(std::set &liveset, } static bool insertParsePoints(Function &F, DominatorTree &DT, Pass *P, - std::vector &toUpdate) { + SmallVectorImpl &toUpdate) { #ifndef NDEBUG // sanity check the input std::set uniqued; @@ -1714,7 +1713,7 @@ static bool insertParsePoints(Function &F, DominatorTree &DT, Pass *P, // A list of dummy calls added to the IR to keep various values obviously // live in the IR. We'll remove all of these when done. - std::vector holders; + SmallVector holders; // Insert a dummy call with all of the arguments to the vm_state we'll need // for the actual safepoint insertion. This ensures reference arguments in @@ -1733,7 +1732,7 @@ static bool insertParsePoints(Function &F, DominatorTree &DT, Pass *P, insertUseHolderAfter(CS, DeoptValues, holders); } - std::vector records; + SmallVector records; records.reserve(toUpdate.size()); for (size_t i = 0; i < toUpdate.size(); i++) { struct PartiallyConstructedSafepointRecord info; @@ -1856,7 +1855,7 @@ static bool insertParsePoints(Function &F, DominatorTree &DT, Pass *P, } // Do all the fixups of the original live variables to their relocated selves - std::vector live; + SmallVector live; for (size_t i = 0; i < records.size(); i++) { struct PartiallyConstructedSafepointRecord &info = records[i]; // We can't simply save the live set from the original insertion. One of @@ -1903,12 +1902,11 @@ bool RewriteStatepointsForGC::runOnFunction(Function &F) { return false; // Gather all the statepoints which need rewritten. - std::vector ParsePointNeeded; - for (inst_iterator itr = inst_begin(F), end = inst_end(F); itr != end; - itr++) { + SmallVector ParsePointNeeded; + for (Instruction &I : inst_range(F)) { // TODO: only the ones with the flag set! - if (isStatepoint(*itr)) - ParsePointNeeded.push_back(CallSite(&*itr)); + if (isStatepoint(I)) + ParsePointNeeded.push_back(CallSite(&I)); } // Return early if no work to do. -- 2.34.1