Changeset View
Changeset View
Standalone View
Standalone View
mlir/lib/IR/MLIRContext.cpp
Show First 20 Lines • Show All 89 Lines • ▼ Show 20 Lines | BuiltinDialect(MLIRContext *context) | ||||
addAttributes<AffineMapAttr, ArrayAttr, DenseIntOrFPElementsAttr, | addAttributes<AffineMapAttr, ArrayAttr, DenseIntOrFPElementsAttr, | ||||
DenseStringElementsAttr, DictionaryAttr, FloatAttr, | DenseStringElementsAttr, DictionaryAttr, FloatAttr, | ||||
SymbolRefAttr, IntegerAttr, IntegerSetAttr, OpaqueAttr, | SymbolRefAttr, IntegerAttr, IntegerSetAttr, OpaqueAttr, | ||||
OpaqueElementsAttr, SparseElementsAttr, StringAttr, TypeAttr, | OpaqueElementsAttr, SparseElementsAttr, StringAttr, TypeAttr, | ||||
UnitAttr>(); | UnitAttr>(); | ||||
addAttributes<CallSiteLoc, FileLineColLoc, FusedLoc, NameLoc, OpaqueLoc, | addAttributes<CallSiteLoc, FileLineColLoc, FusedLoc, NameLoc, OpaqueLoc, | ||||
UnknownLoc>(); | UnknownLoc>(); | ||||
addTypes<ComplexType, FloatType, FunctionType, IndexType, IntegerType, | addTypes<ComplexType, BFloat16Type, Float16Type, Float32Type, Float64Type, | ||||
MemRefType, UnrankedMemRefType, NoneType, OpaqueType, | FunctionType, IndexType, IntegerType, MemRefType, | ||||
RankedTensorType, TupleType, UnrankedTensorType, VectorType>(); | UnrankedMemRefType, NoneType, OpaqueType, RankedTensorType, | ||||
TupleType, UnrankedTensorType, VectorType>(); | |||||
// TODO: These operations should be moved to a different dialect when they | // TODO: These operations should be moved to a different dialect when they | ||||
// have been fully decoupled from the core. | // have been fully decoupled from the core. | ||||
addOperations<FuncOp, ModuleOp, ModuleTerminatorOp>(); | addOperations<FuncOp, ModuleOp, ModuleTerminatorOp>(); | ||||
} | } | ||||
static StringRef getDialectNamespace() { return ""; } | static StringRef getDialectNamespace() { return ""; } | ||||
}; | }; | ||||
} // end anonymous namespace. | } // end anonymous namespace. | ||||
▲ Show 20 Lines • Show All 199 Lines • ▼ Show 20 Lines | public: | ||||
//===--------------------------------------------------------------------===// | //===--------------------------------------------------------------------===// | ||||
// Type uniquing | // Type uniquing | ||||
//===--------------------------------------------------------------------===// | //===--------------------------------------------------------------------===// | ||||
DenseMap<TypeID, const AbstractType *> registeredTypes; | DenseMap<TypeID, const AbstractType *> registeredTypes; | ||||
StorageUniquer typeUniquer; | StorageUniquer typeUniquer; | ||||
/// Cached Type Instances. | /// Cached Type Instances. | ||||
FloatType bf16Ty, f16Ty, f32Ty, f64Ty; | BFloat16Type bf16Ty; | ||||
Float16Type f16Ty; | |||||
Float32Type f32Ty; | |||||
Float64Type f64Ty; | |||||
IndexType indexTy; | IndexType indexTy; | ||||
IntegerType int1Ty, int8Ty, int16Ty, int32Ty, int64Ty, int128Ty; | IntegerType int1Ty, int8Ty, int16Ty, int32Ty, int64Ty, int128Ty; | ||||
NoneType noneType; | NoneType noneType; | ||||
//===--------------------------------------------------------------------===// | //===--------------------------------------------------------------------===// | ||||
// Attribute uniquing | // Attribute uniquing | ||||
//===--------------------------------------------------------------------===// | //===--------------------------------------------------------------------===// | ||||
Show All 29 Lines | MLIRContext::MLIRContext() : impl(new MLIRContextImpl()) { | ||||
getOrCreateDialect<BuiltinDialect>(); | getOrCreateDialect<BuiltinDialect>(); | ||||
registerAllDialects(this); | registerAllDialects(this); | ||||
// Initialize several common attributes and types to avoid the need to lock | // Initialize several common attributes and types to avoid the need to lock | ||||
// the context when accessing them. | // the context when accessing them. | ||||
//// Types. | //// Types. | ||||
/// Floating-point Types. | /// Floating-point Types. | ||||
impl->bf16Ty = TypeUniquer::get<FloatType>(this, StandardTypes::BF16); | impl->bf16Ty = TypeUniquer::get<BFloat16Type>(this, StandardTypes::BF16); | ||||
impl->f16Ty = TypeUniquer::get<FloatType>(this, StandardTypes::F16); | impl->f16Ty = TypeUniquer::get<Float16Type>(this, StandardTypes::F16); | ||||
impl->f32Ty = TypeUniquer::get<FloatType>(this, StandardTypes::F32); | impl->f32Ty = TypeUniquer::get<Float32Type>(this, StandardTypes::F32); | ||||
impl->f64Ty = TypeUniquer::get<FloatType>(this, StandardTypes::F64); | impl->f64Ty = TypeUniquer::get<Float64Type>(this, StandardTypes::F64); | ||||
/// Index Type. | /// Index Type. | ||||
impl->indexTy = TypeUniquer::get<IndexType>(this, StandardTypes::Index); | impl->indexTy = TypeUniquer::get<IndexType>(this, StandardTypes::Index); | ||||
/// Integer Types. | /// Integer Types. | ||||
impl->int1Ty = TypeUniquer::get<IntegerType>(this, StandardTypes::Integer, 1, | impl->int1Ty = TypeUniquer::get<IntegerType>(this, StandardTypes::Integer, 1, | ||||
IntegerType::Signless); | IntegerType::Signless); | ||||
impl->int8Ty = TypeUniquer::get<IntegerType>(this, StandardTypes::Integer, 8, | impl->int8Ty = TypeUniquer::get<IntegerType>(this, StandardTypes::Integer, 8, | ||||
IntegerType::Signless); | IntegerType::Signless); | ||||
impl->int16Ty = TypeUniquer::get<IntegerType>(this, StandardTypes::Integer, | impl->int16Ty = TypeUniquer::get<IntegerType>(this, StandardTypes::Integer, | ||||
▲ Show 20 Lines • Show All 281 Lines • ▼ Show 20 Lines | |||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
// Type uniquing | // Type uniquing | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
/// Returns the storage uniquer used for constructing type storage instances. | /// Returns the storage uniquer used for constructing type storage instances. | ||||
/// This should not be used directly. | /// This should not be used directly. | ||||
StorageUniquer &MLIRContext::getTypeUniquer() { return getImpl().typeUniquer; } | StorageUniquer &MLIRContext::getTypeUniquer() { return getImpl().typeUniquer; } | ||||
FloatType FloatType::get(StandardTypes::Kind kind, MLIRContext *context) { | BFloat16Type BFloat16Type::get(MLIRContext *context) { | ||||
switch (kind) { | |||||
case StandardTypes::BF16: | |||||
return context->getImpl().bf16Ty; | return context->getImpl().bf16Ty; | ||||
case StandardTypes::F16: | } | ||||
Float16Type Float16Type::get(MLIRContext *context) { | |||||
return context->getImpl().f16Ty; | return context->getImpl().f16Ty; | ||||
case StandardTypes::F32: | } | ||||
Float32Type Float32Type::get(MLIRContext *context) { | |||||
return context->getImpl().f32Ty; | return context->getImpl().f32Ty; | ||||
case StandardTypes::F64: | |||||
return context->getImpl().f64Ty; | |||||
default: | |||||
llvm_unreachable("unexpected floating-point kind"); | |||||
} | } | ||||
Float64Type Float64Type::get(MLIRContext *context) { | |||||
return context->getImpl().f64Ty; | |||||
} | } | ||||
/// Get an instance of the IndexType. | /// Get an instance of the IndexType. | ||||
IndexType IndexType::get(MLIRContext *context) { | IndexType IndexType::get(MLIRContext *context) { | ||||
return context->getImpl().indexTy; | return context->getImpl().indexTy; | ||||
} | } | ||||
/// Return an existing integer type instance if one is cached within the | /// Return an existing integer type instance if one is cached within the | ||||
▲ Show 20 Lines • Show All 196 Lines • Show Last 20 Lines |