<div dir="ltr">I've reverted this commit for now as it caused the incremental buildbots to become unstable - they sometimes pass but sometimes fail with one of the tests here.</div><div class="gmail_extra"><br><div class="gmail_quote">2015-05-19 11:17 GMT-07:00 Alex Lorenz <span dir="ltr"><<a href="mailto:arphaman@gmail.com" target="_blank">arphaman@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: arphaman<br>
Date: Tue May 19 13:17:39 2015<br>
New Revision: 237708<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=237708&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=237708&view=rev</a><br>
Log:<br>
MIR Serialization: print and parse LLVM IR using MIR format.<br>
<br>
This commit is the initial commit for the MIR serialization project.<br>
It creates a new library under CodeGen called 'MIR'. This new<br>
library adds a new machine function pass that prints out the LLVM IR<br>
using the MIR format. This pass is then added as a last pass when a<br>
'stop-after' option is used in llc. The new library adds the initial<br>
functionality for parsing of MIR files as well. This commit also<br>
extends the llc tool so that it can recognize and parse MIR input files.<br>
<br>
Reviewers: Duncan P. N. Exon Smith, Matthias Braun, Philip Reames<br>
<br>
Differential Revision: <a href="http://reviews.llvm.org/D9616" target="_blank">http://reviews.llvm.org/D9616</a><br>
<br>
Added:<br>
llvm/trunk/include/llvm/CodeGen/MIR/<br>
llvm/trunk/include/llvm/CodeGen/MIR/MIRParser.h<br>
llvm/trunk/lib/CodeGen/MIR/<br>
llvm/trunk/lib/CodeGen/MIR/CMakeLists.txt<br>
llvm/trunk/lib/CodeGen/MIR/LLVMBuild.txt<br>
llvm/trunk/lib/CodeGen/MIR/MIRParser.cpp<br>
llvm/trunk/lib/CodeGen/MIR/MIRPrinter.cpp<br>
llvm/trunk/lib/CodeGen/MIR/MIRPrinter.h<br>
llvm/trunk/lib/CodeGen/MIR/MIRPrintingPass.cpp<br>
llvm/trunk/lib/CodeGen/MIR/Makefile<br>
llvm/trunk/test/CodeGen/MIR/<br>
llvm/trunk/test/CodeGen/MIR/lit.local.cfg<br>
llvm/trunk/test/CodeGen/MIR/llvmIR.mir<br>
llvm/trunk/test/CodeGen/MIR/llvmIRMissing.mir<br>
Modified:<br>
llvm/trunk/include/llvm/CodeGen/Passes.h<br>
llvm/trunk/include/llvm/InitializePasses.h<br>
llvm/trunk/include/llvm/Support/YAMLTraits.h<br>
llvm/trunk/lib/CodeGen/CMakeLists.txt<br>
llvm/trunk/lib/CodeGen/LLVMBuild.txt<br>
llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp<br>
llvm/trunk/lib/CodeGen/Makefile<br>
llvm/trunk/lib/Support/YAMLTraits.cpp<br>
llvm/trunk/test/CodeGen/Generic/stop-after.ll<br>
llvm/trunk/tools/llc/llc.cpp<br>
<br>
Added: llvm/trunk/include/llvm/CodeGen/MIR/MIRParser.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MIR/MIRParser.h?rev=237708&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MIR/MIRParser.h?rev=237708&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/CodeGen/MIR/MIRParser.h (added)<br>
+++ llvm/trunk/include/llvm/CodeGen/MIR/MIRParser.h Tue May 19 13:17:39 2015<br>
@@ -0,0 +1,52 @@<br>
+//===- MIRParser.h - MIR serialization format parser ----------------------===//<br>
+//<br>
+// The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+//<br>
+// This MIR serialization library is currently a work in progress. It can't<br>
+// serialize machine functions at this time.<br>
+//<br>
+// This file declares the functions that parse the MIR serialization format<br>
+// files.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#ifndef LLVM_CODEGEN_MIR_MIRPARSER_H<br>
+#define LLVM_CODEGEN_MIR_MIRPARSER_H<br>
+<br>
+#include "llvm/ADT/StringRef.h"<br>
+#include "llvm/IR/Module.h"<br>
+#include "llvm/Support/MemoryBuffer.h"<br>
+#include <memory><br>
+<br>
+namespace llvm {<br>
+<br>
+class SMDiagnostic;<br>
+<br>
+/// This function is the main interface to the MIR serialization format parser.<br>
+///<br>
+/// It reads a YAML file that has an optional LLVM IR and returns an LLVM<br>
+/// module.<br>
+/// \param Filename - The name of the file to parse.<br>
+/// \param Error - Error result info.<br>
+/// \param Context - Context in which to allocate globals info.<br>
+std::unique_ptr<Module> parseMIRFile(StringRef Filename, SMDiagnostic &Error,<br>
+ LLVMContext &Context);<br>
+<br>
+/// This function is another interface to the MIR serialization format parser.<br>
+///<br>
+/// It parses the optional LLVM IR in the given buffer, and returns an LLVM<br>
+/// module.<br>
+/// \param Contents - The MemoryBuffer containing the machine level IR.<br>
+/// \param Error - Error result info.<br>
+/// \param Context - Context in which to allocate globals info.<br>
+std::unique_ptr<Module> parseMIR(std::unique_ptr<MemoryBuffer> Contents,<br>
+ SMDiagnostic &Error, LLVMContext &Context);<br>
+<br>
+} // end namespace llvm<br>
+<br>
+#endif<br>
<br>
Modified: llvm/trunk/include/llvm/CodeGen/Passes.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/Passes.h?rev=237708&r1=237707&r2=237708&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/Passes.h?rev=237708&r1=237707&r2=237708&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/CodeGen/Passes.h (original)<br>
+++ llvm/trunk/include/llvm/CodeGen/Passes.h Tue May 19 13:17:39 2015<br>
@@ -374,6 +374,10 @@ namespace llvm {<br>
createMachineFunctionPrinterPass(raw_ostream &OS,<br>
const std::string &Banner ="");<br>
<br>
+ /// MIRPrinting pass - this pass prints out the LLVM IR into the given stream<br>
+ /// using the MIR serialization format.<br>
+ MachineFunctionPass *createPrintMIRPass(raw_ostream &OS);<br>
+<br>
/// createCodeGenPreparePass - Transform the code to expose more pattern<br>
/// matching during instruction selection.<br>
FunctionPass *createCodeGenPreparePass(const TargetMachine *TM = nullptr);<br>
@@ -488,6 +492,10 @@ namespace llvm {<br>
/// MachineFunctionPrinterPass - This pass prints out MachineInstr's.<br>
extern char &MachineFunctionPrinterPassID;<br>
<br>
+ /// MIRPrintingPass - this pass prints out the LLVM IR using the MIR<br>
+ /// serialization format.<br>
+ extern char &MIRPrintingPassID;<br>
+<br>
/// TailDuplicate - Duplicate blocks with unconditional branches<br>
/// into tails of their predecessors.<br>
extern char &TailDuplicateID;<br>
<br>
Modified: llvm/trunk/include/llvm/InitializePasses.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/InitializePasses.h?rev=237708&r1=237707&r2=237708&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/InitializePasses.h?rev=237708&r1=237707&r2=237708&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/InitializePasses.h (original)<br>
+++ llvm/trunk/include/llvm/InitializePasses.h Tue May 19 13:17:39 2015<br>
@@ -289,6 +289,7 @@ void initializeLoopVectorizePass(PassReg<br>
void initializeSLPVectorizerPass(PassRegistry&);<br>
void initializeBBVectorizePass(PassRegistry&);<br>
void initializeMachineFunctionPrinterPassPass(PassRegistry&);<br>
+void initializeMIRPrintingPassPass(PassRegistry&);<br>
void initializeStackMapLivenessPass(PassRegistry&);<br>
void initializeMachineCombinerPass(PassRegistry &);<br>
void initializeLoadCombinePass(PassRegistry&);<br>
<br>
Modified: llvm/trunk/include/llvm/Support/YAMLTraits.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/YAMLTraits.h?rev=237708&r1=237707&r2=237708&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/YAMLTraits.h?rev=237708&r1=237707&r2=237708&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/Support/YAMLTraits.h (original)<br>
+++ llvm/trunk/include/llvm/Support/YAMLTraits.h Tue May 19 13:17:39 2015<br>
@@ -1090,6 +1090,9 @@ public:<br>
bool setCurrentDocument();<br>
bool nextDocument();<br>
<br>
+ /// Returns the current node that's being parsed by the YAML Parser.<br>
+ const Node *getCurrentNode() const;<br>
+<br>
private:<br>
llvm::SourceMgr SrcMgr; // must be before Strm<br>
std::unique_ptr<llvm::yaml::Stream> Strm;<br>
<br>
Modified: llvm/trunk/lib/CodeGen/CMakeLists.txt<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/CMakeLists.txt?rev=237708&r1=237707&r2=237708&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/CMakeLists.txt?rev=237708&r1=237707&r2=237708&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/CMakeLists.txt (original)<br>
+++ llvm/trunk/lib/CodeGen/CMakeLists.txt Tue May 19 13:17:39 2015<br>
@@ -128,3 +128,4 @@ add_dependencies(LLVMCodeGen intrinsics_<br>
<br>
add_subdirectory(SelectionDAG)<br>
add_subdirectory(AsmPrinter)<br>
+add_subdirectory(MIR)<br>
<br>
Modified: llvm/trunk/lib/CodeGen/LLVMBuild.txt<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LLVMBuild.txt?rev=237708&r1=237707&r2=237708&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LLVMBuild.txt?rev=237708&r1=237707&r2=237708&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/LLVMBuild.txt (original)<br>
+++ llvm/trunk/lib/CodeGen/LLVMBuild.txt Tue May 19 13:17:39 2015<br>
@@ -16,10 +16,10 @@<br>
;===------------------------------------------------------------------------===;<br>
<br>
[common]<br>
-subdirectories = AsmPrinter SelectionDAG<br>
+subdirectories = AsmPrinter SelectionDAG MIR<br>
<br>
[component_0]<br>
type = Library<br>
name = CodeGen<br>
parent = Libraries<br>
-required_libraries = Analysis Core MC Scalar Support Target TransformUtils<br>
+required_libraries = Analysis Core MC Scalar Support Target TransformUtils MIR<br>
<br>
Modified: llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp?rev=237708&r1=237707&r2=237708&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp?rev=237708&r1=237707&r2=237708&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp Tue May 19 13:17:39 2015<br>
@@ -150,12 +150,7 @@ bool LLVMTargetMachine::addPassesToEmitF<br>
return true;<br>
<br>
if (StopAfter) {<br>
- // FIXME: The intent is that this should eventually write out a YAML file,<br>
- // containing the LLVM IR, the machine-level IR (when stopping after a<br>
- // machine-level pass), and whatever other information is needed to<br>
- // deserialize the code and resume compilation. For now, just write the<br>
- // LLVM IR.<br>
- PM.add(createPrintModulePass(Out));<br>
+ PM.add(createPrintMIRPass(outs()));<br>
return false;<br>
}<br>
<br>
<br>
Added: llvm/trunk/lib/CodeGen/MIR/CMakeLists.txt<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIR/CMakeLists.txt?rev=237708&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIR/CMakeLists.txt?rev=237708&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/MIR/CMakeLists.txt (added)<br>
+++ llvm/trunk/lib/CodeGen/MIR/CMakeLists.txt Tue May 19 13:17:39 2015<br>
@@ -0,0 +1,7 @@<br>
+add_llvm_library(LLVMMIR<br>
+ MIRPrinter.cpp<br>
+ MIRPrintingPass.cpp<br>
+ MIRParser.cpp<br>
+ )<br>
+<br>
+add_dependencies(LLVMMIR intrinsics_gen)<br>
<br>
Added: llvm/trunk/lib/CodeGen/MIR/LLVMBuild.txt<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIR/LLVMBuild.txt?rev=237708&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIR/LLVMBuild.txt?rev=237708&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/MIR/LLVMBuild.txt (added)<br>
+++ llvm/trunk/lib/CodeGen/MIR/LLVMBuild.txt Tue May 19 13:17:39 2015<br>
@@ -0,0 +1,22 @@<br>
+;===- ./lib/CodeGen/MIR/LLVMBuild.txt --------------------------*- Conf -*--===;<br>
+;<br>
+; The LLVM Compiler Infrastructure<br>
+;<br>
+; This file is distributed under the University of Illinois Open Source<br>
+; License. See LICENSE.TXT for details.<br>
+;<br>
+;===------------------------------------------------------------------------===;<br>
+;<br>
+; This is an LLVMBuild description file for the components in this subdirectory.<br>
+;<br>
+; For more information on the LLVMBuild system, please see:<br>
+;<br>
+; <a href="http://llvm.org/docs/LLVMBuild.html" target="_blank">http://llvm.org/docs/LLVMBuild.html</a><br>
+;<br>
+;===------------------------------------------------------------------------===;<br>
+<br>
+[component_0]<br>
+type = Library<br>
+name = MIR<br>
+parent = CodeGen<br>
+required_libraries = Core Support Target AsmParser<br>
<br>
Added: llvm/trunk/lib/CodeGen/MIR/MIRParser.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIR/MIRParser.cpp?rev=237708&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIR/MIRParser.cpp?rev=237708&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/MIR/MIRParser.cpp (added)<br>
+++ llvm/trunk/lib/CodeGen/MIR/MIRParser.cpp Tue May 19 13:17:39 2015<br>
@@ -0,0 +1,90 @@<br>
+//===- MIRParser.cpp - MIR serialization format parser implementation -----===//<br>
+//<br>
+// The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+//<br>
+// This file implements the class that parses the optional LLVM IR and machine<br>
+// functions that are stored in MIR files.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#include "llvm/CodeGen/MIR/MIRParser.h"<br>
+#include "llvm/ADT/StringRef.h"<br>
+#include "llvm/ADT/STLExtras.h"<br>
+#include "llvm/AsmParser/Parser.h"<br>
+#include "llvm/IR/Module.h"<br>
+#include "llvm/Support/SMLoc.h"<br>
+#include "llvm/Support/SourceMgr.h"<br>
+#include "llvm/Support/MemoryBuffer.h"<br>
+#include "llvm/Support/YAMLTraits.h"<br>
+#include <memory><br>
+<br>
+using namespace llvm;<br>
+<br>
+namespace {<br>
+<br>
+/// This class implements the parsing of LLVM IR that's embedded inside a MIR<br>
+/// file.<br>
+class MIRParserImpl {<br>
+ SourceMgr SM;<br>
+ StringRef Filename;<br>
+ LLVMContext &Context;<br>
+<br>
+public:<br>
+ MIRParserImpl(std::unique_ptr<MemoryBuffer> Contents, StringRef Filename,<br>
+ LLVMContext &Context);<br>
+<br>
+ /// Try to parse the optional LLVM module in the MIR file.<br>
+ ///<br>
+ /// Return null if an error occurred while parsing the LLVM module.<br>
+ std::unique_ptr<Module> parseLLVMModule(SMDiagnostic &Error);<br>
+};<br>
+<br>
+} // end anonymous namespace<br>
+<br>
+MIRParserImpl::MIRParserImpl(std::unique_ptr<MemoryBuffer> Contents,<br>
+ StringRef Filename, LLVMContext &Context)<br>
+ : SM(), Filename(Filename), Context(Context) {<br>
+ SM.AddNewSourceBuffer(std::move(Contents), SMLoc());<br>
+}<br>
+<br>
+std::unique_ptr<Module> MIRParserImpl::parseLLVMModule(SMDiagnostic &Error) {<br>
+ yaml::Input In(SM.getMemoryBuffer(SM.getMainFileID())->getBuffer());<br>
+<br>
+ // Parse the block scalar manually so that we can return unique pointer<br>
+ // without having to go trough YAML traits.<br>
+ if (In.setCurrentDocument()) {<br>
+ if (const auto *BSN =<br>
+ dyn_cast_or_null<yaml::BlockScalarNode>(In.getCurrentNode())) {<br>
+ return parseAssembly(MemoryBufferRef(BSN->getValue(), Filename), Error,<br>
+ Context);<br>
+ }<br>
+ }<br>
+<br>
+ // Create an new, empty module.<br>
+ return llvm::make_unique<Module>(Filename, Context);<br>
+}<br>
+<br>
+std::unique_ptr<Module> llvm::parseMIRFile(StringRef Filename,<br>
+ SMDiagnostic &Error,<br>
+ LLVMContext &Context) {<br>
+ auto FileOrErr = MemoryBuffer::getFile(Filename);<br>
+ if (std::error_code EC = FileOrErr.getError()) {<br>
+ Error = SMDiagnostic(Filename, SourceMgr::DK_Error,<br>
+ "Could not open input file: " + EC.message());<br>
+ return std::unique_ptr<Module>();<br>
+ }<br>
+ return parseMIR(std::move(FileOrErr.get()), Error, Context);<br>
+}<br>
+<br>
+std::unique_ptr<Module> llvm::parseMIR(std::unique_ptr<MemoryBuffer> Contents,<br>
+ SMDiagnostic &Error,<br>
+ LLVMContext &Context) {<br>
+ auto Filename = Contents->getBufferIdentifier();<br>
+ MIRParserImpl Parser(std::move(Contents), Filename, Context);<br>
+ return Parser.parseLLVMModule(Error);<br>
+}<br>
<br>
Added: llvm/trunk/lib/CodeGen/MIR/MIRPrinter.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIR/MIRPrinter.cpp?rev=237708&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIR/MIRPrinter.cpp?rev=237708&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/MIR/MIRPrinter.cpp (added)<br>
+++ llvm/trunk/lib/CodeGen/MIR/MIRPrinter.cpp Tue May 19 13:17:39 2015<br>
@@ -0,0 +1,66 @@<br>
+//===- MIRPrinter.cpp - MIR serialization format printer ------------------===//<br>
+//<br>
+// The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+//<br>
+// This file implements the class that prints out the LLVM IR and machine<br>
+// functions using the MIR serialization format.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#include "MIRPrinter.h"<br>
+#include "llvm/ADT/STLExtras.h"<br>
+#include "llvm/IR/Module.h"<br>
+#include "llvm/Support/MemoryBuffer.h"<br>
+#include "llvm/Support/raw_ostream.h"<br>
+#include "llvm/Support/YAMLTraits.h"<br>
+<br>
+using namespace llvm;<br>
+<br>
+namespace {<br>
+<br>
+/// This class prints out the LLVM IR using the MIR serialization format and<br>
+/// YAML I/O.<br>
+class MIRPrinter {<br>
+ raw_ostream &OS;<br>
+<br>
+public:<br>
+ MIRPrinter(raw_ostream &OS);<br>
+<br>
+ void printModule(const Module &Mod);<br>
+};<br>
+<br>
+} // end anonymous namespace<br>
+<br>
+namespace llvm {<br>
+namespace yaml {<br>
+<br>
+/// This struct serializes the LLVM IR module.<br>
+template <> struct BlockScalarTraits<Module> {<br>
+ static void output(const Module &Mod, void *Ctxt, raw_ostream &OS) {<br>
+ Mod.print(OS, nullptr);<br>
+ }<br>
+ static StringRef input(StringRef Str, void *Ctxt, Module &Mod) {<br>
+ llvm_unreachable("LLVM Module is supposed to be parsed separately");<br>
+ return "";<br>
+ }<br>
+};<br>
+<br>
+} // end namespace yaml<br>
+} // end namespace llvm<br>
+<br>
+MIRPrinter::MIRPrinter(raw_ostream &OS) : OS(OS) {}<br>
+<br>
+void MIRPrinter::printModule(const Module &Mod) {<br>
+ yaml::Output Out(OS);<br>
+ Out << const_cast<Module &>(Mod);<br>
+}<br>
+<br>
+void llvm::printMIR(raw_ostream &OS, const Module &Mod) {<br>
+ MIRPrinter Printer(OS);<br>
+ Printer.printModule(Mod);<br>
+}<br>
<br>
Added: llvm/trunk/lib/CodeGen/MIR/MIRPrinter.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIR/MIRPrinter.h?rev=237708&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIR/MIRPrinter.h?rev=237708&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/MIR/MIRPrinter.h (added)<br>
+++ llvm/trunk/lib/CodeGen/MIR/MIRPrinter.h Tue May 19 13:17:39 2015<br>
@@ -0,0 +1,29 @@<br>
+//===- MIRPrinter.h - MIR serialization format printer --------------------===//<br>
+//<br>
+// The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+//<br>
+// This file declares the function that prints out the LLVM IR using the MIR<br>
+// serialization format.<br>
+// TODO: Print out machine functions.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#ifndef LLVM_LIB_CODEGEN_MIR_MIRPRINTER_H<br>
+#define LLVM_LIB_CODEGEN_MIR_MIRPRINTER_H<br>
+<br>
+namespace llvm {<br>
+<br>
+class Module;<br>
+class raw_ostream;<br>
+<br>
+/// Print LLVM IR using the MIR serialization format to the given output stream.<br>
+void printMIR(raw_ostream &OS, const Module &Mod);<br>
+<br>
+} // end namespace llvm<br>
+<br>
+#endif<br>
<br>
Added: llvm/trunk/lib/CodeGen/MIR/MIRPrintingPass.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIR/MIRPrintingPass.cpp?rev=237708&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIR/MIRPrintingPass.cpp?rev=237708&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/MIR/MIRPrintingPass.cpp (added)<br>
+++ llvm/trunk/lib/CodeGen/MIR/MIRPrintingPass.cpp Tue May 19 13:17:39 2015<br>
@@ -0,0 +1,66 @@<br>
+//===- MIRPrintingPass.cpp - Pass that prints out using the MIR format ----===//<br>
+//<br>
+// The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+//<br>
+// This file implements a pass that prints out the LLVM module using the MIR<br>
+// serialization format.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#include "MIRPrinter.h"<br>
+#include "llvm/CodeGen/Passes.h"<br>
+#include "llvm/CodeGen/MachineFunction.h"<br>
+#include "llvm/CodeGen/MachineFunctionPass.h"<br>
+#include "llvm/Support/Debug.h"<br>
+#include "llvm/Support/raw_ostream.h"<br>
+<br>
+using namespace llvm;<br>
+<br>
+namespace {<br>
+<br>
+/// This pass prints out the LLVM IR to an output stream using the MIR<br>
+/// serialization format.<br>
+struct MIRPrintingPass : public MachineFunctionPass {<br>
+ static char ID;<br>
+ raw_ostream &OS;<br>
+<br>
+ MIRPrintingPass() : MachineFunctionPass(ID), OS(dbgs()) {}<br>
+ MIRPrintingPass(raw_ostream &OS) : MachineFunctionPass(ID), OS(OS) {}<br>
+<br>
+ const char *getPassName() const override { return "MIR Printing Pass"; }<br>
+<br>
+ void getAnalysisUsage(AnalysisUsage &AU) const override {<br>
+ AU.setPreservesAll();<br>
+ MachineFunctionPass::getAnalysisUsage(AU);<br>
+ }<br>
+<br>
+ virtual bool runOnMachineFunction(MachineFunction &MF) override {<br>
+ // TODO: Print out the machine function.<br>
+ return false;<br>
+ }<br>
+<br>
+ virtual bool doFinalization(Module &M) override {<br>
+ printMIR(OS, M);<br>
+ return false;<br>
+ }<br>
+};<br>
+<br>
+char MIRPrintingPass::ID = 0;<br>
+<br>
+} // end anonymous namespace<br>
+<br>
+char &llvm::MIRPrintingPassID = MIRPrintingPass::ID;<br>
+INITIALIZE_PASS(MIRPrintingPass, "mir-printer", "MIR Printer", false, false)<br>
+<br>
+namespace llvm {<br>
+<br>
+MachineFunctionPass *createPrintMIRPass(raw_ostream &OS) {<br>
+ return new MIRPrintingPass(OS);<br>
+}<br>
+<br>
+} // end namespace llvm<br>
<br>
Added: llvm/trunk/lib/CodeGen/MIR/Makefile<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIR/Makefile?rev=237708&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIR/Makefile?rev=237708&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/MIR/Makefile (added)<br>
+++ llvm/trunk/lib/CodeGen/MIR/Makefile Tue May 19 13:17:39 2015<br>
@@ -0,0 +1,13 @@<br>
+##===- lib/CodeGen/MIR/Makefile ----------------------------*- Makefile -*-===##<br>
+#<br>
+# The LLVM Compiler Infrastructure<br>
+#<br>
+# This file is distributed under the University of Illinois Open Source<br>
+# License. See LICENSE.TXT for details.<br>
+#<br>
+##===----------------------------------------------------------------------===##<br>
+<br>
+LEVEL = ../../..<br>
+LIBRARYNAME = LLVMMIR<br>
+<br>
+include $(LEVEL)/Makefile.common<br>
<br>
Modified: llvm/trunk/lib/CodeGen/Makefile<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/Makefile?rev=237708&r1=237707&r2=237708&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/Makefile?rev=237708&r1=237707&r2=237708&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/Makefile (original)<br>
+++ llvm/trunk/lib/CodeGen/Makefile Tue May 19 13:17:39 2015<br>
@@ -9,7 +9,7 @@<br>
<br>
LEVEL = ../..<br>
LIBRARYNAME = LLVMCodeGen<br>
-PARALLEL_DIRS = SelectionDAG AsmPrinter<br>
+PARALLEL_DIRS = SelectionDAG AsmPrinter MIR<br>
BUILD_ARCHIVE = 1<br>
<br>
include $(LEVEL)/Makefile.common<br>
<br>
Modified: llvm/trunk/lib/Support/YAMLTraits.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/YAMLTraits.cpp?rev=237708&r1=237707&r2=237708&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/YAMLTraits.cpp?rev=237708&r1=237707&r2=237708&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Support/YAMLTraits.cpp (original)<br>
+++ llvm/trunk/lib/Support/YAMLTraits.cpp Tue May 19 13:17:39 2015<br>
@@ -97,6 +97,10 @@ bool Input::nextDocument() {<br>
return ++DocIterator != Strm->end();<br>
}<br>
<br>
+const Node *Input::getCurrentNode() const {<br>
+ return CurrentNode ? CurrentNode->_node : nullptr;<br>
+}<br>
+<br>
bool Input::mapTag(StringRef Tag, bool Default) {<br>
std::string foundTag = CurrentNode->_node->getVerbatimTag();<br>
if (foundTag.empty()) {<br>
<br>
Modified: llvm/trunk/test/CodeGen/Generic/stop-after.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Generic/stop-after.ll?rev=237708&r1=237707&r2=237708&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Generic/stop-after.ll?rev=237708&r1=237707&r2=237708&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/test/CodeGen/Generic/stop-after.ll (original)<br>
+++ llvm/trunk/test/CodeGen/Generic/stop-after.ll Tue May 19 13:17:39 2015<br>
@@ -1,9 +1,10 @@<br>
; RUN: llc < %s -debug-pass=Structure -stop-after=loop-reduce -o /dev/null 2>&1 | FileCheck %s -check-prefix=STOP<br>
; RUN: llc < %s -debug-pass=Structure -start-after=loop-reduce -o /dev/null 2>&1 | FileCheck %s -check-prefix=START<br>
<br>
-; STOP: -loop-reduce -print-module<br>
+; STOP: -loop-reduce<br>
; STOP: Loop Strength Reduction<br>
; STOP-NEXT: Machine Function Analysis<br>
+; STOP-NEXT: MIR Printing Pass<br>
<br>
; START: -machine-branch-prob -gc-lowering<br>
; START: FunctionPass Manager<br>
<br>
Added: llvm/trunk/test/CodeGen/MIR/lit.local.cfg<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/MIR/lit.local.cfg?rev=237708&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/MIR/lit.local.cfg?rev=237708&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/CodeGen/MIR/lit.local.cfg (added)<br>
+++ llvm/trunk/test/CodeGen/MIR/lit.local.cfg Tue May 19 13:17:39 2015<br>
@@ -0,0 +1,2 @@<br>
+config.suffixes = ['.mir']<br>
+<br>
<br>
Added: llvm/trunk/test/CodeGen/MIR/llvmIR.mir<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/MIR/llvmIR.mir?rev=237708&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/MIR/llvmIR.mir?rev=237708&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/CodeGen/MIR/llvmIR.mir (added)<br>
+++ llvm/trunk/test/CodeGen/MIR/llvmIR.mir Tue May 19 13:17:39 2015<br>
@@ -0,0 +1,35 @@<br>
+# RUN: ~/build/llvm/bin/llc -start-after branch-folder -stop-after branch-folder -o /dev/null %s | FileCheck %s<br>
+# This test ensures that the LLVM IR that's embedded with MIR is parsed<br>
+# correctly.<br>
+<br>
+--- |<br>
+ target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"<br>
+ target triple = "x86_64-apple-darwin14.3.0"<br>
+<br>
+ ; CHECK: define i32 @foo(i32 %x, i32 %y)<br>
+ ; CHECK: %z = alloca i32, align 4<br>
+ ; CHECK: store i32 %x, i32* %z, align 4<br>
+ ; CHECK: br label %Test<br>
+ ; CHECK: Test:<br>
+ ; CHECK: %m = load i32, i32* %z, align 4<br>
+ ; CHECK: %cond = icmp eq i32 %y, %m<br>
+ ; CHECK: br i1 %cond, label %IfEqual, label %IfUnequal<br>
+ ; CHECK: IfEqual:<br>
+ ; CHECK: ret i32 1<br>
+ ; CHECK: IfUnequal:<br>
+ ; CHECK: ret i32 0<br>
+ define i32 @foo(i32 %x, i32 %y) {<br>
+ %z = alloca i32, align 4<br>
+ store i32 %x, i32* %z, align 4<br>
+ br label %Test<br>
+ Test:<br>
+ %m = load i32, i32* %z, align 4<br>
+ %cond = icmp eq i32 %y, %m<br>
+ br i1 %cond, label %IfEqual, label %IfUnequal<br>
+ IfEqual:<br>
+ ret i32 1<br>
+ IfUnequal:<br>
+ ret i32 0<br>
+ }<br>
+<br>
+...<br>
<br>
Added: llvm/trunk/test/CodeGen/MIR/llvmIRMissing.mir<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/MIR/llvmIRMissing.mir?rev=237708&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/MIR/llvmIRMissing.mir?rev=237708&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/CodeGen/MIR/llvmIRMissing.mir (added)<br>
+++ llvm/trunk/test/CodeGen/MIR/llvmIRMissing.mir Tue May 19 13:17:39 2015<br>
@@ -0,0 +1,5 @@<br>
+# RUN: ~/build/llvm/bin/llc -start-after branch-folder -stop-after branch-folder -o /dev/null %s<br>
+# This test ensures that the MIR parser accepts files without the LLVM IR.<br>
+<br>
+---<br>
+...<br>
<br>
Modified: llvm/trunk/tools/llc/llc.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llc/llc.cpp?rev=237708&r1=237707&r2=237708&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llc/llc.cpp?rev=237708&r1=237707&r2=237708&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/llc/llc.cpp (original)<br>
+++ llvm/trunk/tools/llc/llc.cpp Tue May 19 13:17:39 2015<br>
@@ -20,6 +20,7 @@<br>
#include "llvm/CodeGen/CommandFlags.h"<br>
#include "llvm/CodeGen/LinkAllAsmWriterComponents.h"<br>
#include "llvm/CodeGen/LinkAllCodegenComponents.h"<br>
+#include "llvm/CodeGen/MIR/MIRParser.h"<br>
#include "llvm/IR/DataLayout.h"<br>
#include "llvm/IR/IRPrintingPasses.h"<br>
#include "llvm/IR/LLVMContext.h"<br>
@@ -109,6 +110,8 @@ GetOutputStream(const char *TargetName,<br>
StringRef IFN = InputFilename;<br>
if (IFN.endswith(".bc") || IFN.endswith(".ll"))<br>
OutputFilename = IFN.drop_back(3);<br>
+ else if (IFN.endswith(".mir"))<br>
+ OutputFilename = IFN.drop_back(4);<br>
else<br>
OutputFilename = IFN;<br>
<br>
@@ -214,7 +217,10 @@ static int compileModule(char **argv, LL<br>
<br>
// If user just wants to list available options, skip module loading<br>
if (!SkipModule) {<br>
- M = parseIRFile(InputFilename, Err, Context);<br>
+ if (StringRef(InputFilename).endswith_lower(".mir"))<br>
+ M = parseMIRFile(InputFilename, Err, Context);<br>
+ else<br>
+ M = parseIRFile(InputFilename, Err, Context);<br>
if (!M) {<br>
Err.print(argv[0], errs());<br>
return 1;<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>