Index: llvm/lib/CodeGen/MIRParser/MIRParser.cpp =================================================================== --- llvm/lib/CodeGen/MIRParser/MIRParser.cpp +++ llvm/lib/CodeGen/MIRParser/MIRParser.cpp @@ -368,22 +368,27 @@ const LLVMTargetMachine &TM = MF.getTarget(); for (auto YamlCSInfo : YamlMF.CallSitesInfo) { yaml::CallSiteInfo::MachineInstrLoc MILoc = YamlCSInfo.CallLocation; - if (MILoc.BlockNum >= MF.size()) + unsigned BlockNum = MILoc.BlockNum; + // In case of using GlobalISel, entry block enumeration doesn't start + // from 0, but from 1. + if (YamlMF.Body.Value.Value.find("bb.0") == std::string::npos) + BlockNum -= 1; + if (BlockNum >= MF.size()) return error(Twine(MF.getName()) + Twine(" call instruction block out of range.") + - " Unable to reference bb:" + Twine(MILoc.BlockNum)); - auto CallB = std::next(MF.begin(), MILoc.BlockNum); + " Unable to reference bb:" + Twine(BlockNum)); + auto CallB = std::next(MF.begin(), BlockNum); if (MILoc.Offset >= CallB->size()) return error(Twine(MF.getName()) + Twine(" call instruction offset out of range.") + " Unable to reference instruction at bb: " + - Twine(MILoc.BlockNum) + " at offset:" + Twine(MILoc.Offset)); + Twine(BlockNum) + " at offset:" + Twine(MILoc.Offset)); auto CallI = std::next(CallB->instr_begin(), MILoc.Offset); 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) + + Twine(BlockNum) + " at offset:" + Twine(MILoc.Offset) + " is not a call instruction"); MachineFunction::CallSiteInfo CSInfo; for (auto ArgRegPair : YamlCSInfo.ArgForwardingRegs) { Index: llvm/test/CodeGen/X86/globalisel-entry-block-enumeration.ll =================================================================== --- /dev/null +++ llvm/test/CodeGen/X86/globalisel-entry-block-enumeration.ll @@ -0,0 +1,39 @@ +;; Test enumeration of entry basic blocks when using GlobalISel. +;; When using other instruction selectors entry blocks will start +;; from 0, in case of GlobalISel they start from 1. +; RUN: llc -emit-call-site-info -global-isel %s -stop-after=finalize-isel -o %t.mir +; RUN: cat %t.mir | FileCheck %s +; CHECK: name: fn1 +; CHECK-NOT: bb.0.entry +; CHECK: name: fn3 +; CHECK-NOT: bb.0.entry +; CHECK: name: fn2 +; CHECK-NOT: bb.0.entry + +; Function Attrs: noinline nounwind uwtable +define dso_local i32 @fn1(i32 %a) local_unnamed_addr { +entry: + %c = add i32 %a, 2 + ret i32 %c +} + +; Function Attrs: noinline nounwind uwtable +define dso_local i32 @fn3(i32 %a, i32 %b, i32 %c) local_unnamed_addr { +entry: + %d = add i32 %a, %b + %e = mul i32 %d, %c + %f = call i32 @fn1(i32 %e) + ret i32 %f +} + +; Function Attrs: noinline nounwind uwtable +define dso_local i64 @fn2(i32 %a, i32 %b, i32 %c) local_unnamed_addr { +entry: + %call = call i32 @fn1(i32 5) + %add = mul i32 %a, 3 + %sub = sub i32 %add, %b + %add2 = add i32 %sub, %c + %conv4 = sext i32 %add2 to i64 + %call2 = call i32 @fn3(i32 5, i32 %add2, i32 %add2) + ret i64 %conv4 +}