[CodeGen] Print external symbols as $symbol in both MIR and debug output

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
This commit is contained in:
Francis Visoiu Mistrih 2017-12-14 10:02:58 +00:00
parent 367e62b539
commit d398775f54
8 changed files with 71 additions and 24 deletions

View 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.

View 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());

View 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);

View 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

View 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

View 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] }

View 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:

View 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