LLVM: include/llvm/Analysis/ScalarEvolutionPatternMatch.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13#ifndef LLVM_ANALYSIS_SCALAREVOLUTIONPATTERNMATCH_H

14#define LLVM_ANALYSIS_SCALAREVOLUTIONPATTERNMATCH_H

15

17

18namespace llvm {

20

22 return P.match(S);

23}

24

25template struct cst_pred_ty : public Predicate {

30 "no vector types expected from SCEVs");

32 return C && this->isValue(C->getAPInt());

33 }

34};

35

39

40

42

46

47

49

53

54

58

62

70

71template struct bind_ty {

73

75

76 template bool match(ITy *V) const {

78 VR = CV;

79 return true;

80 }

81 return false;

82 }

83};

84

85

93

97

101

102

105

107

108 template bool match(ITy *S) const { return S == Expr; }

109};

110

111

113

119

120

122

128

129

130

134

137

139

142 "no vector types expected from SCEVs");

144 if (C)

145 return false;

146 CR = &C->getAPInt();

147 return true;

148 }

149};

150

151

153

154

157

159

162 return E && E->getNumOperands() == 1 && Op0.match(E->getOperand(0));

163 }

164};

165

166template <typename SCEVTy, typename Op0_t>

170

171template <typename Op0_t>

172inline SCEVUnaryExpr_match<SCEVSignExtendExpr, Op0_t>

176

177template <typename Op0_t>

178inline SCEVUnaryExpr_match<SCEVZeroExtendExpr, Op0_t>

182

183template <typename Op0_t>

184inline SCEVUnaryExpr_match<SCEVPtrToIntExpr, Op0_t>

188

189template <typename Op0_t>

190inline SCEVUnaryExpr_match<SCEVTruncateExpr, Op0_t>

194

195

196template <typename SCEVTy, typename Op0_t, typename Op1_t,

198 bool Commutable = false>

202

204

207 if (WrappingS->getNoWrapFlags(WrapFlags) != WrapFlags)

208 return false;

209

211 return E && E->getNumOperands() == 2 &&

212 ((Op0.match(E->getOperand(0)) && Op1.match(E->getOperand(1))) ||

213 (Commutable && Op0.match(E->getOperand(1)) &&

214 Op1.match(E->getOperand(0))));

215 }

216};

217

218template <typename SCEVTy, typename Op0_t, typename Op1_t,

220 bool Commutable = false>

221inline SCEVBinaryExpr_match<SCEVTy, Op0_t, Op1_t, WrapFlags, Commutable>

226

227template <typename Op0_t, typename Op1_t>

228inline SCEVBinaryExpr_match<SCEVAddExpr, Op0_t, Op1_t>

232

233template <typename Op0_t, typename Op1_t>

234inline SCEVBinaryExpr_match<SCEVMulExpr, Op0_t, Op1_t>

238

239template <typename Op0_t, typename Op1_t>

240inline SCEVBinaryExpr_match<SCEVMulExpr, Op0_t, Op1_t, SCEV::FlagAnyWrap, true>

245

246template <typename Op0_t, typename Op1_t>

247inline SCEVBinaryExpr_match<SCEVMulExpr, Op0_t, Op1_t, SCEV::FlagNUW, true>

252

253template <typename Op0_t, typename Op1_t>

254inline SCEVBinaryExpr_match<SCEVUDivExpr, Op0_t, Op1_t>

258

259template <typename Op0_t, typename Op1_t>

260inline SCEVBinaryExpr_match<SCEVSMaxExpr, Op0_t, Op1_t>

264

265template <typename Op0_t, typename Op1_t>

266inline SCEVBinaryExpr_match<SCEVMinMaxExpr, Op0_t, Op1_t>

270

271

272

277

280

283 return false;

284

285

286

287

291

292

293 if (SE.getTypeSizeInBits(LHS->getType()) >

294 SE.getTypeSizeInBits(Expr->getType()))

295 return false;

296 if (LHS->getType() != Expr->getType())

299 SE.getConstant(APInt(SE.getTypeSizeInBits(Expr->getType()), 1)

300 << SE.getTypeSizeInBits(TruncTy));

302 }

303

307 return false;

308

