24 #define DEBUG_TYPE "safestacklayout" 31 OS <<
"Stack regions:\n";
32 for (
unsigned i = 0; i < Regions.
size(); ++i) {
33 OS <<
" " << i <<
": [" << Regions[i].Start <<
", " << Regions[i].End
34 <<
"), range " << Regions[i].Range <<
"\n";
36 OS <<
"Stack objects:\n";
37 for (
auto &
IT : ObjectOffsets) {
38 OS <<
" at " <<
IT.getSecond() <<
": " << *
IT.getFirst() <<
"\n";
45 ObjectAlignments[V] = Alignment;
46 MaxAlignment =
std::max(MaxAlignment, Alignment);
54 void StackLayout::layoutObject(StackObject &Obj) {
58 unsigned LastRegionEnd = Regions.
empty() ? 0 : Regions.
back().End;
60 unsigned End = Start + Obj.Size;
62 ObjectOffsets[Obj.Handle] = End;
67 << Obj.Alignment <<
", range " << Obj.Range <<
"\n");
68 assert(Obj.Alignment <= MaxAlignment);
70 unsigned End = Start + Obj.Size;
71 LLVM_DEBUG(
dbgs() <<
" First candidate: " << Start <<
" .. " << End <<
"\n");
72 for (
const StackRegion &R : Regions) {
73 LLVM_DEBUG(
dbgs() <<
" Examining region: " << R.Start <<
" .. " << R.End
74 <<
", range " << R.Range <<
"\n");
80 if (Obj.Range.Overlaps(R.Range)) {
83 End = Start + Obj.Size;
84 LLVM_DEBUG(
dbgs() <<
" Overlaps. Next candidate: " << Start <<
" .. " 94 unsigned LastRegionEnd = Regions.empty() ? 0 : Regions.back().End;
95 if (End > LastRegionEnd) {
97 if (Start > LastRegionEnd) {
98 LLVM_DEBUG(
dbgs() <<
" Creating gap region: " << LastRegionEnd <<
" .. " 100 Regions.emplace_back(LastRegionEnd, Start, StackColoring::LiveRange());
101 LastRegionEnd = Start;
103 LLVM_DEBUG(
dbgs() <<
" Creating new region: " << LastRegionEnd <<
" .. " 104 << End <<
", range " << Obj.Range <<
"\n");
105 Regions.emplace_back(LastRegionEnd, End, Obj.Range);
110 for (
unsigned i = 0; i < Regions.size(); ++i) {
111 StackRegion &R = Regions[i];
112 if (Start > R.Start && Start < R.End) {
114 R.Start = R0.End = Start;
115 Regions.insert(&R, R0);
118 if (End > R.Start && End < R.End) {
120 R0.End = R.Start = End;
121 Regions.insert(&R, R0);
127 for (StackRegion &R : Regions) {
128 if (Start < R.End && End > R.Start)
129 R.Range.Join(Obj.Range);
134 ObjectOffsets[Obj.Handle] = End;
144 if (StackObjects.
size() > 2)
145 std::stable_sort(StackObjects.
begin() + 1, StackObjects.
end(),
146 [](
const StackObject &a,
const StackObject &b) {
147 return a.Size > b.Size;
150 for (
auto &Obj : StackObjects)
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.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
This class represents lattice values for constants.
void push_back(const T &Elt)
uint64_t alignTo(uint64_t Value, uint64_t Align, uint64_t Skew=0)
Returns the next integer (mod 2**64) that is greater than or equal to Value and is a multiple of Alig...
static unsigned AdjustStackOffset(unsigned Offset, unsigned Size, unsigned Alignment)
initializer< Ty > init(const Ty &Val)
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
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")))
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
void print(raw_ostream &OS)
void emplace_back(ArgTypes &&... Args)
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())
LLVM Value Representation.
This class implements an extremely fast bulk output stream that can only output to a stream...