De-virtualize the RSExportType::getClass().
diff --git a/slang_rs_export_type.cpp b/slang_rs_export_type.cpp
index e0f678c..9324c3d 100644
--- a/slang_rs_export_type.cpp
+++ b/slang_rs_export_type.cpp
@@ -391,8 +391,11 @@
ET->getLLVMType());
}
-RSExportType::RSExportType(RSContext *Context, const llvm::StringRef &Name)
+RSExportType::RSExportType(RSContext *Context,
+ ExportClass Class,
+ const llvm::StringRef &Name)
: mContext(Context),
+ mClass(Class),
// Make a copy on Name since memory stored @Name is either allocated in
// ASTContext or allocated in GetTypeName which will be destroyed later.
mName(Name.data(), Name.size()),
@@ -551,7 +554,8 @@
if ((DT == DataTypeUnknown) || TypeName.empty())
return NULL;
else
- return new RSExportPrimitiveType(Context, TypeName, DT, DK, Normalized);
+ return new RSExportPrimitiveType(Context, ExportClassPrimitive, TypeName,
+ DT, DK, Normalized);
}
RSExportPrimitiveType *RSExportPrimitiveType::Create(RSContext *Context,
@@ -564,10 +568,6 @@
return NULL;
}
-RSExportType::ExportClass RSExportPrimitiveType::getClass() const {
- return RSExportType::ExportClassPrimitive;
-}
-
const llvm::Type *RSExportPrimitiveType::convertToLLVMType() const {
llvm::LLVMContext &C = getRSContext()->getLLVMContext();
@@ -659,10 +659,6 @@
return new RSExportPointerType(Context, TypeName, PointeeET);
}
-RSExportType::ExportClass RSExportPointerType::getClass() const {
- return RSExportType::ExportClassPointer;
-}
-
const llvm::Type *RSExportPointerType::convertToLLVMType() const {
const llvm::Type *PointeeType = mPointeeType->getLLVMType();
return llvm::PointerType::getUnqual(PointeeType);
@@ -757,10 +753,6 @@
return NULL;
}
-RSExportType::ExportClass RSExportVectorType::getClass() const {
- return RSExportType::ExportClassVector;
-}
-
const llvm::Type *RSExportVectorType::convertToLLVMType() const {
const llvm::Type *ElementType = RSExportPrimitiveType::convertToLLVMType();
return llvm::VectorType::get(ElementType, getNumElement());
@@ -825,10 +817,6 @@
return new RSExportMatrixType(Context, TypeName, Dim);
}
-RSExportType::ExportClass RSExportMatrixType::getClass() const {
- return RSExportType::ExportClassMatrix;
-}
-
const llvm::Type *RSExportMatrixType::convertToLLVMType() const {
// Construct LLVM type:
// struct {
@@ -866,10 +854,6 @@
Size);
}
-RSExportType::ExportClass RSExportConstantArrayType::getClass() const {
- return RSExportType::ExportClassConstantArray;
-}
-
const llvm::Type *RSExportConstantArrayType::convertToLLVMType() const {
return llvm::ArrayType::get(mElementType->getLLVMType(), getSize());
}
@@ -945,10 +929,6 @@
return ERT;
}
-RSExportType::ExportClass RSExportRecordType::getClass() const {
- return RSExportType::ExportClassRecord;
-}
-
const llvm::Type *RSExportRecordType::convertToLLVMType() const {
std::vector<const llvm::Type*> FieldTypes;
diff --git a/slang_rs_export_type.h b/slang_rs_export_type.h
index 1d583d9..8c56559 100644
--- a/slang_rs_export_type.h
+++ b/slang_rs_export_type.h
@@ -52,13 +52,16 @@
private:
RSContext *mContext;
+ ExportClass mClass;
std::string mName;
// Cache the result after calling convertToLLVMType() at the first time
mutable const llvm::Type *mLLVMType;
protected:
- RSExportType(RSContext *Context, const llvm::StringRef &Name);
+ RSExportType(RSContext *Context,
+ ExportClass Class,
+ const llvm::StringRef &Name);
// Let's make it private since there're some prerequisites to call this
// function.
@@ -99,7 +102,7 @@
static const clang::Type *GetTypeOfDecl(const clang::DeclaratorDecl *DD);
- virtual ExportClass getClass() const = 0;
+ inline ExportClass getClass() const { return mClass; }
inline const llvm::Type *getLLVMType() const {
if (mLLVMType == NULL)
@@ -208,11 +211,13 @@
static DataType GetDataType(const clang::Type *T);
RSExportPrimitiveType(RSContext *Context,
+ // for derived class to set their type class
+ ExportClass Class,
const llvm::StringRef &Name,
DataType DT,
DataKind DK,
bool Normalized)
- : RSExportType(Context, Name),
+ : RSExportType(Context, Class, Name),
mType(DT),
mKind(DK),
mNormalized(Normalized) {
@@ -231,8 +236,6 @@
static size_t GetSizeInBits(const RSExportPrimitiveType *EPT);
- virtual ExportClass getClass() const;
-
inline DataType getType() const { return mType; }
inline DataKind getKind() const { return mKind; }
inline bool isRSObjectType() const {
@@ -250,7 +253,7 @@
RSExportPointerType(RSContext *Context,
const llvm::StringRef &Name,
const RSExportType *PointeeType)
- : RSExportType(Context, Name),
+ : RSExportType(Context, ExportClassPointer, Name),
mPointeeType(PointeeType) {
return;
}
@@ -265,8 +268,6 @@
public:
static const clang::Type *IntegerType;
- virtual ExportClass getClass() const;
-
inline const RSExportType *getPointeeType() const { return mPointeeType; }
}; // RSExportPointerType
@@ -283,7 +284,8 @@
DataKind DK,
bool Normalized,
unsigned NumElement)
- : RSExportPrimitiveType(Context, Name, DT, DK, Normalized),
+ : RSExportPrimitiveType(Context, ExportClassVector, Name,
+ DT, DK, Normalized),
mNumElement(NumElement) {
return;
}
@@ -302,8 +304,6 @@
public:
static llvm::StringRef GetTypeName(const clang::ExtVectorType *EVT);
- virtual ExportClass getClass() const;
-
inline unsigned getNumElement() const { return mNumElement; }
};
@@ -324,15 +324,13 @@
RSExportMatrixType(RSContext *Context,
const llvm::StringRef &Name,
unsigned Dim)
- : RSExportType(Context, Name),
+ : RSExportType(Context, ExportClassMatrix, Name),
mDim(Dim) {
return;
}
virtual const llvm::Type *convertToLLVMType() const;
public:
- virtual ExportClass getClass() const;
-
// @RT was normalized by calling RSExportType::TypeExportable() before
// calling this.
static RSExportMatrixType *Create(RSContext *Context,
@@ -353,6 +351,7 @@
const RSExportType *ElementType,
unsigned Size)
: RSExportType(Context,
+ ExportClassConstantArray,
DUMMY_TYPE_NAME_FOR_RS_CONSTANT_ARRAY_TYPE),
mElementType(ElementType),
mSize(Size) {
@@ -366,8 +365,6 @@
virtual const llvm::Type *convertToLLVMType() const;
public:
- virtual ExportClass getClass() const;
-
inline unsigned getSize() const { return mSize; }
inline const RSExportType *getElementType() const { return mElementType; }
};
@@ -425,7 +422,7 @@
bool IsPacked,
bool IsArtificial,
size_t AllocSize)
- : RSExportType(Context, Name),
+ : RSExportType(Context, ExportClassRecord, Name),
mIsPacked(IsPacked),
mIsArtificial(IsArtificial),
mAllocSize(AllocSize) {
@@ -443,8 +440,6 @@
virtual const llvm::Type *convertToLLVMType() const;
public:
- virtual ExportClass getClass() const;
-
inline const std::list<const Field*>& getFields() const { return mFields; }
inline bool isPacked() const { return mIsPacked; }
inline bool isArtificial() const { return mIsArtificial; }