From 372237487e2494f37ad204b7a0eea3425d919e66 Mon Sep 17 00:00:00 2001 From: Arthur Eubanks Date: Mon, 31 May 2021 16:11:03 -0700 Subject: [PATCH] [OpaquePtr] Remove some uses of PointerType::getElementType() --- llvm/include/llvm/IR/InstrTypes.h | 3 +-- llvm/include/llvm/IR/Instructions.h | 12 ++++++------ llvm/lib/CodeGen/AtomicExpandPass.cpp | 2 +- llvm/lib/ExecutionEngine/Interpreter/Execution.cpp | 2 +- llvm/lib/Transforms/Coroutines/CoroSplit.cpp | 2 +- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/llvm/include/llvm/IR/InstrTypes.h b/llvm/include/llvm/IR/InstrTypes.h index 5b106c200544..802b913aa9f4 100644 --- a/llvm/include/llvm/IR/InstrTypes.h +++ b/llvm/include/llvm/IR/InstrTypes.h @@ -1442,8 +1442,7 @@ public: /// type. void setCalledFunction(FunctionType *FTy, Value *Fn) { this->FTy = FTy; - assert(FTy == cast( - cast(Fn->getType())->getElementType())); + assert(cast(Fn->getType())->isOpaqueOrPointeeTypeMatches(FTy)); // This function doesn't mutate the return type, only the function // type. Seems broken, but I'm just gonna stick an assert in for now. assert(getType() == FTy->getReturnType()); diff --git a/llvm/include/llvm/IR/Instructions.h b/llvm/include/llvm/IR/Instructions.h index a94f5406f3b2..0a1af1026be6 100644 --- a/llvm/include/llvm/IR/Instructions.h +++ b/llvm/include/llvm/IR/Instructions.h @@ -1017,8 +1017,8 @@ public: void setResultElementType(Type *Ty) { ResultElementType = Ty; } Type *getResultElementType() const { - assert(ResultElementType == - cast(getType()->getScalarType())->getElementType()); + assert(cast(getType()->getScalarType()) + ->isOpaqueOrPointeeTypeMatches(ResultElementType)); return ResultElementType; } @@ -1160,8 +1160,8 @@ GetElementPtrInst::GetElementPtrInst(Type *PointeeType, Value *Ptr, Values, InsertBefore), SourceElementType(PointeeType), ResultElementType(getIndexedType(PointeeType, IdxList)) { - assert(ResultElementType == - cast(getType()->getScalarType())->getElementType()); + assert(cast(getType()->getScalarType()) + ->isOpaqueOrPointeeTypeMatches(ResultElementType)); init(Ptr, IdxList, NameStr); } @@ -1174,8 +1174,8 @@ GetElementPtrInst::GetElementPtrInst(Type *PointeeType, Value *Ptr, Values, InsertAtEnd), SourceElementType(PointeeType), ResultElementType(getIndexedType(PointeeType, IdxList)) { - assert(ResultElementType == - cast(getType()->getScalarType())->getElementType()); + assert(cast(getType()->getScalarType()) + ->isOpaqueOrPointeeTypeMatches(ResultElementType)); init(Ptr, IdxList, NameStr); } diff --git a/llvm/lib/CodeGen/AtomicExpandPass.cpp b/llvm/lib/CodeGen/AtomicExpandPass.cpp index 1474573bb41d..c8a7aa31133f 100644 --- a/llvm/lib/CodeGen/AtomicExpandPass.cpp +++ b/llvm/lib/CodeGen/AtomicExpandPass.cpp @@ -441,7 +441,7 @@ bool AtomicExpand::expandAtomicLoadToCmpXchg(LoadInst *LI) { Order = AtomicOrdering::Monotonic; Value *Addr = LI->getPointerOperand(); - Type *Ty = cast(Addr->getType())->getElementType(); + Type *Ty = LI->getType(); Constant *DummyVal = Constant::getNullValue(Ty); Value *Pair = Builder.CreateAtomicCmpXchg( diff --git a/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp b/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp index 62e1ea6e0f0a..770fc9349083 100644 --- a/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp +++ b/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp @@ -1017,7 +1017,7 @@ void Interpreter::SwitchToNewBasicBlock(BasicBlock *Dest, ExecutionContext &SF){ void Interpreter::visitAllocaInst(AllocaInst &I) { ExecutionContext &SF = ECStack.back(); - Type *Ty = I.getType()->getElementType(); // Type to be allocated + Type *Ty = I.getAllocatedType(); // Type to be allocated // Get the number of elements being allocated by the array... unsigned NumElements = diff --git a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp index fb3f3cf3fc25..bc83be3c2cc0 100644 --- a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp +++ b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp @@ -369,7 +369,7 @@ static void createResumeEntryBlock(Function &F, coro::Shape &Shape) { coro::Shape::SwitchFieldIndex::Resume, "ResumeFn.addr"); auto *NullPtr = ConstantPointerNull::get(cast( - cast(GepIndex->getType())->getElementType())); + FrameTy->getTypeAtIndex(coro::Shape::SwitchFieldIndex::Resume))); Builder.CreateStore(NullPtr, GepIndex); } else { auto *GepIndex = Builder.CreateStructGEP(