[Alignment][NFC] Migrate Instructions to Align
[llvm-core.git] / include / llvm / Analysis / StackSafetyAnalysis.h
blobf9d8b08ac1425c38f11fd2a2cc647f591fae1fc5
1 //===- StackSafetyAnalysis.h - Stack memory safety analysis -----*- C++ -*-===//
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 // 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"
19 namespace llvm {
21 /// Interface to access stack safety analysis results for single function.
22 class StackSafetyInfo {
23 public:
24 struct FunctionInfo;
26 private:
27 std::unique_ptr<FunctionInfo> Info;
29 public:
30 StackSafetyInfo();
31 StackSafetyInfo(FunctionInfo &&Info);
32 StackSafetyInfo(StackSafetyInfo &&);
33 StackSafetyInfo &operator=(StackSafetyInfo &&);
34 ~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;
45 public:
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> {
52 raw_ostream &OS;
54 public:
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 {
61 StackSafetyInfo SSI;
63 public:
64 static char ID;
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
78 /// pass manager).
79 class StackSafetyGlobalAnalysis
80 : public AnalysisInfoMixin<StackSafetyGlobalAnalysis> {
81 friend AnalysisInfoMixin<StackSafetyGlobalAnalysis>;
82 static AnalysisKey Key;
84 public:
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> {
92 raw_ostream &OS;
94 public:
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;
104 public:
105 static char ID;
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