Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: src/IceTranslator.cpp

Issue 870653002: Subzero: Initial implementation of multithreaded translation. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Rebase Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/IceTranslator.h ('k') | src/IceUtils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 { 24 Translator::Translator(GlobalContext *Ctx, const ClFlags &Flags)
32 25 : Ctx(Ctx), Flags(Flags),
33 // Match a symbol name against a match string. An empty match string 26 GlobalLowering(TargetGlobalLowering::createLowering(Ctx)), ErrorStatus() {
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 } 27 }
38 28
39 } // end of anonymous namespace
40
41 Translator::~Translator() {} 29 Translator::~Translator() {}
42 30
43 IceString Translator::createUnnamedName(const IceString &Prefix, SizeT Index) { 31 IceString Translator::createUnnamedName(const IceString &Prefix, SizeT Index) {
44 if (Index == 0) 32 if (Index == 0)
45 return Prefix; 33 return Prefix;
46 std::string Buffer; 34 std::string Buffer;
47 llvm::raw_string_ostream StrBuf(Buffer); 35 llvm::raw_string_ostream StrBuf(Buffer);
48 StrBuf << Prefix << Index; 36 StrBuf << Prefix << Index;
49 return StrBuf.str(); 37 return StrBuf.str();
50 } 38 }
51 39
52 bool Translator::checkIfUnnamedNameSafe(const IceString &Name, const char *Kind, 40 bool Translator::checkIfUnnamedNameSafe(const IceString &Name, const char *Kind,
53 const IceString &Prefix) { 41 const IceString &Prefix) {
54 if (Name.find(Prefix) == 0) { 42 if (Name.find(Prefix) == 0) {
55 for (size_t i = Prefix.size(); i < Name.size(); ++i) { 43 for (size_t i = Prefix.size(); i < Name.size(); ++i) {
56 if (!isdigit(Name[i])) { 44 if (!isdigit(Name[i])) {
57 return false; 45 return false;
58 } 46 }
59 } 47 }
60 OstreamLocker L(Ctx); 48 OstreamLocker L(Ctx);
61 Ostream &Stream = Ctx->getStrDump(); 49 Ostream &Stream = Ctx->getStrDump();
62 Stream << "Warning : Default " << Kind << " prefix '" << Prefix 50 Stream << "Warning : Default " << Kind << " prefix '" << Prefix
63 << "' potentially conflicts with name '" << Name << "'.\n"; 51 << "' potentially conflicts with name '" << Name << "'.\n";
64 return true; 52 return true;
65 } 53 }
66 return false; 54 return false;
67 } 55 }
68 56
69 void Translator::translateFcn(Cfg *Fcn) { 57 void Translator::translateFcn(Cfg *Func) {
70 Ctx->resetStats(); 58 Ctx->cfgQueueBlockingPush(Func);
71 Func.reset(Fcn); 59 if (Ctx->getFlags().NumTranslationThreads == 0) {
72 VerboseMask OldVerboseMask = Ctx->getVerbose(); 60 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 } 61 }
96
97 Ctx->setVerbose(OldVerboseMask);
98 } 62 }
99 63
100 void Translator::emitConstants() { 64 void Translator::emitConstants() {
101 if (!Ctx->getFlags().DisableTranslation && Func) 65 if (!getErrorStatus())
102 Func->getTarget()->emitConstants(); 66 GlobalLowering->lowerConstants(Ctx);
67 }
68
69 void Translator::transferErrorCode() const {
70 if (getErrorStatus())
71 Ctx->getErrorStatus()->assign(getErrorStatus().value());
103 } 72 }
104 73
105 void Translator::lowerGlobals( 74 void Translator::lowerGlobals(
106 const VariableDeclarationListType &VariableDeclarations) { 75 const VariableDeclarationListType &VariableDeclarations) {
107 std::unique_ptr<TargetGlobalInitLowering> GlobalLowering(
108 TargetGlobalInitLowering::createLowering(Ctx->getTargetArch(), Ctx));
109 bool DisableTranslation = Ctx->getFlags().DisableTranslation; 76 bool DisableTranslation = Ctx->getFlags().DisableTranslation;
110 const bool DumpGlobalVariables = 77 const bool DumpGlobalVariables =
111 ALLOW_DUMP && Ctx->isVerbose() && Ctx->getFlags().VerboseFocusOn.empty(); 78 ALLOW_DUMP && Ctx->getVerbose() && Ctx->getFlags().VerboseFocusOn.empty();
112 OstreamLocker L(Ctx); 79 OstreamLocker L(Ctx);
113 Ostream &Stream = Ctx->getStrDump(); 80 Ostream &Stream = Ctx->getStrDump();
114 const IceString &TranslateOnly = Ctx->getFlags().TranslateOnly; 81 const IceString &TranslateOnly = Ctx->getFlags().TranslateOnly;
115 for (const Ice::VariableDeclaration *Global : VariableDeclarations) { 82 for (const Ice::VariableDeclaration *Global : VariableDeclarations) {
116 if (DumpGlobalVariables) 83 if (DumpGlobalVariables)
117 Global->dump(getContext(), Stream); 84 Global->dump(getContext(), Stream);
118 if (!DisableTranslation && 85 if (!DisableTranslation &&
119 matchSymbolName(Global->getName(), TranslateOnly)) 86 GlobalContext::matchSymbolName(Global->getName(), TranslateOnly))
120 GlobalLowering->lower(*Global); 87 GlobalLowering->lowerInit(*Global);
121 } 88 }
122 GlobalLowering.reset();
123 } 89 }
OLDNEW
« no previous file with comments | « src/IceTranslator.h ('k') | src/IceUtils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698