summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorAlex Lorenz <arphaman@gmail.com>2015-08-05 18:52:21 +0000
committerAlex Lorenz <arphaman@gmail.com>2015-08-05 18:52:21 +0000
commit05e3882e81d4d25f52f716d2f6555510e25c6143 (patch)
treeb1fc3bfce2a2588955c7f13993a59ca527082c50 /llvm
parent124955aade67bb0455a8c0dc1f01d86b265ef277 (diff)
downloadbcm5719-llvm-05e3882e81d4d25f52f716d2f6555510e25c6143.tar.gz
bcm5719-llvm-05e3882e81d4d25f52f716d2f6555510e25c6143.zip
MIR Serialization: Serialize the typed immediate integer machine operands.
llvm-svn: 244098
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/CodeGen/MIRParser/MILexer.cpp13
-rw-r--r--llvm/lib/CodeGen/MIRParser/MILexer.h1
-rw-r--r--llvm/lib/CodeGen/MIRParser/MIParser.cpp16
-rw-r--r--llvm/lib/CodeGen/MIRPrinter.cpp3
-rw-r--r--llvm/test/CodeGen/MIR/X86/instructions-debug-location.mir35
5 files changed, 68 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/MIRParser/MILexer.cpp b/llvm/lib/CodeGen/MIRParser/MILexer.cpp
index 13fad33d980..da79e1c070d 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<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))
diff --git a/llvm/lib/CodeGen/MIRParser/MILexer.h b/llvm/lib/CodeGen/MIRParser/MILexer.h
index 14eb17aa9da..9896f7bcad7 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 5bedd3e18f3..15f93eea87f 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<ConstantInt>(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 bba9518c299..375fb74790b 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 ca5f77d2a32..57554841086 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'
+...
OpenPOWER on IntegriCloud