LLVM 17.0.0git
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"
11#include "llvm/IR/Module.h"
12#include "llvm/IR/Verifier.h"
14#include "llvm/PassRegistry.h"
16#include <cstring>
17
18using namespace llvm;
19
20/// initializeAnalysis - Initialize all passes linked into the Analysis library.
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
118 LLVMBool Result = verifyFunction(
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}
#define F(x, y, z)
Definition: MD5.cpp:55
Module.h This file contains the declarations for the Module class.
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
Definition: PassRegistry.h:38
A global registry used in conjunction with static constructors to make pluggable components (like tar...
Definition: Registry.h:44
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:642
std::string & str()
Returns the string's reference.
Definition: raw_ostream.h:660
LLVMBool LLVMVerifyModule(LLVMModuleRef M, LLVMVerifierFailureAction Action, char **OutMessages)
Definition: Analysis.cpp:96
void LLVMViewFunctionCFG(LLVMValueRef Fn)
Definition: Analysis.cpp:128
LLVMVerifierFailureAction
Definition: Analysis.h:34
void LLVMViewFunctionCFGOnly(LLVMValueRef Fn)
Definition: Analysis.cpp:133
LLVMBool LLVMVerifyFunction(LLVMValueRef Fn, LLVMVerifierFailureAction Action)
Definition: Analysis.cpp:117
@ LLVMReturnStatusAction
Definition: Analysis.h:37
@ LLVMAbortProcessAction
Definition: Analysis.h:35
void LLVMInitializeAnalysis(LLVMPassRegistryRef R)
Definition: Analysis.cpp:88
void LLVMInitializeIPA(LLVMPassRegistryRef R)
Definition: Analysis.cpp:92
struct LLVMOpaqueValue * LLVMValueRef
Represents an individual value in LLVM IR.
Definition: Types.h:75
int LLVMBool
Definition: Types.h:28
struct LLVMOpaquePassRegistry * LLVMPassRegistryRef
Definition: Types.h:130
struct LLVMOpaqueModule * LLVMModuleRef
The top-level container for all other LLVM Intermediate Representation (IR) objects.
Definition: Types.h:61
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void initializeLCSSAVerificationPassPass(PassRegistry &)
void initializeRegionViewerPass(PassRegistry &)
void initializeTypeBasedAAWrapperPassPass(PassRegistry &)
void initializeTargetTransformInfoWrapperPassPass(PassRegistry &)
void initializeMemorySSAPrinterLegacyPassPass(PassRegistry &)
void initializeLoopInfoWrapperPassPass(PassRegistry &)
void initializeCallGraphViewerPass(PassRegistry &)
void initializeMemorySSAWrapperPassPass(PassRegistry &)
void initializeMemoryDependenceWrapperPassPass(PassRegistry &)
void initializeDependenceAnalysisWrapperPassPass(PassRegistry &)
void initializeCycleInfoWrapperPassPass(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:6428
void initializeDomPrinterWrapperPassPass(PassRegistry &)
void initializeAAEvalLegacyPassPass(PassRegistry &)
void initializePostDomViewerWrapperPassPass(PassRegistry &)
void initializeRegionOnlyPrinterPass(PassRegistry &)
void initializeInstCountLegacyPassPass(PassRegistry &)
void initializeLazyBranchProbabilityInfoPassPass(PassRegistry &)
void initializePhiValuesWrapperPassPass(PassRegistry &)
void initializeMustBeExecutedContextPrinterPass(PassRegistry &)
void initializeBranchProbabilityInfoWrapperPassPass(PassRegistry &)
void initializeModuleSummaryIndexWrapperPassPass(PassRegistry &)
void initializeLazyValueInfoPrinterPass(PassRegistry &)
void initializeCFGOnlyPrinterLegacyPassPass(PassRegistry &)
void initializeRegionInfoPassPass(PassRegistry &)
void initializeDomViewerWrapperPassPass(PassRegistry &)
void initializeDominanceFrontierWrapperPassPass(PassRegistry &)
void initializeScopedNoAliasAAWrapperPassPass(PassRegistry &)
void initializeRegionOnlyViewerPass(PassRegistry &)
void initializeMemDepPrinterPass(PassRegistry &)
void initializeCallGraphWrapperPassPass(PassRegistry &)
void initializeScalarEvolutionWrapperPassPass(PassRegistry &)
void initializeDelinearizationPass(PassRegistry &)
void initializeAAResultsWrapperPassPass(PassRegistry &)
void initializeCostModelAnalysisPass(PassRegistry &)
void initializeOptimizationRemarkEmitterWrapperPassPass(PassRegistry &)
void initializeDemandedBitsWrapperPassPass(PassRegistry &)
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:145
void initializeIVUsersWrapperPassPass(PassRegistry &)
void initializeCallGraphPrinterLegacyPassPass(PassRegistry &)
void initializeSCEVAAWrapperPassPass(PassRegistry &)
void initializeCallGraphDOTPrinterPass(PassRegistry &)
void initializeModuleDebugInfoLegacyPrinterPass(PassRegistry &)
void initializePostDominatorTreeWrapperPassPass(PassRegistry &)
void initializePostDomOnlyPrinterWrapperPassPass(PassRegistry &)
void initializeBlockFrequencyInfoWrapperPassPass(PassRegistry &)
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
void initializeLegacyDivergenceAnalysisPass(PassRegistry &)
void initializeIRSimilarityIdentifierWrapperPassPass(PassRegistry &)
Attribute unwrap(LLVMAttributeRef Attr)
Definition: Attributes.h:285
void initializeStackSafetyGlobalInfoWrapperPassPass(PassRegistry &)
void initializeBasicAAWrapperPassPass(PassRegistry &)
void initializeDomOnlyPrinterWrapperPassPass(PassRegistry &)
void initializeCFGViewerLegacyPassPass(PassRegistry &)
void initializeMemDerefPrinterPass(PassRegistry &)
void initializeCFGPrinterLegacyPassPass(PassRegistry &)
void initializeStackSafetyInfoWrapperPassPass(PassRegistry &)
void initializeGlobalsAAWrapperPassPass(PassRegistry &)
void initializePostDomPrinterWrapperPassPass(PassRegistry &)
void initializeDomOnlyViewerWrapperPassPass(PassRegistry &)
void initializeLazyBlockFrequencyInfoPassPass(PassRegistry &)
void initializeLintLegacyPassPass(PassRegistry &)
void initializeLazyValueInfoWrapperPassPass(PassRegistry &)
void initializeMustExecutePrinterPass(PassRegistry &)
void initializeCFGOnlyViewerLegacyPassPass(PassRegistry &)
void initializePostDomOnlyViewerWrapperPassPass(PassRegistry &)
void initializeRegionPrinterPass(PassRegistry &)
void initializeAnalysis(PassRegistry &)
Initialize all passes linked into the Analysis library.
Definition: Analysis.cpp:21
bool verifyModule(const Module &M, raw_ostream *OS=nullptr, bool *BrokenDebugInfo=nullptr)
Check a module for errors.
Definition: Verifier.cpp:6439
void initializeIntervalPartitionPass(PassRegistry &)