Changeset View
Changeset View
Standalone View
Standalone View
mlir/lib/Dialect/LLVMIR/IR/LLVMTypes.cpp
Show All 12 Lines | |||||
#include "TypeDetail.h" | #include "TypeDetail.h" | ||||
#include "mlir/Dialect/LLVMIR/LLVMDialect.h" | #include "mlir/Dialect/LLVMIR/LLVMDialect.h" | ||||
#include "mlir/Dialect/LLVMIR/LLVMTypes.h" | #include "mlir/Dialect/LLVMIR/LLVMTypes.h" | ||||
#include "mlir/IR/DialectImplementation.h" | #include "mlir/IR/DialectImplementation.h" | ||||
#include "mlir/IR/TypeSupport.h" | #include "mlir/IR/TypeSupport.h" | ||||
#include "llvm/ADT/TypeSwitch.h" | |||||
#include "llvm/Support/TypeSize.h" | #include "llvm/Support/TypeSize.h" | ||||
using namespace mlir; | using namespace mlir; | ||||
using namespace mlir::LLVM; | using namespace mlir::LLVM; | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
// LLVMType. | // LLVMType. | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
bool LLVMType::classof(Type type) { | bool LLVMType::classof(Type type) { | ||||
return llvm::isa<LLVMDialect>(type.getDialect()); | return llvm::isa<LLVMDialect>(type.getDialect()); | ||||
} | } | ||||
LLVMDialect &LLVMType::getDialect() { | LLVMDialect &LLVMType::getDialect() { | ||||
return static_cast<LLVMDialect &>(Type::getDialect()); | return static_cast<LLVMDialect &>(Type::getDialect()); | ||||
} | } | ||||
//----------------------------------------------------------------------------// | //----------------------------------------------------------------------------// | ||||
// Misc type utilities. | |||||
llvm::TypeSize LLVMType::getPrimitiveSizeInBits() { | |||||
return llvm::TypeSwitch<LLVMType, llvm::TypeSize>(*this) | |||||
.Case<LLVMHalfType, LLVMBFloatType>( | |||||
[](LLVMType) { return llvm::TypeSize::Fixed(16); }) | |||||
.Case<LLVMFloatType>([](LLVMType) { return llvm::TypeSize::Fixed(32); }) | |||||
.Case<LLVMDoubleType, LLVMX86MMXType>( | |||||
[](LLVMType) { return llvm::TypeSize::Fixed(64); }) | |||||
.Case<LLVMIntegerType>([](LLVMIntegerType intTy) { | |||||
return llvm::TypeSize::Fixed(intTy.getBitWidth()); | |||||
}) | |||||
.Case<LLVMX86FP80Type>([](LLVMType) { return llvm::TypeSize::Fixed(80); }) | |||||
.Case<LLVMPPCFP128Type, LLVMFP128Type>( | |||||
[](LLVMType) { return llvm::TypeSize::Fixed(128); }) | |||||
.Case<LLVMVectorType>([](LLVMVectorType t) { | |||||
llvm::TypeSize elementSize = | |||||
t.getElementType().getPrimitiveSizeInBits(); | |||||
llvm::ElementCount elementCount = t.getElementCount(); | |||||
assert(!elementSize.isScalable() && | |||||
"vector type should have fixed-width elements"); | |||||
return llvm::TypeSize(elementSize.getFixedSize() * elementCount.Min, | |||||
elementCount.Scalable); | |||||
}) | |||||
.Default([](LLVMType) { return llvm::TypeSize::Fixed(0); }); | |||||
mehdi_amini: It is a bit "unsafe" to have a catch all here: we can't easily check that we correctly covered… | |||||
} | |||||
//----------------------------------------------------------------------------// | |||||
// Integer type utilities. | // Integer type utilities. | ||||
bool LLVMType::isIntegerTy(unsigned bitwidth) { | bool LLVMType::isIntegerTy(unsigned bitwidth) { | ||||
if (auto intType = dyn_cast<LLVMIntegerType>()) | if (auto intType = dyn_cast<LLVMIntegerType>()) | ||||
return intType.getBitWidth() == bitwidth; | return intType.getBitWidth() == bitwidth; | ||||
return false; | return false; | ||||
} | } | ||||
unsigned LLVMType::getIntegerBitWidth() { | unsigned LLVMType::getIntegerBitWidth() { | ||||
▲ Show 20 Lines • Show All 463 Lines • Show Last 20 Lines |
It is a bit "unsafe" to have a catch all here: we can't easily check that we correctly covered all the "sized" types.
Can we list all the types here in a assert(isa<...>) ?