xref: /netbsd-src/external/apache2/llvm/dist/llvm/lib/Analysis/Analysis.cpp (revision 82d56013d7b633d116a93943de88e08335357a7c)
17330f729Sjoerg //===-- Analysis.cpp ------------------------------------------------------===//
27330f729Sjoerg //
37330f729Sjoerg // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
47330f729Sjoerg // See https://llvm.org/LICENSE.txt for license information.
57330f729Sjoerg // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
67330f729Sjoerg //
77330f729Sjoerg //===----------------------------------------------------------------------===//
87330f729Sjoerg 
97330f729Sjoerg #include "llvm-c/Analysis.h"
107330f729Sjoerg #include "llvm-c/Initialization.h"
117330f729Sjoerg #include "llvm/IR/Module.h"
127330f729Sjoerg #include "llvm/IR/Verifier.h"
137330f729Sjoerg #include "llvm/InitializePasses.h"
147330f729Sjoerg #include "llvm/PassRegistry.h"
157330f729Sjoerg #include "llvm/Support/raw_ostream.h"
167330f729Sjoerg #include <cstring>
177330f729Sjoerg 
187330f729Sjoerg using namespace llvm;
197330f729Sjoerg 
207330f729Sjoerg /// initializeAnalysis - Initialize all passes linked into the Analysis library.
initializeAnalysis(PassRegistry & Registry)217330f729Sjoerg void llvm::initializeAnalysis(PassRegistry &Registry) {
227330f729Sjoerg   initializeAAEvalLegacyPassPass(Registry);
237330f729Sjoerg   initializeAliasSetPrinterPass(Registry);
247330f729Sjoerg   initializeBasicAAWrapperPassPass(Registry);
257330f729Sjoerg   initializeBlockFrequencyInfoWrapperPassPass(Registry);
267330f729Sjoerg   initializeBranchProbabilityInfoWrapperPassPass(Registry);
277330f729Sjoerg   initializeCallGraphWrapperPassPass(Registry);
287330f729Sjoerg   initializeCallGraphDOTPrinterPass(Registry);
297330f729Sjoerg   initializeCallGraphPrinterLegacyPassPass(Registry);
307330f729Sjoerg   initializeCallGraphViewerPass(Registry);
317330f729Sjoerg   initializeCostModelAnalysisPass(Registry);
327330f729Sjoerg   initializeCFGViewerLegacyPassPass(Registry);
337330f729Sjoerg   initializeCFGPrinterLegacyPassPass(Registry);
347330f729Sjoerg   initializeCFGOnlyViewerLegacyPassPass(Registry);
357330f729Sjoerg   initializeCFGOnlyPrinterLegacyPassPass(Registry);
367330f729Sjoerg   initializeCFLAndersAAWrapperPassPass(Registry);
377330f729Sjoerg   initializeCFLSteensAAWrapperPassPass(Registry);
387330f729Sjoerg   initializeDependenceAnalysisWrapperPassPass(Registry);
397330f729Sjoerg   initializeDelinearizationPass(Registry);
407330f729Sjoerg   initializeDemandedBitsWrapperPassPass(Registry);
417330f729Sjoerg   initializeDominanceFrontierWrapperPassPass(Registry);
427330f729Sjoerg   initializeDomViewerPass(Registry);
437330f729Sjoerg   initializeDomPrinterPass(Registry);
447330f729Sjoerg   initializeDomOnlyViewerPass(Registry);
457330f729Sjoerg   initializePostDomViewerPass(Registry);
467330f729Sjoerg   initializeDomOnlyPrinterPass(Registry);
477330f729Sjoerg   initializePostDomPrinterPass(Registry);
487330f729Sjoerg   initializePostDomOnlyViewerPass(Registry);
497330f729Sjoerg   initializePostDomOnlyPrinterPass(Registry);
507330f729Sjoerg   initializeAAResultsWrapperPassPass(Registry);
517330f729Sjoerg   initializeGlobalsAAWrapperPassPass(Registry);
527330f729Sjoerg   initializeIVUsersWrapperPassPass(Registry);
53*82d56013Sjoerg   initializeInstCountLegacyPassPass(Registry);
547330f729Sjoerg   initializeIntervalPartitionPass(Registry);
55*82d56013Sjoerg   initializeIRSimilarityIdentifierWrapperPassPass(Registry);
567330f729Sjoerg   initializeLazyBranchProbabilityInfoPassPass(Registry);
577330f729Sjoerg   initializeLazyBlockFrequencyInfoPassPass(Registry);
587330f729Sjoerg   initializeLazyValueInfoWrapperPassPass(Registry);
597330f729Sjoerg   initializeLazyValueInfoPrinterPass(Registry);
607330f729Sjoerg   initializeLegacyDivergenceAnalysisPass(Registry);
61*82d56013Sjoerg   initializeLintLegacyPassPass(Registry);
627330f729Sjoerg   initializeLoopInfoWrapperPassPass(Registry);
637330f729Sjoerg   initializeMemDepPrinterPass(Registry);
647330f729Sjoerg   initializeMemDerefPrinterPass(Registry);
657330f729Sjoerg   initializeMemoryDependenceWrapperPassPass(Registry);
66*82d56013Sjoerg   initializeModuleDebugInfoLegacyPrinterPass(Registry);
677330f729Sjoerg   initializeModuleSummaryIndexWrapperPassPass(Registry);
687330f729Sjoerg   initializeMustExecutePrinterPass(Registry);
697330f729Sjoerg   initializeMustBeExecutedContextPrinterPass(Registry);
707330f729Sjoerg   initializeObjCARCAAWrapperPassPass(Registry);
717330f729Sjoerg   initializeOptimizationRemarkEmitterWrapperPassPass(Registry);
727330f729Sjoerg   initializePhiValuesWrapperPassPass(Registry);
737330f729Sjoerg   initializePostDominatorTreeWrapperPassPass(Registry);
747330f729Sjoerg   initializeRegionInfoPassPass(Registry);
757330f729Sjoerg   initializeRegionViewerPass(Registry);
767330f729Sjoerg   initializeRegionPrinterPass(Registry);
777330f729Sjoerg   initializeRegionOnlyViewerPass(Registry);
787330f729Sjoerg   initializeRegionOnlyPrinterPass(Registry);
797330f729Sjoerg   initializeSCEVAAWrapperPassPass(Registry);
807330f729Sjoerg   initializeScalarEvolutionWrapperPassPass(Registry);
817330f729Sjoerg   initializeStackSafetyGlobalInfoWrapperPassPass(Registry);
827330f729Sjoerg   initializeStackSafetyInfoWrapperPassPass(Registry);
837330f729Sjoerg   initializeTargetTransformInfoWrapperPassPass(Registry);
847330f729Sjoerg   initializeTypeBasedAAWrapperPassPass(Registry);
857330f729Sjoerg   initializeScopedNoAliasAAWrapperPassPass(Registry);
867330f729Sjoerg   initializeLCSSAVerificationPassPass(Registry);
877330f729Sjoerg   initializeMemorySSAWrapperPassPass(Registry);
887330f729Sjoerg   initializeMemorySSAPrinterLegacyPassPass(Registry);
897330f729Sjoerg }
907330f729Sjoerg 
LLVMInitializeAnalysis(LLVMPassRegistryRef R)917330f729Sjoerg void LLVMInitializeAnalysis(LLVMPassRegistryRef R) {
927330f729Sjoerg   initializeAnalysis(*unwrap(R));
937330f729Sjoerg }
947330f729Sjoerg 
LLVMInitializeIPA(LLVMPassRegistryRef R)957330f729Sjoerg void LLVMInitializeIPA(LLVMPassRegistryRef R) {
967330f729Sjoerg   initializeAnalysis(*unwrap(R));
977330f729Sjoerg }
987330f729Sjoerg 
LLVMVerifyModule(LLVMModuleRef M,LLVMVerifierFailureAction Action,char ** OutMessages)997330f729Sjoerg LLVMBool LLVMVerifyModule(LLVMModuleRef M, LLVMVerifierFailureAction Action,
1007330f729Sjoerg                           char **OutMessages) {
1017330f729Sjoerg   raw_ostream *DebugOS = Action != LLVMReturnStatusAction ? &errs() : nullptr;
1027330f729Sjoerg   std::string Messages;
1037330f729Sjoerg   raw_string_ostream MsgsOS(Messages);
1047330f729Sjoerg 
1057330f729Sjoerg   LLVMBool Result = verifyModule(*unwrap(M), OutMessages ? &MsgsOS : DebugOS);
1067330f729Sjoerg 
1077330f729Sjoerg   // Duplicate the output to stderr.
1087330f729Sjoerg   if (DebugOS && OutMessages)
1097330f729Sjoerg     *DebugOS << MsgsOS.str();
1107330f729Sjoerg 
1117330f729Sjoerg   if (Action == LLVMAbortProcessAction && Result)
1127330f729Sjoerg     report_fatal_error("Broken module found, compilation aborted!");
1137330f729Sjoerg 
1147330f729Sjoerg   if (OutMessages)
1157330f729Sjoerg     *OutMessages = strdup(MsgsOS.str().c_str());
1167330f729Sjoerg 
1177330f729Sjoerg   return Result;
1187330f729Sjoerg }
1197330f729Sjoerg 
LLVMVerifyFunction(LLVMValueRef Fn,LLVMVerifierFailureAction Action)1207330f729Sjoerg LLVMBool LLVMVerifyFunction(LLVMValueRef Fn, LLVMVerifierFailureAction Action) {
1217330f729Sjoerg   LLVMBool Result = verifyFunction(
1227330f729Sjoerg       *unwrap<Function>(Fn), Action != LLVMReturnStatusAction ? &errs()
1237330f729Sjoerg                                                               : nullptr);
1247330f729Sjoerg 
1257330f729Sjoerg   if (Action == LLVMAbortProcessAction && Result)
1267330f729Sjoerg     report_fatal_error("Broken function found, compilation aborted!");
1277330f729Sjoerg 
1287330f729Sjoerg   return Result;
1297330f729Sjoerg }
1307330f729Sjoerg 
LLVMViewFunctionCFG(LLVMValueRef Fn)1317330f729Sjoerg void LLVMViewFunctionCFG(LLVMValueRef Fn) {
1327330f729Sjoerg   Function *F = unwrap<Function>(Fn);
1337330f729Sjoerg   F->viewCFG();
1347330f729Sjoerg }
1357330f729Sjoerg 
LLVMViewFunctionCFGOnly(LLVMValueRef Fn)1367330f729Sjoerg void LLVMViewFunctionCFGOnly(LLVMValueRef Fn) {
1377330f729Sjoerg   Function *F = unwrap<Function>(Fn);
1387330f729Sjoerg   F->viewCFGOnly();
1397330f729Sjoerg }
140