Skip to content

Commit

Permalink
llvm: address v11-dev compatibility issues (round 2)
Browse files Browse the repository at this point in the history
  • Loading branch information
vchuravy committed Mar 17, 2020
1 parent 8aa0050 commit 4c543cc
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 7 deletions.
17 changes: 16 additions & 1 deletion src/aotcompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,9 @@ void *jl_create_native(jl_array_t *methods, const jl_cgparams_t cgparams)

// process the globals array, before jl_merge_module destroys them
std::vector<std::string> gvars;

for (auto &global : params.globals) {
gvars.push_back(global.second->getName());
gvars.push_back(std::string(global.second->getName()));
data->jl_value_to_llvm[global.first] = gvars.size();
}

Expand Down Expand Up @@ -847,13 +848,23 @@ addPassesToGenerateCode(LLVMTargetMachine *TM, PassManagerBase &PM) {
TargetPassConfig *PassConfig = TM->createPassConfig(PM);
PassConfig->setDisableVerify(false);
PM.add(PassConfig);
#if JL_LLVM_VERSION >= 110000
MachineModuleInfoWrapperPass *MMIWP =
new MachineModuleInfoWrapperPass(TM);
PM.add(MMIWP);
#else
MachineModuleInfo *MMI = new MachineModuleInfo(TM);
PM.add(MMI);
#endif
if (PassConfig->addISelPasses())
return NULL;
PassConfig->addMachinePasses();
PassConfig->setInitialized();
#if JL_LLVM_VERSION >= 110000
return &MMIWP->getMMI().getContext();
#else
return &MMI->getContext();
#endif
}

