Skip to content

Commit e05d4e9

Browse files
authored
Merge pull request #32018 from davezarzycki/pr32018
[IRGen] NFC: Clean up Alignment type
2 parents a676a37 + eab7cb7 commit e05d4e9

File tree

6 files changed

+37
-37
lines changed

6 files changed

+37
-37
lines changed

lib/IRGen/DebugTypeInfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class DebugTypeInfo {
4343
/// the storage type for undefined variables.
4444
llvm::Type *StorageType = nullptr;
4545
Size size = Size(0);
46-
Alignment align = Alignment(0);
46+
Alignment align = Alignment();
4747
bool DefaultAlignment = true;
4848
bool IsMetadataType = false;
4949

@@ -123,7 +123,7 @@ template <> struct DenseMapInfo<swift::irgen::DebugTypeInfo> {
123123
static swift::irgen::DebugTypeInfo getTombstoneKey() {
124124
return swift::irgen::DebugTypeInfo(
125125
llvm::DenseMapInfo<swift::TypeBase *>::getTombstoneKey(), nullptr,
126-
swift::irgen::Size(0), swift::irgen::Alignment(0), false, false);
126+
swift::irgen::Size(0), swift::irgen::Alignment(), false, false);
127127
}
128128
static unsigned getHashValue(swift::irgen::DebugTypeInfo Val) {
129129
return DenseMapInfo<swift::CanType>::getHashValue(Val.getType());

lib/IRGen/GenCall.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1851,7 +1851,7 @@ void CallEmission::emitToExplosion(Explosion &out, bool isOutlined) {
18511851
auto fnType = getCallee().getFunctionPointer().getFunctionType();
18521852
assert(fnType->getNumParams() > 0);
18531853
auto resultTy = fnType->getParamType(0)->getPointerElementType();
1854-
auto temp = IGF.createAlloca(resultTy, Alignment(0), "indirect.result");
1854+
auto temp = IGF.createAlloca(resultTy, Alignment(), "indirect.result");
18551855
emitToMemory(temp, substResultTI, isOutlined);
18561856
return;
18571857
}

lib/IRGen/GenValueWitness.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,28 +1056,28 @@ getAddrOfKnownValueWitnessTable(IRGenModule &IGM, CanType type,
10561056
// Reuse one of the integer witnesses if applicable.
10571057
switch (sizeAndAlignment(fixedTI->getFixedSize(),
10581058
fixedTI->getFixedAlignment())) {
1059-
case sizeAndAlignment(Size(0), Alignment(1)):
1059+
case sizeAndAlignment(Size(0), Alignment::create<1>()):
10601060
witnessSurrogate = TupleType::getEmpty(C);
10611061
break;
1062-
case sizeAndAlignment(Size(1), Alignment(1)):
1062+
case sizeAndAlignment(Size(1), Alignment::create<1>()):
10631063
witnessSurrogate = BuiltinIntegerType::get(8, C)->getCanonicalType();
10641064
break;
1065-
case sizeAndAlignment(Size(2), Alignment(2)):
1065+
case sizeAndAlignment(Size(2), Alignment::create<2>()):
10661066
witnessSurrogate = BuiltinIntegerType::get(16, C)->getCanonicalType();
10671067
break;
1068-
case sizeAndAlignment(Size(4), Alignment(4)):
1068+
case sizeAndAlignment(Size(4), Alignment::create<4>()):
10691069
witnessSurrogate = BuiltinIntegerType::get(32, C)->getCanonicalType();
10701070
break;
1071-
case sizeAndAlignment(Size(8), Alignment(8)):
1071+
case sizeAndAlignment(Size(8), Alignment::create<8>()):
10721072
witnessSurrogate = BuiltinIntegerType::get(64, C)->getCanonicalType();
10731073
break;
1074-
case sizeAndAlignment(Size(16), Alignment(16)):
1074+
case sizeAndAlignment(Size(16), Alignment::create<16>()):
10751075
witnessSurrogate = BuiltinIntegerType::get(128, C)->getCanonicalType();
10761076
break;
1077-
case sizeAndAlignment(Size(32), Alignment(32)):
1077+
case sizeAndAlignment(Size(32), Alignment::create<32>()):
10781078
witnessSurrogate = BuiltinIntegerType::get(256, C)->getCanonicalType();
10791079
break;
1080-
case sizeAndAlignment(Size(64), Alignment(64)):
1080+
case sizeAndAlignment(Size(64), Alignment::create<64>()):
10811081
witnessSurrogate = BuiltinIntegerType::get(512, C)->getCanonicalType();
10821082
break;
10831083
}

lib/IRGen/IRGen.h

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -235,24 +235,21 @@ inline bool operator<=(OperationCost l, OperationCost r) {
235235
/// An alignment value, in eight-bit units.
236236
class Alignment {
237237
public:
238-
using int_type = uint32_t;
239-
240-
constexpr Alignment() : Value(0) {}
241-
constexpr explicit Alignment(int_type Value) : Value(Value) {}
242-
explicit Alignment(clang::CharUnits value) : Value(value.getQuantity()) {}
238+
using int_type = uint64_t;
243239

244-
constexpr int_type getValue() const { return Value; }
245-
constexpr int_type getMaskValue() const { return Value - 1; }
240+
constexpr Alignment() : Shift(0) {}
241+
explicit Alignment(int_type Value) : Shift(llvm::Log2_64(Value)) {
242+
assert(llvm::isPowerOf2_64(Value));
243+
}
244+
explicit Alignment(clang::CharUnits value) : Alignment(value.getQuantity()) {}
246245

247-
bool isOne() const { return Value == 1; }
248-
bool isZero() const { return Value == 0; }
246+
constexpr int_type getValue() const { return int_type(1) << Shift; }
247+
constexpr int_type getMaskValue() const { return getValue() - 1; }
249248

250249
Alignment alignmentAtOffset(Size S) const;
251250
Size asSize() const;
252251

253-
unsigned log2() const {
254-
return llvm::Log2_64(Value);
255-
}
252+
unsigned log2() const { return Shift; }
256253

257254
operator clang::CharUnits() const {
258255
return asCharUnits();
@@ -261,19 +258,24 @@ class Alignment {
261258
return clang::CharUnits::fromQuantity(getValue());
262259
}
263260

264-
explicit operator bool() const { return Value != 0; }
261+
explicit operator llvm::MaybeAlign() const { return llvm::MaybeAlign(getValue()); }
265262

266-
explicit operator llvm::MaybeAlign() const { return llvm::MaybeAlign(Value); }
263+
friend bool operator< (Alignment L, Alignment R){ return L.Shift < R.Shift; }
264+
friend bool operator<=(Alignment L, Alignment R){ return L.Shift <= R.Shift; }
265+
friend bool operator> (Alignment L, Alignment R){ return L.Shift > R.Shift; }
266+
friend bool operator>=(Alignment L, Alignment R){ return L.Shift >= R.Shift; }
267+
friend bool operator==(Alignment L, Alignment R){ return L.Shift == R.Shift; }
268+
friend bool operator!=(Alignment L, Alignment R){ return L.Shift != R.Shift; }
267269

268-
friend bool operator< (Alignment L, Alignment R){ return L.Value < R.Value; }
269-
friend bool operator<=(Alignment L, Alignment R){ return L.Value <= R.Value; }
270-
friend bool operator> (Alignment L, Alignment R){ return L.Value > R.Value; }
271-
friend bool operator>=(Alignment L, Alignment R){ return L.Value >= R.Value; }
272-
friend bool operator==(Alignment L, Alignment R){ return L.Value == R.Value; }
273-
friend bool operator!=(Alignment L, Alignment R){ return L.Value != R.Value; }
270+
template<unsigned Value>
271+
static constexpr Alignment create() {
272+
Alignment result;
273+
result.Shift = llvm::CTLog2<Value>();
274+
return result;
275+
}
274276

275277
private:
276-
int_type Value;
278+
unsigned char Shift;
277279
};
278280

279281
/// A size value, in eight-bit units.

lib/IRGen/IRGenSIL.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -698,9 +698,8 @@ class IRGenSILFunction :
698698

699699
/// Unconditionally emit a stack shadow copy of an \c llvm::Value.
700700
llvm::Value *emitShadowCopy(llvm::Value *Storage, const SILDebugScope *Scope,
701-
SILDebugVariable VarInfo, Alignment Align) {
702-
if (Align.isZero())
703-
Align = IGM.getPointerAlignment();
701+
SILDebugVariable VarInfo, llvm::Optional<Alignment> _Align) {
702+
auto Align = _Align.getValueOr(IGM.getPointerAlignment());
704703

705704
unsigned ArgNo = VarInfo.ArgNo;
706705
auto &Alloca = ShadowStackSlots[{ArgNo, {Scope, VarInfo.Name}}];
@@ -721,7 +720,7 @@ class IRGenSILFunction :
721720
const SILDebugScope *Scope,
722721
SILDebugVariable VarInfo,
723722
bool IsAnonymous,
724-
Alignment Align = Alignment(0)) {
723+
llvm::Optional<Alignment> Align = None) {
725724
// Never emit shadow copies when optimizing, or if already on the stack.
726725
// No debug info is emitted for refcounts either.
727726
if (IGM.IRGen.Opts.DisableDebuggerShadowCopies ||

lib/IRGen/TypeInfo.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ class TypeInfo {
148148
IsABIAccessible_t abiAccessible,
149149
SpecialTypeInfoKind stik) : StorageType(Type) {
150150
assert(stik >= SpecialTypeInfoKind::Fixed || !alwaysFixedSize);
151-
assert(!A.isZero() && "Invalid alignment");
152151
Bits.OpaqueBits = 0;
153152
Bits.TypeInfo.Kind = unsigned(stik);
154153
Bits.TypeInfo.AlignmentShift = llvm::Log2_32(A.getValue());

0 commit comments

Comments
 (0)