309 const auto MatchURemWithDivisor = [&](const SCEV *B) {

310

311 if (Expr == SE.getURemExpr(A, B))

312 return Op0.match(A) && Op1.match(B);

313 return false;

314 };

315

316

318 return MatchURemWithDivisor(Mul->getOperand(1)) ||

319 MatchURemWithDivisor(Mul->getOperand(2));

320

321

322 if (Mul->getNumOperands() == 2)

323 return MatchURemWithDivisor(Mul->getOperand(1)) ||

324 MatchURemWithDivisor(Mul->getOperand(0)) ||

325 MatchURemWithDivisor(SE.getNegativeSCEV(Mul->getOperand(1))) ||

326 MatchURemWithDivisor(SE.getNegativeSCEV(Mul->getOperand(0)));

327 return false;

328 }

329};

330

331

332

333

334

335template <typename Op0_t, typename Op1_t>

340

342

343

344template <typename Op0_t, typename Op1_t, typename Loop_t>

356

357

360

362

363 bool match(const Loop *L) const { return L == this->L; }

364};

365

367

369

370template <typename Op0_t, typename Op1_t>

371inline SCEVAffineAddRec_match<Op0_t, Op1_t, class_match>

376

377template <typename Op0_t, typename Op1_t, typename Loop_t>

378inline SCEVAffineAddRec_match<Op0_t, Op1_t, Loop_t>

382

390

391

395

396}

397}

398

399#endif

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")

static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")

static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")

Class for arbitrary precision integers.

Represents a single loop in the control flow graph.

This node represents an addition of some number of SCEVs.

This class represents a constant integer value.

This node represents multiplication of some number of SCEVs.

This means that we are dealing with an entirely unknown SCEV value, and only represent it as its LLVM...

This class represents an analyzed expression in the program.

LLVM_ABI Type * getType() const

Return the LLVM type of this SCEV expression.

NoWrapFlags

NoWrapFlags are bitfield indices into SubclassData.

The main scalar evolution driver.

The instances of the Type class are immutable: once they are created, they are never changed.

bool isVectorTy() const

True if this is an instance of VectorType.

bool isPointerTy() const

True if this is an instance of PointerType.

@ C

The default llvm calling convention, compatible with C.

cstval_pred_ty< Predicate, ConstantInt, AllowPoison > cst_pred_ty

specialization of cstval_pred_ty for ConstantInt

class_match< const SCEVVScale > m_SCEVVScale()

Definition ScalarEvolutionPatternMatch.h:67

bind_cst_ty m_scev_APInt(const APInt *&C)

Match an SCEV constant and bind it to an APInt.

Definition ScalarEvolutionPatternMatch.h:152

cst_pred_ty< is_all_ones > m_scev_AllOnes()

Match an integer with all bits set.

Definition ScalarEvolutionPatternMatch.h:55

SCEVUnaryExpr_match< SCEVZeroExtendExpr, Op0_t > m_scev_ZExt(const Op0_t &Op0)

Definition ScalarEvolutionPatternMatch.h:179

is_undef_or_poison m_scev_UndefOrPoison()

Match an SCEVUnknown wrapping undef or poison.

Definition ScalarEvolutionPatternMatch.h:392

SCEVBinaryExpr_match< SCEVMinMaxExpr, Op0_t, Op1_t > m_scev_MinMax(const Op0_t &Op0, const Op1_t &Op1)

Definition ScalarEvolutionPatternMatch.h:267

class_match< const SCEVConstant > m_SCEVConstant()

Definition ScalarEvolutionPatternMatch.h:64

cst_pred_ty< is_one > m_scev_One()

Match an integer 1.

Definition ScalarEvolutionPatternMatch.h:48

specificloop_ty m_SpecificLoop(const Loop *L)

Definition ScalarEvolutionPatternMatch.h:366

cst_pred_ty< is_specific_signed_cst > m_scev_SpecificSInt(int64_t V)

Match an SCEV constant with a plain signed integer (sign-extended value will be matched)

Definition ScalarEvolutionPatternMatch.h:131

SCEVBinaryExpr_match< SCEVTy, Op0_t, Op1_t, WrapFlags, Commutable > m_scev_Binary(const Op0_t &Op0, const Op1_t &Op1)

Definition ScalarEvolutionPatternMatch.h:222

