llvm.org GIT mirror llvm / 9b90153
AMDGPU: Add and set AMDGPU-specific e_flags Differential Revision: https://reviews.llvm.org/D38556 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@314987 91177308-0d34-0410-b5e6-96231b3b80d8 Konstantin Zhuravlyov 2 years ago
13 changed file(s) with 187 addition(s) and 63 deletion(s). Raw diff Collapse all Expand all
646646 #include "ELFRelocs/WebAssembly.def"
647647 };
648648
649 // AMDGPU specific e_flags.
650 enum : unsigned {
651 // AMDGPU machine architectures.
652 EF_AMDGPU_ARCH_NONE = 0x00000000, // None/unknown.
653 EF_AMDGPU_ARCH_R600 = 0x00000001, // AMD HD2XXX-HD6XXX GPUs.
654 EF_AMDGPU_ARCH_GCN = 0x00000002, // AMD GCN GFX6+ GPUs.
655 EF_AMDGPU_ARCH = 0x0000000f // EF_AMDGPU_ARCH_XXX selection mask.
656 };
657
649658 // ELF Relocation types for AMDGPU
650659 enum {
651660 #include "ELFRelocs/AMDGPU.def"
10621062 default: return Triple::UnknownArch;
10631063 }
10641064
1065 case ELF::EM_AMDGPU:
1066 if (EF.getHeader()->e_ident[ELF::EI_CLASS] != ELF::ELFCLASS64)
1067 return Triple::UnknownArch;
1065 case ELF::EM_AMDGPU: {
10681066 if (!IsLittleEndian)
10691067 return Triple::UnknownArch;
10701068
1071 // TODO: Determine r600/amdgcn architecture based e_flags.
1072 return Triple::amdgcn;
1069 unsigned EFlags = EF.getHeader()->e_flags;
1070 switch (EFlags & ELF::EF_AMDGPU_ARCH) {
1071 case ELF::EF_AMDGPU_ARCH_R600:
1072 return Triple::r600;
1073 case ELF::EF_AMDGPU_ARCH_GCN:
1074 return Triple::amdgcn;
1075 default:
1076 return Triple::UnknownArch;
1077 }
1078 }
10731079
10741080 case ELF::EM_BPF:
10751081 return IsLittleEndian ? Triple::bpfel : Triple::bpfeb;
245245 ECase(ELFOSABI_HPUX);
246246 ECase(ELFOSABI_NETBSD);
247247 ECase(ELFOSABI_GNU);
248 ECase(ELFOSABI_GNU);
249248 ECase(ELFOSABI_HURD);
250249 ECase(ELFOSABI_SOLARIS);
251250 ECase(ELFOSABI_AIX);
369368 BCase(EF_RISCV_RVE);
370369 break;
371370 case ELF::EM_AMDGPU:
371 BCaseMask(EF_AMDGPU_ARCH_R600, EF_AMDGPU_ARCH);
372 BCaseMask(EF_AMDGPU_ARCH_GCN, EF_AMDGPU_ARCH);
373 break;
372374 case ELF::EM_X86_64:
373375 break;
374376 default:
88
99 #include "AMDGPUELFStreamer.h"
1010 #include "Utils/AMDGPUBaseInfo.h"
11 #include "llvm/BinaryFormat/ELF.h"
1112
1213 using namespace llvm;
1314
14 MCELFStreamer *llvm::createAMDGPUELFStreamer(MCContext &Context,
15 MCAsmBackend &MAB,
16 raw_pwrite_stream &OS,
17 MCCodeEmitter *Emitter,
18 bool RelaxAll) {
19 return new AMDGPUELFStreamer(Context, MAB, OS, Emitter);
15 AMDGPUELFStreamer::AMDGPUELFStreamer(const Triple &T, MCContext &Context,
16 MCAsmBackend &MAB, raw_pwrite_stream &OS,
17 MCCodeEmitter *Emitter)
18 : MCELFStreamer(Context, MAB, OS, Emitter) {
19 unsigned Arch = ELF::EF_AMDGPU_ARCH_NONE;
20 switch (T.getArch()) {
21 case Triple::r600:
22 Arch = ELF::EF_AMDGPU_ARCH_R600;
23 break;
24 case Triple::amdgcn:
25 Arch = ELF::EF_AMDGPU_ARCH_GCN;
26 break;
27 default:
28 break;
29 }
30
31 MCAssembler &MCA = getAssembler();
32 unsigned EFlags = MCA.getELFHeaderEFlags();
33 EFlags &= ~ELF::EF_AMDGPU_ARCH;
34 EFlags |= Arch;
35 MCA.setELFHeaderEFlags(EFlags);
2036 }
37
38 MCELFStreamer *llvm::createAMDGPUELFStreamer(const Triple &T, MCContext &Context,
39 MCAsmBackend &MAB,
40 raw_pwrite_stream &OS,
41 MCCodeEmitter *Emitter,
42 bool RelaxAll) {
43 return new AMDGPUELFStreamer(T, Context, MAB, OS, Emitter);
44 }
2424
2525 class AMDGPUELFStreamer : public MCELFStreamer {
2626 public:
27 AMDGPUELFStreamer(MCContext &Context, MCAsmBackend &MAB, raw_pwrite_stream &OS,
28 MCCodeEmitter *Emitter)
29 : MCELFStreamer(Context, MAB, OS, Emitter) { }
30
27 AMDGPUELFStreamer(const Triple &T, MCContext &Context, MCAsmBackend &MAB,
28 raw_pwrite_stream &OS, MCCodeEmitter *Emitter);
3129 };
3230
33 MCELFStreamer *createAMDGPUELFStreamer(MCContext &Context, MCAsmBackend &MAB,
34 raw_pwrite_stream &OS,
35 MCCodeEmitter *Emitter, bool RelaxAll);
31 MCELFStreamer *createAMDGPUELFStreamer(const Triple &T, MCContext &Context,
32 MCAsmBackend &MAB, raw_pwrite_stream &OS,
33 MCCodeEmitter *Emitter, bool RelaxAll);
3634 } // namespace llvm.
3735
3836 #endif
7979 static MCStreamer *createMCStreamer(const Triple &T, MCContext &Context,
8080 MCAsmBackend &MAB, raw_pwrite_stream &OS,
8181 MCCodeEmitter *Emitter, bool RelaxAll) {
82 if (T.getOS() == Triple::AMDHSA)
83 return createAMDGPUELFStreamer(Context, MAB, OS, Emitter, RelaxAll);
84
85 return createELFStreamer(Context, MAB, OS, Emitter, RelaxAll);
82 return createAMDGPUELFStreamer(T, Context, MAB, OS, Emitter, RelaxAll);
8683 }
8784
8885 extern "C" void LLVMInitializeAMDGPUTargetMC() {
2222 ; RUN: llc -mtriple=amdgcn-unknown-mesa3d -filetype=obj < %s | llvm-readobj -file-headers - | FileCheck --check-prefix=GCN --check-prefix=GCN-OSABI-MESA3D %s
2323
2424 ; R600: Format: ELF32-amdgpu
25 ; R600: Arch: unknown
25 ; R600: Arch: r600
2626 ; R600: AddressSize: 32bit
27 ; GCN: Format: ELF64-amdgpu
28 ; GCN: Arch: amdgcn
29 ; GCN: AddressSize: 64bit
27 ; GCN: Format: ELF64-amdgpu
28 ; GCN: Arch: amdgcn
29 ; GCN: AddressSize: 64bit
3030
3131 ; R600-OSABI-NONE: OS/ABI: SystemV (0x0)
3232 ; GCN-OSABI-NONE: OS/ABI: SystemV (0x0)
3535 ; GCN-OSABI-MESA3D: OS/ABI: AMDGPU_MESA3D (0x42)
3636
3737 ; R600: Machine: EM_AMDGPU (0xE0)
38 ; GCN: Machine: EM_AMDGPU (0xE0)
38 ; R600: Flags [ (0x1)
39 ; R600: EF_AMDGPU_ARCH_R600 (0x1)
40 ; R600: ]
41 ; GCN: Machine: EM_AMDGPU (0xE0)
42 ; GCN: Flags [ (0x2)
43 ; GCN: EF_AMDGPU_ARCH_GCN (0x2)
44 ; GCN: ]
3945
4046 define amdgpu_kernel void @elf_header() {
4147 ret void
42 }
48 }
0 # RUN: yaml2obj %s > %t.o
1 # RUN: llvm-readobj -s -file-headers %t.o | FileCheck --check-prefix=ELF %s
2 # RUN: obj2yaml %t.o | FileCheck --check-prefix=YAML %s
3
4 # ELF: Format: ELF32-amdgpu
5 # ELF: Arch: r600
6 # ELF: ElfHeader {
7 # ELF: Ident {
8 # ELF: OS/ABI: AMDGPU_HSA (0x40)
9 # ELF: ABIVersion: 0
10 # ELF: }
11 # ELF: Machine: EM_AMDGPU (0xE0)
12 # ELF: Flags [ (0x1)
13 # ELF: EF_AMDGPU_ARCH_R600 (0x1)
14 # ELF: ]
15 # ELF: }
16
17 # YAML: FileHeader
18 # YAML: Class: ELFCLASS32
19 # YAML: Data: ELFDATA2LSB
20 # YAML: OSABI: ELFOSABI_AMDGPU_HSA
21 # YAML: Type: ET_REL
22 # YAML: Machine: EM_AMDGPU
23 # YAML: Flags: [ EF_AMDGPU_ARCH_R600 ]
24
25 --- !ELF
26 FileHeader:
27 Class: ELFCLASS32
28 Data: ELFDATA2LSB
29 OSABI: ELFOSABI_AMDGPU_HSA
30 Type: ET_REL
31 Machine: EM_AMDGPU
32 Flags: [ EF_AMDGPU_ARCH_R600 ]
33 ...
0 # RUN: yaml2obj %s > %t.o
1 # RUN: llvm-readobj -s -file-headers %t.o | FileCheck %s
1 # RUN: llvm-readobj -s -file-headers %t.o | FileCheck --check-prefix=ELF %s
2 # RUN: obj2yaml %t.o | FileCheck --check-prefix=YAML %s
23
3 # CHECK: Format: ELF64-amdgpu
4 # CHECK: Arch: amdgcn
5 # CHECK: ElfHeader {
6 # CHECK: Ident {
7 # CHECK: OS/ABI: AMDGPU_HSA (0x40)
8 # CHECK: ABIVersion: 0
9 # CHECK: }
10 # CHECK: Machine: EM_AMDGPU (0xE0)
11 # CHECK: }
4 # ELF: Format: ELF64-amdgpu
5 # ELF: Arch: amdgcn
6 # ELF: ElfHeader {
7 # ELF: Ident {
8 # ELF: OS/ABI: AMDGPU_HSA (0x40)
9 # ELF: ABIVersion: 0
10 # ELF: }
11 # ELF: Machine: EM_AMDGPU (0xE0)
12 # ELF: Flags [ (0x2)
13 # ELF: EF_AMDGPU_ARCH_GCN (0x2)
14 # ELF: ]
15 # ELF: }
16
17 # YAML: FileHeader
18 # YAML: Class: ELFCLASS64
19 # YAML: Data: ELFDATA2LSB
20 # YAML: OSABI: ELFOSABI_AMDGPU_HSA
21 # YAML: Type: ET_REL
22 # YAML: Machine: EM_AMDGPU
23 # YAML: Flags: [ EF_AMDGPU_ARCH_GCN ]
1224
1325 --- !ELF
1426 FileHeader:
1527 Class: ELFCLASS64
1628 Data: ELFDATA2LSB
29 OSABI: ELFOSABI_AMDGPU_HSA
1730 Type: ET_REL
1831 Machine: EM_AMDGPU
19 OSABI: ELFOSABI_AMDGPU_HSA
32 Flags: [ EF_AMDGPU_ARCH_GCN ]
2033 ...
0 # RUN: yaml2obj %s > %t.o
1 # RUN: llvm-readobj -s -file-headers %t.o | FileCheck %s
1 # RUN: llvm-readobj -s -file-headers %t.o | FileCheck --check-prefix=ELF %s
2 # RUN: obj2yaml %t.o | FileCheck --check-prefix=YAML %s
23
3 # CHECK: Format: ELF64-amdgpu
4 # CHECK: Arch: amdgcn
5 # CHECK: ElfHeader {
6 # CHECK: Ident {
7 # CHECK: OS/ABI: AMDGPU_PAL (0x41)
8 # CHECK: ABIVersion: 0
9 # CHECK: }
10 # CHECK: Machine: EM_AMDGPU (0xE0)
11 # CHECK: }
4 # ELF: Format: ELF64-amdgpu
5 # ELF: Arch: amdgcn
6 # ELF: ElfHeader {
7 # ELF: Ident {
8 # ELF: OS/ABI: AMDGPU_PAL (0x41)
9 # ELF: ABIVersion: 0
10 # ELF: }
11 # ELF: Machine: EM_AMDGPU (0xE0)
12 # ELF: Flags [ (0x2)
13 # ELF: EF_AMDGPU_ARCH_GCN (0x2)
14 # ELF: ]
15 # ELF: }
16
17 # YAML: FileHeader
18 # YAML: Class: ELFCLASS64
19 # YAML: Data: ELFDATA2LSB
20 # YAML: OSABI: ELFOSABI_AMDGPU_PAL
21 # YAML: Type: ET_REL
22 # YAML: Machine: EM_AMDGPU
23 # YAML: Flags: [ EF_AMDGPU_ARCH_GCN ]
1224
1325 --- !ELF
1426 FileHeader:
1527 Class: ELFCLASS64
1628 Data: ELFDATA2LSB
29 OSABI: ELFOSABI_AMDGPU_PAL
1730 Type: ET_REL
1831 Machine: EM_AMDGPU
19 OSABI: ELFOSABI_AMDGPU_PAL
32 Flags: [ EF_AMDGPU_ARCH_GCN ]
2033 ...
0 # RUN: yaml2obj %s > %t.o
1 # RUN: llvm-readobj -s -file-headers %t.o | FileCheck %s
1 # RUN: llvm-readobj -s -file-headers %t.o | FileCheck --check-prefix=ELF %s
2 # RUN: obj2yaml %t.o | FileCheck --check-prefix=YAML %s
23
3 # CHECK: Format: ELF64-amdgpu
4 # CHECK: Arch: amdgcn
5 # CHECK: ElfHeader {
6 # CHECK: Ident {
7 # CHECK: OS/ABI: AMDGPU_MESA3D (0x42)
8 # CHECK: ABIVersion: 0
9 # CHECK: }
10 # CHECK: Machine: EM_AMDGPU (0xE0)
11 # CHECK: }
4 # ELF: Format: ELF64-amdgpu
5 # ELF: Arch: amdgcn
6 # ELF: ElfHeader {
7 # ELF: Ident {
8 # ELF: OS/ABI: AMDGPU_MESA3D (0x42)
9 # ELF: ABIVersion: 0
10 # ELF: }
11 # ELF: Machine: EM_AMDGPU (0xE0)
12 # ELF: Flags [ (0x2)
13 # ELF: EF_AMDGPU_ARCH_GCN (0x2)
14 # ELF: ]
15 # ELF: }
16
17 # YAML: FileHeader
18 # YAML: Class: ELFCLASS64
19 # YAML: Data: ELFDATA2LSB
20 # YAML: OSABI: ELFOSABI_AMDGPU_MESA3D
21 # YAML: Type: ET_REL
22 # YAML: Machine: EM_AMDGPU
23 # YAML: Flags: [ EF_AMDGPU_ARCH_GCN ]
1224
1325 --- !ELF
1426 FileHeader:
1527 Class: ELFCLASS64
1628 Data: ELFDATA2LSB
29 OSABI: ELFOSABI_AMDGPU_MESA3D
1730 Type: ET_REL
1831 Machine: EM_AMDGPU
19 OSABI: ELFOSABI_AMDGPU_MESA3D
32 Flags: [ EF_AMDGPU_ARCH_GCN ]
2033 ...
0 RUN: llvm-readobj -file-headers -program-headers -sections -symbols %p/Inputs/trivial.obj.elf-amdhsa-gfx803 | FileCheck %s
11
22 CHECK: Format: ELF64-amdgpu
3 CHECK: Arch: amdgcn
3 CHECK: Arch: unknown
44 CHECK: ElfHeader {
55 CHECK: Ident {
66 CHECK: OS/ABI: AMDGPU_HSA (0x40)
12431243 LLVM_READOBJ_ENUM_ENT(ELF, EF_MIPS_ARCH_64R6)
12441244 };
12451245
1246 static const EnumEntry ElfHeaderAMDGPUFlags[] = {
1247 LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_ARCH_NONE),
1248 LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_ARCH_R600),
1249 LLVM_READOBJ_ENUM_ENT(ELF, EF_AMDGPU_ARCH_GCN)
1250 };
1251
12461252 static const EnumEntry ElfHeaderRISCVFlags[] = {
12471253 LLVM_READOBJ_ENUM_ENT(ELF, EF_RISCV_RVC),
12481254 LLVM_READOBJ_ENUM_ENT(ELF, EF_RISCV_FLOAT_ABI_SINGLE),
35613567 W.printFlags("Flags", e->e_flags, makeArrayRef(ElfHeaderMipsFlags),
35623568 unsigned(ELF::EF_MIPS_ARCH), unsigned(ELF::EF_MIPS_ABI),
35633569 unsigned(ELF::EF_MIPS_MACH));
3570 else if (e->e_machine == EM_AMDGPU)
3571 W.printFlags("Flags", e->e_flags, makeArrayRef(ElfHeaderAMDGPUFlags),
3572 unsigned(ELF::EF_AMDGPU_ARCH));
35643573 else if (e->e_machine == EM_RISCV)
35653574 W.printFlags("Flags", e->e_flags, makeArrayRef(ElfHeaderRISCVFlags));
35663575 else