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

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: Add error log 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
« no previous file with comments | « src/IceTargetLowering.h ('k') | src/IceTargetLoweringARM32.cpp » ('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/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 std::vector<llvm::SmallBitVector> ExcludeSet(TypeToRegisterSetSize,
167 llvm::SmallBitVector(NumRegs));
151 168
152 std::unordered_map<IceString, int32_t> RegNameToIndex; 169 std::unordered_map<IceString, int32_t> RegNameToIndex;
153 for (int32_t RegIndex = 0; RegIndex < NumRegs; ++RegIndex) 170 for (int32_t RegIndex = 0; RegIndex < NumRegs; ++RegIndex)
154 RegNameToIndex[getRegName(RegIndex)] = RegIndex; 171 RegNameToIndex[getRegName(RegIndex)] = RegIndex;
155 172
156 ClFlags::StringVector BadRegNames; 173 ClFlags::StringVector BadRegNames;
157 for (const IceString &RegName : Ctx->getFlags().getUseRestrictedRegisters()) { 174
158 if (!RegNameToIndex.count(RegName)) { 175 // The processRegList function iterates across the RegNames vector. Each
159 BadRegNames.push_back(RegName); 176 // entry in the vector is a string of the form "<reg>" or "<class>:<reg>".
160 continue; 177 // The register class and register number are computed, and the corresponding
178 // bit is set in RegSet[][]. If "<class>:" is missing, then the bit is set
179 // for all classes.
180 auto processRegList = [&](const ClFlags::StringVector &RegNames,
181 std::vector<llvm::SmallBitVector> &RegSet) {
182 for (const IceString &RegClassAndName : RegNames) {
183 IceString RClass;
184 IceString RName;
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] = TypeToRegisterSet[TypeIndex][RegIndex];
196 }
197 }
161 } 198 }
162 const int32_t RegIndex = RegNameToIndex[RegName]; 199 };
163 for (SizeT TypeIndex = 0; TypeIndex < TypeToRegisterSetSize; ++TypeIndex)
164 UseSet[TypeIndex][RegIndex] = TypeToRegisterSet[TypeIndex][RegIndex];
165 }
166 200
167 for (const IceString &RegName : Ctx->getFlags().getExcludedRegisters()) { 201 processRegList(Ctx->getFlags().getUseRestrictedRegisters(), UseSet);
168 if (!RegNameToIndex.count(RegName)) { 202 processRegList(Ctx->getFlags().getExcludedRegisters(), ExcludeSet);
169 BadRegNames.push_back(RegName);
170 continue;
171 }
172 ExcludeBitSet[RegNameToIndex[RegName]] = false;
173 }
174 203
175 if (!BadRegNames.empty()) { 204 if (!BadRegNames.empty()) {
176 std::string Buffer; 205 std::string Buffer;
177 llvm::raw_string_ostream StrBuf(Buffer); 206 llvm::raw_string_ostream StrBuf(Buffer);
178 StrBuf << "Unrecognized use/exclude registers:"; 207 StrBuf << "Unrecognized use/exclude registers:";
179 for (const auto &RegName : BadRegNames) 208 for (const auto &RegName : BadRegNames)
180 StrBuf << " " << RegName; 209 StrBuf << " " << RegName;
181 llvm::report_fatal_error(StrBuf.str()); 210 llvm::report_fatal_error(StrBuf.str());
182 } 211 }
183 212
184 // Apply filters. 213 // Apply filters.
185 for (size_t TypeIndex = 0; TypeIndex < TypeToRegisterSetSize; ++TypeIndex) { 214 for (size_t TypeIndex = 0; TypeIndex < TypeToRegisterSetSize; ++TypeIndex) {
186 llvm::SmallBitVector *TypeBitSet = &TypeToRegisterSet[TypeIndex]; 215 llvm::SmallBitVector *TypeBitSet = &TypeToRegisterSet[TypeIndex];
187 llvm::SmallBitVector *UseBitSet = &UseSet[TypeIndex]; 216 llvm::SmallBitVector *UseBitSet = &UseSet[TypeIndex];
217 llvm::SmallBitVector *ExcludeBitSet = &ExcludeSet[TypeIndex];
188 if (UseBitSet->any()) 218 if (UseBitSet->any())
189 *TypeBitSet = *UseBitSet; 219 *TypeBitSet = *UseBitSet;
190 *TypeBitSet &= ExcludeBitSet; 220 (*TypeBitSet).reset(*ExcludeBitSet);
191 } 221 }
192 222
193 // Display filtered register sets, if requested. 223 // Display filtered register sets, if requested.
194 if (BuildDefs::dump() && NumRegs && 224 if (BuildDefs::dump() && NumRegs &&
195 (Ctx->getFlags().getVerbose() & IceV_AvailableRegs)) { 225 (Ctx->getFlags().getVerbose() & IceV_AvailableRegs)) {
196 Ostream &Str = Ctx->getStrDump(); 226 Ostream &Str = Ctx->getStrDump();
197 const IceString Indent = " "; 227 const IceString Indent = " ";
198 const IceString IndentTwice = Indent + Indent; 228 const IceString IndentTwice = Indent + Indent;
199 Str << "Registers available for register allocation:\n"; 229 Str << "Registers available for register allocation:\n";
200 for (size_t TypeIndex = 0; TypeIndex < TypeToRegisterSetSize; ++TypeIndex) { 230 for (size_t TypeIndex = 0; TypeIndex < TypeToRegisterSetSize; ++TypeIndex) {
201 Str << Indent; 231 Str << Indent << getRegClassName(static_cast<RegClass>(TypeIndex))
202 if (TypeIndex < IceType_NUM) { 232 << ":\n";
203 Str << typeString(static_cast<Type>(TypeIndex));
204 } else {
205 Str << "other[" << TypeIndex << "]";
206 }
207 Str << ":\n";
208 printRegisterSet(Str, TypeToRegisterSet[TypeIndex], getRegName, 233 printRegisterSet(Str, TypeToRegisterSet[TypeIndex], getRegName,
209 IndentTwice); 234 IndentTwice);
210 } 235 }
211 Str << "\n"; 236 Str << "\n";
212 } 237 }
213 } 238 }
214 239
215 std::unique_ptr<TargetLowering> 240 std::unique_ptr<TargetLowering>
216 TargetLowering::createLowering(TargetArch Target, Cfg *Func) { 241 TargetLowering::createLowering(TargetArch Target, Cfg *Func) {
217 switch (Target) { 242 switch (Target) {
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 case Target_##X: \ 842 case Target_##X: \
818 return ::X::createTargetHeaderLowering(Ctx); 843 return ::X::createTargetHeaderLowering(Ctx);
819 #include "llvm/Config/SZTargets.def" 844 #include "llvm/Config/SZTargets.def"
820 #undef SUBZERO_TARGET 845 #undef SUBZERO_TARGET
821 } 846 }
822 } 847 }
823 848
824 TargetHeaderLowering::~TargetHeaderLowering() = default; 849 TargetHeaderLowering::~TargetHeaderLowering() = default;
825 850
826 } // end of namespace Ice 851 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceTargetLowering.h ('k') | src/IceTargetLoweringARM32.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698