1 //===- LoopGenerators.h - IR helper to create loops -------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains functions to create scalar and OpenMP parallel loops
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"
30 /// @brief Create a scalar loop.
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.
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
);
47 typedef std::map
<Value
*, Value
*> ValueToValueMapTy
;
49 OMPGenerator(IRBuilder
<> &Builder
, Pass
*P
): Builder(Builder
), P(P
) {}
51 /// @brief Create an OpenMP parallel loop.
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
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.
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
);
78 IntegerType
*getIntPtrTy();
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.
94 /// @param Stride The value by which the induction variable is
96 /// @param Struct The structure that is used to make Values available to
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