FunctionAttrs.h 3.2 KB

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