xref: /aosp_15_r20/external/llvm/include/llvm/Transforms/IPO/FunctionAttrs.h (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1 //===-- FunctionAttrs.h - Compute function attrs --------------------------===//
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 /// \file
10 /// Provides passes for computing function attributes based on interprocedural
11 /// analyses.
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_TRANSFORMS_IPO_FUNCTIONATTRS_H
15 #define LLVM_TRANSFORMS_IPO_FUNCTIONATTRS_H
16 
17 #include "llvm/Analysis/LazyCallGraph.h"
18 #include "llvm/Analysis/CGSCCPassManager.h"
19 #include "llvm/IR/PassManager.h"
20 
21 namespace llvm {
22 
23 /// Computes function attributes in post-order over the call graph.
24 ///
25 /// By operating in post-order, this pass computes precise attributes for
26 /// called functions prior to processsing their callers. This "bottom-up"
27 /// approach allows powerful interprocedural inference of function attributes
28 /// like memory access patterns, etc. It can discover functions that do not
29 /// access memory, or only read memory, and give them the readnone/readonly
30 /// attribute. It also discovers function arguments that are not captured by
31 /// the function and marks them with the nocapture attribute.
32 struct PostOrderFunctionAttrsPass : PassInfoMixin<PostOrderFunctionAttrsPass> {
33   PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &AM);
34 };
35 
36 /// Create a legacy pass manager instance of a pass to compute function attrs
37 /// in post-order.
38 Pass *createPostOrderFunctionAttrsLegacyPass();
39 
40 /// A pass to do RPO deduction and propagation of function attributes.
41 ///
42 /// This pass provides a general RPO or "top down" propagation of
43 /// function attributes. For a few (rare) cases, we can deduce significantly
44 /// more about function attributes by working in RPO, so this pass
45 /// provides the compliment to the post-order pass above where the majority of
46 /// deduction is performed.
47 // FIXME: Currently there is no RPO CGSCC pass structure to slide into and so
48 // this is a boring module pass, but eventually it should be an RPO CGSCC pass
49 // when such infrastructure is available.
50 class ReversePostOrderFunctionAttrsPass
51     : public PassInfoMixin<ReversePostOrderFunctionAttrsPass> {
52 public:
53   PreservedAnalyses run(Module &M, AnalysisManager<Module> &AM);
54 };
55 }
56 
57 #endif // LLVM_TRANSFORMS_IPO_FUNCTIONATTRS_H
58