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/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"
19 /// initializeAnalysis - Initialize all passes linked into the Analysis library.
20 void llvm::initializeAnalysis(PassRegistry
&Registry
) {
21 initializeBasicAAWrapperPassPass(Registry
);
22 initializeBlockFrequencyInfoWrapperPassPass(Registry
);
23 initializeBranchProbabilityInfoWrapperPassPass(Registry
);
24 initializeCallGraphWrapperPassPass(Registry
);
25 initializeCallGraphDOTPrinterPass(Registry
);
26 initializeCallGraphViewerPass(Registry
);
27 initializeCycleInfoWrapperPassPass(Registry
);
28 initializeDependenceAnalysisWrapperPassPass(Registry
);
29 initializeDominanceFrontierWrapperPassPass(Registry
);
30 initializeDomViewerWrapperPassPass(Registry
);
31 initializeDomPrinterWrapperPassPass(Registry
);
32 initializeDomOnlyViewerWrapperPassPass(Registry
);
33 initializePostDomViewerWrapperPassPass(Registry
);
34 initializeDomOnlyPrinterWrapperPassPass(Registry
);
35 initializePostDomPrinterWrapperPassPass(Registry
);
36 initializePostDomOnlyViewerWrapperPassPass(Registry
);
37 initializePostDomOnlyPrinterWrapperPassPass(Registry
);
38 initializeAAResultsWrapperPassPass(Registry
);
39 initializeGlobalsAAWrapperPassPass(Registry
);
40 initializeIVUsersWrapperPassPass(Registry
);
41 initializeIntervalPartitionPass(Registry
);
42 initializeIRSimilarityIdentifierWrapperPassPass(Registry
);
43 initializeLazyBranchProbabilityInfoPassPass(Registry
);
44 initializeLazyBlockFrequencyInfoPassPass(Registry
);
45 initializeLazyValueInfoWrapperPassPass(Registry
);
46 initializeLoopInfoWrapperPassPass(Registry
);
47 initializeMemoryDependenceWrapperPassPass(Registry
);
48 initializeModuleSummaryIndexWrapperPassPass(Registry
);
49 initializeOptimizationRemarkEmitterWrapperPassPass(Registry
);
50 initializePhiValuesWrapperPassPass(Registry
);
51 initializePostDominatorTreeWrapperPassPass(Registry
);
52 initializeRegionInfoPassPass(Registry
);
53 initializeRegionViewerPass(Registry
);
54 initializeRegionPrinterPass(Registry
);
55 initializeRegionOnlyViewerPass(Registry
);
56 initializeRegionOnlyPrinterPass(Registry
);
57 initializeSCEVAAWrapperPassPass(Registry
);
58 initializeScalarEvolutionWrapperPassPass(Registry
);
59 initializeStackSafetyGlobalInfoWrapperPassPass(Registry
);
60 initializeStackSafetyInfoWrapperPassPass(Registry
);
61 initializeTargetTransformInfoWrapperPassPass(Registry
);
62 initializeTypeBasedAAWrapperPassPass(Registry
);
63 initializeScopedNoAliasAAWrapperPassPass(Registry
);
64 initializeLCSSAVerificationPassPass(Registry
);
65 initializeMemorySSAWrapperPassPass(Registry
);
68 LLVMBool
LLVMVerifyModule(LLVMModuleRef M
, LLVMVerifierFailureAction Action
,
70 raw_ostream
*DebugOS
= Action
!= LLVMReturnStatusAction
? &errs() : nullptr;
72 raw_string_ostream
MsgsOS(Messages
);
74 LLVMBool Result
= verifyModule(*unwrap(M
), OutMessages
? &MsgsOS
: DebugOS
);
76 // Duplicate the output to stderr.
77 if (DebugOS
&& OutMessages
)
78 *DebugOS
<< MsgsOS
.str();
80 if (Action
== LLVMAbortProcessAction
&& Result
)
81 report_fatal_error("Broken module found, compilation aborted!");
84 *OutMessages
= strdup(MsgsOS
.str().c_str());
89 LLVMBool
LLVMVerifyFunction(LLVMValueRef Fn
, LLVMVerifierFailureAction Action
) {
90 LLVMBool Result
= verifyFunction(
91 *unwrap
<Function
>(Fn
), Action
!= LLVMReturnStatusAction
? &errs()
94 if (Action
== LLVMAbortProcessAction
&& Result
)
95 report_fatal_error("Broken function found, compilation aborted!");
100 void LLVMViewFunctionCFG(LLVMValueRef Fn
) {
101 Function
*F
= unwrap
<Function
>(Fn
);
105 void LLVMViewFunctionCFGOnly(LLVMValueRef Fn
) {
106 Function
*F
= unwrap
<Function
>(Fn
);