[PATCH] D145767: [Verifier][NFC] Refactor check for associated metadata to allow multiple operands on AIX

Ting Wang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 9 22:03:11 PST 2023


tingwang created this revision.
tingwang added reviewers: arsenm, shchenz, hubert.reinterpretcast, nemanjai, cebowleratibm.
tingwang added a project: LLVM.
Herald added a subscriber: hiraditya.
Herald added a project: All.
tingwang requested review of this revision.
Herald added subscribers: llvm-commits, wdng.

Currently associated metadata is limited to have single operand.

Patch https://reviews.llvm.org/D125095 intends to use associated metadata to express the associations between global objects on AIX. The association could be one to multiple, for example one static variable could have associated with init and term functions.

This patch intends to setup context to check multiple operands for `TT.isOSAIX()`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145767

Files:
  llvm/lib/IR/Verifier.cpp


Index: llvm/lib/IR/Verifier.cpp
===================================================================
--- llvm/lib/IR/Verifier.cpp
+++ llvm/lib/IR/Verifier.cpp
@@ -663,22 +663,29 @@
             GO->getMetadata(LLVMContext::MD_associated)) {
       Check(Associated->getNumOperands() == 1,
             "associated metadata must have one operand", &GV, Associated);
-      const Metadata *Op = Associated->getOperand(0).get();
-      Check(Op, "associated metadata must have a global value", GO, Associated);
-
-      const auto *VM = dyn_cast_or_null<ValueAsMetadata>(Op);
-      Check(VM, "associated metadata must be ValueAsMetadata", GO, Associated);
-      if (VM) {
-        Check(isa<PointerType>(VM->getValue()->getType()),
-              "associated value must be pointer typed", GV, Associated);
-
-        const Value *Stripped = VM->getValue()->stripPointerCastsAndAliases();
-        Check(isa<GlobalObject>(Stripped) || isa<Constant>(Stripped),
-              "associated metadata must point to a GlobalObject", GO, Stripped);
-        Check(Stripped != GO,
-              "global values should not associate to themselves", GO,
+      auto CheckAssocOperand = [this, &GV, GO, Associated](const Metadata *Op) {
+        Check(Op, "associated metadata must have a global value", GO,
               Associated);
-      }
+
+        const auto *VM = dyn_cast_or_null<ValueAsMetadata>(Op);
+        Check(VM, "associated metadata must be ValueAsMetadata", GO,
+              Associated);
+        if (VM) {
+          Check(isa<PointerType>(VM->getValue()->getType()),
+                "associated value must be pointer typed", GV, Associated);
+
+          const Value *Stripped = VM->getValue()->stripPointerCastsAndAliases();
+          Check(isa<GlobalObject>(Stripped) || isa<Constant>(Stripped),
+                "associated metadata must point to a GlobalObject", GO,
+                Stripped);
+          Check(Stripped != GO,
+                "global values should not associate to themselves", GO,
+                Associated);
+        }
+      };
+
+      for (unsigned i = 0, e = Associated->getNumOperands(); i != e; ++i)
+        CheckAssocOperand(Associated->getOperand(i).get());
     }
   }
   Check(!GV.hasAppendingLinkage() || isa<GlobalVariable>(GV),


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145767.504023.patch
Type: text/x-patch
Size: 2281 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230310/bb2adb99/attachment.bin>


More information about the llvm-commits mailing list