mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-03 00:20:40 +03:00
Fix compilation with LLVM 14 (#3822)
This commit is contained in:
parent
613ed42dca
commit
1568d0cdca
13 changed files with 135 additions and 33 deletions
|
@ -322,7 +322,7 @@ void outputIR2ObjRelevantCmdlineArgs(llvm::raw_ostream &hash_os) {
|
|||
#if LDC_LLVM_VER >= 800
|
||||
const auto framePointerUsage = opts::framePointerUsage();
|
||||
if (framePointerUsage.hasValue())
|
||||
hash_os << framePointerUsage.getValue();
|
||||
hash_os << static_cast<int>(framePointerUsage.getValue());
|
||||
#else
|
||||
hash_os << opts::disableFPElim();
|
||||
#endif
|
||||
|
|
|
@ -64,8 +64,14 @@ Optional<CodeModel::Model> getCodeModel() {
|
|||
#endif
|
||||
}
|
||||
|
||||
#if LDC_LLVM_VER >= 1400
|
||||
using FPK = llvm::FramePointerKind;
|
||||
#elif LDC_LLVM_VER >= 800
|
||||
using FPK = llvm::FramePointer::FP;
|
||||
#endif
|
||||
|
||||
#if LDC_LLVM_VER >= 800
|
||||
llvm::Optional<llvm::FramePointer::FP> framePointerUsage() {
|
||||
llvm::Optional<FPK> framePointerUsage() {
|
||||
#if LDC_LLVM_VER >= 1100
|
||||
// Defaults to `FP::None`; no way to check if set explicitly by user except
|
||||
// indirectly via setFunctionAttributes()...
|
||||
|
|
|
@ -24,7 +24,9 @@ namespace opts {
|
|||
std::string getArchStr();
|
||||
llvm::Optional<llvm::Reloc::Model> getRelocModel();
|
||||
llvm::Optional<llvm::CodeModel::Model> getCodeModel();
|
||||
#if LDC_LLVM_VER >= 800
|
||||
#if LDC_LLVM_VER >= 1400
|
||||
llvm::Optional<llvm::FramePointerKind> framePointerUsage();
|
||||
#elif LDC_LLVM_VER >= 800
|
||||
llvm::Optional<llvm::FramePointer::FP> framePointerUsage();
|
||||
#else
|
||||
llvm::cl::boolOrDefault disableFPElim();
|
||||
|
|
|
@ -21,6 +21,9 @@
|
|||
#include "llvm/ADT/StringSwitch.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include "llvm/Support/SpecialCaseList.h"
|
||||
#if LDC_LLVM_VER >= 1400
|
||||
#include "llvm/Support/VirtualFileSystem.h"
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
|
|
|
@ -152,20 +152,16 @@ void emitLLVMUsedArray(IRState &irs) {
|
|||
llvmUsed->setSection("llvm.metadata");
|
||||
}
|
||||
|
||||
void inlineAsmDiagnosticHandler(const llvm::SMDiagnostic &d, void *context,
|
||||
unsigned locCookie) {
|
||||
if (d.getKind() == llvm::SourceMgr::DK_Error)
|
||||
++global.errors;
|
||||
|
||||
bool inlineAsmDiagnostic(IRState* irs,const llvm::SMDiagnostic &d, unsigned locCookie)
|
||||
{
|
||||
if (!locCookie) {
|
||||
d.print(nullptr, llvm::errs());
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
// replace the `<inline asm>` dummy filename by the LOC of the actual D
|
||||
// expression/statement (`myfile.d(123)`)
|
||||
const Loc &loc =
|
||||
static_cast<IRState *>(context)->getInlineAsmSrcLoc(locCookie);
|
||||
const Loc &loc = irs->getInlineAsmSrcLoc(locCookie);
|
||||
const char *filename = loc.toChars(/*showColumns*/ false);
|
||||
|
||||
// keep on using llvm::SMDiagnostic::print() for nice, colorful output
|
||||
|
@ -173,8 +169,34 @@ void inlineAsmDiagnosticHandler(const llvm::SMDiagnostic &d, void *context,
|
|||
d.getColumnNo(), d.getKind(), d.getMessage(),
|
||||
d.getLineContents(), d.getRanges(), d.getFixIts());
|
||||
d2.print(nullptr, llvm::errs());
|
||||
return true;
|
||||
}
|
||||
|
||||
#if LDC_LLVM_VER < 1300
|
||||
void inlineAsmDiagnosticHandler(const llvm::SMDiagnostic &d, void *context,
|
||||
unsigned locCookie) {
|
||||
if (d.getKind() == llvm::SourceMgr::DK_Error)
|
||||
++global.errors;
|
||||
inlineAsmDiagnostic(static_cast<IRState *>(context), d, locCookie);
|
||||
}
|
||||
#else
|
||||
struct InlineAsmDiagnosticHandler : public llvm::DiagnosticHandler {
|
||||
IRState *irs;
|
||||
InlineAsmDiagnosticHandler(IRState *irs) : irs(irs) {}
|
||||
|
||||
// return false to defer to LLVMContext::diagnose()
|
||||
bool handleDiagnostics(const llvm::DiagnosticInfo &DI) override {
|
||||
if (DI.getKind() != llvm::DK_SrcMgr)
|
||||
return false;
|
||||
|
||||
const auto &DISM = llvm::cast<llvm::DiagnosticInfoSrcMgr>(DI);
|
||||
if (DISM.getKind() == llvm::SourceMgr::DK_Error)
|
||||
++global.errors;
|
||||
return inlineAsmDiagnostic(irs, DISM.getSMDiag(), DISM.getLocCookie());
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
namespace ldc {
|
||||
|
@ -265,7 +287,12 @@ void CodeGenerator::writeAndFreeLLModule(const char *filename) {
|
|||
llvm::Metadata *IdentNode[] = {llvm::MDString::get(ir_->context(), Version)};
|
||||
IdentMetadata->addOperand(llvm::MDNode::get(ir_->context(), IdentNode));
|
||||
|
||||
#if LDC_LLVM_VER < 1300
|
||||
context_.setInlineAsmDiagnosticHandler(inlineAsmDiagnosticHandler, ir_);
|
||||
#else
|
||||
context_.setDiagnosticHandler(
|
||||
std::make_unique<InlineAsmDiagnosticHandler>(ir_));
|
||||
#endif
|
||||
|
||||
std::unique_ptr<llvm::ToolOutputFile> diagnosticsOutputFile =
|
||||
createAndSetDiagnosticsOutputFile(*ir_, context_, filename);
|
||||
|
|
|
@ -715,7 +715,13 @@ void translateArgs(const llvm::SmallVectorImpl<const char *> &ldmdArgs,
|
|||
}
|
||||
} else {
|
||||
const auto ext = ls::path::extension(p);
|
||||
if (ext.equals_lower(".exe")) {
|
||||
if (
|
||||
#if LDC_LLVM_VER >= 1400
|
||||
ext.equals_insensitive(".exe")
|
||||
#else
|
||||
ext.equals_lower(".exe")
|
||||
#endif
|
||||
) {
|
||||
// should be for Windows targets only
|
||||
ldcArgs.push_back(concat("-of=", p));
|
||||
continue;
|
||||
|
|
|
@ -36,6 +36,10 @@ void addMscrtLibs(bool useInternalToolchain, std::vector<std::string> &args) {
|
|||
// We need the vcruntime lib for druntime's exception handling (ldc.eh_msvc).
|
||||
// Pick one of the 4 variants matching the selected main UCRT lib.
|
||||
|
||||
#if LDC_LLVM_VER >= 1400
|
||||
#define contains_lower contains_insensitive
|
||||
#define endswith_lower endswith_insensitive
|
||||
#endif
|
||||
if (useInternalToolchain) {
|
||||
assert(mscrtlibName.contains_lower("vcruntime"));
|
||||
return;
|
||||
|
|
|
@ -11,18 +11,33 @@
|
|||
#include "gen/irstate.h"
|
||||
|
||||
AttrSet::AttrSet(const AttrSet &base, unsigned index, LLAttribute attribute)
|
||||
#if LDC_LLVM_VER >= 1400
|
||||
: set(base.set.addAttributeAtIndex(gIR->context(), index, attribute)) {}
|
||||
#else
|
||||
: set(base.set.addAttribute(gIR->context(), index, attribute)) {}
|
||||
#endif
|
||||
|
||||
AttrSet
|
||||
AttrSet::extractFunctionAndReturnAttributes(const llvm::Function *function) {
|
||||
auto old = function->getAttributes();
|
||||
return {LLAttributeList::get(gIR->context(), old.getFnAttributes(),
|
||||
old.getRetAttributes(), {})};
|
||||
return {LLAttributeList::get(gIR->context(),
|
||||
#if LDC_LLVM_VER >= 1400
|
||||
old.getFnAttrs(),
|
||||
old.getRetAttrs(),
|
||||
#else
|
||||
old.getFnAttributes(),
|
||||
old.getRetAttributes(),
|
||||
#endif
|
||||
{})};
|
||||
}
|
||||
|
||||
AttrSet &AttrSet::add(unsigned index, const llvm::AttrBuilder &builder) {
|
||||
if (builder.hasAttributes()) {
|
||||
#if LDC_LLVM_VER >= 1400
|
||||
set = set.addAttributesAtIndex(gIR->context(), index, builder);
|
||||
#else
|
||||
set = set.addAttributes(gIR->context(), index, builder);
|
||||
#endif
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
|
|
@ -43,6 +43,9 @@ void emitCoverageLinecountInc(const Loc &loc) {
|
|||
case opts::CoverageIncrement::atomic:
|
||||
// Do an atomic increment, so this works when multiple threads are executed.
|
||||
gIR->ir->CreateAtomicRMW(llvm::AtomicRMWInst::Add, ptr, DtoConstUint(1),
|
||||
#if LDC_LLVM_VER >= 1400
|
||||
LLAlign(4),
|
||||
#endif
|
||||
llvm::AtomicOrdering::Monotonic);
|
||||
break;
|
||||
case opts::CoverageIncrement::nonatomic: {
|
||||
|
|
|
@ -37,8 +37,13 @@ struct TempDisableDiscardValueNames {
|
|||
/// Note: don't add function _parameter_ attributes
|
||||
void copyFnAttributes(llvm::Function *wannabe, llvm::Function *idol) {
|
||||
auto attrSet = idol->getAttributes();
|
||||
#if LDC_LLVM_VER >= 1400
|
||||
auto fnAttrSet = attrSet.getFnAttrs();
|
||||
wannabe->addFnAttrs(fnAttrSet);
|
||||
#else
|
||||
auto fnAttrSet = attrSet.getFnAttributes();
|
||||
wannabe->addAttributes(LLAttributeList::FunctionIndex, fnAttrSet);
|
||||
#endif
|
||||
}
|
||||
|
||||
llvm::StringRef exprToString(StringExp *strexp) {
|
||||
|
|
|
@ -508,8 +508,12 @@ bool DtoLowerMagicIntrinsic(IRState *p, FuncDeclaration *fndecl, CallExp *e,
|
|||
fatal();
|
||||
}
|
||||
|
||||
auto ret = p->ir->CreateAtomicCmpXchg(ptr, cmp, val, successOrdering,
|
||||
failureOrdering);
|
||||
auto ret =
|
||||
p->ir->CreateAtomicCmpXchg(ptr, cmp, val,
|
||||
#if LDC_LLVM_VER >= 1400
|
||||
LLMaybeAlign(gDataLayout->getABITypeAlignment(val->getType())),
|
||||
#endif
|
||||
successOrdering, failureOrdering);
|
||||
ret->setWeak(isWeak);
|
||||
|
||||
// we return a struct; allocate on stack and store to both fields manually
|
||||
|
@ -554,6 +558,9 @@ bool DtoLowerMagicIntrinsic(IRState *p, FuncDeclaration *fndecl, CallExp *e,
|
|||
LLValue *val = DtoRVal(exp2);
|
||||
LLValue *ret =
|
||||
p->ir->CreateAtomicRMW(llvm::AtomicRMWInst::BinOp(op), ptr, val,
|
||||
#if LDC_LLVM_VER >= 1400
|
||||
LLMaybeAlign(gDataLayout->getABITypeAlignment(val->getType())),
|
||||
#endif
|
||||
llvm::AtomicOrdering(atomicOrdering));
|
||||
result = new DImValue(exp2->type, ret);
|
||||
return true;
|
||||
|
@ -1028,9 +1035,15 @@ DValue *DtoCallFunction(const Loc &loc, Type *resulttype, DValue *fnval,
|
|||
call->setCallingConv(callconv);
|
||||
}
|
||||
// merge in function attributes set in callOrInvoke
|
||||
#if LDC_LLVM_VER >= 1400
|
||||
attrlist = attrlist.addFnAttributes(
|
||||
gIR->context(),
|
||||
llvm::AttrBuilder(call->getAttributes(), LLAttributeList::FunctionIndex));
|
||||
#else
|
||||
attrlist = attrlist.addAttributes(
|
||||
gIR->context(), LLAttributeList::FunctionIndex,
|
||||
llvm::AttrBuilder(call->getAttributes(), LLAttributeList::FunctionIndex));
|
||||
#endif
|
||||
call->setAttributes(attrlist);
|
||||
|
||||
// Special case for struct constructor calls: For temporaries, using the
|
||||
|
|
|
@ -197,7 +197,11 @@ void applyAttrAllocSize(StructLiteralExp *sle, IrFunction *irFunc) {
|
|||
|
||||
llvm::Function *func = irFunc->getLLVMFunc();
|
||||
|
||||
#if LDC_LLVM_VER >= 1400
|
||||
func->addFnAttrs(builder);
|
||||
#else
|
||||
func->addAttributes(LLAttributeList::FunctionIndex, builder);
|
||||
#endif
|
||||
}
|
||||
|
||||
// @llvmAttr("key", "value")
|
||||
|
@ -414,7 +418,11 @@ void applyFuncDeclUDAs(FuncDeclaration *decl, IrFunction *irFunc) {
|
|||
} else if (ident == Id::udaLLVMAttr) {
|
||||
llvm::AttrBuilder attrs;
|
||||
applyAttrLLVMAttr(sle, attrs);
|
||||
#if LDC_LLVM_VER >= 1400
|
||||
func->addFnAttrs(attrs);
|
||||
#else
|
||||
func->addAttributes(LLAttributeList::FunctionIndex, attrs);
|
||||
#endif
|
||||
} else if (ident == Id::udaLLVMFastMathFlag) {
|
||||
applyAttrLLVMFastMathFlag(sle, irFunc);
|
||||
} else if (ident == Id::udaOptStrategy) {
|
||||
|
|
|
@ -29,14 +29,24 @@ IrFunction::IrFunction(FuncDeclaration *fd)
|
|||
}
|
||||
|
||||
void IrFunction::setNeverInline() {
|
||||
assert(!func->getAttributes().hasAttribute(LLAttributeList::FunctionIndex,
|
||||
assert(!func->getAttributes()
|
||||
#if LDC_LLVM_VER < 1400
|
||||
.hasAttribute(LLAttributeList::FunctionIndex,
|
||||
#else
|
||||
.hasFnAttr(
|
||||
#endif
|
||||
llvm::Attribute::AlwaysInline) &&
|
||||
"function can't be never- and always-inline at the same time");
|
||||
func->addFnAttr(llvm::Attribute::NoInline);
|
||||
}
|
||||
|
||||
void IrFunction::setAlwaysInline() {
|
||||
assert(!func->getAttributes().hasAttribute(LLAttributeList::FunctionIndex,
|
||||
assert(!func->getAttributes()
|
||||
#if LDC_LLVM_VER < 1400
|
||||
.hasAttribute(LLAttributeList::FunctionIndex,
|
||||
#else
|
||||
.hasFnAttr(
|
||||
#endif
|
||||
llvm::Attribute::NoInline) &&
|
||||
"function can't be never- and always-inline at the same time");
|
||||
func->addFnAttr(llvm::Attribute::AlwaysInline);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue