Analysis.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. //===-- Analysis.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. #include "llvm-c/Analysis.h"
  9. #include "llvm-c/Initialization.h"
  10. #include "llvm/IR/Module.h"
  11. #include "llvm/IR/Verifier.h"
  12. #include "llvm/InitializePasses.h"
  13. #include "llvm/PassRegistry.h"
  14. #include "llvm/Support/raw_ostream.h"
  15. #include <cstring>
  16. using namespace llvm;
  17. /// initializeAnalysis - Initialize all passes linked into the Analysis library.
  18. void llvm::initializeAnalysis(PassRegistry &Registry) {
  19. initializeAAEvalLegacyPassPass(Registry);
  20. initializeBasicAAWrapperPassPass(Registry);
  21. initializeBlockFrequencyInfoWrapperPassPass(Registry);
  22. initializeBranchProbabilityInfoWrapperPassPass(Registry);
  23. initializeCallGraphWrapperPassPass(Registry);
  24. initializeCallGraphDOTPrinterPass(Registry);
  25. initializeCallGraphPrinterLegacyPassPass(Registry);
  26. initializeCallGraphViewerPass(Registry);
  27. initializeCostModelAnalysisPass(Registry);
  28. initializeCFGViewerLegacyPassPass(Registry);
  29. initializeCFGPrinterLegacyPassPass(Registry);
  30. initializeCFGOnlyViewerLegacyPassPass(Registry);
  31. initializeCFGOnlyPrinterLegacyPassPass(Registry);
  32. initializeCycleInfoWrapperPassPass(Registry);
  33. initializeDependenceAnalysisWrapperPassPass(Registry);
  34. initializeDelinearizationPass(Registry);
  35. initializeDemandedBitsWrapperPassPass(Registry);
  36. initializeDominanceFrontierWrapperPassPass(Registry);
  37. initializeDomViewerWrapperPassPass(Registry);
  38. initializeDomPrinterWrapperPassPass(Registry);
  39. initializeDomOnlyViewerWrapperPassPass(Registry);
  40. initializePostDomViewerWrapperPassPass(Registry);
  41. initializeDomOnlyPrinterWrapperPassPass(Registry);
  42. initializePostDomPrinterWrapperPassPass(Registry);
  43. initializePostDomOnlyViewerWrapperPassPass(Registry);
  44. initializePostDomOnlyPrinterWrapperPassPass(Registry);
  45. initializeAAResultsWrapperPassPass(Registry);
  46. initializeGlobalsAAWrapperPassPass(Registry);
  47. initializeIVUsersWrapperPassPass(Registry);
  48. initializeInstCountLegacyPassPass(Registry);
  49. initializeIntervalPartitionPass(Registry);
  50. initializeIRSimilarityIdentifierWrapperPassPass(Registry);
  51. initializeLazyBranchProbabilityInfoPassPass(Registry);
  52. initializeLazyBlockFrequencyInfoPassPass(Registry);
  53. initializeLazyValueInfoWrapperPassPass(Registry);
  54. initializeLazyValueInfoPrinterPass(Registry);
  55. initializeLegacyDivergenceAnalysisPass(Registry);
  56. initializeLintLegacyPassPass(Registry);
  57. initializeLoopInfoWrapperPassPass(Registry);
  58. initializeMemDepPrinterPass(Registry);
  59. initializeMemDerefPrinterPass(Registry);
  60. initializeMemoryDependenceWrapperPassPass(Registry);
  61. initializeModuleDebugInfoLegacyPrinterPass(Registry);
  62. initializeModuleSummaryIndexWrapperPassPass(Registry);
  63. initializeMustExecutePrinterPass(Registry);
  64. initializeMustBeExecutedContextPrinterPass(Registry);
  65. initializeOptimizationRemarkEmitterWrapperPassPass(Registry);
  66. initializePhiValuesWrapperPassPass(Registry);
  67. initializePostDominatorTreeWrapperPassPass(Registry);
  68. initializeRegionInfoPassPass(Registry);
  69. initializeRegionViewerPass(Registry);
  70. initializeRegionPrinterPass(Registry);
  71. initializeRegionOnlyViewerPass(Registry);
  72. initializeRegionOnlyPrinterPass(Registry);
  73. initializeSCEVAAWrapperPassPass(Registry);
  74. initializeScalarEvolutionWrapperPassPass(Registry);
  75. initializeStackSafetyGlobalInfoWrapperPassPass(Registry);
  76. initializeStackSafetyInfoWrapperPassPass(Registry);
  77. initializeTargetTransformInfoWrapperPassPass(Registry);
  78. initializeTypeBasedAAWrapperPassPass(Registry);
  79. initializeScopedNoAliasAAWrapperPassPass(Registry);
  80. initializeLCSSAVerificationPassPass(Registry);
  81. initializeMemorySSAWrapperPassPass(Registry);
  82. initializeMemorySSAPrinterLegacyPassPass(Registry);
  83. }
  84. void LLVMInitializeAnalysis(LLVMPassRegistryRef R) {
  85. initializeAnalysis(*unwrap(R));
  86. }
  87. void LLVMInitializeIPA(LLVMPassRegistryRef R) {
  88. initializeAnalysis(*unwrap(R));
  89. }
  90. LLVMBool LLVMVerifyModule(LLVMModuleRef M, LLVMVerifierFailureAction Action,
  91. char **OutMessages) {
  92. raw_ostream *DebugOS = Action != LLVMReturnStatusAction ? &errs() : nullptr;
  93. std::string Messages;
  94. raw_string_ostream MsgsOS(Messages);
  95. LLVMBool Result = verifyModule(*unwrap(M), OutMessages ? &MsgsOS : DebugOS);
  96. // Duplicate the output to stderr.
  97. if (DebugOS && OutMessages)
  98. *DebugOS << MsgsOS.str();
  99. if (Action == LLVMAbortProcessAction && Result)
  100. report_fatal_error("Broken module found, compilation aborted!");
  101. if (OutMessages)
  102. *OutMessages = strdup(MsgsOS.str().c_str());
  103. return Result;
  104. }
  105. LLVMBool LLVMVerifyFunction(LLVMValueRef Fn, LLVMVerifierFailureAction Action) {
  106. LLVMBool Result = verifyFunction(
  107. *unwrap<Function>(Fn), Action != LLVMReturnStatusAction ? &errs()
  108. : nullptr);
  109. if (Action == LLVMAbortProcessAction && Result)
  110. report_fatal_error("Broken function found, compilation aborted!");
  111. return Result;
  112. }
  113. void LLVMViewFunctionCFG(LLVMValueRef Fn) {
  114. Function *F = unwrap<Function>(Fn);
  115. F->viewCFG();
  116. }
  117. void LLVMViewFunctionCFGOnly(LLVMValueRef Fn) {
  118. Function *F = unwrap<Function>(Fn);
  119. F->viewCFGOnly();
  120. }