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/CGSCCPassManager.h" 18 #include "llvm/Analysis/LazyCallGraph.h" 19 #include "llvm/IR/PassManager.h" 20 21 namespace llvm { 22 23 class AAResults; 24 25 /// The three kinds of memory access relevant to 'readonly' and 26 /// 'readnone' attributes. 27 enum MemoryAccessKind { 28 MAK_ReadNone = 0, 29 MAK_ReadOnly = 1, 30 MAK_MayWrite = 2 31 }; 32 33 /// Returns the memory access properties of this copy of the function. 34 MemoryAccessKind computeFunctionBodyMemoryAccess(Function &F, AAResults &AAR); 35 36 /// Computes function attributes in post-order over the call graph. 37 /// 38 /// By operating in post-order, this pass computes precise attributes for 39 /// called functions prior to processsing their callers. This "bottom-up" 40 /// approach allows powerful interprocedural inference of function attributes 41 /// like memory access patterns, etc. It can discover functions that do not 42 /// access memory, or only read memory, and give them the readnone/readonly 43 /// attribute. It also discovers function arguments that are not captured by 44 /// the function and marks them with the nocapture attribute. 45 struct PostOrderFunctionAttrsPass : PassInfoMixin<PostOrderFunctionAttrsPass> { 46 PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &AM, 47 LazyCallGraph &CG, CGSCCUpdateResult &UR); 48 }; 49 50 /// Create a legacy pass manager instance of a pass to compute function attrs 51 /// in post-order. 52 Pass *createPostOrderFunctionAttrsLegacyPass(); 53 54 /// A pass to do RPO deduction and propagation of function attributes. 55 /// 56 /// This pass provides a general RPO or "top down" propagation of 57 /// function attributes. For a few (rare) cases, we can deduce significantly 58 /// more about function attributes by working in RPO, so this pass 59 /// provides the complement to the post-order pass above where the majority of 60 /// deduction is performed. 61 // FIXME: Currently there is no RPO CGSCC pass structure to slide into and so 62 // this is a boring module pass, but eventually it should be an RPO CGSCC pass 63 // when such infrastructure is available. 64 class ReversePostOrderFunctionAttrsPass 65 : public PassInfoMixin<ReversePostOrderFunctionAttrsPass> { 66 public: 67 PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM); 68 }; 69 } 70 71 #endif // LLVM_TRANSFORMS_IPO_FUNCTIONATTRS_H 72