Skip to content

[SOL] Turn on solana feature for SBF target by default #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions clang/lib/Driver/ToolChains/Arch/BPF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ 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 All @@ -51,6 +46,14 @@ void bpf::getBPFTargetFeatures(const Driver &D, const ArgList &Args,
std::vector<StringRef> &Features) {
Arg *A;
bool success = true;

if ((A = Args.getLastArg(options::OPT_target))) {
StringRef Target = A->getValue();
if (Target == "sbf") {
Features.push_back("+solana");
}
}

if ((A = Args.getLastArg(options::OPT_march_EQ)))
success = getBPFArchFeaturesFromMarch(D, A->getValue(), Args, Features);
if (!success)
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Target/BPF/BPFRegisterInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ static void WarnSize(int Offset, MachineFunction &MF, DebugLoc& DL)
dbgs() << " ";
DL.print(dbgs());
}
dbgs() << " Function " << MF.getFunction().getName() << " Stack offset of " << Offset
<< " exceeded max offset of " << MaxOffset << " by "
<< -(Offset - MaxOffset) << " bytes, please minimize large stack variables\n";
dbgs() << " Function " << MF.getFunction().getName() << " Stack offset of " << -Offset
<< " exceeded max offset of " << -MaxOffset << " by "
<< MaxOffset - Offset << " bytes, please minimize large stack variables\n";
} else {
DiagnosticInfoUnsupported DiagStackSize(MF.getFunction(),
"BPF stack limit of 512 bytes is exceeded. "
Expand Down
11 changes: 6 additions & 5 deletions llvm/lib/Target/BPF/BPFSubtarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@ using namespace llvm;

void BPFSubtarget::anchor() {}

BPFSubtarget &BPFSubtarget::initializeSubtargetDependencies(StringRef CPU,
BPFSubtarget &BPFSubtarget::initializeSubtargetDependencies(const Triple &TT,
StringRef CPU,
StringRef FS) {
initializeEnvironment();
initializeEnvironment(TT);
initSubtargetFeatures(CPU, FS);
ParseSubtargetFeatures(CPU, /*TuneCPU*/ CPU, FS);
return *this;
}

void BPFSubtarget::initializeEnvironment() {
IsSolana = false;
void BPFSubtarget::initializeEnvironment(const Triple &TT) {
IsSolana = TT.getArch() == Triple::sbf;
HasJmpExt = false;
HasJmp32 = false;
HasAlu32 = false;
Expand All @@ -61,7 +62,7 @@ void BPFSubtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) {
BPFSubtarget::BPFSubtarget(const Triple &TT, const std::string &CPU,
const std::string &FS, const TargetMachine &TM)
: BPFGenSubtargetInfo(TT, CPU, /*TuneCPU*/ CPU, FS), InstrInfo(),
FrameLowering(initializeSubtargetDependencies(CPU, FS)),
FrameLowering(initializeSubtargetDependencies(TT, CPU, FS)),
TLInfo(TM, *this) {
if (TT.getArch() == Triple::sbf) {
IsSolana = true;
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/BPF/BPFSubtarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class BPFSubtarget : public BPFGenSubtargetInfo {
BPFSelectionDAGInfo TSInfo;

private:
void initializeEnvironment();
void initializeEnvironment(const Triple &TT);
void initSubtargetFeatures(StringRef CPU, StringRef FS);
bool probeJmpExt();

Expand Down Expand Up @@ -66,7 +66,7 @@ class BPFSubtarget : public BPFGenSubtargetInfo {
BPFSubtarget(const Triple &TT, const std::string &CPU, const std::string &FS,
const TargetMachine &TM);

BPFSubtarget &initializeSubtargetDependencies(StringRef CPU, StringRef FS);
BPFSubtarget &initializeSubtargetDependencies(const Triple &TT, StringRef CPU, StringRef FS);

// ParseSubtargetFeatures - Parses features string setting specified
// subtarget options. Definition of function is auto generated by tblgen.
Expand Down
9 changes: 5 additions & 4 deletions llvm/lib/Target/BPF/BPFTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeBPFTarget() {

// DataLayout: little or big endian
static std::string computeDataLayout(const Triple &TT, StringRef FS) {
bool isSolana = TT.getArch() == Triple::sbf || 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"
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"
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 All @@ -83,7 +83,8 @@ BPFTargetMachine::BPFTargetMachine(const Target &T, const Triple &TT,
BPFMCAsmInfo *MAI =
static_cast<BPFMCAsmInfo *>(const_cast<MCAsmInfo *>(AsmInfo.get()));
MAI->setDwarfUsesRelocationsAcrossSections(!Subtarget.getUseDwarfRIS());
MAI->setSupportsDebugInformation(!FS.contains("solana"));
bool IsSolana = TT.getArch() == Triple::sbf || FS.contains("solana");
MAI->setSupportsDebugInformation(!IsSolana);
}

namespace {
Expand Down