From 3ba7dedcd9864a4fb91a0937ca3f570de2d12a62 Mon Sep 17 00:00:00 2001 From: Lukas Zaoral Date: Thu, 10 Sep 2020 17:24:49 +0200 Subject: llvm11: Composite and Sequential types were removed See: https://reviews.llvm.org/D75660 https://reviews.llvm.org/D75661 --- lib/Core/Executor.cpp | 54 +++++++++++++++++++----------------- lib/Core/Executor.h | 5 ++++ lib/Core/GetElementPtrTypeIterator.h | 10 +++++++ 3 files changed, 43 insertions(+), 26 deletions(-) (limited to 'lib') diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp index c0d29272..fac36b71 100644 --- a/lib/Core/Executor.cpp +++ b/lib/Core/Executor.cpp @@ -3270,6 +3270,25 @@ void Executor::updateStates(ExecutionState *current) { removedStates.clear(); } +template +void Executor::computeOffsetsSeqTy(KGEPInstruction *kgepi, + ref &constantOffset, + uint64_t index, const TypeIt it) { + const auto *sq = cast(*it); + uint64_t elementSize = + kmodule->targetData->getTypeStoreSize(sq->getElementType()); + const Value *operand = it.getOperand(); + if (const Constant *c = dyn_cast(operand)) { + ref index = + evalConstant(c)->SExt(Context::get().getPointerWidth()); + ref addend = index->Mul( + ConstantExpr::alloc(elementSize, Context::get().getPointerWidth())); + constantOffset = constantOffset->Add(addend); + } else { + kgepi->indices.emplace_back(index, elementSize); + } +} + template void Executor::computeOffsets(KGEPInstruction *kgepi, TypeIt ib, TypeIt ie) { ref constantOffset = @@ -3282,33 +3301,16 @@ void Executor::computeOffsets(KGEPInstruction *kgepi, TypeIt ib, TypeIt ie) { uint64_t addend = sl->getElementOffset((unsigned) ci->getZExtValue()); constantOffset = constantOffset->Add(ConstantExpr::alloc(addend, Context::get().getPointerWidth())); - } else if (const auto set = dyn_cast(*ii)) { - uint64_t elementSize = - kmodule->targetData->getTypeStoreSize(set->getElementType()); - Value *operand = ii.getOperand(); - if (Constant *c = dyn_cast(operand)) { - ref index = - evalConstant(c)->SExt(Context::get().getPointerWidth()); - ref addend = - index->Mul(ConstantExpr::alloc(elementSize, - Context::get().getPointerWidth())); - constantOffset = constantOffset->Add(addend); - } else { - kgepi->indices.push_back(std::make_pair(index, elementSize)); - } #if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0) - } else if (const auto ptr = dyn_cast(*ii)) { - auto elementSize = - kmodule->targetData->getTypeStoreSize(ptr->getElementType()); - auto operand = ii.getOperand(); - if (auto c = dyn_cast(operand)) { - auto index = evalConstant(c)->SExt(Context::get().getPointerWidth()); - auto addend = index->Mul(ConstantExpr::alloc(elementSize, - Context::get().getPointerWidth())); - constantOffset = constantOffset->Add(addend); - } else { - kgepi->indices.push_back(std::make_pair(index, elementSize)); - } + } else if (isa(*ii)) { + computeOffsetsSeqTy(kgepi, constantOffset, index, ii); + } else if (isa(*ii)) { + computeOffsetsSeqTy(kgepi, constantOffset, index, ii); + } else if (isa(*ii)) { + computeOffsetsSeqTy(kgepi, constantOffset, index, ii); +#else + } else if (isa(*ii)) { + computeOffsetsSeqTy(kgepi, constantOffset, index, ii); #endif } else assert("invalid type" && 0); diff --git a/lib/Core/Executor.h b/lib/Core/Executor.h index 30d1dd92..1614a0f9 100644 --- a/lib/Core/Executor.h +++ b/lib/Core/Executor.h @@ -449,6 +449,11 @@ private: /// bindModuleConstants - Initialize the module constant table. void bindModuleConstants(); + template + void computeOffsetsSeqTy(KGEPInstruction *kgepi, + ref &constantOffset, uint64_t index, + const TypeIt it); + template void computeOffsets(KGEPInstruction *kgepi, TypeIt ib, TypeIt ie); diff --git a/lib/Core/GetElementPtrTypeIterator.h b/lib/Core/GetElementPtrTypeIterator.h index cdbc36bc..87de667d 100644 --- a/lib/Core/GetElementPtrTypeIterator.h +++ b/lib/Core/GetElementPtrTypeIterator.h @@ -65,8 +65,12 @@ class generic_gep_type_iterator llvm::Type *operator*() const { return CurTy; } llvm::Type *getIndexedType() const { +#if LLVM_VERSION_CODE >= LLVM_VERSION(11, 0) + return llvm::GetElementPtrInst::getTypeAtIndex(CurTy, getOperand()); +#else llvm::CompositeType *CT = cast(CurTy); return CT->getTypeAtIndex(getOperand()); +#endif } // This is a non-standard operator->. It allows you to call methods on the @@ -76,8 +80,14 @@ class generic_gep_type_iterator llvm::Value *getOperand() const { return asValue(*OpIt); } generic_gep_type_iterator& operator++() { // Preincrement +#if LLVM_VERSION_CODE >= LLVM_VERSION(11, 0) + if (isa(CurTy) || isa(CurTy) || + isa(CurTy)) { + CurTy = llvm::GetElementPtrInst::getTypeAtIndex(CurTy, getOperand()); +#else if (llvm::CompositeType *CT = dyn_cast(CurTy)) { CurTy = CT->getTypeAtIndex(getOperand()); +#endif #if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0) } else if (auto ptr = dyn_cast(CurTy)) { CurTy = ptr->getElementType(); -- cgit 1.4.1