Skip to content
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

Enable LLVM 16.0.3 #4411

Merged
merged 10 commits into from
Aug 16, 2023
13 changes: 12 additions & 1 deletion .github/workflows/supported_llvm_versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ jobs:
fail-fast: false
matrix:
include:
- job_name: Ubuntu 22.04, LLVM 16, latest LDC beta
os: ubuntu-22.04
host_dc: ldc-beta
llvm_version: 16.0.3
- job_name: Ubuntu 20.04, LLVM 15, latest LDC beta
os: ubuntu-20.04
host_dc: ldc-beta
Expand Down Expand Up @@ -77,7 +81,12 @@ jobs:
set -eux
sudo apt-get update
# Don't use latest gdb v10+ from Ubuntu toolchain PPA with regressions, use official v9
sudo apt-get install gdb=9.1-0ubuntu1 llvm
version='${{ matrix.llvm_version }}'
if [[ "$version" =~ ^1[6-9]\. ]]; then # LLVM 16.0.3+
sudo apt-get install gdb llvm
else
sudo apt-get install gdb=9.1-0ubuntu1 llvm
fi

- name: Try to restore cached LLVM
uses: actions/cache@v2
Expand All @@ -95,6 +104,8 @@ jobs:
version='${{ matrix.llvm_version }}'
if [[ '${{ runner.os }}' == macOS ]]; then
suffix='x86_64-apple-darwin'
elif [[ "$version" =~ ^1[6-9]\. ]]; then # LLVM 16.0.3+
suffix='x86_64-linux-gnu-ubuntu-22.04' # LLVM 13.0.1+
elif [[ "$version" =~ ^1[3-9]\. ]]; then
suffix='x86_64-linux-gnu-ubuntu-18.04' # LLVM 13.0.1+
else
Expand Down
4 changes: 4 additions & 0 deletions driver/args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,11 @@ int executeAndWait(std::vector<const char *> fullArgs,
}

const std::vector<llvm::StringRef> argv = toRefsVector(fullArgs);
#if LDC_LLVM_VER < 1600
auto envVars = llvm::None;
#else
auto envVars = std::nullopt;
#endif

