1 //===-- Analysis.cpp ------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "llvm-c/Analysis.h"
10 #include "llvm-c/Initialization.h"
11 #include "llvm/IR/Module.h"
12 #include "llvm/IR/Verifier.h"
13 #include "llvm/InitializePasses.h"
14 #include "llvm/PassRegistry.h"
15 #include "llvm/Support/raw_ostream.h"
20 /// initializeAnalysis - Initialize all passes linked into the Analysis library.
21 void llvm::initializeAnalysis(PassRegistry
&Registry
) {
22 initializeAAEvalLegacyPassPass(Registry
);
23 initializeAliasSetPrinterPass(Registry
);
24 initializeBasicAAWrapperPassPass(Registry
);
25 initializeBlockFrequencyInfoWrapperPassPass(Registry
);
26 initializeBranchProbabilityInfoWrapperPassPass(Registry
);
27 initializeCallGraphWrapperPassPass(Registry
);
28 initializeCallGraphDOTPrinterPass(Registry
);
29 initializeCallGraphPrinterLegacyPassPass(Registry
);
30 initializeCallGraphViewerPass(Registry
);
31 initializeCostModelAnalysisPass(Registry
);
32 initializeCFGViewerLegacyPassPass(Registry
);
33 initializeCFGPrinterLegacyPassPass(Registry
);
34 initializeCFGOnlyViewerLegacyPassPass(Registry
);
35 initializeCFGOnlyPrinterLegacyPassPass(Registry
);
36 initializeCFLAndersAAWrapperPassPass(Registry
);
37 initializeCFLSteensAAWrapperPassPass(Registry
);
38 initializeDependenceAnalysisWrapperPassPass(Registry
);
39 initializeDelinearizationPass(Registry
);
40 initializeDemandedBitsWrapperPassPass(Registry
);
41 initializeDominanceFrontierWrapperPassPass(Registry
);
42 initializeDomViewerPass(Registry
);
43 initializeDomPrinterPass(Registry
);
44 initializeDomOnlyViewerPass(Registry
);
45 initializePostDomViewerPass(Registry
);
46 initializeDomOnlyPrinterPass(Registry
);
47 initializePostDomPrinterPass(Registry
);
48 initializePostDomOnlyViewerPass(Registry
);
49 initializePostDomOnlyPrinterPass(Registry
);
50 initializeAAResultsWrapperPassPass(Registry
);
51 initializeGlobalsAAWrapperPassPass(Registry
);
52 initializeIVUsersWrapperPassPass(Registry
);
53 initializeInstCountPass(Registry
);
54 initializeIntervalPartitionPass(Registry
);
55 initializeLazyBranchProbabilityInfoPassPass(Registry
);
56 initializeLazyBlockFrequencyInfoPassPass(Registry
);
57 initializeLazyValueInfoWrapperPassPass(Registry
);
58 initializeLazyValueInfoPrinterPass(Registry
);
59 initializeLegacyDivergenceAnalysisPass(Registry
);
60 initializeLintPass(Registry
);
61 initializeLoopInfoWrapperPassPass(Registry
);
62 initializeMemDepPrinterPass(Registry
);
63 initializeMemDerefPrinterPass(Registry
);
64 initializeMemoryDependenceWrapperPassPass(Registry
);
65 initializeModuleDebugInfoPrinterPass(Registry
);
66 initializeModuleSummaryIndexWrapperPassPass(Registry
);
67 initializeMustExecutePrinterPass(Registry
);
68 initializeObjCARCAAWrapperPassPass(Registry
);
69 initializeOptimizationRemarkEmitterWrapperPassPass(Registry
);
70 initializePhiValuesWrapperPassPass(Registry
);
71 initializePostDominatorTreeWrapperPassPass(Registry
);
72 initializeRegionInfoPassPass(Registry
);
73 initializeRegionViewerPass(Registry
);
74 initializeRegionPrinterPass(Registry
);
75 initializeRegionOnlyViewerPass(Registry
);
76 initializeRegionOnlyPrinterPass(Registry
);
77 initializeSCEVAAWrapperPassPass(Registry
);
78 initializeScalarEvolutionWrapperPassPass(Registry
);
79 initializeStackSafetyGlobalInfoWrapperPassPass(Registry
);
80 initializeStackSafetyInfoWrapperPassPass(Registry
);
81 initializeTargetTransformInfoWrapperPassPass(Registry
);
82 initializeTypeBasedAAWrapperPassPass(Registry
);
83 initializeScopedNoAliasAAWrapperPassPass(Registry
);
84 initializeLCSSAVerificationPassPass(Registry
);
85 initializeMemorySSAWrapperPassPass(Registry
);
86 initializeMemorySSAPrinterLegacyPassPass(Registry
);
89 void LLVMInitializeAnalysis(LLVMPassRegistryRef R
) {
90 initializeAnalysis(*unwrap(R
));
93 void LLVMInitializeIPA(LLVMPassRegistryRef R
) {
94 initializeAnalysis(*unwrap(R
));
97 LLVMBool
LLVMVerifyModule(LLVMModuleRef M
, LLVMVerifierFailureAction Action
,
99 raw_ostream
*DebugOS
= Action
!= LLVMReturnStatusAction
? &errs() : nullptr;
100 std::string Messages
;
101 raw_string_ostream
MsgsOS(Messages
);
103 LLVMBool Result
= verifyModule(*unwrap(M
), OutMessages
? &MsgsOS
: DebugOS
);
105 // Duplicate the output to stderr.
106 if (DebugOS
&& OutMessages
)
107 *DebugOS
<< MsgsOS
.str();
109 if (Action
== LLVMAbortProcessAction
&& Result
)
110 report_fatal_error("Broken module found, compilation aborted!");
113 *OutMessages
= strdup(MsgsOS
.str().c_str());
118 LLVMBool
LLVMVerifyFunction(LLVMValueRef Fn
, LLVMVerifierFailureAction Action
) {
119 LLVMBool Result
= verifyFunction(
120 *unwrap
<Function
>(Fn
), Action
!= LLVMReturnStatusAction
? &errs()
123 if (Action
== LLVMAbortProcessAction
&& Result
)
124 report_fatal_error("Broken function found, compilation aborted!");
129 void LLVMViewFunctionCFG(LLVMValueRef Fn
) {
130 Function
*F
= unwrap
<Function
>(Fn
);
134 void LLVMViewFunctionCFGOnly(LLVMValueRef Fn
) {
135 Function
*F
= unwrap
<Function
>(Fn
);