llvm.org GIT mirror llvm / d398775
[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 Francis Visoiu Mistrih 2 years ago
8 changed file(s) with 72 addition(s) and 25 deletion(s). Raw diff Collapse all Expand all
664664 - id: 1
665665 blocks: [ '%bb.7', '%bb.7', '%bb.4.d3', '%bb.5' ]
666666
667 External Symbol Operands
668 ^^^^^^^^^^^^^^^^^^^^^^^^^
669
670 An external symbol operand is represented using an identifier with the ``$``
671 prefix. The identifier is surrounded with ""'s and escaped if it has any
672 special non-printable characters in it.
673
674 Example:
675
676 .. code-block:: text
677
678 CALL64pcrel32 $__stack_chk_fail, csr_64, implicit %rsp, implicit-def %rsp
679
680
667681 .. TODO: Describe the parsers default behaviour when optional YAML attributes
668682 are missing.
669683 .. TODO: Describe the syntax for the bundled instructions.
670684 .. TODO: Describe the syntax for virtual register YAML definitions.
671685 .. TODO: Describe the machine function's YAML flag attributes.
672 .. TODO: Describe the syntax for the external symbol and register
673 mask machine operands.
686 .. TODO: Describe the syntax for the register mask machine operands.
674687 .. TODO: Describe the frame information YAML mapping.
675688 .. TODO: Describe the syntax of the stack object machine operands and their
676689 YAML definitions.
852852 case MachineOperand::MO_MachineBasicBlock:
853853 case MachineOperand::MO_ConstantPoolIndex:
854854 case MachineOperand::MO_TargetIndex:
855 case MachineOperand::MO_JumpTableIndex: {
855 case MachineOperand::MO_JumpTableIndex:
856 case MachineOperand::MO_ExternalSymbol: {
856857 unsigned TiedOperandIdx = 0;
857858 if (ShouldPrintRegisterTies && Op.isReg() && Op.isTied() && !Op.isDef())
858859 TiedOperandIdx = Op.getParent()->findTiedOperandIdx(OpIdx);
867868 case MachineOperand::MO_FrameIndex:
868869 printStackObjectReference(Op.getIndex());
869870 break;
870 case MachineOperand::MO_ExternalSymbol: {
871 StringRef Name = Op.getSymbolName();
872 OS << '$';
873 if (Name.empty()) {
874 OS << "\"\"";
875 } else {
876 printLLVMNameWithoutPrefix(OS, Name);
877 }
878 printOffset(Op.getOffset());
879 break;
880 }
881871 case MachineOperand::MO_GlobalAddress:
882872 Op.getGlobal()->printAsOperand(OS, /*PrintType=*/false, MST);
883873 printOffset(Op.getOffset());
1818 #include "llvm/CodeGen/TargetInstrInfo.h"
1919 #include "llvm/CodeGen/TargetRegisterInfo.h"
2020 #include "llvm/IR/Constants.h"
21 #include "llvm/IR/IRPrintingPasses.h"
2122 #include "llvm/IR/ModuleSlotTracker.h"
2223 #include "llvm/Target/TargetIntrinsicInfo.h"
2324 #include "llvm/Target/TargetMachine.h"
532533 OS << "+" << getOffset();
533534 OS << '>';
534535 break;
535 case MachineOperand::MO_ExternalSymbol:
536 OS << "
537 if (getOffset())
538 OS << "+" << getOffset();
539 OS << '>';
540 break;
536 case MachineOperand::MO_ExternalSymbol: {
537 StringRef Name = getSymbolName();
538 OS << '$';
539 if (Name.empty()) {
540 OS << "\"\"";
541 } else {
542 printLLVMNameWithoutPrefix(OS, Name);
543 }
544 printOffset(OS, getOffset());
545 break;
546 }
541547 case MachineOperand::MO_BlockAddress:
542548 OS << '<';
543549 getBlockAddress()->printAsOperand(OS, /*PrintType=*/false, MST);
88 ret void
99 }
1010
11 ; CHECK: tBL pred:14, pred:%noreg, , implicit-def %lr, implicit %sp, implicit killed %r4, implicit-def %r4, implicit-def dead %r12, implicit-def dead %cpsr
11 ; 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
1212
77
88 define void @memory_asm_operand(i32 %a) {
99 ; "m" operand will be represented as:
10 ; INLINEASM , 10, %R2, 20, -4, %R1
10 ; INLINEASM fake $0, 10, %R2, 20, -4, %R1
1111 ; It is difficult to find the flag operand (20) when starting from %R1
1212 call i32 asm "lbzx $0, $1", "=r,m" (i32 %a)
1313 ret void
436436 ; inline-asm instruction and the ST register was live across another
437437 ; inline-asm instruction.
438438 ;
439 ; INLINEASM [sideeffect] [attdialect], $0:[regdef], %st0, $1:[reguse tiedto:$0], %st0, $2:[clobber], early-clobber implicit dead %eflags
440 ; INLINEASM [sideeffect] [mayload] [attdialect], $0:[mem], undef %eax, 1, %noreg, 0, %noreg, $1:[clobber], early-clobber implicit dead %eflags
439 ; INLINEASM $frndint [sideeffect] [attdialect], $0:[regdef], %st0, $1:[reguse tiedto:$0], %st0, $2:[clobber], early-clobber implicit dead %eflags
440 ; INLINEASM $fldcw $0 [sideeffect] [mayload] [attdialect], $0:[mem], undef %eax, 1, %noreg, 0, %noreg, $1:[clobber], early-clobber implicit dead %eflags
441441 ; %fp0 = COPY %st0
442442
443443 %struct.fpu_t = type { [8 x x86_fp80], x86_fp80, %struct.anon1, %struct.anon2, i32, i8, [15 x i8] }
55 ; DARWIN-SELDAG: # Machine code for function test_branch_weights:
66 ; DARWIN-SELDAG: Successors according to CFG: %bb.[[SUCCESS:[0-9]+]]({{[0-9a-fx/= ]+}}100.00%) %bb.[[FAILURE:[0-9]+]]
77 ; DARWIN-SELDAG: %bb.[[FAILURE]]:
8 ; DARWIN-SELDAG: CALL64pcrel32
8 ; DARWIN-SELDAG: CALL64pcrel32 $__stack_chk_fail
99 ; DARWIN-SELDAG: %bb.[[SUCCESS]]:
1010
1111 ; DARWIN-IR: # Machine code for function test_branch_weights:
196196 ASSERT_TRUE(OS.str() == "%jump-table.3");
197197 }
198198
199 TEST(MachineOperandTest, PrintExternalSymbol) {
200 // Create a MachineOperand with an external symbol and print it.
201 MachineOperand MO = MachineOperand::CreateES("foo");
202
203 // Checking some preconditions on the newly created
204 // MachineOperand.
205 ASSERT_TRUE(MO.isSymbol());
206 ASSERT_TRUE(MO.getSymbolName() == StringRef("foo"));
207
208 // Print a MachineOperand containing an external symbol and no offset.
209 std::string str;
210 {
211 raw_string_ostream OS(str);
212 MO.print(OS, /*TRI=*/nullptr, /*IntrinsicInfo=*/nullptr);
213 ASSERT_TRUE(OS.str() == "$foo");
214 }
215
216 str.clear();
217 MO.setOffset(12);
218
219 // Print a MachineOperand containing an external symbol and a positive offset.
220 {
221 raw_string_ostream OS(str);
222 MO.print(OS, /*TRI=*/nullptr, /*IntrinsicInfo=*/nullptr);
223 ASSERT_TRUE(OS.str() == "$foo + 12");
224 }
225
226 str.clear();
227 MO.setOffset(-12);
228
229 // Print a MachineOperand containing an external symbol and a negative offset.
230 {
231 raw_string_ostream OS(str);
232 MO.print(OS, /*TRI=*/nullptr, /*IntrinsicInfo=*/nullptr);
233 ASSERT_TRUE(OS.str() == "$foo - 12");
234 }
235 }
236
199237 } // end namespace