From 13a85a78cfea78af908300b3e8993b57da83921f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Stefan=20Gr=C3=A4nitz?= Date: Tue, 24 Jan 2023 11:39:25 +0100 Subject: [PATCH] [ObjC][ARC] Share bundle handling code between steps of the ObjCARCOpts pass and cleanup (NFC) Generalize and share code for operand bundle handling. Drop the anonymous namespace (all other helper functions are local static). Rename the existing funclet test for cleanup-pads. Reviewed By: compnerd Differential Revision: https://reviews.llvm.org/D137945 --- llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp | 34 +++++++++------------- .../ObjCARC/{funclet.ll => funclet-cleanuppad.ll} | 0 2 files changed, 14 insertions(+), 20 deletions(-) rename llvm/test/Transforms/ObjCARC/{funclet.ll => funclet-cleanuppad.ll} (100%) diff --git a/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp b/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp index 5108598..a374958 100644 --- a/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp +++ b/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp @@ -567,25 +567,15 @@ class ObjCARCOpt { void OptimizeReturns(Function &F); - Instruction *cloneCallInstForBB(CallInst &CI, BasicBlock &BB) { - SmallVector OpBundles; - for (unsigned I = 0, E = CI.getNumOperandBundles(); I != E; ++I) { - auto Bundle = CI.getOperandBundleAt(I); - // Funclets will be reassociated in the future. - if (Bundle.getTagID() == LLVMContext::OB_funclet) - continue; - OpBundles.emplace_back(Bundle); + template + static void cloneOpBundlesIf(CallBase *CI, + SmallVectorImpl &OpBundles, + PredicateT Predicate) { + for (unsigned I = 0, E = CI->getNumOperandBundles(); I != E; ++I) { + OperandBundleUse B = CI->getOperandBundleAt(I); + if (Predicate(B)) + OpBundles.emplace_back(B); } - - if (!BlockEHColors.empty()) { - const ColorVector &CV = BlockEHColors.find(&BB)->second; - assert(CV.size() > 0 && "non-unique color for block!"); - Instruction *EHPad = CV.front()->getFirstNonPHI(); - if (EHPad->isEHPad()) - OpBundles.emplace_back("funclet", EHPad); - } - - return CallInst::Create(&CI, OpBundles); } void addOpBundleForFunclet(BasicBlock *BB, @@ -1152,8 +1142,12 @@ void ObjCARCOpt::OptimizeIndividualCallImpl(Function &F, Instruction *Inst, continue; Value *Op = PN->getIncomingValue(i); Instruction *InsertPos = &PN->getIncomingBlock(i)->back(); - CallInst *Clone = - cast(cloneCallInstForBB(*CInst, *InsertPos->getParent())); + SmallVector OpBundles; + cloneOpBundlesIf(CInst, OpBundles, [](const OperandBundleUse &B) { + return B.getTagID() != LLVMContext::OB_funclet; + }); + addOpBundleForFunclet(InsertPos->getParent(), OpBundles); + CallInst *Clone = CallInst::Create(CInst, OpBundles); if (Op->getType() != ParamTy) Op = new BitCastInst(Op, ParamTy, "", InsertPos); Clone->setArgOperand(0, Op); diff --git a/llvm/test/Transforms/ObjCARC/funclet.ll b/llvm/test/Transforms/ObjCARC/funclet-cleanuppad.ll similarity index 100% rename from llvm/test/Transforms/ObjCARC/funclet.ll rename to llvm/test/Transforms/ObjCARC/funclet-cleanuppad.ll -- 2.7.4