Skip to content

Commit

Permalink
[SOL] Adjustments after LLVM 19 upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasSte committed Feb 27, 2025
1 parent ae7341e commit c5bb2cb
Show file tree
Hide file tree
Showing 40 changed files with 459 additions and 237 deletions.
27 changes: 24 additions & 3 deletions clang/lib/Basic/Targets/BPF.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ namespace clang {
namespace targets {

class LLVM_LIBRARY_VISIBILITY BPFTargetInfo : public TargetInfo {
bool HasSolanaFeature = false;
bool HasAlu32 = false;

public:
BPFTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
BPFTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
: TargetInfo(Triple) {
LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
SizeType = UnsignedLong;
Expand All @@ -34,10 +35,28 @@ class LLVM_LIBRARY_VISIBILITY BPFTargetInfo : public TargetInfo {
IntMaxType = SignedLong;
Int64Type = SignedLong;
RegParmMax = 5;
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) {
resetDataLayout("E-m:e-p:64:64-i64:64-i128:128-n32:64-S128");
if (HasSolanaFeature) {
resetDataLayout("E-m:e-p:64:64-i64:64-n32:64-S128");
} else {
resetDataLayout("E-m:e-p:64:64-i64:64-i128:128-n32:64-S128");
}
} else {
resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n32:64-S128");
if (HasSolanaFeature) {
resetDataLayout("e-m:e-p:64:64-i64:64-n32:64-S128");
} else {
resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n32:64-S128");
}
}
MaxAtomicPromoteWidth = 64;
MaxAtomicInlineWidth = 64;
Expand Down Expand Up @@ -117,6 +136,8 @@ class LLVM_LIBRARY_VISIBILITY BPFTargetInfo : public TargetInfo {
std::pair<unsigned, unsigned> hardwareInterferenceSizes() const override {
return std::make_pair(32, 32);
}

bool hasBitIntType() const override { return HasSolanaFeature; }
};
} // namespace targets
} // namespace clang
Expand Down
147 changes: 0 additions & 147 deletions lld/ELF/Arch/BPF.cpp

This file was deleted.

2 changes: 0 additions & 2 deletions lld/ELF/Target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ TargetInfo *elf::getTarget() {
return getARMTargetInfo();
case EM_AVR:
return getAVRTargetInfo();
case EM_BPF:
return getBPFTargetInfo();
case EM_SBF:
return getSBFTargetInfo();
case EM_HEXAGON:
Expand Down
12 changes: 12 additions & 0 deletions lld/tools/lld/lld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "llvm/Support/Path.h"
#include "llvm/Support/PluginLoader.h"
#include "llvm/Support/Process.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/TargetParser/Host.h"
#include "llvm/TargetParser/Triple.h"
#include <cstdlib>
Expand Down Expand Up @@ -72,6 +73,17 @@ LLD_HAS_DRIVER(mingw)
LLD_HAS_DRIVER(macho)
LLD_HAS_DRIVER(wasm)

// This function is called on startup. We need this for LTO since
// LTO calls LLVM functions to compile bitcode files to native code.
// Technically this can be delayed until we read bitcode files, but
// we don't bother to do lazily because the initialization is fast.
static void initLLVM() {
InitializeAllTargets();
InitializeAllTargetMCs();
InitializeAllAsmPrinters();
InitializeAllAsmParsers();
}

int lld_main(int argc, char **argv, const llvm::ToolContext &) {
initLLVM();
sys::Process::UseANSIEscapeCodes(true);
Expand Down
3 changes: 3 additions & 0 deletions llvm/include/llvm/TargetParser/Triple.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class Triple {
wasm64, // WebAssembly with 64-bit pointers
renderscript32, // 32-bit RenderScript
renderscript64, // 64-bit RenderScript
sbf,
ve, // NEC SX-Aurora Vector Engine
LastArchType = ve
};
Expand Down Expand Up @@ -199,6 +200,7 @@ class Triple {
Mesa,
SUSE,
Solana,
OpenEmbedded,
LastVendorType = OpenEmbedded
};
enum OSType {
Expand Down Expand Up @@ -243,6 +245,7 @@ class Triple {
ShaderModel, // DirectX ShaderModel
LiteOS,
Serenity,
SolanaOS,
Vulkan, // Vulkan SPIR-V
LastOSType = Vulkan
};
Expand Down
7 changes: 0 additions & 7 deletions llvm/lib/Analysis/TargetLibraryInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -888,13 +888,6 @@ static void initializeLibCalls(TargetLibraryInfoImpl &TLI, const Triple &T,
if (T.isOSAIX())
TLI.setUnavailable(LibFunc_memrchr);


if (T.isBPF() || T.isSBF()) {
TLI.setUnavailable(LibFunc_rust_alloc);
TLI.setUnavailable(LibFunc_rust_dealloc);
TLI.setUnavailable(LibFunc_rust_realloc);
}

TLI.addVectorizableFunctionsFromVecLib(ClVectorLibrary, T);
}

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/BPF/BPFISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ BPFTargetLowering::BPFTargetLowering(const TargetMachine &TM,

setOperationAction(ISD::SDIVREM, VT, Expand);
setOperationAction(ISD::UDIVREM, VT, Expand);
if (!STI.hasSdivSmod() && !Subtarget->isSolana()) {
if (!STI.hasSdivSmod()) {
setOperationAction(ISD::SDIV, VT, Custom);
setOperationAction(ISD::SREM, VT, Custom);
}
Expand Down
2 changes: 0 additions & 2 deletions llvm/lib/Target/BPF/BPFRegisterInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ static cl::opt<int>
cl::desc("Specify the BPF stack size limit"),
cl::init(512));

unsigned BPFRegisterInfo::FrameLength = 512;

BPFRegisterInfo::BPFRegisterInfo()
: BPFGenRegisterInfo(BPF::R0) {}

Expand Down
8 changes: 1 addition & 7 deletions llvm/lib/Target/BPF/BPFSubtarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ BPFSubtarget &BPFSubtarget::initializeSubtargetDependencies(StringRef CPU,
return *this;
}

void BPFSubtarget::initializeEnvironment(const Triple &TT) {
// TODO: jle: remove, sbf is now provided by the SBF backend.
IsSolana = false;
void BPFSubtarget::initializeEnvironment() {
HasJmpExt = false;
HasJmp32 = false;
HasAlu32 = false;
Expand Down Expand Up @@ -101,10 +99,6 @@ BPFSubtarget::BPFSubtarget(const Triple &TT, const std::string &CPU,
FrameLowering(initializeSubtargetDependencies(CPU, FS)),
TLInfo(TM, *this) {
IsLittleEndian = TT.isLittleEndian();
<<<<<<< HEAD
=======
TSInfo.setSolanaFlag(false);
>>>>>>> 3d16ab60503b ([SOL] Initial squash commit for new SBF LLVM back-end and related.)

CallLoweringInfo.reset(new BPFCallLowering(*getTargetLowering()));
Legalizer.reset(new BPFLegalizerInfo(*this));
Expand Down
15 changes: 5 additions & 10 deletions llvm/lib/Target/BPF/BPFTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,11 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeBPFTarget() {
}

// DataLayout: little or big endian
static std::string computeDataLayout(const Triple &TT, StringRef FS) {
// TODO: jle: remove 'solana', sbf is now provided by the SBF backend.
bool IsSolana = 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";
} else {
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";
}
static std::string computeDataLayout(const Triple &TT) {
if (TT.getArch() == Triple::bpfeb)
return "E-m:e-p:64:64-i64:64-i128:128-n32:64-S128";
else
return "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128";
}

static Reloc::Model getEffectiveRelocModel(std::optional<Reloc::Model> RM) {
Expand Down
1 change: 0 additions & 1 deletion llvm/lib/Target/BPF/MCTargetDesc/BPFAsmBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "llvm/MC/MCFixup.h"
#include "llvm/MC/MCFixupKindInfo.h"
#include "llvm/MC/MCObjectWriter.h"
#include "llvm/MC/MCSubtargetInfo.h"
#include "llvm/Support/EndianStream.h"
#include <cassert>
#include <cstdint>
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/Target/SBF/AsmParser/SBFAsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ struct SBFOperand : public MCParsedAsmOperand {
/// getEndLoc - Gets location of the last token of this operand
SMLoc getEndLoc() const override { return EndLoc; }

unsigned getReg() const override {
MCRegister getReg() const override {
assert(Kind == Register && "Invalid type access!");
return Reg.RegNum;
return MCRegister(Reg.RegNum);
}

const MCExpr *getImm() const {
Expand All @@ -167,7 +167,7 @@ struct SBFOperand : public MCParsedAsmOperand {
break;
case Register:
OS << "<register ";
OS << RegName(getReg()) << ">";
OS << RegName(getReg().id()) << ">";
break;
case Token:
OS << "'" << getToken() << "'";
Expand All @@ -187,7 +187,7 @@ struct SBFOperand : public MCParsedAsmOperand {
// Used by the TableGen Code
void addRegOperands(MCInst &Inst, unsigned N) const {
assert(N == 1 && "Invalid number of operands!");
Inst.addOperand(MCOperand::createReg(getReg()));
Inst.addOperand(MCOperand::createReg(getReg().id()));
}

void addImmOperands(MCInst &Inst, unsigned N) const {
Expand Down
5 changes: 3 additions & 2 deletions llvm/lib/Target/SBF/BTFDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "llvm/BinaryFormat/ELF.h"
#include "llvm/CodeGen/AsmPrinter.h"
#include "llvm/CodeGen/MachineModuleInfo.h"
#include "llvm/IR/Module.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCObjectFileInfo.h"
#include "llvm/MC/MCSectionELF.h"
Expand Down Expand Up @@ -589,7 +590,7 @@ void BTFDebug::processDeclAnnotations(DINodeArray Annotations,
for (const Metadata *Annotation : Annotations->operands()) {
const MDNode *MD = cast<MDNode>(Annotation);
const MDString *Name = cast<MDString>(MD->getOperand(0));
if (!Name->getString().equals("btf_decl_tag"))
if (Name->getString() != "btf_decl_tag")
continue;

const MDString *Value = cast<MDString>(MD->getOperand(1));
Expand Down Expand Up @@ -628,7 +629,7 @@ int BTFDebug::genBTFTypeTags(const DIDerivedType *DTy, int BaseTypeId) {
for (const Metadata *Annotations : Annots->operands()) {
const MDNode *MD = cast<MDNode>(Annotations);
const MDString *Name = cast<MDString>(MD->getOperand(0));
if (!Name->getString().equals("btf_type_tag"))
if (Name->getString() != "btf_type_tag")
continue;
MDStrs.push_back(cast<MDString>(MD->getOperand(1)));
}
Expand Down
Loading

0 comments on commit c5bb2cb

Please sign in to comment.