Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate LLVM at llvm/llvm-project@3cc311ab8674 #3059

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
278 changes: 278 additions & 0 deletions third_party/llvm/generated.patch
Original file line number Diff line number Diff line change
@@ -1,4 +1,282 @@
Auto generated patch. Do not edit or delete it, even if empty.
diff -ruN --strip-trailing-cr a/mlir/include/mlir/Conversion/LLVMCommon/TypeConverter.h b/mlir/include/mlir/Conversion/LLVMCommon/TypeConverter.h
--- a/mlir/include/mlir/Conversion/LLVMCommon/TypeConverter.h
+++ b/mlir/include/mlir/Conversion/LLVMCommon/TypeConverter.h
@@ -161,6 +161,41 @@
/// Check if a memref type can be converted to a bare pointer.
static bool canConvertToBarePtr(BaseMemRefType type);

+ /// Convert a memref type into a list of LLVM IR types that will form the
+ /// memref descriptor. If `unpackAggregates` is true the `sizes` and `strides`
+ /// arrays in the descriptors are unpacked to individual index-typed elements,
+ /// else they are kept as rank-sized arrays of index type. In particular,
+ /// the list will contain:
+ /// - two pointers to the memref element type, followed by
+ /// - an index-typed offset, followed by
+ /// - (if unpackAggregates = true)
+ /// - one index-typed size per dimension of the memref, followed by
+ /// - one index-typed stride per dimension of the memref.
+ /// - (if unpackArrregates = false)
+ /// - one rank-sized array of index-type for the size of each dimension
+ /// - one rank-sized array of index-type for the stride of each dimension
+ ///
+ /// For example, memref<?x?xf32> is converted to the following list:
+ /// - `!llvm<"float*">` (allocated pointer),
+ /// - `!llvm<"float*">` (aligned pointer),
+ /// - `i64` (offset),
+ /// - `i64`, `i64` (sizes),
+ /// - `i64`, `i64` (strides).
+ /// These types can be recomposed to a memref descriptor struct.
+ SmallVector<Type, 5> getMemRefDescriptorFields(MemRefType type,
+ bool unpackAggregates) const;
+
+ /// Convert an unranked memref type into a list of non-aggregate LLVM IR types
+ /// that will form the unranked memref descriptor. In particular, this list
+ /// contains:
+ /// - an integer rank, followed by
+ /// - a pointer to the memref descriptor struct.
+ /// For example, memref<*xf32> is converted to the following list:
+ /// i64 (rank)
+ /// !llvm<"i8*"> (type-erased pointer).
+ /// These types can be recomposed to a unranked memref descriptor struct.
+ SmallVector<Type, 2> getUnrankedMemRefDescriptorFields() const;
+
protected:
/// Pointer to the LLVM dialect.
LLVM::LLVMDialect *llvmDialect;
@@ -213,41 +248,6 @@
/// Convert a memref type into an LLVM type that captures the relevant data.
Type convertMemRefType(MemRefType type) const;

- /// Convert a memref type into a list of LLVM IR types that will form the
- /// memref descriptor. If `unpackAggregates` is true the `sizes` and `strides`
- /// arrays in the descriptors are unpacked to individual index-typed elements,
- /// else they are kept as rank-sized arrays of index type. In particular,
- /// the list will contain:
- /// - two pointers to the memref element type, followed by
- /// - an index-typed offset, followed by
- /// - (if unpackAggregates = true)
- /// - one index-typed size per dimension of the memref, followed by
- /// - one index-typed stride per dimension of the memref.
- /// - (if unpackArrregates = false)
- /// - one rank-sized array of index-type for the size of each dimension
- /// - one rank-sized array of index-type for the stride of each dimension
- ///
- /// For example, memref<?x?xf32> is converted to the following list:
- /// - `!llvm<"float*">` (allocated pointer),
- /// - `!llvm<"float*">` (aligned pointer),
- /// - `i64` (offset),
- /// - `i64`, `i64` (sizes),
- /// - `i64`, `i64` (strides).
- /// These types can be recomposed to a memref descriptor struct.
- SmallVector<Type, 5> getMemRefDescriptorFields(MemRefType type,
- bool unpackAggregates) const;
-
- /// Convert an unranked memref type into a list of non-aggregate LLVM IR types
- /// that will form the unranked memref descriptor. In particular, this list
- /// contains:
- /// - an integer rank, followed by
- /// - a pointer to the memref descriptor struct.
- /// For example, memref<*xf32> is converted to the following list:
- /// i64 (rank)
- /// !llvm<"i8*"> (type-erased pointer).
- /// These types can be recomposed to a unranked memref descriptor struct.
- SmallVector<Type, 2> getUnrankedMemRefDescriptorFields() const;
-
/// Convert an unranked memref type to an LLVM type that captures the
/// runtime rank and a pointer to the static ranked memref desc
Type convertUnrankedMemRefType(UnrankedMemRefType type) const;
diff -ruN --strip-trailing-cr a/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp b/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp
--- a/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp
+++ b/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp
@@ -44,6 +44,74 @@
const DataLayoutAnalysis *analysis)
: LLVMTypeConverter(ctx, LowerToLLVMOptions(ctx), analysis) {}

