|
24 | 24 | #include "polly/Support/ISLTools.h"
|
25 | 25 | #include "polly/Support/SCEVValidator.h"
|
26 | 26 | #include "polly/Support/ScopHelper.h"
|
| 27 | +#include "polly/Support/VirtualInstruction.h" |
27 | 28 | #include "llvm/ADT/APInt.h"
|
28 | 29 | #include "llvm/ADT/PostOrderIterator.h"
|
29 | 30 | #include "llvm/ADT/SetVector.h"
|
@@ -205,40 +206,68 @@ int IslNodeBuilder::getNumberOfIterations(isl::ast_node_for For) {
|
205 | 206 | return NumberIterations + 1;
|
206 | 207 | }
|
207 | 208 |
|
208 |
| -/// Extract the values and SCEVs needed to generate code for a block. |
209 |
| -static int findReferencesInBlock(struct SubtreeReferences &References, |
210 |
| - const ScopStmt *Stmt, BasicBlock *BB) { |
211 |
| - for (Instruction &Inst : *BB) { |
212 |
| - // Include invariant loads |
213 |
| - if (isa<LoadInst>(Inst)) |
214 |
| - if (Value *InvariantLoad = References.GlobalMap.lookup(&Inst)) |
215 |
| - References.Values.insert(InvariantLoad); |
216 |
| - |
217 |
| - for (Value *SrcVal : Inst.operands()) { |
218 |
| - auto *Scope = References.LI.getLoopFor(BB); |
219 |
| - if (canSynthesize(SrcVal, References.S, &References.SE, Scope)) { |
220 |
| - References.SCEVs.insert(References.SE.getSCEVAtScope(SrcVal, Scope)); |
221 |
| - continue; |
222 |
| - } else if (Value *NewVal = References.GlobalMap.lookup(SrcVal)) |
223 |
| - References.Values.insert(NewVal); |
| 209 | +static void findReferencesByUse(Value *SrcVal, ScopStmt *UserStmt, |
| 210 | + Loop *UserScope, const ValueMapT &GlobalMap, |
| 211 | + SetVector<Value *> &Values, |
| 212 | + SetVector<const SCEV *> &SCEVs) { |
| 213 | + VirtualUse VUse = VirtualUse::create(UserStmt, UserScope, SrcVal, true); |
| 214 | + switch (VUse.getKind()) { |
| 215 | + case VirtualUse::Constant: |
| 216 | + // When accelerator-offloading, GlobalValue is a host address whose content |
| 217 | + // must still be transferred to the GPU. |
| 218 | + if (isa<GlobalValue>(SrcVal)) |
| 219 | + Values.insert(SrcVal); |
| 220 | + break; |
| 221 | + |
| 222 | + case VirtualUse::Synthesizable: |
| 223 | + SCEVs.insert(VUse.getScevExpr()); |
| 224 | + return; |
| 225 | + |
| 226 | + case VirtualUse::Block: |
| 227 | + case VirtualUse::ReadOnly: |
| 228 | + case VirtualUse::Hoisted: |
| 229 | + case VirtualUse::Intra: |
| 230 | + case VirtualUse::Inter: |
| 231 | + break; |
| 232 | + } |
| 233 | + |
| 234 | + if (Value *NewVal = GlobalMap.lookup(SrcVal)) |
| 235 | + Values.insert(NewVal); |
| 236 | +} |
| 237 | + |
| 238 | +static void findReferencesInInst(Instruction *Inst, ScopStmt *UserStmt, |
| 239 | + Loop *UserScope, const ValueMapT &GlobalMap, |
| 240 | + SetVector<Value *> &Values, |
| 241 | + SetVector<const SCEV *> &SCEVs) { |
| 242 | + for (Use &U : Inst->operands()) |
| 243 | + findReferencesByUse(U.get(), UserStmt, UserScope, GlobalMap, Values, SCEVs); |
| 244 | +} |
| 245 | + |
| 246 | +static void findReferencesInStmt(ScopStmt *Stmt, SetVector<Value *> &Values, |
| 247 | + ValueMapT &GlobalMap, |
| 248 | + SetVector<const SCEV *> &SCEVs) { |
| 249 | + LoopInfo *LI = Stmt->getParent()->getLI(); |
| 250 | + |
| 251 | + BasicBlock *BB = Stmt->getBasicBlock(); |
| 252 | + Loop *Scope = LI->getLoopFor(BB); |
| 253 | + for (Instruction *Inst : Stmt->getInstructions()) |
| 254 | + findReferencesInInst(Inst, Stmt, Scope, GlobalMap, Values, SCEVs); |
| 255 | + |
| 256 | + if (Stmt->isRegionStmt()) { |
| 257 | + for (BasicBlock *BB : Stmt->getRegion()->blocks()) { |
| 258 | + Loop *Scope = LI->getLoopFor(BB); |
| 259 | + for (Instruction &Inst : *BB) |
| 260 | + findReferencesInInst(&Inst, Stmt, Scope, GlobalMap, Values, SCEVs); |
224 | 261 | }
|
225 | 262 | }
|
226 |
| - return 0; |
227 | 263 | }
|
228 | 264 |
|
229 |
| -void polly::addReferencesFromStmt(const ScopStmt *Stmt, void *UserPtr, |
| 265 | +void polly::addReferencesFromStmt(ScopStmt *Stmt, void *UserPtr, |
230 | 266 | bool CreateScalarRefs) {
|
231 | 267 | auto &References = *static_cast<struct SubtreeReferences *>(UserPtr);
|
232 | 268 |
|
233 |
| - if (Stmt->isBlockStmt()) |
234 |
| - findReferencesInBlock(References, Stmt, Stmt->getBasicBlock()); |
235 |
| - else if (Stmt->isRegionStmt()) { |
236 |
| - for (BasicBlock *BB : Stmt->getRegion()->blocks()) |
237 |
| - findReferencesInBlock(References, Stmt, BB); |
238 |
| - } else { |
239 |
| - assert(Stmt->isCopyStmt()); |
240 |
| - // Copy Stmts have no instructions that we need to consider. |
241 |
| - } |
| 269 | + findReferencesInStmt(Stmt, References.Values, References.GlobalMap, |
| 270 | + References.SCEVs); |
242 | 271 |
|
243 | 272 | for (auto &Access : *Stmt) {
|
244 | 273 | if (References.ParamSpace) {
|
@@ -276,8 +305,8 @@ void polly::addReferencesFromStmt(const ScopStmt *Stmt, void *UserPtr,
|
276 | 305 | static void addReferencesFromStmtSet(isl::set Set,
|
277 | 306 | struct SubtreeReferences *UserPtr) {
|
278 | 307 | isl::id Id = Set.get_tuple_id();
|
279 |
| - auto *Stmt = static_cast<const ScopStmt *>(Id.get_user()); |
280 |
| - return addReferencesFromStmt(Stmt, UserPtr); |
| 308 | + auto *Stmt = static_cast<ScopStmt *>(Id.get_user()); |
| 309 | + addReferencesFromStmt(Stmt, UserPtr); |
281 | 310 | }
|
282 | 311 |
|
283 | 312 | /// Extract the out-of-scop values and SCEVs referenced from a union set
|
|
0 commit comments