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.
66}
67
69 char **OutMessages) {
70 raw_ostream *DebugOS = Action != LLVMReturnStatusAction ? &errs() : nullptr;
71 std::string Messages;
72 raw_string_ostream MsgsOS(Messages);
73
74 LLVMBool Result = verifyModule(*unwrap(M), OutMessages ? &MsgsOS : DebugOS);
75
76 // Duplicate the output to stderr.
77 if (DebugOS && OutMessages)
78 *DebugOS << MsgsOS.str();
79
80 if (Action == LLVMAbortProcessAction && Result)
81 report_fatal_error("Broken module found, compilation aborted!");
82
83 if (OutMessages)
84 *OutMessages = strdup(MsgsOS.str().c_str());
85
86 return Result;
87}
88
90 LLVMBool Result = verifyFunction(
91 *unwrap<Function>(Fn), Action != LLVMReturnStatusAction ? &errs()
92 : nullptr);
93
94 if (Action == LLVMAbortProcessAction && Result)
95 report_fatal_error("Broken function found, compilation aborted!");
96
97 return Result;
98}
99
101 Function *F = unwrap<Function>(Fn);
102 F->viewCFG();
103}
104
106 Function *F = unwrap<Function>(Fn);
107 F->viewCFGOnly();
108}
#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: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:68
void LLVMViewFunctionCFG(LLVMValueRef Fn)
Definition: Analysis.cpp:100
LLVMVerifierFailureAction
Definition: Analysis.h:34
void LLVMViewFunctionCFGOnly(LLVMValueRef Fn)
Definition: Analysis.cpp:105
LLVMBool LLVMVerifyFunction(LLVMValueRef Fn, LLVMVerifierFailureAction Action)
Definition: Analysis.cpp:89
@ 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 initializeDXILResourceWrapperPassPass(PassRegistry &)
void initializeTypeBasedAAWrapperPassPass(PassRegistry &)
void initializeTargetTransformInfoWrapperPassPass(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:7151
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 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:320
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:7162