[llvm] r244098 - MIR Serialization: Serialize the typed immediate integer machine operands.
Alex Lorenz
arphaman at gmail.com
Wed Aug 5 11:52:21 PDT 2015
Author: arphaman
Date: Wed Aug 5 13:52:21 2015
New Revision: 244098
URL: http://llvm.org/viewvc/llvm-project?rev=244098&view=rev
Log:
MIR Serialization: Serialize the typed immediate integer machine operands.
Modified:
llvm/trunk/lib/CodeGen/MIRParser/MILexer.cpp
llvm/trunk/lib/CodeGen/MIRParser/MILexer.h
llvm/trunk/lib/CodeGen/MIRParser/MIParser.cpp
llvm/trunk/lib/CodeGen/MIRPrinter.cpp
llvm/trunk/test/CodeGen/MIR/X86/instructions-debug-location.mir
Modified: llvm/trunk/lib/CodeGen/MIRParser/MILexer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIRParser/MILexer.cpp?rev=244098&r1=244097&r2=244098&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MIRParser/MILexer.cpp (original)
+++ llvm/trunk/lib/CodeGen/MIRParser/MILexer.cpp Wed Aug 5 13:52:21 2015
@@ -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<MIToken::TokenKind>(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))
Modified: llvm/trunk/lib/CodeGen/MIRParser/MILexer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIRParser/MILexer.h?rev=244098&r1=244097&r2=244098&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MIRParser/MILexer.h (original)
+++ llvm/trunk/lib/CodeGen/MIRParser/MILexer.h Wed Aug 5 13:52:21 2015
@@ -67,6 +67,7 @@ struct MIToken {
// Identifier tokens
Identifier,
+ IntegerType,
NamedRegister,
MachineBasicBlock,
StackObject,
Modified: llvm/trunk/lib/CodeGen/MIRParser/MIParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIRParser/MIParser.cpp?rev=244098&r1=244097&r2=244098&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MIRParser/MIParser.cpp (original)
+++ llvm/trunk/lib/CodeGen/MIRParser/MIParser.cpp Wed Aug 5 13:52:21 2015
@@ -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
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<ConstantInt>(C));
+ return false;
+}
+
bool MIParser::parseFPImmediateOperand(MachineOperand &Dest) {
auto Loc = Token.location();
lex();
@@ -907,6 +921,8 @@ bool MIParser::parseMachineOperand(Machi
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:
Modified: llvm/trunk/lib/CodeGen/MIRPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIRPrinter.cpp?rev=244098&r1=244097&r2=244098&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MIRPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/MIRPrinter.cpp Wed Aug 5 13:52:21 2015
@@ -541,6 +541,9 @@ void MIPrinter::print(const MachineOpera
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;
Modified: llvm/trunk/test/CodeGen/MIR/X86/instructions-debug-location.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/MIR/X86/instructions-debug-location.mir?rev=244098&r1=244097&r2=244098&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/MIR/X86/instructions-debug-location.mir (original)
+++ llvm/trunk/test/CodeGen/MIR/X86/instructions-debug-location.mir Wed Aug 5 13:52:21 2015
@@ -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'
+...
More information about the llvm-commits
mailing list