[llvm] r304825 - llc: Add ability to parse mir from stdin
Matthias Braun via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 6 13:06:57 PDT 2017
Author: matze
Date: Tue Jun 6 15:06:57 2017
New Revision: 304825
URL: http://llvm.org/viewvc/llvm-project?rev=304825&view=rev
Log:
llc: Add ability to parse mir from stdin
- Add -x <language> option to switch between IR and MIR inputs.
- Change MIR parser to read from stdin when filename is '-'.
- Add a simple mir roundtrip test.
Added:
llvm/trunk/test/CodeGen/MIR/X86/roundtrip.mir
Modified:
llvm/trunk/lib/CodeGen/MIRParser/MIRParser.cpp
llvm/trunk/tools/llc/llc.cpp
Modified: llvm/trunk/lib/CodeGen/MIRParser/MIRParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIRParser/MIRParser.cpp?rev=304825&r1=304824&r2=304825&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MIRParser/MIRParser.cpp (original)
+++ llvm/trunk/lib/CodeGen/MIRParser/MIRParser.cpp Tue Jun 6 15:06:57 2017
@@ -869,7 +869,7 @@ bool MIRParser::parseMachineFunctions(Mo
std::unique_ptr<MIRParser> 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());
Added: llvm/trunk/test/CodeGen/MIR/X86/roundtrip.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/MIR/X86/roundtrip.mir?rev=304825&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/MIR/X86/roundtrip.mir (added)
+++ llvm/trunk/test/CodeGen/MIR/X86/roundtrip.mir Tue Jun 6 15:06:57 2017
@@ -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
+...
Modified: llvm/trunk/tools/llc/llc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llc/llc.cpp?rev=304825&r1=304824&r2=304825&view=diff
==============================================================================
--- llvm/trunk/tools/llc/llc.cpp (original)
+++ llvm/trunk/tools/llc/llc.cpp Tue Jun 6 15:06:57 2017
@@ -62,6 +62,9 @@ static cl::opt<std::string>
InputFilename(cl::Positional, cl::desc("<input bitcode>"), cl::init("-"));
static cl::opt<std::string>
+InputLanguage("x", cl::desc("Input language ('ir' or 'mir')"));
+
+static cl::opt<std::string>
OutputFilename("o", cl::desc("Output filename"), cl::value_desc("filename"));
static cl::opt<unsigned>
@@ -335,6 +338,12 @@ int main(int argc, char **argv) {
llvm::make_unique<yaml::Output>(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, LL
// 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();
More information about the llvm-commits
mailing list