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 <iostream> | 15 #include <iostream> |
16 #include <memory> | 16 #include <memory> |
17 | 17 |
18 #include "llvm/IR/Constant.h" | 18 #include "llvm/IR/Constant.h" |
19 #include "llvm/IR/Constants.h" | 19 #include "llvm/IR/Constants.h" |
20 #include "llvm/IR/Module.h" | 20 #include "llvm/IR/Module.h" |
21 | 21 |
22 #include "IceCfg.h" | 22 #include "IceCfg.h" |
23 #include "IceClFlags.h" | 23 #include "IceClFlags.h" |
24 #include "IceDefs.h" | 24 #include "IceDefs.h" |
| 25 #include "IceGlobalInits.h" |
25 #include "IceTargetLowering.h" | 26 #include "IceTargetLowering.h" |
26 #include "IceTranslator.h" | 27 #include "IceTranslator.h" |
27 | 28 |
28 using namespace Ice; | 29 using namespace Ice; |
29 | 30 |
30 Translator::~Translator() {} | 31 Translator::~Translator() {} |
31 | 32 |
32 IceString Translator::createUnnamedName(const IceString &Prefix, SizeT Index) { | 33 IceString Translator::createUnnamedName(const IceString &Prefix, SizeT Index) { |
33 if (Index == 0) | 34 if (Index == 0) |
34 return Prefix; | 35 return Prefix; |
(...skipping 12 matching lines...) Expand all Loading... |
47 return false; | 48 return false; |
48 } | 49 } |
49 } | 50 } |
50 Stream << "Warning : Default " << Kind << " prefix '" << Prefix | 51 Stream << "Warning : Default " << Kind << " prefix '" << Prefix |
51 << "' potentially conflicts with name '" << Name << "'.\n"; | 52 << "' potentially conflicts with name '" << Name << "'.\n"; |
52 return true; | 53 return true; |
53 } | 54 } |
54 return false; | 55 return false; |
55 } | 56 } |
56 | 57 |
57 void Translator::nameUnnamedGlobalAddresses(llvm::Module *Mod) { | |
58 const IceString &GlobalPrefix = Flags.DefaultGlobalPrefix; | |
59 if (GlobalPrefix.empty()) | |
60 return; | |
61 uint32_t NameIndex = 0; | |
62 Ostream &errs = Ctx->getStrDump(); | |
63 for (auto V = Mod->global_begin(), E = Mod->global_end(); V != E; ++V) { | |
64 if (!V->hasName()) { | |
65 V->setName(createUnnamedName(GlobalPrefix, NameIndex)); | |
66 ++NameIndex; | |
67 } else { | |
68 checkIfUnnamedNameSafe(V->getName(), "global", GlobalPrefix, errs); | |
69 } | |
70 } | |
71 } | |
72 | |
73 void Translator::nameUnnamedFunctions(llvm::Module *Mod) { | |
74 const IceString &FunctionPrefix = Flags.DefaultFunctionPrefix; | |
75 if (FunctionPrefix.empty()) | |
76 return; | |
77 uint32_t NameIndex = 0; | |
78 Ostream &errs = Ctx->getStrDump(); | |
79 for (llvm::Function &F : *Mod) { | |
80 if (!F.hasName()) { | |
81 F.setName(createUnnamedName(FunctionPrefix, NameIndex)); | |
82 ++NameIndex; | |
83 } else { | |
84 checkIfUnnamedNameSafe(F.getName(), "function", FunctionPrefix, errs); | |
85 } | |
86 } | |
87 } | |
88 | |
89 void Translator::translateFcn(Cfg *Fcn) { | 58 void Translator::translateFcn(Cfg *Fcn) { |
90 Ctx->resetStats(); | 59 Ctx->resetStats(); |
91 Func.reset(Fcn); | 60 Func.reset(Fcn); |
92 if (Ctx->getFlags().DisableInternal) | 61 if (Ctx->getFlags().DisableInternal) |
93 Func->setInternal(false); | 62 Func->setInternal(false); |
94 if (Ctx->getFlags().DisableTranslation) { | 63 if (Ctx->getFlags().DisableTranslation) { |
95 Func->dump(); | 64 Func->dump(); |
96 } else { | 65 } else { |
97 Func->translate(); | 66 Func->translate(); |
98 if (Func->hasError()) { | 67 if (Func->hasError()) { |
99 std::cerr << "ICE translation error: " << Func->getError() << "\n"; | 68 std::cerr << "ICE translation error: " << Func->getError() << "\n"; |
100 ErrorStatus = true; | 69 ErrorStatus = true; |
101 } | 70 } |
102 | 71 |
103 Func->emit(); | 72 Func->emit(); |
104 Ctx->dumpStats(Func->getFunctionName()); | 73 Ctx->dumpStats(Func->getFunctionName()); |
105 } | 74 } |
106 } | 75 } |
107 | 76 |
108 void Translator::emitConstants() { | 77 void Translator::emitConstants() { |
109 if (!Ctx->getFlags().DisableTranslation && Func) | 78 if (!Ctx->getFlags().DisableTranslation && Func) |
110 Func->getTarget()->emitConstants(); | 79 Func->getTarget()->emitConstants(); |
111 } | 80 } |
112 | 81 |
113 void Translator::lowerGlobals(const GlobalAddressList &GlobalAddresses) { | 82 void Translator::lowerGlobals( |
114 llvm::OwningPtr<Ice::TargetGlobalInitLowering> GlobalLowering( | 83 const VariableDeclarationListType &VariableDeclarations) { |
115 Ice::TargetGlobalInitLowering::createLowering(Ctx->getTargetArch(), Ctx)); | 84 llvm::OwningPtr<TargetGlobalInitLowering> GlobalLowering( |
| 85 TargetGlobalInitLowering::createLowering(Ctx->getTargetArch(), Ctx)); |
116 bool DisableTranslation = Ctx->getFlags().DisableTranslation; | 86 bool DisableTranslation = Ctx->getFlags().DisableTranslation; |
117 for (const Ice::GlobalAddress *Addr : GlobalAddresses) { | 87 bool DumpGlobalVariables = Ctx->isVerbose(); |
118 GlobalLowering->lower(*Addr, DisableTranslation); | 88 Ostream &Stream = Ctx->getStrDump(); |
| 89 for (const Ice::VariableDeclaration *Global : VariableDeclarations) { |
| 90 if (DumpGlobalVariables) |
| 91 Global->dump(Stream); |
| 92 if(!DisableTranslation) |
| 93 GlobalLowering->lower(*Global); |
119 } | 94 } |
120 GlobalLowering.reset(); | 95 GlobalLowering.reset(); |
121 } | 96 } |
OLD | NEW |