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 "IceTranslator.h" | 15 #include "IceTranslator.h" |
16 | 16 |
17 #include "IceCfg.h" | 17 #include "IceCfg.h" |
18 #include "IceClFlags.h" | 18 #include "IceClFlags.h" |
| 19 #include "IceDefs.h" |
19 #include "IceTargetLowering.h" | 20 #include "IceTargetLowering.h" |
| 21 #include "llvm/IR/Module.h" |
20 | 22 |
21 #include <iostream> | 23 #include <iostream> |
22 | 24 |
23 using namespace Ice; | 25 using namespace Ice; |
24 | 26 |
25 Translator::~Translator() {} | 27 Translator::~Translator() {} |
26 | 28 |
27 void Translator::translateFcn(Ice::Cfg *Fcn) { | 29 namespace { |
| 30 void setValueName(llvm::Value *V, const char *Kind, const IceString &Prefix, |
| 31 uint32_t &NameIndex, Ostream &errs) { |
| 32 if (V->hasName()) { |
| 33 const std::string &Name(V->getName()); |
| 34 if (Name.find(Prefix) == 0) { |
| 35 errs << "Warning: Default " << Kind << " prefix '" << Prefix |
| 36 << "' conflicts with name '" << Name << "'.\n"; |
| 37 } |
| 38 return; |
| 39 } |
| 40 if (NameIndex == 0) { |
| 41 V->setName(Prefix); |
| 42 ++NameIndex; |
| 43 return; |
| 44 } |
| 45 std::string Buffer; |
| 46 llvm::raw_string_ostream StrBuf(Buffer); |
| 47 StrBuf << Prefix << NameIndex; |
| 48 V->setName(StrBuf.str()); |
| 49 ++NameIndex; |
| 50 } |
| 51 } // end of anonymous namespace |
| 52 |
| 53 void Translator::nameUnnamedGlobalAddresses(llvm::Module *Mod) { |
| 54 const IceString &GlobalPrefix = Flags.DefaultGlobalPrefix; |
| 55 Ostream &errs = Ctx->getStrDump(); |
| 56 if (!GlobalPrefix.empty()) { |
| 57 uint32_t NameIndex = 0; |
| 58 for (llvm::Module::global_iterator I = Mod->global_begin(), |
| 59 E = Mod->global_end(); |
| 60 I != E; ++I) { |
| 61 setValueName(I, "global", GlobalPrefix, NameIndex, errs); |
| 62 } |
| 63 } |
| 64 const IceString &FunctionPrefix = Flags.DefaultFunctionPrefix; |
| 65 if (FunctionPrefix.empty()) |
| 66 return; |
| 67 uint32_t NameIndex = 0; |
| 68 for (llvm::Module::iterator I = Mod->begin(), E = Mod->end(); I != E; ++I) { |
| 69 setValueName(I, "function", FunctionPrefix, NameIndex, errs); |
| 70 } |
| 71 } |
| 72 |
| 73 void Translator::translateFcn(Cfg *Fcn) { |
28 Func.reset(Fcn); | 74 Func.reset(Fcn); |
29 if (Ctx->getFlags().DisableInternal) | 75 if (Ctx->getFlags().DisableInternal) |
30 Func->setInternal(false); | 76 Func->setInternal(false); |
31 if (Ctx->getFlags().DisableTranslation) { | 77 if (Ctx->getFlags().DisableTranslation) { |
32 Func->dump(); | 78 Func->dump(); |
33 } else { | 79 } else { |
34 Ice::Timer TTranslate; | 80 Timer TTranslate; |
35 Func->translate(); | 81 Func->translate(); |
36 if (Ctx->getFlags().SubzeroTimingEnabled) { | 82 if (Ctx->getFlags().SubzeroTimingEnabled) { |
37 std::cerr << "[Subzero timing] Translate function " | 83 std::cerr << "[Subzero timing] Translate function " |
38 << Func->getFunctionName() << ": " << TTranslate.getElapsedSec() | 84 << Func->getFunctionName() << ": " << TTranslate.getElapsedSec() |
39 << " sec\n"; | 85 << " sec\n"; |
40 } | 86 } |
41 if (Func->hasError()) { | 87 if (Func->hasError()) { |
42 std::cerr << "ICE translation error: " << Func->getError() << "\n"; | 88 std::cerr << "ICE translation error: " << Func->getError() << "\n"; |
43 ErrorStatus = true; | 89 ErrorStatus = true; |
44 } | 90 } |
45 | 91 |
46 Ice::Timer TEmit; | 92 Timer TEmit; |
47 Func->emit(); | 93 Func->emit(); |
48 if (Ctx->getFlags().SubzeroTimingEnabled) { | 94 if (Ctx->getFlags().SubzeroTimingEnabled) { |
49 std::cerr << "[Subzero timing] Emit function " << Func->getFunctionName() | 95 std::cerr << "[Subzero timing] Emit function " << Func->getFunctionName() |
50 << ": " << TEmit.getElapsedSec() << " sec\n"; | 96 << ": " << TEmit.getElapsedSec() << " sec\n"; |
51 } | 97 } |
52 } | 98 } |
53 } | 99 } |
54 | 100 |
55 void Translator::emitConstants() { | 101 void Translator::emitConstants() { |
56 if (!Ctx->getFlags().DisableTranslation && Func) | 102 if (!Ctx->getFlags().DisableTranslation && Func) |
57 Func->getTarget()->emitConstants(); | 103 Func->getTarget()->emitConstants(); |
58 } | 104 } |
OLD | NEW |