Coverage Report

Created: 2017-09-21 03:39

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