1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | #ifndef LLVM_CLANG_LIB_CODEGEN_CGLOOPINFO_H |
15 | #define LLVM_CLANG_LIB_CODEGEN_CGLOOPINFO_H |
16 | |
17 | #include "llvm/ADT/ArrayRef.h" |
18 | #include "llvm/ADT/SmallVector.h" |
19 | #include "llvm/IR/DebugLoc.h" |
20 | #include "llvm/IR/Value.h" |
21 | #include "llvm/Support/Compiler.h" |
22 | |
23 | namespace llvm { |
24 | class BasicBlock; |
25 | class Instruction; |
26 | class MDNode; |
27 | } |
28 | |
29 | namespace clang { |
30 | class Attr; |
31 | class ASTContext; |
32 | namespace CodeGen { |
33 | |
34 | |
35 | struct LoopAttributes { |
36 | explicit LoopAttributes(bool IsParallel = false); |
37 | void clear(); |
38 | |
39 | |
40 | bool IsParallel; |
41 | |
42 | |
43 | enum LVEnableState { Unspecified, Enable, Disable, Full }; |
44 | |
45 | |
46 | LVEnableState VectorizeEnable; |
47 | |
48 | |
49 | LVEnableState UnrollEnable; |
50 | |
51 | |
52 | LVEnableState UnrollAndJamEnable; |
53 | |
54 | |
55 | unsigned VectorizeWidth; |
56 | |
57 | |
58 | unsigned InterleaveCount; |
59 | |
60 | |
61 | unsigned UnrollCount; |
62 | |
63 | |
64 | unsigned UnrollAndJamCount; |
65 | |
66 | |
67 | LVEnableState DistributeEnable; |
68 | |
69 | |
70 | bool PipelineDisabled; |
71 | |
72 | |
73 | unsigned PipelineInitiationInterval; |
74 | }; |
75 | |
76 | |
77 | class LoopInfo { |
78 | public: |
79 | |
80 | LoopInfo(llvm::BasicBlock *, const LoopAttributes &Attrs, |
81 | const llvm::DebugLoc &StartLoc, const llvm::DebugLoc &EndLoc); |
82 | |
83 | |
84 | llvm::MDNode *getLoopID() const { return LoopID; } |
85 | |
86 | |
87 | llvm::BasicBlock *() const { return Header; } |
88 | |
89 | |
90 | const LoopAttributes &getAttributes() const { return Attrs; } |
91 | |
92 | |
93 | llvm::MDNode *getAccessGroup() const { return AccGroup; } |
94 | |
95 | private: |
96 | |
97 | llvm::MDNode *LoopID; |
98 | |
99 | llvm::BasicBlock *; |
100 | |
101 | LoopAttributes Attrs; |
102 | |
103 | llvm::MDNode *AccGroup = nullptr; |
104 | }; |
105 | |
106 | |
107 | |
108 | |
109 | class LoopInfoStack { |
110 | LoopInfoStack(const LoopInfoStack &) = delete; |
111 | void operator=(const LoopInfoStack &) = delete; |
112 | |
113 | public: |
114 | LoopInfoStack() {} |
115 | |
116 | |
117 | |
118 | void push(llvm::BasicBlock *, const llvm::DebugLoc &StartLoc, |
119 | const llvm::DebugLoc &EndLoc); |
120 | |
121 | |
122 | |
123 | void push(llvm::BasicBlock *, clang::ASTContext &Ctx, |
124 | llvm::ArrayRef<const Attr *> Attrs, const llvm::DebugLoc &StartLoc, |
125 | const llvm::DebugLoc &EndLoc); |
126 | |
127 | |
128 | void pop(); |
129 | |
130 | |
131 | llvm::MDNode *getCurLoopID() const { return getInfo().getLoopID(); } |
132 | |
133 | |
134 | bool getCurLoopParallel() const { |
135 | return hasInfo() ? getInfo().getAttributes().IsParallel : false; |
136 | } |
137 | |
138 | |
139 | |
140 | void InsertHelper(llvm::Instruction *I) const; |
141 | |
142 | |
143 | void setParallel(bool Enable = true) { StagedAttrs.IsParallel = Enable; } |
144 | |
145 | |
146 | void setVectorizeEnable(bool Enable = true) { |
147 | StagedAttrs.VectorizeEnable = |
148 | Enable ? LoopAttributes::Enable : LoopAttributes::Disable; |
149 | } |
150 | |
151 | |
152 | void setDistributeState(bool Enable = true) { |
153 | StagedAttrs.DistributeEnable = |
154 | Enable ? LoopAttributes::Enable : LoopAttributes::Disable; |
155 | } |
156 | |
157 | |
158 | void setUnrollState(const LoopAttributes::LVEnableState &State) { |
159 | StagedAttrs.UnrollEnable = State; |
160 | } |
161 | |
162 | |
163 | void setUnrollAndJamState(const LoopAttributes::LVEnableState &State) { |
164 | StagedAttrs.UnrollAndJamEnable = State; |
165 | } |
166 | |
167 | |
168 | void setVectorizeWidth(unsigned W) { StagedAttrs.VectorizeWidth = W; } |
169 | |
170 | |
171 | void setInterleaveCount(unsigned C) { StagedAttrs.InterleaveCount = C; } |
172 | |
173 | |
174 | void setUnrollCount(unsigned C) { StagedAttrs.UnrollCount = C; } |
175 | |
176 | |
177 | void setUnrollAndJamCount(unsigned C) { StagedAttrs.UnrollAndJamCount = C; } |
178 | |
179 | |
180 | void setPipelineDisabled(bool S) { StagedAttrs.PipelineDisabled = S; } |
181 | |
182 | |
183 | void setPipelineInitiationInterval(unsigned C) { |
184 | StagedAttrs.PipelineInitiationInterval = C; |
185 | } |
186 | |
187 | private: |
188 | |
189 | bool hasInfo() const { return !Active.empty(); } |
190 | |
191 | |
192 | const LoopInfo &getInfo() const { return Active.back(); } |
193 | |
194 | LoopAttributes StagedAttrs; |
195 | |
196 | llvm::SmallVector<LoopInfo, 4> Active; |
197 | }; |
198 | |
199 | } |
200 | } |
201 | |
202 | #endif |
203 | |