Gordon Henriksen | c3d661a | 2007-10-06 21:00:36 +0000 | [diff] [blame] | 1 | //===-- Analysis.cpp ------------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | f3ebc3f | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Gordon Henriksen | c3d661a | 2007-10-06 21:00:36 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "llvm-c/Analysis.h" |
Benjamin Kramer | 5a656883 | 2011-08-19 01:36:54 +0000 | [diff] [blame] | 11 | #include "llvm-c/Initialization.h" |
Filip Pizlo | dec20e4 | 2013-05-01 20:59:00 +0000 | [diff] [blame] | 12 | #include "llvm/IR/Module.h" |
Chandler Carruth | 5ad5f15 | 2014-01-13 09:26:24 +0000 | [diff] [blame] | 13 | #include "llvm/IR/Verifier.h" |
Chandler Carruth | 8a8cd2b | 2014-01-07 11:48:04 +0000 | [diff] [blame] | 14 | #include "llvm/InitializePasses.h" |
Filip Pizlo | dec20e4 | 2013-05-01 20:59:00 +0000 | [diff] [blame] | 15 | #include "llvm/PassRegistry.h" |
Chandler Carruth | 442f784 | 2014-03-04 10:07:28 +0000 | [diff] [blame^] | 16 | #include "llvm/Support/raw_ostream.h" |
Anton Korobeynikov | 579f071 | 2008-02-20 11:08:44 +0000 | [diff] [blame] | 17 | #include <cstring> |
Gordon Henriksen | c3d661a | 2007-10-06 21:00:36 +0000 | [diff] [blame] | 18 | |
| 19 | using namespace llvm; |
| 20 | |
Owen Anderson | 6875c2e | 2010-10-07 18:31:00 +0000 | [diff] [blame] | 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); |
Jakub Staszak | 875ebd5 | 2011-07-25 19:25:40 +0000 | [diff] [blame] | 30 | initializeBlockFrequencyInfoPass(Registry); |
Andrew Trick | 49371f3 | 2011-06-04 01:16:30 +0000 | [diff] [blame] | 31 | initializeBranchProbabilityInfoPass(Registry); |
Nadav Rotem | a6b91ac | 2012-11-02 21:48:17 +0000 | [diff] [blame] | 32 | initializeCostModelAnalysisPass(Registry); |
Owen Anderson | 6875c2e | 2010-10-07 18:31:00 +0000 | [diff] [blame] | 33 | initializeCFGViewerPass(Registry); |
| 34 | initializeCFGPrinterPass(Registry); |
| 35 | initializeCFGOnlyViewerPass(Registry); |
| 36 | initializeCFGOnlyPrinterPass(Registry); |
Sebastian Pop | 59b61b9 | 2012-10-11 07:32:34 +0000 | [diff] [blame] | 37 | initializeDependenceAnalysisPass(Registry); |
Sebastian Pop | c62c679 | 2013-11-12 22:47:20 +0000 | [diff] [blame] | 38 | initializeDelinearizationPass(Registry); |
Cameron Zwarich | 6b0c4c9 | 2011-01-18 06:06:27 +0000 | [diff] [blame] | 39 | initializeDominanceFrontierPass(Registry); |
Owen Anderson | 6875c2e | 2010-10-07 18:31:00 +0000 | [diff] [blame] | 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 | initializeLazyValueInfoPass(Registry); |
| 52 | initializeLibCallAliasAnalysisPass(Registry); |
| 53 | initializeLintPass(Registry); |
Owen Anderson | 6875c2e | 2010-10-07 18:31:00 +0000 | [diff] [blame] | 54 | initializeLoopInfoPass(Registry); |
| 55 | initializeMemDepPrinterPass(Registry); |
| 56 | initializeMemoryDependenceAnalysisPass(Registry); |
| 57 | initializeModuleDebugInfoPrinterPass(Registry); |
| 58 | initializePostDominatorTreePass(Registry); |
Owen Anderson | 6875c2e | 2010-10-07 18:31:00 +0000 | [diff] [blame] | 59 | initializeRegionInfoPass(Registry); |
| 60 | initializeRegionViewerPass(Registry); |
| 61 | initializeRegionPrinterPass(Registry); |
| 62 | initializeRegionOnlyViewerPass(Registry); |
| 63 | initializeRegionOnlyPrinterPass(Registry); |
| 64 | initializeScalarEvolutionPass(Registry); |
| 65 | initializeScalarEvolutionAliasAnalysisPass(Registry); |
Chandler Carruth | f1f5452 | 2013-01-07 03:33:08 +0000 | [diff] [blame] | 66 | initializeTargetTransformInfoAnalysisGroup(Registry); |
Owen Anderson | 6875c2e | 2010-10-07 18:31:00 +0000 | [diff] [blame] | 67 | initializeTypeBasedAliasAnalysisPass(Registry); |
| 68 | } |
| 69 | |
| 70 | void LLVMInitializeAnalysis(LLVMPassRegistryRef R) { |
| 71 | initializeAnalysis(*unwrap(R)); |
| 72 | } |
| 73 | |
Chris Lattner | 25963c6 | 2010-01-09 22:27:07 +0000 | [diff] [blame] | 74 | LLVMBool LLVMVerifyModule(LLVMModuleRef M, LLVMVerifierFailureAction Action, |
| 75 | char **OutMessages) { |
Chandler Carruth | 043949d | 2014-01-19 02:22:18 +0000 | [diff] [blame] | 76 | raw_ostream *DebugOS = Action != LLVMReturnStatusAction ? &errs() : 0; |
Gordon Henriksen | c3d661a | 2007-10-06 21:00:36 +0000 | [diff] [blame] | 77 | std::string Messages; |
Chandler Carruth | 043949d | 2014-01-19 02:22:18 +0000 | [diff] [blame] | 78 | raw_string_ostream MsgsOS(Messages); |
Andrew Trick | 24f5ff0 | 2011-01-29 01:09:53 +0000 | [diff] [blame] | 79 | |
Chandler Carruth | 043949d | 2014-01-19 02:22:18 +0000 | [diff] [blame] | 80 | LLVMBool Result = verifyModule(*unwrap(M), OutMessages ? &MsgsOS : DebugOS); |
| 81 | |
| 82 | // Duplicate the output to stderr. |
| 83 | if (DebugOS && OutMessages) |
| 84 | *DebugOS << MsgsOS.str(); |
| 85 | |
| 86 | if (Action == LLVMAbortProcessAction && Result) |
| 87 | report_fatal_error("Broken module found, compilation aborted!"); |
Andrew Trick | 24f5ff0 | 2011-01-29 01:09:53 +0000 | [diff] [blame] | 88 | |
Gordon Henriksen | c3d661a | 2007-10-06 21:00:36 +0000 | [diff] [blame] | 89 | if (OutMessages) |
Chandler Carruth | 043949d | 2014-01-19 02:22:18 +0000 | [diff] [blame] | 90 | *OutMessages = strdup(MsgsOS.str().c_str()); |
Andrew Trick | 24f5ff0 | 2011-01-29 01:09:53 +0000 | [diff] [blame] | 91 | |
Gordon Henriksen | c3d661a | 2007-10-06 21:00:36 +0000 | [diff] [blame] | 92 | return Result; |
| 93 | } |
| 94 | |
Chris Lattner | 25963c6 | 2010-01-09 22:27:07 +0000 | [diff] [blame] | 95 | LLVMBool LLVMVerifyFunction(LLVMValueRef Fn, LLVMVerifierFailureAction Action) { |
Chandler Carruth | 043949d | 2014-01-19 02:22:18 +0000 | [diff] [blame] | 96 | LLVMBool Result = verifyFunction( |
| 97 | *unwrap<Function>(Fn), Action != LLVMReturnStatusAction ? &errs() : 0); |
| 98 | |
| 99 | if (Action == LLVMAbortProcessAction && Result) |
| 100 | report_fatal_error("Broken function found, compilation aborted!"); |
| 101 | |
| 102 | return Result; |
Gordon Henriksen | c3d661a | 2007-10-06 21:00:36 +0000 | [diff] [blame] | 103 | } |
| 104 | |
Erick Tryzelaar | 4a0da98 | 2008-03-31 16:22:09 +0000 | [diff] [blame] | 105 | void LLVMViewFunctionCFG(LLVMValueRef Fn) { |
| 106 | Function *F = unwrap<Function>(Fn); |
| 107 | F->viewCFG(); |
| 108 | } |
| 109 | |
| 110 | void LLVMViewFunctionCFGOnly(LLVMValueRef Fn) { |
| 111 | Function *F = unwrap<Function>(Fn); |
| 112 | F->viewCFGOnly(); |
| 113 | } |