MIR Serialization: Serialize the unnamed basic block references.
This commit serializes the references from the machine basic blocks to the
unnamed basic blocks.
This commit adds a new attribute to the machine basic block's YAML mapping
called 'ir-block'. This attribute contains the actual reference to the
basic block.
Reviewers: Duncan P. N. Exon Smith
llvm-svn: 243340
diff --git a/llvm/lib/CodeGen/MIRPrinter.cpp b/llvm/lib/CodeGen/MIRPrinter.cpp
index 3db6368..cb20df8 100644
--- a/llvm/lib/CodeGen/MIRPrinter.cpp
+++ b/llvm/lib/CodeGen/MIRPrinter.cpp
@@ -163,6 +163,7 @@
convert(YamlMF, *ConstantPool);
ModuleSlotTracker MST(MF.getFunction()->getParent());
+ MST.incorporateFunction(*MF.getFunction());
if (const auto *JumpTableInfo = MF.getJumpTableInfo())
convert(MST, YamlMF.JumpTableInfo, *JumpTableInfo);
int I = 0;
@@ -336,11 +337,17 @@
const MachineBasicBlock &MBB) {
assert(MBB.getNumber() >= 0 && "Invalid MBB number");
YamlMBB.ID = (unsigned)MBB.getNumber();
- // TODO: Serialize unnamed BB references.
- if (const auto *BB = MBB.getBasicBlock())
- YamlMBB.Name.Value = BB->hasName() ? BB->getName() : "<unnamed bb>";
- else
- YamlMBB.Name.Value = "";
+ if (const auto *BB = MBB.getBasicBlock()) {
+ if (BB->hasName()) {
+ YamlMBB.Name.Value = BB->getName();
+ } else {
+ int Slot = MST.getLocalSlot(BB);
+ if (Slot == -1)
+ YamlMBB.IRBlock.Value = "<badref>";
+ else
+ YamlMBB.IRBlock.Value = (Twine("%ir-block.") + Twine(Slot)).str();
+ }
+ }
YamlMBB.Alignment = MBB.getAlignment();
YamlMBB.AddressTaken = MBB.hasAddressTaken();
YamlMBB.IsLandingPad = MBB.isLandingPad();