MIR Serialization: Serialize the 'killed' register machine operand flag.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241734 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Alex Lorenz 2015-07-08 21:23:34 +00:00
parent afab5f8c17
commit 03dcd3c6ef
5 changed files with 55 additions and 4 deletions

View File

@ -71,6 +71,7 @@ static MIToken::TokenKind getIdentifierKind(StringRef Identifier) {
.Case("implicit", MIToken::kw_implicit) .Case("implicit", MIToken::kw_implicit)
.Case("implicit-def", MIToken::kw_implicit_define) .Case("implicit-def", MIToken::kw_implicit_define)
.Case("dead", MIToken::kw_dead) .Case("dead", MIToken::kw_dead)
.Case("killed", MIToken::kw_killed)
.Default(MIToken::Identifier); .Default(MIToken::Identifier);
} }

View File

@ -40,6 +40,7 @@ struct MIToken {
kw_implicit, kw_implicit,
kw_implicit_define, kw_implicit_define,
kw_dead, kw_dead,
kw_killed,
// Identifier tokens // Identifier tokens
Identifier, Identifier,
@ -75,7 +76,8 @@ public:
} }
bool isRegisterFlag() const { bool isRegisterFlag() const {
return Kind == kw_implicit || Kind == kw_implicit_define || Kind == kw_dead; return Kind == kw_implicit || Kind == kw_implicit_define ||
Kind == kw_dead || Kind == kw_killed;
} }
bool is(TokenKind K) const { return Kind == K; } bool is(TokenKind K) const { return Kind == K; }

View File

@ -308,6 +308,9 @@ bool MIParser::parseRegisterFlag(unsigned &Flags) {
case MIToken::kw_dead: case MIToken::kw_dead:
Flags |= RegState::Dead; Flags |= RegState::Dead;
break; break;
case MIToken::kw_killed:
Flags |= RegState::Kill;
break;
// TODO: report an error when we specify the same flag more than once. // TODO: report an error when we specify the same flag more than once.
// TODO: parse the other register flags. // TODO: parse the other register flags.
default: default:
@ -330,9 +333,9 @@ bool MIParser::parseRegisterOperand(MachineOperand &Dest, bool IsDef) {
return true; return true;
lex(); lex();
// TODO: Parse subregister. // TODO: Parse subregister.
Dest = MachineOperand::CreateReg(Reg, Flags & RegState::Define, Dest = MachineOperand::CreateReg(
Flags & RegState::Implicit, /*IsKill=*/false, Reg, Flags & RegState::Define, Flags & RegState::Implicit,
Flags & RegState::Dead); Flags & RegState::Kill, Flags & RegState::Dead);
return false; return false;
} }
@ -417,6 +420,7 @@ bool MIParser::parseMachineOperand(MachineOperand &Dest) {
case MIToken::kw_implicit: case MIToken::kw_implicit:
case MIToken::kw_implicit_define: case MIToken::kw_implicit_define:
case MIToken::kw_dead: case MIToken::kw_dead:
case MIToken::kw_killed:
case MIToken::underscore: case MIToken::underscore:
case MIToken::NamedRegister: case MIToken::NamedRegister:
return parseRegisterOperand(Dest); return parseRegisterOperand(Dest);

View File

@ -218,6 +218,8 @@ void MIPrinter::print(const MachineOperand &Op, const TargetRegisterInfo *TRI) {
OS << (Op.isDef() ? "implicit-def " : "implicit "); OS << (Op.isDef() ? "implicit-def " : "implicit ");
if (Op.isDead()) if (Op.isDead())
OS << "dead "; OS << "dead ";
if (Op.isKill())
OS << "killed ";
printReg(Op.getReg(), OS, TRI); printReg(Op.getReg(), OS, TRI);
// TODO: Print sub register. // TODO: Print sub register.
break; break;

View File

@ -0,0 +1,42 @@
# 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 'killed' register flags
# correctly.
--- |
define i32 @foo(i32 %a) {
entry:
%0 = icmp sle i32 %a, 10
br i1 %0, label %less, label %exit
less:
ret i32 0
exit:
ret i32 %a
}
...
---
name: foo
body:
- id: 0
name: entry
instructions:
- 'CMP32ri8 %edi, 10, implicit-def %eflags'
- 'JG_1 %bb.2.exit, implicit %eflags'
- id: 1
name: less
instructions:
# CHECK: - '%eax = MOV32r0
# CHECK-NEXT: - 'RETQ killed %eax
- '%eax = MOV32r0 implicit-def %eflags'
- 'RETQ killed %eax'
- id: 2
name: exit
instructions:
# CHECK: - '%eax = COPY killed %edi
# CHECK-NEXT: - 'RETQ killed %eax
- '%eax = COPY killed %edi'
- 'RETQ killed %eax'
...