Skip to content

[CodeGen] Add typed error logic to SwiftAggLowering #8939

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
Jul 1, 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
2 changes: 2 additions & 0 deletions clang/include/clang/CodeGen/SwiftCallingConv.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ class SwiftAggLowering {
/// passed indirectly as an argument
bool shouldPassIndirectly(bool asReturnValue) const;

bool shouldReturnTypedErrorIndirectly() const;

using EnumerationCallback =
llvm::function_ref<void(CharUnits offset, CharUnits end, llvm::Type *type)>;

Expand Down
9 changes: 9 additions & 0 deletions clang/lib/CodeGen/ABIInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,15 @@ bool SwiftABIInfo::shouldPassIndirectly(ArrayRef<llvm::Type *> ComponentTys,
return occupiesMoreThan(ComponentTys, /*total=*/4);
}

bool SwiftABIInfo::shouldReturnTypedErrorIndirectly(
ArrayRef<llvm::Type *> ComponentTys) const {
for (llvm::Type *type : ComponentTys) {
if (!type->isIntegerTy() && !type->isPointerTy())
return true;
}
return shouldPassIndirectly(ComponentTys, /*AsReturnValue=*/true);
}

bool SwiftABIInfo::isLegalVectorType(CharUnits VectorSize, llvm::Type *EltTy,
unsigned NumElts) const {
// The default implementation of this assumes that the target guarantees
Expand Down
3 changes: 3 additions & 0 deletions clang/lib/CodeGen/ABIInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ class SwiftABIInfo {

/// Returns true if swifterror is lowered to a register by the target ABI.
bool isSwiftErrorInRegister() const { return SwiftErrorInRegister; };

virtual bool
shouldReturnTypedErrorIndirectly(ArrayRef<llvm::Type *> ComponentTys) const;
};
} // end namespace CodeGen
} // end namespace clang
Expand Down
21 changes: 21 additions & 0 deletions clang/lib/CodeGen/SwiftCallingConv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,27 @@ bool SwiftAggLowering::shouldPassIndirectly(bool asReturnValue) const {
return getSwiftABIInfo(CGM).shouldPassIndirectly(componentTys, asReturnValue);
}

bool SwiftAggLowering::shouldReturnTypedErrorIndirectly() const {
assert(Finished && "haven't yet finished lowering");

// Empty types don't need to be passed indirectly.
if (Entries.empty())
return false;

// Avoid copying the array of types when there's just a single element.
if (Entries.size() == 1) {
return getSwiftABIInfo(CGM).shouldReturnTypedErrorIndirectly(
Entries.back().Type);
}

SmallVector<llvm::Type *, 8> componentTys;
componentTys.reserve(Entries.size());
for (auto &entry : Entries) {
componentTys.push_back(entry.Type);
}
return getSwiftABIInfo(CGM).shouldReturnTypedErrorIndirectly(componentTys);
}

bool swiftcall::shouldPassIndirectly(CodeGenModule &CGM,
ArrayRef<llvm::Type*> componentTys,
bool asReturnValue) {
Expand Down