Skip to content

Commit 318a295

Browse files
committed
[SOL] Create SBF sub architectures (#136)
* Split targets * Use sbpf instead of sbf for triples
1 parent f8f6682 commit 318a295

File tree

12 files changed

+106
-5
lines changed

12 files changed

+106
-5
lines changed

llvm/include/llvm/TargetParser/Triple.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ class Triple {
165165
SPIRVSubArch_v15,
166166
SPIRVSubArch_v16,
167167

168+
168169
// DXIL sub-arch corresponds to its version.
169170
DXILSubArch_v1_0,
170171
DXILSubArch_v1_1,
@@ -176,6 +177,10 @@ class Triple {
176177
DXILSubArch_v1_7,
177178
DXILSubArch_v1_8,
178179
LatestDXILSubArch = DXILSubArch_v1_8,
180+
181+
SBFSubArch_v1,
182+
SBFSubArch_v2,
183+
SBFSubArch_v3,
179184
};
180185
enum VendorType {
181186
UnknownVendor,

llvm/lib/Target/SBF/MCTargetDesc/SBFMCTargetDesc.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ static MCRegisterInfo *createSBFMCRegisterInfo(const Triple &TT) {
5454

5555
static MCSubtargetInfo *createSBFMCSubtargetInfo(const Triple &TT,
5656
StringRef CPU, StringRef FS) {
57-
return createSBFMCSubtargetInfoImpl(TT, CPU, /*TuneCPU*/ CPU, FS);
57+
std::string CpuStr = cpuFromSubArch(TT, CPU.str());
58+
StringRef CpuRef = CpuStr;
59+
return createSBFMCSubtargetInfoImpl(TT, CpuRef, /*TuneCPU*/ CpuRef, FS);
5860
}
5961

6062
static MCStreamer *createSBFMCStreamer(const Triple &T, MCContext &Ctx,

llvm/lib/Target/SBF/SBFSubtarget.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "SBF.h"
1515
#include "llvm/MC/TargetRegistry.h"
1616
#include "llvm/TargetParser/Host.h"
17+
#include "TargetInfo/SBFTargetInfo.h"
1718

1819
using namespace llvm;
1920

@@ -59,8 +60,8 @@ void SBFSubtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) {
5960

6061
SBFSubtarget::SBFSubtarget(const Triple &TT, const std::string &CPU,
6162
const std::string &FS, const TargetMachine &TM)
62-
: SBFGenSubtargetInfo(TT, CPU, /*TuneCPU*/ CPU, FS), InstrInfo(),
63-
FrameLowering(initializeSubtargetDependencies(TT, CPU, FS)),
63+
: SBFGenSubtargetInfo(TT, cpuFromSubArch(TT, CPU), /*TuneCPU*/ cpuFromSubArch(TT, CPU), FS), InstrInfo(),
64+
FrameLowering(initializeSubtargetDependencies(TT, cpuFromSubArch(TT, CPU), FS)),
6465
TLInfo(TM, *this) {
6566
assert(TT.getArch() == Triple::sbf && "expected Triple::sbf");
6667
}

llvm/lib/Target/SBF/TargetInfo/SBFTargetInfo.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,32 @@ Target &llvm::getTheSBFXTarget() {
1616
return TheSBFTarget;
1717
}
1818

19+
std::string llvm::cpuFromSubArch(const Triple &TT, const std::string &CPU) {
20+
std::string CpuType;
21+
switch (TT.getSubArch()) {
22+
case Triple::SBFSubArch_v1:
23+
CpuType = "v1";
24+
break;
25+
case Triple::SBFSubArch_v2:
26+
CpuType = "v2";
27+
break;
28+
case Triple::SBFSubArch_v3:
29+
CpuType = "v3";
30+
break;
31+
default:
32+
break;
33+
}
34+
35+
assert((CPU.empty() || CpuType.empty() || CPU == CpuType) &&
36+
"Subarch type must match CPU type");
37+
38+
if (!CpuType.empty()) {
39+
return CpuType;
40+
}
41+
42+
return CPU;
43+
}
44+
1945
extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeSBFTargetInfo() {
2046
TargetRegistry::RegisterTarget(
2147
getTheSBFXTarget(), "sbf", "SBF new (little endian)", "SBF",

llvm/lib/Target/SBF/TargetInfo/SBFTargetInfo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
8+
#include "llvm/TargetParser/Triple.h"
89

910
#ifndef LLVM_LIB_TARGET_SBF_TARGETINFO_SBFTARGETINFO_H
1011
#define LLVM_LIB_TARGET_SBF_TARGETINFO_SBFTARGETINFO_H
@@ -14,6 +15,7 @@ namespace llvm {
1415
class Target;
1516

1617
Target &getTheSBFXTarget();
18+
std::string cpuFromSubArch(const Triple &TT, const std::string &CPU);
1719
} // namespace llvm
1820

1921
#endif // LLVM_LIB_TARGET_SBF_TARGETINFO_SBFTARGETINFO_H

llvm/lib/TargetParser/Triple.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,10 @@ static Triple::ArchType parseBPFArch(StringRef ArchName) {
414414
return Triple::bpfeb;
415415
} else if (ArchName == "bpf_le" || ArchName == "bpfel") {
416416
return Triple::bpfel;
417+
} else if (ArchName.equals("sbf") || ArchName.equals("sbpf") ||
418+
ArchName.equals("sbpfv1") || ArchName.equals("sbpfv2") ||
419+
ArchName.equals("sbpfv3")) {
420+
return Triple::sbf;
417421
} else {
418422
return Triple::UnknownArch;
419423
}
@@ -449,6 +453,8 @@ Triple::ArchType Triple::getArchTypeForLLVMName(StringRef Name) {
449453
.Case("riscv32", riscv32)
450454
.Case("riscv64", riscv64)
451455
.Case("hexagon", hexagon)
456+
.Case("sbf", BPFArch)
457+
.Case("sbpf", BPFArch)
452458
.Case("sparc", sparc)
453459
.Case("sparcel", sparcel)
454460
.Case("sparcv9", sparcv9)
@@ -640,7 +646,8 @@ static Triple::ArchType parseArch(StringRef ArchName) {
640646
if (ArchName.starts_with("arm") || ArchName.starts_with("thumb") ||
641647
ArchName.starts_with("aarch64"))
642648
return parseARMArch(ArchName);
643-
if (ArchName.starts_with("bpf"))
649+
if (ArchName.starts_with("bpf") || ArchName.starts_with("sbf") ||
650+
ArchName.starts_with("sbpf"))
644651
return parseBPFArch(ArchName);
645652
}
646653

@@ -821,6 +828,14 @@ static Triple::SubArchType parseSubArch(StringRef SubArchName) {
821828
.EndsWith("v1.8", Triple::DXILSubArch_v1_8)
822829
.Default(Triple::NoSubArch);
823830

831+
if (SubArchName.starts_with("sbpf")) {
832+
return StringSwitch<Triple::SubArchType>(SubArchName)
833+
.EndsWith("v1", Triple::SBFSubArch_v1)
834+
.EndsWith("v2", Triple::SBFSubArch_v2)
835+
.EndsWith("v3", Triple::SBFSubArch_v3)
836+
.Default(Triple::NoSubArch);
837+
}
838+
824839
StringRef ARMSubArch = ARM::getCanonicalArchName(SubArchName);
825840

826841
// For now, this is the small part. Early return.

llvm/test/CodeGen/SBF/many_args_new_conv.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
; RUN: llc -O2 -march=sbf -mcpu=v1 < %s | FileCheck %s
2+
; RUN: llc -O2 -mtriple=sbpfv1-solana-solana < %s | FileCheck %s
23
; RUN: llc -O2 -march=sbf -mcpu=v1 -mattr=+mem-encoding < %s | FileCheck %s
34

45
; Function Attrs: nounwind uwtable

llvm/test/CodeGen/SBF/many_args_value_size.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
; RUN: llc -march=sbf -mcpu=v2 < %s | FileCheck %s
2+
; RUN: llc -mtriple=sbpfv2-solana-solana < %s | FileCheck %s
23

34
define i64 @test_func(i64 %a, i64 %b, i64 %c, i64 %d, i64 %e) {
45
start:

llvm/test/CodeGen/SBF/reloc-abs64-sbf.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
; RUN: llc -march=sbf -filetype=obj < %s | llvm-objdump -r - | tee -i /tmp/foo | FileCheck --check-prefix=CHECK-RELOC-BPF %s
22
; RUN: llc -march=sbf -mcpu=v3 -filetype=obj < %s | llvm-objdump -r - | tee -i /tmp/foo | FileCheck --check-prefix=CHECK-RELOC-SBFv3 %s
3+
; RUN: llc -mtriple=sbpfv3-solana-solana -filetype=obj < %s | llvm-objdump -r - | tee -i /tmp/foo | FileCheck --check-prefix=CHECK-RELOC-SBFv3 %s
34

45
@.str = private unnamed_addr constant [25 x i8] c"reloc_64_relative_data.c\00", align 1
56
@FILE = dso_local constant i64 ptrtoint ([25 x i8]* @.str to i64), align 8

llvm/test/MC/SBF/elf-flags.s

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
11
# RUN: llvm-mc -triple=sbf-solana-solana -filetype=obj < %s \
22
# RUN: | llvm-readobj --file-headers - \
33
# RUN: | FileCheck -check-prefix=CHECK-NONE %s
4+
# RUN: llvm-mc -triple=sbpf-solana-solana -filetype=obj < %s \
5+
# RUN: | llvm-readobj --file-headers - \
6+
# RUN: | FileCheck -check-prefix=CHECK-NONE %s
47
# RUN: llvm-mc -triple=sbf-solana-solana -mcpu=v1 -filetype=obj < %s \
58
# RUN: | llvm-readobj --file-headers - \
69
# RUN: | FileCheck -check-prefix=CHECK-SBFV1 %s
7-
# RUN: llvm-mc -triple=sbf-solana-solana -mcpu=v1 -filetype=obj < %s \
10+
# RUN: llvm-mc -triple=sbpfv1-solana-solana -filetype=obj < %s \
811
# RUN: | llvm-readobj --file-headers - \
912
# RUN: | FileCheck -check-prefix=CHECK-SBFV1 %s
13+
# RUN: llvm-mc -triple=sbf-solana-solana -mcpu=v2 -filetype=obj < %s \
14+
# RUN: | llvm-readobj --file-headers - \
15+
# RUN: | FileCheck -check-prefix=CHECK-SBFV2 %s
16+
# RUN: llvm-mc -triple=sbpfv2-solana-solana -filetype=obj < %s \
17+
# RUN: | llvm-readobj --file-headers - \
18+
# RUN: | FileCheck -check-prefix=CHECK-SBFV2 %s
1019
# RUN: llvm-mc -triple=sbf-solana-solana -mcpu=v3 -filetype=obj < %s \
1120
# RUN: | llvm-readobj --file-headers - \
1221
# RUN: | FileCheck -check-prefix=CHECK-SBFV3 %s
22+
# RUN: llvm-mc -triple=sbpfv3-solana-solana -filetype=obj < %s \
23+
# RUN: | llvm-readobj --file-headers - \
24+
# RUN: | FileCheck -check-prefix=CHECK-SBFV3 %s
1325

1426

1527
# CHECK-NONE: Flags [ (0x0)

0 commit comments

Comments
 (0)