[llvm] [MIR] Resolve callSites and calledGlobals blocks by number (PR #229320)

via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 6 03:34:00 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-aarch64

Author: Mian Miftah (mmiftahx)

<details>
<summary>Changes</summary>

The bb field of callSites and calledGlobals is the number of the block,
as the MIR printer writes it, but the parser used it as the position of
the block in the function. The two differ once a pass adds, removes or
moves blocks without renumbering them, for example after block placement
or when a custom inserter splits a block in finalize-isel. Such MIR then
fails to parse, or an entry is silently attached to the call in another
block.

Look the block up by number, as block references in instructions are.


---

Patch is 54.72 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/229320.diff


62 Files Affected:

- (modified) llvm/docs/MIRLangRef.md (+4-1) 
- (modified) llvm/include/llvm/CodeGen/MIRYamlMapping.h (+5-5) 
- (modified) llvm/lib/CodeGen/MIRParser/MIRParser.cpp (+20-21) 
- (modified) llvm/lib/CodeGen/MIRPrinter.cpp (+21-18) 
- (modified) llvm/test/CodeGen/AArch64/calleetypeid-directcall-mismatched.ll (+3-3) 
- (modified) llvm/test/CodeGen/AArch64/expand-blr-rvmarker-pseudo.mir (+2-2) 
- (modified) llvm/test/CodeGen/ARM/calleetypeid-directcall-mismatched.ll (+3-3) 
- (modified) llvm/test/CodeGen/MIR/AArch64/called-globals.mir (+4-4) 
- (modified) llvm/test/CodeGen/MIR/Hexagon/bundled-call-site-info.mir (+2-2) 
- (modified) llvm/test/CodeGen/MIR/X86/call-site-info-ambiguous-indirect-call-typeid.mir (+1-1) 
- (added) llvm/test/CodeGen/MIR/X86/call-site-info-block-numbers.mir (+48) 
- (modified) llvm/test/CodeGen/MIR/X86/call-site-info-direct-calls-typeid.mir (+3-3) 
- (modified) llvm/test/CodeGen/MIR/X86/call-site-info-error1.mir (+2-2) 
- (modified) llvm/test/CodeGen/MIR/X86/call-site-info-error2.mir (+2-2) 
- (modified) llvm/test/CodeGen/MIR/X86/call-site-info-error3.mir (+2-2) 
- (modified) llvm/test/CodeGen/MIR/X86/call-site-info-error4.mir (+1-1) 
- (modified) llvm/test/CodeGen/MIR/X86/call-site-info-typeid.mir (+1-1) 
- (modified) llvm/test/CodeGen/Mips/calleetypeid-directcall-mismatched.ll (+3-3) 
- (modified) llvm/test/CodeGen/RISCV/calleetypeid-directcall-mismatched.ll (+3-3) 
- (modified) llvm/test/CodeGen/X86/calleetypeid-directcall-mismatched.ll (+3-3) 
- (modified) llvm/test/CodeGen/X86/taildup-callsiteinfo.mir (+3-3) 
- (modified) llvm/test/DebugInfo/AArch64/callsite.mir (+1-1) 
- (modified) llvm/test/DebugInfo/MIR/AArch64/dbgcall-site-expr-chain.mir (+1-1) 
- (modified) llvm/test/DebugInfo/MIR/AArch64/dbgcall-site-expr-entry-value.mir (+1-1) 
- (modified) llvm/test/DebugInfo/MIR/AArch64/dbgcall-site-indirect-param-with-offset.mir (+2-2) 
- (modified) llvm/test/DebugInfo/MIR/AArch64/dbgcall-site-indirect-param.mir (+2-2) 
- (modified) llvm/test/DebugInfo/MIR/AArch64/dbgcall-site-interpret-movzxi.mir (+4-4) 
- (modified) llvm/test/DebugInfo/MIR/AArch64/dbgcall-site-interpretation.mir (+2-2) 
- (modified) llvm/test/DebugInfo/MIR/AArch64/dbgcall-site-orr-moves.mir (+3-3) 
- (modified) llvm/test/DebugInfo/MIR/AArch64/dbgcall-site-preserved-subreg.mir (+1-1) 
- (modified) llvm/test/DebugInfo/MIR/ARM/call-site-info-vmovd.mir (+2-2) 
- (modified) llvm/test/DebugInfo/MIR/ARM/call-site-info-vmovs.mir (+2-2) 
- (modified) llvm/test/DebugInfo/MIR/ARM/dbgcall-site-interpretation.mir (+2-2) 
- (modified) llvm/test/DebugInfo/MIR/ARM/dbgcallsite-noreg-is-imm-check.mir (+1-1) 
- (modified) llvm/test/DebugInfo/MIR/ARM/if-coverter-call-site-info.mir (+1-1) 
- (modified) llvm/test/DebugInfo/MIR/Hexagon/dbgcall-site-instr-before-bundled-call.mir (+1-1) 
- (modified) llvm/test/DebugInfo/MIR/Mips/call-site-info-update-delay-slot-filler.mir (+1-1) 
- (modified) llvm/test/DebugInfo/MIR/Mips/dbg-call-site-copy-sub-reg.mir (+1-1) 
- (modified) llvm/test/DebugInfo/MIR/Mips/dbg-call-site-delay-slot-interpretation-64bit.mir (+1-1) 
- (modified) llvm/test/DebugInfo/MIR/Mips/dbg-call-site-delay-slot-interpretation.mir (+1-1) 
- (modified) llvm/test/DebugInfo/MIR/Mips/dbg-call-site-param-addiu-64bit.mir (+2-2) 
- (modified) llvm/test/DebugInfo/MIR/Mips/dbg-call-site-param-addiu.mir (+2-2) 
- (modified) llvm/test/DebugInfo/MIR/SystemZ/call-site-lzer.mir (+1-1) 
- (modified) llvm/test/DebugInfo/MIR/X86/backup-entry-values-usage.mir (+1-1) 
- (modified) llvm/test/DebugInfo/MIR/X86/call-site-gnu-vs-dwarf5-attrs.mir (+4-4) 
- (modified) llvm/test/DebugInfo/MIR/X86/call-site-param-mov16.mir (+1-1) 
- (modified) llvm/test/DebugInfo/MIR/X86/callsite-stack-value.mir (+1-1) 
- (modified) llvm/test/DebugInfo/MIR/X86/dbg-call-site-spilled-arg-multiple-defs.mir (+1-1) 
- (modified) llvm/test/DebugInfo/MIR/X86/dbg-call-site-spilled-arg.mir (+1-1) 
- (modified) llvm/test/DebugInfo/MIR/X86/dbgcall-site-clobbered-regs.mir (+2-2) 
- (modified) llvm/test/DebugInfo/MIR/X86/dbgcall-site-copy-super-sub.mir (+2-2) 
- (modified) llvm/test/DebugInfo/MIR/X86/dbgcall-site-interpretation.mir (+2-2) 
- (modified) llvm/test/DebugInfo/MIR/X86/dbgcall-site-lea-interpretation.mir (+2-2) 
- (modified) llvm/test/DebugInfo/MIR/X86/dbgcall-site-partial-describe-subreg.mir (+1-1) 
- (modified) llvm/test/DebugInfo/MIR/X86/dbgcall-site-partial-describe.mir (+1-1) 
- (modified) llvm/test/DebugInfo/MIR/X86/dbgcall-site-preserved-after.mir (+2-2) 
- (modified) llvm/test/DebugInfo/MIR/X86/dbgcall-site-preserved-clobbered.mir (+1-1) 
- (modified) llvm/test/DebugInfo/MIR/X86/dbgcall-site-reg-shuffle.mir (+1-1) 
- (modified) llvm/test/DebugInfo/MIR/X86/dbgcall-site-two-fwd-reg-defs.mir (+2-2) 
- (modified) llvm/test/DebugInfo/MIR/X86/debug-call-site-param.mir (+2-2) 
- (modified) llvm/test/DebugInfo/MIR/X86/unreachable-block-call-site.mir (+1-1) 
- (modified) llvm/test/DebugInfo/Mips/livedebugvariables-reorder.mir (+1-1) 


``````````diff
diff --git a/llvm/docs/MIRLangRef.md b/llvm/docs/MIRLangRef.md
index 0ded89c1a4de44..321bafd746fcb5 100644
--- a/llvm/docs/MIRLangRef.md
+++ b/llvm/docs/MIRLangRef.md
@@ -177,7 +177,7 @@ of such a YAML document:
  liveins:
    - { reg: '$rdi' }
  callSites:
-   - { bb: 0, offset: 3, fwdArgRegs:
+   - { bb: '%bb.0', offset: 3, fwdArgRegs:
        - { arg: 0, reg: '$edi' } }
  body: |
    bb.0.entry:
@@ -202,6 +202,9 @@ the function's machine basic blocks and their machine instructions.
 
 The attribute `callSites` is a representation of call site information which
 keeps track of call instructions and registers used to transfer call arguments.
+Each entry names the block of its call with a block reference, `bb`, and gives
+the call's position in that block, counting instructions in bundles, as
+`offset`.
 
 ## Machine Instructions Format Reference
 
diff --git a/llvm/include/llvm/CodeGen/MIRYamlMapping.h b/llvm/include/llvm/CodeGen/MIRYamlMapping.h
index ab1c91d9f0de5b..3d9d8dd32adb81 100644
--- a/llvm/include/llvm/CodeGen/MIRYamlMapping.h
+++ b/llvm/include/llvm/CodeGen/MIRYamlMapping.h
@@ -493,11 +493,11 @@ template <> struct ScalarTraits<FrameIndex> {
 
 /// Identifies call instruction location in machine function.
 struct MachineInstrLoc {
-  unsigned BlockNum;
+  StringValue Block;
   unsigned Offset;
 
   bool operator==(const MachineInstrLoc &Other) const {
-    return BlockNum == Other.BlockNum && Offset == Other.Offset;
+    return Block == Other.Block && Offset == Other.Offset;
   }
 };
 
@@ -520,7 +520,7 @@ struct CallSiteInfo {
   std::vector<uint64_t> CalleeTypeIds;
 
   bool operator==(const CallSiteInfo &Other) const {
-    return CallLocation.BlockNum == Other.CallLocation.BlockNum &&
+    return CallLocation.Block == Other.CallLocation.Block &&
            CallLocation.Offset == Other.CallLocation.Offset;
   }
 };
@@ -543,7 +543,7 @@ namespace yaml {
 
 template <> struct MappingTraits<CallSiteInfo> {
   static void mapping(IO &YamlIO, CallSiteInfo &CSInfo) {
-    YamlIO.mapRequired("bb", CSInfo.CallLocation.BlockNum);
+    YamlIO.mapRequired("bb", CSInfo.CallLocation.Block);
     YamlIO.mapRequired("offset", CSInfo.CallLocation.Offset);
     YamlIO.mapOptional("fwdArgRegs", CSInfo.ArgForwardingRegs,
                        std::vector<CallSiteInfo::ArgRegPair>());
@@ -645,7 +645,7 @@ struct CalledGlobal {
 
 template <> struct MappingTraits<CalledGlobal> {
   static void mapping(IO &YamlIO, CalledGlobal &CG) {
-    YamlIO.mapRequired("bb", CG.CallSite.BlockNum);
+    YamlIO.mapRequired("bb", CG.CallSite.Block);
     YamlIO.mapRequired("offset", CG.CallSite.Offset);
     YamlIO.mapRequired("callee", CG.Callee);
     YamlIO.mapRequired("flags", CG.Flags);
diff --git a/llvm/lib/CodeGen/MIRParser/MIRParser.cpp b/llvm/lib/CodeGen/MIRParser/MIRParser.cpp
index 26af6ef073082d..f2af6ccefea00d 100644
--- a/llvm/lib/CodeGen/MIRParser/MIRParser.cpp
+++ b/llvm/lib/CodeGen/MIRParser/MIRParser.cpp
@@ -193,7 +193,8 @@ class MIRParserImpl {
   void setupDebugValueTracking(MachineFunction &MF,
     PerFunctionMIParsingState &PFS, const yaml::MachineFunction &YamlMF);
 
-  bool parseMachineInst(MachineFunction &MF, yaml::MachineInstrLoc MILoc,
+  bool parseMachineInst(PerFunctionMIParsingState &PFS,
+                        const yaml::MachineInstrLoc &MILoc,
                         MachineInstr const *&MI);
 };
 
@@ -482,20 +483,18 @@ bool MIRParserImpl::computeFunctionProperties(
   return false;
 }
 
-bool MIRParserImpl::parseMachineInst(MachineFunction &MF,
-                                     yaml::MachineInstrLoc MILoc,
+bool MIRParserImpl::parseMachineInst(PerFunctionMIParsingState &PFS,
+                                     const yaml::MachineInstrLoc &MILoc,
                                      MachineInstr const *&MI) {
-  if (MILoc.BlockNum >= MF.size()) {
-    return error(Twine(MF.getName()) +
-                 Twine(" instruction block out of range.") +
-                 " Unable to reference bb:" + Twine(MILoc.BlockNum));
-  }
-  auto BB = std::next(MF.begin(), MILoc.BlockNum);
+  MachineFunction &MF = PFS.MF;
+  MachineBasicBlock *BB;
+  if (parseMBBReference(PFS, BB, MILoc.Block))
+    return true;
   if (MILoc.Offset >= BB->size())
-    return error(
-        Twine(MF.getName()) + Twine(" instruction offset out of range.") +
-        " Unable to reference instruction at bb: " + Twine(MILoc.BlockNum) +
-        " at offset:" + Twine(MILoc.Offset));
+    return error(Twine(MF.getName()) +
+                 Twine(" instruction offset out of range.") +
+                 " Unable to reference instruction at " + MILoc.Block.Value +
+                 " at offset:" + Twine(MILoc.Offset));
   MI = &*std::next(BB->instr_begin(), MILoc.Offset);
   return false;
 }
@@ -506,15 +505,15 @@ bool MIRParserImpl::initializeCallSiteInfo(
   SMDiagnostic Error;
   const TargetMachine &TM = MF.getTarget();
   for (auto &YamlCSInfo : YamlMF.CallSitesInfo) {
-    yaml::MachineInstrLoc MILoc = YamlCSInfo.CallLocation;
+    const yaml::MachineInstrLoc &MILoc = YamlCSInfo.CallLocation;
     const MachineInstr *CallI;
-    if (parseMachineInst(MF, MILoc, CallI))
+    if (parseMachineInst(PFS, MILoc, CallI))
       return true;
     if (!CallI->isCall(MachineInstr::IgnoreBundle))
       return error(Twine(MF.getName()) +
                    Twine(" call site info should reference call "
-                         "instruction. Instruction at bb:") +
-                   Twine(MILoc.BlockNum) + " at offset:" + Twine(MILoc.Offset) +
+                         "instruction. Instruction at ") +
+                   MILoc.Block.Value + " at offset:" + Twine(MILoc.Offset) +
                    " is not a call instruction");
     MachineFunction::CallSiteInfo CSInfo;
     for (auto ArgRegPair : YamlCSInfo.ArgForwardingRegs) {
@@ -1275,15 +1274,15 @@ bool MIRParserImpl::parseCalledGlobals(PerFunctionMIParsingState &PFS,
                                        const yaml::MachineFunction &YMF) {
   Function &F = MF.getFunction();
   for (const auto &YamlCG : YMF.CalledGlobals) {
-    yaml::MachineInstrLoc MILoc = YamlCG.CallSite;
+    const yaml::MachineInstrLoc &MILoc = YamlCG.CallSite;
     const MachineInstr *CallI;
-    if (parseMachineInst(MF, MILoc, CallI))
+    if (parseMachineInst(PFS, MILoc, CallI))
       return true;
     if (!CallI->isCall(MachineInstr::IgnoreBundle))
       return error(Twine(MF.getName()) +
                    Twine(" called global should reference call "
-                         "instruction. Instruction at bb:") +
-                   Twine(MILoc.BlockNum) + " at offset:" + Twine(MILoc.Offset) +
+                         "instruction. Instruction at ") +
+                   MILoc.Block.Value + " at offset:" + Twine(MILoc.Offset) +
                    " is not a call instruction");
 
     auto Callee =
diff --git a/llvm/lib/CodeGen/MIRPrinter.cpp b/llvm/lib/CodeGen/MIRPrinter.cpp
index 7ac0c40dfd93fb..7e7c13fa58e333 100644
--- a/llvm/lib/CodeGen/MIRPrinter.cpp
+++ b/llvm/lib/CodeGen/MIRPrinter.cpp
@@ -560,16 +560,19 @@ static void convertCallSiteObjects(yaml::MachineFunction &YMF,
                                    const MachineFunction &MF,
                                    ModuleSlotTracker &MST) {
   const auto *TRI = MF.getSubtarget().getRegisterInfo();
+  // Each entry with the number of its block and its offset, for sorting.
+  SmallVector<std::pair<std::pair<int, unsigned>, yaml::CallSiteInfo>> Entries;
   for (auto [MI, CallSiteInfo] : MF.getCallSitesInfo()) {
     yaml::CallSiteInfo YmlCS;
     yaml::MachineInstrLoc CallLocation;
 
     // Prepare instruction position.
     MachineBasicBlock::const_instr_iterator CallI = MI->getIterator();
-    CallLocation.BlockNum = CallI->getParent()->getNumber();
+    const MachineBasicBlock &MBB = *CallI->getParent();
+    raw_string_ostream StrOS(CallLocation.Block.Value);
+    StrOS << printMBBReference(MBB);
     // Get call instruction offset from the beginning of block.
-    CallLocation.Offset =
-        std::distance(CallI->getParent()->instr_begin(), CallI);
+    CallLocation.Offset = std::distance(MBB.instr_begin(), CallI);
     YmlCS.CallLocation = CallLocation;
 
     auto [ArgRegPairs, CalleeTypeIds, _] = CallSiteInfo;
@@ -584,15 +587,14 @@ static void convertCallSiteObjects(yaml::MachineFunction &YMF,
     for (auto *CalleeTypeId : CalleeTypeIds) {
       YmlCS.CalleeTypeIds.push_back(CalleeTypeId->getZExtValue());
     }
-    YMF.CallSitesInfo.push_back(std::move(YmlCS));
+    Entries.push_back(
+        {{MBB.getNumber(), CallLocation.Offset}, std::move(YmlCS)});
   }
 
   // Sort call info by position of call instructions.
-  llvm::sort(YMF.CallSitesInfo.begin(), YMF.CallSitesInfo.end(),
-             [](yaml::CallSiteInfo A, yaml::CallSiteInfo B) {
-               return std::tie(A.CallLocation.BlockNum, A.CallLocation.Offset) <
-                      std::tie(B.CallLocation.BlockNum, B.CallLocation.Offset);
-             });
+  llvm::sort(Entries.begin(), Entries.end(), llvm::less_first());
+  for (auto &Entry : Entries)
+    YMF.CallSitesInfo.push_back(std::move(Entry.second));
 }
 
 static void convertMachineMetadataNodes(yaml::MachineFunction &YMF,
@@ -611,23 +613,24 @@ static void convertMachineMetadataNodes(yaml::MachineFunction &YMF,
 static void convertCalledGlobals(yaml::MachineFunction &YMF,
                                  const MachineFunction &MF,
                                  MachineModuleSlotTracker &MST) {
+  // Each entry with the number of its block and its offset, for sorting.
+  SmallVector<std::pair<std::pair<int, unsigned>, yaml::CalledGlobal>> Entries;
   for (const auto &[CallInst, CG] : MF.getCalledGlobals()) {
+    const MachineBasicBlock &MBB = *CallInst->getParent();
     yaml::MachineInstrLoc CallSite;
-    CallSite.BlockNum = CallInst->getParent()->getNumber();
-    CallSite.Offset = std::distance(CallInst->getParent()->instr_begin(),
-                                    CallInst->getIterator());
+    raw_string_ostream StrOS(CallSite.Block.Value);
+    StrOS << printMBBReference(MBB);
+    CallSite.Offset = std::distance(MBB.instr_begin(), CallInst->getIterator());
 
     yaml::CalledGlobal YamlCG{CallSite, CG.Callee->getName().str(),
                               CG.TargetFlags};
-    YMF.CalledGlobals.push_back(std::move(YamlCG));
+    Entries.push_back({{MBB.getNumber(), CallSite.Offset}, std::move(YamlCG)});
   }
 
   // Sort by position of call instructions.
-  llvm::sort(YMF.CalledGlobals.begin(), YMF.CalledGlobals.end(),
-             [](yaml::CalledGlobal A, yaml::CalledGlobal B) {
-               return std::tie(A.CallSite.BlockNum, A.CallSite.Offset) <
-                      std::tie(B.CallSite.BlockNum, B.CallSite.Offset);
-             });
+  llvm::sort(Entries.begin(), Entries.end(), llvm::less_first());
+  for (auto &Entry : Entries)
+    YMF.CalledGlobals.push_back(std::move(Entry.second));
 }
 
 static void convertPrefetchTargets(yaml::MachineFunction &YMF,
diff --git a/llvm/test/CodeGen/AArch64/calleetypeid-directcall-mismatched.ll b/llvm/test/CodeGen/AArch64/calleetypeid-directcall-mismatched.ll
index 7aae1783de2cbf..fa793af8607a4c 100644
--- a/llvm/test/CodeGen/AArch64/calleetypeid-directcall-mismatched.ll
+++ b/llvm/test/CodeGen/AArch64/calleetypeid-directcall-mismatched.ll
@@ -4,9 +4,9 @@
 
 ;; Test that `calleeTypeIds` field is not present in `callSites`
 ; CHECK-LABEL: callSites:
-; CHECK-NEXT: - { bb: {{[0-9]+}}, offset: {{[0-9]+}}, fwdArgRegs: [] }
-; CHECK-NEXT: - { bb: {{[0-9]+}}, offset: {{[0-9]+}}, fwdArgRegs: [] }
-; CHECK-NEXT: - { bb: {{[0-9]+}}, offset: {{[0-9]+}}, fwdArgRegs: [] }
+; CHECK-NEXT: - { bb: '%bb.{{[0-9]+}}', offset: {{[0-9]+}}, fwdArgRegs: [] }
+; CHECK-NEXT: - { bb: '%bb.{{[0-9]+}}', offset: {{[0-9]+}}, fwdArgRegs: [] }
+; CHECK-NEXT: - { bb: '%bb.{{[0-9]+}}', offset: {{[0-9]+}}, fwdArgRegs: [] }
 define i32 @foo(i32 %x, i32 %y) !callgraph !0 {
 entry:
   ;; Call instruction with accurate callee_type.
diff --git a/llvm/test/CodeGen/AArch64/expand-blr-rvmarker-pseudo.mir b/llvm/test/CodeGen/AArch64/expand-blr-rvmarker-pseudo.mir
index ee874905aa904b..3681dfbef106f6 100644
--- a/llvm/test/CodeGen/AArch64/expand-blr-rvmarker-pseudo.mir
+++ b/llvm/test/CodeGen/AArch64/expand-blr-rvmarker-pseudo.mir
@@ -53,7 +53,7 @@
 #
 name: test_1_callsite_info
 callSites:
-  - {bb: 0, offset: 0, fwdArgRegs:
+  - {bb: '%bb.0', offset: 0, fwdArgRegs:
     - { arg: 0, reg: '$x0' } }
 body:             |
     bb.0:
@@ -179,7 +179,7 @@ body:             |
 #
 name: test_no_nop
 callSites:
-  - {bb: 0, offset: 0, fwdArgRegs:
+  - {bb: '%bb.0', offset: 0, fwdArgRegs:
     - { arg: 0, reg: '$x0' } }
 body:             |
     bb.0:
diff --git a/llvm/test/CodeGen/ARM/calleetypeid-directcall-mismatched.ll b/llvm/test/CodeGen/ARM/calleetypeid-directcall-mismatched.ll
index 6a474227e2b427..d169ec40419c69 100644
--- a/llvm/test/CodeGen/ARM/calleetypeid-directcall-mismatched.ll
+++ b/llvm/test/CodeGen/ARM/calleetypeid-directcall-mismatched.ll
@@ -4,9 +4,9 @@
 
 ;; Test that `calleeTypeIds` field is not present in `callSites`
 ; CHECK-LABEL: callSites:
-; CHECK-NEXT: - { bb: {{[0-9]+}}, offset: {{[0-9]+}}, fwdArgRegs: [] }
-; CHECK-NEXT: - { bb: {{[0-9]+}}, offset: {{[0-9]+}}, fwdArgRegs: [] }
-; CHECK-NEXT: - { bb: {{[0-9]+}}, offset: {{[0-9]+}}, fwdArgRegs: [] }
+; CHECK-NEXT: - { bb: '%bb.{{[0-9]+}}', offset: {{[0-9]+}}, fwdArgRegs: [] }
+; CHECK-NEXT: - { bb: '%bb.{{[0-9]+}}', offset: {{[0-9]+}}, fwdArgRegs: [] }
+; CHECK-NEXT: - { bb: '%bb.{{[0-9]+}}', offset: {{[0-9]+}}, fwdArgRegs: [] }
 define i32 @foo(i32 %x, i32 %y) !callgraph !0 {
 entry:
   ;; Call instruction with accurate callee_type.
diff --git a/llvm/test/CodeGen/MIR/AArch64/called-globals.mir b/llvm/test/CodeGen/MIR/AArch64/called-globals.mir
index cf0f0a23e2d910..10fffb574c52b8 100644
--- a/llvm/test/CodeGen/MIR/AArch64/called-globals.mir
+++ b/llvm/test/CodeGen/MIR/AArch64/called-globals.mir
@@ -20,11 +20,11 @@ stack:
       stack-id: default, callee-saved-register: '$x19', callee-saved-restored: true,
       debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
 calledGlobals:
-  - bb:              0
+  - bb:              '%bb.0'
     offset:          7
     callee:          callee_func
     flags:           144
-  - bb:              0
+  - bb:              '%bb.0'
     offset:          8
     callee:          callee_func
     flags:           144
@@ -51,11 +51,11 @@ body:             |
 ...
 
 # CHECK-LABEL: calledGlobals:
-# CHECK-NEXT:  - bb:              0
+# CHECK-NEXT:  - bb:              '%bb.0'
 # CHECK-NEXT:    offset:          7
 # CHECK-NEXT:    callee:          callee_func
 # CHECK-NEXT:    flags:           144
-# CHECK-NEXT:  - bb:              0
+# CHECK-NEXT:  - bb:              '%bb.0'
 # CHECK-NEXT:    offset:          8
 # CHECK-NEXT:    callee:          callee_func
 # CHECK-NEXT:    flags:           144
diff --git a/llvm/test/CodeGen/MIR/Hexagon/bundled-call-site-info.mir b/llvm/test/CodeGen/MIR/Hexagon/bundled-call-site-info.mir
index 3c018713913a9f..4f142f03a5bfe8 100644
--- a/llvm/test/CodeGen/MIR/Hexagon/bundled-call-site-info.mir
+++ b/llvm/test/CodeGen/MIR/Hexagon/bundled-call-site-info.mir
@@ -8,7 +8,7 @@
 
 # CHECK: name: caller
 # CHECK: callSites:
-# CHECK-NEXT: bb: 0, offset: 3, fwdArgRegs:
+# CHECK-NEXT: bb: '%bb.0', offset: 3, fwdArgRegs:
 # CHECK-NEXT:   arg: 0, reg: '$r0'
 
 # XXX: Please note that at the time of creating this test the Hexagon target
@@ -32,7 +32,7 @@
 name:            caller
 tracksRegLiveness: true
 callSites:
-  - { bb: 0, offset: 3, fwdArgRegs:
+  - { bb: '%bb.0', offset: 3, fwdArgRegs:
       - { arg: 0, reg: '$r0' } }
 body:             |
   bb.0.entry:
diff --git a/llvm/test/CodeGen/MIR/X86/call-site-info-ambiguous-indirect-call-typeid.mir b/llvm/test/CodeGen/MIR/X86/call-site-info-ambiguous-indirect-call-typeid.mir
index 5573be87fbb2d1..8a9e4eaf995a72 100644
--- a/llvm/test/CodeGen/MIR/X86/call-site-info-ambiguous-indirect-call-typeid.mir
+++ b/llvm/test/CodeGen/MIR/X86/call-site-info-ambiguous-indirect-call-typeid.mir
@@ -22,7 +22,7 @@
 ---
 name:            ambiguous_caller
 callSites:
-  - { bb: 0, offset: 1, fwdArgRegs: [], calleeTypeIds: [ 1234, 5678 ] }
+  - { bb: '%bb.0', offset: 1, fwdArgRegs: [], calleeTypeIds: [ 1234, 5678 ] }
 body:             |
   bb.0.entry:
     %0:gr64 = MOV32ri64 4
diff --git a/llvm/test/CodeGen/MIR/X86/call-site-info-block-numbers.mir b/llvm/test/CodeGen/MIR/X86/call-site-info-block-numbers.mir
new file mode 100644
index 00000000000000..dcd82486b0f16b
--- /dev/null
+++ b/llvm/test/CodeGen/MIR/X86/call-site-info-block-numbers.mir
@@ -0,0 +1,48 @@
+# RUN: llc -mtriple=x86_64 -emit-call-site-info -run-pass=none %s -o - | FileCheck %s
+
+# The bb field of callSites and calledGlobals is a block number, which need not
+# match the position of the block in the function. The parser renumbers the
+# blocks in layout order, so the entries for bb.2 come out as bb.1.
+
+# CHECK:      callSites:
+# CHECK-NEXT:   - { bb: '%bb.1', offset: 0, fwdArgRegs:
+# CHECK-NEXT:       - { arg: 0, reg: '$edi' } }
+# CHECK-NEXT:   - { bb: '%bb.2', offset: 0, fwdArgRegs:
+# CHECK-NEXT:       - { arg: 0, reg: '$esi' } }
+# CHECK:      calledGlobals:
+# CHECK-NEXT:   - bb: '%bb.1'
+# CHECK-NEXT:     offset: 0
+# CHECK-NEXT:     callee: foo
+# CHECK:        - bb: '%bb.2'
+# CHECK-NEXT:     offset: 0
+# CHECK-NEXT:     callee: bar
+
+--- |
+  declare void @foo()
+  declare void @bar()
+  define void @caller() { ret void }
+...
+---
+name: caller
+callSites:
+  - { bb: '%bb.2', offset: 0, fwdArgRegs: [ { arg: 0, reg: '$edi' } ] }
+  - { bb: '%bb.1', offset: 0, fwdArgRegs: [ { arg: 0, reg: '$esi' } ] }
+calledGlobals:
+  - { bb: '%bb.2', offset: 0, callee: foo, flags: 0 }
+  - { bb: '%bb.1', offset: 0, callee: bar, flags: 0 }
+body: |
+  bb.0:
+    liveins: $rdi, $eflags
+    JCC_1 %bb.1, 4, implicit $eflags
+    JMP_1 %bb.2
+
+  bb.2:
+    liveins: $rdi
+    CALL64r $rdi, csr_64, implicit $rsp, implicit $ssp, implicit-def $rsp, implicit-def $ssp
+    RET64
+
+  bb.1:
+    liveins: $rdi
+    CALL64r $rdi, csr_64, implicit $rsp, implicit $ssp, implicit-def $rsp, implicit-def $ssp
+    RET64
+...
diff --git a/llvm/test/CodeGen/MIR/X86/call-site-info-direct-calls-typeid.mir b/llvm/test/CodeGen/MIR/X86/call-site-info-direct-calls-typeid.mir
index faa021c1700237..ba9b1c610e8535 100644
--- a/llvm/test/CodeGen/MIR/X86/call-site-info-direct-calls-typeid.mir
+++ b/llvm/test/CodeGen/MIR/X86/call-site-info-direct-calls-typeid.mir
@@ -35,8 +35,8 @@
 ---
 name:            bar
 callSites:
-  - { bb: 0, offset: 0, fwdArgRegs: [] }
-  - { bb: 0, offset: 1, fwdArgRegs: [] }
+  - { bb: '%bb.0', offset: 0, fwdArgRegs: [] }
+  - { bb: '%bb.0', offset: 1, fwdArgRegs: [] }
 body:             |
   bb.0.entry:
     CALL64pcrel32 target-flags(x86-plt) @buzz, csr_64, implicit $rsp, implicit $ssp, implicit $edi, implicit $esi, implicit-def $rsp, implicit-def $ssp, implicit-def $eax
@@ -46,7 +46,7 @@ body:             |
 ---
 name:            foo
 callSites:
-  - { bb: 0, offset: 0, fwdArgRegs: [] }
+  - { bb: '%bb.0', offset: 0, fwdArgRegs: [] }
 body:             |
   bb.0.entry:
     CALL64pcrel32 target-flags(x86-plt) @bar, csr_64, implicit $rsp, implicit $ssp, implicit $edi, implicit $esi, implicit-def $rsp, implicit-def $ssp, implicit-def $eax
diff --git a/llvm/test/CodeGen/MIR/X86/call-site-info-error1.mir b/llvm/test/CodeGen/MIR/X86/call-site-info-error1.mir
index e4dab779216a88..0b94c3c7345894 100644
--- a/llvm/test/CodeGen/MIR/X86/call-site-info-error1.mir
+++ b/llvm/test/CodeGen/MIR/X86/call-site-info-error1.mir
@@ -1,5 +1,5 @@
 # RUN: not llc -mtriple=x86_64-- -run-pass none -debug-entry-values %s -o - 2>&1 | FileCheck %s
-# CHECK: baa instruction block out of range. Unable to reference bb:1
+# CHECK: use of undefined machine basic block #1
 --- |
   define dso_local i32 @baa(i32 %a) local_unnamed_addr {
   entry:
@@ -12,7 +12,7 @@
 ---
 name: baa
 callSites:
-  - {bb: 1, offset: 0, fwdArgRegs:
+  - {bb: '%bb.1', offset: 0, fwdArgRegs:
     - { arg: 0, reg: '$edi' } }
 body: |
   bb.0:
diff --git a/llvm/test/CodeGen/MIR/X86/call-site-info-error2.mir b/llvm/test/CodeGen/MIR/X86/call-site-info-error2.mir
index 183610b326eeb4..b19693001b1c8e 100644
--- a/llvm/test/CodeGen/MIR/X86/call-site-info-error2.mir
+++ b/llvm/test/CodeGen/MIR/X86/call-site-info-error2.mir
@@ -1,5 +1,5 @@
 # RUN: not llc -mtriple=x86_64-- -run-pass non...
[truncated]

``````````

</details>


https://github.com/llvm/llvm-project/pull/229320


More information about the llvm-commits mailing list