Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1 | //===------ CodeGeneration.cpp - Code generate the Scops. -----------------===// |
| 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 CodeGeneration pass takes a Scop created by ScopInfo and translates it |
| 11 | // back to LLVM-IR using Cloog. |
| 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. Cloog is used to generate an abstract syntax tree (clast) that |
| 16 | // reflects the updated execution order. This clast is used to create new |
| 17 | // LLVM-IR that is computational equivalent to the original control flow region, |
| 18 | // but executes its code in the new execution order defined by the changed |
| 19 | // scattering. |
| 20 | // |
| 21 | //===----------------------------------------------------------------------===// |
| 22 | |
Tobias Grosser | 0a91f32 | 2012-05-29 09:11:46 +0000 | [diff] [blame] | 23 | #include "polly/CodeGen/Cloog.h" |
Sebastian Pop | e1f6554 | 2012-05-07 16:35:11 +0000 | [diff] [blame] | 24 | #ifdef CLOOG_FOUND |
| 25 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 26 | #include "polly/Dependences.h" |
Tobias Grosser | bda1f8f | 2012-02-01 14:23:29 +0000 | [diff] [blame] | 27 | #include "polly/LinkAllPasses.h" |
Tobias Grosser | 637bd63 | 2013-05-07 07:31:10 +0000 | [diff] [blame] | 28 | #include "polly/Options.h" |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 29 | #include "polly/ScopInfo.h" |
| 30 | #include "polly/TempScopInfo.h" |
Hongbin Zheng | 8a84661 | 2012-04-25 13:18:28 +0000 | [diff] [blame] | 31 | #include "polly/CodeGen/CodeGeneration.h" |
| 32 | #include "polly/CodeGen/BlockGenerators.h" |
| 33 | #include "polly/CodeGen/LoopGenerators.h" |
Tobias Grosser | 6217e18 | 2012-08-03 12:50:07 +0000 | [diff] [blame] | 34 | #include "polly/CodeGen/PTXGenerator.h" |
Tobias Grosser | 3a275d2 | 2012-05-29 09:11:54 +0000 | [diff] [blame] | 35 | #include "polly/CodeGen/Utils.h" |
Hongbin Zheng | 3b11a16 | 2012-04-25 13:16:49 +0000 | [diff] [blame] | 36 | #include "polly/Support/GICHelper.h" |
Tobias Grosser | 0ee50f6 | 2013-04-10 06:55:31 +0000 | [diff] [blame] | 37 | #include "polly/Support/ScopHelper.h" |
Tobias Grosser | bda1f8f | 2012-02-01 14:23:29 +0000 | [diff] [blame] | 38 | |
Chandler Carruth | 535d52c | 2013-01-02 11:47:44 +0000 | [diff] [blame] | 39 | #include "llvm/IR/Module.h" |
Tobias Grosser | bda1f8f | 2012-02-01 14:23:29 +0000 | [diff] [blame] | 40 | #include "llvm/ADT/SetVector.h" |
Tobias Grosser | 900893d | 2012-03-29 13:10:26 +0000 | [diff] [blame] | 41 | #include "llvm/ADT/PostOrderIterator.h" |
Tobias Grosser | bda1f8f | 2012-02-01 14:23:29 +0000 | [diff] [blame] | 42 | #include "llvm/Analysis/LoopInfo.h" |
| 43 | #include "llvm/Analysis/ScalarEvolutionExpander.h" |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 44 | #include "llvm/Support/Debug.h" |
Chandler Carruth | 535d52c | 2013-01-02 11:47:44 +0000 | [diff] [blame] | 45 | #include "llvm/IR/DataLayout.h" |
Tobias Grosser | bda1f8f | 2012-02-01 14:23:29 +0000 | [diff] [blame] | 46 | #include "llvm/Transforms/Utils/BasicBlockUtils.h" |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 47 | |
| 48 | #define CLOOG_INT_GMP 1 |
| 49 | #include "cloog/cloog.h" |
| 50 | #include "cloog/isl/cloog.h" |
| 51 | |
Raghesh Aloor | a71989c | 2011-12-28 02:48:26 +0000 | [diff] [blame] | 52 | #include "isl/aff.h" |
| 53 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 54 | #include <vector> |
| 55 | #include <utility> |
| 56 | |
| 57 | using namespace polly; |
| 58 | using namespace llvm; |
| 59 | |
Chandler Carruth | 95fef94 | 2014-04-22 03:30:19 +0000 | [diff] [blame] | 60 | #define DEBUG_TYPE "polly-codegen" |
| 61 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 62 | struct isl_set; |
| 63 | |
| 64 | namespace polly { |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 65 | static cl::opt<bool> |
Tobias Grosser | 483a90d | 2014-07-09 10:50:10 +0000 | [diff] [blame] | 66 | OpenMP("enable-polly-openmp", cl::desc("Generate OpenMP parallel code"), |
| 67 | cl::value_desc("OpenMP code generation enabled if true"), |
| 68 | cl::init(false), cl::ZeroOrMore, cl::cat(PollyCategory)); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 69 | |
Tobias Grosser | 6217e18 | 2012-08-03 12:50:07 +0000 | [diff] [blame] | 70 | #ifdef GPU_CODEGEN |
| 71 | static cl::opt<bool> |
Tobias Grosser | 483a90d | 2014-07-09 10:50:10 +0000 | [diff] [blame] | 72 | GPGPU("enable-polly-gpgpu", cl::desc("Generate GPU parallel code"), |
| 73 | cl::Hidden, cl::value_desc("GPGPU code generation enabled if true"), |
| 74 | cl::init(false), cl::ZeroOrMore, cl::cat(PollyCategory)); |
Tobias Grosser | 6217e18 | 2012-08-03 12:50:07 +0000 | [diff] [blame] | 75 | |
Tobias Grosser | e602a07 | 2013-05-07 07:30:56 +0000 | [diff] [blame] | 76 | static cl::opt<std::string> |
Tobias Grosser | 483a90d | 2014-07-09 10:50:10 +0000 | [diff] [blame] | 77 | GPUTriple("polly-gpgpu-triple", |
| 78 | cl::desc("Target triple for GPU code generation"), cl::Hidden, |
| 79 | cl::init(""), cl::cat(PollyCategory)); |
Tobias Grosser | 6217e18 | 2012-08-03 12:50:07 +0000 | [diff] [blame] | 80 | #endif /* GPU_CODEGEN */ |
| 81 | |
Tobias Grosser | c14582f | 2013-02-05 18:01:29 +0000 | [diff] [blame] | 82 | typedef DenseMap<const char *, Value *> CharMapT; |
Tobias Grosser | 70e8cdb | 2012-01-24 16:42:21 +0000 | [diff] [blame] | 83 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 84 | /// Class to generate LLVM-IR that calculates the value of a clast_expr. |
| 85 | class ClastExpCodeGen { |
Tobias Grosser | 5103ba7 | 2014-03-04 14:58:49 +0000 | [diff] [blame] | 86 | PollyIRBuilder &Builder; |
Tobias Grosser | 5e8ffa8 | 2012-03-23 12:20:36 +0000 | [diff] [blame] | 87 | const CharMapT &IVS; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 88 | |
Tobias Grosser | bb137e3 | 2012-01-24 16:42:28 +0000 | [diff] [blame] | 89 | Value *codegen(const clast_name *e, Type *Ty); |
| 90 | Value *codegen(const clast_term *e, Type *Ty); |
| 91 | Value *codegen(const clast_binary *e, Type *Ty); |
| 92 | Value *codegen(const clast_reduction *r, Type *Ty); |
Tobias Grosser | d7e5864 | 2013-04-10 06:55:45 +0000 | [diff] [blame] | 93 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 94 | public: |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 95 | // A generator for clast expressions. |
| 96 | // |
| 97 | // @param B The IRBuilder that defines where the code to calculate the |
| 98 | // clast expressions should be inserted. |
| 99 | // @param IVMAP A Map that translates strings describing the induction |
| 100 | // variables to the Values* that represent these variables |
| 101 | // on the LLVM side. |
Tobias Grosser | 5103ba7 | 2014-03-04 14:58:49 +0000 | [diff] [blame] | 102 | ClastExpCodeGen(PollyIRBuilder &B, CharMapT &IVMap); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 103 | |
| 104 | // Generates code to calculate a given clast expression. |
| 105 | // |
| 106 | // @param e The expression to calculate. |
| 107 | // @return The Value that holds the result. |
Tobias Grosser | bb137e3 | 2012-01-24 16:42:28 +0000 | [diff] [blame] | 108 | Value *codegen(const clast_expr *e, Type *Ty); |
Tobias Grosser | bb137e3 | 2012-01-24 16:42:28 +0000 | [diff] [blame] | 109 | }; |
| 110 | |
| 111 | Value *ClastExpCodeGen::codegen(const clast_name *e, Type *Ty) { |
Tobias Grosser | 5e8ffa8 | 2012-03-23 12:20:36 +0000 | [diff] [blame] | 112 | CharMapT::const_iterator I = IVS.find(e->name); |
Tobias Grosser | bb137e3 | 2012-01-24 16:42:28 +0000 | [diff] [blame] | 113 | |
Tobias Grosser | 5e8ffa8 | 2012-03-23 12:20:36 +0000 | [diff] [blame] | 114 | assert(I != IVS.end() && "Clast name not found"); |
Tobias Grosser | bb137e3 | 2012-01-24 16:42:28 +0000 | [diff] [blame] | 115 | |
| 116 | return Builder.CreateSExtOrBitCast(I->second, Ty); |
| 117 | } |
| 118 | |
Sebastian Pop | bfec361 | 2014-02-22 02:15:39 +0000 | [diff] [blame] | 119 | static APInt APInt_from_MPZ(const mpz_t mpz) { |
Tobias Grosser | 5a56cbf | 2014-04-16 07:33:47 +0000 | [diff] [blame] | 120 | uint64_t *p = nullptr; |
Sebastian Pop | bfec361 | 2014-02-22 02:15:39 +0000 | [diff] [blame] | 121 | size_t sz; |
| 122 | |
| 123 | p = (uint64_t *)mpz_export(p, &sz, -1, sizeof(uint64_t), 0, 0, mpz); |
| 124 | |
| 125 | if (p) { |
| 126 | APInt A((unsigned)mpz_sizeinbase(mpz, 2), (unsigned)sz, p); |
| 127 | A = A.zext(A.getBitWidth() + 1); |
| 128 | free(p); |
| 129 | |
| 130 | if (mpz_sgn(mpz) == -1) |
| 131 | return -A; |
| 132 | else |
| 133 | return A; |
| 134 | } else { |
| 135 | uint64_t val = 0; |
| 136 | return APInt(1, 1, &val); |
| 137 | } |
| 138 | } |
| 139 | |
Tobias Grosser | bb137e3 | 2012-01-24 16:42:28 +0000 | [diff] [blame] | 140 | Value *ClastExpCodeGen::codegen(const clast_term *e, Type *Ty) { |
| 141 | APInt a = APInt_from_MPZ(e->val); |
| 142 | |
| 143 | Value *ConstOne = ConstantInt::get(Builder.getContext(), a); |
| 144 | ConstOne = Builder.CreateSExtOrBitCast(ConstOne, Ty); |
| 145 | |
| 146 | if (!e->var) |
| 147 | return ConstOne; |
| 148 | |
| 149 | Value *var = codegen(e->var, Ty); |
| 150 | return Builder.CreateMul(ConstOne, var); |
| 151 | } |
| 152 | |
| 153 | Value *ClastExpCodeGen::codegen(const clast_binary *e, Type *Ty) { |
| 154 | Value *LHS = codegen(e->LHS, Ty); |
| 155 | |
| 156 | APInt RHS_AP = APInt_from_MPZ(e->RHS); |
| 157 | |
| 158 | Value *RHS = ConstantInt::get(Builder.getContext(), RHS_AP); |
| 159 | RHS = Builder.CreateSExtOrBitCast(RHS, Ty); |
| 160 | |
| 161 | switch (e->type) { |
| 162 | case clast_bin_mod: |
| 163 | return Builder.CreateSRem(LHS, RHS); |
Tobias Grosser | c14582f | 2013-02-05 18:01:29 +0000 | [diff] [blame] | 164 | case clast_bin_fdiv: { |
| 165 | // floord(n,d) ((n < 0) ? (n - d + 1) : n) / d |
| 166 | Value *One = ConstantInt::get(Ty, 1); |
| 167 | Value *Zero = ConstantInt::get(Ty, 0); |
| 168 | Value *Sum1 = Builder.CreateSub(LHS, RHS); |
| 169 | Value *Sum2 = Builder.CreateAdd(Sum1, One); |
| 170 | Value *isNegative = Builder.CreateICmpSLT(LHS, Zero); |
| 171 | Value *Dividend = Builder.CreateSelect(isNegative, Sum2, LHS); |
| 172 | return Builder.CreateSDiv(Dividend, RHS); |
| 173 | } |
| 174 | case clast_bin_cdiv: { |
| 175 | // ceild(n,d) ((n < 0) ? n : (n + d - 1)) / d |
| 176 | Value *One = ConstantInt::get(Ty, 1); |
| 177 | Value *Zero = ConstantInt::get(Ty, 0); |
| 178 | Value *Sum1 = Builder.CreateAdd(LHS, RHS); |
| 179 | Value *Sum2 = Builder.CreateSub(Sum1, One); |
| 180 | Value *isNegative = Builder.CreateICmpSLT(LHS, Zero); |
| 181 | Value *Dividend = Builder.CreateSelect(isNegative, LHS, Sum2); |
| 182 | return Builder.CreateSDiv(Dividend, RHS); |
| 183 | } |
Tobias Grosser | bb137e3 | 2012-01-24 16:42:28 +0000 | [diff] [blame] | 184 | case clast_bin_div: |
| 185 | return Builder.CreateSDiv(LHS, RHS); |
Tobias Grosser | c14582f | 2013-02-05 18:01:29 +0000 | [diff] [blame] | 186 | } |
Tobias Grosser | bb137e3 | 2012-01-24 16:42:28 +0000 | [diff] [blame] | 187 | |
| 188 | llvm_unreachable("Unknown clast binary expression type"); |
| 189 | } |
| 190 | |
| 191 | Value *ClastExpCodeGen::codegen(const clast_reduction *r, Type *Ty) { |
Tobias Grosser | c14582f | 2013-02-05 18:01:29 +0000 | [diff] [blame] | 192 | assert((r->type == clast_red_min || r->type == clast_red_max || |
Tobias Grosser | 58032cb | 2013-06-23 01:29:29 +0000 | [diff] [blame] | 193 | r->type == clast_red_sum) && |
| 194 | "Clast reduction type not supported"); |
Tobias Grosser | bb137e3 | 2012-01-24 16:42:28 +0000 | [diff] [blame] | 195 | Value *old = codegen(r->elts[0], Ty); |
| 196 | |
Tobias Grosser | 1bb59b0 | 2012-12-29 23:47:38 +0000 | [diff] [blame] | 197 | for (int i = 1; i < r->n; ++i) { |
Tobias Grosser | bb137e3 | 2012-01-24 16:42:28 +0000 | [diff] [blame] | 198 | Value *exprValue = codegen(r->elts[i], Ty); |
| 199 | |
| 200 | switch (r->type) { |
Tobias Grosser | c14582f | 2013-02-05 18:01:29 +0000 | [diff] [blame] | 201 | case clast_red_min: { |
| 202 | Value *cmp = Builder.CreateICmpSLT(old, exprValue); |
| 203 | old = Builder.CreateSelect(cmp, old, exprValue); |
| 204 | break; |
| 205 | } |
| 206 | case clast_red_max: { |
| 207 | Value *cmp = Builder.CreateICmpSGT(old, exprValue); |
| 208 | old = Builder.CreateSelect(cmp, old, exprValue); |
| 209 | break; |
| 210 | } |
Tobias Grosser | bb137e3 | 2012-01-24 16:42:28 +0000 | [diff] [blame] | 211 | case clast_red_sum: |
| 212 | old = Builder.CreateAdd(old, exprValue); |
| 213 | break; |
Tobias Grosser | bb137e3 | 2012-01-24 16:42:28 +0000 | [diff] [blame] | 214 | } |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 215 | } |
| 216 | |
Tobias Grosser | bb137e3 | 2012-01-24 16:42:28 +0000 | [diff] [blame] | 217 | return old; |
| 218 | } |
| 219 | |
Tobias Grosser | 5103ba7 | 2014-03-04 14:58:49 +0000 | [diff] [blame] | 220 | ClastExpCodeGen::ClastExpCodeGen(PollyIRBuilder &B, CharMapT &IVMap) |
Tobias Grosser | 4d96c8d | 2013-03-23 01:05:07 +0000 | [diff] [blame] | 221 | : Builder(B), IVS(IVMap) {} |
Tobias Grosser | bb137e3 | 2012-01-24 16:42:28 +0000 | [diff] [blame] | 222 | |
| 223 | Value *ClastExpCodeGen::codegen(const clast_expr *e, Type *Ty) { |
Tobias Grosser | c14582f | 2013-02-05 18:01:29 +0000 | [diff] [blame] | 224 | switch (e->type) { |
Tobias Grosser | bb137e3 | 2012-01-24 16:42:28 +0000 | [diff] [blame] | 225 | case clast_expr_name: |
| 226 | return codegen((const clast_name *)e, Ty); |
| 227 | case clast_expr_term: |
| 228 | return codegen((const clast_term *)e, Ty); |
| 229 | case clast_expr_bin: |
| 230 | return codegen((const clast_binary *)e, Ty); |
| 231 | case clast_expr_red: |
| 232 | return codegen((const clast_reduction *)e, Ty); |
| 233 | } |
| 234 | |
| 235 | llvm_unreachable("Unknown clast expression!"); |
| 236 | } |
| 237 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 238 | class ClastStmtCodeGen { |
Tobias Grosser | f74a4cd | 2012-03-23 10:35:18 +0000 | [diff] [blame] | 239 | public: |
| 240 | const std::vector<std::string> &getParallelLoops(); |
| 241 | |
| 242 | private: |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 243 | // The Scop we code generate. |
| 244 | Scop *S; |
Tobias Grosser | 0ac9214 | 2012-02-14 14:02:27 +0000 | [diff] [blame] | 245 | Pass *P; |
Johannes Doerfert | c5129d8 | 2014-08-08 04:23:13 +0000 | [diff] [blame] | 246 | LoopInfo &LI; |
| 247 | ScalarEvolution &SE; |
| 248 | DominatorTree &DT; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 249 | |
| 250 | // The Builder specifies the current location to code generate at. |
Tobias Grosser | 5103ba7 | 2014-03-04 14:58:49 +0000 | [diff] [blame] | 251 | PollyIRBuilder &Builder; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 252 | |
| 253 | // Map the Values from the old code to their counterparts in the new code. |
| 254 | ValueMapT ValueMap; |
| 255 | |
Sebastian Pop | 9d10fff | 2013-02-15 20:55:59 +0000 | [diff] [blame] | 256 | // Map the loops from the old code to expressions function of the induction |
| 257 | // variables in the new code. For example, when the code generator produces |
| 258 | // this AST: |
| 259 | // |
| 260 | // for (int c1 = 0; c1 <= 1023; c1 += 1) |
| 261 | // for (int c2 = 0; c2 <= 1023; c2 += 1) |
| 262 | // Stmt(c2 + 3, c1); |
| 263 | // |
| 264 | // LoopToScev is a map associating: |
| 265 | // "outer loop in the old loop nest" -> SCEV("c2 + 3"), |
| 266 | // "inner loop in the old loop nest" -> SCEV("c1"). |
| 267 | LoopToScevMapT LoopToScev; |
| 268 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 269 | // clastVars maps from the textual representation of a clast variable to its |
| 270 | // current *Value. clast variables are scheduling variables, original |
| 271 | // induction variables or parameters. They are used either in loop bounds or |
| 272 | // to define the statement instance that is executed. |
| 273 | // |
| 274 | // for (s = 0; s < n + 3; ++i) |
| 275 | // for (t = s; t < m; ++j) |
| 276 | // Stmt(i = s + 3 * m, j = t); |
| 277 | // |
| 278 | // {s,t,i,j,n,m} is the set of clast variables in this clast. |
Tobias Grosser | 5e8ffa8 | 2012-03-23 12:20:36 +0000 | [diff] [blame] | 279 | CharMapT ClastVars; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 280 | |
| 281 | // Codegenerator for clast expressions. |
| 282 | ClastExpCodeGen ExpGen; |
| 283 | |
| 284 | // Do we currently generate parallel code? |
| 285 | bool parallelCodeGeneration; |
| 286 | |
| 287 | std::vector<std::string> parallelLoops; |
| 288 | |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 289 | void codegen(const clast_assignment *a); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 290 | |
Tobias Grosser | e602a07 | 2013-05-07 07:30:56 +0000 | [diff] [blame] | 291 | void codegen(const clast_assignment *a, ScopStmt *Statement, |
| 292 | unsigned Dimension, int vectorDim, |
| 293 | std::vector<ValueMapT> *VectorVMap = 0, |
| 294 | std::vector<LoopToScevMapT> *VLTS = 0); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 295 | |
Tobias Grosser | c14582f | 2013-02-05 18:01:29 +0000 | [diff] [blame] | 296 | void codegenSubstitutions(const clast_stmt *Assignment, ScopStmt *Statement, |
| 297 | int vectorDim = 0, |
Sebastian Pop | 9d10fff | 2013-02-15 20:55:59 +0000 | [diff] [blame] | 298 | std::vector<ValueMapT> *VectorVMap = 0, |
| 299 | std::vector<LoopToScevMapT> *VLTS = 0); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 300 | |
Tobias Grosser | 5a56cbf | 2014-04-16 07:33:47 +0000 | [diff] [blame] | 301 | void codegen(const clast_user_stmt *u, std::vector<Value *> *IVS = nullptr, |
| 302 | const char *iterator = nullptr, |
Tobias Grosser | 880c52f | 2013-07-29 01:58:07 +0000 | [diff] [blame] | 303 | __isl_take isl_set *scatteringDomain = 0); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 304 | |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 305 | void codegen(const clast_block *b); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 306 | |
| 307 | /// @brief Create a classical sequential loop. |
Tobias Grosser | f74a4cd | 2012-03-23 10:35:18 +0000 | [diff] [blame] | 308 | void codegenForSequential(const clast_for *f); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 309 | |
| 310 | /// @brief Create OpenMP structure values. |
| 311 | /// |
Tobias Grosser | f74a4cd | 2012-03-23 10:35:18 +0000 | [diff] [blame] | 312 | /// Create a list of values that has to be stored into the OpenMP subfuncition |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 313 | /// structure. |
Tobias Grosser | c14582f | 2013-02-05 18:01:29 +0000 | [diff] [blame] | 314 | SetVector<Value *> getOMPValues(const clast_stmt *Body); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 315 | |
Tobias Grosser | a17f666 | 2012-11-01 05:34:35 +0000 | [diff] [blame] | 316 | /// @brief Update ClastVars and ValueMap according to a value map. |
Tobias Grosser | 5e8ffa8 | 2012-03-23 12:20:36 +0000 | [diff] [blame] | 317 | /// |
Tobias Grosser | a17f666 | 2012-11-01 05:34:35 +0000 | [diff] [blame] | 318 | /// @param VMap A map from old to new values. |
| 319 | void updateWithValueMap(OMPGenerator::ValueToValueMapTy &VMap); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 320 | |
| 321 | /// @brief Create an OpenMP parallel for loop. |
| 322 | /// |
| 323 | /// This loop reflects a loop as if it would have been created by an OpenMP |
| 324 | /// statement. |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 325 | void codegenForOpenMP(const clast_for *f); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 326 | |
Tobias Grosser | 6217e18 | 2012-08-03 12:50:07 +0000 | [diff] [blame] | 327 | #ifdef GPU_CODEGEN |
| 328 | /// @brief Create GPGPU device memory access values. |
| 329 | /// |
| 330 | /// Create a list of values that will be set to be parameters of the GPGPU |
| 331 | /// subfunction. These parameters represent device memory base addresses |
| 332 | /// and the size in bytes. |
Tobias Grosser | c14582f | 2013-02-05 18:01:29 +0000 | [diff] [blame] | 333 | SetVector<Value *> getGPUValues(unsigned &OutputBytes); |
Tobias Grosser | 6217e18 | 2012-08-03 12:50:07 +0000 | [diff] [blame] | 334 | |
| 335 | /// @brief Create a GPU parallel for loop. |
| 336 | /// |
| 337 | /// This loop reflects a loop as if it would have been created by a GPU |
| 338 | /// statement. |
| 339 | void codegenForGPGPU(const clast_for *F); |
| 340 | |
| 341 | /// @brief Get innermost for loop. |
Tobias Grosser | e602a07 | 2013-05-07 07:30:56 +0000 | [diff] [blame] | 342 | const clast_stmt *getScheduleInfo(const clast_for *F, |
| 343 | std::vector<int> &NumIters, |
| 344 | unsigned &LoopDepth, |
| 345 | unsigned &NonPLoopDepth); |
Tobias Grosser | 6217e18 | 2012-08-03 12:50:07 +0000 | [diff] [blame] | 346 | #endif /* GPU_CODEGEN */ |
| 347 | |
Tobias Grosser | e192b23 | 2012-05-22 08:46:07 +0000 | [diff] [blame] | 348 | /// @brief Check if a loop is parallel |
| 349 | /// |
| 350 | /// Detect if a clast_for loop can be executed in parallel. |
| 351 | /// |
Tobias Grosser | c1b6cec | 2012-11-19 12:26:25 +0000 | [diff] [blame] | 352 | /// @param For The clast for loop to check. |
Tobias Grosser | e192b23 | 2012-05-22 08:46:07 +0000 | [diff] [blame] | 353 | /// |
| 354 | /// @return bool Returns true if the incoming clast_for statement can |
| 355 | /// execute in parallel. |
| 356 | bool isParallelFor(const clast_for *For); |
| 357 | |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 358 | bool isInnermostLoop(const clast_for *f); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 359 | |
| 360 | /// @brief Get the number of loop iterations for this loop. |
| 361 | /// @param f The clast for loop to check. |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 362 | int getNumberOfIterations(const clast_for *f); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 363 | |
| 364 | /// @brief Create vector instructions for this loop. |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 365 | void codegenForVector(const clast_for *f); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 366 | |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 367 | void codegen(const clast_for *f); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 368 | |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 369 | Value *codegen(const clast_equation *eq); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 370 | |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 371 | void codegen(const clast_guard *g); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 372 | |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 373 | void codegen(const clast_stmt *stmt); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 374 | |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 375 | void addParameters(const CloogNames *names); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 376 | |
Tobias Grosser | e9ffea2 | 2012-03-15 09:34:48 +0000 | [diff] [blame] | 377 | IntegerType *getIntPtrTy(); |
| 378 | |
Tobias Grosser | 1bb59b0 | 2012-12-29 23:47:38 +0000 | [diff] [blame] | 379 | public: |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 380 | void codegen(const clast_root *r); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 381 | |
Tobias Grosser | 5103ba7 | 2014-03-04 14:58:49 +0000 | [diff] [blame] | 382 | ClastStmtCodeGen(Scop *scop, PollyIRBuilder &B, Pass *P); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 383 | }; |
| 384 | } |
| 385 | |
Tobias Grosser | e9ffea2 | 2012-03-15 09:34:48 +0000 | [diff] [blame] | 386 | IntegerType *ClastStmtCodeGen::getIntPtrTy() { |
Rafael Espindola | c5d1689 | 2014-02-25 19:17:57 +0000 | [diff] [blame] | 387 | return P->getAnalysis<DataLayoutPass>().getDataLayout().getIntPtrType( |
| 388 | Builder.getContext()); |
Tobias Grosser | e9ffea2 | 2012-03-15 09:34:48 +0000 | [diff] [blame] | 389 | } |
| 390 | |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 391 | const std::vector<std::string> &ClastStmtCodeGen::getParallelLoops() { |
| 392 | return parallelLoops; |
| 393 | } |
| 394 | |
| 395 | void ClastStmtCodeGen::codegen(const clast_assignment *a) { |
Tobias Grosser | 1bb59b0 | 2012-12-29 23:47:38 +0000 | [diff] [blame] | 396 | Value *V = ExpGen.codegen(a->RHS, getIntPtrTy()); |
Tobias Grosser | 5e8ffa8 | 2012-03-23 12:20:36 +0000 | [diff] [blame] | 397 | ClastVars[a->LHS] = V; |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 398 | } |
| 399 | |
Tobias Grosser | e602a07 | 2013-05-07 07:30:56 +0000 | [diff] [blame] | 400 | void ClastStmtCodeGen::codegen(const clast_assignment *A, ScopStmt *Stmt, |
| 401 | unsigned Dim, int VectorDim, |
| 402 | std::vector<ValueMapT> *VectorVMap, |
| 403 | std::vector<LoopToScevMapT> *VLTS) { |
Tobias Grosser | f00bd96 | 2012-04-02 12:26:13 +0000 | [diff] [blame] | 404 | Value *RHS; |
| 405 | |
| 406 | assert(!A->LHS && "Statement assignments do not have left hand side"); |
| 407 | |
Tobias Grosser | 0905a23 | 2012-04-03 12:24:32 +0000 | [diff] [blame] | 408 | RHS = ExpGen.codegen(A->RHS, Builder.getInt64Ty()); |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 409 | |
Sebastian Pop | 9d10fff | 2013-02-15 20:55:59 +0000 | [diff] [blame] | 410 | const llvm::SCEV *URHS = S->getSE()->getUnknown(RHS); |
| 411 | if (VLTS) |
| 412 | (*VLTS)[VectorDim][Stmt->getLoopForDimension(Dim)] = URHS; |
Sebastian Pop | 9d10fff | 2013-02-15 20:55:59 +0000 | [diff] [blame] | 413 | LoopToScev[Stmt->getLoopForDimension(Dim)] = URHS; |
Sebastian Pop | e039bb1 | 2013-03-18 19:09:49 +0000 | [diff] [blame] | 414 | |
| 415 | const PHINode *PN = Stmt->getInductionVariableForDimension(Dim); |
| 416 | if (PN) { |
| 417 | RHS = Builder.CreateTruncOrBitCast(RHS, PN->getType()); |
| 418 | |
| 419 | if (VectorVMap) |
| 420 | (*VectorVMap)[VectorDim][PN] = RHS; |
| 421 | |
| 422 | ValueMap[PN] = RHS; |
| 423 | } |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 424 | } |
| 425 | |
Tobias Grosser | e602a07 | 2013-05-07 07:30:56 +0000 | [diff] [blame] | 426 | void ClastStmtCodeGen::codegenSubstitutions(const clast_stmt *Assignment, |
| 427 | ScopStmt *Statement, int vectorDim, |
| 428 | std::vector<ValueMapT> *VectorVMap, |
| 429 | std::vector<LoopToScevMapT> *VLTS) { |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 430 | int Dimension = 0; |
| 431 | |
| 432 | while (Assignment) { |
Tobias Grosser | ae2d83e | 2012-12-29 23:57:18 +0000 | [diff] [blame] | 433 | assert(CLAST_STMT_IS_A(Assignment, stmt_ass) && |
| 434 | "Substitions are expected to be assignments"); |
Tobias Grosser | c14582f | 2013-02-05 18:01:29 +0000 | [diff] [blame] | 435 | codegen((const clast_assignment *)Assignment, Statement, Dimension, |
Sebastian Pop | 9d10fff | 2013-02-15 20:55:59 +0000 | [diff] [blame] | 436 | vectorDim, VectorVMap, VLTS); |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 437 | Assignment = Assignment->next; |
| 438 | Dimension++; |
| 439 | } |
| 440 | } |
| 441 | |
Sebastian Pop | a00a029 | 2012-12-18 07:46:06 +0000 | [diff] [blame] | 442 | // Takes the cloog specific domain and translates it into a map Statement -> |
| 443 | // PartialSchedule, where the PartialSchedule contains all the dimensions that |
| 444 | // have been code generated up to this point. |
Tobias Grosser | e602a07 | 2013-05-07 07:30:56 +0000 | [diff] [blame] | 445 | static __isl_give isl_map *extractPartialSchedule(ScopStmt *Statement, |
Tobias Grosser | 880c52f | 2013-07-29 01:58:07 +0000 | [diff] [blame] | 446 | __isl_take isl_set *Domain) { |
Sebastian Pop | a00a029 | 2012-12-18 07:46:06 +0000 | [diff] [blame] | 447 | isl_map *Schedule = Statement->getScattering(); |
| 448 | int ScheduledDimensions = isl_set_dim(Domain, isl_dim_set); |
Tobias Grosser | c14582f | 2013-02-05 18:01:29 +0000 | [diff] [blame] | 449 | int UnscheduledDimensions = |
| 450 | isl_map_dim(Schedule, isl_dim_out) - ScheduledDimensions; |
Sebastian Pop | a00a029 | 2012-12-18 07:46:06 +0000 | [diff] [blame] | 451 | |
Tobias Grosser | 880c52f | 2013-07-29 01:58:07 +0000 | [diff] [blame] | 452 | isl_set_free(Domain); |
| 453 | |
Sebastian Pop | a00a029 | 2012-12-18 07:46:06 +0000 | [diff] [blame] | 454 | return isl_map_project_out(Schedule, isl_dim_out, ScheduledDimensions, |
| 455 | UnscheduledDimensions); |
| 456 | } |
| 457 | |
Tobias Grosser | e602a07 | 2013-05-07 07:30:56 +0000 | [diff] [blame] | 458 | void ClastStmtCodeGen::codegen(const clast_user_stmt *u, |
| 459 | std::vector<Value *> *IVS, const char *iterator, |
Tobias Grosser | 880c52f | 2013-07-29 01:58:07 +0000 | [diff] [blame] | 460 | __isl_take isl_set *Domain) { |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 461 | ScopStmt *Statement = (ScopStmt *)u->statement->usr; |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 462 | |
| 463 | if (u->substitutions) |
| 464 | codegenSubstitutions(u->substitutions, Statement); |
| 465 | |
Tobias Grosser | 80998e7 | 2012-03-02 11:27:28 +0000 | [diff] [blame] | 466 | int VectorDimensions = IVS ? IVS->size() : 1; |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 467 | |
Tobias Grosser | 80998e7 | 2012-03-02 11:27:28 +0000 | [diff] [blame] | 468 | if (VectorDimensions == 1) { |
Johannes Doerfert | c5129d8 | 2014-08-08 04:23:13 +0000 | [diff] [blame] | 469 | BlockGenerator::generate(Builder, *Statement, ValueMap, LoopToScev, P, LI, |
| 470 | SE); |
Tobias Grosser | efc3013 | 2014-04-14 08:33:24 +0000 | [diff] [blame] | 471 | isl_set_free(Domain); |
Tobias Grosser | 80998e7 | 2012-03-02 11:27:28 +0000 | [diff] [blame] | 472 | return; |
| 473 | } |
| 474 | |
| 475 | VectorValueMapT VectorMap(VectorDimensions); |
Sebastian Pop | 9d10fff | 2013-02-15 20:55:59 +0000 | [diff] [blame] | 476 | std::vector<LoopToScevMapT> VLTS(VectorDimensions); |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 477 | |
| 478 | if (IVS) { |
Tobias Grosser | 1bb59b0 | 2012-12-29 23:47:38 +0000 | [diff] [blame] | 479 | assert(u->substitutions && "Substitutions expected!"); |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 480 | int i = 0; |
Tobias Grosser | 1fee67d | 2014-08-31 16:10:31 +0000 | [diff] [blame] | 481 | for (Value *IV : *IVS) { |
| 482 | ClastVars[iterator] = IV; |
Sebastian Pop | 9d10fff | 2013-02-15 20:55:59 +0000 | [diff] [blame] | 483 | codegenSubstitutions(u->substitutions, Statement, i, &VectorMap, &VLTS); |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 484 | i++; |
| 485 | } |
| 486 | } |
| 487 | |
Tobias Grosser | 75b7672 | 2014-04-15 22:30:06 +0000 | [diff] [blame] | 488 | // Copy the current value map into all vector maps if the key wasn't |
| 489 | // available yet. This is needed in case vector codegen is performed in |
| 490 | // OpenMP subfunctions. |
Tobias Grosser | 0244ee8 | 2014-09-10 14:42:06 +0000 | [diff] [blame] | 491 | for (const auto &KV : ValueMap) |
Tobias Grosser | 75b7672 | 2014-04-15 22:30:06 +0000 | [diff] [blame] | 492 | for (int i = 0; i < VectorDimensions; ++i) |
| 493 | VectorMap[i].insert(KV); |
| 494 | |
Sebastian Pop | a00a029 | 2012-12-18 07:46:06 +0000 | [diff] [blame] | 495 | isl_map *Schedule = extractPartialSchedule(Statement, Domain); |
Sebastian Pop | 9d10fff | 2013-02-15 20:55:59 +0000 | [diff] [blame] | 496 | VectorBlockGenerator::generate(Builder, *Statement, VectorMap, VLTS, Schedule, |
Johannes Doerfert | c5129d8 | 2014-08-08 04:23:13 +0000 | [diff] [blame] | 497 | P, LI, SE); |
Sebastian Pop | a00a029 | 2012-12-18 07:46:06 +0000 | [diff] [blame] | 498 | isl_map_free(Schedule); |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | void ClastStmtCodeGen::codegen(const clast_block *b) { |
| 502 | if (b->body) |
| 503 | codegen(b->body); |
| 504 | } |
| 505 | |
Tobias Grosser | f74a4cd | 2012-03-23 10:35:18 +0000 | [diff] [blame] | 506 | void ClastStmtCodeGen::codegenForSequential(const clast_for *f) { |
| 507 | Value *LowerBound, *UpperBound, *IV, *Stride; |
Tobias Grosser | 5db6ffd | 2013-05-16 06:40:06 +0000 | [diff] [blame] | 508 | BasicBlock *ExitBlock; |
Tobias Grosser | e9ffea2 | 2012-03-15 09:34:48 +0000 | [diff] [blame] | 509 | Type *IntPtrTy = getIntPtrTy(); |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 510 | |
Tobias Grosser | f74a4cd | 2012-03-23 10:35:18 +0000 | [diff] [blame] | 511 | LowerBound = ExpGen.codegen(f->LB, IntPtrTy); |
| 512 | UpperBound = ExpGen.codegen(f->UB, IntPtrTy); |
| 513 | Stride = Builder.getInt(APInt_from_MPZ(f->stride)); |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 514 | |
Johannes Doerfert | c5129d8 | 2014-08-08 04:23:13 +0000 | [diff] [blame] | 515 | IV = createLoop(LowerBound, UpperBound, Stride, Builder, P, LI, DT, ExitBlock, |
Tobias Grosser | c967d8e | 2012-10-16 07:29:13 +0000 | [diff] [blame] | 516 | CmpInst::ICMP_SLE); |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 517 | |
| 518 | // Add loop iv to symbols. |
Tobias Grosser | 5e8ffa8 | 2012-03-23 12:20:36 +0000 | [diff] [blame] | 519 | ClastVars[f->iterator] = IV; |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 520 | |
| 521 | if (f->body) |
| 522 | codegen(f->body); |
| 523 | |
| 524 | // Loop is finished, so remove its iv from the live symbols. |
Tobias Grosser | 5e8ffa8 | 2012-03-23 12:20:36 +0000 | [diff] [blame] | 525 | ClastVars.erase(f->iterator); |
Tobias Grosser | 5db6ffd | 2013-05-16 06:40:06 +0000 | [diff] [blame] | 526 | Builder.SetInsertPoint(ExitBlock->begin()); |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 527 | } |
| 528 | |
Tobias Grosser | 177982c | 2012-11-01 05:34:48 +0000 | [diff] [blame] | 529 | // Helper class to determine all scalar parameters used in the basic blocks of a |
| 530 | // clast. Scalar parameters are scalar variables defined outside of the SCoP. |
| 531 | class ParameterVisitor : public ClastVisitor { |
| 532 | std::set<Value *> Values; |
Tobias Grosser | d7e5864 | 2013-04-10 06:55:45 +0000 | [diff] [blame] | 533 | |
Tobias Grosser | 177982c | 2012-11-01 05:34:48 +0000 | [diff] [blame] | 534 | public: |
Tobias Grosser | c14582f | 2013-02-05 18:01:29 +0000 | [diff] [blame] | 535 | ParameterVisitor() : ClastVisitor(), Values() {} |
Tobias Grosser | 177982c | 2012-11-01 05:34:48 +0000 | [diff] [blame] | 536 | |
| 537 | void visitUser(const clast_user_stmt *Stmt) { |
| 538 | const ScopStmt *S = static_cast<const ScopStmt *>(Stmt->statement->usr); |
| 539 | const BasicBlock *BB = S->getBasicBlock(); |
| 540 | |
| 541 | // Check all the operands of instructions in the basic block. |
Tobias Grosser | 083d3d3 | 2014-06-28 08:59:45 +0000 | [diff] [blame] | 542 | for (const Instruction &Inst : *BB) { |
| 543 | for (Value *SrcVal : Inst.operands()) { |
Tobias Grosser | 177982c | 2012-11-01 05:34:48 +0000 | [diff] [blame] | 544 | if (Instruction *OpInst = dyn_cast<Instruction>(SrcVal)) |
| 545 | if (S->getParent()->getRegion().contains(OpInst)) |
| 546 | continue; |
| 547 | |
| 548 | if (isa<Instruction>(SrcVal) || isa<Argument>(SrcVal)) |
| 549 | Values.insert(SrcVal); |
| 550 | } |
| 551 | } |
| 552 | } |
| 553 | |
| 554 | // Iterator to iterate over the values found. |
| 555 | typedef std::set<Value *>::const_iterator const_iterator; |
| 556 | inline const_iterator begin() const { return Values.begin(); } |
Tobias Grosser | c14582f | 2013-02-05 18:01:29 +0000 | [diff] [blame] | 557 | inline const_iterator end() const { return Values.end(); } |
Tobias Grosser | 177982c | 2012-11-01 05:34:48 +0000 | [diff] [blame] | 558 | }; |
| 559 | |
Tobias Grosser | c14582f | 2013-02-05 18:01:29 +0000 | [diff] [blame] | 560 | SetVector<Value *> ClastStmtCodeGen::getOMPValues(const clast_stmt *Body) { |
| 561 | SetVector<Value *> Values; |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 562 | |
Tobias Grosser | f74a4cd | 2012-03-23 10:35:18 +0000 | [diff] [blame] | 563 | // The clast variables |
Tobias Grosser | 0244ee8 | 2014-09-10 14:42:06 +0000 | [diff] [blame] | 564 | for (const auto &I : ClastVars) |
Tobias Grosser | 1fee67d | 2014-08-31 16:10:31 +0000 | [diff] [blame] | 565 | Values.insert(I.second); |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 566 | |
Tobias Grosser | 177982c | 2012-11-01 05:34:48 +0000 | [diff] [blame] | 567 | // Find the temporaries that are referenced in the clast statements' |
| 568 | // basic blocks but are not defined by these blocks (e.g., references |
| 569 | // to function arguments or temporaries defined before the start of |
| 570 | // the SCoP). |
| 571 | ParameterVisitor Params; |
| 572 | Params.visit(Body); |
| 573 | |
Tobias Grosser | 1fee67d | 2014-08-31 16:10:31 +0000 | [diff] [blame] | 574 | for (Value *V : Params) { |
Tobias Grosser | 177982c | 2012-11-01 05:34:48 +0000 | [diff] [blame] | 575 | Values.insert(V); |
| 576 | DEBUG(dbgs() << "Adding temporary for OMP copy-in: " << *V << "\n"); |
| 577 | } |
| 578 | |
Tobias Grosser | f74a4cd | 2012-03-23 10:35:18 +0000 | [diff] [blame] | 579 | return Values; |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 580 | } |
| 581 | |
Tobias Grosser | d7e5864 | 2013-04-10 06:55:45 +0000 | [diff] [blame] | 582 | void |
| 583 | ClastStmtCodeGen::updateWithValueMap(OMPGenerator::ValueToValueMapTy &VMap) { |
Tobias Grosser | c14582f | 2013-02-05 18:01:29 +0000 | [diff] [blame] | 584 | std::set<Value *> Inserted; |
Tobias Grosser | f74a4cd | 2012-03-23 10:35:18 +0000 | [diff] [blame] | 585 | |
Tobias Grosser | 0244ee8 | 2014-09-10 14:42:06 +0000 | [diff] [blame] | 586 | for (const auto &I : ClastVars) { |
Tobias Grosser | 1fee67d | 2014-08-31 16:10:31 +0000 | [diff] [blame] | 587 | ClastVars[I.first] = VMap[I.second]; |
| 588 | Inserted.insert(I.second); |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 589 | } |
| 590 | |
Tobias Grosser | 0244ee8 | 2014-09-10 14:42:06 +0000 | [diff] [blame] | 591 | for (const auto &I : VMap) { |
Tobias Grosser | 1fee67d | 2014-08-31 16:10:31 +0000 | [diff] [blame] | 592 | if (Inserted.count(I.first)) |
Tobias Grosser | f74a4cd | 2012-03-23 10:35:18 +0000 | [diff] [blame] | 593 | continue; |
| 594 | |
Tobias Grosser | 1fee67d | 2014-08-31 16:10:31 +0000 | [diff] [blame] | 595 | ValueMap[I.first] = I.second; |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 596 | } |
| 597 | } |
| 598 | |
Tobias Grosser | 900893d | 2012-03-29 13:10:26 +0000 | [diff] [blame] | 599 | static void clearDomtree(Function *F, DominatorTree &DT) { |
| 600 | DomTreeNode *N = DT.getNode(&F->getEntryBlock()); |
Tobias Grosser | c14582f | 2013-02-05 18:01:29 +0000 | [diff] [blame] | 601 | std::vector<BasicBlock *> Nodes; |
| 602 | for (po_iterator<DomTreeNode *> I = po_begin(N), E = po_end(N); I != E; ++I) |
Tobias Grosser | 900893d | 2012-03-29 13:10:26 +0000 | [diff] [blame] | 603 | Nodes.push_back(I->getBlock()); |
| 604 | |
Tobias Grosser | 1fee67d | 2014-08-31 16:10:31 +0000 | [diff] [blame] | 605 | for (BasicBlock *BB : Nodes) |
| 606 | DT.eraseNode(BB); |
Tobias Grosser | 900893d | 2012-03-29 13:10:26 +0000 | [diff] [blame] | 607 | } |
| 608 | |
Tobias Grosser | f74a4cd | 2012-03-23 10:35:18 +0000 | [diff] [blame] | 609 | void ClastStmtCodeGen::codegenForOpenMP(const clast_for *For) { |
Tobias Grosser | ebf3008 | 2012-03-23 12:20:32 +0000 | [diff] [blame] | 610 | Value *Stride, *LB, *UB, *IV; |
Tobias Grosser | f74a4cd | 2012-03-23 10:35:18 +0000 | [diff] [blame] | 611 | BasicBlock::iterator LoopBody; |
| 612 | IntegerType *IntPtrTy = getIntPtrTy(); |
Tobias Grosser | c14582f | 2013-02-05 18:01:29 +0000 | [diff] [blame] | 613 | SetVector<Value *> Values; |
Tobias Grosser | f74a4cd | 2012-03-23 10:35:18 +0000 | [diff] [blame] | 614 | OMPGenerator::ValueToValueMapTy VMap; |
| 615 | OMPGenerator OMPGen(Builder, P); |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 616 | |
Tobias Grosser | f74a4cd | 2012-03-23 10:35:18 +0000 | [diff] [blame] | 617 | Stride = Builder.getInt(APInt_from_MPZ(For->stride)); |
| 618 | Stride = Builder.CreateSExtOrBitCast(Stride, IntPtrTy); |
Tobias Grosser | ebf3008 | 2012-03-23 12:20:32 +0000 | [diff] [blame] | 619 | LB = ExpGen.codegen(For->LB, IntPtrTy); |
| 620 | UB = ExpGen.codegen(For->UB, IntPtrTy); |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 621 | |
Tobias Grosser | 177982c | 2012-11-01 05:34:48 +0000 | [diff] [blame] | 622 | Values = getOMPValues(For->body); |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 623 | |
Tobias Grosser | ebf3008 | 2012-03-23 12:20:32 +0000 | [diff] [blame] | 624 | IV = OMPGen.createParallelLoop(LB, UB, Stride, Values, VMap, &LoopBody); |
Tobias Grosser | f74a4cd | 2012-03-23 10:35:18 +0000 | [diff] [blame] | 625 | BasicBlock::iterator AfterLoop = Builder.GetInsertPoint(); |
| 626 | Builder.SetInsertPoint(LoopBody); |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 627 | |
Tobias Grosser | a17f666 | 2012-11-01 05:34:35 +0000 | [diff] [blame] | 628 | // Save the current values. |
| 629 | const ValueMapT ValueMapCopy = ValueMap; |
| 630 | const CharMapT ClastVarsCopy = ClastVars; |
| 631 | |
| 632 | updateWithValueMap(VMap); |
Tobias Grosser | 5e8ffa8 | 2012-03-23 12:20:36 +0000 | [diff] [blame] | 633 | ClastVars[For->iterator] = IV; |
Tobias Grosser | f74a4cd | 2012-03-23 10:35:18 +0000 | [diff] [blame] | 634 | |
| 635 | if (For->body) |
| 636 | codegen(For->body); |
| 637 | |
Tobias Grosser | a17f666 | 2012-11-01 05:34:35 +0000 | [diff] [blame] | 638 | // Restore the original values. |
| 639 | ValueMap = ValueMapCopy; |
| 640 | ClastVars = ClastVarsCopy; |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 641 | |
Tobias Grosser | 900893d | 2012-03-29 13:10:26 +0000 | [diff] [blame] | 642 | clearDomtree((*LoopBody).getParent()->getParent(), |
Tobias Grosser | 42aff30 | 2014-01-13 22:29:56 +0000 | [diff] [blame] | 643 | P->getAnalysis<DominatorTreeWrapperPass>().getDomTree()); |
Tobias Grosser | 900893d | 2012-03-29 13:10:26 +0000 | [diff] [blame] | 644 | |
Tobias Grosser | f74a4cd | 2012-03-23 10:35:18 +0000 | [diff] [blame] | 645 | Builder.SetInsertPoint(AfterLoop); |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 646 | } |
| 647 | |
Tobias Grosser | 6217e18 | 2012-08-03 12:50:07 +0000 | [diff] [blame] | 648 | #ifdef GPU_CODEGEN |
| 649 | static unsigned getArraySizeInBytes(const ArrayType *AT) { |
| 650 | unsigned Bytes = AT->getNumElements(); |
| 651 | if (const ArrayType *T = dyn_cast<ArrayType>(AT->getElementType())) |
| 652 | Bytes *= getArraySizeInBytes(T); |
| 653 | else |
| 654 | Bytes *= AT->getElementType()->getPrimitiveSizeInBits() / 8; |
| 655 | |
| 656 | return Bytes; |
| 657 | } |
| 658 | |
Tobias Grosser | c14582f | 2013-02-05 18:01:29 +0000 | [diff] [blame] | 659 | SetVector<Value *> ClastStmtCodeGen::getGPUValues(unsigned &OutputBytes) { |
| 660 | SetVector<Value *> Values; |
Tobias Grosser | 6217e18 | 2012-08-03 12:50:07 +0000 | [diff] [blame] | 661 | OutputBytes = 0; |
| 662 | |
| 663 | // Record the memory reference base addresses. |
Tobias Grosser | 868832b | 2014-06-19 16:45:04 +0000 | [diff] [blame] | 664 | for (ScopStmt *Stmt : *S) { |
| 665 | for (MemoryAccess *MA : *Stmt) { |
Johannes Doerfert | d9e1dbd3 | 2014-07-29 08:36:18 +0000 | [diff] [blame] | 666 | Value *BaseAddr = MA->getBaseAddr(); |
Tobias Grosser | 6217e18 | 2012-08-03 12:50:07 +0000 | [diff] [blame] | 667 | Values.insert((BaseAddr)); |
| 668 | |
| 669 | // FIXME: we assume that there is one and only one array to be written |
| 670 | // in a SCoP. |
| 671 | int NumWrites = 0; |
Tobias Grosser | 868832b | 2014-06-19 16:45:04 +0000 | [diff] [blame] | 672 | if (MA->isWrite()) { |
Tobias Grosser | 6217e18 | 2012-08-03 12:50:07 +0000 | [diff] [blame] | 673 | ++NumWrites; |
| 674 | assert(NumWrites <= 1 && |
| 675 | "We support at most one array to be written in a SCoP."); |
Tobias Grosser | c14582f | 2013-02-05 18:01:29 +0000 | [diff] [blame] | 676 | if (const PointerType *PT = |
| 677 | dyn_cast<PointerType>(BaseAddr->getType())) { |
Tobias Grosser | 6217e18 | 2012-08-03 12:50:07 +0000 | [diff] [blame] | 678 | Type *T = PT->getArrayElementType(); |
| 679 | const ArrayType *ATy = dyn_cast<ArrayType>(T); |
| 680 | OutputBytes = getArraySizeInBytes(ATy); |
| 681 | } |
| 682 | } |
| 683 | } |
| 684 | } |
| 685 | |
| 686 | return Values; |
| 687 | } |
| 688 | |
Tobias Grosser | e602a07 | 2013-05-07 07:30:56 +0000 | [diff] [blame] | 689 | const clast_stmt *ClastStmtCodeGen::getScheduleInfo(const clast_for *F, |
| 690 | std::vector<int> &NumIters, |
| 691 | unsigned &LoopDepth, |
| 692 | unsigned &NonPLoopDepth) { |
Tobias Grosser | 6217e18 | 2012-08-03 12:50:07 +0000 | [diff] [blame] | 693 | clast_stmt *Stmt = (clast_stmt *)F; |
| 694 | const clast_for *Result; |
| 695 | bool NonParaFlag = false; |
| 696 | LoopDepth = 0; |
| 697 | NonPLoopDepth = 0; |
| 698 | |
| 699 | while (Stmt) { |
| 700 | if (CLAST_STMT_IS_A(Stmt, stmt_for)) { |
Tobias Grosser | c14582f | 2013-02-05 18:01:29 +0000 | [diff] [blame] | 701 | const clast_for *T = (clast_for *)Stmt; |
Tobias Grosser | 6217e18 | 2012-08-03 12:50:07 +0000 | [diff] [blame] | 702 | if (isParallelFor(T)) { |
| 703 | if (!NonParaFlag) { |
| 704 | NumIters.push_back(getNumberOfIterations(T)); |
| 705 | Result = T; |
| 706 | } |
| 707 | } else |
| 708 | NonParaFlag = true; |
| 709 | |
| 710 | Stmt = T->body; |
| 711 | LoopDepth++; |
| 712 | continue; |
| 713 | } |
| 714 | Stmt = Stmt->next; |
| 715 | } |
| 716 | |
| 717 | assert(NumIters.size() == 4 && |
| 718 | "The loops should be tiled into 4-depth parallel loops and an " |
| 719 | "innermost non-parallel one (if exist)."); |
| 720 | NonPLoopDepth = LoopDepth - NumIters.size(); |
Tobias Grosser | c14582f | 2013-02-05 18:01:29 +0000 | [diff] [blame] | 721 | assert(NonPLoopDepth <= 1 && |
| 722 | "We support only one innermost non-parallel loop currently."); |
Tobias Grosser | 6217e18 | 2012-08-03 12:50:07 +0000 | [diff] [blame] | 723 | return (const clast_stmt *)Result->body; |
| 724 | } |
| 725 | |
| 726 | void ClastStmtCodeGen::codegenForGPGPU(const clast_for *F) { |
| 727 | BasicBlock::iterator LoopBody; |
| 728 | SetVector<Value *> Values; |
| 729 | SetVector<Value *> IVS; |
| 730 | std::vector<int> NumIterations; |
| 731 | PTXGenerator::ValueToValueMapTy VMap; |
| 732 | |
Tobias Grosser | ae2d83e | 2012-12-29 23:57:18 +0000 | [diff] [blame] | 733 | assert(!GPUTriple.empty() && |
| 734 | "Target triple should be set properly for GPGPU code generation."); |
Tobias Grosser | 6217e18 | 2012-08-03 12:50:07 +0000 | [diff] [blame] | 735 | PTXGenerator PTXGen(Builder, P, GPUTriple); |
| 736 | |
| 737 | // Get original IVS and ScopStmt |
| 738 | unsigned TiledLoopDepth, NonPLoopDepth; |
Tobias Grosser | c14582f | 2013-02-05 18:01:29 +0000 | [diff] [blame] | 739 | const clast_stmt *InnerStmt = |
| 740 | getScheduleInfo(F, NumIterations, TiledLoopDepth, NonPLoopDepth); |
Tobias Grosser | 6217e18 | 2012-08-03 12:50:07 +0000 | [diff] [blame] | 741 | const clast_stmt *TmpStmt; |
| 742 | const clast_user_stmt *U; |
| 743 | const clast_for *InnerFor; |
| 744 | if (CLAST_STMT_IS_A(InnerStmt, stmt_for)) { |
| 745 | InnerFor = (const clast_for *)InnerStmt; |
| 746 | TmpStmt = InnerFor->body; |
| 747 | } else |
| 748 | TmpStmt = InnerStmt; |
Tobias Grosser | c14582f | 2013-02-05 18:01:29 +0000 | [diff] [blame] | 749 | U = (const clast_user_stmt *)TmpStmt; |
| 750 | ScopStmt *Statement = (ScopStmt *)U->statement->usr; |
Tobias Grosser | 6217e18 | 2012-08-03 12:50:07 +0000 | [diff] [blame] | 751 | for (unsigned i = 0; i < Statement->getNumIterators() - NonPLoopDepth; i++) { |
Tobias Grosser | 1bb59b0 | 2012-12-29 23:47:38 +0000 | [diff] [blame] | 752 | const Value *IV = Statement->getInductionVariableForDimension(i); |
Tobias Grosser | 6217e18 | 2012-08-03 12:50:07 +0000 | [diff] [blame] | 753 | IVS.insert(const_cast<Value *>(IV)); |
| 754 | } |
| 755 | |
| 756 | unsigned OutBytes; |
| 757 | Values = getGPUValues(OutBytes); |
| 758 | PTXGen.setOutputBytes(OutBytes); |
| 759 | PTXGen.startGeneration(Values, IVS, VMap, &LoopBody); |
| 760 | |
| 761 | BasicBlock::iterator AfterLoop = Builder.GetInsertPoint(); |
| 762 | Builder.SetInsertPoint(LoopBody); |
| 763 | |
| 764 | BasicBlock *AfterBB = 0; |
| 765 | if (NonPLoopDepth) { |
| 766 | Value *LowerBound, *UpperBound, *IV, *Stride; |
| 767 | Type *IntPtrTy = getIntPtrTy(); |
| 768 | LowerBound = ExpGen.codegen(InnerFor->LB, IntPtrTy); |
| 769 | UpperBound = ExpGen.codegen(InnerFor->UB, IntPtrTy); |
| 770 | Stride = Builder.getInt(APInt_from_MPZ(InnerFor->stride)); |
Johannes Doerfert | c5129d8 | 2014-08-08 04:23:13 +0000 | [diff] [blame] | 771 | IV = createLoop(LowerBound, UpperBound, Stride, Builder, P, LI, DT, AfterBB, |
Tobias Grosser | 6f3d063 | 2012-11-30 00:39:49 +0000 | [diff] [blame] | 772 | CmpInst::ICMP_SLE); |
Tobias Grosser | 6217e18 | 2012-08-03 12:50:07 +0000 | [diff] [blame] | 773 | const Value *OldIV_ = Statement->getInductionVariableForDimension(2); |
| 774 | Value *OldIV = const_cast<Value *>(OldIV_); |
Tobias Grosser | ba1724d | 2014-05-07 10:06:33 +0000 | [diff] [blame] | 775 | VMap.insert(std::make_pair(OldIV, IV)); |
Tobias Grosser | 6217e18 | 2012-08-03 12:50:07 +0000 | [diff] [blame] | 776 | } |
| 777 | |
Tobias Grosser | 46c6abb | 2012-11-30 01:05:05 +0000 | [diff] [blame] | 778 | updateWithValueMap(VMap); |
Tobias Grosser | a17f666 | 2012-11-01 05:34:35 +0000 | [diff] [blame] | 779 | |
Johannes Doerfert | c5129d8 | 2014-08-08 04:23:13 +0000 | [diff] [blame] | 780 | BlockGenerator::generate(Builder, *Statement, ValueMap, LoopToScev, P, LI, |
| 781 | SE); |
Tobias Grosser | a17f666 | 2012-11-01 05:34:35 +0000 | [diff] [blame] | 782 | |
Tobias Grosser | 6217e18 | 2012-08-03 12:50:07 +0000 | [diff] [blame] | 783 | if (AfterBB) |
| 784 | Builder.SetInsertPoint(AfterBB->begin()); |
| 785 | |
| 786 | // FIXME: The replacement of the host base address with the parameter of ptx |
| 787 | // subfunction should have been done by updateWithValueMap. We use the |
| 788 | // following codes to avoid affecting other parts of Polly. This should be |
| 789 | // fixed later. |
| 790 | Function *FN = Builder.GetInsertBlock()->getParent(); |
Tobias Grosser | 1fee67d | 2014-08-31 16:10:31 +0000 | [diff] [blame] | 791 | for (Value *BaseAddr : Values) |
Tobias Grosser | 6a4d3f7 | 2014-08-31 16:21:20 +0000 | [diff] [blame] | 792 | for (BasicBlock *BB : *FN) |
Tobias Grosser | 1fee67d | 2014-08-31 16:10:31 +0000 | [diff] [blame] | 793 | for (Instruction *Inst : *BB) |
| 794 | Inst->replaceUsesOfWith(BaseAddr, ValueMap[BaseAddr]); |
Tobias Grosser | 6217e18 | 2012-08-03 12:50:07 +0000 | [diff] [blame] | 795 | Builder.SetInsertPoint(AfterLoop); |
| 796 | PTXGen.setLaunchingParameters(NumIterations[0], NumIterations[1], |
| 797 | NumIterations[2], NumIterations[3]); |
| 798 | PTXGen.finishGeneration(FN); |
| 799 | } |
| 800 | #endif |
| 801 | |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 802 | bool ClastStmtCodeGen::isInnermostLoop(const clast_for *f) { |
| 803 | const clast_stmt *stmt = f->body; |
| 804 | |
| 805 | while (stmt) { |
| 806 | if (!CLAST_STMT_IS_A(stmt, stmt_user)) |
| 807 | return false; |
| 808 | |
| 809 | stmt = stmt->next; |
| 810 | } |
| 811 | |
| 812 | return true; |
| 813 | } |
| 814 | |
Sebastian Pop | 04c4ce3 | 2012-12-18 07:46:13 +0000 | [diff] [blame] | 815 | int ClastStmtCodeGen::getNumberOfIterations(const clast_for *For) { |
| 816 | isl_set *LoopDomain = isl_set_copy(isl_set_from_cloog_domain(For->domain)); |
Sebastian Pop | 2aa5c24 | 2012-12-18 08:56:51 +0000 | [diff] [blame] | 817 | int NumberOfIterations = polly::getNumberOfIterations(LoopDomain); |
| 818 | if (NumberOfIterations == -1) |
| 819 | return -1; |
Tobias Grosser | b8cd4a8 | 2014-01-19 11:31:23 +0000 | [diff] [blame] | 820 | return NumberOfIterations / mpz_get_si(For->stride) + 1; |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 821 | } |
| 822 | |
Tobias Grosser | 2da263e | 2012-03-15 09:34:55 +0000 | [diff] [blame] | 823 | void ClastStmtCodeGen::codegenForVector(const clast_for *F) { |
| 824 | DEBUG(dbgs() << "Vectorizing loop '" << F->iterator << "'\n";); |
| 825 | int VectorWidth = getNumberOfIterations(F); |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 826 | |
Tobias Grosser | 2da263e | 2012-03-15 09:34:55 +0000 | [diff] [blame] | 827 | Value *LB = ExpGen.codegen(F->LB, getIntPtrTy()); |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 828 | |
Tobias Grosser | 2da263e | 2012-03-15 09:34:55 +0000 | [diff] [blame] | 829 | APInt Stride = APInt_from_MPZ(F->stride); |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 830 | IntegerType *LoopIVType = dyn_cast<IntegerType>(LB->getType()); |
Tobias Grosser | 1bb59b0 | 2012-12-29 23:47:38 +0000 | [diff] [blame] | 831 | Stride = Stride.zext(LoopIVType->getBitWidth()); |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 832 | Value *StrideValue = ConstantInt::get(LoopIVType, Stride); |
| 833 | |
Tobias Grosser | c14582f | 2013-02-05 18:01:29 +0000 | [diff] [blame] | 834 | std::vector<Value *> IVS(VectorWidth); |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 835 | IVS[0] = LB; |
| 836 | |
Tobias Grosser | 2da263e | 2012-03-15 09:34:55 +0000 | [diff] [blame] | 837 | for (int i = 1; i < VectorWidth; i++) |
Tobias Grosser | c14582f | 2013-02-05 18:01:29 +0000 | [diff] [blame] | 838 | IVS[i] = Builder.CreateAdd(IVS[i - 1], StrideValue, "p_vector_iv"); |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 839 | |
Tobias Grosser | 880c52f | 2013-07-29 01:58:07 +0000 | [diff] [blame] | 840 | isl_set *Domain = isl_set_copy(isl_set_from_cloog_domain(F->domain)); |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 841 | |
| 842 | // Add loop iv to symbols. |
Tobias Grosser | 5e8ffa8 | 2012-03-23 12:20:36 +0000 | [diff] [blame] | 843 | ClastVars[F->iterator] = LB; |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 844 | |
Tobias Grosser | 2da263e | 2012-03-15 09:34:55 +0000 | [diff] [blame] | 845 | const clast_stmt *Stmt = F->body; |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 846 | |
Tobias Grosser | 2da263e | 2012-03-15 09:34:55 +0000 | [diff] [blame] | 847 | while (Stmt) { |
Tobias Grosser | 00d898d | 2012-03-15 09:34:58 +0000 | [diff] [blame] | 848 | codegen((const clast_user_stmt *)Stmt, &IVS, F->iterator, |
| 849 | isl_set_copy(Domain)); |
Tobias Grosser | 2da263e | 2012-03-15 09:34:55 +0000 | [diff] [blame] | 850 | Stmt = Stmt->next; |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | // Loop is finished, so remove its iv from the live symbols. |
Tobias Grosser | 00d898d | 2012-03-15 09:34:58 +0000 | [diff] [blame] | 854 | isl_set_free(Domain); |
Tobias Grosser | 5e8ffa8 | 2012-03-23 12:20:36 +0000 | [diff] [blame] | 855 | ClastVars.erase(F->iterator); |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 856 | } |
| 857 | |
Johannes Doerfert | 515f857 | 2014-07-28 03:46:28 +0000 | [diff] [blame] | 858 | static isl_union_map *getCombinedScheduleForSpace(Scop *S, unsigned dimLevel) { |
| 859 | isl_space *Space = S->getParamSpace(); |
| 860 | isl_union_map *schedule = isl_union_map_empty(Space); |
| 861 | |
| 862 | for (ScopStmt *Stmt : *S) { |
| 863 | unsigned remainingDimensions = Stmt->getNumScattering() - dimLevel; |
| 864 | isl_map *Scattering = isl_map_project_out( |
| 865 | Stmt->getScattering(), isl_dim_out, dimLevel, remainingDimensions); |
| 866 | schedule = isl_union_map_add_map(schedule, Scattering); |
| 867 | } |
| 868 | |
| 869 | return schedule; |
| 870 | } |
| 871 | |
Tobias Grosser | e192b23 | 2012-05-22 08:46:07 +0000 | [diff] [blame] | 872 | bool ClastStmtCodeGen::isParallelFor(const clast_for *f) { |
Tobias Grosser | 880c52f | 2013-07-29 01:58:07 +0000 | [diff] [blame] | 873 | isl_set *Domain = isl_set_copy(isl_set_from_cloog_domain(f->domain)); |
Tobias Grosser | e192b23 | 2012-05-22 08:46:07 +0000 | [diff] [blame] | 874 | assert(Domain && "Cannot access domain of loop"); |
| 875 | |
| 876 | Dependences &D = P->getAnalysis<Dependences>(); |
Johannes Doerfert | 515f857 | 2014-07-28 03:46:28 +0000 | [diff] [blame] | 877 | isl_union_map *Deps = |
| 878 | D.getDependences(Dependences::TYPE_RAW | Dependences::TYPE_WAW | |
| 879 | Dependences::TYPE_WAR | Dependences::TYPE_RAW); |
| 880 | isl_union_map *Schedule = |
| 881 | getCombinedScheduleForSpace(S, isl_set_n_dim(Domain)); |
| 882 | Schedule = |
| 883 | isl_union_map_intersect_range(Schedule, isl_union_set_from_set(Domain)); |
| 884 | bool IsParallel = D.isParallel(Schedule, Deps); |
| 885 | isl_union_map_free(Schedule); |
| 886 | return IsParallel; |
Tobias Grosser | e192b23 | 2012-05-22 08:46:07 +0000 | [diff] [blame] | 887 | } |
| 888 | |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 889 | void ClastStmtCodeGen::codegen(const clast_for *f) { |
Hongbin Zheng | 6879421 | 2012-05-06 10:22:19 +0000 | [diff] [blame] | 890 | bool Vector = PollyVectorizerChoice != VECTORIZER_NONE; |
Tobias Grosser | e192b23 | 2012-05-22 08:46:07 +0000 | [diff] [blame] | 891 | if ((Vector || OpenMP) && isParallelFor(f)) { |
Tobias Grosser | ae2d83e | 2012-12-29 23:57:18 +0000 | [diff] [blame] | 892 | if (Vector && isInnermostLoop(f) && (-1 != getNumberOfIterations(f)) && |
| 893 | (getNumberOfIterations(f) <= 16)) { |
Tobias Grosser | ce3f537 | 2012-03-02 11:26:42 +0000 | [diff] [blame] | 894 | codegenForVector(f); |
| 895 | return; |
| 896 | } |
| 897 | |
| 898 | if (OpenMP && !parallelCodeGeneration) { |
| 899 | parallelCodeGeneration = true; |
| 900 | parallelLoops.push_back(f->iterator); |
| 901 | codegenForOpenMP(f); |
| 902 | parallelCodeGeneration = false; |
| 903 | return; |
| 904 | } |
| 905 | } |
| 906 | |
Tobias Grosser | 6217e18 | 2012-08-03 12:50:07 +0000 | [diff] [blame] | 907 | #ifdef GPU_CODEGEN |
| 908 | if (GPGPU && isParallelFor(f)) { |
| 909 | if (!parallelCodeGeneration) { |
| 910 | parallelCodeGeneration = true; |
| 911 | parallelLoops.push_back(f->iterator); |
| 912 | codegenForGPGPU(f); |
| 913 | parallelCodeGeneration = false; |
| 914 | return; |
| 915 | } |
| 916 | } |
| 917 | #endif |
| 918 | |
Tobias Grosser | ce3f537 | 2012-03-02 11:26:42 +0000 | [diff] [blame] | 919 | codegenForSequential(f); |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 920 | } |
| 921 | |
| 922 | Value *ClastStmtCodeGen::codegen(const clast_equation *eq) { |
Tobias Grosser | e9ffea2 | 2012-03-15 09:34:48 +0000 | [diff] [blame] | 923 | Value *LHS = ExpGen.codegen(eq->LHS, getIntPtrTy()); |
| 924 | Value *RHS = ExpGen.codegen(eq->RHS, getIntPtrTy()); |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 925 | CmpInst::Predicate P; |
| 926 | |
| 927 | if (eq->sign == 0) |
| 928 | P = ICmpInst::ICMP_EQ; |
| 929 | else if (eq->sign > 0) |
| 930 | P = ICmpInst::ICMP_SGE; |
| 931 | else |
| 932 | P = ICmpInst::ICMP_SLE; |
| 933 | |
| 934 | return Builder.CreateICmp(P, LHS, RHS); |
| 935 | } |
| 936 | |
| 937 | void ClastStmtCodeGen::codegen(const clast_guard *g) { |
| 938 | Function *F = Builder.GetInsertBlock()->getParent(); |
| 939 | LLVMContext &Context = F->getContext(); |
Tobias Grosser | 0ac9214 | 2012-02-14 14:02:27 +0000 | [diff] [blame] | 940 | |
Tobias Grosser | c14582f | 2013-02-05 18:01:29 +0000 | [diff] [blame] | 941 | BasicBlock *CondBB = |
| 942 | SplitBlock(Builder.GetInsertBlock(), Builder.GetInsertPoint(), P); |
Tobias Grosser | 0ac9214 | 2012-02-14 14:02:27 +0000 | [diff] [blame] | 943 | CondBB->setName("polly.cond"); |
| 944 | BasicBlock *MergeBB = SplitBlock(CondBB, CondBB->begin(), P); |
| 945 | MergeBB->setName("polly.merge"); |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 946 | BasicBlock *ThenBB = BasicBlock::Create(Context, "polly.then", F); |
Tobias Grosser | 0ac9214 | 2012-02-14 14:02:27 +0000 | [diff] [blame] | 947 | |
Tobias Grosser | 42aff30 | 2014-01-13 22:29:56 +0000 | [diff] [blame] | 948 | DominatorTree &DT = P->getAnalysis<DominatorTreeWrapperPass>().getDomTree(); |
Tobias Grosser | d596b37 | 2012-03-15 09:34:52 +0000 | [diff] [blame] | 949 | DT.addNewBlock(ThenBB, CondBB); |
| 950 | DT.changeImmediateDominator(MergeBB, CondBB); |
Tobias Grosser | 0ac9214 | 2012-02-14 14:02:27 +0000 | [diff] [blame] | 951 | |
| 952 | CondBB->getTerminator()->eraseFromParent(); |
| 953 | |
| 954 | Builder.SetInsertPoint(CondBB); |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 955 | |
| 956 | Value *Predicate = codegen(&(g->eq[0])); |
| 957 | |
| 958 | for (int i = 1; i < g->n; ++i) { |
| 959 | Value *TmpPredicate = codegen(&(g->eq[i])); |
| 960 | Predicate = Builder.CreateAnd(Predicate, TmpPredicate); |
| 961 | } |
| 962 | |
| 963 | Builder.CreateCondBr(Predicate, ThenBB, MergeBB); |
| 964 | Builder.SetInsertPoint(ThenBB); |
Tobias Grosser | 0ac9214 | 2012-02-14 14:02:27 +0000 | [diff] [blame] | 965 | Builder.CreateBr(MergeBB); |
| 966 | Builder.SetInsertPoint(ThenBB->begin()); |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 967 | |
Tobias Grosser | 3081b0f | 2013-05-16 06:40:24 +0000 | [diff] [blame] | 968 | LoopInfo &LI = P->getAnalysis<LoopInfo>(); |
| 969 | Loop *L = LI.getLoopFor(CondBB); |
Tobias Grosser | 815c635 | 2013-09-02 16:13:00 +0000 | [diff] [blame] | 970 | if (L) |
Tobias Grosser | 3081b0f | 2013-05-16 06:40:24 +0000 | [diff] [blame] | 971 | L->addBasicBlockToLoop(ThenBB, LI.getBase()); |
Tobias Grosser | 3081b0f | 2013-05-16 06:40:24 +0000 | [diff] [blame] | 972 | |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 973 | codegen(g->then); |
Tobias Grosser | 62a3c96 | 2012-02-16 09:56:21 +0000 | [diff] [blame] | 974 | |
| 975 | Builder.SetInsertPoint(MergeBB->begin()); |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 976 | } |
| 977 | |
| 978 | void ClastStmtCodeGen::codegen(const clast_stmt *stmt) { |
Tobias Grosser | c14582f | 2013-02-05 18:01:29 +0000 | [diff] [blame] | 979 | if (CLAST_STMT_IS_A(stmt, stmt_root)) |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 980 | assert(false && "No second root statement expected"); |
| 981 | else if (CLAST_STMT_IS_A(stmt, stmt_ass)) |
| 982 | codegen((const clast_assignment *)stmt); |
| 983 | else if (CLAST_STMT_IS_A(stmt, stmt_user)) |
| 984 | codegen((const clast_user_stmt *)stmt); |
| 985 | else if (CLAST_STMT_IS_A(stmt, stmt_block)) |
| 986 | codegen((const clast_block *)stmt); |
| 987 | else if (CLAST_STMT_IS_A(stmt, stmt_for)) |
| 988 | codegen((const clast_for *)stmt); |
| 989 | else if (CLAST_STMT_IS_A(stmt, stmt_guard)) |
| 990 | codegen((const clast_guard *)stmt); |
| 991 | |
| 992 | if (stmt->next) |
| 993 | codegen(stmt->next); |
| 994 | } |
| 995 | |
| 996 | void ClastStmtCodeGen::addParameters(const CloogNames *names) { |
Tobias Grosser | d596b37 | 2012-03-15 09:34:52 +0000 | [diff] [blame] | 997 | SCEVExpander Rewriter(P->getAnalysis<ScalarEvolution>(), "polly"); |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 998 | |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 999 | int i = 0; |
| 1000 | for (Scop::param_iterator PI = S->param_begin(), PE = S->param_end(); |
| 1001 | PI != PE; ++PI) { |
| 1002 | assert(i < names->nb_parameters && "Not enough parameter names"); |
| 1003 | |
| 1004 | const SCEV *Param = *PI; |
| 1005 | Type *Ty = Param->getType(); |
| 1006 | |
| 1007 | Instruction *insertLocation = --(Builder.GetInsertBlock()->end()); |
| 1008 | Value *V = Rewriter.expandCodeFor(Param, Ty, insertLocation); |
Tobias Grosser | 5e8ffa8 | 2012-03-23 12:20:36 +0000 | [diff] [blame] | 1009 | ClastVars[names->parameters[i]] = V; |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 1010 | |
| 1011 | ++i; |
| 1012 | } |
| 1013 | } |
| 1014 | |
| 1015 | void ClastStmtCodeGen::codegen(const clast_root *r) { |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 1016 | addParameters(r->names); |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 1017 | |
| 1018 | parallelCodeGeneration = false; |
| 1019 | |
Tobias Grosser | c14582f | 2013-02-05 18:01:29 +0000 | [diff] [blame] | 1020 | const clast_stmt *stmt = (const clast_stmt *)r; |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 1021 | if (stmt->next) |
| 1022 | codegen(stmt->next); |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 1023 | } |
| 1024 | |
Tobias Grosser | 5103ba7 | 2014-03-04 14:58:49 +0000 | [diff] [blame] | 1025 | ClastStmtCodeGen::ClastStmtCodeGen(Scop *scop, PollyIRBuilder &B, Pass *P) |
Johannes Doerfert | c5129d8 | 2014-08-08 04:23:13 +0000 | [diff] [blame] | 1026 | : S(scop), P(P), LI(P->getAnalysis<LoopInfo>()), |
| 1027 | SE(P->getAnalysis<ScalarEvolution>()), |
| 1028 | DT(P->getAnalysis<DominatorTreeWrapperPass>().getDomTree()), Builder(B), |
| 1029 | ExpGen(Builder, ClastVars) {} |
Tobias Grosser | 9bc5eb08 | 2012-01-24 16:42:32 +0000 | [diff] [blame] | 1030 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1031 | namespace { |
| 1032 | class CodeGeneration : public ScopPass { |
Tobias Grosser | 3a275d2 | 2012-05-29 09:11:54 +0000 | [diff] [blame] | 1033 | std::vector<std::string> ParallelLoops; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1034 | |
Tobias Grosser | 1bb59b0 | 2012-12-29 23:47:38 +0000 | [diff] [blame] | 1035 | public: |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1036 | static char ID; |
| 1037 | |
| 1038 | CodeGeneration() : ScopPass(ID) {} |
| 1039 | |
Tobias Grosser | 3a275d2 | 2012-05-29 09:11:54 +0000 | [diff] [blame] | 1040 | bool runOnScop(Scop &S) { |
| 1041 | ParallelLoops.clear(); |
Tobias Grosser | 8c4cfc32 | 2011-05-14 19:01:49 +0000 | [diff] [blame] | 1042 | |
Tobias Grosser | e602a07 | 2013-05-07 07:30:56 +0000 | [diff] [blame] | 1043 | assert(!S.getRegion().isTopLevelRegion() && |
| 1044 | "Top level regions are not supported"); |
Tobias Grosser | 0ee50f6 | 2013-04-10 06:55:31 +0000 | [diff] [blame] | 1045 | |
Tobias Grosser | 8edce4e | 2013-04-16 08:04:42 +0000 | [diff] [blame] | 1046 | simplifyRegion(&S, this); |
Tobias Grosser | cb47dfe | 2012-02-15 09:58:50 +0000 | [diff] [blame] | 1047 | |
Johannes Doerfert | 3826224 | 2014-09-10 14:50:23 +0000 | [diff] [blame] | 1048 | Value *RTC = ConstantInt::getTrue(S.getSE()->getContext()); |
| 1049 | BasicBlock *StartBlock = executeScopConditionally(S, this, RTC); |
Tobias Grosser | 8c4cfc32 | 2011-05-14 19:01:49 +0000 | [diff] [blame] | 1050 | |
Tobias Grosser | 5103ba7 | 2014-03-04 14:58:49 +0000 | [diff] [blame] | 1051 | PollyIRBuilder Builder(StartBlock->begin()); |
Tobias Grosser | 8c4cfc32 | 2011-05-14 19:01:49 +0000 | [diff] [blame] | 1052 | |
Tobias Grosser | 3a275d2 | 2012-05-29 09:11:54 +0000 | [diff] [blame] | 1053 | ClastStmtCodeGen CodeGen(&S, Builder, this); |
Tobias Grosser | 3fdecae | 2011-05-14 19:02:39 +0000 | [diff] [blame] | 1054 | CloogInfo &C = getAnalysis<CloogInfo>(); |
| 1055 | CodeGen.codegen(C.getClast()); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1056 | |
Tobias Grosser | 3a275d2 | 2012-05-29 09:11:54 +0000 | [diff] [blame] | 1057 | ParallelLoops.insert(ParallelLoops.begin(), |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1058 | CodeGen.getParallelLoops().begin(), |
| 1059 | CodeGen.getParallelLoops().end()); |
Tobias Grosser | abb6dcd | 2011-05-14 19:02:34 +0000 | [diff] [blame] | 1060 | return true; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | virtual void printScop(raw_ostream &OS) const { |
Tobias Grosser | 0244ee8 | 2014-09-10 14:42:06 +0000 | [diff] [blame] | 1064 | for (const auto &PI : ParallelLoops) |
Tobias Grosser | 1fee67d | 2014-08-31 16:10:31 +0000 | [diff] [blame] | 1065 | OS << "Parallel loop with iterator '" << PI << "' generated\n"; |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1066 | } |
| 1067 | |
| 1068 | virtual void getAnalysisUsage(AnalysisUsage &AU) const { |
| 1069 | AU.addRequired<CloogInfo>(); |
| 1070 | AU.addRequired<Dependences>(); |
Tobias Grosser | 42aff30 | 2014-01-13 22:29:56 +0000 | [diff] [blame] | 1071 | AU.addRequired<DominatorTreeWrapperPass>(); |
Matt Arsenault | 8ca3681 | 2014-07-19 18:40:17 +0000 | [diff] [blame] | 1072 | AU.addRequired<RegionInfoPass>(); |
Tobias Grosser | 73600b8 | 2011-10-08 00:30:40 +0000 | [diff] [blame] | 1073 | AU.addRequired<ScalarEvolution>(); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1074 | AU.addRequired<ScopDetection>(); |
| 1075 | AU.addRequired<ScopInfo>(); |
Rafael Espindola | c5d1689 | 2014-02-25 19:17:57 +0000 | [diff] [blame] | 1076 | AU.addRequired<DataLayoutPass>(); |
Tobias Grosser | ecfe21b | 2013-03-20 18:03:18 +0000 | [diff] [blame] | 1077 | AU.addRequired<LoopInfo>(); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1078 | |
| 1079 | AU.addPreserved<CloogInfo>(); |
| 1080 | AU.addPreserved<Dependences>(); |
| 1081 | AU.addPreserved<LoopInfo>(); |
Tobias Grosser | 42aff30 | 2014-01-13 22:29:56 +0000 | [diff] [blame] | 1082 | AU.addPreserved<DominatorTreeWrapperPass>(); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1083 | AU.addPreserved<ScopDetection>(); |
| 1084 | AU.addPreserved<ScalarEvolution>(); |
Tobias Grosser | 5d6eb86 | 2011-05-14 19:02:45 +0000 | [diff] [blame] | 1085 | |
Tobias Grosser | 4e3f9a4 | 2011-05-23 15:23:36 +0000 | [diff] [blame] | 1086 | // FIXME: We do not yet add regions for the newly generated code to the |
| 1087 | // region tree. |
Matt Arsenault | 8ca3681 | 2014-07-19 18:40:17 +0000 | [diff] [blame] | 1088 | AU.addPreserved<RegionInfoPass>(); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1089 | AU.addPreserved<TempScopInfo>(); |
| 1090 | AU.addPreserved<ScopInfo>(); |
| 1091 | AU.addPreservedID(IndependentBlocksID); |
| 1092 | } |
| 1093 | }; |
| 1094 | } |
| 1095 | |
| 1096 | char CodeGeneration::ID = 1; |
| 1097 | |
Tobias Grosser | 4d96c8d | 2013-03-23 01:05:07 +0000 | [diff] [blame] | 1098 | Pass *polly::createCodeGenerationPass() { return new CodeGeneration(); } |
Sebastian Pop | e1f6554 | 2012-05-07 16:35:11 +0000 | [diff] [blame] | 1099 | |
Tobias Grosser | 7242ad9 | 2013-02-22 08:07:06 +0000 | [diff] [blame] | 1100 | INITIALIZE_PASS_BEGIN(CodeGeneration, "polly-codegen", |
| 1101 | "Polly - Create LLVM-IR from SCoPs", false, false); |
| 1102 | INITIALIZE_PASS_DEPENDENCY(CloogInfo); |
| 1103 | INITIALIZE_PASS_DEPENDENCY(Dependences); |
Tobias Grosser | 42aff30 | 2014-01-13 22:29:56 +0000 | [diff] [blame] | 1104 | INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass); |
Matt Arsenault | 8ca3681 | 2014-07-19 18:40:17 +0000 | [diff] [blame] | 1105 | INITIALIZE_PASS_DEPENDENCY(RegionInfoPass); |
Tobias Grosser | 7242ad9 | 2013-02-22 08:07:06 +0000 | [diff] [blame] | 1106 | INITIALIZE_PASS_DEPENDENCY(ScalarEvolution); |
| 1107 | INITIALIZE_PASS_DEPENDENCY(ScopDetection); |
Rafael Espindola | c5d1689 | 2014-02-25 19:17:57 +0000 | [diff] [blame] | 1108 | INITIALIZE_PASS_DEPENDENCY(DataLayoutPass); |
Tobias Grosser | 7242ad9 | 2013-02-22 08:07:06 +0000 | [diff] [blame] | 1109 | INITIALIZE_PASS_END(CodeGeneration, "polly-codegen", |
Tobias Grosser | 4d96c8d | 2013-03-23 01:05:07 +0000 | [diff] [blame] | 1110 | "Polly - Create LLVM-IR from SCoPs", false, false) |
Tobias Grosser | 7242ad9 | 2013-02-22 08:07:06 +0000 | [diff] [blame] | 1111 | |
Sebastian Pop | e1f6554 | 2012-05-07 16:35:11 +0000 | [diff] [blame] | 1112 | #endif // CLOOG_FOUND |