diff options
author | Alex Lorenz <arphaman@gmail.com> | 2015-07-15 23:38:35 +0000 |
---|---|---|
committer | Alex Lorenz <arphaman@gmail.com> | 2015-07-15 23:38:35 +0000 |
commit | 31d706836c83c690e1803dfb7a1e788e92c46da7 (patch) | |
tree | f6ddf70ba7b1aaf7876c07e414458e2054e374eb /llvm/lib/CodeGen/MIRParser | |
parent | 6799e9b3e05d0dd9cee926689551fc0d592b96ba (diff) | |
download | bcm5719-llvm-31d706836c83c690e1803dfb7a1e788e92c46da7.tar.gz bcm5719-llvm-31d706836c83c690e1803dfb7a1e788e92c46da7.zip |
MIR Serialization: Serialize the jump table index operands.
Reviewers: Duncan P. N. Exon Smith
llvm-svn: 242358
Diffstat (limited to 'llvm/lib/CodeGen/MIRParser')
-rw-r--r-- | llvm/lib/CodeGen/MIRParser/MILexer.cpp | 19 | ||||
-rw-r--r-- | llvm/lib/CodeGen/MIRParser/MILexer.h | 6 | ||||
-rw-r--r-- | llvm/lib/CodeGen/MIRParser/MIParser.cpp | 17 | ||||
-rw-r--r-- | llvm/lib/CodeGen/MIRParser/MIParser.h | 1 | ||||
-rw-r--r-- | llvm/lib/CodeGen/MIRParser/MIRParser.cpp | 8 |
5 files changed, 46 insertions, 5 deletions
diff --git a/llvm/lib/CodeGen/MIRParser/MILexer.cpp b/llvm/lib/CodeGen/MIRParser/MILexer.cpp index 482c33ae223..9babb3b0a3d 100644 --- a/llvm/lib/CodeGen/MIRParser/MILexer.cpp +++ b/llvm/lib/CodeGen/MIRParser/MILexer.cpp @@ -115,6 +115,23 @@ static Cursor maybeLexMachineBasicBlock( return C; } +static Cursor maybeLexIndex(Cursor C, MIToken &Token, StringRef Rule, + MIToken::TokenKind Kind) { + if (!C.remaining().startswith(Rule) || !isdigit(C.peek(Rule.size()))) + return None; + auto Range = C; + C.advance(Rule.size()); + auto NumberRange = C; + while (isdigit(C.peek())) + C.advance(); + Token = MIToken(Kind, Range.upto(C), APSInt(NumberRange.upto(C))); + return C; +} + +static Cursor maybeLexJumpTableIndex(Cursor C, MIToken &Token) { + return maybeLexIndex(C, Token, "%jump-table.", MIToken::JumpTableIndex); +} + static Cursor lexVirtualRegister(Cursor C, MIToken &Token) { auto Range = C; C.advance(); // Skip '%' @@ -209,6 +226,8 @@ StringRef llvm::lexMIToken( return R.remaining(); if (Cursor R = maybeLexMachineBasicBlock(C, Token, ErrorCallback)) return R.remaining(); + if (Cursor R = maybeLexJumpTableIndex(C, Token)) + return R.remaining(); if (Cursor R = maybeLexRegister(C, Token)) return R.remaining(); if (Cursor R = maybeLexGlobalValue(C, Token)) diff --git a/llvm/lib/CodeGen/MIRParser/MILexer.h b/llvm/lib/CodeGen/MIRParser/MILexer.h index 55460b56e7d..b1c05226158 100644 --- a/llvm/lib/CodeGen/MIRParser/MILexer.h +++ b/llvm/lib/CodeGen/MIRParser/MILexer.h @@ -53,7 +53,8 @@ struct MIToken { // Other tokens IntegerLiteral, - VirtualRegister + VirtualRegister, + JumpTableIndex }; private: @@ -96,7 +97,8 @@ public: bool hasIntegerValue() const { return Kind == IntegerLiteral || Kind == MachineBasicBlock || - Kind == GlobalValue || Kind == VirtualRegister; + Kind == GlobalValue || Kind == VirtualRegister || + Kind == JumpTableIndex; } }; diff --git a/llvm/lib/CodeGen/MIRParser/MIParser.cpp b/llvm/lib/CodeGen/MIRParser/MIParser.cpp index c00011288a6..62a3fbe1e5f 100644 --- a/llvm/lib/CodeGen/MIRParser/MIParser.cpp +++ b/llvm/lib/CodeGen/MIRParser/MIParser.cpp @@ -88,6 +88,7 @@ public: bool parseMBBReference(MachineBasicBlock *&MBB); bool parseMBBOperand(MachineOperand &Dest); bool parseGlobalAddressOperand(MachineOperand &Dest); + bool parseJumpTableIndexOperand(MachineOperand &Dest); bool parseMachineOperand(MachineOperand &Dest); private: @@ -468,6 +469,20 @@ bool MIParser::parseGlobalAddressOperand(MachineOperand &Dest) { return false; } +bool MIParser::parseJumpTableIndexOperand(MachineOperand &Dest) { + assert(Token.is(MIToken::JumpTableIndex)); + unsigned ID; + if (getUnsigned(ID)) + return true; + auto JumpTableEntryInfo = PFS.JumpTableSlots.find(ID); + if (JumpTableEntryInfo == PFS.JumpTableSlots.end()) + return error("use of undefined jump table '%jump-table." + Twine(ID) + "'"); + lex(); + // TODO: Parse target flags. + Dest = MachineOperand::CreateJTI(JumpTableEntryInfo->second); + return false; +} + bool MIParser::parseMachineOperand(MachineOperand &Dest) { switch (Token.kind()) { case MIToken::kw_implicit: @@ -486,6 +501,8 @@ bool MIParser::parseMachineOperand(MachineOperand &Dest) { case MIToken::GlobalValue: case MIToken::NamedGlobalValue: return parseGlobalAddressOperand(Dest); + case MIToken::JumpTableIndex: + return parseJumpTableIndexOperand(Dest); case MIToken::Error: return true; case MIToken::Identifier: diff --git a/llvm/lib/CodeGen/MIRParser/MIParser.h b/llvm/lib/CodeGen/MIRParser/MIParser.h index fca4c4e6f88..405e637267f 100644 --- a/llvm/lib/CodeGen/MIRParser/MIParser.h +++ b/llvm/lib/CodeGen/MIRParser/MIParser.h @@ -29,6 +29,7 @@ class SourceMgr; struct PerFunctionMIParsingState { DenseMap<unsigned, MachineBasicBlock *> MBBSlots; DenseMap<unsigned, unsigned> VirtualRegisterSlots; + DenseMap<unsigned, unsigned> JumpTableSlots; }; bool parseMachineInstr(MachineInstr *&MI, SourceMgr &SM, MachineFunction &MF, diff --git a/llvm/lib/CodeGen/MIRParser/MIRParser.cpp b/llvm/lib/CodeGen/MIRParser/MIRParser.cpp index 1ba5db841af..fb1878febda 100644 --- a/llvm/lib/CodeGen/MIRParser/MIRParser.cpp +++ b/llvm/lib/CodeGen/MIRParser/MIRParser.cpp @@ -113,7 +113,7 @@ public: bool initializeJumpTableInfo(MachineFunction &MF, const yaml::MachineJumpTable &YamlJTI, - const PerFunctionMIParsingState &PFS); + PerFunctionMIParsingState &PFS); private: /// Return a MIR diagnostic converted from an MI string diagnostic. @@ -436,7 +436,7 @@ bool MIRParserImpl::initializeFrameInfo(const Function &F, bool MIRParserImpl::initializeJumpTableInfo( MachineFunction &MF, const yaml::MachineJumpTable &YamlJTI, - const PerFunctionMIParsingState &PFS) { + PerFunctionMIParsingState &PFS) { MachineJumpTableInfo *JTI = MF.getOrCreateJumpTableInfo(YamlJTI.Kind); SMDiagnostic Error; for (const auto &Entry : YamlJTI.Entries) { @@ -447,7 +447,9 @@ bool MIRParserImpl::initializeJumpTableInfo( return error(Error, MBBSource.SourceRange); Blocks.push_back(MBB); } - JTI->createJumpTableIndex(Blocks); + unsigned Index = JTI->createJumpTableIndex(Blocks); + // TODO: Report an error when the same jump table slot ID is redefined. + PFS.JumpTableSlots.insert(std::make_pair(Entry.ID, Index)); } return false; } |