1 //===- StackSafetyAnalysis.h - Stack memory safety analysis -----*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // Stack Safety Analysis detects allocas and arguments with safe access.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_ANALYSIS_STACKSAFETYANALYSIS_H
14 #define LLVM_ANALYSIS_STACKSAFETYANALYSIS_H
16 #include "llvm/IR/PassManager.h"
17 #include "llvm/Pass.h"
21 /// Interface to access stack safety analysis results for single function.
22 class StackSafetyInfo
{
27 std::unique_ptr
<FunctionInfo
> Info
;
31 StackSafetyInfo(FunctionInfo
&&Info
);
32 StackSafetyInfo(StackSafetyInfo
&&);
33 StackSafetyInfo
&operator=(StackSafetyInfo
&&);
36 // TODO: Add useful for client methods.
37 void print(raw_ostream
&O
) const;
40 /// StackSafetyInfo wrapper for the new pass manager.
41 class StackSafetyAnalysis
: public AnalysisInfoMixin
<StackSafetyAnalysis
> {
42 friend AnalysisInfoMixin
<StackSafetyAnalysis
>;
43 static AnalysisKey Key
;
46 using Result
= StackSafetyInfo
;
47 StackSafetyInfo
run(Function
&F
, FunctionAnalysisManager
&AM
);
50 /// Printer pass for the \c StackSafetyAnalysis results.
51 class StackSafetyPrinterPass
: public PassInfoMixin
<StackSafetyPrinterPass
> {
55 explicit StackSafetyPrinterPass(raw_ostream
&OS
) : OS(OS
) {}
56 PreservedAnalyses
run(Function
&F
, FunctionAnalysisManager
&AM
);
59 /// StackSafetyInfo wrapper for the legacy pass manager
60 class StackSafetyInfoWrapperPass
: public FunctionPass
{
65 StackSafetyInfoWrapperPass();
67 const StackSafetyInfo
&getResult() const { return SSI
; }
69 void print(raw_ostream
&O
, const Module
*M
) const override
;
70 void getAnalysisUsage(AnalysisUsage
&AU
) const override
;
72 bool runOnFunction(Function
&F
) override
;
75 using StackSafetyGlobalInfo
= std::map
<const GlobalValue
*, StackSafetyInfo
>;
77 /// This pass performs the global (interprocedural) stack safety analysis (new
79 class StackSafetyGlobalAnalysis
80 : public AnalysisInfoMixin
<StackSafetyGlobalAnalysis
> {
81 friend AnalysisInfoMixin
<StackSafetyGlobalAnalysis
>;
82 static AnalysisKey Key
;
85 using Result
= StackSafetyGlobalInfo
;
86 Result
run(Module
&M
, ModuleAnalysisManager
&AM
);
89 /// Printer pass for the \c StackSafetyGlobalAnalysis results.
90 class StackSafetyGlobalPrinterPass
91 : public PassInfoMixin
<StackSafetyGlobalPrinterPass
> {
95 explicit StackSafetyGlobalPrinterPass(raw_ostream
&OS
) : OS(OS
) {}
96 PreservedAnalyses
run(Module
&M
, ModuleAnalysisManager
&AM
);
99 /// This pass performs the global (interprocedural) stack safety analysis
100 /// (legacy pass manager).
101 class StackSafetyGlobalInfoWrapperPass
: public ModulePass
{
102 StackSafetyGlobalInfo SSI
;
107 StackSafetyGlobalInfoWrapperPass();
109 const StackSafetyGlobalInfo
&getResult() const { return SSI
; }
111 void print(raw_ostream
&O
, const Module
*M
) const override
;
112 void getAnalysisUsage(AnalysisUsage
&AU
) const override
;
114 bool runOnModule(Module
&M
) override
;
117 } // end namespace llvm
119 #endif // LLVM_ANALYSIS_STACKSAFETYANALYSIS_H