]> granicus.if.org Git - llvm/commitdiff
[CodeGen] Print external symbols as $symbol in both MIR and debug output
authorFrancis Visoiu Mistrih <francisvm@yahoo.com>
Thu, 14 Dec 2017 10:02:58 +0000 (10:02 +0000)
committerFrancis Visoiu Mistrih <francisvm@yahoo.com>
Thu, 14 Dec 2017 10:02:58 +0000 (10:02 +0000)
Work towards the unification of MIR and debug output by printing
`$symbol` instead of `<es:symbol>`.

Only debug syntax is affected.

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

docs/MIRLangRef.rst
lib/CodeGen/MIRPrinter.cpp
lib/CodeGen/MachineOperand.cpp
test/CodeGen/ARM/Windows/vla-cpsr.ll
test/CodeGen/PowerPC/2009-07-16-InlineAsm-M-Operand.ll
test/CodeGen/X86/inline-asm-fpstack.ll
test/CodeGen/X86/stack-protector-weight.ll
unittests/CodeGen/MachineOperandTest.cpp

index ebc9d456703623efaedc7eaba0e22085e9f7c1b5..14ac63bbd9d2716118f442e6b8e3d73d79fdad52 100644 (file)
@@ -665,13 +665,26 @@ Example:
         - id:             1
           blocks:         [ '%bb.7', '%bb.7', '%bb.4.d3', '%bb.5' ]
 
+External Symbol Operands
+^^^^^^^^^^^^^^^^^^^^^^^^^
+
+An external symbol operand is represented using an identifier with the ``$``
+prefix. The identifier is surrounded with ""'s and escaped if it has any
+special non-printable characters in it.
+
+Example:
+
+.. code-block:: text
+
+    CALL64pcrel32 $__stack_chk_fail, csr_64, implicit %rsp, implicit-def %rsp
+
+
 .. TODO: Describe the parsers default behaviour when optional YAML attributes
    are missing.
 .. TODO: Describe the syntax for the bundled instructions.
 .. TODO: Describe the syntax for virtual register YAML definitions.
 .. TODO: Describe the machine function's YAML flag attributes.
-.. TODO: Describe the syntax for the external symbol and register
-   mask machine operands.
+.. TODO: Describe the syntax for the register mask machine operands.
 .. TODO: Describe the frame information YAML mapping.
 .. TODO: Describe the syntax of the stack object machine operands and their
    YAML definitions.
