[llvm-branch-commits] [mlir] [draft] Dialect Conversion without Rollback (PR #93412)
@@ -1053,3 +1055,241 @@ LogicalResult mlir::applyOpPatternsAndFold( }); return converged; } + +//===--===// +// One-Shot Dialect Conversion Infrastructure +//===--===// + +namespace { +/// A conversion rewriter for the One-Shot Dialect Conversion. This rewriter +/// immediately materializes all IR changes. It derives from +/// `ConversionPatternRewriter` so that the existing conversion patterns can +/// be used with the One-Shot Dialect Conversion. +class OneShotConversionPatternRewriter : public ConversionPatternRewriter { +public: + OneShotConversionPatternRewriter(MLIRContext *ctx) + : ConversionPatternRewriter(ctx) {} + + bool canRecoverFromRewriteFailure() const override { return false; } + + void replaceOp(Operation *op, ValueRange newValues) override; + + void replaceOp(Operation *op, Operation *newOp) override { +replaceOp(op, newOp->getResults()); + } + + void eraseOp(Operation *op) override { PatternRewriter::eraseOp(op); } + + void eraseBlock(Block *block) override { PatternRewriter::eraseBlock(block); } + + void inlineBlockBefore(Block *source, Block *dest, Block::iterator before, + ValueRange argValues = std::nullopt) override { +PatternRewriter::inlineBlockBefore(source, dest, before, argValues); + } + using PatternRewriter::inlineBlockBefore; + + void startOpModification(Operation *op) override { +PatternRewriter::startOpModification(op); + } + + void finalizeOpModification(Operation *op) override { +PatternRewriter::finalizeOpModification(op); + } + + void cancelOpModification(Operation *op) override { +PatternRewriter::cancelOpModification(op); + } + + void setCurrentTypeConverter(const TypeConverter *converter) override { +typeConverter = converter; + } + + const TypeConverter *getCurrentTypeConverter() const override { +return typeConverter; + } + + LogicalResult getAdapterOperands(StringRef valueDiagTag, + std::optional inputLoc, + ValueRange values, + SmallVector ) override; + +private: + /// Build an unrealized_conversion_cast op or look it up in the cache. + Value buildUnrealizedConversionCast(Location loc, Type type, Value value); + + /// The current type converter. + const TypeConverter *typeConverter; + + /// A cache for unrealized_conversion_casts. To ensure that identical casts + /// are not built multiple times. + DenseMap, Value> castCache; +}; + +void OneShotConversionPatternRewriter::replaceOp(Operation *op, + ValueRange newValues) { + assert(op->getNumResults() == newValues.size()); + for (auto [orig, repl] : llvm::zip_equal(op->getResults(), newValues)) { +if (orig.getType() != repl.getType()) { + // Type mismatch: insert unrealized_conversion cast. + replaceAllUsesWith(orig, buildUnrealizedConversionCast( + op->getLoc(), orig.getType(), repl)); +} else { + // Same type: use replacement value directly. + replaceAllUsesWith(orig, repl); +} + } + eraseOp(op); +} + +Value OneShotConversionPatternRewriter::buildUnrealizedConversionCast( +Location loc, Type type, Value value) { + auto it = castCache.find(std::make_pair(value, type)); + if (it != castCache.end()) +return it->second; + + // Insert cast at the beginning of the block (for block arguments) or right + // after the defining op. + OpBuilder::InsertionGuard g(*this); + Block *insertBlock = value.getParentBlock(); + Block::iterator insertPt = insertBlock->begin(); + if (OpResult inputRes = dyn_cast(value)) +insertPt = ++inputRes.getOwner()->getIterator(); + setInsertionPoint(insertBlock, insertPt); + auto castOp = create(loc, type, value); + castCache[std::make_pair(value, type)] = castOp.getOutputs()[0]; + return castOp.getOutputs()[0]; +} + +class ConversionPatternRewriteDriver : public GreedyPatternRewriteDriver { joker-eph wrote: I don't have problem with dialect conversion complexity actually, other than replaceAllUsesWith not doing what it says it does, and the fact that you have to go through the rewriter for these. But you're not changing these aspects are you? > I am reluctant to build something that is not compatible with the large > number of existing conversion patterns. Without rollback you're incompatible anyway, people can't "just adopt it". But otherwise what kind of incompatibility are you worried about here? Greedy is a fixed-point iterative algorithm which has non-trivial cost associated with it. I don't quite get why it is suitable here? https://github.com/llvm/llvm-project/pull/93412 ___ llvm-branch-commits mailing list
[llvm-branch-commits] [mlir] [draft] Dialect Conversion without Rollback (PR #93412)
@@ -1053,3 +1055,241 @@ LogicalResult mlir::applyOpPatternsAndFold( }); return converged; } + +//===--===// +// One-Shot Dialect Conversion Infrastructure +//===--===// + +namespace { +/// A conversion rewriter for the One-Shot Dialect Conversion. This rewriter +/// immediately materializes all IR changes. It derives from +/// `ConversionPatternRewriter` so that the existing conversion patterns can +/// be used with the One-Shot Dialect Conversion. +class OneShotConversionPatternRewriter : public ConversionPatternRewriter { +public: + OneShotConversionPatternRewriter(MLIRContext *ctx) + : ConversionPatternRewriter(ctx) {} + + bool canRecoverFromRewriteFailure() const override { return false; } + + void replaceOp(Operation *op, ValueRange newValues) override; + + void replaceOp(Operation *op, Operation *newOp) override { +replaceOp(op, newOp->getResults()); + } + + void eraseOp(Operation *op) override { PatternRewriter::eraseOp(op); } + + void eraseBlock(Block *block) override { PatternRewriter::eraseBlock(block); } + + void inlineBlockBefore(Block *source, Block *dest, Block::iterator before, + ValueRange argValues = std::nullopt) override { +PatternRewriter::inlineBlockBefore(source, dest, before, argValues); + } + using PatternRewriter::inlineBlockBefore; + + void startOpModification(Operation *op) override { +PatternRewriter::startOpModification(op); + } + + void finalizeOpModification(Operation *op) override { +PatternRewriter::finalizeOpModification(op); + } + + void cancelOpModification(Operation *op) override { +PatternRewriter::cancelOpModification(op); + } + + void setCurrentTypeConverter(const TypeConverter *converter) override { +typeConverter = converter; + } + + const TypeConverter *getCurrentTypeConverter() const override { +return typeConverter; + } + + LogicalResult getAdapterOperands(StringRef valueDiagTag, + std::optional inputLoc, + ValueRange values, + SmallVector ) override; + +private: + /// Build an unrealized_conversion_cast op or look it up in the cache. + Value buildUnrealizedConversionCast(Location loc, Type type, Value value); + + /// The current type converter. + const TypeConverter *typeConverter; + + /// A cache for unrealized_conversion_casts. To ensure that identical casts + /// are not built multiple times. + DenseMap, Value> castCache; +}; + +void OneShotConversionPatternRewriter::replaceOp(Operation *op, + ValueRange newValues) { + assert(op->getNumResults() == newValues.size()); + for (auto [orig, repl] : llvm::zip_equal(op->getResults(), newValues)) { +if (orig.getType() != repl.getType()) { + // Type mismatch: insert unrealized_conversion cast. + replaceAllUsesWith(orig, buildUnrealizedConversionCast( + op->getLoc(), orig.getType(), repl)); +} else { + // Same type: use replacement value directly. + replaceAllUsesWith(orig, repl); +} + } + eraseOp(op); +} + +Value OneShotConversionPatternRewriter::buildUnrealizedConversionCast( +Location loc, Type type, Value value) { + auto it = castCache.find(std::make_pair(value, type)); + if (it != castCache.end()) +return it->second; + + // Insert cast at the beginning of the block (for block arguments) or right + // after the defining op. + OpBuilder::InsertionGuard g(*this); + Block *insertBlock = value.getParentBlock(); + Block::iterator insertPt = insertBlock->begin(); + if (OpResult inputRes = dyn_cast(value)) +insertPt = ++inputRes.getOwner()->getIterator(); + setInsertionPoint(insertBlock, insertPt); + auto castOp = create(loc, type, value); + castCache[std::make_pair(value, type)] = castOp.getOutputs()[0]; + return castOp.getOutputs()[0]; +} + +class ConversionPatternRewriteDriver : public GreedyPatternRewriteDriver { joker-eph wrote: Relying on the greedy driver makes me concerned about the "one shot" aspect. I would really like to see a **simple** implementation, with the minimum amount of bookkeeping (ideally not even a worklist!), and relying on the GreedyPatternRewriteDriver does not really go in this direction right now. https://github.com/llvm/llvm-project/pull/93412 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [mlir] Revise IDE folder structure (PR #89749)
https://github.com/joker-eph approved this pull request. https://github.com/llvm/llvm-project/pull/89749 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [mlir][test] Reorganize the test dialect (PR #89424)
https://github.com/joker-eph approved this pull request. https://github.com/llvm/llvm-project/pull/89424 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [mlir][test] Reorganize the test dialect (PR #89424)
joker-eph wrote: LG, but please make sure to remove all spurious headers from the commit description (seems like it should start at "This PR massively ...") https://github.com/llvm/llvm-project/pull/89424 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [mlir] [mlir][test] Shard and reorganize the test dialect (PR #89424)
@@ -228,6 +332,7 @@ void TestDialect::initialize() { >(); registerOpsSyntax(); addOperations(); + registerTestDialectOperations(this); joker-eph wrote: This the actual "magic" right? You're calling into the generated registration method which dispatch to the shards? What does the: ``` addOperations< #define GET_OP_LIST #include "TestOps.cpp.inc" >(); ``` still do above? https://github.com/llvm/llvm-project/pull/89424 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [CIR][NFC] Add scaffolding for the CIR dialect and CIROps.td (PR #86080)
@@ -0,0 +1,44 @@ +//===- CIRDialect.td - CIR dialect -*- tablegen -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// This file declares the CIR dialect. +// +//===--===// + +#ifndef LLVM_CLANG_CIR_DIALECT_IR_CIRDIALECT +#define LLVM_CLANG_CIR_DIALECT_IR_CIRDIALECT + +include "mlir/IR/OpBase.td" + +def CIR_Dialect : Dialect { + let name = "cir"; + + // A short one-line summary of our dialect. + let summary = "A high-level dialect for analyzing and optimizing Clang " +"supported languages"; + + let cppNamespace = "::mlir::cir"; + + let useDefaultAttributePrinterParser = 0; + let useDefaultTypePrinterParser = 0; + + let extraClassDeclaration = [{ +void registerAttributes(); +void registerTypes(); + +Type parseType(DialectAsmParser ) const override; joker-eph wrote: I think I mentioned it elsewhere, but worth keeping in mind: MLIR didn't intend to diverge from LLVM, it started about at the time where there was this plan to adopt a new style for LLVM: https://llvm.org/docs/Proposals/VariableNames.html So we thought we were just adopting the "new coding style" to limit churn, and unfortunately this didn't pan out for the whole codebase (I think lldb and lld are also using this style now) https://github.com/llvm/llvm-project/pull/86080 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [CIR][NFC] Add scaffolding for the CIR dialect and CIROps.td (PR #86080)
@@ -0,0 +1,44 @@ +//===- CIRDialect.td - CIR dialect -*- tablegen -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// This file declares the CIR dialect. +// +//===--===// + +#ifndef LLVM_CLANG_CIR_DIALECT_IR_CIRDIALECT +#define LLVM_CLANG_CIR_DIALECT_IR_CIRDIALECT + +include "mlir/IR/OpBase.td" + +def CIR_Dialect : Dialect { + let name = "cir"; + + // A short one-line summary of our dialect. + let summary = "A high-level dialect for analyzing and optimizing Clang " +"supported languages"; + + let cppNamespace = "::mlir::cir"; + + let useDefaultAttributePrinterParser = 0; + let useDefaultTypePrinterParser = 0; + + let extraClassDeclaration = [{ +void registerAttributes(); +void registerTypes(); + +Type parseType(DialectAsmParser ) const override; joker-eph wrote: This will be added to generated class which have lower-case starting APIs: consistency within the class seems to prevail to me. You should really expect that all the MLIR code will follow this convention, because it'll be intertwined closely with the MLIR framework. https://github.com/llvm/llvm-project/pull/86080 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [mlir][Interfaces] `ValueBoundsOpInterface`: Fix typo (PR #87976)
joker-eph wrote: Can you provide a test that exercises this? Thanks! https://github.com/llvm/llvm-project/pull/87976 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [MLIR][OpenMP] Introduce the LoopWrapperInterface (PR #87232)
@@ -69,6 +69,74 @@ def ReductionClauseInterface : OpInterface<"ReductionClauseInterface"> { ]; } +def LoopWrapperInterface : OpInterface<"LoopWrapperInterface"> { + let description = [{ +OpenMP operations that can wrap a single loop nest. When taking a wrapper +role, these operations must only contain a single region with a single block +in which there's a single operation and a terminator. That nested operation +must be another loop wrapper or an `omp.loop_nest`. + }]; + + let cppNamespace = "::mlir::omp"; + + let methods = [ +InterfaceMethod< + /*description=*/[{ +Tell whether the operation could be taking the role of a loop wrapper. +That is, it has a single region with a single block in which there are +two operations: another wrapper or `omp.loop_nest` operation and a +terminator. + }], + /*retTy=*/"bool", + /*methodName=*/"isWrapper", + (ins ), [{}], [{ +if ($_op->getNumRegions() != 1) + return false; + +::mlir::Region = $_op->getRegion(0); joker-eph wrote: It depends if anyone outside of this dialect could also implement this interface? (if not then why is it in the public header directory though?) Another dialect implementing this interface could be in another namespace and see this kind of code injected potentially. https://github.com/llvm/llvm-project/pull/87232 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] release/18.x: [ODS][NFC] Cast range.size() to int32_t in accumulation (#85629) (PR #86677)
https://github.com/joker-eph approved this pull request. https://github.com/llvm/llvm-project/pull/86677 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [CIR][NFC] Add scaffolding for the CIR dialect and CIROps.td (PR #86080)
@@ -0,0 +1,46 @@ +//===- CIRTypes.td - CIR dialect types -*- tablegen -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// This file declares the CIR dialect. +// +//===--===// + +#ifndef MLIR_CIR_DIALECT_CIR +#define MLIR_CIR_DIALECT_CIR + +include "mlir/IR/OpBase.td" + +def CIR_Dialect : Dialect { + let name = "cir"; + + // A short one-line summary of our dialect. + let summary = "A high-level dialect for analyzing and optimizing Clang " +"supported languages"; + + let cppNamespace = "::mlir::cir"; + + let useDefaultAttributePrinterParser = 0; + let useDefaultTypePrinterParser = 0; joker-eph wrote: Thread: https://groups.google.com/g/llvm-dev/c/i7TLvzd1OAw/m/cJg8sGnMDAAJ https://github.com/llvm/llvm-project/pull/86080 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [CIR][NFC] Add scaffolding for the CIR dialect and CIROps.td (PR #86080)
https://github.com/joker-eph edited https://github.com/llvm/llvm-project/pull/86080 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [CIR][NFC] Add scaffolding for the CIR dialect and CIROps.td (PR #86080)
@@ -0,0 +1,46 @@ +//===- CIRTypes.td - CIR dialect types -*- tablegen -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// This file declares the CIR dialect. +// +//===--===// + +#ifndef MLIR_CIR_DIALECT_CIR +#define MLIR_CIR_DIALECT_CIR + +include "mlir/IR/OpBase.td" + +def CIR_Dialect : Dialect { + let name = "cir"; + + // A short one-line summary of our dialect. + let summary = "A high-level dialect for analyzing and optimizing Clang " +"supported languages"; + + let cppNamespace = "::mlir::cir"; + + let useDefaultAttributePrinterParser = 0; + let useDefaultTypePrinterParser = 0; joker-eph wrote: Yes, in the early months of MLIR, there was a big discussion on llvm-dev@ about changing the naming convention to start with lower-cases. And it seemed to us that it converged and so on our side we anticipated and updated all the codebase to use the "new" convention. However this didn't carry forward, I don't remember why... (The plan was even documented: https://llvm.org/docs/Proposals/VariableNames.html ) https://github.com/llvm/llvm-project/pull/86080 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [CIR][NFC] Add scaffolding for the CIR dialect and CIROps.td (PR #86080)
@@ -0,0 +1,16 @@ +# This replicates part of the add_mlir_dialect cmake function from MLIR that +# cannot be used here. This happens because it expects to be run inside MLIR +# directory which is not the case for CIR (and also FIR, both have similar +# workarounds). + +# Equivalent to add_mlir_dialect(CIROps cir) +set(LLVM_TARGET_DEFINITIONS CIROps.td) +mlir_tablegen(CIROps.h.inc -gen-op-decls) +mlir_tablegen(CIROps.cpp.inc -gen-op-defs) +mlir_tablegen(CIROpsTypes.h.inc -gen-typedef-decls) +mlir_tablegen(CIROpsTypes.cpp.inc -gen-typedef-defs) +mlir_tablegen(CIROpsDialect.h.inc -gen-dialect-decls) +mlir_tablegen(CIROpsDialect.cpp.inc -gen-dialect-defs) +add_public_tablegen_target(MLIRCIROpsIncGen) +add_dependencies(mlir-headers MLIRCIROpsIncGen) joker-eph wrote: Also: can these lines be abstracted by just calling the `add_mlir_dialect` macro? https://github.com/llvm/llvm-project/pull/86080 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [CIR][NFC] Add scaffolding for the CIR dialect and CIROps.td (PR #86080)
@@ -0,0 +1,46 @@ +//===- CIRTypes.td - CIR dialect types -*- tablegen -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// This file declares the CIR dialect. +// +//===--===// + +#ifndef MLIR_CIR_DIALECT_CIR +#define MLIR_CIR_DIALECT_CIR + +include "mlir/IR/OpBase.td" + +def CIR_Dialect : Dialect { + let name = "cir"; + + // A short one-line summary of our dialect. + let summary = "A high-level dialect for analyzing and optimizing Clang " +"supported languages"; + + let cppNamespace = "::mlir::cir"; + + let useDefaultAttributePrinterParser = 0; + let useDefaultTypePrinterParser = 0; joker-eph wrote: If the comment is on the TableGen code: you don't have a choice here because you're implement the ODS API. These aren't just "data member", they are actually "magic" names used by the tablegen backend. For the C++ code a few lines below, function like `printType()` are override of virtual methods defined in MLIR. https://github.com/llvm/llvm-project/pull/86080 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [CIR][NFC] Add scaffolding for the CIR dialect and CIROps.td (PR #86080)
@@ -0,0 +1,18 @@ +//===-- CIROps.td - CIR dialect definition -*- tablegen -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +/// +/// \file +/// Definition of the CIR dialect +/// +//===--===// + +#ifndef MLIR_CIR_DIALECT_CIR_OPS joker-eph wrote: It not "as well", I believe it should be "instead of `MLIR_`" here? Also `IR` is missing, the path mangles into `CLANG_CIR_DIALECT_IR_CIR_OPS_TD` I think? https://github.com/llvm/llvm-project/pull/86080 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [CIR][NFC] Add scaffolding for the CIR dialect and CIROps.td (PR #86080)
@@ -0,0 +1,16 @@ +# This replicates part of the add_mlir_dialect cmake function from MLIR that +# cannot be used here. This happens because it expects to be run inside MLIR +# directory which is not the case for CIR (and also FIR, both have similar +# workarounds). + +# Equivalent to add_mlir_dialect(CIROps cir) +set(LLVM_TARGET_DEFINITIONS CIROps.td) +mlir_tablegen(CIROps.h.inc -gen-op-decls) +mlir_tablegen(CIROps.cpp.inc -gen-op-defs) +mlir_tablegen(CIROpsTypes.h.inc -gen-typedef-decls) +mlir_tablegen(CIROpsTypes.cpp.inc -gen-typedef-defs) +mlir_tablegen(CIROpsDialect.h.inc -gen-dialect-decls) +mlir_tablegen(CIROpsDialect.cpp.inc -gen-dialect-defs) +add_public_tablegen_target(MLIRCIROpsIncGen) +add_dependencies(mlir-headers MLIRCIROpsIncGen) joker-eph wrote: You're not generating the dialect doc? https://github.com/llvm/llvm-project/pull/86080 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [CIR][NFC] Add scaffolding for the CIR dialect and CIROps.td (PR #86080)
@@ -0,0 +1,46 @@ +//===- CIRTypes.td - CIR dialect types -*- tablegen -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// This file declares the CIR dialect. +// +//===--===// + +#ifndef MLIR_CIR_DIALECT_CIR +#define MLIR_CIR_DIALECT_CIR + +include "mlir/IR/OpBase.td" + +def CIR_Dialect : Dialect { + let name = "cir"; + + // A short one-line summary of our dialect. + let summary = "A high-level dialect for analyzing and optimizing Clang " +"supported languages"; + + let cppNamespace = "::mlir::cir"; + + let useDefaultAttributePrinterParser = 0; + let useDefaultTypePrinterParser = 0; + + let extraClassDeclaration = [{ +void registerAttributes(); +void registerTypes(); + +::mlir::Type parseType(::mlir::DialectAsmParser ) const override; +void printType(::mlir::Type type, + ::mlir::DialectAsmPrinter ) const override; + +::mlir::Attribute parseAttribute(::mlir::DialectAsmParser , + ::mlir::Type type) const override; + +void printAttribute(::mlir::Attribute attr, +::mlir::DialectAsmPrinter ) const override; joker-eph wrote: Nit: you are defining this dialect in the ::mlir::cir namespace, so you can remove the ::mlir:: prefix everywhere here. https://github.com/llvm/llvm-project/pull/86080 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [mlir][LLVM] erase call mappings in forgetMapping() (PR #84955)
@@ -0,0 +1,47 @@ +// RUN: mlir-translate -mlir-to-llvmir %s | FileCheck %s + +// Test that we don't crash when there is a call operation in the combiner + +omp.reduction.declare @add_f32 : f32 +init { +^bb0(%arg: f32): + %0 = llvm.mlir.constant(0.0 : f32) : f32 + omp.yield (%0 : f32) +} +combiner { +^bb1(%arg0: f32, %arg1: f32): +// test this call here: + llvm.call @test_call() : () -> () + %1 = llvm.fadd %arg0, %arg1 : f32 + omp.yield (%1 : f32) +} +atomic { +^bb2(%arg2: !llvm.ptr, %arg3: !llvm.ptr): + %2 = llvm.load %arg3 : !llvm.ptr -> f32 + llvm.atomicrmw fadd %arg2, %2 monotonic : !llvm.ptr, f32 + omp.yield +} + +llvm.func @simple_reduction(%lb : i64, %ub : i64, %step : i64) { + %c1 = llvm.mlir.constant(1 : i32) : i32 + %0 = llvm.alloca %c1 x i32 : (i32) -> !llvm.ptr + omp.parallel { +omp.wsloop reduction(@add_f32 %0 -> %prv : !llvm.ptr) +for (%iv) : i64 = (%lb) to (%ub) step (%step) { + %1 = llvm.mlir.constant(2.0 : f32) : f32 + %2 = llvm.load %prv : !llvm.ptr -> f32 + %3 = llvm.fadd %1, %2 : f32 + llvm.store %3, %prv : f32, !llvm.ptr + omp.yield +} +omp.terminator + } + llvm.return +} + +llvm.func @test_call() -> () joker-eph wrote: The OpenMP translation predates the LLVMTranslationInterface, but it really should evolve to this model: the OpenMP specific component should be better identified and isolated really. Anyway that's not a thing for this PR, thank for clarifying! https://github.com/llvm/llvm-project/pull/84955 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [mlir][LLVM] erase call mappings in forgetMapping() (PR #84955)
@@ -0,0 +1,47 @@ +// RUN: mlir-translate -mlir-to-llvmir %s | FileCheck %s + +// Test that we don't crash when there is a call operation in the combiner + +omp.reduction.declare @add_f32 : f32 +init { +^bb0(%arg: f32): + %0 = llvm.mlir.constant(0.0 : f32) : f32 + omp.yield (%0 : f32) +} +combiner { +^bb1(%arg0: f32, %arg1: f32): +// test this call here: + llvm.call @test_call() : () -> () + %1 = llvm.fadd %arg0, %arg1 : f32 + omp.yield (%1 : f32) +} +atomic { +^bb2(%arg2: !llvm.ptr, %arg3: !llvm.ptr): + %2 = llvm.load %arg3 : !llvm.ptr -> f32 + llvm.atomicrmw fadd %arg2, %2 monotonic : !llvm.ptr, f32 + omp.yield +} + +llvm.func @simple_reduction(%lb : i64, %ub : i64, %step : i64) { + %c1 = llvm.mlir.constant(1 : i32) : i32 + %0 = llvm.alloca %c1 x i32 : (i32) -> !llvm.ptr + omp.parallel { +omp.wsloop reduction(@add_f32 %0 -> %prv : !llvm.ptr) +for (%iv) : i64 = (%lb) to (%ub) step (%step) { + %1 = llvm.mlir.constant(2.0 : f32) : f32 + %2 = llvm.load %prv : !llvm.ptr -> f32 + %3 = llvm.fadd %1, %2 : f32 + llvm.store %3, %prv : f32, !llvm.ptr + omp.yield +} +omp.terminator + } + llvm.return +} + +llvm.func @test_call() -> () joker-eph wrote: This seems quite complex to me: is this the minimum test? Why do we need any OpenMp constructs here? https://github.com/llvm/llvm-project/pull/84955 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] release/18.x: [mlir][NFC] Apply rule of five to *Pass classes (#80998) (PR #83971)
joker-eph wrote: Do we have any ABI stability guarantees for LLVM C++ APIs? I would think that a lot of back ports can break the C++ ABI of LLVM in general? (I was assuming we'd care about the LLVM C API, libclang, ...) https://github.com/llvm/llvm-project/pull/83971 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [mlir][LLVM] erase call mappings in forgetMapping() (PR #84955)
joker-eph wrote: We need a test here https://github.com/llvm/llvm-project/pull/84955 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] release/18.x: [mlir][NFC] Apply rule of five to *Pass classes (#80998) (PR #83971)
https://github.com/joker-eph approved this pull request. https://github.com/llvm/llvm-project/pull/83971 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [mlir][Transforms] Support `replaceAllUsesWith` in dialect conversion (PR #84725)
@@ -751,6 +731,44 @@ class UnresolvedMaterializationRewrite : public OperationRewrite { /// The original output type. This is only used for argument conversions. Type origOutputType; }; + +/// A value rewrite. +class ValueRewrite : public IRRewrite { +public: + /// Return the operation that this rewrite operates on. + Value getValue() const { return value; } + + static bool classof(const IRRewrite *rewrite) { +return rewrite->getKind() >= Kind::ReplaceAllUses && + rewrite->getKind() <= Kind::ReplaceAllUses; + } + +protected: + ValueRewrite(Kind kind, ConversionPatternRewriterImpl , + Value value) + : IRRewrite(kind, rewriterImpl), value(value) {} + + // The value that this rewrite operates on. + Value value; +}; + +/// Replacing a value. This rewrite is not immediately reflected in the IR. An +/// internal IR mapping is updated, but the actual replacement is delayed until +/// the rewrite is committed. +class ReplaceAllUsesRewrite : public ValueRewrite { +public: + ReplaceAllUsesRewrite(ConversionPatternRewriterImpl , +Value value) + : ValueRewrite(Kind::ReplaceAllUses, rewriterImpl, value) {} + + static bool classof(const IRRewrite *rewrite) { +return rewrite->getKind() == Kind::ReplaceAllUses; + } + + void commit(RewriterBase ) override; + + void rollback() override; +}; joker-eph wrote: The whole flow of Dialect conversion tracking of these changes is too complicated for me to know whether the commit/rollback logic is safe and complete here :( It's likely that only testing will tell, but that's unfortunate! https://github.com/llvm/llvm-project/pull/84725 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [mlir][IR][NFC] Make `replaceAllUsesWith` non-templatized (PR #84722)
https://github.com/joker-eph approved this pull request. https://github.com/llvm/llvm-project/pull/84722 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [mlir][IR] Add listener notifications for pattern begin/end (PR #84131)
https://github.com/joker-eph approved this pull request. https://github.com/llvm/llvm-project/pull/84131 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [mlir][IR] Add listener notifications for pattern begin/end (PR #84131)
@@ -572,20 +571,33 @@ bool GreedyPatternRewriteDriver::processWorklist() { logger.getOStream() << ")' {\n"; logger.indent(); }); + if (config.listener) +config.listener->notifyPatternBegin(pattern, op); return true; }; -auto onFailure = [&](const Pattern ) { - LLVM_DEBUG(logResult("failure", "pattern failed to match")); -}; -auto onSuccess = [&](const Pattern ) { - LLVM_DEBUG(logResult("success", "pattern applied successfully")); - return success(); -}; -#else -function_ref canApply = {}; -function_ref onFailure = {}; -function_ref onSuccess = {}; -#endif +function_ref onFailure = +[&](const Pattern ) { + LLVM_DEBUG(logResult("failure", "pattern failed to match")); + if (config.listener) +config.listener->notifyPatternEnd(pattern, failure()); +}; +function_ref onSuccess = +[&](const Pattern ) { + LLVM_DEBUG(logResult("success", "pattern applied successfully")); + if (config.listener) +config.listener->notifyPatternEnd(pattern, success()); + return success(); +}; + +#ifdef NDEBUG +// Optimization: PatternApplicator callbacks are not needed when running in +// optimized mode and without a listener. +if (!config.listener) { + canApply = nullptr; + onFailure = nullptr; + onSuccess = nullptr; +} +#endif // NDEBUG joker-eph wrote: Note: I didn't suggest changing this, what you had here was reasonable! https://github.com/llvm/llvm-project/pull/84131 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [mlir][IR] Add listener notifications for pattern begin/end (PR #84131)
https://github.com/joker-eph edited https://github.com/llvm/llvm-project/pull/84131 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [mlir][IR] Add listener notifications for pattern begin/end (PR #84131)
https://github.com/joker-eph edited https://github.com/llvm/llvm-project/pull/84131 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [mlir][IR] Add listener notifications for pattern begin/end (PR #84131)
@@ -68,9 +68,9 @@ class PatternApplicator { ///invalidate the match and try another pattern. LogicalResult matchAndRewrite(Operation *op, PatternRewriter , - function_ref canApply = {}, - function_ref onFailure = {}, - function_ref onSuccess = {}); + std::function canApply = {}, + std::function onFailure = {}, + std::function onSuccess = {}); joker-eph wrote: > What are you referring to with this function? Where this comment thread is anchored: `matchAndRewrite` > The problem here is really just caused by the fact that the canApply = > assignment is inside of a nested scope. And the lambda object is dead by the > time matcher.matchAndRewrite is called. I.e., the canApply function_ref > points to an already free'd lambda. At least that's my understanding. Yes, but that's a problem for the call-site, I don't quite see where you make the connection to the signature of `matchAndRewrite`? https://github.com/llvm/llvm-project/pull/84131 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [mlir][IR] Add listener notifications for pattern begin/end (PR #84131)
@@ -68,9 +68,9 @@ class PatternApplicator { ///invalidate the match and try another pattern. LogicalResult matchAndRewrite(Operation *op, PatternRewriter , - function_ref canApply = {}, - function_ref onFailure = {}, - function_ref onSuccess = {}); + std::function canApply = {}, + std::function onFailure = {}, + std::function onSuccess = {}); joker-eph wrote: That can explain why you changed it at the call-site, but I'm puzzled about this function: it does not capture the callback as far as I can tell. https://github.com/llvm/llvm-project/pull/84131 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [mlir][IR] Add listener notifications for pattern begin/end (PR #84131)
@@ -562,30 +562,39 @@ bool GreedyPatternRewriteDriver::processWorklist() { // Try to match one of the patterns. The rewriter is automatically // notified of any necessary changes, so there is nothing else to do // here. +std::function canApply = nullptr; +std::function onFailure = nullptr; +std::function onSuccess = nullptr; +bool debugBuild = false; #ifndef NDEBUG -auto canApply = [&](const Pattern ) { - LLVM_DEBUG({ -logger.getOStream() << "\n"; -logger.startLine() << "* Pattern " << pattern.getDebugName() << " : '" - << op->getName() << " -> ("; -llvm::interleaveComma(pattern.getGeneratedOps(), logger.getOStream()); -logger.getOStream() << ")' {\n"; -logger.indent(); - }); - return true; -}; -auto onFailure = [&](const Pattern ) { - LLVM_DEBUG(logResult("failure", "pattern failed to match")); -}; -auto onSuccess = [&](const Pattern ) { - LLVM_DEBUG(logResult("success", "pattern applied successfully")); - return success(); -}; -#else -function_ref canApply = {}; -function_ref onFailure = {}; -function_ref onSuccess = {}; -#endif +debugBuild = true; joker-eph wrote: Oh never mind I see! https://github.com/llvm/llvm-project/pull/84131 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [mlir][IR] Add listener notifications for pattern begin/end (PR #84131)
@@ -562,30 +562,39 @@ bool GreedyPatternRewriteDriver::processWorklist() { // Try to match one of the patterns. The rewriter is automatically // notified of any necessary changes, so there is nothing else to do // here. +std::function canApply = nullptr; +std::function onFailure = nullptr; +std::function onSuccess = nullptr; +bool debugBuild = false; #ifndef NDEBUG -auto canApply = [&](const Pattern ) { - LLVM_DEBUG({ -logger.getOStream() << "\n"; -logger.startLine() << "* Pattern " << pattern.getDebugName() << " : '" - << op->getName() << " -> ("; -llvm::interleaveComma(pattern.getGeneratedOps(), logger.getOStream()); -logger.getOStream() << ")' {\n"; -logger.indent(); - }); - return true; -}; -auto onFailure = [&](const Pattern ) { - LLVM_DEBUG(logResult("failure", "pattern failed to match")); -}; -auto onSuccess = [&](const Pattern ) { - LLVM_DEBUG(logResult("success", "pattern applied successfully")); - return success(); -}; -#else -function_ref canApply = {}; -function_ref onFailure = {}; -function_ref onSuccess = {}; -#endif +debugBuild = true; joker-eph wrote: Why changing the structure of the code with this variable? https://github.com/llvm/llvm-project/pull/84131 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [mlir][IR] Add listener notifications for pattern begin/end (PR #84131)
@@ -68,9 +68,9 @@ class PatternApplicator { ///invalidate the match and try another pattern. LogicalResult matchAndRewrite(Operation *op, PatternRewriter , - function_ref canApply = {}, - function_ref onFailure = {}, - function_ref onSuccess = {}); + std::function canApply = {}, + std::function onFailure = {}, + std::function onSuccess = {}); joker-eph wrote: Why this change? https://github.com/llvm/llvm-project/pull/84131 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [clang-tools-extra] [lld] [lldb] [llvm] [mlir] Rename llvm::ThreadPool -> llvm::DefaultThreadPool (NFC) (PR #83702)
https://github.com/joker-eph reopened https://github.com/llvm/llvm-project/pull/83702 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [clang-tools-extra] [lld] [lldb] [llvm] [mlir] Rename llvm::ThreadPool -> llvm::DefaultThreadPool (NFC) (PR #83702)
https://github.com/joker-eph closed https://github.com/llvm/llvm-project/pull/83702 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [clang-tools-extra] [lld] [lldb] [llvm] [mlir] Rename llvm::ThreadPool -> llvm::DefaultThreadPool (NFC) (PR #83702)
joker-eph wrote: Here is the extracted one: https://github.com/llvm/llvm-project/pull/84056 And the diff here is now clean (stacked on top of #84056 ) How does it look now @dwblaikie ? https://github.com/llvm/llvm-project/pull/83702 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [clang-tools-extra] [lld] [lldb] [llvm] [mlir] Rename llvm::ThreadPool -> llvm::DefaultThreadPool (NFC) (PR #83702)
https://github.com/joker-eph updated https://github.com/llvm/llvm-project/pull/83702 >From 7935f2b8d298c7c882a472baf982cd29aa87cb26 Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Tue, 5 Mar 2024 10:38:41 -0800 Subject: [PATCH] Rename llvm::ThreadPool -> llvm::DefaultThreadPool (NFC) The base class llvm::ThreadPoolInterface will be renamed llvm::ThreadPool in a subsequent commit. --- bolt/lib/Core/ParallelUtilities.cpp | 4 ++-- bolt/tools/merge-fdata/merge-fdata.cpp| 2 +- .../clang-doc/tool/ClangDocMain.cpp | 2 +- .../tool/FindAllSymbolsMain.cpp | 2 +- clang/lib/Tooling/AllTUsExecution.cpp | 2 +- clang/tools/clang-scan-deps/ClangScanDeps.cpp | 2 +- lld/MachO/Writer.cpp | 2 +- lldb/source/Core/Debugger.cpp | 4 ++-- llvm/docs/ORCv2.rst | 2 +- .../SpeculativeJIT/SpeculativeJIT.cpp | 2 +- llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h | 2 +- llvm/include/llvm/Support/ThreadPool.h| 7 +++--- llvm/lib/CodeGen/ParallelCG.cpp | 2 +- llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp | 2 +- .../DWARFLinker/Parallel/DWARFLinkerImpl.cpp | 2 +- llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp | 2 +- llvm/lib/ExecutionEngine/Orc/LLJIT.cpp| 4 ++-- llvm/lib/LTO/LTO.cpp | 2 +- llvm/lib/LTO/LTOBackend.cpp | 2 +- llvm/lib/LTO/ThinLTOCodeGenerator.cpp | 4 ++-- llvm/lib/Support/BalancedPartitioning.cpp | 2 +- llvm/tools/dsymutil/dsymutil.cpp | 2 +- llvm/tools/llvm-cov/CodeCoverage.cpp | 2 +- llvm/tools/llvm-cov/CoverageExporterJson.cpp | 2 +- llvm/tools/llvm-cov/CoverageReport.cpp| 4 ++-- .../tools/llvm-debuginfod/llvm-debuginfod.cpp | 2 +- llvm/tools/llvm-profdata/llvm-profdata.cpp| 2 +- llvm/tools/llvm-reduce/deltas/Delta.cpp | 2 +- llvm/unittests/ADT/LazyAtomicPointerTest.cpp | 4 ++-- llvm/unittests/Debuginfod/HTTPServerTests.cpp | 16 +++--- llvm/unittests/Support/ParallelTest.cpp | 2 +- llvm/unittests/Support/ThreadPool.cpp | 22 +-- .../Support/ThreadSafeAllocatorTest.cpp | 6 ++--- mlir/include/mlir/IR/MLIRContext.h| 2 +- mlir/lib/CAPI/IR/Support.cpp | 2 +- mlir/lib/ExecutionEngine/AsyncRuntime.cpp | 2 +- mlir/lib/IR/MLIRContext.cpp | 4 ++-- 37 files changed, 65 insertions(+), 66 deletions(-) diff --git a/bolt/lib/Core/ParallelUtilities.cpp b/bolt/lib/Core/ParallelUtilities.cpp index 88d9444a6a2ba7..5f5e96e0e7881c 100644 --- a/bolt/lib/Core/ParallelUtilities.cpp +++ b/bolt/lib/Core/ParallelUtilities.cpp @@ -49,7 +49,7 @@ namespace ParallelUtilities { namespace { /// A single thread pool that is used to run parallel tasks -std::unique_ptr ThreadPoolPtr; +std::unique_ptr ThreadPoolPtr; unsigned computeCostFor(const BinaryFunction , const PredicateTy , @@ -106,7 +106,7 @@ ThreadPoolInterface () { if (ThreadPoolPtr.get()) return *ThreadPoolPtr; - ThreadPoolPtr = std::make_unique( + ThreadPoolPtr = std::make_unique( llvm::hardware_concurrency(opts::ThreadCount)); return *ThreadPoolPtr; } diff --git a/bolt/tools/merge-fdata/merge-fdata.cpp b/bolt/tools/merge-fdata/merge-fdata.cpp index c6dfd3cfdc56de..f2ac5ad4492ee5 100644 --- a/bolt/tools/merge-fdata/merge-fdata.cpp +++ b/bolt/tools/merge-fdata/merge-fdata.cpp @@ -316,7 +316,7 @@ void mergeLegacyProfiles(const SmallVectorImpl ) { // least 4 tasks. ThreadPoolStrategy S = optimal_concurrency( std::max(Filenames.size() / 4, static_cast(1))); - ThreadPool Pool(S); + DefaultThreadPool Pool(S); DenseMap ParsedProfiles( Pool.getMaxConcurrency()); for (const auto : Filenames) diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp index 22bdb5de22d871..21b581fa6df2e1 100644 --- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp +++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp @@ -238,7 +238,7 @@ Example usage for a project using a compile commands database: Error = false; llvm::sys::Mutex IndexMutex; // ExecutorConcurrency is a flag exposed by AllTUsExecution.h - llvm::ThreadPool Pool(llvm::hardware_concurrency(ExecutorConcurrency)); + llvm::DefaultThreadPool Pool(llvm::hardware_concurrency(ExecutorConcurrency)); for (auto : USRToBitcode) { Pool.async([&]() { std::vector> Infos; diff --git a/clang-tools-extra/clang-include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp b/clang-tools-extra/clang-include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp index b2d0efecc20692..298b02e77cb0aa 100644 --- a/clang-tools-extra/clang-include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp +++ b/clang-tools-extra/clang-include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp @@ -89,7 +89,7
[llvm-branch-commits] [clang] [clang-tools-extra] [lld] [lldb] [llvm] [mlir] Rename llvm::ThreadPool -> llvm::DefaultThreadPool (NFC) (PR #83702)
https://github.com/joker-eph edited https://github.com/llvm/llvm-project/pull/83702 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [mlir][Transforms] Support rolling back properties in dialect conversion (PR #82474)
https://github.com/joker-eph approved this pull request. https://github.com/llvm/llvm-project/pull/82474 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] [mlir] [mlir][Transforms] Make `ConversionPatternRewriter` constructor private (PR #82244)
https://github.com/joker-eph approved this pull request. https://github.com/llvm/llvm-project/pull/82244 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [mlir][Transforms] Support rolling back properties in dialect conversion (PR #82474)
https://github.com/joker-eph edited https://github.com/llvm/llvm-project/pull/82474 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [mlir][Transforms] Support rolling back properties in dialect conversion (PR #82474)
@@ -1002,12 +1002,31 @@ class ModifyOperationRewrite : public OperationRewrite { : OperationRewrite(Kind::ModifyOperation, rewriterImpl, op), loc(op->getLoc()), attrs(op->getAttrDictionary()), operands(op->operand_begin(), op->operand_end()), -successors(op->successor_begin(), op->successor_end()) {} +successors(op->successor_begin(), op->successor_end()) { +if (OpaqueProperties prop = op->getPropertiesStorage()) { + // Make a copy of the properties. + propertiesStorage = operator new(op->getPropertiesStorageSize()); + OpaqueProperties propCopy(propertiesStorage); + op->getName().copyOpProperties(propCopy, prop); joker-eph wrote: The constructor is never called I believe https://github.com/llvm/llvm-project/pull/82474 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [mlir][Transforms] Support rolling back properties in dialect conversion (PR #82474)
@@ -1016,13 +1035,20 @@ class ModifyOperationRewrite : public OperationRewrite { op->setOperands(operands); for (const auto : llvm::enumerate(successors)) op->setSuccessor(it.value(), it.index()); +if (propertiesStorage) { + OpaqueProperties prop(propertiesStorage); + op->copyProperties(prop); + operator delete(propertiesStorage); joker-eph wrote: (Same) https://github.com/llvm/llvm-project/pull/82474 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [mlir][Transforms] Support rolling back properties in dialect conversion (PR #82474)
@@ -1002,12 +1002,31 @@ class ModifyOperationRewrite : public OperationRewrite { : OperationRewrite(Kind::ModifyOperation, rewriterImpl, op), loc(op->getLoc()), attrs(op->getAttrDictionary()), operands(op->operand_begin(), op->operand_end()), -successors(op->successor_begin(), op->successor_end()) {} +successors(op->successor_begin(), op->successor_end()) { +if (OpaqueProperties prop = op->getPropertiesStorage()) { + // Make a copy of the properties. + propertiesStorage = operator new(op->getPropertiesStorageSize()); + OpaqueProperties propCopy(propertiesStorage); + op->getName().copyOpProperties(propCopy, prop); +} + } static bool classof(const IRRewrite *rewrite) { return rewrite->getKind() == Kind::ModifyOperation; } + ~ModifyOperationRewrite() override { +assert(!propertiesStorage && + "rewrite was neither committed nor rolled back"); + } + + void commit() override { +if (propertiesStorage) { + operator delete(propertiesStorage); joker-eph wrote: This needs to call the property destructor https://github.com/llvm/llvm-project/pull/82474 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [mlir][Transforms] Support rolling back properties in dialect conversion (PR #82474)
@@ -1002,12 +1002,31 @@ class ModifyOperationRewrite : public OperationRewrite { : OperationRewrite(Kind::ModifyOperation, rewriterImpl, op), loc(op->getLoc()), attrs(op->getAttrDictionary()), operands(op->operand_begin(), op->operand_end()), -successors(op->successor_begin(), op->successor_end()) {} +successors(op->successor_begin(), op->successor_end()) { +if (OpaqueProperties prop = op->getPropertiesStorage()) { + // Make a copy of the properties. + int size = op->getPropertiesStorageSize(); + propertiesStorage = operator new(size); + memcpy(propertiesStorage, prop.as(), size); joker-eph wrote: That does not seem correct C++ to me: you can't assume that a property can be copied as a "POD" (I don't remember the new terminology). Properties can be arbitrary C++ objects (think std::string for example). https://github.com/llvm/llvm-project/pull/82474 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [mlir][Transforms] Support `moveOpBefore`/`After` in dialect conversion (PR #81240)
https://github.com/joker-eph approved this pull request. https://github.com/llvm/llvm-project/pull/81240 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [mlir][Transforms][NFC] Modularize block actions (PR #81237)
https://github.com/joker-eph approved this pull request. https://github.com/llvm/llvm-project/pull/81237 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] release/18.x: [mlir] Skip invalid test on big endian platform (s390x) (#80246) (PR #81373)
https://github.com/joker-eph approved this pull request. https://github.com/llvm/llvm-project/pull/81373 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [mlir][Transforms][NFC] Modularize block actions (PR #81237)
@@ -820,6 +740,238 @@ void ArgConverter::insertConversion(Block *newBlock, conversionInfo.insert({newBlock, std::move(info)}); } +//===--===// +// RewriteAction joker-eph wrote: Mentioned it in the other PR: do we have an alternative to "Action" here? https://github.com/llvm/llvm-project/pull/81237 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [mlir][Transforms] Support `moveOpBefore`/`After` in dialect conversion (PR #81240)
https://github.com/joker-eph approved this pull request. https://github.com/llvm/llvm-project/pull/81240 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [mlir][Transforms] Support `moveOpBefore`/`After` in dialect conversion (PR #81240)
@@ -970,6 +971,54 @@ class BlockTypeConversionAction : public BlockAction { void rollback() override; }; + +/// An operation rewrite. joker-eph wrote: Can you expand on the role of the class, the context where it's used? The "Action" name for this whole section is not great by the way, since the concept of "Actions" is now core to MLIR tracing... https://github.com/llvm/llvm-project/pull/81240 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [mlir] Start moving some builtin type formats to the dialect (PR #80421)
@@ -25,7 +25,8 @@ include "mlir/IR/BuiltinTypeInterfaces.td" // Base class for Builtin dialect types. class Builtin_Type traits = [], string baseCppClass = "::mlir::Type"> -: TypeDef { +: TypeDefhttps://github.com/llvm/llvm-project/pull/80421 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] 6542aad - [혀헽헿] initial version
Author: Florian Hahn Date: 2023-11-03T13:31:37-07:00 New Revision: 6542aad3fd2f8a158f6c2180b44c875144670dec URL: https://github.com/llvm/llvm-project/commit/6542aad3fd2f8a158f6c2180b44c875144670dec DIFF: https://github.com/llvm/llvm-project/commit/6542aad3fd2f8a158f6c2180b44c875144670dec.diff LOG: [혀헽헿] initial version Created using spr 1.3.4 Added: Modified: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp llvm/test/Transforms/LoopVectorize/X86/drop-poison-generating-flags.ll Removed: diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 4f547886f602534..1c208f72af678f7 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -1103,7 +1103,8 @@ void InnerLoopVectorizer::collectPoisonGeneratingRecipes( if (auto *RecWithFlags = dyn_cast(CurRec)) { RecWithFlags->dropPoisonGeneratingFlags(); } else { -Instruction *Instr = CurRec->getUnderlyingInstr(); +Instruction *Instr = dyn_cast_or_null( +CurRec->getVPSingleValue()->getUnderlyingValue()); (void)Instr; assert((!Instr || !Instr->hasPoisonGeneratingFlags()) && "found instruction with poison generating flags not covered by " diff --git a/llvm/test/Transforms/LoopVectorize/X86/drop-poison-generating-flags.ll b/llvm/test/Transforms/LoopVectorize/X86/drop-poison-generating-flags.ll index b440da6dd866081..5694367dd1f9016 100644 --- a/llvm/test/Transforms/LoopVectorize/X86/drop-poison-generating-flags.ll +++ b/llvm/test/Transforms/LoopVectorize/X86/drop-poison-generating-flags.ll @@ -405,6 +405,89 @@ loop.exit: ret void } +@c = external global [5 x i8] + +; Test case for https://github.com/llvm/llvm-project/issues/70590. +; Note that the then block has UB, but I could not find any other way to +; construct a suitable test case. +define void @pr70590_recipe_without_underlying_instr(i64 %n, ptr noalias %dst) { +; CHECK-LABEL: @pr70590_recipe_without_underlying_instr( +; CHECK: vector.body: +; CHECK-NEXT:[[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH:%.+]] ], [ [[INDEX_NEXT:%.*]], [[PRED_SREM_CONTINUE6:%.*]] ] +; CHECK-NEXT:[[VEC_IND:%.*]] = phi <4 x i64> [ , [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[PRED_SREM_CONTINUE6]] ] +; CHECK-NEXT:[[TMP0:%.*]] = add i64 [[INDEX]], 0 +; CHECK-NEXT:[[TMP1:%.*]] = icmp eq <4 x i64> [[VEC_IND]], +; CHECK-NEXT:[[TMP2:%.*]] = xor <4 x i1> [[TMP1]], +; CHECK-NEXT:[[TMP3:%.*]] = extractelement <4 x i1> [[TMP2]], i32 0 +; CHECK-NEXT:br i1 [[TMP3]], label [[PRED_SREM_IF:%.*]], label [[PRED_SREM_CONTINUE:%.*]] +; CHECK: pred.srem.if: +; CHECK-NEXT:[[TMP4:%.*]] = srem i64 3, 0 +; CHECK-NEXT:br label [[PRED_SREM_CONTINUE]] +; CHECK: pred.srem.continue: +; CHECK-NEXT:[[TMP5:%.*]] = phi i64 [ poison, %vector.body ], [ [[TMP4]], [[PRED_SREM_IF]] ] +; CHECK-NEXT:[[TMP6:%.*]] = extractelement <4 x i1> [[TMP2]], i32 1 +; CHECK-NEXT:br i1 [[TMP6]], label [[PRED_SREM_IF1:%.*]], label [[PRED_SREM_CONTINUE2:%.*]] +; CHECK: pred.srem.if1: +; CHECK-NEXT:[[TMP7:%.*]] = srem i64 3, 0 +; CHECK-NEXT:br label [[PRED_SREM_CONTINUE2]] +; CHECK: pred.srem.continue2: +; CHECK-NEXT:[[TMP8:%.*]] = phi i64 [ poison, [[PRED_SREM_CONTINUE]] ], [ [[TMP7]], [[PRED_SREM_IF1]] ] +; CHECK-NEXT:[[TMP9:%.*]] = extractelement <4 x i1> [[TMP2]], i32 2 +; CHECK-NEXT:br i1 [[TMP9]], label [[PRED_SREM_IF3:%.*]], label [[PRED_SREM_CONTINUE4:%.*]] +; CHECK: pred.srem.if3: +; CHECK-NEXT:[[TMP10:%.*]] = srem i64 3, 0 +; CHECK-NEXT:br label [[PRED_SREM_CONTINUE4]] +; CHECK: pred.srem.continue4: +; CHECK-NEXT:[[TMP11:%.*]] = phi i64 [ poison, [[PRED_SREM_CONTINUE2]] ], [ [[TMP10]], [[PRED_SREM_IF3]] ] +; CHECK-NEXT:[[TMP12:%.*]] = extractelement <4 x i1> [[TMP2]], i32 3 +; CHECK-NEXT:br i1 [[TMP12]], label [[PRED_SREM_IF5:%.*]], label [[PRED_SREM_CONTINUE6]] +; CHECK: pred.srem.if5: +; CHECK-NEXT:[[TMP13:%.*]] = srem i64 3, 0 +; CHECK-NEXT:br label [[PRED_SREM_CONTINUE6]] +; CHECK: pred.srem.continue6: +; CHECK-NEXT:[[TMP14:%.*]] = phi i64 [ poison, [[PRED_SREM_CONTINUE4]] ], [ [[TMP13]], [[PRED_SREM_IF5]] ] +; CHECK-NEXT:[[TMP15:%.*]] = add i64 [[TMP5]], -3 +; CHECK-NEXT:[[TMP16:%.*]] = add i64 [[TMP0]], [[TMP15]] +; CHECK-NEXT:[[TMP17:%.*]] = getelementptr [5 x i8], ptr @c, i64 0, i64 [[TMP16]] +; CHECK-NEXT:[[TMP18:%.*]] = getelementptr i8, ptr [[TMP17]], i32 0 +; CHECK-NEXT:[[WIDE_LOAD:%.*]] = load <4 x i8>, ptr [[TMP18]], align 1 +; CHECK-NEXT:[[PREDPHI:%.*]] = select <4 x i1> [[TMP2]], <4 x i8> [[WIDE_LOAD]], <4 x i8> zeroinitializer +; CHECK-NEXT:[[TMP19:%.*]] = getelementptr i8, ptr %dst, i64 [[TMP0]] +; CHECK-NEXT:[[TMP20:%.*]] = getelementptr i8, ptr
[llvm-branch-commits] [clang] [clang-tools-extra] [llvm] [flang] [lldb] [mlir] [libcxx] [compiler-rt] [libcxxabi] [lld] Refactor ModuleToObject to offer more flexibility to subclass (NFC) (PR #71165)
https://github.com/joker-eph updated https://github.com/llvm/llvm-project/pull/71165 >From 183f5094ff7da09beed46f760a857af449a24245 Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Fri, 3 Nov 2023 13:26:56 -0700 Subject: [PATCH] use cached TM Created using spr 1.3.4 --- mlir/lib/Target/LLVM/ModuleToObject.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mlir/lib/Target/LLVM/ModuleToObject.cpp b/mlir/lib/Target/LLVM/ModuleToObject.cpp index 6af3d49ab23bf74..d94c10de8d7c424 100644 --- a/mlir/lib/Target/LLVM/ModuleToObject.cpp +++ b/mlir/lib/Target/LLVM/ModuleToObject.cpp @@ -45,8 +45,10 @@ Operation ::getOperation() { return module; } std::optional ModuleToObject::getOrCreateTargetMachine() { - std::string error; + if (targetMachine) +return targetMachine.get(); // Load the target. + std::string error; const llvm::Target *target = llvm::TargetRegistry::lookupTarget(triple, error); if (!target) { ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [clang] [mlir] Refactor ModuleToObject to offer more flexibility to subclass (NFC) (PR #71165)
https://github.com/joker-eph updated https://github.com/llvm/llvm-project/pull/71165 >From 183f5094ff7da09beed46f760a857af449a24245 Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Fri, 3 Nov 2023 13:26:56 -0700 Subject: [PATCH] use cached TM Created using spr 1.3.4 --- mlir/lib/Target/LLVM/ModuleToObject.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mlir/lib/Target/LLVM/ModuleToObject.cpp b/mlir/lib/Target/LLVM/ModuleToObject.cpp index 6af3d49ab23bf74..d94c10de8d7c424 100644 --- a/mlir/lib/Target/LLVM/ModuleToObject.cpp +++ b/mlir/lib/Target/LLVM/ModuleToObject.cpp @@ -45,8 +45,10 @@ Operation ::getOperation() { return module; } std::optional ModuleToObject::getOrCreateTargetMachine() { - std::string error; + if (targetMachine) +return targetMachine.get(); // Load the target. + std::string error; const llvm::Target *target = llvm::TargetRegistry::lookupTarget(triple, error); if (!target) { ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] 183f509 - use cached TM
Author: Mehdi Amini Date: 2023-11-03T13:26:56-07:00 New Revision: 183f5094ff7da09beed46f760a857af449a24245 URL: https://github.com/llvm/llvm-project/commit/183f5094ff7da09beed46f760a857af449a24245 DIFF: https://github.com/llvm/llvm-project/commit/183f5094ff7da09beed46f760a857af449a24245.diff LOG: use cached TM Created using spr 1.3.4 Added: Modified: mlir/lib/Target/LLVM/ModuleToObject.cpp Removed: diff --git a/mlir/lib/Target/LLVM/ModuleToObject.cpp b/mlir/lib/Target/LLVM/ModuleToObject.cpp index 6af3d49ab23bf74..d94c10de8d7c424 100644 --- a/mlir/lib/Target/LLVM/ModuleToObject.cpp +++ b/mlir/lib/Target/LLVM/ModuleToObject.cpp @@ -45,8 +45,10 @@ Operation ::getOperation() { return module; } std::optional ModuleToObject::getOrCreateTargetMachine() { - std::string error; + if (targetMachine) +return targetMachine.get(); // Load the target. + std::string error; const llvm::Target *target = llvm::TargetRegistry::lookupTarget(triple, error); if (!target) { ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [mlir] [llvm] Refactor ModuleToObject to offer more flexibility to subclass (NFC) (PR #71165)
@@ -39,32 +39,32 @@ ModuleToObject::ModuleToObject(Operation , StringRef triple, : module(module), triple(triple), chip(chip), features(features), optLevel(optLevel) {} +ModuleToObject::~ModuleToObject() = default; + Operation ::getOperation() { return module; } -std::unique_ptr ModuleToObject::createTargetMachine() { +std::optional +ModuleToObject::getOrCreateTargetMachine() { std::string error; joker-eph wrote: Thanks! https://github.com/llvm/llvm-project/pull/71165 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] b7e4dc7 - rebase
Author: Mehdi Amini Date: 2023-11-03T03:23:50-07:00 New Revision: b7e4dc73442b986e8effe80afdd7bb409d0a367b URL: https://github.com/llvm/llvm-project/commit/b7e4dc73442b986e8effe80afdd7bb409d0a367b DIFF: https://github.com/llvm/llvm-project/commit/b7e4dc73442b986e8effe80afdd7bb409d0a367b.diff LOG: rebase Created using spr 1.3.4 Added: Modified: clang/test/OpenMP/cancel_codegen.cpp clang/test/OpenMP/parallel_codegen.cpp llvm/lib/IR/ConstantFold.cpp mlir/include/mlir/Conversion/Passes.td mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVMPass.cpp mlir/test/Conversion/VectorToLLVM/vector-mask-to-llvm.mlir mlir/test/Conversion/VectorToLLVM/vector-reduction-to-llvm.mlir mlir/test/Conversion/VectorToLLVM/vector-scalable-memcpy.mlir mlir/test/Conversion/VectorToLLVM/vector-to-llvm.mlir Removed: mlir/test/Conversion/VectorToLLVM/typed-pointers.mlir diff --git a/clang/test/OpenMP/cancel_codegen.cpp b/clang/test/OpenMP/cancel_codegen.cpp index 53580e0c2b0293f..03024cf331b2717 100644 --- a/clang/test/OpenMP/cancel_codegen.cpp +++ b/clang/test/OpenMP/cancel_codegen.cpp @@ -1026,25 +1026,25 @@ for (int i = 0; i < argc; ++i) { // CHECK3-NEXT:call void @llvm.experimental.noalias.scope.decl(metadata [[META8:![0-9]+]]) // CHECK3-NEXT:call void @llvm.experimental.noalias.scope.decl(metadata [[META10:![0-9]+]]) // CHECK3-NEXT:call void @llvm.experimental.noalias.scope.decl(metadata [[META12:![0-9]+]]) -// CHECK3-NEXT:store i32 [[TMP2]], ptr [[DOTGLOBAL_TID__ADDR_I]], align 4, !noalias !14 -// CHECK3-NEXT:store ptr [[TMP5]], ptr [[DOTPART_ID__ADDR_I]], align 8, !noalias !14 -// CHECK3-NEXT:store ptr null, ptr [[DOTPRIVATES__ADDR_I]], align 8, !noalias !14 -// CHECK3-NEXT:store ptr null, ptr [[DOTCOPY_FN__ADDR_I]], align 8, !noalias !14 -// CHECK3-NEXT:store ptr [[TMP3]], ptr [[DOTTASK_T__ADDR_I]], align 8, !noalias !14 -// CHECK3-NEXT:store ptr [[TMP7]], ptr [[__CONTEXT_ADDR_I]], align 8, !noalias !14 -// CHECK3-NEXT:[[TMP8:%.*]] = load ptr, ptr [[__CONTEXT_ADDR_I]], align 8, !noalias !14 +// CHECK3-NEXT:store i32 [[TMP2]], ptr [[DOTGLOBAL_TID__ADDR_I]], align 4, !noalias ![[NOALIAS0:[0-9]+]] +// CHECK3-NEXT:store ptr [[TMP5]], ptr [[DOTPART_ID__ADDR_I]], align 8, !noalias ![[NOALIAS0]] +// CHECK3-NEXT:store ptr null, ptr [[DOTPRIVATES__ADDR_I]], align 8, !noalias ![[NOALIAS0]] +// CHECK3-NEXT:store ptr null, ptr [[DOTCOPY_FN__ADDR_I]], align 8, !noalias ![[NOALIAS0]] +// CHECK3-NEXT:store ptr [[TMP3]], ptr [[DOTTASK_T__ADDR_I]], align 8, !noalias ![[NOALIAS0]] +// CHECK3-NEXT:store ptr [[TMP7]], ptr [[__CONTEXT_ADDR_I]], align 8, !noalias ![[NOALIAS0]] +// CHECK3-NEXT:[[TMP8:%.*]] = load ptr, ptr [[__CONTEXT_ADDR_I]], align 8, !noalias ![[NOALIAS0]] // CHECK3-NEXT:[[OMP_GLOBAL_THREAD_NUM_I:%.*]] = call i32 @__kmpc_global_thread_num(ptr @[[GLOB12:[0-9]+]]) // CHECK3-NEXT:[[TMP9:%.*]] = call i32 @__kmpc_cancel(ptr @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM_I]], i32 4) // CHECK3-NEXT:[[TMP10:%.*]] = icmp ne i32 [[TMP9]], 0 // CHECK3-NEXT:br i1 [[TMP10]], label [[DOTCANCEL_EXIT_I:%.*]], label [[DOTCANCEL_CONTINUE_I:%.*]] // CHECK3: .cancel.exit.i: -// CHECK3-NEXT:store i32 1, ptr [[CLEANUP_DEST_SLOT_I]], align 4, !noalias !14 +// CHECK3-NEXT:store i32 1, ptr [[CLEANUP_DEST_SLOT_I]], align 4, !noalias ![[NOALIAS1:[0-9]+]] // CHECK3-NEXT:br label [[DOTOMP_OUTLINED__EXIT:%.*]] // CHECK3: .cancel.continue.i: -// CHECK3-NEXT:store i32 0, ptr [[CLEANUP_DEST_SLOT_I]], align 4, !noalias !14 +// CHECK3-NEXT:store i32 0, ptr [[CLEANUP_DEST_SLOT_I]], align 4, !noalias ![[NOALIAS1]] // CHECK3-NEXT:br label [[DOTOMP_OUTLINED__EXIT]] // CHECK3: .omp_outlined..exit: -// CHECK3-NEXT:[[CLEANUP_DEST_I:%.*]] = load i32, ptr [[CLEANUP_DEST_SLOT_I]], align 4, !noalias !14 +// CHECK3-NEXT:[[CLEANUP_DEST_I:%.*]] = load i32, ptr [[CLEANUP_DEST_SLOT_I]], align 4, !noalias ![[NOALIAS1]] // CHECK3-NEXT:ret i32 0 // // diff --git a/clang/test/OpenMP/parallel_codegen.cpp b/clang/test/OpenMP/parallel_codegen.cpp index 5c98761be0808ef..d545b4a9d9fa887 100644 --- a/clang/test/OpenMP/parallel_codegen.cpp +++ b/clang/test/OpenMP/parallel_codegen.cpp @@ -812,7 +812,7 @@ int main (int argc, char **argv) { // // // CHECK3-LABEL: define {{[^@]+}}@_Z5tmainIPPcEiT_..omp_par -// CHECK3-SAME: (ptr noalias [[TID_ADDR:%.*]], ptr noalias [[ZERO_ADDR:%.*]], ptr [[TMP0:%.*]]) #[[ATTR1]] { +// CHECK3-SAME: (ptr noalias [[TID_ADDR:%.*]], ptr noalias [[ZERO_ADDR:%.*]], ptr [[TMP0:%.*]]) #[[ATTR2:[0-9]+]] // CHECK3-NEXT: omp.par.entry: // CHECK3-NEXT:[[GEP__RELOADED:%.*]] = getelementptr { ptr, ptr }, ptr [[TMP0]], i32 0, i32 0 // CHECK3-NEXT:[[LOADGEP__RELOADED:%.*]] = load ptr, ptr
[llvm-branch-commits] [clang] 3289ecf - [혀헽헿] changes introduced through rebase
Author: Mehdi Amini Date: 2023-11-03T03:23:43-07:00 New Revision: 3289ecff8e8f5022cb6a40777392c98f1bcf5780 URL: https://github.com/llvm/llvm-project/commit/3289ecff8e8f5022cb6a40777392c98f1bcf5780 DIFF: https://github.com/llvm/llvm-project/commit/3289ecff8e8f5022cb6a40777392c98f1bcf5780.diff LOG: [혀헽헿] changes introduced through rebase Created using spr 1.3.4 [skip ci] Added: Modified: clang/test/OpenMP/cancel_codegen.cpp clang/test/OpenMP/parallel_codegen.cpp llvm/lib/IR/ConstantFold.cpp mlir/include/mlir/Conversion/Passes.td mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVMPass.cpp mlir/test/Conversion/VectorToLLVM/vector-mask-to-llvm.mlir mlir/test/Conversion/VectorToLLVM/vector-reduction-to-llvm.mlir mlir/test/Conversion/VectorToLLVM/vector-scalable-memcpy.mlir mlir/test/Conversion/VectorToLLVM/vector-to-llvm.mlir Removed: mlir/test/Conversion/VectorToLLVM/typed-pointers.mlir diff --git a/clang/test/OpenMP/cancel_codegen.cpp b/clang/test/OpenMP/cancel_codegen.cpp index 53580e0c2b0293f..03024cf331b2717 100644 --- a/clang/test/OpenMP/cancel_codegen.cpp +++ b/clang/test/OpenMP/cancel_codegen.cpp @@ -1026,25 +1026,25 @@ for (int i = 0; i < argc; ++i) { // CHECK3-NEXT:call void @llvm.experimental.noalias.scope.decl(metadata [[META8:![0-9]+]]) // CHECK3-NEXT:call void @llvm.experimental.noalias.scope.decl(metadata [[META10:![0-9]+]]) // CHECK3-NEXT:call void @llvm.experimental.noalias.scope.decl(metadata [[META12:![0-9]+]]) -// CHECK3-NEXT:store i32 [[TMP2]], ptr [[DOTGLOBAL_TID__ADDR_I]], align 4, !noalias !14 -// CHECK3-NEXT:store ptr [[TMP5]], ptr [[DOTPART_ID__ADDR_I]], align 8, !noalias !14 -// CHECK3-NEXT:store ptr null, ptr [[DOTPRIVATES__ADDR_I]], align 8, !noalias !14 -// CHECK3-NEXT:store ptr null, ptr [[DOTCOPY_FN__ADDR_I]], align 8, !noalias !14 -// CHECK3-NEXT:store ptr [[TMP3]], ptr [[DOTTASK_T__ADDR_I]], align 8, !noalias !14 -// CHECK3-NEXT:store ptr [[TMP7]], ptr [[__CONTEXT_ADDR_I]], align 8, !noalias !14 -// CHECK3-NEXT:[[TMP8:%.*]] = load ptr, ptr [[__CONTEXT_ADDR_I]], align 8, !noalias !14 +// CHECK3-NEXT:store i32 [[TMP2]], ptr [[DOTGLOBAL_TID__ADDR_I]], align 4, !noalias ![[NOALIAS0:[0-9]+]] +// CHECK3-NEXT:store ptr [[TMP5]], ptr [[DOTPART_ID__ADDR_I]], align 8, !noalias ![[NOALIAS0]] +// CHECK3-NEXT:store ptr null, ptr [[DOTPRIVATES__ADDR_I]], align 8, !noalias ![[NOALIAS0]] +// CHECK3-NEXT:store ptr null, ptr [[DOTCOPY_FN__ADDR_I]], align 8, !noalias ![[NOALIAS0]] +// CHECK3-NEXT:store ptr [[TMP3]], ptr [[DOTTASK_T__ADDR_I]], align 8, !noalias ![[NOALIAS0]] +// CHECK3-NEXT:store ptr [[TMP7]], ptr [[__CONTEXT_ADDR_I]], align 8, !noalias ![[NOALIAS0]] +// CHECK3-NEXT:[[TMP8:%.*]] = load ptr, ptr [[__CONTEXT_ADDR_I]], align 8, !noalias ![[NOALIAS0]] // CHECK3-NEXT:[[OMP_GLOBAL_THREAD_NUM_I:%.*]] = call i32 @__kmpc_global_thread_num(ptr @[[GLOB12:[0-9]+]]) // CHECK3-NEXT:[[TMP9:%.*]] = call i32 @__kmpc_cancel(ptr @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM_I]], i32 4) // CHECK3-NEXT:[[TMP10:%.*]] = icmp ne i32 [[TMP9]], 0 // CHECK3-NEXT:br i1 [[TMP10]], label [[DOTCANCEL_EXIT_I:%.*]], label [[DOTCANCEL_CONTINUE_I:%.*]] // CHECK3: .cancel.exit.i: -// CHECK3-NEXT:store i32 1, ptr [[CLEANUP_DEST_SLOT_I]], align 4, !noalias !14 +// CHECK3-NEXT:store i32 1, ptr [[CLEANUP_DEST_SLOT_I]], align 4, !noalias ![[NOALIAS1:[0-9]+]] // CHECK3-NEXT:br label [[DOTOMP_OUTLINED__EXIT:%.*]] // CHECK3: .cancel.continue.i: -// CHECK3-NEXT:store i32 0, ptr [[CLEANUP_DEST_SLOT_I]], align 4, !noalias !14 +// CHECK3-NEXT:store i32 0, ptr [[CLEANUP_DEST_SLOT_I]], align 4, !noalias ![[NOALIAS1]] // CHECK3-NEXT:br label [[DOTOMP_OUTLINED__EXIT]] // CHECK3: .omp_outlined..exit: -// CHECK3-NEXT:[[CLEANUP_DEST_I:%.*]] = load i32, ptr [[CLEANUP_DEST_SLOT_I]], align 4, !noalias !14 +// CHECK3-NEXT:[[CLEANUP_DEST_I:%.*]] = load i32, ptr [[CLEANUP_DEST_SLOT_I]], align 4, !noalias ![[NOALIAS1]] // CHECK3-NEXT:ret i32 0 // // diff --git a/clang/test/OpenMP/parallel_codegen.cpp b/clang/test/OpenMP/parallel_codegen.cpp index 5c98761be0808ef..d545b4a9d9fa887 100644 --- a/clang/test/OpenMP/parallel_codegen.cpp +++ b/clang/test/OpenMP/parallel_codegen.cpp @@ -812,7 +812,7 @@ int main (int argc, char **argv) { // // // CHECK3-LABEL: define {{[^@]+}}@_Z5tmainIPPcEiT_..omp_par -// CHECK3-SAME: (ptr noalias [[TID_ADDR:%.*]], ptr noalias [[ZERO_ADDR:%.*]], ptr [[TMP0:%.*]]) #[[ATTR1]] { +// CHECK3-SAME: (ptr noalias [[TID_ADDR:%.*]], ptr noalias [[ZERO_ADDR:%.*]], ptr [[TMP0:%.*]]) #[[ATTR2:[0-9]+]] // CHECK3-NEXT: omp.par.entry: // CHECK3-NEXT:[[GEP__RELOADED:%.*]] = getelementptr { ptr, ptr }, ptr [[TMP0]], i32 0, i32 0 // CHECK3-NEXT:
[llvm-branch-commits] [mlir] [clang] [llvm] Refactor ModuleToObject to offer more flexibility to subclass (NFC) (PR #71165)
https://github.com/joker-eph updated https://github.com/llvm/llvm-project/pull/71165 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [mlir] Refactor ModuleToObject to offer more flexibility to subclass (NFC) (PR #71165)
https://github.com/joker-eph created https://github.com/llvm/llvm-project/pull/71165 Some specific implementation of the offload may want more customization, and even avoid using LLVM in-tree to dispatch the ISA translation to a custom solution. This refactoring makes it possible for such implementation to work without even configuring the target backend in LLVM. ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] 0267760 - [혀헽헿] initial version
Author: Mehdi Amini Date: 2023-11-03T03:07:34-07:00 New Revision: 0267760d2726671d76bb8d3adfe0b981288b3fb6 URL: https://github.com/llvm/llvm-project/commit/0267760d2726671d76bb8d3adfe0b981288b3fb6 DIFF: https://github.com/llvm/llvm-project/commit/0267760d2726671d76bb8d3adfe0b981288b3fb6.diff LOG: [혀헽헿] initial version Created using spr 1.3.4 Added: Modified: llvm/CMakeLists.txt llvm/include/llvm/Config/llvm-config.h.cmake mlir/include/mlir/Target/LLVM/ModuleToObject.h mlir/include/mlir/Target/LLVM/NVVM/Utils.h mlir/include/mlir/Target/LLVM/ROCDL/Utils.h mlir/lib/Conversion/GPUCommon/CMakeLists.txt mlir/lib/Dialect/GPU/CMakeLists.txt mlir/lib/Target/LLVM/CMakeLists.txt mlir/lib/Target/LLVM/ModuleToObject.cpp mlir/lib/Target/LLVM/NVVM/Target.cpp mlir/lib/Target/LLVM/ROCDL/Target.cpp Removed: diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt index 292efa3316df748..7ff3acd48304de7 100644 --- a/llvm/CMakeLists.txt +++ b/llvm/CMakeLists.txt @@ -955,6 +955,8 @@ foreach(t ${LLVM_TARGETS_TO_BUILD}) endif() else() set(LLVM_ENUM_TARGETS "${LLVM_ENUM_TARGETS}LLVM_TARGET(${t})\n") +string(TOUPPER ${t} T_UPPER) +set(LLVM_HAS_${T_UPPER}_TARGET 1) endif() file(GLOB asmp_file "${td}/*AsmPrinter.cpp") diff --git a/llvm/include/llvm/Config/llvm-config.h.cmake b/llvm/include/llvm/Config/llvm-config.h.cmake index 17b2d47fb6c43a3..6605ea60df99e14 100644 --- a/llvm/include/llvm/Config/llvm-config.h.cmake +++ b/llvm/include/llvm/Config/llvm-config.h.cmake @@ -54,6 +54,81 @@ /* LLVM name for the native target MCA init function, if available */ #cmakedefine LLVM_NATIVE_TARGETMCA LLVMInitialize${LLVM_NATIVE_ARCH}TargetMCA +/* Define if the AArch64 target is built in */ +#cmakedefine01 LLVM_HAS_AARCH64_TARGET + +/* Define if the AMDGPU target is built in */ +#cmakedefine01 LLVM_HAS_AMDGPU_TARGET + +/* Define if the ARC target is built in */ +#cmakedefine01 LLVM_HAS_ARC_TARGET + +/* Define if the ARM target is built in */ +#cmakedefine01 LLVM_HAS_ARM_TARGET + +/* Define if the AVR target is built in */ +#cmakedefine01 LLVM_HAS_AVR_TARGET + +/* Define if the BPF target is built in */ +#cmakedefine01 LLVM_HAS_BPF_TARGET + +/* Define if the CSKY target is built in */ +#cmakedefine01 LLVM_HAS_CSKY_TARGET + +/* Define if the DirectX target is built in */ +#cmakedefine01 LLVM_HAS_DIRECTX_TARGET + +/* Define if the Hexagon target is built in */ +#cmakedefine01 LLVM_HAS_HEXAGON_TARGET + +/* Define if the Lanai target is built in */ +#cmakedefine01 LLVM_HAS_LANAI_TARGET + +/* Define if the LoongArch target is built in */ +#cmakedefine01 LLVM_HAS_LOONGARCH_TARGET + +/* Define if the M68k target is built in */ +#cmakedefine01 LLVM_HAS_M68K_TARGET + +/* Define if the Mips target is built in */ +#cmakedefine01 LLVM_HAS_MIPS_TARGET + +/* Define if the MSP430 target is built in */ +#cmakedefine01 LLVM_HAS_MSP430_TARGET + +/* Define if the NVPTX target is built in */ +#cmakedefine01 LLVM_HAS_NVPTX_TARGET + +/* Define if the PowerPC target is built in */ +#cmakedefine01 LLVM_HAS_POWERPC_TARGET + +/* Define if the RISCV target is built in */ +#cmakedefine01 LLVM_HAS_RISCV_TARGET + +/* Define if the Sparc target is built in */ +#cmakedefine01 LLVM_HAS_SPARC_TARGET + +/* Define if the SPIRV target is built in */ +#cmakedefine01 LLVM_HAS_SPIRV_TARGET + +/* Define if the SystemZ target is built in */ +#cmakedefine01 LLVM_HAS_SYSTEMZ_TARGET + +/* Define if the VE target is built in */ +#cmakedefine01 LLVM_HAS_VE_TARGET + +/* Define if the WebAssembly target is built in */ +#cmakedefine01 LLVM_HAS_WEBASSEMBLY_TARGET + +/* Define if the X86 target is built in */ +#cmakedefine01 LLVM_HAS_X86_TARGET + +/* Define if the XCore target is built in */ +#cmakedefine01 LLVM_HAS_XCORE_TARGET + +/* Define if the Xtensa target is built in */ +#cmakedefine01 LLVM_HAS_XTENSA_TARGET + /* Define if this is Unixish platform */ #cmakedefine LLVM_ON_UNIX ${LLVM_ON_UNIX} diff --git a/mlir/include/mlir/Target/LLVM/ModuleToObject.h b/mlir/include/mlir/Target/LLVM/ModuleToObject.h index d17afc1077fb45d..e40d7e9a43dd6b5 100644 --- a/mlir/include/mlir/Target/LLVM/ModuleToObject.h +++ b/mlir/include/mlir/Target/LLVM/ModuleToObject.h @@ -31,7 +31,7 @@ class ModuleToObject { public: ModuleToObject(Operation , StringRef triple, StringRef chip, StringRef features = {}, int optLevel = 3); - virtual ~ModuleToObject() = default; + virtual ~ModuleToObject(); /// Returns the operation being serialized. Operation (); @@ -42,44 +42,43 @@ class ModuleToObject { protected: // Hooks to be implemented by derived classes. + /// Hook for computing the Datalayout + virtual void setDataLayoutAndTriple(llvm::Module ); + /// Hook for loading bitcode files, returns std::nullopt on failure. virtual std::optional>> - loadBitcodeFiles(llvm::Module ,
[llvm-branch-commits] [llvm] f013914 - [혀헽헿] initial version
Author: Mehdi Amini Date: 2023-11-03T03:07:29-07:00 New Revision: f013914def456db56fe6aeacacafb200cc11fe0e URL: https://github.com/llvm/llvm-project/commit/f013914def456db56fe6aeacacafb200cc11fe0e DIFF: https://github.com/llvm/llvm-project/commit/f013914def456db56fe6aeacacafb200cc11fe0e.diff LOG: [혀헽헿] initial version Created using spr 1.3.4 Added: Modified: llvm/CMakeLists.txt llvm/include/llvm/Config/llvm-config.h.cmake Removed: diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt index 292efa3316df748..7ff3acd48304de7 100644 --- a/llvm/CMakeLists.txt +++ b/llvm/CMakeLists.txt @@ -955,6 +955,8 @@ foreach(t ${LLVM_TARGETS_TO_BUILD}) endif() else() set(LLVM_ENUM_TARGETS "${LLVM_ENUM_TARGETS}LLVM_TARGET(${t})\n") +string(TOUPPER ${t} T_UPPER) +set(LLVM_HAS_${T_UPPER}_TARGET 1) endif() file(GLOB asmp_file "${td}/*AsmPrinter.cpp") diff --git a/llvm/include/llvm/Config/llvm-config.h.cmake b/llvm/include/llvm/Config/llvm-config.h.cmake index 17b2d47fb6c43a3..6605ea60df99e14 100644 --- a/llvm/include/llvm/Config/llvm-config.h.cmake +++ b/llvm/include/llvm/Config/llvm-config.h.cmake @@ -54,6 +54,81 @@ /* LLVM name for the native target MCA init function, if available */ #cmakedefine LLVM_NATIVE_TARGETMCA LLVMInitialize${LLVM_NATIVE_ARCH}TargetMCA +/* Define if the AArch64 target is built in */ +#cmakedefine01 LLVM_HAS_AARCH64_TARGET + +/* Define if the AMDGPU target is built in */ +#cmakedefine01 LLVM_HAS_AMDGPU_TARGET + +/* Define if the ARC target is built in */ +#cmakedefine01 LLVM_HAS_ARC_TARGET + +/* Define if the ARM target is built in */ +#cmakedefine01 LLVM_HAS_ARM_TARGET + +/* Define if the AVR target is built in */ +#cmakedefine01 LLVM_HAS_AVR_TARGET + +/* Define if the BPF target is built in */ +#cmakedefine01 LLVM_HAS_BPF_TARGET + +/* Define if the CSKY target is built in */ +#cmakedefine01 LLVM_HAS_CSKY_TARGET + +/* Define if the DirectX target is built in */ +#cmakedefine01 LLVM_HAS_DIRECTX_TARGET + +/* Define if the Hexagon target is built in */ +#cmakedefine01 LLVM_HAS_HEXAGON_TARGET + +/* Define if the Lanai target is built in */ +#cmakedefine01 LLVM_HAS_LANAI_TARGET + +/* Define if the LoongArch target is built in */ +#cmakedefine01 LLVM_HAS_LOONGARCH_TARGET + +/* Define if the M68k target is built in */ +#cmakedefine01 LLVM_HAS_M68K_TARGET + +/* Define if the Mips target is built in */ +#cmakedefine01 LLVM_HAS_MIPS_TARGET + +/* Define if the MSP430 target is built in */ +#cmakedefine01 LLVM_HAS_MSP430_TARGET + +/* Define if the NVPTX target is built in */ +#cmakedefine01 LLVM_HAS_NVPTX_TARGET + +/* Define if the PowerPC target is built in */ +#cmakedefine01 LLVM_HAS_POWERPC_TARGET + +/* Define if the RISCV target is built in */ +#cmakedefine01 LLVM_HAS_RISCV_TARGET + +/* Define if the Sparc target is built in */ +#cmakedefine01 LLVM_HAS_SPARC_TARGET + +/* Define if the SPIRV target is built in */ +#cmakedefine01 LLVM_HAS_SPIRV_TARGET + +/* Define if the SystemZ target is built in */ +#cmakedefine01 LLVM_HAS_SYSTEMZ_TARGET + +/* Define if the VE target is built in */ +#cmakedefine01 LLVM_HAS_VE_TARGET + +/* Define if the WebAssembly target is built in */ +#cmakedefine01 LLVM_HAS_WEBASSEMBLY_TARGET + +/* Define if the X86 target is built in */ +#cmakedefine01 LLVM_HAS_X86_TARGET + +/* Define if the XCore target is built in */ +#cmakedefine01 LLVM_HAS_XCORE_TARGET + +/* Define if the Xtensa target is built in */ +#cmakedefine01 LLVM_HAS_XTENSA_TARGET + /* Define if this is Unixish platform */ #cmakedefine LLVM_ON_UNIX ${LLVM_ON_UNIX} ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] Backport into 17.x : [mlir][nfc] Allow ops to have operands/attributes named `context`. (PR #65281)
https://github.com/joker-eph review_requested https://github.com/llvm/llvm-project/pull/65281 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] Backport into 17.x : [mlir][nfc] Allow ops to have operands/attributes named `context`. (PR #65281)
https://github.com/joker-eph created https://github.com/llvm/llvm-project/pull/65281: This is important to back port because it'll help adopting MLIR "properties" which became the default in LLVM 18 Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D159185 >From 1810c14ff5f3a0a34b8a4c858f51f15264236eba Mon Sep 17 00:00:00 2001 From: Christian Sigg Date: Wed, 30 Aug 2023 12:23:25 +0200 Subject: [PATCH] [mlir][nfc] Allow ops to have operands/attributes named `context`. This is probably a bad idea, but it's only become a problem with properties and is easy to fix. Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D159185 --- mlir/include/mlir/IR/OperationSupport.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mlir/include/mlir/IR/OperationSupport.h b/mlir/include/mlir/IR/OperationSupport.h index f3a79eb52f8ec00..adae3560570ddca 100644 --- a/mlir/include/mlir/IR/OperationSupport.h +++ b/mlir/include/mlir/IR/OperationSupport.h @@ -555,7 +555,7 @@ class RegisteredOperationName : public OperationName { StringRef name) final { if constexpr (hasProperties) { auto concreteOp = cast(op); -return ConcreteOp::getInherentAttr(concreteOp.getContext(), +return ConcreteOp::getInherentAttr(concreteOp->getContext(), concreteOp.getProperties(), name); } // If the op does not have support for properties, we dispatch back to the @@ -576,7 +576,7 @@ class RegisteredOperationName : public OperationName { void populateInherentAttrs(Operation *op, NamedAttrList ) final { if constexpr (hasProperties) { auto concreteOp = cast(op); -ConcreteOp::populateInherentAttrs(concreteOp.getContext(), +ConcreteOp::populateInherentAttrs(concreteOp->getContext(), concreteOp.getProperties(), attrs); } } ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] 922b26c - Add Python bindings for the builtin dialect
Author: Mehdi Amini Date: 2021-01-21T22:44:44Z New Revision: 922b26cde4d1c89a5fa90e6a1d6d97d0f8eace6d URL: https://github.com/llvm/llvm-project/commit/922b26cde4d1c89a5fa90e6a1d6d97d0f8eace6d DIFF: https://github.com/llvm/llvm-project/commit/922b26cde4d1c89a5fa90e6a1d6d97d0f8eace6d.diff LOG: Add Python bindings for the builtin dialect This includes some minor customization for FuncOp and ModuleOp. Differential Revision: https://reviews.llvm.org/D95022 Added: mlir/lib/Bindings/Python/BuiltinOps.td mlir/lib/Bindings/Python/mlir/dialects/_builtin.py mlir/test/Bindings/Python/.style.yapf mlir/test/Bindings/Python/dialects/builtin.py Modified: mlir/lib/Bindings/Python/CMakeLists.txt mlir/lib/Bindings/Python/mlir/dialects/__init__.py mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp Removed: diff --git a/mlir/lib/Bindings/Python/BuiltinOps.td b/mlir/lib/Bindings/Python/BuiltinOps.td new file mode 100644 index ..ecbb8227d490 --- /dev/null +++ b/mlir/lib/Bindings/Python/BuiltinOps.td @@ -0,0 +1,15 @@ +//===-- BuiltinOps.td - Entry point for builtin bindings ---*- tablegen -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#ifndef PYTHON_BINDINGS_BUILTIN_OPS +#define PYTHON_BINDINGS_BUILTIN_OPS + +include "mlir/Bindings/Python/Attributes.td" +include "mlir/IR/BuiltinOps.td" + +#endif diff --git a/mlir/lib/Bindings/Python/CMakeLists.txt b/mlir/lib/Bindings/Python/CMakeLists.txt index 1749ea2e5472..951aa7883c90 100644 --- a/mlir/lib/Bindings/Python/CMakeLists.txt +++ b/mlir/lib/Bindings/Python/CMakeLists.txt @@ -11,6 +11,7 @@ set(PY_SRC_FILES mlir/ir.py mlir/dialects/__init__.py mlir/dialects/_linalg.py + mlir/dialects/_builtin.py mlir/ir.py mlir/passmanager.py mlir/transforms/__init__.py @@ -36,6 +37,11 @@ endforeach() # Generate dialect-specific bindings. +add_mlir_dialect_python_bindings(MLIRBindingsPythonBuiltinOps + TD_FILE BuiltinOps.td + DIALECT_NAME builtin) +add_dependencies(MLIRBindingsPythonSources MLIRBindingsPythonBuiltinOps) + add_mlir_dialect_python_bindings(MLIRBindingsPythonLinalgOps TD_FILE LinalgOps.td DIALECT_NAME linalg diff --git a/mlir/lib/Bindings/Python/mlir/dialects/__init__.py b/mlir/lib/Bindings/Python/mlir/dialects/__init__.py index 9c003b415438..f5a71bf88700 100644 --- a/mlir/lib/Bindings/Python/mlir/dialects/__init__.py +++ b/mlir/lib/Bindings/Python/mlir/dialects/__init__.py @@ -43,7 +43,7 @@ def class_decorator(parent_opview_cls: type): except AttributeError: # Try to default resolve it. try: -select_mixin = getattr(ext_module, parent_opview_cls.__name__) +mixin_cls = getattr(ext_module, parent_opview_cls.__name__) except AttributeError: pass else: diff --git a/mlir/lib/Bindings/Python/mlir/dialects/_builtin.py b/mlir/lib/Bindings/Python/mlir/dialects/_builtin.py new file mode 100644 index ..8d430d5a50da --- /dev/null +++ b/mlir/lib/Bindings/Python/mlir/dialects/_builtin.py @@ -0,0 +1,93 @@ +# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +from mlir.ir import * + + +class ModuleOp: + """Specialization for the module op class.""" + + def __init__(self, loc=None, ip=None): +super().__init__( +self._ods_build_default(operands=[], results=[], loc=loc, ip=ip)) +body = self.regions[0].blocks.append() +with InsertionPoint(body): + Operation.create("module_terminator") + + @property + def body(self): +return self.regions[0].blocks[0] + + +class FuncOp: + """Specialization for the func op class.""" + + def __init__(self, + name, + type, + visibility, + body_builder=None, + loc=None, + ip=None): +""" +Create a FuncOp with the provided `name`, `type`, and `visibility`. +- `name` is a string representing the function name. +- `type` is either a FunctionType or a pair of list describing inputs and + results. +- `visibility` is a string matching `public`, `private`, or `nested`. The + empty string implies a private visibility. +- `body_builder` is an optional callback, when provided a new entry block + is created and the callback is invoked with the new op as argument within + an InsertionPoint context already set for the block. The callback is + expected to insert a terminator in the block. +""" +
[llvm-branch-commits] [mlir] 8a7ff73 - [mlir] Make MLIRContext::getOrLoadDialect(StringRef, TypeID, ...) public
Author: mfehr Date: 2021-01-21T00:29:58Z New Revision: 8a7ff7301a6ce50f2adf52959c04f37a00c5a631 URL: https://github.com/llvm/llvm-project/commit/8a7ff7301a6ce50f2adf52959c04f37a00c5a631 DIFF: https://github.com/llvm/llvm-project/commit/8a7ff7301a6ce50f2adf52959c04f37a00c5a631.diff LOG: [mlir] Make MLIRContext::getOrLoadDialect(StringRef, TypeID, ...) public Having this function in a public scope is helpful to register dialects that are defined at runtime, and thus that need a runtime-defined TypeID. Also, a similar function in DialectRegistry, insert(TypeID, StringRef, ...), has a public scope. Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D95091 Added: Modified: mlir/include/mlir/IR/MLIRContext.h Removed: diff --git a/mlir/include/mlir/IR/MLIRContext.h b/mlir/include/mlir/IR/MLIRContext.h index e460064a889f..4751f00a36df 100644 --- a/mlir/include/mlir/IR/MLIRContext.h +++ b/mlir/include/mlir/IR/MLIRContext.h @@ -156,17 +156,19 @@ class MLIRContext { void enterMultiThreadedExecution(); void exitMultiThreadedExecution(); -private: - const std::unique_ptr impl; - /// Get a dialect for the provided namespace and TypeID: abort the program if /// a dialect exist for this namespace with diff erent TypeID. If a dialect has /// not been loaded for this namespace/TypeID yet, use the provided ctor to /// create one on the fly and load it. Returns a pointer to the dialect owned /// by the context. + /// The use of this method is in general discouraged in favor of + /// 'getOrLoadDialect()'. Dialect *getOrLoadDialect(StringRef dialectNamespace, TypeID dialectID, function_ref()> ctor); +private: + const std::unique_ptr impl; + MLIRContext(const MLIRContext &) = delete; void operator=(const MLIRContext &) = delete; }; ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] 1bf2b16 - Implement constant folding for DivFOp
Author: Jackson Fellows Date: 2021-01-19T23:08:06Z New Revision: 1bf2b1665b43e1a5090177486c8fa6374a4596a2 URL: https://github.com/llvm/llvm-project/commit/1bf2b1665b43e1a5090177486c8fa6374a4596a2 DIFF: https://github.com/llvm/llvm-project/commit/1bf2b1665b43e1a5090177486c8fa6374a4596a2.diff LOG: Implement constant folding for DivFOp Add a constant folder for DivFOp. Analogous to existing folders for AddFOp, SubFOp, and MulFOp. Matches the behavior of existing LLVM constant folding (https://github.com/llvm/llvm-project/blob/999f5da6b3088fa4c0bb9d05b358d015ca74c71f/llvm/lib/IR/ConstantFold.cpp#L1432). Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D94939 Added: Modified: mlir/include/mlir/Dialect/StandardOps/IR/Ops.td mlir/lib/Dialect/StandardOps/IR/Ops.cpp Removed: diff --git a/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td b/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td index 8e3f1f1a7a85..8db6129dbb88 100644 --- a/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td +++ b/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td @@ -1589,6 +1589,7 @@ def DimOp : Std_Op<"dim", [NoSideEffect]> { def DivFOp : FloatArithmeticOp<"divf"> { let summary = "floating point division operation"; + let hasFolder = 1; } //===--===// diff --git a/mlir/lib/Dialect/StandardOps/IR/Ops.cpp b/mlir/lib/Dialect/StandardOps/IR/Ops.cpp index e1be47f54798..1718ab14d5d1 100644 --- a/mlir/lib/Dialect/StandardOps/IR/Ops.cpp +++ b/mlir/lib/Dialect/StandardOps/IR/Ops.cpp @@ -1483,6 +1483,15 @@ void DimOp::getCanonicalizationPatterns(OwningRewritePatternList , DimOfCastOp>(context); } +// --- +// DivFOp +// --- + +OpFoldResult DivFOp::fold(ArrayRef operands) { + return constFoldBinaryOp( + operands, [](APFloat a, APFloat b) { return a / b; }); +} + // --- // DmaStartOp // --- ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] 7dadcd0 - Fix a few GCC compiler warnings (NFC)
Author: Mehdi Amini Date: 2021-01-19T06:00:04Z New Revision: 7dadcd02d6ce0278723c87736f6278610da0ddb2 URL: https://github.com/llvm/llvm-project/commit/7dadcd02d6ce0278723c87736f6278610da0ddb2 DIFF: https://github.com/llvm/llvm-project/commit/7dadcd02d6ce0278723c87736f6278610da0ddb2.diff LOG: Fix a few GCC compiler warnings (NFC) Added: Modified: mlir/lib/CAPI/Dialect/Linalg.cpp mlir/lib/CAPI/Dialect/SCF.cpp mlir/lib/CAPI/Dialect/Shape.cpp mlir/lib/CAPI/Dialect/Standard.cpp mlir/lib/CAPI/Dialect/Tensor.cpp mlir/lib/Dialect/Linalg/Transforms/Sparsification.cpp mlir/lib/ExecutionEngine/SparseUtils.cpp mlir/lib/Rewrite/ByteCode.cpp mlir/tools/mlir-tblgen/OpFormatGen.cpp mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp Removed: diff --git a/mlir/lib/CAPI/Dialect/Linalg.cpp b/mlir/lib/CAPI/Dialect/Linalg.cpp index 3e45c41adc72..da6fd4846bd6 100644 --- a/mlir/lib/CAPI/Dialect/Linalg.cpp +++ b/mlir/lib/CAPI/Dialect/Linalg.cpp @@ -11,4 +11,4 @@ #include "mlir/Dialect/Linalg/IR/LinalgOps.h" MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(Linalg, linalg, - mlir::linalg::LinalgDialect); + mlir::linalg::LinalgDialect) diff --git a/mlir/lib/CAPI/Dialect/SCF.cpp b/mlir/lib/CAPI/Dialect/SCF.cpp index f81b010b04e2..c1dca6d2118f 100644 --- a/mlir/lib/CAPI/Dialect/SCF.cpp +++ b/mlir/lib/CAPI/Dialect/SCF.cpp @@ -10,4 +10,4 @@ #include "mlir-c/Dialect/SCF.h" #include "mlir/CAPI/Registration.h" -MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(SCF, scf, mlir::scf::SCFDialect); +MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(SCF, scf, mlir::scf::SCFDialect) diff --git a/mlir/lib/CAPI/Dialect/Shape.cpp b/mlir/lib/CAPI/Dialect/Shape.cpp index 22e20ad8eaaa..1f8e83a0c729 100644 --- a/mlir/lib/CAPI/Dialect/Shape.cpp +++ b/mlir/lib/CAPI/Dialect/Shape.cpp @@ -10,4 +10,4 @@ #include "mlir-c/Dialect/Shape.h" #include "mlir/CAPI/Registration.h" -MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(Shape, shape, mlir::shape::ShapeDialect); +MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(Shape, shape, mlir::shape::ShapeDialect) diff --git a/mlir/lib/CAPI/Dialect/Standard.cpp b/mlir/lib/CAPI/Dialect/Standard.cpp index b611cb85f6f6..57083a8a21a3 100644 --- a/mlir/lib/CAPI/Dialect/Standard.cpp +++ b/mlir/lib/CAPI/Dialect/Standard.cpp @@ -10,4 +10,4 @@ #include "mlir/CAPI/Registration.h" #include "mlir/Dialect/StandardOps/IR/Ops.h" -MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(Standard, std, mlir::StandardOpsDialect); +MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(Standard, std, mlir::StandardOpsDialect) diff --git a/mlir/lib/CAPI/Dialect/Tensor.cpp b/mlir/lib/CAPI/Dialect/Tensor.cpp index 8f336c0bf3c4..266efc26b6f9 100644 --- a/mlir/lib/CAPI/Dialect/Tensor.cpp +++ b/mlir/lib/CAPI/Dialect/Tensor.cpp @@ -11,4 +11,4 @@ #include "mlir/CAPI/Registration.h" MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(Tensor, tensor, - mlir::tensor::TensorDialect); + mlir::tensor::TensorDialect) diff --git a/mlir/lib/Dialect/Linalg/Transforms/Sparsification.cpp b/mlir/lib/Dialect/Linalg/Transforms/Sparsification.cpp index 84c71e84c42e..898b15266072 100644 --- a/mlir/lib/Dialect/Linalg/Transforms/Sparsification.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/Sparsification.cpp @@ -500,6 +500,7 @@ static unsigned buildLattices(Merger , linalg::GenericOp op, case Kind::kAddI: return merger.takeDisj(kind, s0, s1); } + llvm_unreachable("unexpected expression kind"); } /// Maps sparse integer option to actual integral storage type. @@ -512,6 +513,7 @@ static Type genIntType(PatternRewriter , linalg::SparseIntType tp) { case linalg::SparseIntType::kI32: return rewriter.getIntegerType(32); } + llvm_unreachable("unexpected SparseIntType"); } /// Local bufferization of all dense and sparse data structures. @@ -735,6 +737,7 @@ static Value genExp(Merger , CodeGen , PatternRewriter , case Kind::kAddI: return rewriter.create(op.getLoc(), v0, v1); } + llvm_unreachable("unexpected expression kind"); } /// Hoists loop invariant tensor loads for which indices have been exhausted. @@ -825,6 +828,7 @@ static bool isVectorFor(CodeGen , bool isInner, bool isSparse) { case linalg::SparseVectorizationStrategy::kAnyStorageInnerLoop: return isInner; } + llvm_unreachable("unexpected vectorization strategy"); } /// Returns parallelization strategy. Any implicit loop in the Linalg operation @@ -844,6 +848,7 @@ static bool isParallelFor(CodeGen , bool isOuter, bool isReduction, case linalg::SparseParallelizationStrategy::kAnyStorageAnyLoop: return !isReduction && !isVector; } + llvm_unreachable("unexpected parallelization strategy"); } /// Generates a for-loop on a single index. diff --git a/mlir/lib/ExecutionEngine/SparseUtils.cpp
[llvm-branch-commits] [mlir] d8113cd - Add newline to terminate debug message (NFC)
Author: Mehdi Amini Date: 2021-01-14T19:29:18Z New Revision: d8113cda782b56477d71321027c50389f05f5d31 URL: https://github.com/llvm/llvm-project/commit/d8113cda782b56477d71321027c50389f05f5d31 DIFF: https://github.com/llvm/llvm-project/commit/d8113cda782b56477d71321027c50389f05f5d31.diff LOG: Add newline to terminate debug message (NFC) Added: Modified: mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp Removed: diff --git a/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp b/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp index 170f882c02d0..c1d286690c48 100644 --- a/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp +++ b/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp @@ -258,7 +258,7 @@ mlir::applyPatternsAndFoldGreedily(MutableArrayRef regions, bool converged = driver.simplify(regions, maxIterations); LLVM_DEBUG(if (!converged) { llvm::dbgs() << "The pattern rewrite doesn't converge after scanning " - << maxIterations << " times"; + << maxIterations << " times\n"; }); return success(converged); } ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] 762ffc9 - Update syntax for tensor and memref types to match parser.
Author: Richard Uhler Date: 2021-01-11T22:57:14Z New Revision: 762ffc95550c32606e771b630fcab2e521873419 URL: https://github.com/llvm/llvm-project/commit/762ffc95550c32606e771b630fcab2e521873419 DIFF: https://github.com/llvm/llvm-project/commit/762ffc95550c32606e771b630fcab2e521873419.diff LOG: Update syntax for tensor and memref types to match parser. Based on the comments in lib/Parser/TypeParser.cpp on the parseMemRefType and parseTensorType functions. Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D94262 Added: Modified: mlir/docs/LangRef.md mlir/lib/Parser/TypeParser.cpp Removed: diff --git a/mlir/docs/LangRef.md b/mlir/docs/LangRef.md index 28962a8893ee..017ec02af7ae 100644 --- a/mlir/docs/LangRef.md +++ b/mlir/docs/LangRef.md @@ -929,15 +929,15 @@ Syntax: ``` memref-type ::= ranked-memref-type | unranked-memref-type -ranked-memref-type ::= `memref` `<` dimension-list-ranked tensor-memref-element-type +ranked-memref-type ::= `memref` `<` dimension-list-ranked type (`,` layout-specification)? (`,` memory-space)? `>` -unranked-memref-type ::= `memref` `<*x` tensor-memref-element-type - (`,` memory-space)? `>` +unranked-memref-type ::= `memref` `<*x` type (`,` memory-space)? `>` stride-list ::= `[` (dimension (`,` dimension)*)? `]` strided-layout ::= `offset:` dimension `,` `strides: ` stride-list -layout-specification ::= semi-affine-map | strided-layout +semi-affine-map-composition ::= (semi-affine-map `,` )* semi-affine-map +layout-specification ::= semi-affine-map-composition | strided-layout memory-space ::= integer-literal /* | TODO: address-space-id */ ``` @@ -1201,10 +1201,8 @@ where its value does not have a defined dynamic representation. Syntax: ``` -tensor-type ::= `tensor` `<` dimension-list tensor-memref-element-type `>` -tensor-memref-element-type ::= vector-element-type | vector-type | complex-type +tensor-type ::= `tensor` `<` dimension-list type `>` -// memref requires a known rank, but tensor does not. dimension-list ::= dimension-list-ranked | (`*` `x`) dimension-list-ranked ::= (dimension `x`)* dimension ::= `?` | decimal-literal diff --git a/mlir/lib/Parser/TypeParser.cpp b/mlir/lib/Parser/TypeParser.cpp index ab7f85a645e4..c258cc8b6d29 100644 --- a/mlir/lib/Parser/TypeParser.cpp +++ b/mlir/lib/Parser/TypeParser.cpp @@ -181,12 +181,14 @@ ParseResult Parser::parseStridedLayout(int64_t , /// memref-type ::= ranked-memref-type | unranked-memref-type /// /// ranked-memref-type ::= `memref` `<` dimension-list-ranked type -/// (`,` semi-affine-map-composition)? (`,` -/// memory-space)? `>` +/// (`,` layout-specification)? (`,` memory-space)? `>` /// /// unranked-memref-type ::= `memref` `<*x` type (`,` memory-space)? `>` /// +/// stride-list ::= `[` (dimension (`,` dimension)*)? `]` +/// strided-layout ::= `offset:` dimension `,` `strides: ` stride-list /// semi-affine-map-composition ::= (semi-affine-map `,` )* semi-affine-map +/// layout-specification ::= semi-affine-map-composition | strided-layout /// memory-space ::= integer-literal /* | TODO: address-space-id */ /// Type Parser::parseMemRefType() { ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] 1107758 - Revert "[mlir][linalg] Support parsing attributes in named op spec"
Author: Mehdi Amini Date: 2021-01-11T20:43:42Z New Revision: 110775809ad114e190132290657a86b2c292a878 URL: https://github.com/llvm/llvm-project/commit/110775809ad114e190132290657a86b2c292a878 DIFF: https://github.com/llvm/llvm-project/commit/110775809ad114e190132290657a86b2c292a878.diff LOG: Revert "[mlir][linalg] Support parsing attributes in named op spec" This reverts commit df86f15f0c53c395dac5a14aba08745bc12b9b9b. The gcc-5 build was broken by this change: mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-gen.cpp:1275:77: required from here /usr/include/c++/5/ext/new_allocator.h:120:4: error: no matching function for call to 'std::pair, {anonymous}::TCParser::RegisteredAttr>::pair(llvm::StringRef&, {anonymous}::TCParser::RegisteredAttr' Added: Modified: mlir/test/mlir-linalg-ods-gen/test-linalg-ods-gen.tc mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-gen.cpp Removed: diff --git a/mlir/test/mlir-linalg-ods-gen/test-linalg-ods-gen.tc b/mlir/test/mlir-linalg-ods-gen/test-linalg-ods-gen.tc index 1ef128760637..f81380f02bb3 100644 --- a/mlir/test/mlir-linalg-ods-gen/test-linalg-ods-gen.tc +++ b/mlir/test/mlir-linalg-ods-gen/test-linalg-ods-gen.tc @@ -72,25 +72,3 @@ ods_def : def test3(A: f32(Batch, M, K), B: f32(K, N)) -> (C: f32(Batch, M, N)) { C(b, m, n) = std_addf(std_mulf(A(b, m, k), B(k, n))); } - -// Test attribute definitions -// ODS-LABEL: def Test4Op -// ODS: F32ArrayAttr:$array_attr, -// ODS: F32:$f32_attr, -// ODS: RankedF32ElementsAttr<[4]>:$fvec_attr, -// ODS: I32:$i32_attr, -// ODS: RankedI32ElementsAttr<[5, 6]>:$ivec_attr, -// ODS: OptionalAttr:$optional_attr -// -ods_def : -def test4(A: f32(Batch, M, K), B: f32(K, N)) -> (C: f32(Batch, M, N)) -attr( - f32_attr: f32, - i32_attr: i32, - fvec_attr: 4xf32, - ivec_attr: 5x6xi32, - array_attr : f32[], - optional_attr? : f32 -) { - C(b, m, n) = std_addf(std_mulf(A(b, m, k), B(k, n))); -} diff --git a/mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-gen.cpp b/mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-gen.cpp index e7ab5edc1118..592e6cb774fb 100644 --- a/mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-gen.cpp +++ b/mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-gen.cpp @@ -20,17 +20,11 @@ #include "mlir/Support/LLVM.h" #include "mlir/Support/LogicalResult.h" #include "llvm/ADT/SetVector.h" -#include "llvm/ADT/SmallVector.h" -#include "llvm/ADT/StringRef.h" -#include "llvm/ADT/StringSwitch.h" -#include "llvm/ADT/Twine.h" #include "llvm/Support/Casting.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/FormatVariadic.h" #include "llvm/Support/ToolOutputFile.h" -#include - #define DEBUG_TYPE "linalg-ods-gen" static llvm::cl::OptionCategory ODSGenCat("Linalg ODS Gen"); @@ -85,14 +79,11 @@ class Token { gt, l_brace, l_paren, -l_square, lt, minus, plus, -question, r_brace, r_paren, -r_square, semicolon, star, @@ -100,7 +91,6 @@ class Token { kw_def, FIRST_KEYWORD = kw_def, kw_ods_def, -kw_attr_def, kw_floordiv, kw_ceildiv, kw_mod, @@ -161,10 +151,6 @@ class Lexer { Token emitError(llvm::SMLoc loc, const Twine ); Token emitError(const char *loc, const Twine ); - /// Change the position of the lexer cursor. The next token we lex will start - /// at the designated point in the input. - void resetPointer(const char *newPtr) { curPtr = newPtr; } - private: Token formToken(Token::Kind kind, const char *tokStart) { return Token(kind, StringRef(tokStart, curPtr - tokStart)); @@ -261,14 +247,10 @@ Token Lexer::lexToken() { return formToken(Token::Kind::l_brace, tokStart); case '(': return formToken(Token::Kind::l_paren, tokStart); -case '[': - return formToken(Token::Kind::l_square, tokStart); case '}': return formToken(Token::Kind::r_brace, tokStart); case ')': return formToken(Token::Kind::r_paren, tokStart); -case ']': - return formToken(Token::Kind::r_square, tokStart); case '<': return formToken(Token::Kind::lt, tokStart); case '>': @@ -281,8 +263,6 @@ Token Lexer::lexToken() { return formToken(Token::Kind::semicolon, tokStart); case '*': return formToken(Token::Kind::star, tokStart); -case '?': - return formToken(Token::Kind::question, tokStart); case '/': if (*curPtr == '/') { skipComment(); @@ -309,7 +289,6 @@ Token Lexer::lexIdentifier(const char *tokStart) { // Check to see if this identifier is a keyword. StringRef str(tokStart, curPtr - tokStart); Token::Kind kind = StringSwitch(str) - .Case("attr", Token::Kind::kw_attr_def) .Case("def", Token::Kind::kw_def) .Case("ods_def", Token::Kind::kw_ods_def) .Case("floordiv",
[llvm-branch-commits] [mlir] 03d2493 - [mlir] Enhance mlir-opt show-dialects test case
Author: Lewuathe Date: 2021-01-09T20:43:51Z New Revision: 03d249396d6b736447d529915e77dfeb84f2eeae URL: https://github.com/llvm/llvm-project/commit/03d249396d6b736447d529915e77dfeb84f2eeae DIFF: https://github.com/llvm/llvm-project/commit/03d249396d6b736447d529915e77dfeb84f2eeae.diff LOG: [mlir] Enhance mlir-opt show-dialects test case mlir-opt supports many more test cases. All available dialects supported by latest mlir-opt should be coverted in the test case. Reviewed By: aartbik, stephenneuendorffer, mehdi_amini Differential Revision: https://reviews.llvm.org/D93821 Added: Modified: mlir/test/mlir-opt/commandline.mlir Removed: diff --git a/mlir/test/mlir-opt/commandline.mlir b/mlir/test/mlir-opt/commandline.mlir index 4cf6ea9d8a69..94eb94483790 100644 --- a/mlir/test/mlir-opt/commandline.mlir +++ b/mlir/test/mlir-opt/commandline.mlir @@ -1,16 +1,29 @@ // RUN: mlir-opt --show-dialects | FileCheck %s // CHECK: Available Dialects: -// CHECK: affine -// CHECK: gpu -// CHECK: linalg -// CHECK: llvm -// CHECK: nvvm -// CHECK: omp -// CHECK: quant -// CHECK: rocdl -// CHECK: scf -// CHECK: sdbm -// CHECK: spv -// CHECK: std -// CHECK: test -// CHECK: vector +// CHECK-NEXT: acc +// CHECK-NEXT: affine +// CHECK-NEXT: arm_neon +// CHECK-NEXT: arm_sve +// CHECK-NEXT: async +// CHECK-NEXT: avx512 +// CHECK-NEXT: gpu +// CHECK-NEXT: linalg +// CHECK-NEXT: llvm +// CHECK-NEXT: llvm_arm_neon +// CHECK-NEXT: llvm_arm_sve +// CHECK-NEXT: llvm_avx512 +// CHECK-NEXT: nvvm +// CHECK-NEXT: omp +// CHECK-NEXT: pdl +// CHECK-NEXT: pdl_interp +// CHECK-NEXT: quant +// CHECK-NEXT: rocdl +// CHECK-NEXT: scf +// CHECK-NEXT: sdbm +// CHECK-NEXT: shape +// CHECK-NEXT: spv +// CHECK-NEXT: std +// CHECK-NEXT: tensor +// CHECK-NEXT: test +// CHECK-NEXT: tosa +// CHECK-NEXT: vector ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] f02e61a - Fix MLIR DRR matching when attributes are interleaved with operands
Author: Mehdi Amini Date: 2021-01-08T03:18:26Z New Revision: f02e61a8b957871292e092aa440964c0f4e2bb21 URL: https://github.com/llvm/llvm-project/commit/f02e61a8b957871292e092aa440964c0f4e2bb21 DIFF: https://github.com/llvm/llvm-project/commit/f02e61a8b957871292e092aa440964c0f4e2bb21.diff LOG: Fix MLIR DRR matching when attributes are interleaved with operands The ODSOperand indexing should ignore the attributes. Differential Revision: https://reviews.llvm.org/D94281 Added: Modified: mlir/test/mlir-tblgen/rewriter-indexing.td mlir/tools/mlir-tblgen/RewriterGen.cpp Removed: diff --git a/mlir/test/mlir-tblgen/rewriter-indexing.td b/mlir/test/mlir-tblgen/rewriter-indexing.td index c21b04f6d0f6..a6b403285765 100644 --- a/mlir/test/mlir-tblgen/rewriter-indexing.td +++ b/mlir/test/mlir-tblgen/rewriter-indexing.td @@ -51,6 +51,9 @@ def test2 : Pat<(COp $attr1, $op1, $attr2, (AOp $op2)), // Check rewriting with a DAG subtree in the result and remapping a location. // CHECK: struct test3 : public ::mlir::RewritePattern { +// We expect ODSOperand 0 here, the attribute before the operand in BOp +// definition shouldn't shift the counter. +// CHECK: op1 = (*castedOp0.getODSOperands(0).begin()).getDefiningOp(); // CHECK: rewriter.create((*a.getODSResults(0).begin()).getLoc() def test3 : Pat<(BOp $attr, (AOp:$a $input)), (BOp $attr, (AOp $input), (location $a))>; diff --git a/mlir/tools/mlir-tblgen/RewriterGen.cpp b/mlir/tools/mlir-tblgen/RewriterGen.cpp index 9fca15b416ba..1a665174 100644 --- a/mlir/tools/mlir-tblgen/RewriterGen.cpp +++ b/mlir/tools/mlir-tblgen/RewriterGen.cpp @@ -83,9 +83,10 @@ class PatternEmitter { void emitOpMatch(DagNode tree, StringRef opName, int depth); // Emits C++ statements for matching the `argIndex`-th argument of the given - // DAG `tree` as an operand. + // DAG `tree` as an operand. operandIndex is the index in the DAG excluding + // the preceding attributes. void emitOperandMatch(DagNode tree, StringRef opName, int argIndex, -int depth); +int operandIndex, int depth); // Emits C++ statements for matching the `argIndex`-th argument of the given // DAG `tree` as an attribute. @@ -379,7 +380,7 @@ void PatternEmitter::emitOpMatch(DagNode tree, StringRef opName, int depth) { // Next handle DAG leaf: operand or attribute if (opArg.is()) { // emitOperandMatch's argument indexing counts attributes. - emitOperandMatch(tree, castedName, i, depth); + emitOperandMatch(tree, castedName, i, nextOperand, depth); ++nextOperand; } else if (opArg.is()) { emitAttributeMatch(tree, opName, i, depth); @@ -393,7 +394,8 @@ void PatternEmitter::emitOpMatch(DagNode tree, StringRef opName, int depth) { } void PatternEmitter::emitOperandMatch(DagNode tree, StringRef opName, - int argIndex, int depth) { + int argIndex, int operandIndex, + int depth) { Operator = tree.getDialectOp(opMap); auto *operand = op.getArg(argIndex).get(); auto matcher = tree.getArgAsLeaf(argIndex); @@ -418,7 +420,7 @@ void PatternEmitter::emitOperandMatch(DagNode tree, StringRef opName, PrintFatalError(loc, error); } auto self = formatv("(*{0}.getODSOperands({1}).begin()).getType()", - opName, argIndex); + opName, operandIndex); emitMatchCheck( opName, tgfmt(constraint.getConditionTemplate(), (self)), ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [debuginfo-tests] 9e1aaa9 - Fix check-gdb-mlir-support build after MLIR API changed to take Context as first argument
Author: Mehdi Amini Date: 2021-01-07T21:30:39Z New Revision: 9e1aaa9943b814c22ae03f4abb3171dac8062801 URL: https://github.com/llvm/llvm-project/commit/9e1aaa9943b814c22ae03f4abb3171dac8062801 DIFF: https://github.com/llvm/llvm-project/commit/9e1aaa9943b814c22ae03f4abb3171dac8062801.diff LOG: Fix check-gdb-mlir-support build after MLIR API changed to take Context as first argument Added: Modified: debuginfo-tests/llvm-prettyprinters/gdb/mlir-support.cpp Removed: diff --git a/debuginfo-tests/llvm-prettyprinters/gdb/mlir-support.cpp b/debuginfo-tests/llvm-prettyprinters/gdb/mlir-support.cpp index a65f62404de8..629ef1668c8f 100644 --- a/debuginfo-tests/llvm-prettyprinters/gdb/mlir-support.cpp +++ b/debuginfo-tests/llvm-prettyprinters/gdb/mlir-support.cpp @@ -15,13 +15,13 @@ mlir::Value Value({reinterpret_cast(0x8), mlir::Type Type(nullptr); mlir::Type IndexType = mlir::IndexType::get(); mlir::Type IntegerType = -mlir::IntegerType::get(3, mlir::IntegerType::Unsigned, ); +mlir::IntegerType::get(, 3, mlir::IntegerType::Unsigned); mlir::Type FloatType = mlir::Float32Type::get(); mlir::Type MemRefType = mlir::MemRefType::get({4, 5}, FloatType); mlir::Type UnrankedMemRefType = mlir::UnrankedMemRefType::get(IntegerType, 6); mlir::Type VectorType = mlir::VectorType::get({1, 2}, FloatType); mlir::Type TupleType = -mlir::TupleType::get(mlir::TypeRange({IndexType, FloatType}), ); +mlir::TupleType::get(, mlir::TypeRange({IndexType, FloatType})); auto UnknownLoc = mlir::UnknownLoc::get(); auto FileLineColLoc = mlir::FileLineColLoc::get("file", 7, 8, ); ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [debuginfo-tests] 476db17 - Fix include path for check-gdb-mlir-support to include the MLIR binary dir
Author: Mehdi Amini Date: 2021-01-07T21:29:09Z New Revision: 476db17dcb64ef3ec6e247f4b1c673b57f61a367 URL: https://github.com/llvm/llvm-project/commit/476db17dcb64ef3ec6e247f4b1c673b57f61a367 DIFF: https://github.com/llvm/llvm-project/commit/476db17dcb64ef3ec6e247f4b1c673b57f61a367.diff LOG: Fix include path for check-gdb-mlir-support to include the MLIR binary dir This fixes a build failure: fatal error: 'mlir/IR/BuiltinTypes.h.inc' file not found Added: Modified: debuginfo-tests/CMakeLists.txt Removed: diff --git a/debuginfo-tests/CMakeLists.txt b/debuginfo-tests/CMakeLists.txt index 4b6af5212fc8..0abbe4604a79 100644 --- a/debuginfo-tests/CMakeLists.txt +++ b/debuginfo-tests/CMakeLists.txt @@ -26,7 +26,9 @@ if ("mlir" IN_LIST LLVM_ENABLE_PROJECTS) add_llvm_executable(check-gdb-mlir-support llvm-prettyprinters/gdb/mlir-support.cpp ) - target_include_directories(check-gdb-mlir-support PRIVATE ${LLVM_EXTERNAL_MLIR_SOURCE_DIR}/include) + target_include_directories(check-gdb-mlir-support PRIVATE + ${LLVM_EXTERNAL_MLIR_SOURCE_DIR}/include + ${LLVM_BINARY_DIR}/tools/mlir/include) target_link_libraries(check-gdb-mlir-support PRIVATE MLIRIR) list(APPEND DEBUGINFO_TEST_DEPS check-gdb-mlir-support) set(MLIR_SOURCE_DIR ${LLVM_EXTERNAL_MLIR_SOURCE_DIR}) ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] 41e31ea - Fix GCC5 build, require explicit this->... in this call inside a lambda (NFC)
Author: Mehdi Amini Date: 2021-01-07T17:44:42Z New Revision: 41e31eac14c239970a220f81de5fdd3b231b5184 URL: https://github.com/llvm/llvm-project/commit/41e31eac14c239970a220f81de5fdd3b231b5184 DIFF: https://github.com/llvm/llvm-project/commit/41e31eac14c239970a220f81de5fdd3b231b5184.diff LOG: Fix GCC5 build, require explicit this->... in this call inside a lambda (NFC) Error was: mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp:2247:36: error: cannot call member function 'mlir::LLVM::FastmathFlags mlir::LLVM::FMFAttr::getFlags() const' without object return bitEnumContains(getFlags(), flag); ^ Added: Modified: mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp Removed: diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp index b7f7789ee44b..cc57b1803f26 100644 --- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp @@ -2244,7 +2244,7 @@ static constexpr const FastmathFlags FastmathFlagsList[] = { void FMFAttr::print(DialectAsmPrinter ) const { printer << "fastmath<"; auto flags = llvm::make_filter_range(FastmathFlagsList, [&](auto flag) { -return bitEnumContains(getFlags(), flag); +return bitEnumContains(this->getFlags(), flag); }); llvm::interleaveComma(flags, printer, [&](auto flag) { printer << stringifyEnum(flag); }); ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] 4ae7952 - [mlir] Fix MathJax rendering in Affine doc
Author: lewuathe Date: 2021-01-06T02:11:36Z New Revision: 4ae7952e2b3566d373c55c8e9740051ca37ed738 URL: https://github.com/llvm/llvm-project/commit/4ae7952e2b3566d373c55c8e9740051ca37ed738 DIFF: https://github.com/llvm/llvm-project/commit/4ae7952e2b3566d373c55c8e9740051ca37ed738.diff LOG: [mlir] Fix MathJax rendering in Affine doc MathJax is not properly imported in Affine doc. It causes the invalid rendering of math formulas in the Affine doc page. https://mlir.llvm.org/docs/Dialects/Affine/#affine-expressions Importing MathJax code from CDN resolved the rendering issue as follows. {F14942131} Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D94004 Added: Modified: mlir/docs/Dialects/Affine.md Removed: diff --git a/mlir/docs/Dialects/Affine.md b/mlir/docs/Dialects/Affine.md index cedbb0106c30..1ce535a0c9b7 100644 --- a/mlir/docs/Dialects/Affine.md +++ b/mlir/docs/Dialects/Affine.md @@ -124,19 +124,19 @@ one-dimensional affine expressions, with the entire list enclosed in parentheses. **Context:** An affine function, informally, is a linear function plus a -constant. More formally, a function f defined on a vector $$\vec{v} \in -\mathbb{Z}^n$$ is a multidimensional affine function of $$\vec{v}$$ if -$$f(\vec{v})$$ can be expressed in the form $$M \vec{v} + \vec{c}$$ where $$M$$ -is a constant matrix from $$\mathbb{Z}^{m \times n}$$ and $$\vec{c}$$ is a -constant vector from $$\mathbb{Z}$$. $$m$$ is the dimensionality of such an +constant. More formally, a function f defined on a vector $\vec{v} \in +\mathbb{Z}^n$ is a multidimensional affine function of $\vec{v}$ if +$f(\vec{v})$ can be expressed in the form $M \vec{v} + \vec{c}$ where $M$ +is a constant matrix from $\mathbb{Z}^{m \times n}$ and $\vec{c}$ is a +constant vector from $\mathbb{Z}$. $m$ is the dimensionality of such an affine function. MLIR further extends the definition of an affine function to allow 'floordiv', 'ceildiv', and 'mod' with respect to positive integer constants. Such extensions to affine functions have often been referred to as quasi-affine functions by the polyhedral compiler community. MLIR uses the term 'affine map' to refer to these multidimensional quasi-affine functions. As -examples, $$(i+j+1, j)$$, $$(i \mod 2, j+i)$$, $$(j, i/4, i \mod 4)$$, $$(2i+1, -j)$$ are two-dimensional affine functions of $$(i, j)$$, but $$(i \cdot j, -i^2)$$, $$(i \mod j, i/j)$$ are not affine functions of $$(i, j)$$. +examples, $(i+j+1, j)$, $(i \mod 2, j+i)$, $(j, i/4, i \mod 4)$, $(2i+1, +j)$ are two-dimensional affine functions of $(i, j)$, but $(i \cdot j, +i^2)$, $(i \mod j, i/j)$ are not affine functions of $(i, j)$. ### Affine Maps ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] 86d68e2 - [mlir] Gen removeAttr methods with tablegen
Author: Felipe de Azevedo Piovezan Date: 2021-01-05T18:48:09Z New Revision: 86d68e288585964546d6382ecf71dcce10d018b7 URL: https://github.com/llvm/llvm-project/commit/86d68e288585964546d6382ecf71dcce10d018b7 DIFF: https://github.com/llvm/llvm-project/commit/86d68e288585964546d6382ecf71dcce10d018b7.diff LOG: [mlir] Gen removeAttr methods with tablegen If an operation defines an optional attribute (OptionalAttr or UnitAttr), transformations may wish to remove these attributes while maintaining invariants established by the operation. Currently, the only way to do this is by calling `Operation::removeAttr("attrName")`, which requires developers to know the exact name of the attribute used by table-gen. Furthermore, if the attribute name changes, this won't be detected at compile time. Instead, `removeAttr` would return an empty attribute and no errors would be raised, unless the caller checks for the returned value. This patch adds table gen support for generating `removeAttr` methods for OptionalAttributes defined by operations. Implementation choice: to preserve camelCase for the method's name, the first character of an attribute called `myAttr` is changed to upper case in order to preserve the coding style, so the final method would be called `removeMyAttr`. Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D93903 Added: Modified: mlir/test/mlir-tblgen/op-attribute.td mlir/test/mlir-tblgen/op-decl.td mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp Removed: diff --git a/mlir/test/mlir-tblgen/op-attribute.td b/mlir/test/mlir-tblgen/op-attribute.td index 833f90dd28a2..b4c193c30c51 100644 --- a/mlir/test/mlir-tblgen/op-attribute.td +++ b/mlir/test/mlir-tblgen/op-attribute.td @@ -77,6 +77,12 @@ def AOp : NS_Op<"a_op", []> { // DEF: void AOp::cAttrAttr(some-attr-kind attr) { // DEF-NEXT: (*this)->setAttr("cAttr", attr); +// Test remove methods +// --- + +// DEF: Attribute AOp::removeCAttrAttr() { +// DEF-NEXT: return (*this)->removeAttr("cAttr"); + // Test build methods // --- @@ -265,6 +271,9 @@ def UnitAttrOp : NS_Op<"unit_attr_op", []> { // DEF: bool UnitAttrOp::attr() { // DEF: return {{.*}} != nullptr +// DEF: Attribute UnitAttrOp::removeAttrAttr() { +// DEF-NEXT: (*this)->removeAttr("attr"); + // DEF: build(::mlir::OpBuilder , ::mlir::OperationState , /*optional*/::mlir::UnitAttr attr) diff --git a/mlir/test/mlir-tblgen/op-decl.td b/mlir/test/mlir-tblgen/op-decl.td index 13daca67c475..d4d1a8b012c6 100644 --- a/mlir/test/mlir-tblgen/op-decl.td +++ b/mlir/test/mlir-tblgen/op-decl.td @@ -81,6 +81,7 @@ def NS_AOp : NS_Op<"a_op", [IsolatedFromAbove, IsolatedFromAbove]> { // CHECK: uint32_t attr1(); // CHECK: ::mlir::FloatAttr attr2Attr() // CHECK: ::llvm::Optional< ::llvm::APFloat > attr2(); +// CHECK: Attribute removeAttr2Attr(); // CHECK: static void build(::mlir::OpBuilder , ::mlir::OperationState , Value val); // CHECK: static void build(::mlir::OpBuilder , ::mlir::OperationState , int integer = 0); // CHECK: static void build(::mlir::OpBuilder , ::mlir::OperationState , ::mlir::Type r, ::mlir::TypeRange s, ::mlir::Value a, ::mlir::ValueRange b, ::mlir::IntegerAttr attr1, /*optional*/::mlir::FloatAttr attr2, unsigned someRegionsCount) diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp index 995b4cd05cd5..468fd7848d82 100644 --- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp +++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp @@ -328,6 +328,9 @@ class OpEmitter { // Generates setter for the attributes. void genAttrSetters(); + // Generates removers for optional attributes. + void genOptionalAttrRemovers(); + // Generates getters for named operands. void genNamedOperandGetters(); @@ -600,6 +603,7 @@ OpEmitter::OpEmitter(const Operator , genNamedSuccessorGetters(); genAttrGetters(); genAttrSetters(); + genOptionalAttrRemovers(); genBuilder(); genParser(); genPrinter(); @@ -777,6 +781,28 @@ void OpEmitter::genAttrSetters() { } } +void OpEmitter::genOptionalAttrRemovers() { + // Generate methods for removing optional attributes, instead of having to + // use the string interface. Enables better compile time verification. + auto emitRemoveAttr = [&](StringRef name) { +auto upperInitial = name.take_front().upper(); +auto suffix = name.drop_front(); +auto *method = opClass.addMethodAndPrune( +"Attribute", ("remove" + upperInitial + suffix + "Attr").str()); +if (!method) + return; +auto = method->body(); +body << " return (*this)->removeAttr(\"" << name << "\");"; + }; + + for (const auto : op.getAttributes()) { +const auto = namedAttr.name; +const auto = namedAttr.attr; +if (attr.isOptional()) + emitRemoveAttr(name); + } +} + // Generates the code to compute
[llvm-branch-commits] [mlir] 7afd5cf - [NFC] Fix -Wrange-loop-analysis warnings.
Author: Dan Zheng Date: 2021-01-05T18:44:17Z New Revision: 7afd5cfbc757b004cba99d234df4e76b06956b2d URL: https://github.com/llvm/llvm-project/commit/7afd5cfbc757b004cba99d234df4e76b06956b2d DIFF: https://github.com/llvm/llvm-project/commit/7afd5cfbc757b004cba99d234df4e76b06956b2d.diff LOG: [NFC] Fix -Wrange-loop-analysis warnings. Remove unnecessary `&` from loop variables. Fix warnings: "loop variable is always a copy because the range does not return a reference". ``` [240/2862] Building CXX object tools/mlir/tools/mlir-tblgen/CMakeFiles/mlir-tblgen.dir/TypeDefGen.cpp.o llvm-project/mlir/tools/mlir-tblgen/TypeDefGen.cpp:50:25: warning: loop variable 'typeDef' is always a copy because the range of type 'llvm::iterator_range, (lambda at llvm-project/mlir/tools/mlir-tblgen/TypeDefGen.cpp:40:16), mlir::tblgen::TypeDef> >' does not return a reference [-Wrange-loop-analysis] for (const TypeDef : defs) ^ llvm-project/mlir/tools/mlir-tblgen/TypeDefGen.cpp:50:10: note: use non-reference type 'mlir::tblgen::TypeDef' for (const TypeDef : defs) ^~~~ llvm-project/mlir/tools/mlir-tblgen/TypeDefGen.cpp:64:23: warning: loop variable 'typeDef' is always a copy because the range of type 'llvm::iterator_range, (lambda at llvm-project/mlir/tools/mlir-tblgen/TypeDefGen.cpp:40:16), mlir::tblgen::TypeDef> >' does not return a reference [-Wrange-loop-analysis] for (const TypeDef : defs) ^ llvm-project/mlir/tools/mlir-tblgen/TypeDefGen.cpp:64:8: note: use non-reference type 'mlir::tblgen::TypeDef' for (const TypeDef : defs) ^~~~ 2 warnings generated. [1934/2862] Building CXX object tools...Files/toyc-ch4.dir/mlir/MLIRGen.cpp.o llvm-project/mlir/examples/toy/Ch4/mlir/MLIRGen.cpp:139:22: warning: loop variable 'name_value' is always a copy because the range of type 'detail::zippy > > &, MutableArrayRef >' does not return a reference [-Wrange-loop-analysis] for (const auto _value : ^ llvm-project/mlir/examples/toy/Ch4/mlir/MLIRGen.cpp:139:10: note: use non-reference type 'std::__1::tuple > &, mlir::BlockArgument &>' for (const auto _value : ^~~~ 1 warning generated. [1940/2862] Building CXX object tools...Files/toyc-ch5.dir/mlir/MLIRGen.cpp.o llvm-project/mlir/examples/toy/Ch5/mlir/MLIRGen.cpp:139:22: warning: loop variable 'name_value' is always a copy because the range of type 'detail::zippy > > &, MutableArrayRef >' does not return a reference [-Wrange-loop-analysis] for (const auto _value : ^ llvm-project/mlir/examples/toy/Ch5/mlir/MLIRGen.cpp:139:10: note: use non-reference type 'std::__1::tuple > &, mlir::BlockArgument &>' for (const auto _value : ^~~~ 1 warning generated. ``` Reviewed By: jpienaar Differential Revision: https://reviews.llvm.org/D94003 Added: Modified: mlir/examples/toy/Ch2/mlir/MLIRGen.cpp mlir/examples/toy/Ch3/mlir/MLIRGen.cpp mlir/examples/toy/Ch4/mlir/MLIRGen.cpp mlir/examples/toy/Ch5/mlir/MLIRGen.cpp mlir/examples/toy/Ch6/mlir/MLIRGen.cpp mlir/examples/toy/Ch7/mlir/Dialect.cpp mlir/examples/toy/Ch7/mlir/MLIRGen.cpp mlir/tools/mlir-tblgen/TypeDefGen.cpp Removed: diff --git a/mlir/examples/toy/Ch2/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch2/mlir/MLIRGen.cpp index 282a1bc76815..8b9f9dbdf190 100644 --- a/mlir/examples/toy/Ch2/mlir/MLIRGen.cpp +++ b/mlir/examples/toy/Ch2/mlir/MLIRGen.cpp @@ -136,10 +136,10 @@ class MLIRGenImpl { auto protoArgs = funcAST.getProto()->getArgs(); // Declare all the function arguments in the symbol table. -for (const auto _value : +for (const auto nameValue : llvm::zip(protoArgs, entryBlock.getArguments())) { - if (failed(declare(std::get<0>(name_value)->getName(), - std::get<1>(name_value + if (failed(declare(std::get<0>(nameValue)->getName(), + std::get<1>(nameValue return nullptr; } diff --git a/mlir/examples/toy/Ch3/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch3/mlir/MLIRGen.cpp index 282a1bc76815..8b9f9dbdf190 100644 --- a/mlir/examples/toy/Ch3/mlir/MLIRGen.cpp +++ b/mlir/examples/toy/Ch3/mlir/MLIRGen.cpp @@ -136,10 +136,10 @@ class MLIRGenImpl { auto protoArgs = funcAST.getProto()->getArgs(); // Declare all the function arguments in the symbol table. -for (const auto _value : +for (const auto nameValue : llvm::zip(protoArgs, entryBlock.getArguments())) { - if (failed(declare(std::get<0>(name_value)->getName(), - std::get<1>(name_value + if (failed(declare(std::get<0>(nameValue)->getName(), + std::get<1>(nameValue return nullptr; } diff --git
[llvm-branch-commits] [mlir] 58ce477 - Fix DRR pattern when attributes and operands are interleaved and a dag subtree appears in the rewrite
Author: Mehdi Amini Date: 2020-12-30T00:19:38Z New Revision: 58ce477676c7bd9c6cee0c6d05f2708b4e178ff3 URL: https://github.com/llvm/llvm-project/commit/58ce477676c7bd9c6cee0c6d05f2708b4e178ff3 DIFF: https://github.com/llvm/llvm-project/commit/58ce477676c7bd9c6cee0c6d05f2708b4e178ff3.diff LOG: Fix DRR pattern when attributes and operands are interleaved and a dag subtree appears in the rewrite This fixes an incorrect fatal error in TableGen. This code probably comes from before attributes were allowed to interleave with operands in ODS. Reviewed By: jpienaar Differential Revision: https://reviews.llvm.org/D93915 Added: Modified: mlir/test/mlir-tblgen/rewriter-indexing.td mlir/tools/mlir-tblgen/RewriterGen.cpp Removed: diff --git a/mlir/test/mlir-tblgen/rewriter-indexing.td b/mlir/test/mlir-tblgen/rewriter-indexing.td index ed493d09008b..c21b04f6d0f6 100644 --- a/mlir/test/mlir-tblgen/rewriter-indexing.td +++ b/mlir/test/mlir-tblgen/rewriter-indexing.td @@ -47,3 +47,11 @@ def test1 : Pat<(BOp $attr, (AOp $input)), // CHECK: castedOp0.getODSOperands(1).begin()).getDefiningOp() def test2 : Pat<(COp $attr1, $op1, $attr2, (AOp $op2)), (BOp $attr1, $op2)>; + + +// Check rewriting with a DAG subtree in the result and remapping a location. +// CHECK: struct test3 : public ::mlir::RewritePattern { +// CHECK: rewriter.create((*a.getODSResults(0).begin()).getLoc() +def test3 : Pat<(BOp $attr, (AOp:$a $input)), +(BOp $attr, (AOp $input), (location $a))>; + diff --git a/mlir/tools/mlir-tblgen/RewriterGen.cpp b/mlir/tools/mlir-tblgen/RewriterGen.cpp index da189c65ec2a..96488d9cedc0 100644 --- a/mlir/tools/mlir-tblgen/RewriterGen.cpp +++ b/mlir/tools/mlir-tblgen/RewriterGen.cpp @@ -998,7 +998,7 @@ std::string PatternEmitter::handleOpCreation(DagNode tree, int resultIndex, // First go through all the child nodes who are nested DAG constructs to // create ops for them and remember the symbol names for them, so that we can // use the results in the current node. This happens in a recursive manner. - for (int i = 0, e = resultOp.getNumOperands(); i != e; ++i) { + for (int i = 0, e = tree.getNumArgs() - hasLocationDirective; i != e; ++i) { if (auto child = tree.getArgAsNestedDag(i)) childNodeNames[i] = handleResultPattern(child, i, depth + 1); } ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] 2c8f5bd - [MLIR] Make ComplexType buildable if its element type is buildable
Author: Chris Morin Date: 2020-12-29T23:31:42Z New Revision: 2c8f5bd53945a209cd3cd851c63df3713fa0f9bd URL: https://github.com/llvm/llvm-project/commit/2c8f5bd53945a209cd3cd851c63df3713fa0f9bd DIFF: https://github.com/llvm/llvm-project/commit/2c8f5bd53945a209cd3cd851c63df3713fa0f9bd.diff LOG: [MLIR] Make ComplexType buildable if its element type is buildable If a ComplexType's element type is buildable, then that ComplexType should be buildable. This is accomplished by the introduction of a new ODS class called `SameBuildabilityAs`. This can be used by other types that are conditionally buildable. Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D93892 Added: Modified: mlir/include/mlir/IR/OpBase.td mlir/test/mlir-tblgen/types.mlir Removed: diff --git a/mlir/include/mlir/IR/OpBase.td b/mlir/include/mlir/IR/OpBase.td index 857a652f17d9..c65cc22c90f0 100644 --- a/mlir/include/mlir/IR/OpBase.td +++ b/mlir/include/mlir/IR/OpBase.td @@ -333,6 +333,13 @@ class BuildableType { code builderCall = builder; } +// A type that's buildable iff the type passed as an argument is buildable. +// This is intended for use by types like container types, which are only +// buildable if the type of their elements is buildable. +class SameBuildabilityAs { + code builderCall = !if(!empty(type.builderCall), "", builder); +} + // Any type at all. def AnyType : Type, "any type">; @@ -479,7 +486,9 @@ class Complex "$_self.cast<::mlir::ComplexType>().getElementType()", type.predicate>]>, "complex type with " # type.description # " elements", - "::mlir::ComplexType"> { + "::mlir::ComplexType">, + SameBuildabilityAs { Type elementType = type; } diff --git a/mlir/test/mlir-tblgen/types.mlir b/mlir/test/mlir-tblgen/types.mlir index 5e4dac33012b..61727d18e68f 100644 --- a/mlir/test/mlir-tblgen/types.mlir +++ b/mlir/test/mlir-tblgen/types.mlir @@ -58,7 +58,7 @@ func @complex_f64_tensor_success() { // - func @complex_f64_failure() { - // expected-error@+1 {{must be complex type with 64-bit float elements}} + // expected-error@+1 {{op inferred type incompatible with return type of operation}} "test.complex_f64"() : () -> (f64) return } ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] c1d6de4 - [mlir][CAPI] Add the missing in Support.h
Author: Gnimuc Date: 2020-12-20T05:01:49Z New Revision: c1d6de41a9d9fc34c3de580cfe7c287d8b48b417 URL: https://github.com/llvm/llvm-project/commit/c1d6de41a9d9fc34c3de580cfe7c287d8b48b417 DIFF: https://github.com/llvm/llvm-project/commit/c1d6de41a9d9fc34c3de580cfe7c287d8b48b417.diff LOG: [mlir][CAPI] Add the missing in Support.h This was likely an oversight in https://reviews.llvm.org/D92292 Reviewed By: stellaraccident Differential Revision: https://reviews.llvm.org/D93588 Added: Modified: mlir/include/mlir-c/Support.h Removed: diff --git a/mlir/include/mlir-c/Support.h b/mlir/include/mlir-c/Support.h index 558b68f9d8d0..072b96051e01 100644 --- a/mlir/include/mlir-c/Support.h +++ b/mlir/include/mlir-c/Support.h @@ -15,6 +15,7 @@ #ifndef MLIR_C_SUPPORT_H #define MLIR_C_SUPPORT_H +#include #include #include ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] 9887097 - Remove unneeded header include (NFC)
Author: Mehdi Amini Date: 2020-12-18T00:10:26Z New Revision: 9887097d802d0a585807e693727ab8836790da8d URL: https://github.com/llvm/llvm-project/commit/9887097d802d0a585807e693727ab8836790da8d DIFF: https://github.com/llvm/llvm-project/commit/9887097d802d0a585807e693727ab8836790da8d.diff LOG: Remove unneeded header include (NFC) Added: Modified: mlir/lib/Support/MlirOptMain.cpp Removed: diff --git a/mlir/lib/Support/MlirOptMain.cpp b/mlir/lib/Support/MlirOptMain.cpp index dbda704dc7d8..5d852292fd06 100644 --- a/mlir/lib/Support/MlirOptMain.cpp +++ b/mlir/lib/Support/MlirOptMain.cpp @@ -24,7 +24,6 @@ #include "mlir/Pass/PassManager.h" #include "mlir/Support/FileUtilities.h" #include "mlir/Support/ToolUtilities.h" -#include "mlir/Transforms/Passes.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/FileUtilities.h" #include "llvm/Support/InitLLVM.h" ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] a555ca8 - Workaround around clang 5.0 bug by including SmallVector.h in LLVM.h (PR41549)
Author: Mehdi Amini Date: 2020-12-18T00:00:36Z New Revision: a555ca8b3d67267c19db48fc2470d20daae80aeb URL: https://github.com/llvm/llvm-project/commit/a555ca8b3d67267c19db48fc2470d20daae80aeb DIFF: https://github.com/llvm/llvm-project/commit/a555ca8b3d67267c19db48fc2470d20daae80aeb.diff LOG: Workaround around clang 5.0 bug by including SmallVector.h in LLVM.h (PR41549) The forward declaration for SmallVector does not play well with clang-5. Differential Revision: https://reviews.llvm.org/D93498 Added: Modified: mlir/include/mlir/Support/LLVM.h Removed: diff --git a/mlir/include/mlir/Support/LLVM.h b/mlir/include/mlir/Support/LLVM.h index e8595ae29ed7..ced7a7a35363 100644 --- a/mlir/include/mlir/Support/LLVM.h +++ b/mlir/include/mlir/Support/LLVM.h @@ -23,6 +23,13 @@ #include "llvm/ADT/None.h" #include "llvm/Support/Casting.h" +// Workaround for clang-5 (PR41549) +#if defined(__clang_major__) +#if __clang_major__ <= 5 +#include "llvm/ADT/SmallVector.h" +#endif +#endif + // Forward declarations. namespace llvm { // String types ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] a48172c - Add brief description of dialects doc section.
Author: Richard Uhler Date: 2020-12-17T18:37:34Z New Revision: a48172cf1c1527123a7db35a7d0d7fa84f5dc37c URL: https://github.com/llvm/llvm-project/commit/a48172cf1c1527123a7db35a7d0d7fa84f5dc37c DIFF: https://github.com/llvm/llvm-project/commit/a48172cf1c1527123a7db35a7d0d7fa84f5dc37c.diff LOG: Add brief description of dialects doc section. Reviewed By: jpienaar Differential Revision: https://reviews.llvm.org/D93466 Added: mlir/docs/Dialects/_index.md Modified: Removed: diff --git a/mlir/docs/Dialects/_index.md b/mlir/docs/Dialects/_index.md new file mode 100644 index ..da19ddcca777 --- /dev/null +++ b/mlir/docs/Dialects/_index.md @@ -0,0 +1,6 @@ +# Dialects + +This section contains documentation for core and contributed dialects available +from the MLIR repository. The description for each dialect includes content +automatically generated from the dialect's +[Operation Definition Specification (ODS)](../OpDefinitions.md). ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] c21ee1a - Improve the verifier diagnostic on dominance error
Author: Mehdi Amini Date: 2020-12-16T22:05:17Z New Revision: c21ee1a9426710eba5923062efd0e0b0789edd47 URL: https://github.com/llvm/llvm-project/commit/c21ee1a9426710eba5923062efd0e0b0789edd47 DIFF: https://github.com/llvm/llvm-project/commit/c21ee1a9426710eba5923062efd0e0b0789edd47.diff LOG: Improve the verifier diagnostic on dominance error Address PR47937 Differential Revision: https://reviews.llvm.org/D93361 Added: Modified: mlir/lib/IR/Verifier.cpp mlir/test/IR/invalid.mlir Removed: diff --git a/mlir/lib/IR/Verifier.cpp b/mlir/lib/IR/Verifier.cpp index e214a654dbee..036919bd84b9 100644 --- a/mlir/lib/IR/Verifier.cpp +++ b/mlir/lib/IR/Verifier.cpp @@ -245,6 +245,56 @@ LogicalResult OperationVerifier::verifyOperation(Operation ) { return success(); } +/// Attach a note to an in-flight diagnostic that provide more information about +/// where an op operand is defined. +static void attachNoteForOperandDefinition(InFlightDiagnostic , + Operation , Value operand) { + if (auto *useOp = operand.getDefiningOp()) { +Diagnostic = diag.attachNote(useOp->getLoc()); +note << "operand defined here"; +Block *block1 = op.getBlock(); +Block *block2 = useOp->getBlock(); +Region *region1 = block1->getParent(); +Region *region2 = block2->getParent(); +if (block1 == block2) + note << " (op in the same block)"; +else if (region1 == region2) + note << " (op in the same region)"; +else if (region2->isProperAncestor(region1)) + note << " (op in a parent region)"; +else if (region1->isProperAncestor(region2)) + note << " (op in a child region)"; +else + note << " (op is neither in a parent nor in a child region)"; +return; + } + // Block argument case. + Block *block1 = op.getBlock(); + Block *block2 = operand.cast().getOwner(); + Region *region1 = block1->getParent(); + Region *region2 = block2->getParent(); + Location loc = UnknownLoc::get(op.getContext()); + if (block2->getParentOp()) +loc = block2->getParentOp()->getLoc(); + Diagnostic = diag.attachNote(loc); + if (!region2) { +note << " (block without parent)"; +return; + } + if (block1 == block2) +llvm::report_fatal_error("Internal error in dominance verification"); + int index = std::distance(region2->begin(), block2->getIterator()); + note << "operand defined as a block argument (block #" << index; + if (region1 == region2) +note << " in the same region)"; + else if (region2->isProperAncestor(region1)) +note << " in a parent region)"; + else if (region1->isProperAncestor(region2)) +note << " in a child region)"; + else +note << " neither in a parent nor in a child region)"; +} + LogicalResult OperationVerifier::verifyDominance(Region ) { // Verify the dominance of each of the held operations. for (Block : region) { @@ -254,14 +304,14 @@ LogicalResult OperationVerifier::verifyDominance(Region ) { // Check that operands properly dominate this use. for (unsigned operandNo = 0, e = op.getNumOperands(); operandNo != e; ++operandNo) { - auto operand = op.getOperand(operandNo); + Value operand = op.getOperand(operandNo); if (domInfo->properlyDominates(operand, )) continue; - auto diag = op.emitError("operand #") - << operandNo << " does not dominate this use"; - if (auto *useOp = operand.getDefiningOp()) -diag.attachNote(useOp->getLoc()) << "operand defined here"; + InFlightDiagnostic diag = op.emitError("operand #") +<< operandNo +<< " does not dominate this use"; + attachNoteForOperandDefinition(diag, op, operand); return failure(); } // Recursively verify dominance within each operation in the diff --git a/mlir/test/IR/invalid.mlir b/mlir/test/IR/invalid.mlir index 86245ad25c3b..4e6c950d637a 100644 --- a/mlir/test/IR/invalid.mlir +++ b/mlir/test/IR/invalid.mlir @@ -464,7 +464,49 @@ func @dominance_failure() { "foo"(%x) : (i32) -> ()// expected-error {{operand #0 does not dominate this use}} br ^bb1 ^bb1: - %x = "bar"() : () -> i32// expected-note {{operand defined here}} + %x = "bar"() : () -> i32// expected-note {{operand defined here (op in the same region)}} + return +} + +// - + +func @dominance_failure() { +^bb0: + "foo"(%x) : (i32) -> ()// expected-error {{operand #0 does not dominate this use}} + %x = "bar"() : () -> i32// expected-note {{operand defined here (op in the same block)}} + br ^bb1 +^bb1: + return +} + +// - + +func @dominance_failure() { + "foo"() ({ +"foo"(%x) : (i32) -> ()// expected-error {{operand #0 does not dominate this use}} + }) : () -> () + %x = "bar"()
[llvm-branch-commits] [mlir] 4bd9e62 - Remove spurious MLIRLLVMConversionsIncGen dependency from LLVM Dialect (NFC)
Author: Mehdi Amini Date: 2020-12-16T17:32:49Z New Revision: 4bd9e62422d1e3c63e01ce9f3523d5dcc59d7215 URL: https://github.com/llvm/llvm-project/commit/4bd9e62422d1e3c63e01ce9f3523d5dcc59d7215 DIFF: https://github.com/llvm/llvm-project/commit/4bd9e62422d1e3c63e01ce9f3523d5dcc59d7215.diff LOG: Remove spurious MLIRLLVMConversionsIncGen dependency from LLVM Dialect (NFC) Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D93335 Added: Modified: mlir/lib/Dialect/LLVMIR/CMakeLists.txt Removed: diff --git a/mlir/lib/Dialect/LLVMIR/CMakeLists.txt b/mlir/lib/Dialect/LLVMIR/CMakeLists.txt index cd73e7dcfc69..91fb02db9601 100644 --- a/mlir/lib/Dialect/LLVMIR/CMakeLists.txt +++ b/mlir/lib/Dialect/LLVMIR/CMakeLists.txt @@ -10,7 +10,6 @@ add_mlir_dialect_library(MLIRLLVMIR DEPENDS MLIRLLVMOpsIncGen - MLIRLLVMConversionsIncGen MLIROpenMPOpsIncGen intrinsics_gen ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] aece4e2 - [mlir][ArmSVE][RFC] Add an ArmSVE dialect
Author: Javier Setoain Date: 2020-12-14T21:35:01Z New Revision: aece4e2793ccf0d63d5e677a0ace83752b30979a URL: https://github.com/llvm/llvm-project/commit/aece4e2793ccf0d63d5e677a0ace83752b30979a DIFF: https://github.com/llvm/llvm-project/commit/aece4e2793ccf0d63d5e677a0ace83752b30979a.diff LOG: [mlir][ArmSVE][RFC] Add an ArmSVE dialect This revision starts an Arm-specific ArmSVE dialect discussed in the discourse RFC thread: https://llvm.discourse.group/t/rfc-vector-dialects-neon-and-sve/2284 Reviewed By: rriddle Differential Revision: https://reviews.llvm.org/D92172 Added: mlir/include/mlir/Conversion/ArmSVEToLLVM/ArmSVEToLLVM.h mlir/include/mlir/Dialect/ArmSVE/ArmSVE.td mlir/include/mlir/Dialect/ArmSVE/ArmSVEDialect.h mlir/include/mlir/Dialect/ArmSVE/CMakeLists.txt mlir/include/mlir/Dialect/LLVMIR/LLVMArmSVE.td mlir/include/mlir/Dialect/LLVMIR/LLVMArmSVEDialect.h mlir/lib/Conversion/ArmSVEToLLVM/ArmSVEToLLVM.cpp mlir/lib/Conversion/ArmSVEToLLVM/CMakeLists.txt mlir/lib/Dialect/ArmSVE/CMakeLists.txt mlir/lib/Dialect/ArmSVE/IR/ArmSVEDialect.cpp mlir/lib/Dialect/LLVMIR/IR/LLVMArmSVEDialect.cpp mlir/lib/Target/LLVMIR/LLVMArmSVEIntr.cpp mlir/test/Conversion/ArmSVEToLLVM/convert-to-llvm.mlir mlir/test/Dialect/ArmSVE/roundtrip.mlir mlir/test/Target/arm-sve.mlir Modified: mlir/include/mlir/Conversion/Passes.td mlir/include/mlir/Conversion/VectorToLLVM/ConvertVectorToLLVM.h mlir/include/mlir/Dialect/CMakeLists.txt mlir/include/mlir/Dialect/LLVMIR/CMakeLists.txt mlir/include/mlir/InitAllDialects.h mlir/include/mlir/InitAllTranslations.h mlir/lib/Conversion/CMakeLists.txt mlir/lib/Conversion/PassDetail.h mlir/lib/Conversion/VectorToLLVM/CMakeLists.txt mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVMPass.cpp mlir/lib/Dialect/CMakeLists.txt mlir/lib/Dialect/LLVMIR/CMakeLists.txt mlir/lib/Target/CMakeLists.txt Removed: diff --git a/mlir/include/mlir/Conversion/ArmSVEToLLVM/ArmSVEToLLVM.h b/mlir/include/mlir/Conversion/ArmSVEToLLVM/ArmSVEToLLVM.h new file mode 100644 index ..8cba4e9be5d5 --- /dev/null +++ b/mlir/include/mlir/Conversion/ArmSVEToLLVM/ArmSVEToLLVM.h @@ -0,0 +1,23 @@ +//===- ArmSVEToLLVM.h - Conversion Patterns from ArmSVE to LLVM ---===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#ifndef MLIR_CONVERSION_ARMSVETOLLVM_ARMSVETOLLVM_H_ +#define MLIR_CONVERSION_ARMSVETOLLVM_ARMSVETOLLVM_H_ + +namespace mlir { + +class LLVMTypeConverter; +class OwningRewritePatternList; + +/// Collect a set of patterns to convert from the ArmSVE dialect to LLVM. +void populateArmSVEToLLVMConversionPatterns(LLVMTypeConverter , +OwningRewritePatternList ); + +} // namespace mlir + +#endif // MLIR_CONVERSION_ARMSVETOLLVM_ARMSVETOLLVM_H_ diff --git a/mlir/include/mlir/Conversion/Passes.td b/mlir/include/mlir/Conversion/Passes.td index 56169d90c849..b364700bd849 100644 --- a/mlir/include/mlir/Conversion/Passes.td +++ b/mlir/include/mlir/Conversion/Passes.td @@ -396,8 +396,8 @@ def ConvertVectorToLLVM : Pass<"convert-vector-to-llvm", "ModuleOp"> { operations. The lowering pass provides several options to control the kinds of optimizations that are allowed. It also provides options that enable the use of one or more architectural-specific dialects -(AVX512, ArmNeon, SVE, etc.) in combination with the architectural-neutral -vector dialect lowering. +(AVX512, ArmNeon, ArmSVE, etc.) in combination with the +architectural-neutral vector dialect lowering. }]; let constructor = "mlir::createConvertVectorToLLVMPass()"; @@ -418,7 +418,11 @@ def ConvertVectorToLLVM : Pass<"convert-vector-to-llvm", "ModuleOp"> { Option<"enableArmNeon", "enable-arm-neon", "bool", /*default=*/"false", "Enables the use of ArmNeon dialect while lowering the vector " - "dialect."> + "dialect.">, +Option<"enableArmSVE", "enable-arm-sve", + "bool", /*default=*/"false", + "Enables the use of ArmSVE dialect while lowering the vector " + "dialect."> ]; } diff --git a/mlir/include/mlir/Conversion/VectorToLLVM/ConvertVectorToLLVM.h b/mlir/include/mlir/Conversion/VectorToLLVM/ConvertVectorToLLVM.h index 7ff061cb9d09..8d24803eeb1c 100644 --- a/mlir/include/mlir/Conversion/VectorToLLVM/ConvertVectorToLLVM.h +++ b/mlir/include/mlir/Conversion/VectorToLLVM/ConvertVectorToLLVM.h @@ -23,7 +23,7 @@ class OperationPass; struct LowerVectorToLLVMOptions { LowerVectorToLLVMOptions() :
[llvm-branch-commits] [mlir] c84b53c - [mlir] Add Python binding for MLIR Dict Attribute
Author: kweisamx Date: 2020-12-13T04:30:35Z New Revision: c84b53ca9bcddcbaa8b726be0a4d6cb684dedbd5 URL: https://github.com/llvm/llvm-project/commit/c84b53ca9bcddcbaa8b726be0a4d6cb684dedbd5 DIFF: https://github.com/llvm/llvm-project/commit/c84b53ca9bcddcbaa8b726be0a4d6cb684dedbd5.diff LOG: [mlir] Add Python binding for MLIR Dict Attribute Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D93004 Added: Modified: mlir/lib/Bindings/Python/IRModules.cpp mlir/test/Bindings/Python/ir_attributes.py Removed: diff --git a/mlir/lib/Bindings/Python/IRModules.cpp b/mlir/lib/Bindings/Python/IRModules.cpp index 66443bf89072..8a77d60741b4 100644 --- a/mlir/lib/Bindings/Python/IRModules.cpp +++ b/mlir/lib/Bindings/Python/IRModules.cpp @@ -1968,6 +1968,58 @@ class PyDenseIntElementsAttribute } }; +class PyDictAttribute : public PyConcreteAttribute { +public: + static constexpr IsAFunctionTy isaFunction = mlirAttributeIsADictionary; + static constexpr const char *pyClassName = "DictAttr"; + using PyConcreteAttribute::PyConcreteAttribute; + + intptr_t dunderLen() { return mlirDictionaryAttrGetNumElements(*this); } + + static void bindDerived(ClassTy ) { +c.def("__len__", ::dunderLen); +c.def_static( +"get", +[](py::dict attributes, DefaultingPyMlirContext context) { + SmallVector mlirNamedAttributes; + mlirNamedAttributes.reserve(attributes.size()); + for (auto : attributes) { +auto _attr = it.second.cast(); +auto name = it.first.cast(); +mlirNamedAttributes.push_back(mlirNamedAttributeGet( +mlirIdentifierGet(mlirAttributeGetContext(mlir_attr), + toMlirStringRef(name)), +mlir_attr)); + } + MlirAttribute attr = + mlirDictionaryAttrGet(context->get(), mlirNamedAttributes.size(), +mlirNamedAttributes.data()); + return PyDictAttribute(context->getRef(), attr); +}, +py::arg("value"), py::arg("context") = py::none(), +"Gets an uniqued dict attribute"); +c.def("__getitem__", [](PyDictAttribute , const std::string ) { + MlirAttribute attr = + mlirDictionaryAttrGetElementByName(self, toMlirStringRef(name)); + if (mlirAttributeIsNull(attr)) { +throw SetPyError(PyExc_KeyError, + "attempt to access a non-existent attribute"); + } + return PyAttribute(self.getContext(), attr); +}); +c.def("__getitem__", [](PyDictAttribute , intptr_t index) { + if (index < 0 || index >= self.dunderLen()) { +throw SetPyError(PyExc_IndexError, + "attempt to access out of bounds attribute"); + } + MlirNamedAttribute namedAttr = mlirDictionaryAttrGetElement(self, index); + return PyNamedAttribute( + namedAttr.attribute, + std::string(mlirIdentifierStr(namedAttr.name).data)); +}); + } +}; + /// Refinement of PyDenseElementsAttribute for attributes containing /// floating-point values. Supports element access. class PyDenseFPElementsAttribute @@ -3181,6 +3233,7 @@ void mlir::python::populateIRSubmodule(py::module ) { PyDenseElementsAttribute::bind(m); PyDenseIntElementsAttribute::bind(m); PyDenseFPElementsAttribute::bind(m); + PyDictAttribute::bind(m); PyTypeAttribute::bind(m); PyUnitAttribute::bind(m); diff --git a/mlir/test/Bindings/Python/ir_attributes.py b/mlir/test/Bindings/Python/ir_attributes.py index 642c1f6a836c..84f313912547 100644 --- a/mlir/test/Bindings/Python/ir_attributes.py +++ b/mlir/test/Bindings/Python/ir_attributes.py @@ -257,6 +257,47 @@ def testDenseFPAttr(): run(testDenseFPAttr) +# CHECK-LABEL: TEST: testDictAttr +def testDictAttr(): + with Context(): +dict_attr = { + 'stringattr': StringAttr.get('string'), + 'integerattr' : IntegerAttr.get( +IntegerType.get_signless(32), 42) +} + +a = DictAttr.get(dict_attr) + +# CHECK attr: {integerattr = 42 : i32, stringattr = "string"} +print("attr:", a) + +assert len(a) == 2 + +# CHECK: 42 : i32 +print(a['integerattr']) + +# CHECK: "string" +print(a['stringattr']) + +# Check that exceptions are raised as expected. +try: + _ = a['does_not_exist'] +except KeyError: + pass +else: + assert False, "Exception not produced" + +try: + _ = a[42] +except IndexError: + pass +else: + assert False, "expected IndexError on accessing an out-of-bounds attribute" + + + +run(testDictAttr) + # CHECK-LABEL: TEST: testTypeAttr def testTypeAttr(): with Context(): ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org
[llvm-branch-commits] [mlir] aadcb26 - Store a MlirIdentifier instead of a MlirStringRef in MlirNameAttribute
Author: Mehdi Amini Date: 2020-12-11T22:38:48Z New Revision: aadcb26ee1650de8eaddc5a141c4302691c446a1 URL: https://github.com/llvm/llvm-project/commit/aadcb26ee1650de8eaddc5a141c4302691c446a1 DIFF: https://github.com/llvm/llvm-project/commit/aadcb26ee1650de8eaddc5a141c4302691c446a1.diff LOG: Store a MlirIdentifier instead of a MlirStringRef in MlirNameAttribute This mirror the C++ API for NamedAttribute, and has the advantage or internalizing earlier in the Context and not requiring the caller to keep the StringRef alive beyong this call. Differential Revision: https://reviews.llvm.org/D93133 Added: Modified: mlir/include/mlir-c/IR.h mlir/lib/Bindings/Python/IRModules.cpp mlir/lib/CAPI/IR/BuiltinAttributes.cpp mlir/lib/CAPI/IR/IR.cpp mlir/test/CAPI/ir.c Removed: diff --git a/mlir/include/mlir-c/IR.h b/mlir/include/mlir-c/IR.h index 02d1e54d20e5..74c90af5b4d5 100644 --- a/mlir/include/mlir-c/IR.h +++ b/mlir/include/mlir-c/IR.h @@ -70,7 +70,7 @@ DEFINE_C_API_STRUCT(MlirValue, const void); * a string. */ struct MlirNamedAttribute { - MlirStringRef name; + MlirIdentifier name; MlirAttribute attribute; }; typedef struct MlirNamedAttribute MlirNamedAttribute; @@ -600,7 +600,7 @@ MLIR_CAPI_EXPORTED void mlirAttributePrint(MlirAttribute attr, MLIR_CAPI_EXPORTED void mlirAttributeDump(MlirAttribute attr); /// Associates an attribute with the name. Takes ownership of neither. -MLIR_CAPI_EXPORTED MlirNamedAttribute mlirNamedAttributeGet(MlirStringRef name, +MLIR_CAPI_EXPORTED MlirNamedAttribute mlirNamedAttributeGet(MlirIdentifier name, MlirAttribute attr); //===--===// diff --git a/mlir/lib/Bindings/Python/IRModules.cpp b/mlir/lib/Bindings/Python/IRModules.cpp index 5ebb2e4ccee3..66443bf89072 100644 --- a/mlir/lib/Bindings/Python/IRModules.cpp +++ b/mlir/lib/Bindings/Python/IRModules.cpp @@ -962,8 +962,10 @@ py::object PyOperation::create( llvm::SmallVector mlirNamedAttributes; mlirNamedAttributes.reserve(mlirAttributes.size()); for (auto : mlirAttributes) - mlirNamedAttributes.push_back( - mlirNamedAttributeGet(toMlirStringRef(it.first), it.second)); + mlirNamedAttributes.push_back(mlirNamedAttributeGet( + mlirIdentifierGet(mlirAttributeGetContext(it.second), +toMlirStringRef(it.first)), + it.second)); mlirOperationStateAddAttributes(, mlirNamedAttributes.size(), mlirNamedAttributes.data()); } @@ -1134,7 +1136,10 @@ PyAttribute PyAttribute::createFromCapsule(py::object capsule) { PyNamedAttribute::PyNamedAttribute(MlirAttribute attr, std::string ownedName) : ownedName(new std::string(std::move(ownedName))) { - namedAttr = mlirNamedAttributeGet(toMlirStringRef(*this->ownedName), attr); + namedAttr = mlirNamedAttributeGet( + mlirIdentifierGet(mlirAttributeGetContext(attr), +toMlirStringRef(*this->ownedName)), + attr); } //-- @@ -1373,8 +1378,9 @@ class PyOpAttributeMap { } MlirNamedAttribute namedAttr = mlirOperationGetAttribute(operation->get(), index); -return PyNamedAttribute(namedAttr.attribute, -std::string(namedAttr.name.data)); +return PyNamedAttribute( +namedAttr.attribute, +std::string(mlirIdentifierStr(namedAttr.name).data)); } void dunderSetItem(const std::string , PyAttribute attr) { @@ -3137,7 +3143,8 @@ void mlir::python::populateIRSubmodule(py::module ) { [](PyNamedAttribute ) { PyPrintAccumulator printAccum; printAccum.parts.append("NamedAttribute("); - printAccum.parts.append(self.namedAttr.name.data); + printAccum.parts.append( + mlirIdentifierStr(self.namedAttr.name).data); printAccum.parts.append("="); mlirAttributePrint(self.namedAttr.attribute, printAccum.getCallback(), @@ -3148,8 +3155,8 @@ void mlir::python::populateIRSubmodule(py::module ) { .def_property_readonly( "name", [](PyNamedAttribute ) { -return py::str(self.namedAttr.name.data, - self.namedAttr.name.length); +return py::str(mlirIdentifierStr(self.namedAttr.name).data, + mlirIdentifierStr(self.namedAttr.name).length); }, "The name of the NamedAttribute binding") .def_property_readonly( diff --git a/mlir/lib/CAPI/IR/BuiltinAttributes.cpp b/mlir/lib/CAPI/IR/BuiltinAttributes.cpp index 8db4ac3d3a38..90ed9cb0ad02 100644 ---
[llvm-branch-commits] [mlir] 285c0aa - Add MLIR Python binding for Array Attribute
Author: Mehdi Amini Date: 2020-12-10T20:51:34Z New Revision: 285c0aa262c9255e6ea4efbce1418e5f5f17e9c1 URL: https://github.com/llvm/llvm-project/commit/285c0aa262c9255e6ea4efbce1418e5f5f17e9c1 DIFF: https://github.com/llvm/llvm-project/commit/285c0aa262c9255e6ea4efbce1418e5f5f17e9c1.diff LOG: Add MLIR Python binding for Array Attribute Differential Revision: https://reviews.llvm.org/D92948 Added: Modified: mlir/lib/Bindings/Python/IRModules.cpp mlir/test/Bindings/Python/ir_attributes.py Removed: diff --git a/mlir/lib/Bindings/Python/IRModules.cpp b/mlir/lib/Bindings/Python/IRModules.cpp index 5519c66ee1ab..5ebb2e4ccee3 100644 --- a/mlir/lib/Bindings/Python/IRModules.cpp +++ b/mlir/lib/Bindings/Python/IRModules.cpp @@ -1461,6 +1461,83 @@ class PyConcreteAttribute : public BaseTy { static void bindDerived(ClassTy ) {} }; +class PyArrayAttribute : public PyConcreteAttribute { +public: + static constexpr IsAFunctionTy isaFunction = mlirAttributeIsAArray; + static constexpr const char *pyClassName = "ArrayAttr"; + using PyConcreteAttribute::PyConcreteAttribute; + + class PyArrayAttributeIterator { + public: +PyArrayAttributeIterator(PyAttribute attr) : attr(attr) {} + +PyArrayAttributeIterator () { return *this; } + +PyAttribute dunderNext() { + if (nextIndex >= mlirArrayAttrGetNumElements(attr.get())) { +throw py::stop_iteration(); + } + return PyAttribute(attr.getContext(), + mlirArrayAttrGetElement(attr.get(), nextIndex++)); +} + +static void bind(py::module ) { + py::class_(m, "ArrayAttributeIterator") + .def("__iter__", ::dunderIter) + .def("__next__", ::dunderNext); +} + + private: +PyAttribute attr; +int nextIndex = 0; + }; + + static void bindDerived(ClassTy ) { +c.def_static( +"get", +[](py::list attributes, DefaultingPyMlirContext context) { + SmallVector mlirAttributes; + mlirAttributes.reserve(py::len(attributes)); + for (auto attribute : attributes) { +try { + mlirAttributes.push_back(attribute.cast()); +} catch (py::cast_error ) { + std::string msg = std::string("Invalid attribute when attempting " +"to create an ArrayAttribute (") + +err.what() + ")"; + throw py::cast_error(msg); +} catch (py::reference_cast_error ) { + // This exception seems thrown when the value is "None". + std::string msg = + std::string("Invalid attribute (None?) when attempting to " + "create an ArrayAttribute (") + + err.what() + ")"; + throw py::cast_error(msg); +} + } + MlirAttribute attr = mlirArrayAttrGet( + context->get(), mlirAttributes.size(), mlirAttributes.data()); + return PyArrayAttribute(context->getRef(), attr); +}, +py::arg("attributes"), py::arg("context") = py::none(), +"Gets a uniqued Array attribute"); +c.def("__getitem__", + [](PyArrayAttribute , intptr_t i) { +if (i >= mlirArrayAttrGetNumElements(arr)) + throw py::index_error("ArrayAttribute index out of range"); +return PyAttribute(arr.getContext(), + mlirArrayAttrGetElement(arr, i)); + }) +.def("__len__", + [](const PyArrayAttribute ) { + return mlirArrayAttrGetNumElements(arr); + }) +.def("__iter__", [](const PyArrayAttribute ) { + return PyArrayAttributeIterator(arr); +}); + } +}; + /// Float Point Attribute subclass - FloatAttr. class PyFloatAttribute : public PyConcreteAttribute { public: @@ -3089,6 +3166,8 @@ void mlir::python::populateIRSubmodule(py::module ) { // Builtin attribute bindings. PyFloatAttribute::bind(m); + PyArrayAttribute::bind(m); + PyArrayAttribute::PyArrayAttributeIterator::bind(m); PyIntegerAttribute::bind(m); PyBoolAttribute::bind(m); PyStringAttribute::bind(m); diff --git a/mlir/test/Bindings/Python/ir_attributes.py b/mlir/test/Bindings/Python/ir_attributes.py index 4ad180bb1b37..642c1f6a836c 100644 --- a/mlir/test/Bindings/Python/ir_attributes.py +++ b/mlir/test/Bindings/Python/ir_attributes.py @@ -269,3 +269,54 @@ def testTypeAttr(): run(testTypeAttr) + + +# CHECK-LABEL: TEST: testArrayAttr +def testArrayAttr(): + with Context(): +raw = Attribute.parse("[42, true, vector<4xf32>]") + # CHECK: attr: [42, true, vector<4xf32>] + print("raw attr:", raw) + # CHECK: - 42 + # CHECK: - true + # CHECK: - vector<4xf32> + for attr in ArrayAttr(raw): +print("- ", attr) + + with Context(): +intAttr = Attribute.parse("42") +
[llvm-branch-commits] [mlir] ac6ada4 - Fix MLIR Python bindings build after changes to the C API to use StringRef (NFC)
Author: Mehdi Amini Date: 2020-12-09T03:27:37Z New Revision: ac6ada4d3e059397d2812c8c0bd449214bc58737 URL: https://github.com/llvm/llvm-project/commit/ac6ada4d3e059397d2812c8c0bd449214bc58737 DIFF: https://github.com/llvm/llvm-project/commit/ac6ada4d3e059397d2812c8c0bd449214bc58737.diff LOG: Fix MLIR Python bindings build after changes to the C API to use StringRef (NFC) Added: Modified: mlir/lib/Bindings/Python/IRModules.cpp Removed: diff --git a/mlir/lib/Bindings/Python/IRModules.cpp b/mlir/lib/Bindings/Python/IRModules.cpp index cffebf6c715c..5519c66ee1ab 100644 --- a/mlir/lib/Bindings/Python/IRModules.cpp +++ b/mlir/lib/Bindings/Python/IRModules.cpp @@ -1571,7 +1571,7 @@ class PyStringAttribute : public PyConcreteAttribute { "get", [](std::string value, DefaultingPyMlirContext context) { MlirAttribute attr = - mlirStringAttrGet(context->get(), value.size(), [0]); + mlirStringAttrGet(context->get(), toMlirStringRef(value)); return PyStringAttribute(context->getRef(), attr); }, py::arg("value"), py::arg("context") = py::none(), @@ -1580,7 +1580,7 @@ class PyStringAttribute : public PyConcreteAttribute { "get_typed", [](PyType , std::string value) { MlirAttribute attr = - mlirStringAttrTypedGet(type, value.size(), [0]); + mlirStringAttrTypedGet(type, toMlirStringRef(value)); return PyStringAttribute(type.getContext(), attr); }, ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] e56f398 - Add Python binding for MLIR Type Attribute
Author: Mehdi Amini Date: 2020-12-07T23:06:58Z New Revision: e56f398dd3740d97ac3b7ec1c69a12b951efd9a3 URL: https://github.com/llvm/llvm-project/commit/e56f398dd3740d97ac3b7ec1c69a12b951efd9a3 DIFF: https://github.com/llvm/llvm-project/commit/e56f398dd3740d97ac3b7ec1c69a12b951efd9a3.diff LOG: Add Python binding for MLIR Type Attribute Differential Revision: https://reviews.llvm.org/D92711 Added: Modified: mlir/lib/Bindings/Python/IRModules.cpp mlir/test/Bindings/Python/ir_attributes.py Removed: diff --git a/mlir/lib/Bindings/Python/IRModules.cpp b/mlir/lib/Bindings/Python/IRModules.cpp index 39a17d053543..cffebf6c715c 100644 --- a/mlir/lib/Bindings/Python/IRModules.cpp +++ b/mlir/lib/Bindings/Python/IRModules.cpp @@ -1922,6 +1922,28 @@ class PyDenseFPElementsAttribute } }; +class PyTypeAttribute : public PyConcreteAttribute { +public: + static constexpr IsAFunctionTy isaFunction = mlirAttributeIsAType; + static constexpr const char *pyClassName = "TypeAttr"; + using PyConcreteAttribute::PyConcreteAttribute; + + static void bindDerived(ClassTy ) { +c.def_static( +"get", +[](PyType value, DefaultingPyMlirContext context) { + MlirAttribute attr = mlirTypeAttrGet(value.get()); + return PyTypeAttribute(context->getRef(), attr); +}, +py::arg("value"), py::arg("context") = py::none(), +"Gets a uniqued Type attribute"); +c.def_property_readonly("value", [](PyTypeAttribute ) { + return PyType(self.getContext()->getRef(), +mlirTypeAttrGetValue(self.get())); +}); + } +}; + /// Unit Attribute subclass. Unit attributes don't have values. class PyUnitAttribute : public PyConcreteAttribute { public: @@ -3073,6 +3095,7 @@ void mlir::python::populateIRSubmodule(py::module ) { PyDenseElementsAttribute::bind(m); PyDenseIntElementsAttribute::bind(m); PyDenseFPElementsAttribute::bind(m); + PyTypeAttribute::bind(m); PyUnitAttribute::bind(m); // diff --git a/mlir/test/Bindings/Python/ir_attributes.py b/mlir/test/Bindings/Python/ir_attributes.py index 0572220c750d..4ad180bb1b37 100644 --- a/mlir/test/Bindings/Python/ir_attributes.py +++ b/mlir/test/Bindings/Python/ir_attributes.py @@ -255,3 +255,17 @@ def testDenseFPAttr(): run(testDenseFPAttr) + + +# CHECK-LABEL: TEST: testTypeAttr +def testTypeAttr(): + with Context(): +raw = Attribute.parse("vector<4xf32>") +# CHECK: attr: vector<4xf32> +print("attr:", raw) +type_attr = TypeAttr(raw) +# CHECK: f32 +print(ShapedType(type_attr.value).element_type) + + +run(testTypeAttr) ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] e15ae45 - Customize exception thrown from mlir.Operation.create() python bindings
Author: Mehdi Amini Date: 2020-12-07T23:06:58Z New Revision: e15ae454b4b4632d4f40a9d95a5c7e4de95990cc URL: https://github.com/llvm/llvm-project/commit/e15ae454b4b4632d4f40a9d95a5c7e4de95990cc DIFF: https://github.com/llvm/llvm-project/commit/e15ae454b4b4632d4f40a9d95a5c7e4de95990cc.diff LOG: Customize exception thrown from mlir.Operation.create() python bindings The default exception handling isn't very user friendly and does not point accurately to the issue. Instead we can indicate which of the operands isn't valid and provide contextual information in the error message. Differential Revision: https://reviews.llvm.org/D92710 Added: Modified: mlir/lib/Bindings/Python/IRModules.cpp mlir/test/Bindings/Python/ir_operation.py Removed: diff --git a/mlir/lib/Bindings/Python/IRModules.cpp b/mlir/lib/Bindings/Python/IRModules.cpp index 3a80064866c0..39a17d053543 100644 --- a/mlir/lib/Bindings/Python/IRModules.cpp +++ b/mlir/lib/Bindings/Python/IRModules.cpp @@ -906,11 +906,31 @@ py::object PyOperation::create( if (attributes) { mlirAttributes.reserve(attributes->size()); for (auto : *attributes) { - - auto name = it.first.cast(); - auto = it.second.cast(); - // TODO: Verify attribute originates from the same context. - mlirAttributes.emplace_back(std::move(name), attribute); + std::string key; + try { +key = it.first.cast(); + } catch (py::cast_error ) { +std::string msg = "Invalid attribute key (not a string) when " + "attempting to create the operation \"" + + name + "\" (" + err.what() + ")"; +throw py::cast_error(msg); + } + try { +auto = it.second.cast(); +// TODO: Verify attribute originates from the same context. +mlirAttributes.emplace_back(std::move(key), attribute); + } catch (py::reference_cast_error &) { +// This exception seems thrown when the value is "None". +std::string msg = +"Found an invalid (`None`?) attribute value for the key \"" + key + +"\" when attempting to create the operation \"" + name + "\""; +throw py::cast_error(msg); + } catch (py::cast_error ) { +std::string msg = "Invalid attribute value for the key \"" + key + + "\" when attempting to create the operation \"" + + name + "\" (" + err.what() + ")"; +throw py::cast_error(msg); + } } } // Unpack/validate successors. diff --git a/mlir/test/Bindings/Python/ir_operation.py b/mlir/test/Bindings/Python/ir_operation.py index d23e0b6c0b4e..1f6df8626a0a 100644 --- a/mlir/test/Bindings/Python/ir_operation.py +++ b/mlir/test/Bindings/Python/ir_operation.py @@ -551,3 +551,30 @@ def testPrintInvalidOperation(): # CHECK: "module"() ( { # CHECK: }) : () -> () run(testPrintInvalidOperation) + + +# CHECK-LABEL: TEST: testCreateWithInvalidAttributes +def testCreateWithInvalidAttributes(): + ctx = Context() + with Location.unknown(ctx): +try: + Operation.create("module", attributes={None:StringAttr.get("name")}) +except Exception as e: + # CHECK: Invalid attribute key (not a string) when attempting to create the operation "module" (Unable to cast Python instance of type to C++ type + print(e) +try: + Operation.create("module", attributes={42:StringAttr.get("name")}) +except Exception as e: + # CHECK: Invalid attribute key (not a string) when attempting to create the operation "module" (Unable to cast Python instance of type to C++ type + print(e) +try: + Operation.create("module", attributes={"some_key":ctx}) +except Exception as e: + # CHECK: Invalid attribute value for the key "some_key" when attempting to create the operation "module" (Unable to cast Python instance of type to C++ type 'mlir::python::PyAttribute') + print(e) +try: + Operation.create("module", attributes={"some_key":None}) +except Exception as e: + # CHECK: Found an invalid (`None`?) attribute value for the key "some_key" when attempting to create the operation "module" + print(e) +run(testCreateWithInvalidAttributes) ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] 5d208d5 - Revert "Include Region.h in OperationSupport.h instead of forward declaring it (NFC)"
Author: Mehdi Amini Date: 2020-12-03T19:59:20Z New Revision: 5d208d505438fbd3e6d6a467e72d70d98e9136c0 URL: https://github.com/llvm/llvm-project/commit/5d208d505438fbd3e6d6a467e72d70d98e9136c0 DIFF: https://github.com/llvm/llvm-project/commit/5d208d505438fbd3e6d6a467e72d70d98e9136c0.diff LOG: Revert "Include Region.h in OperationSupport.h instead of forward declaring it (NFC)" This reverts commit e312b388ebadcd074d559454aca1fd6e75e8e7a5. The original breaking change has been reverted Added: Modified: mlir/include/mlir/IR/OperationSupport.h Removed: diff --git a/mlir/include/mlir/IR/OperationSupport.h b/mlir/include/mlir/IR/OperationSupport.h index fb3dc20964bb..74899c9565fe 100644 --- a/mlir/include/mlir/IR/OperationSupport.h +++ b/mlir/include/mlir/IR/OperationSupport.h @@ -18,7 +18,6 @@ #include "mlir/IR/BlockSupport.h" #include "mlir/IR/Identifier.h" #include "mlir/IR/Location.h" -#include "mlir/IR/Region.h" #include "mlir/IR/TypeRange.h" #include "mlir/IR/Types.h" #include "mlir/IR/Value.h" @@ -40,6 +39,7 @@ class OperandRange; class OpFoldResult; class ParseResult; class Pattern; +class Region; class ResultRange; class RewritePattern; class Type; ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] 6cd9608 - Revert "Switch to std::is_trivially_move_constructible and std::is_trivially_copy_constructible"
Author: Mehdi Amini Date: 2020-12-03T19:58:06Z New Revision: 6cd9608fb37ca2418fb44b57ec955bb5efe10689 URL: https://github.com/llvm/llvm-project/commit/6cd9608fb37ca2418fb44b57ec955bb5efe10689 DIFF: https://github.com/llvm/llvm-project/commit/6cd9608fb37ca2418fb44b57ec955bb5efe10689.diff LOG: Revert "Switch to std::is_trivially_move_constructible and std::is_trivially_copy_constructible" This reverts commit c8d406c93c5bb0150201f78d8428dd29d289. Builds are broken with some versions of GCC. Added: llvm/unittests/Support/TypeTraitsTest.cpp Modified: llvm/include/llvm/ADT/FunctionExtras.h llvm/include/llvm/ADT/SmallVector.h llvm/include/llvm/Support/type_traits.h llvm/unittests/Support/CMakeLists.txt llvm/utils/gn/secondary/llvm/unittests/Support/BUILD.gn Removed: diff --git a/llvm/include/llvm/ADT/FunctionExtras.h b/llvm/include/llvm/ADT/FunctionExtras.h index c6ce4eb5c3be..7f8fb103f148 100644 --- a/llvm/include/llvm/ADT/FunctionExtras.h +++ b/llvm/include/llvm/ADT/FunctionExtras.h @@ -57,7 +57,7 @@ namespace detail { template using EnableIfTrivial = -std::enable_if_t::value && +std::enable_if_t::value && std::is_trivially_destructible::value>; template class UniqueFunctionBase { @@ -83,8 +83,8 @@ template class UniqueFunctionBase { template using AdjustedParamT = typename std::conditional< !std::is_reference::value && - std::is_trivially_copy_constructible::value && - std::is_trivially_move_constructible::value && + llvm::is_trivially_copy_constructible::value && + llvm::is_trivially_move_constructible::value && IsSizeLessThanThresholdT::value, T, T &>::type; diff --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h index f288f4bd106e..c5bb1ece0667 100644 --- a/llvm/include/llvm/ADT/SmallVector.h +++ b/llvm/include/llvm/ADT/SmallVector.h @@ -278,8 +278,8 @@ class SmallVectorTemplateCommon /// copy these types with memcpy, there is no way for the type to observe this. /// This catches the important case of std::pair, which is not /// trivially assignable. -template ::value) && - (std::is_trivially_move_constructible::value) && +template ::value) && + (is_trivially_move_constructible::value) && std::is_trivially_destructible::value> class SmallVectorTemplateBase : public SmallVectorTemplateCommon { protected: diff --git a/llvm/include/llvm/Support/type_traits.h b/llvm/include/llvm/Support/type_traits.h index 14d9d06c50ad..7b7d5d991f3f 100644 --- a/llvm/include/llvm/Support/type_traits.h +++ b/llvm/include/llvm/Support/type_traits.h @@ -70,6 +70,20 @@ struct const_pointer_or_const_ref union copy_construction_triviality_helper { +T t; +copy_construction_triviality_helper() = default; +copy_construction_triviality_helper(const copy_construction_triviality_helper&) = default; +~copy_construction_triviality_helper() = default; +}; +/// Internal utility to detect trivial move construction. +template union move_construction_triviality_helper { +T t; +move_construction_triviality_helper() = default; +move_construction_triviality_helper(move_construction_triviality_helper&&) = default; +~move_construction_triviality_helper() = default; +}; template union trivial_helper { @@ -78,6 +92,29 @@ union trivial_helper { } // end namespace detail +/// An implementation of `std::is_trivially_copy_constructible` since we have +/// users with STLs that don't yet include it. +template +struct is_trivially_copy_constructible +: std::is_copy_constructible< + ::llvm::detail::copy_construction_triviality_helper> {}; +template +struct is_trivially_copy_constructible : std::true_type {}; +template +struct is_trivially_copy_constructible : std::false_type {}; + +/// An implementation of `std::is_trivially_move_constructible` since we have +/// users with STLs that don't yet include it. +template +struct is_trivially_move_constructible +: std::is_move_constructible< + ::llvm::detail::move_construction_triviality_helper> {}; +template +struct is_trivially_move_constructible : std::true_type {}; +template +struct is_trivially_move_constructible : std::true_type {}; + + template struct is_copy_assignable { template diff --git a/llvm/unittests/Support/CMakeLists.txt b/llvm/unittests/Support/CMakeLists.txt index 48941b6d4d50..86a25faa7d78 100644 --- a/llvm/unittests/Support/CMakeLists.txt +++ b/llvm/unittests/Support/CMakeLists.txt @@ -80,6 +80,7 @@ add_llvm_unittest(SupportTests TimerTest.cpp ToolOutputFileTest.cpp TypeNameTest.cpp + TypeTraitsTest.cpp TrailingObjectsTest.cpp TrigramIndexTest.cpp UnicodeTest.cpp diff --git a/llvm/unittests/Support/TypeTraitsTest.cpp
[llvm-branch-commits] [mlir] e312b38 - Include Region.h in OperationSupport.h instead of forward declaring it (NFC)
Author: Mehdi Amini Date: 2020-12-03T18:54:27Z New Revision: e312b388ebadcd074d559454aca1fd6e75e8e7a5 URL: https://github.com/llvm/llvm-project/commit/e312b388ebadcd074d559454aca1fd6e75e8e7a5 DIFF: https://github.com/llvm/llvm-project/commit/e312b388ebadcd074d559454aca1fd6e75e8e7a5.diff LOG: Include Region.h in OperationSupport.h instead of forward declaring it (NFC) This fixes the build on gcc5 toolchain where sizeof is required for types used in SmallVector now. This is a consequence of using std::is_trivially_copy_constructible instead of the LLVM variant: https://reviews.llvm.org/D92543 Added: Modified: mlir/include/mlir/IR/OperationSupport.h Removed: diff --git a/mlir/include/mlir/IR/OperationSupport.h b/mlir/include/mlir/IR/OperationSupport.h index 74899c9565fe..fb3dc20964bb 100644 --- a/mlir/include/mlir/IR/OperationSupport.h +++ b/mlir/include/mlir/IR/OperationSupport.h @@ -18,6 +18,7 @@ #include "mlir/IR/BlockSupport.h" #include "mlir/IR/Identifier.h" #include "mlir/IR/Location.h" +#include "mlir/IR/Region.h" #include "mlir/IR/TypeRange.h" #include "mlir/IR/Types.h" #include "mlir/IR/Value.h" @@ -39,7 +40,6 @@ class OperandRange; class OpFoldResult; class ParseResult; class Pattern; -class Region; class ResultRange; class RewritePattern; class Type; ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits