Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions clang/lib/Basic/Targets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,9 @@ std::unique_ptr<TargetInfo> AllocateTarget(const llvm::Triple &Triple,
case llvm::Triple::OpenBSD:
return std::make_unique<OpenBSDTargetInfo<LoongArch64TargetInfo>>(Triple,
Opts);
case llvm::Triple::UEFI:
return std::make_unique<UEFITargetInfo<LoongArch64TargetInfo>>(Triple,
Opts);
default:
return std::make_unique<LoongArch64TargetInfo>(Triple, Opts);
}
Expand Down
3 changes: 3 additions & 0 deletions clang/lib/Basic/Targets/LoongArch.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#ifndef LLVM_CLANG_LIB_BASIC_TARGETS_LOONGARCH_H
#define LLVM_CLANG_LIB_BASIC_TARGETS_LOONGARCH_H

#include "OSTargets.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Basic/TargetOptions.h"
#include "llvm/Support/Compiler.h"
Expand Down Expand Up @@ -159,6 +160,8 @@ class LLVM_LIBRARY_VISIBILITY LoongArch64TargetInfo
IntMaxType = Int64Type = SignedLong;
HasUnalignedAccess = true;
resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n32:64-S128");
if (Triple.isUEFI())
resetDataLayout("e-m:w-p:64:64-i64:64-i128:128-n32:64-S128");
// TODO: select appropriate ABI.
setABI("lp64d");
}
Expand Down
6 changes: 4 additions & 2 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -698,8 +698,10 @@ static llvm::Triple computeTargetTriple(const Driver &D,
}
}

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

// The `-maix[32|64]` flags are only valid for AIX targets.
Expand Down
3 changes: 3 additions & 0 deletions clang/test/CodeGen/LoongArch/uefi-data-layout.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// RUN: %clang -target loongarch64-unknown-uefi -S -emit-llvm -o - %s | \
// RUN: FileCheck --check-prefix=LA64_UEFI %s
// LA64_UEFI: target datalayout = "e-m:w-p:64:64-i64:64-i128:128-n32:64-S128"
15 changes: 15 additions & 0 deletions clang/test/Driver/uefi-constructed-args.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,18 @@
// CHECK-SAME: "/entry:EfiMain"
// CHECK-SAME: "/tsaware:no"
// CHECK-SAME: "/debug"

// RUN: %clang -### --target=loongarch64-unknown-uefi -g -- %s 2>&1 \
// RUN: | FileCheck -check-prefixes=LA64 %s
// RUN: %clang_cl -### --target=loongarch64-unknown-uefi -g -- %s 2>&1 \
// RUN: | FileCheck -check-prefixes=LA64 %s
// LA64: "-cc1"
// LA64-SAME: "-triple" "loongarch64-unknown-uefi"
// LA64-SAME: "-mrelocation-model" "pic" "-pic-level" "2"
// LA64-SAME: "-mframe-pointer=all"
// LA64-SAME: "-fms-extensions"
// LA64-NEXT: "/nologo"
// LA64-SAME: "/subsystem:efi_application"
// LA64-SAME: "/entry:EfiMain"
// LA64-SAME: "/tsaware:no"
// LA64-SAME: "/debug"
Loading