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 // This file implements the skeleton of the TargetLowering class, | 10 // This file implements the skeleton of the TargetLowering class, |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 // | 119 // |
120 // The lowering method may look ahead in the instruction stream as | 120 // The lowering method may look ahead in the instruction stream as |
121 // desired, and lower additional instructions in conjunction with the | 121 // desired, and lower additional instructions in conjunction with the |
122 // current one, for example fusing a compare and branch. If it does, | 122 // current one, for example fusing a compare and branch. If it does, |
123 // it should advance Context.Cur to point to the next non-deleted | 123 // it should advance Context.Cur to point to the next non-deleted |
124 // instruction to process, and it should delete any additional | 124 // instruction to process, and it should delete any additional |
125 // instructions it consumes. | 125 // instructions it consumes. |
126 void TargetLowering::lower() { | 126 void TargetLowering::lower() { |
127 assert(!Context.atEnd()); | 127 assert(!Context.atEnd()); |
128 Inst *Inst = Context.getCur(); | 128 Inst *Inst = Context.getCur(); |
129 // Mark the current instruction as deleted before lowering, | 129 Inst->deleteIfDead(); |
130 // otherwise the Dest variable will likely get marked as non-SSA. | 130 if (!Inst->isDeleted()) { |
131 // See Variable::setDefinition(). | 131 // Mark the current instruction as deleted before lowering, |
132 Inst->setDeleted(); | 132 // otherwise the Dest variable will likely get marked as non-SSA. |
133 switch (Inst->getKind()) { | 133 // See Variable::setDefinition(). |
134 case Inst::Alloca: | 134 Inst->setDeleted(); |
135 lowerAlloca(llvm::dyn_cast<InstAlloca>(Inst)); | 135 switch (Inst->getKind()) { |
136 break; | 136 case Inst::Alloca: |
137 case Inst::Arithmetic: | 137 lowerAlloca(llvm::cast<InstAlloca>(Inst)); |
138 lowerArithmetic(llvm::dyn_cast<InstArithmetic>(Inst)); | 138 break; |
139 break; | 139 case Inst::Arithmetic: |
140 case Inst::Assign: | 140 lowerArithmetic(llvm::cast<InstArithmetic>(Inst)); |
141 lowerAssign(llvm::dyn_cast<InstAssign>(Inst)); | 141 break; |
142 break; | 142 case Inst::Assign: |
143 case Inst::Br: | 143 lowerAssign(llvm::cast<InstAssign>(Inst)); |
144 lowerBr(llvm::dyn_cast<InstBr>(Inst)); | 144 break; |
145 break; | 145 case Inst::Br: |
146 case Inst::Call: | 146 lowerBr(llvm::cast<InstBr>(Inst)); |
147 lowerCall(llvm::dyn_cast<InstCall>(Inst)); | 147 break; |
148 break; | 148 case Inst::Call: |
149 case Inst::Cast: | 149 lowerCall(llvm::cast<InstCall>(Inst)); |
150 lowerCast(llvm::dyn_cast<InstCast>(Inst)); | 150 break; |
151 break; | 151 case Inst::Cast: |
152 case Inst::ExtractElement: | 152 lowerCast(llvm::cast<InstCast>(Inst)); |
153 lowerExtractElement(llvm::dyn_cast<InstExtractElement>(Inst)); | 153 break; |
154 break; | 154 case Inst::ExtractElement: |
155 case Inst::Fcmp: | 155 lowerExtractElement(llvm::cast<InstExtractElement>(Inst)); |
156 lowerFcmp(llvm::dyn_cast<InstFcmp>(Inst)); | 156 break; |
157 break; | 157 case Inst::Fcmp: |
158 case Inst::Icmp: | 158 lowerFcmp(llvm::cast<InstFcmp>(Inst)); |
159 lowerIcmp(llvm::dyn_cast<InstIcmp>(Inst)); | 159 break; |
160 break; | 160 case Inst::Icmp: |
161 case Inst::InsertElement: | 161 lowerIcmp(llvm::cast<InstIcmp>(Inst)); |
162 lowerInsertElement(llvm::dyn_cast<InstInsertElement>(Inst)); | 162 break; |
163 break; | 163 case Inst::InsertElement: |
164 case Inst::IntrinsicCall: { | 164 lowerInsertElement(llvm::cast<InstInsertElement>(Inst)); |
165 InstIntrinsicCall *Call = llvm::dyn_cast<InstIntrinsicCall>(Inst); | 165 break; |
166 if (Call->getIntrinsicInfo().ReturnsTwice) | 166 case Inst::IntrinsicCall: { |
167 setCallsReturnsTwice(true); | 167 InstIntrinsicCall *Call = llvm::cast<InstIntrinsicCall>(Inst); |
168 lowerIntrinsicCall(Call); | 168 if (Call->getIntrinsicInfo().ReturnsTwice) |
169 break; | 169 setCallsReturnsTwice(true); |
| 170 lowerIntrinsicCall(Call); |
| 171 break; |
| 172 } |
| 173 case Inst::Load: |
| 174 lowerLoad(llvm::cast<InstLoad>(Inst)); |
| 175 break; |
| 176 case Inst::Phi: |
| 177 lowerPhi(llvm::cast<InstPhi>(Inst)); |
| 178 break; |
| 179 case Inst::Ret: |
| 180 lowerRet(llvm::cast<InstRet>(Inst)); |
| 181 break; |
| 182 case Inst::Select: |
| 183 lowerSelect(llvm::cast<InstSelect>(Inst)); |
| 184 break; |
| 185 case Inst::Store: |
| 186 lowerStore(llvm::cast<InstStore>(Inst)); |
| 187 break; |
| 188 case Inst::Switch: |
| 189 lowerSwitch(llvm::cast<InstSwitch>(Inst)); |
| 190 break; |
| 191 case Inst::Unreachable: |
| 192 lowerUnreachable(llvm::cast<InstUnreachable>(Inst)); |
| 193 break; |
| 194 case Inst::BundleLock: |
| 195 case Inst::BundleUnlock: |
| 196 case Inst::FakeDef: |
| 197 case Inst::FakeUse: |
| 198 case Inst::FakeKill: |
| 199 case Inst::Target: |
| 200 // These are all Target instruction types and shouldn't be |
| 201 // encountered at this stage. |
| 202 Func->setError("Can't lower unsupported instruction type"); |
| 203 break; |
| 204 } |
| 205 |
| 206 postLower(); |
170 } | 207 } |
171 case Inst::Load: | |
172 lowerLoad(llvm::dyn_cast<InstLoad>(Inst)); | |
173 break; | |
174 case Inst::Phi: | |
175 lowerPhi(llvm::dyn_cast<InstPhi>(Inst)); | |
176 break; | |
177 case Inst::Ret: | |
178 lowerRet(llvm::dyn_cast<InstRet>(Inst)); | |
179 break; | |
180 case Inst::Select: | |
181 lowerSelect(llvm::dyn_cast<InstSelect>(Inst)); | |
182 break; | |
183 case Inst::Store: | |
184 lowerStore(llvm::dyn_cast<InstStore>(Inst)); | |
185 break; | |
186 case Inst::Switch: | |
187 lowerSwitch(llvm::dyn_cast<InstSwitch>(Inst)); | |
188 break; | |
189 case Inst::Unreachable: | |
190 lowerUnreachable(llvm::dyn_cast<InstUnreachable>(Inst)); | |
191 break; | |
192 case Inst::BundleLock: | |
193 case Inst::BundleUnlock: | |
194 case Inst::FakeDef: | |
195 case Inst::FakeUse: | |
196 case Inst::FakeKill: | |
197 case Inst::Target: | |
198 // These are all Target instruction types and shouldn't be | |
199 // encountered at this stage. | |
200 Func->setError("Can't lower unsupported instruction type"); | |
201 break; | |
202 } | |
203 | |
204 postLower(); | |
205 | 208 |
206 Context.advanceCur(); | 209 Context.advanceCur(); |
207 Context.advanceNext(); | 210 Context.advanceNext(); |
208 } | 211 } |
209 | 212 |
210 // Drives register allocation, allowing all physical registers (except | 213 // Drives register allocation, allowing all physical registers (except |
211 // perhaps for the frame pointer) to be allocated. This set of | 214 // perhaps for the frame pointer) to be allocated. This set of |
212 // registers could potentially be parameterized if we want to restrict | 215 // registers could potentially be parameterized if we want to restrict |
213 // registers e.g. for performance testing. | 216 // registers e.g. for performance testing. |
214 void TargetLowering::regAlloc(RegAllocKind Kind) { | 217 void TargetLowering::regAlloc(RegAllocKind Kind) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 return std::unique_ptr<TargetDataLowering>(TargetData##X::create(Ctx)); | 269 return std::unique_ptr<TargetDataLowering>(TargetData##X::create(Ctx)); |
267 #include "llvm/Config/SZTargets.def" | 270 #include "llvm/Config/SZTargets.def" |
268 | 271 |
269 llvm_unreachable("Unsupported target data lowering"); | 272 llvm_unreachable("Unsupported target data lowering"); |
270 return nullptr; | 273 return nullptr; |
271 } | 274 } |
272 | 275 |
273 TargetDataLowering::~TargetDataLowering() {} | 276 TargetDataLowering::~TargetDataLowering() {} |
274 | 277 |
275 } // end of namespace Ice | 278 } // end of namespace Ice |
OLD | NEW |