Coverage Report

Created: 2019-02-23 12:57

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/polly/include/polly/Support/SCEVAffinator.h
Line
Count
Source
1
//===------ polly/SCEVAffinator.h - Create isl expressions from SCEVs -----===//
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
13
#ifndef POLLY_SCEV_AFFINATOR_H
14
#define POLLY_SCEV_AFFINATOR_H
15
16
#include "llvm/ADT/DenseMap.h"
17
#include "llvm/Analysis/ScalarEvolutionExpressions.h"
18
19
#include "isl/isl-noexceptions.h"
20
21
namespace llvm {
22
class Region;
23
class BasicBlock;
24
class DataLayout;
25
class ScalarEvolution;
26
} // namespace llvm
27
28
namespace polly {
29
class Scop;
30
class ScopStmt;
31
32
/// The result type of the SCEVAffinator.
33
///
34
/// The first element of the pair is the isl representation of the SCEV, the
35
/// second is the domain under which it is __invalid__.
36
typedef std::pair<isl::pw_aff, isl::set> PWACtx;
37
38
/// Translate a SCEV to an isl::pw_aff and the domain on which it is invalid.
39
struct SCEVAffinator : public llvm::SCEVVisitor<SCEVAffinator, PWACtx> {
40
public:
41
  SCEVAffinator(Scop *S, llvm::LoopInfo &LI);
42
43
  /// Translate a SCEV to an isl::pw_aff.
44
  ///
45
  /// @param E  he expression that is translated.
46
  /// @param BB The block in which @p E is executed.
47
  ///
48
  /// @returns The isl representation of the SCEV @p E in @p Domain.
49
  PWACtx getPwAff(const llvm::SCEV *E, llvm::BasicBlock *BB = nullptr);
50
51
  /// Take the assumption that @p PWAC is non-negative.
52
  void takeNonNegativeAssumption(PWACtx &PWAC);
53
54
  /// Interpret the PWA in @p PWAC as an unsigned value.
55
  void interpretAsUnsigned(PWACtx &PWAC, unsigned Width);
56
57
  /// Check an <nsw> AddRec for the loop @p L is cached.
58
  bool hasNSWAddRecForLoop(llvm::Loop *L) const;
59
60
  /// Return the LoopInfo used by thi object.
61
2.70k
  llvm::LoopInfo *getLI() const { return &LI; }
62
63
private:
64
  /// Key to identify cached expressions.
65
  using CacheKey = std::pair<const llvm::SCEV *, llvm::BasicBlock *>;
66
67
  /// Map to remembered cached expressions.
68
  llvm::DenseMap<CacheKey, PWACtx> CachedExpressions;
69
70
  Scop *S;
71
  isl::ctx Ctx;
72
  unsigned NumIterators;
73
  llvm::ScalarEvolution &SE;
74
  llvm::LoopInfo &LI;
75
  llvm::BasicBlock *BB;
76
77
  /// Target data for element size computing.
78
  const llvm::DataLayout &TD;
79
80
  /// Return the loop for the current block if any.
81
  llvm::Loop *getScope();
82
83
  /// Return a PWACtx for @p PWA that is always valid.
84
  PWACtx getPWACtxFromPWA(isl::pw_aff PWA);
85
86
  /// Compute the non-wrapping version of @p PWA for type @p ExprType.
87
  ///
88
  /// @param PWA  The piece-wise affine function that might wrap.
89
  /// @param Type The type of the SCEV that was translated to @p PWA.
90
  ///
91
  /// @returns The expr @p PWA modulo the size constraints of @p ExprType.
92
  isl::pw_aff addModuloSemantic(isl::pw_aff PWA, llvm::Type *ExprType) const;
93
94
  /// If @p Expr might cause an integer wrap record an assumption.
95
  ///
96
  /// @param Expr The SCEV expression that might wrap.
97
  /// @param PWAC The isl representation of @p Expr with the invalid domain.
98
  ///
99
  /// @returns The isl representation @p PWAC with a possibly adjusted domain.
100
  PWACtx checkForWrapping(const llvm::SCEV *Expr, PWACtx PWAC) const;
101
102
  /// Whether to track the value of this expression precisely, rather than
103
  /// assuming it won't wrap.
104
  bool computeModuloForExpr(const llvm::SCEV *Expr);
105
106
  PWACtx visit(const llvm::SCEV *E);
107
  PWACtx visitConstant(const llvm::SCEVConstant *E);
108
  PWACtx visitTruncateExpr(const llvm::SCEVTruncateExpr *E);
109
  PWACtx visitZeroExtendExpr(const llvm::SCEVZeroExtendExpr *E);
110
  PWACtx visitSignExtendExpr(const llvm::SCEVSignExtendExpr *E);
111
  PWACtx visitAddExpr(const llvm::SCEVAddExpr *E);
112
  PWACtx visitMulExpr(const llvm::SCEVMulExpr *E);
113
  PWACtx visitUDivExpr(const llvm::SCEVUDivExpr *E);
114
  PWACtx visitAddRecExpr(const llvm::SCEVAddRecExpr *E);
115
  PWACtx visitSMaxExpr(const llvm::SCEVSMaxExpr *E);
116
  PWACtx visitUMaxExpr(const llvm::SCEVUMaxExpr *E);
117
  PWACtx visitUnknown(const llvm::SCEVUnknown *E);
118
  PWACtx visitSDivInstruction(llvm::Instruction *SDiv);
119
  PWACtx visitSRemInstruction(llvm::Instruction *SRem);
120
  PWACtx complexityBailout();
121
122
  friend struct llvm::SCEVVisitor<SCEVAffinator, PWACtx>;
123
};
124
} // namespace polly
125
126
#endif