Skip to content

Commit

Permalink
[SOL] Add sbf-solana-solana target triplet
Browse files Browse the repository at this point in the history
  • Loading branch information
dmakarov committed Dec 1, 2021
1 parent d9d227e commit be5571c
Show file tree
Hide file tree
Showing 20 changed files with 69 additions and 11 deletions.
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/Attr.td
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ def TargetARM : TargetArch<["arm", "thumb", "armeb", "thumbeb"]>;
def TargetAArch64 : TargetArch<["aarch64"]>;
def TargetAnyArm : TargetArch<!listconcat(TargetARM.Arches, TargetAArch64.Arches)>;
def TargetAVR : TargetArch<["avr"]>;
def TargetBPF : TargetArch<["bpfel", "bpfeb"]>;
def TargetBPF : TargetArch<["bpfel", "bpfeb", "sbf"]>;
def TargetMips32 : TargetArch<["mips", "mipsel"]>;
def TargetAnyMips : TargetArch<["mips", "mipsel", "mips64", "mips64el"]>;
def TargetMSP430 : TargetArch<["msp430"]>;
Expand Down
1 change: 1 addition & 0 deletions clang/lib/Basic/Targets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ TargetInfo *AllocateTarget(const llvm::Triple &Triple,
return new AVRTargetInfo(Triple, Opts);
case llvm::Triple::bpfeb:
case llvm::Triple::bpfel:
case llvm::Triple::sbf:
return new BPFTargetInfo(Triple, Opts);

case llvm::Triple::msp430:
Expand Down
12 changes: 8 additions & 4 deletions clang/lib/Basic/Targets/BPF.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,14 @@ class LLVM_LIBRARY_VISIBILITY BPFTargetInfo : public TargetInfo {
IntMaxType = SignedLong;
Int64Type = SignedLong;
RegParmMax = 5;
for (auto& it : Opts.FeaturesAsWritten) {
if (it == "+solana") {
HasSolanaFeature = true;
break;
if (Triple.getArch() == llvm::Triple::sbf) {
HasSolanaFeature = true;
} else {
for (auto& it : Opts.FeaturesAsWritten) {
if (it == "+solana") {
HasSolanaFeature = true;
break;
}
}
}
if (Triple.getArch() == llvm::Triple::bpfeb) {
Expand Down
1 change: 1 addition & 0 deletions clang/lib/CodeGen/CGBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5308,6 +5308,7 @@ static Value *EmitTargetArchBuiltinExpr(CodeGenFunction *CGF,
return CGF->EmitAArch64BuiltinExpr(BuiltinID, E, Arch);
case llvm::Triple::bpfeb:
case llvm::Triple::bpfel:
case llvm::Triple::sbf:
return CGF->EmitBPFBuiltinExpr(BuiltinID, E);
case llvm::Triple::x86:
case llvm::Triple::x86_64:
Expand Down
5 changes: 5 additions & 0 deletions clang/lib/Driver/ToolChains/Arch/BPF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ getBPFArchFeaturesFromMarch(const Driver &D, StringRef March,
std::string MarchLowerCase = March.lower();
std::pair<StringRef, StringRef> Split = StringRef(MarchLowerCase).split("+");

if (Split.first == "sbf") {
Features.push_back("+solana");
return true;
}

return (Split.first == "bpfel" || Split.first == "bpfeb") &&
(Split.second.size() == 0 || DecodeBPFFeatures(D, Split.second, Features));
}
Expand Down
1 change: 1 addition & 0 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ static void getTargetFeatures(const Driver &D, const llvm::Triple &Triple,
break;
case llvm::Triple::bpfeb:
case llvm::Triple::bpfel:
case llvm::Triple::sbf:
bpf::getBPFTargetFeatures(D, Args, Features);
break;
case llvm::Triple::x86:
Expand Down
1 change: 1 addition & 0 deletions clang/lib/Driver/ToolChains/CommonArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ std::string tools::getCPUName(const ArgList &Args, const llvm::Triple &T,

case llvm::Triple::bpfel:
case llvm::Triple::bpfeb:
case llvm::Triple::sbf:
case llvm::Triple::sparc:
case llvm::Triple::sparcel:
case llvm::Triple::sparcv9:
Expand Down
1 change: 1 addition & 0 deletions clang/lib/Driver/ToolChains/Gnu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2744,6 +2744,7 @@ bool Generic_GCC::IsIntegratedAssemblerDefault() const {
case llvm::Triple::avr:
case llvm::Triple::bpfel:
case llvm::Triple::bpfeb:
case llvm::Triple::sbf:
case llvm::Triple::thumb:
case llvm::Triple::thumbeb:
case llvm::Triple::ppc:
Expand Down
1 change: 1 addition & 0 deletions clang/lib/Sema/SemaChecking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1410,6 +1410,7 @@ bool Sema::CheckTSBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID,
return CheckAArch64BuiltinFunctionCall(TI, BuiltinID, TheCall);
case llvm::Triple::bpfeb:
case llvm::Triple::bpfel:
case llvm::Triple::sbf:
return CheckBPFBuiltinFunctionCall(BuiltinID, TheCall);
case llvm::Triple::hexagon:
return CheckHexagonBuiltinFunctionCall(BuiltinID, TheCall);
Expand Down
4 changes: 4 additions & 0 deletions clang/test/CodeGen/target-data.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@
// RUN: FileCheck %s -check-prefix=BPFEB
// BPFEB: target datalayout = "E-m:e-p:64:64-i64:64-i128:128-n32:64-S128"

// RUN: %clang_cc1 -triple sbf -o - -emit-llvm %s | \
// RUN: FileCheck %s -check-prefix=SBF
// SBF: target datalayout = "e-m:e-p:64:64-i64:64-n32:64-S128"

// RUN: %clang_cc1 -triple bpfel -target-feature +solana -o - -emit-llvm %s | \
// RUN: FileCheck %s -check-prefix=BPFELSOL
// BPFELSOL: target datalayout = "e-m:e-p:64:64-i64:64-n32:64-S128"
Expand Down
3 changes: 3 additions & 0 deletions llvm/include/llvm/ADT/Triple.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class Triple {
avr, // AVR: Atmel AVR microcontroller
bpfel, // eBPF or extended BPF or 64-bit BPF (little endian)
bpfeb, // eBPF or extended BPF or 64-bit BPF (big endian)
sbf, // Solana dialect of eBPF (little endian)
csky, // CSKY: csky
hexagon, // Hexagon: hexagon
m68k, // M68k: Motorola 680x0 family
Expand Down Expand Up @@ -159,6 +160,7 @@ class Triple {
Mesa,
SUSE,
OpenEmbedded,
Solana,
LastVendorType = OpenEmbedded
};
enum OSType {
Expand Down Expand Up @@ -199,6 +201,7 @@ class Triple {
Hurd, // GNU/Hurd
WASI, // Experimental WebAssembly OS
Emscripten,
SolanaOS,
LastOSType = Emscripten
};
enum EnvironmentType {
Expand Down
17 changes: 16 additions & 1 deletion llvm/lib/Support/Triple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ StringRef Triple::getArchTypeName(ArchType Kind) {
case renderscript64: return "renderscript64";
case riscv32: return "riscv32";
case riscv64: return "riscv64";
case sbf: return "sbf";
case shave: return "shave";
case sparc: return "sparc";
case sparcel: return "sparcel";
Expand Down Expand Up @@ -158,6 +159,8 @@ StringRef Triple::getArchTypePrefix(ArchType Kind) {

case ve: return "ve";
case csky: return "csky";

case sbf: return "sbf";
}
}

Expand All @@ -179,6 +182,7 @@ StringRef Triple::getVendorTypeName(VendorType Kind) {
case PC: return "pc";
case SCEI: return "scei";
case SUSE: return "suse";
case Solana: return "solana";
}

llvm_unreachable("Invalid VendorType!");
Expand Down Expand Up @@ -223,6 +227,7 @@ StringRef Triple::getOSTypeName(OSType Kind) {
case WatchOS: return "watchos";
case Win32: return "windows";
case ZOS: return "zos";
case SolanaOS: return "solana";
}

llvm_unreachable("Invalid OSType");
Expand Down Expand Up @@ -267,6 +272,8 @@ static Triple::ArchType parseBPFArch(StringRef ArchName) {
return Triple::bpfeb;
} else if (ArchName.equals("bpf_le") || ArchName.equals("bpfel")) {
return Triple::bpfel;
} else if (ArchName.equals("sbf")) {
return Triple::sbf;
} else {
return Triple::UnknownArch;
}
Expand Down Expand Up @@ -302,6 +309,7 @@ Triple::ArchType Triple::getArchTypeForLLVMName(StringRef Name) {
.Case("riscv32", riscv32)
.Case("riscv64", riscv64)
.Case("hexagon", hexagon)
.Case("sbf", BPFArch)
.Case("sparc", sparc)
.Case("sparcel", sparcel)
.Case("sparcv9", sparcv9)
Expand Down Expand Up @@ -473,7 +481,7 @@ static Triple::ArchType parseArch(StringRef ArchName) {
if (ArchName.startswith("arm") || ArchName.startswith("thumb") ||
ArchName.startswith("aarch64"))
return parseARMArch(ArchName);
if (ArchName.startswith("bpf"))
if (ArchName.startswith("bpf") || ArchName.startswith("sbf"))
return parseBPFArch(ArchName);
}

Expand All @@ -497,6 +505,7 @@ static Triple::VendorType parseVendor(StringRef VendorName) {
.Case("mesa", Triple::Mesa)
.Case("suse", Triple::SUSE)
.Case("oe", Triple::OpenEmbedded)
.Case("solana", Triple::Solana)
.Default(Triple::UnknownVendor);
}

Expand Down Expand Up @@ -538,6 +547,7 @@ static Triple::OSType parseOS(StringRef OSName) {
.StartsWith("hurd", Triple::Hurd)
.StartsWith("wasi", Triple::WASI)
.StartsWith("emscripten", Triple::Emscripten)
.StartsWith("solana", Triple::SolanaOS)
.Default(Triple::UnknownOS);
}

Expand Down Expand Up @@ -726,6 +736,7 @@ static Triple::ObjectFormatType getDefaultFormat(const Triple &T) {
case Triple::renderscript64:
case Triple::riscv32:
case Triple::riscv64:
case Triple::sbf:
case Triple::shave:
case Triple::sparc:
case Triple::sparcel:
Expand Down Expand Up @@ -1322,6 +1333,7 @@ static unsigned getArchPointerBitWidth(llvm::Triple::ArchType Arch) {
case llvm::Triple::ppc64le:
case llvm::Triple::renderscript64:
case llvm::Triple::riscv64:
case llvm::Triple::sbf:
case llvm::Triple::sparcv9:
case llvm::Triple::spir64:
case llvm::Triple::systemz:
Expand Down Expand Up @@ -1354,6 +1366,7 @@ Triple Triple::get32BitArchVariant() const {
case Triple::bpfeb:
case Triple::bpfel:
case Triple::msp430:
case Triple::sbf:
case Triple::systemz:
case Triple::ve:
T.setArch(UnknownArch);
Expand Down Expand Up @@ -1449,6 +1462,7 @@ Triple Triple::get64BitArchVariant() const {
case Triple::ppc64le:
case Triple::renderscript64:
case Triple::riscv64:
case Triple::sbf:
case Triple::sparcv9:
case Triple::spir64:
case Triple::systemz:
Expand Down Expand Up @@ -1600,6 +1614,7 @@ bool Triple::isLittleEndian() const {
case Triple::renderscript64:
case Triple::riscv32:
case Triple::riscv64:
case Triple::sbf:
case Triple::shave:
case Triple::sparcel:
case Triple::spir64:
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ uint32_t BPFAbstractMemberAccess::GetFieldInfo(uint32_t InfoKind,
report_fatal_error("too big field size for llvm.bpf.preserve.field.info");

unsigned OffsetInBits = MemberTy->getOffsetInBits();
if (Triple.getArch() == Triple::bpfel)
if (Triple.getArch() == Triple::bpfel || Triple.getArch() == Triple::sbf)
return SBitOffset + 64 - OffsetInBits - SizeInBits;
else
return OffsetInBits + 64 - NextSBitOffset;
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Target/BPF/BPFAsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,5 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeBPFAsmPrinter() {
RegisterAsmPrinter<BPFAsmPrinter> X(getTheBPFleTarget());
RegisterAsmPrinter<BPFAsmPrinter> Y(getTheBPFbeTarget());
RegisterAsmPrinter<BPFAsmPrinter> Z(getTheBPFTarget());
RegisterAsmPrinter<BPFAsmPrinter> XX(getTheSBFTarget());
}
3 changes: 3 additions & 0 deletions llvm/lib/Target/BPF/BPFSubtarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,8 @@ BPFSubtarget::BPFSubtarget(const Triple &TT, const std::string &CPU,
: BPFGenSubtargetInfo(TT, CPU, /*TuneCPU*/ CPU, FS), InstrInfo(),
FrameLowering(initializeSubtargetDependencies(CPU, FS)),
TLInfo(TM, *this) {
if (TT.getArch() == Triple::sbf) {
IsSolana = true;
}
TSInfo.setSolanaFlag(IsSolana);
}
4 changes: 3 additions & 1 deletion llvm/lib/Target/BPF/BPFTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeBPFTarget() {
RegisterTargetMachine<BPFTargetMachine> Y(getTheBPFbeTarget());
RegisterTargetMachine<BPFTargetMachine> Z(getTheBPFTarget());

RegisterTargetMachine<BPFTargetMachine> XX(getTheSBFTarget());

PassRegistry &PR = *PassRegistry::getPassRegistry();
initializeBPFAbstractMemberAccessLegacyPassPass(PR);
initializeBPFPreserveDITypePass(PR);
Expand All @@ -51,7 +53,7 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeBPFTarget() {

// DataLayout: little or big endian
static std::string computeDataLayout(const Triple &TT, StringRef FS) {
bool isSolana = FS.contains("solana");
bool isSolana = TT.getArch() == Triple::sbf || FS.contains("solana");
if (TT.getArch() == Triple::bpfeb) {
return isSolana ? "E-m:e-p:64:64-i64:64-n32:64-S128"
: "E-m:e-p:64:64-i64:64-i128:128-n32:64-S128";
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Target/BPF/Disassembler/BPFDisassembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeBPFDisassembler() {
createBPFDisassembler);
TargetRegistry::RegisterMCDisassembler(getTheBPFbeTarget(),
createBPFDisassembler);
TargetRegistry::RegisterMCDisassembler(getTheSBFTarget(),
createBPFDisassembler);
}

static const unsigned GPRDecoderTable[] = {
Expand Down
6 changes: 5 additions & 1 deletion llvm/lib/Target/BPF/MCTargetDesc/BPFMCTargetDesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ static MCInstrAnalysis *createBPFInstrAnalysis(const MCInstrInfo *Info) {

extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeBPFTargetMC() {
for (Target *T :
{&getTheBPFleTarget(), &getTheBPFbeTarget(), &getTheBPFTarget()}) {
{&getTheBPFleTarget(), &getTheBPFbeTarget(), &getTheBPFTarget(), &getTheSBFTarget()}) {
// Register the MC asm info.
RegisterMCAsmInfo<BPFMCAsmInfo> X(*T);

Expand Down Expand Up @@ -128,12 +128,16 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeBPFTargetMC() {
createBPFMCCodeEmitter);
TargetRegistry::RegisterMCCodeEmitter(getTheBPFbeTarget(),
createBPFbeMCCodeEmitter);
TargetRegistry::RegisterMCCodeEmitter(getTheSBFTarget(),
createBPFMCCodeEmitter);

// Register the ASM Backend
TargetRegistry::RegisterMCAsmBackend(getTheBPFleTarget(),
createBPFAsmBackend);
TargetRegistry::RegisterMCAsmBackend(getTheBPFbeTarget(),
createBPFbeAsmBackend);
TargetRegistry::RegisterMCAsmBackend(getTheSBFTarget(),
createBPFAsmBackend);

if (sys::IsLittleEndianHost) {
TargetRegistry::RegisterMCCodeEmitter(getTheBPFTarget(),
Expand Down
12 changes: 10 additions & 2 deletions llvm/lib/Target/BPF/TargetInfo/BPFTargetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,20 @@ Target &llvm::getTheBPFTarget() {
return TheBPFTarget;
}

Target &llvm::getTheSBFTarget() {
static Target TheSBFTarget;
return TheSBFTarget;
}

extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeBPFTargetInfo() {
TargetRegistry::RegisterTarget(getTheBPFTarget(), "bpf", "BPF (host endian)",
"BPF", [](Triple::ArchType) { return false; },
true);
RegisterTarget<Triple::bpfel, /*HasJIT=*/true> X(
getTheBPFleTarget(), "bpfel", "BPF (little endian)", "BPF");
RegisterTarget<Triple::bpfeb, /*HasJIT=*/true> Y(getTheBPFbeTarget(), "bpfeb",
"BPF (big endian)", "BPF");
RegisterTarget<Triple::bpfeb, /*HasJIT=*/true> Y(
getTheBPFbeTarget(), "bpfeb", "BPF (big endian)", "BPF");

RegisterTarget<Triple::sbf, /*HasJIT=*/true> XX(
getTheSBFTarget(), "sbf", "SBF (little endian)", "SBF");
}
1 change: 1 addition & 0 deletions llvm/lib/Target/BPF/TargetInfo/BPFTargetInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Target &getTheBPFleTarget();
Target &getTheBPFbeTarget();
Target &getTheBPFTarget();

Target &getTheSBFTarget();
} // namespace llvm

#endif // LLVM_LIB_TARGET_BPF_TARGETINFO_BPFTARGETINFO_H

0 comments on commit be5571c

Please sign in to comment.