]> granicus.if.org Git - llvm/commitdiff
[CodeGen] Move printing MO_CImmediate operands to MachineOperand::print
authorFrancis Visoiu Mistrih <francisvm@yahoo.com>
Fri, 8 Dec 2017 11:40:06 +0000 (11:40 +0000)
committerFrancis Visoiu Mistrih <francisvm@yahoo.com>
Fri, 8 Dec 2017 11:40:06 +0000 (11:40 +0000)
Work towards the unification of MIR and debug output by refactoring the
interfaces.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320140 91177308-0d34-0410-b5e6-96231b3b80d8

docs/MIRLangRef.rst
lib/CodeGen/MIRPrinter.cpp
lib/CodeGen/MachineOperand.cpp
unittests/CodeGen/MachineOperandTest.cpp

index fff0d3ef0eb094eed6f3c8744c03ac7ca10a86e8..e217b792e62e9aaf50ff089ece34677b137d18f7 100644 (file)
@@ -430,7 +430,11 @@ immediate machine operand ``-42``:
 
     %eax = MOV32ri -42
 
-.. TODO: Describe the CIMM (Rare) and FPIMM immediate operands.
+For integers > 64bit, we use a special machine operand, ``MO_CImmediate``,
+which stores the immediate in a ``ConstantInt`` using an ``APInt`` (LLVM's
+arbitrary precision integers).
+
+.. TODO: Describe the FPIMM immediate operands.
 
 .. _register-operands:
 
index e8a358e5209cd5ba6b9c9ead35f183f8a3a24e07..b442dab2efb5233a1f6448169d4c97d07e3d7578 100644 (file)
@@ -854,7 +854,8 @@ void MIPrinter::print(const MachineInstr &MI, unsigned OpIdx,
   const MachineOperand &Op = MI.getOperand(OpIdx);
   printTargetFlags(Op);
   switch (Op.getType()) {
-  case MachineOperand::MO_Register: {
+  case MachineOperand::MO_Register:
+  case MachineOperand::MO_CImmediate: {
     unsigned TiedOperandIdx = 0;
     if (ShouldPrintRegisterTies && Op.isTied() && !Op.isDef())
       TiedOperandIdx = Op.getParent()->findTiedOperandIdx(OpIdx);
@@ -869,9 +870,6 @@ void MIPrinter::print(const MachineInstr &MI, unsigned OpIdx,
     else
       OS << Op.getImm();
     break;
-  case MachineOperand::MO_CImmediate:
-    Op.getCImm()->printAsOperand(OS, /*PrintType=*/true, MST);
-    break;
   case MachineOperand::MO_FPImmediate:
     Op.getFPImm()->printAsOperand(OS, /*PrintType=*/true, MST);
     break;
index 85b441c40ab2ac155f9de8b7998debeddb607150..0cbcb65a99a27bbb243dbc75d8c620145c5137f2 100644 (file)
@@ -410,7 +410,7 @@ void MachineOperand::print(raw_ostream &OS, ModuleSlotTracker &MST,
     OS << getImm();
     break;
   case MachineOperand::MO_CImmediate:
-    getCImm()->getValue().print(OS, false);
+    getCImm()->printAsOperand(OS, /*PrintType=*/true, MST);
     break;
   case MachineOperand::MO_FPImmediate:
     if (getFPImm()->getType()->isFloatTy()) {
index 5926b6767ff048d247d63177c506a29d56b04b41..4884d374521af78e579736fc27d116edc9b36f78 100644 (file)
@@ -9,6 +9,8 @@
 
 #include "llvm/ADT/ilist_node.h"
 #include "llvm/CodeGen/MachineOperand.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/LLVMContext.h"
 #include "llvm/Support/raw_ostream.h"
 #include "gtest/gtest.h"
 
@@ -76,4 +78,26 @@ TEST(MachineOperandTest, PrintSubReg) {
   ASSERT_TRUE(OS.str() == "%physreg1.subreg5");
 }
 
+TEST(MachineOperandTest, PrintCImm) {
+  LLVMContext Context;
+  APInt Int(128, UINT64_MAX);
+  ++Int;
+  ConstantInt *CImm = ConstantInt::get(Context, Int);
+  // Create a MachineOperand with an Imm=(UINT64_MAX + 1)
+  MachineOperand MO = MachineOperand::CreateCImm(CImm);
+
+  // Checking some preconditions on the newly created
+  // MachineOperand.
+  ASSERT_TRUE(MO.isCImm());
+  ASSERT_TRUE(MO.getCImm() == CImm);
+  ASSERT_TRUE(MO.getCImm()->getValue() == Int);
+
+  // Print a MachineOperand containing a SubReg. Here we check that without a
+  // TRI and IntrinsicInfo we can still print the subreg index.
+  std::string str;
+  raw_string_ostream OS(str);
+  MO.print(OS, /*TRI=*/nullptr, /*IntrinsicInfo=*/nullptr);
+  ASSERT_TRUE(OS.str() == "i128 18446744073709551616");
+}
+
 } // end namespace