void ScopAnnotator::buildAliasScopes(Scop &S) { SE = S.getSE(); LLVMContext &Ctx = SE->getContext(); AliasScopeDomain = getID(Ctx, MDString::get(Ctx, "polly.alias.scope.domain")); AliasScopeMap.clear(); OtherAliasScopeListMap.clear(); SetVector<Value *> BasePtrs; for (ScopStmt &Stmt : S) for (MemoryAccess *MA : Stmt) BasePtrs.insert(MA->getBaseAddr()); std::string AliasScopeStr = "polly.alias.scope."; for (Value *BasePtr : BasePtrs) AliasScopeMap[BasePtr] = getID( Ctx, AliasScopeDomain, MDString::get(Ctx, (AliasScopeStr + BasePtr->getName()).str().c_str())); for (Value *BasePtr : BasePtrs) { MDNode *AliasScopeList = MDNode::get(Ctx, {}); for (const auto &AliasScopePair : AliasScopeMap) { if (BasePtr == AliasScopePair.first) continue; Metadata *Args = {AliasScopePair.second}; AliasScopeList = MDNode::concatenate(AliasScopeList, MDNode::get(Ctx, Args)); } OtherAliasScopeListMap[BasePtr] = AliasScopeList; } }
__isl_give isl_pw_aff *SCEVAffinator::getPwAff(ScopStmt *Stmt, const SCEV *Scev) { Scop *S = Stmt->getParent(); const Region *Reg = &S->getRegion(); S->addParams(getParamsInAffineExpr(Reg, Scev, *S->getSE())); SCEVAffinator Affinator(Stmt); return Affinator.visit(Scev); }
__isl_give isl_pw_aff * SCEVAffinator::visitAddRecExpr(const SCEVAddRecExpr *Expr) { assert(Expr->isAffine() && "Only affine AddRecurrences allowed"); // Directly generate isl_pw_aff for Expr if 'start' is zero. if (Expr->getStart()->isZero()) { assert(S->getRegion().contains(Expr->getLoop()) && "Scop does not contain the loop referenced in this AddRec"); isl_pw_aff *Start = visit(Expr->getStart()); isl_pw_aff *Step = visit(Expr->getOperand(1)); isl_space *Space = isl_space_set_alloc(Ctx, 0, NbLoopSpaces); isl_local_space *LocalSpace = isl_local_space_from_space(Space); int loopDimension = getLoopDepth(Expr->getLoop()); isl_aff *LAff = isl_aff_set_coefficient_si( isl_aff_zero_on_domain(LocalSpace), isl_dim_in, loopDimension, 1); isl_pw_aff *LPwAff = isl_pw_aff_from_aff(LAff); // TODO: Do we need to check for NSW and NUW? return isl_pw_aff_add(Start, isl_pw_aff_mul(Step, LPwAff)); } // Translate AddRecExpr from '{start, +, inc}' into 'start + {0, +, inc}' // if 'start' is not zero. ScalarEvolution &SE = *S->getSE(); const SCEV *ZeroStartExpr = SE.getAddRecExpr( SE.getConstant(Expr->getStart()->getType(), 0), Expr->getStepRecurrence(SE), Expr->getLoop(), SCEV::FlagAnyWrap); isl_pw_aff *ZeroStartResult = visit(ZeroStartExpr); isl_pw_aff *Start = visit(Expr->getStart()); return isl_pw_aff_add(ZeroStartResult, Start); }