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

Side by Side Diff: src/IceTargetLowering.cpp

Issue 1614273002: Subzero: Make -reg-use and -reg-exclude specific to register class. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Cleanup 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 } 131 }
132 if (Count > 0 && Count % RegistersPerLine == 0) 132 if (Count > 0 && Count % RegistersPerLine == 0)
133 Str << "\n" << LineIndentString; 133 Str << "\n" << LineIndentString;
134 ++Count; 134 ++Count;
135 Str << getRegName(i); 135 Str << getRegName(i);
136 } 136 }
137 if (Count) 137 if (Count)
138 Str << "\n"; 138 Str << "\n";
139 } 139 }
140 140
141 // Splits "<class>:<reg>" into "<class>" plus "<reg>". If there is no <class>
142 // component, the result is "" plus "<reg>".
143 void splitToClassAndName(const IceString &RegName, IceString *SplitRegClass,
144 IceString *SplitRegName) {
145 constexpr const char Separator[] = ":";
146 constexpr size_t SeparatorWidth = llvm::array_lengthof(Separator) - 1;
147 size_t Pos = RegName.find(Separator);
148 if (Pos == std::string::npos) {
149 *SplitRegClass = "";
150 *SplitRegName = RegName;
151 } else {
152 *SplitRegClass = RegName.substr(0, Pos);
153 *SplitRegName = RegName.substr(Pos + SeparatorWidth);
154 }
155 }
156
141 } // end of anonymous namespace 157 } // end of anonymous namespace
142 158
143 void TargetLowering::filterTypeToRegisterSet( 159 void TargetLowering::filterTypeToRegisterSet(
144 GlobalContext *Ctx, int32_t NumRegs, 160 GlobalContext *Ctx, int32_t NumRegs,
145 llvm::SmallBitVector TypeToRegisterSet[], size_t TypeToRegisterSetSize, 161 llvm::SmallBitVector TypeToRegisterSet[], size_t TypeToRegisterSetSize,
146 std::function<IceString(int32_t)> getRegName) { 162 std::function<IceString(int32_t)> getRegName,
147 llvm::SmallBitVector ExcludeBitSet(NumRegs); 163 std::function<IceString(RegClass)> getRegClassName) {
148 std::vector<llvm::SmallBitVector> UseSet(TypeToRegisterSetSize, 164 std::vector<llvm::SmallBitVector> UseSet(TypeToRegisterSetSize,
149 ExcludeBitSet); 165 llvm::SmallBitVector(NumRegs)),
150 ExcludeBitSet.flip(); 166 ExcludeSet(TypeToRegisterSetSize, llvm::SmallBitVector(NumRegs));
151 167
152 std::unordered_map<IceString, int32_t> RegNameToIndex; 168 std::unordered_map<IceString, int32_t> RegNameToIndex;
153 for (int32_t RegIndex = 0; RegIndex < NumRegs; ++RegIndex) 169 for (int32_t RegIndex = 0; RegIndex < NumRegs; ++RegIndex)
154 RegNameToIndex[getRegName(RegIndex)] = RegIndex; 170 RegNameToIndex[getRegName(RegIndex)] = RegIndex;
155 171
156 ClFlags::StringVector BadRegNames; 172 ClFlags::StringVector BadRegNames;
157 for (const IceString &RegName : Ctx->getFlags().getUseRestrictedRegisters()) {
158 if (!RegNameToIndex.count(RegName)) {
159 BadRegNames.push_back(RegName);
160 continue;
161 }
162 const int32_t RegIndex = RegNameToIndex[RegName];
163 for (SizeT TypeIndex = 0; TypeIndex < TypeToRegisterSetSize; ++TypeIndex)
164 UseSet[TypeIndex][RegIndex] = TypeToRegisterSet[TypeIndex][RegIndex];
165 }
166 173
167 for (const IceString &RegName : Ctx->getFlags().getExcludedRegisters()) { 174 // The processRegList function iterates across the RegNames vector. Each
168 if (!RegNameToIndex.count(RegName)) { 175 // entry in the vector is a string of the form "<reg>" or "<class>:<reg>".
169 BadRegNames.push_back(RegName); 176 // The register class and register number are computed, and the corresponding
170 continue; 177 // bit is set in RegSet[][]. If "<class>:" is missing, then the bit is set
171 } 178 // for all classes.
172 ExcludeBitSet[RegNameToIndex[RegName]] = false; 179 auto processRegList =
173 } 180 [&BadRegNames, RegNameToIndex, TypeToRegisterSet, TypeToRegisterSetSize,
Karl 2016/01/22 17:10:54 Why not just use [&] and let the compiler figure o
Jim Stichnoth 2016/01/22 19:02:17 Sweet, I had no idea!
181 getRegClassName](const ClFlags::StringVector &RegNames,
182 std::vector<llvm::SmallBitVector> &RegSet) {
183 for (const IceString &RegClassAndName : RegNames) {
184 IceString RClass, RName;
Karl 2016/01/22 17:10:54 I don't think our style allowed multiple variables
Jim Stichnoth 2016/01/22 19:02:17 Not sure that style issue is actually addressed an
185 splitToClassAndName(RegClassAndName, &RClass, &RName);
186 if (!RegNameToIndex.count(RName)) {
187 BadRegNames.push_back(RName);
188 continue;
189 }
190 const int32_t RegIndex = RegNameToIndex.at(RName);
191 for (SizeT TypeIndex = 0; TypeIndex < TypeToRegisterSetSize;
192 ++TypeIndex) {
193 if (RClass.empty() ||
194 RClass == getRegClassName(static_cast<RegClass>(TypeIndex))) {
195 RegSet[TypeIndex][RegIndex] =
196 TypeToRegisterSet[TypeIndex][RegIndex];
197 }
198 }
199 }
200 };
201
202 processRegList(Ctx->getFlags().getUseRestrictedRegisters(), UseSet);
203 processRegList(Ctx->getFlags().getExcludedRegisters(), ExcludeSet);
174 204
175 if (!BadRegNames.empty()) { 205 if (!BadRegNames.empty()) {
176 std::string Buffer; 206 std::string Buffer;
177 llvm::raw_string_ostream StrBuf(Buffer); 207 llvm::raw_string_ostream StrBuf(Buffer);
178 StrBuf << "Unrecognized use/exclude registers:"; 208 StrBuf << "Unrecognized use/exclude registers:";
179 for (const auto &RegName : BadRegNames) 209 for (const auto &RegName : BadRegNames)
180 StrBuf << " " << RegName; 210 StrBuf << " " << RegName;
181 llvm::report_fatal_error(StrBuf.str()); 211 llvm::report_fatal_error(StrBuf.str());
182 } 212 }
183 213
184 // Apply filters. 214 // Apply filters.
185 for (size_t TypeIndex = 0; TypeIndex < TypeToRegisterSetSize; ++TypeIndex) { 215 for (size_t TypeIndex = 0; TypeIndex < TypeToRegisterSetSize; ++TypeIndex) {
186 llvm::SmallBitVector *TypeBitSet = &TypeToRegisterSet[TypeIndex]; 216 llvm::SmallBitVector *TypeBitSet = &TypeToRegisterSet[TypeIndex];
187 llvm::SmallBitVector *UseBitSet = &UseSet[TypeIndex]; 217 llvm::SmallBitVector *UseBitSet = &UseSet[TypeIndex];
218 llvm::SmallBitVector *ExcludeBitSet = &ExcludeSet[TypeIndex];
188 if (UseBitSet->any()) 219 if (UseBitSet->any())
189 *TypeBitSet = *UseBitSet; 220 *TypeBitSet = *UseBitSet;
190 *TypeBitSet &= ExcludeBitSet; 221 (*TypeBitSet).reset(*ExcludeBitSet);
191 } 222 }
192 223
193 // Display filtered register sets, if requested. 224 // Display filtered register sets, if requested.
194 if (BuildDefs::dump() && NumRegs && 225 if (BuildDefs::dump() && NumRegs &&
195 (Ctx->getFlags().getVerbose() & IceV_AvailableRegs)) { 226 (Ctx->getFlags().getVerbose() & IceV_AvailableRegs)) {
196 Ostream &Str = Ctx->getStrDump(); 227 Ostream &Str = Ctx->getStrDump();
197 const IceString Indent = " "; 228 const IceString Indent = " ";
198 const IceString IndentTwice = Indent + Indent; 229 const IceString IndentTwice = Indent + Indent;
199 Str << "Registers available for register allocation:\n"; 230 Str << "Registers available for register allocation:\n";
200 for (size_t TypeIndex = 0; TypeIndex < TypeToRegisterSetSize; ++TypeIndex) { 231 for (size_t TypeIndex = 0; TypeIndex < TypeToRegisterSetSize; ++TypeIndex) {
201 Str << Indent; 232 Str << Indent << getRegClassName(static_cast<RegClass>(TypeIndex))
202 if (TypeIndex < IceType_NUM) { 233 << ":\n";
203 Str << typeString(static_cast<Type>(TypeIndex));
204 } else {
205 Str << "other[" << TypeIndex << "]";
206 }
207 Str << ":\n";
208 printRegisterSet(Str, TypeToRegisterSet[TypeIndex], getRegName, 234 printRegisterSet(Str, TypeToRegisterSet[TypeIndex], getRegName,
209 IndentTwice); 235 IndentTwice);
210 } 236 }
211 Str << "\n"; 237 Str << "\n";
212 } 238 }
213 } 239 }
214 240
215 std::unique_ptr<TargetLowering> 241 std::unique_ptr<TargetLowering>
216 TargetLowering::createLowering(TargetArch Target, Cfg *Func) { 242 TargetLowering::createLowering(TargetArch Target, Cfg *Func) {
217 switch (Target) { 243 switch (Target) {
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 case Target_##X: \ 843 case Target_##X: \
818 return ::X::createTargetHeaderLowering(Ctx); 844 return ::X::createTargetHeaderLowering(Ctx);
819 #include "llvm/Config/SZTargets.def" 845 #include "llvm/Config/SZTargets.def"
820 #undef SUBZERO_TARGET 846 #undef SUBZERO_TARGET
821 } 847 }
822 } 848 }
823 849
824 TargetHeaderLowering::~TargetHeaderLowering() = default; 850 TargetHeaderLowering::~TargetHeaderLowering() = default;
825 851
826 } // end of namespace Ice 852 } // end of namespace Ice
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698