LLVM API Documentation
00001 //===-- Analysis.cpp ------------------------------------------------------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 00010 #include "llvm-c/Analysis.h" 00011 #include "llvm-c/Initialization.h" 00012 #include "llvm/IR/Module.h" 00013 #include "llvm/IR/Verifier.h" 00014 #include "llvm/InitializePasses.h" 00015 #include "llvm/PassRegistry.h" 00016 #include "llvm/Support/raw_ostream.h" 00017 #include <cstring> 00018 00019 using namespace llvm; 00020 00021 /// initializeAnalysis - Initialize all passes linked into the Analysis library. 00022 void llvm::initializeAnalysis(PassRegistry &Registry) { 00023 initializeAliasAnalysisAnalysisGroup(Registry); 00024 initializeAliasAnalysisCounterPass(Registry); 00025 initializeAAEvalPass(Registry); 00026 initializeAliasDebuggerPass(Registry); 00027 initializeAliasSetPrinterPass(Registry); 00028 initializeNoAAPass(Registry); 00029 initializeBasicAliasAnalysisPass(Registry); 00030 initializeBlockFrequencyInfoPass(Registry); 00031 initializeBranchProbabilityInfoPass(Registry); 00032 initializeCostModelAnalysisPass(Registry); 00033 initializeCFGViewerPass(Registry); 00034 initializeCFGPrinterPass(Registry); 00035 initializeCFGOnlyViewerPass(Registry); 00036 initializeCFGOnlyPrinterPass(Registry); 00037 initializeCFLAliasAnalysisPass(Registry); 00038 initializeDependenceAnalysisPass(Registry); 00039 initializeDelinearizationPass(Registry); 00040 initializeDominanceFrontierPass(Registry); 00041 initializeDomViewerPass(Registry); 00042 initializeDomPrinterPass(Registry); 00043 initializeDomOnlyViewerPass(Registry); 00044 initializePostDomViewerPass(Registry); 00045 initializeDomOnlyPrinterPass(Registry); 00046 initializePostDomPrinterPass(Registry); 00047 initializePostDomOnlyViewerPass(Registry); 00048 initializePostDomOnlyPrinterPass(Registry); 00049 initializeIVUsersPass(Registry); 00050 initializeInstCountPass(Registry); 00051 initializeIntervalPartitionPass(Registry); 00052 initializeJumpInstrTableInfoPass(Registry); 00053 initializeLazyValueInfoPass(Registry); 00054 initializeLibCallAliasAnalysisPass(Registry); 00055 initializeLintPass(Registry); 00056 initializeLoopInfoPass(Registry); 00057 initializeMemDepPrinterPass(Registry); 00058 initializeMemoryDependenceAnalysisPass(Registry); 00059 initializeModuleDebugInfoPrinterPass(Registry); 00060 initializePostDominatorTreePass(Registry); 00061 initializeRegionInfoPassPass(Registry); 00062 initializeRegionViewerPass(Registry); 00063 initializeRegionPrinterPass(Registry); 00064 initializeRegionOnlyViewerPass(Registry); 00065 initializeRegionOnlyPrinterPass(Registry); 00066 initializeScalarEvolutionPass(Registry); 00067 initializeScalarEvolutionAliasAnalysisPass(Registry); 00068 initializeTargetTransformInfoAnalysisGroup(Registry); 00069 initializeTypeBasedAliasAnalysisPass(Registry); 00070 initializeScopedNoAliasAAPass(Registry); 00071 } 00072 00073 void LLVMInitializeAnalysis(LLVMPassRegistryRef R) { 00074 initializeAnalysis(*unwrap(R)); 00075 } 00076 00077 LLVMBool LLVMVerifyModule(LLVMModuleRef M, LLVMVerifierFailureAction Action, 00078 char **OutMessages) { 00079 raw_ostream *DebugOS = Action != LLVMReturnStatusAction ? &errs() : nullptr; 00080 std::string Messages; 00081 raw_string_ostream MsgsOS(Messages); 00082 00083 LLVMBool Result = verifyModule(*unwrap(M), OutMessages ? &MsgsOS : DebugOS); 00084 00085 // Duplicate the output to stderr. 00086 if (DebugOS && OutMessages) 00087 *DebugOS << MsgsOS.str(); 00088 00089 if (Action == LLVMAbortProcessAction && Result) 00090 report_fatal_error("Broken module found, compilation aborted!"); 00091 00092 if (OutMessages) 00093 *OutMessages = strdup(MsgsOS.str().c_str()); 00094 00095 return Result; 00096 } 00097 00098 LLVMBool LLVMVerifyFunction(LLVMValueRef Fn, LLVMVerifierFailureAction Action) { 00099 LLVMBool Result = verifyFunction( 00100 *unwrap<Function>(Fn), Action != LLVMReturnStatusAction ? &errs() 00101 : nullptr); 00102 00103 if (Action == LLVMAbortProcessAction && Result) 00104 report_fatal_error("Broken function found, compilation aborted!"); 00105 00106 return Result; 00107 } 00108 00109 void LLVMViewFunctionCFG(LLVMValueRef Fn) { 00110 Function *F = unwrap<Function>(Fn); 00111 F->viewCFG(); 00112 } 00113 00114 void LLVMViewFunctionCFGOnly(LLVMValueRef Fn) { 00115 Function *F = unwrap<Function>(Fn); 00116 F->viewCFGOnly(); 00117 }