OLD | NEW |
1 //===- subzero/src/llvm2ice.cpp - Driver for testing ----------------------===// | 1 //===- subzero/src/llvm2ice.cpp - Driver for testing ----------------------===// |
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 // This file defines a driver that uses LLVM capabilities to parse a | 10 // This file defines a driver that uses LLVM capabilities to parse a |
11 // bitcode file and build the LLVM IR, and then convert the LLVM basic | 11 // bitcode file and build the LLVM IR, and then convert the LLVM basic |
12 // blocks, instructions, and operands into their Subzero equivalents. | 12 // blocks, instructions, and operands into their Subzero equivalents. |
13 // | 13 // |
14 //===----------------------------------------------------------------------===// | 14 //===----------------------------------------------------------------------===// |
15 | 15 |
16 #include <fstream> | 16 #include <fstream> |
17 #include <iostream> | 17 #include <iostream> |
18 | 18 |
| 19 #include "llvm/ADT/STLExtras.h" |
19 #include "llvm/IR/LLVMContext.h" | 20 #include "llvm/IR/LLVMContext.h" |
20 #include "llvm/IRReader/IRReader.h" | 21 #include "llvm/IRReader/IRReader.h" |
21 #include "llvm/Support/CommandLine.h" | 22 #include "llvm/Support/CommandLine.h" |
22 #include "llvm/Support/raw_os_ostream.h" | 23 #include "llvm/Support/raw_os_ostream.h" |
23 #include "llvm/Support/SourceMgr.h" | 24 #include "llvm/Support/SourceMgr.h" |
24 | 25 |
25 #include "IceCfg.h" | 26 #include "IceCfg.h" |
26 #include "IceClFlags.h" | 27 #include "IceClFlags.h" |
27 #include "IceConverter.h" | 28 #include "IceConverter.h" |
28 #include "PNaClTranslator.h" | 29 #include "PNaClTranslator.h" |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 cl::desc("Use integrated assembler (default yes)"), | 155 cl::desc("Use integrated assembler (default yes)"), |
155 cl::init(true)); | 156 cl::init(true)); |
156 | 157 |
157 static cl::alias UseIas("ias", cl::desc("Alias for -integrated-as"), | 158 static cl::alias UseIas("ias", cl::desc("Alias for -integrated-as"), |
158 cl::NotHidden, cl::aliasopt(UseIntegratedAssembler)); | 159 cl::NotHidden, cl::aliasopt(UseIntegratedAssembler)); |
159 | 160 |
160 static cl::opt<bool> AlwaysExitSuccess( | 161 static cl::opt<bool> AlwaysExitSuccess( |
161 "exit-success", cl::desc("Exit with success status, even if errors found"), | 162 "exit-success", cl::desc("Exit with success status, even if errors found"), |
162 cl::init(false)); | 163 cl::init(false)); |
163 | 164 |
| 165 static cl::opt<bool> GenerateBuildAtts( |
| 166 "build-atts", cl::desc("Generate list of build attributes associated with " |
| 167 "this executable."), |
| 168 cl::init(false)); |
| 169 |
164 static int GetReturnValue(int Val) { | 170 static int GetReturnValue(int Val) { |
165 if (AlwaysExitSuccess) | 171 if (AlwaysExitSuccess) |
166 return 0; | 172 return 0; |
167 return Val; | 173 return Val; |
168 } | 174 } |
169 | 175 |
| 176 static struct { |
| 177 const char *FlagName; |
| 178 int FlagValue; |
| 179 } ConditionalBuildAttributes[] = { |
| 180 { "text_asm", ALLOW_TEXT_ASM }, |
| 181 { "dump", ALLOW_DUMP }, |
| 182 { "llvm_cl", ALLOW_LLVM_CL }, |
| 183 { "llvm_ir", ALLOW_LLVM_IR }, |
| 184 { "llvm_ir_as_input", ALLOW_LLVM_IR_AS_INPUT } |
| 185 }; |
| 186 |
| 187 // Validates values of build attributes. Prints them to Stream if |
| 188 // Stream is non-null. |
| 189 static void ValidateAndGenerateBuildAttributes(raw_os_ostream *Stream) { |
| 190 |
| 191 if (Stream) |
| 192 *Stream << TargetArch << "\n"; |
| 193 |
| 194 for (size_t i = 0; i < array_lengthof(ConditionalBuildAttributes); ++i) { |
| 195 switch (ConditionalBuildAttributes[i].FlagValue) { |
| 196 case 0: |
| 197 if (Stream) |
| 198 *Stream << "no_" << ConditionalBuildAttributes[i].FlagName << "\n"; |
| 199 break; |
| 200 case 1: |
| 201 if (Stream) |
| 202 *Stream << "allow_" << ConditionalBuildAttributes[i].FlagName << "\n"; |
| 203 break; |
| 204 default: { |
| 205 std::string Buffer; |
| 206 raw_string_ostream StrBuf(Buffer); |
| 207 StrBuf << "Flag " << ConditionalBuildAttributes[i].FlagName |
| 208 << " must be defined as 0/1. Found: " |
| 209 << ConditionalBuildAttributes[i].FlagValue; |
| 210 report_fatal_error(StrBuf.str()); |
| 211 } |
| 212 } |
| 213 } |
| 214 } |
| 215 |
170 int main(int argc, char **argv) { | 216 int main(int argc, char **argv) { |
171 | 217 |
172 cl::ParseCommandLineOptions(argc, argv); | 218 cl::ParseCommandLineOptions(argc, argv); |
173 | 219 |
174 Ice::VerboseMask VMask = Ice::IceV_None; | 220 Ice::VerboseMask VMask = Ice::IceV_None; |
175 for (unsigned i = 0; i != VerboseList.size(); ++i) | 221 for (unsigned i = 0; i != VerboseList.size(); ++i) |
176 VMask |= VerboseList[i]; | 222 VMask |= VerboseList[i]; |
177 | 223 |
178 std::ofstream Ofs; | 224 std::ofstream Ofs; |
179 if (OutputFilename != "-") { | 225 if (OutputFilename != "-") { |
180 Ofs.open(OutputFilename.c_str(), std::ofstream::out); | 226 Ofs.open(OutputFilename.c_str(), std::ofstream::out); |
181 } | 227 } |
182 raw_os_ostream *Os = | 228 raw_os_ostream *Os = |
183 new raw_os_ostream(OutputFilename == "-" ? std::cout : Ofs); | 229 new raw_os_ostream(OutputFilename == "-" ? std::cout : Ofs); |
184 Os->SetUnbuffered(); | 230 Os->SetUnbuffered(); |
| 231 |
| 232 ValidateAndGenerateBuildAttributes(GenerateBuildAtts ? Os : nullptr); |
| 233 if (GenerateBuildAtts) |
| 234 return GetReturnValue(0); |
| 235 |
185 std::ofstream Lfs; | 236 std::ofstream Lfs; |
186 if (LogFilename != "-") { | 237 if (LogFilename != "-") { |
187 Lfs.open(LogFilename.c_str(), std::ofstream::out); | 238 Lfs.open(LogFilename.c_str(), std::ofstream::out); |
188 } | 239 } |
189 raw_os_ostream *Ls = new raw_os_ostream(LogFilename == "-" ? std::cout : Lfs); | 240 raw_os_ostream *Ls = new raw_os_ostream(LogFilename == "-" ? std::cout : Lfs); |
190 Ls->SetUnbuffered(); | 241 Ls->SetUnbuffered(); |
191 | 242 |
192 Ice::ClFlags Flags; | 243 Ice::ClFlags Flags; |
193 Flags.DisableInternal = DisableInternal; | 244 Flags.DisableInternal = DisableInternal; |
194 Flags.SubzeroTimingEnabled = SubzeroTimingEnabled; | 245 Flags.SubzeroTimingEnabled = SubzeroTimingEnabled; |
195 Flags.DisableTranslation = DisableTranslation; | 246 Flags.DisableTranslation = DisableTranslation; |
196 Flags.FunctionSections = FunctionSections; | 247 Flags.FunctionSections = FunctionSections; |
197 Flags.DataSections = DataSections; | 248 Flags.DataSections = DataSections; |
198 Flags.UseIntegratedAssembler = UseIntegratedAssembler; | 249 Flags.UseIntegratedAssembler = UseIntegratedAssembler; |
199 Flags.UseSandboxing = UseSandboxing; | 250 Flags.UseSandboxing = UseSandboxing; |
200 Flags.DumpStats = DumpStats; | 251 Flags.DumpStats = DumpStats; |
201 Flags.AllowUninitializedGlobals = AllowUninitializedGlobals; | 252 Flags.AllowUninitializedGlobals = AllowUninitializedGlobals; |
202 Flags.TimeEachFunction = TimeEachFunction; | 253 Flags.TimeEachFunction = TimeEachFunction; |
203 Flags.DefaultGlobalPrefix = DefaultGlobalPrefix; | 254 Flags.DefaultGlobalPrefix = DefaultGlobalPrefix; |
204 Flags.DefaultFunctionPrefix = DefaultFunctionPrefix; | 255 Flags.DefaultFunctionPrefix = DefaultFunctionPrefix; |
205 Flags.TimingFocusOn = TimingFocusOn; | 256 Flags.TimingFocusOn = TimingFocusOn; |
206 Flags.VerboseFocusOn = VerboseFocusOn; | 257 Flags.VerboseFocusOn = VerboseFocusOn; |
207 | 258 |
208 Ice::GlobalContext Ctx(Ls, Os, VMask, TargetArch, OptLevel, TestPrefix, | 259 Ice::GlobalContext Ctx(Ls, Os, VMask, TargetArch, OptLevel, TestPrefix, |
209 Flags); | 260 Flags); |
| 261 |
210 Ice::TimerMarker T(Ice::TimerStack::TT_szmain, &Ctx); | 262 Ice::TimerMarker T(Ice::TimerStack::TT_szmain, &Ctx); |
211 | 263 |
212 int ErrorStatus = 0; | 264 int ErrorStatus = 0; |
213 if (BuildOnRead) { | 265 if (BuildOnRead) { |
214 Ice::PNaClTranslator Translator(&Ctx, Flags); | 266 Ice::PNaClTranslator Translator(&Ctx, Flags); |
215 Translator.translate(IRFilename); | 267 Translator.translate(IRFilename); |
216 ErrorStatus = Translator.getErrorStatus(); | 268 ErrorStatus = Translator.getErrorStatus(); |
217 } else { | 269 } else { |
218 // Parse the input LLVM IR file into a module. | 270 // Parse the input LLVM IR file into a module. |
219 SMDiagnostic Err; | 271 SMDiagnostic Err; |
(...skipping 13 matching lines...) Expand all Loading... |
233 if (TimeEachFunction) { | 285 if (TimeEachFunction) { |
234 const bool DumpCumulative = false; | 286 const bool DumpCumulative = false; |
235 Ctx.dumpTimers(Ice::GlobalContext::TSK_Funcs, DumpCumulative); | 287 Ctx.dumpTimers(Ice::GlobalContext::TSK_Funcs, DumpCumulative); |
236 } | 288 } |
237 if (SubzeroTimingEnabled) | 289 if (SubzeroTimingEnabled) |
238 Ctx.dumpTimers(); | 290 Ctx.dumpTimers(); |
239 const bool FinalStats = true; | 291 const bool FinalStats = true; |
240 Ctx.dumpStats("_FINAL_", FinalStats); | 292 Ctx.dumpStats("_FINAL_", FinalStats); |
241 return GetReturnValue(ErrorStatus); | 293 return GetReturnValue(ErrorStatus); |
242 } | 294 } |
OLD | NEW |