Chromium Code Reviews| 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 |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 cl::init(true)); | 166 cl::init(true)); |
| 167 | 167 |
| 168 static cl::opt<bool> | 168 static cl::opt<bool> |
| 169 UseIntegratedAssembler("integrated-as", | 169 UseIntegratedAssembler("integrated-as", |
| 170 cl::desc("Use integrated assembler (default yes)"), | 170 cl::desc("Use integrated assembler (default yes)"), |
| 171 cl::init(true)); | 171 cl::init(true)); |
| 172 | 172 |
| 173 static cl::alias UseIas("ias", cl::desc("Alias for -integrated-as"), | 173 static cl::alias UseIas("ias", cl::desc("Alias for -integrated-as"), |
| 174 cl::NotHidden, cl::aliasopt(UseIntegratedAssembler)); | 174 cl::NotHidden, cl::aliasopt(UseIntegratedAssembler)); |
| 175 | 175 |
| 176 static cl::opt<bool> | |
| 177 UseELFWriter("elf-writer", | |
| 178 cl::desc("Use ELF writer with the integrated assembler"), | |
| 179 cl::init(false)); | |
| 180 | |
| 176 static cl::opt<bool> AlwaysExitSuccess( | 181 static cl::opt<bool> AlwaysExitSuccess( |
| 177 "exit-success", cl::desc("Exit with success status, even if errors found"), | 182 "exit-success", cl::desc("Exit with success status, even if errors found"), |
| 178 cl::init(false)); | 183 cl::init(false)); |
| 179 | 184 |
| 180 static cl::opt<bool> | 185 static cl::opt<bool> |
| 181 GenerateBuildAtts("build-atts", | 186 GenerateBuildAtts("build-atts", |
| 182 cl::desc("Generate list of build attributes associated with " | 187 cl::desc("Generate list of build attributes associated with " |
| 183 "this executable."), | 188 "this executable."), |
| 184 cl::init(false)); | 189 cl::init(false)); |
| 185 | 190 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 235 DisableTranslation = true; | 240 DisableTranslation = true; |
| 236 | 241 |
| 237 Ice::VerboseMask VMask = Ice::IceV_None; | 242 Ice::VerboseMask VMask = Ice::IceV_None; |
| 238 // Don't generate verbose messages if routines | 243 // Don't generate verbose messages if routines |
| 239 // to dump messages are not available. | 244 // to dump messages are not available. |
| 240 if (ALLOW_DUMP) { | 245 if (ALLOW_DUMP) { |
| 241 for (unsigned i = 0; i != VerboseList.size(); ++i) | 246 for (unsigned i = 0; i != VerboseList.size(); ++i) |
| 242 VMask |= VerboseList[i]; | 247 VMask |= VerboseList[i]; |
| 243 } | 248 } |
| 244 | 249 |
| 245 std::ofstream Ofs; | |
| 246 if (OutputFilename != "-") { | |
| 247 Ofs.open(OutputFilename.c_str(), std::ofstream::out); | |
| 248 } | |
| 249 raw_os_ostream *Os = | |
| 250 new raw_os_ostream(OutputFilename == "-" ? std::cout : Ofs); | |
| 251 Os->SetUnbuffered(); | |
| 252 | |
| 253 ValidateAndGenerateBuildAttributes(GenerateBuildAtts ? Os : nullptr); | |
| 254 if (GenerateBuildAtts) | |
| 255 return GetReturnValue(0); | |
| 256 | |
| 257 std::ofstream Lfs; | 250 std::ofstream Lfs; |
| 258 if (LogFilename != "-") { | 251 if (LogFilename != "-") { |
| 259 Lfs.open(LogFilename.c_str(), std::ofstream::out); | 252 Lfs.open(LogFilename.c_str(), std::ofstream::out); |
| 260 } | 253 } |
| 261 raw_os_ostream *Ls = new raw_os_ostream(LogFilename == "-" ? std::cout : Lfs); | 254 raw_os_ostream *Ls = new raw_os_ostream(LogFilename == "-" ? std::cout : Lfs); |
| 262 Ls->SetUnbuffered(); | 255 Ls->SetUnbuffered(); |
| 263 | 256 |
| 257 ValidateAndGenerateBuildAttributes(GenerateBuildAtts ? Ls : nullptr); | |
| 258 if (GenerateBuildAtts) | |
| 259 return GetReturnValue(0); | |
| 260 | |
| 264 if (!ALLOW_DISABLE_IR_GEN && DisableIRGeneration) { | 261 if (!ALLOW_DISABLE_IR_GEN && DisableIRGeneration) { |
| 265 *Ls << "Error: Build doesn't allow --no-ir-gen when not " | 262 *Ls << "Error: Build doesn't allow --no-ir-gen when not " |
| 266 << "ALLOW_DISABLE_IR_GEN!\n"; | 263 << "ALLOW_DISABLE_IR_GEN!\n"; |
| 267 return GetReturnValue(1); | 264 return GetReturnValue(1); |
| 268 } | 265 } |
| 269 | 266 |
| 270 Ice::ClFlags Flags; | 267 Ice::ClFlags Flags; |
| 271 Flags.DisableInternal = DisableInternal; | 268 Flags.DisableInternal = DisableInternal; |
| 272 Flags.SubzeroTimingEnabled = SubzeroTimingEnabled; | 269 Flags.SubzeroTimingEnabled = SubzeroTimingEnabled; |
| 273 Flags.DisableTranslation = DisableTranslation; | 270 Flags.DisableTranslation = DisableTranslation; |
| 274 Flags.FunctionSections = FunctionSections; | 271 Flags.FunctionSections = FunctionSections; |
| 275 Flags.DataSections = DataSections; | 272 Flags.DataSections = DataSections; |
| 276 Flags.UseIntegratedAssembler = UseIntegratedAssembler; | 273 Flags.UseIntegratedAssembler = UseIntegratedAssembler; |
| 274 Flags.UseELFWriter = UseELFWriter; | |
| 277 Flags.UseSandboxing = UseSandboxing; | 275 Flags.UseSandboxing = UseSandboxing; |
| 278 Flags.PhiEdgeSplit = EnablePhiEdgeSplit; | 276 Flags.PhiEdgeSplit = EnablePhiEdgeSplit; |
| 279 Flags.DecorateAsm = DecorateAsm; | 277 Flags.DecorateAsm = DecorateAsm; |
| 280 Flags.DumpStats = DumpStats; | 278 Flags.DumpStats = DumpStats; |
| 281 Flags.AllowUninitializedGlobals = AllowUninitializedGlobals; | 279 Flags.AllowUninitializedGlobals = AllowUninitializedGlobals; |
| 282 Flags.TimeEachFunction = TimeEachFunction; | 280 Flags.TimeEachFunction = TimeEachFunction; |
| 283 Flags.DefaultGlobalPrefix = DefaultGlobalPrefix; | 281 Flags.DefaultGlobalPrefix = DefaultGlobalPrefix; |
| 284 Flags.DefaultFunctionPrefix = DefaultFunctionPrefix; | 282 Flags.DefaultFunctionPrefix = DefaultFunctionPrefix; |
| 285 Flags.TimingFocusOn = TimingFocusOn; | 283 Flags.TimingFocusOn = TimingFocusOn; |
| 286 Flags.VerboseFocusOn = VerboseFocusOn; | 284 Flags.VerboseFocusOn = VerboseFocusOn; |
| 287 Flags.TranslateOnly = TranslateOnly; | 285 Flags.TranslateOnly = TranslateOnly; |
| 288 Flags.DisableIRGeneration = DisableIRGeneration; | 286 Flags.DisableIRGeneration = DisableIRGeneration; |
| 289 | 287 |
| 290 // Force -build-on-read=0 for .ll files. | 288 // Force -build-on-read=0 for .ll files. |
| 291 const std::string LLSuffix = ".ll"; | 289 const std::string LLSuffix = ".ll"; |
| 292 if (IRFilename.length() >= LLSuffix.length() && | 290 if (IRFilename.length() >= LLSuffix.length() && |
| 293 IRFilename.compare(IRFilename.length() - LLSuffix.length(), | 291 IRFilename.compare(IRFilename.length() - LLSuffix.length(), |
| 294 LLSuffix.length(), LLSuffix) == 0) | 292 LLSuffix.length(), LLSuffix) == 0) |
| 295 BuildOnRead = false; | 293 BuildOnRead = false; |
| 296 | 294 |
| 297 Ice::GlobalContext Ctx(Ls, Os, VMask, TargetArch, OptLevel, TestPrefix, | 295 // With the ELF writer, use a raw_fd_ostream to allow seeking. |
| 298 Flags); | 296 // Also don't buffer, otherwise it gets pretty slow. |
| 297 Ice::Ostream *Os; | |
| 298 Ice::ELFStreamer *ELFStr = nullptr; | |
| 299 std::ofstream Ofs; | |
| 300 if (UseELFWriter) { | |
| 301 std::string ErrorInfo; | |
| 302 raw_fd_ostream *FdOs = | |
| 303 new raw_fd_ostream(OutputFilename.c_str(), ErrorInfo); | |
|
Jim Stichnoth
2014/11/21 21:32:23
Should we disallow OutputFilename=="-" which is it
jvoung (off chromium)
2014/11/24 21:35:47
Done -- streaming to stdout will have problems bec
| |
| 304 if (!ErrorInfo.empty()) { | |
| 305 *Ls << "Failed to open output file: " << OutputFilename << ":\n" | |
| 306 << ErrorInfo << "\n"; | |
| 307 return GetReturnValue(1); | |
| 308 } | |
| 309 ELFStr = new Ice::ELFStreamer(*FdOs); | |
| 310 Os = FdOs; | |
| 311 } else { | |
| 312 if (OutputFilename != "-") { | |
| 313 Ofs.open(OutputFilename.c_str(), std::ofstream::out); | |
| 314 } | |
| 315 Os = new raw_os_ostream(OutputFilename == "-" ? std::cout : Ofs); | |
|
Jim Stichnoth
2014/11/21 21:32:23
I know this was just copy/paste, but can we struct
jvoung (off chromium)
2014/11/24 21:35:46
Done. Did something similar for the Ls stream.
| |
| 316 Os->SetUnbuffered(); | |
| 317 } | |
| 318 | |
| 319 Ice::GlobalContext Ctx(Ls, Os, ELFStr, VMask, TargetArch, OptLevel, | |
| 320 TestPrefix, Flags); | |
| 299 | 321 |
| 300 Ice::TimerMarker T(Ice::TimerStack::TT_szmain, &Ctx); | 322 Ice::TimerMarker T(Ice::TimerStack::TT_szmain, &Ctx); |
| 301 | 323 |
| 324 if (UseELFWriter) { | |
| 325 Ctx.getObjectWriter()->writeInitialELFHeader(); | |
| 326 } | |
| 327 | |
| 302 int ErrorStatus = 0; | 328 int ErrorStatus = 0; |
| 303 if (BuildOnRead) { | 329 if (BuildOnRead) { |
| 304 Ice::PNaClTranslator Translator(&Ctx, Flags); | 330 Ice::PNaClTranslator Translator(&Ctx, Flags); |
| 305 Translator.translate(IRFilename); | 331 Translator.translate(IRFilename); |
| 306 ErrorStatus = Translator.getErrorStatus(); | 332 ErrorStatus = Translator.getErrorStatus(); |
| 307 } else if (ALLOW_LLVM_IR) { | 333 } else if (ALLOW_LLVM_IR) { |
| 308 // Parse the input LLVM IR file into a module. | 334 // Parse the input LLVM IR file into a module. |
| 309 SMDiagnostic Err; | 335 SMDiagnostic Err; |
| 310 Ice::TimerMarker T1(Ice::TimerStack::TT_parse, &Ctx); | 336 Ice::TimerMarker T1(Ice::TimerStack::TT_parse, &Ctx); |
| 311 Module *Mod = | 337 Module *Mod = |
| 312 NaClParseIRFile(IRFilename, InputFileFormat, Err, getGlobalContext()); | 338 NaClParseIRFile(IRFilename, InputFileFormat, Err, getGlobalContext()); |
| 313 | 339 |
| 314 if (!Mod) { | 340 if (!Mod) { |
| 315 Err.print(argv[0], errs()); | 341 Err.print(argv[0], errs()); |
| 316 return GetReturnValue(1); | 342 return GetReturnValue(1); |
| 317 } | 343 } |
| 318 | 344 |
| 319 Ice::Converter Converter(Mod, &Ctx, Flags); | 345 Ice::Converter Converter(Mod, &Ctx, Flags); |
| 320 Converter.convertToIce(); | 346 Converter.convertToIce(); |
| 321 ErrorStatus = Converter.getErrorStatus(); | 347 ErrorStatus = Converter.getErrorStatus(); |
| 322 } else { | 348 } else { |
| 323 *Ls << "Error: Build doesn't allow LLVM IR, " | 349 *Ls << "Error: Build doesn't allow LLVM IR, " |
| 324 << "--build-on-read=0 not allowed\n"; | 350 << "--build-on-read=0 not allowed\n"; |
| 325 return GetReturnValue(1); | 351 return GetReturnValue(1); |
| 326 } | 352 } |
| 353 if (UseELFWriter) { | |
| 354 Ctx.getObjectWriter()->writeNonUserSections(); | |
| 355 } | |
| 327 if (SubzeroTimingEnabled) | 356 if (SubzeroTimingEnabled) |
| 328 Ctx.dumpTimers(); | 357 Ctx.dumpTimers(); |
| 329 if (TimeEachFunction) { | 358 if (TimeEachFunction) { |
| 330 const bool DumpCumulative = false; | 359 const bool DumpCumulative = false; |
| 331 Ctx.dumpTimers(Ice::GlobalContext::TSK_Funcs, DumpCumulative); | 360 Ctx.dumpTimers(Ice::GlobalContext::TSK_Funcs, DumpCumulative); |
| 332 } | 361 } |
| 333 const bool FinalStats = true; | 362 const bool FinalStats = true; |
| 334 Ctx.dumpStats("_FINAL_", FinalStats); | 363 Ctx.dumpStats("_FINAL_", FinalStats); |
| 364 Os->flush(); | |
|
Jim Stichnoth
2014/11/21 21:32:23
Is it enough to just flush Os? Should it be close
jvoung (off chromium)
2014/11/24 21:35:46
Switch Os and Ls to a unique_ptr, so it gets delet
| |
| 335 return GetReturnValue(ErrorStatus); | 365 return GetReturnValue(ErrorStatus); |
| 336 } | 366 } |
| OLD | NEW |