[mlir] Remove static constructors from LLVMType

LLVMType contains numerous static constructors that were initially introduced
for API compatibility with LLVM. Most of these merely forward to arguments to
`SpecificType::get` (MLIR defines classes for all types, unlike LLVM IR), while
some introduce subtle semantics differences due to different modeling of MLIR
types (e.g., structs are not auto-renamed in case of conflicts). Furthermore,
these constructors don't match MLIR idioms and actively prevent us from making
the LLVM dialect type system more open. Remove them and use `SpecificType::get`
instead.

Depends On D93680

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D93681
This commit is contained in:
Alex Zinenko
2020-12-22 11:22:56 +01:00
parent eb9483b210
commit 7ed9cfc7b1
23 changed files with 267 additions and 415 deletions

View File

@@ -209,7 +209,7 @@ static LogicalResult getIndexedPtrs(ConversionPatternRewriter &rewriter,
if (failed(getBase(rewriter, loc, memref, memRefType, base)))
return failure();
auto pType = MemRefDescriptor(memref).getElementPtrType();
auto ptrsType = LLVM::LLVMType::getVectorTy(pType, vType.getDimSize(0));
auto ptrsType = LLVM::LLVMFixedVectorType::get(pType, vType.getDimSize(0));
ptrs = rewriter.create<LLVM::GEPOp>(loc, ptrsType, base, indices);
return success();
}
@@ -748,7 +748,7 @@ public:
// Remaining extraction of element from 1-D LLVM vector
auto position = positionAttrs.back().cast<IntegerAttr>();
auto i64Type = LLVM::LLVMType::getInt64Ty(rewriter.getContext());
auto i64Type = LLVM::LLVMIntegerType::get(rewriter.getContext(), 64);
auto constant = rewriter.create<LLVM::ConstantOp>(loc, i64Type, position);
extracted =
rewriter.create<LLVM::ExtractElementOp>(loc, extracted, constant);
@@ -856,7 +856,7 @@ public:
}
// Insertion of an element into a 1-D LLVM vector.
auto i64Type = LLVM::LLVMType::getInt64Ty(rewriter.getContext());
auto i64Type = LLVM::LLVMIntegerType::get(rewriter.getContext(), 64);
auto constant = rewriter.create<LLVM::ConstantOp>(loc, i64Type, position);
Value inserted = rewriter.create<LLVM::InsertElementOp>(
loc, typeConverter->convertType(oneDVectorType), extracted,
@@ -1123,7 +1123,7 @@ public:
}))
return failure();
auto int64Ty = LLVM::LLVMType::getInt64Ty(rewriter.getContext());
auto int64Ty = LLVM::LLVMIntegerType::get(rewriter.getContext(), 64);
// Create descriptor.
auto desc = MemRefDescriptor::undef(rewriter, loc, llvmTargetDescriptorTy);
@@ -1362,11 +1362,11 @@ private:
switch (conversion) {
case PrintConversion::ZeroExt64:
value = rewriter.create<ZeroExtendIOp>(
loc, value, LLVM::LLVMType::getInt64Ty(rewriter.getContext()));
loc, value, LLVM::LLVMIntegerType::get(rewriter.getContext(), 64));
break;
case PrintConversion::SignExt64:
value = rewriter.create<SignExtendIOp>(
loc, value, LLVM::LLVMType::getInt64Ty(rewriter.getContext()));
loc, value, LLVM::LLVMIntegerType::get(rewriter.getContext(), 64));
break;
case PrintConversion::None:
break;
@@ -1410,27 +1410,25 @@ private:
OpBuilder moduleBuilder(module.getBodyRegion());
return moduleBuilder.create<LLVM::LLVMFuncOp>(
op->getLoc(), name,
LLVM::LLVMType::getFunctionTy(
LLVM::LLVMType::getVoidTy(op->getContext()), params,
/*isVarArg=*/false));
LLVM::LLVMFunctionType::get(LLVM::LLVMVoidType::get(op->getContext()),
params));
}
// Helpers for method names.
Operation *getPrintI64(Operation *op) const {
return getPrint(op, "printI64",
LLVM::LLVMType::getInt64Ty(op->getContext()));
LLVM::LLVMIntegerType::get(op->getContext(), 64));
}
Operation *getPrintU64(Operation *op) const {
return getPrint(op, "printU64",
LLVM::LLVMType::getInt64Ty(op->getContext()));
LLVM::LLVMIntegerType::get(op->getContext(), 64));
}
Operation *getPrintFloat(Operation *op) const {
return getPrint(op, "printF32",
LLVM::LLVMType::getFloatTy(op->getContext()));
return getPrint(op, "printF32", LLVM::LLVMFloatType::get(op->getContext()));
}
Operation *getPrintDouble(Operation *op) const {
return getPrint(op, "printF64",
LLVM::LLVMType::getDoubleTy(op->getContext()));
LLVM::LLVMDoubleType::get(op->getContext()));
}
Operation *getPrintOpen(Operation *op) const {
return getPrint(op, "printOpen", {});