diff --git a/polly/lib/CodeGen/IslCodeGeneration.cpp b/polly/lib/CodeGen/IslCodeGeneration.cpp index fde674d78b13..b4d23a136410 100644 --- a/polly/lib/CodeGen/IslCodeGeneration.cpp +++ b/polly/lib/CodeGen/IslCodeGeneration.cpp @@ -312,17 +312,9 @@ struct FindValuesUser { SetVector &SCEVs; }; -/// Extract the values and SCEVs needed to generate code for a ScopStmt. -/// -/// This function extracts a ScopStmt from a given isl_set and computes the -/// Values this statement depends on as well as a set of SCEV expressions that -/// need to be synthesized when generating code for this statment. -static int findValuesInStmt(isl_set *Set, void *UserPtr) { - isl_id *Id = isl_set_get_tuple_id(Set); - struct FindValuesUser &User = *static_cast(UserPtr); - const ScopStmt *Stmt = static_cast(isl_id_get_user(Id)); - const BasicBlock *BB = Stmt->getBasicBlock(); - +/// @brief Extract the values and SCEVs needed to generate code for a block. +static int findValuesInBlock(struct FindValuesUser &User, const ScopStmt *Stmt, + const BasicBlock *BB) { // Check all the operands of instructions in the basic block. for (const Instruction &Inst : *BB) { for (Value *SrcVal : Inst.operands()) { @@ -340,6 +332,28 @@ static int findValuesInStmt(isl_set *Set, void *UserPtr) { User.Values.insert(SrcVal); } } + return 0; +} + +/// Extract the values and SCEVs needed to generate code for a ScopStmt. +/// +/// This function extracts a ScopStmt from a given isl_set and computes the +/// Values this statement depends on as well as a set of SCEV expressions that +/// need to be synthesized when generating code for this statment. +static int findValuesInStmt(isl_set *Set, void *UserPtr) { + isl_id *Id = isl_set_get_tuple_id(Set); + struct FindValuesUser &User = *static_cast(UserPtr); + const ScopStmt *Stmt = static_cast(isl_id_get_user(Id)); + + if (Stmt->isBlockStmt()) + findValuesInBlock(User, Stmt, Stmt->getBasicBlock()); + else { + assert(Stmt->isRegionStmt() && + "Stmt was neither block nor region statement"); + for (const BasicBlock *BB : Stmt->getRegion()->blocks()) + findValuesInBlock(User, Stmt, BB); + } + isl_id_free(Id); isl_set_free(Set); return 0;