LLVM  11.0.0git
StackSafetyAnalysis.h
Go to the documentation of this file.
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.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_ANALYSIS_STACKSAFETYANALYSIS_H
14 #define LLVM_ANALYSIS_STACKSAFETYANALYSIS_H
15 
17 #include "llvm/IR/PassManager.h"
18 #include "llvm/Pass.h"
19 
20 namespace llvm {
21 
22 class AllocaInst;
23 class ScalarEvolution;
24 
25 /// Interface to access stack safety analysis results for single function.
27 public:
28  struct InfoTy;
29 
30 private:
31  Function *F = nullptr;
32  std::function<ScalarEvolution &()> GetSE;
33  mutable std::unique_ptr<InfoTy> Info;
34 
35 public:
41 
42  const InfoTy &getInfo() const;
43 
44  // TODO: Add useful for client methods.
45  void print(raw_ostream &O) const;
46 
47  /// Parameters use for a FunctionSummary.
48  std::vector<FunctionSummary::ParamAccess> getParamAccesses() const;
49 };
50 
52 public:
53  struct InfoTy;
54 
55 private:
56  Module *M = nullptr;
57  std::function<const StackSafetyInfo &(Function &F)> GetSSI;
58  const ModuleSummaryIndex *Index = nullptr;
59  mutable std::unique_ptr<InfoTy> Info;
60  const InfoTy &getInfo() const;
61 
62 public:
65  Module *M, std::function<const StackSafetyInfo &(Function &F)> GetSSI,
66  const ModuleSummaryIndex *Index);
70 
71  bool isSafe(const AllocaInst &AI) const;
72  void print(raw_ostream &O) const;
73  void dump() const;
74 };
75 
76 /// StackSafetyInfo wrapper for the new pass manager.
77 class StackSafetyAnalysis : public AnalysisInfoMixin<StackSafetyAnalysis> {
79  static AnalysisKey Key;
80 
81 public:
84 };
85 
86 /// Printer pass for the \c StackSafetyAnalysis results.
87 class StackSafetyPrinterPass : public PassInfoMixin<StackSafetyPrinterPass> {
88  raw_ostream &OS;
89 
90 public:
91  explicit StackSafetyPrinterPass(raw_ostream &OS) : OS(OS) {}
93 };
94 
95 /// StackSafetyInfo wrapper for the legacy pass manager
97  StackSafetyInfo SSI;
98 
99 public:
100  static char ID;
102 
103  const StackSafetyInfo &getResult() const { return SSI; }
104 
105  void print(raw_ostream &O, const Module *M) const override;
106  void getAnalysisUsage(AnalysisUsage &AU) const override;
107 
108  bool runOnFunction(Function &F) override;
109 };
110 
111 /// This pass performs the global (interprocedural) stack safety analysis (new
112 /// pass manager).
114  : public AnalysisInfoMixin<StackSafetyGlobalAnalysis> {
116  static AnalysisKey Key;
117 
118 public:
120  Result run(Module &M, ModuleAnalysisManager &AM);
121 };
122 
123 /// Printer pass for the \c StackSafetyGlobalAnalysis results.
125  : public PassInfoMixin<StackSafetyGlobalPrinterPass> {
126  raw_ostream &OS;
127 
128 public:
129  explicit StackSafetyGlobalPrinterPass(raw_ostream &OS) : OS(OS) {}
131 };
132 
133 /// This pass performs the global (interprocedural) stack safety analysis
134 /// (legacy pass manager).
137 
138 public:
139  static char ID;
140 
143 
144  const StackSafetyGlobalInfo &getResult() const { return SSGI; }
145 
146  void print(raw_ostream &O, const Module *M) const override;
147  void getAnalysisUsage(AnalysisUsage &AU) const override;
148 
149  bool runOnModule(Module &M) override;
150 };
151 
152 bool needsParamAccessSummary(const Module &M);
153 
155 
156 } // end namespace llvm
157 
158 #endif // LLVM_ANALYSIS_STACKSAFETYANALYSIS_H
This class represents lattice values for constants.
Definition: AllocatorList.h:23
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:67
The main scalar evolution driver.
F(f)
StackSafetyInfo & operator=(StackSafetyInfo &&)
Key
PAL metadata keys.
#define F(x, y, z)
Definition: MD5.cpp:56
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:373
This pass performs the global (interprocedural) stack safety analysis (legacy pass manager)...
Class to hold module path string table and global value map, and encapsulate methods for operating on...
Analysis containing CSE Info
Definition: CSEInfo.cpp:25
const StackSafetyGlobalInfo & getResult() const
StackSafetyInfo wrapper for the new pass manager.
static bool runOnFunction(Function &F, bool PostInlining)
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:154
void generateParamAccessSummary(ModuleSummaryIndex &Index)
Interface to access stack safety analysis results for single function.
A CRTP mix-in that provides informational APIs needed for analysis passes.
Definition: PassManager.h:390
Represent the analysis usage information of a pass.
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:284
This pass performs the global (interprocedural) stack safety analysis (new pass manager).
StackSafetyInfo wrapper for the legacy pass manager.
void print(raw_ostream &O) const
Printer pass for the StackSafetyAnalysis results.
const StackSafetyInfo & getResult() const
Printer pass for the StackSafetyGlobalAnalysis results.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition: Pass.h:224
StackSafetyPrinterPass(raw_ostream &OS)
bool needsParamAccessSummary(const Module &M)
const InfoTy & getInfo() const
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
std::vector< FunctionSummary::ParamAccess > getParamAccesses() const
Parameters use for a FunctionSummary.
print Print MemDeps of function
A container for analyses that lazily runs them and caches their results.
This header defines various interfaces for pass management in LLVM.
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: PassManager.h:71
an instruction to allocate memory on the stack
Definition: Instructions.h:60