diff options
| author | Alex Lorenz <arphaman@gmail.com> | 2015-07-06 23:07:26 +0000 |
|---|---|---|
| committer | Alex Lorenz <arphaman@gmail.com> | 2015-07-06 23:07:26 +0000 |
| commit | cb268d46f002d8f506f9b506f3eb812f6dc136b8 (patch) | |
| tree | 50c7588205ba7e25cc9ec38dcd1dcfd1e6426a24 /llvm/lib/CodeGen/MIRParser | |
| parent | e869b753e4edb9aee7fc30cc2dd886241cbdba1f (diff) | |
| download | bcm5719-llvm-cb268d46f002d8f506f9b506f3eb812f6dc136b8.tar.gz bcm5719-llvm-cb268d46f002d8f506f9b506f3eb812f6dc136b8.zip | |
MIR Serialization: Serialize the implicit register flag.
This commit serializes the implicit flag for the register machine operands. It
introduces two new keywords into the machine instruction syntax: 'implicit' and
'implicit-def'. The 'implicit' keyword is used for the implicit register
operands, and the 'implicit-def' keyword is used for the register operands that
have both the implicit and the define flags set.
Reviewers: Duncan P. N. Exon Smith
Differential Revision: http://reviews.llvm.org/D10709
llvm-svn: 241519
Diffstat (limited to 'llvm/lib/CodeGen/MIRParser')
| -rw-r--r-- | llvm/lib/CodeGen/MIRParser/MILexer.cpp | 12 | ||||
| -rw-r--r-- | llvm/lib/CodeGen/MIRParser/MILexer.h | 8 | ||||
| -rw-r--r-- | llvm/lib/CodeGen/MIRParser/MIParser.cpp | 51 |
3 files changed, 51 insertions, 20 deletions
diff --git a/llvm/lib/CodeGen/MIRParser/MILexer.cpp b/llvm/lib/CodeGen/MIRParser/MILexer.cpp index e9b3916a11f..856d908b778 100644 --- a/llvm/lib/CodeGen/MIRParser/MILexer.cpp +++ b/llvm/lib/CodeGen/MIRParser/MILexer.cpp @@ -12,6 +12,7 @@ //===----------------------------------------------------------------------===// #include "MILexer.h" +#include "llvm/ADT/StringSwitch.h" #include "llvm/ADT/Twine.h" #include <cctype> @@ -64,6 +65,14 @@ static bool isIdentifierChar(char C) { return isalpha(C) || isdigit(C) || C == '_' || C == '-' || C == '.'; } +static MIToken::TokenKind getIdentifierKind(StringRef Identifier) { + return StringSwitch<MIToken::TokenKind>(Identifier) + .Case("_", MIToken::underscore) + .Case("implicit", MIToken::kw_implicit) + .Case("implicit-def", MIToken::kw_implicit_define) + .Default(MIToken::Identifier); +} + static Cursor maybeLexIdentifier(Cursor C, MIToken &Token) { if (!isalpha(C.peek()) && C.peek() != '_') return None; @@ -71,8 +80,7 @@ static Cursor maybeLexIdentifier(Cursor C, MIToken &Token) { while (isIdentifierChar(C.peek())) C.advance(); auto Identifier = Range.upto(C); - Token = MIToken(Identifier == "_" ? MIToken::underscore : MIToken::Identifier, - Identifier); + Token = MIToken(getIdentifierKind(Identifier), Identifier); return C; } diff --git a/llvm/lib/CodeGen/MIRParser/MILexer.h b/llvm/lib/CodeGen/MIRParser/MILexer.h index c28935f3890..c66b2006e35 100644 --- a/llvm/lib/CodeGen/MIRParser/MILexer.h +++ b/llvm/lib/CodeGen/MIRParser/MILexer.h @@ -36,6 +36,10 @@ struct MIToken { equal, underscore, + // Keywords + kw_implicit, + kw_implicit_define, + // Identifier tokens Identifier, NamedRegister, @@ -69,6 +73,10 @@ public: return Kind == NamedRegister || Kind == underscore; } + bool isRegisterFlag() const { + return Kind == kw_implicit || Kind == kw_implicit_define; + } + bool is(TokenKind K) const { return Kind == K; } bool isNot(TokenKind K) const { return Kind != K; } diff --git a/llvm/lib/CodeGen/MIRParser/MIParser.cpp b/llvm/lib/CodeGen/MIRParser/MIParser.cpp index b618e53b8e4..a2ddd48ab16 100644 --- a/llvm/lib/CodeGen/MIRParser/MIParser.cpp +++ b/llvm/lib/CodeGen/MIRParser/MIParser.cpp @@ -18,6 +18,7 @@ #include "llvm/CodeGen/MachineBasicBlock.h" #include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MachineInstr.h" +#include "llvm/CodeGen/MachineInstrBuilder.h" #include "llvm/IR/Module.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Support/SourceMgr.h" @@ -67,6 +68,7 @@ public: bool parseMBB(MachineBasicBlock *&MBB); bool parseRegister(unsigned &Reg); + bool parseRegisterFlag(unsigned &Flags); bool parseRegisterOperand(MachineOperand &Dest, bool IsDef = false); bool parseImmediateOperand(MachineOperand &Dest); bool parseMBBReference(MachineBasicBlock *&MBB); @@ -138,7 +140,7 @@ bool MIParser::parse(MachineInstr *&MI) { // TODO: Allow parsing of multiple operands before '=' MachineOperand MO = MachineOperand::CreateImm(0); SmallVector<MachineOperand, 8> Operands; - if (Token.isRegister()) { + if (Token.isRegister() || Token.isRegisterFlag()) { if (parseRegisterOperand(MO, /*IsDef=*/true)) return true; Operands.push_back(MO); @@ -167,21 +169,8 @@ bool MIParser::parse(MachineInstr *&MI) { const auto &MCID = MF.getSubtarget().getInstrInfo()->get(OpCode); - // Verify machine operands. - if (!MCID.isVariadic()) { - for (size_t I = 0, E = Operands.size(); I < E; ++I) { - if (I < MCID.getNumOperands()) - continue; - // Mark this register as implicit to prevent an assertion when it's added - // to an instruction. This is a temporary workaround until the implicit - // register flag can be parsed. - if (Operands[I].isReg()) - Operands[I].setImplicit(); - } - } - - // TODO: Determine the implicit behaviour when implicit register flags are - // parsed. + // TODO: Check for extraneous machine operands. + // TODO: Check that this instruction has the implicit register operands. MI = MF.CreateMachineInstr(MCID, DebugLoc(), /*NoImplicit=*/true); for (const auto &Operand : Operands) MI->addOperand(MF, Operand); @@ -229,14 +218,38 @@ bool MIParser::parseRegister(unsigned &Reg) { return false; } +bool MIParser::parseRegisterFlag(unsigned &Flags) { + switch (Token.kind()) { + case MIToken::kw_implicit: + Flags |= RegState::Implicit; + break; + case MIToken::kw_implicit_define: + Flags |= RegState::ImplicitDefine; + break; + // TODO: report an error when we specify the same flag more than once. + // TODO: parse the other register flags. + default: + llvm_unreachable("The current token should be a register flag"); + } + lex(); + return false; +} + bool MIParser::parseRegisterOperand(MachineOperand &Dest, bool IsDef) { unsigned Reg; - // TODO: Parse register flags. + unsigned Flags = IsDef ? RegState::Define : 0; + while (Token.isRegisterFlag()) { + if (parseRegisterFlag(Flags)) + return true; + } + if (!Token.isRegister()) + return error("expected a register after register flags"); if (parseRegister(Reg)) return true; lex(); // TODO: Parse subregister. - Dest = MachineOperand::CreateReg(Reg, IsDef); + Dest = MachineOperand::CreateReg(Reg, Flags & RegState::Define, + Flags & RegState::Implicit); return false; } @@ -318,6 +331,8 @@ bool MIParser::parseGlobalAddressOperand(MachineOperand &Dest) { bool MIParser::parseMachineOperand(MachineOperand &Dest) { switch (Token.kind()) { + case MIToken::kw_implicit: + case MIToken::kw_implicit_define: case MIToken::underscore: case MIToken::NamedRegister: return parseRegisterOperand(Dest); |

