OLD | NEW |
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 Loading... |
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 Loading... |
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, |
| 123 const IceString &LineIndentString) { |
| 124 constexpr size_t RegistersPerLine = 16; |
| 125 size_t Count = 0; |
| 126 for (int i = Bitset.find_first(); i != -1; i = Bitset.find_next(i)) { |
| 127 if (Count == 0) { |
| 128 Str << LineIndentString; |
| 129 } else { |
| 130 Str << ","; |
| 131 } |
| 132 if (Count > 0 && Count % RegistersPerLine == 0) |
| 133 Str << "\n" << LineIndentString; |
| 134 ++Count; |
| 135 Str << getRegName(i); |
| 136 } |
| 137 if (Count) |
| 138 Str << "\n"; |
| 139 } |
| 140 |
| 141 } // end of anonymous namespace |
| 142 |
| 143 void TargetLowering::filterTypeToRegisterSet( |
| 144 GlobalContext *Ctx, int32_t NumRegs, |
| 145 llvm::SmallBitVector TypeToRegisterSet[], size_t TypeToRegisterSetSize, |
| 146 std::function<IceString(int32_t)> getRegName) { |
| 147 llvm::SmallBitVector ExcludeBitSet(NumRegs); |
| 148 std::vector<llvm::SmallBitVector> UseSet(TypeToRegisterSetSize, |
| 149 ExcludeBitSet); |
| 150 ExcludeBitSet.flip(); |
| 151 |
| 152 std::unordered_map<IceString, int32_t> RegNameToIndex; |
| 153 for (int32_t RegIndex = 0; RegIndex < NumRegs; ++RegIndex) |
| 154 RegNameToIndex[getRegName(RegIndex)] = RegIndex; |
| 155 |
| 156 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 |
| 167 for (const IceString &RegName : Ctx->getFlags().getExcludedRegisters()) { |
| 168 if (!RegNameToIndex.count(RegName)) { |
| 169 BadRegNames.push_back(RegName); |
| 170 continue; |
| 171 } |
| 172 ExcludeBitSet[RegNameToIndex[RegName]] = false; |
| 173 } |
| 174 |
| 175 if (!BadRegNames.empty()) { |
| 176 std::string Buffer; |
| 177 llvm::raw_string_ostream StrBuf(Buffer); |
| 178 StrBuf << "Unrecognized use/exclude registers:"; |
| 179 for (const auto &RegName : BadRegNames) |
| 180 StrBuf << " " << RegName; |
| 181 llvm::report_fatal_error(StrBuf.str()); |
| 182 } |
| 183 |
| 184 // Apply filters. |
| 185 for (size_t TypeIndex = 0; TypeIndex < TypeToRegisterSetSize; ++TypeIndex) { |
| 186 llvm::SmallBitVector *TypeBitSet = &TypeToRegisterSet[TypeIndex]; |
| 187 llvm::SmallBitVector *UseBitSet = &UseSet[TypeIndex]; |
| 188 if (UseBitSet->any()) |
| 189 *TypeBitSet = *UseBitSet; |
| 190 *TypeBitSet &= ExcludeBitSet; |
| 191 } |
| 192 |
| 193 // Display filtered register sets, if requested. |
| 194 if (BuildDefs::dump() && NumRegs && |
| 195 (Ctx->getFlags().getVerbose() & IceV_AvailableRegs)) { |
| 196 Ostream &Str = Ctx->getStrDump(); |
| 197 const IceString Indent = " "; |
| 198 const IceString IndentTwice = Indent + Indent; |
| 199 Str << "Registers available for register allocation:\n"; |
| 200 for (size_t TypeIndex = 0; TypeIndex < TypeToRegisterSetSize; ++TypeIndex) { |
| 201 Str << Indent; |
| 202 if (TypeIndex < IceType_NUM) { |
| 203 Str << typeString(static_cast<Type>(TypeIndex)); |
| 204 } else { |
| 205 Str << "other[" << TypeIndex << "]"; |
| 206 } |
| 207 Str << ":\n"; |
| 208 printRegisterSet(Str, TypeToRegisterSet[TypeIndex], getRegName, |
| 209 IndentTwice); |
| 210 } |
| 211 Str << "\n"; |
| 212 } |
| 213 } |
| 214 |
119 std::unique_ptr<TargetLowering> | 215 std::unique_ptr<TargetLowering> |
120 TargetLowering::createLowering(TargetArch Target, Cfg *Func) { | 216 TargetLowering::createLowering(TargetArch Target, Cfg *Func) { |
121 switch (Target) { | 217 switch (Target) { |
122 default: | 218 default: |
123 llvm::report_fatal_error("Unsupported target"); | 219 llvm::report_fatal_error("Unsupported target"); |
124 #define SUBZERO_TARGET(X) \ | 220 #define SUBZERO_TARGET(X) \ |
125 case Target_##X: \ | 221 case Target_##X: \ |
126 return ::X::createTargetLowering(Func); | 222 return ::X::createTargetLowering(Func); |
127 #include "llvm/Config/SZTargets.def" | 223 #include "llvm/Config/SZTargets.def" |
128 #undef SUBZERO_TARGET | 224 #undef SUBZERO_TARGET |
129 } | 225 } |
130 } | 226 } |
131 | 227 |
132 void TargetLowering::staticInit(const ClFlags &Flags) { | 228 void TargetLowering::staticInit(GlobalContext *Ctx) { |
133 const TargetArch Target = Flags.getTargetArch(); | 229 const TargetArch Target = Ctx->getFlags().getTargetArch(); |
134 // Call the specified target's static initializer. | 230 // Call the specified target's static initializer. |
135 switch (Target) { | 231 switch (Target) { |
136 default: | 232 default: |
137 llvm::report_fatal_error("Unsupported target"); | 233 llvm::report_fatal_error("Unsupported target"); |
138 #define SUBZERO_TARGET(X) \ | 234 #define SUBZERO_TARGET(X) \ |
139 case Target_##X: { \ | 235 case Target_##X: { \ |
140 static bool InitGuard##X = false; \ | 236 static bool InitGuard##X = false; \ |
141 if (InitGuard##X) { \ | 237 if (InitGuard##X) { \ |
142 return; \ | 238 return; \ |
143 } \ | 239 } \ |
144 InitGuard##X = true; \ | 240 InitGuard##X = true; \ |
145 ::X::staticInit(Flags); \ | 241 ::X::staticInit(Ctx); \ |
146 } break; | 242 } break; |
147 #include "llvm/Config/SZTargets.def" | 243 #include "llvm/Config/SZTargets.def" |
148 #undef SUBZERO_TARGET | 244 #undef SUBZERO_TARGET |
149 } | 245 } |
150 } | 246 } |
151 | 247 |
152 TargetLowering::TargetLowering(Cfg *Func) | 248 TargetLowering::TargetLowering(Cfg *Func) |
153 : Func(Func), Ctx(Func->getContext()), Context() {} | 249 : Func(Func), Ctx(Func->getContext()), Context() {} |
154 | 250 |
155 void TargetLowering::genTargetHelperCalls() { | 251 void TargetLowering::genTargetHelperCalls() { |
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
682 case Target_##X: \ | 778 case Target_##X: \ |
683 return ::X::createTargetHeaderLowering(Ctx); | 779 return ::X::createTargetHeaderLowering(Ctx); |
684 #include "llvm/Config/SZTargets.def" | 780 #include "llvm/Config/SZTargets.def" |
685 #undef SUBZERO_TARGET | 781 #undef SUBZERO_TARGET |
686 } | 782 } |
687 } | 783 } |
688 | 784 |
689 TargetHeaderLowering::~TargetHeaderLowering() = default; | 785 TargetHeaderLowering::~TargetHeaderLowering() = default; |
690 | 786 |
691 } // end of namespace Ice | 787 } // end of namespace Ice |
OLD | NEW |