mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-01-26 19:36:28 +00:00
[SafeStack] Use Align instead of uint64_t
It is better typed, and the calls to getAlignment() are deprecated. Differential Revision: https://reviews.llvm.org/D115466
This commit is contained in:
parent
3d595eccc7
commit
eba7b26815
@ -521,8 +521,7 @@ Value *SafeStack::moveStaticAllocasToUnsafeStack(
|
|||||||
StackLayout SSL(StackAlignment);
|
StackLayout SSL(StackAlignment);
|
||||||
if (StackGuardSlot) {
|
if (StackGuardSlot) {
|
||||||
Type *Ty = StackGuardSlot->getAllocatedType();
|
Type *Ty = StackGuardSlot->getAllocatedType();
|
||||||
uint64_t Align =
|
Align Align = std::max(DL.getPrefTypeAlign(Ty), StackGuardSlot->getAlign());
|
||||||
std::max(DL.getPrefTypeAlignment(Ty), StackGuardSlot->getAlignment());
|
|
||||||
SSL.addObject(StackGuardSlot, getStaticAllocaAllocationSize(StackGuardSlot),
|
SSL.addObject(StackGuardSlot, getStaticAllocaAllocationSize(StackGuardSlot),
|
||||||
Align, SSC.getFullLiveRange());
|
Align, SSC.getFullLiveRange());
|
||||||
}
|
}
|
||||||
@ -534,8 +533,9 @@ Value *SafeStack::moveStaticAllocasToUnsafeStack(
|
|||||||
Size = 1; // Don't create zero-sized stack objects.
|
Size = 1; // Don't create zero-sized stack objects.
|
||||||
|
|
||||||
// Ensure the object is properly aligned.
|
// Ensure the object is properly aligned.
|
||||||
uint64_t Align =
|
Align Align = DL.getPrefTypeAlign(Ty);
|
||||||
std::max(DL.getPrefTypeAlignment(Ty), Arg->getParamAlignment());
|
if (auto A = Arg->getParamAlign())
|
||||||
|
Align = std::max(Align, *A);
|
||||||
SSL.addObject(Arg, Size, Align, SSC.getFullLiveRange());
|
SSL.addObject(Arg, Size, Align, SSC.getFullLiveRange());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -546,24 +546,24 @@ Value *SafeStack::moveStaticAllocasToUnsafeStack(
|
|||||||
Size = 1; // Don't create zero-sized stack objects.
|
Size = 1; // Don't create zero-sized stack objects.
|
||||||
|
|
||||||
// Ensure the object is properly aligned.
|
// Ensure the object is properly aligned.
|
||||||
uint64_t Align = std::max(DL.getPrefTypeAlignment(Ty), AI->getAlignment());
|
Align Align = std::max(DL.getPrefTypeAlign(Ty), AI->getAlign());
|
||||||
|
|
||||||
SSL.addObject(AI, Size, Align,
|
SSL.addObject(AI, Size, Align,
|
||||||
ClColoring ? SSC.getLiveRange(AI) : NoColoringRange);
|
ClColoring ? SSC.getLiveRange(AI) : NoColoringRange);
|
||||||
}
|
}
|
||||||
|
|
||||||
SSL.computeLayout();
|
SSL.computeLayout();
|
||||||
uint64_t FrameAlignment = SSL.getFrameAlignment();
|
Align FrameAlignment = SSL.getFrameAlignment();
|
||||||
|
|
||||||
// FIXME: tell SSL that we start at a less-then-MaxAlignment aligned location
|
// FIXME: tell SSL that we start at a less-then-MaxAlignment aligned location
|
||||||
// (AlignmentSkew).
|
// (AlignmentSkew).
|
||||||
if (FrameAlignment > StackAlignment) {
|
if (FrameAlignment > StackAlignment) {
|
||||||
// Re-align the base pointer according to the max requested alignment.
|
// Re-align the base pointer according to the max requested alignment.
|
||||||
assert(isPowerOf2_64(FrameAlignment));
|
|
||||||
IRB.SetInsertPoint(BasePointer->getNextNode());
|
IRB.SetInsertPoint(BasePointer->getNextNode());
|
||||||
BasePointer = cast<Instruction>(IRB.CreateIntToPtr(
|
BasePointer = cast<Instruction>(IRB.CreateIntToPtr(
|
||||||
IRB.CreateAnd(IRB.CreatePtrToInt(BasePointer, IntPtrTy),
|
IRB.CreateAnd(
|
||||||
ConstantInt::get(IntPtrTy, ~uint64_t(FrameAlignment - 1))),
|
IRB.CreatePtrToInt(BasePointer, IntPtrTy),
|
||||||
|
ConstantInt::get(IntPtrTy, ~(FrameAlignment.value() - 1))),
|
||||||
StackPtrTy));
|
StackPtrTy));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ LLVM_DUMP_METHOD void StackLayout::print(raw_ostream &OS) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void StackLayout::addObject(const Value *V, unsigned Size, uint64_t Alignment,
|
void StackLayout::addObject(const Value *V, unsigned Size, Align Alignment,
|
||||||
const StackLifetime::LiveRange &Range) {
|
const StackLifetime::LiveRange &Range) {
|
||||||
StackObjects.push_back({V, Size, Alignment, Range});
|
StackObjects.push_back({V, Size, Alignment, Range});
|
||||||
ObjectAlignments[V] = Alignment;
|
ObjectAlignments[V] = Alignment;
|
||||||
@ -45,7 +45,7 @@ void StackLayout::addObject(const Value *V, unsigned Size, uint64_t Alignment,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static unsigned AdjustStackOffset(unsigned Offset, unsigned Size,
|
static unsigned AdjustStackOffset(unsigned Offset, unsigned Size,
|
||||||
uint64_t Alignment) {
|
Align Alignment) {
|
||||||
return alignTo(Offset + Size, Alignment) - Size;
|
return alignTo(Offset + Size, Alignment) - Size;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,7 +62,8 @@ void StackLayout::layoutObject(StackObject &Obj) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
LLVM_DEBUG(dbgs() << "Layout: size " << Obj.Size << ", align "
|
LLVM_DEBUG(dbgs() << "Layout: size " << Obj.Size << ", align "
|
||||||
<< Obj.Alignment << ", range " << Obj.Range << "\n");
|
<< Obj.Alignment.value() << ", range " << Obj.Range
|
||||||
|
<< "\n");
|
||||||
assert(Obj.Alignment <= MaxAlignment);
|
assert(Obj.Alignment <= MaxAlignment);
|
||||||
unsigned Start = AdjustStackOffset(0, Obj.Size, Obj.Alignment);
|
unsigned Start = AdjustStackOffset(0, Obj.Size, Obj.Alignment);
|
||||||
unsigned End = Start + Obj.Size;
|
unsigned End = Start + Obj.Size;
|
||||||
|
@ -22,7 +22,7 @@ namespace safestack {
|
|||||||
|
|
||||||
/// Compute the layout of an unsafe stack frame.
|
/// Compute the layout of an unsafe stack frame.
|
||||||
class StackLayout {
|
class StackLayout {
|
||||||
uint64_t MaxAlignment;
|
Align MaxAlignment;
|
||||||
|
|
||||||
struct StackRegion {
|
struct StackRegion {
|
||||||
unsigned Start;
|
unsigned Start;
|
||||||
@ -40,14 +40,14 @@ class StackLayout {
|
|||||||
struct StackObject {
|
struct StackObject {
|
||||||
const Value *Handle;
|
const Value *Handle;
|
||||||
unsigned Size;
|
unsigned Size;
|
||||||
uint64_t Alignment;
|
Align Alignment;
|
||||||
StackLifetime::LiveRange Range;
|
StackLifetime::LiveRange Range;
|
||||||
};
|
};
|
||||||
|
|
||||||
SmallVector<StackObject, 8> StackObjects;
|
SmallVector<StackObject, 8> StackObjects;
|
||||||
|
|
||||||
DenseMap<const Value *, unsigned> ObjectOffsets;
|
DenseMap<const Value *, unsigned> ObjectOffsets;
|
||||||
DenseMap<const Value *, uint64_t> ObjectAlignments;
|
DenseMap<const Value *, Align> ObjectAlignments;
|
||||||
|
|
||||||
void layoutObject(StackObject &Obj);
|
void layoutObject(StackObject &Obj);
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ public:
|
|||||||
|
|
||||||
/// Add an object to the stack frame. Value pointer is opaque and used as a
|
/// Add an object to the stack frame. Value pointer is opaque and used as a
|
||||||
/// handle to retrieve the object's offset in the frame later.
|
/// handle to retrieve the object's offset in the frame later.
|
||||||
void addObject(const Value *V, unsigned Size, uint64_t Alignment,
|
void addObject(const Value *V, unsigned Size, Align Alignment,
|
||||||
const StackLifetime::LiveRange &Range);
|
const StackLifetime::LiveRange &Range);
|
||||||
|
|
||||||
/// Run the layout computation for all previously added objects.
|
/// Run the layout computation for all previously added objects.
|
||||||
@ -66,13 +66,13 @@ public:
|
|||||||
unsigned getObjectOffset(const Value *V) { return ObjectOffsets[V]; }
|
unsigned getObjectOffset(const Value *V) { return ObjectOffsets[V]; }
|
||||||
|
|
||||||
/// Returns the alignment of the object
|
/// Returns the alignment of the object
|
||||||
uint64_t getObjectAlignment(const Value *V) { return ObjectAlignments[V]; }
|
Align getObjectAlignment(const Value *V) { return ObjectAlignments[V]; }
|
||||||
|
|
||||||
/// Returns the size of the entire frame.
|
/// Returns the size of the entire frame.
|
||||||
unsigned getFrameSize() { return Regions.empty() ? 0 : Regions.back().End; }
|
unsigned getFrameSize() { return Regions.empty() ? 0 : Regions.back().End; }
|
||||||
|
|
||||||
/// Returns the alignment of the frame.
|
/// Returns the alignment of the frame.
|
||||||
uint64_t getFrameAlignment() { return MaxAlignment; }
|
Align getFrameAlignment() { return MaxAlignment; }
|
||||||
|
|
||||||
void print(raw_ostream &OS);
|
void print(raw_ostream &OS);
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user