• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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   initializeAAEvalLegacyPassPass(Registry);
24   initializeAliasSetPrinterPass(Registry);
25   initializeBasicAAWrapperPassPass(Registry);
26   initializeBlockFrequencyInfoWrapperPassPass(Registry);
27   initializeBranchProbabilityInfoWrapperPassPass(Registry);
28   initializeCallGraphWrapperPassPass(Registry);
29   initializeCallGraphDOTPrinterPass(Registry);
30   initializeCallGraphPrinterLegacyPassPass(Registry);
31   initializeCallGraphViewerPass(Registry);
32   initializeCostModelAnalysisPass(Registry);
33   initializeCFGViewerPass(Registry);
34   initializeCFGPrinterPass(Registry);
35   initializeCFGOnlyViewerPass(Registry);
36   initializeCFGOnlyPrinterPass(Registry);
37   initializeCFLAndersAAWrapperPassPass(Registry);
38   initializeCFLSteensAAWrapperPassPass(Registry);
39   initializeDependenceAnalysisWrapperPassPass(Registry);
40   initializeDelinearizationPass(Registry);
41   initializeDemandedBitsWrapperPassPass(Registry);
42   initializeDivergenceAnalysisPass(Registry);
43   initializeDominanceFrontierWrapperPassPass(Registry);
44   initializeDomViewerPass(Registry);
45   initializeDomPrinterPass(Registry);
46   initializeDomOnlyViewerPass(Registry);
47   initializePostDomViewerPass(Registry);
48   initializeDomOnlyPrinterPass(Registry);
49   initializePostDomPrinterPass(Registry);
50   initializePostDomOnlyViewerPass(Registry);
51   initializePostDomOnlyPrinterPass(Registry);
52   initializeAAResultsWrapperPassPass(Registry);
53   initializeGlobalsAAWrapperPassPass(Registry);
54   initializeIVUsersPass(Registry);
55   initializeInstCountPass(Registry);
56   initializeIntervalPartitionPass(Registry);
57   initializeLazyBlockFrequencyInfoPassPass(Registry);
58   initializeLazyValueInfoWrapperPassPass(Registry);
59   initializeLintPass(Registry);
60   initializeLoopInfoWrapperPassPass(Registry);
61   initializeMemDepPrinterPass(Registry);
62   initializeMemDerefPrinterPass(Registry);
63   initializeMemoryDependenceWrapperPassPass(Registry);
64   initializeModuleDebugInfoPrinterPass(Registry);
65   initializeModuleSummaryIndexWrapperPassPass(Registry);
66   initializeObjCARCAAWrapperPassPass(Registry);
67   initializePostDominatorTreeWrapperPassPass(Registry);
68   initializeRegionInfoPassPass(Registry);
69   initializeRegionViewerPass(Registry);
70   initializeRegionPrinterPass(Registry);
71   initializeRegionOnlyViewerPass(Registry);
72   initializeRegionOnlyPrinterPass(Registry);
73   initializeSCEVAAWrapperPassPass(Registry);
74   initializeScalarEvolutionWrapperPassPass(Registry);
75   initializeTargetTransformInfoWrapperPassPass(Registry);
76   initializeTypeBasedAAWrapperPassPass(Registry);
77   initializeScopedNoAliasAAWrapperPassPass(Registry);
78 }
79 
LLVMInitializeAnalysis(LLVMPassRegistryRef R)80 void LLVMInitializeAnalysis(LLVMPassRegistryRef R) {
81   initializeAnalysis(*unwrap(R));
82 }
83 
LLVMInitializeIPA(LLVMPassRegistryRef R)84 void LLVMInitializeIPA(LLVMPassRegistryRef R) {
85   initializeAnalysis(*unwrap(R));
86 }
87 
LLVMVerifyModule(LLVMModuleRef M,LLVMVerifierFailureAction Action,char ** OutMessages)88 LLVMBool LLVMVerifyModule(LLVMModuleRef M, LLVMVerifierFailureAction Action,
89                           char **OutMessages) {
90   raw_ostream *DebugOS = Action != LLVMReturnStatusAction ? &errs() : nullptr;
91   std::string Messages;
92   raw_string_ostream MsgsOS(Messages);
93 
94   LLVMBool Result = verifyModule(*unwrap(M), OutMessages ? &MsgsOS : DebugOS);
95 
96   // Duplicate the output to stderr.
97   if (DebugOS && OutMessages)
98     *DebugOS << MsgsOS.str();
99 
100   if (Action == LLVMAbortProcessAction && Result)
101     report_fatal_error("Broken module found, compilation aborted!");
102 
103   if (OutMessages)
104     *OutMessages = strdup(MsgsOS.str().c_str());
105 
106   return Result;
107 }
108 
LLVMVerifyFunction(LLVMValueRef Fn,LLVMVerifierFailureAction Action)109 LLVMBool LLVMVerifyFunction(LLVMValueRef Fn, LLVMVerifierFailureAction Action) {
110   LLVMBool Result = verifyFunction(
111       *unwrap<Function>(Fn), Action != LLVMReturnStatusAction ? &errs()
112                                                               : nullptr);
113 
114   if (Action == LLVMAbortProcessAction && Result)
115     report_fatal_error("Broken function found, compilation aborted!");
116 
117   return Result;
118 }
119 
LLVMViewFunctionCFG(LLVMValueRef Fn)120 void LLVMViewFunctionCFG(LLVMValueRef Fn) {
121   Function *F = unwrap<Function>(Fn);
122   F->viewCFG();
123 }
124 
LLVMViewFunctionCFGOnly(LLVMValueRef Fn)125 void LLVMViewFunctionCFGOnly(LLVMValueRef Fn) {
126   Function *F = unwrap<Function>(Fn);
127   F->viewCFGOnly();
128 }
129