@@ -145,6 +145,7 @@ class Dependences final {
145145 friend struct DependenceAnalysis ;
146146 friend struct DependenceInfoPrinterPass ;
147147 friend class DependenceInfo ;
148+ friend class DependenceInfoWrapperPass ;
148149
149150 // / Destructor that will free internal objects.
150151 ~Dependences () { releaseMemory (); }
@@ -191,8 +192,6 @@ class Dependences final {
191192 const AnalysisLevel Level;
192193};
193194
194- extern Dependences::AnalysisLevel OptAnalysisLevel;
195-
196195struct DependenceAnalysis final : public AnalysisInfoMixin<DependenceAnalysis> {
197196 static AnalysisKey Key;
198197 struct Result {
@@ -233,7 +232,108 @@ struct DependenceInfoPrinterPass final
233232 raw_ostream &OS;
234233};
235234
236- DependenceAnalysis::Result runDependenceAnalysis (Scop &S);
235+ class DependenceInfo final : public ScopPass {
236+ public:
237+ static char ID;
238+
239+ // / Construct a new DependenceInfo pass.
240+ DependenceInfo () : ScopPass(ID) {}
241+
242+ // / Return the dependence information for the current SCoP.
243+ // /
244+ // / @param Level The granularity of dependence analysis result.
245+ // /
246+ // / @return The dependence analysis result
247+ // /
248+ const Dependences &getDependences (Dependences::AnalysisLevel Level);
249+
250+ // / Recompute dependences from schedule and memory accesses.
251+ const Dependences &recomputeDependences (Dependences::AnalysisLevel Level);
252+
253+ // / Invalidate the dependence information and recompute it when needed again.
254+ // / May be required when the underlying Scop was changed in a way that would
255+ // / add new dependencies (e.g. between new statement instances insierted into
256+ // / the SCoP) or intentionally breaks existing ones. It is not required when
257+ // / updating the schedule that conforms the existing dependencies.
258+ void abandonDependences ();
259+
260+ // / Compute the dependence information for the SCoP @p S.
261+ bool runOnScop (Scop &S) override ;
262+
263+ // / Print the dependences for the given SCoP to @p OS.
264+ void printScop (raw_ostream &OS, Scop &) const override ;
265+
266+ // / Release the internal memory.
267+ void releaseMemory () override {
268+ for (auto &d : D)
269+ d.reset ();
270+ }
271+
272+ // / Register all analyses and transformation required.
273+ void getAnalysisUsage (AnalysisUsage &AU) const override ;
274+
275+ private:
276+ Scop *S;
277+
278+ // / Dependences struct for the current SCoP.
279+ std::unique_ptr<Dependences> D[Dependences::NumAnalysisLevels];
280+ };
281+
282+ llvm::Pass *createDependenceInfoPass ();
283+ llvm::Pass *createDependenceInfoPrinterLegacyPass (llvm::raw_ostream &OS);
284+
285+ // / Construct a new DependenceInfoWrapper pass.
286+ class DependenceInfoWrapperPass final : public FunctionPass {
287+ public:
288+ static char ID;
289+
290+ // / Construct a new DependenceInfoWrapper pass.
291+ DependenceInfoWrapperPass () : FunctionPass(ID) {}
292+
293+ // / Return the dependence information for the given SCoP.
294+ // /
295+ // / @param S SCoP object.
296+ // / @param Level The granularity of dependence analysis result.
297+ // /
298+ // / @return The dependence analysis result
299+ // /
300+ const Dependences &getDependences (Scop *S, Dependences::AnalysisLevel Level);
301+
302+ // / Recompute dependences from schedule and memory accesses.
303+ const Dependences &recomputeDependences (Scop *S,
304+ Dependences::AnalysisLevel Level);
305+
306+ // / Compute the dependence information on-the-fly for the function.
307+ bool runOnFunction (Function &F) override ;
308+
309+ // / Print the dependences for the current function to @p OS.
310+ void print (raw_ostream &OS, const Module *M = nullptr ) const override ;
311+
312+ // / Release the internal memory.
313+ void releaseMemory () override { ScopToDepsMap.clear (); }
314+
315+ // / Register all analyses and transformation required.
316+ void getAnalysisUsage (AnalysisUsage &AU) const override ;
317+
318+ private:
319+ using ScopToDepsMapTy = DenseMap<Scop *, std::unique_ptr<Dependences>>;
320+
321+ // / Scop to Dependence map for the current function.
322+ ScopToDepsMapTy ScopToDepsMap;
323+ };
324+
325+ llvm::Pass *createDependenceInfoWrapperPassPass ();
326+ llvm::Pass *
327+ createDependenceInfoPrinterLegacyFunctionPass (llvm::raw_ostream &OS);
328+
237329} // namespace polly
238330
331+ namespace llvm {
332+ void initializeDependenceInfoPass (llvm::PassRegistry &);
333+ void initializeDependenceInfoPrinterLegacyPassPass (llvm::PassRegistry &);
334+ void initializeDependenceInfoWrapperPassPass (llvm::PassRegistry &);
335+ void initializeDependenceInfoPrinterLegacyFunctionPassPass (
336+ llvm::PassRegistry &);
337+ } // namespace llvm
338+
239339#endif
0 commit comments