Skip to content

Commit

Permalink
Merge pull request #8870 from drexin/wip-typed-throws
Browse files Browse the repository at this point in the history
[CodeGen] Add typed error logic to  SwiftAggLowering
  • Loading branch information
drexin committed Jun 22, 2024
2 parents 2d53850 + 7936f81 commit 983a35a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
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 @@ -151,6 +151,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

0 comments on commit 983a35a

Please sign in to comment.