diff --git a/docs/MIRLangRef.rst b/docs/MIRLangRef.rst index ebc9d456703..14ac63bbd9d 100644 --- a/docs/MIRLangRef.rst +++ b/docs/MIRLangRef.rst @@ -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. diff --git a/lib/CodeGen/MIRPrinter.cpp b/lib/CodeGen/MIRPrinter.cpp index 505b7c3b6c7..053ab607976 100644 --- a/lib/CodeGen/MIRPrinter.cpp +++ b/lib/CodeGen/MIRPrinter.cpp @@ -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()); diff --git a/lib/CodeGen/MachineOperand.cpp b/lib/CodeGen/MachineOperand.cpp index 82e635d9c62..6882e9ff700 100644 --- a/lib/CodeGen/MachineOperand.cpp +++ b/lib/CodeGen/MachineOperand.cpp @@ -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 << "'; + 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); diff --git a/test/CodeGen/ARM/Windows/vla-cpsr.ll b/test/CodeGen/ARM/Windows/vla-cpsr.ll index 39527425a76..a6bef8c178f 100644 --- a/test/CodeGen/ARM/Windows/vla-cpsr.ll +++ b/test/CodeGen/ARM/Windows/vla-cpsr.ll @@ -9,5 +9,5 @@ entry: ret void } -; 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 +; 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 diff --git a/test/CodeGen/PowerPC/2009-07-16-InlineAsm-M-Operand.ll b/test/CodeGen/PowerPC/2009-07-16-InlineAsm-M-Operand.ll index 50b35f55f41..76468f63ee7 100644 --- a/test/CodeGen/PowerPC/2009-07-16-InlineAsm-M-Operand.ll +++ b/test/CodeGen/PowerPC/2009-07-16-InlineAsm-M-Operand.ll @@ -8,7 +8,7 @@ define void @memory_asm_operand(i32 %a) { ; "m" operand will be represented as: - ; INLINEASM , 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 diff --git a/test/CodeGen/X86/inline-asm-fpstack.ll b/test/CodeGen/X86/inline-asm-fpstack.ll index c66121e10c7..b6ac8a18b40 100644 --- a/test/CodeGen/X86/inline-asm-fpstack.ll +++ b/test/CodeGen/X86/inline-asm-fpstack.ll @@ -437,8 +437,8 @@ entry: ; inline-asm instruction and the ST register was live across another ; inline-asm instruction. ; -; INLINEASM [sideeffect] [attdialect], $0:[regdef], %st0, $1:[reguse tiedto:$0], %st0, $2:[clobber], early-clobber implicit dead %eflags -; INLINEASM [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, $1:[reguse tiedto:$0], %st0, $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] } diff --git a/test/CodeGen/X86/stack-protector-weight.ll b/test/CodeGen/X86/stack-protector-weight.ll index 3708d216f8d..74050195277 100644 --- a/test/CodeGen/X86/stack-protector-weight.ll +++ b/test/CodeGen/X86/stack-protector-weight.ll @@ -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 +; DARWIN-SELDAG: CALL64pcrel32 $__stack_chk_fail ; DARWIN-SELDAG: %bb.[[SUCCESS]]: ; DARWIN-IR: # Machine code for function test_branch_weights: diff --git a/unittests/CodeGen/MachineOperandTest.cpp b/unittests/CodeGen/MachineOperandTest.cpp index aed60c0a3d6..36897d918b3 100644 --- a/unittests/CodeGen/MachineOperandTest.cpp +++ b/unittests/CodeGen/MachineOperandTest.cpp @@ -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