llvm.org GIT mirror llvm / f632627
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@304825 91177308-0d34-0410-b5e6-96231b3b80d8 Matthias Braun 3 years ago
3 changed file(s) with 32 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
868868 std::unique_ptr llvm::createMIRParserFromFile(StringRef Filename,
869869 SMDiagnostic &Error,
870870 LLVMContext &Context) {
871 auto FileOrErr = MemoryBuffer::getFile(Filename);
871 auto FileOrErr = MemoryBuffer::getFileOrSTDIN(Filename);
872872 if (std::error_code EC = FileOrErr.getError()) {
873873 Error = SMDiagnostic(Filename, SourceMgr::DK_Error,
874874 "Could not open input file: " + EC.message());
0 # RUN: llc -o - %s -mtriple=x86_64-- -run-pass=none | llc -o - -x mir - -mtriple=x86_64-- -run-pass=none | FileCheck %s
1 ---
2 # CHECK-LABEL: name: func0
3 # CHECK: registers:
4 # CHECK: - { id: 0, class: gr32, preferred-register: '' }
5 # CHECK: - { id: 1, class: gr32, preferred-register: '' }
6 # CHECK: body: |
7 # CHECK: bb.0:
8 # CHECK: %0 = MOV32r0 implicit-def %eflags
9 # CHECK: dead %1 = COPY %0
10 # CHECK: MOV32mr undef %rcx, 1, _, 0, _, killed %0 :: (volatile store 4)
11 # CHECK: RETQ undef %eax
12 name: func0
13 body: |
14 bb.0:
15 %0 : gr32 = MOV32r0 implicit-def %eflags
16 dead %1 : gr32 = COPY %0
17 MOV32mr undef %rcx, 1, _, 0, _, killed %0 :: (volatile store 4)
18 RETQ undef %eax
19 ...
6161 InputFilename(cl::Positional, cl::desc(""), cl::init("-"));
6262
6363 static cl::opt
64 InputLanguage("x", cl::desc("Input language ('ir' or 'mir')"));
65
66 static cl::opt
6467 OutputFilename("o", cl::desc("Output filename"), cl::value_desc("filename"));
6568
6669 static cl::opt
334337 llvm::make_unique(YamlFile->os()));
335338 }
336339
340 if (InputLanguage != "" && InputLanguage != "ir" &&
341 InputLanguage != "mir") {
342 errs() << argv[0] << "Input language must be '', 'IR' or 'MIR'\n";
343 return 1;
344 }
345
337346 // Compile the module TimeCompilations times to give better compile time
338347 // metrics.
339348 for (unsigned I = TimeCompilations; I; --I)
397406
398407 // If user just wants to list available options, skip module loading
399408 if (!SkipModule) {
400 if (StringRef(InputFilename).endswith_lower(".mir")) {
409 if (InputLanguage == "mir" ||
410 (InputLanguage == "" && StringRef(InputFilename).endswith(".mir"))) {
401411 MIR = createMIRParserFromFile(InputFilename, Err, Context);
402412 if (MIR)
403413 M = MIR->parseIRModule();