LLVM  9.0.0svn
Analysis.cpp
Go to the documentation of this file.
1 //===-- Analysis.cpp ------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "llvm-c/Analysis.h"
10 #include "llvm-c/Initialization.h"
11 #include "llvm/IR/Module.h"
12 #include "llvm/IR/Verifier.h"
13 #include "llvm/InitializePasses.h"
14 #include "llvm/PassRegistry.h"
16 #include <cstring>
17 
18 using namespace llvm;
19 
20 /// initializeAnalysis - Initialize all passes linked into the Analysis library.
42  initializeDomViewerPass(Registry);
43  initializeDomPrinterPass(Registry);
53  initializeInstCountPass(Registry);
60  initializeLintPass(Registry);
87 }
88 
91 }
92 
95 }
96 
98  char **OutMessages) {
99  raw_ostream *DebugOS = Action != LLVMReturnStatusAction ? &errs() : nullptr;
100  std::string Messages;
101  raw_string_ostream MsgsOS(Messages);
102 
103  LLVMBool Result = verifyModule(*unwrap(M), OutMessages ? &MsgsOS : DebugOS);
104 
105  // Duplicate the output to stderr.
106  if (DebugOS && OutMessages)
107  *DebugOS << MsgsOS.str();
108 
109  if (Action == LLVMAbortProcessAction && Result)
110  report_fatal_error("Broken module found, compilation aborted!");
111 
112  if (OutMessages)
113  *OutMessages = strdup(MsgsOS.str().c_str());
114 
115  return Result;
116 }
117 
119  LLVMBool Result = verifyFunction(
120  *unwrap<Function>(Fn), Action != LLVMReturnStatusAction ? &errs()
121  : nullptr);
122 
123  if (Action == LLVMAbortProcessAction && Result)
124  report_fatal_error("Broken function found, compilation aborted!");
125 
126  return Result;
127 }
128 
130  Function *F = unwrap<Function>(Fn);
131  F->viewCFG();
132 }
133 
135  Function *F = unwrap<Function>(Fn);
136  F->viewCFGOnly();
137 }
void initializeMemorySSAWrapperPassPass(PassRegistry &)
void initializeDemandedBitsWrapperPassPass(PassRegistry &)
void initializeDomViewerPass(PassRegistry &)
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
void initializeMemDepPrinterPass(PassRegistry &)
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:139
This class represents lattice values for constants.
Definition: AllocatorList.h:23
struct LLVMOpaqueModule * LLVMModuleRef
The top-level container for all other LLVM Intermediate Representation (IR) objects.
Definition: Types.h:62
void initializeLazyValueInfoWrapperPassPass(PassRegistry &)
void initializeRegionViewerPass(PassRegistry &)
void initializeCostModelAnalysisPass(PassRegistry &)
void initializeRegionPrinterPass(PassRegistry &)
void initializeOptimizationRemarkEmitterWrapperPassPass(PassRegistry &)
void initializeAAEvalLegacyPassPass(PassRegistry &)
void initializeCFLAndersAAWrapperPassPass(PassRegistry &)
A global registry used in conjunction with static constructors to make pluggable components (like tar...
Definition: Registry.h:44
void initializeIVUsersWrapperPassPass(PassRegistry &)
void initializePostDomViewerPass(PassRegistry &)
void initializePostDomOnlyViewerPass(PassRegistry &)
struct LLVMOpaquePassRegistry * LLVMPassRegistryRef
Definition: Types.h:131
F(f)
void initializeModuleSummaryIndexWrapperPassPass(PassRegistry &)
void initializeRegionInfoPassPass(PassRegistry &)
LLVMBool LLVMVerifyModule(LLVMModuleRef M, LLVMVerifierFailureAction Action, char **OutMessages)
Definition: Analysis.cpp:97
void initializeTypeBasedAAWrapperPassPass(PassRegistry &)
void initializeDomOnlyPrinterPass(PassRegistry &)
void initializeBlockFrequencyInfoWrapperPassPass(PassRegistry &)
void initializeCFGOnlyPrinterLegacyPassPass(PassRegistry &)
void LLVMViewFunctionCFG(LLVMValueRef Fn)
Definition: Analysis.cpp:129
void initializeLoopInfoWrapperPassPass(PassRegistry &)
Attribute unwrap(LLVMAttributeRef Attr)
Definition: Attributes.h:203
void initializeInstCountPass(PassRegistry &)
void initializePostDomPrinterPass(PassRegistry &)
void initializeAliasSetPrinterPass(PassRegistry &)
void initializeDependenceAnalysisWrapperPassPass(PassRegistry &)
void LLVMInitializeAnalysis(LLVMPassRegistryRef R)
Definition: Analysis.cpp:89
void initializeAnalysis(PassRegistry &)
Initialize all passes linked into the Analysis library.
Definition: Analysis.cpp:21
LLVMVerifierFailureAction
Definition: Analysis.h:35
void initializeAAResultsWrapperPassPass(PassRegistry &)
void viewCFG() const
viewCFG - This function is meant for use from the debugger.
Definition: CFGPrinter.cpp:176
void initializeScopedNoAliasAAWrapperPassPass(PassRegistry &)
void initializeTargetTransformInfoWrapperPassPass(PassRegistry &)
void initializeDelinearizationPass(PassRegistry &)
void initializeModuleDebugInfoPrinterPass(PassRegistry &)
void initializeCallGraphViewerPass(PassRegistry &)
void initializeBranchProbabilityInfoWrapperPassPass(PassRegistry &)
void initializeCallGraphPrinterLegacyPassPass(PassRegistry &)
void viewCFGOnly() const
viewCFGOnly - This function is meant for use from the debugger.
Definition: CFGPrinter.cpp:187
void initializeLazyBranchProbabilityInfoPassPass(PassRegistry &)
void initializeCallGraphWrapperPassPass(PassRegistry &)
void initializePostDominatorTreeWrapperPassPass(PassRegistry &)
void initializeDomOnlyViewerPass(PassRegistry &)
void initializeLazyBlockFrequencyInfoPassPass(PassRegistry &)
void initializeMemDerefPrinterPass(PassRegistry &)
void initializeSCEVAAWrapperPassPass(PassRegistry &)
void initializeCallGraphDOTPrinterPass(PassRegistry &)
int LLVMBool
Definition: Types.h:29
std::string & str()
Flushes the stream contents to the target string and returns the string&#39;s reference.
Definition: raw_ostream.h:498
void initializeGlobalsAAWrapperPassPass(PassRegistry &)
void initializePostDomOnlyPrinterPass(PassRegistry &)
LLVMBool LLVMVerifyFunction(LLVMValueRef Fn, LLVMVerifierFailureAction Action)
Definition: Analysis.cpp:118
void initializeScalarEvolutionWrapperPassPass(PassRegistry &)
void LLVMViewFunctionCFGOnly(LLVMValueRef Fn)
Definition: Analysis.cpp:134
Module.h This file contains the declarations for the Module class.
void initializeDominanceFrontierWrapperPassPass(PassRegistry &)
void initializeLintPass(PassRegistry &)
void initializeIntervalPartitionPass(PassRegistry &)
void initializeObjCARCAAWrapperPassPass(PassRegistry &)
void initializeRegionOnlyViewerPass(PassRegistry &)
void initializeDomPrinterPass(PassRegistry &)
bool verifyModule(const Module &M, raw_ostream *OS=nullptr, bool *BrokenDebugInfo=nullptr)
Check a module for errors.
Definition: Verifier.cpp:4988
void initializeCFGViewerLegacyPassPass(PassRegistry &)
void initializeMemorySSAPrinterLegacyPassPass(PassRegistry &)
void initializeCFGPrinterLegacyPassPass(PassRegistry &)
void initializeMemoryDependenceWrapperPassPass(PassRegistry &)
void initializeRegionOnlyPrinterPass(PassRegistry &)
void initializeStackSafetyGlobalInfoWrapperPassPass(PassRegistry &)
bool verifyFunction(const Function &F, raw_ostream *OS=nullptr)
Check a function for errors, useful for use when debugging a pass.
Definition: Verifier.cpp:4977
void initializeCFLSteensAAWrapperPassPass(PassRegistry &)
void initializeStackSafetyInfoWrapperPassPass(PassRegistry &)
void LLVMInitializeIPA(LLVMPassRegistryRef R)
Definition: Analysis.cpp:93
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:482
void initializePhiValuesWrapperPassPass(PassRegistry &)
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
Definition: PassRegistry.h:38
void initializeMustExecutePrinterPass(PassRegistry &)
void initializeLegacyDivergenceAnalysisPass(PassRegistry &)
void initializeLCSSAVerificationPassPass(PassRegistry &)
void initializeLazyValueInfoPrinterPass(PassRegistry &)
struct LLVMOpaqueValue * LLVMValueRef
Represents an individual value in LLVM IR.
Definition: Types.h:76
void initializeBasicAAWrapperPassPass(PassRegistry &)
void initializeCFGOnlyViewerLegacyPassPass(PassRegistry &)