Skip to content

Commit 81cd003

Browse files
[clang] use mixin for aarch64 and x86_64 uefi
1 parent c7a6fcd commit 81cd003

File tree

3 files changed

+17
-39
lines changed

3 files changed

+17
-39
lines changed

clang/lib/Basic/Targets.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ std::unique_ptr<TargetInfo> AllocateTarget(const llvm::Triple &Triple,
165165
case llvm::Triple::OpenBSD:
166166
return std::make_unique<OpenBSDTargetInfo<AArch64leTargetInfo>>(Triple,
167167
Opts);
168+
case llvm::Triple::UEFI:
169+
return std::make_unique<UEFITargetInfo<AArch64leTargetInfo>>(Triple,
170+
Opts);
171+
168172
case llvm::Triple::Win32:
169173
switch (Triple.getEnvironment()) {
170174
case llvm::Triple::GNU:
@@ -614,7 +618,7 @@ std::unique_ptr<TargetInfo> AllocateTarget(const llvm::Triple &Triple,
614618
return std::make_unique<SolarisTargetInfo<X86_64TargetInfo>>(Triple,
615619
Opts);
616620
case llvm::Triple::UEFI:
617-
return std::make_unique<UEFIX86_64TargetInfo>(Triple, Opts);
621+
return std::make_unique<UEFITargetInfo<X86_64TargetInfo>>(Triple, Opts);
618622

619623
case llvm::Triple::Win32: {
620624
switch (Triple.getEnvironment()) {

clang/lib/Basic/Targets/OSTargets.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#define LLVM_CLANG_LIB_BASIC_TARGETS_OSTARGETS_H
1414

1515
#include "Targets.h"
16+
#include "clang/Basic/TargetInfo.h"
1617

1718
namespace clang {
1819
namespace targets {
@@ -788,6 +789,8 @@ class LLVM_LIBRARY_VISIBILITY ZOSTargetInfo : public OSTargetInfo<Target> {
788789
// UEFI target
789790
template <typename Target>
790791
class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo<Target> {
792+
llvm::Triple Triple;
793+
791794
protected:
792795
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
793796
MacroBuilder &Builder) const override {
@@ -796,10 +799,18 @@ class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo<Target> {
796799

797800
public:
798801
UEFITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
799-
: OSTargetInfo<Target>(Triple, Opts) {
802+
: OSTargetInfo<Target>(Triple, Opts), Triple(Triple) {
800803
this->WCharType = TargetInfo::UnsignedShort;
801804
this->WIntType = TargetInfo::UnsignedShort;
802805
}
806+
807+
TargetInfo::CallingConvKind
808+
getCallingConvKind(bool ClangABICompat4) const override {
809+
if (Triple.getArch() == llvm::Triple::x86_64)
810+
return TargetInfo::CallingConvKind::CCK_MicrosoftWin64;
811+
812+
return Target::getCallingConvKind(ClangABICompat4);
813+
}
803814
};
804815

805816
void addWindowsDefines(const llvm::Triple &Triple, const LangOptions &Opts,

clang/lib/Basic/Targets/X86.h

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -820,43 +820,6 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public X86TargetInfo {
820820
}
821821
};
822822

823-
// x86-64 UEFI target
824-
class LLVM_LIBRARY_VISIBILITY UEFIX86_64TargetInfo
825-
: public UEFITargetInfo<X86_64TargetInfo> {
826-
public:
827-
UEFIX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
828-
: UEFITargetInfo<X86_64TargetInfo>(Triple, Opts) {
829-
this->TheCXXABI.set(TargetCXXABI::Microsoft);
830-
this->MaxTLSAlign = 8192u * this->getCharWidth();
831-
this->resetDataLayout("e-m:w-p270:32:32-p271:32:32-p272:64:64-"
832-
"i64:64-i128:128-f80:128-n8:16:32:64-S128");
833-
}
834-
835-
void getTargetDefines(const LangOptions &Opts,
836-
MacroBuilder &Builder) const override {
837-
getOSDefines(Opts, X86TargetInfo::getTriple(), Builder);
838-
}
839-
840-
BuiltinVaListKind getBuiltinVaListKind() const override {
841-
return TargetInfo::CharPtrBuiltinVaList;
842-
}
843-
844-
CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
845-
switch (CC) {
846-
case CC_C:
847-
case CC_Win64:
848-
return CCCR_OK;
849-
default:
850-
return CCCR_Warning;
851-
}
852-
}
853-
854-
TargetInfo::CallingConvKind
855-
getCallingConvKind(bool ClangABICompat4) const override {
856-
return CCK_MicrosoftWin64;
857-
}
858-
};
859-
860823
// x86-64 Windows target
861824
class LLVM_LIBRARY_VISIBILITY WindowsX86_64TargetInfo
862825
: public WindowsTargetInfo<X86_64TargetInfo> {

0 commit comments

Comments
 (0)