From 63e8725bc2700f7d19cc2c5846a8f073e6123f7e Mon Sep 17 00:00:00 2001 From: River Riddle Date: Sun, 24 Mar 2019 23:51:05 -0700 Subject: [PATCH] Update some of the derived type classes to use getImpl instead of a static_cast. PiperOrigin-RevId: 240084937 --- mlir/include/mlir/IR/Types.h | 2 +- mlir/lib/IR/StandardTypes.cpp | 26 +++++++++----------------- mlir/lib/IR/Types.cpp | 14 +++++--------- mlir/lib/LLVMIR/IR/LLVMDialect.cpp | 2 +- 4 files changed, 16 insertions(+), 28 deletions(-) diff --git a/mlir/include/mlir/IR/Types.h b/mlir/include/mlir/IR/Types.h index 7a1f3bc..bc18043 100644 --- a/mlir/include/mlir/IR/Types.h +++ b/mlir/include/mlir/IR/Types.h @@ -167,7 +167,7 @@ public: } /// Utility for easy access to the storage instance. - ImplType *getImpl() { return static_cast(type); } + ImplType *getImpl() const { return static_cast(type); } }; using ImplType = TypeStorage; diff --git a/mlir/lib/IR/StandardTypes.cpp b/mlir/lib/IR/StandardTypes.cpp index b9da3b9..21323a0 100644 --- a/mlir/lib/IR/StandardTypes.cpp +++ b/mlir/lib/IR/StandardTypes.cpp @@ -50,9 +50,7 @@ IntegerType IntegerType::getChecked(unsigned width, MLIRContext *context, return Base::getChecked(location, context, StandardTypes::Integer, width); } -unsigned IntegerType::getWidth() const { - return static_cast(type)->width; -} +unsigned IntegerType::getWidth() const { return getImpl()->width; } /// Float Type. @@ -221,9 +219,7 @@ bool VectorType::verifyConstructionInvariants(llvm::Optional loc, return false; } -ArrayRef VectorType::getShape() const { - return static_cast(type)->getShape(); -} +ArrayRef VectorType::getShape() const { return getImpl()->getShape(); } /// TensorType @@ -269,11 +265,7 @@ bool RankedTensorType::verifyConstructionInvariants( } ArrayRef RankedTensorType::getShape() const { - return static_cast(type)->getShape(); -} - -ArrayRef MemRefType::getShape() const { - return static_cast(type)->getShape(); + return getImpl()->getShape(); } /// UnrankedTensorType @@ -351,6 +343,10 @@ MemRefType MemRefType::getImpl(ArrayRef shape, Type elementType, cleanedAffineMapComposition, memorySpace); } +ArrayRef MemRefType::getShape() const { + return static_cast(type)->getShape(); +} + Type MemRefType::getElementType() const { return static_cast(type)->elementType; } @@ -376,11 +372,7 @@ TupleType TupleType::get(ArrayRef elementTypes, MLIRContext *context) { } /// Return the elements types for this tuple. -ArrayRef TupleType::getTypes() const { - return static_cast(type)->getTypes(); -} +ArrayRef TupleType::getTypes() const { return getImpl()->getTypes(); } /// Return the number of element types. -unsigned TupleType::size() const { - return static_cast(type)->size(); -} +unsigned TupleType::size() const { return getImpl()->size(); } diff --git a/mlir/lib/IR/Types.cpp b/mlir/lib/IR/Types.cpp index 6510187..d41af58 100644 --- a/mlir/lib/IR/Types.cpp +++ b/mlir/lib/IR/Types.cpp @@ -41,15 +41,13 @@ FunctionType FunctionType::get(ArrayRef inputs, ArrayRef results, } ArrayRef FunctionType::getInputs() const { - return static_cast(type)->getInputs(); + return getImpl()->getInputs(); } -unsigned FunctionType::getNumResults() const { - return static_cast(type)->numResults; -} +unsigned FunctionType::getNumResults() const { return getImpl()->numResults; } ArrayRef FunctionType::getResults() const { - return static_cast(type)->getResults(); + return getImpl()->getResults(); } /// UnknownType @@ -66,13 +64,11 @@ UnknownType UnknownType::getChecked(Identifier dialect, StringRef typeData, /// Returns the dialect namespace of the unknown type. Identifier UnknownType::getDialectNamespace() const { - return static_cast(type)->dialectNamespace; + return getImpl()->dialectNamespace; } /// Returns the raw type data of the unknown type. -StringRef UnknownType::getTypeData() const { - return static_cast(type)->typeData; -} +StringRef UnknownType::getTypeData() const { return getImpl()->typeData; } /// Verify the construction of an unknown type. bool UnknownType::verifyConstructionInvariants(llvm::Optional loc, diff --git a/mlir/lib/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/LLVMIR/IR/LLVMDialect.cpp index 7f7a00a..b2e0f97 100644 --- a/mlir/lib/LLVMIR/IR/LLVMDialect.cpp +++ b/mlir/lib/LLVMIR/IR/LLVMDialect.cpp @@ -57,7 +57,7 @@ LLVMType LLVMType::get(MLIRContext *context, llvm::Type *llvmType) { } llvm::Type *LLVMType::getUnderlyingType() const { - return static_cast(type)->underlyingType; + return getImpl()->underlyingType; } /*---- LLVM IR Dialect and its registration ----------------------------- */ -- 2.7.4