Skip to content

Commit

Permalink
[SOL] Make adjustments after upgrading to llvm 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dmakarov committed Sep 28, 2023
1 parent f07d0da commit a53bae0
Show file tree
Hide file tree
Showing 53 changed files with 614 additions and 592 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/clang-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ on:
workflow_dispatch:
push:
ignore-forks: true
#branches:
# - 'release/**'
branches:
- 'release/**'
paths:
- 'clang/**'
- '.github/workflows/clang-tests.yml'
- '.github/workflows/llvm-project-tests.yml'
- '!llvm/**'
pull_request:
ignore-forks: true
#branches:
# - 'release/**'
branches:
- 'release/**'
paths:
- 'clang/**'
- '.github/workflows/clang-tests.yml'
Expand All @@ -29,7 +29,7 @@ concurrency:

jobs:
check_clang:
#if: github.repository_owner == 'llvm'
if: github.repository_owner == 'llvm'
name: Test clang,lldb,libclc
uses: ./.github/workflows/llvm-project-tests.yml
with:
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/lld-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ on:
workflow_dispatch:
push:
ignore-forks: true
#branches:
# - 'release/**'
branches:
- 'release/**'
paths:
- 'lld/**'
- '.github/workflows/lld-tests.yml'
- '.github/workflows/llvm-project-tests.yml'
- '!llvm/**'
pull_request:
ignore-forks: true
#branches:
# - 'release/**'
branches:
- 'release/**'
paths:
- 'lld/**'
- '.github/workflows/lld-tests.yml'
Expand All @@ -29,7 +29,7 @@ concurrency:

