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> | |
Jim Stichnoth
2015/12/23 15:54:15
Our (unwritten) convention is to put system includ
Jim Stichnoth
2015/12/25 15:31:01
This still needs to be done.
rkotlerimgtec
2015/12/26 23:29:42
Done.
| |
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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 llvm::report_fatal_error(StrBuf.str()); | 84 llvm::report_fatal_error(StrBuf.str()); |
83 } | 85 } |
84 } | 86 } |
85 } | 87 } |
86 } | 88 } |
87 | 89 |
88 } // end of anonymous namespace | 90 } // end of anonymous namespace |
89 | 91 |
90 void Compiler::run(const Ice::ClFlagsExtra &ExtraFlags, GlobalContext &Ctx, | 92 void Compiler::run(const Ice::ClFlagsExtra &ExtraFlags, GlobalContext &Ctx, |
91 std::unique_ptr<llvm::DataStreamer> &&InputStream) { | 93 std::unique_ptr<llvm::DataStreamer> &&InputStream) { |
92 validateAndGenerateBuildAttributes( | 94 if (ExtraFlags.getGenerateBuildAtts()) { |
93 ExtraFlags.getGenerateBuildAtts() ? &Ctx.getStrDump() : nullptr); | 95 validateAndGenerateBuildAttributes(&Ctx.getStrDump()); |
94 if (ExtraFlags.getGenerateBuildAtts()) | 96 Ctx.getErrorStatus()->assign(EC_None); |
95 return Ctx.getErrorStatus()->assign(EC_None); | 97 return; |
96 | 98 } |
97 // The Minimal build (specifically, when dump()/emit() are not implemented) | 99 // The Minimal build (specifically, when dump()/emit() are not implemented) |
98 // allows only --filetype=obj. Check here to avoid cryptic error messages | 100 // allows only --filetype=obj. Check here to avoid cryptic error messages |
99 // downstream. | 101 // downstream. |
100 if (!BuildDefs::dump() && Ctx.getFlags().getOutFileType() != FT_Elf) { | 102 if (!BuildDefs::dump() && Ctx.getFlags().getOutFileType() != FT_Elf) { |
101 // TODO(stichnot): Access the actual command-line argument via | 103 // TODO(stichnot): Access the actual command-line argument via |
102 // llvm::Option.ArgStr and .ValueStr . | 104 // llvm::Option.ArgStr and .ValueStr . |
103 Ctx.getStrError() | 105 Ctx.getStrError() |
104 << "Error: only --filetype=obj is supported in this build.\n"; | 106 << "Error: only --filetype=obj is supported in this build.\n"; |
105 return Ctx.getErrorStatus()->assign(EC_Args); | 107 Ctx.getErrorStatus()->assign(EC_Args); |
108 return; | |
106 } | 109 } |
107 | 110 |
108 // Force -build-on-read=0 for .ll files. | |
109 const std::string LLSuffix = ".ll"; | |
110 const IceString &IRFilename = ExtraFlags.getIRFilename(); | |
111 bool BuildOnRead = ExtraFlags.getBuildOnRead(); | |
112 if (BuildDefs::llvmIrAsInput() && IRFilename.length() >= LLSuffix.length() && | |
113 IRFilename.compare(IRFilename.length() - LLSuffix.length(), | |
114 LLSuffix.length(), LLSuffix) == 0) | |
115 BuildOnRead = false; | |
116 | |
117 TimerMarker T(Ice::TimerStack::TT_szmain, &Ctx); | 111 TimerMarker T(Ice::TimerStack::TT_szmain, &Ctx); |
118 | 112 |
119 Ctx.emitFileHeader(); | 113 Ctx.emitFileHeader(); |
120 Ctx.startWorkerThreads(); | 114 Ctx.startWorkerThreads(); |
121 | 115 |
122 std::unique_ptr<Translator> Translator; | 116 std::unique_ptr<Translator> Translator; |
123 if (BuildOnRead) { | 117 const IceString &IRFilename = ExtraFlags.getIRFilename(); |
118 // Force -build-on-read=0 for .ll files. | |
119 if (!std::regex_match(IRFilename, std::regex(".*\\.ll")) && | |
120 ExtraFlags.getBuildOnRead()) { | |
124 std::unique_ptr<PNaClTranslator> PTranslator(new PNaClTranslator(&Ctx)); | 121 std::unique_ptr<PNaClTranslator> PTranslator(new PNaClTranslator(&Ctx)); |
125 std::unique_ptr<llvm::StreamingMemoryObject> MemObj( | 122 std::unique_ptr<llvm::StreamingMemoryObject> MemObj( |
126 new llvm::StreamingMemoryObjectImpl(InputStream.release())); | 123 new llvm::StreamingMemoryObjectImpl(InputStream.release())); |
127 PTranslator->translate(IRFilename, std::move(MemObj)); | 124 PTranslator->translate(IRFilename, std::move(MemObj)); |
128 Translator.reset(PTranslator.release()); | 125 Translator.reset(PTranslator.release()); |
129 } else if (BuildDefs::llvmIr()) { | 126 } else if (BuildDefs::llvmIr()) { |
130 if (BuildDefs::browser()) { | 127 if (BuildDefs::browser()) { |
131 Ctx.getStrError() | 128 Ctx.getStrError() |
132 << "non BuildOnRead is not supported w/ PNACL_BROWSER_TRANSLATOR\n"; | 129 << "non BuildOnRead is not supported w/ PNACL_BROWSER_TRANSLATOR\n"; |
133 return Ctx.getErrorStatus()->assign(EC_Args); | 130 Ctx.getErrorStatus()->assign(EC_Args); |
131 return; | |
134 } | 132 } |
135 // Parse the input LLVM IR file into a module. | 133 // Parse the input LLVM IR file into a module. |
136 llvm::SMDiagnostic Err; | 134 llvm::SMDiagnostic Err; |
137 TimerMarker T1(Ice::TimerStack::TT_parse, &Ctx); | 135 TimerMarker T1(Ice::TimerStack::TT_parse, &Ctx); |
138 llvm::DiagnosticHandlerFunction DiagnosticHandler = | 136 llvm::DiagnosticHandlerFunction DiagnosticHandler = |
139 ExtraFlags.getLLVMVerboseErrors() | 137 ExtraFlags.getLLVMVerboseErrors() |
140 ? redirectNaClDiagnosticToStream(llvm::errs()) | 138 ? redirectNaClDiagnosticToStream(llvm::errs()) |
141 : nullptr; | 139 : nullptr; |
142 std::unique_ptr<llvm::Module> Mod = | 140 std::unique_ptr<llvm::Module> Mod = |
143 NaClParseIRFile(IRFilename, ExtraFlags.getInputFileFormat(), Err, | 141 NaClParseIRFile(IRFilename, ExtraFlags.getInputFileFormat(), Err, |
144 llvm::getGlobalContext(), DiagnosticHandler); | 142 llvm::getGlobalContext(), DiagnosticHandler); |
145 if (!Mod) { | 143 if (!Mod) { |
146 Err.print(ExtraFlags.getAppName().c_str(), llvm::errs()); | 144 Err.print(ExtraFlags.getAppName().c_str(), llvm::errs()); |
147 return Ctx.getErrorStatus()->assign(EC_Bitcode); | 145 Ctx.getErrorStatus()->assign(EC_Bitcode); |
146 return; | |
148 } | 147 } |
149 | 148 |
150 std::unique_ptr<Converter> Converter(new class Converter(Mod.get(), &Ctx)); | 149 std::unique_ptr<Converter> Converter(new class Converter(Mod.get(), &Ctx)); |
151 Converter->convertToIce(); | 150 Converter->convertToIce(); |
152 Translator.reset(Converter.release()); | 151 Translator.reset(Converter.release()); |
153 } else { | 152 } else { |
154 Ctx.getStrError() << "Error: Build doesn't allow LLVM IR, " | 153 Ctx.getStrError() << "Error: Build doesn't allow LLVM IR, " |
155 << "--build-on-read=0 not allowed\n"; | 154 << "--build-on-read=0 not allowed\n"; |
156 return Ctx.getErrorStatus()->assign(EC_Args); | 155 Ctx.getErrorStatus()->assign(EC_Args); |
156 return; | |
157 } | 157 } |
158 | 158 |
159 Ctx.waitForWorkerThreads(); | 159 Ctx.waitForWorkerThreads(); |
160 if (Translator->getErrorStatus()) { | 160 if (Translator->getErrorStatus()) { |
161 Ctx.getErrorStatus()->assign(Translator->getErrorStatus().value()); | 161 Ctx.getErrorStatus()->assign(Translator->getErrorStatus().value()); |
162 } else { | 162 } else { |
163 Ctx.lowerGlobals("last"); | 163 Ctx.lowerGlobals("last"); |
164 Ctx.lowerProfileData(); | 164 Ctx.lowerProfileData(); |
165 Ctx.lowerConstants(); | 165 Ctx.lowerConstants(); |
166 Ctx.lowerJumpTables(); | 166 Ctx.lowerJumpTables(); |
(...skipping 10 matching lines...) Expand all Loading... | |
177 | 177 |
178 if (Ctx.getFlags().getTimeEachFunction()) { | 178 if (Ctx.getFlags().getTimeEachFunction()) { |
179 constexpr bool DumpCumulative = false; | 179 constexpr bool DumpCumulative = false; |
180 Ctx.dumpTimers(GlobalContext::TSK_Funcs, DumpCumulative); | 180 Ctx.dumpTimers(GlobalContext::TSK_Funcs, DumpCumulative); |
181 } | 181 } |
182 constexpr bool FinalStats = true; | 182 constexpr bool FinalStats = true; |
183 Ctx.dumpStats("_FINAL_", FinalStats); | 183 Ctx.dumpStats("_FINAL_", FinalStats); |
184 } | 184 } |
185 | 185 |
186 } // end of namespace Ice | 186 } // end of namespace Ice |
OLD | NEW |