Coverage Report

Created: 2019-07-24 05:18

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