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. 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 initializeDependenceAnalysisPass(Registry); 38 initializeDelinearizationPass(Registry); 39 initializeDominanceFrontierPass(Registry); 40 initializeDomViewerPass(Registry); 41 initializeDomPrinterPass(Registry); 42 initializeDomOnlyViewerPass(Registry); 43 initializePostDomViewerPass(Registry); 44 initializeDomOnlyPrinterPass(Registry); 45 initializePostDomPrinterPass(Registry); 46 initializePostDomOnlyViewerPass(Registry); 47 initializePostDomOnlyPrinterPass(Registry); 48 initializeIVUsersPass(Registry); 49 initializeInstCountPass(Registry); 50 initializeIntervalPartitionPass(Registry); 51 initializeJumpInstrTableInfoPass(Registry); 52 initializeLazyValueInfoPass(Registry); 53 initializeLibCallAliasAnalysisPass(Registry); 54 initializeLintPass(Registry); 55 initializeLoopInfoPass(Registry); 56 initializeMemDepPrinterPass(Registry); 57 initializeMemoryDependenceAnalysisPass(Registry); 58 initializeModuleDebugInfoPrinterPass(Registry); 59 initializePostDominatorTreePass(Registry); 60 initializeRegionInfoPass(Registry); 61 initializeRegionViewerPass(Registry); 62 initializeRegionPrinterPass(Registry); 63 initializeRegionOnlyViewerPass(Registry); 64 initializeRegionOnlyPrinterPass(Registry); 65 initializeScalarEvolutionPass(Registry); 66 initializeScalarEvolutionAliasAnalysisPass(Registry); 67 initializeTargetTransformInfoAnalysisGroup(Registry); 68 initializeTypeBasedAliasAnalysisPass(Registry); 69 } 70 71 void LLVMInitializeAnalysis(LLVMPassRegistryRef R) { 72 initializeAnalysis(*unwrap(R)); 73 } 74 75 LLVMBool LLVMVerifyModule(LLVMModuleRef M, LLVMVerifierFailureAction Action, 76 char **OutMessages) { 77 raw_ostream *DebugOS = Action != LLVMReturnStatusAction ? &errs() : nullptr; 78 std::string Messages; 79 raw_string_ostream MsgsOS(Messages); 80 81 LLVMBool Result = verifyModule(*unwrap(M), OutMessages ? &MsgsOS : DebugOS); 82 83 // Duplicate the output to stderr. 84 if (DebugOS && OutMessages) 85 *DebugOS << MsgsOS.str(); 86 87 if (Action == LLVMAbortProcessAction && Result) 88 report_fatal_error("Broken module found, compilation aborted!"); 89 90 if (OutMessages) 91 *OutMessages = strdup(MsgsOS.str().c_str()); 92 93 return Result; 94 } 95 96 LLVMBool LLVMVerifyFunction(LLVMValueRef Fn, LLVMVerifierFailureAction Action) { 97 LLVMBool Result = verifyFunction( 98 *unwrap<Function>(Fn), Action != LLVMReturnStatusAction ? &errs() 99 : nullptr); 100 101 if (Action == LLVMAbortProcessAction && Result) 102 report_fatal_error("Broken function found, compilation aborted!"); 103 104 return Result; 105 } 106 107 void LLVMViewFunctionCFG(LLVMValueRef Fn) { 108 Function *F = unwrap<Function>(Fn); 109 F->viewCFG(); 110 } 111 112 void LLVMViewFunctionCFGOnly(LLVMValueRef Fn) { 113 Function *F = unwrap<Function>(Fn); 114 F->viewCFGOnly(); 115 } 116