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) { |
Chandler Carruth | 4f846a5 | 2016-02-20 03:46:03 +0000 | [diff] [blame] | 23 | initializeAAEvalLegacyPassPass(Registry); |
Owen Anderson | 6875c2e | 2010-10-07 18:31:00 +0000 | [diff] [blame] | 24 | initializeAliasSetPrinterPass(Registry); |
Chandler Carruth | 7b560d4 | 2015-09-09 17:55:00 +0000 | [diff] [blame] | 25 | initializeBasicAAWrapperPassPass(Registry); |
Wei Mi | deee61e | 2015-07-14 23:40:50 +0000 | [diff] [blame] | 26 | initializeBlockFrequencyInfoWrapperPassPass(Registry); |
Cong Hou | ab23bfb | 2015-07-15 22:48:29 +0000 | [diff] [blame] | 27 | initializeBranchProbabilityInfoWrapperPassPass(Registry); |
Chandler Carruth | 7adc3a2 | 2015-08-18 17:51:53 +0000 | [diff] [blame] | 28 | initializeCallGraphWrapperPassPass(Registry); |
Chandler Carruth | 5f43229 | 2016-03-10 11:04:40 +0000 | [diff] [blame] | 29 | initializeCallGraphDOTPrinterPass(Registry); |
Chandler Carruth | 1ecd740 | 2016-03-10 11:08:44 +0000 | [diff] [blame] | 30 | initializeCallGraphPrinterLegacyPassPass(Registry); |
Chandler Carruth | 7adc3a2 | 2015-08-18 17:51:53 +0000 | [diff] [blame] | 31 | initializeCallGraphViewerPass(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); |
Chandler Carruth | 7b560d4 | 2015-09-09 17:55:00 +0000 | [diff] [blame] | 37 | initializeCFLAAWrapperPassPass(Registry); |
Chandler Carruth | 49c2219 | 2016-05-12 22:19:39 +0000 | [diff] [blame] | 38 | initializeDependenceAnalysisWrapperPassPass(Registry); |
Sebastian Pop | c62c679 | 2013-11-12 22:47:20 +0000 | [diff] [blame] | 39 | initializeDelinearizationPass(Registry); |
Michael Kuperstein | de16b44 | 2016-04-18 23:55:01 +0000 | [diff] [blame] | 40 | initializeDemandedBitsWrapperPassPass(Registry); |
Jingyue Wu | 5da831c | 2015-04-10 05:03:50 +0000 | [diff] [blame] | 41 | initializeDivergenceAnalysisPass(Registry); |
Hongbin Zheng | 751337f | 2016-02-25 17:54:15 +0000 | [diff] [blame] | 42 | initializeDominanceFrontierWrapperPassPass(Registry); |
Owen Anderson | 6875c2e | 2010-10-07 18:31:00 +0000 | [diff] [blame] | 43 | initializeDomViewerPass(Registry); |
| 44 | initializeDomPrinterPass(Registry); |
| 45 | initializeDomOnlyViewerPass(Registry); |
| 46 | initializePostDomViewerPass(Registry); |
| 47 | initializeDomOnlyPrinterPass(Registry); |
| 48 | initializePostDomPrinterPass(Registry); |
| 49 | initializePostDomOnlyViewerPass(Registry); |
| 50 | initializePostDomOnlyPrinterPass(Registry); |
Chandler Carruth | 7b560d4 | 2015-09-09 17:55:00 +0000 | [diff] [blame] | 51 | initializeAAResultsWrapperPassPass(Registry); |
| 52 | initializeGlobalsAAWrapperPassPass(Registry); |
Owen Anderson | 6875c2e | 2010-10-07 18:31:00 +0000 | [diff] [blame] | 53 | initializeIVUsersPass(Registry); |
| 54 | initializeInstCountPass(Registry); |
| 55 | initializeIntervalPartitionPass(Registry); |
Sean Silva | 687019f | 2016-06-13 22:01:25 +0000 | [diff] [blame^] | 56 | initializeLazyValueInfoWrapperPassPass(Registry); |
Owen Anderson | 6875c2e | 2010-10-07 18:31:00 +0000 | [diff] [blame] | 57 | initializeLintPass(Registry); |
Chandler Carruth | 4f8f307 | 2015-01-17 14:16:18 +0000 | [diff] [blame] | 58 | initializeLoopInfoWrapperPassPass(Registry); |
Owen Anderson | 6875c2e | 2010-10-07 18:31:00 +0000 | [diff] [blame] | 59 | initializeMemDepPrinterPass(Registry); |
Ramkumar Ramachandra | 8378ac3 | 2015-02-06 01:46:42 +0000 | [diff] [blame] | 60 | initializeMemDerefPrinterPass(Registry); |
Chandler Carruth | 61440d2 | 2016-03-10 00:55:30 +0000 | [diff] [blame] | 61 | initializeMemoryDependenceWrapperPassPass(Registry); |
Owen Anderson | 6875c2e | 2010-10-07 18:31:00 +0000 | [diff] [blame] | 62 | initializeModuleDebugInfoPrinterPass(Registry); |
Teresa Johnson | 2d5487c | 2016-04-11 13:58:45 +0000 | [diff] [blame] | 63 | initializeModuleSummaryIndexWrapperPassPass(Registry); |
Chandler Carruth | 7b560d4 | 2015-09-09 17:55:00 +0000 | [diff] [blame] | 64 | initializeObjCARCAAWrapperPassPass(Registry); |
Hongbin Zheng | 3f97840 | 2016-02-25 17:54:07 +0000 | [diff] [blame] | 65 | initializePostDominatorTreeWrapperPassPass(Registry); |
Matt Arsenault | 1b8d837 | 2014-07-19 18:29:29 +0000 | [diff] [blame] | 66 | initializeRegionInfoPassPass(Registry); |
Owen Anderson | 6875c2e | 2010-10-07 18:31:00 +0000 | [diff] [blame] | 67 | initializeRegionViewerPass(Registry); |
| 68 | initializeRegionPrinterPass(Registry); |
| 69 | initializeRegionOnlyViewerPass(Registry); |
| 70 | initializeRegionOnlyPrinterPass(Registry); |
Chandler Carruth | 7b560d4 | 2015-09-09 17:55:00 +0000 | [diff] [blame] | 71 | initializeSCEVAAWrapperPassPass(Registry); |
Chandler Carruth | 2f1fd16 | 2015-08-17 02:08:17 +0000 | [diff] [blame] | 72 | initializeScalarEvolutionWrapperPassPass(Registry); |
Chandler Carruth | 705b185 | 2015-01-31 03:43:40 +0000 | [diff] [blame] | 73 | initializeTargetTransformInfoWrapperPassPass(Registry); |
Chandler Carruth | 7b560d4 | 2015-09-09 17:55:00 +0000 | [diff] [blame] | 74 | initializeTypeBasedAAWrapperPassPass(Registry); |
| 75 | initializeScopedNoAliasAAWrapperPassPass(Registry); |
Owen Anderson | 6875c2e | 2010-10-07 18:31:00 +0000 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | void LLVMInitializeAnalysis(LLVMPassRegistryRef R) { |
| 79 | initializeAnalysis(*unwrap(R)); |
| 80 | } |
| 81 | |
Chandler Carruth | 7adc3a2 | 2015-08-18 17:51:53 +0000 | [diff] [blame] | 82 | void LLVMInitializeIPA(LLVMPassRegistryRef R) { |
| 83 | initializeAnalysis(*unwrap(R)); |
| 84 | } |
| 85 | |
Chris Lattner | 25963c6 | 2010-01-09 22:27:07 +0000 | [diff] [blame] | 86 | LLVMBool LLVMVerifyModule(LLVMModuleRef M, LLVMVerifierFailureAction Action, |
| 87 | char **OutMessages) { |
Craig Topper | 9f00886 | 2014-04-15 04:59:12 +0000 | [diff] [blame] | 88 | raw_ostream *DebugOS = Action != LLVMReturnStatusAction ? &errs() : nullptr; |
Alp Toker | e69170a | 2014-06-26 22:52:05 +0000 | [diff] [blame] | 89 | std::string Messages; |
| 90 | raw_string_ostream MsgsOS(Messages); |
Andrew Trick | 24f5ff0 | 2011-01-29 01:09:53 +0000 | [diff] [blame] | 91 | |
Chandler Carruth | 043949d | 2014-01-19 02:22:18 +0000 | [diff] [blame] | 92 | LLVMBool Result = verifyModule(*unwrap(M), OutMessages ? &MsgsOS : DebugOS); |
| 93 | |
| 94 | // Duplicate the output to stderr. |
| 95 | if (DebugOS && OutMessages) |
| 96 | *DebugOS << MsgsOS.str(); |
| 97 | |
| 98 | if (Action == LLVMAbortProcessAction && Result) |
| 99 | report_fatal_error("Broken module found, compilation aborted!"); |
Andrew Trick | 24f5ff0 | 2011-01-29 01:09:53 +0000 | [diff] [blame] | 100 | |
Alp Toker | e69170a | 2014-06-26 22:52:05 +0000 | [diff] [blame] | 101 | if (OutMessages) |
| 102 | *OutMessages = strdup(MsgsOS.str().c_str()); |
Andrew Trick | 24f5ff0 | 2011-01-29 01:09:53 +0000 | [diff] [blame] | 103 | |
Gordon Henriksen | c3d661a | 2007-10-06 21:00:36 +0000 | [diff] [blame] | 104 | return Result; |
| 105 | } |
| 106 | |
Chris Lattner | 25963c6 | 2010-01-09 22:27:07 +0000 | [diff] [blame] | 107 | LLVMBool LLVMVerifyFunction(LLVMValueRef Fn, LLVMVerifierFailureAction Action) { |
Chandler Carruth | 043949d | 2014-01-19 02:22:18 +0000 | [diff] [blame] | 108 | LLVMBool Result = verifyFunction( |
Craig Topper | 9f00886 | 2014-04-15 04:59:12 +0000 | [diff] [blame] | 109 | *unwrap<Function>(Fn), Action != LLVMReturnStatusAction ? &errs() |
| 110 | : nullptr); |
Chandler Carruth | 043949d | 2014-01-19 02:22:18 +0000 | [diff] [blame] | 111 | |
| 112 | if (Action == LLVMAbortProcessAction && Result) |
| 113 | report_fatal_error("Broken function found, compilation aborted!"); |
| 114 | |
| 115 | return Result; |
Gordon Henriksen | c3d661a | 2007-10-06 21:00:36 +0000 | [diff] [blame] | 116 | } |
| 117 | |
Erick Tryzelaar | 4a0da98 | 2008-03-31 16:22:09 +0000 | [diff] [blame] | 118 | void LLVMViewFunctionCFG(LLVMValueRef Fn) { |
| 119 | Function *F = unwrap<Function>(Fn); |
| 120 | F->viewCFG(); |
| 121 | } |
| 122 | |
| 123 | void LLVMViewFunctionCFGOnly(LLVMValueRef Fn) { |
| 124 | Function *F = unwrap<Function>(Fn); |
| 125 | F->viewCFGOnly(); |
| 126 | } |