From: Matthias Braun Date: Tue, 6 Jun 2017 20:06:57 +0000 (+0000) Subject: llc: Add ability to parse mir from stdin X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f632627ec767551f87ea469c02b4e9b1637fd1f9;p=llvm llc: Add ability to parse mir from stdin - Add -x option to switch between IR and MIR inputs. - Change MIR parser to read from stdin when filename is '-'. - Add a simple mir roundtrip test. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@304825 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/MIRParser/MIRParser.cpp b/lib/CodeGen/MIRParser/MIRParser.cpp index cdeba007458..78b57f35778 100644 --- a/lib/CodeGen/MIRParser/MIRParser.cpp +++ b/lib/CodeGen/MIRParser/MIRParser.cpp @@ -869,7 +869,7 @@ bool MIRParser::parseMachineFunctions(Module &M, MachineModuleInfo &MMI) { std::unique_ptr llvm::createMIRParserFromFile(StringRef Filename, SMDiagnostic &Error, LLVMContext &Context) { - auto FileOrErr = MemoryBuffer::getFile(Filename); + auto FileOrErr = MemoryBuffer::getFileOrSTDIN(Filename); if (std::error_code EC = FileOrErr.getError()) { Error = SMDiagnostic(Filename, SourceMgr::DK_Error, "Could not open input file: " + EC.message()); diff --git a/test/CodeGen/MIR/X86/roundtrip.mir b/test/CodeGen/MIR/X86/roundtrip.mir new file mode 100644 index 00000000000..c697f730604 --- /dev/null +++ b/test/CodeGen/MIR/X86/roundtrip.mir @@ -0,0 +1,20 @@ +# RUN: llc -o - %s -mtriple=x86_64-- -run-pass=none | llc -o - -x mir - -mtriple=x86_64-- -run-pass=none | FileCheck %s +--- +# CHECK-LABEL: name: func0 +# CHECK: registers: +# CHECK: - { id: 0, class: gr32, preferred-register: '' } +# CHECK: - { id: 1, class: gr32, preferred-register: '' } +# CHECK: body: | +# CHECK: bb.0: +# CHECK: %0 = MOV32r0 implicit-def %eflags +# CHECK: dead %1 = COPY %0 +# CHECK: MOV32mr undef %rcx, 1, _, 0, _, killed %0 :: (volatile store 4) +# CHECK: RETQ undef %eax +name: func0 +body: | + bb.0: + %0 : gr32 = MOV32r0 implicit-def %eflags + dead %1 : gr32 = COPY %0 + MOV32mr undef %rcx, 1, _, 0, _, killed %0 :: (volatile store 4) + RETQ undef %eax +... diff --git a/tools/llc/llc.cpp b/tools/llc/llc.cpp index 10fb9f62332..e71c3c5bb70 100644 --- a/tools/llc/llc.cpp +++ b/tools/llc/llc.cpp @@ -61,6 +61,9 @@ using namespace llvm; static cl::opt InputFilename(cl::Positional, cl::desc(""), cl::init("-")); +static cl::opt +InputLanguage("x", cl::desc("Input language ('ir' or 'mir')")); + static cl::opt OutputFilename("o", cl::desc("Output filename"), cl::value_desc("filename")); @@ -335,6 +338,12 @@ int main(int argc, char **argv) { llvm::make_unique(YamlFile->os())); } + if (InputLanguage != "" && InputLanguage != "ir" && + InputLanguage != "mir") { + errs() << argv[0] << "Input language must be '', 'IR' or 'MIR'\n"; + return 1; + } + // Compile the module TimeCompilations times to give better compile time // metrics. for (unsigned I = TimeCompilations; I; --I) @@ -398,7 +407,8 @@ static int compileModule(char **argv, LLVMContext &Context) { // If user just wants to list available options, skip module loading if (!SkipModule) { - if (StringRef(InputFilename).endswith_lower(".mir")) { + if (InputLanguage == "mir" || + (InputLanguage == "" && StringRef(InputFilename).endswith(".mir"))) { MIR = createMIRParserFromFile(InputFilename, Err, Context); if (MIR) M = MIR->parseIRModule();