diff options
author | Alex Lorenz <arphaman@gmail.com> | 2015-06-26 16:46:11 +0000 |
---|---|---|
committer | Alex Lorenz <arphaman@gmail.com> | 2015-06-26 16:46:11 +0000 |
commit | 33f0aef32f92efe150ae18a9a5d2678a064517a3 (patch) | |
tree | 469e6267d09a320280b813753c89e61e5e437a83 /llvm/lib/CodeGen/MIRParser/MIRParser.cpp | |
parent | a67e50c301fc0bf2a0e84a819408354b38e51580 (diff) | |
download | bcm5719-llvm-33f0aef32f92efe150ae18a9a5d2678a064517a3.tar.gz bcm5719-llvm-33f0aef32f92efe150ae18a9a5d2678a064517a3.zip |
MIR Serialization: Serialize machine basic block operands.
This commit serializes machine basic block operands. The
machine basic block operands use the following syntax:
%bb.<id>[.<name>]
This commit also modifies the YAML representation for the
machine basic blocks - a new, required field 'id' is added
to the MBB YAML mapping.
The id is used to resolve the MBB references to the
actual MBBs. And while the name of the MBB can be
included in a MBB reference, this name isn't used to
resolve MBB references - as it's possible that multiple
MBBs will reference the same BB and thus they will have the
same name. If the name is specified, the parser will verify
that it is equal to the name of the MBB with the specified id.
Reviewers: Duncan P. N. Exon Smith
Differential Revision: http://reviews.llvm.org/D10608
llvm-svn: 240792
Diffstat (limited to 'llvm/lib/CodeGen/MIRParser/MIRParser.cpp')
-rw-r--r-- | llvm/lib/CodeGen/MIRParser/MIRParser.cpp | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/llvm/lib/CodeGen/MIRParser/MIRParser.cpp b/llvm/lib/CodeGen/MIRParser/MIRParser.cpp index 1803116b417..79b2ee6c948 100644 --- a/llvm/lib/CodeGen/MIRParser/MIRParser.cpp +++ b/llvm/lib/CodeGen/MIRParser/MIRParser.cpp @@ -14,6 +14,7 @@ #include "llvm/CodeGen/MIRParser/MIRParser.h" #include "MIParser.h" +#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/STLExtras.h" @@ -81,8 +82,10 @@ public: /// Initialize the machine basic block using it's YAML representation. /// /// Return true if an error occurred. - bool initializeMachineBasicBlock(MachineFunction &MF, MachineBasicBlock &MBB, - const yaml::MachineBasicBlock &YamlMBB); + bool initializeMachineBasicBlock( + MachineFunction &MF, MachineBasicBlock &MBB, + const yaml::MachineBasicBlock &YamlMBB, + const DenseMap<unsigned, MachineBasicBlock *> &MBBSlots); bool initializeRegisterInfo(MachineRegisterInfo &RegInfo, const yaml::MachineFunction &YamlMF); @@ -220,6 +223,7 @@ bool MIRParserImpl::initializeMachineFunction(MachineFunction &MF) { return true; const auto &F = *MF.getFunction(); + DenseMap<unsigned, MachineBasicBlock *> MBBSlots; for (const auto &YamlMBB : YamlMF.BasicBlocks) { const BasicBlock *BB = nullptr; if (!YamlMBB.Name.empty()) { @@ -231,7 +235,18 @@ bool MIRParserImpl::initializeMachineFunction(MachineFunction &MF) { } auto *MBB = MF.CreateMachineBasicBlock(BB); MF.insert(MF.end(), MBB); - if (initializeMachineBasicBlock(MF, *MBB, YamlMBB)) + bool WasInserted = MBBSlots.insert(std::make_pair(YamlMBB.ID, MBB)).second; + if (!WasInserted) + return error(Twine("redefinition of machine basic block with id #") + + Twine(YamlMBB.ID)); + } + + // Initialize the machine basic blocks after creating them all so that the + // machine instructions parser can resolve the MBB references. + unsigned I = 0; + for (const auto &YamlMBB : YamlMF.BasicBlocks) { + if (initializeMachineBasicBlock(MF, *MF.getBlockNumbered(I++), YamlMBB, + MBBSlots)) return true; } return false; @@ -239,7 +254,8 @@ bool MIRParserImpl::initializeMachineFunction(MachineFunction &MF) { bool MIRParserImpl::initializeMachineBasicBlock( MachineFunction &MF, MachineBasicBlock &MBB, - const yaml::MachineBasicBlock &YamlMBB) { + const yaml::MachineBasicBlock &YamlMBB, + const DenseMap<unsigned, MachineBasicBlock *> &MBBSlots) { MBB.setAlignment(YamlMBB.Alignment); if (YamlMBB.AddressTaken) MBB.setHasAddressTaken(); @@ -247,7 +263,7 @@ bool MIRParserImpl::initializeMachineBasicBlock( // Parse the instructions. for (const auto &MISource : YamlMBB.Instructions) { SMDiagnostic Error; - if (auto *MI = parseMachineInstr(SM, MF, MISource.Value, Error)) { + if (auto *MI = parseMachineInstr(SM, MF, MISource.Value, MBBSlots, Error)) { MBB.insert(MBB.end(), MI); continue; } |