[llvm] eba7b26 - [SafeStack] Use Align instead of uint64_t
Arthur Eubanks via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 15 14:41:09 PST 2021
Author: Arthur Eubanks
Date: 2021-12-15T14:40:56-08:00
New Revision: eba7b26815d84cc964f631971a64bf0da805958e
URL: https://github.com/llvm/llvm-project/commit/eba7b26815d84cc964f631971a64bf0da805958e
DIFF: https://github.com/llvm/llvm-project/commit/eba7b26815d84cc964f631971a64bf0da805958e.diff
LOG: [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
Added:
Modified:
llvm/lib/CodeGen/SafeStack.cpp
llvm/lib/CodeGen/SafeStackLayout.cpp
llvm/lib/CodeGen/SafeStackLayout.h
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/SafeStack.cpp b/llvm/lib/CodeGen/SafeStack.cpp
index 50d9d64bfcfda..3d8a7eecce188 100644
--- a/llvm/lib/CodeGen/SafeStack.cpp
+++ b/llvm/lib/CodeGen/SafeStack.cpp
@@ -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));
}
diff --git a/llvm/lib/CodeGen/SafeStackLayout.cpp b/llvm/lib/CodeGen/SafeStackLayout.cpp
index 7cdda7743c162..602afcfa9001b 100644
--- a/llvm/lib/CodeGen/SafeStackLayout.cpp
+++ b/llvm/lib/CodeGen/SafeStackLayout.cpp
@@ -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;
diff --git a/llvm/lib/CodeGen/SafeStackLayout.h b/llvm/lib/CodeGen/SafeStackLayout.h
index b72450e570808..4ac7af2059f5f 100644
--- a/llvm/lib/CodeGen/SafeStackLayout.h
+++ b/llvm/lib/CodeGen/SafeStackLayout.h
@@ -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 @@ class StackLayout {
/// 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 @@ class StackLayout {
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);
};
More information about the llvm-commits
mailing list