@@ -2372,20 +2372,17 @@ bool DependenceInfo::testMIV(const SCEV *Src, const SCEV *Dst,
2372
2372
banerjeeMIVtest (Src, Dst, Loops, Result);
2373
2373
}
2374
2374
2375
-
2376
2375
// Given a product, e.g., 10*X*Y, returns the first constant operand,
2377
- // in this case 10. If there is no constant part, returns NULL.
2378
- static
2379
- const SCEVConstant *getConstantPart (const SCEV *Expr) {
2376
+ // in this case 10. If there is no constant part, returns std::nullopt.
2377
+ static std::optional<APInt> getConstantPart (const SCEV *Expr) {
2380
2378
if (const auto *Constant = dyn_cast<SCEVConstant>(Expr))
2381
- return Constant;
2382
- else if (const auto *Product = dyn_cast<SCEVMulExpr>(Expr))
2379
+ return Constant-> getAPInt () ;
2380
+ if (const auto *Product = dyn_cast<SCEVMulExpr>(Expr))
2383
2381
if (const auto *Constant = dyn_cast<SCEVConstant>(Product->getOperand (0 )))
2384
- return Constant;
2385
- return nullptr ;
2382
+ return Constant-> getAPInt () ;
2383
+ return std::nullopt ;
2386
2384
}
2387
2385
2388
-
2389
2386
// ===----------------------------------------------------------------------===//
2390
2387
// gcdMIVtest -
2391
2388
// Tests an MIV subscript pair for dependence.
@@ -2421,11 +2418,10 @@ bool DependenceInfo::gcdMIVtest(const SCEV *Src, const SCEV *Dst,
2421
2418
const SCEV *Coeff = AddRec->getStepRecurrence (*SE);
2422
2419
// If the coefficient is the product of a constant and other stuff,
2423
2420
// we can use the constant in the GCD computation.
2424
- const auto *Constant = getConstantPart (Coeff);
2425
- if (!Constant )
2421
+ std::optional<APInt> ConstCoeff = getConstantPart (Coeff);
2422
+ if (!ConstCoeff )
2426
2423
return false ;
2427
- APInt ConstCoeff = Constant->getAPInt ();
2428
- RunningGCD = APIntOps::GreatestCommonDivisor (RunningGCD, ConstCoeff.abs ());
2424
+ RunningGCD = APIntOps::GreatestCommonDivisor (RunningGCD, ConstCoeff->abs ());
2429
2425
Coefficients = AddRec->getStart ();
2430
2426
}
2431
2427
const SCEV *SrcConst = Coefficients;
@@ -2440,11 +2436,10 @@ bool DependenceInfo::gcdMIVtest(const SCEV *Src, const SCEV *Dst,
2440
2436
const SCEV *Coeff = AddRec->getStepRecurrence (*SE);
2441
2437
// If the coefficient is the product of a constant and other stuff,
2442
2438
// we can use the constant in the GCD computation.
2443
- const auto *Constant = getConstantPart (Coeff);
2444
- if (!Constant )
2439
+ std::optional<APInt> ConstCoeff = getConstantPart (Coeff);
2440
+ if (!ConstCoeff )
2445
2441
return false ;
2446
- APInt ConstCoeff = Constant->getAPInt ();
2447
- RunningGCD = APIntOps::GreatestCommonDivisor (RunningGCD, ConstCoeff.abs ());
2442
+ RunningGCD = APIntOps::GreatestCommonDivisor (RunningGCD, ConstCoeff->abs ());
2448
2443
Coefficients = AddRec->getStart ();
2449
2444
}
2450
2445
const SCEV *DstConst = Coefficients;
@@ -2463,12 +2458,10 @@ bool DependenceInfo::gcdMIVtest(const SCEV *Src, const SCEV *Dst,
2463
2458
else if (const SCEVMulExpr *Product = dyn_cast<SCEVMulExpr>(Operand)) {
2464
2459
// Search for constant operand to participate in GCD;
2465
2460
// If none found; return false.
2466
- const SCEVConstant * ConstOp = getConstantPart (Product);
2461
+ std::optional<APInt> ConstOp = getConstantPart (Product);
2467
2462
if (!ConstOp)
2468
2463
return false ;
2469
- APInt ConstOpValue = ConstOp->getAPInt ();
2470
- ExtraGCD = APIntOps::GreatestCommonDivisor (ExtraGCD,
2471
- ConstOpValue.abs ());
2464
+ ExtraGCD = APIntOps::GreatestCommonDivisor (ExtraGCD, ConstOp->abs ());
2472
2465
}
2473
2466
else
2474
2467
return false ;
@@ -2520,11 +2513,11 @@ bool DependenceInfo::gcdMIVtest(const SCEV *Src, const SCEV *Dst,
2520
2513
else {
2521
2514
// If the coefficient is the product of a constant and other stuff,
2522
2515
// we can use the constant in the GCD computation.
2523
- Constant = getConstantPart (Coeff);
2524
- if (!Constant )
2516
+ std::optional<APInt> ConstCoeff = getConstantPart (Coeff);
2517
+ if (!ConstCoeff )
2525
2518
return false ;
2526
- APInt ConstCoeff = Constant-> getAPInt ();
2527
- RunningGCD = APIntOps::GreatestCommonDivisor (RunningGCD, ConstCoeff. abs ());
2519
+ RunningGCD =
2520
+ APIntOps::GreatestCommonDivisor (RunningGCD, ConstCoeff-> abs ());
2528
2521
}
2529
2522
Inner = AddRec->getStart ();
2530
2523
}
@@ -2537,24 +2530,23 @@ bool DependenceInfo::gcdMIVtest(const SCEV *Src, const SCEV *Dst,
2537
2530
else {
2538
2531
// If the coefficient is the product of a constant and other stuff,
2539
2532
// we can use the constant in the GCD computation.
2540
- Constant = getConstantPart (Coeff);
2541
- if (!Constant )
2533
+ std::optional<APInt> ConstCoeff = getConstantPart (Coeff);
2534
+ if (!ConstCoeff )
2542
2535
return false ;
2543
- APInt ConstCoeff = Constant-> getAPInt ();
2544
- RunningGCD = APIntOps::GreatestCommonDivisor (RunningGCD, ConstCoeff. abs ());
2536
+ RunningGCD =
2537
+ APIntOps::GreatestCommonDivisor (RunningGCD, ConstCoeff-> abs ());
2545
2538
}
2546
2539
Inner = AddRec->getStart ();
2547
2540
}
2548
2541
Delta = SE->getMinusSCEV (SrcCoeff, DstCoeff);
2549
2542
// If the coefficient is the product of a constant and other stuff,
2550
2543
// we can use the constant in the GCD computation.
2551
- Constant = getConstantPart (Delta);
2552
- if (!Constant )
2544
+ std::optional<APInt> ConstCoeff = getConstantPart (Delta);
2545
+ if (!ConstCoeff )
2553
2546
// The difference of the two coefficients might not be a product
2554
2547
// or constant, in which case we give up on this direction.
2555
2548
continue ;
2556
- APInt ConstCoeff = Constant->getAPInt ();
2557
- RunningGCD = APIntOps::GreatestCommonDivisor (RunningGCD, ConstCoeff.abs ());
2549
+ RunningGCD = APIntOps::GreatestCommonDivisor (RunningGCD, ConstCoeff->abs ());
2558
2550
LLVM_DEBUG (dbgs () << " \t RunningGCD = " << RunningGCD << " \n " );
2559
2551
if (RunningGCD != 0 ) {
2560
2552
Remainder = ConstDelta.srem (RunningGCD);
0 commit comments