[llvm] 13a85a7 - [ObjC][ARC] Share bundle handling code between steps of the ObjCARCOpts pass and cleanup (NFC)

Stefan Gränitz via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 24 06:17:47 PST 2023


Author: Stefan Gränitz
Date: 2023-01-24T15:17:18+01:00
New Revision: 13a85a78cfea78af908300b3e8993b57da83921f

URL: https://github.com/llvm/llvm-project/commit/13a85a78cfea78af908300b3e8993b57da83921f
DIFF: https://github.com/llvm/llvm-project/commit/13a85a78cfea78af908300b3e8993b57da83921f.diff

LOG: [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

Added: 
    llvm/test/Transforms/ObjCARC/funclet-cleanuppad.ll

Modified: 
    llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp

Removed: 
    llvm/test/Transforms/ObjCARC/funclet.ll


################################################################################
diff  --git a/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp b/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
index 510859842603..a374958f9707 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<OperandBundleDef, 1> 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 <typename PredicateT>
+  static void cloneOpBundlesIf(CallBase *CI,
+                               SmallVectorImpl<OperandBundleDef> &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<CallInst>(cloneCallInstForBB(*CInst, *InsertPos->getParent()));
+      SmallVector<OperandBundleDef, 1> 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


        


More information about the llvm-commits mailing list