Skip to content

Fix compilation with LLVM11 #3322

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

Closed
wants to merge 6 commits into from
Closed
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
3 changes: 2 additions & 1 deletion cmake/Modules/FindLLVM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
# We also want an user-specified LLVM_ROOT_DIR to take precedence over the
# system default locations such as /usr/local/bin. Executing find_program()
# multiples times is the approach recommended in the docs.
set(llvm_config_names llvm-config-10.0 llvm-config100 llvm-config-10
set(llvm_config_names llvm-config-11.0 llvm-config110 llvm-config-11
llvm-config-10.0 llvm-config100 llvm-config-10
llvm-config-9.0 llvm-config90 llvm-config-9
llvm-config-8.0 llvm-config80 llvm-config-8
llvm-config-7.0 llvm-config70 llvm-config-7
Expand Down
10 changes: 8 additions & 2 deletions driver/codegenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
#include "gen/logger.h"
#include "gen/modules.h"
#include "gen/runtime.h"
#if LDC_LLVM_VER >= 900
#if LDC_LLVM_VER >= 1100
#include "llvm/IR/LLVMRemarkStreamer.h"
#elif LDC_LLVM_VER >= 900
#include "llvm/IR/RemarkStreamer.h"
#endif
#include "llvm/Support/FileSystem.h"
Expand Down Expand Up @@ -57,8 +59,12 @@ createAndSetDiagnosticsOutputFile(IRState &irs, llvm::LLVMContext &ctx,
// If there is instrumentation data available, also output function hotness
const bool withHotness = opts::isUsingPGOProfile();

#if LDC_LLVM_VER >= 900
#if LDC_LLVM_VER >= 1100
auto remarksFileOrError = llvm::setupLLVMOptimizationRemarks(
#elif LDC_LLVM_VER >= 900
auto remarksFileOrError = llvm::setupOptimizationRemarks(
#endif
#if LDC_LLVM_VER >= 900
ctx, diagnosticsFilename, "", "", withHotness);
if (llvm::Error e = remarksFileOrError.takeError()) {
irs.dmodule->error("Could not create file %s: %s",
Expand Down
2 changes: 1 addition & 1 deletion driver/toobj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void codegenModule(llvm::TargetMachine &Target, llvm::Module &m,
if (cb == ComputeBackend::SPIRV) {
#ifdef LDC_LLVM_SUPPORTED_TARGET_SPIRV
IF_LOG Logger::println("running createSPIRVWriterPass()");
#if LDC_LLVM_VER >= 900
#if LDC_LLVM_VER >= 900 && LDC_LLVM_VER < 1000
std::ofstream out(filename, std::ofstream::binary);
#else
std::error_code errinfo;
Expand Down
5 changes: 4 additions & 1 deletion gen/dibuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -941,8 +941,11 @@ DIModule DIBuilder::EmitModule(Module *m) {
CUNode,
name, // qualified module name
llvm::StringRef(), // (clang modules specific) ConfigurationMacros
llvm::StringRef(), // (clang modules specific) IncludePath
llvm::StringRef() // (clang modules specific) IncludePath
#if LDC_LLVM_VER < 1100
,
llvm::StringRef() // (clang modules specific) ISysRoot
#endif
);

return irm->diModule;
Expand Down
2 changes: 2 additions & 0 deletions gen/irstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ IRScope::IRScope() : builder(gIR->context()) { begin = nullptr; }

IRScope::IRScope(llvm::BasicBlock *b) : begin(b), builder(b) {}

IRScope::IRScope(const IRScope &other) : begin(other.begin), builder(begin) {}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IRBuilder had its copy constructor deleted...


IRScope &IRScope::operator=(const IRScope &rhs) {
begin = rhs.begin;
builder.SetInsertPoint(begin);
Expand Down
2 changes: 1 addition & 1 deletion gen/irstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct IRScope {
IRBuilder<> builder;

IRScope();
IRScope(const IRScope &) = default;
IRScope(const IRScope &);
explicit IRScope(llvm::BasicBlock *b);

IRScope &operator=(const IRScope &rhs);
Expand Down
4 changes: 2 additions & 2 deletions gen/passes/GarbageCollect2Stack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ class ArrayFI : public TypeInfoFI {
}

Value *promote(CallSite CS, IRBuilder<> &B, const Analysis &A) override {
IRBuilder<> Builder = B;
IRBuilder<> &Builder(B);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hence this change and the one below. I'm pretty sure this is not the right fix but I'm not sure what is.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't make a copy, then we should just use B instead of adding a reference to it. By not making a copy, my guess is that the insertion point of B is changed after leaving this function, whereas previously the insertion point stayed the same?

// If the allocation is of constant size it's best to put it in the
// entry block, so do so if we're not already there.
// For dynamically-sized allocations it's best to avoid the overhead
Expand Down Expand Up @@ -360,7 +360,7 @@ class UntypedMemoryFI : public FunctionInfo {
}

Value *promote(CallSite CS, IRBuilder<> &B, const Analysis &A) override {
IRBuilder<> Builder = B;
IRBuilder<> &Builder = B;
// If the allocation is of constant size it's best to put it in the
// entry block, so do so if we're not already there.
// For dynamically-sized allocations it's best to avoid the overhead
Expand Down
4 changes: 4 additions & 0 deletions gen/uda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,11 @@ void applyAttrLLVMAttr(StructLiteralExp *sle, llvm::AttrBuilder &attrs) {
llvm::StringRef key = getStringElem(sle, 0);
llvm::StringRef value = getStringElem(sle, 1);
if (value.empty()) {
#if LDC_LLVM_VER >= 1100
const auto kind = llvm::Attribute::getAttrKindFromName(key);
#else
const auto kind = llvm::getAttrKindFromName(key);
#endif
if (kind != llvm::Attribute::None) {
attrs.addAttribute(kind);
} else {
Expand Down
8 changes: 4 additions & 4 deletions utils/gen_gccbuiltins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ string dtype(Record* rec, bool readOnlyMem)

string attributes(ListInit* propertyList)
{
string prop =
auto prop =
propertyList->size()
? propertyList->getElementAsRecord(0)->getName() : "";

Expand All @@ -97,8 +97,8 @@ void processRecord(raw_ostream& os, Record& rec, string arch)
if(!rec.getValue("GCCBuiltinName"))
return;

string builtinName = rec.getValueAsString("GCCBuiltinName");
string name = rec.getName();
auto builtinName = rec.getValueAsString("GCCBuiltinName");
string name = string(rec.getName());

if(name.substr(0, 4) != "int_" || name.find(arch) == string::npos)
return;
Expand All @@ -108,7 +108,7 @@ void processRecord(raw_ostream& os, Record& rec, string arch)
name = string("llvm.") + name;

ListInit* propsList = rec.getValueAsListInit("IntrProperties");
string prop =
auto prop =
propsList->size()
? propsList->getElementAsRecord(0)->getName() : "";

Expand Down