Skip to content

Add the inreg attribute to sreg when present. #76159

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

Merged
merged 1 commit into from
Sep 5, 2024
Merged
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
16 changes: 10 additions & 6 deletions lib/IRGen/GenCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,8 @@ static void addIndirectResultAttributes(IRGenModule &IGM,
llvm::AttributeList &attrs,
unsigned paramIndex, bool allowSRet,
llvm::Type *storageType,
const TypeInfo &typeInfo) {
const TypeInfo &typeInfo,
bool useInReg = false) {
llvm::AttrBuilder b(IGM.getLLVMContext());
b.addAttribute(llvm::Attribute::NoAlias);
// Bitwise takable value types are guaranteed not to capture
Expand All @@ -370,6 +371,8 @@ static void addIndirectResultAttributes(IRGenModule &IGM,
if (allowSRet) {
assert(storageType);
b.addStructRetAttr(storageType);
if (useInReg)
b.addAttribute(llvm::Attribute::InReg);
}
attrs = attrs.addParamAttributes(IGM.getLLVMContext(), paramIndex, b);
}
Expand Down Expand Up @@ -552,7 +555,7 @@ namespace {

private:
const TypeInfo &expand(SILParameterInfo param);
llvm::Type *addIndirectResult(SILType resultType);
llvm::Type *addIndirectResult(SILType resultType, bool useInReg = false);

SILFunctionConventions getSILFuncConventions() const {
return SILFunctionConventions(FnType, IGM.getSILModule());
Expand Down Expand Up @@ -611,11 +614,12 @@ namespace {
} // end namespace irgen
} // end namespace swift

llvm::Type *SignatureExpansion::addIndirectResult(SILType resultType) {
llvm::Type *SignatureExpansion::addIndirectResult(SILType resultType,
bool useInReg) {
const TypeInfo &resultTI = IGM.getTypeInfo(resultType);
auto storageTy = resultTI.getStorageType();
addIndirectResultAttributes(IGM, Attrs, ParamIRTypes.size(), claimSRet(),
storageTy, resultTI);
storageTy, resultTI, useInReg);
addPointerParameter(storageTy);
return IGM.VoidTy;
}
Expand Down Expand Up @@ -1707,9 +1711,9 @@ void SignatureExpansion::expandExternalSignatureTypes() {
// returned indirect values.
emitArg(0);
firstParamToLowerNormally = 1;
addIndirectResult(resultType);
addIndirectResult(resultType, returnInfo.getInReg());
} else
addIndirectResult(resultType);
addIndirectResult(resultType, returnInfo.getInReg());
}

// Use a special IR type for passing block pointers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public func use() -> CInt {

// CHECK: %[[instance:.*]] = alloca %TSo10HasMethodsV
// CHECK: %[[result:.*]] = alloca %TSo19NonTrivialInWrapperV
// CHECK: call void @"?nonConstPassThroughAsWrapper@HasMethods@@QEAA?AUNonTrivialInWrapper@@H@Z"(ptr %[[instance]], ptr noalias sret(%TSo19NonTrivialInWrapperV) %[[result]], i32 42)
// CHECK-x86_64: call void @"?nonConstPassThroughAsWrapper@HasMethods@@QEAA?AUNonTrivialInWrapper@@H@Z"(ptr %[[instance]], ptr noalias sret(%TSo19NonTrivialInWrapperV) %[[result]], i32 42)
// CHECK-aarch64: call void @"?nonConstPassThroughAsWrapper@HasMethods@@QEAA?AUNonTrivialInWrapper@@H@Z"(ptr %[[instance]], ptr inreg noalias sret(%TSo19NonTrivialInWrapperV) %[[result]], i32 42)

// CHECK-x86_64: define {{.*}} void @"?nonConstPassThroughAsWrapper@HasMethods@@QEAA?AUNonTrivialInWrapper@@H@Z"(ptr {{.*}} %{{.*}}, ptr noalias sret(%struct.NonTrivialInWrapper) {{.*}} %{{.*}}, i32 noundef %{{.*}})
// CHECK-aarch64: define {{.*}} void @"?nonConstPassThroughAsWrapper@HasMethods@@QEAA?AUNonTrivialInWrapper@@H@Z"(ptr {{.*}} %{{.*}}, ptr inreg noalias sret(%struct.NonTrivialInWrapper) {{.*}} %{{.*}}, i32 noundef %{{.*}})