Skip to content

Commit 74ef093

Browse files
committed
[SOL] Adjustments after LLVM 20 update
1 parent 45bf9ac commit 74ef093

26 files changed

+95
-122
lines changed

clang/lib/Basic/Targets/BPF.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,6 @@ ArrayRef<Builtin::Info> BPFTargetInfo::getTargetBuiltins() const {
9595

9696
bool BPFTargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
9797
DiagnosticsEngine &Diags) {
98-
// TODO: The SBF back-end now provides the sbf target. Issue deprecation
99-
// warning directing use of '-target sbf' instead. Eventually remove the
100-
// +solana support from the BPF back-end.
101-
if (getTriple().getArch() != llvm::Triple::sbf && HasSolanaFeature)
102-
Diags.Report(diag::warn_drv_no_solana_with_bpf);
103-
10498
for (const auto &Feature : Features) {
10599
if (Feature == "+alu32") {
106100
HasAlu32 = true;

clang/test/Misc/warning-flags.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ CHECK-NEXT: warn_double_const_requires_fp64
4545
CHECK-NEXT: warn_drv_amdgpu_cov6
4646
CHECK-NEXT: warn_drv_assuming_mfloat_abi_is
4747
CHECK-NEXT: warn_drv_clang_unsupported
48-
CHECK-NEXT: warn_drv_no_solana_with_bpf
4948
CHECK-NEXT: warn_drv_pch_not_first_include
5049
CHECK-NEXT: warn_expected_qualified_after_typename
5150
CHECK-NEXT: warn_fe_backend_unsupported

lld/ELF/Arch/SBF.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace elf {
2525
namespace {
2626
class SBF final : public TargetInfo {
2727
public:
28-
SBF();
28+
SBF(Ctx & ctx);
2929
RelExpr getRelExpr(RelType type, const Symbol &s,
3030
const uint8_t *loc) const override;
3131
RelType getDynRel(RelType type) const override;
@@ -54,7 +54,7 @@ RelExpr SBF::getRelExpr(RelType type, const Symbol &s,
5454
case R_SBF_64_64:
5555
return R_ABS;
5656
default:
57-
error(getErrorLocation(loc) + "unrecognized reloc " + toString(type));
57+
Err(ctx) << getErrorLoc(ctx, loc) << "unrecognized reloc " << type.v;
5858
}
5959
return R_NONE;
6060
}
@@ -113,12 +113,12 @@ void SBF::relocate(uint8_t *loc, const Relocation &rel, uint64_t val) const {
113113
break;
114114
}
115115
default:
116-
error(getErrorLocation(loc) + "unrecognized reloc " + toString(rel.type));
116+
Err(ctx) << getErrorLoc(ctx, loc) << "unrecognized reloc " << rel.type.v;
117117
}
118118
}
119119

120-
static uint32_t getEFlags(InputFile *file) {
121-
if (config->ekind == ELF64BEKind)
120+
static uint32_t getEFlags(InputFile *file, Ctx &ctx) {
121+
if (ctx.arg.ekind == ELF64BEKind)
122122
return cast<ObjFile<ELF64BE>>(file)->getObj().getHeader().e_flags;
123123
return cast<ObjFile<ELF64LE>>(file)->getObj().getHeader().e_flags;
124124
}
@@ -129,7 +129,7 @@ uint32_t SBF::calcEFlags() const {
129129
// Ensure that all the object files were compiled with the same flags, as
130130
// different flags indicate different ABIs.
131131
for (InputFile *f : ctx.objectFiles) {
132-
uint32_t flags = getEFlags(f);
132+
uint32_t flags = getEFlags(f, ctx);
133133
if (ret == 0) {
134134
ret = flags;
135135
} else if (ret != flags) {

lld/ELF/InputSection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,7 @@ void InputSection::relocateNonAlloc(Ctx &ctx, uint8_t *buf,
10431043
const uint64_t offset = rel.r_offset;
10441044

10451045
// FIX: Temporary remap BPF_64_64 relocations in debug sections.
1046-
if (config->emachine == EM_SBF && type == R_SBF_64_64 && isDebug)
1046+
if (ctx.arg.emachine == EM_SBF && type == R_SBF_64_64 && isDebug)
10471047
type = R_BPF_64_ABS64;
10481048

10491049
uint8_t *bufLoc = buf + offset;

llvm/lib/Target/SBF/AsmParser/SBFAsmParser.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include "MCTargetDesc/SBFMCTargetDesc.h"
1010
#include "MCTargetDesc/SBFInstPrinter.h"
1111
#include "TargetInfo/SBFTargetInfo.h"
12-
#include "llvm/ADT/STLExtras.h"
1312
#include "llvm/ADT/StringSwitch.h"
1413
#include "llvm/MC/MCContext.h"
1514
#include "llvm/MC/MCExpr.h"
@@ -18,7 +17,6 @@
1817
#include "llvm/MC/MCParser/MCAsmLexer.h"
1918
#include "llvm/MC/MCParser/MCParsedAsmOperand.h"
2019
#include "llvm/MC/MCParser/MCTargetAsmParser.h"
21-
#include "llvm/MC/MCRegisterInfo.h"
2220
#include "llvm/MC/MCStreamer.h"
2321
#include "llvm/MC/MCSubtargetInfo.h"
2422
#include "llvm/MC/TargetRegistry.h"
@@ -33,7 +31,7 @@ class SBFAsmParser : public MCTargetAsmParser {
3331

3432
SMLoc getLoc() const { return getParser().getTok().getLoc(); }
3533

36-
bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
34+
bool matchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
3735
OperandVector &Operands, MCStreamer &Out,
3836
uint64_t &ErrorInfo,
3937
bool MatchingInlineAsm) override;
@@ -43,7 +41,7 @@ class SBFAsmParser : public MCTargetAsmParser {
4341
ParseStatus tryParseRegister(MCRegister &Reg, SMLoc &StartLoc,
4442
SMLoc &EndLoc) override;
4543

46-
bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
44+
bool parseInstruction(ParseInstructionInfo &Info, StringRef Name,
4745
SMLoc NameLoc, OperandVector &Operands) override;
4846

4947
#define GET_ASSEMBLER_HEADER
@@ -80,7 +78,7 @@ struct SBFOperand : public MCParsedAsmOperand {
8078
} Kind;
8179

8280
struct RegOp {
83-
unsigned RegNum;
81+
MCRegister RegNum;
8482
};
8583

8684
struct ImmOp {
@@ -203,10 +201,10 @@ struct SBFOperand : public MCParsedAsmOperand {
203201
return Op;
204202
}
205203

206-
static std::unique_ptr<SBFOperand> createReg(unsigned RegNo, SMLoc S,
204+
static std::unique_ptr<SBFOperand> createReg(MCRegister Reg, SMLoc S,
207205
SMLoc E) {
208206
auto Op = std::make_unique<SBFOperand>(Register);
209-
Op->Reg.RegNum = RegNo;
207+
Op->Reg.RegNum = Reg;
210208
Op->StartLoc = S;
211209
Op->EndLoc = E;
212210
return Op;
@@ -261,7 +259,7 @@ struct SBFOperand : public MCParsedAsmOperand {
261259
#define GET_MATCHER_IMPLEMENTATION
262260
#include "SBFGenAsmMatcher.inc"
263261

264-
bool SBFAsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
262+
bool SBFAsmParser::matchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
265263
OperandVector &Operands,
266264
MCStreamer &Out, uint64_t &ErrorInfo,
267265
bool MatchingInlineAsm) {
@@ -331,13 +329,13 @@ OperandMatchResultTy SBFAsmParser::parseRegister(OperandVector &Operands) {
331329
return MatchOperand_NoMatch;
332330
case AsmToken::Identifier:
333331
StringRef Name = getLexer().getTok().getIdentifier();
334-
unsigned RegNo = MatchRegisterName(Name);
332+
MCRegister Reg = MatchRegisterName(Name);
335333

336-
if (RegNo == 0)
334+
if (!Reg)
337335
return MatchOperand_NoMatch;
338336

339337
getLexer().Lex();
340-
Operands.push_back(SBFOperand::createReg(RegNo, S, E));
338+
Operands.push_back(SBFOperand::createReg(Reg, S, E));
341339
}
342340
return MatchOperand_Success;
343341
}
@@ -420,7 +418,7 @@ bool SBFAsmParser::parseOperand(OperandVector &Operands, StringRef Mnemonic) {
420418
}
421419

422420
/// Parse an SBF instruction.
423-
bool SBFAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
421+
bool SBFAsmParser::parseInstruction(ParseInstructionInfo &Info, StringRef Name,
424422
SMLoc NameLoc, OperandVector &Operands) {
425423
// First operand is token for instruction mnemonic.
426424
Operands.push_back(SBFOperand::createToken(Name, NameLoc));

llvm/lib/Target/SBF/BTFDebug.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ void BTFDebug::visitArrayType(const DICompositeType *CTy, uint32_t &TypeId) {
707707
if (auto *Element = dyn_cast_or_null<DINode>(Elements[I]))
708708
if (Element->getTag() == dwarf::DW_TAG_subrange_type) {
709709
const DISubrange *SR = cast<DISubrange>(Element);
710-
auto *CI = SR->getCount().dyn_cast<ConstantInt *>();
710+
auto *CI = dyn_cast<ConstantInt *>(SR->getCount());
711711
int64_t Count = CI->getSExtValue();
712712

713713
// For struct s { int b; char c[]; }, the c[] will be represented
@@ -1493,17 +1493,15 @@ void BTFDebug::processGlobals(bool ProcessingMapDef) {
14931493
continue;
14941494

14951495
// Find or create a DataSec
1496-
if (DataSecEntries.find(std::string(SecName)) == DataSecEntries.end()) {
1497-
DataSecEntries[std::string(SecName)] =
1498-
std::make_unique<BTFKindDataSec>(Asm, std::string(SecName));
1499-
}
1496+
auto [It, Inserted] = DataSecEntries.try_emplace(std::string(SecName));
1497+
if (Inserted)
1498+
It->second = std::make_unique<BTFKindDataSec>(Asm, std::string(SecName));
15001499

15011500
// Calculate symbol size
15021501
const DataLayout &DL = Global.getParent()->getDataLayout();
15031502
uint32_t Size = DL.getTypeAllocSize(Global.getValueType());
15041503

1505-
DataSecEntries[std::string(SecName)]->addDataSecEntry(VarId,
1506-
Asm->getSymbol(&Global), Size);
1504+
It->second->addDataSecEntry(VarId, Asm->getSymbol(&Global), Size);
15071505
}
15081506
}
15091507

@@ -1584,14 +1582,12 @@ void BTFDebug::processFuncPrototypes(const Function *F) {
15841582
if (F->hasSection()) {
15851583
StringRef SecName = F->getSection();
15861584

1587-
if (DataSecEntries.find(std::string(SecName)) == DataSecEntries.end()) {
1588-
DataSecEntries[std::string(SecName)] =
1589-
std::make_unique<BTFKindDataSec>(Asm, std::string(SecName));
1590-
}
1585+
auto [It, Inserted] = DataSecEntries.try_emplace(std::string(SecName));
1586+
if (Inserted)
1587+
It->second = std::make_unique<BTFKindDataSec>(Asm, std::string(SecName));
15911588

15921589
// We really don't know func size, set it to 0.
1593-
DataSecEntries[std::string(SecName)]->addDataSecEntry(FuncId,
1594-
Asm->getSymbol(F), 0);
1590+
It->second->addDataSecEntry(FuncId, Asm->getSymbol(F), 0);
15951591
}
15961592
}
15971593

llvm/lib/Target/SBF/MCTargetDesc/SBFInstPrinter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ class SBFInstPrinter : public MCInstPrinter {
3232
void printBrTargetOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O);
3333

3434
// Autogenerated by tblgen.
35-
std::pair<const char *, uint64_t> getMnemonic(const MCInst *MI) override;
35+
std::pair<const char *, uint64_t>
36+
getMnemonic(const MCInst &MI) const override;
3637
void printInstruction(const MCInst *MI, uint64_t Address, raw_ostream &O);
3738
static const char *getRegisterName(MCRegister Reg);
3839
};

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "llvm/MC/MCAssembler.h"
2020
#include "llvm/MC/MCCodeEmitter.h"
2121
#include "llvm/MC/MCContext.h"
22+
#include "llvm/MC/MCELFObjectWriter.h"
2223
#include "llvm/MC/MCELFStreamer.h"
2324
#include "llvm/MC/MCInstrAnalysis.h"
2425
#include "llvm/MC/MCInstrInfo.h"

llvm/lib/Target/SBF/SBFAbstractMemberAccess.cpp

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,13 @@ uint32_t SBFCoreSharedInfo::SeqNum;
101101
Instruction *SBFCoreSharedInfo::insertPassThrough(Module *M, BasicBlock *BB,
102102
Instruction *Input,
103103
Instruction *Before) {
104-
Function *Fn = Intrinsic::getDeclaration(
104+
Function *Fn = Intrinsic::getOrInsertDeclaration(
105105
M, Intrinsic::bpf_passthrough, {Input->getType(), Input->getType()});
106106
Constant *SeqNumVal = ConstantInt::get(Type::getInt32Ty(BB->getContext()),
107107
SBFCoreSharedInfo::SeqNum++);
108108

109109
auto *NewInst = CallInst::Create(Fn, {SeqNumVal, Input});
110-
NewInst->insertBefore(Before);
110+
NewInst->insertBefore(Before->getIterator());
111111
return NewInst;
112112
}
113113
} // namespace llvm
@@ -223,10 +223,9 @@ bool SBFAbstractMemberAccess::run(Function &F) {
223223

224224
void SBFAbstractMemberAccess::ResetMetadata(struct CallInfo &CInfo) {
225225
if (auto Ty = dyn_cast<DICompositeType>(CInfo.Metadata)) {
226-
if (AnonRecords.find(Ty) != AnonRecords.end()) {
227-
if (AnonRecords[Ty] != nullptr)
228-
CInfo.Metadata = AnonRecords[Ty];
229-
}
226+
auto It = AnonRecords.find(Ty);
227+
if (It != AnonRecords.end() && It->second != nullptr)
228+
CInfo.Metadata = It->second;
230229
}
231230
}
232231

@@ -236,18 +235,13 @@ void SBFAbstractMemberAccess::CheckCompositeType(DIDerivedType *ParentTy,
236235
ParentTy->getTag() != dwarf::DW_TAG_typedef)
237236
return;
238237

239-
if (AnonRecords.find(CTy) == AnonRecords.end()) {
240-
AnonRecords[CTy] = ParentTy;
241-
return;
242-
}
238+
auto [It, Inserted] = AnonRecords.try_emplace(CTy, ParentTy);
243239

244240
// Two or more typedef's may point to the same anon record.
245241
// If this is the case, set the typedef DIType to be nullptr
246242
// to indicate the duplication case.
247-
DIDerivedType *CurrTy = AnonRecords[CTy];
248-
if (CurrTy == ParentTy)
249-
return;
250-
AnonRecords[CTy] = nullptr;
243+
if (!Inserted && It->second != ParentTy)
244+
It->second = nullptr;
251245
}
252246

253247
void SBFAbstractMemberAccess::CheckDerivedType(DIDerivedType *ParentTy,
@@ -312,7 +306,7 @@ static uint32_t calcArraySize(const DICompositeType *CTy, uint32_t StartDim) {
312306
if (auto *Element = dyn_cast_or_null<DINode>(Elements[I]))
313307
if (Element->getTag() == dwarf::DW_TAG_subrange_type) {
314308
const DISubrange *SR = cast<DISubrange>(Element);
315-
auto *CI = SR->getCount().dyn_cast<ConstantInt *>();
309+
auto *CI = dyn_cast<ConstantInt *>(SR->getCount());
316310
DimSize *= CI->getSExtValue();
317311
}
318312
}
@@ -425,7 +419,7 @@ void SBFAbstractMemberAccess::replaceWithGEP(std::vector<CallInst *> &CallList,
425419
IdxList.push_back(Call->getArgOperand(GEPIndex));
426420

427421
auto *GEP = GetElementPtrInst::CreateInBounds(
428-
getBaseElementType(Call), Call->getArgOperand(0), IdxList, "", Call);
422+
getBaseElementType(Call), Call->getArgOperand(0), IdxList, "", Call->getIterator());
429423
Call->replaceAllUsesWith(GEP);
430424
Call->eraseFromParent();
431425
}
@@ -1083,9 +1077,9 @@ bool SBFAbstractMemberAccess::transformGEPChain(CallInst *Call,
10831077
// Load the global variable which represents the returned field info.
10841078
LoadInst *LDInst;
10851079
if (IsInt32Ret)
1086-
LDInst = new LoadInst(Type::getInt32Ty(BB->getContext()), GV, "", Call);
1080+
LDInst = new LoadInst(Type::getInt32Ty(BB->getContext()), GV, "", Call->getIterator());
10871081
else
1088-
LDInst = new LoadInst(Type::getInt64Ty(BB->getContext()), GV, "", Call);
1082+
LDInst = new LoadInst(Type::getInt64Ty(BB->getContext()), GV, "", Call->getIterator());
10891083

10901084
Instruction *PassThroughInst =
10911085
SBFCoreSharedInfo::insertPassThrough(M, BB, LDInst, Call);
@@ -1105,21 +1099,23 @@ bool SBFAbstractMemberAccess::transformGEPChain(CallInst *Call,
11051099
// The original Call inst is removed.
11061100

11071101
// Load the global variable.
1108-
auto *LDInst = new LoadInst(Type::getInt64Ty(BB->getContext()), GV, "", Call);
1102+
auto *LDInst = new LoadInst(Type::getInt64Ty(BB->getContext()), GV, "", Call->getIterator());
11091103

11101104
// Generate a BitCast
11111105
auto *BCInst =
1112-
new BitCastInst(Base, PointerType::getUnqual(BB->getContext()));
1113-
BCInst->insertBefore(Call);
1106+
new BitCastInst(
1107+
Base, PointerType::get(BB->getContext(),
1108+
Base->getType()->getPointerAddressSpace()));
1109+
BCInst->insertBefore(Call->getIterator());
11141110

11151111
// Generate a GetElementPtr
11161112
auto *GEP = GetElementPtrInst::Create(Type::getInt8Ty(BB->getContext()),
11171113
BCInst, LDInst);
1118-
GEP->insertBefore(Call);
1114+
GEP->insertBefore(Call->getIterator());
11191115

11201116
// Generate a BitCast
11211117
auto *BCInst2 = new BitCastInst(GEP, Call->getType());
1122-
BCInst2->insertBefore(Call);
1118+
BCInst2->insertBefore(Call->getIterator());
11231119

11241120
// For the following code,
11251121
// Block0:

llvm/lib/Target/SBF/SBFAsmPrinter.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@
1414
#include "SBF.h"
1515
#include "SBFInstrInfo.h"
1616
#include "SBFMCInstLower.h"
17-
#include "SBFTargetMachine.h"
1817
#include "BTFDebug.h"
1918
#include "MCTargetDesc/SBFInstPrinter.h"
2019
#include "MCTargetDesc/SBFMCTargetDesc.h"
2120
#include "TargetInfo/SBFTargetInfo.h"
2221
#include "llvm/CodeGen/AsmPrinter.h"
2322
#include "llvm/CodeGen/MachineConstantPool.h"
24-
#include "llvm/CodeGen/MachineFunctionPass.h"
2523
#include "llvm/CodeGen/MachineInstr.h"
2624
#include "llvm/CodeGen/MachineModuleInfo.h"
2725
#include "llvm/IR/Module.h"
@@ -70,7 +68,7 @@ bool SBFAsmPrinter::doInitialization(Module &M) {
7068
if (MAI->doesSupportDebugInformation() && !M.debug_compile_units().empty() &&
7169
SBFEnableBTFEmission) {
7270
BTF = new BTFX::BTFDebug(this);
73-
DebugHandlers.push_back(std::unique_ptr<BTFX::BTFDebug>(BTF));
71+
Handlers.push_back(std::unique_ptr<BTFX::BTFDebug>(BTF));
7472
}
7573

7674
return false;

0 commit comments

Comments
 (0)