1 //===- SafeStackLayout.h - SafeStack frame layout --------------*- C++ -*--===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_LIB_CODEGEN_SAFESTACKLAYOUT_H
11 #define LLVM_LIB_CODEGEN_SAFESTACKLAYOUT_H
13 #include "SafeStackColoring.h"
14 #include "llvm/ADT/DenseMap.h"
15 #include "llvm/ADT/SmallVector.h"
24 /// Compute the layout of an unsafe stack frame.
26 unsigned MaxAlignment
;
31 StackColoring::LiveRange Range
;
33 StackRegion(unsigned Start
, unsigned End
,
34 const StackColoring::LiveRange
&Range
)
35 : Start(Start
), End(End
), Range(Range
) {}
38 /// The list of current stack regions, sorted by StackRegion::Start.
39 SmallVector
<StackRegion
, 16> Regions
;
43 unsigned Size
, Alignment
;
44 StackColoring::LiveRange Range
;
47 SmallVector
<StackObject
, 8> StackObjects
;
49 DenseMap
<const Value
*, unsigned> ObjectOffsets
;
50 DenseMap
<const Value
*, unsigned> ObjectAlignments
;
52 void layoutObject(StackObject
&Obj
);
55 StackLayout(unsigned StackAlignment
) : MaxAlignment(StackAlignment
) {}
57 /// Add an object to the stack frame. Value pointer is opaque and used as a
58 /// handle to retrieve the object's offset in the frame later.
59 void addObject(const Value
*V
, unsigned Size
, unsigned Alignment
,
60 const StackColoring::LiveRange
&Range
);
62 /// Run the layout computation for all previously added objects.
65 /// Returns the offset to the object start in the stack frame.
66 unsigned getObjectOffset(const Value
*V
) { return ObjectOffsets
[V
]; }
68 /// Returns the alignment of the object
69 unsigned getObjectAlignment(const Value
*V
) { return ObjectAlignments
[V
]; }
71 /// Returns the size of the entire frame.
72 unsigned getFrameSize() { return Regions
.empty() ? 0 : Regions
.back().End
; }
74 /// Returns the alignment of the frame.
75 unsigned getFrameAlignment() { return MaxAlignment
; }
77 void print(raw_ostream
&OS
);
80 } // end namespace safestack
82 } // end namespace llvm
84 #endif // LLVM_LIB_CODEGEN_SAFESTACKLAYOUT_H