index 505b7c3b6c78ad25dc4806eb6aec519ba0e0c68f..053ab607976b78e940b4cdfd9c917bb38806ebf9 100644 (file)
@@ -853,7 +853,8 @@ void MIPrinter::print(const MachineInstr &MI, unsigned OpIdx,
   case MachineOperand::MO_MachineBasicBlock:
   case MachineOperand::MO_ConstantPoolIndex:
   case MachineOperand::MO_TargetIndex:
-  case MachineOperand::MO_JumpTableIndex: {
+  case MachineOperand::MO_JumpTableIndex:
+  case MachineOperand::MO_ExternalSymbol: {
     unsigned TiedOperandIdx = 0;
     if (ShouldPrintRegisterTies && Op.isReg() && Op.isTied() && !Op.isDef())
       TiedOperandIdx = Op.getParent()->findTiedOperandIdx(OpIdx);
@@ -868,17 +869,6 @@ void MIPrinter::print(const MachineInstr &MI, unsigned OpIdx,
   case MachineOperand::MO_FrameIndex:
     printStackObjectReference(Op.getIndex());
     break;
-  case MachineOperand::MO_ExternalSymbol: {
-    StringRef Name = Op.getSymbolName();
-    OS << '$';
-    if (Name.empty()) {
-      OS << "\"\"";
-    } else {
-      printLLVMNameWithoutPrefix(OS, Name);
-    }
-    printOffset(Op.getOffset());
-    break;
-  }
   case MachineOperand::MO_GlobalAddress:
     Op.getGlobal()->printAsOperand(OS, /*PrintType=*/false, MST);
     printOffset(Op.getOffset());
index 82e635d9c62f5209799669d7020cfd24af51d837..6882e9ff7005a7c3629f8580f1e99773c26361c5 100644 (file)
@@ -19,6 +19,7 @@
 #include "llvm/CodeGen/TargetInstrInfo.h"
 #include "llvm/CodeGen/TargetRegisterInfo.h"
 #include "llvm/IR/Constants.h"
+#include "llvm/IR/IRPrintingPasses.h"
 #include "llvm/IR/ModuleSlotTracker.h"
 #include "llvm/Target/TargetIntrinsicInfo.h"
 #include "llvm/Target/TargetMachine.h"
@@ -533,12 +534,17 @@ void MachineOperand::print(raw_ostream &OS, ModuleSlotTracker &MST,
       OS << "+" << getOffset();
     OS << '>';
     break;
-  case MachineOperand::MO_ExternalSymbol:
-    OS << "<es:" << getSymbolName();
-    if (getOffset())
-      OS << "+" << getOffset();
-    OS << '>';
+  case MachineOperand::MO_ExternalSymbol: {
+    StringRef Name = getSymbolName();
+    OS << '$';
+    if (Name.empty()) {
+      OS << "\"\"";
+    } else {
+      printLLVMNameWithoutPrefix(OS, Name);
+    }
+    printOffset(OS, getOffset());
     break;
+  }
   case MachineOperand::MO_BlockAddress:
     OS << '<';
     getBlockAddress()->printAsOperand(OS, /*PrintType=*/false, MST);
index 39527425a7645294fb0117d20e69ac6c9891047e..a6bef8c178f82ead7a001d9786a2c7318ef6f93b 100644 (file)
@@ -9,5 +9,5 @@ entry:
   ret void
 }
 
-; CHECK: tBL pred:14, pred:%noreg, <es:__chkstk>, implicit-def %lr, implicit %sp, implicit killed %r4, implicit-def %r4, implicit-def dead %r12, implicit-def dead %cpsr
+; CHECK: tBL pred:14, pred:%noreg, $__chkstk, implicit-def %lr, implicit %sp, implicit killed %r4, implicit-def %r4, implicit-def dead %r12, implicit-def dead %cpsr
 
index 50b35f55f41df4580f5740ea5349aefc1f76d4d4..76468f63ee741cf084bfd44ae4d85583d0dc2b31 100644 (file)
@@ -8,7 +8,7 @@
 
 define void @memory_asm_operand(i32 %a) {
   ; "m" operand will be represented as:
-  ; INLINEASM <es:fake $0>, 10, %R2, 20, -4, %R1
+  ; INLINEASM fake $0, 10, %R2, 20, -4, %R1
   ; It is difficult to find the flag operand (20) when starting from %R1
   call i32 asm "lbzx $0, $1", "=r,m" (i32 %a)
   ret void
index c66121e10c7823bd8624bbb6eac20dae2675ea03..b6ac8a18b40b7ad7d4c548852f49c64eefc894b5 100644 (file)
@@ -437,8 +437,8 @@ entry:
 ; inline-asm instruction and the ST register was live across another
 ; inline-asm instruction.
 ;
-; INLINEASM <es:frndint> [sideeffect] [attdialect], $0:[regdef], %st0<imp-def,tied5>, $1:[reguse tiedto:$0], %st0<tied3>, $2:[clobber], early-clobber implicit dead %eflags
-; INLINEASM <es:fldcw $0> [sideeffect] [mayload] [attdialect], $0:[mem], undef %eax, 1, %noreg, 0, %noreg, $1:[clobber], early-clobber implicit dead %eflags
+; INLINEASM $frndint [sideeffect] [attdialect], $0:[regdef], %st0<imp-def,tied5>, $1:[reguse tiedto:$0], %st0<tied3>, $2:[clobber], early-clobber implicit dead %eflags
+; INLINEASM $fldcw $0 [sideeffect] [mayload] [attdialect], $0:[mem], undef %eax, 1, %noreg, 0, %noreg, $1:[clobber], early-clobber implicit dead %eflags
 ; %fp0 = COPY %st0
 
 %struct.fpu_t = type { [8 x x86_fp80], x86_fp80, %struct.anon1, %struct.anon2, i32, i8, [15 x i8] }
index 3708d216f8df0036f0ae5d897c3abc901a846cab..74050195277a50715e74aaf953af61cc65ee0eca 100644 (file)
@@ -6,7 +6,7 @@
 ; DARWIN-SELDAG: # Machine code for function test_branch_weights:
 ; DARWIN-SELDAG: Successors according to CFG: %bb.[[SUCCESS:[0-9]+]]({{[0-9a-fx/= ]+}}100.00%) %bb.[[FAILURE:[0-9]+]]
 ; DARWIN-SELDAG: %bb.[[FAILURE]]:
-; DARWIN-SELDAG: CALL64pcrel32 <es:__stack_chk_fail>
+; DARWIN-SELDAG: CALL64pcrel32 $__stack_chk_fail
 ; DARWIN-SELDAG: %bb.[[SUCCESS]]:
 
 ; DARWIN-IR: # Machine code for function test_branch_weights:
index aed60c0a3d619bdf2a51cb4da1ca07590f8699e7..36897d918b33f815817d5ffdd5e1231a2a8f0864 100644 (file)
@@ -197,4 +197,42 @@ TEST(MachineOperandTest, PrintJumpTableIndex) {
   ASSERT_TRUE(OS.str() == "%jump-table.3");
 }
 
+TEST(MachineOperandTest, PrintExternalSymbol) {
+  // Create a MachineOperand with an external symbol and print it.
+  MachineOperand MO = MachineOperand::CreateES("foo");
+
+  // Checking some preconditions on the newly created
+  // MachineOperand.
+  ASSERT_TRUE(MO.isSymbol());
+  ASSERT_TRUE(MO.getSymbolName() == StringRef("foo"));
+
+  // Print a MachineOperand containing an external symbol and no offset.
+  std::string str;
+  {
+    raw_string_ostream OS(str);
+    MO.print(OS, /*TRI=*/nullptr, /*IntrinsicInfo=*/nullptr);
+    ASSERT_TRUE(OS.str() == "$foo");
+  }
+
+  str.clear();
+  MO.setOffset(12);
+
+  // Print a MachineOperand containing an external symbol and a positive offset.
+  {
+    raw_string_ostream OS(str);
+    MO.print(OS, /*TRI=*/nullptr, /*IntrinsicInfo=*/nullptr);
+    ASSERT_TRUE(OS.str() == "$foo + 12");
+  }
+
+  str.clear();
+  MO.setOffset(-12);
+
+  // Print a MachineOperand containing an external symbol and a negative offset.
+  {
+    raw_string_ostream OS(str);
+    MO.print(OS, /*TRI=*/nullptr, /*IntrinsicInfo=*/nullptr);
+    ASSERT_TRUE(OS.str() == "$foo - 12");
+  }
+}
+
 } // end namespace