diff options
Diffstat (limited to 'llvm/lib/CodeGen/MIRParser')
-rw-r--r-- | llvm/lib/CodeGen/MIRParser/MILexer.cpp | 33 | ||||
-rw-r--r-- | llvm/lib/CodeGen/MIRParser/MILexer.h | 3 | ||||
-rw-r--r-- | llvm/lib/CodeGen/MIRParser/MIParser.cpp | 43 | ||||
-rw-r--r-- | llvm/lib/CodeGen/MIRParser/MIParser.h | 2 | ||||
-rw-r--r-- | llvm/lib/CodeGen/MIRParser/MIRParser.cpp | 23 |
5 files changed, 95 insertions, 9 deletions
diff --git a/llvm/lib/CodeGen/MIRParser/MILexer.cpp b/llvm/lib/CodeGen/MIRParser/MILexer.cpp index 9babb3b0a3d..53c393da45d 100644 --- a/llvm/lib/CodeGen/MIRParser/MILexer.cpp +++ b/llvm/lib/CodeGen/MIRParser/MILexer.cpp @@ -128,10 +128,39 @@ static Cursor maybeLexIndex(Cursor C, MIToken &Token, StringRef Rule, return C; } +static Cursor maybeLexIndexAndName(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(); + StringRef Number = NumberRange.upto(C); + unsigned StringOffset = Rule.size() + Number.size(); + if (C.peek() == '.') { + C.advance(); + ++StringOffset; + while (isIdentifierChar(C.peek())) + C.advance(); + } + Token = MIToken(Kind, Range.upto(C), APSInt(Number), StringOffset); + return C; +} + static Cursor maybeLexJumpTableIndex(Cursor C, MIToken &Token) { return maybeLexIndex(C, Token, "%jump-table.", MIToken::JumpTableIndex); } +static Cursor maybeLexStackObject(Cursor C, MIToken &Token) { + return maybeLexIndexAndName(C, Token, "%stack.", MIToken::StackObject); +} + +static Cursor maybeLexFixedStackObject(Cursor C, MIToken &Token) { + return maybeLexIndex(C, Token, "%fixed-stack.", MIToken::FixedStackObject); +} + static Cursor lexVirtualRegister(Cursor C, MIToken &Token) { auto Range = C; C.advance(); // Skip '%' @@ -228,6 +257,10 @@ StringRef llvm::lexMIToken( return R.remaining(); if (Cursor R = maybeLexJumpTableIndex(C, Token)) return R.remaining(); + if (Cursor R = maybeLexStackObject(C, Token)) + return R.remaining(); + if (Cursor R = maybeLexFixedStackObject(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 b1c05226158..03b4d486f98 100644 --- a/llvm/lib/CodeGen/MIRParser/MILexer.h +++ b/llvm/lib/CodeGen/MIRParser/MILexer.h @@ -48,6 +48,8 @@ struct MIToken { Identifier, NamedRegister, MachineBasicBlock, + StackObject, + FixedStackObject, NamedGlobalValue, GlobalValue, @@ -97,6 +99,7 @@ public: bool hasIntegerValue() const { return Kind == IntegerLiteral || Kind == MachineBasicBlock || + Kind == StackObject || Kind == FixedStackObject || Kind == GlobalValue || Kind == VirtualRegister || Kind == JumpTableIndex; } diff --git a/llvm/lib/CodeGen/MIRParser/MIParser.cpp b/llvm/lib/CodeGen/MIRParser/MIParser.cpp index 62a3fbe1e5f..b2931189578 100644 --- a/llvm/lib/CodeGen/MIRParser/MIParser.cpp +++ b/llvm/lib/CodeGen/MIRParser/MIParser.cpp @@ -17,8 +17,10 @@ #include "llvm/AsmParser/SlotMapping.h" #include "llvm/CodeGen/MachineBasicBlock.h" #include "llvm/CodeGen/MachineFunction.h" +#include "llvm/CodeGen/MachineFrameInfo.h" #include "llvm/CodeGen/MachineInstr.h" #include "llvm/CodeGen/MachineInstrBuilder.h" +#include "llvm/IR/Instructions.h" #include "llvm/IR/Module.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Support/SourceMgr.h" @@ -87,6 +89,8 @@ public: bool parseImmediateOperand(MachineOperand &Dest); bool parseMBBReference(MachineBasicBlock *&MBB); bool parseMBBOperand(MachineOperand &Dest); + bool parseStackObjectOperand(MachineOperand &Dest); + bool parseFixedStackObjectOperand(MachineOperand &Dest); bool parseGlobalAddressOperand(MachineOperand &Dest); bool parseJumpTableIndexOperand(MachineOperand &Dest); bool parseMachineOperand(MachineOperand &Dest); @@ -439,6 +443,41 @@ bool MIParser::parseMBBOperand(MachineOperand &Dest) { return false; } +bool MIParser::parseStackObjectOperand(MachineOperand &Dest) { + assert(Token.is(MIToken::StackObject)); + unsigned ID; + if (getUnsigned(ID)) + return true; + auto ObjectInfo = PFS.StackObjectSlots.find(ID); + if (ObjectInfo == PFS.StackObjectSlots.end()) + return error(Twine("use of undefined stack object '%stack.") + Twine(ID) + + "'"); + StringRef Name; + if (const auto *Alloca = + MF.getFrameInfo()->getObjectAllocation(ObjectInfo->second)) + Name = Alloca->getName(); + if (!Token.stringValue().empty() && Token.stringValue() != Name) + return error(Twine("the name of the stack object '%stack.") + Twine(ID) + + "' isn't '" + Token.stringValue() + "'"); + lex(); + Dest = MachineOperand::CreateFI(ObjectInfo->second); + return false; +} + +bool MIParser::parseFixedStackObjectOperand(MachineOperand &Dest) { + assert(Token.is(MIToken::FixedStackObject)); + unsigned ID; + if (getUnsigned(ID)) + return true; + auto ObjectInfo = PFS.FixedStackObjectSlots.find(ID); + if (ObjectInfo == PFS.FixedStackObjectSlots.end()) + return error(Twine("use of undefined fixed stack object '%fixed-stack.") + + Twine(ID) + "'"); + lex(); + Dest = MachineOperand::CreateFI(ObjectInfo->second); + return false; +} + bool MIParser::parseGlobalAddressOperand(MachineOperand &Dest) { switch (Token.kind()) { case MIToken::NamedGlobalValue: { @@ -498,6 +537,10 @@ bool MIParser::parseMachineOperand(MachineOperand &Dest) { return parseImmediateOperand(Dest); case MIToken::MachineBasicBlock: return parseMBBOperand(Dest); + case MIToken::StackObject: + return parseStackObjectOperand(Dest); + case MIToken::FixedStackObject: + return parseFixedStackObjectOperand(Dest); case MIToken::GlobalValue: case MIToken::NamedGlobalValue: return parseGlobalAddressOperand(Dest); diff --git a/llvm/lib/CodeGen/MIRParser/MIParser.h b/llvm/lib/CodeGen/MIRParser/MIParser.h index 405e637267f..b34b7626eb8 100644 --- a/llvm/lib/CodeGen/MIRParser/MIParser.h +++ b/llvm/lib/CodeGen/MIRParser/MIParser.h @@ -29,6 +29,8 @@ class SourceMgr; struct PerFunctionMIParsingState { DenseMap<unsigned, MachineBasicBlock *> MBBSlots; DenseMap<unsigned, unsigned> VirtualRegisterSlots; + DenseMap<unsigned, int> FixedStackObjectSlots; + DenseMap<unsigned, int> StackObjectSlots; DenseMap<unsigned, unsigned> JumpTableSlots; }; diff --git a/llvm/lib/CodeGen/MIRParser/MIRParser.cpp b/llvm/lib/CodeGen/MIRParser/MIRParser.cpp index fb1878febda..ca46de44740 100644 --- a/llvm/lib/CodeGen/MIRParser/MIRParser.cpp +++ b/llvm/lib/CodeGen/MIRParser/MIRParser.cpp @@ -109,7 +109,9 @@ public: DenseMap<unsigned, unsigned> &VirtualRegisterSlots); bool initializeFrameInfo(const Function &F, MachineFrameInfo &MFI, - const yaml::MachineFunction &YamlMF); + const yaml::MachineFunction &YamlMF, + DenseMap<unsigned, int> &StackObjectSlots, + DenseMap<unsigned, int> &FixedStackObjectSlots); bool initializeJumpTableInfo(MachineFunction &MF, const yaml::MachineJumpTable &YamlJTI, @@ -268,7 +270,8 @@ bool MIRParserImpl::initializeMachineFunction(MachineFunction &MF) { if (initializeRegisterInfo(MF, MF.getRegInfo(), YamlMF, PFS.VirtualRegisterSlots)) return true; - if (initializeFrameInfo(*MF.getFunction(), *MF.getFrameInfo(), YamlMF)) + if (initializeFrameInfo(*MF.getFunction(), *MF.getFrameInfo(), YamlMF, + PFS.StackObjectSlots, PFS.FixedStackObjectSlots)) return true; const auto &F = *MF.getFunction(); @@ -375,9 +378,11 @@ bool MIRParserImpl::initializeRegisterInfo( return false; } -bool MIRParserImpl::initializeFrameInfo(const Function &F, - MachineFrameInfo &MFI, - const yaml::MachineFunction &YamlMF) { +bool MIRParserImpl::initializeFrameInfo( + const Function &F, MachineFrameInfo &MFI, + const yaml::MachineFunction &YamlMF, + DenseMap<unsigned, int> &StackObjectSlots, + DenseMap<unsigned, int> &FixedStackObjectSlots) { const yaml::MachineFrameInfo &YamlMFI = YamlMF.FrameInfo; MFI.setFrameAddressIsTaken(YamlMFI.IsFrameAddressTaken); MFI.setReturnAddressIsTaken(YamlMFI.IsReturnAddressTaken); @@ -403,8 +408,8 @@ bool MIRParserImpl::initializeFrameInfo(const Function &F, else ObjectIdx = MFI.CreateFixedSpillStackObject(Object.Size, Object.Offset); MFI.setObjectAlignment(ObjectIdx, Object.Alignment); - // TODO: Store the mapping between fixed object IDs and object indices to - // parse fixed stack object references correctly. + // TODO: Report an error when objects are redefined. + FixedStackObjectSlots.insert(std::make_pair(Object.ID, ObjectIdx)); } // Initialize the ordinary frame objects. @@ -428,8 +433,8 @@ bool MIRParserImpl::initializeFrameInfo(const Function &F, Object.Size, Object.Alignment, Object.Type == yaml::MachineStackObject::SpillSlot, Alloca); MFI.setObjectOffset(ObjectIdx, Object.Offset); - // TODO: Store the mapping between object IDs and object indices to parse - // stack object references correctly. + // TODO: Report an error when objects are redefined. + StackObjectSlots.insert(std::make_pair(Object.ID, ObjectIdx)); } return false; } |