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 initializeInstCountLegacyPassPass(Registry
);
54 initializeIntervalPartitionPass(Registry
);
55 initializeIRSimilarityIdentifierWrapperPassPass(Registry
);
56 initializeLazyBranchProbabilityInfoPassPass(Registry
);
57 initializeLazyBlockFrequencyInfoPassPass(Registry
);
58 initializeLazyValueInfoWrapperPassPass(Registry
);
59 initializeLazyValueInfoPrinterPass(Registry
);
60 initializeLegacyDivergenceAnalysisPass(Registry
);
61 initializeLintLegacyPassPass(Registry
);
62 initializeLoopInfoWrapperPassPass(Registry
);
63 initializeMemDepPrinterPass(Registry
);
64 initializeMemDerefPrinterPass(Registry
);
65 initializeMemoryDependenceWrapperPassPass(Registry
);
66 initializeModuleDebugInfoLegacyPrinterPass(Registry
);
67 initializeModuleSummaryIndexWrapperPassPass(Registry
);
68 initializeMustExecutePrinterPass(Registry
);
69 initializeMustBeExecutedContextPrinterPass(Registry
);
70 initializeObjCARCAAWrapperPassPass(Registry
);
71 initializeOptimizationRemarkEmitterWrapperPassPass(Registry
);
72 initializePhiValuesWrapperPassPass(Registry
);
73 initializePostDominatorTreeWrapperPassPass(Registry
);
74 initializeRegionInfoPassPass(Registry
);
75 initializeRegionViewerPass(Registry
);
76 initializeRegionPrinterPass(Registry
);
77 initializeRegionOnlyViewerPass(Registry
);
78 initializeRegionOnlyPrinterPass(Registry
);
79 initializeSCEVAAWrapperPassPass(Registry
);
80 initializeScalarEvolutionWrapperPassPass(Registry
);
81 initializeStackSafetyGlobalInfoWrapperPassPass(Registry
);
82 initializeStackSafetyInfoWrapperPassPass(Registry
);
83 initializeTargetTransformInfoWrapperPassPass(Registry
);
84 initializeTypeBasedAAWrapperPassPass(Registry
);
85 initializeScopedNoAliasAAWrapperPassPass(Registry
);
86 initializeLCSSAVerificationPassPass(Registry
);
87 initializeMemorySSAWrapperPassPass(Registry
);
88 initializeMemorySSAPrinterLegacyPassPass(Registry
);
91 void LLVMInitializeAnalysis(LLVMPassRegistryRef R
) {
92 initializeAnalysis(*unwrap(R
));
95 void LLVMInitializeIPA(LLVMPassRegistryRef R
) {
96 initializeAnalysis(*unwrap(R
));
99 LLVMBool
LLVMVerifyModule(LLVMModuleRef M
, LLVMVerifierFailureAction Action
,
100 char **OutMessages
) {
101 raw_ostream
*DebugOS
= Action
!= LLVMReturnStatusAction
? &errs() : nullptr;
102 std::string Messages
;
103 raw_string_ostream
MsgsOS(Messages
);
105 LLVMBool Result
= verifyModule(*unwrap(M
), OutMessages
? &MsgsOS
: DebugOS
);
107 // Duplicate the output to stderr.
108 if (DebugOS
&& OutMessages
)
109 *DebugOS
<< MsgsOS
.str();
111 if (Action
== LLVMAbortProcessAction
&& Result
)
112 report_fatal_error("Broken module found, compilation aborted!");
115 *OutMessages
= strdup(MsgsOS
.str().c_str());
120 LLVMBool
LLVMVerifyFunction(LLVMValueRef Fn
, LLVMVerifierFailureAction Action
) {
121 LLVMBool Result
= verifyFunction(
122 *unwrap
<Function
>(Fn
), Action
!= LLVMReturnStatusAction
? &errs()
125 if (Action
== LLVMAbortProcessAction
&& Result
)
126 report_fatal_error("Broken function found, compilation aborted!");
131 void LLVMViewFunctionCFG(LLVMValueRef Fn
) {
132 Function
*F
= unwrap
<Function
>(Fn
);
136 void LLVMViewFunctionCFGOnly(LLVMValueRef Fn
) {
137 Function
*F
= unwrap
<Function
>(Fn
);