23 #define DEBUG_TYPE "safestacklayout" 30 OS <<
"Stack regions:\n";
31 for (
unsigned i = 0; i < Regions.
size(); ++i) {
32 OS <<
" " << i <<
": [" << Regions[i].Start <<
", " << Regions[i].End
33 <<
"), range " << Regions[i].Range <<
"\n";
35 OS <<
"Stack objects:\n";
36 for (
auto &
IT : ObjectOffsets) {
37 OS <<
" at " <<
IT.getSecond() <<
": " << *
IT.getFirst() <<
"\n";
44 ObjectAlignments[V] = Alignment;
45 MaxAlignment =
std::max(MaxAlignment, Alignment);
53 void StackLayout::layoutObject(StackObject &Obj) {
57 unsigned LastRegionEnd = Regions.
empty() ? 0 : Regions.
back().End;
59 unsigned End = Start + Obj.Size;
61 ObjectOffsets[Obj.Handle] = End;
66 << Obj.Alignment <<
", range " << Obj.Range <<
"\n");
67 assert(Obj.Alignment <= MaxAlignment);
69 unsigned End = Start + Obj.Size;
70 LLVM_DEBUG(
dbgs() <<
" First candidate: " << Start <<
" .. " << End <<
"\n");
71 for (
const StackRegion &R : Regions) {
72 LLVM_DEBUG(
dbgs() <<
" Examining region: " << R.Start <<
" .. " << R.End
73 <<
", range " << R.Range <<
"\n");
79 if (Obj.Range.Overlaps(R.Range)) {
82 End = Start + Obj.Size;
83 LLVM_DEBUG(
dbgs() <<
" Overlaps. Next candidate: " << Start <<
" .. " 93 unsigned LastRegionEnd = Regions.empty() ? 0 : Regions.back().End;
94 if (End > LastRegionEnd) {
96 if (Start > LastRegionEnd) {
97 LLVM_DEBUG(
dbgs() <<
" Creating gap region: " << LastRegionEnd <<
" .. " 99 Regions.emplace_back(LastRegionEnd, Start, StackColoring::LiveRange());
100 LastRegionEnd = Start;
102 LLVM_DEBUG(
dbgs() <<
" Creating new region: " << LastRegionEnd <<
" .. " 103 << End <<
", range " << Obj.Range <<
"\n");
104 Regions.emplace_back(LastRegionEnd, End, Obj.Range);
109 for (
unsigned i = 0; i < Regions.size(); ++i) {
110 StackRegion &R = Regions[i];
111 if (Start > R.Start && Start < R.End) {
113 R.Start = R0.End = Start;
114 Regions.insert(&R, R0);
117 if (End > R.Start && End < R.End) {
119 R0.End = R.Start = End;
120 Regions.insert(&R, R0);
126 for (StackRegion &R : Regions) {
127 if (Start < R.End && End > R.Start)
128 R.Range.Join(Obj.Range);
133 ObjectOffsets[Obj.Handle] = End;
143 if (StackObjects.
size() > 2)
145 [](
const StackObject &a,
const StackObject &b) {
146 return a.Size > b.Size;
149 for (
auto &Obj : StackObjects)
reference emplace_back(ArgTypes &&... Args)
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.
This class represents lattice values for constants.
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
void push_back(const T &Elt)
static unsigned AdjustStackOffset(unsigned Offset, unsigned Size, unsigned Alignment)
initializer< Ty > init(const Ty &Val)
Align max(MaybeAlign Lhs, Align Rhs)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void computeLayout()
Run the layout computation for all previously added objects.
static cl::opt< ITMode > IT(cl::desc("IT block support"), cl::Hidden, cl::init(DefaultIT), cl::ZeroOrMore, cl::values(clEnumValN(DefaultIT, "arm-default-it", "Generate IT block based on arch"), clEnumValN(RestrictedIT, "arm-restrict-it", "Disallow deprecated IT based on ARMv8"), clEnumValN(NoRestrictedIT, "arm-no-restrict-it", "Allow IT blocks based on ARMv7")))
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
void print(raw_ostream &OS)
LLVM_NODISCARD bool empty() const
static cl::opt< bool > ClLayout("safe-stack-layout", cl::desc("enable safe stack layout"), cl::Hidden, cl::init(true))
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void stable_sort(R &&Range)
LLVM Value Representation.
This class implements an extremely fast bulk output stream that can only output to a stream...