1 //===- FunctionAttrs.h - Compute function attributes ------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 /// \file 10 /// Provides passes for computing function attributes based on interprocedural 11 /// analyses. 12 // 13 //===----------------------------------------------------------------------===// 14 15 #ifndef LLVM_TRANSFORMS_IPO_FUNCTIONATTRS_H 16 #define LLVM_TRANSFORMS_IPO_FUNCTIONATTRS_H 17 18 #include "llvm/Analysis/AliasAnalysis.h" 19 #include "llvm/Analysis/CGSCCPassManager.h" 20 #include "llvm/Analysis/LazyCallGraph.h" 21 #include "llvm/IR/PassManager.h" 22 23 namespace llvm { 24 25 class GlobalValueSummary; 26 class ModuleSummaryIndex; 27 class Function; 28 class Module; 29 30 /// Returns the memory access properties of this copy of the function. 31 MemoryEffects computeFunctionBodyMemoryAccess(Function &F, AAResults &AAR); 32 33 /// Propagate function attributes for function summaries along the index's 34 /// callgraph during thinlink 35 bool thinLTOPropagateFunctionAttrs( 36 ModuleSummaryIndex &Index, 37 function_ref<bool(GlobalValue::GUID, const GlobalValueSummary *)> 38 isPrevailing); 39 40 /// Computes function attributes in post-order over the call graph. 41 /// 42 /// By operating in post-order, this pass computes precise attributes for 43 /// called functions prior to processsing their callers. This "bottom-up" 44 /// approach allows powerful interprocedural inference of function attributes 45 /// like memory access patterns, etc. It can discover functions that do not 46 /// access memory, or only read memory, and give them the readnone/readonly 47 /// attribute. It also discovers function arguments that are not captured by 48 /// the function and marks them with the nocapture attribute. 49 struct PostOrderFunctionAttrsPass : PassInfoMixin<PostOrderFunctionAttrsPass> { 50 PostOrderFunctionAttrsPass(bool SkipNonRecursive = false) SkipNonRecursivePostOrderFunctionAttrsPass51 : SkipNonRecursive(SkipNonRecursive) {} 52 PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &AM, 53 LazyCallGraph &CG, CGSCCUpdateResult &UR); 54 55 void printPipeline(raw_ostream &OS, 56 function_ref<StringRef(StringRef)> MapClassName2PassName); 57 58 private: 59 bool SkipNonRecursive; 60 }; 61 62 /// A pass to do RPO deduction and propagation of function attributes. 63 /// 64 /// This pass provides a general RPO or "top down" propagation of 65 /// function attributes. For a few (rare) cases, we can deduce significantly 66 /// more about function attributes by working in RPO, so this pass 67 /// provides the complement to the post-order pass above where the majority of 68 /// deduction is performed. 69 // FIXME: Currently there is no RPO CGSCC pass structure to slide into and so 70 // this is a boring module pass, but eventually it should be an RPO CGSCC pass 71 // when such infrastructure is available. 72 class ReversePostOrderFunctionAttrsPass 73 : public PassInfoMixin<ReversePostOrderFunctionAttrsPass> { 74 public: 75 PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM); 76 }; 77 78 } // end namespace llvm 79 80 #endif // LLVM_TRANSFORMS_IPO_FUNCTIONATTRS_H 81