SCEVAffineAddRec_match< Op0_t, Op1_t, class_match< const Loop > > m_scev_AffineAddRec(const Op0_t &Op0, const Op1_t &Op1)

Definition ScalarEvolutionPatternMatch.h:372

bind_ty< const SCEVMulExpr > m_scev_Mul(const SCEVMulExpr *&V)

Definition ScalarEvolutionPatternMatch.h:98

SCEVUnaryExpr_match< SCEVTy, Op0_t > m_scev_Unary(const Op0_t &Op0)

Definition ScalarEvolutionPatternMatch.h:167

SCEVUnaryExpr_match< SCEVSignExtendExpr, Op0_t > m_scev_SExt(const Op0_t &Op0)

Definition ScalarEvolutionPatternMatch.h:173

cst_pred_ty< is_zero > m_scev_Zero()

Match an integer 0.

Definition ScalarEvolutionPatternMatch.h:41

SCEVUnaryExpr_match< SCEVTruncateExpr, Op0_t > m_scev_Trunc(const Op0_t &Op0)

Definition ScalarEvolutionPatternMatch.h:191

bool match(const SCEV *S, const Pattern &P)

Definition ScalarEvolutionPatternMatch.h:21

SCEVBinaryExpr_match< SCEVUDivExpr, Op0_t, Op1_t > m_scev_UDiv(const Op0_t &Op0, const Op1_t &Op1)

Definition ScalarEvolutionPatternMatch.h:255

specificscev_ty m_scev_Specific(const SCEV *S)

Match if we have a specific specified SCEV.

Definition ScalarEvolutionPatternMatch.h:112

SCEVBinaryExpr_match< SCEVMulExpr, Op0_t, Op1_t, SCEV::FlagNUW, true > m_scev_c_NUWMul(const Op0_t &Op0, const Op1_t &Op1)

Definition ScalarEvolutionPatternMatch.h:248

class_match< const Loop > m_Loop()

Definition ScalarEvolutionPatternMatch.h:341

bind_ty< const SCEVAddExpr > m_scev_Add(const SCEVAddExpr *&V)

Definition ScalarEvolutionPatternMatch.h:94

SCEVUnaryExpr_match< SCEVPtrToIntExpr, Op0_t > m_scev_PtrToInt(const Op0_t &Op0)

Definition ScalarEvolutionPatternMatch.h:185

bind_ty< const SCEVUnknown > m_SCEVUnknown(const SCEVUnknown *&V)

Definition ScalarEvolutionPatternMatch.h:90

cst_pred_ty< is_specific_cst > m_scev_SpecificInt(uint64_t V)

Match an SCEV constant with a plain unsigned integer.

Definition ScalarEvolutionPatternMatch.h:121

SCEVBinaryExpr_match< SCEVMulExpr, Op0_t, Op1_t, SCEV::FlagAnyWrap, true > m_scev_c_Mul(const Op0_t &Op0, const Op1_t &Op1)

Definition ScalarEvolutionPatternMatch.h:241

SCEVBinaryExpr_match< SCEVSMaxExpr, Op0_t, Op1_t > m_scev_SMax(const Op0_t &Op0, const Op1_t &Op1)

Definition ScalarEvolutionPatternMatch.h:261

SCEVURem_match< Op0_t, Op1_t > m_scev_URem(Op0_t LHS, Op1_t RHS, ScalarEvolution &SE)

Match the mathematical pattern A - (A / B) * B, where A and B can be arbitrary expressions.

Definition ScalarEvolutionPatternMatch.h:336

class_match< const SCEV > m_SCEV()

Definition ScalarEvolutionPatternMatch.h:63

This is an optimization pass for GlobalISel generic memory operations.

decltype(auto) dyn_cast(const From &Val)

dyn_cast - Return the argument parameter cast to the specified type.

bool isa(const From &Val)

isa - Return true if the parameter to the template is an instance of one of the template type argu...

@ Mul

Product of integers.

decltype(auto) cast(const From &Val)

cast - Return the argument parameter cast to the specified type.

Match an affine SCEVAddRecExpr.

Definition ScalarEvolutionPatternMatch.h:345

Loop_t Loop

Definition ScalarEvolutionPatternMatch.h:347

SCEVBinaryExpr_match< SCEVAddRecExpr, Op0_t, Op1_t > Ops

