diff --git a/gen/asmstmt.cpp b/gen/asmstmt.cpp index 015792d6d9..aaea0730e9 100644 --- a/gen/asmstmt.cpp +++ b/gen/asmstmt.cpp @@ -746,8 +746,7 @@ void CompoundAsmStatement_toIR(CompoundAsmStatement *stmt, IRState *p) { // make new blocks llvm::BasicBlock *bb = p->insertBB("afterasmgotoforwarder"); - llvm::LoadInst *val = - p->ir->CreateLoad(jump_target, "__llvm_jump_target_value"); + auto val = DtoLoad(jump_target, "__llvm_jump_target_value"); llvm::SwitchInst *sw = p->ir->CreateSwitch(val, bb, gotoToVal.size()); // add all cases diff --git a/gen/classes.cpp b/gen/classes.cpp index 5ec0080e54..e5fec01c4f 100644 --- a/gen/classes.cpp +++ b/gen/classes.cpp @@ -278,10 +278,9 @@ DValue *DtoCastClass(const Loc &loc, DValue *val, Type *_to) { LLValue *orig = DtoRVal(val); LLValue *v = orig; if (offset != 0) { + assert(offset > 0); v = DtoBitCast(v, getVoidPtrType()); - LLValue *off = - LLConstantInt::get(LLType::getInt32Ty(gIR->context()), offset); - v = gIR->ir->CreateGEP(v, off); + v = DtoGEP1(v, DtoConstUint(offset)); } IF_LOG { Logger::cout() << "V = " << *v << std::endl; diff --git a/gen/coverage.cpp b/gen/coverage.cpp index 6959a1296d..06eff18c9b 100644 --- a/gen/coverage.cpp +++ b/gen/coverage.cpp @@ -33,10 +33,10 @@ void emitCoverageLinecountInc(const Loc &loc) { // Increment the line counter: // Get GEP into _d_cover_data array... + LLType *i32Type = LLType::getInt32Ty(gIR->context()); LLConstant *idxs[] = {DtoConstUint(0), DtoConstUint(line)}; LLValue *ptr = llvm::ConstantExpr::getGetElementPtr( - LLArrayType::get(LLType::getInt32Ty(gIR->context()), m->numlines), - m->d_cover_data, idxs, true); + LLArrayType::get(i32Type, m->numlines), m->d_cover_data, idxs, true); // ...and generate the "increment" instruction(s) switch (opts::coverageIncrement) { case opts::CoverageIncrement::_default: // fallthrough @@ -51,7 +51,11 @@ void emitCoverageLinecountInc(const Loc &loc) { case opts::CoverageIncrement::nonatomic: { // Do a non-atomic increment, user is responsible for correct results with // multithreaded execution - llvm::LoadInst *load = gIR->ir->CreateAlignedLoad(ptr, LLAlign(4)); + llvm::LoadInst *load = gIR->ir->CreateAlignedLoad( +#if LDC_LLVM_VER >= 800 + i32Type, +#endif + ptr, LLAlign(4)); llvm::StoreInst *store = gIR->ir->CreateAlignedStore( gIR->ir->CreateAdd(load, DtoConstUint(1)), ptr, LLAlign(4)); // add !nontemporal attribute, to inform the optimizer that caching is not diff --git a/gen/moduleinfo.cpp b/gen/moduleinfo.cpp index d371a681cd..f61b3892f8 100644 --- a/gen/moduleinfo.cpp +++ b/gen/moduleinfo.cpp @@ -87,7 +87,11 @@ llvm::Function *buildForwarderFunction( for (auto gate : gates) { assert(getIrGlobal(gate)); const auto val = getIrGlobal(gate)->value; - const auto rval = builder.CreateLoad(val, "vgate"); + const auto rval = builder.CreateLoad( +#if LDC_LLVM_VER >= 800 + getPointeeType(val), +#endif + val, "vgate"); const auto res = builder.CreateAdd(rval, DtoConstUint(1), "vgate"); builder.CreateStore(res, val); } diff --git a/gen/modules.cpp b/gen/modules.cpp index f2a5a8ce42..472d5b05d4 100644 --- a/gen/modules.cpp +++ b/gen/modules.cpp @@ -164,7 +164,11 @@ LLFunction *build_module_reference_and_ctor(const char *moduleMangle, gIR->DBuilder.EmitModuleCTor(ctor, fname.c_str()); // get current beginning - LLValue *curbeg = builder.CreateLoad(mref, "current"); + LLValue *curbeg = builder.CreateLoad( +#if LDC_LLVM_VER >= 800 + modulerefPtrTy, +#endif + mref, "current"); // put current beginning as the next of this one LLValue *gep = builder.CreateStructGEP( diff --git a/gen/passes/DLLImportRelocation.cpp b/gen/passes/DLLImportRelocation.cpp index e48f56d082..b01bed1848 100644 --- a/gen/passes/DLLImportRelocation.cpp +++ b/gen/passes/DLLImportRelocation.cpp @@ -184,12 +184,16 @@ private: Value *address = currentGlobal; for (auto i : currentGepPath) { + auto t = address->getType()->getPointerElementType(); if (i <= 0xFFFFFFFFu) { - address = b.CreateConstInBoundsGEP2_32( - address->getType()->getPointerElementType(), address, 0, - static_cast(i)); + address = b.CreateConstInBoundsGEP2_32(t, address, 0, + static_cast(i)); } else { - address = b.CreateConstInBoundsGEP2_64(address, 0, i); + address = b.CreateConstInBoundsGEP2_64( +#if LDC_LLVM_VER >= 800 + t, +#endif + address, 0, i); } } @@ -207,9 +211,13 @@ private: auto ifbb = BasicBlock::Create(m.getContext(), "if", ctor); auto endbb = BasicBlock::Create(m.getContext(), "endif", ctor); - auto isStillNull = - b.CreateICmp(CmpInst::ICMP_EQ, b.CreateLoad(address, false), - Constant::getNullValue(t)); + auto isStillNull = b.CreateICmp(CmpInst::ICMP_EQ, + b.CreateLoad( +#if LDC_LLVM_VER >= 800 + t, +#endif + address, false), + Constant::getNullValue(t)); b.CreateCondBr(isStillNull, ifbb, endbb); b.SetInsertPoint(ifbb); diff --git a/gen/statements.cpp b/gen/statements.cpp index afa64aad7d..3bd160a88e 100644 --- a/gen/statements.cpp +++ b/gen/statements.cpp @@ -1365,7 +1365,7 @@ public: PGO.emitCounterIncrement(stmt); // get value for this iteration - LLValue *loadedKey = irs->ir->CreateLoad(keyvar); + LLValue *loadedKey = DtoLoad(keyvar); LLValue *gep = DtoGEP1(val, loadedKey); if (!stmt->value->isRef() && !stmt->value->isOut()) { diff --git a/gen/tocall.cpp b/gen/tocall.cpp index 32949b9ad8..2b0e26a031 100644 --- a/gen/tocall.cpp +++ b/gen/tocall.cpp @@ -451,7 +451,7 @@ bool DtoLowerMagicIntrinsic(IRState *p, FuncDeclaration *fndecl, CallExp *e, int atomicOrdering = (*e->arguments)[1]->toInteger(); LLValue *ptr = DtoRVal(exp); - LLType *pointeeType = ptr->getType()->getContainedType(0); + LLType *pointeeType = getPointeeType(ptr); Type *retType = exp->type->nextOf(); if (!pointeeType->isIntegerTy()) { @@ -465,13 +465,18 @@ bool DtoLowerMagicIntrinsic(IRState *p, FuncDeclaration *fndecl, CallExp *e, } } - llvm::LoadInst *load = p->ir->CreateLoad(ptr); - if (auto alignment = getTypeAllocSize(load->getType())) { + const auto loadedType = getPointeeType(ptr); + llvm::LoadInst *load = p->ir->CreateLoad( +#if LDC_LLVM_VER >= 800 + loadedType, +#endif + ptr); + if (auto alignment = getTypeAllocSize(loadedType)) { load->setAlignment(LLAlign(alignment)); } load->setAtomic(llvm::AtomicOrdering(atomicOrdering)); llvm::Value *val = load; - if (val->getType() != pointeeType) { + if (loadedType != pointeeType) { val = DtoAllocaDump(val, retType); result = new DLValue(retType, val); } else { diff --git a/gen/tollvm.cpp b/gen/tollvm.cpp index 2c31918652..6d4a370ee7 100644 --- a/gen/tollvm.cpp +++ b/gen/tollvm.cpp @@ -502,14 +502,24 @@ LLConstant *DtoConstString(const char *str) { //////////////////////////////////////////////////////////////////////////////// +namespace { +llvm::LoadInst *DtoLoadImpl(LLValue *src, const char *name) { + return gIR->ir->CreateLoad( +#if LDC_LLVM_VER >= 800 + getPointeeType(src), +#endif + src, name); +} +} + LLValue *DtoLoad(LLValue *src, const char *name) { - return gIR->ir->CreateLoad(src, name); + return DtoLoadImpl(src, name); } // Like DtoLoad, but the pointer is guaranteed to be aligned appropriately for // the type. LLValue *DtoAlignedLoad(LLValue *src, const char *name) { - llvm::LoadInst *ld = gIR->ir->CreateLoad(src, name); + llvm::LoadInst *ld = DtoLoadImpl(src, name); if (auto alignment = getABITypeAlign(ld->getType())) { ld->setAlignment(LLAlign(alignment)); } @@ -517,7 +527,7 @@ LLValue *DtoAlignedLoad(LLValue *src, const char *name) { } LLValue *DtoVolatileLoad(LLValue *src, const char *name) { - llvm::LoadInst *ld = gIR->ir->CreateLoad(src, name); + llvm::LoadInst *ld = DtoLoadImpl(src, name); ld->setVolatile(true); return ld; } diff --git a/gen/trycatchfinally.cpp b/gen/trycatchfinally.cpp index aaed9d3f21..ef1b7d821f 100644 --- a/gen/trycatchfinally.cpp +++ b/gen/trycatchfinally.cpp @@ -255,7 +255,11 @@ void emitBeginCatchMSVC(IRState &irs, Catch *ctch, if (cpyObj) { // assign the caught exception to the location in the closure - auto val = irs.ir->CreateLoad(exnObj); + auto val = irs.ir->CreateLoad( +#if LDC_LLVM_VER >= 800 + getPointeeType(exnObj), +#endif + exnObj); irs.ir->CreateStore(val, cpyObj); exnObj = cpyObj; } @@ -698,8 +702,9 @@ llvm::BasicBlock *TryCatchFinallyScopes::emitLandingPad() { irs.ir->CreateStore(ehPtr, getOrCreateEhPtrSlot()); llvm::Value *ehSelector = DtoExtractValue(landingPad, 1); + const auto ehSelectorType = ehSelector->getType(); if (!ehSelectorSlot) - ehSelectorSlot = DtoRawAlloca(ehSelector->getType(), 0, "eh.selector"); + ehSelectorSlot = DtoRawAlloca(ehSelectorType, 0, "eh.selector"); irs.ir->CreateStore(ehSelector, ehSelectorSlot); // Add landingpad clauses, emit finallys and 'if' chain to catch the @@ -738,9 +743,13 @@ llvm::BasicBlock *TryCatchFinallyScopes::emitLandingPad() { // Compare the selector value from the unwinder against the expected // one and branch accordingly. - irs.ir->CreateCondBr( - irs.ir->CreateICmpEQ(irs.ir->CreateLoad(ehSelectorSlot), ehTypeId), - cb.bodyBB, mismatchBB, cb.branchWeights); + irs.ir->CreateCondBr(irs.ir->CreateICmpEQ(irs.ir->CreateLoad( +#if LDC_LLVM_VER >= 800 + ehSelectorType, +#endif + ehSelectorSlot), + ehTypeId), + cb.bodyBB, mismatchBB, cb.branchWeights); irs.ir->SetInsertPoint(mismatchBB); } }