void jl_strip_llvm_debug(Module *m);
Expand Down Expand Up @@ -894,7 +905,11 @@ jl_value_t *jl_dump_llvm_asm(void *F, const char* asm_variant, const char *debug
std::unique_ptr<MCAsmBackend> MAB(TM->getTarget().createMCAsmBackend(
STI, MRI, TM->Options.MCOptions));
std::unique_ptr<MCCodeEmitter> MCE;
#if JL_LLVM_VERSION >= 110000
auto FOut = std::make_unique<formatted_raw_ostream>(asmfile);
#else
auto FOut = llvm::make_unique<formatted_raw_ostream>(asmfile);
#endif
std::unique_ptr<MCStreamer> S(TM->getTarget().createAsmStreamer(
*Context, std::move(FOut), true,
true, InstPrinter,
Expand Down
6 changes: 6 additions & 0 deletions src/codegen_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,14 @@ struct CountTrackedPointers {
bool derived = false;
CountTrackedPointers(llvm::Type *T);
};

#if JL_LLVM_VERSION >= 110000
unsigned TrackWithShadow(llvm::Value *Src, llvm::Type *T, bool isptr, llvm::Value *Dst, llvm::IRBuilder<> &irbuilder);
std::vector<llvm::Value*> ExtractTrackedValues(llvm::Value *Src, llvm::Type *STy, bool isptr, llvm::IRBuilder<> &irbuilder);
#else
unsigned TrackWithShadow(llvm::Value *Src, llvm::Type *T, bool isptr, llvm::Value *Dst, llvm::IRBuilder<> irbuilder);
std::vector<llvm::Value*> ExtractTrackedValues(llvm::Value *Src, llvm::Type *STy, bool isptr, llvm::IRBuilder<> irbuilder);
#endif

static inline void llvm_dump(llvm::Value *v)
{
Expand Down
45 changes: 39 additions & 6 deletions src/disasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,11 @@ static void jl_dump_asm_internal(
std::string buf;
dbgctx.emit_lineinfo(buf, di_lineIter->second);
if (!buf.empty()) {
#if JL_LLVM_VERSION >= 110000
Streamer->emitRawText(buf);
#else
Streamer->EmitRawText(buf);
#endif
}
}
}
Expand All @@ -905,8 +909,13 @@ static void jl_dump_asm_internal(
else {
dbgctx.emit_lineinfo(buf, di_lineIter->second);
}
if (!buf.empty())
if (!buf.empty()) {
#if JL_LLVM_VERSION >= 110000
Streamer->emitRawText(buf);
#else
Streamer->EmitRawText(buf);
#endif
}
nextLineAddr = (++di_lineIter)->first;
}
}
Expand All @@ -916,8 +925,13 @@ static void jl_dump_asm_internal(
// Uncomment this to output addresses for all instructions
// stream << Index << ": ";
MCSymbol *symbol = DisInfo.lookupSymbol(Fptr+Index);
if (symbol)
if (symbol) {
#if JL_LLVM_VERSION >= 110000
Streamer->emitLabel(symbol);
#else
Streamer->EmitLabel(symbol);
#endif
}
}

MCInst Inst;
Expand All @@ -940,22 +954,33 @@ static void jl_dump_asm_internal(
#endif
if (pass != 0) {
std::ostringstream buf;
if (insSize == 4)
if (insSize == 4) {
buf << "\t.long\t0x" << std::hex
<< std::setfill('0') << std::setw(8)
<< *(uint32_t*)(Fptr+Index);
else
for (uint64_t i=0; i<insSize; ++i)
} else {
for (uint64_t i=0; i<insSize; ++i) {
buf << "\t.byte\t0x" << std::hex
<< std::setfill('0') << std::setw(2)
<< (int)*(uint8_t*)(Fptr+Index+i);
}
#if JL_LLVM_VERSION >= 110000
Streamer->emitRawText(StringRef(buf.str()));
#else
Streamer->EmitRawText(StringRef(buf.str()));
#endif
}
}
break;

case MCDisassembler::SoftFail:
if (pass != 0)
if (pass != 0) {
#if JL_LLVM_VERSION >= 110000
Streamer->emitRawText(StringRef("potentially undefined instruction encoding:"));
#else
Streamer->EmitRawText(StringRef("potentially undefined instruction encoding:"));
#endif
}
// Fall through

case MCDisassembler::Success:
Expand Down Expand Up @@ -987,7 +1012,11 @@ static void jl_dump_asm_internal(
}
}
}
#if JL_LLVM_VERSION >= 110000
Streamer->emitInstruction(Inst, *STI);
#else
Streamer->EmitInstruction(Inst, *STI);
#endif
}
break;
}
Expand All @@ -1001,7 +1030,11 @@ static void jl_dump_asm_internal(
std::string buf;
dbgctx.emit_finish(buf);
if (!buf.empty()) {
#if JL_LLVM_VERSION >= 110000
Streamer->emitRawText(buf);
#else
Streamer->EmitRawText(buf);
#endif
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/llvm-late-gc-lowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1525,7 +1525,11 @@ State LateLowerGCFrame::LocalScan(Function &F) {
return S;
}

#if JL_LLVM_VERSION >= 110000
static Value *ExtractScalar(Value *V, Type *VTy, bool isptr, ArrayRef<unsigned> Idxs, IRBuilder<> &irbuilder) {
#else
static Value *ExtractScalar(Value *V, Type *VTy, bool isptr, ArrayRef<unsigned> Idxs, IRBuilder<> irbuilder) {
#endif
Type *T_int32 = Type::getInt32Ty(V->getContext());
if (isptr) {
std::vector<Value*> IdxList{Idxs.size() + 1};
Expand All @@ -1551,7 +1555,11 @@ static Value *ExtractScalar(Value *V, Type *VTy, bool isptr, ArrayRef<unsigned>
return V;
}

#if JL_LLVM_VERSION >= 110000
std::vector<Value*> ExtractTrackedValues(Value *Src, Type *STy, bool isptr, IRBuilder<> &irbuilder) {
#else
std::vector<Value*> ExtractTrackedValues(Value *Src, Type *STy, bool isptr, IRBuilder<> irbuilder) {
#endif
auto Tracked = TrackCompositeType(STy);
std::vector<Value*> Ptrs;
for (unsigned i = 0; i < Tracked.size(); ++i) {
Expand All @@ -1562,7 +1570,11 @@ std::vector<Value*> ExtractTrackedValues(Value *Src, Type *STy, bool isptr, IRBu
return Ptrs;
}

#if JL_LLVM_VERSION >= 110000
unsigned TrackWithShadow(Value *Src, Type *STy, bool isptr, Value *Dst, IRBuilder<> &irbuilder) {
#else
unsigned TrackWithShadow(Value *Src, Type *STy, bool isptr, Value *Dst, IRBuilder<> irbuilder) {
#endif
auto Ptrs = ExtractTrackedValues(Src, STy, isptr, irbuilder);
for (unsigned i = 0; i < Ptrs.size(); ++i) {
Value *Elem = Ptrs[i];
Expand Down
1 change: 1 addition & 0 deletions src/runtime_ccall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <map>
#include <string>
#include <cstdio>
#include <llvm/ADT/StringMap.h>
#include <llvm/Support/Host.h>
#include <llvm/Support/raw_ostream.h>

Expand Down

0 comments on commit 4c543cc

Please sign in to comment.