extractStoreMemRefs(MachineInstr::mmo_iterator Begin,
MachineInstr::mmo_iterator End);
+ /// Allocate a string and populate it with the given external symbol name.
+ const char *createExternalSymbolName(StringRef Name);
+
//===--------------------------------------------------------------------===//
// Label Manipulation.
//
return C;
}
+static Cursor lexName(
+ Cursor C, MIToken &Token, MIToken::TokenKind Type,
+ MIToken::TokenKind QuotedType, unsigned PrefixLength,
+ function_ref<void(StringRef::iterator Loc, const Twine &)> ErrorCallback) {
+ auto Range = C;
+ C.advance(PrefixLength);
+ if (C.peek() == '"') {
+ if (Cursor R = lexStringConstant(C, ErrorCallback)) {
+ Token = MIToken(QuotedType, Range.upto(R), PrefixLength);
+ return R;
+ }
+ Token = MIToken(MIToken::Error, Range.remaining());
+ return Range;
+ }
+ while (isIdentifierChar(C.peek()))
+ C.advance();
+ Token = MIToken(Type, Range.upto(C), PrefixLength);
+ return C;
+}
+
+static Cursor maybeLexExternalSymbol(
+ Cursor C, MIToken &Token,
+ function_ref<void(StringRef::iterator Loc, const Twine &)> ErrorCallback) {
+ if (C.peek() != '$')
+ return None;
+ return lexName(C, Token, MIToken::ExternalSymbol,
+ MIToken::QuotedExternalSymbol,
+ /*PrefixLength=*/1, ErrorCallback);
+}
+
static Cursor maybeLexIntegerLiteral(Cursor C, MIToken &Token) {
if (!isdigit(C.peek()) && (C.peek() != '-' || !isdigit(C.peek(1))))
return None;
return R.remaining();
if (Cursor R = maybeLexGlobalValue(C, Token, ErrorCallback))
return R.remaining();
+ if (Cursor R = maybeLexExternalSymbol(C, Token, ErrorCallback))
+ return R.remaining();
if (Cursor R = maybeLexIntegerLiteral(C, Token))
return R.remaining();
if (Cursor R = maybeLexSymbol(C, Token))
NamedGlobalValue,
QuotedNamedGlobalValue,
GlobalValue,
+ ExternalSymbol,
+ QuotedExternalSymbol,
// Other tokens
IntegerLiteral,
StringRef::iterator location() const { return Range.begin(); }
- bool isStringValueQuoted() const { return Kind == QuotedNamedGlobalValue; }
+ bool isStringValueQuoted() const {
+ return Kind == QuotedNamedGlobalValue || Kind == QuotedExternalSymbol;
+ }
/// Return the token's raw string value.
///
bool parseGlobalAddressOperand(MachineOperand &Dest);
bool parseConstantPoolIndexOperand(MachineOperand &Dest);
bool parseJumpTableIndexOperand(MachineOperand &Dest);
+ bool parseExternalSymbolOperand(MachineOperand &Dest);
bool parseMachineOperand(MachineOperand &Dest);
private:
return false;
}
+bool MIParser::parseExternalSymbolOperand(MachineOperand &Dest) {
+ assert(Token.is(MIToken::ExternalSymbol) ||
+ Token.is(MIToken::QuotedExternalSymbol));
+ StringValueUtility Name(Token);
+ const char *Symbol = MF.createExternalSymbolName(Name);
+ lex();
+ // TODO: Parse the target flags.
+ Dest = MachineOperand::CreateES(Symbol);
+ return false;
+}
+
bool MIParser::parseMachineOperand(MachineOperand &Dest) {
switch (Token.kind()) {
case MIToken::kw_implicit:
return parseConstantPoolIndexOperand(Dest);
case MIToken::JumpTableIndex:
return parseJumpTableIndexOperand(Dest);
+ case MIToken::ExternalSymbol:
+ case MIToken::QuotedExternalSymbol:
+ return parseExternalSymbolOperand(Dest);
case MIToken::Error:
return true;
case MIToken::Identifier:
#include "llvm/CodeGen/MIRYamlMapping.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Instructions.h"
+#include "llvm/IR/IRPrintingPasses.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/ModuleSlotTracker.h"
#include "llvm/Support/MemoryBuffer.h"
OS << "%jump-table." << Op.getIndex();
// TODO: Print target flags.
break;
+ case MachineOperand::MO_ExternalSymbol:
+ OS << '$';
+ printLLVMNameWithoutPrefix(OS, Op.getSymbolName());
+ // TODO: Print the target flags.
+ break;
case MachineOperand::MO_GlobalAddress:
Op.getGlobal()->printAsOperand(OS, /*PrintType=*/false, MST);
// TODO: Print offset and target flags.
return std::make_pair(Result, Result + Num);
}
+const char *MachineFunction::createExternalSymbolName(StringRef Name) {
+ char *Dest = Allocator.Allocate<char>(Name.size() + 1);
+ std::copy(Name.begin(), Name.end(), Dest);
+ Dest[Name.size()] = 0;
+ return Dest;
+}
+
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
void MachineFunction::dump() const {
print(dbgs());
--- /dev/null
+# RUN: llc -march=x86-64 -start-after branch-folder -stop-after branch-folder -o /dev/null %s | FileCheck %s
+# This test ensures that the MIR parser parses the external symbol machine
+# operands correctly.
+
+--- |
+ @__stack_chk_guard = external global i8*
+
+ define i32 @test(i32 %n) #0 {
+ entry:
+ %StackGuardSlot = alloca i8*
+ %StackGuard = load i8*, i8** @__stack_chk_guard
+ call void @llvm.stackprotector(i8* %StackGuard, i8** %StackGuardSlot)
+ %a = alloca [128 x i32], align 16
+ %idxprom = sext i32 %n to i64
+ %arrayidx = getelementptr inbounds [128 x i32], [128 x i32]* %a, i64 0, i64 %idxprom
+ %0 = load i32, i32* %arrayidx, align 4
+ call void @llvm.stackprotectorcheck(i8** @__stack_chk_guard)
+ ret i32 %0
+ }
+
+ declare void @llvm.stackprotector(i8*, i8**) #1
+
+ declare void @llvm.stackprotectorcheck(i8**) #1
+
+ attributes #0 = { ssp "stack-protector-buffer-size"="8" }
+ attributes #1 = { nounwind }
+
+...
+---
+name: test
+tracksRegLiveness: true
+body:
+ - id: 0
+ name: entry
+ successors: [ '%bb.1.entry', '%bb.2.entry' ]
+ instructions:
+ - '%rsp = SUB64ri32 %rsp, 520, implicit-def %eflags'
+ - '%rcx = LOAD_STACK_GUARD'
+ - 'MOV64mr %rsp, 1, _, 512, _, %rcx'
+ - '%rax = MOVSX64rr32 %edi'
+ - '%eax = MOV32rm %rsp, 4, %rax, 0, _'
+ - 'CMP64rm %rcx, %rsp, 1, _, 512, _, implicit-def %eflags'
+ - 'JNE_1 %bb.2.entry, implicit %eflags'
+ - id: 1
+ name: entry
+ instructions:
+ - '%rsp = ADD64ri32 %rsp, 520, implicit-def %eflags'
+ - 'RETQ %eax'
+ - id: 2
+ name: entry
+ instructions:
+ # CHECK: CALL64pcrel32 $__stack_chk_fail,
+ # CHECK-NEXT: CALL64pcrel32 $__stack_chk_fail.09-_,
+ # CHECK-NEXT: CALL64pcrel32 $"__stack_chk_fail$",
+ # CHECK-NEXT: CALL64pcrel32 $"$Quoted \09 External symbol \11 ",
+ - 'CALL64pcrel32 $__stack_chk_fail, csr_64, implicit %rsp, implicit-def %rsp'
+ - 'CALL64pcrel32 $__stack_chk_fail.09-_, csr_64, implicit %rsp, implicit-def %rsp'
+ - 'CALL64pcrel32 $__stack_chk_fail$, csr_64, implicit %rsp, implicit-def %rsp'
+ - 'CALL64pcrel32 $"$Quoted \09 External symbol \11 ", csr_64, implicit %rsp, implicit-def %rsp'
+...