Skip to content

Commit 6524e58

Browse files
committed
[clang] Add Swift support for MIPS
Adds support for compiling Swift targeting the MIPS ABI Differential Revision: https://reviews.llvm.org/D137512
1 parent 6bf159a commit 6524e58

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

clang/lib/Basic/Targets/Mips.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,17 @@ class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public TargetInfo {
407407

408408
bool validateTarget(DiagnosticsEngine &Diags) const override;
409409
bool hasExtIntType() const override { return true; }
410+
411+
CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
412+
switch (CC) {
413+
case CC_Swift:
414+
return CCCR_OK;
415+
case CC_SwiftAsync:
416+
return CCCR_Error;
417+
default:
418+
return CCCR_Warning;
419+
}
420+
}
410421
};
411422
} // namespace targets
412423
} // namespace clang

clang/lib/CodeGen/TargetInfo.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7704,7 +7704,7 @@ void MSP430TargetCodeGenInfo::setTargetAttributes(
77047704
//===----------------------------------------------------------------------===//
77057705

77067706
namespace {
7707-
class MipsABIInfo : public ABIInfo {
7707+
class MipsABIInfo : public SwiftABIInfo {
77087708
bool IsO32;
77097709
unsigned MinABIStackAlignInBytes, StackAlignInBytes;
77107710
void CoerceToIntArgs(uint64_t TySize,
@@ -7713,16 +7713,25 @@ class MipsABIInfo : public ABIInfo {
77137713
llvm::Type* returnAggregateInRegs(QualType RetTy, uint64_t Size) const;
77147714
llvm::Type* getPaddingType(uint64_t Align, uint64_t Offset) const;
77157715
public:
7716-
MipsABIInfo(CodeGenTypes &CGT, bool _IsO32) :
7717-
ABIInfo(CGT), IsO32(_IsO32), MinABIStackAlignInBytes(IsO32 ? 4 : 8),
7718-
StackAlignInBytes(IsO32 ? 8 : 16) {}
7716+
MipsABIInfo(CodeGenTypes &CGT, bool _IsO32)
7717+
: SwiftABIInfo(CGT), IsO32(_IsO32),
7718+
MinABIStackAlignInBytes(IsO32 ? 4 : 8),
7719+
StackAlignInBytes(IsO32 ? 8 : 16) {}
77197720

77207721
ABIArgInfo classifyReturnType(QualType RetTy) const;
77217722
ABIArgInfo classifyArgumentType(QualType RetTy, uint64_t &Offset) const;
77227723
void computeInfo(CGFunctionInfo &FI) const override;
77237724
Address EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
77247725
QualType Ty) const override;
77257726
ABIArgInfo extendType(QualType Ty) const;
7727+
7728+
private:
7729+
bool shouldPassIndirectlyForSwift(ArrayRef<llvm::Type *> scalars,
7730+
bool asReturnValue) const override {
7731+
return occupiesMoreThan(CGT, scalars, /*total*/ 4);
7732+
}
7733+
7734+
bool isSwiftErrorInRegister() const override { return false; }
77267735
};
77277736

77287737
class MIPSTargetCodeGenInfo : public TargetCodeGenInfo {

0 commit comments

Comments
 (0)