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 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 } | 56 } |
57 | 57 |
58 } // end of anonymous namespace | 58 } // end of anonymous namespace |
59 | 59 |
60 void Compiler::run(const Ice::ClFlags &Flags, GlobalContext &Ctx, | 60 void Compiler::run(const Ice::ClFlags &Flags, GlobalContext &Ctx, |
61 std::unique_ptr<llvm::DataStreamer> &&InputStream) { | 61 std::unique_ptr<llvm::DataStreamer> &&InputStream) { |
62 // The Minimal build (specifically, when dump()/emit() are not implemented) | 62 // The Minimal build (specifically, when dump()/emit() are not implemented) |
63 // allows only --filetype=obj. Check here to avoid cryptic error messages | 63 // allows only --filetype=obj. Check here to avoid cryptic error messages |
64 // downstream. | 64 // downstream. |
65 if (!BuildDefs::dump() && Ctx.getFlags().getOutFileType() != FT_Elf) { | 65 if (!BuildDefs::dump() && Ctx.getFlags().getOutFileType() != FT_Elf) { |
66 // TODO(stichnot): Access the actual command-line argument via | |
67 // llvm::Option.ArgStr and .ValueStr . | |
68 Ctx.getStrError() | 66 Ctx.getStrError() |
69 << "Error: only --filetype=obj is supported in this build.\n"; | 67 << "Error: only --filetype=obj is supported in this build.\n"; |
70 Ctx.getErrorStatus()->assign(EC_Args); | 68 Ctx.getErrorStatus()->assign(EC_Args); |
71 return; | 69 return; |
72 } | 70 } |
73 | 71 |
74 TimerMarker T(Ice::TimerStack::TT_szmain, &Ctx); | 72 TimerMarker T(Ice::TimerStack::TT_szmain, &Ctx); |
75 | 73 |
76 Ctx.emitFileHeader(); | 74 Ctx.emitFileHeader(); |
77 Ctx.startWorkerThreads(); | 75 Ctx.startWorkerThreads(); |
78 | 76 |
79 std::unique_ptr<Translator> Translator; | 77 std::unique_ptr<Translator> Translator; |
80 const IceString &IRFilename = Flags.getIRFilename(); | 78 const IceString &IRFilename = Flags.getIRFilename(); |
81 const bool BuildOnRead = Flags.getBuildOnRead() && !llvmIRInput(IRFilename); | 79 const bool BuildOnRead = Flags.getBuildOnRead() && !llvmIRInput(IRFilename); |
82 if (BuildOnRead) { | 80 if (BuildOnRead) { |
83 std::unique_ptr<PNaClTranslator> PTranslator(new PNaClTranslator(&Ctx)); | 81 std::unique_ptr<PNaClTranslator> PTranslator(new PNaClTranslator(&Ctx)); |
84 std::unique_ptr<llvm::StreamingMemoryObject> MemObj( | 82 std::unique_ptr<llvm::StreamingMemoryObject> MemObj( |
85 new llvm::StreamingMemoryObjectImpl(InputStream.release())); | 83 new llvm::StreamingMemoryObjectImpl(InputStream.release())); |
86 PTranslator->translate(IRFilename, std::move(MemObj)); | 84 PTranslator->translate(IRFilename, std::move(MemObj)); |
87 Translator.reset(PTranslator.release()); | 85 Translator.reset(PTranslator.release()); |
88 } else if (BuildDefs::llvmIr()) { | 86 } else if (BuildDefs::llvmIr()) { |
89 if (BuildDefs::browser()) { | 87 if (BuildDefs::browser()) { |
90 Ctx.getStrError() | 88 Ctx.getStrError() |
91 << "non BuildOnRead is not supported w/ PNACL_BROWSER_TRANSLATOR\n"; | 89 << "non BuildOnRead is not supported w/ PNACL_BROWSER_TRANSLATOR\n"; |
92 Ctx.getErrorStatus()->assign(EC_Args); | 90 Ctx.getErrorStatus()->assign(EC_Args); |
| 91 Ctx.waitForWorkerThreads(); |
93 return; | 92 return; |
94 } | 93 } |
95 // Globals must be kept alive after lowering when converting from LLVM to | 94 // Globals must be kept alive after lowering when converting from LLVM to |
96 // Ice. | 95 // Ice. |
97 Ctx.setDisposeGlobalVariablesAfterLowering(false); | 96 Ctx.setDisposeGlobalVariablesAfterLowering(false); |
98 // Parse the input LLVM IR file into a module. | 97 // Parse the input LLVM IR file into a module. |
99 llvm::SMDiagnostic Err; | 98 llvm::SMDiagnostic Err; |
100 TimerMarker T1(Ice::TimerStack::TT_parse, &Ctx); | 99 TimerMarker T1(Ice::TimerStack::TT_parse, &Ctx); |
101 llvm::DiagnosticHandlerFunction DiagnosticHandler = | 100 llvm::DiagnosticHandlerFunction DiagnosticHandler = |
102 Flags.getLLVMVerboseErrors() | 101 Flags.getLLVMVerboseErrors() |
103 ? redirectNaClDiagnosticToStream(llvm::errs()) | 102 ? redirectNaClDiagnosticToStream(llvm::errs()) |
104 : nullptr; | 103 : nullptr; |
105 std::unique_ptr<llvm::Module> Mod = | 104 std::unique_ptr<llvm::Module> Mod = |
106 NaClParseIRFile(IRFilename, Flags.getInputFileFormat(), Err, | 105 NaClParseIRFile(IRFilename, Flags.getInputFileFormat(), Err, |
107 llvm::getGlobalContext(), DiagnosticHandler); | 106 llvm::getGlobalContext(), DiagnosticHandler); |
108 if (!Mod) { | 107 if (!Mod) { |
109 Err.print(Flags.getAppName().c_str(), llvm::errs()); | 108 Err.print(Flags.getAppName().c_str(), llvm::errs()); |
110 Ctx.getErrorStatus()->assign(EC_Bitcode); | 109 Ctx.getErrorStatus()->assign(EC_Bitcode); |
| 110 Ctx.waitForWorkerThreads(); |
111 return; | 111 return; |
112 } | 112 } |
113 | 113 |
114 std::unique_ptr<Converter> Converter(new class Converter(Mod.get(), &Ctx)); | 114 std::unique_ptr<Converter> Converter(new class Converter(Mod.get(), &Ctx)); |
115 Converter->convertToIce(); | 115 Converter->convertToIce(); |
116 Translator.reset(Converter.release()); | 116 Translator.reset(Converter.release()); |
117 } else { | 117 } else { |
118 Ctx.getStrError() << "Error: Build doesn't allow LLVM IR, " | 118 Ctx.getStrError() << "Error: Build doesn't allow LLVM IR, " |
119 << "--build-on-read=0 not allowed\n"; | 119 << "--build-on-read=0 not allowed\n"; |
120 Ctx.getErrorStatus()->assign(EC_Args); | 120 Ctx.getErrorStatus()->assign(EC_Args); |
| 121 Ctx.waitForWorkerThreads(); |
121 return; | 122 return; |
122 } | 123 } |
123 | 124 |
124 Ctx.waitForWorkerThreads(); | 125 Ctx.waitForWorkerThreads(); |
125 if (Translator->getErrorStatus()) { | 126 if (Translator->getErrorStatus()) { |
126 Ctx.getErrorStatus()->assign(Translator->getErrorStatus().value()); | 127 Ctx.getErrorStatus()->assign(Translator->getErrorStatus().value()); |
127 } else { | 128 } else { |
128 Ctx.lowerGlobals("last"); | 129 Ctx.lowerGlobals("last"); |
129 Ctx.lowerProfileData(); | 130 Ctx.lowerProfileData(); |
130 Ctx.lowerConstants(); | 131 Ctx.lowerConstants(); |
(...skipping 11 matching lines...) Expand all Loading... |
142 | 143 |
143 if (Ctx.getFlags().getTimeEachFunction()) { | 144 if (Ctx.getFlags().getTimeEachFunction()) { |
144 constexpr bool NoDumpCumulative = false; | 145 constexpr bool NoDumpCumulative = false; |
145 Ctx.dumpTimers(GlobalContext::TSK_Funcs, NoDumpCumulative); | 146 Ctx.dumpTimers(GlobalContext::TSK_Funcs, NoDumpCumulative); |
146 } | 147 } |
147 constexpr bool FinalStats = true; | 148 constexpr bool FinalStats = true; |
148 Ctx.dumpStats("_FINAL_", FinalStats); | 149 Ctx.dumpStats("_FINAL_", FinalStats); |
149 } | 150 } |
150 | 151 |
151 } // end of namespace Ice | 152 } // end of namespace Ice |
OLD | NEW |