return llvm::sys::ExecuteAndWait(argv[0], argv, envVars, {}, 0, 0, errorMsg);
}
Expand Down
4 changes: 4 additions & 0 deletions driver/linker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,11 @@ static std::vector<std::string> getDefaultLibNames() {
llvm::Optional<std::vector<std::string>> getExplicitPlatformLibs() {
if (platformLib.getNumOccurrences() > 0)
return parseLibNames(platformLib);
#if LDC_LLVM_VER < 1600
return llvm::None;
#else
return std::nullopt;
#endif
}

//////////////////////////////////////////////////////////////////////////////
Expand Down
4 changes: 4 additions & 0 deletions driver/linker.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ bool linkAgainstSharedDefaultLibs();
/**
* Returns the -platformlib library names, if specified.
*/
#if LDC_LLVM_VER < 1600
llvm::Optional<std::vector<std::string>> getExplicitPlatformLibs();
#else
std::optional<std::vector<std::string>> getExplicitPlatformLibs();
#endif

/**
* Returns the value of -mscrtlib.
Expand Down
2 changes: 2 additions & 0 deletions driver/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,9 @@ void initializePasses() {
#endif
initializeVectorization(Registry);
initializeInstCombine(Registry);
#if LDC_LLVM_VER < 1600
initializeAggressiveInstCombine(Registry);
#endif
initializeIPO(Registry);
#if LDC_LLVM_VER < 1600
initializeInstrumentation(Registry);
Expand Down
2 changes: 2 additions & 0 deletions driver/targetmachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,11 @@ static std::string getARMTargetCPU(const llvm::Triple &triple) {
}

static std::string getAArch64TargetCPU(const llvm::Triple &triple) {
#if LDC_LLVM_VER < 1600
auto defaultCPU = llvm::AArch64::getDefaultCPU(triple.getArchName());
if (!defaultCPU.empty())
return std::string(defaultCPU);
#endif

return "generic";
}
Expand Down
7 changes: 6 additions & 1 deletion gen/dcompute/druntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,13 @@ bool isFromLDC_OpenCL(Dsymbol *sym) {
}

llvm::Optional<DcomputePointer> toDcomputePointer(StructDeclaration *sd) {
if (sd->ident != Id::dcPointer || !isFromLDC_DCompute(sd))
if (sd->ident != Id::dcPointer || !isFromLDC_DCompute(sd)) {
#if LDC_LLVM_VER < 1600
return llvm::Optional<DcomputePointer>(llvm::None);
#else
return std::optional<DcomputePointer>(std::nullopt);
#endif
}

TemplateInstance *ti = sd->isInstantiated();
int addrspace = isExpression((*ti->tiargs)[0])->toInteger();
Expand Down
21 changes: 21 additions & 0 deletions gen/dibuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,11 @@ DIType DIBuilder::CreateEnumType(TypeEnum *type) {
DIType DIBuilder::CreatePointerType(TypePointer *type) {
// TODO: The addressspace is important for dcompute targets. See e.g.
// https://www.mail-archive.com/dwarf-discuss@lists.dwarfstd.org/msg00326.html
#if LDC_LLVM_VER < 1600
const llvm::Optional<unsigned> DWARFAddressSpace = llvm::None;
#else
const std::optional<unsigned> DWARFAddressSpace = std::nullopt;
#endif

const auto name = processDIName(type->toPrettyChars(true));

Expand Down Expand Up @@ -730,7 +734,11 @@ DISubroutineType DIBuilder::CreateFunctionType(Type *type) {
}

DISubroutineType DIBuilder::CreateEmptyFunctionType() {
#if LDC_LLVM_VER < 1600
auto paramsArray = DBuilder.getOrCreateTypeArray(llvm::None);
#else
auto paramsArray = DBuilder.getOrCreateTypeArray(std::nullopt);
#endif
return DBuilder.createSubroutineType(paramsArray);
}

Expand Down Expand Up @@ -774,9 +782,16 @@ DIType DIBuilder::CreateTypeDescription(Type *t, bool voidToUbyte) {
return nullptr;
if (t->ty == TY::Tnull) {
// display null as void*
#if LDC_LLVM_VER < 1600
return DBuilder.createPointerType(
CreateTypeDescription(Type::tvoid), target.ptrsize * 8, 0,
/* DWARFAddressSpace */ llvm::None, "typeof(null)");
#else
return DBuilder.createPointerType(
CreateTypeDescription(Type::tvoid), target.ptrsize * 8, 0,
/* DWARFAddressSpace */ std::nullopt, "typeof(null)");
#endif

}
if (auto te = t->isTypeEnum())
return CreateEnumType(te);
Expand All @@ -798,8 +813,14 @@ DIType DIBuilder::CreateTypeDescription(Type *t, bool voidToUbyte) {
const auto aggregateDIType = CreateCompositeType(t);
const auto name =
(tc->sym->toPrettyChars(true) + llvm::StringRef("*")).str();
#if LDC_LLVM_VER < 1600
return DBuilder.createPointerType(aggregateDIType, target.ptrsize * 8, 0,
llvm::None, processDIName(name));
#else
return DBuilder.createPointerType(aggregateDIType, target.ptrsize * 8, 0,
std::nullopt, processDIName(name));
#endif

}
if (auto tf = t->isTypeFunction())
return CreateFunctionType(tf);
Expand Down
5 changes: 5 additions & 0 deletions gen/ms-cxx-helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,12 @@ void cloneBlocks(const std::vector<llvm::BasicBlock *> &srcblocks,
if (!newInst)
newInst = Inst->clone();

#if LDC_LLVM_VER < 1600
nbb->getInstList().push_back(newInst);
#else
newInst->insertInto(nbb, nbb->end());
#endif

VMap[Inst] = newInst; // Add instruction map to value.
if (unwindTo)
if (auto dest = getUnwindDest(Inst))
Expand Down
9 changes: 9 additions & 0 deletions gen/optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,13 @@ static llvm::Optional<PGOOptions> getPGOOptions() {
PGOOptions::CSPGOAction::NoCSAction,
debugInfoForProfiling, pseudoProbeForProfiling);
}
#if LDC_LLVM_VER < 1600
return None;
#else
return std::nullopt;
#endif
}

static PipelineTuningOptions getPipelineTuningOptions(unsigned optLevelVal, unsigned sizeLevelVal) {
PipelineTuningOptions pto;

Expand Down Expand Up @@ -637,7 +642,11 @@ void runOptimizationPasses(llvm::Module *M) {
bool debugLogging = false;
ppo.Indent = false;
ppo.SkipAnalyses = false;
#if LDC_LLVM_VER < 1600
StandardInstrumentations si(debugLogging, /*VerifyEach=*/false, ppo);
#else
StandardInstrumentations si(M->getContext(), debugLogging, /*VerifyEach=*/false, ppo);
#endif

si.registerCallbacks(pic, &fam);

Expand Down
2 changes: 1 addition & 1 deletion gen/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include "llvm/Bitcode/BitcodeWriter.h"
#include "llvm/IR/Attributes.h"
#if LDC_LLVM_VER >= 1600
#include "llvm/IR/ModRef.h"
#include "llvm/Support/ModRef.h"
#endif
#include "llvm/IR/Module.h"
#include "llvm/Support/CommandLine.h"
Expand Down
4 changes: 4 additions & 0 deletions gen/uda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,11 @@ void applyAttrAllocSize(StructLiteralExp *sle, IrFunction *irFunc) {
if (numArgIdx >= 0) {
builder.addAllocSizeAttr(llvmSizeIdx, llvmNumIdx);
} else {
#if LDC_LLVM_VER < 1600
builder.addAllocSizeAttr(llvmSizeIdx, llvm::Optional<unsigned>());
#else
builder.addAllocSizeAttr(llvmSizeIdx, std::optional<unsigned>());
#endif
}

llvm::Function *func = irFunc->getLLVMFunc();
Expand Down
Loading