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 initializeDXILResourceBindingWrapperPassPass(Registry
);
29 initializeDXILResourceTypeWrapperPassPass(Registry
);
30 initializeDependenceAnalysisWrapperPassPass(Registry
);
31 initializeDominanceFrontierWrapperPassPass(Registry
);
32 initializeDomViewerWrapperPassPass(Registry
);
33 initializeDomPrinterWrapperPassPass(Registry
);
34 initializeDomOnlyViewerWrapperPassPass(Registry
);
35 initializePostDomViewerWrapperPassPass(Registry
);
36 initializeDomOnlyPrinterWrapperPassPass(Registry
);
37 initializePostDomPrinterWrapperPassPass(Registry
);
38 initializePostDomOnlyViewerWrapperPassPass(Registry
);
39 initializePostDomOnlyPrinterWrapperPassPass(Registry
);
40 initializeAAResultsWrapperPassPass(Registry
);
41 initializeGlobalsAAWrapperPassPass(Registry
);
42 initializeIVUsersWrapperPassPass(Registry
);
43 initializeIRSimilarityIdentifierWrapperPassPass(Registry
);
44 initializeLazyBranchProbabilityInfoPassPass(Registry
);
45 initializeLazyBlockFrequencyInfoPassPass(Registry
);
46 initializeLazyValueInfoWrapperPassPass(Registry
);
47 initializeLoopInfoWrapperPassPass(Registry
);
48 initializeMemoryDependenceWrapperPassPass(Registry
);
49 initializeModuleSummaryIndexWrapperPassPass(Registry
);
50 initializeOptimizationRemarkEmitterWrapperPassPass(Registry
);
51 initializePhiValuesWrapperPassPass(Registry
);
52 initializePostDominatorTreeWrapperPassPass(Registry
);
53 initializeRegionInfoPassPass(Registry
);
54 initializeRegionViewerPass(Registry
);
55 initializeRegionPrinterPass(Registry
);
56 initializeRegionOnlyViewerPass(Registry
);
57 initializeRegionOnlyPrinterPass(Registry
);
58 initializeSCEVAAWrapperPassPass(Registry
);
59 initializeScalarEvolutionWrapperPassPass(Registry
);
60 initializeStackSafetyGlobalInfoWrapperPassPass(Registry
);
61 initializeStackSafetyInfoWrapperPassPass(Registry
);
62 initializeTargetTransformInfoWrapperPassPass(Registry
);
63 initializeTypeBasedAAWrapperPassPass(Registry
);
64 initializeScopedNoAliasAAWrapperPassPass(Registry
);
65 initializeLCSSAVerificationPassPass(Registry
);
66 initializeMemorySSAWrapperPassPass(Registry
);
69 LLVMBool
LLVMVerifyModule(LLVMModuleRef M
, LLVMVerifierFailureAction Action
,
71 raw_ostream
*DebugOS
= Action
!= LLVMReturnStatusAction
? &errs() : nullptr;
73 raw_string_ostream
MsgsOS(Messages
);
75 LLVMBool Result
= verifyModule(*unwrap(M
), OutMessages
? &MsgsOS
: DebugOS
);
77 // Duplicate the output to stderr.
78 if (DebugOS
&& OutMessages
)
79 *DebugOS
<< MsgsOS
.str();
81 if (Action
== LLVMAbortProcessAction
&& Result
)
82 report_fatal_error("Broken module found, compilation aborted!");
85 *OutMessages
= strdup(MsgsOS
.str().c_str());
90 LLVMBool
LLVMVerifyFunction(LLVMValueRef Fn
, LLVMVerifierFailureAction Action
) {
91 LLVMBool Result
= verifyFunction(
92 *unwrap
<Function
>(Fn
), Action
!= LLVMReturnStatusAction
? &errs()
95 if (Action
== LLVMAbortProcessAction
&& Result
)
96 report_fatal_error("Broken function found, compilation aborted!");
101 void LLVMViewFunctionCFG(LLVMValueRef Fn
) {
102 Function
*F
= unwrap
<Function
>(Fn
);
106 void LLVMViewFunctionCFGOnly(LLVMValueRef Fn
) {
107 Function
*F
= unwrap
<Function
>(Fn
);