1327952Sdim//===- FunctionAttrs.h - Compute function attributes ------------*- C++ -*-===// 2303231Sdim// 3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4353358Sdim// See https://llvm.org/LICENSE.txt for license information. 5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6303231Sdim// 7303231Sdim//===----------------------------------------------------------------------===// 8327952Sdim// 9303231Sdim/// \file 10303231Sdim/// Provides passes for computing function attributes based on interprocedural 11303231Sdim/// analyses. 12327952Sdim// 13303231Sdim//===----------------------------------------------------------------------===// 14303231Sdim 15303231Sdim#ifndef LLVM_TRANSFORMS_IPO_FUNCTIONATTRS_H 16303231Sdim#define LLVM_TRANSFORMS_IPO_FUNCTIONATTRS_H 17303231Sdim 18321369Sdim#include "llvm/Analysis/CGSCCPassManager.h" 19303231Sdim#include "llvm/Analysis/LazyCallGraph.h" 20303231Sdim#include "llvm/IR/PassManager.h" 21303231Sdim 22303231Sdimnamespace llvm { 23303231Sdim 24321369Sdimclass AAResults; 25327952Sdimclass Function; 26327952Sdimclass Module; 27327952Sdimclass Pass; 28321369Sdim 29321369Sdim/// The three kinds of memory access relevant to 'readonly' and 30321369Sdim/// 'readnone' attributes. 31321369Sdimenum MemoryAccessKind { 32321369Sdim MAK_ReadNone = 0, 33321369Sdim MAK_ReadOnly = 1, 34344779Sdim MAK_MayWrite = 2, 35344779Sdim MAK_WriteOnly = 3 36321369Sdim}; 37321369Sdim 38321369Sdim/// Returns the memory access properties of this copy of the function. 39321369SdimMemoryAccessKind computeFunctionBodyMemoryAccess(Function &F, AAResults &AAR); 40321369Sdim 41303231Sdim/// Computes function attributes in post-order over the call graph. 42303231Sdim/// 43303231Sdim/// By operating in post-order, this pass computes precise attributes for 44303231Sdim/// called functions prior to processsing their callers. This "bottom-up" 45303231Sdim/// approach allows powerful interprocedural inference of function attributes 46303231Sdim/// like memory access patterns, etc. It can discover functions that do not 47303231Sdim/// access memory, or only read memory, and give them the readnone/readonly 48303231Sdim/// attribute. It also discovers function arguments that are not captured by 49303231Sdim/// the function and marks them with the nocapture attribute. 50303231Sdimstruct PostOrderFunctionAttrsPass : PassInfoMixin<PostOrderFunctionAttrsPass> { 51314564Sdim PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &AM, 52314564Sdim LazyCallGraph &CG, CGSCCUpdateResult &UR); 53303231Sdim}; 54303231Sdim 55303231Sdim/// Create a legacy pass manager instance of a pass to compute function attrs 56303231Sdim/// in post-order. 57303231SdimPass *createPostOrderFunctionAttrsLegacyPass(); 58303231Sdim 59303231Sdim/// A pass to do RPO deduction and propagation of function attributes. 60303231Sdim/// 61303231Sdim/// This pass provides a general RPO or "top down" propagation of 62303231Sdim/// function attributes. For a few (rare) cases, we can deduce significantly 63303231Sdim/// more about function attributes by working in RPO, so this pass 64321369Sdim/// provides the complement to the post-order pass above where the majority of 65303231Sdim/// deduction is performed. 66303231Sdim// FIXME: Currently there is no RPO CGSCC pass structure to slide into and so 67303231Sdim// this is a boring module pass, but eventually it should be an RPO CGSCC pass 68303231Sdim// when such infrastructure is available. 69303231Sdimclass ReversePostOrderFunctionAttrsPass 70303231Sdim : public PassInfoMixin<ReversePostOrderFunctionAttrsPass> { 71303231Sdimpublic: 72314564Sdim PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM); 73303231Sdim}; 74303231Sdim 75327952Sdim} // end namespace llvm 76327952Sdim 77303231Sdim#endif // LLVM_TRANSFORMS_IPO_FUNCTIONATTRS_H 78