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