[CodeGen] Print constant pool index operands as %const.0 + 8 in both MIR and debug output
Work towards the unification of MIR and debug output by printing
`%const.0 + 8` instead of `<cp#0+8>` and `%const.0 - 8` instead of
`<cp#0-8>`.
Only debug syntax is affected.
Differential Revision: https://reviews.llvm.org/D41116
llvm-svn: 320564
diff --git a/llvm/unittests/CodeGen/MachineOperandTest.cpp b/llvm/unittests/CodeGen/MachineOperandTest.cpp
index 24a7f55..c21bff6 100644
--- a/llvm/unittests/CodeGen/MachineOperandTest.cpp
+++ b/llvm/unittests/CodeGen/MachineOperandTest.cpp
@@ -119,4 +119,36 @@
ASSERT_TRUE(OS.str() == "%subreg.3");
}
+TEST(MachineOperandTest, PrintCPI) {
+ // Create a MachineOperand with a constant pool index and print it.
+ MachineOperand MO = MachineOperand::CreateCPI(0, 8);
+
+ // Checking some preconditions on the newly created
+ // MachineOperand.
+ ASSERT_TRUE(MO.isCPI());
+ ASSERT_TRUE(MO.getIndex() == 0);
+ ASSERT_TRUE(MO.getOffset() == 8);
+
+ // Print a MachineOperand containing a constant pool index and a positive
+ // offset.
+ std::string str;
+ {
+ raw_string_ostream OS(str);
+ MO.print(OS, /*TRI=*/nullptr, /*IntrinsicInfo=*/nullptr);
+ ASSERT_TRUE(OS.str() == "%const.0 + 8");
+ }
+
+ str.clear();
+
+ MO.setOffset(-12);
+
+ // Print a MachineOperand containing a constant pool index and a negative
+ // offset.
+ {
+ raw_string_ostream OS(str);
+ MO.print(OS, /*TRI=*/nullptr, /*IntrinsicInfo=*/nullptr);
+ ASSERT_TRUE(OS.str() == "%const.0 - 12");
+ }
+}
+
} // end namespace