Sebastian Pop | 082cea8 | 2012-05-07 16:20:07 +0000 | [diff] [blame] | 1 | //===------ IslCodeGeneration.cpp - Code generate the Scops using ISL. ----===// |
| 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 | // The IslCodeGeneration pass takes a Scop created by ScopInfo and translates it |
| 11 | // back to LLVM-IR using the ISL code generator. |
| 12 | // |
| 13 | // The Scop describes the high level memory behaviour of a control flow region. |
| 14 | // Transformation passes can update the schedule (execution order) of statements |
| 15 | // in the Scop. ISL is used to generate an abstract syntax tree that reflects |
| 16 | // the updated execution order. This clast is used to create new LLVM-IR that is |
| 17 | // computationally equivalent to the original control flow region, but executes |
| 18 | // its code in the new execution order defined by the changed scattering. |
| 19 | // |
| 20 | //===----------------------------------------------------------------------===// |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 21 | #include "polly/Config/config.h" |
Johannes Doerfert | a63b257 | 2014-08-03 01:51:59 +0000 | [diff] [blame] | 22 | #include "polly/CodeGen/IslExprBuilder.h" |
Tobias Grosser | 8362818 | 2013-05-07 08:11:54 +0000 | [diff] [blame] | 23 | #include "polly/CodeGen/BlockGenerators.h" |
| 24 | #include "polly/CodeGen/CodeGeneration.h" |
| 25 | #include "polly/CodeGen/IslAst.h" |
| 26 | #include "polly/CodeGen/LoopGenerators.h" |
| 27 | #include "polly/CodeGen/Utils.h" |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 28 | #include "polly/Dependences.h" |
| 29 | #include "polly/LinkAllPasses.h" |
| 30 | #include "polly/ScopInfo.h" |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 31 | #include "polly/Support/GICHelper.h" |
Tobias Grosser | 0ee50f6 | 2013-04-10 06:55:31 +0000 | [diff] [blame] | 32 | #include "polly/Support/ScopHelper.h" |
Tobias Grosser | e3c0558 | 2014-11-15 21:32:53 +0000 | [diff] [blame^] | 33 | #include "polly/Support/SCEVValidator.h" |
Tobias Grosser | 8362818 | 2013-05-07 08:11:54 +0000 | [diff] [blame] | 34 | #include "polly/TempScopInfo.h" |
Tobias Grosser | e3c0558 | 2014-11-15 21:32:53 +0000 | [diff] [blame^] | 35 | |
| 36 | #include "llvm/ADT/PostOrderIterator.h" |
| 37 | #include "llvm/ADT/SmallPtrSet.h" |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 38 | #include "llvm/Analysis/LoopInfo.h" |
Matt Arsenault | 8ca3681 | 2014-07-19 18:40:17 +0000 | [diff] [blame] | 39 | #include "llvm/Analysis/PostDominators.h" |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 40 | #include "llvm/Analysis/ScalarEvolutionExpander.h" |
Tobias Grosser | 8362818 | 2013-05-07 08:11:54 +0000 | [diff] [blame] | 41 | #include "llvm/IR/Module.h" |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 42 | #include "llvm/Support/CommandLine.h" |
| 43 | #include "llvm/Support/Debug.h" |
Chandler Carruth | 535d52c | 2013-01-02 11:47:44 +0000 | [diff] [blame] | 44 | #include "llvm/IR/DataLayout.h" |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 45 | #include "llvm/Transforms/Utils/BasicBlockUtils.h" |
| 46 | |
| 47 | #include "isl/union_map.h" |
| 48 | #include "isl/list.h" |
| 49 | #include "isl/ast.h" |
| 50 | #include "isl/ast_build.h" |
| 51 | #include "isl/set.h" |
| 52 | #include "isl/map.h" |
| 53 | #include "isl/aff.h" |
| 54 | |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 55 | using namespace polly; |
| 56 | using namespace llvm; |
| 57 | |
Chandler Carruth | 95fef94 | 2014-04-22 03:30:19 +0000 | [diff] [blame] | 58 | #define DEBUG_TYPE "polly-codegen-isl" |
| 59 | |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 60 | class IslNodeBuilder { |
| 61 | public: |
Johannes Doerfert | 51d1c74 | 2014-10-02 15:32:17 +0000 | [diff] [blame] | 62 | IslNodeBuilder(PollyIRBuilder &Builder, ScopAnnotator &Annotator, Pass *P, |
Tobias Grosser | e3c0558 | 2014-11-15 21:32:53 +0000 | [diff] [blame^] | 63 | const DataLayout &DL, LoopInfo &LI, ScalarEvolution &SE, |
| 64 | DominatorTree &DT, Scop &S) |
| 65 | : S(S), Builder(Builder), Annotator(Annotator), |
Johannes Doerfert | 2ef33e9 | 2014-10-05 11:33:59 +0000 | [diff] [blame] | 66 | Rewriter(new SCEVExpander(SE, "polly")), |
Tobias Grosser | e3c0558 | 2014-11-15 21:32:53 +0000 | [diff] [blame^] | 67 | ExprBuilder(Builder, IDToValue, *Rewriter), P(P), DL(DL), LI(LI), |
| 68 | SE(SE), DT(DT) {} |
Johannes Doerfert | 2ef33e9 | 2014-10-05 11:33:59 +0000 | [diff] [blame] | 69 | |
| 70 | ~IslNodeBuilder() { delete Rewriter; } |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 71 | |
| 72 | void addParameters(__isl_take isl_set *Context); |
| 73 | void create(__isl_take isl_ast_node *Node); |
Tobias Grosser | 54ee0ba | 2013-11-17 03:18:25 +0000 | [diff] [blame] | 74 | IslExprBuilder &getExprBuilder() { return ExprBuilder; } |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 75 | |
| 76 | private: |
Tobias Grosser | e3c0558 | 2014-11-15 21:32:53 +0000 | [diff] [blame^] | 77 | Scop &S; |
Tobias Grosser | 5103ba7 | 2014-03-04 14:58:49 +0000 | [diff] [blame] | 78 | PollyIRBuilder &Builder; |
Johannes Doerfert | 51d1c74 | 2014-10-02 15:32:17 +0000 | [diff] [blame] | 79 | ScopAnnotator &Annotator; |
Johannes Doerfert | 2ef33e9 | 2014-10-05 11:33:59 +0000 | [diff] [blame] | 80 | |
| 81 | /// @brief A SCEVExpander to create llvm values from SCEVs. |
| 82 | SCEVExpander *Rewriter; |
| 83 | |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 84 | IslExprBuilder ExprBuilder; |
| 85 | Pass *P; |
Tobias Grosser | e3c0558 | 2014-11-15 21:32:53 +0000 | [diff] [blame^] | 86 | const DataLayout &DL; |
Johannes Doerfert | 2ef3f4f | 2014-08-07 17:14:54 +0000 | [diff] [blame] | 87 | LoopInfo &LI; |
| 88 | ScalarEvolution &SE; |
| 89 | DominatorTree &DT; |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 90 | |
Tobias Grosser | e3c0558 | 2014-11-15 21:32:53 +0000 | [diff] [blame^] | 91 | /// @brief The current iteration of out-of-scop loops |
| 92 | /// |
| 93 | /// This map provides for a given loop a llvm::Value that contains the current |
| 94 | /// loop iteration. |
| 95 | LoopToScevMapT OutsideLoopIterations; |
| 96 | |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 97 | // This maps an isl_id* to the Value* it has in the generated program. For now |
| 98 | // on, the only isl_ids that are stored here are the newly calculated loop |
| 99 | // ivs. |
Tobias Grosser | 566ad58 | 2014-08-31 16:21:12 +0000 | [diff] [blame] | 100 | IslExprBuilder::IDToValueTy IDToValue; |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 101 | |
Tobias Grosser | ec7d67e | 2014-11-06 00:27:01 +0000 | [diff] [blame] | 102 | /// Generate code for a given SCEV* |
| 103 | /// |
| 104 | /// This function generates code for a given SCEV expression. It generated |
| 105 | /// code is emmitted at the end of the basic block our Builder currently |
| 106 | /// points to and the resulting value is returned. |
| 107 | /// |
| 108 | /// @param Expr The expression to code generate. |
| 109 | Value *generateSCEV(const SCEV *Expr); |
| 110 | |
Tobias Grosser | e3c0558 | 2014-11-15 21:32:53 +0000 | [diff] [blame^] | 111 | /// A set of Value -> Value remappings to apply when generating new code. |
| 112 | /// |
| 113 | /// When generating new code for a ScopStmt this map is used to map certain |
| 114 | /// llvm::Values to new llvm::Values. |
| 115 | ValueMapT ValueMap; |
| 116 | |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 117 | // Extract the upper bound of this loop |
| 118 | // |
| 119 | // The isl code generation can generate arbitrary expressions to check if the |
| 120 | // upper bound of a loop is reached, but it provides an option to enforce |
| 121 | // 'atomic' upper bounds. An 'atomic upper bound is always of the form |
| 122 | // iv <= expr, where expr is an (arbitrary) expression not containing iv. |
| 123 | // |
| 124 | // This function extracts 'atomic' upper bounds. Polly, in general, requires |
| 125 | // atomic upper bounds for the following reasons: |
| 126 | // |
| 127 | // 1. An atomic upper bound is loop invariant |
| 128 | // |
| 129 | // It must not be calculated at each loop iteration and can often even be |
| 130 | // hoisted out further by the loop invariant code motion. |
| 131 | // |
| 132 | // 2. OpenMP needs a loop invarient upper bound to calculate the number |
| 133 | // of loop iterations. |
| 134 | // |
| 135 | // 3. With the existing code, upper bounds have been easier to implement. |
Tobias Grosser | e602a07 | 2013-05-07 07:30:56 +0000 | [diff] [blame] | 136 | __isl_give isl_ast_expr *getUpperBound(__isl_keep isl_ast_node *For, |
| 137 | CmpInst::Predicate &Predicate); |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 138 | |
Sebastian Pop | 04c4ce3 | 2012-12-18 07:46:13 +0000 | [diff] [blame] | 139 | unsigned getNumberOfIterations(__isl_keep isl_ast_node *For); |
| 140 | |
Tobias Grosser | e3c0558 | 2014-11-15 21:32:53 +0000 | [diff] [blame^] | 141 | /// Compute the values and loops referenced in this subtree. |
| 142 | /// |
| 143 | /// This function looks at all ScopStmts scheduled below the provided For node |
| 144 | /// and finds the llvm::Value[s] and llvm::Loops[s] which are referenced but |
| 145 | /// not locally defined. |
| 146 | /// |
| 147 | /// Values that can be synthesized or that are available as globals are |
| 148 | /// considered locally defined. |
| 149 | /// |
| 150 | /// Loops that contain the scop or that are part of the scop are considered |
| 151 | /// locally defined. Loops that are before the scop, but do not contain the |
| 152 | /// scop itself are considered not locally defined. |
| 153 | /// |
| 154 | /// @param For The node defining the subtree. |
| 155 | /// @param Values A vector that will be filled with the Values referenced in |
| 156 | /// this subtree. |
| 157 | /// @param Loops A vector that will be filled with the Loops referenced in |
| 158 | /// this subtree. |
| 159 | void getReferencesInSubtree(__isl_keep isl_ast_node *For, |
| 160 | SetVector<Value *> &Values, |
| 161 | SetVector<const Loop *> &Loops); |
| 162 | |
| 163 | /// Change the llvm::Value(s) used for code generation. |
| 164 | /// |
| 165 | /// When generating code certain values (e.g., references to induction |
| 166 | /// variables or array base pointers) in the original code may be replaced by |
| 167 | /// new values. This function allows to (partially) update the set of values |
| 168 | /// used. A typical use case for this function is the case when we continue |
| 169 | /// code generation in a subfunction/kernel function and need to explicitly |
| 170 | /// pass down certain values. |
| 171 | /// |
| 172 | /// @param NewValues A map that maps certain llvm::Values to new llvm::Values. |
| 173 | void updateValues(ParallelLoopGenerator::ValueToValueMapTy &NewValues); |
| 174 | |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 175 | void createFor(__isl_take isl_ast_node *For); |
Sebastian Pop | 04c4ce3 | 2012-12-18 07:46:13 +0000 | [diff] [blame] | 176 | void createForVector(__isl_take isl_ast_node *For, int VectorWidth); |
| 177 | void createForSequential(__isl_take isl_ast_node *For); |
Tobias Grosser | ce67a04 | 2014-07-02 16:26:47 +0000 | [diff] [blame] | 178 | |
Tobias Grosser | e3c0558 | 2014-11-15 21:32:53 +0000 | [diff] [blame^] | 179 | /// Create LLVM-IR that executes a for node thread parallel. |
| 180 | /// |
| 181 | /// @param For The FOR isl_ast_node for which code is generated. |
| 182 | void createForParallel(__isl_take isl_ast_node *For); |
| 183 | |
Tobias Grosser | ce67a04 | 2014-07-02 16:26:47 +0000 | [diff] [blame] | 184 | /// Generate LLVM-IR that computes the values of the original induction |
| 185 | /// variables in function of the newly generated loop induction variables. |
| 186 | /// |
| 187 | /// Example: |
| 188 | /// |
| 189 | /// // Original |
| 190 | /// for i |
| 191 | /// for j |
| 192 | /// S(i) |
| 193 | /// |
| 194 | /// Schedule: [i,j] -> [i+j, j] |
| 195 | /// |
| 196 | /// // New |
| 197 | /// for c0 |
| 198 | /// for c1 |
| 199 | /// S(c0 - c1, c1) |
| 200 | /// |
| 201 | /// Assuming the original code consists of two loops which are |
| 202 | /// transformed according to a schedule [i,j] -> [c0=i+j,c1=j]. The resulting |
| 203 | /// ast models the original statement as a call expression where each argument |
| 204 | /// is an expression that computes the old induction variables from the new |
| 205 | /// ones, ordered such that the first argument computes the value of induction |
| 206 | /// variable that was outermost in the original code. |
| 207 | /// |
| 208 | /// @param Expr The call expression that represents the statement. |
| 209 | /// @param Stmt The statement that is called. |
| 210 | /// @param VMap The value map into which the mapping from the old induction |
| 211 | /// variable to the new one is inserted. This mapping is used |
| 212 | /// for the classical code generation (not scev-based) and |
| 213 | /// gives an explicit mapping from an original, materialized |
| 214 | /// induction variable. It consequently can only be expressed |
| 215 | /// if there was an explicit induction variable. |
| 216 | /// @param LTS The loop to SCEV map in which the mapping from the original |
| 217 | /// loop to a SCEV representing the new loop iv is added. This |
| 218 | /// mapping does not require an explicit induction variable. |
| 219 | /// Instead, we think in terms of an implicit induction variable |
| 220 | /// that counts the number of times a loop is executed. For each |
| 221 | /// original loop this count, expressed in function of the new |
| 222 | /// induction variables, is added to the LTS map. |
| 223 | void createSubstitutions(__isl_take isl_ast_expr *Expr, ScopStmt *Stmt, |
Sebastian Pop | 9d10fff | 2013-02-15 20:55:59 +0000 | [diff] [blame] | 224 | ValueMapT &VMap, LoopToScevMapT <S); |
Tobias Grosser | ce67a04 | 2014-07-02 16:26:47 +0000 | [diff] [blame] | 225 | void createSubstitutionsVector(__isl_take isl_ast_expr *Expr, ScopStmt *Stmt, |
| 226 | VectorValueMapT &VMap, |
Tobias Grosser | e602a07 | 2013-05-07 07:30:56 +0000 | [diff] [blame] | 227 | std::vector<LoopToScevMapT> &VLTS, |
| 228 | std::vector<Value *> &IVS, |
| 229 | __isl_take isl_id *IteratorID); |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 230 | void createIf(__isl_take isl_ast_node *If); |
Tobias Grosser | e602a07 | 2013-05-07 07:30:56 +0000 | [diff] [blame] | 231 | void createUserVector(__isl_take isl_ast_node *User, |
| 232 | std::vector<Value *> &IVS, |
| 233 | __isl_take isl_id *IteratorID, |
| 234 | __isl_take isl_union_map *Schedule); |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 235 | void createUser(__isl_take isl_ast_node *User); |
| 236 | void createBlock(__isl_take isl_ast_node *Block); |
| 237 | }; |
| 238 | |
Tobias Grosser | e602a07 | 2013-05-07 07:30:56 +0000 | [diff] [blame] | 239 | __isl_give isl_ast_expr * |
| 240 | IslNodeBuilder::getUpperBound(__isl_keep isl_ast_node *For, |
| 241 | ICmpInst::Predicate &Predicate) { |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 242 | isl_id *UBID, *IteratorID; |
| 243 | isl_ast_expr *Cond, *Iterator, *UB, *Arg0; |
Tobias Grosser | c967d8e | 2012-10-16 07:29:13 +0000 | [diff] [blame] | 244 | isl_ast_op_type Type; |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 245 | |
| 246 | Cond = isl_ast_node_for_get_cond(For); |
| 247 | Iterator = isl_ast_node_for_get_iterator(For); |
Tobias Grosser | c967d8e | 2012-10-16 07:29:13 +0000 | [diff] [blame] | 248 | Type = isl_ast_expr_get_op_type(Cond); |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 249 | |
Tobias Grosser | ae2d83e | 2012-12-29 23:57:18 +0000 | [diff] [blame] | 250 | assert(isl_ast_expr_get_type(Cond) == isl_ast_expr_op && |
| 251 | "conditional expression is not an atomic upper bound"); |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 252 | |
Tobias Grosser | c967d8e | 2012-10-16 07:29:13 +0000 | [diff] [blame] | 253 | switch (Type) { |
Tobias Grosser | c14582f | 2013-02-05 18:01:29 +0000 | [diff] [blame] | 254 | case isl_ast_op_le: |
| 255 | Predicate = ICmpInst::ICMP_SLE; |
| 256 | break; |
| 257 | case isl_ast_op_lt: |
| 258 | Predicate = ICmpInst::ICMP_SLT; |
| 259 | break; |
| 260 | default: |
| 261 | llvm_unreachable("Unexpected comparision type in loop conditon"); |
Tobias Grosser | c967d8e | 2012-10-16 07:29:13 +0000 | [diff] [blame] | 262 | } |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 263 | |
| 264 | Arg0 = isl_ast_expr_get_op_arg(Cond, 0); |
| 265 | |
Tobias Grosser | ae2d83e | 2012-12-29 23:57:18 +0000 | [diff] [blame] | 266 | assert(isl_ast_expr_get_type(Arg0) == isl_ast_expr_id && |
| 267 | "conditional expression is not an atomic upper bound"); |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 268 | |
| 269 | UBID = isl_ast_expr_get_id(Arg0); |
| 270 | |
Tobias Grosser | ae2d83e | 2012-12-29 23:57:18 +0000 | [diff] [blame] | 271 | assert(isl_ast_expr_get_type(Iterator) == isl_ast_expr_id && |
| 272 | "Could not get the iterator"); |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 273 | |
| 274 | IteratorID = isl_ast_expr_get_id(Iterator); |
| 275 | |
Tobias Grosser | ae2d83e | 2012-12-29 23:57:18 +0000 | [diff] [blame] | 276 | assert(UBID == IteratorID && |
| 277 | "conditional expression is not an atomic upper bound"); |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 278 | |
| 279 | UB = isl_ast_expr_get_op_arg(Cond, 1); |
| 280 | |
| 281 | isl_ast_expr_free(Cond); |
| 282 | isl_ast_expr_free(Iterator); |
| 283 | isl_ast_expr_free(Arg0); |
| 284 | isl_id_free(IteratorID); |
| 285 | isl_id_free(UBID); |
| 286 | |
| 287 | return UB; |
| 288 | } |
| 289 | |
Sebastian Pop | 04c4ce3 | 2012-12-18 07:46:13 +0000 | [diff] [blame] | 290 | unsigned IslNodeBuilder::getNumberOfIterations(__isl_keep isl_ast_node *For) { |
Johannes Doerfert | 94d9082 | 2014-07-23 20:26:25 +0000 | [diff] [blame] | 291 | isl_union_map *Schedule = IslAstInfo::getSchedule(For); |
Sebastian Pop | 04c4ce3 | 2012-12-18 07:46:13 +0000 | [diff] [blame] | 292 | isl_set *LoopDomain = isl_set_from_union_set(isl_union_map_range(Schedule)); |
Sebastian Pop | 2aa5c24 | 2012-12-18 08:56:51 +0000 | [diff] [blame] | 293 | int NumberOfIterations = polly::getNumberOfIterations(LoopDomain); |
| 294 | if (NumberOfIterations == -1) |
| 295 | return -1; |
| 296 | return NumberOfIterations + 1; |
Sebastian Pop | 04c4ce3 | 2012-12-18 07:46:13 +0000 | [diff] [blame] | 297 | } |
| 298 | |
Tobias Grosser | e3c0558 | 2014-11-15 21:32:53 +0000 | [diff] [blame^] | 299 | struct FindValuesUser { |
| 300 | LoopInfo &LI; |
| 301 | ScalarEvolution &SE; |
| 302 | Region &R; |
| 303 | SetVector<Value *> &Values; |
| 304 | SetVector<const SCEV *> &SCEVs; |
| 305 | }; |
| 306 | |
| 307 | /// Extract the values and SCEVs needed to generate code for a ScopStmt. |
| 308 | /// |
| 309 | /// This function extracts a ScopStmt from a given isl_set and computes the |
| 310 | /// Values this statement depends on as well as a set of SCEV expressions that |
| 311 | /// need to be synthesized when generating code for this statment. |
| 312 | static int findValuesInStmt(isl_set *Set, void *UserPtr) { |
| 313 | isl_id *Id = isl_set_get_tuple_id(Set); |
| 314 | struct FindValuesUser &User = *static_cast<struct FindValuesUser *>(UserPtr); |
| 315 | const ScopStmt *Stmt = static_cast<const ScopStmt *>(isl_id_get_user(Id)); |
| 316 | const BasicBlock *BB = Stmt->getBasicBlock(); |
| 317 | |
| 318 | // Check all the operands of instructions in the basic block. |
| 319 | for (const Instruction &Inst : *BB) { |
| 320 | for (Value *SrcVal : Inst.operands()) { |
| 321 | if (Instruction *OpInst = dyn_cast<Instruction>(SrcVal)) |
| 322 | if (canSynthesize(OpInst, &User.LI, &User.SE, &User.R)) { |
| 323 | User.SCEVs.insert( |
| 324 | User.SE.getSCEVAtScope(OpInst, User.LI.getLoopFor(BB))); |
| 325 | continue; |
| 326 | } |
| 327 | if (Instruction *OpInst = dyn_cast<Instruction>(SrcVal)) |
| 328 | if (Stmt->getParent()->getRegion().contains(OpInst)) |
| 329 | continue; |
| 330 | |
| 331 | if (isa<Instruction>(SrcVal) || isa<Argument>(SrcVal)) |
| 332 | User.Values.insert(SrcVal); |
| 333 | } |
| 334 | } |
| 335 | isl_id_free(Id); |
| 336 | isl_set_free(Set); |
| 337 | return 0; |
| 338 | } |
| 339 | |
| 340 | void IslNodeBuilder::getReferencesInSubtree(__isl_keep isl_ast_node *For, |
| 341 | SetVector<Value *> &Values, |
| 342 | SetVector<const Loop *> &Loops) { |
| 343 | |
| 344 | SetVector<const SCEV *> SCEVs; |
| 345 | struct FindValuesUser FindValues = {LI, SE, S.getRegion(), Values, SCEVs}; |
| 346 | |
| 347 | for (const auto &I : IDToValue) |
| 348 | Values.insert(I.second); |
| 349 | |
| 350 | for (const auto &I : OutsideLoopIterations) |
| 351 | Values.insert(cast<SCEVUnknown>(I.second)->getValue()); |
| 352 | |
| 353 | isl_union_set *Schedule = isl_union_map_domain(IslAstInfo::getSchedule(For)); |
| 354 | |
| 355 | isl_union_set_foreach_set(Schedule, findValuesInStmt, &FindValues); |
| 356 | isl_union_set_free(Schedule); |
| 357 | |
| 358 | for (const SCEV *Expr : SCEVs) { |
| 359 | findValues(Expr, Values); |
| 360 | findLoops(Expr, Loops); |
| 361 | } |
| 362 | |
| 363 | Values.remove_if([](const Value *V) { return isa<GlobalValue>(V); }); |
| 364 | |
| 365 | /// Remove loops that contain the scop or that are part of the scop, as they |
| 366 | /// are considered local. This leaves only loops that are before the scop, but |
| 367 | /// do not contain the scop itself. |
| 368 | Loops.remove_if([this](const Loop *L) { |
| 369 | return this->S.getRegion().contains(L) || |
| 370 | L->contains(S.getRegion().getEntry()); |
| 371 | }); |
| 372 | } |
| 373 | |
| 374 | void IslNodeBuilder::updateValues( |
| 375 | ParallelLoopGenerator::ValueToValueMapTy &NewValues) { |
| 376 | SmallPtrSet<Value *, 5> Inserted; |
| 377 | |
| 378 | for (const auto &I : IDToValue) { |
| 379 | IDToValue[I.first] = NewValues[I.second]; |
| 380 | Inserted.insert(I.second); |
| 381 | } |
| 382 | |
| 383 | for (const auto &I : NewValues) { |
| 384 | if (Inserted.count(I.first)) |
| 385 | continue; |
| 386 | |
| 387 | ValueMap[I.first] = I.second; |
| 388 | } |
| 389 | } |
| 390 | |
Tobias Grosser | e602a07 | 2013-05-07 07:30:56 +0000 | [diff] [blame] | 391 | void IslNodeBuilder::createUserVector(__isl_take isl_ast_node *User, |
| 392 | std::vector<Value *> &IVS, |
| 393 | __isl_take isl_id *IteratorID, |
| 394 | __isl_take isl_union_map *Schedule) { |
Tobias Grosser | ce67a04 | 2014-07-02 16:26:47 +0000 | [diff] [blame] | 395 | isl_ast_expr *Expr = isl_ast_node_user_get_expr(User); |
| 396 | isl_ast_expr *StmtExpr = isl_ast_expr_get_op_arg(Expr, 0); |
| 397 | isl_id *Id = isl_ast_expr_get_id(StmtExpr); |
| 398 | isl_ast_expr_free(StmtExpr); |
Tobias Grosser | c14582f | 2013-02-05 18:01:29 +0000 | [diff] [blame] | 399 | ScopStmt *Stmt = (ScopStmt *)isl_id_get_user(Id); |
Sebastian Pop | 04c4ce3 | 2012-12-18 07:46:13 +0000 | [diff] [blame] | 400 | VectorValueMapT VectorMap(IVS.size()); |
Sebastian Pop | 9d10fff | 2013-02-15 20:55:59 +0000 | [diff] [blame] | 401 | std::vector<LoopToScevMapT> VLTS(IVS.size()); |
Sebastian Pop | 04c4ce3 | 2012-12-18 07:46:13 +0000 | [diff] [blame] | 402 | |
| 403 | isl_union_set *Domain = isl_union_set_from_set(Stmt->getDomain()); |
| 404 | Schedule = isl_union_map_intersect_domain(Schedule, Domain); |
| 405 | isl_map *S = isl_map_from_union_map(Schedule); |
| 406 | |
Tobias Grosser | ce67a04 | 2014-07-02 16:26:47 +0000 | [diff] [blame] | 407 | createSubstitutionsVector(Expr, Stmt, VectorMap, VLTS, IVS, IteratorID); |
Johannes Doerfert | 731685e | 2014-10-08 17:25:30 +0000 | [diff] [blame] | 408 | VectorBlockGenerator::generate(Builder, *Stmt, VectorMap, VLTS, S, P, LI, SE, |
| 409 | IslAstInfo::getBuild(User), &ExprBuilder); |
Sebastian Pop | 04c4ce3 | 2012-12-18 07:46:13 +0000 | [diff] [blame] | 410 | |
Sebastian Pop | 04c4ce3 | 2012-12-18 07:46:13 +0000 | [diff] [blame] | 411 | isl_map_free(S); |
Sebastian Pop | 04c4ce3 | 2012-12-18 07:46:13 +0000 | [diff] [blame] | 412 | isl_id_free(Id); |
| 413 | isl_ast_node_free(User); |
| 414 | } |
| 415 | |
Tobias Grosser | e602a07 | 2013-05-07 07:30:56 +0000 | [diff] [blame] | 416 | void IslNodeBuilder::createForVector(__isl_take isl_ast_node *For, |
| 417 | int VectorWidth) { |
Sebastian Pop | 04c4ce3 | 2012-12-18 07:46:13 +0000 | [diff] [blame] | 418 | isl_ast_node *Body = isl_ast_node_for_get_body(For); |
| 419 | isl_ast_expr *Init = isl_ast_node_for_get_init(For); |
| 420 | isl_ast_expr *Inc = isl_ast_node_for_get_inc(For); |
| 421 | isl_ast_expr *Iterator = isl_ast_node_for_get_iterator(For); |
| 422 | isl_id *IteratorID = isl_ast_expr_get_id(Iterator); |
Sebastian Pop | 04c4ce3 | 2012-12-18 07:46:13 +0000 | [diff] [blame] | 423 | |
| 424 | Value *ValueLB = ExprBuilder.create(Init); |
Sebastian Pop | 04c4ce3 | 2012-12-18 07:46:13 +0000 | [diff] [blame] | 425 | Value *ValueInc = ExprBuilder.create(Inc); |
| 426 | |
| 427 | Type *MaxType = ExprBuilder.getType(Iterator); |
| 428 | MaxType = ExprBuilder.getWidestType(MaxType, ValueLB->getType()); |
Sebastian Pop | 04c4ce3 | 2012-12-18 07:46:13 +0000 | [diff] [blame] | 429 | MaxType = ExprBuilder.getWidestType(MaxType, ValueInc->getType()); |
| 430 | |
| 431 | if (MaxType != ValueLB->getType()) |
| 432 | ValueLB = Builder.CreateSExt(ValueLB, MaxType); |
Sebastian Pop | 04c4ce3 | 2012-12-18 07:46:13 +0000 | [diff] [blame] | 433 | if (MaxType != ValueInc->getType()) |
| 434 | ValueInc = Builder.CreateSExt(ValueInc, MaxType); |
| 435 | |
Tobias Grosser | c14582f | 2013-02-05 18:01:29 +0000 | [diff] [blame] | 436 | std::vector<Value *> IVS(VectorWidth); |
Sebastian Pop | 04c4ce3 | 2012-12-18 07:46:13 +0000 | [diff] [blame] | 437 | IVS[0] = ValueLB; |
| 438 | |
| 439 | for (int i = 1; i < VectorWidth; i++) |
Tobias Grosser | c14582f | 2013-02-05 18:01:29 +0000 | [diff] [blame] | 440 | IVS[i] = Builder.CreateAdd(IVS[i - 1], ValueInc, "p_vector_iv"); |
Sebastian Pop | 04c4ce3 | 2012-12-18 07:46:13 +0000 | [diff] [blame] | 441 | |
Johannes Doerfert | 94d9082 | 2014-07-23 20:26:25 +0000 | [diff] [blame] | 442 | isl_union_map *Schedule = IslAstInfo::getSchedule(For); |
Sebastian Pop | 04c4ce3 | 2012-12-18 07:46:13 +0000 | [diff] [blame] | 443 | assert(Schedule && "For statement annotation does not contain its schedule"); |
| 444 | |
| 445 | IDToValue[IteratorID] = ValueLB; |
| 446 | |
| 447 | switch (isl_ast_node_get_type(Body)) { |
| 448 | case isl_ast_node_user: |
| 449 | createUserVector(Body, IVS, isl_id_copy(IteratorID), |
| 450 | isl_union_map_copy(Schedule)); |
| 451 | break; |
| 452 | case isl_ast_node_block: { |
| 453 | isl_ast_node_list *List = isl_ast_node_block_get_children(Body); |
| 454 | |
| 455 | for (int i = 0; i < isl_ast_node_list_n_ast_node(List); ++i) |
| 456 | createUserVector(isl_ast_node_list_get_ast_node(List, i), IVS, |
Tobias Grosser | 1bb59b0 | 2012-12-29 23:47:38 +0000 | [diff] [blame] | 457 | isl_id_copy(IteratorID), isl_union_map_copy(Schedule)); |
Sebastian Pop | 04c4ce3 | 2012-12-18 07:46:13 +0000 | [diff] [blame] | 458 | |
| 459 | isl_ast_node_free(Body); |
| 460 | isl_ast_node_list_free(List); |
| 461 | break; |
| 462 | } |
| 463 | default: |
| 464 | isl_ast_node_dump(Body); |
| 465 | llvm_unreachable("Unhandled isl_ast_node in vectorizer"); |
| 466 | } |
| 467 | |
Tobias Grosser | e3c0558 | 2014-11-15 21:32:53 +0000 | [diff] [blame^] | 468 | IDToValue.erase(IDToValue.find(IteratorID)); |
Sebastian Pop | 04c4ce3 | 2012-12-18 07:46:13 +0000 | [diff] [blame] | 469 | isl_id_free(IteratorID); |
Sebastian Pop | 04c4ce3 | 2012-12-18 07:46:13 +0000 | [diff] [blame] | 470 | isl_union_map_free(Schedule); |
| 471 | |
| 472 | isl_ast_node_free(For); |
| 473 | isl_ast_expr_free(Iterator); |
| 474 | } |
| 475 | |
| 476 | void IslNodeBuilder::createForSequential(__isl_take isl_ast_node *For) { |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 477 | isl_ast_node *Body; |
| 478 | isl_ast_expr *Init, *Inc, *Iterator, *UB; |
| 479 | isl_id *IteratorID; |
| 480 | Value *ValueLB, *ValueUB, *ValueInc; |
| 481 | Type *MaxType; |
Tobias Grosser | 5db6ffd | 2013-05-16 06:40:06 +0000 | [diff] [blame] | 482 | BasicBlock *ExitBlock; |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 483 | Value *IV; |
Tobias Grosser | c967d8e | 2012-10-16 07:29:13 +0000 | [diff] [blame] | 484 | CmpInst::Predicate Predicate; |
Tobias Grosser | 37c9b8e | 2014-03-04 14:59:00 +0000 | [diff] [blame] | 485 | bool Parallel; |
| 486 | |
Johannes Doerfert | c7b719f | 2014-10-01 20:10:44 +0000 | [diff] [blame] | 487 | Parallel = |
| 488 | IslAstInfo::isParallel(For) && !IslAstInfo::isReductionParallel(For); |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 489 | |
| 490 | Body = isl_ast_node_for_get_body(For); |
| 491 | |
| 492 | // isl_ast_node_for_is_degenerate(For) |
| 493 | // |
| 494 | // TODO: For degenerated loops we could generate a plain assignment. |
| 495 | // However, for now we just reuse the logic for normal loops, which will |
| 496 | // create a loop with a single iteration. |
| 497 | |
| 498 | Init = isl_ast_node_for_get_init(For); |
| 499 | Inc = isl_ast_node_for_get_inc(For); |
| 500 | Iterator = isl_ast_node_for_get_iterator(For); |
| 501 | IteratorID = isl_ast_expr_get_id(Iterator); |
Tobias Grosser | c967d8e | 2012-10-16 07:29:13 +0000 | [diff] [blame] | 502 | UB = getUpperBound(For, Predicate); |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 503 | |
| 504 | ValueLB = ExprBuilder.create(Init); |
| 505 | ValueUB = ExprBuilder.create(UB); |
| 506 | ValueInc = ExprBuilder.create(Inc); |
| 507 | |
| 508 | MaxType = ExprBuilder.getType(Iterator); |
| 509 | MaxType = ExprBuilder.getWidestType(MaxType, ValueLB->getType()); |
| 510 | MaxType = ExprBuilder.getWidestType(MaxType, ValueUB->getType()); |
| 511 | MaxType = ExprBuilder.getWidestType(MaxType, ValueInc->getType()); |
| 512 | |
| 513 | if (MaxType != ValueLB->getType()) |
| 514 | ValueLB = Builder.CreateSExt(ValueLB, MaxType); |
| 515 | if (MaxType != ValueUB->getType()) |
| 516 | ValueUB = Builder.CreateSExt(ValueUB, MaxType); |
| 517 | if (MaxType != ValueInc->getType()) |
| 518 | ValueInc = Builder.CreateSExt(ValueInc, MaxType); |
| 519 | |
Johannes Doerfert | dd5c144 | 2014-09-10 17:33:32 +0000 | [diff] [blame] | 520 | // If we can show that LB <Predicate> UB holds at least once, we can |
| 521 | // omit the GuardBB in front of the loop. |
| 522 | bool UseGuardBB = |
| 523 | !SE.isKnownPredicate(Predicate, SE.getSCEV(ValueLB), SE.getSCEV(ValueUB)); |
Johannes Doerfert | 2ef3f4f | 2014-08-07 17:14:54 +0000 | [diff] [blame] | 524 | IV = createLoop(ValueLB, ValueUB, ValueInc, Builder, P, LI, DT, ExitBlock, |
Johannes Doerfert | dd5c144 | 2014-09-10 17:33:32 +0000 | [diff] [blame] | 525 | Predicate, &Annotator, Parallel, UseGuardBB); |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 526 | IDToValue[IteratorID] = IV; |
| 527 | |
| 528 | create(Body); |
| 529 | |
Johannes Doerfert | c7b719f | 2014-10-01 20:10:44 +0000 | [diff] [blame] | 530 | Annotator.popLoop(Parallel); |
Tobias Grosser | 37c9b8e | 2014-03-04 14:59:00 +0000 | [diff] [blame] | 531 | |
Tobias Grosser | e3c0558 | 2014-11-15 21:32:53 +0000 | [diff] [blame^] | 532 | IDToValue.erase(IDToValue.find(IteratorID)); |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 533 | |
Tobias Grosser | 5db6ffd | 2013-05-16 06:40:06 +0000 | [diff] [blame] | 534 | Builder.SetInsertPoint(ExitBlock->begin()); |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 535 | |
| 536 | isl_ast_node_free(For); |
| 537 | isl_ast_expr_free(Iterator); |
| 538 | isl_id_free(IteratorID); |
| 539 | } |
| 540 | |
Tobias Grosser | e3c0558 | 2014-11-15 21:32:53 +0000 | [diff] [blame^] | 541 | /// @brief Remove the BBs contained in a (sub)function from the dominator tree. |
| 542 | /// |
| 543 | /// This function removes the basic blocks that are part of a subfunction from |
| 544 | /// the dominator tree. Specifically, when generating code it may happen that at |
| 545 | /// some point the code generation continues in a new sub-function (e.g., when |
| 546 | /// generating OpenMP code). The basic blocks that are created in this |
| 547 | /// sub-function are then still part of the dominator tree of the original |
| 548 | /// function, such that the dominator tree reaches over function boundaries. |
| 549 | /// This is not only incorrect, but also causes crashes. This function now |
| 550 | /// removes from the dominator tree all basic blocks that are dominated (and |
| 551 | /// consequently reachable) from the entry block of this (sub)function. |
| 552 | /// |
| 553 | /// FIXME: A LLVM (function or region) pass should not touch anything outside of |
| 554 | /// the function/region it runs on. Hence, the pure need for this function shows |
| 555 | /// that we do not comply to this rule. At the moment, this does not cause any |
| 556 | /// issues, but we should be aware that such issues may appear. Unfortunately |
| 557 | /// the current LLVM pass infrastructure does not allow to make Polly a module |
| 558 | /// or call-graph pass to solve this issue, as such a pass would not have access |
| 559 | /// to the per-function analyses passes needed by Polly. A future pass manager |
| 560 | /// infrastructure is supposed to enable such kind of access possibly allowing |
| 561 | /// us to create a cleaner solution here. |
| 562 | /// |
| 563 | /// FIXME: Instead of adding the dominance information and then dropping it |
| 564 | /// later on, we should try to just not add it in the first place. This requires |
| 565 | /// some careful testing to make sure this does not break in interaction with |
| 566 | /// the SCEVBuilder and SplitBlock which may rely on the dominator tree or |
| 567 | /// which may try to update it. |
| 568 | /// |
| 569 | /// @param F The function which contains the BBs to removed. |
| 570 | /// @param DT The dominator tree from which to remove the BBs. |
| 571 | static void removeSubFuncFromDomTree(Function *F, DominatorTree &DT) { |
| 572 | DomTreeNode *N = DT.getNode(&F->getEntryBlock()); |
| 573 | std::vector<BasicBlock *> Nodes; |
| 574 | |
| 575 | // We can only remove an element from the dominator tree, if all its children |
| 576 | // have been removed. To ensure this we obtain the list of nodes to remove |
| 577 | // using a post-order tree traversal. |
| 578 | for (po_iterator<DomTreeNode *> I = po_begin(N), E = po_end(N); I != E; ++I) |
| 579 | Nodes.push_back(I->getBlock()); |
| 580 | |
| 581 | for (BasicBlock *BB : Nodes) |
| 582 | DT.eraseNode(BB); |
| 583 | } |
| 584 | |
| 585 | void IslNodeBuilder::createForParallel(__isl_take isl_ast_node *For) { |
| 586 | isl_ast_node *Body; |
| 587 | isl_ast_expr *Init, *Inc, *Iterator, *UB; |
| 588 | isl_id *IteratorID; |
| 589 | Value *ValueLB, *ValueUB, *ValueInc; |
| 590 | Type *MaxType; |
| 591 | Value *IV; |
| 592 | CmpInst::Predicate Predicate; |
| 593 | |
| 594 | Body = isl_ast_node_for_get_body(For); |
| 595 | Init = isl_ast_node_for_get_init(For); |
| 596 | Inc = isl_ast_node_for_get_inc(For); |
| 597 | Iterator = isl_ast_node_for_get_iterator(For); |
| 598 | IteratorID = isl_ast_expr_get_id(Iterator); |
| 599 | UB = getUpperBound(For, Predicate); |
| 600 | |
| 601 | ValueLB = ExprBuilder.create(Init); |
| 602 | ValueUB = ExprBuilder.create(UB); |
| 603 | ValueInc = ExprBuilder.create(Inc); |
| 604 | |
| 605 | // OpenMP always uses SLE. In case the isl generated AST uses a SLT |
| 606 | // expression, we need to adjust the loop blound by one. |
| 607 | if (Predicate == CmpInst::ICMP_SLT) |
| 608 | ValueUB = Builder.CreateAdd( |
| 609 | ValueUB, Builder.CreateSExt(Builder.getTrue(), ValueUB->getType())); |
| 610 | |
| 611 | MaxType = ExprBuilder.getType(Iterator); |
| 612 | MaxType = ExprBuilder.getWidestType(MaxType, ValueLB->getType()); |
| 613 | MaxType = ExprBuilder.getWidestType(MaxType, ValueUB->getType()); |
| 614 | MaxType = ExprBuilder.getWidestType(MaxType, ValueInc->getType()); |
| 615 | |
| 616 | if (MaxType != ValueLB->getType()) |
| 617 | ValueLB = Builder.CreateSExt(ValueLB, MaxType); |
| 618 | if (MaxType != ValueUB->getType()) |
| 619 | ValueUB = Builder.CreateSExt(ValueUB, MaxType); |
| 620 | if (MaxType != ValueInc->getType()) |
| 621 | ValueInc = Builder.CreateSExt(ValueInc, MaxType); |
| 622 | |
| 623 | BasicBlock::iterator LoopBody; |
| 624 | |
| 625 | SetVector<Value *> SubtreeValues; |
| 626 | SetVector<const Loop *> Loops; |
| 627 | |
| 628 | getReferencesInSubtree(For, SubtreeValues, Loops); |
| 629 | |
| 630 | // Create for all loops we depend on values that contain the current loop |
| 631 | // iteration. These values are necessary to generate code for SCEVs that |
| 632 | // depend on such loops. As a result we need to pass them to the subfunction. |
| 633 | for (const Loop *L : Loops) { |
| 634 | const SCEV *OuterLIV = SE.getAddRecExpr(SE.getUnknown(Builder.getInt64(0)), |
| 635 | SE.getUnknown(Builder.getInt64(1)), |
| 636 | L, SCEV::FlagAnyWrap); |
| 637 | Value *V = generateSCEV(OuterLIV); |
| 638 | OutsideLoopIterations[L] = SE.getUnknown(V); |
| 639 | SubtreeValues.insert(V); |
| 640 | } |
| 641 | |
| 642 | ParallelLoopGenerator::ValueToValueMapTy NewValues; |
| 643 | ParallelLoopGenerator ParallelLoopGen(Builder, P, LI, DT, DL); |
| 644 | |
| 645 | IV = ParallelLoopGen.createParallelLoop(ValueLB, ValueUB, ValueInc, |
| 646 | SubtreeValues, NewValues, &LoopBody); |
| 647 | BasicBlock::iterator AfterLoop = Builder.GetInsertPoint(); |
| 648 | Builder.SetInsertPoint(LoopBody); |
| 649 | |
| 650 | // Save the current values. |
| 651 | ValueMapT ValueMapCopy = ValueMap; |
| 652 | IslExprBuilder::IDToValueTy IDToValueCopy = IDToValue; |
| 653 | |
| 654 | updateValues(NewValues); |
| 655 | IDToValue[IteratorID] = IV; |
| 656 | |
| 657 | create(Body); |
| 658 | |
| 659 | // Restore the original values. |
| 660 | ValueMap = ValueMapCopy; |
| 661 | IDToValue = IDToValueCopy; |
| 662 | |
| 663 | Builder.SetInsertPoint(AfterLoop); |
| 664 | removeSubFuncFromDomTree((*LoopBody).getParent()->getParent(), DT); |
| 665 | |
| 666 | for (const Loop *L : Loops) |
| 667 | OutsideLoopIterations.erase(L); |
| 668 | |
| 669 | isl_ast_node_free(For); |
| 670 | isl_ast_expr_free(Iterator); |
| 671 | isl_id_free(IteratorID); |
| 672 | } |
| 673 | |
Sebastian Pop | 04c4ce3 | 2012-12-18 07:46:13 +0000 | [diff] [blame] | 674 | void IslNodeBuilder::createFor(__isl_take isl_ast_node *For) { |
| 675 | bool Vector = PollyVectorizerChoice != VECTORIZER_NONE; |
| 676 | |
Johannes Doerfert | ed67f8b | 2014-08-01 08:14:28 +0000 | [diff] [blame] | 677 | if (Vector && IslAstInfo::isInnermostParallel(For) && |
| 678 | !IslAstInfo::isReductionParallel(For)) { |
Sebastian Pop | 04c4ce3 | 2012-12-18 07:46:13 +0000 | [diff] [blame] | 679 | int VectorWidth = getNumberOfIterations(For); |
| 680 | if (1 < VectorWidth && VectorWidth <= 16) { |
| 681 | createForVector(For, VectorWidth); |
| 682 | return; |
| 683 | } |
| 684 | } |
Tobias Grosser | e3c0558 | 2014-11-15 21:32:53 +0000 | [diff] [blame^] | 685 | |
| 686 | if (IslAstInfo::isExecutedInParallel(For)) { |
| 687 | createForParallel(For); |
| 688 | return; |
| 689 | } |
Sebastian Pop | 04c4ce3 | 2012-12-18 07:46:13 +0000 | [diff] [blame] | 690 | createForSequential(For); |
| 691 | } |
| 692 | |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 693 | void IslNodeBuilder::createIf(__isl_take isl_ast_node *If) { |
| 694 | isl_ast_expr *Cond = isl_ast_node_if_get_cond(If); |
| 695 | |
| 696 | Function *F = Builder.GetInsertBlock()->getParent(); |
| 697 | LLVMContext &Context = F->getContext(); |
| 698 | |
Tobias Grosser | c14582f | 2013-02-05 18:01:29 +0000 | [diff] [blame] | 699 | BasicBlock *CondBB = |
| 700 | SplitBlock(Builder.GetInsertBlock(), Builder.GetInsertPoint(), P); |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 701 | CondBB->setName("polly.cond"); |
| 702 | BasicBlock *MergeBB = SplitBlock(CondBB, CondBB->begin(), P); |
| 703 | MergeBB->setName("polly.merge"); |
| 704 | BasicBlock *ThenBB = BasicBlock::Create(Context, "polly.then", F); |
| 705 | BasicBlock *ElseBB = BasicBlock::Create(Context, "polly.else", F); |
| 706 | |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 707 | DT.addNewBlock(ThenBB, CondBB); |
| 708 | DT.addNewBlock(ElseBB, CondBB); |
| 709 | DT.changeImmediateDominator(MergeBB, CondBB); |
| 710 | |
Tobias Grosser | 3081b0f | 2013-05-16 06:40:24 +0000 | [diff] [blame] | 711 | Loop *L = LI.getLoopFor(CondBB); |
| 712 | if (L) { |
| 713 | L->addBasicBlockToLoop(ThenBB, LI.getBase()); |
| 714 | L->addBasicBlockToLoop(ElseBB, LI.getBase()); |
| 715 | } |
| 716 | |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 717 | CondBB->getTerminator()->eraseFromParent(); |
| 718 | |
| 719 | Builder.SetInsertPoint(CondBB); |
| 720 | Value *Predicate = ExprBuilder.create(Cond); |
| 721 | Builder.CreateCondBr(Predicate, ThenBB, ElseBB); |
| 722 | Builder.SetInsertPoint(ThenBB); |
| 723 | Builder.CreateBr(MergeBB); |
| 724 | Builder.SetInsertPoint(ElseBB); |
| 725 | Builder.CreateBr(MergeBB); |
| 726 | Builder.SetInsertPoint(ThenBB->begin()); |
| 727 | |
| 728 | create(isl_ast_node_if_get_then(If)); |
| 729 | |
| 730 | Builder.SetInsertPoint(ElseBB->begin()); |
| 731 | |
| 732 | if (isl_ast_node_if_has_else(If)) |
| 733 | create(isl_ast_node_if_get_else(If)); |
| 734 | |
| 735 | Builder.SetInsertPoint(MergeBB->begin()); |
| 736 | |
| 737 | isl_ast_node_free(If); |
| 738 | } |
| 739 | |
Tobias Grosser | ce67a04 | 2014-07-02 16:26:47 +0000 | [diff] [blame] | 740 | void IslNodeBuilder::createSubstitutions(isl_ast_expr *Expr, ScopStmt *Stmt, |
| 741 | ValueMapT &VMap, LoopToScevMapT <S) { |
| 742 | assert(isl_ast_expr_get_type(Expr) == isl_ast_expr_op && |
| 743 | "Expression of type 'op' expected"); |
| 744 | assert(isl_ast_expr_get_op_type(Expr) == isl_ast_op_call && |
| 745 | "Opertation of type 'call' expected"); |
| 746 | for (int i = 0; i < isl_ast_expr_get_op_n_arg(Expr) - 1; ++i) { |
| 747 | isl_ast_expr *SubExpr; |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 748 | Value *V; |
| 749 | |
Tobias Grosser | ce67a04 | 2014-07-02 16:26:47 +0000 | [diff] [blame] | 750 | SubExpr = isl_ast_expr_get_op_arg(Expr, i + 1); |
| 751 | V = ExprBuilder.create(SubExpr); |
Sebastian Pop | e039bb1 | 2013-03-18 19:09:49 +0000 | [diff] [blame] | 752 | ScalarEvolution *SE = Stmt->getParent()->getSE(); |
| 753 | LTS[Stmt->getLoopForDimension(i)] = SE->getUnknown(V); |
| 754 | |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 755 | // CreateIntCast can introduce trunc expressions. This is correct, as the |
| 756 | // result will always fit into the type of the original induction variable |
| 757 | // (because we calculate a value of the original induction variable). |
Sebastian Pop | e039bb1 | 2013-03-18 19:09:49 +0000 | [diff] [blame] | 758 | const Value *OldIV = Stmt->getInductionVariableForDimension(i); |
| 759 | if (OldIV) { |
| 760 | V = Builder.CreateIntCast(V, OldIV->getType(), true); |
| 761 | VMap[OldIV] = V; |
| 762 | } |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 763 | } |
| 764 | |
Tobias Grosser | e3c0558 | 2014-11-15 21:32:53 +0000 | [diff] [blame^] | 765 | // Add the current ValueMap to our per-statement value map. |
| 766 | // |
| 767 | // This is needed e.g. to rewrite array base addresses when moving code |
| 768 | // into a parallely executed subfunction. |
| 769 | VMap.insert(ValueMap.begin(), ValueMap.end()); |
| 770 | |
Tobias Grosser | ce67a04 | 2014-07-02 16:26:47 +0000 | [diff] [blame] | 771 | isl_ast_expr_free(Expr); |
Sebastian Pop | 04c4ce3 | 2012-12-18 07:46:13 +0000 | [diff] [blame] | 772 | } |
| 773 | |
Tobias Grosser | c14582f | 2013-02-05 18:01:29 +0000 | [diff] [blame] | 774 | void IslNodeBuilder::createSubstitutionsVector( |
Tobias Grosser | ce67a04 | 2014-07-02 16:26:47 +0000 | [diff] [blame] | 775 | __isl_take isl_ast_expr *Expr, ScopStmt *Stmt, VectorValueMapT &VMap, |
| 776 | std::vector<LoopToScevMapT> &VLTS, std::vector<Value *> &IVS, |
| 777 | __isl_take isl_id *IteratorID) { |
Sebastian Pop | 04c4ce3 | 2012-12-18 07:46:13 +0000 | [diff] [blame] | 778 | int i = 0; |
| 779 | |
| 780 | Value *OldValue = IDToValue[IteratorID]; |
Tobias Grosser | 91f5b26 | 2014-06-04 08:06:40 +0000 | [diff] [blame] | 781 | for (Value *IV : IVS) { |
| 782 | IDToValue[IteratorID] = IV; |
Tobias Grosser | ce67a04 | 2014-07-02 16:26:47 +0000 | [diff] [blame] | 783 | createSubstitutions(isl_ast_expr_copy(Expr), Stmt, VMap[i], VLTS[i]); |
Sebastian Pop | 04c4ce3 | 2012-12-18 07:46:13 +0000 | [diff] [blame] | 784 | i++; |
| 785 | } |
| 786 | |
| 787 | IDToValue[IteratorID] = OldValue; |
| 788 | isl_id_free(IteratorID); |
Tobias Grosser | ce67a04 | 2014-07-02 16:26:47 +0000 | [diff] [blame] | 789 | isl_ast_expr_free(Expr); |
Sebastian Pop | 04c4ce3 | 2012-12-18 07:46:13 +0000 | [diff] [blame] | 790 | } |
| 791 | |
| 792 | void IslNodeBuilder::createUser(__isl_take isl_ast_node *User) { |
| 793 | ValueMapT VMap; |
Sebastian Pop | 9d10fff | 2013-02-15 20:55:59 +0000 | [diff] [blame] | 794 | LoopToScevMapT LTS; |
Tobias Grosser | ce67a04 | 2014-07-02 16:26:47 +0000 | [diff] [blame] | 795 | isl_id *Id; |
Sebastian Pop | 04c4ce3 | 2012-12-18 07:46:13 +0000 | [diff] [blame] | 796 | ScopStmt *Stmt; |
| 797 | |
Tobias Grosser | ce67a04 | 2014-07-02 16:26:47 +0000 | [diff] [blame] | 798 | isl_ast_expr *Expr = isl_ast_node_user_get_expr(User); |
| 799 | isl_ast_expr *StmtExpr = isl_ast_expr_get_op_arg(Expr, 0); |
| 800 | Id = isl_ast_expr_get_id(StmtExpr); |
| 801 | isl_ast_expr_free(StmtExpr); |
Sebastian Pop | 04c4ce3 | 2012-12-18 07:46:13 +0000 | [diff] [blame] | 802 | |
Tobias Grosser | e3c0558 | 2014-11-15 21:32:53 +0000 | [diff] [blame^] | 803 | LTS.insert(OutsideLoopIterations.begin(), OutsideLoopIterations.end()); |
| 804 | |
Tobias Grosser | c14582f | 2013-02-05 18:01:29 +0000 | [diff] [blame] | 805 | Stmt = (ScopStmt *)isl_id_get_user(Id); |
Johannes Doerfert | a63b257 | 2014-08-03 01:51:59 +0000 | [diff] [blame] | 806 | |
Tobias Grosser | ce67a04 | 2014-07-02 16:26:47 +0000 | [diff] [blame] | 807 | createSubstitutions(Expr, Stmt, VMap, LTS); |
Johannes Doerfert | 2ef3f4f | 2014-08-07 17:14:54 +0000 | [diff] [blame] | 808 | BlockGenerator::generate(Builder, *Stmt, VMap, LTS, P, LI, SE, |
Johannes Doerfert | a63b257 | 2014-08-03 01:51:59 +0000 | [diff] [blame] | 809 | IslAstInfo::getBuild(User), &ExprBuilder); |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 810 | |
| 811 | isl_ast_node_free(User); |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 812 | isl_id_free(Id); |
| 813 | } |
| 814 | |
| 815 | void IslNodeBuilder::createBlock(__isl_take isl_ast_node *Block) { |
| 816 | isl_ast_node_list *List = isl_ast_node_block_get_children(Block); |
| 817 | |
| 818 | for (int i = 0; i < isl_ast_node_list_n_ast_node(List); ++i) |
| 819 | create(isl_ast_node_list_get_ast_node(List, i)); |
| 820 | |
| 821 | isl_ast_node_free(Block); |
| 822 | isl_ast_node_list_free(List); |
| 823 | } |
| 824 | |
| 825 | void IslNodeBuilder::create(__isl_take isl_ast_node *Node) { |
| 826 | switch (isl_ast_node_get_type(Node)) { |
| 827 | case isl_ast_node_error: |
| 828 | llvm_unreachable("code generation error"); |
| 829 | case isl_ast_node_for: |
| 830 | createFor(Node); |
| 831 | return; |
| 832 | case isl_ast_node_if: |
| 833 | createIf(Node); |
| 834 | return; |
| 835 | case isl_ast_node_user: |
| 836 | createUser(Node); |
| 837 | return; |
| 838 | case isl_ast_node_block: |
| 839 | createBlock(Node); |
| 840 | return; |
| 841 | } |
| 842 | |
| 843 | llvm_unreachable("Unknown isl_ast_node type"); |
| 844 | } |
| 845 | |
| 846 | void IslNodeBuilder::addParameters(__isl_take isl_set *Context) { |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 847 | |
| 848 | for (unsigned i = 0; i < isl_set_dim(Context, isl_dim_param); ++i) { |
| 849 | isl_id *Id; |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 850 | |
| 851 | Id = isl_set_get_dim_id(Context, isl_dim_param, i); |
Tobias Grosser | ec7d67e | 2014-11-06 00:27:01 +0000 | [diff] [blame] | 852 | IDToValue[Id] = generateSCEV((const SCEV *)isl_id_get_user(Id)); |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 853 | |
| 854 | isl_id_free(Id); |
| 855 | } |
| 856 | |
Tobias Grosser | e3c0558 | 2014-11-15 21:32:53 +0000 | [diff] [blame^] | 857 | // Generate values for the current loop iteration for all surrounding loops. |
| 858 | // |
| 859 | // We may also reference loops outside of the scop which do not contain the |
| 860 | // scop itself, but as the number of such scops may be arbitrarily large we do |
| 861 | // not generate code for them here, but only at the point of code generation |
| 862 | // where these values are needed. |
| 863 | Region &R = S.getRegion(); |
| 864 | Loop *L = LI.getLoopFor(R.getEntry()); |
| 865 | |
| 866 | while (L != nullptr && R.contains(L)) |
| 867 | L = L->getParentLoop(); |
| 868 | |
| 869 | while (L != nullptr) { |
| 870 | const SCEV *OuterLIV = SE.getAddRecExpr(SE.getUnknown(Builder.getInt64(0)), |
| 871 | SE.getUnknown(Builder.getInt64(1)), |
| 872 | L, SCEV::FlagAnyWrap); |
| 873 | Value *V = generateSCEV(OuterLIV); |
| 874 | OutsideLoopIterations[L] = SE.getUnknown(V); |
| 875 | L = L->getParentLoop(); |
| 876 | } |
| 877 | |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 878 | isl_set_free(Context); |
| 879 | } |
| 880 | |
Tobias Grosser | ec7d67e | 2014-11-06 00:27:01 +0000 | [diff] [blame] | 881 | Value *IslNodeBuilder::generateSCEV(const SCEV *Expr) { |
| 882 | Instruction *InsertLocation = --(Builder.GetInsertBlock()->end()); |
| 883 | return Rewriter->expandCodeFor(Expr, cast<IntegerType>(Expr->getType()), |
| 884 | InsertLocation); |
| 885 | } |
| 886 | |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 887 | namespace { |
| 888 | class IslCodeGeneration : public ScopPass { |
Tobias Grosser | 1bb59b0 | 2012-12-29 23:47:38 +0000 | [diff] [blame] | 889 | public: |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 890 | static char ID; |
| 891 | |
| 892 | IslCodeGeneration() : ScopPass(ID) {} |
| 893 | |
Tobias Grosser | e3c0558 | 2014-11-15 21:32:53 +0000 | [diff] [blame^] | 894 | /// @brief The datalayout used |
| 895 | const DataLayout *DL; |
| 896 | |
Johannes Doerfert | 3826224 | 2014-09-10 14:50:23 +0000 | [diff] [blame] | 897 | /// @name The analysis passes we need to generate code. |
| 898 | /// |
| 899 | ///{ |
| 900 | LoopInfo *LI; |
| 901 | IslAstInfo *AI; |
| 902 | DominatorTree *DT; |
| 903 | ScalarEvolution *SE; |
| 904 | ///} |
| 905 | |
| 906 | /// @brief The loop annotator to generate llvm.loop metadata. |
Johannes Doerfert | 51d1c74 | 2014-10-02 15:32:17 +0000 | [diff] [blame] | 907 | ScopAnnotator Annotator; |
Johannes Doerfert | 3826224 | 2014-09-10 14:50:23 +0000 | [diff] [blame] | 908 | |
| 909 | /// @brief Build the runtime condition. |
| 910 | /// |
| 911 | /// Build the condition that evaluates at run-time to true iff all |
| 912 | /// assumptions taken for the SCoP hold, and to false otherwise. |
| 913 | /// |
| 914 | /// @return A value evaluating to true/false if execution is save/unsafe. |
| 915 | Value *buildRTC(PollyIRBuilder &Builder, IslExprBuilder &ExprBuilder) { |
| 916 | Builder.SetInsertPoint(Builder.GetInsertBlock()->getTerminator()); |
| 917 | Value *RTC = ExprBuilder.create(AI->getRunCondition()); |
Johannes Doerfert | b164c79 | 2014-09-18 11:17:17 +0000 | [diff] [blame] | 918 | if (!RTC->getType()->isIntegerTy(1)) |
| 919 | RTC = Builder.CreateIsNotNull(RTC); |
| 920 | return RTC; |
Johannes Doerfert | 3826224 | 2014-09-10 14:50:23 +0000 | [diff] [blame] | 921 | } |
| 922 | |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 923 | bool runOnScop(Scop &S) { |
Johannes Doerfert | 3826224 | 2014-09-10 14:50:23 +0000 | [diff] [blame] | 924 | LI = &getAnalysis<LoopInfo>(); |
| 925 | AI = &getAnalysis<IslAstInfo>(); |
| 926 | DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree(); |
| 927 | SE = &getAnalysis<ScalarEvolution>(); |
Tobias Grosser | e3c0558 | 2014-11-15 21:32:53 +0000 | [diff] [blame^] | 928 | DL = &getAnalysis<DataLayoutPass>().getDataLayout(); |
Tobias Grosser | 0ee50f6 | 2013-04-10 06:55:31 +0000 | [diff] [blame] | 929 | |
Tobias Grosser | e602a07 | 2013-05-07 07:30:56 +0000 | [diff] [blame] | 930 | assert(!S.getRegion().isTopLevelRegion() && |
| 931 | "Top level regions are not supported"); |
Tobias Grosser | 0ee50f6 | 2013-04-10 06:55:31 +0000 | [diff] [blame] | 932 | |
Johannes Doerfert | ecdf263 | 2014-10-02 15:31:24 +0000 | [diff] [blame] | 933 | // Build the alias scopes for annotations first. |
| 934 | if (PollyAnnotateAliasScopes) |
| 935 | Annotator.buildAliasScopes(S); |
| 936 | |
Johannes Doerfert | 3826224 | 2014-09-10 14:50:23 +0000 | [diff] [blame] | 937 | BasicBlock *EnteringBB = simplifyRegion(&S, this); |
| 938 | PollyIRBuilder Builder = createPollyIRBuilder(EnteringBB, Annotator); |
Johannes Doerfert | 9744c4a | 2014-08-12 18:35:54 +0000 | [diff] [blame] | 939 | |
Tobias Grosser | e3c0558 | 2014-11-15 21:32:53 +0000 | [diff] [blame^] | 940 | IslNodeBuilder NodeBuilder(Builder, Annotator, this, *DL, *LI, *SE, *DT, S); |
Tobias Grosser | 2873594 | 2014-08-16 09:09:15 +0000 | [diff] [blame] | 941 | NodeBuilder.addParameters(S.getContext()); |
Johannes Doerfert | 3826224 | 2014-09-10 14:50:23 +0000 | [diff] [blame] | 942 | |
| 943 | Value *RTC = buildRTC(Builder, NodeBuilder.getExprBuilder()); |
| 944 | BasicBlock *StartBlock = executeScopConditionally(S, this, RTC); |
Tobias Grosser | 2873594 | 2014-08-16 09:09:15 +0000 | [diff] [blame] | 945 | Builder.SetInsertPoint(StartBlock->begin()); |
| 946 | |
Johannes Doerfert | 3826224 | 2014-09-10 14:50:23 +0000 | [diff] [blame] | 947 | NodeBuilder.create(AI->getAst()); |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 948 | return true; |
| 949 | } |
| 950 | |
Tobias Grosser | c14582f | 2013-02-05 18:01:29 +0000 | [diff] [blame] | 951 | virtual void printScop(raw_ostream &OS) const {} |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 952 | |
| 953 | virtual void getAnalysisUsage(AnalysisUsage &AU) const { |
Tobias Grosser | e3c0558 | 2014-11-15 21:32:53 +0000 | [diff] [blame^] | 954 | AU.addRequired<DataLayoutPass>(); |
Tobias Grosser | 42aff30 | 2014-01-13 22:29:56 +0000 | [diff] [blame] | 955 | AU.addRequired<DominatorTreeWrapperPass>(); |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 956 | AU.addRequired<IslAstInfo>(); |
Matt Arsenault | 8ca3681 | 2014-07-19 18:40:17 +0000 | [diff] [blame] | 957 | AU.addRequired<RegionInfoPass>(); |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 958 | AU.addRequired<ScalarEvolution>(); |
| 959 | AU.addRequired<ScopDetection>(); |
| 960 | AU.addRequired<ScopInfo>(); |
Tobias Grosser | ecfe21b | 2013-03-20 18:03:18 +0000 | [diff] [blame] | 961 | AU.addRequired<LoopInfo>(); |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 962 | |
| 963 | AU.addPreserved<Dependences>(); |
| 964 | |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 965 | AU.addPreserved<LoopInfo>(); |
Tobias Grosser | 42aff30 | 2014-01-13 22:29:56 +0000 | [diff] [blame] | 966 | AU.addPreserved<DominatorTreeWrapperPass>(); |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 967 | AU.addPreserved<IslAstInfo>(); |
| 968 | AU.addPreserved<ScopDetection>(); |
| 969 | AU.addPreserved<ScalarEvolution>(); |
| 970 | |
| 971 | // FIXME: We do not yet add regions for the newly generated code to the |
| 972 | // region tree. |
Matt Arsenault | 8ca3681 | 2014-07-19 18:40:17 +0000 | [diff] [blame] | 973 | AU.addPreserved<RegionInfoPass>(); |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 974 | AU.addPreserved<TempScopInfo>(); |
| 975 | AU.addPreserved<ScopInfo>(); |
| 976 | AU.addPreservedID(IndependentBlocksID); |
| 977 | } |
| 978 | }; |
| 979 | } |
| 980 | |
| 981 | char IslCodeGeneration::ID = 1; |
| 982 | |
Tobias Grosser | 7242ad9 | 2013-02-22 08:07:06 +0000 | [diff] [blame] | 983 | Pass *polly::createIslCodeGenerationPass() { return new IslCodeGeneration(); } |
Tobias Grosser | 8a5bc6e | 2012-10-02 19:50:43 +0000 | [diff] [blame] | 984 | |
Tobias Grosser | 7242ad9 | 2013-02-22 08:07:06 +0000 | [diff] [blame] | 985 | INITIALIZE_PASS_BEGIN(IslCodeGeneration, "polly-codegen-isl", |
| 986 | "Polly - Create LLVM-IR from SCoPs", false, false); |
| 987 | INITIALIZE_PASS_DEPENDENCY(Dependences); |
Tobias Grosser | 42aff30 | 2014-01-13 22:29:56 +0000 | [diff] [blame] | 988 | INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass); |
Tobias Grosser | 7242ad9 | 2013-02-22 08:07:06 +0000 | [diff] [blame] | 989 | INITIALIZE_PASS_DEPENDENCY(LoopInfo); |
Matt Arsenault | 8ca3681 | 2014-07-19 18:40:17 +0000 | [diff] [blame] | 990 | INITIALIZE_PASS_DEPENDENCY(RegionInfoPass); |
Tobias Grosser | 7242ad9 | 2013-02-22 08:07:06 +0000 | [diff] [blame] | 991 | INITIALIZE_PASS_DEPENDENCY(ScalarEvolution); |
| 992 | INITIALIZE_PASS_DEPENDENCY(ScopDetection); |
| 993 | INITIALIZE_PASS_END(IslCodeGeneration, "polly-codegen-isl", |
| 994 | "Polly - Create LLVM-IR from SCoPs", false, false) |