Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp
Show First 20 Lines • Show All 163 Lines • ▼ Show 20 Lines | |||||
MLIRContext &LLVMTypeConverter::getContext() { | MLIRContext &LLVMTypeConverter::getContext() { | ||||
return *getDialect()->getContext(); | return *getDialect()->getContext(); | ||||
} | } | ||||
Type LLVMTypeConverter::getIndexType() { | Type LLVMTypeConverter::getIndexType() { | ||||
return IntegerType::get(&getContext(), getIndexTypeBitwidth()); | return IntegerType::get(&getContext(), getIndexTypeBitwidth()); | ||||
} | } | ||||
LLVM::LLVMPointerType LLVMTypeConverter::getPointer(Type elementType, | |||||
unsigned int addressSpace) { | |||||
if (useOpaquePointers()) | |||||
return LLVM::LLVMPointerType::get(&getContext(), addressSpace); | |||||
return LLVM::LLVMPointerType::get(elementType, addressSpace); | |||||
} | |||||
unsigned LLVMTypeConverter::getPointerBitwidth(unsigned addressSpace) { | unsigned LLVMTypeConverter::getPointerBitwidth(unsigned addressSpace) { | ||||
return options.dataLayout.getPointerSizeInBits(addressSpace); | return options.dataLayout.getPointerSizeInBits(addressSpace); | ||||
} | } | ||||
Type LLVMTypeConverter::convertIndexType(IndexType type) { | Type LLVMTypeConverter::convertIndexType(IndexType type) { | ||||
return getIndexType(); | return getIndexType(); | ||||
} | } | ||||
Show All 11 Lines | Type LLVMTypeConverter::convertComplexType(ComplexType type) { | ||||
auto elementType = convertType(type.getElementType()); | auto elementType = convertType(type.getElementType()); | ||||
return LLVM::LLVMStructType::getLiteral(&getContext(), | return LLVM::LLVMStructType::getLiteral(&getContext(), | ||||
{elementType, elementType}); | {elementType, elementType}); | ||||
} | } | ||||
// Except for signatures, MLIR function types are converted into LLVM | // Except for signatures, MLIR function types are converted into LLVM | ||||
// pointer-to-function types. | // pointer-to-function types. | ||||
Type LLVMTypeConverter::convertFunctionType(FunctionType type) { | Type LLVMTypeConverter::convertFunctionType(FunctionType type) { | ||||
if (options.useOpaquePointers) | |||||
return LLVM::LLVMPointerType::get(type.getContext()); | |||||
gysit: nit: Using `getPointer()` below may also be an option? | |||||
SignatureConversion conversion(type.getNumInputs()); | SignatureConversion conversion(type.getNumInputs()); | ||||
Type converted = | Type converted = | ||||
convertFunctionSignature(type, /*isVariadic=*/false, conversion); | convertFunctionSignature(type, /*isVariadic=*/false, conversion); | ||||
if (!converted) | if (!converted) | ||||
return {}; | return {}; | ||||
return LLVM::LLVMPointerType::get(converted); | return LLVM::LLVMPointerType::get(converted); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 96 Lines • ▼ Show 20 Lines | LLVMTypeConverter::getMemRefDescriptorFields(MemRefType type, | ||||
if (!isStrided(type)) { | if (!isStrided(type)) { | ||||
emitError( | emitError( | ||||
UnknownLoc::get(type.getContext()), | UnknownLoc::get(type.getContext()), | ||||
"conversion to strided form failed either due to non-strided layout " | "conversion to strided form failed either due to non-strided layout " | ||||
"maps (which should have been normalized away) or other reasons"); | "maps (which should have been normalized away) or other reasons"); | ||||
return {}; | return {}; | ||||
} | } | ||||
LLVM::LLVMPointerType ptrTy; | |||||
if (!options.useOpaquePointers) { | |||||
Type elementType = convertType(type.getElementType()); | Type elementType = convertType(type.getElementType()); | ||||
if (!elementType) | if (!elementType) | ||||
return {}; | return {}; | ||||
auto ptrTy = | ptrTy = LLVM::LLVMPointerType::get(elementType, type.getMemorySpaceAsInt()); | ||||
LLVM::LLVMPointerType::get(elementType, type.getMemorySpaceAsInt()); | } else { | ||||
ptrTy = LLVM::LLVMPointerType::get(type.getContext(), | |||||
type.getMemorySpaceAsInt()); | |||||
} | |||||
auto indexTy = getIndexType(); | auto indexTy = getIndexType(); | ||||
SmallVector<Type, 5> results = {ptrTy, ptrTy, indexTy}; | SmallVector<Type, 5> results = {ptrTy, ptrTy, indexTy}; | ||||
auto rank = type.getRank(); | auto rank = type.getRank(); | ||||
if (rank == 0) | if (rank == 0) | ||||
return results; | return results; | ||||
if (unpackAggregates) | if (unpackAggregates) | ||||
Show All 26 Lines | |||||
/// Convert an unranked memref type into a list of non-aggregate LLVM IR types | /// Convert an unranked memref type into a list of non-aggregate LLVM IR types | ||||
/// that will form the unranked memref descriptor. In particular, the fields | /// that will form the unranked memref descriptor. In particular, the fields | ||||
/// for an unranked memref descriptor are: | /// for an unranked memref descriptor are: | ||||
/// 1. index-typed rank, the dynamic rank of this MemRef | /// 1. index-typed rank, the dynamic rank of this MemRef | ||||
/// 2. void* ptr, pointer to the static ranked MemRef descriptor. This will be | /// 2. void* ptr, pointer to the static ranked MemRef descriptor. This will be | ||||
/// stack allocated (alloca) copy of a MemRef descriptor that got casted to | /// stack allocated (alloca) copy of a MemRef descriptor that got casted to | ||||
/// be unranked. | /// be unranked. | ||||
SmallVector<Type, 2> LLVMTypeConverter::getUnrankedMemRefDescriptorFields() { | SmallVector<Type, 2> LLVMTypeConverter::getUnrankedMemRefDescriptorFields() { | ||||
if (options.useOpaquePointers) | |||||
return {getIndexType(), LLVM::LLVMPointerType::get(&getContext())}; | |||||
return {getIndexType(), | return {getIndexType(), | ||||
LLVM::LLVMPointerType::get(IntegerType::get(&getContext(), 8))}; | LLVM::LLVMPointerType::get(IntegerType::get(&getContext(), 8))}; | ||||
} | } | ||||
unsigned | unsigned | ||||
LLVMTypeConverter::getUnrankedMemRefDescriptorSize(UnrankedMemRefType type, | LLVMTypeConverter::getUnrankedMemRefDescriptorSize(UnrankedMemRefType type, | ||||
const DataLayout &layout) { | const DataLayout &layout) { | ||||
// Compute the descriptor size given that of its components indicated above. | // Compute the descriptor size given that of its components indicated above. | ||||
Show All 32 Lines | bool LLVMTypeConverter::canConvertToBarePtr(BaseMemRefType type) { | ||||
return !ShapedType::isDynamic(offset); | return !ShapedType::isDynamic(offset); | ||||
} | } | ||||
/// Convert a memref type to a bare pointer to the memref element type. | /// Convert a memref type to a bare pointer to the memref element type. | ||||
Type LLVMTypeConverter::convertMemRefToBarePtr(BaseMemRefType type) { | Type LLVMTypeConverter::convertMemRefToBarePtr(BaseMemRefType type) { | ||||
if (!canConvertToBarePtr(type)) | if (!canConvertToBarePtr(type)) | ||||
return {}; | return {}; | ||||
if (options.useOpaquePointers) | |||||
return LLVM::LLVMPointerType::get(type.getContext(), | |||||
type.getMemorySpaceAsInt()); | |||||
Type elementType = convertType(type.getElementType()); | Type elementType = convertType(type.getElementType()); | ||||
if (!elementType) | if (!elementType) | ||||
return {}; | return {}; | ||||
return LLVM::LLVMPointerType::get(elementType, type.getMemorySpaceAsInt()); | return LLVM::LLVMPointerType::get(elementType, type.getMemorySpaceAsInt()); | ||||
} | } | ||||
/// Convert an n-D vector type to an LLVM vector type: | /// Convert an n-D vector type to an LLVM vector type: | ||||
/// * 0-D `vector<T>` are converted to vector<1xT> | /// * 0-D `vector<T>` are converted to vector<1xT> | ||||
▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | Type LLVMTypeConverter::packFunctionResults(TypeRange types) { | ||||
return LLVM::LLVMStructType::getLiteral(&getContext(), resultTypes); | return LLVM::LLVMStructType::getLiteral(&getContext(), resultTypes); | ||||
} | } | ||||
Value LLVMTypeConverter::promoteOneMemRefDescriptor(Location loc, Value operand, | Value LLVMTypeConverter::promoteOneMemRefDescriptor(Location loc, Value operand, | ||||
OpBuilder &builder) { | OpBuilder &builder) { | ||||
// Alloca with proper alignment. We do not expect optimizations of this | // Alloca with proper alignment. We do not expect optimizations of this | ||||
// alloca op and so we omit allocating at the entry block. | // alloca op and so we omit allocating at the entry block. | ||||
auto ptrType = LLVM::LLVMPointerType::get(operand.getType()); | |||||
Value one = builder.create<LLVM::ConstantOp>(loc, builder.getI64Type(), | Value one = builder.create<LLVM::ConstantOp>(loc, builder.getI64Type(), | ||||
builder.getIndexAttr(1)); | builder.getIndexAttr(1)); | ||||
LLVM::LLVMPointerType ptrType; | |||||
if (options.useOpaquePointers) { | |||||
ptrType = LLVM::LLVMPointerType::get(&getContext()); | |||||
} else { | |||||
ptrType = LLVM::LLVMPointerType::get(operand.getType()); | |||||
} | |||||
Value allocated = | Value allocated = | ||||
builder.create<LLVM::AllocaOp>(loc, ptrType, one, /*alignment=*/0); | builder.create<LLVM::AllocaOp>(loc, ptrType, operand.getType(), one); | ||||
// Store into the alloca'ed descriptor. | // Store into the alloca'ed descriptor. | ||||
builder.create<LLVM::StoreOp>(loc, operand, allocated); | builder.create<LLVM::StoreOp>(loc, operand, allocated); | ||||
return allocated; | return allocated; | ||||
} | } | ||||
SmallVector<Value, 4> LLVMTypeConverter::promoteOperands(Location loc, | SmallVector<Value, 4> LLVMTypeConverter::promoteOperands(Location loc, | ||||
ValueRange opOperands, | ValueRange opOperands, | ||||
ValueRange operands, | ValueRange operands, | ||||
▲ Show 20 Lines • Show All 77 Lines • Show Last 20 Lines |
nit: Using getPointer() below may also be an option?