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

Side by Side Diff: src/IceTargetLowering.cpp

Issue 1571433004: Implements include/exclude register lists for translation. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Add CL tests. Created 4 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
OLDNEW
1 //===- subzero/src/IceTargetLowering.cpp - Basic lowering implementation --===// 1 //===- subzero/src/IceTargetLowering.cpp - Basic lowering implementation --===//
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 /// \file 10 /// \file
(...skipping 21 matching lines...) Expand all
32 // (TargetLowering, TargetDataLowering, and TargetHeaderLowering) we use the 32 // (TargetLowering, TargetDataLowering, and TargetHeaderLowering) we use the
33 // following named constructors. For reference, each target Foo needs to 33 // following named constructors. For reference, each target Foo needs to
34 // implement the following named constructors and initializer: 34 // implement the following named constructors and initializer:
35 // 35 //
36 // namespace Foo { 36 // namespace Foo {
37 // unique_ptr<Ice::TargetLowering> createTargetLowering(Ice::Cfg *); 37 // unique_ptr<Ice::TargetLowering> createTargetLowering(Ice::Cfg *);
38 // unique_ptr<Ice::TargetDataLowering> 38 // unique_ptr<Ice::TargetDataLowering>
39 // createTargetDataLowering(Ice::GlobalContext*); 39 // createTargetDataLowering(Ice::GlobalContext*);
40 // unique_ptr<Ice::TargetHeaderLowering> 40 // unique_ptr<Ice::TargetHeaderLowering>
41 // createTargetHeaderLowering(Ice::GlobalContext *); 41 // createTargetHeaderLowering(Ice::GlobalContext *);
42 // void staticInit(const ::Ice::ClFlags &Flags); 42 // void staticInit(::Ice::GlobalContext *);
43 // } 43 // }
44 #define SUBZERO_TARGET(X) \ 44 #define SUBZERO_TARGET(X) \
45 namespace X { \ 45 namespace X { \
46 std::unique_ptr<::Ice::TargetLowering> \ 46 std::unique_ptr<::Ice::TargetLowering> \
47 createTargetLowering(::Ice::Cfg *Func); \ 47 createTargetLowering(::Ice::Cfg *Func); \
48 std::unique_ptr<::Ice::TargetDataLowering> \ 48 std::unique_ptr<::Ice::TargetDataLowering> \
49 createTargetDataLowering(::Ice::GlobalContext *Ctx); \ 49 createTargetDataLowering(::Ice::GlobalContext *Ctx); \
50 std::unique_ptr<::Ice::TargetHeaderLowering> \ 50 std::unique_ptr<::Ice::TargetHeaderLowering> \
51 createTargetHeaderLowering(::Ice::GlobalContext *Ctx); \ 51 createTargetHeaderLowering(::Ice::GlobalContext *Ctx); \
52 void staticInit(const ::Ice::ClFlags &Flags); \ 52 void staticInit(::Ice::GlobalContext *Ctx); \
53 } // end of namespace X 53 } // end of namespace X
54 #include "llvm/Config/SZTargets.def" 54 #include "llvm/Config/SZTargets.def"
55 #undef SUBZERO_TARGET 55 #undef SUBZERO_TARGET
56 56
57 namespace Ice { 57 namespace Ice {
58 void LoweringContext::init(CfgNode *N) { 58 void LoweringContext::init(CfgNode *N) {
59 Node = N; 59 Node = N;
60 End = getNode()->getInsts().end(); 60 End = getNode()->getInsts().end();
61 rewind(); 61 rewind();
62 advanceForward(Next); 62 advanceForward(Next);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 LastSrc = llvm::cast<Variable>(Instr->getSrc(0)); 109 LastSrc = llvm::cast<Variable>(Instr->getSrc(0));
110 } 110 }
111 111
112 Variable *LoweringContext::availabilityGet(Operand *Src) const { 112 Variable *LoweringContext::availabilityGet(Operand *Src) const {
113 assert(Src); 113 assert(Src);
114 if (Src == LastDest) 114 if (Src == LastDest)
115 return LastSrc; 115 return LastSrc;
116 return nullptr; 116 return nullptr;
117 } 117 }
118 118
119 namespace {
120
121 void printRegisterSet(Ostream &Str, const llvm::SmallBitVector &Bitset,
122 std::function<IceString(int32_t)> getRegName,
Jim Stichnoth 2016/01/15 00:50:56 My head nearly exploded as I investigated the inco
Karl 2016/01/15 16:54:24 Acknowledged.
123 SizeT LineIndent) {
Jim Stichnoth 2016/01/15 00:50:56 Change SizeT to size_t. Also, I would change its
Karl 2016/01/15 16:54:24 Done.
124 constexpr int RegistersPerLine = 16;
Jim Stichnoth 2016/01/15 00:50:56 Probably want the types of RegisterPerLine and Cou
Karl 2016/01/15 16:54:24 Done.
125 size_t Count = 0;
126 constexpr int BitsetEnd = -1;
Jim Stichnoth 2016/01/15 00:50:56 I wouldn't use BitsetEnd, I would just use the raw
Karl 2016/01/15 16:54:24 Done.
127 IceString Indent = std::string(LineIndent, ' ');
128 for (int i = Bitset.find_first(); i != BitsetEnd; i = Bitset.find_next(i)) {
129 if (Count == 0) {
130 Str << Indent;
131 } else {
132 Str << ",";
133 }
134 if (Count > 0 && Count % RegistersPerLine == 0)
135 Str << "\n" << Indent;
136 ++Count;
137 Str << getRegName(i);
138 }
139 if (Count)
140 Str << "\n";
141 }
142
143 } // end of anonymous namespace
144
145 void TargetLowering::filterTypeToRegisterSet(
146 GlobalContext *Ctx, int32_t NumRegs,
147 llvm::SmallBitVector TypeToRegisterSet[], size_t TypeToRegisterSetSize,
148 std::function<IceString(int32_t)> getRegName) {
149 llvm::SmallBitVector ExcludeBitSet(NumRegs);
150 std::vector<llvm::SmallBitVector> UseSet(TypeToRegisterSetSize,
151 ExcludeBitSet);
152 ExcludeBitSet.flip();
153
154 std::unordered_map<IceString, int32_t> RegNameToIndex;
155 for (int32_t RegIndex = 0; RegIndex < NumRegs; ++RegIndex)
156 RegNameToIndex[getRegName(RegIndex)] = RegIndex;
157
158 for (const IceString &RegName : Ctx->getFlags().getUseRestrictedRegisters()) {
159 if (!RegNameToIndex.count(RegName))
160 llvm::report_fatal_error("Can't find register use: " + RegName);
Jim Stichnoth 2016/01/15 00:50:56 It would be nicer if it would tell me *all* the re
Karl 2016/01/15 16:54:24 Done.
161 const int32_t RegIndex = RegNameToIndex[RegName];
162 for (SizeT TypeIndex = 0; TypeIndex < TypeToRegisterSetSize; ++TypeIndex)
163 UseSet[TypeIndex][RegIndex] = TypeToRegisterSet[TypeIndex][RegIndex];
164 }
165
166 for (const IceString &RegName : Ctx->getFlags().getExcludedRegisters()) {
167 if (!RegNameToIndex.count(RegName))
168 llvm::report_fatal_error("Can't find register exclude: " + RegName);
169 ExcludeBitSet[RegNameToIndex[RegName]] = false;
170 }
171
172 // Apply filters.
173 for (size_t TypeIndex = 0; TypeIndex < TypeToRegisterSetSize; ++TypeIndex) {
174 llvm::SmallBitVector *TypeBitSet = &TypeToRegisterSet[TypeIndex];
175 llvm::SmallBitVector *UseBitSet = &UseSet[TypeIndex];
176 if (UseBitSet->any())
177 *TypeBitSet = *UseBitSet;
178 *TypeBitSet &= ExcludeBitSet;
179 }
180
181 // Display filtered register sets, if requested.
182 if (BuildDefs::dump() && NumRegs &&
183 (Ctx->getFlags().getVerbose() & IceV_AvailableRegs)) {
184 Ostream &Str = Ctx->getStrDump();
185 constexpr const char LineIndent[] = " ";
186 const size_t RegSetIndent = 2 * llvm::array_lengthof(LineIndent);
187 Str << "Registers available for register allocation:\n";
188 for (size_t TypeIndex = 0; TypeIndex < TypeToRegisterSetSize; ++TypeIndex) {
189 Str << LineIndent;
190 if (TypeIndex < IceType_NUM) {
191 Str << typeString(static_cast<Type>(TypeIndex));
192 } else {
193 Str << "other[" << TypeIndex << "]";
194 }
195 Str << ":\n";
196 printRegisterSet(Str, TypeToRegisterSet[TypeIndex], getRegName,
197 RegSetIndent);
198 }
199 Str << "\n";
200 }
201 }
202
119 std::unique_ptr<TargetLowering> 203 std::unique_ptr<TargetLowering>
120 TargetLowering::createLowering(TargetArch Target, Cfg *Func) { 204 TargetLowering::createLowering(TargetArch Target, Cfg *Func) {
121 switch (Target) { 205 switch (Target) {
122 default: 206 default:
123 llvm::report_fatal_error("Unsupported target"); 207 llvm::report_fatal_error("Unsupported target");
124 #define SUBZERO_TARGET(X) \ 208 #define SUBZERO_TARGET(X) \
125 case Target_##X: \ 209 case Target_##X: \
126 return ::X::createTargetLowering(Func); 210 return ::X::createTargetLowering(Func);
127 #include "llvm/Config/SZTargets.def" 211 #include "llvm/Config/SZTargets.def"
128 #undef SUBZERO_TARGET 212 #undef SUBZERO_TARGET
129 } 213 }
130 } 214 }
131 215
132 void TargetLowering::staticInit(const ClFlags &Flags) { 216 void TargetLowering::staticInit(GlobalContext *Ctx) {
133 const TargetArch Target = Flags.getTargetArch(); 217 const TargetArch Target = Ctx->getFlags().getTargetArch();
134 // Call the specified target's static initializer. 218 // Call the specified target's static initializer.
135 switch (Target) { 219 switch (Target) {
136 default: 220 default:
137 llvm::report_fatal_error("Unsupported target"); 221 llvm::report_fatal_error("Unsupported target");
138 #define SUBZERO_TARGET(X) \ 222 #define SUBZERO_TARGET(X) \
139 case Target_##X: { \ 223 case Target_##X: { \
140 static bool InitGuard##X = false; \ 224 static bool InitGuard##X = false; \
141 if (InitGuard##X) { \ 225 if (InitGuard##X) { \
142 return; \ 226 return; \
143 } \ 227 } \
144 InitGuard##X = true; \ 228 InitGuard##X = true; \
145 ::X::staticInit(Flags); \ 229 ::X::staticInit(Ctx); \
146 } break; 230 } break;
147 #include "llvm/Config/SZTargets.def" 231 #include "llvm/Config/SZTargets.def"
148 #undef SUBZERO_TARGET 232 #undef SUBZERO_TARGET
149 } 233 }
150 } 234 }
151 235
152 TargetLowering::TargetLowering(Cfg *Func) 236 TargetLowering::TargetLowering(Cfg *Func)
153 : Func(Func), Ctx(Func->getContext()), Context() {} 237 : Func(Func), Ctx(Func->getContext()), Context() {}
154 238
155 void TargetLowering::genTargetHelperCalls() { 239 void TargetLowering::genTargetHelperCalls() {
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 case Target_##X: \ 766 case Target_##X: \
683 return ::X::createTargetHeaderLowering(Ctx); 767 return ::X::createTargetHeaderLowering(Ctx);
684 #include "llvm/Config/SZTargets.def" 768 #include "llvm/Config/SZTargets.def"
685 #undef SUBZERO_TARGET 769 #undef SUBZERO_TARGET
686 } 770 }
687 } 771 }
688 772
689 TargetHeaderLowering::~TargetHeaderLowering() = default; 773 TargetHeaderLowering::~TargetHeaderLowering() = default;
690 774
691 } // end of namespace Ice 775 } // end of namespace Ice
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698