+/// Helper function that checks if the given value range is a bare pointer.
+static bool isBarePointer(ValueRange values) {
+ return values.size() == 1 &&
+ isa<LLVM::LLVMPointerType>(values.front().getType());
+};
+
+/// Pack SSA values into an unranked memref descriptor struct.
+static Value packUnrankedMemRefDesc(OpBuilder &builder,
+ UnrankedMemRefType resultType,
+ ValueRange inputs, Location loc,
+ const LLVMTypeConverter &converter) {
+ // Note: Bare pointers are not supported for unranked memrefs because a
+ // memref descriptor cannot be built just from a bare pointer.
+ if (TypeRange(inputs) != converter.getUnrankedMemRefDescriptorFields())
+ return Value();
+ return UnrankedMemRefDescriptor::pack(builder, loc, converter, resultType,
+ inputs);
+}
+
+/// Pack SSA values into a ranked memref descriptor struct.
+static Value packRankedMemRefDesc(OpBuilder &builder, MemRefType resultType,
+ ValueRange inputs, Location loc,
+ const LLVMTypeConverter &converter) {
+ assert(resultType && "expected non-null result type");
+ if (isBarePointer(inputs))
+ return MemRefDescriptor::fromStaticShape(builder, loc, converter,
+ resultType, inputs[0]);
+ if (TypeRange(inputs) ==
+ converter.getMemRefDescriptorFields(resultType,
+ /*unpackAggregates=*/true))
+ return MemRefDescriptor::pack(builder, loc, converter, resultType, inputs);
+ // The inputs are neither a bare pointer nor an unpacked memref descriptor.
+ // This materialization function cannot be used.
+ return Value();
+}
+
+/// MemRef descriptor elements -> UnrankedMemRefType
+static Value unrankedMemRefMaterialization(OpBuilder &builder,
+ UnrankedMemRefType resultType,
+ ValueRange inputs, Location loc,
+ const LLVMTypeConverter &converter) {
+ // An argument materialization must return a value of type
+ // `resultType`, so insert a cast from the memref descriptor type
+ // (!llvm.struct) to the original memref type.
+ Value packed =
+ packUnrankedMemRefDesc(builder, resultType, inputs, loc, converter);
+ if (!packed)
+ return Value();
+ return builder.create<UnrealizedConversionCastOp>(loc, resultType, packed)
+ .getResult(0);
+};
+
+/// MemRef descriptor elements -> MemRefType
+static Value rankedMemRefMaterialization(OpBuilder &builder,
+ MemRefType resultType,
+ ValueRange inputs, Location loc,
+ const LLVMTypeConverter &converter) {
+ // An argument materialization must return a value of type `resultType`,
+ // so insert a cast from the memref descriptor type (!llvm.struct) to the
+ // original memref type.
+ Value packed =
+ packRankedMemRefDesc(builder, resultType, inputs, loc, converter);
+ if (!packed)
+ return Value();
+ return builder.create<UnrealizedConversionCastOp>(loc, resultType, packed)
+ .getResult(0);
+}
+
/// Create an LLVMTypeConverter using custom LowerToLLVMOptions.
LLVMTypeConverter::LLVMTypeConverter(MLIRContext *ctx,
const LowerToLLVMOptions &options,
@@ -166,81 +234,29 @@
.getResult(0);
});

