Polly 23.0.0git
SCEVAffinator.cpp
Go to the documentation of this file.
1//===--------- SCEVAffinator.cpp - Create Scops from LLVM IR -------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Create a polyhedral description for a SCEV value.
10//
11//===----------------------------------------------------------------------===//
12
14#include "polly/Options.h"
15#include "polly/ScopInfo.h"
18#include "llvm/IR/DataLayout.h"
19#include "isl/aff.h"
20#include "isl/local_space.h"
21#include "isl/set.h"
22#include "isl/val.h"
23
24using namespace llvm;
25using namespace polly;
26
27static cl::opt<bool> IgnoreIntegerWrapping(
28 "polly-ignore-integer-wrapping",
29 cl::desc("Do not build run-time checks to proof absence of integer "
30 "wrapping"),
31 cl::Hidden, cl::cat(PollyCategory));
32
33// The maximal number of basic sets we allow during the construction of a
34// piecewise affine function. More complex ones will result in very high
35// compile time.
36static int const MaxDisjunctionsInPwAff = 100;
37
38// The maximal number of bits for which a general expression is modeled
39// precisely.
40static unsigned const MaxSmallBitWidth = 7;
41
42/// Add the number of basic sets in @p Domain to @p User
44 __isl_take isl_aff *Aff, void *User) {
45 auto *NumBasicSets = static_cast<unsigned *>(User);
46 *NumBasicSets += isl_set_n_basic_set(Domain);
48 isl_aff_free(Aff);
49 return isl_stat_ok;
50}
51
52/// Determine if @p PWAC is too complex to continue.
53static bool isTooComplex(PWACtx PWAC) {
54 unsigned NumBasicSets = 0;
55 isl_pw_aff_foreach_piece(PWAC.first.get(), addNumBasicSets, &NumBasicSets);
56 if (NumBasicSets <= MaxDisjunctionsInPwAff)
57 return false;
58 return true;
59}
60
61/// Return the flag describing the possible wrapping of @p Expr.
62static SCEV::NoWrapFlags getNoWrapFlags(const SCEV *Expr) {
63 if (auto *NAry = dyn_cast<SCEVNAryExpr>(Expr))
64 return NAry->getNoWrapFlags();
65 return SCEV::NoWrapMask;
66}
67
68static PWACtx combine(PWACtx PWAC0, PWACtx PWAC1,
71 PWAC0.first = isl::manage(Fn(PWAC0.first.release(), PWAC1.first.release()));
72 PWAC0.second = PWAC0.second.unite(PWAC1.second);
73 return PWAC0;
74}
75
77 __isl_take isl_set *Dom) {
78 auto *Ctx = isl_set_get_ctx(Dom);
79 auto *WidthVal = isl_val_int_from_ui(Ctx, Width);
80 auto *ExpVal = isl_val_2exp(WidthVal);
81 return isl_pw_aff_val_on_domain(Dom, ExpVal);
82}
83
85 : S(S), Ctx(S->getIslCtx().get()), SE(*S->getSE()), LI(LI),
86 TD(S->getFunction().getDataLayout()) {}
87
88Loop *SCEVAffinator::getScope() { return BB ? LI.getLoopFor(BB) : nullptr; }
89
90void SCEVAffinator::interpretAsUnsigned(PWACtx &PWAC, unsigned Width) {
91 auto *NonNegDom = isl_pw_aff_nonneg_set(PWAC.first.copy());
92 auto *NonNegPWA =
93 isl_pw_aff_intersect_domain(PWAC.first.copy(), isl_set_copy(NonNegDom));
94 auto *ExpPWA = getWidthExpValOnDomain(Width, isl_set_complement(NonNegDom));
96 NonNegPWA, isl_pw_aff_add(PWAC.first.release(), ExpPWA)));
97}
98
101 this->RecordedAssumptions = RecordedAssumptions;
102
103 auto *NegPWA = isl_pw_aff_neg(PWAC.first.copy());
104 auto *NegDom = isl_pw_aff_pos_set(NegPWA);
105 PWAC.second =
106 isl::manage(isl_set_union(PWAC.second.release(), isl_set_copy(NegDom)));
107 auto *Restriction = BB ? NegDom : isl_set_params(NegDom);
108 auto DL = BB ? BB->getTerminator()->getDebugLoc() : DebugLoc();
111}
112
116
117PWACtx SCEVAffinator::getPwAff(const SCEV *Expr, BasicBlock *BB,
119 bool IsInsideDomain) {
120 this->BB = BB;
121 this->IsInsideDomain = IsInsideDomain;
122 this->RecordedAssumptions = RecordedAssumptions;
123
124 if (BB) {
125 auto *DC = S->getDomainConditions(BB).release();
127 isl_set_free(DC);
128 } else
129 NumIterators = 0;
130
131 return visit(Expr);
132}
133
134PWACtx SCEVAffinator::checkForWrapping(const SCEV *Expr, PWACtx PWAC) const {
135 // If the SCEV flags do contain NSW (no signed wrap) then PWA already
136 // represents Expr in modulo semantic (it is not allowed to overflow), thus we
137 // are done. Otherwise, we will compute:
138 // PWA = ((PWA + 2^(n-1)) mod (2 ^ n)) - 2^(n-1)
139 // whereas n is the number of bits of the Expr, hence:
140 // n = bitwidth(ExprType)
141
142 if (IgnoreIntegerWrapping || any(getNoWrapFlags(Expr) & SCEV::FlagNSW))
143 return PWAC;
144
145 isl::pw_aff PWAMod = addModuloSemantic(PWAC.first, Expr->getType());
146
147 isl::set NotEqualSet = PWAC.first.ne_set(PWAMod);
148 PWAC.second = PWAC.second.unite(NotEqualSet).coalesce();
149
150 const DebugLoc &Loc = BB ? BB->getTerminator()->getDebugLoc() : DebugLoc();
151 if (!BB)
152 NotEqualSet = NotEqualSet.params();
153 NotEqualSet = NotEqualSet.coalesce();
154
155 if (!NotEqualSet.is_empty())
158
159 return PWAC;
160}
161
163 Type *ExprType) const {
164 unsigned Width = TD.getTypeSizeInBits(ExprType);
165
166 auto ModVal = isl::val::int_from_ui(Ctx, Width);
167 ModVal = ModVal.pow2();
168
169 isl::set Domain = PWA.domain();
170 isl::pw_aff AddPW =
171 isl::manage(getWidthExpValOnDomain(Width - 1, Domain.release()));
172
173 return PWA.add(AddPW).mod(ModVal).sub(AddPW);
174}
175
177 for (const auto &CachedPair : CachedExpressions) {
178 auto *AddRec = dyn_cast<SCEVAddRecExpr>(CachedPair.first.first);
179 if (!AddRec)
180 continue;
181 if (AddRec->getLoop() != L)
182 continue;
183 if (AddRec->hasNoSignedWrap())
184 return true;
185 }
186
187 return false;
188}
189
191 unsigned Width = TD.getTypeSizeInBits(Expr->getType());
192 // We assume nsw expressions never overflow.
193 if (auto *NAry = dyn_cast<SCEVNAryExpr>(Expr))
194 if (NAry->hasNoSignedWrap())
195 return false;
196 return Width <= MaxSmallBitWidth;
197}
198
199PWACtx SCEVAffinator::visit(const SCEV *Expr) {
200
201 auto Key = std::make_pair(Expr, BB);
202 PWACtx PWAC = CachedExpressions[Key];
203 if (!PWAC.first.is_null())
204 return PWAC;
205
206 auto ConstantAndLeftOverPair = extractConstantFactor(Expr, SE);
207 auto *Factor = ConstantAndLeftOverPair.first;
208 Expr = ConstantAndLeftOverPair.second;
209
210 auto *Scope = getScope();
211 S->addParams(getParamsInAffineExpr(&S->getRegion(), Scope, Expr, SE));
212
213 // In case the scev is a valid parameter, we do not further analyze this
214 // expression, but create a new parameter in the isl_pw_aff. This allows us
215 // to treat subexpressions that we cannot translate into an piecewise affine
216 // expression, as constant parameters of the piecewise affine expression.
217 if (isl_id *Id = S->getIdForParam(Expr).release()) {
218 isl_space *Space = isl_space_set_alloc(Ctx.get(), 1, NumIterators);
219 Space = isl_space_set_dim_id(Space, isl_dim_param, 0, Id);
220
223 Affine = isl_aff_add_coefficient_si(Affine, isl_dim_param, 0, 1);
224
226 } else {
227 PWAC = SCEVVisitor<SCEVAffinator, PWACtx>::visit(Expr);
228 if (computeModuloForExpr(Expr))
229 PWAC.first = addModuloSemantic(PWAC.first, Expr->getType());
230 else
231 PWAC = checkForWrapping(Expr, PWAC);
232 }
233
234 if (!Factor->getType()->isIntegerTy(1)) {
235 PWAC = combine(PWAC, visitConstant(Factor), isl_pw_aff_mul);
236 if (computeModuloForExpr(Key.first))
237 PWAC.first = addModuloSemantic(PWAC.first, Expr->getType());
238 }
239
240 // For compile time reasons we need to simplify the PWAC before we cache and
241 // return it.
242 PWAC.first = PWAC.first.coalesce();
243 if (!computeModuloForExpr(Key.first))
244 PWAC = checkForWrapping(Key.first, PWAC);
245
246 CachedExpressions[Key] = PWAC;
247 return PWAC;
248}
249
250PWACtx SCEVAffinator::visitConstant(const SCEVConstant *Expr) {
251 ConstantInt *Value = Expr->getValue();
252 isl_val *v;
253
254 // LLVM does not define if an integer value is interpreted as a signed or
255 // unsigned value. Hence, without further information, it is unknown how
256 // this value needs to be converted to GMP. At the moment, we only support
257 // signed operations. So we just interpret it as signed. Later, there are
258 // two options:
259 //
260 // 1. We always interpret any value as signed and convert the values on
261 // demand.
262 // 2. We pass down the signedness of the calculation and use it to interpret
263 // this constant correctly.
264 v = isl_valFromAPInt(Ctx.get(), Value->getValue(), /* isSigned */ true);
265
266 isl_space *Space = isl_space_set_alloc(Ctx.get(), 0, NumIterators);
268 return getPWACtxFromPWA(
270}
271
272PWACtx SCEVAffinator::visitVScale(const SCEVVScale *VScale) {
273 llvm_unreachable("SCEVVScale not yet supported");
274}
275
276PWACtx SCEVAffinator::visitPtrToAddrExpr(const SCEVPtrToAddrExpr *Expr) {
277 return visit(Expr->getOperand(0));
278}
279
280PWACtx SCEVAffinator::visitPtrToIntExpr(const SCEVPtrToIntExpr *Expr) {
281 return visit(Expr->getOperand(0));
282}
283
284PWACtx SCEVAffinator::visitTruncateExpr(const SCEVTruncateExpr *Expr) {
285 // Truncate operations are basically modulo operations, thus we can
286 // model them that way. However, for large types we assume the operand
287 // to fit in the new type size instead of introducing a modulo with a very
288 // large constant.
289
290 const SCEV *Op = Expr->getOperand();
291 auto OpPWAC = visit(Op);
292
293 unsigned Width = TD.getTypeSizeInBits(Expr->getType());
294
295 if (computeModuloForExpr(Expr))
296 return OpPWAC;
297
298 auto *Dom = OpPWAC.first.domain().release();
299 auto *ExpPWA = getWidthExpValOnDomain(Width - 1, Dom);
300 auto *GreaterDom =
301 isl_pw_aff_ge_set(OpPWAC.first.copy(), isl_pw_aff_copy(ExpPWA));
302 auto *SmallerDom =
303 isl_pw_aff_lt_set(OpPWAC.first.copy(), isl_pw_aff_neg(ExpPWA));
304 auto *OutOfBoundsDom = isl_set_union(SmallerDom, GreaterDom);
305 OpPWAC.second = OpPWAC.second.unite(isl::manage_copy(OutOfBoundsDom));
306
307 if (!BB) {
308 assert(isl_set_dim(OutOfBoundsDom, isl_dim_set) == 0 &&
309 "Expected a zero dimensional set for non-basic-block domains");
310 OutOfBoundsDom = isl_set_params(OutOfBoundsDom);
311 }
312
314 DebugLoc(), AS_RESTRICTION, IsInsideDomain ? BB : nullptr);
315
316 return OpPWAC;
317}
318
319PWACtx SCEVAffinator::visitZeroExtendExpr(const SCEVZeroExtendExpr *Expr) {
320 // A zero-extended value can be interpreted as a piecewise defined signed
321 // value. If the value was non-negative it stays the same, otherwise it
322 // is the sum of the original value and 2^n where n is the bit-width of
323 // the original (or operand) type. Examples:
324 // zext i8 127 to i32 -> { [127] }
325 // zext i8 -1 to i32 -> { [256 + (-1)] } = { [255] }
326 // zext i8 %v to i32 -> [v] -> { [v] | v >= 0; [256 + v] | v < 0 }
327 //
328 // However, LLVM/Scalar Evolution uses zero-extend (potentially lead by a
329 // truncate) to represent some forms of modulo computation. The left-hand side
330 // of the condition in the code below would result in the SCEV
331 // "zext i1 <false, +, true>for.body" which is just another description
332 // of the C expression "i & 1 != 0" or, equivalently, "i % 2 != 0".
333 //
334 // for (i = 0; i < N; i++)
335 // if (i & 1 != 0 /* == i % 2 */)
336 // /* do something */
337 //
338 // If we do not make the modulo explicit but only use the mechanism described
339 // above we will get the very restrictive assumption "N < 3", because for all
340 // values of N >= 3 the SCEVAddRecExpr operand of the zero-extend would wrap.
341 // Alternatively, we can make the modulo in the operand explicit in the
342 // resulting piecewise function and thereby avoid the assumption on N. For the
343 // example this would result in the following piecewise affine function:
344 // { [i0] -> [(1)] : 2*floor((-1 + i0)/2) = -1 + i0;
345 // [i0] -> [(0)] : 2*floor((i0)/2) = i0 }
346 // To this end we can first determine if the (immediate) operand of the
347 // zero-extend can wrap and, in case it might, we will use explicit modulo
348 // semantic to compute the result instead of emitting non-wrapping
349 // assumptions.
350 //
351 // Note that operands with large bit-widths are less likely to be negative
352 // because it would result in a very large access offset or loop bound after
353 // the zero-extend. To this end one can optimistically assume the operand to
354 // be positive and avoid the piecewise definition if the bit-width is bigger
355 // than some threshold (here MaxZextSmallBitWidth).
356 //
357 // We choose to go with a hybrid solution of all modeling techniques described
358 // above. For small bit-widths (up to MaxZextSmallBitWidth) we will model the
359 // wrapping explicitly and use a piecewise defined function. However, if the
360 // bit-width is bigger than MaxZextSmallBitWidth we will employ overflow
361 // assumptions and assume the "former negative" piece will not exist.
362
363 const SCEV *Op = Expr->getOperand();
364 auto OpPWAC = visit(Op);
365
366 // If the width is to big we assume the negative part does not occur.
367 if (!computeModuloForExpr(Op)) {
369 return OpPWAC;
370 }
371
372 // If the width is small build the piece for the non-negative part and
373 // the one for the negative part and unify them.
374 unsigned Width = TD.getTypeSizeInBits(Op->getType());
375 interpretAsUnsigned(OpPWAC, Width);
376 return OpPWAC;
377}
378
379PWACtx SCEVAffinator::visitSignExtendExpr(const SCEVSignExtendExpr *Expr) {
380 // As all values are represented as signed, a sign extension is a noop.
381 return visit(Expr->getOperand());
382}
383
384PWACtx SCEVAffinator::visitAddExpr(const SCEVAddExpr *Expr) {
385 PWACtx Sum = visit(Expr->getOperand(0));
386
387 for (int i = 1, e = Expr->getNumOperands(); i < e; ++i) {
388 Sum = combine(Sum, visit(Expr->getOperand(i)), isl_pw_aff_add);
389 if (isTooComplex(Sum))
390 return complexityBailout();
391 }
392
393 return Sum;
394}
395
396PWACtx SCEVAffinator::visitMulExpr(const SCEVMulExpr *Expr) {
397 PWACtx Prod = visit(Expr->getOperand(0));
398
399 for (int i = 1, e = Expr->getNumOperands(); i < e; ++i) {
400 Prod = combine(Prod, visit(Expr->getOperand(i)), isl_pw_aff_mul);
401 if (isTooComplex(Prod))
402 return complexityBailout();
403 }
404
405 return Prod;
406}
407
408PWACtx SCEVAffinator::visitAddRecExpr(const SCEVAddRecExpr *Expr) {
409 assert(Expr->isAffine() && "Only affine AddRecurrences allowed");
410
411 auto Flags = Expr->getNoWrapFlags();
412
413 // Directly generate isl_pw_aff for Expr if 'start' is zero.
414 if (Expr->getStart()->isZero()) {
415 assert(S->contains(Expr->getLoop()) &&
416 "Scop does not contain the loop referenced in this AddRec");
417
418 PWACtx Step = visit(Expr->getOperand(1));
419 isl_space *Space = isl_space_set_alloc(Ctx.get(), 0, NumIterators);
420 isl_local_space *LocalSpace = isl_local_space_from_space(Space);
421
422 unsigned loopDimension = S->getRelativeLoopDepth(Expr->getLoop());
423
425 isl_aff_zero_on_domain(LocalSpace), isl_dim_in, loopDimension, 1);
426 isl_pw_aff *LPwAff = isl_pw_aff_from_aff(LAff);
427
428 Step.first = Step.first.mul(isl::manage(LPwAff));
429 return Step;
430 }
431
432 // Translate AddRecExpr from '{start, +, inc}' into 'start + {0, +, inc}'
433 // if 'start' is not zero.
434 // TODO: Using the original SCEV no-wrap flags is not always safe, however
435 // as our code generation is reordering the expression anyway it doesn't
436 // really matter.
437 const SCEV *ZeroStartExpr =
438 SE.getAddRecExpr(SE.getConstant(Expr->getStart()->getType(), 0),
439 Expr->getStepRecurrence(SE), Expr->getLoop(), Flags);
440
441 PWACtx Result = visit(ZeroStartExpr);
442 PWACtx Start = visit(Expr->getStart());
443 Result = combine(Result, Start, isl_pw_aff_add);
444 return Result;
445}
446
447PWACtx SCEVAffinator::visitSMaxExpr(const SCEVSMaxExpr *Expr) {
448 PWACtx Max = visit(Expr->getOperand(0));
449
450 for (int i = 1, e = Expr->getNumOperands(); i < e; ++i) {
451 Max = combine(Max, visit(Expr->getOperand(i)), isl_pw_aff_max);
452 if (isTooComplex(Max))
453 return complexityBailout();
454 }
455
456 return Max;
457}
458
459PWACtx SCEVAffinator::visitSMinExpr(const SCEVSMinExpr *Expr) {
460 PWACtx Min = visit(Expr->getOperand(0));
461
462 for (int i = 1, e = Expr->getNumOperands(); i < e; ++i) {
463 Min = combine(Min, visit(Expr->getOperand(i)), isl_pw_aff_min);
464 if (isTooComplex(Min))
465 return complexityBailout();
466 }
467
468 return Min;
469}
470
471PWACtx SCEVAffinator::visitUMaxExpr(const SCEVUMaxExpr *Expr) {
472 llvm_unreachable("SCEVUMaxExpr not yet supported");
473}
474
475PWACtx SCEVAffinator::visitUMinExpr(const SCEVUMinExpr *Expr) {
476 llvm_unreachable("SCEVUMinExpr not yet supported");
477}
478
479PWACtx
480SCEVAffinator::visitSequentialUMinExpr(const SCEVSequentialUMinExpr *Expr) {
481 llvm_unreachable("SCEVSequentialUMinExpr not yet supported");
482}
483
484PWACtx SCEVAffinator::visitUDivExpr(const SCEVUDivExpr *Expr) {
485 // The handling of unsigned division is basically the same as for signed
486 // division, except the interpretation of the operands. As the divisor
487 // has to be constant in both cases we can simply interpret it as an
488 // unsigned value without additional complexity in the representation.
489 // For the dividend we could choose from the different representation
490 // schemes introduced for zero-extend operations but for now we will
491 // simply use an assumption.
492 const SCEV *Dividend = Expr->getLHS();
493 const SCEV *Divisor = Expr->getRHS();
494 assert(isa<SCEVConstant>(Divisor) &&
495 "UDiv is no parameter but has a non-constant RHS.");
496
497 auto DividendPWAC = visit(Dividend);
498 auto DivisorPWAC = visit(Divisor);
499
500 if (SE.isKnownNegative(Divisor)) {
501 // Interpret negative divisors unsigned. This is a special case of the
502 // piece-wise defined value described for zero-extends as we already know
503 // the actual value of the constant divisor.
504 unsigned Width = TD.getTypeSizeInBits(Expr->getType());
505 auto *DivisorDom = DivisorPWAC.first.domain().release();
506 auto *WidthExpPWA = getWidthExpValOnDomain(Width, DivisorDom);
507 DivisorPWAC.first = DivisorPWAC.first.add(isl::manage(WidthExpPWA));
508 }
509
510 // TODO: One can represent the dividend as piece-wise function to be more
511 // precise but therefore a heuristic is needed.
512
513 // Assume a non-negative dividend.
515
516 DividendPWAC = combine(DividendPWAC, DivisorPWAC, isl_pw_aff_div);
517 DividendPWAC.first = DividendPWAC.first.floor();
518
519 return DividendPWAC;
520}
521
523 assert(SDiv->getOpcode() == Instruction::SDiv && "Assumed SDiv instruction!");
524
525 auto *Scope = getScope();
526 auto *Divisor = SDiv->getOperand(1);
527 const SCEV *DivisorSCEV = SE.getSCEVAtScope(Divisor, Scope);
528 auto DivisorPWAC = visit(DivisorSCEV);
529 assert(isa<SCEVConstant>(DivisorSCEV) &&
530 "SDiv is no parameter but has a non-constant RHS.");
531
532 auto *Dividend = SDiv->getOperand(0);
533 const SCEV *DividendSCEV = SE.getSCEVAtScope(Dividend, Scope);
534 auto DividendPWAC = visit(DividendSCEV);
535 DividendPWAC = combine(DividendPWAC, DivisorPWAC, isl_pw_aff_tdiv_q);
536 return DividendPWAC;
537}
538
540 assert(SRem->getOpcode() == Instruction::SRem && "Assumed SRem instruction!");
541
542 auto *Scope = getScope();
543 auto *Divisor = SRem->getOperand(1);
544 const SCEV *DivisorSCEV = SE.getSCEVAtScope(Divisor, Scope);
545 auto DivisorPWAC = visit(DivisorSCEV);
546 assert(isa<ConstantInt>(Divisor) &&
547 "SRem is no parameter but has a non-constant RHS.");
548
549 auto *Dividend = SRem->getOperand(0);
550 const SCEV *DividendSCEV = SE.getSCEVAtScope(Dividend, Scope);
551 auto DividendPWAC = visit(DividendSCEV);
552 DividendPWAC = combine(DividendPWAC, DivisorPWAC, isl_pw_aff_tdiv_r);
553 return DividendPWAC;
554}
555
556PWACtx SCEVAffinator::visitUnknown(const SCEVUnknown *Expr) {
557 if (Instruction *I = dyn_cast<Instruction>(Expr->getValue())) {
558 switch (I->getOpcode()) {
559 case Instruction::IntToPtr:
560 return visit(SE.getSCEVAtScope(I->getOperand(0), getScope()));
561 case Instruction::SDiv:
562 return visitSDivInstruction(I);
563 case Instruction::SRem:
564 return visitSRemInstruction(I);
565 default:
566 break; // Fall through.
567 }
568 }
569
570 if (isa<ConstantPointerNull>(Expr->getValue())) {
571 isl::val v{Ctx, 0};
572 isl::space Space{Ctx, 0, NumIterators};
573 isl::local_space ls{Space};
574 return getPWACtxFromPWA(isl::aff(ls, v));
575 }
576
577 llvm_unreachable("Unknowns SCEV was neither a parameter, a constant nor a "
578 "valid instruction.");
579}
580
582 // We hit the complexity limit for affine expressions; invalidate the scop
583 // and return a constant zero.
584 const DebugLoc &Loc = BB ? BB->getTerminator()->getDebugLoc() : DebugLoc();
585 S->invalidate(COMPLEXITY, Loc);
586 return visit(SE.getZero(Type::getInt32Ty(S->getFunction().getContext())));
587}
llvm::cl::OptionCategory PollyCategory
static __isl_give isl_pw_aff * getWidthExpValOnDomain(unsigned Width, __isl_take isl_set *Dom)
static unsigned const MaxSmallBitWidth
static PWACtx combine(PWACtx PWAC0, PWACtx PWAC1, __isl_give isl_pw_aff *(Fn)(__isl_take isl_pw_aff *, __isl_take isl_pw_aff *))
static bool isTooComplex(PWACtx PWAC)
Determine if PWAC is too complex to continue.
static isl_stat addNumBasicSets(__isl_take isl_set *Domain, __isl_take isl_aff *Aff, void *User)
Add the number of basic sets in Domain to User.
static SCEV::NoWrapFlags getNoWrapFlags(const SCEV *Expr)
Return the flag describing the possible wrapping of Expr.
static int const MaxDisjunctionsInPwAff
static cl::opt< bool > IgnoreIntegerWrapping("polly-ignore-integer-wrapping", cl::desc("Do not build run-time checks to proof absence of integer " "wrapping"), cl::Hidden, cl::cat(PollyCategory))
__isl_null isl_aff * isl_aff_free(__isl_take isl_aff *aff)
Definition isl_aff.c:449
__isl_give isl_pw_aff * isl_pw_aff_val_on_domain(__isl_take isl_set *domain, __isl_take isl_val *v)
Definition isl_aff.c:7729
__isl_export __isl_give isl_pw_aff * isl_pw_aff_div(__isl_take isl_pw_aff *pa1, __isl_take isl_pw_aff *pa2)
Definition isl_aff.c:3627
__isl_export __isl_give isl_pw_aff * isl_pw_aff_tdiv_r(__isl_take isl_pw_aff *pa1, __isl_take isl_pw_aff *pa2)
Definition isl_aff.c:3692
__isl_give isl_aff * isl_aff_val_on_domain(__isl_take isl_local_space *ls, __isl_take isl_val *val)
Definition isl_aff.c:331
__isl_export __isl_give isl_pw_aff * isl_pw_aff_tdiv_q(__isl_take isl_pw_aff *pa1, __isl_take isl_pw_aff *pa2)
Definition isl_aff.c:3656
__isl_export __isl_give isl_pw_aff * isl_pw_aff_mul(__isl_take isl_pw_aff *pwaff1, __isl_take isl_pw_aff *pwaff2)
Definition isl_aff.c:3618
__isl_give isl_pw_aff * isl_pw_aff_alloc(__isl_take isl_set *set, __isl_take isl_aff *aff)
isl_stat isl_pw_aff_foreach_piece(__isl_keep isl_pw_aff *pwaff, isl_stat(*fn)(__isl_take isl_set *set, __isl_take isl_aff *aff, void *user), void *user)
__isl_export __isl_give isl_pw_aff * isl_pw_aff_union_add(__isl_take isl_pw_aff *pwaff1, __isl_take isl_pw_aff *pwaff2)
__isl_give isl_aff * isl_aff_set_coefficient_si(__isl_take isl_aff *aff, enum isl_dim_type type, int pos, int v)
Definition isl_aff.c:1221
__isl_export __isl_give isl_pw_aff * isl_pw_aff_min(__isl_take isl_pw_aff *pwaff1, __isl_take isl_pw_aff *pwaff2)
Definition isl_aff.c:3811
__isl_export __isl_give isl_pw_aff * isl_pw_aff_intersect_domain(__isl_take isl_pw_aff *pa, __isl_take isl_set *set)
__isl_export __isl_give isl_pw_aff * isl_pw_aff_neg(__isl_take isl_pw_aff *pwaff)
__isl_give isl_set * isl_pw_aff_pos_set(__isl_take isl_pw_aff *pa)
Definition isl_aff.c:3035
__isl_give isl_aff * isl_aff_add_coefficient_si(__isl_take isl_aff *aff, enum isl_dim_type type, int pos, int v)
Definition isl_aff.c:1426
__isl_give isl_aff * isl_aff_zero_on_domain(__isl_take isl_local_space *ls)
Definition isl_aff.c:235
__isl_constructor __isl_give isl_pw_aff * isl_pw_aff_from_aff(__isl_take isl_aff *aff)
__isl_give isl_set * isl_pw_aff_nonneg_set(__isl_take isl_pw_aff *pwaff)
Definition isl_aff.c:3043
__isl_export __isl_give isl_set * isl_pw_aff_lt_set(__isl_take isl_pw_aff *pwaff1, __isl_take isl_pw_aff *pwaff2)
Definition isl_aff.c:3188
__isl_export __isl_give isl_pw_aff * isl_pw_aff_add(__isl_take isl_pw_aff *pwaff1, __isl_take isl_pw_aff *pwaff2)
Definition isl_aff.c:3611
__isl_export __isl_give isl_pw_aff * isl_pw_aff_max(__isl_take isl_pw_aff *pwaff1, __isl_take isl_pw_aff *pwaff2)
Definition isl_aff.c:3819
__isl_give isl_pw_aff * isl_pw_aff_copy(__isl_keep isl_pw_aff *pwaff)
__isl_export __isl_give isl_set * isl_pw_aff_ge_set(__isl_take isl_pw_aff *pwaff1, __isl_take isl_pw_aff *pwaff2)
Definition isl_aff.c:3165
isl::checked::multi_pw_aff sub(isl::checked::multi_pw_aff multi2) const
isl::checked::set domain() const
isl::checked::multi_pw_aff add(const isl::checked::multi_pw_aff &multi2) const
isl::checked::set unite(isl::checked::set set2) const
isl::checked::set coalesce() const
boolean is_empty() const
isl::checked::set params() const
static isl::set empty(isl::space space)
static isl::val int_from_ui(isl::ctx ctx, unsigned long u)
PWACtx visitMulExpr(const llvm::SCEVMulExpr *E)
PWACtx getPwAff(const llvm::SCEV *E, llvm::BasicBlock *BB=nullptr, RecordedAssumptionsTy *RecordedAssumptions=nullptr, bool IsInsideDomain=true)
Translate a SCEV to an isl::pw_aff.
PWACtx visitUMinExpr(const llvm::SCEVUMinExpr *E)
void interpretAsUnsigned(PWACtx &PWAC, unsigned Width)
Interpret the PWA in PWAC as an unsigned value.
bool computeModuloForExpr(const llvm::SCEV *Expr)
Whether to track the value of this expression precisely, rather than assuming it won't wrap.
PWACtx visitUMaxExpr(const llvm::SCEVUMaxExpr *E)
SCEVAffinator(Scop *S, llvm::LoopInfo &LI)
PWACtx visitUDivExpr(const llvm::SCEVUDivExpr *E)
PWACtx visit(const llvm::SCEV *E)
bool hasNSWAddRecForLoop(llvm::Loop *L) const
Check an <nsw> AddRec for the loop L is cached.
void takeNonNegativeAssumption(PWACtx &PWAC, RecordedAssumptionsTy *RecordedAssumptions=nullptr)
Take the assumption that PWAC is non-negative.
llvm::DenseMap< CacheKey, PWACtx > CachedExpressions
Map to remembered cached expressions.
RecordedAssumptionsTy * RecordedAssumptions
PWACtx visitTruncateExpr(const llvm::SCEVTruncateExpr *E)
PWACtx visitSMinExpr(const llvm::SCEVSMinExpr *E)
PWACtx visitSDivInstruction(llvm::Instruction *SDiv)
PWACtx visitConstant(const llvm::SCEVConstant *E)
PWACtx visitPtrToIntExpr(const llvm::SCEVPtrToIntExpr *E)
llvm::LoopInfo & LI
const llvm::DataLayout & TD
Target data for element size computing.
PWACtx visitAddExpr(const llvm::SCEVAddExpr *E)
PWACtx visitVScale(const llvm::SCEVVScale *E)
llvm::BasicBlock * BB
PWACtx visitSequentialUMinExpr(const llvm::SCEVSequentialUMinExpr *E)
isl::pw_aff addModuloSemantic(isl::pw_aff PWA, llvm::Type *ExprType) const
Compute the non-wrapping version of PWA for type ExprType.
llvm::ScalarEvolution & SE
PWACtx visitSRemInstruction(llvm::Instruction *SRem)
PWACtx visitAddRecExpr(const llvm::SCEVAddRecExpr *E)
PWACtx checkForWrapping(const llvm::SCEV *Expr, PWACtx PWAC) const
If Expr might cause an integer wrap record an assumption.
PWACtx visitUnknown(const llvm::SCEVUnknown *E)
PWACtx visitPtrToAddrExpr(const llvm::SCEVPtrToAddrExpr *E)
PWACtx getPWACtxFromPWA(isl::pw_aff PWA)
Return a PWACtx for PWA that is always valid.
llvm::Loop * getScope()
Return the loop for the current block if any.
bool IsInsideDomain
Whether the evaluation takes place only when BB's domain has already been checked.
PWACtx visitSMaxExpr(const llvm::SCEVSMaxExpr *E)
PWACtx visitSignExtendExpr(const llvm::SCEVSignExtendExpr *E)
PWACtx visitZeroExtendExpr(const llvm::SCEVZeroExtendExpr *E)
Static Control Part.
Definition ScopInfo.h:1625
#define __isl_take
Definition ctx.h:23
isl_stat
Definition ctx.h:85
@ isl_stat_ok
Definition ctx.h:87
#define __isl_give
Definition ctx.h:20
#define isl_set
#define assert(exp)
__isl_give isl_local_space * isl_local_space_from_space(__isl_take isl_space *space)
boolean manage(isl_bool val)
Definition cpp-checked.h:98
aff manage_copy(__isl_keep isl_aff *ptr)
std::pair< isl::pw_aff, isl::set > PWACtx
The result type of the SCEVAffinator.
__isl_give isl_val * isl_valFromAPInt(isl_ctx *Ctx, const llvm::APInt Int, bool IsSigned)
Translate an llvm::APInt to an isl_val.
@ AS_RESTRICTION
Definition ScopHelper.h:58
@ Value
MemoryKind::Value: Models an llvm::Value.
Definition ScopInfo.h:149
void recordAssumption(RecordedAssumptionsTy *RecordedAssumptions, AssumptionKind Kind, isl::set Set, llvm::DebugLoc Loc, AssumptionSign Sign, llvm::BasicBlock *BB=nullptr, bool RTC=true)
Record an assumption for later addition to the assumed context.
std::pair< const llvm::SCEVConstant *, const llvm::SCEV * > extractConstantFactor(const llvm::SCEV *M, llvm::ScalarEvolution &SE)
Extract the constant factors from the multiplication M.
ParameterSetTy getParamsInAffineExpr(const llvm::Region *R, llvm::Loop *Scope, const llvm::SCEV *Expression, llvm::ScalarEvolution &SE)
llvm::SmallVector< Assumption, 8 > RecordedAssumptionsTy
Definition ScopHelper.h:81
@ WRAPPING
Definition ScopHelper.h:47
@ COMPLEXITY
Definition ScopHelper.h:51
@ UNSIGNED
Definition ScopHelper.h:48
static bool any(const std::vector< bool > &vector)
Definition python.cc:576
__isl_export __isl_give isl_set * isl_set_universe(__isl_take isl_space *space)
Definition isl_map.c:6985
isl_ctx * isl_set_get_ctx(__isl_keep isl_set *set)
Definition isl_map.c:397
__isl_export __isl_give isl_set * isl_set_union(__isl_take isl_set *set1, __isl_take isl_set *set2)
Definition isl_map.c:8929
__isl_export __isl_give isl_set * isl_set_complement(__isl_take isl_set *set)
__isl_null isl_set * isl_set_free(__isl_take isl_set *set)
Definition isl_map.c:4055
isl_size isl_set_n_dim(__isl_keep isl_set *set)
Definition isl_map.c:223
__isl_give isl_set * isl_set_copy(__isl_keep isl_set *set)
Definition isl_map.c:1470
isl_size isl_set_dim(__isl_keep isl_set *set, enum isl_dim_type type)
Definition isl_map.c:132
__isl_export isl_size isl_set_n_basic_set(__isl_keep isl_set *set)
Definition isl_map.c:11927
__isl_export __isl_give isl_set * isl_set_params(__isl_take isl_set *set)
Definition isl_map.c:6567
__isl_give isl_space * isl_space_copy(__isl_keep isl_space *space)
Definition isl_space.c:469
__isl_give isl_space * isl_space_set_dim_id(__isl_take isl_space *space, enum isl_dim_type type, unsigned pos, __isl_take isl_id *id)
Definition isl_space.c:737
__isl_give isl_space * isl_space_set_alloc(isl_ctx *ctx, unsigned nparam, unsigned dim)
Definition isl_space.c:188
@ isl_dim_param
Definition space_type.h:15
@ isl_dim_in
Definition space_type.h:16
@ isl_dim_set
Definition space_type.h:18
static TupleKindPtr Domain("Domain")
static void combine(std::vector< std::string > &vec1, const std::vector< std::string > &vec2)
static TupleKindPtr Ctx
__isl_give isl_val * isl_val_2exp(__isl_take isl_val *v)
Definition isl_val.c:563
__isl_give isl_val * isl_val_int_from_ui(isl_ctx *ctx, unsigned long u)
Definition isl_val.c:169