From 05e3882e81d4d25f52f716d2f6555510e25c6143 Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Wed, 5 Aug 2015 18:52:21 +0000 Subject: [PATCH] MIR Serialization: Serialize the typed immediate integer machine operands. llvm-svn: 244098 --- llvm/lib/CodeGen/MIRParser/MILexer.cpp | 13 ++++++++ llvm/lib/CodeGen/MIRParser/MILexer.h | 1 + llvm/lib/CodeGen/MIRParser/MIParser.cpp | 16 ++++++++++ llvm/lib/CodeGen/MIRPrinter.cpp | 3 ++ .../MIR/X86/instructions-debug-location.mir | 35 ++++++++++++++++++++++ 5 files changed, 68 insertions(+) diff --git a/llvm/lib/CodeGen/MIRParser/MILexer.cpp b/llvm/lib/CodeGen/MIRParser/MILexer.cpp index 13fad33..da79e1c 100644 --- a/llvm/lib/CodeGen/MIRParser/MILexer.cpp +++ b/llvm/lib/CodeGen/MIRParser/MILexer.cpp @@ -138,6 +138,17 @@ static Cursor lexName( return C; } +static Cursor maybeLexIntegerType(Cursor C, MIToken &Token) { + if (C.peek() != 'i' || !isdigit(C.peek(1))) + return None; + auto Range = C; + C.advance(); // Skip 'i' + while (isdigit(C.peek())) + C.advance(); + Token = MIToken(MIToken::IntegerType, Range.upto(C)); + return C; +} + static MIToken::TokenKind getIdentifierKind(StringRef Identifier) { return StringSwitch(Identifier) .Case("_", MIToken::underscore) @@ -418,6 +429,8 @@ StringRef llvm::lexMIToken( return C.remaining(); } + if (Cursor R = maybeLexIntegerType(C, Token)) + return R.remaining(); if (Cursor R = maybeLexIdentifier(C, Token)) return R.remaining(); if (Cursor R = maybeLexMachineBasicBlock(C, Token, ErrorCallback)) diff --git a/llvm/lib/CodeGen/MIRParser/MILexer.h b/llvm/lib/CodeGen/MIRParser/MILexer.h index 14eb17a..9896f7b 100644 --- a/llvm/lib/CodeGen/MIRParser/MILexer.h +++ b/llvm/lib/CodeGen/MIRParser/MILexer.h @@ -67,6 +67,7 @@ struct MIToken { // Identifier tokens Identifier, + IntegerType, NamedRegister, MachineBasicBlock, StackObject, diff --git a/llvm/lib/CodeGen/MIRParser/MIParser.cpp b/llvm/lib/CodeGen/MIRParser/MIParser.cpp index 5bedd3e..15f93ee 100644 --- a/llvm/lib/CodeGen/MIRParser/MIParser.cpp +++ b/llvm/lib/CodeGen/MIRParser/MIParser.cpp @@ -100,6 +100,7 @@ public: bool parseRegisterOperand(MachineOperand &Dest, bool IsDef = false); bool parseImmediateOperand(MachineOperand &Dest); bool parseIRConstant(StringRef::iterator Loc, const Constant *&C); + bool parseTypedImmediateOperand(MachineOperand &Dest); bool parseFPImmediateOperand(MachineOperand &Dest); bool parseMBBReference(MachineBasicBlock *&MBB); bool parseMBBOperand(MachineOperand &Dest); @@ -568,6 +569,19 @@ bool MIParser::parseIRConstant(StringRef::iterator Loc, const Constant *&C) { return false; } +bool MIParser::parseTypedImmediateOperand(MachineOperand &Dest) { + assert(Token.is(MIToken::IntegerType)); + auto Loc = Token.location(); + lex(); + if (Token.isNot(MIToken::IntegerLiteral)) + return error("expected an integer literal"); + const Constant *C = nullptr; + if (parseIRConstant(Loc, C)) + return true; + Dest = MachineOperand::CreateCImm(cast(C)); + return false; +} + bool MIParser::parseFPImmediateOperand(MachineOperand &Dest) { auto Loc = Token.location(); lex(); @@ -907,6 +921,8 @@ bool MIParser::parseMachineOperand(MachineOperand &Dest) { return parseRegisterOperand(Dest); case MIToken::IntegerLiteral: return parseImmediateOperand(Dest); + case MIToken::IntegerType: + return parseTypedImmediateOperand(Dest); case MIToken::kw_half: case MIToken::kw_float: case MIToken::kw_double: diff --git a/llvm/lib/CodeGen/MIRPrinter.cpp b/llvm/lib/CodeGen/MIRPrinter.cpp index bba9518..375fb74 100644 --- a/llvm/lib/CodeGen/MIRPrinter.cpp +++ b/llvm/lib/CodeGen/MIRPrinter.cpp @@ -541,6 +541,9 @@ void MIPrinter::print(const MachineOperand &Op, const TargetRegisterInfo *TRI) { case MachineOperand::MO_Immediate: OS << Op.getImm(); break; + case MachineOperand::MO_CImmediate: + Op.getCImm()->printAsOperand(OS, /*PrintType=*/true, MST); + break; case MachineOperand::MO_FPImmediate: Op.getFPImm()->printAsOperand(OS, /*PrintType=*/true, MST); break; diff --git a/llvm/test/CodeGen/MIR/X86/instructions-debug-location.mir b/llvm/test/CodeGen/MIR/X86/instructions-debug-location.mir index ca5f77d..5755484 100644 --- a/llvm/test/CodeGen/MIR/X86/instructions-debug-location.mir +++ b/llvm/test/CodeGen/MIR/X86/instructions-debug-location.mir @@ -13,6 +13,15 @@ ret i32 %0, !dbg !15 } + define i32 @test_typed_immediates(i32 %x) #0 { + entry: + %x.addr = alloca i32, align 4 + store i32 %x, i32* %x.addr, align 4 + call void @llvm.dbg.declare(metadata i32* %x.addr, metadata !12, metadata !13), !dbg !14 + %0 = load i32, i32* %x.addr, align 4, !dbg !15 + ret i32 %0, !dbg !15 + } + declare void @llvm.dbg.declare(metadata, metadata, metadata) #1 attributes #0 = { nounwind "no-frame-pointer-elim"="false" } @@ -64,3 +73,29 @@ body: - '%eax = COPY %0, debug-location !15' - 'RETQ %eax, debug-location !15' ... +--- +name: test_typed_immediates +isSSA: true +tracksRegLiveness: true +registers: + - { id: 0, class: gr32 } +frameInfo: + maxAlignment: 4 +stack: + - { id: 0, name: x.addr, size: 4, alignment: 4 } +body: + - id: 0 + name: entry + liveins: [ '%edi' ] + instructions: + - '%0 = COPY %edi' +# CHECK: DBG_VALUE _, i32 0, !12, !13 +# CHECK-NEXT: DBG_VALUE _, i64 -22, !12, !13 +# CHECK-NEXT: DBG_VALUE _, i128 123492148938512984928424384934328985928, !12, !13 + - 'DBG_VALUE _, i32 0, !12, !13' + - 'DBG_VALUE _, i64 -22, !12, !13' + - 'DBG_VALUE _, i128 123492148938512984928424384934328985928, !12, !13' + - 'MOV32mr %stack.0.x.addr, 1, _, 0, _, %0' + - '%eax = COPY %0' + - 'RETQ %eax' +... -- 2.7.4