LLVM  4.0.0
SafeStackLayout.h
Go to the documentation of this file.
1 //===-- SafeStackLayout.h - SafeStack frame layout -------------*- C++ -*--===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLVM_LIB_CODEGEN_SAFESTACKLAYOUT_H
11 #define LLVM_LIB_CODEGEN_SAFESTACKLAYOUT_H
12 
13 #include "SafeStackColoring.h"
14 
15 namespace llvm {
16 namespace safestack {
17 
18 /// Compute the layout of an unsafe stack frame.
19 class StackLayout {
20  unsigned MaxAlignment;
21 
22  struct StackRegion {
23  unsigned Start;
24  unsigned End;
26  StackRegion(unsigned Start, unsigned End,
27  const StackColoring::LiveRange &Range)
28  : Start(Start), End(End), Range(Range) {}
29  };
30  /// The list of current stack regions, sorted by StackRegion::Start.
32 
33  struct StackObject {
34  const Value *Handle;
35  unsigned Size, Alignment;
37  };
38  SmallVector<StackObject, 8> StackObjects;
39 
41 
42  void layoutObject(StackObject &Obj);
43 
44 public:
45  StackLayout(unsigned StackAlignment) : MaxAlignment(StackAlignment) {}
46  /// Add an object to the stack frame. Value pointer is opaque and used as a
47  /// handle to retrieve the object's offset in the frame later.
48  void addObject(const Value *V, unsigned Size, unsigned Alignment,
49  const StackColoring::LiveRange &Range);
50 
51  /// Run the layout computation for all previously added objects.
52  void computeLayout();
53 
54  /// Returns the offset to the object start in the stack frame.
55  unsigned getObjectOffset(const Value *V) { return ObjectOffsets[V]; }
56 
57  /// Returns the size of the entire frame.
58  unsigned getFrameSize() { return Regions.empty() ? 0 : Regions.back().End; }
59 
60  /// Returns the alignment of the frame.
61  unsigned getFrameAlignment() { return MaxAlignment; }
62  void print(raw_ostream &OS);
63 };
64 
65 } // namespace safestack
66 } // namespace llvm
67 
68 #endif // LLVM_LIB_CODEGEN_SAFESTACKLAYOUT_H
This class represents a set of interesting instructions where an alloca is live.
void addObject(const Value *V, unsigned Size, unsigned Alignment, const StackColoring::LiveRange &Range)
Add an object to the stack frame.
unsigned getFrameSize()
Returns the size of the entire frame.
unsigned getObjectOffset(const Value *V)
Returns the offset to the object start in the stack frame.
StackLayout(unsigned StackAlignment)
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:60
Compute the layout of an unsafe stack frame.
static const unsigned End
void computeLayout()
Run the layout computation for all previously added objects.
unsigned getFrameAlignment()
Returns the alignment of the frame.
void print(raw_ostream &OS)
LLVM Value Representation.
Definition: Value.h:71
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44