Chromium Code Reviews| 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 llvm::SmallBitVector TargetLowering::getRegisterSetMask( | |
| 120 GlobalContext *Ctx, SizeT NumRegs, SizeT NumRegClasses, | |
| 121 std::function<SizeT(int32_t)> RegClassFcn, | |
| 122 std::function<IceString(int32_t)> RegNameFcn) { | |
| 123 llvm::SmallBitVector RegMask(NumRegs); | |
| 124 | |
| 125 // Collect registers to use. | |
| 126 const std::unordered_set<std::string> &RegUses = | |
| 127 Ctx->getFlags().getUseRestrictedRegisters(); | |
| 128 std::vector<llvm::SmallBitVector> AllRegClass(NumRegClasses, RegMask); | |
| 129 std::vector<llvm::SmallBitVector> UseRegClass(NumRegClasses, RegMask); | |
| 130 for (SizeT i = 0; i < NumRegs; ++i) { | |
| 131 SizeT ClassIndex = RegClassFcn(i); | |
|
Jim Stichnoth
2016/01/13 16:24:54
RegClassFcn is supposed to take an int32_t argumen
Karl
2016/01/14 18:27:19
Done.
| |
| 132 assert(ClassIndex < NumRegClasses); | |
| 133 AllRegClass[ClassIndex][i] = true; | |
| 134 if (RegUses.count(RegNameFcn(i))) | |
| 135 UseRegClass[ClassIndex][i] = true; | |
| 136 } | |
| 137 for (SizeT ClassIndex = 0; ClassIndex < NumRegClasses; ++ClassIndex) { | |
| 138 RegMask |= (UseRegClass[ClassIndex].any() ? UseRegClass[ClassIndex] | |
| 139 : AllRegClass[ClassIndex]); | |
| 140 } | |
| 141 | |
| 142 // Remove registers to exclude. | |
| 143 const std::unordered_set<std::string> &RegExcludes = | |
| 144 Ctx->getFlags().getExcludedRegisters(); | |
| 145 for (SizeT i = 0; i < NumRegs; ++i) { | |
| 146 if (RegExcludes.count(RegNameFcn(i))) | |
| 147 RegMask[i] = false; | |
| 148 } | |
| 149 | |
| 150 // Trace registers available if requested. | |
| 151 if (BuildDefs::dump() && NumRegs && | |
| 152 (Ctx->getFlags().getVerbose() & IceV_AvailableRegs)) { | |
| 153 Ostream &Out = Ctx->getStrEmit(); | |
|
Jim Stichnoth
2016/01/13 16:24:54
getStrDump()
and usually, the variable is named "
Karl
2016/01/14 18:27:19
Done.
| |
| 154 Out << "Registers available for register allocation:\n"; | |
| 155 constexpr SizeT RegistersPerLine = 15; | |
| 156 bool AtBeginning = true; | |
| 157 SizeT Count = 0; | |
| 158 for (SizeT i = 0; i < NumRegs; ++i) { | |
| 159 if (!RegMask[i]) | |
| 160 continue; | |
| 161 if (AtBeginning) { | |
| 162 Out << " "; | |
| 163 AtBeginning = false; | |
| 164 } else { | |
| 165 Out << ", "; | |
| 166 } | |
| 167 if ((Count > 0) && ((Count % RegistersPerLine) == 0)) { | |
| 168 Out << "\n "; | |
| 169 } | |
| 170 ++Count; | |
| 171 Out << RegNameFcn(i); | |
| 172 } | |
| 173 if (!AtBeginning) | |
| 174 Out << "\n"; | |
| 175 } | |
| 176 | |
| 177 return RegMask; | |
| 178 } | |
| 179 | |
| 119 std::unique_ptr<TargetLowering> | 180 std::unique_ptr<TargetLowering> |
| 120 TargetLowering::createLowering(TargetArch Target, Cfg *Func) { | 181 TargetLowering::createLowering(TargetArch Target, Cfg *Func) { |
| 121 switch (Target) { | 182 switch (Target) { |
| 122 default: | 183 default: |
| 123 llvm::report_fatal_error("Unsupported target"); | 184 llvm::report_fatal_error("Unsupported target"); |
| 124 #define SUBZERO_TARGET(X) \ | 185 #define SUBZERO_TARGET(X) \ |
| 125 case Target_##X: \ | 186 case Target_##X: \ |
| 126 return ::X::createTargetLowering(Func); | 187 return ::X::createTargetLowering(Func); |
| 127 #include "llvm/Config/SZTargets.def" | 188 #include "llvm/Config/SZTargets.def" |
| 128 #undef SUBZERO_TARGET | 189 #undef SUBZERO_TARGET |
| 129 } | 190 } |
| 130 } | 191 } |
| 131 | 192 |
| 132 void TargetLowering::staticInit(const ClFlags &Flags) { | 193 void TargetLowering::staticInit(GlobalContext *Ctx) { |
| 133 const TargetArch Target = Flags.getTargetArch(); | 194 const TargetArch Target = Ctx->getFlags().getTargetArch(); |
| 134 // Call the specified target's static initializer. | 195 // Call the specified target's static initializer. |
| 135 switch (Target) { | 196 switch (Target) { |
| 136 default: | 197 default: |
| 137 llvm::report_fatal_error("Unsupported target"); | 198 llvm::report_fatal_error("Unsupported target"); |
| 138 #define SUBZERO_TARGET(X) \ | 199 #define SUBZERO_TARGET(X) \ |
| 139 case Target_##X: { \ | 200 case Target_##X: { \ |
| 140 static bool InitGuard##X = false; \ | 201 static bool InitGuard##X = false; \ |
| 141 if (InitGuard##X) { \ | 202 if (InitGuard##X) { \ |
| 142 return; \ | 203 return; \ |
| 143 } \ | 204 } \ |
| 144 InitGuard##X = true; \ | 205 InitGuard##X = true; \ |
| 145 ::X::staticInit(Flags); \ | 206 ::X::staticInit(Ctx); \ |
| 146 } break; | 207 } break; |
| 147 #include "llvm/Config/SZTargets.def" | 208 #include "llvm/Config/SZTargets.def" |
| 148 #undef SUBZERO_TARGET | 209 #undef SUBZERO_TARGET |
| 149 } | 210 } |
| 150 } | 211 } |
| 151 | 212 |
| 152 TargetLowering::TargetLowering(Cfg *Func) | 213 TargetLowering::TargetLowering(Cfg *Func) |
| 153 : Func(Func), Ctx(Func->getContext()), Context() {} | 214 : Func(Func), Ctx(Func->getContext()), Context() {} |
| 154 | 215 |
| 155 void TargetLowering::genTargetHelperCalls() { | 216 void TargetLowering::genTargetHelperCalls() { |
| (...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 682 case Target_##X: \ | 743 case Target_##X: \ |
| 683 return ::X::createTargetHeaderLowering(Ctx); | 744 return ::X::createTargetHeaderLowering(Ctx); |
| 684 #include "llvm/Config/SZTargets.def" | 745 #include "llvm/Config/SZTargets.def" |
| 685 #undef SUBZERO_TARGET | 746 #undef SUBZERO_TARGET |
| 686 } | 747 } |
| 687 } | 748 } |
| 688 | 749 |
| 689 TargetHeaderLowering::~TargetHeaderLowering() = default; | 750 TargetHeaderLowering::~TargetHeaderLowering() = default; |
| 690 | 751 |
| 691 } // end of namespace Ice | 752 } // end of namespace Ice |
| OLD | NEW |