LLVM 22.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"
10#include "llvm/IR/Module.h"
11#include "llvm/IR/Verifier.h"
13#include "llvm/PassRegistry.h"
15#include <cstring>
16
17using namespace llvm;
18
19/// initializeAnalysis - Initialize all passes linked into the Analysis library.
78}
79
81 char **OutMessages) {
82 raw_ostream *DebugOS = Action != LLVMReturnStatusAction ? &errs() : nullptr;
83 std::string Messages;
84 raw_string_ostream MsgsOS(Messages);
85
86 LLVMBool Result = verifyModule(*unwrap(M), OutMessages ? &MsgsOS : DebugOS);
87
88 // Duplicate the output to stderr.
89 if (DebugOS && OutMessages)
90 *DebugOS << MsgsOS.str();
91
92 if (Action == LLVMAbortProcessAction && Result)
93 report_fatal_error("Broken module found, compilation aborted!");
94
95 if (OutMessages)
96 *OutMessages = strdup(MsgsOS.str().c_str());
97
98 return Result;
99}
100
102 LLVMBool Result = verifyFunction(
103 *unwrap<Function>(Fn), Action != LLVMReturnStatusAction ? &errs()
104 : nullptr);
105
106 if (Action == LLVMAbortProcessAction && Result)
107 report_fatal_error("Broken function found, compilation aborted!");
108
109 return Result;
110}
111
113 Function *F = unwrap<Function>(Fn);
114 F->viewCFG();
115}
116
118 Function *F = unwrap<Function>(Fn);
119 F->viewCFGOnly();
120}
Module.h This file contains the declarations for the Module class.
#define F(x, y, z)
Definition: MD5.cpp:55
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:53
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:662
std::string & str()
Returns the string's reference.
Definition: raw_ostream.h:680
LLVMBool LLVMVerifyFunction(LLVMValueRef Fn, LLVMVerifierFailureAction Action)
Definition: Analysis.cpp:101
void LLVMViewFunctionCFG(LLVMValueRef Fn)
Definition: Analysis.cpp:112
LLVMBool LLVMVerifyModule(LLVMModuleRef M, LLVMVerifierFailureAction Action, char **OutMessages)
Definition: Analysis.cpp:80
void LLVMViewFunctionCFGOnly(LLVMValueRef Fn)
Definition: Analysis.cpp:117
LLVMVerifierFailureAction
Definition: Analysis.h:35
@ LLVMReturnStatusAction
Definition: Analysis.h:38
@ LLVMAbortProcessAction
Definition: Analysis.h:36
struct LLVMOpaqueValue * LLVMValueRef
Represents an individual value in LLVM IR.
Definition: Types.h:75
int LLVMBool
Definition: Types.h:28
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
LLVM_ABI void initializeSCEVAAWrapperPassPass(PassRegistry &)
LLVM_ABI void initializeLazyBranchProbabilityInfoPassPass(PassRegistry &)
LLVM_ABI void initializePostDomOnlyViewerWrapperPassPass(PassRegistry &)
LLVM_ABI void initializeLCSSAVerificationPassPass(PassRegistry &)
LLVM_ABI void initializePostDomViewerWrapperPassPass(PassRegistry &)
LLVM_ABI void initializeDependenceAnalysisWrapperPassPass(PassRegistry &)
LLVM_ABI void initializeBasicAAWrapperPassPass(PassRegistry &)
LLVM_ABI void initializeTypeBasedAAWrapperPassPass(PassRegistry &)
LLVM_ABI void initializeUniformityInfoWrapperPassPass(PassRegistry &)
LLVM_ABI bool verifyFunction(const Function &F, raw_ostream *OS=nullptr)
Check a function for errors, useful for use when debugging a pass.
Definition: Verifier.cpp:7502
LLVM_ABI void initializeRegionViewerPass(PassRegistry &)
LLVM_ABI void initializeDomOnlyPrinterWrapperPassPass(PassRegistry &)
LLVM_ABI void initializeDXILMetadataAnalysisWrapperPassPass(PassRegistry &)
LLVM_ABI void initializeBlockFrequencyInfoWrapperPassPass(PassRegistry &)
LLVM_ABI void initializeDomViewerWrapperPassPass(PassRegistry &)
LLVM_ABI void initializeRegionInfoPassPass(PassRegistry &)
LLVM_ABI void initializeLazyBFIPassPass(PassRegistry &)
LLVM_ABI void initializeProfileSummaryInfoWrapperPassPass(PassRegistry &)
LLVM_ABI void initializeOptimizationRemarkEmitterWrapperPassPass(PassRegistry &)
LLVM_ABI void initializeStackSafetyGlobalInfoWrapperPassPass(PassRegistry &)
LLVM_ABI void initializeMemorySSAWrapperPassPass(PassRegistry &)
LLVM_ABI void initializeCallGraphDOTPrinterPass(PassRegistry &)
LLVM_ABI void initializeCallGraphWrapperPassPass(PassRegistry &)
LLVM_ABI void initializeRegionOnlyPrinterPass(PassRegistry &)
LLVM_ABI void initializeScalarEvolutionWrapperPassPass(PassRegistry &)
LLVM_ABI void initializeStackSafetyInfoWrapperPassPass(PassRegistry &)
LLVM_ABI void initializeDXILResourceBindingWrapperPassPass(PassRegistry &)
LLVM_ABI void initializeScopedNoAliasAAWrapperPassPass(PassRegistry &)
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition: Error.cpp:167
LLVM_ABI void initializeDomOnlyViewerWrapperPassPass(PassRegistry &)
LLVM_ABI void initializePostDomPrinterWrapperPassPass(PassRegistry &)
LLVM_ABI void initializePostDominatorTreeWrapperPassPass(PassRegistry &)
LLVM_ABI void initializeExternalAAWrapperPassPass(PassRegistry &)
LLVM_ABI void initializeRegionOnlyViewerPass(PassRegistry &)
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
LLVM_ABI void initializePostDomOnlyPrinterWrapperPassPass(PassRegistry &)
LLVM_ABI void initializeIRSimilarityIdentifierWrapperPassPass(PassRegistry &)
LLVM_ABI void initializeCycleInfoWrapperPassPass(PassRegistry &)
Attribute unwrap(LLVMAttributeRef Attr)
Definition: Attributes.h:351
LLVM_ABI void initializeDominanceFrontierWrapperPassPass(PassRegistry &)
LLVM_ABI void initializeAssumptionCacheTrackerPass(PassRegistry &)
LLVM_ABI void initializeTargetTransformInfoWrapperPassPass(PassRegistry &)
LLVM_ABI void initializeAAResultsWrapperPassPass(PassRegistry &)
LLVM_ABI void initializeDXILResourceTypeWrapperPassPass(PassRegistry &)
LLVM_ABI void initializeIVUsersWrapperPassPass(PassRegistry &)
LLVM_ABI void initializeTargetLibraryInfoWrapperPassPass(PassRegistry &)
LLVM_ABI void initializeCallGraphViewerPass(PassRegistry &)
LLVM_ABI void initializeImmutableModuleSummaryIndexWrapperPassPass(PassRegistry &)
LLVM_ABI void initializeDXILResourceWrapperPassPass(PassRegistry &)
LLVM_ABI void initializeBranchProbabilityInfoWrapperPassPass(PassRegistry &)
LLVM_ABI void initializeRegionPrinterPass(PassRegistry &)
LLVM_ABI void initializeLoopInfoWrapperPassPass(PassRegistry &)
LLVM_ABI void initializeStaticDataProfileInfoWrapperPassPass(PassRegistry &)
LLVM_ABI void initializeLazyValueInfoWrapperPassPass(PassRegistry &)
LLVM_ABI void initializeLazyBlockFrequencyInfoPassPass(PassRegistry &)
LLVM_ABI void initializeGlobalsAAWrapperPassPass(PassRegistry &)
LLVM_ABI void initializeDomPrinterWrapperPassPass(PassRegistry &)
LLVM_ABI void initializeMemoryDependenceWrapperPassPass(PassRegistry &)
LLVM_ABI void initializePhiValuesWrapperPassPass(PassRegistry &)
LLVM_ABI void initializeModuleSummaryIndexWrapperPassPass(PassRegistry &)
LLVM_ABI void initializeAnalysis(PassRegistry &)
Initialize all passes linked into the Analysis library.
Definition: Analysis.cpp:20
LLVM_ABI bool verifyModule(const Module &M, raw_ostream *OS=nullptr, bool *BrokenDebugInfo=nullptr)
Check a module for errors.
Definition: Verifier.cpp:7513