1 //===-- Analysis.cpp ------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "llvm-c/Analysis.h"
11 #include "llvm-c/Initialization.h"
12 #include "llvm/IR/Module.h"
13 #include "llvm/IR/Verifier.h"
14 #include "llvm/InitializePasses.h"
15 #include "llvm/PassRegistry.h"
16 #include "llvm/Support/raw_ostream.h"
17 #include <cstring>
18
19 using namespace llvm;
20
21 /// initializeAnalysis - Initialize all passes linked into the Analysis library.
initializeAnalysis(PassRegistry & Registry)22 void llvm::initializeAnalysis(PassRegistry &Registry) {
23 initializeAliasAnalysisAnalysisGroup(Registry);
24 initializeAliasAnalysisCounterPass(Registry);
25 initializeAAEvalPass(Registry);
26 initializeAliasDebuggerPass(Registry);
27 initializeAliasSetPrinterPass(Registry);
28 initializeNoAAPass(Registry);
29 initializeBasicAliasAnalysisPass(Registry);
30 initializeBlockFrequencyInfoPass(Registry);
31 initializeBranchProbabilityInfoPass(Registry);
32 initializeCostModelAnalysisPass(Registry);
33 initializeCFGViewerPass(Registry);
34 initializeCFGPrinterPass(Registry);
35 initializeCFGOnlyViewerPass(Registry);
36 initializeCFGOnlyPrinterPass(Registry);
37 initializeCFLAliasAnalysisPass(Registry);
38 initializeDependenceAnalysisPass(Registry);
39 initializeDelinearizationPass(Registry);
40 initializeDivergenceAnalysisPass(Registry);
41 initializeDominanceFrontierPass(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 initializeIVUsersPass(Registry);
51 initializeInstCountPass(Registry);
52 initializeIntervalPartitionPass(Registry);
53 initializeLazyValueInfoPass(Registry);
54 initializeLibCallAliasAnalysisPass(Registry);
55 initializeLintPass(Registry);
56 initializeLoopInfoWrapperPassPass(Registry);
57 initializeMemDepPrinterPass(Registry);
58 initializeMemDerefPrinterPass(Registry);
59 initializeMemoryDependenceAnalysisPass(Registry);
60 initializeModuleDebugInfoPrinterPass(Registry);
61 initializePostDominatorTreePass(Registry);
62 initializeRegionInfoPassPass(Registry);
63 initializeRegionViewerPass(Registry);
64 initializeRegionPrinterPass(Registry);
65 initializeRegionOnlyViewerPass(Registry);
66 initializeRegionOnlyPrinterPass(Registry);
67 initializeScalarEvolutionPass(Registry);
68 initializeScalarEvolutionAliasAnalysisPass(Registry);
69 initializeTargetTransformInfoWrapperPassPass(Registry);
70 initializeTypeBasedAliasAnalysisPass(Registry);
71 initializeScopedNoAliasAAPass(Registry);
72 }
73
LLVMInitializeAnalysis(LLVMPassRegistryRef R)74 void LLVMInitializeAnalysis(LLVMPassRegistryRef R) {
75 initializeAnalysis(*unwrap(R));
76 }
77
LLVMVerifyModule(LLVMModuleRef M,LLVMVerifierFailureAction Action,char ** OutMessages)78 LLVMBool LLVMVerifyModule(LLVMModuleRef M, LLVMVerifierFailureAction Action,
79 char **OutMessages) {
80 raw_ostream *DebugOS = Action != LLVMReturnStatusAction ? &errs() : nullptr;
81 std::string Messages;
82 raw_string_ostream MsgsOS(Messages);
83
84 LLVMBool Result = verifyModule(*unwrap(M), OutMessages ? &MsgsOS : DebugOS);
85
86 // Duplicate the output to stderr.
87 if (DebugOS && OutMessages)
88 *DebugOS << MsgsOS.str();
89
90 if (Action == LLVMAbortProcessAction && Result)
91 report_fatal_error("Broken module found, compilation aborted!");
92
93 if (OutMessages)
94 *OutMessages = strdup(MsgsOS.str().c_str());
95
96 return Result;
97 }
98
LLVMVerifyFunction(LLVMValueRef Fn,LLVMVerifierFailureAction Action)99 LLVMBool LLVMVerifyFunction(LLVMValueRef Fn, LLVMVerifierFailureAction Action) {
100 LLVMBool Result = verifyFunction(
101 *unwrap<Function>(Fn), Action != LLVMReturnStatusAction ? &errs()
102 : nullptr);
103
104 if (Action == LLVMAbortProcessAction && Result)
105 report_fatal_error("Broken function found, compilation aborted!");
106
107 return Result;
108 }
109
LLVMViewFunctionCFG(LLVMValueRef Fn)110 void LLVMViewFunctionCFG(LLVMValueRef Fn) {
111 Function *F = unwrap<Function>(Fn);
112 F->viewCFG();
113 }
114
LLVMViewFunctionCFGOnly(LLVMValueRef Fn)115 void LLVMViewFunctionCFGOnly(LLVMValueRef Fn) {
116 Function *F = unwrap<Function>(Fn);
117 F->viewCFGOnly();
118 }
119