Integrate llvm-project at e9c9ee9fe694067ee96643d05d6ac378349386bb (#8585)
* Integrate llvm-project at e9c9ee9fe694067ee96643d05d6ac378349386bb
* Reset third_party/llvm-project: e9c9ee9fe694067ee96643d05d6ac378349386bb (2022-03-15 21:51:12 +0000): [libc][NFC] Fix typos and reduntent code triggering compiler warinings.
* Move MHLO and TF to matching commits
TF: 05f17fca35623f4ab6d275ed95f0e1363c939f73
MHLO: 57288f12595a2ee0488806672a42da59b1e56e13
Piper CL: 435187843
* Fixes for bump LLVM @5e8700ce8bf58bdf0a59eef99c85185a74177555
* Remove uses of `verifier`.
* Fix verification methods after signature change of custom verify methods.
* Fixup fallout from bufferization changes
https://reviews.llvm.org/D121361
https://reviews.llvm.org/D121519
* Fix verifiers of Flow and VM ops.
* Fix lit test.
* Update iree-dialects in integrations.
Co-authored-by: Nicolas Vasilache <ntv@google.com>
Co-authored-by: Stella Laurenzo <stellaraccident@gmail.com>
diff --git a/llvm-external-projects/iree-dialects/lib/Dialect/PyDM/IR/PyDMDialect.cpp b/llvm-external-projects/iree-dialects/lib/Dialect/PyDM/IR/PyDMDialect.cpp
index 1915da7..82381bc 100644
--- a/llvm-external-projects/iree-dialects/lib/Dialect/PyDM/IR/PyDMDialect.cpp
+++ b/llvm-external-projects/iree-dialects/lib/Dialect/PyDM/IR/PyDMDialect.cpp
@@ -33,7 +33,10 @@
using PyBoolType = PYDM::BoolType;
using PyConstantOp = PYDM::ConstantOp;
using PyIntegerType = PYDM::IntegerType;
+using PyListType = PYDM::ListType;
using PyRealType = PYDM::RealType;
+using PyObjectType = PYDM::ObjectType;
+using PyUnionType = PYDM::UnionType;
void IREEPyDMDialect::initialize() {
addTypes<
@@ -115,6 +118,49 @@
return emitError() << "unsupported python integer bit width: " << w;
}
+Type PyIntegerType::parse(mlir::AsmParser &parser) {
+ MLIRContext *ctxt = parser.getContext();
+ auto emitError = [&]() -> InFlightDiagnostic {
+ return parser.emitError(parser.getCurrentLocation());
+ };
+ // Weak
+ if (failed(parser.parseOptionalLess())) return get(ctxt);
+ // AP
+ if (succeeded(parser.parseOptionalStar())) {
+ if (failed(parser.parseGreater())) return Type();
+ return get(ctxt, None);
+ }
+
+ // Explicit
+ bool isSigned;
+ if (succeeded(parser.parseOptionalKeyword("unsigned"))) {
+ isSigned = false;
+ } else {
+ isSigned = true;
+ }
+
+ int width;
+ if (failed(parser.parseInteger(width))) return Type();
+ if (failed(parser.parseGreater())) return Type();
+ if (!isSigned) width = -width;
+ return getChecked(emitError, ctxt, width);
+}
+
+void PyIntegerType::print(mlir::AsmPrinter &printer) const {
+ auto w = getImpl()->bitWidth;
+ if (w) {
+ printer << "<";
+ if (*w == 0) {
+ printer << "*";
+ } else if (*w > 0) {
+ printer << *w;
+ } else {
+ printer << "unsigned " << (-*w);
+ }
+ printer << ">";
+ }
+}
+
BuiltinTypeCode PYDM::IntegerType::getTypeCode() const {
return static_cast<BuiltinTypeCode>(
makeNumericTypeCode(*getNumericCategory(), *getNumericSubTypeCode()));
@@ -170,6 +216,57 @@
}
// ListType
+void PyListType::print(mlir::AsmPrinter &printer) const {
+ if (getImpl()->uniformElementType ||
+ getImpl()->storageClass != CollectionStorageClass::Boxed) {
+ printer << "<";
+ switch (getImpl()->storageClass) {
+ case CollectionStorageClass::Boxed:
+ printer << "boxed";
+ break;
+ case CollectionStorageClass::Empty:
+ printer << "empty";
+ break;
+ case CollectionStorageClass::Unboxed:
+ printer << "unboxed";
+ break;
+ }
+
+ if (getImpl()->uniformElementType) {
+ printer << ",";
+ printer << getImpl()->uniformElementType;
+ }
+ printer << ">";
+ }
+}
+
+Type PyListType::parse(mlir::AsmParser &parser) {
+ MLIRContext *ctxt = parser.getContext();
+ if (parser.parseOptionalLess())
+ return get(ctxt, CollectionStorageClass::Boxed, nullptr);
+
+ Type t;
+ StringRef storageClassKeyword;
+ if (parser.parseKeyword(&storageClassKeyword)) return Type();
+ if (parser.parseComma()) return Type();
+ if (parser.parseType(t)) return Type();
+ if (parser.parseGreater()) return Type();
+
+ CollectionStorageClass storageClass;
+ if (storageClassKeyword == "boxed")
+ storageClass = CollectionStorageClass::Boxed;
+ else if (storageClassKeyword == "empty")
+ storageClass = CollectionStorageClass::Empty;
+ else if (storageClassKeyword == "unboxed")
+ storageClass = CollectionStorageClass::Unboxed;
+ else {
+ parser.emitError(parser.getCurrentLocation(),
+ "expected one of 'boxed', 'empty', 'unboxed'");
+ return Type();
+ }
+ return get(ctxt, storageClass, t);
+}
+
StringRef PYDM::ListType::getPythonTypeName() const { return "list"; }
BuiltinTypeCode PYDM::NoneType::getTypeCode() const {
@@ -206,6 +303,26 @@
StringRef PYDM::NoneType::getPythonTypeName() const { return "None"; }
// ObjectType
+void PyObjectType::print(mlir::AsmPrinter &printer) const {
+ if (getImpl()->primitiveType)
+ printer << "<" << getImpl()->primitiveType << ">";
+}
+
+Type PyObjectType::parse(mlir::AsmParser &parser) {
+ MLIRContext *ctxt = parser.getContext();
+ if (parser.parseOptionalLess()) return get(ctxt, nullptr);
+
+ Type t;
+ if (parser.parseType(t)) return Type();
+ if (parser.parseGreater()) return Type();
+ if (auto primitiveType = t.dyn_cast<PrimitiveType>())
+ return get(ctxt, primitiveType);
+ else {
+ parser.emitError(parser.getNameLoc(), "expected a primitive type");
+ return Type();
+ }
+}
+
BuiltinTypeCode PYDM::ObjectType::getTypeCode() const {
return BuiltinTypeCode::Object;
}
@@ -222,6 +339,26 @@
}
// RealType
+void PyRealType::print(mlir::AsmPrinter &printer) const {
+ auto ft = getImpl()->floatType;
+ if (ft) printer << "<" << ft << ">";
+}
+
+Type PyRealType::parse(mlir::AsmParser &parser) {
+ MLIRContext *ctxt = parser.getContext();
+
+ auto emitError = [&]() -> InFlightDiagnostic {
+ return parser.emitError(parser.getCurrentLocation());
+ };
+ // Weak
+ if (failed(parser.parseOptionalLess())) return get(ctxt);
+ // Explicit
+ FloatType subType;
+ if (failed(parser.parseType(subType))) return Type();
+ if (failed(parser.parseGreater())) return Type();
+ return getChecked(emitError, ctxt, subType);
+}
+
LogicalResult PYDM::RealType::verify(
function_ref<InFlightDiagnostic()> emitError, FloatType floatType) {
if (!floatType) return success();
@@ -295,6 +432,26 @@
// Union type implementation
//------------------------------------------------------------------------------
+void PyUnionType::print(mlir::AsmPrinter &printer) const {
+ llvm::interleaveComma(getAlternatives(), printer);
+}
+
+Type PyUnionType::parse(mlir::AsmParser &parser) {
+ MLIRContext *ctxt = parser.getContext();
+ if (parser.parseOptionalLess()) return get(ctxt, {});
+
+ SmallVector<::mlir::Type> alternatives;
+
+ do {
+ Type type;
+ if (parser.parseType(type)) return Type();
+ alternatives.push_back(type);
+ } while (succeeded(parser.parseOptionalComma()));
+
+ return getChecked([&]() { return parser.emitError(parser.getNameLoc()); },
+ ctxt, alternatives);
+}
+
LogicalResult PYDM::UnionType::verify(
llvm::function_ref<InFlightDiagnostic()> emitError,
ArrayRef<Type> alternatives) {
diff --git a/llvm-external-projects/iree-dialects/lib/Dialect/PyDM/IR/PyDMOps.cpp b/llvm-external-projects/iree-dialects/lib/Dialect/PyDM/IR/PyDMOps.cpp
index cbb07b8..2010688 100644
--- a/llvm-external-projects/iree-dialects/lib/Dialect/PyDM/IR/PyDMOps.cpp
+++ b/llvm-external-projects/iree-dialects/lib/Dialect/PyDM/IR/PyDMOps.cpp
@@ -29,8 +29,6 @@
using PyCallOp = PYDM::CallOp;
using PyFuncOp = PYDM::FuncOp;
-static LogicalResult verify(Operation *) { return success(); }
-
//===----------------------------------------------------------------------===//
// Utilities
//===----------------------------------------------------------------------===//
@@ -439,9 +437,9 @@
::llvm::StringRef FunctionalIfOp::getDefaultDialect() { return "iree_pydm"; }
-static LogicalResult verify(FunctionalIfOp op) {
- if (op.getNumResults() != 0 && op.elseRegion().empty())
- return op.emitOpError("must have an else block if defining values");
+LogicalResult FunctionalIfOp::verify() {
+ if (getNumResults() != 0 && elseRegion().empty())
+ return emitOpError("must have an else block if defining values");
return success();
}
@@ -562,39 +560,34 @@
p, *this, fnType.getInputs(), /*isVariadic=*/false, fnType.getResults());
}
-static LogicalResult verify(PyFuncOp op) {
- // TODO: Enforce invariants.
- return success();
-}
-
//===----------------------------------------------------------------------===//
// MakeListOp
//===----------------------------------------------------------------------===//
-static LogicalResult verify(MakeListOp op) {
- auto listType = op.list().getType().cast<ListType>();
+LogicalResult MakeListOp::verify() {
+ auto listType = list().getType().cast<ListType>();
switch (listType.getStorageClass()) {
case CollectionStorageClass::Boxed:
- for (auto element : op.elements()) {
+ for (auto element : elements()) {
if (!element.getType().isa<ObjectType>()) {
- return op.emitOpError() << "making a list with boxed storage class "
- "must have object elements. Got: "
- << element.getType();
+ return emitOpError() << "making a list with boxed storage class "
+ "must have object elements. Got: "
+ << element.getType();
}
}
break;
case CollectionStorageClass::Unboxed:
- for (auto element : op.elements()) {
+ for (auto element : elements()) {
if (element.getType().isa<ObjectType>()) {
- return op.emitOpError() << "making a list with unboxed storage class "
- "must not have object elements. Got: "
- << element.getType();
+ return emitOpError() << "making a list with unboxed storage class "
+ "must not have object elements. Got: "
+ << element.getType();
}
}
break;
case CollectionStorageClass::Empty:
- if (!op.elements().empty()) {
- return op.emitOpError()
+ if (!elements().empty()) {
+ return emitOpError()
<< "making a list with empty storage class must have zero "
"elements";
}