LLVM  8.0.1
Analysis.cpp
Go to the documentation of this file.
1 //===-- Analysis.cpp ------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "llvm-c/Analysis.h"
11 #include "llvm-c/Initialization.h"
12 #include "llvm/IR/Module.h"
13 #include "llvm/IR/Verifier.h"
14 #include "llvm/InitializePasses.h"
15 #include "llvm/PassRegistry.h"
17 #include <cstring>
18 
19 using namespace llvm;
20 
21 /// initializeAnalysis - Initialize all passes linked into the Analysis library.
43  initializeDomViewerPass(Registry);
44  initializeDomPrinterPass(Registry);
54  initializeInstCountPass(Registry);
61  initializeLintPass(Registry);
88 }
89 
92 }
93 
96 }
97 
99  char **OutMessages) {
100  raw_ostream *DebugOS = Action != LLVMReturnStatusAction ? &errs() : nullptr;
101  std::string Messages;
102  raw_string_ostream MsgsOS(Messages);
103 
104  LLVMBool Result = verifyModule(*unwrap(M), OutMessages ? &MsgsOS : DebugOS);
105 
106  // Duplicate the output to stderr.
107  if (DebugOS && OutMessages)
108  *DebugOS << MsgsOS.str();
109 
110  if (Action == LLVMAbortProcessAction && Result)
111  report_fatal_error("Broken module found, compilation aborted!");
112 
113  if (OutMessages)
114  *OutMessages = strdup(MsgsOS.str().c_str());
115 
116  return Result;
117 }
118 
120  LLVMBool Result = verifyFunction(
121  *unwrap<Function>(Fn), Action != LLVMReturnStatusAction ? &errs()
122  : nullptr);
123 
124  if (Action == LLVMAbortProcessAction && Result)
125  report_fatal_error("Broken function found, compilation aborted!");
126 
127  return Result;
128 }
129 
131  Function *F = unwrap<Function>(Fn);
132  F->viewCFG();
133 }
134 
136  Function *F = unwrap<Function>(Fn);
137  F->viewCFGOnly();
138 }
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:140
This class represents lattice values for constants.
Definition: AllocatorList.h:24
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:45
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:98
void initializeTypeBasedAAWrapperPassPass(PassRegistry &)
void initializeDomOnlyPrinterPass(PassRegistry &)
void initializeBlockFrequencyInfoWrapperPassPass(PassRegistry &)
void initializeCFGOnlyPrinterLegacyPassPass(PassRegistry &)
void LLVMViewFunctionCFG(LLVMValueRef Fn)
Definition: Analysis.cpp:130
void initializeLoopInfoWrapperPassPass(PassRegistry &)
Attribute unwrap(LLVMAttributeRef Attr)
Definition: Attributes.h:195
void initializeInstCountPass(PassRegistry &)
void initializePostDomPrinterPass(PassRegistry &)
void initializeAliasSetPrinterPass(PassRegistry &)
void initializeDependenceAnalysisWrapperPassPass(PassRegistry &)
void LLVMInitializeAnalysis(LLVMPassRegistryRef R)
Definition: Analysis.cpp:90
void initializeAnalysis(PassRegistry &)
Initialize all passes linked into the Analysis library.
Definition: Analysis.cpp:22
LLVMVerifierFailureAction
Definition: Analysis.h:35
void initializeAAResultsWrapperPassPass(PassRegistry &)
void viewCFG() const
viewCFG - This function is meant for use from the debugger.
Definition: CFGPrinter.cpp:177
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:188
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:499
void initializeGlobalsAAWrapperPassPass(PassRegistry &)
void initializePostDomOnlyPrinterPass(PassRegistry &)
LLVMBool LLVMVerifyFunction(LLVMValueRef Fn, LLVMVerifierFailureAction Action)
Definition: Analysis.cpp:119
void initializeScalarEvolutionWrapperPassPass(PassRegistry &)
void LLVMViewFunctionCFGOnly(LLVMValueRef Fn)
Definition: Analysis.cpp:135
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:4820
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:4809
void initializeCFLSteensAAWrapperPassPass(PassRegistry &)
void initializeStackSafetyInfoWrapperPassPass(PassRegistry &)
void LLVMInitializeIPA(LLVMPassRegistryRef R)
Definition: Analysis.cpp:94
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:483
void initializePhiValuesWrapperPassPass(PassRegistry &)
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
Definition: PassRegistry.h:39
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 &)