Skip to content

Commit

Permalink
[NFC] Remove more uses of PointerType::getElementType() (NFC)
Browse files Browse the repository at this point in the history
Replace more uses which I missed in the first pass with
Type::getPointerElementType().
  • Loading branch information
nikic committed Jan 25, 2022
1 parent aa97bc1 commit 2248728
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
12 changes: 6 additions & 6 deletions llvm/unittests/AsmParser/AsmParserTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ TEST(AsmParserTest, TypeWithSlotMappingParsing) {
ASSERT_TRUE(Ty->isPointerTy());

PointerType *PT = cast<PointerType>(Ty);
Ty = PT->getElementType();
Ty = PT->getPointerElementType();
ASSERT_TRUE(Ty->isIntegerTy());
ASSERT_TRUE(Ty->getPrimitiveSizeInBits() == 32);

Expand All @@ -262,11 +262,11 @@ TEST(AsmParserTest, TypeWithSlotMappingParsing) {
ASSERT_TRUE(Ty->isPointerTy());

PT = cast<PointerType>(Ty);
Ty = PT->getElementType();
Ty = PT->getPointerElementType();
ASSERT_TRUE(Ty->isPointerTy());

PT = cast<PointerType>(Ty);
Ty = PT->getElementType();
Ty = PT->getPointerElementType();
ASSERT_TRUE(Ty->isIntegerTy());
ASSERT_TRUE(Ty->getPrimitiveSizeInBits() == 32);

Expand Down Expand Up @@ -386,7 +386,7 @@ TEST(AsmParserTest, TypeAtBeginningWithSlotMappingParsing) {
ASSERT_TRUE(Read == 4);

PointerType *PT = cast<PointerType>(Ty);
Ty = PT->getElementType();
Ty = PT->getPointerElementType();
ASSERT_TRUE(Ty->isIntegerTy());
ASSERT_TRUE(Ty->getPrimitiveSizeInBits() == 32);

Expand All @@ -397,11 +397,11 @@ TEST(AsmParserTest, TypeAtBeginningWithSlotMappingParsing) {
ASSERT_TRUE(Read == 5);

PT = cast<PointerType>(Ty);
Ty = PT->getElementType();
Ty = PT->getPointerElementType();
ASSERT_TRUE(Ty->isPointerTy());

PT = cast<PointerType>(Ty);
Ty = PT->getElementType();
Ty = PT->getPointerElementType();
ASSERT_TRUE(Ty->isIntegerTy());
ASSERT_TRUE(Ty->getPrimitiveSizeInBits() == 32);

Expand Down
18 changes: 8 additions & 10 deletions mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,10 @@ convertOperationImpl(Operation &opInst, llvm::IRBuilderBase &builder,
if (auto attr = op.getAttrOfType<FlatSymbolRefAttr>("callee"))
return builder.CreateCall(
moduleTranslation.lookupFunction(attr.getValue()), operandsRef);
auto *calleePtrType =
cast<llvm::PointerType>(operandsRef.front()->getType());
auto *calleeType =
cast<llvm::FunctionType>(calleePtrType->getElementType());
return builder.CreateCall(calleeType, operandsRef.front(),
auto *calleeType = operandsRef.front()->getType();
auto *calleeFunctionType =
cast<llvm::FunctionType>(calleeType->getPointerElementType());
return builder.CreateCall(calleeFunctionType, operandsRef.front(),
operandsRef.drop_front());
};

Expand Down Expand Up @@ -349,12 +348,11 @@ convertOperationImpl(Operation &opInst, llvm::IRBuilderBase &builder,
moduleTranslation.lookupBlock(invOp.getSuccessor(0)),
moduleTranslation.lookupBlock(invOp.getSuccessor(1)), operandsRef);
} else {
auto *calleePtrType =
cast<llvm::PointerType>(operandsRef.front()->getType());
auto *calleeType =
cast<llvm::FunctionType>(calleePtrType->getElementType());
auto *calleeType = operandsRef.front()->getType();
auto *calleeFunctionType =
cast<llvm::FunctionType>(calleeType->getPointerElementType());
result = builder.CreateInvoke(
calleeType, operandsRef.front(),
calleeFunctionType, operandsRef.front(),
moduleTranslation.lookupBlock(invOp.getSuccessor(0)),
moduleTranslation.lookupBlock(invOp.getSuccessor(1)),
operandsRef.drop_front());
Expand Down
4 changes: 2 additions & 2 deletions mlir/lib/Target/LLVMIR/TypeFromLLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ class TypeFromLLVMIRTranslatorImpl {

/// Translates the given pointer type.
Type translate(llvm::PointerType *type) {
return LLVM::LLVMPointerType::get(translateType(type->getElementType()),
type->getAddressSpace());
return LLVM::LLVMPointerType::get(
translateType(type->getPointerElementType()), type->getAddressSpace());
}

/// Translates the given structure type.
Expand Down

0 comments on commit 2248728

Please sign in to comment.