Rewrite #includes for llvm/Foo.h to llvm/IR/Foo.h as appropriate to
[polly-mirror.git] / include / polly / CodeGen / LoopGenerators.h
blobf6e2ef058d06e828cd82eb610ddce059d28757a4
1 //===- LoopGenerators.h - IR helper to create loops -------------*- C++ -*-===//
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 // This file contains functions to create scalar and OpenMP parallel loops
11 // as LLVM-IR.
13 //===----------------------------------------------------------------------===//
14 #ifndef POLLY_LOOP_GENERATORS_H
15 #define POLLY_LOOP_GENERATORS_H
16 #include "llvm/IR/IRBuilder.h"
17 #include "llvm/ADT/SetVector.h"
19 #include <map>
21 namespace llvm {
22 class Value;
23 class Pass;
24 class BasicBlock;
27 namespace polly {
28 using namespace llvm;
30 /// @brief Create a scalar loop.
31 ///
32 /// @param LowerBound The starting value of the induction variable.
33 /// @param UpperBound The upper bound of the induction variable.
34 /// @param Stride The value by which the induction variable is incremented.
35 ///
36 /// @param Builder The builder used to create the loop.
37 /// @param P A pointer to the pass that uses this function. It is used
38 /// to update analysis information.
39 /// @param Predicate The predicate used to generate the upper loop bound.
40 /// @return Value* The newly created induction variable for this loop.
41 Value *createLoop(Value *LowerBound, Value *UpperBound, Value *Stride,
42 IRBuilder<> &Builder, Pass *P, BasicBlock *&AfterBlock,
43 ICmpInst::Predicate Predicate);
45 class OMPGenerator {
46 public:
47 typedef std::map<Value*, Value*> ValueToValueMapTy;
49 OMPGenerator(IRBuilder<> &Builder, Pass *P): Builder(Builder), P(P) {}
51 /// @brief Create an OpenMP parallel loop.
52 ///
53 ///
54 /// @param LowerBound The starting value of the induction variable.
55 /// @param UpperBound The upper bound of the induction variable.
56 /// @param Stride The value by which the induction variable is
57 /// incremented.
58 ///
59 /// @param UsedValues A set of LLVM-IR Values that should be available to
60 /// the new loop body.
61 /// @param VMap This map is filled by createParallelLoop(). It
62 /// maps the values in UsedValues to Values through which
63 /// their content is available within the loop body.
64 /// @param LoopBody A pointer to an iterator that is set to point to the
65 /// body of the created loop. It should be used to insert
66 /// instructions that form the actual loop body.
67 ///
68 /// @return Value* The newly created induction variable for this loop.
69 Value *createParallelLoop(Value *LowerBound, Value *UpperBound, Value *Stride,
70 SetVector<Value*> &UsedValues,
71 ValueToValueMapTy &VMap,
72 BasicBlock::iterator *LoopBody);
74 private:
75 IRBuilder<> &Builder;
76 Pass *P;
78 IntegerType *getIntPtrTy();
79 Module *getModule();
81 void createCallParallelLoopStart(Value *SubFunction, Value *SubfunctionParam,
82 Value *NumberOfThreads, Value *LowerBound,
83 Value *UpperBound, Value *Stride);
84 Value *createCallLoopNext(Value *LowerBoundPtr, Value *UpperBoundPtr);
85 void createCallParallelEnd();
86 void createCallLoopEndNowait();
88 Value *loadValuesIntoStruct(SetVector<Value*> &Values);
89 void extractValuesFromStruct(SetVector<Value*> OldValues,
90 Value *Struct, ValueToValueMapTy &Map);
92 /// @brief Create the OpenMP subfunction.
93 ///
94 /// @param Stride The value by which the induction variable is
95 /// incremented.
96 /// @param Struct The structure that is used to make Values available to
97 /// the loop body.
98 /// @param UsedValues A set of LLVM-IR Values that should be available to
99 /// the new loop body.
100 /// @param VMap This map that is filled by createSubfunction(). It
101 /// maps the values in UsedValues to Values through which
102 /// their content is available within the loop body.
103 /// @param SubFunction The newly created SubFunction is returned here.
105 /// @return Value* The newly created induction variable.
106 Value *createSubfunction(Value *Stride, Value *Struct,
107 SetVector<Value*> UsedValues,
108 ValueToValueMapTy &VMap,
109 Function **SubFunction);
111 /// @brief Create the definition of the OpenMP subfunction.
112 Function *createSubfunctionDefinition();
114 } // end namespace polly
115 #endif