OLD | NEW |
---|---|
1 //===- subzero/src/IceCompiler.cpp - Driver for bitcode translation -------===// | 1 //===- subzero/src/IceCompiler.cpp - Driver for bitcode translation -------===// |
2 // | 2 // |
3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 /// | 9 /// |
10 /// \file | 10 /// \file |
11 /// \brief Defines a driver for translating PNaCl bitcode into native code. | 11 /// \brief Defines a driver for translating PNaCl bitcode into native code. |
12 /// | 12 /// |
13 /// The driver can either directly parse the binary bitcode file, or use LLVM | 13 /// The driver can either directly parse the binary bitcode file, or use LLVM |
14 /// routines to parse a textual bitcode file into LLVM IR and then convert LLVM | 14 /// routines to parse a textual bitcode file into LLVM IR and then convert LLVM |
15 /// IR into ICE. In either case, the high-level ICE is then compiled down to | 15 /// IR into ICE. In either case, the high-level ICE is then compiled down to |
16 /// native code, as either an ELF object file or a textual asm file. | 16 /// native code, as either an ELF object file or a textual asm file. |
17 /// | 17 /// |
18 //===----------------------------------------------------------------------===// | 18 //===----------------------------------------------------------------------===// |
19 | 19 |
20 #include <regex> | |
21 | |
20 #include "IceCompiler.h" | 22 #include "IceCompiler.h" |
21 | 23 |
22 #include "IceBuildDefs.h" | 24 #include "IceBuildDefs.h" |
23 #include "IceCfg.h" | 25 #include "IceCfg.h" |
24 #include "IceClFlags.h" | 26 #include "IceClFlags.h" |
25 #include "IceClFlagsExtra.h" | 27 #include "IceClFlagsExtra.h" |
26 #include "IceConverter.h" | 28 #include "IceConverter.h" |
27 #include "IceELFObjectWriter.h" | 29 #include "IceELFObjectWriter.h" |
28 #include "PNaClTranslator.h" | 30 #include "PNaClTranslator.h" |
29 | 31 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 ++i) { | 67 ++i) { |
66 const auto &A = ConditionalBuildAttributes[i]; | 68 const auto &A = ConditionalBuildAttributes[i]; |
67 *Stream << Prefix[A.FlagValue] << "_" << A.FlagName << "\n"; | 69 *Stream << Prefix[A.FlagValue] << "_" << A.FlagName << "\n"; |
68 } | 70 } |
69 } | 71 } |
70 | 72 |
71 } // end of anonymous namespace | 73 } // end of anonymous namespace |
72 | 74 |
73 void Compiler::run(const Ice::ClFlagsExtra &ExtraFlags, GlobalContext &Ctx, | 75 void Compiler::run(const Ice::ClFlagsExtra &ExtraFlags, GlobalContext &Ctx, |
74 std::unique_ptr<llvm::DataStreamer> &&InputStream) { | 76 std::unique_ptr<llvm::DataStreamer> &&InputStream) { |
75 dumpBuildAttributes(ExtraFlags.getGenerateBuildAtts() ? &Ctx.getStrDump() | 77 if (ExtraFlags.getGenerateBuildAtts()) { |
76 : nullptr); | 78 dumpBuildAttributes(&Ctx.getStrDump()); |
77 if (ExtraFlags.getGenerateBuildAtts()) | 79 Ctx.getErrorStatus()->assign(EC_None); |
78 return Ctx.getErrorStatus()->assign(EC_None); | 80 return; |
79 | 81 } |
80 // The Minimal build (specifically, when dump()/emit() are not implemented) | 82 // The Minimal build (specifically, when dump()/emit() are not implemented) |
81 // allows only --filetype=obj. Check here to avoid cryptic error messages | 83 // allows only --filetype=obj. Check here to avoid cryptic error messages |
82 // downstream. | 84 // downstream. |
83 if (!BuildDefs::dump() && Ctx.getFlags().getOutFileType() != FT_Elf) { | 85 if (!BuildDefs::dump() && Ctx.getFlags().getOutFileType() != FT_Elf) { |
84 // TODO(stichnot): Access the actual command-line argument via | 86 // TODO(stichnot): Access the actual command-line argument via |
85 // llvm::Option.ArgStr and .ValueStr . | 87 // llvm::Option.ArgStr and .ValueStr . |
86 Ctx.getStrError() | 88 Ctx.getStrError() |
87 << "Error: only --filetype=obj is supported in this build.\n"; | 89 << "Error: only --filetype=obj is supported in this build.\n"; |
88 return Ctx.getErrorStatus()->assign(EC_Args); | 90 Ctx.getErrorStatus()->assign(EC_Args); |
91 return; | |
89 } | 92 } |
90 | 93 |
91 // Force -build-on-read=0 for .ll files. | |
92 const std::string LLSuffix = ".ll"; | |
93 const IceString &IRFilename = ExtraFlags.getIRFilename(); | |
94 bool BuildOnRead = ExtraFlags.getBuildOnRead(); | |
95 if (BuildDefs::llvmIrAsInput() && IRFilename.length() >= LLSuffix.length() && | |
96 IRFilename.compare(IRFilename.length() - LLSuffix.length(), | |
97 LLSuffix.length(), LLSuffix) == 0) | |
98 BuildOnRead = false; | |
99 | |
100 TimerMarker T(Ice::TimerStack::TT_szmain, &Ctx); | 94 TimerMarker T(Ice::TimerStack::TT_szmain, &Ctx); |
101 | 95 |
102 Ctx.emitFileHeader(); | 96 Ctx.emitFileHeader(); |
103 Ctx.startWorkerThreads(); | 97 Ctx.startWorkerThreads(); |
104 | 98 |
105 std::unique_ptr<Translator> Translator; | 99 std::unique_ptr<Translator> Translator; |
106 if (BuildOnRead) { | 100 const IceString &IRFilename = ExtraFlags.getIRFilename(); |
101 // Force -build-on-read=0 for .ll files. | |
102 if (!std::regex_match(IRFilename, std::regex(".*\\.ll")) && | |
rkotlerimgtec
2015/12/22 23:21:55
I would also be okay to just create a function whe
Jim Stichnoth
2015/12/23 15:54:15
The regex use is nice. However, I would like it t
| |
103 ExtraFlags.getBuildOnRead()) { | |
107 std::unique_ptr<PNaClTranslator> PTranslator(new PNaClTranslator(&Ctx)); | 104 std::unique_ptr<PNaClTranslator> PTranslator(new PNaClTranslator(&Ctx)); |
108 std::unique_ptr<llvm::StreamingMemoryObject> MemObj( | 105 std::unique_ptr<llvm::StreamingMemoryObject> MemObj( |
109 new llvm::StreamingMemoryObjectImpl(InputStream.release())); | 106 new llvm::StreamingMemoryObjectImpl(InputStream.release())); |
110 PTranslator->translate(IRFilename, std::move(MemObj)); | 107 PTranslator->translate(IRFilename, std::move(MemObj)); |
111 Translator.reset(PTranslator.release()); | 108 Translator.reset(PTranslator.release()); |
112 } else if (BuildDefs::llvmIr()) { | 109 } else if (BuildDefs::llvmIr()) { |
113 if (BuildDefs::browser()) { | 110 if (BuildDefs::browser()) { |
114 Ctx.getStrError() | 111 Ctx.getStrError() |
115 << "non BuildOnRead is not supported w/ PNACL_BROWSER_TRANSLATOR\n"; | 112 << "non BuildOnRead is not supported w/ PNACL_BROWSER_TRANSLATOR\n"; |
116 return Ctx.getErrorStatus()->assign(EC_Args); | 113 Ctx.getErrorStatus()->assign(EC_Args); |
114 return; | |
117 } | 115 } |
118 // Parse the input LLVM IR file into a module. | 116 // Parse the input LLVM IR file into a module. |
119 llvm::SMDiagnostic Err; | 117 llvm::SMDiagnostic Err; |
120 TimerMarker T1(Ice::TimerStack::TT_parse, &Ctx); | 118 TimerMarker T1(Ice::TimerStack::TT_parse, &Ctx); |
121 llvm::DiagnosticHandlerFunction DiagnosticHandler = | 119 llvm::DiagnosticHandlerFunction DiagnosticHandler = |
122 ExtraFlags.getLLVMVerboseErrors() | 120 ExtraFlags.getLLVMVerboseErrors() |
123 ? redirectNaClDiagnosticToStream(llvm::errs()) | 121 ? redirectNaClDiagnosticToStream(llvm::errs()) |
124 : nullptr; | 122 : nullptr; |
125 std::unique_ptr<llvm::Module> Mod = | 123 std::unique_ptr<llvm::Module> Mod = |
126 NaClParseIRFile(IRFilename, ExtraFlags.getInputFileFormat(), Err, | 124 NaClParseIRFile(IRFilename, ExtraFlags.getInputFileFormat(), Err, |
127 llvm::getGlobalContext(), DiagnosticHandler); | 125 llvm::getGlobalContext(), DiagnosticHandler); |
128 if (!Mod) { | 126 if (!Mod) { |
129 Err.print(ExtraFlags.getAppName().c_str(), llvm::errs()); | 127 Err.print(ExtraFlags.getAppName().c_str(), llvm::errs()); |
130 return Ctx.getErrorStatus()->assign(EC_Bitcode); | 128 Ctx.getErrorStatus()->assign(EC_Bitcode); |
129 return; | |
131 } | 130 } |
132 | 131 |
133 std::unique_ptr<Converter> Converter(new class Converter(Mod.get(), &Ctx)); | 132 std::unique_ptr<Converter> Converter(new class Converter(Mod.get(), &Ctx)); |
134 Converter->convertToIce(); | 133 Converter->convertToIce(); |
135 Translator.reset(Converter.release()); | 134 Translator.reset(Converter.release()); |
136 } else { | 135 } else { |
137 Ctx.getStrError() << "Error: Build doesn't allow LLVM IR, " | 136 Ctx.getStrError() << "Error: Build doesn't allow LLVM IR, " |
138 << "--build-on-read=0 not allowed\n"; | 137 << "--build-on-read=0 not allowed\n"; |
139 return Ctx.getErrorStatus()->assign(EC_Args); | 138 Ctx.getErrorStatus()->assign(EC_Args); |
139 return; | |
140 } | 140 } |
141 | 141 |
142 Ctx.waitForWorkerThreads(); | 142 Ctx.waitForWorkerThreads(); |
143 if (Translator->getErrorStatus()) { | 143 if (Translator->getErrorStatus()) { |
144 Ctx.getErrorStatus()->assign(Translator->getErrorStatus().value()); | 144 Ctx.getErrorStatus()->assign(Translator->getErrorStatus().value()); |
145 } else { | 145 } else { |
146 Ctx.lowerGlobals("last"); | 146 Ctx.lowerGlobals("last"); |
147 Ctx.lowerProfileData(); | 147 Ctx.lowerProfileData(); |
148 Ctx.lowerConstants(); | 148 Ctx.lowerConstants(); |
149 Ctx.lowerJumpTables(); | 149 Ctx.lowerJumpTables(); |
(...skipping 10 matching lines...) Expand all Loading... | |
160 | 160 |
161 if (Ctx.getFlags().getTimeEachFunction()) { | 161 if (Ctx.getFlags().getTimeEachFunction()) { |
162 constexpr bool DumpCumulative = false; | 162 constexpr bool DumpCumulative = false; |
163 Ctx.dumpTimers(GlobalContext::TSK_Funcs, DumpCumulative); | 163 Ctx.dumpTimers(GlobalContext::TSK_Funcs, DumpCumulative); |
164 } | 164 } |
165 constexpr bool FinalStats = true; | 165 constexpr bool FinalStats = true; |
166 Ctx.dumpStats("_FINAL_", FinalStats); | 166 Ctx.dumpStats("_FINAL_", FinalStats); |
167 } | 167 } |
168 | 168 |
169 } // end of namespace Ice | 169 } // end of namespace Ice |
OLD | NEW |