LLVM 20.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.
67}
68
70 char **OutMessages) {
71 raw_ostream *DebugOS = Action != LLVMReturnStatusAction ? &errs() : nullptr;
72 std::string Messages;
73 raw_string_ostream MsgsOS(Messages);
74
75 LLVMBool Result = verifyModule(*unwrap(M), OutMessages ? &MsgsOS : DebugOS);
76
77 // Duplicate the output to stderr.
78 if (DebugOS && OutMessages)
79 *DebugOS << MsgsOS.str();
80
81 if (Action == LLVMAbortProcessAction && Result)
82 report_fatal_error("Broken module found, compilation aborted!");
83
84 if (OutMessages)
85 *OutMessages = strdup(MsgsOS.str().c_str());
86
87 return Result;
88}
89
91 LLVMBool Result = verifyFunction(
92 *unwrap<Function>(Fn), Action != LLVMReturnStatusAction ? &errs()
93 : nullptr);
94
95 if (Action == LLVMAbortProcessAction && Result)
96 report_fatal_error("Broken function found, compilation aborted!");
97
98 return Result;
99}
100
102 Function *F = unwrap<Function>(Fn);
103 F->viewCFG();
104}
105
107 Function *F = unwrap<Function>(Fn);
108 F->viewCFGOnly();
109}
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:37
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:661
std::string & str()
Returns the string's reference.
Definition: raw_ostream.h:679
LLVMBool LLVMVerifyModule(LLVMModuleRef M, LLVMVerifierFailureAction Action, char **OutMessages)
Definition: Analysis.cpp:69
void LLVMViewFunctionCFG(LLVMValueRef Fn)
Definition: Analysis.cpp:101
LLVMVerifierFailureAction
Definition: Analysis.h:34
void LLVMViewFunctionCFGOnly(LLVMValueRef Fn)
Definition: Analysis.cpp:106
LLVMBool LLVMVerifyFunction(LLVMValueRef Fn, LLVMVerifierFailureAction Action)
Definition: Analysis.cpp:90
@ LLVMReturnStatusAction
Definition: Analysis.h:37
@ LLVMAbortProcessAction
Definition: Analysis.h:35
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
void initializeLCSSAVerificationPassPass(PassRegistry &)
void initializeRegionViewerPass(PassRegistry &)
void initializeTypeBasedAAWrapperPassPass(PassRegistry &)
void initializeTargetTransformInfoWrapperPassPass(PassRegistry &)
void initializeDXILResourceTypeWrapperPassPass(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:7293
void initializeDomPrinterWrapperPassPass(PassRegistry &)
void initializePostDomViewerWrapperPassPass(PassRegistry &)
void initializeRegionOnlyPrinterPass(PassRegistry &)
void initializeLazyBranchProbabilityInfoPassPass(PassRegistry &)
void initializePhiValuesWrapperPassPass(PassRegistry &)
void initializeBranchProbabilityInfoWrapperPassPass(PassRegistry &)
void initializeModuleSummaryIndexWrapperPassPass(PassRegistry &)
void initializeRegionInfoPassPass(PassRegistry &)
void initializeDomViewerWrapperPassPass(PassRegistry &)
void initializeDominanceFrontierWrapperPassPass(PassRegistry &)
void initializeScopedNoAliasAAWrapperPassPass(PassRegistry &)
void initializeRegionOnlyViewerPass(PassRegistry &)
void initializeCallGraphWrapperPassPass(PassRegistry &)
void initializeScalarEvolutionWrapperPassPass(PassRegistry &)
void initializeAAResultsWrapperPassPass(PassRegistry &)
void initializeDXILResourceBindingWrapperPassPass(PassRegistry &)
void initializeOptimizationRemarkEmitterWrapperPassPass(PassRegistry &)
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:167
void initializeIVUsersWrapperPassPass(PassRegistry &)
void initializeSCEVAAWrapperPassPass(PassRegistry &)
void initializeCallGraphDOTPrinterPass(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 initializeIRSimilarityIdentifierWrapperPassPass(PassRegistry &)
Attribute unwrap(LLVMAttributeRef Attr)
Definition: Attributes.h:332
void initializeStackSafetyGlobalInfoWrapperPassPass(PassRegistry &)
void initializeBasicAAWrapperPassPass(PassRegistry &)
void initializeDomOnlyPrinterWrapperPassPass(PassRegistry &)
void initializeStackSafetyInfoWrapperPassPass(PassRegistry &)
void initializeGlobalsAAWrapperPassPass(PassRegistry &)
void initializePostDomPrinterWrapperPassPass(PassRegistry &)
void initializeDomOnlyViewerWrapperPassPass(PassRegistry &)
void initializeLazyBlockFrequencyInfoPassPass(PassRegistry &)
void initializeLazyValueInfoWrapperPassPass(PassRegistry &)
void initializePostDomOnlyViewerWrapperPassPass(PassRegistry &)
void initializeRegionPrinterPass(PassRegistry &)
void initializeAnalysis(PassRegistry &)
Initialize all passes linked into the Analysis library.
Definition: Analysis.cpp:20
bool verifyModule(const Module &M, raw_ostream *OS=nullptr, bool *BrokenDebugInfo=nullptr)
Check a module for errors.
Definition: Verifier.cpp:7304