LLVM  10.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);
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: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 &)
void initializeMustBeExecutedContextPrinterPass(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:204
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: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:519
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:5065
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:5054
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:503
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 &)