LLVM  3.7.0
Analysis/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.
25  initializeAAEvalPass(Registry);
28  initializeNoAAPass(Registry);
33  initializeCFGViewerPass(Registry);
34  initializeCFGPrinterPass(Registry);
42  initializeDomViewerPass(Registry);
43  initializeDomPrinterPass(Registry);
50  initializeIVUsersPass(Registry);
51  initializeInstCountPass(Registry);
55  initializeLintPass(Registry);
72 }
73 
76 }
77 
79  char **OutMessages) {
80  raw_ostream *DebugOS = Action != LLVMReturnStatusAction ? &errs() : nullptr;
81  std::string Messages;
82  raw_string_ostream MsgsOS(Messages);
83 
84  LLVMBool Result = verifyModule(*unwrap(M), OutMessages ? &MsgsOS : DebugOS);
85 
86  // Duplicate the output to stderr.
87  if (DebugOS && OutMessages)
88  *DebugOS << MsgsOS.str();
89 
90  if (Action == LLVMAbortProcessAction && Result)
91  report_fatal_error("Broken module found, compilation aborted!");
92 
93  if (OutMessages)
94  *OutMessages = strdup(MsgsOS.str().c_str());
95 
96  return Result;
97 }
98 
100  LLVMBool Result = verifyFunction(
101  *unwrap<Function>(Fn), Action != LLVMReturnStatusAction ? &errs()
102  : nullptr);
103 
104  if (Action == LLVMAbortProcessAction && Result)
105  report_fatal_error("Broken function found, compilation aborted!");
106 
107  return Result;
108 }
109 
111  Function *F = unwrap<Function>(Fn);
112  F->viewCFG();
113 }
114 
116  Function *F = unwrap<Function>(Fn);
117  F->viewCFGOnly();
118 }
void viewCFGOnly() const
viewCFGOnly - This function is meant for use from the debugger.
void initializeDomViewerPass(PassRegistry &)
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
void initializeMemDepPrinterPass(PassRegistry &)
void initializeRegionViewerPass(PassRegistry &)
void initializeCostModelAnalysisPass(PassRegistry &)
void initializeRegionPrinterPass(PassRegistry &)
A global registry used in conjunction with static constructors to make pluggable components (like tar...
Definition: Registry.h:61
void initializePostDomViewerPass(PassRegistry &)
void initializePostDomOnlyViewerPass(PassRegistry &)
void initializeScalarEvolutionAliasAnalysisPass(PassRegistry &)
F(f)
void initializeRegionInfoPassPass(PassRegistry &)
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(const char *reason, bool gen_crash_diag=true)
Reports a serious error, calling any installed error handler.
LLVMBool LLVMVerifyModule(LLVMModuleRef M, LLVMVerifierFailureAction Action, char **OutMessages)
void initializeBranchProbabilityInfoPass(PassRegistry &)
void initializeDomOnlyPrinterPass(PassRegistry &)
void initializeTypeBasedAliasAnalysisPass(PassRegistry &)
void initializeIVUsersPass(PassRegistry &)
void LLVMViewFunctionCFG(LLVMValueRef Fn)
void initializeLoopInfoWrapperPassPass(PassRegistry &)
void initializeInstCountPass(PassRegistry &)
void initializePostDomPrinterPass(PassRegistry &)
void initializeAliasSetPrinterPass(PassRegistry &)
void LLVMInitializeAnalysis(LLVMPassRegistryRef R)
void initializeAnalysis(PassRegistry &)
initializeAnalysis - Initialize all passes linked into the Analysis library.
void viewCFG() const
viewCFG - This function is meant for use from the debugger.
LLVMVerifierFailureAction
Definition: c/Analysis.h:35
void initializeAliasAnalysisCounterPass(PassRegistry &)
void initializeCFGOnlyPrinterPass(PassRegistry &)
void initializeAliasAnalysisAnalysisGroup(PassRegistry &)
void initializeTargetTransformInfoWrapperPassPass(PassRegistry &)
void initializeDivergenceAnalysisPass(PassRegistry &)
void initializeDelinearizationPass(PassRegistry &)
void initializeModuleDebugInfoPrinterPass(PassRegistry &)
void initializeAliasDebuggerPass(PassRegistry &)
DataLayout * unwrap(LLVMTargetDataRef P)
Definition: DataLayout.h:465
void initializeNoAAPass(PassRegistry &)
void initializeDomOnlyViewerPass(PassRegistry &)
void initializeMemDerefPrinterPass(PassRegistry &)
void initializeCFGPrinterPass(PassRegistry &)
void initializeCFGViewerPass(PassRegistry &)
int LLVMBool
Definition: Support.h:29
void initializeAAEvalPass(PassRegistry &)
void initializeBasicAliasAnalysisPass(PassRegistry &)
void initializeBlockFrequencyInfoPass(PassRegistry &)
std::string & str()
Flushes the stream contents to the target string and returns the string's reference.
Definition: raw_ostream.h:480
struct LLVMOpaqueValue * LLVMValueRef
Represents an individual value in LLVM IR.
Definition: Core.h:92
void initializeScopedNoAliasAAPass(PassRegistry &)
void initializePostDomOnlyPrinterPass(PassRegistry &)
bool verifyModule(const Module &M, raw_ostream *OS=nullptr)
Check a module for errors.
Definition: Verifier.cpp:3651
void initializeDependenceAnalysisPass(PassRegistry &)
LLVMBool LLVMVerifyFunction(LLVMValueRef Fn, LLVMVerifierFailureAction Action)
struct LLVMOpaquePassRegistry * LLVMPassRegistryRef
Definition: Core.h:119
void LLVMViewFunctionCFGOnly(LLVMValueRef Fn)
Module.h This file contains the declarations for the Module class.
void initializeCFGOnlyViewerPass(PassRegistry &)
void initializeLintPass(PassRegistry &)
void initializeIntervalPartitionPass(PassRegistry &)
void initializeRegionOnlyViewerPass(PassRegistry &)
void initializePostDominatorTreePass(PassRegistry &)
void initializeDominanceFrontierPass(PassRegistry &)
void initializeDomPrinterPass(PassRegistry &)
void initializeLibCallAliasAnalysisPass(PassRegistry &)
void initializeMemoryDependenceAnalysisPass(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:3639
struct LLVMOpaqueModule * LLVMModuleRef
The top-level container for all other LLVM Intermediate Representation (IR) objects.
Definition: Core.h:78
void initializeScalarEvolutionPass(PassRegistry &)
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:465
void initializeCFLAliasAnalysisPass(PassRegistry &)
void initializeLazyValueInfoPass(PassRegistry &)
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:38
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
Definition: PassRegistry.h:41