Index: src/IceTargetLowering.cpp |
diff --git a/src/IceTargetLowering.cpp b/src/IceTargetLowering.cpp |
index 04f77e61b2caf26ea4fe4bedffc1efae35434fcd..d9cf0c37c7dbcfeff6bdd1ed10e800e3fc0481a1 100644 |
--- a/src/IceTargetLowering.cpp |
+++ b/src/IceTargetLowering.cpp |
@@ -39,7 +39,7 @@ |
// createTargetDataLowering(Ice::GlobalContext*); |
// unique_ptr<Ice::TargetHeaderLowering> |
// createTargetHeaderLowering(Ice::GlobalContext *); |
-// void staticInit(const ::Ice::ClFlags &Flags); |
+// void staticInit(::Ice::GlobalContext *); |
// } |
#define SUBZERO_TARGET(X) \ |
namespace X { \ |
@@ -49,7 +49,7 @@ |
createTargetDataLowering(::Ice::GlobalContext *Ctx); \ |
std::unique_ptr<::Ice::TargetHeaderLowering> \ |
createTargetHeaderLowering(::Ice::GlobalContext *Ctx); \ |
- void staticInit(const ::Ice::ClFlags &Flags); \ |
+ void staticInit(::Ice::GlobalContext *Ctx); \ |
} // end of namespace X |
#include "llvm/Config/SZTargets.def" |
#undef SUBZERO_TARGET |
@@ -116,6 +116,90 @@ Variable *LoweringContext::availabilityGet(Operand *Src) const { |
return nullptr; |
} |
+namespace { |
+ |
+void printRegisterSet(Ostream &Str, const llvm::SmallBitVector &Bitset, |
+ 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.
|
+ 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.
|
+ 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.
|
+ size_t Count = 0; |
+ 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.
|
+ IceString Indent = std::string(LineIndent, ' '); |
+ for (int i = Bitset.find_first(); i != BitsetEnd; i = Bitset.find_next(i)) { |
+ if (Count == 0) { |
+ Str << Indent; |
+ } else { |
+ Str << ","; |
+ } |
+ if (Count > 0 && Count % RegistersPerLine == 0) |
+ Str << "\n" << Indent; |
+ ++Count; |
+ Str << getRegName(i); |
+ } |
+ if (Count) |
+ Str << "\n"; |
+} |
+ |
+} // end of anonymous namespace |
+ |
+void TargetLowering::filterTypeToRegisterSet( |
+ GlobalContext *Ctx, int32_t NumRegs, |
+ llvm::SmallBitVector TypeToRegisterSet[], size_t TypeToRegisterSetSize, |
+ std::function<IceString(int32_t)> getRegName) { |
+ llvm::SmallBitVector ExcludeBitSet(NumRegs); |
+ std::vector<llvm::SmallBitVector> UseSet(TypeToRegisterSetSize, |
+ ExcludeBitSet); |
+ ExcludeBitSet.flip(); |
+ |
+ std::unordered_map<IceString, int32_t> RegNameToIndex; |
+ for (int32_t RegIndex = 0; RegIndex < NumRegs; ++RegIndex) |
+ RegNameToIndex[getRegName(RegIndex)] = RegIndex; |
+ |
+ for (const IceString &RegName : Ctx->getFlags().getUseRestrictedRegisters()) { |
+ if (!RegNameToIndex.count(RegName)) |
+ 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.
|
+ const int32_t RegIndex = RegNameToIndex[RegName]; |
+ for (SizeT TypeIndex = 0; TypeIndex < TypeToRegisterSetSize; ++TypeIndex) |
+ UseSet[TypeIndex][RegIndex] = TypeToRegisterSet[TypeIndex][RegIndex]; |
+ } |
+ |
+ for (const IceString &RegName : Ctx->getFlags().getExcludedRegisters()) { |
+ if (!RegNameToIndex.count(RegName)) |
+ llvm::report_fatal_error("Can't find register exclude: " + RegName); |
+ ExcludeBitSet[RegNameToIndex[RegName]] = false; |
+ } |
+ |
+ // Apply filters. |
+ for (size_t TypeIndex = 0; TypeIndex < TypeToRegisterSetSize; ++TypeIndex) { |
+ llvm::SmallBitVector *TypeBitSet = &TypeToRegisterSet[TypeIndex]; |
+ llvm::SmallBitVector *UseBitSet = &UseSet[TypeIndex]; |
+ if (UseBitSet->any()) |
+ *TypeBitSet = *UseBitSet; |
+ *TypeBitSet &= ExcludeBitSet; |
+ } |
+ |
+ // Display filtered register sets, if requested. |
+ if (BuildDefs::dump() && NumRegs && |
+ (Ctx->getFlags().getVerbose() & IceV_AvailableRegs)) { |
+ Ostream &Str = Ctx->getStrDump(); |
+ constexpr const char LineIndent[] = " "; |
+ const size_t RegSetIndent = 2 * llvm::array_lengthof(LineIndent); |
+ Str << "Registers available for register allocation:\n"; |
+ for (size_t TypeIndex = 0; TypeIndex < TypeToRegisterSetSize; ++TypeIndex) { |
+ Str << LineIndent; |
+ if (TypeIndex < IceType_NUM) { |
+ Str << typeString(static_cast<Type>(TypeIndex)); |
+ } else { |
+ Str << "other[" << TypeIndex << "]"; |
+ } |
+ Str << ":\n"; |
+ printRegisterSet(Str, TypeToRegisterSet[TypeIndex], getRegName, |
+ RegSetIndent); |
+ } |
+ Str << "\n"; |
+ } |
+} |
+ |
std::unique_ptr<TargetLowering> |
TargetLowering::createLowering(TargetArch Target, Cfg *Func) { |
switch (Target) { |
@@ -129,8 +213,8 @@ TargetLowering::createLowering(TargetArch Target, Cfg *Func) { |
} |
} |
-void TargetLowering::staticInit(const ClFlags &Flags) { |
- const TargetArch Target = Flags.getTargetArch(); |
+void TargetLowering::staticInit(GlobalContext *Ctx) { |
+ const TargetArch Target = Ctx->getFlags().getTargetArch(); |
// Call the specified target's static initializer. |
switch (Target) { |
default: |
@@ -142,7 +226,7 @@ void TargetLowering::staticInit(const ClFlags &Flags) { |
return; \ |
} \ |
InitGuard##X = true; \ |
- ::X::staticInit(Flags); \ |
+ ::X::staticInit(Ctx); \ |
} break; |
#include "llvm/Config/SZTargets.def" |
#undef SUBZERO_TARGET |