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