Skip to content

Commit e7e0a87

Browse files
committed
Merge pull request #1254 from jrose-apple/Fixnum
Replace uses of llvm::Fixnum with llvm::PointerEmbeddedInt.
2 parents 9aa3d01 + 36a44cf commit e7e0a87

File tree

13 files changed

+79
-60
lines changed

13 files changed

+79
-60
lines changed

include/swift/AST/LazyResolver.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#define SWIFT_AST_LAZYRESOLVER_H
1919

2020
#include "swift/AST/TypeLoc.h"
21-
#include "llvm/ADT/Fixnum.h"
21+
#include "llvm/ADT/PointerEmbeddedInt.h"
2222

2323
namespace swift {
2424

@@ -160,7 +160,7 @@ class alignas(void*) LazyMemberLoader {
160160
/// A placeholder for either an array or a member loader.
161161
template <typename T>
162162
class LazyLoaderArray {
163-
using LengthTy = llvm::Fixnum<31>;
163+
using LengthTy = llvm::PointerEmbeddedInt<size_t, 31>;
164164
PointerUnion<LengthTy, LazyMemberLoader *> lengthOrLoader;
165165
uint64_t data = 0;
166166
public:

include/swift/AST/Types.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
#include "swift/Basic/UUID.h"
2929
#include "llvm/ADT/ArrayRef.h"
3030
#include "llvm/ADT/DenseMapInfo.h"
31-
#include "llvm/ADT/Fixnum.h"
3231
#include "llvm/ADT/FoldingSet.h"
32+
#include "llvm/ADT/PointerEmbeddedInt.h"
3333
#include "llvm/ADT/PointerUnion.h"
3434
#include "llvm/Support/ErrorHandling.h"
3535
#include "llvm/Support/TrailingObjects.h"
@@ -3758,9 +3758,10 @@ DEFINE_EMPTY_CAN_TYPE_WRAPPER(AbstractTypeParamType, SubstitutableType)
37583758
///
37593759
/// \sa GenericTypeParamDecl
37603760
class GenericTypeParamType : public AbstractTypeParamType {
3761+
using DepthIndexTy = llvm::PointerEmbeddedInt<unsigned, 31>;
3762+
37613763
/// The generic type parameter or depth/index.
3762-
llvm::PointerUnion<GenericTypeParamDecl *, llvm::Fixnum<31>>
3763-
ParamOrDepthIndex;
3764+
llvm::PointerUnion<GenericTypeParamDecl *, DepthIndexTy> ParamOrDepthIndex;
37643765

37653766
public:
37663767
/// Retrieve a generic type parameter at the given depth and index.

include/swift/Serialization/ModuleFile.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include "swift/Basic/LLVM.h"
2626
#include "llvm/ADT/ArrayRef.h"
2727
#include "llvm/ADT/DenseMap.h"
28-
#include "llvm/ADT/Fixnum.h"
2928
#include "llvm/ADT/TinyPtrVector.h"
3029
#include "llvm/Bitcode/BitstreamReader.h"
3130
#include "llvm/Support/MemoryBuffer.h"
@@ -199,7 +198,9 @@ class ModuleFile : public LazyMemberLoader {
199198
: Value(), Offset(offset), IsFullyDeserialized(0) {}
200199

201200
/*implicit*/ PartiallySerialized(RawBitOffset offset)
202-
: Value(), Offset(offset), IsFullyDeserialized(0) {}
201+
: Value(), Offset(static_cast<unsigned>(offset)), IsFullyDeserialized(0) {
202+
assert(Offset == offset && "offset is too large");
203+
}
203204

204205
bool isDeserialized() const {
205206
return Value != T();
@@ -257,7 +258,9 @@ class ModuleFile : public LazyMemberLoader {
257258

258259
template <typename IntTy>
259260
/*implicit*/ SerializedIdentifier(IntTy rawOffset)
260-
: Offset(rawOffset) {}
261+
: Offset(static_cast<unsigned>(rawOffset)) {
262+
assert(Offset == rawOffset && "not enough bits");
263+
}
261264
};
262265

263266
/// Identifiers referenced by this module.

include/swift/Serialization/ModuleFormat.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@
2222
#include "swift/AST/Decl.h"
2323
#include "llvm/Bitcode/RecordLayout.h"
2424
#include "llvm/Bitcode/BitCodes.h"
25+
#include "llvm/ADT/PointerEmbeddedInt.h"
2526

2627
namespace swift {
2728
namespace serialization {
2829

29-
using llvm::Fixnum;
30+
using llvm::PointerEmbeddedInt;
3031
using llvm::BCArray;
3132
using llvm::BCBlob;
3233
using llvm::BCFixed;
@@ -54,7 +55,7 @@ const uint16_t VERSION_MAJOR = 0;
5455
/// it just ensures a conflict if two people change the module format.
5556
const uint16_t VERSION_MINOR = 238; // SILValue changes
5657

57-
using DeclID = Fixnum<31>;
58+
using DeclID = PointerEmbeddedInt<unsigned, 31>;
5859
using DeclIDField = BCFixed<31>;
5960

6061
// TypeID must be the same as DeclID because it is stored in the same way.
@@ -78,7 +79,7 @@ using NormalConformanceIDField = DeclIDField;
7879
using ModuleID = IdentifierID;
7980
using ModuleIDField = IdentifierIDField;
8081

81-
using BitOffset = Fixnum<31>;
82+
using BitOffset = PointerEmbeddedInt<unsigned, 31>;
8283
using BitOffsetField = BCFixed<31>;
8384

8485
// CharOffset must be the same as BitOffset because it is stored in the

lib/AST/Type.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#include <functional>
3333
#include <iterator>
3434
using namespace swift;
35-
using llvm::Fixnum;
3635

3736
bool TypeLoc::isError() const {
3837
assert(wasValidated() && "Type not yet validated");
@@ -1350,7 +1349,7 @@ unsigned GenericTypeParamType::getDepth() const {
13501349
return param->getDepth();
13511350
}
13521351

1353-
auto fixedNum = ParamOrDepthIndex.get<Fixnum<31>>();
1352+
auto fixedNum = ParamOrDepthIndex.get<DepthIndexTy>();
13541353
return fixedNum >> 16;
13551354
}
13561355

@@ -1359,7 +1358,7 @@ unsigned GenericTypeParamType::getIndex() const {
13591358
return param->getIndex();
13601359
}
13611360

1362-
auto fixedNum = ParamOrDepthIndex.get<Fixnum<31>>();
1361+
auto fixedNum = ParamOrDepthIndex.get<DepthIndexTy>();
13631362
return fixedNum & 0xFFFF;
13641363
}
13651364

@@ -1373,7 +1372,7 @@ Identifier GenericTypeParamType::getName() const {
13731372
// getASTContext() doesn't actually mutate an already-canonical type.
13741373
auto &C = const_cast<GenericTypeParamType*>(this)->getASTContext();
13751374
auto &names = C.CanonicalGenericTypeParamTypeNames;
1376-
unsigned depthIndex = ParamOrDepthIndex.get<Fixnum<31>>();
1375+
unsigned depthIndex = ParamOrDepthIndex.get<DepthIndexTy>();
13771376
auto cached = names.find(depthIndex);
13781377
if (cached != names.end())
13791378
return cached->second;

lib/ClangImporter/SwiftLookupTable.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,6 @@ void SwiftLookupTable::dump() const {
386386
// ---------------------------------------------------------------------------
387387
// Serialization
388388
// ---------------------------------------------------------------------------
389-
using llvm::Fixnum;
390389
using llvm::BCArray;
391390
using llvm::BCBlob;
392391
using llvm::BCFixed;

lib/IRGen/EnumPayload.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "TypeInfo.h"
1919
#include "llvm/IR/BasicBlock.h"
2020
#include "llvm/IR/DerivedTypes.h"
21-
#include "llvm/ADT/Fixnum.h"
21+
#include "llvm/ADT/PointerEmbeddedInt.h"
2222
#include "llvm/ADT/PointerUnion.h"
2323
#include <utility>
2424

@@ -29,7 +29,9 @@ namespace irgen {
2929
/// A payload can either use a generic word-chunked representation, or attempt
3030
/// to follow the explosion schema of one of its payload types.
3131
class EnumPayloadSchema {
32-
const llvm::PointerUnion<ExplosionSchema *, llvm::Fixnum<31>> Value;
32+
using BitSizeTy = llvm::PointerEmbeddedInt<unsigned, 31>;
33+
34+
const llvm::PointerUnion<ExplosionSchema *, BitSizeTy> Value;
3335

3436
public:
3537
EnumPayloadSchema() : Value((ExplosionSchema *)nullptr) {}
@@ -39,7 +41,7 @@ class EnumPayloadSchema {
3941
}
4042

4143
explicit EnumPayloadSchema(unsigned bits)
42-
: Value(llvm::Fixnum<31>(bits)) {}
44+
: Value(BitSizeTy(bits)) {}
4345

4446
EnumPayloadSchema(ExplosionSchema &s)
4547
: Value(&s) {}
@@ -69,7 +71,7 @@ class EnumPayloadSchema {
6971
}
7072

7173
// Otherwise, chunk into pointer-sized integer values by default.
72-
unsigned bitSize = Value.get<llvm::Fixnum<31>>();
74+
unsigned bitSize = Value.get<BitSizeTy>();
7375
unsigned pointerSize = IGM.getPointerSize().getValueInBits();
7476

7577
while (bitSize >= pointerSize) {

lib/Sema/ConstraintLocator.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "swift/AST/Type.h"
2323
#include "swift/AST/Types.h"
2424
#include "llvm/ADT/ArrayRef.h"
25-
#include "llvm/ADT/Fixnum.h"
2625
#include "llvm/ADT/FoldingSet.h"
2726
#include "llvm/ADT/PointerIntPair.h"
2827
#include "llvm/ADT/PointerUnion.h"
@@ -231,9 +230,6 @@ class ConstraintLocator : public llvm::FoldingSetNode {
231230
StoredKindAndValue
232231
};
233232

234-
/// \brief The type of storage used for a kind and numeric value.
235-
typedef llvm::Fixnum<62> KindAndValueStorage;
236-
237233
/// \brief The actual storage for the path element, which involves both a
238234
/// kind and (potentially) a value.
239235
///
@@ -251,15 +247,13 @@ class ConstraintLocator : public llvm::FoldingSetNode {
251247
uint64_t storedKind : 2;
252248

253249
/// \brief Encode a path element kind and a value into the storage format.
254-
static KindAndValueStorage encodeStorage(PathElementKind kind,
255-
unsigned value) {
256-
unsigned result = (value << 8) | (unsigned)kind;
257-
return result;
250+
static uint64_t encodeStorage(PathElementKind kind, unsigned value) {
251+
return ((uint64_t)value << 8) | kind;
258252
}
259253

260254
/// \brief Decode a storage value into path element kind and value.
261255
static std::pair<PathElementKind, unsigned>
262-
decodeStorage(KindAndValueStorage storage) {
256+
decodeStorage(uint64_t storage) {
263257
return { (PathElementKind)((unsigned)storage & 0xFF), storage >> 8 };
264258
}
265259

lib/Sema/ConstraintSystem.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include "swift/AST/NameLookup.h"
3131
#include "swift/AST/Types.h"
3232
#include "swift/AST/TypeCheckerDebugConsumer.h"
33-
#include "llvm/ADT/Fixnum.h"
3433
#include "llvm/ADT/ilist.h"
3534
#include "llvm/ADT/PointerUnion.h"
3635
#include "llvm/ADT/SmallPtrSet.h"

lib/Serialization/DeserializeSIL.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,8 @@ SILBasicBlock *SILDeserializer::readSILBasicBlock(SILFunction *Fn,
574574
auto Arg = new (SILMod) SILArgument(CurrentBB,
575575
getSILType(ArgTy,
576576
(SILValueCategory)Args[I+1]));
577-
setLocalValue(Arg, ++LastValueID);
577+
LastValueID = LastValueID + 1;
578+
setLocalValue(Arg, LastValueID);
578579
}
579580
return CurrentBB;
580581
}
@@ -1728,8 +1729,10 @@ bool SILDeserializer::readSILInstruction(SILFunction *Fn, SILBasicBlock *BB,
17281729
break;
17291730
}
17301731
}
1731-
if (ResultVal->hasValue())
1732-
setLocalValue(ResultVal, ++LastValueID);
1732+
if (ResultVal->hasValue()) {
1733+
LastValueID = LastValueID + 1;
1734+
setLocalValue(ResultVal, LastValueID);
1735+
}
17331736

17341737
return false;
17351738
}

lib/Serialization/ModuleFile.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ class ModuleFile::LocalDeclTableInfo {
355355

356356
static std::pair<unsigned, unsigned> ReadKeyDataLength(const uint8_t *&data) {
357357
unsigned keyLength = endian::readNext<uint16_t, little, unaligned>(data);
358-
return { keyLength, sizeof(DeclID) + sizeof(unsigned) };
358+
return { keyLength, sizeof(uint32_t) + sizeof(unsigned) };
359359
}
360360

361361
static internal_key_type ReadKey(const uint8_t *data, unsigned length) {
@@ -364,7 +364,7 @@ class ModuleFile::LocalDeclTableInfo {
364364

365365
static data_type ReadData(internal_key_type key, const uint8_t *data,
366366
unsigned length) {
367-
auto declID = endian::readNext<DeclID, little, unaligned>(data);
367+
auto declID = endian::readNext<uint32_t, little, unaligned>(data);
368368
auto discriminator = endian::readNext<unsigned, little, unaligned>(data);
369369
return { declID, discriminator };
370370
}
@@ -432,7 +432,7 @@ class ModuleFile::ObjCMethodTableInfo {
432432
bool isInstanceMethod = *data++ != 0;
433433
DeclID methodID = endian::readNext<uint32_t, little, unaligned>(data);
434434
result.push_back(std::make_tuple(typeID, isInstanceMethod, methodID));
435-
length -= sizeof(TypeID) + 1 + sizeof(DeclID);
435+
length -= sizeof(uint32_t) + 1 + sizeof(uint32_t);
436436
}
437437

438438
return result;

0 commit comments

Comments
 (0)