diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 12d09181a2ea87..474a166b8f9e5a 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -364,7 +364,7 @@ def TargetARM : TargetArch<["arm", "thumb", "armeb", "thumbeb"]>; def TargetAArch64 : TargetArch<["aarch64"]>; def TargetAnyArm : TargetArch; 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"]>; diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp index ba91d0439968c9..33ea5d2bd41091 100644 --- a/clang/lib/Basic/Targets.cpp +++ b/clang/lib/Basic/Targets.cpp @@ -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: diff --git a/clang/lib/Basic/Targets/BPF.h b/clang/lib/Basic/Targets/BPF.h index 8d1d88d7b95b50..22650b4d8032c6 100644 --- a/clang/lib/Basic/Targets/BPF.h +++ b/clang/lib/Basic/Targets/BPF.h @@ -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) { diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index d9b2a5fe16bec3..cb091fb46cfa7c 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -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: diff --git a/clang/lib/Driver/ToolChains/Arch/BPF.cpp b/clang/lib/Driver/ToolChains/Arch/BPF.cpp index 05d1c8e7634481..d7b9eef9c9a9a9 100644 --- a/clang/lib/Driver/ToolChains/Arch/BPF.cpp +++ b/clang/lib/Driver/ToolChains/Arch/BPF.cpp @@ -38,6 +38,11 @@ getBPFArchFeaturesFromMarch(const Driver &D, StringRef March, std::string MarchLowerCase = March.lower(); std::pair 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)); } diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index d4659ccf015708..2a4c4a0b372f99 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -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: diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index 83cab3ac00cb6c..b74cede9535b8d 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -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: diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp index da39f29e46190e..3c67e3bd06f9a4 100644 --- a/clang/lib/Driver/ToolChains/Gnu.cpp +++ b/clang/lib/Driver/ToolChains/Gnu.cpp @@ -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: diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index de75c10417e715..068619a2a9eeba 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -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); diff --git a/clang/test/CodeGen/target-data.c b/clang/test/CodeGen/target-data.c index 06e73a4ca70e30..dbbe0512a183c7 100644 --- a/clang/test/CodeGen/target-data.c +++ b/clang/test/CodeGen/target-data.c @@ -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" diff --git a/llvm/include/llvm/ADT/Triple.h b/llvm/include/llvm/ADT/Triple.h index dc930522977c75..754269d226a190 100644 --- a/llvm/include/llvm/ADT/Triple.h +++ b/llvm/include/llvm/ADT/Triple.h @@ -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 @@ -159,6 +160,7 @@ class Triple { Mesa, SUSE, OpenEmbedded, + Solana, LastVendorType = OpenEmbedded }; enum OSType { @@ -199,6 +201,7 @@ class Triple { Hurd, // GNU/Hurd WASI, // Experimental WebAssembly OS Emscripten, + SolanaOS, LastOSType = Emscripten }; enum EnvironmentType { diff --git a/llvm/lib/Support/Triple.cpp b/llvm/lib/Support/Triple.cpp index 88311546354b6d..e889f628d2082d 100644 --- a/llvm/lib/Support/Triple.cpp +++ b/llvm/lib/Support/Triple.cpp @@ -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"; @@ -158,6 +159,8 @@ StringRef Triple::getArchTypePrefix(ArchType Kind) { case ve: return "ve"; case csky: return "csky"; + + case sbf: return "sbf"; } } @@ -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!"); @@ -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"); @@ -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; } @@ -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) @@ -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); } @@ -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); } @@ -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); } @@ -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: @@ -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: @@ -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); @@ -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: @@ -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: diff --git a/llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp b/llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp index ab7e848409d9dc..ef138a72b07faa 100644 --- a/llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp +++ b/llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp @@ -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; diff --git a/llvm/lib/Target/BPF/BPFAsmPrinter.cpp b/llvm/lib/Target/BPF/BPFAsmPrinter.cpp index 37950e105bdc15..3a639d52e5f737 100644 --- a/llvm/lib/Target/BPF/BPFAsmPrinter.cpp +++ b/llvm/lib/Target/BPF/BPFAsmPrinter.cpp @@ -152,4 +152,5 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeBPFAsmPrinter() { RegisterAsmPrinter X(getTheBPFleTarget()); RegisterAsmPrinter Y(getTheBPFbeTarget()); RegisterAsmPrinter Z(getTheBPFTarget()); + RegisterAsmPrinter XX(getTheSBFTarget()); } diff --git a/llvm/lib/Target/BPF/BPFSubtarget.cpp b/llvm/lib/Target/BPF/BPFSubtarget.cpp index df513f5a85f508..e24946ae1a15a7 100644 --- a/llvm/lib/Target/BPF/BPFSubtarget.cpp +++ b/llvm/lib/Target/BPF/BPFSubtarget.cpp @@ -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); } diff --git a/llvm/lib/Target/BPF/BPFTargetMachine.cpp b/llvm/lib/Target/BPF/BPFTargetMachine.cpp index f64a42a1731b99..3ece4d5133b19d 100644 --- a/llvm/lib/Target/BPF/BPFTargetMachine.cpp +++ b/llvm/lib/Target/BPF/BPFTargetMachine.cpp @@ -40,6 +40,8 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeBPFTarget() { RegisterTargetMachine Y(getTheBPFbeTarget()); RegisterTargetMachine Z(getTheBPFTarget()); + RegisterTargetMachine XX(getTheSBFTarget()); + PassRegistry &PR = *PassRegistry::getPassRegistry(); initializeBPFAbstractMemberAccessLegacyPassPass(PR); initializeBPFPreserveDITypePass(PR); @@ -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"; diff --git a/llvm/lib/Target/BPF/Disassembler/BPFDisassembler.cpp b/llvm/lib/Target/BPF/Disassembler/BPFDisassembler.cpp index 3a1492743bf400..4bc4b03e0bd83f 100644 --- a/llvm/lib/Target/BPF/Disassembler/BPFDisassembler.cpp +++ b/llvm/lib/Target/BPF/Disassembler/BPFDisassembler.cpp @@ -91,6 +91,8 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeBPFDisassembler() { createBPFDisassembler); TargetRegistry::RegisterMCDisassembler(getTheBPFbeTarget(), createBPFDisassembler); + TargetRegistry::RegisterMCDisassembler(getTheSBFTarget(), + createBPFDisassembler); } static const unsigned GPRDecoderTable[] = { diff --git a/llvm/lib/Target/BPF/MCTargetDesc/BPFMCTargetDesc.cpp b/llvm/lib/Target/BPF/MCTargetDesc/BPFMCTargetDesc.cpp index 8fb7d7e89f09b0..975404a00ee7cc 100644 --- a/llvm/lib/Target/BPF/MCTargetDesc/BPFMCTargetDesc.cpp +++ b/llvm/lib/Target/BPF/MCTargetDesc/BPFMCTargetDesc.cpp @@ -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 X(*T); @@ -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(), diff --git a/llvm/lib/Target/BPF/TargetInfo/BPFTargetInfo.cpp b/llvm/lib/Target/BPF/TargetInfo/BPFTargetInfo.cpp index 49eb9ad62c5627..4f582a3931c23e 100644 --- a/llvm/lib/Target/BPF/TargetInfo/BPFTargetInfo.cpp +++ b/llvm/lib/Target/BPF/TargetInfo/BPFTargetInfo.cpp @@ -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 X( getTheBPFleTarget(), "bpfel", "BPF (little endian)", "BPF"); - RegisterTarget Y(getTheBPFbeTarget(), "bpfeb", - "BPF (big endian)", "BPF"); + RegisterTarget Y( + getTheBPFbeTarget(), "bpfeb", "BPF (big endian)", "BPF"); + + RegisterTarget XX( + getTheSBFTarget(), "sbf", "SBF (little endian)", "SBF"); } diff --git a/llvm/lib/Target/BPF/TargetInfo/BPFTargetInfo.h b/llvm/lib/Target/BPF/TargetInfo/BPFTargetInfo.h index 150526c1a9db6b..c8a256f56e894b 100644 --- a/llvm/lib/Target/BPF/TargetInfo/BPFTargetInfo.h +++ b/llvm/lib/Target/BPF/TargetInfo/BPFTargetInfo.h @@ -17,6 +17,7 @@ Target &getTheBPFleTarget(); Target &getTheBPFbeTarget(); Target &getTheBPFTarget(); +Target &getTheSBFTarget(); } // namespace llvm #endif // LLVM_LIB_TARGET_BPF_TARGETINFO_BPFTARGETINFO_H