mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-01-25 18:55:48 +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);
|
||||
if (StackGuardSlot) {
|
||||
Type *Ty = StackGuardSlot->getAllocatedType();
|
||||
uint64_t Align =
|
||||
std::max(DL.getPrefTypeAlignment(Ty), StackGuardSlot->getAlignment());
|
||||
Align Align = std::max(DL.getPrefTypeAlign(Ty), StackGuardSlot->getAlign());
|
||||
SSL.addObject(StackGuardSlot, getStaticAllocaAllocationSize(StackGuardSlot),
|
||||
Align, SSC.getFullLiveRange());
|
||||
}
|
||||
@ -534,8 +533,9 @@ Value *SafeStack::moveStaticAllocasToUnsafeStack(
|
||||
Size = 1; // Don't create zero-sized stack objects.
|
||||
|
||||
// Ensure the object is properly aligned.
|
||||
uint64_t Align =
|
||||
std::max(DL.getPrefTypeAlignment(Ty), Arg->getParamAlignment());
|
||||
Align Align = DL.getPrefTypeAlign(Ty);
|
||||
if (auto A = Arg->getParamAlign())
|
||||
Align = std::max(Align, *A);
|
||||
SSL.addObject(Arg, Size, Align, SSC.getFullLiveRange());
|
||||
}
|
||||
|
||||
@ -546,24 +546,24 @@ Value *SafeStack::moveStaticAllocasToUnsafeStack(
|
||||
Size = 1; // Don't create zero-sized stack objects.
|
||||
|
||||
// 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,
|
||||
ClColoring ? SSC.getLiveRange(AI) : NoColoringRange);
|
||||
}
|
||||
|
||||
SSL.computeLayout();
|
||||
uint64_t FrameAlignment = SSL.getFrameAlignment();
|
||||
Align FrameAlignment = SSL.getFrameAlignment();
|
||||
|
||||
// FIXME: tell SSL that we start at a less-then-MaxAlignment aligned location
|
||||
// (AlignmentSkew).
|
||||
if (FrameAlignment > StackAlignment) {
|
||||
// Re-align the base pointer according to the max requested alignment.
|
||||
assert(isPowerOf2_64(FrameAlignment));
|
||||
IRB.SetInsertPoint(BasePointer->getNextNode());
|
||||
BasePointer = cast<Instruction>(IRB.CreateIntToPtr(
|
||||
IRB.CreateAnd(IRB.CreatePtrToInt(BasePointer, IntPtrTy),
|
||||
ConstantInt::get(IntPtrTy, ~uint64_t(FrameAlignment - 1))),
|
||||
IRB.CreateAnd(
|
||||
IRB.CreatePtrToInt(BasePointer, IntPtrTy),
|
||||
ConstantInt::get(IntPtrTy, ~(FrameAlignment.value() - 1))),
|
||||
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) {
|
||||
StackObjects.push_back({V, Size, Alignment, Range});
|
||||
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,
|
||||
uint64_t Alignment) {
|
||||
Align Alignment) {
|
||||
return alignTo(Offset + Size, Alignment) - Size;
|
||||
}
|
||||
|
||||
@ -62,7 +62,8 @@ void StackLayout::layoutObject(StackObject &Obj) {
|
||||
}
|
||||
|
||||
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);
|
||||
unsigned Start = AdjustStackOffset(0, Obj.Size, Obj.Alignment);
|
||||
unsigned End = Start + Obj.Size;
|
||||
|
@ -22,7 +22,7 @@ namespace safestack {
|
||||
|
||||
/// Compute the layout of an unsafe stack frame.
|
||||
class StackLayout {
|
||||
uint64_t MaxAlignment;
|
||||
Align MaxAlignment;
|
||||
|
||||
struct StackRegion {
|
||||
unsigned Start;
|
||||
@ -40,14 +40,14 @@ class StackLayout {
|
||||
struct StackObject {
|
||||
const Value *Handle;
|
||||
unsigned Size;
|
||||
uint64_t Alignment;
|
||||
Align Alignment;
|
||||
StackLifetime::LiveRange Range;
|
||||
};
|
||||
|
||||
SmallVector<StackObject, 8> StackObjects;
|
||||
|
||||
DenseMap<const Value *, unsigned> ObjectOffsets;
|
||||
DenseMap<const Value *, uint64_t> ObjectAlignments;
|
||||
DenseMap<const Value *, Align> ObjectAlignments;
|
||||
|
||||
void layoutObject(StackObject &Obj);
|
||||
|
||||
@ -56,7 +56,7 @@ public:
|
||||
|
||||
/// 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.
|
||||
void addObject(const Value *V, unsigned Size, uint64_t Alignment,
|
||||
void addObject(const Value *V, unsigned Size, Align Alignment,
|
||||
const StackLifetime::LiveRange &Range);
|
||||
|
||||
/// Run the layout computation for all previously added objects.
|
||||
@ -66,13 +66,13 @@ public:
|
||||
unsigned getObjectOffset(const Value *V) { return ObjectOffsets[V]; }
|
||||
|
||||
/// 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.
|
||||
unsigned getFrameSize() { return Regions.empty() ? 0 : Regions.back().End; }
|
||||
|
||||
/// Returns the alignment of the frame.
|
||||
uint64_t getFrameAlignment() { return MaxAlignment; }
|
||||
Align getFrameAlignment() { return MaxAlignment; }
|
||||
|
||||
void print(raw_ostream &OS);
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user