FunctionAttrs.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- FunctionAttrs.h - Compute function attributes ------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. /// \file
  15. /// Provides passes for computing function attributes based on interprocedural
  16. /// analyses.
  17. //
  18. //===----------------------------------------------------------------------===//
  19. #ifndef LLVM_TRANSFORMS_IPO_FUNCTIONATTRS_H
  20. #define LLVM_TRANSFORMS_IPO_FUNCTIONATTRS_H
  21. #include "llvm/Analysis/CGSCCPassManager.h"
  22. #include "llvm/Analysis/LazyCallGraph.h"
  23. #include "llvm/IR/ModuleSummaryIndex.h"
  24. #include "llvm/IR/PassManager.h"
  25. namespace llvm {
  26. class AAResults;
  27. class Function;
  28. class Module;
  29. class Pass;
  30. /// The three kinds of memory access relevant to 'readonly' and
  31. /// 'readnone' attributes.
  32. enum MemoryAccessKind {
  33. MAK_ReadNone = 0,
  34. MAK_ReadOnly = 1,
  35. MAK_MayWrite = 2,
  36. MAK_WriteOnly = 3
  37. };
  38. /// Returns the memory access properties of this copy of the function.
  39. MemoryAccessKind computeFunctionBodyMemoryAccess(Function &F, AAResults &AAR);
  40. /// Propagate function attributes for function summaries along the index's
  41. /// callgraph during thinlink
  42. bool thinLTOPropagateFunctionAttrs(
  43. ModuleSummaryIndex &Index,
  44. function_ref<bool(GlobalValue::GUID, const GlobalValueSummary *)>
  45. isPrevailing);
  46. /// Computes function attributes in post-order over the call graph.
  47. ///
  48. /// By operating in post-order, this pass computes precise attributes for
  49. /// called functions prior to processsing their callers. This "bottom-up"
  50. /// approach allows powerful interprocedural inference of function attributes
  51. /// like memory access patterns, etc. It can discover functions that do not
  52. /// access memory, or only read memory, and give them the readnone/readonly
  53. /// attribute. It also discovers function arguments that are not captured by
  54. /// the function and marks them with the nocapture attribute.
  55. struct PostOrderFunctionAttrsPass : PassInfoMixin<PostOrderFunctionAttrsPass> {
  56. PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &AM,
  57. LazyCallGraph &CG, CGSCCUpdateResult &UR);
  58. };
  59. /// Create a legacy pass manager instance of a pass to compute function attrs
  60. /// in post-order.
  61. Pass *createPostOrderFunctionAttrsLegacyPass();
  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. } // end namespace llvm
  78. #endif // LLVM_TRANSFORMS_IPO_FUNCTIONATTRS_H
  79. #ifdef __GNUC__
  80. #pragma GCC diagnostic pop
  81. #endif