Skip to content

Commit e5f0720

Browse files
committed
[Clang][LoongArch] Add support for UEFI target
This patch adds basic UEFI target support for loongarch64, enabling Clang to recognize and handle the loongarch64-unknown-uefi target triple.
1 parent 114b3b8 commit e5f0720

File tree

5 files changed

+28
-2
lines changed

5 files changed

+28
-2
lines changed

clang/lib/Basic/Targets.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,9 @@ std::unique_ptr<TargetInfo> AllocateTarget(const llvm::Triple &Triple,
767767
case llvm::Triple::OpenBSD:
768768
return std::make_unique<OpenBSDTargetInfo<LoongArch64TargetInfo>>(Triple,
769769
Opts);
770+
case llvm::Triple::UEFI:
771+
return std::make_unique<UEFITargetInfo<LoongArch64TargetInfo>>(Triple,
772+
Opts);
770773
default:
771774
return std::make_unique<LoongArch64TargetInfo>(Triple, Opts);
772775
}

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"
@@ -159,6 +160,8 @@ class LLVM_LIBRARY_VISIBILITY LoongArch64TargetInfo
159160
IntMaxType = Int64Type = SignedLong;
160161
HasUnalignedAccess = true;
161162
resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n32:64-S128");
163+
if (Triple.isUEFI())
164+
resetDataLayout("e-m:w-p:64:64-i64:64-i128:128-n32:64-S128");
162165
// TODO: select appropriate ABI.
163166
setABI("lp64d");
164167
}

clang/lib/Driver/Driver.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -698,8 +698,10 @@ static llvm::Triple computeTargetTriple(const Driver &D,
698698
}
699699
}
700700

701-
// Currently the only architecture supported by *-uefi triples are x86_64.
702-
if (Target.isUEFI() && Target.getArch() != llvm::Triple::x86_64)
701+
// Currently the only architectures supported by *-uefi triples are
702+
// x86_64 and loongarch64.
703+
if (Target.isUEFI() && Target.getArch() != llvm::Triple::x86_64 &&
704+
Target.getArch() != llvm::Triple::loongarch64)
703705
D.Diag(diag::err_target_unknown_triple) << Target.str();
704706

705707
// The `-maix[32|64]` flags are only valid for AIX targets.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// RUN: %clang -target loongarch64-unknown-uefi -S -emit-llvm -o - %s | \
2+
// RUN: FileCheck --check-prefix=LA64_UEFI %s
3+
// LA64_UEFI: target datalayout = "e-m:w-p:64:64-i64:64-i128:128-n32:64-S128"

clang/test/Driver/uefi-constructed-args.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,18 @@
1212
// CHECK-SAME: "/entry:EfiMain"
1313
// CHECK-SAME: "/tsaware:no"
1414
// CHECK-SAME: "/debug"
15+
16+
// RUN: %clang -### --target=loongarch64-unknown-uefi -g -- %s 2>&1 \
17+
// RUN: | FileCheck -check-prefixes=LA64 %s
18+
// RUN: %clang_cl -### --target=loongarch64-unknown-uefi -g -- %s 2>&1 \
19+
// RUN: | FileCheck -check-prefixes=LA64 %s
20+
// LA64: "-cc1"
21+
// LA64-SAME: "-triple" "loongarch64-unknown-uefi"
22+
// LA64-SAME: "-mrelocation-model" "pic" "-pic-level" "2"
23+
// LA64-SAME: "-mframe-pointer=all"
24+
// LA64-SAME: "-fms-extensions"
25+
// LA64-NEXT: "/nologo"
26+
// LA64-SAME: "/subsystem:efi_application"
27+
// LA64-SAME: "/entry:EfiMain"
28+
// LA64-SAME: "/tsaware:no"
29+
// LA64-SAME: "/debug"

0 commit comments

Comments
 (0)