Skip to content

Commit cc504c5

Browse files
committed
[Driver] Add toolchain for LoongArch64 UEFI target
This patch is inspired by the X86_64's pr D159541.
1 parent 72c55e8 commit cc504c5

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

clang/lib/Basic/Targets.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,9 @@ std::unique_ptr<TargetInfo> AllocateTarget(const llvm::Triple &Triple,
760760
case llvm::Triple::FreeBSD:
761761
return std::make_unique<FreeBSDTargetInfo<LoongArch64TargetInfo>>(Triple,
762762
Opts);
763+
case llvm::Triple::UEFI:
764+
return std::make_unique<UEFITargetInfo<LoongArch64TargetInfo>>(Triple,
765+
Opts);
763766
default:
764767
return std::make_unique<LoongArch64TargetInfo>(Triple, Opts);
765768
}

clang/lib/Basic/Targets/LoongArch.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef LLVM_CLANG_LIB_BASIC_TARGETS_LOONGARCH_H
1414
#define LLVM_CLANG_LIB_BASIC_TARGETS_LOONGARCH_H
1515

16+
#include "OSTargets.h"
1617
#include "clang/Basic/TargetInfo.h"
1718
#include "clang/Basic/TargetOptions.h"
1819
#include "llvm/Support/Compiler.h"
@@ -146,6 +147,8 @@ class LLVM_LIBRARY_VISIBILITY LoongArch64TargetInfo
146147
IntMaxType = Int64Type = SignedLong;
147148
HasUnalignedAccess = true;
148149
resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n32:64-S128");
150+
if (Triple.isUEFI())
151+
resetDataLayout("e-m:w-p:64:64-i64:64-i128:128-n32:64-S128");
149152
// TODO: select appropriate ABI.
150153
setABI("lp64d");
151154
}

llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,11 @@ static cl::opt<bool>
5656
cl::init(false));
5757

5858
static std::string computeDataLayout(const Triple &TT) {
59-
if (TT.isArch64Bit())
59+
if (TT.isArch64Bit()) {
60+
if (TT.isUEFI())
61+
return "e-m:w-p:64:64-i64:64-i128:128-n32:64-S128";
6062
return "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128";
63+
}
6164
assert(TT.isArch32Bit() && "only LA32 and LA64 are currently supported");
6265
return "e-m:e-p:32:32-i64:64-n32-S128";
6366
}

0 commit comments

Comments
 (0)