[llvm] 4f2fde7 - [LoongArch] Honor the `--target-abi` option when generating e_flags
Weining Lu via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 1 19:40:01 PST 2023
Author: Weining Lu
Date: 2023-02-02T11:39:32+08:00
New Revision: 4f2fde781fa93294c480236392826dd1d2cb0741
URL: https://github.com/llvm/llvm-project/commit/4f2fde781fa93294c480236392826dd1d2cb0741
DIFF: https://github.com/llvm/llvm-project/commit/4f2fde781fa93294c480236392826dd1d2cb0741.diff
LOG: [LoongArch] Honor the `--target-abi` option when generating e_flags
Reviewed By: xen0n, MaskRay
Differential Revision: https://reviews.llvm.org/D142837
Added:
Modified:
llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.h
llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFStreamer.cpp
llvm/test/CodeGen/LoongArch/e_flags.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
index ff0804e2a144d..ecb68ff401e9f 100644
--- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
+++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
@@ -202,5 +202,5 @@ MCAsmBackend *llvm::createLoongArchAsmBackend(const Target &T,
const MCTargetOptions &Options) {
const Triple &TT = STI.getTargetTriple();
uint8_t OSABI = MCELFObjectTargetWriter::getOSABI(TT.getOS());
- return new LoongArchAsmBackend(STI, OSABI, TT.isArch64Bit());
+ return new LoongArchAsmBackend(STI, OSABI, TT.isArch64Bit(), Options);
}
diff --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.h b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.h
index 0d04cecc45547..ae9bb8af04198 100644
--- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.h
+++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.h
@@ -26,11 +26,13 @@ class LoongArchAsmBackend : public MCAsmBackend {
const MCSubtargetInfo &STI;
uint8_t OSABI;
bool Is64Bit;
+ const MCTargetOptions &TargetOptions;
public:
- LoongArchAsmBackend(const MCSubtargetInfo &STI, uint8_t OSABI, bool Is64Bit)
- : MCAsmBackend(support::little), STI(STI), OSABI(OSABI),
- Is64Bit(Is64Bit) {}
+ LoongArchAsmBackend(const MCSubtargetInfo &STI, uint8_t OSABI, bool Is64Bit,
+ const MCTargetOptions &Options)
+ : MCAsmBackend(support::little), STI(STI), OSABI(OSABI), Is64Bit(Is64Bit),
+ TargetOptions(Options) {}
~LoongArchAsmBackend() override {}
void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
@@ -63,6 +65,7 @@ class LoongArchAsmBackend : public MCAsmBackend {
std::unique_ptr<MCObjectTargetWriter>
createObjectTargetWriter() const override;
+ const MCTargetOptions &getTargetOptions() const { return TargetOptions; }
};
} // end namespace llvm
diff --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFStreamer.cpp b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFStreamer.cpp
index 3410c8f4277d7..a6e15e09463d2 100644
--- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFStreamer.cpp
+++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFStreamer.cpp
@@ -12,6 +12,7 @@
#include "LoongArchELFStreamer.h"
#include "LoongArchAsmBackend.h"
+#include "LoongArchBaseInfo.h"
#include "llvm/BinaryFormat/ELF.h"
#include "llvm/MC/MCAssembler.h"
#include "llvm/MC/MCCodeEmitter.h"
@@ -23,9 +24,10 @@ using namespace llvm;
LoongArchTargetELFStreamer::LoongArchTargetELFStreamer(
MCStreamer &S, const MCSubtargetInfo &STI)
: LoongArchTargetStreamer(S) {
- // FIXME: select appropriate ABI.
- setTargetABI(STI.getTargetTriple().isArch64Bit() ? LoongArchABI::ABI_LP64D
- : LoongArchABI::ABI_ILP32D);
+ auto &MAB = static_cast<LoongArchAsmBackend &>(
+ getStreamer().getAssembler().getBackend());
+ setTargetABI(LoongArchABI::computeTargetABI(
+ STI.getTargetTriple(), MAB.getTargetOptions().getABIName()));
}
MCELFStreamer &LoongArchTargetELFStreamer::getStreamer() {
diff --git a/llvm/test/CodeGen/LoongArch/e_flags.ll b/llvm/test/CodeGen/LoongArch/e_flags.ll
index d55b9b7267484..a15e4ac5b4393 100644
--- a/llvm/test/CodeGen/LoongArch/e_flags.ll
+++ b/llvm/test/CodeGen/LoongArch/e_flags.ll
@@ -1,15 +1,32 @@
; RUN: llc --mtriple=loongarch32 --filetype=obj %s -o %t-la32
; RUN: llvm-readelf -h %t-la32 | FileCheck %s --check-prefixes=ILP32,ABI-D --match-full-lines
+
+; RUN: llc --mtriple=loongarch32 --filetype=obj %s --target-abi=ilp32s -o %t-ilp32s
+; RUN: llvm-readelf -h %t-ilp32s | FileCheck %s --check-prefixes=ILP32,ABI-S --match-full-lines
+
+; RUN: llc --mtriple=loongarch32 --filetype=obj %s --target-abi=ilp32f -o %t-ilp32f
+; RUN: llvm-readelf -h %t-ilp32f | FileCheck %s --check-prefixes=ILP32,ABI-F --match-full-lines
+
+; RUN: llc --mtriple=loongarch32 --filetype=obj %s --target-abi=ilp32d -o %t-ilp32d
+; RUN: llvm-readelf -h %t-ilp32d | FileCheck %s --check-prefixes=ILP32,ABI-D --match-full-lines
+
; RUN: llc --mtriple=loongarch64 --filetype=obj %s -o %t-la64
; RUN: llvm-readelf -h %t-la64 | FileCheck %s --check-prefixes=LP64,ABI-D --match-full-lines
-;; Note that we have not support the -target-abi option to select specific ABI.
-;; See comments in LoongArchELFStreamer.cpp. So here we only check the default behaviour.
-;; After -target-abi is supported, we can add more tests.
+; RUN: llc --mtriple=loongarch64 --filetype=obj %s --target-abi=lp64s -o %t-lp64s
+; RUN: llvm-readelf -h %t-lp64s | FileCheck %s --check-prefixes=LP64,ABI-S --match-full-lines
+
+; RUN: llc --mtriple=loongarch64 --filetype=obj %s --target-abi=lp64f -o %t-lp64f
+; RUN: llvm-readelf -h %t-lp64f | FileCheck %s --check-prefixes=LP64,ABI-F --match-full-lines
+
+; RUN: llc --mtriple=loongarch64 --filetype=obj %s --target-abi=lp64d -o %t-lp64d
+; RUN: llvm-readelf -h %t-lp64d | FileCheck %s --check-prefixes=LP64,ABI-D --match-full-lines
; LP64: Class: ELF64
; ILP32: Class: ELF32
+; ABI-S: Flags: 0x41, SOFT-FLOAT, OBJ-v1
+; ABI-F: Flags: 0x42, SINGLE-FLOAT, OBJ-v1
; ABI-D: Flags: 0x43, DOUBLE-FLOAT, OBJ-v1
define void @foo() {
More information about the llvm-commits
mailing list