- // Helper function that checks if the given value range is a bare pointer.
- auto isBarePointer = [](ValueRange values) {
- return values.size() == 1 &&
- isa<LLVM::LLVMPointerType>(values.front().getType());
- };
-
- // TODO: For some reason, `this` is nullptr in here, so the LLVMTypeConverter
- // must be passed explicitly.
- auto packUnrankedMemRefDesc =
- [&](OpBuilder &builder, UnrankedMemRefType resultType, ValueRange inputs,
- Location loc, LLVMTypeConverter &converter) -> Value {
- // Note: Bare pointers are not supported for unranked memrefs because a
- // memref descriptor cannot be built just from a bare pointer.
- if (TypeRange(inputs) != converter.getUnrankedMemRefDescriptorFields())
- return Value();
- return UnrankedMemRefDescriptor::pack(builder, loc, converter, resultType,
- inputs);
- };
-
- // MemRef descriptor elements -> UnrankedMemRefType
- auto unrakedMemRefMaterialization = [&](OpBuilder &builder,
- UnrankedMemRefType resultType,
- ValueRange inputs, Location loc) {
- // An argument materialization must return a value of type
- // `resultType`, so insert a cast from the memref descriptor type
- // (!llvm.struct) to the original memref type.
- Value packed =
- packUnrankedMemRefDesc(builder, resultType, inputs, loc, *this);
- if (!packed)
- return Value();
- return builder.create<UnrealizedConversionCastOp>(loc, resultType, packed)
- .getResult(0);
- };
-
- // TODO: For some reason, `this` is nullptr in here, so the LLVMTypeConverter
- // must be passed explicitly.
- auto packRankedMemRefDesc = [&](OpBuilder &builder, MemRefType resultType,
- ValueRange inputs, Location loc,
- LLVMTypeConverter &converter) -> Value {
- assert(resultType && "expected non-null result type");
- if (isBarePointer(inputs))
- return MemRefDescriptor::fromStaticShape(builder, loc, converter,
- resultType, inputs[0]);
- if (TypeRange(inputs) ==
- converter.getMemRefDescriptorFields(resultType,
- /*unpackAggregates=*/true))
- return MemRefDescriptor::pack(builder, loc, converter, resultType,
- inputs);
- // The inputs are neither a bare pointer nor an unpacked memref descriptor.
- // This materialization function cannot be used.
- return Value();
- };
-
- // MemRef descriptor elements -> MemRefType
- auto rankedMemRefMaterialization = [&](OpBuilder &builder,
- MemRefType resultType,
- ValueRange inputs, Location loc) {
- // An argument materialization must return a value of type `resultType`,
- // so insert a cast from the memref descriptor type (!llvm.struct) to the
- // original memref type.
- Value packed =
- packRankedMemRefDesc(builder, resultType, inputs, loc, *this);
- if (!packed)
- return Value();
- return builder.create<UnrealizedConversionCastOp>(loc, resultType, packed)
- .getResult(0);
- };
-
// Argument materializations convert from the new block argument types
// (multiple SSA values that make up a memref descriptor) back to the
// original block argument type.
- addArgumentMaterialization(unrakedMemRefMaterialization);
- addArgumentMaterialization(rankedMemRefMaterialization);
- addSourceMaterialization(unrakedMemRefMaterialization);
- addSourceMaterialization(rankedMemRefMaterialization);
+ addArgumentMaterialization([&](OpBuilder &builder,
+ UnrankedMemRefType resultType,
+ ValueRange inputs, Location loc) {
+ return unrankedMemRefMaterialization(builder, resultType, inputs, loc,
+ *this);
+ });
+ addArgumentMaterialization([&](OpBuilder &builder, MemRefType resultType,
+ ValueRange inputs, Location loc) {
+ return rankedMemRefMaterialization(builder, resultType, inputs, loc, *this);
+ });
+ addSourceMaterialization([&](OpBuilder &builder,
+ UnrankedMemRefType resultType, ValueRange inputs,
+ Location loc) {
+ return unrankedMemRefMaterialization(builder, resultType, inputs, loc,
+ *this);
+ });
+ addSourceMaterialization([&](OpBuilder &builder, MemRefType resultType,
+ ValueRange inputs, Location loc) {
+ return rankedMemRefMaterialization(builder, resultType, inputs, loc, *this);
+ });

// Bare pointer -> Packed MemRef descriptor
addTargetMaterialization([&](OpBuilder &builder, Type resultType,
diff -ruN --strip-trailing-cr a/mlir/lib/Transforms/Utils/DialectConversion.cpp b/mlir/lib/Transforms/Utils/DialectConversion.cpp
--- a/mlir/lib/Transforms/Utils/DialectConversion.cpp
+++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp
@@ -2843,7 +2843,6 @@

LogicalResult TypeConverter::convertType(Type t,
SmallVectorImpl<Type> &results) const {
- assert(this && "expected non-null type converter");
assert(t && "expected non-null type");

{
diff -ruN --strip-trailing-cr a/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel b/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
--- a/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
Expand Down
4 changes: 2 additions & 2 deletions third_party/llvm/workspace.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ load("//third_party:repo.bzl", "tf_http_archive")

def repo(name):
"""Imports LLVM."""
LLVM_COMMIT = "c660b281b60085cbe40d73d692badd43d7708d20"
LLVM_SHA256 = "77714a6dbfab00cb7a8d54ae119770011c9da9d810ea02864b173fce90b4ca14"
LLVM_COMMIT = "3cc311ab8674eab6b9101cdf3823b55ea23d6535"
LLVM_SHA256 = "7d049ac4a90f740a5a624981a5726b1dfee957d526f295a3b3e7c88ed930fffb"

tf_http_archive(
name = name,
Expand Down