Skip to content

16 bit pointer fixes #74693

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmake/modules/SwiftHandleGybSources.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ function(handle_gyb_sources dependency_out_var_name sources_var_name)
if (GYB_ARCH)
set_if_arch_bitness(ptr_size
ARCH "${GYB_ARCH}"
CASE_16_BIT "2"
CASE_32_BIT "4"
CASE_64_BIT "8")
set(extra_gyb_flags "-DCMAKE_SIZEOF_VOID_P=${ptr_size}")
Expand Down
2 changes: 1 addition & 1 deletion cmake/modules/SwiftSetIfArchBitness.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ function(set_if_arch_bitness var_name)
cmake_parse_arguments(
SIA # prefix
"" # options
"ARCH;CASE_32_BIT;CASE_64_BIT" # single-value args
"ARCH;CASE_16_BIT;CASE_32_BIT;CASE_64_BIT" # single-value args
"" # multi-value args
${ARGN})

Expand Down
9 changes: 8 additions & 1 deletion lib/Basic/LangOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ static const SupportedConditionalValue SupportedConditionalCompilationEndianness
};

static const SupportedConditionalValue SupportedConditionalCompilationPointerBitWidths[] = {
"_16",
"_32",
"_64"
};
Expand Down Expand Up @@ -396,6 +397,10 @@ void LangOptions::setHasAtomicBitWidth(llvm::Triple triple) {
// case please update the switch with your flavor of arch. Otherwise assume
// every arch supports at least word atomics.

if (triple.isArch16Bit()) {
setMaxAtomicBitWidth(16);
}

if (triple.isArch32Bit()) {
setMaxAtomicBitWidth(32);
}
Expand Down Expand Up @@ -564,7 +569,9 @@ std::pair<bool, bool> LangOptions::setTarget(llvm::Triple triple) {
}

// Set the "_pointerBitWidth" platform condition.
if (Target.isArch32Bit()) {
if (Target.isArch16Bit()) {
addPlatformConditionValue(PlatformConditionKind::PointerBitWidth, "_16");
} else if (Target.isArch32Bit()) {
addPlatformConditionValue(PlatformConditionKind::PointerBitWidth, "_32");
} else if (Target.isArch64Bit()) {
addPlatformConditionValue(PlatformConditionKind::PointerBitWidth, "_64");
Expand Down
4 changes: 2 additions & 2 deletions lib/IRGen/ExtraInhabitants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ llvm::Value *PointerInfo::getExtraInhabitantIndex(IRGenFunction &IGF,

// Truncate down to i32 if necessary.
if (index->getType() != IGF.IGM.Int32Ty) {
index = IGF.Builder.CreateTrunc(index, IGF.IGM.Int32Ty);
index = IGF.Builder.CreateZExtOrTrunc(index, IGF.IGM.Int32Ty);
}

phiValues.push_back({IGF.Builder.GetInsertBlock(), index});
Expand Down Expand Up @@ -195,7 +195,7 @@ void PointerInfo::storeExtraInhabitant(IRGenFunction &IGF,
llvm::Value *index,
Address dest) const {
if (index->getType() != IGF.IGM.SizeTy) {
index = IGF.Builder.CreateZExt(index, IGF.IGM.SizeTy);
index = IGF.Builder.CreateZExtOrTrunc(index, IGF.IGM.SizeTy);
}

if (Nullable) {
Expand Down
4 changes: 2 additions & 2 deletions lib/IRGen/GenClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3028,14 +3028,14 @@ irgen::emitClassResilientInstanceSizeAndAlignMask(IRGenFunction &IGF,
slot = IGF.Builder.CreateElementBitCast(slot, IGF.IGM.Int32Ty);
llvm::Value *size = IGF.Builder.CreateLoad(slot);
if (IGF.IGM.SizeTy != IGF.IGM.Int32Ty)
size = IGF.Builder.CreateZExt(size, IGF.IGM.SizeTy);
size = IGF.Builder.CreateZExtOrTrunc(size, IGF.IGM.SizeTy);

slot = IGF.Builder.CreateConstByteArrayGEP(
metadataAsBytes,
layout.getInstanceAlignMaskOffset());
slot = IGF.Builder.CreateElementBitCast(slot, IGF.IGM.Int16Ty);
llvm::Value *alignMask = IGF.Builder.CreateLoad(slot);
alignMask = IGF.Builder.CreateZExt(alignMask, IGF.IGM.SizeTy);
alignMask = IGF.Builder.CreateZExtOrTrunc(alignMask, IGF.IGM.SizeTy);

return {size, alignMask};
}
Expand Down
6 changes: 5 additions & 1 deletion lib/IRGen/Linking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,11 @@ llvm::Type *LinkEntity::getDefaultDeclarationType(IRGenModule &IGM) const {
case Kind::NoncanonicalSpecializedGenericTypeMetadataCacheVariable:
return IGM.TypeMetadataPtrTy;
case Kind::TypeMetadataDemanglingCacheVariable:
return llvm::StructType::get(IGM.Int32Ty, IGM.Int32Ty);
if (IGM.getModule()->getDataLayout().isBigEndian()) {
return llvm::StructType::get(IGM.Int32Ty, IGM.RelativeAddressTy);
} else {
return llvm::StructType::get(IGM.RelativeAddressTy, IGM.Int32Ty);
}
case Kind::TypeMetadataSingletonInitializationCache:
// TODO: put a cache variable on IGM
return llvm::StructType::get(IGM.getLLVMContext(),
Expand Down
4 changes: 2 additions & 2 deletions lib/IRGen/MetadataRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3228,8 +3228,8 @@ emitMetadataAccessByMangledName(IRGenFunction &IGF, CanType type,

auto stringAddrOffset = subIGF.Builder.CreateTrunc(load,
IGM.Int32Ty);
stringAddrOffset = subIGF.Builder.CreateSExtOrBitCast(stringAddrOffset,
IGM.SizeTy);
stringAddrOffset = subIGF.Builder.CreateSExtOrTrunc(stringAddrOffset,
IGM.SizeTy);
auto stringAddrBase = subIGF.Builder.CreatePtrToInt(cache, IGM.SizeTy);
if (IGM.getModule()->getDataLayout().isBigEndian()) {
stringAddrBase = subIGF.Builder.CreateAdd(stringAddrBase,
Expand Down