IPO.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. //===-- IPO.cpp -----------------------------------------------------------===//
  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. // This file implements the common infrastructure (including C bindings) for
  10. // libLLVMIPO.a, which implements several transformations over the LLVM
  11. // intermediate representation.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #include "llvm-c/Transforms/IPO.h"
  15. #include "llvm-c/Initialization.h"
  16. #include "llvm/IR/LegacyPassManager.h"
  17. #include "llvm/InitializePasses.h"
  18. #include "llvm/Transforms/IPO.h"
  19. #include "llvm/Transforms/IPO/AlwaysInliner.h"
  20. #include "llvm/Transforms/IPO/FunctionAttrs.h"
  21. using namespace llvm;
  22. void llvm::initializeIPO(PassRegistry &Registry) {
  23. initializeAnnotation2MetadataLegacyPass(Registry);
  24. initializeCalledValuePropagationLegacyPassPass(Registry);
  25. initializeConstantMergeLegacyPassPass(Registry);
  26. initializeCrossDSOCFIPass(Registry);
  27. initializeDAEPass(Registry);
  28. initializeDAHPass(Registry);
  29. initializeForceFunctionAttrsLegacyPassPass(Registry);
  30. initializeGlobalDCELegacyPassPass(Registry);
  31. initializeGlobalOptLegacyPassPass(Registry);
  32. initializeGlobalSplitPass(Registry);
  33. initializeHotColdSplittingLegacyPassPass(Registry);
  34. initializeIROutlinerLegacyPassPass(Registry);
  35. initializeAlwaysInlinerLegacyPassPass(Registry);
  36. initializeSimpleInlinerPass(Registry);
  37. initializeInferFunctionAttrsLegacyPassPass(Registry);
  38. initializeInternalizeLegacyPassPass(Registry);
  39. initializeLoopExtractorLegacyPassPass(Registry);
  40. initializeSingleLoopExtractorPass(Registry);
  41. initializeMergeFunctionsLegacyPassPass(Registry);
  42. initializePartialInlinerLegacyPassPass(Registry);
  43. initializeAttributorLegacyPassPass(Registry);
  44. initializeAttributorCGSCCLegacyPassPass(Registry);
  45. initializePostOrderFunctionAttrsLegacyPassPass(Registry);
  46. initializeReversePostOrderFunctionAttrsLegacyPassPass(Registry);
  47. initializeIPSCCPLegacyPassPass(Registry);
  48. initializeStripDeadPrototypesLegacyPassPass(Registry);
  49. initializeStripSymbolsPass(Registry);
  50. initializeStripDebugDeclarePass(Registry);
  51. initializeStripDeadDebugInfoPass(Registry);
  52. initializeStripNonDebugSymbolsPass(Registry);
  53. initializeBarrierNoopPass(Registry);
  54. initializeEliminateAvailableExternallyLegacyPassPass(Registry);
  55. }
  56. void LLVMInitializeIPO(LLVMPassRegistryRef R) {
  57. initializeIPO(*unwrap(R));
  58. }
  59. void LLVMAddCalledValuePropagationPass(LLVMPassManagerRef PM) {
  60. unwrap(PM)->add(createCalledValuePropagationPass());
  61. }
  62. void LLVMAddConstantMergePass(LLVMPassManagerRef PM) {
  63. unwrap(PM)->add(createConstantMergePass());
  64. }
  65. void LLVMAddDeadArgEliminationPass(LLVMPassManagerRef PM) {
  66. unwrap(PM)->add(createDeadArgEliminationPass());
  67. }
  68. void LLVMAddFunctionAttrsPass(LLVMPassManagerRef PM) {
  69. unwrap(PM)->add(createPostOrderFunctionAttrsLegacyPass());
  70. }
  71. void LLVMAddFunctionInliningPass(LLVMPassManagerRef PM) {
  72. unwrap(PM)->add(createFunctionInliningPass());
  73. }
  74. void LLVMAddAlwaysInlinerPass(LLVMPassManagerRef PM) {
  75. unwrap(PM)->add(llvm::createAlwaysInlinerLegacyPass());
  76. }
  77. void LLVMAddGlobalDCEPass(LLVMPassManagerRef PM) {
  78. unwrap(PM)->add(createGlobalDCEPass());
  79. }
  80. void LLVMAddGlobalOptimizerPass(LLVMPassManagerRef PM) {
  81. unwrap(PM)->add(createGlobalOptimizerPass());
  82. }
  83. void LLVMAddIPSCCPPass(LLVMPassManagerRef PM) {
  84. unwrap(PM)->add(createIPSCCPPass());
  85. }
  86. void LLVMAddMergeFunctionsPass(LLVMPassManagerRef PM) {
  87. unwrap(PM)->add(createMergeFunctionsPass());
  88. }
  89. void LLVMAddInternalizePass(LLVMPassManagerRef PM, unsigned AllButMain) {
  90. auto PreserveMain = [=](const GlobalValue &GV) {
  91. return AllButMain && GV.getName() == "main";
  92. };
  93. unwrap(PM)->add(createInternalizePass(PreserveMain));
  94. }
  95. void LLVMAddInternalizePassWithMustPreservePredicate(
  96. LLVMPassManagerRef PM,
  97. void *Context,
  98. LLVMBool (*Pred)(LLVMValueRef, void *)) {
  99. unwrap(PM)->add(createInternalizePass([=](const GlobalValue &GV) {
  100. return Pred(wrap(&GV), Context) == 0 ? false : true;
  101. }));
  102. }
  103. void LLVMAddStripDeadPrototypesPass(LLVMPassManagerRef PM) {
  104. unwrap(PM)->add(createStripDeadPrototypesPass());
  105. }
  106. void LLVMAddStripSymbolsPass(LLVMPassManagerRef PM) {
  107. unwrap(PM)->add(createStripSymbolsPass());
  108. }