Definition ScalarEvolutionPatternMatch.h:346

bool match(const SCEV *S) const

Definition ScalarEvolutionPatternMatch.h:352

SCEVAffineAddRec_match(Op0_t Op0, Op1_t Op1, Loop_t Loop)

Definition ScalarEvolutionPatternMatch.h:349

Match a binary SCEV.

Definition ScalarEvolutionPatternMatch.h:199

Op1_t Op1

Definition ScalarEvolutionPatternMatch.h:201

SCEVBinaryExpr_match(Op0_t Op0, Op1_t Op1)

Definition ScalarEvolutionPatternMatch.h:203

Op0_t Op0

Definition ScalarEvolutionPatternMatch.h:200

bool match(const SCEV *S) const

Definition ScalarEvolutionPatternMatch.h:205

Match unsigned remainder pattern.

Definition ScalarEvolutionPatternMatch.h:273

SCEVURem_match(Op0_t Op0, Op1_t Op1, ScalarEvolution &SE)

Definition ScalarEvolutionPatternMatch.h:278

ScalarEvolution & SE

Definition ScalarEvolutionPatternMatch.h:276

Op0_t Op0

Definition ScalarEvolutionPatternMatch.h:274

bool match(const SCEV *Expr) const

Definition ScalarEvolutionPatternMatch.h:281

Op1_t Op1

Definition ScalarEvolutionPatternMatch.h:275

Match a unary SCEV.

Definition ScalarEvolutionPatternMatch.h:155

bool match(const SCEV *S) const

Definition ScalarEvolutionPatternMatch.h:160

Op0_t Op0

Definition ScalarEvolutionPatternMatch.h:156

SCEVUnaryExpr_match(Op0_t Op0)

Definition ScalarEvolutionPatternMatch.h:158

const APInt *& CR

Definition ScalarEvolutionPatternMatch.h:136

bind_cst_ty(const APInt *&Op0)

Definition ScalarEvolutionPatternMatch.h:138

bool match(const SCEV *S) const

Definition ScalarEvolutionPatternMatch.h:140

bool match(ITy *V) const

Definition ScalarEvolutionPatternMatch.h:76

Class *& VR

Definition ScalarEvolutionPatternMatch.h:72

bind_ty(Class *&V)

Definition ScalarEvolutionPatternMatch.h:74

bool match(ITy *V) const

Definition ScalarEvolutionPatternMatch.h:60

cst_pred_ty(uint64_t V)

Definition ScalarEvolutionPatternMatch.h:27

bool match(const SCEV *S) const

Definition ScalarEvolutionPatternMatch.h:28

bool isValue(const APInt &C) const

Definition ScalarEvolutionPatternMatch.h:51

bool isValue(const APInt &C) const

Definition ScalarEvolutionPatternMatch.h:44

is_specific_cst(uint64_t C)

Definition ScalarEvolutionPatternMatch.h:116

bool isValue(const APInt &C) const

Definition ScalarEvolutionPatternMatch.h:117

uint64_t CV

Definition ScalarEvolutionPatternMatch.h:115

bool isValue(const APInt &C) const

Definition ScalarEvolutionPatternMatch.h:126

is_specific_signed_cst(int64_t C)

Definition ScalarEvolutionPatternMatch.h:125

int64_t CV

Definition ScalarEvolutionPatternMatch.h:124

bool match(const SCEV *S) const

Definition ScalarEvolutionPatternMatch.h:384

bool isValue(const APInt &C) const

Definition ScalarEvolutionPatternMatch.h:37

Match a specified const Loop*.

Definition ScalarEvolutionPatternMatch.h:358

bool match(const Loop *L) const

Definition ScalarEvolutionPatternMatch.h:363

const Loop * L

Definition ScalarEvolutionPatternMatch.h:359

specificloop_ty(const Loop *L)

Definition ScalarEvolutionPatternMatch.h:361

Match a specified const SCEV *.

Definition ScalarEvolutionPatternMatch.h:103

bool match(ITy *S) const

Definition ScalarEvolutionPatternMatch.h:108

specificscev_ty(const SCEV *Expr)

Definition ScalarEvolutionPatternMatch.h:106

const SCEV * Expr

Definition ScalarEvolutionPatternMatch.h:104