diff options
author | Alex Lorenz <arphaman@gmail.com> | 2015-06-19 17:43:07 +0000 |
---|---|---|
committer | Alex Lorenz <arphaman@gmail.com> | 2015-06-19 17:43:07 +0000 |
commit | 4f093bf1ce0c6b4c9cd4472fbaa0b2b0a942a38c (patch) | |
tree | 684ec16865e23a9fecaf0e197b6f69115ae8e5c2 /llvm/lib/CodeGen | |
parent | 4d8ffa082c19eeb6c07ec3f82b06604d66c18949 (diff) | |
download | bcm5719-llvm-4f093bf1ce0c6b4c9cd4472fbaa0b2b0a942a38c.tar.gz bcm5719-llvm-4f093bf1ce0c6b4c9cd4472fbaa0b2b0a942a38c.zip |
MIR Serialization: Serialize the list of machine basic blocks with simple attributes.
This commit implements the initial serialization of machine basic blocks in a
machine function. Only the simple, scalar MBB attributes are serialized. The
reference to LLVM IR's basic block is preserved when that basic block has a name.
Reviewers: Duncan P. N. Exon Smith
Differential Revision: http://reviews.llvm.org/D10465
llvm-svn: 240145
Diffstat (limited to 'llvm/lib/CodeGen')
-rw-r--r-- | llvm/lib/CodeGen/MIRParser/MIRParser.cpp | 30 | ||||
-rw-r--r-- | llvm/lib/CodeGen/MIRPrinter.cpp | 20 |
2 files changed, 50 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/MIRParser/MIRParser.cpp b/llvm/lib/CodeGen/MIRParser/MIRParser.cpp index 8fe4c838000..20d7f815655 100644 --- a/llvm/lib/CodeGen/MIRParser/MIRParser.cpp +++ b/llvm/lib/CodeGen/MIRParser/MIRParser.cpp @@ -19,10 +19,12 @@ #include "llvm/AsmParser/Parser.h" #include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MIRYamlMapping.h" +#include "llvm/IR/BasicBlock.h" #include "llvm/IR/DiagnosticInfo.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Module.h" +#include "llvm/IR/ValueSymbolTable.h" #include "llvm/Support/LineIterator.h" #include "llvm/Support/SMLoc.h" #include "llvm/Support/SourceMgr.h" @@ -74,6 +76,12 @@ public: /// Return true if error occurred. bool initializeMachineFunction(MachineFunction &MF); + /// Initialize the machine basic block using it's YAML representation. + /// + /// Return true if an error occurred. + bool initializeMachineBasicBlock(MachineBasicBlock &MBB, + const yaml::MachineBasicBlock &YamlMBB); + private: /// Return a MIR diagnostic converted from an LLVM assembly diagnostic. SMDiagnostic diagFromLLVMAssemblyDiag(const SMDiagnostic &Error, @@ -198,6 +206,28 @@ bool MIRParserImpl::initializeMachineFunction(MachineFunction &MF) { MF.setAlignment(YamlMF.Alignment); MF.setExposesReturnsTwice(YamlMF.ExposesReturnsTwice); MF.setHasInlineAsm(YamlMF.HasInlineAsm); + const auto &F = *MF.getFunction(); + for (const auto &YamlMBB : YamlMF.BasicBlocks) { + const BasicBlock *BB = nullptr; + if (!YamlMBB.Name.empty()) { + BB = dyn_cast_or_null<BasicBlock>( + F.getValueSymbolTable().lookup(YamlMBB.Name)); + // TODO: Report an error if a basic block isn't found. + } + auto *MBB = MF.CreateMachineBasicBlock(BB); + MF.insert(MF.end(), MBB); + if (initializeMachineBasicBlock(*MBB, YamlMBB)) + return true; + } + return false; +} + +bool MIRParserImpl::initializeMachineBasicBlock( + MachineBasicBlock &MBB, const yaml::MachineBasicBlock &YamlMBB) { + MBB.setAlignment(YamlMBB.Alignment); + if (YamlMBB.AddressTaken) + MBB.setHasAddressTaken(); + MBB.setIsLandingPad(YamlMBB.IsLandingPad); return false; } diff --git a/llvm/lib/CodeGen/MIRPrinter.cpp b/llvm/lib/CodeGen/MIRPrinter.cpp index b2bb2f9278d..bbf163a759e 100644 --- a/llvm/lib/CodeGen/MIRPrinter.cpp +++ b/llvm/lib/CodeGen/MIRPrinter.cpp @@ -16,6 +16,7 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MIRYamlMapping.h" +#include "llvm/IR/BasicBlock.h" #include "llvm/IR/Module.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/raw_ostream.h" @@ -34,6 +35,8 @@ public: MIRPrinter(raw_ostream &OS) : OS(OS) {} void print(const MachineFunction &MF); + + void convert(yaml::MachineBasicBlock &YamlMBB, const MachineBasicBlock &MBB); }; } // end anonymous namespace @@ -61,10 +64,27 @@ void MIRPrinter::print(const MachineFunction &MF) { YamlMF.Alignment = MF.getAlignment(); YamlMF.ExposesReturnsTwice = MF.exposesReturnsTwice(); YamlMF.HasInlineAsm = MF.hasInlineAsm(); + for (const auto &MBB : MF) { + yaml::MachineBasicBlock YamlMBB; + convert(YamlMBB, MBB); + YamlMF.BasicBlocks.push_back(YamlMBB); + } yaml::Output Out(OS); Out << YamlMF; } +void MIRPrinter::convert(yaml::MachineBasicBlock &YamlMBB, + const MachineBasicBlock &MBB) { + // TODO: Serialize unnamed BB references. + if (const auto *BB = MBB.getBasicBlock()) + YamlMBB.Name = BB->hasName() ? BB->getName() : "<unnamed bb>"; + else + YamlMBB.Name = ""; + YamlMBB.Alignment = MBB.getAlignment(); + YamlMBB.AddressTaken = MBB.hasAddressTaken(); + YamlMBB.IsLandingPad = MBB.isLandingPad(); +} + void llvm::printMIR(raw_ostream &OS, const Module &M) { yaml::Output Out(OS); Out << const_cast<Module &>(M); |