OLD | NEW |
1 //===- subzero/src/IceTranslator.cpp - ICE to machine code ------*- C++ -*-===// | 1 //===- subzero/src/IceTranslator.cpp - ICE to machine code ------*- C++ -*-===// |
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 the general driver class for translating ICE to | 10 // This file defines the general driver class for translating ICE to |
11 // machine code. | 11 // machine code. |
12 // | 12 // |
13 //===----------------------------------------------------------------------===// | 13 //===----------------------------------------------------------------------===// |
14 | 14 |
15 #include "IceCfg.h" | 15 #include "IceCfg.h" |
16 #include "IceClFlags.h" | 16 #include "IceClFlags.h" |
17 #include "IceDefs.h" | 17 #include "IceDefs.h" |
18 #include "IceGlobalInits.h" | 18 #include "IceGlobalInits.h" |
19 #include "IceTargetLowering.h" | 19 #include "IceTargetLowering.h" |
20 #include "IceTranslator.h" | 20 #include "IceTranslator.h" |
21 | 21 |
22 using namespace Ice; | 22 using namespace Ice; |
23 | 23 |
24 Translator::Translator(GlobalContext *Ctx, const ClFlags &Flags) | 24 Translator::Translator(GlobalContext *Ctx, const ClFlags &Flags) |
25 : Ctx(Ctx), Flags(Flags), | 25 : Ctx(Ctx), Flags(Flags), |
26 GlobalLowering(TargetGlobalLowering::createLowering(Ctx)), ErrorStatus() { | 26 DataLowering(TargetDataLowering::createLowering(Ctx)), ErrorStatus() {} |
27 } | |
28 | 27 |
29 Translator::~Translator() {} | 28 Translator::~Translator() {} |
30 | 29 |
31 IceString Translator::createUnnamedName(const IceString &Prefix, SizeT Index) { | 30 IceString Translator::createUnnamedName(const IceString &Prefix, SizeT Index) { |
32 if (Index == 0) | 31 if (Index == 0) |
33 return Prefix; | 32 return Prefix; |
34 std::string Buffer; | 33 std::string Buffer; |
35 llvm::raw_string_ostream StrBuf(Buffer); | 34 llvm::raw_string_ostream StrBuf(Buffer); |
36 StrBuf << Prefix << Index; | 35 StrBuf << Prefix << Index; |
37 return StrBuf.str(); | 36 return StrBuf.str(); |
(...skipping 18 matching lines...) Expand all Loading... |
56 | 55 |
57 void Translator::translateFcn(Cfg *Func) { | 56 void Translator::translateFcn(Cfg *Func) { |
58 Ctx->cfgQueueBlockingPush(Func); | 57 Ctx->cfgQueueBlockingPush(Func); |
59 if (Ctx->getFlags().NumTranslationThreads == 0) { | 58 if (Ctx->getFlags().NumTranslationThreads == 0) { |
60 Ctx->translateFunctions(); | 59 Ctx->translateFunctions(); |
61 } | 60 } |
62 } | 61 } |
63 | 62 |
64 void Translator::emitConstants() { | 63 void Translator::emitConstants() { |
65 if (!getErrorStatus()) | 64 if (!getErrorStatus()) |
66 GlobalLowering->lowerConstants(Ctx); | 65 DataLowering->lowerConstants(Ctx); |
67 } | 66 } |
68 | 67 |
69 void Translator::transferErrorCode() const { | 68 void Translator::transferErrorCode() const { |
70 if (getErrorStatus()) | 69 if (getErrorStatus()) |
71 Ctx->getErrorStatus()->assign(getErrorStatus().value()); | 70 Ctx->getErrorStatus()->assign(getErrorStatus().value()); |
72 } | 71 } |
73 | 72 |
74 void Translator::lowerGlobals( | 73 void |
75 const VariableDeclarationListType &VariableDeclarations) { | 74 Translator::lowerGlobals(const VariableDeclarationList &VariableDeclarations) { |
| 75 TimerMarker T(TimerStack::TT_emitGlobalInitializers, Ctx); |
76 bool DisableTranslation = Ctx->getFlags().DisableTranslation; | 76 bool DisableTranslation = Ctx->getFlags().DisableTranslation; |
77 const bool DumpGlobalVariables = | 77 const bool DumpGlobalVariables = |
78 ALLOW_DUMP && Ctx->getVerbose() && Ctx->getFlags().VerboseFocusOn.empty(); | 78 ALLOW_DUMP && Ctx->getVerbose() && Ctx->getFlags().VerboseFocusOn.empty(); |
79 OstreamLocker L(Ctx); | 79 if (Ctx->getFlags().UseELFWriter) { |
80 Ostream &Stream = Ctx->getStrDump(); | 80 // Dump all globals if requested, but don't interleave w/ emission. |
81 const IceString &TranslateOnly = Ctx->getFlags().TranslateOnly; | 81 if (DumpGlobalVariables) { |
82 for (const Ice::VariableDeclaration *Global : VariableDeclarations) { | 82 OstreamLocker L(Ctx); |
83 if (DumpGlobalVariables) | 83 Ostream &Stream = Ctx->getStrDump(); |
84 Global->dump(getContext(), Stream); | 84 for (const Ice::VariableDeclaration *Global : VariableDeclarations) { |
85 if (!DisableTranslation && | 85 Global->dump(getContext(), Stream); |
86 GlobalContext::matchSymbolName(Global->getName(), TranslateOnly)) | 86 } |
87 GlobalLowering->lowerInit(*Global); | 87 } |
| 88 DataLowering->lowerGlobalsELF(VariableDeclarations); |
| 89 } else { |
| 90 const IceString &TranslateOnly = Ctx->getFlags().TranslateOnly; |
| 91 OstreamLocker L(Ctx); |
| 92 Ostream &Stream = Ctx->getStrDump(); |
| 93 for (const Ice::VariableDeclaration *Global : VariableDeclarations) { |
| 94 // Interleave dump output w/ emit output. |
| 95 if (DumpGlobalVariables) |
| 96 Global->dump(getContext(), Stream); |
| 97 if (!DisableTranslation && |
| 98 GlobalContext::matchSymbolName(Global->getName(), TranslateOnly)) |
| 99 DataLowering->lowerGlobal(*Global); |
| 100 } |
88 } | 101 } |
89 } | 102 } |
OLD | NEW |