OLD | NEW |
1 //===- subzero/src/IceGlobalContext.cpp - Global context defs -------------===// | 1 //===- subzero/src/IceGlobalContext.cpp - Global context defs -------------===// |
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 aspects of the compilation that persist across | 10 // This file defines aspects of the compilation that persist across |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 AllThreadContexts.push_back(MyTLS); | 151 AllThreadContexts.push_back(MyTLS); |
152 ICE_TLS_SET_FIELD(TLS, MyTLS); | 152 ICE_TLS_SET_FIELD(TLS, MyTLS); |
153 // Pre-register built-in stack names. | 153 // Pre-register built-in stack names. |
154 if (ALLOW_DUMP) { | 154 if (ALLOW_DUMP) { |
155 // TODO(stichnot): There needs to be a strong relationship between | 155 // TODO(stichnot): There needs to be a strong relationship between |
156 // the newTimerStackID() return values and TSK_Default/TSK_Funcs. | 156 // the newTimerStackID() return values and TSK_Default/TSK_Funcs. |
157 newTimerStackID("Total across all functions"); | 157 newTimerStackID("Total across all functions"); |
158 newTimerStackID("Per-function summary"); | 158 newTimerStackID("Per-function summary"); |
159 } | 159 } |
160 Timers.initInto(MyTLS->Timers); | 160 Timers.initInto(MyTLS->Timers); |
161 if (Flags.getUseELFWriter()) { | 161 switch (Flags.getOutFileType()) { |
| 162 case FT_Elf: |
162 ObjectWriter.reset(new ELFObjectWriter(*this, *ELFStr)); | 163 ObjectWriter.reset(new ELFObjectWriter(*this, *ELFStr)); |
| 164 break; |
| 165 case FT_Asm: |
| 166 case FT_Iasm: |
| 167 break; |
163 } | 168 } |
164 } | 169 } |
165 | 170 |
166 void GlobalContext::translateFunctions() { | 171 void GlobalContext::translateFunctions() { |
167 while (std::unique_ptr<Cfg> Func = optQueueBlockingPop()) { | 172 while (std::unique_ptr<Cfg> Func = optQueueBlockingPop()) { |
168 // Install Func in TLS for Cfg-specific container allocators. | 173 // Install Func in TLS for Cfg-specific container allocators. |
169 Cfg::setCurrentCfg(Func.get()); | 174 Cfg::setCurrentCfg(Func.get()); |
170 // Reset per-function stats being accumulated in TLS. | 175 // Reset per-function stats being accumulated in TLS. |
171 resetStats(); | 176 resetStats(); |
172 // Set verbose level to none if the current function does NOT | 177 // Set verbose level to none if the current function does NOT |
(...skipping 13 matching lines...) Expand all Loading... |
186 continue; // Func goes out of scope and gets deleted | 191 continue; // Func goes out of scope and gets deleted |
187 } | 192 } |
188 Func->translate(); | 193 Func->translate(); |
189 EmitterWorkItem *Item = nullptr; | 194 EmitterWorkItem *Item = nullptr; |
190 if (Func->hasError()) { | 195 if (Func->hasError()) { |
191 getErrorStatus()->assign(EC_Translation); | 196 getErrorStatus()->assign(EC_Translation); |
192 OstreamLocker L(this); | 197 OstreamLocker L(this); |
193 getStrDump() << "ICE translation error: " << Func->getError() << "\n"; | 198 getStrDump() << "ICE translation error: " << Func->getError() << "\n"; |
194 Item = new EmitterWorkItem(Func->getSequenceNumber()); | 199 Item = new EmitterWorkItem(Func->getSequenceNumber()); |
195 } else { | 200 } else { |
196 if (getFlags().getUseIntegratedAssembler()) { | 201 switch (getFlags().getOutFileType()) { |
| 202 case FT_Elf: |
| 203 case FT_Iasm: { |
197 Func->emitIAS(); | 204 Func->emitIAS(); |
198 // The Cfg has already emitted into the assembly buffer, so | 205 // The Cfg has already emitted into the assembly buffer, so |
199 // stats have been fully collected into this thread's TLS. | 206 // stats have been fully collected into this thread's TLS. |
200 // Dump them before TLS is reset for the next Cfg. | 207 // Dump them before TLS is reset for the next Cfg. |
201 dumpStats(Func->getFunctionName()); | 208 dumpStats(Func->getFunctionName()); |
202 Assembler *Asm = Func->releaseAssembler(); | 209 Assembler *Asm = Func->releaseAssembler(); |
203 // Copy relevant fields into Asm before Func is deleted. | 210 // Copy relevant fields into Asm before Func is deleted. |
204 Asm->setFunctionName(Func->getFunctionName()); | 211 Asm->setFunctionName(Func->getFunctionName()); |
205 Asm->setInternal(Func->getInternal()); | 212 Asm->setInternal(Func->getInternal()); |
206 Item = new EmitterWorkItem(Func->getSequenceNumber(), Asm); | 213 Item = new EmitterWorkItem(Func->getSequenceNumber(), Asm); |
207 } else { | 214 } break; |
| 215 case FT_Asm: |
208 // The Cfg has not been emitted yet, so stats are not ready | 216 // The Cfg has not been emitted yet, so stats are not ready |
209 // to be dumped. | 217 // to be dumped. |
210 Item = new EmitterWorkItem(Func->getSequenceNumber(), Func.release()); | 218 Item = new EmitterWorkItem(Func->getSequenceNumber(), Func.release()); |
| 219 break; |
211 } | 220 } |
212 } | 221 } |
213 Cfg::setCurrentCfg(nullptr); | 222 Cfg::setCurrentCfg(nullptr); |
214 assert(Item); | 223 assert(Item); |
215 emitQueueBlockingPush(Item); | 224 emitQueueBlockingPush(Item); |
216 // The Cfg now gets deleted as Func goes out of scope. | 225 // The Cfg now gets deleted as Func goes out of scope. |
217 } | 226 } |
218 } | 227 } |
219 | 228 |
220 namespace { | 229 namespace { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 case EmitterWorkItem::WI_Nop: | 285 case EmitterWorkItem::WI_Nop: |
277 break; | 286 break; |
278 case EmitterWorkItem::WI_GlobalInits: { | 287 case EmitterWorkItem::WI_GlobalInits: { |
279 lowerGlobals(this, Item->getGlobalInits(), | 288 lowerGlobals(this, Item->getGlobalInits(), |
280 TargetDataLowering::createLowering(this).get()); | 289 TargetDataLowering::createLowering(this).get()); |
281 } break; | 290 } break; |
282 case EmitterWorkItem::WI_Asm: { | 291 case EmitterWorkItem::WI_Asm: { |
283 std::unique_ptr<Assembler> Asm = Item->getAsm(); | 292 std::unique_ptr<Assembler> Asm = Item->getAsm(); |
284 Asm->alignFunction(); | 293 Asm->alignFunction(); |
285 IceString MangledName = mangleName(Asm->getFunctionName()); | 294 IceString MangledName = mangleName(Asm->getFunctionName()); |
286 if (getFlags().getUseELFWriter()) { | 295 switch (getFlags().getOutFileType()) { |
| 296 case FT_Elf: |
287 getObjectWriter()->writeFunctionCode(MangledName, Asm->getInternal(), | 297 getObjectWriter()->writeFunctionCode(MangledName, Asm->getInternal(), |
288 Asm.get()); | 298 Asm.get()); |
289 } else { | 299 break; |
| 300 case FT_Iasm: { |
290 OstreamLocker L(this); | 301 OstreamLocker L(this); |
291 Cfg::emitTextHeader(MangledName, this, Asm.get()); | 302 Cfg::emitTextHeader(MangledName, this, Asm.get()); |
292 Asm->emitIASBytes(this); | 303 Asm->emitIASBytes(this); |
| 304 } break; |
| 305 case FT_Asm: |
| 306 llvm::report_fatal_error("Unexpected FT_Asm"); |
| 307 break; |
293 } | 308 } |
294 } break; | 309 } break; |
295 case EmitterWorkItem::WI_Cfg: { | 310 case EmitterWorkItem::WI_Cfg: { |
296 if (!ALLOW_DUMP) | 311 if (!ALLOW_DUMP) |
297 llvm::report_fatal_error("WI_Cfg work item created inappropriately"); | 312 llvm::report_fatal_error("WI_Cfg work item created inappropriately"); |
298 assert(!getFlags().getUseIntegratedAssembler()); | 313 assert(getFlags().getOutFileType() == FT_Asm); |
299 std::unique_ptr<Cfg> Func = Item->getCfg(); | 314 std::unique_ptr<Cfg> Func = Item->getCfg(); |
300 // Unfortunately, we have to temporarily install the Cfg in TLS | 315 // Unfortunately, we have to temporarily install the Cfg in TLS |
301 // because Variable::asType() uses the allocator to create the | 316 // because Variable::asType() uses the allocator to create the |
302 // differently-typed copy. | 317 // differently-typed copy. |
303 Cfg::setCurrentCfg(Func.get()); | 318 Cfg::setCurrentCfg(Func.get()); |
304 Func->emit(); | 319 Func->emit(); |
305 Cfg::setCurrentCfg(nullptr); | 320 Cfg::setCurrentCfg(nullptr); |
306 dumpStats(Func->getFunctionName()); | 321 dumpStats(Func->getFunctionName()); |
307 } break; | 322 } break; |
308 } | 323 } |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 Ctx = Func->getContext(); | 740 Ctx = Func->getContext(); |
726 Active = | 741 Active = |
727 Func->getFocusedTiming() || Ctx->getFlags().getSubzeroTimingEnabled(); | 742 Func->getFocusedTiming() || Ctx->getFlags().getSubzeroTimingEnabled(); |
728 if (Active) | 743 if (Active) |
729 Ctx->pushTimer(ID, StackID); | 744 Ctx->pushTimer(ID, StackID); |
730 } | 745 } |
731 | 746 |
732 ICE_TLS_DEFINE_FIELD(GlobalContext::ThreadContext *, GlobalContext, TLS); | 747 ICE_TLS_DEFINE_FIELD(GlobalContext::ThreadContext *, GlobalContext, TLS); |
733 | 748 |
734 } // end of namespace Ice | 749 } // end of namespace Ice |
OLD | NEW |