| 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> | |
| 16 #include <memory> | |
| 17 | |
| 18 #include "llvm/IR/Constant.h" | |
| 19 #include "llvm/IR/Constants.h" | |
| 20 #include "llvm/IR/Module.h" | |
| 21 | |
| 22 #include "IceCfg.h" | 15 #include "IceCfg.h" |
| 23 #include "IceClFlags.h" | 16 #include "IceClFlags.h" |
| 24 #include "IceDefs.h" | 17 #include "IceDefs.h" |
| 25 #include "IceGlobalInits.h" | 18 #include "IceGlobalInits.h" |
| 26 #include "IceTargetLowering.h" | 19 #include "IceTargetLowering.h" |
| 27 #include "IceTranslator.h" | 20 #include "IceTranslator.h" |
| 28 | 21 |
| 29 using namespace Ice; | 22 using namespace Ice; |
| 30 | 23 |
| 31 namespace { | |
| 32 | |
| 33 // Match a symbol name against a match string. An empty match string | |
| 34 // means match everything. Returns true if there is a match. | |
| 35 bool matchSymbolName(const IceString &SymbolName, const IceString &Match) { | |
| 36 return Match.empty() || Match == SymbolName; | |
| 37 } | |
| 38 | |
| 39 } // end of anonymous namespace | |
| 40 | |
| 41 Translator::~Translator() {} | 24 Translator::~Translator() {} |
| 42 | 25 |
| 43 IceString Translator::createUnnamedName(const IceString &Prefix, SizeT Index) { | 26 IceString Translator::createUnnamedName(const IceString &Prefix, SizeT Index) { |
| 44 if (Index == 0) | 27 if (Index == 0) |
| 45 return Prefix; | 28 return Prefix; |
| 46 std::string Buffer; | 29 std::string Buffer; |
| 47 llvm::raw_string_ostream StrBuf(Buffer); | 30 llvm::raw_string_ostream StrBuf(Buffer); |
| 48 StrBuf << Prefix << Index; | 31 StrBuf << Prefix << Index; |
| 49 return StrBuf.str(); | 32 return StrBuf.str(); |
| 50 } | 33 } |
| 51 | 34 |
| 52 bool Translator::checkIfUnnamedNameSafe(const IceString &Name, const char *Kind, | 35 bool Translator::checkIfUnnamedNameSafe(const IceString &Name, const char *Kind, |
| 53 const IceString &Prefix) { | 36 const IceString &Prefix) { |
| 54 if (Name.find(Prefix) == 0) { | 37 if (Name.find(Prefix) == 0) { |
| 55 for (size_t i = Prefix.size(); i < Name.size(); ++i) { | 38 for (size_t i = Prefix.size(); i < Name.size(); ++i) { |
| 56 if (!isdigit(Name[i])) { | 39 if (!isdigit(Name[i])) { |
| 57 return false; | 40 return false; |
| 58 } | 41 } |
| 59 } | 42 } |
| 60 OstreamLocker L(Ctx); | 43 OstreamLocker L(Ctx); |
| 61 Ostream &Stream = Ctx->getStrDump(); | 44 Ostream &Stream = Ctx->getStrDump(); |
| 62 Stream << "Warning : Default " << Kind << " prefix '" << Prefix | 45 Stream << "Warning : Default " << Kind << " prefix '" << Prefix |
| 63 << "' potentially conflicts with name '" << Name << "'.\n"; | 46 << "' potentially conflicts with name '" << Name << "'.\n"; |
| 64 return true; | 47 return true; |
| 65 } | 48 } |
| 66 return false; | 49 return false; |
| 67 } | 50 } |
| 68 | 51 |
| 69 void Translator::translateFcn(Cfg *Fcn) { | 52 void Translator::translateFcn(Cfg *Func) { |
| 70 Ctx->resetStats(); | 53 Ctx->cfgQueueAdd(Func); |
| 71 Func.reset(Fcn); | 54 if (Ctx->getFlags().NumTranslationThreads == 0) { |
| 72 VerboseMask OldVerboseMask = Ctx->getVerbose(); | 55 Ctx->translateFunctions(); |
| 73 if (!matchSymbolName(Func->getFunctionName(), Ctx->getFlags().VerboseFocusOn)) | |
| 74 Ctx->setVerbose(IceV_None); | |
| 75 | |
| 76 if (Ctx->getFlags().DisableTranslation || | |
| 77 !matchSymbolName(Func->getFunctionName(), | |
| 78 Ctx->getFlags().TranslateOnly)) { | |
| 79 Func->dump(); | |
| 80 } else { | |
| 81 Func->translate(); | |
| 82 if (Func->hasError()) { | |
| 83 std::cerr << "ICE translation error: " << Func->getError() << "\n"; | |
| 84 ErrorStatus = true; | |
| 85 } | |
| 86 | |
| 87 if (!ErrorStatus) { | |
| 88 if (Ctx->getFlags().UseIntegratedAssembler) { | |
| 89 Func->emitIAS(); | |
| 90 } else { | |
| 91 Func->emit(); | |
| 92 } | |
| 93 } | |
| 94 Ctx->dumpStats(Func->getFunctionName()); | |
| 95 } | 56 } |
| 96 | |
| 97 Ctx->setVerbose(OldVerboseMask); | |
| 98 } | 57 } |
| 99 | 58 |
| 100 void Translator::emitConstants() { | 59 void Translator::emitConstants() { |
| 101 if (!Ctx->getFlags().DisableTranslation && Func) | 60 if (!getErrorStatus()) |
| 102 Func->getTarget()->emitConstants(); | 61 TargetLowering::emitConstants(Ctx); |
| 103 } | 62 } |
| 104 | 63 |
| 105 void Translator::lowerGlobals( | 64 void Translator::lowerGlobals( |
| 106 const VariableDeclarationListType &VariableDeclarations) { | 65 const VariableDeclarationListType &VariableDeclarations) { |
| 107 std::unique_ptr<TargetGlobalInitLowering> GlobalLowering( | 66 std::unique_ptr<TargetGlobalInitLowering> GlobalLowering( |
| 108 TargetGlobalInitLowering::createLowering(Ctx->getTargetArch(), Ctx)); | 67 TargetGlobalInitLowering::createLowering(Ctx->getTargetArch(), Ctx)); |
| 109 bool DisableTranslation = Ctx->getFlags().DisableTranslation; | 68 bool DisableTranslation = Ctx->getFlags().DisableTranslation; |
| 110 const bool DumpGlobalVariables = | 69 const bool DumpGlobalVariables = |
| 111 ALLOW_DUMP && Ctx->isVerbose() && Ctx->getFlags().VerboseFocusOn.empty(); | 70 ALLOW_DUMP && Ctx->getVerbose() && Ctx->getFlags().VerboseFocusOn.empty(); |
| 112 OstreamLocker L(Ctx); | 71 OstreamLocker L(Ctx); |
| 113 Ostream &Stream = Ctx->getStrDump(); | 72 Ostream &Stream = Ctx->getStrDump(); |
| 114 const IceString &TranslateOnly = Ctx->getFlags().TranslateOnly; | 73 const IceString &TranslateOnly = Ctx->getFlags().TranslateOnly; |
| 115 for (const Ice::VariableDeclaration *Global : VariableDeclarations) { | 74 for (const Ice::VariableDeclaration *Global : VariableDeclarations) { |
| 116 if (DumpGlobalVariables) | 75 if (DumpGlobalVariables) |
| 117 Global->dump(getContext(), Stream); | 76 Global->dump(getContext(), Stream); |
| 118 if (!DisableTranslation && | 77 if (!DisableTranslation && |
| 119 matchSymbolName(Global->getName(), TranslateOnly)) | 78 GlobalContext::matchSymbolName(Global->getName(), TranslateOnly)) |
| 120 GlobalLowering->lower(*Global); | 79 GlobalLowering->lower(*Global); |
| 121 } | 80 } |
| 122 GlobalLowering.reset(); | 81 GlobalLowering.reset(); |
| 123 } | 82 } |
| OLD | NEW |