LLVM  8.0.0svn
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);
86 }
87 
90 }
91 
94 }
95 
97  char **OutMessages) {
98  raw_ostream *DebugOS = Action != LLVMReturnStatusAction ? &errs() : nullptr;
99  std::string Messages;
100  raw_string_ostream MsgsOS(Messages);
101 
102  LLVMBool Result = verifyModule(*unwrap(M), OutMessages ? &MsgsOS : DebugOS);
103 
104  // Duplicate the output to stderr.
105  if (DebugOS && OutMessages)
106  *DebugOS << MsgsOS.str();
107 
108  if (Action == LLVMAbortProcessAction && Result)
109  report_fatal_error("Broken module found, compilation aborted!");
110 
111  if (OutMessages)
112  *OutMessages = strdup(MsgsOS.str().c_str());
113 
114  return Result;
115 }
116 
119  *unwrap<Function>(Fn), Action != LLVMReturnStatusAction ? &errs()
120  : nullptr);
121 
122  if (Action == LLVMAbortProcessAction && Result)
123  report_fatal_error("Broken function found, compilation aborted!");
124 
125  return Result;
126 }
127 
129  Function *F = unwrap<Function>(Fn);
130  F->viewCFG();
131 }
132 
134  Function *F = unwrap<Function>(Fn);
135  F->viewCFGOnly();
136 }
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
Compute iterated dominance frontiers using a linear time algorithm.
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:96
void initializeTypeBasedAAWrapperPassPass(PassRegistry &)
void initializeDomOnlyPrinterPass(PassRegistry &)
void initializeBlockFrequencyInfoWrapperPassPass(PassRegistry &)
void initializeCFGOnlyPrinterLegacyPassPass(PassRegistry &)
void LLVMViewFunctionCFG(LLVMValueRef Fn)
Definition: Analysis.cpp:128
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:88
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:117
void initializeScalarEvolutionWrapperPassPass(PassRegistry &)
void LLVMViewFunctionCFGOnly(LLVMValueRef Fn)
Definition: Analysis.cpp:133
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:4717
void initializeCFGViewerLegacyPassPass(PassRegistry &)
void initializeMemorySSAPrinterLegacyPassPass(PassRegistry &)
void initializeCFGPrinterLegacyPassPass(PassRegistry &)
void initializeMemoryDependenceWrapperPassPass(PassRegistry &)
void initializeRegionOnlyPrinterPass(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:4706
void initializeCFLSteensAAWrapperPassPass(PassRegistry &)
void LLVMInitializeIPA(LLVMPassRegistryRef R)
Definition: Analysis.cpp:92
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 &)