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