jobs:
check_lld:
#if: github.repository_owner == 'llvm'
if: github.repository_owner == 'llvm'
name: Test lld
uses: ./.github/workflows/llvm-project-tests.yml
with:
Expand Down
6 changes: 0 additions & 6 deletions .github/workflows/llvm-project-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install homebrew packages
if: startsWith(matrix.os, 'macOS')
run: |
brew rm swig
brew install swig@3
brew link swig@3
- name: Install Ninja
uses: llvm/actions/install-ninja@main
# actions/checkout deletes any existing files in the new git directory,
Expand Down
1 change: 0 additions & 1 deletion clang/lib/Basic/Targets/BPF.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ namespace targets {
class LLVM_LIBRARY_VISIBILITY BPFTargetInfo : public TargetInfo {
bool HasSolanaFeature = false;
bool HasAlu32 = false;
static const Builtin::Info BuiltinInfo[];

public:
BPFTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Interpreter/global-dtor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ extern "C" int printf(const char *, ...);
struct D { float f = 1.0; D *m = nullptr; D(){} ~D() { printf("D[f=%f, m=0x%llx]\n", f, reinterpret_cast<unsigned long long>(m)); }} d;
// CHECK: D[f=1.000000, m=0x0]

%quit
%quit
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ createInterpreter(const Args &ExtraArgs = {},
}

TEST(InterpreterTest, CatchException) {
GTEST_SKIP() << "Skipping single test";
llvm::llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
llvm::InitializeNativeTarget();
llvm::InitializeNativeTargetAsmPrinter();
Expand Down
2 changes: 1 addition & 1 deletion lld/ELF/Arch/BPF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ uint32_t BPF::calcEFlags() const {

// Ensure that all the object files were compiled with the same flags, as
// different flags indicate different ABIs.
for (InputFile *f : ctx->objectFiles) {
for (InputFile *f : ctx.objectFiles) {
uint32_t flags = getEFlags(f);
if (ret == 0) {
ret = flags;
Expand Down
2 changes: 1 addition & 1 deletion lld/ELF/Arch/SBF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ uint32_t SBF::calcEFlags() const {

// Ensure that all the object files were compiled with the same flags, as
// different flags indicate different ABIs.
for (InputFile *f : ctx->objectFiles) {
for (InputFile *f : ctx.objectFiles) {
uint32_t flags = getEFlags(f);
if (ret == 0) {
ret = flags;
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ static uint32_t subTypeFromElfHeader(const elf::ELFHeader &header) {
else if (header.e_machine == llvm::ELF::EM_LOONGARCH)
return loongarchVariantFromElfFlags(header);
else if (header.e_machine == llvm::ELF::EM_BPF)
return bpfVariantFromElfFlags(header);
return sbfVariantFromElfFlags(header);
else if (header.e_machine == llvm::ELF::EM_SBF)
return sbfVariantFromElfFlags(header);

Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Target/BPF/BPFISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,13 @@ BPFTargetLowering::BPFTargetLowering(const TargetMachine &TM,
}

bool BPFTargetLowering::allowsMisalignedMemoryAccesses(
EVT VT, unsigned, Align, MachineMemOperand::Flags, bool *Fast) const {
EVT VT, unsigned, Align, MachineMemOperand::Flags, unsigned *Fast) const {
if (!VT.isSimple()) {
return false;
}
bool isSolana = Subtarget->isSolana();
if (isSolana && Fast) {
*Fast = true;
*Fast = 1;
}
return isSolana;
}
Expand Down Expand Up @@ -833,7 +833,7 @@ SDValue BPFTargetLowering::LowerATOMICRMW(SDValue Op, SelectionDAG &DAG) const {
// Load the current value
SDValue Load =
DAG.getExtLoad(ISD::EXTLOAD, DL, RetVT, Chain, Ptr, MachinePointerInfo(),
PtrVT, AN->getAlignment());
PtrVT, AN->getAlign());
Chain = Load.getValue(1);

// Most ops return the current value, except CMP_SWAP_WITH_SUCCESS see below
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/BPF/BPFISelLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class BPFTargetLowering : public TargetLowering {

bool allowsMisalignedMemoryAccesses(EVT VT, unsigned, Align,
MachineMemOperand::Flags,
bool *) const override;
unsigned *) const override;

// Provide custom lowering hooks for some operations.
SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
Expand Down
15 changes: 8 additions & 7 deletions llvm/lib/Target/SBF/AsmParser/SBFAsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ class SBFAsmParser : public MCTargetAsmParser {
uint64_t &ErrorInfo,
bool MatchingInlineAsm) override;

bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc) override;
OperandMatchResultTy tryParseRegister(unsigned &RegNo, SMLoc &StartLoc,
bool parseRegister(MCRegister &Reg, SMLoc &StartLoc,
SMLoc &EndLoc) override;
OperandMatchResultTy tryParseRegister(MCRegister &Reg, SMLoc &StartLoc,
SMLoc &EndLoc) override;

bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
Expand Down Expand Up @@ -347,20 +348,20 @@ bool SBFAsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
llvm_unreachable("Unknown match type detected!");
}

bool SBFAsmParser::ParseRegister(unsigned &RegNo, SMLoc &StartLoc,
bool SBFAsmParser::parseRegister(MCRegister &Reg, SMLoc &StartLoc,
SMLoc &EndLoc) {
if (tryParseRegister(RegNo, StartLoc, EndLoc) != MatchOperand_Success)
if (tryParseRegister(Reg, StartLoc, EndLoc) != MatchOperand_Success)
return Error(StartLoc, "invalid register name");
return false;
}

OperandMatchResultTy SBFAsmParser::tryParseRegister(unsigned &RegNo,
OperandMatchResultTy SBFAsmParser::tryParseRegister(MCRegister &Reg,
SMLoc &StartLoc,
SMLoc &EndLoc) {
const AsmToken &Tok = getParser().getTok();
StartLoc = Tok.getLoc();
EndLoc = Tok.getEndLoc();
RegNo = 0;
Reg = 0;
StringRef Name = getLexer().getTok().getIdentifier();

if (!MatchRegisterName(Name)) {
Expand Down Expand Up @@ -395,7 +396,7 @@ SBFAsmParser::parseOperandAsOperator(OperandVector &Operands) {
case AsmToken::Plus: {
if (getLexer().peekTok().is(AsmToken::Integer))
return MatchOperand_NoMatch;
LLVM_FALLTHROUGH;
[[fallthrough]];
}

case AsmToken::Equal:
Expand Down
116 changes: 69 additions & 47 deletions llvm/lib/Target/SBF/BTFDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "llvm/Support/LineIterator.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Target/TargetLoweringObjectFile.h"
#include <optional>

using namespace llvm;
using namespace BTFX;
Expand Down Expand Up @@ -597,6 +598,25 @@ void BTFDebug::processDeclAnnotations(DINodeArray Annotations,
}
}

uint32_t BTFDebug::processDISubprogram(const DISubprogram *SP,
uint32_t ProtoTypeId, uint8_t Scope) {
auto FuncTypeEntry =
std::make_unique<BTFTypeFunc>(SP->getName(), ProtoTypeId, Scope);
uint32_t FuncId = addType(std::move(FuncTypeEntry));

// Process argument annotations.
for (const DINode *DN : SP->getRetainedNodes()) {
if (const auto *DV = dyn_cast<DILocalVariable>(DN)) {
uint32_t Arg = DV->getArg();
if (Arg)
processDeclAnnotations(DV->getAnnotations(), FuncId, Arg - 1);
}
}
processDeclAnnotations(SP->getAnnotations(), FuncId, -1);

return FuncId;
}

/// Generate btf_type_tag chains.
int BTFDebug::genBTFTypeTags(const DIDerivedType *DTy, int BaseTypeId) {
SmallVector<const MDString *, 4> MDStrs;
Expand Down Expand Up @@ -763,6 +783,17 @@ void BTFDebug::visitCompositeType(const DICompositeType *CTy,
visitEnumType(CTy, TypeId);
}

bool BTFDebug::IsForwardDeclCandidate(const DIType *Base) {
if (const auto *CTy = dyn_cast<DICompositeType>(Base)) {
auto CTag = CTy->getTag();
if ((CTag == dwarf::DW_TAG_structure_type ||
CTag == dwarf::DW_TAG_union_type) &&
!CTy->getName().empty() && !CTy->isForwardDecl())
return true;
}
return false;
}

/// Handle pointer, typedef, const, volatile, restrict and member types.
void BTFDebug::visitDerivedType(const DIDerivedType *DTy, uint32_t &TypeId,
bool CheckPointer, bool SeenPointer) {
Expand All @@ -777,20 +808,15 @@ void BTFDebug::visitDerivedType(const DIDerivedType *DTy, uint32_t &TypeId,
if (CheckPointer && SeenPointer) {
const DIType *Base = DTy->getBaseType();
if (Base) {
if (const auto *CTy = dyn_cast<DICompositeType>(Base)) {
auto CTag = CTy->getTag();
if ((CTag == dwarf::DW_TAG_structure_type ||
CTag == dwarf::DW_TAG_union_type) &&
!CTy->getName().empty() && !CTy->isForwardDecl()) {
/// Find a candidate, generate a fixup. Later on the struct/union
/// pointee type will be replaced with either a real type or
/// a forward declaration.
auto TypeEntry = std::make_unique<BTFTypeDerived>(DTy, Tag, true);
auto &Fixup = FixupDerivedTypes[CTy];
Fixup.push_back(std::make_pair(DTy, TypeEntry.get()));
TypeId = addType(std::move(TypeEntry), DTy);
return;
}
if (IsForwardDeclCandidate(Base)) {
/// Find a candidate, generate a fixup. Later on the struct/union
/// pointee type will be replaced with either a real type or
/// a forward declaration.
auto TypeEntry = std::make_unique<BTFTypeDerived>(DTy, Tag, true);
auto &Fixup = FixupDerivedTypes[dyn_cast<DICompositeType>(Base)];
Fixup.push_back(std::make_pair(DTy, TypeEntry.get()));
TypeId = addType(std::move(TypeEntry), DTy);
return;
}
}
}
Expand Down Expand Up @@ -825,6 +851,13 @@ void BTFDebug::visitDerivedType(const DIDerivedType *DTy, uint32_t &TypeId,
visitTypeEntry(DTy->getBaseType(), TempTypeId, CheckPointer, SeenPointer);
}

/// Visit a type entry. CheckPointer is true if the type has
/// one of its predecessors as one struct/union member. SeenPointer
/// is true if CheckPointer is true and one of its predecessors
/// is a pointer. The goal of CheckPointer and SeenPointer is to
/// do pruning for struct/union types so some of these types
/// will not be emitted in BTF and rather forward declarations
/// will be generated.
void BTFDebug::visitTypeEntry(const DIType *Ty, uint32_t &TypeId,
bool CheckPointer, bool SeenPointer) {
if (!Ty || DIToIdMap.find(Ty) != DIToIdMap.end()) {
Expand Down Expand Up @@ -869,6 +902,11 @@ void BTFDebug::visitTypeEntry(const DIType *Ty, uint32_t &TypeId,
if (DIToIdMap.find(BaseTy) != DIToIdMap.end()) {
DTy = dyn_cast<DIDerivedType>(BaseTy);
} else {
if (CheckPointer && DTy->getTag() == dwarf::DW_TAG_pointer_type) {
SeenPointer = true;
if (IsForwardDeclCandidate(BaseTy))
break;
}
uint32_t TmpTypeId;
visitTypeEntry(BaseTy, TmpTypeId, CheckPointer, SeenPointer);
break;
Expand Down Expand Up @@ -1178,20 +1216,7 @@ void BTFDebug::beginFunctionImpl(const MachineFunction *MF) {

// Construct subprogram func type
uint8_t Scope = SP->isLocalToUnit() ? BTF::FUNC_STATIC : BTF::FUNC_GLOBAL;
auto FuncTypeEntry =
std::make_unique<BTFTypeFunc>(SP->getName(), ProtoTypeId, Scope);
uint32_t FuncTypeId = addType(std::move(FuncTypeEntry));

// Process argument annotations.
for (const DINode *DN : SP->getRetainedNodes()) {
if (const auto *DV = dyn_cast<DILocalVariable>(DN)) {
uint32_t Arg = DV->getArg();
if (Arg)
processDeclAnnotations(DV->getAnnotations(), FuncTypeId, Arg - 1);
}
}

processDeclAnnotations(SP->getAnnotations(), FuncTypeId, -1);
uint32_t FuncTypeId = processDISubprogram(SP, ProtoTypeId, Scope);

for (const auto &TypeEntry : TypeEntries)
TypeEntry->completeType(*this);
Expand Down Expand Up @@ -1358,7 +1383,7 @@ void BTFDebug::beginInstruction(const MachineInstr *MI) {
OS.emitLabel(LineSym);

// Construct the lineinfo.
auto SP = DL.get()->getScope()->getSubprogram();
auto SP = DL->getScope()->getSubprogram();
constructLineInfo(SP, LineSym, DL.getLine(), DL.getCol());

LineInfoGenerated = true;
Expand All @@ -1371,14 +1396,19 @@ void BTFDebug::processGlobals(bool ProcessingMapDef) {
for (const GlobalVariable &Global : M->globals()) {
// Decide the section name.
StringRef SecName;
if (Global.hasSection()) {
SecName = Global.getSection();
} else if (Global.hasInitializer()) {
// data, bss, or readonly sections
if (Global.isConstant())
SecName = ".rodata";
else
SecName = Global.getInitializer()->isZeroValue() ? ".bss" : ".data";
std::optional<SectionKind> GVKind;

if (!Global.isDeclarationForLinker())
GVKind = TargetLoweringObjectFile::getKindForGlobal(&Global, Asm->TM);

if (Global.isDeclarationForLinker())
SecName = Global.hasSection() ? Global.getSection() : "";
else if (GVKind->isCommon())
SecName = ".bss";
else {
TargetLoweringObjectFile *TLOF = Asm->TM.getObjFileLowering();
MCSection *Sec = TLOF->SectionForGlobal(&Global, Asm->TM);
SecName = Sec->getName();
}

if (ProcessingMapDef != SecName.startswith(".maps"))
Expand All @@ -1389,10 +1419,8 @@ void BTFDebug::processGlobals(bool ProcessingMapDef) {
// and .rodata.cst<#> sections.
if (SecName == ".rodata" && Global.hasPrivateLinkage() &&
DataSecEntries.find(std::string(SecName)) == DataSecEntries.end()) {
SectionKind GVKind =
TargetLoweringObjectFile::getKindForGlobal(&Global, Asm->TM);
// skip .rodata.str<#> and .rodata.cst<#> sections
if (!GVKind.isMergeableCString() && !GVKind.isMergeableConst()) {
if (!GVKind->isMergeableCString() && !GVKind->isMergeableConst()) {
DataSecEntries[std::string(SecName)] =
std::make_unique<BTFKindDataSec>(Asm, std::string(SecName));
}
Expand Down Expand Up @@ -1534,13 +1562,7 @@ void BTFDebug::processFuncPrototypes(const Function *F) {
uint32_t ProtoTypeId;
const std::unordered_map<uint32_t, StringRef> FuncArgNames;
visitSubroutineType(SP->getType(), false, FuncArgNames, ProtoTypeId);

uint8_t Scope = BTF::FUNC_EXTERN;
auto FuncTypeEntry =
std::make_unique<BTFTypeFunc>(SP->getName(), ProtoTypeId, Scope);
uint32_t FuncId = addType(std::move(FuncTypeEntry));

processDeclAnnotations(SP->getAnnotations(), FuncId, -1);
uint32_t FuncId = processDISubprogram(SP, ProtoTypeId, BTF::FUNC_EXTERN);

if (F->hasSection()) {
StringRef SecName = F->getSection();
Expand Down
Loading

0 comments on commit a53bae0

Please sign in to comment.