| 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 cl::init("-"), | 87 cl::init("-"), |
| 88 cl::value_desc("filename")); | 88 cl::value_desc("filename")); |
| 89 static cl::opt<std::string> | 89 static cl::opt<std::string> |
| 90 TestPrefix("prefix", cl::desc("Prepend a prefix to symbol names for testing"), | 90 TestPrefix("prefix", cl::desc("Prepend a prefix to symbol names for testing"), |
| 91 cl::init(""), cl::value_desc("prefix")); | 91 cl::init(""), cl::value_desc("prefix")); |
| 92 static cl::opt<bool> | 92 static cl::opt<bool> |
| 93 DisableInternal("externalize", | 93 DisableInternal("externalize", |
| 94 cl::desc("Externalize all symbols")); | 94 cl::desc("Externalize all symbols")); |
| 95 static cl::opt<bool> | 95 static cl::opt<bool> |
| 96 DisableTranslation("notranslate", cl::desc("Disable Subzero translation")); | 96 DisableTranslation("notranslate", cl::desc("Disable Subzero translation")); |
| 97 // Note: Modifiable only if ALLOW_DISABLE_IR_GEN. |
| 98 static cl::opt<bool> |
| 99 DisableIRGeneration("no-ir-gen", |
| 100 cl::desc("Disable generating Subzero IR.")); |
| 97 static cl::opt<std::string> | 101 static cl::opt<std::string> |
| 98 TranslateOnly("translate-only", cl::desc("Translate only the given function"), | 102 TranslateOnly("translate-only", cl::desc("Translate only the given function"), |
| 99 cl::init("")); | 103 cl::init("")); |
| 100 | 104 |
| 101 static cl::opt<bool> SubzeroTimingEnabled( | 105 static cl::opt<bool> SubzeroTimingEnabled( |
| 102 "timing", cl::desc("Enable breakdown timing of Subzero translation")); | 106 "timing", cl::desc("Enable breakdown timing of Subzero translation")); |
| 103 | 107 |
| 104 static cl::opt<bool> | 108 static cl::opt<bool> |
| 105 TimeEachFunction("timing-funcs", | 109 TimeEachFunction("timing-funcs", |
| 106 cl::desc("Print total translation time for each function")); | 110 cl::desc("Print total translation time for each function")); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 | 185 |
| 182 static int GetReturnValue(int Val) { | 186 static int GetReturnValue(int Val) { |
| 183 if (AlwaysExitSuccess) | 187 if (AlwaysExitSuccess) |
| 184 return 0; | 188 return 0; |
| 185 return Val; | 189 return Val; |
| 186 } | 190 } |
| 187 | 191 |
| 188 static struct { | 192 static struct { |
| 189 const char *FlagName; | 193 const char *FlagName; |
| 190 int FlagValue; | 194 int FlagValue; |
| 191 } ConditionalBuildAttributes[] = { { "text_asm", ALLOW_TEXT_ASM }, | 195 } ConditionalBuildAttributes[] = {{"text_asm", ALLOW_TEXT_ASM}, |
| 192 { "dump", ALLOW_DUMP }, | 196 {"dump", ALLOW_DUMP}, |
| 193 { "llvm_cl", ALLOW_LLVM_CL }, | 197 {"llvm_cl", ALLOW_LLVM_CL}, |
| 194 { "llvm_ir", ALLOW_LLVM_IR }, | 198 {"llvm_ir", ALLOW_LLVM_IR}, |
| 195 { "llvm_ir_as_input", | 199 {"llvm_ir_as_input", ALLOW_LLVM_IR_AS_INPUT}, |
| 196 ALLOW_LLVM_IR_AS_INPUT } }; | 200 {"disable_ir_gen", ALLOW_DISABLE_IR_GEN}}; |
| 197 | 201 |
| 198 // Validates values of build attributes. Prints them to Stream if | 202 // Validates values of build attributes. Prints them to Stream if |
| 199 // Stream is non-null. | 203 // Stream is non-null. |
| 200 static void ValidateAndGenerateBuildAttributes(raw_os_ostream *Stream) { | 204 static void ValidateAndGenerateBuildAttributes(raw_os_ostream *Stream) { |
| 201 | 205 |
| 202 if (Stream) | 206 if (Stream) |
| 203 *Stream << TargetArch << "\n"; | 207 *Stream << TargetArch << "\n"; |
| 204 | 208 |
| 205 for (size_t i = 0; i < array_lengthof(ConditionalBuildAttributes); ++i) { | 209 for (size_t i = 0; i < array_lengthof(ConditionalBuildAttributes); ++i) { |
| 206 switch (ConditionalBuildAttributes[i].FlagValue) { | 210 switch (ConditionalBuildAttributes[i].FlagValue) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 221 report_fatal_error(StrBuf.str()); | 225 report_fatal_error(StrBuf.str()); |
| 222 } | 226 } |
| 223 } | 227 } |
| 224 } | 228 } |
| 225 } | 229 } |
| 226 | 230 |
| 227 int main(int argc, char **argv) { | 231 int main(int argc, char **argv) { |
| 228 | 232 |
| 229 cl::ParseCommandLineOptions(argc, argv); | 233 cl::ParseCommandLineOptions(argc, argv); |
| 230 | 234 |
| 235 if (DisableIRGeneration) |
| 236 DisableTranslation = true; |
| 237 |
| 231 Ice::VerboseMask VMask = Ice::IceV_None; | 238 Ice::VerboseMask VMask = Ice::IceV_None; |
| 232 for (unsigned i = 0; i != VerboseList.size(); ++i) | 239 for (unsigned i = 0; i != VerboseList.size(); ++i) |
| 233 VMask |= VerboseList[i]; | 240 VMask |= VerboseList[i]; |
| 234 | 241 |
| 235 std::ofstream Ofs; | 242 std::ofstream Ofs; |
| 236 if (OutputFilename != "-") { | 243 if (OutputFilename != "-") { |
| 237 Ofs.open(OutputFilename.c_str(), std::ofstream::out); | 244 Ofs.open(OutputFilename.c_str(), std::ofstream::out); |
| 238 } | 245 } |
| 239 raw_os_ostream *Os = | 246 raw_os_ostream *Os = |
| 240 new raw_os_ostream(OutputFilename == "-" ? std::cout : Ofs); | 247 new raw_os_ostream(OutputFilename == "-" ? std::cout : Ofs); |
| 241 Os->SetUnbuffered(); | 248 Os->SetUnbuffered(); |
| 242 | 249 |
| 243 ValidateAndGenerateBuildAttributes(GenerateBuildAtts ? Os : nullptr); | 250 ValidateAndGenerateBuildAttributes(GenerateBuildAtts ? Os : nullptr); |
| 244 if (GenerateBuildAtts) | 251 if (GenerateBuildAtts) |
| 245 return GetReturnValue(0); | 252 return GetReturnValue(0); |
| 246 | 253 |
| 247 std::ofstream Lfs; | 254 std::ofstream Lfs; |
| 248 if (LogFilename != "-") { | 255 if (LogFilename != "-") { |
| 249 Lfs.open(LogFilename.c_str(), std::ofstream::out); | 256 Lfs.open(LogFilename.c_str(), std::ofstream::out); |
| 250 } | 257 } |
| 251 raw_os_ostream *Ls = new raw_os_ostream(LogFilename == "-" ? std::cout : Lfs); | 258 raw_os_ostream *Ls = new raw_os_ostream(LogFilename == "-" ? std::cout : Lfs); |
| 252 Ls->SetUnbuffered(); | 259 Ls->SetUnbuffered(); |
| 253 | 260 |
| 261 if (!ALLOW_DISABLE_IR_GEN && DisableIRGeneration) { |
| 262 *Ls << "Error: Build doesn't allow --no-ir-gen when not " |
| 263 << "ALLOW_DISABLE_IR_GEN!\n"; |
| 264 return GetReturnValue(1); |
| 265 } |
| 266 |
| 254 Ice::ClFlags Flags; | 267 Ice::ClFlags Flags; |
| 255 Flags.DisableInternal = DisableInternal; | 268 Flags.DisableInternal = DisableInternal; |
| 256 Flags.SubzeroTimingEnabled = SubzeroTimingEnabled; | 269 Flags.SubzeroTimingEnabled = SubzeroTimingEnabled; |
| 257 Flags.DisableTranslation = DisableTranslation; | 270 Flags.DisableTranslation = DisableTranslation; |
| 258 Flags.FunctionSections = FunctionSections; | 271 Flags.FunctionSections = FunctionSections; |
| 259 Flags.DataSections = DataSections; | 272 Flags.DataSections = DataSections; |
| 260 Flags.UseIntegratedAssembler = UseIntegratedAssembler; | 273 Flags.UseIntegratedAssembler = UseIntegratedAssembler; |
| 261 Flags.UseSandboxing = UseSandboxing; | 274 Flags.UseSandboxing = UseSandboxing; |
| 262 Flags.PhiEdgeSplit = EnablePhiEdgeSplit; | 275 Flags.PhiEdgeSplit = EnablePhiEdgeSplit; |
| 263 Flags.DecorateAsm = DecorateAsm; | 276 Flags.DecorateAsm = DecorateAsm; |
| 264 Flags.DumpStats = DumpStats; | 277 Flags.DumpStats = DumpStats; |
| 265 Flags.AllowUninitializedGlobals = AllowUninitializedGlobals; | 278 Flags.AllowUninitializedGlobals = AllowUninitializedGlobals; |
| 266 Flags.TimeEachFunction = TimeEachFunction; | 279 Flags.TimeEachFunction = TimeEachFunction; |
| 267 Flags.DefaultGlobalPrefix = DefaultGlobalPrefix; | 280 Flags.DefaultGlobalPrefix = DefaultGlobalPrefix; |
| 268 Flags.DefaultFunctionPrefix = DefaultFunctionPrefix; | 281 Flags.DefaultFunctionPrefix = DefaultFunctionPrefix; |
| 269 Flags.TimingFocusOn = TimingFocusOn; | 282 Flags.TimingFocusOn = TimingFocusOn; |
| 270 Flags.VerboseFocusOn = VerboseFocusOn; | 283 Flags.VerboseFocusOn = VerboseFocusOn; |
| 271 Flags.TranslateOnly = TranslateOnly; | 284 Flags.TranslateOnly = TranslateOnly; |
| 285 Flags.DisableIRGeneration = DisableIRGeneration; |
| 272 | 286 |
| 273 Ice::GlobalContext Ctx(Ls, Os, VMask, TargetArch, OptLevel, TestPrefix, | 287 Ice::GlobalContext Ctx(Ls, Os, VMask, TargetArch, OptLevel, TestPrefix, |
| 274 Flags); | 288 Flags); |
| 275 | 289 |
| 276 Ice::TimerMarker T(Ice::TimerStack::TT_szmain, &Ctx); | 290 Ice::TimerMarker T(Ice::TimerStack::TT_szmain, &Ctx); |
| 277 | 291 |
| 278 int ErrorStatus = 0; | 292 int ErrorStatus = 0; |
| 279 if (BuildOnRead) { | 293 if (BuildOnRead) { |
| 280 Ice::PNaClTranslator Translator(&Ctx, Flags); | 294 Ice::PNaClTranslator Translator(&Ctx, Flags); |
| 281 Translator.translate(IRFilename); | 295 Translator.translate(IRFilename); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 303 if (SubzeroTimingEnabled) | 317 if (SubzeroTimingEnabled) |
| 304 Ctx.dumpTimers(); | 318 Ctx.dumpTimers(); |
| 305 if (TimeEachFunction) { | 319 if (TimeEachFunction) { |
| 306 const bool DumpCumulative = false; | 320 const bool DumpCumulative = false; |
| 307 Ctx.dumpTimers(Ice::GlobalContext::TSK_Funcs, DumpCumulative); | 321 Ctx.dumpTimers(Ice::GlobalContext::TSK_Funcs, DumpCumulative); |
| 308 } | 322 } |
| 309 const bool FinalStats = true; | 323 const bool FinalStats = true; |
| 310 Ctx.dumpStats("_FINAL_", FinalStats); | 324 Ctx.dumpStats("_FINAL_", FinalStats); |
| 311 return GetReturnValue(ErrorStatus); | 325 return GetReturnValue(ErrorStatus); |
| 312 } | 326 } |
| OLD | NEW |