[llvm-branch-commits] [mlir] 28070f1 - xla_lhlo dialect fixes to work with upstream
Author: Uday Bondhugula Date: 2021-09-22T14:28:52+05:30 New Revision: 28070f1be700f812dd228e51ecbe1efb3b4a73ea URL: https://github.com/llvm/llvm-project/commit/28070f1be700f812dd228e51ecbe1efb3b4a73ea DIFF: https://github.com/llvm/llvm-project/commit/28070f1be700f812dd228e51ecbe1efb3b4a73ea.diff LOG: xla_lhlo dialect fixes to work with upstream Added: Modified: mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.h mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.td mlir/include/mlir/InitAllDialects.h mlir/lib/Dialect/LHLO/IR/CMakeLists.txt mlir/lib/Dialect/LHLO/IR/LHLOOps.cc mlir/test/Dialect/LHLO/lhlo_ops.mlir Removed: diff --git a/mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.h b/mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.h index 45309f5110ad..c17ee6d63bd4 100644 --- a/mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.h +++ b/mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.h @@ -20,28 +20,25 @@ limitations under the License. #include "llvm/ADT/StringRef.h" #include "mlir/IR/Attributes.h" // from @llvm-project +#include "mlir/IR/BuiltinTypes.h" // from @llvm-project #include "mlir/IR/Dialect.h" // from @llvm-project #include "mlir/IR/Location.h" // from @llvm-project #include "mlir/IR/MLIRContext.h" // from @llvm-project #include "mlir/IR/OpDefinition.h" // from @llvm-project #include "mlir/IR/Operation.h" // from @llvm-project -#include "mlir/IR/StandardTypes.h" // from @llvm-project #include "mlir/IR/Types.h" // from @llvm-project #include "mlir/Interfaces/SideEffectInterfaces.h" // from @llvm-project namespace mlir { class OpBuilder; +} // end namespace mlir #include "mlir/Dialect/LHLO/IR/LHLOStructs.h.inc" -namespace xla_lhlo { - #include "mlir/Dialect/LHLO/IR/LHLOOpsDialect.h.inc" #define GET_OP_CLASSES #include "mlir/Dialect/LHLO/IR/LHLOOps.h.inc" -} // namespace xla_lhlo -} // end namespace mlir #endif // MLIR_DIALECT_LHLO_IR_LHLO_OPS_H_ diff --git a/mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.td b/mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.td index 3ae266e82c3c..7f83425f138c 100644 --- a/mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.td +++ b/mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.td @@ -24,7 +24,7 @@ include "mlir/Dialect/LHLO/IR/HLOOpsBase.td" def LHLO_Dialect : Dialect { let name = "xla_lhlo"; - let cppNamespace = "xla_lhlo"; + let cppNamespace = "::mlir::xla_lhlo"; } //===--===// @@ -382,7 +382,7 @@ def ConvDimensionNumbers : StructAttr<"ConvDimensionNumbers", LHLO_Dialect, [ StructFieldAttr<"output_feature_dimension", I64Attr>, StructFieldAttr<"output_spatial_dimensions", I64ElementsAttr>] > { - let description = "Structure of dimension information for conv op"; + let summary = "Structure of dimension information for conv op"; } def LHLO_ConvOp : LHLO_Op<"convolution", []>, BASE_HLO_ConvOp { @@ -427,7 +427,7 @@ def DotDimensionNumbers : StructAttr<"DotDimensionNumbers", LHLO_Dialect, [ StructFieldAttr<"lhs_contracting_dimensions", I64ElementsAttr>, StructFieldAttr<"rhs_contracting_dimensions", I64ElementsAttr> ]> { - let description = "Structure of dimension information for dot product"; + let summary = "Structure of dimension information for dot product"; } def LHLO_DotGeneralOp : LHLO_Op<"dot_general", []>, BASE_HLO_DotGeneralOp { @@ -452,7 +452,7 @@ def GatherDimensionNumbers: StructAttr<"GatherDimensionNumbers", LHLO_Dialect, StructFieldAttr<"collapsed_slice_dims", I64ElementsAttr>, StructFieldAttr<"start_index_map", I64ElementsAttr>, StructFieldAttr<"index_vector_dim", I64Attr>]> { - let description = "Structure of dimension information for gather"; + let summary = "Structure of dimension information for gather"; } def LHLO_GatherOp: LHLO_Op<"gather", []>, BASE_HLO_GatherOp { @@ -489,7 +489,7 @@ def ScatterDimensionNumbers StructFieldAttr<"scatter_dims_to_operand_dims", I64ElementsAttr>, StructFieldAttr<"index_vector_dim", I64Attr> ]> { - let description = "Structure of dimension information for scatter"; + let summary = "Structure of dimension information for scatter"; } def LHLO_ScatterOp: LHLO_Op<"scatter", [RecursiveSideEffects]>, @@ -597,9 +597,7 @@ def LHLO_TupleOp : LHLO_ReadOnlyOp<"tuple", [NoSideEffect]>, BASE_HLO_TupleOp { let arguments = (ins Arg, "", [MemRead]>:$input); let results = (outs NestedTupleOf<[LHLO_BufferOrIntOrFP]>); - let builders = [OpBuilder< - "OpBuilder &builder, OperationState &results, " - "ValueRange values">]; + let builders = [OpBuilder<(ins "ValueRange":$values)>]; } def LHLO_WhileOp @@ -642,8 +640,7 @@ def FusionOp : LHLO_Op<"fusion", [SingleBlockImplicitTerminator<"TerminatorOp">] let skipDefaultBuilders = 1; let builders = [ - OpBuilder<"OpBuilder &builder, Operatio
[llvm-branch-commits] [mlir] 1e17c40 - [MLIR] Introduce trait EquiMemRefAndEltTypeOperands
Author: Uday Bondhugula Date: 2021-09-22T14:23:45+05:30 New Revision: 1e17c40c4ce8daf46bf5df28a04d1e9ea5690cb2 URL: https://github.com/llvm/llvm-project/commit/1e17c40c4ce8daf46bf5df28a04d1e9ea5690cb2 DIFF: https://github.com/llvm/llvm-project/commit/1e17c40c4ce8daf46bf5df28a04d1e9ea5690cb2.diff LOG: [MLIR] Introduce trait EquiMemRefAndEltTypeOperands This trait is used by LHLO ops where the operands and result may either have operands of the same type or equivalent types where a 0-d memref of an elemental type is considered equivalent to that elemental type. TODO: add a test dialect test case here. Added: Modified: mlir/include/mlir/IR/OpBase.td mlir/include/mlir/IR/OpDefinition.h mlir/lib/IR/Operation.cpp Removed: diff --git a/mlir/include/mlir/IR/OpBase.td b/mlir/include/mlir/IR/OpBase.td index ac99ac4d0897d..d82b734a329a8 100644 --- a/mlir/include/mlir/IR/OpBase.td +++ b/mlir/include/mlir/IR/OpBase.td @@ -1889,6 +1889,9 @@ def IsolatedFromAbove : NativeOpTrait<"IsIsolatedFromAbove">; def ResultsAreFloatLike : NativeOpTrait<"ResultsAreFloatLike">; // Op has the same operand type. def SameTypeOperands : NativeOpTrait<"SameTypeOperands">; +// Op has the same operand type or 0-d memref equivalent type. +def EquiMemRefAndEltTypeOperands +: NativeOpTrait<"EquiMemRefAndEltTypeOperands">; // Op has same shape for all operands. def SameOperandsShape : NativeOpTrait<"SameOperandsShape">; // Op has same operand and result shape. diff --git a/mlir/include/mlir/IR/OpDefinition.h b/mlir/include/mlir/IR/OpDefinition.h index e7f644f456b22..932ef0542781e 100644 --- a/mlir/include/mlir/IR/OpDefinition.h +++ b/mlir/include/mlir/IR/OpDefinition.h @@ -248,6 +248,7 @@ LogicalResult verifyAtLeastNOperands(Operation *op, unsigned numOperands); LogicalResult verifyOperandsAreFloatLike(Operation *op); LogicalResult verifyOperandsAreSignlessIntegerLike(Operation *op); LogicalResult verifySameTypeOperands(Operation *op); +LogicalResult verifyEquiMemRefAndEltTypeOperands(Operation *op); LogicalResult verifyZeroRegion(Operation *op); LogicalResult verifyOneRegion(Operation *op); LogicalResult verifyNRegions(Operation *op, unsigned numRegions); @@ -1143,6 +1144,18 @@ class SameTypeOperands : public TraitBase { } }; +/// This class verifies that all operands of the specified op have the same +/// type with the exception that 0-d memref type of an elemental type is treated +/// the same as that elemental type. +template +class EquiMemRefAndEltTypeOperands +: public TraitBase { +public: + static LogicalResult verifyTrait(Operation *op) { +return impl::verifyEquiMemRefAndEltTypeOperands(op); + } +}; + /// This class provides the API for a sub-set of ops that are known to be /// constant-like. These are non-side effecting operations with one result and /// zero operands that can always be folded to a specific attribute value. diff --git a/mlir/lib/IR/Operation.cpp b/mlir/lib/IR/Operation.cpp index 457c993b92ad3..657b612ccce16 100644 --- a/mlir/lib/IR/Operation.cpp +++ b/mlir/lib/IR/Operation.cpp @@ -792,6 +792,32 @@ LogicalResult OpTrait::impl::verifySameTypeOperands(Operation *op) { return success(); } +LogicalResult OpTrait::impl::verifyEquiMemRefAndEltTypeOperands(Operation *op) { + // Zero or one operand always have the "same" type. + unsigned nOperands = op->getNumOperands(); + if (nOperands < 2) +return success(); + + StringRef msg = + "requires all operands to have the same or equivalent type where a 0-d " + "memref type is considered equivalent to its elemental type"; + + auto prevType = op->getOperand(0).getType(); + for (auto opType : llvm::drop_begin(op->getOperandTypes(), 1)) { +if (opType != prevType) { + if (auto opMemRefType = opType.dyn_cast()) +if (opMemRefType.getRank() != 0 || +opMemRefType.getElementType() != prevType) + return op->emitOpError(msg); + if (auto prevMemRefType = prevType.dyn_cast()) +if (prevMemRefType.getRank() != 0 && +prevMemRefType.getElementType() != opType) + return op->emitOpError(msg); +} + } + return success(); +} + LogicalResult OpTrait::impl::verifyZeroRegion(Operation *op) { if (op->getNumRegions() != 0) return op->emitOpError() << "requires zero regions"; ___ 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] 7a34031 - [MLIR] Add verifier for LHLO get tuple element op
Author: Uday Bondhugula Date: 2021-09-23T05:52:22+05:30 New Revision: 7a34031a8fdabe5f484a537c96a7cd31999c51d5 URL: https://github.com/llvm/llvm-project/commit/7a34031a8fdabe5f484a537c96a7cd31999c51d5 DIFF: https://github.com/llvm/llvm-project/commit/7a34031a8fdabe5f484a537c96a7cd31999c51d5.diff LOG: [MLIR] Add verifier for LHLO get tuple element op The LHLO GetTupleElementOp was missing its verifier. Add the verifier. Added: mlir/test/Dialect/LHLO/invalid.mlir Modified: mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.td mlir/lib/Dialect/LHLO/IR/LHLOOps.cc Removed: diff --git a/mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.td b/mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.td index 15c17ee3b85c..104e9c011de6 100644 --- a/mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.td +++ b/mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.td @@ -251,6 +251,8 @@ def LHLO_GetTupleElementOp: LHLO_Op<"get_tuple_element", []>, BASE_HLO_GetTupleE ); let results = (outs Arg); + + let verifier = [{ return ::verify(*this); }]; } def LHLO_CompareOp: LHLO_Op<"compare", []>, BASE_HLO_CompareOp { diff --git a/mlir/lib/Dialect/LHLO/IR/LHLOOps.cc b/mlir/lib/Dialect/LHLO/IR/LHLOOps.cc index 26251379be8f..01b0da948dea 100644 --- a/mlir/lib/Dialect/LHLO/IR/LHLOOps.cc +++ b/mlir/lib/Dialect/LHLO/IR/LHLOOps.cc @@ -59,11 +59,10 @@ void LHLODialect::initialize() { >(); } -#define GET_OP_CLASSES -#include "mlir/Dialect/LHLO/IR/LHLOOps.cpp.inc" - -namespace mlir { -namespace xla_lhlo { +using xla_lhlo::ConstOp; +using xla_lhlo::FusionOp; +using xla_lhlo::GetTupleElementOp; +using xla_lhlo::TupleOp; //===--===// // ConstOp. @@ -123,5 +122,30 @@ void TupleOp::build(OpBuilder& builder, OperationState& result, build(builder, result, builder.getTupleType(types), values); } -} // namespace xla_lhlo -} // namespace mlir +//===--===// +// GetTupleElementOp +//===--===// + +static LogicalResult verify(GetTupleElementOp op) { + unsigned index = op.index(); + auto operandType = op.getOperand().getType().cast(); + if (index >= operandType.size()) { +return op.emitOpError( +llvm::formatv("index {0} is out of bounds of operand with size {1}", + index, operandType.size())); + } + + Type expectedType = operandType.getType(index); + if (op.getType() != expectedType) { +return op.emitOpError(llvm::formatv("has return type {0}, but expected {1}", +op.getType(), expectedType)); + } + return success(); +} + +//===--===// +// TableGen'd op method definitions +//===--===// + +#define GET_OP_CLASSES +#include "mlir/Dialect/LHLO/IR/LHLOOps.cpp.inc" diff --git a/mlir/test/Dialect/LHLO/invalid.mlir b/mlir/test/Dialect/LHLO/invalid.mlir new file mode 100644 index ..0e269535d00c --- /dev/null +++ b/mlir/test/Dialect/LHLO/invalid.mlir @@ -0,0 +1,10 @@ +// RUN: mlir-opt %s -split-input-file -verify-diagnostics + +func @passthrough(%arg : memref<8xi32>) { + %c0_i32 = constant 0 : i32 + %tuple = "xla_lhlo.tuple"(%c0_i32, %arg) : (i32, memref<8xi32>) -> (tuple>) + %elt = "xla_lhlo.get_tuple_element"(%tuple) {index = 0 : i32} : (tuple>) -> i32 + // expected-error@+1{{'xla_lhlo.get_tuple_element' op has return type memref<8xi32>, but expected i32}} + %mem = "xla_lhlo.get_tuple_element"(%tuple) {index = 0 : i32} : (tuple>) -> memref<8xi32> + 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] 071e483 - Add verifier for the LHLO TupleOp
Author: Prateek Gupta Date: 2021-09-23T05:53:52+05:30 New Revision: 071e483b072ee7ff59ec3386b6bc0155c7a230b3 URL: https://github.com/llvm/llvm-project/commit/071e483b072ee7ff59ec3386b6bc0155c7a230b3 DIFF: https://github.com/llvm/llvm-project/commit/071e483b072ee7ff59ec3386b6bc0155c7a230b3.diff LOG: Add verifier for the LHLO TupleOp Added verification support for LHLO TupleOp, so that inconsistency between input and output types for the LHLO TupleOp can be checked. Added: Modified: mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.td mlir/lib/Dialect/LHLO/IR/LHLOOps.cc mlir/test/Dialect/LHLO/invalid.mlir Removed: diff --git a/mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.td b/mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.td index 104e9c011de6..752992761485 100644 --- a/mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.td +++ b/mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.td @@ -600,6 +600,8 @@ def LHLO_TupleOp : LHLO_ReadOnlyOp<"tuple", [NoSideEffect]>, BASE_HLO_TupleOp { let results = (outs NestedTupleOf<[LHLO_BufferOrIntOrFP]>); let builders = [OpBuilder<(ins "ValueRange":$values)>]; + + let verifier = [{ return::verify(*this);}]; } def LHLO_WhileOp diff --git a/mlir/lib/Dialect/LHLO/IR/LHLOOps.cc b/mlir/lib/Dialect/LHLO/IR/LHLOOps.cc index 01b0da948dea..27d2596f167e 100644 --- a/mlir/lib/Dialect/LHLO/IR/LHLOOps.cc +++ b/mlir/lib/Dialect/LHLO/IR/LHLOOps.cc @@ -122,6 +122,17 @@ void TupleOp::build(OpBuilder& builder, OperationState& result, build(builder, result, builder.getTupleType(types), values); } +static LogicalResult verify(TupleOp op) { + SmallVector operandTypes = {op.operand_type_begin(), + op.operand_type_end()}; + auto expectedType = TupleType::get(op.getContext(), operandTypes); + if (op.getType() != expectedType) { +return op.emitOpError(llvm::formatv("has return type {0}, but expected {1}", +op.getType(), expectedType)); + } + return success(); +} + //===--===// // GetTupleElementOp //===--===// diff --git a/mlir/test/Dialect/LHLO/invalid.mlir b/mlir/test/Dialect/LHLO/invalid.mlir index 0e269535d00c..98e744c0167c 100644 --- a/mlir/test/Dialect/LHLO/invalid.mlir +++ b/mlir/test/Dialect/LHLO/invalid.mlir @@ -8,3 +8,30 @@ func @passthrough(%arg : memref<8xi32>) { %mem = "xla_lhlo.get_tuple_element"(%tuple) {index = 0 : i32} : (tuple>) -> memref<8xi32> return } + +// - + +func @pass_wrong_number_of_arguments(%arg : memref<8xi32>){ +%c0 = constant 0 : i32 +%c1 = constant 1 : i32 +// expected-error@+1{{'xla_lhlo.tuple' op has return type tuple, but expected tuple, i32>}} +%tuple = "xla_lhlo.tuple"(%c0, %arg, %c1) : (i32, memref<8xi32>, i32) -> (tuple) +} + +// - + +func @pass_wrong_type(%arg : i32){ +%c = constant 0 : i32 +// expected-error@+1{{'xla_lhlo.tuple' op has return type tuple>, but expected tuple}} +%tuple = "xla_lhlo.tuple"(%c, %arg) : (i32, i32) -> (tuple>) +return +} + +// - + +func @pass_wrong_order(%arg : memref<8xi32>){ +%c = constant 0 : i32 +// expected-error@+1{{'xla_lhlo.tuple' op has return type tuple, i32>, but expected tuple>}} +%tuple = "xla_lhlo.tuple"(%c, %arg) : (i32, memref<8xi32>) -> (tuple, i32>) +return +} \ No newline at end of file ___ 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] 87b4572 - [MLIR] [NFC] Update xla_lhlo WhileOp documentation
Author: Uday Bondhugula Date: 2021-09-23T05:33:00+05:30 New Revision: 87b4572a6b574fba930770d0c8c96455d0340809 URL: https://github.com/llvm/llvm-project/commit/87b4572a6b574fba930770d0c8c96455d0340809 DIFF: https://github.com/llvm/llvm-project/commit/87b4572a6b574fba930770d0c8c96455d0340809.diff LOG: [MLIR] [NFC] Update xla_lhlo WhileOp documentation Update xla_lhlo WhileOp documentation. NFC. Added: Modified: mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.td Removed: diff --git a/mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.td b/mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.td index 7f83425f138c..15c17ee3b85c 100644 --- a/mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.td +++ b/mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.td @@ -607,7 +607,11 @@ def LHLO_WhileOp string description = [{ Returns the result of executing a body function until the cond body returns -true. +true. The `body` and `cond` regions are expected to have a single block +terminated with a `yield`. The operand (`init`), the result, the argument to +the body, the yield value from the body, and the argument to the conditional +are all a single tuple value of the same type. The yield value from the +conditional is always a boolean of type i1. See https://www.tensorflow.org/xla/operation_semantics#while. }]; ___ 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] eff9b54 - [MLIR] Introduce IfOp in the xla_lhlo dialect
Author: Uday Bondhugula Date: 2021-09-23T05:56:13+05:30 New Revision: eff9b542c7e3cbc44faac86046461a982ac9dcdc URL: https://github.com/llvm/llvm-project/commit/eff9b542c7e3cbc44faac86046461a982ac9dcdc DIFF: https://github.com/llvm/llvm-project/commit/eff9b542c7e3cbc44faac86046461a982ac9dcdc.diff LOG: [MLIR] Introduce IfOp in the xla_lhlo dialect Introduce LHLO IfOp to model conditionals on the memref form. This is lowered form form of HLO IfOp (the latter operates on tensors). Its design is similar to that of the LHLO WhileOp, taking in tuples of memrefs or elemental types. The true and the false bodies return a tuple of the same type. Added: Modified: mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.td mlir/test/Dialect/LHLO/lhlo_ops.mlir Removed: diff --git a/mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.td b/mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.td index 752992761485..711549940570 100644 --- a/mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.td +++ b/mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.td @@ -467,6 +467,53 @@ def LHLO_GatherOp: LHLO_Op<"gather", []>, BASE_HLO_GatherOp { ); } +def LHLO_IfOp : LHLO_Op<"if", [AffineScope, RecursiveSideEffects]> { + string summary = "If operator"; + + string description = [{ +Returns the result of executing either a true or false function depending on +the result of a condition function. In contrast to the HLO version, the +tuple operands for the true or false branch are a tuple of memrefs or int/fp +types. Both the true and false branches also return such a tuple type: they +both return the same type and this match the result type of the op. + +Example: + +```mlir +func @lhlo_if(%arg0: memref<1x1x10xf32>, %arg1: memref<1x1x10xf32>, %arg2: memref) { + %0 = "xla_lhlo.tuple"(%arg0, %arg1) : (memref<1x1x10xf32>, memref<1x1x10xf32>) -> tuple, memref<1x1x10xf32>> + %1 = "xla_lhlo.if"(%arg2, %0, %0) ( { +^bb0(%arg3: tuple, memref<1x1x10xf32>>): +%2 = "xla_lhlo.get_tuple_element"(%arg3) {index = 0 : i32} : (tuple, memref<1x1x10xf32>>) -> memref<1x1x10xf32> +%3 = "xla_lhlo.tuple"(%2) : (memref<1x1x10xf32>) -> tuple> +"xla_lhlo.yield"(%3) : (tuple>) -> () + }, { +^bb0(%arg3: tuple, memref<1x1x10xf32>>): // no predecessors +%2 = "xla_lhlo.get_tuple_element"(%arg3) {index = 1 : i32} : (tuple, memref<1x1x10xf32>>) -> memref<1x1x10xf32> +%3 = "xla_lhlo.tuple"(%2) : (memref<1x1x10xf32>) -> tuple> +"xla_lhlo.yield"(%3) : (tuple>) -> () + }) : (memref, tuple, memref<1x1x10xf32>>, tuple, memref<1x1x10xf32>>) -> tuple> + "xla_lhlo.terminator"() : () -> () +} +``` + +See https://www.tensorflow.org/xla/operation_semantics#conditional. + }]; + + let arguments = (ins Arg : $init); + + let arguments = (ins +LHLO_PredBufferOrI1:$pred, +LHLO_TupleOfBufferOrIntOrFP:$true_arg, +LHLO_TupleOfBufferOrIntOrFP:$false_arg + ); + + let regions = (region AnyRegion:$true_branch, +AnyRegion:$false_branch); + + let results = (outs Arg); +} + def LHLO_MapOp : LHLO_Op<"map", [RecursiveSideEffects, SameOperandsShape]>, BASE_HLO_MapOp { let description = [{ diff --git a/mlir/test/Dialect/LHLO/lhlo_ops.mlir b/mlir/test/Dialect/LHLO/lhlo_ops.mlir index 30a84c5b4bcb..59ccfc8113be 100644 --- a/mlir/test/Dialect/LHLO/lhlo_ops.mlir +++ b/mlir/test/Dialect/LHLO/lhlo_ops.mlir @@ -235,3 +235,40 @@ func @while_op(%arg0: memref<4x?x16xf32>, %arg1: memref<4x?x16xf32>) { }) : (tuple>) -> tuple> "xla_lhlo.terminator"() : () -> () } + +// - + +func @lhlo_if(%arg0: memref<1x1x10xf32>, %arg1: memref<1x1x10xf32>, %arg2: memref) { + %0 = "xla_lhlo.tuple"(%arg0, %arg1) : (memref<1x1x10xf32>, memref<1x1x10xf32>) -> tuple, memref<1x1x10xf32>> + // CHECK: xla_lhlo.if + %1 = "xla_lhlo.if"(%arg2, %0, %0) ( { +^bb0(%arg3: tuple, memref<1x1x10xf32>>): +%2 = "xla_lhlo.get_tuple_element"(%arg3) {index = 0 : i32} : (tuple, memref<1x1x10xf32>>) -> memref<1x1x10xf32> +%3 = "xla_lhlo.tuple"(%2) : (memref<1x1x10xf32>) -> tuple> +"xla_lhlo.yield"(%3) : (tuple>) -> () + }, { +^bb0(%arg3: tuple, memref<1x1x10xf32>>): // no predecessors +%2 = "xla_lhlo.get_tuple_element"(%arg3) {index = 1 : i32} : (tuple, memref<1x1x10xf32>>) -> memref<1x1x10xf32> +%3 = "xla_lhlo.tuple"(%2) : (memref<1x1x10xf32>) -> tuple> +"xla_lhlo.yield"(%3) : (tuple>) -> () + }) : (memref, tuple, memref<1x1x10xf32>>, tuple, memref<1x1x10xf32>>) -> tuple> + "xla_lhlo.terminator"() : () -> () +} + +// CHECK-LABEL: func @lhlo_if_empty_arg +func @lhlo_if_empty_arg(%arg0: memref) { + %cst = constant 1.00e+00 : f32 + %cst_0 = constant 0.00e+00 : f32 + %0 = "xla_lhlo.tuple"() : () -> tuple<> + // CHECK: xla_lhlo.if + %1 = "xla_lhlo.if"(%arg0, %0, %0) ( { +^bb0(%arg1: tuple<>): +%2
[llvm-branch-commits] [mlir] 51de919 - Rename xla_lhlo dialect and namespace -> lmhlo
Author: Uday Bondhugula Date: 2021-09-23T06:12:54+05:30 New Revision: 51de91957abebee3c6fdf870f1388b266ea011b1 URL: https://github.com/llvm/llvm-project/commit/51de91957abebee3c6fdf870f1388b266ea011b1 DIFF: https://github.com/llvm/llvm-project/commit/51de91957abebee3c6fdf870f1388b266ea011b1.diff LOG: Rename xla_lhlo dialect and namespace -> lmhlo This change of name is being done to avoid a clash in the python binding with the xla_lhlo in Monolith's TensorFlow. While xla_lhlo was moved to MLIR proper in our branches, Monolith's TensorFlow still has it and its methods would get called instead of those in MLIR linked in by Monolith. Added: Modified: mlir/include/mlir/Dialect/LHLO/IR/CMakeLists.txt mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.h mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.td mlir/include/mlir/InitAllDialects.h mlir/lib/Dialect/LHLO/IR/LHLOOps.cc mlir/test/Dialect/LHLO/invalid.mlir mlir/test/Dialect/LHLO/lhlo_ops.mlir mlir/test/mlir-opt/commandline.mlir Removed: diff --git a/mlir/include/mlir/Dialect/LHLO/IR/CMakeLists.txt b/mlir/include/mlir/Dialect/LHLO/IR/CMakeLists.txt index f5c4548ccf534..b852d42171bd7 100644 --- a/mlir/include/mlir/Dialect/LHLO/IR/CMakeLists.txt +++ b/mlir/include/mlir/Dialect/LHLO/IR/CMakeLists.txt @@ -1,4 +1,4 @@ -add_mlir_dialect(LHLOOps xla_lhlo) +add_mlir_dialect(LHLOOps lmhlo) set(LLVM_TARGET_DEFINITIONS LHLOOps.td) mlir_tablegen(LHLOStructs.h.inc -gen-struct-attr-decls) diff --git a/mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.h b/mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.h index c17ee6d63bd40..94a9de69cfd27 100644 --- a/mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.h +++ b/mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.h @@ -40,5 +40,4 @@ class OpBuilder; #define GET_OP_CLASSES #include "mlir/Dialect/LHLO/IR/LHLOOps.h.inc" - #endif // MLIR_DIALECT_LHLO_IR_LHLO_OPS_H_ diff --git a/mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.td b/mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.td index 711549940570c..0ee24446cad8b 100644 --- a/mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.td +++ b/mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.td @@ -23,8 +23,8 @@ include "mlir/Interfaces/SideEffectInterfaces.td" include "mlir/Dialect/LHLO/IR/HLOOpsBase.td" def LHLO_Dialect : Dialect { - let name = "xla_lhlo"; - let cppNamespace = "::mlir::xla_lhlo"; + let name = "lmhlo"; + let cppNamespace = "::mlir::lmhlo"; } //===--===// @@ -481,19 +481,19 @@ def LHLO_IfOp : LHLO_Op<"if", [AffineScope, RecursiveSideEffects]> { ```mlir func @lhlo_if(%arg0: memref<1x1x10xf32>, %arg1: memref<1x1x10xf32>, %arg2: memref) { - %0 = "xla_lhlo.tuple"(%arg0, %arg1) : (memref<1x1x10xf32>, memref<1x1x10xf32>) -> tuple, memref<1x1x10xf32>> - %1 = "xla_lhlo.if"(%arg2, %0, %0) ( { + %0 = "lmhlo.tuple"(%arg0, %arg1) : (memref<1x1x10xf32>, memref<1x1x10xf32>) -> tuple, memref<1x1x10xf32>> + %1 = "lmhlo.if"(%arg2, %0, %0) ( { ^bb0(%arg3: tuple, memref<1x1x10xf32>>): -%2 = "xla_lhlo.get_tuple_element"(%arg3) {index = 0 : i32} : (tuple, memref<1x1x10xf32>>) -> memref<1x1x10xf32> -%3 = "xla_lhlo.tuple"(%2) : (memref<1x1x10xf32>) -> tuple> -"xla_lhlo.yield"(%3) : (tuple>) -> () +%2 = "lmhlo.get_tuple_element"(%arg3) {index = 0 : i32} : (tuple, memref<1x1x10xf32>>) -> memref<1x1x10xf32> +%3 = "lmhlo.tuple"(%2) : (memref<1x1x10xf32>) -> tuple> +"lmhlo.yield"(%3) : (tuple>) -> () }, { ^bb0(%arg3: tuple, memref<1x1x10xf32>>): // no predecessors -%2 = "xla_lhlo.get_tuple_element"(%arg3) {index = 1 : i32} : (tuple, memref<1x1x10xf32>>) -> memref<1x1x10xf32> -%3 = "xla_lhlo.tuple"(%2) : (memref<1x1x10xf32>) -> tuple> -"xla_lhlo.yield"(%3) : (tuple>) -> () +%2 = "lmhlo.get_tuple_element"(%arg3) {index = 1 : i32} : (tuple, memref<1x1x10xf32>>) -> memref<1x1x10xf32> +%3 = "lmhlo.tuple"(%2) : (memref<1x1x10xf32>) -> tuple> +"lmhlo.yield"(%3) : (tuple>) -> () }) : (memref, tuple, memref<1x1x10xf32>>, tuple, memref<1x1x10xf32>>) -> tuple> - "xla_lhlo.terminator"() : () -> () + "lmhlo.terminator"() : () -> () } ``` diff --git a/mlir/include/mlir/InitAllDialects.h b/mlir/include/mlir/InitAllDialects.h index e9869365e54eb..43712b70d5362 100644 --- a/mlir/include/mlir/InitAllDialects.h +++ b/mlir/include/mlir/InitAllDialects.h @@ -80,7 +80,7 @@ inline void registerAllDialects(DialectRegistry ®istry) { tensor::TensorDialect, tosa::TosaDialect, x86vector::X86VectorDialect, - xla_lhlo::LHLODialect>(); + lmhlo::LHLODialect>(); // clang-format on } diff --git a/mlir/lib/Dialect/LHLO/IR/LHLOOps.cc b/mlir/lib/Dialect/LHLO/IR/LHLOOps.cc index 27d259
[llvm-branch-commits] [mlir] c6b7f22 - [MLIR] Add xla_lhlo dialect from tensorflow
Author: Uday Bondhugula Date: 2021-09-22T14:23:46+05:30 New Revision: c6b7f22240229f69af9ebb75d4b7a9b5f1dd0da1 URL: https://github.com/llvm/llvm-project/commit/c6b7f22240229f69af9ebb75d4b7a9b5f1dd0da1 DIFF: https://github.com/llvm/llvm-project/commit/c6b7f22240229f69af9ebb75d4b7a9b5f1dd0da1.diff LOG: [MLIR] Add xla_lhlo dialect from tensorflow Add xla_lhlo dialect from tensorflow (the version used by the right branch of the private repo). This commit brings in just the LHLO ops part of it. So, LHLO transforms or any conversions out of LHLO are not included. This is to mainly to allow the use of xla_lhlo dialect ops along with MLIR. So, the users would be aware of LHLO ops (make use of its accessors) as the xla_lhlo dialect would be registered. This is a temporary arrangement before we can migrate to depending on mlir-hlo. Depending on tensorflow just for xla_lhlo isn't really feasible. Added: mlir/include/mlir/Dialect/LHLO/CMakeLists.txt mlir/include/mlir/Dialect/LHLO/IR/CMakeLists.txt mlir/include/mlir/Dialect/LHLO/IR/HLOOpsBase.td mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.h mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.td mlir/lib/Dialect/LHLO/CMakeLists.txt mlir/lib/Dialect/LHLO/IR/CMakeLists.txt mlir/lib/Dialect/LHLO/IR/LHLOOps.cc mlir/test/Dialect/LHLO/lhlo_ops.mlir Modified: mlir/include/mlir/Dialect/CMakeLists.txt mlir/include/mlir/InitAllDialects.h mlir/lib/Dialect/CMakeLists.txt Removed: diff --git a/mlir/include/mlir/Dialect/CMakeLists.txt b/mlir/include/mlir/Dialect/CMakeLists.txt index 44a9249cef839..60e31ed7cac55 100644 --- a/mlir/include/mlir/Dialect/CMakeLists.txt +++ b/mlir/include/mlir/Dialect/CMakeLists.txt @@ -9,6 +9,7 @@ add_subdirectory(EmitC) add_subdirectory(GPU) add_subdirectory(Math) add_subdirectory(Linalg) +add_subdirectory(LHLO) add_subdirectory(LLVMIR) add_subdirectory(MemRef) add_subdirectory(OpenACC) diff --git a/mlir/include/mlir/Dialect/LHLO/CMakeLists.txt b/mlir/include/mlir/Dialect/LHLO/CMakeLists.txt new file mode 100644 index 0..f33061b2d87cf --- /dev/null +++ b/mlir/include/mlir/Dialect/LHLO/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(IR) diff --git a/mlir/include/mlir/Dialect/LHLO/IR/CMakeLists.txt b/mlir/include/mlir/Dialect/LHLO/IR/CMakeLists.txt new file mode 100644 index 0..f5c4548ccf534 --- /dev/null +++ b/mlir/include/mlir/Dialect/LHLO/IR/CMakeLists.txt @@ -0,0 +1,8 @@ +add_mlir_dialect(LHLOOps xla_lhlo) + +set(LLVM_TARGET_DEFINITIONS LHLOOps.td) +mlir_tablegen(LHLOStructs.h.inc -gen-struct-attr-decls) +mlir_tablegen(LHLOStructs.cpp.inc -gen-struct-attr-defs) +add_public_tablegen_target(MLIRLHLOStructsGen) + +add_mlir_doc(LHLOOps -gen-op-doc LHLOOps Dialects/) diff --git a/mlir/include/mlir/Dialect/LHLO/IR/HLOOpsBase.td b/mlir/include/mlir/Dialect/LHLO/IR/HLOOpsBase.td new file mode 100644 index 0..9312ed9e96f9f --- /dev/null +++ b/mlir/include/mlir/Dialect/LHLO/IR/HLOOpsBase.td @@ -0,0 +1,1260 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==*/ + +#ifndef HLO_OPS_BASE +#define HLO_OPS_BASE + +include "mlir/IR/OpBase.td" + +def HLO_Pred : TypeAlias; + +// TODO(hinsu): Use signed integers instead of signless integer which is being +// used for legacy reasons. +def HLO_SInt : SignlessIntOfWidths<[8, 16, 32, 64]>; +def HLO_UInt : UnsignedIntOfWidths<[8, 16, 32, 64]>; +def HLO_Int : AnyTypeOf<[HLO_SInt, HLO_UInt]>; +def HLO_I1 : SignlessIntOfWidths<[1]>; + +def HLO_Complex : Complex>; + +// The broadcasting dimensions correspond to a tuple that describes how a +// smaller rank shape is broadcast into a larger rank shape. For example, +// given a 2x3x4 cuboid and a 3x4 matrix, a broadcasting tuple (1,2) means +// matching the matrix to dimensions 1 and 2 of the cuboid. +defvar BroadcastDimAttr = I64ElementsAttr; + +//===--===// +// XLA on tensors type definitions. +//===--===// + +// Token type. +def HLO_Token : Type()">, "token">; + +// Any integer tensor types +def HLO_IntTensor : TensorOf<[HLO_Int]>; + +// Any integer tensor type with rank 0 (i.e. representing a single integer). +def HLO_ScalarIntTensor : Shaped
[llvm-branch-commits] [mlir] db04767 - [MLIR] Add the seed attribute for random_uniform ops in lmhlo dialect. (#35)
Author: Prashant Kumar Date: 2021-09-23T06:20:43+05:30 New Revision: db04767afbea48b62a7a25017e42248a5d83480c URL: https://github.com/llvm/llvm-project/commit/db04767afbea48b62a7a25017e42248a5d83480c DIFF: https://github.com/llvm/llvm-project/commit/db04767afbea48b62a7a25017e42248a5d83480c.diff LOG: [MLIR] Add the seed attribute for random_uniform ops in lmhlo dialect. (#35) The `seed` and `seed2` attribute are added to lmhlo dialect in case of random_uniform ops. The changes are made as a part of hlo-legalize-to-lhlo` pass. Added: Modified: mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.td Removed: diff --git a/mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.td b/mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.td index 0ee24446cad8..16fff82d6c7a 100644 --- a/mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.td +++ b/mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.td @@ -568,10 +568,17 @@ def LHLO_ReshapeOp: LHLO_Op<"reshape", []>, BASE_HLO_ReshapeOp { // output memref consistent with HLO op xla_hlo::rng_uniform. //===--===// def LHLO_RngUniformOp : LHLO_Op<"rng_uniform", []>, BASE_HLO_RngUniformOp { + let summary = [{ + The generated values follow a uniform distribution in the range [minval, maxval]. + Operations that rely on a random seed actually derive it from two seeds: + the global and operation-level seeds which are `seed` and `seed2` respectively. + }]; let arguments = (ins AnyTypeOf<[AnyInteger, AnyFloat]>:$a, AnyTypeOf<[AnyInteger, AnyFloat]>:$b, -Arg:$output +Arg:$output, +OptionalAttr:$seed, +OptionalAttr:$seed2 ); } ___ 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] 10cf6d4 - [MLIR] Add RngNormalOp in LHLO dialect (#60)
Author: Abhishek Varma Date: 2021-09-23T06:20:44+05:30 New Revision: 10cf6d43c473449402675de0d06650464f01bc9f URL: https://github.com/llvm/llvm-project/commit/10cf6d43c473449402675de0d06650464f01bc9f DIFF: https://github.com/llvm/llvm-project/commit/10cf6d43c473449402675de0d06650464f01bc9f.diff LOG: [MLIR] Add RngNormalOp in LHLO dialect (#60) -- This commit introduces RngNormalOp as part of LHLO dialect. Signed-off-by: Abhishek Varma Added: Modified: mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.td Removed: diff --git a/mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.td b/mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.td index 16fff82d6c7a..394f6c6679a8 100644 --- a/mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.td +++ b/mlir/include/mlir/Dialect/LHLO/IR/LHLOOps.td @@ -582,6 +582,26 @@ def LHLO_RngUniformOp : LHLO_Op<"rng_uniform", []>, BASE_HLO_RngUniformOp { ); } +//===--===// +// RngNormal operator that takes scalar low and high values and populates the +// output memref consistent with HLO op xla_hlo::rng_normal. +//===--===// +def LHLO_RngNormalOp : LHLO_Op<"rng_normal", []>, BASE_HLO_RngNormalOp { + let summary = [{ + The generated values follow a standard normal distribution in the range + [minval, maxval]. Operations that rely on a random seed actually derive it + from two seeds: the global and operation-level seeds which are `seed` and + `seed2` respectively. + }]; + let arguments = (ins +AnyTypeOf<[AnyInteger, AnyFloat]>:$a, +AnyTypeOf<[AnyInteger, AnyFloat]>:$b, +Arg:$output, +OptionalAttr:$seed, +OptionalAttr:$seed2 + ); +} + def LHLO_SelectOp: LHLO_Op<"select", []>, BASE_HLO_SelectOp { let arguments = (ins Arg:$pred, ___ 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] 81fe64d - [MLIR] Add AffineMap::isPureAffine
Author: Uday Bondhugula Date: 2021-09-23T08:19:19+05:30 New Revision: 81fe64da18fa4d4c9252b2ddd646f6623e1d1704 URL: https://github.com/llvm/llvm-project/commit/81fe64da18fa4d4c9252b2ddd646f6623e1d1704 DIFF: https://github.com/llvm/llvm-project/commit/81fe64da18fa4d4c9252b2ddd646f6623e1d1704.diff LOG: [MLIR] Add AffineMap::isPureAffine Signed-off-by: Uday Bondhugula Added: Modified: mlir/include/mlir/IR/AffineMap.h mlir/lib/IR/AffineMap.cpp Removed: diff --git a/mlir/include/mlir/IR/AffineMap.h b/mlir/include/mlir/IR/AffineMap.h index 906c53db4b32..f1f00acd8022 100644 --- a/mlir/include/mlir/IR/AffineMap.h +++ b/mlir/include/mlir/IR/AffineMap.h @@ -81,6 +81,11 @@ class AffineMap { static AffineMap getPermutationMap(ArrayRef permutation, MLIRContext *context); + /// Returns true if all of this map's result expressions are pure affine, + /// i.e., multiplication, floordiv, ceildiv, and mod is only allowed w.r.t + /// constants. + bool isPureAffine() const; + /// Returns a vector of AffineMaps; each with as many results as /// `exprs.size()`, as many dims as the largest dim in `exprs` and as many /// symbols as the largest symbol in `exprs`. diff --git a/mlir/lib/IR/AffineMap.cpp b/mlir/lib/IR/AffineMap.cpp index 9c6f25d3c53e..0989d821655d 100644 --- a/mlir/lib/IR/AffineMap.cpp +++ b/mlir/lib/IR/AffineMap.cpp @@ -344,6 +344,12 @@ unsigned AffineMap::getPermutedPosition(unsigned input) const { llvm_unreachable("incorrect permutation request"); } +bool AffineMap::isPureAffine() const { + return llvm::all_of(getResults(), [](AffineExpr expr) { +return expr.isPureAffine(); + }); +} + /// Folds the results of the application of an affine map on the provided /// operands to a constant if possible. Returns false if the folding happens, /// true otherwise. ___ 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] eb1aacd - [MLIR-LAIR] Custom printing for multi-dim affine index maps
Author: Uday Bondhugula Date: 2021-09-23T08:19:53+05:30 New Revision: eb1aacd495d84384e2d2e4e40c893aebfbd19837 URL: https://github.com/llvm/llvm-project/commit/eb1aacd495d84384e2d2e4e40c893aebfbd19837 DIFF: https://github.com/llvm/llvm-project/commit/eb1aacd495d84384e2d2e4e40c893aebfbd19837.diff LOG: [MLIR-LAIR] Custom printing for multi-dim affine index maps Custom printing for AffineMaps with named SSA values - to aid printing NGDL accesses. Added: Modified: mlir/include/mlir/IR/AffineMap.h mlir/lib/IR/AsmPrinter.cpp Removed: diff --git a/mlir/include/mlir/IR/AffineMap.h b/mlir/include/mlir/IR/AffineMap.h index f1f00acd8022..4ab75ad3ea64 100644 --- a/mlir/include/mlir/IR/AffineMap.h +++ b/mlir/include/mlir/IR/AffineMap.h @@ -534,6 +534,11 @@ inline raw_ostream &operator<<(raw_ostream &os, AffineMap map) { map.print(os); return os; } + +/// Prints an affine map index in the form [expr_1][expr_2] with the supplied +/// names used for the inputs. +void printAffineMapAccess(AffineMap map, ArrayRef names, + raw_ostream &os); } // end namespace mlir namespace llvm { diff --git a/mlir/lib/IR/AsmPrinter.cpp b/mlir/lib/IR/AsmPrinter.cpp index b6d072f9f60a..9c717eef111c 100644 --- a/mlir/lib/IR/AsmPrinter.cpp +++ b/mlir/lib/IR/AsmPrinter.cpp @@ -2241,6 +2241,18 @@ void ModulePrinter::printAffineConstraint(AffineExpr expr, bool isEq) { isEq ? os << " == 0" : os << " >= 0"; } +void mlir::printAffineMapAccess(AffineMap map, ArrayRef names, +raw_ostream &os) { + assert(map.getNumInputs() == names.size() && "too few/many names"); + ModulePrinter p(os); + auto printValueName = [&](unsigned pos, bool isSymbol) { os << names[pos]; }; + for (auto expr : map.getResults()) { +os << '['; +p.printAffineExpr(expr, printValueName); +os << ']'; + } +} + void ModulePrinter::printAffineMap(AffineMap map) { // Dimension identifiers. os << '('; ___ 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] 5a72ea0 - [MLIR] Add method mlir::isPerfectNestRoot
Author: Uday Bondhugula Date: 2021-09-23T08:20:06+05:30 New Revision: 5a72ea079cde160b044ec7241928bb9520a5ae75 URL: https://github.com/llvm/llvm-project/commit/5a72ea079cde160b044ec7241928bb9520a5ae75 DIFF: https://github.com/llvm/llvm-project/commit/5a72ea079cde160b044ec7241928bb9520a5ae75.diff LOG: [MLIR] Add method mlir::isPerfectNestRoot Add method to check if an affine.for op is the root of a nest that is nested perfectly all the way. Added: Modified: mlir/include/mlir/Transforms/LoopUtils.h mlir/lib/Transforms/Utils/LoopUtils.cpp Removed: diff --git a/mlir/include/mlir/Transforms/LoopUtils.h b/mlir/include/mlir/Transforms/LoopUtils.h index 8c851215e3c08..fe89a86c4d2e8 100644 --- a/mlir/include/mlir/Transforms/LoopUtils.h +++ b/mlir/include/mlir/Transforms/LoopUtils.h @@ -57,6 +57,9 @@ LogicalResult loopUnrollUpToFactor(AffineForOp forOp, uint64_t unrollFactor); /// in it from outermost to innermost. bool LLVM_ATTRIBUTE_UNUSED isPerfectlyNested(ArrayRef loops); +/// Returns true if the nest rooted at `loop` is a perfectly nested loop nest. +bool isPerfectNestRoot(AffineForOp loop); + /// Get perfectly nested sequence of loops starting at root of loop nest /// (the first op being another AffineFor, and the second op - a terminator). /// A loop is perfectly nested iff: the first op in the loop's body is another diff --git a/mlir/lib/Transforms/Utils/LoopUtils.cpp b/mlir/lib/Transforms/Utils/LoopUtils.cpp index 4427001be2204..41a6aa692ee7c 100644 --- a/mlir/lib/Transforms/Utils/LoopUtils.cpp +++ b/mlir/lib/Transforms/Utils/LoopUtils.cpp @@ -1543,6 +1543,24 @@ mlir::isPerfectlyNested(ArrayRef loops) { return true; } +/// Returns true if no other affine for op's are nested within `forOp`. +static bool isInnermostAffineForOp(AffineForOp forOp) { + // Only for the innermost affine.for op's. + bool isInnermost = true; + forOp.walk([&](AffineForOp thisForOp) { +isInnermost = (thisForOp == forOp); +return WalkResult::interrupt(); + }); + return isInnermost; +} + +/// Returns true if the nest rooted at `loop` is a perfectly nested loop nest. +bool mlir::isPerfectNestRoot(AffineForOp loop) { + SmallVector nest; + getPerfectlyNestedLoops(nest, loop); + return isInnermostAffineForOp(nest.back()); +} + // input[i] should move from position i -> permMap[i]. Returns the position in // `input` that becomes the new outermost loop. unsigned mlir::permuteLoops(MutableArrayRef input, ___ 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] 64e8f9d - [MLIR] Add affine-cs-pipeline.
Author: Prateek Gupta Date: 2021-09-24T20:50:55+05:30 New Revision: 64e8f9dd5cacb266ae38f788feb1c1acfb3475d3 URL: https://github.com/llvm/llvm-project/commit/64e8f9dd5cacb266ae38f788feb1c1acfb3475d3 DIFF: https://github.com/llvm/llvm-project/commit/64e8f9dd5cacb266ae38f788feb1c1acfb3475d3.diff LOG: [MLIR] Add affine-cs-pipeline. This commit introduces affine-cs-pipeline. The pipeline performs maximal affine loop fusion and memref data flow optimization with canonicalization between every pass. Relevant test case is also added. Signed-off-by: Prateek Gupta Changes while porting to upstream: 1. MemRefDataFlowOptPass is now called AffineScalarReplacementPass. 2. Registering the AffineCSPipeline at one place for `mlir-opt`. 3. Unused store elimination is added upstream, and therefore, test case that involves an unused store is eliminated. Added: mlir/lib/Transforms/AffineCSPipeline.cpp mlir/test/Transforms/affine-cs-pipeline.mlir Modified: mlir/include/mlir/InitAllPasses.h mlir/lib/Transforms/CMakeLists.txt Removed: diff --git a/mlir/include/mlir/InitAllPasses.h b/mlir/include/mlir/InitAllPasses.h index 59b35b7096f5a..47ef5f0e7d771 100644 --- a/mlir/include/mlir/InitAllPasses.h +++ b/mlir/include/mlir/InitAllPasses.h @@ -34,6 +34,8 @@ #include namespace mlir { +// Cerebras specific pipeline. +void registerAffineCSPipeline(); // This function may be called to register the MLIR passes with the // global registry. @@ -66,6 +68,9 @@ inline void registerAllPasses() { registerStandardPasses(); tensor::registerTensorPasses(); tosa::registerTosaOptPasses(); + + // Cerebras specific pipeline. + registerAffineCSPipeline(); } } // namespace mlir diff --git a/mlir/lib/Transforms/AffineCSPipeline.cpp b/mlir/lib/Transforms/AffineCSPipeline.cpp new file mode 100644 index 0..c6994188b0fd0 --- /dev/null +++ b/mlir/lib/Transforms/AffineCSPipeline.cpp @@ -0,0 +1,36 @@ +//===-AffineCSPipeline.cpp-===// +// +// 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 implements a pipeline for performing affine loop fusion and other +// complimentary optimizations. +// +//===--===// + +#include "mlir/Dialect/Affine/Passes.h" +#include "mlir/Pass/Pass.h" +#include "mlir/Pass/PassManager.h" +#include "mlir/Transforms/Passes.h" + +namespace mlir { +void createAffineCSPipeline(OpPassManager &pm) { + pm.addPass(mlir::createCanonicalizerPass()); + pm.addPass(mlir::createLoopFusionPass(/*fastMemorySpace=*/0, +/*localBufSizeThreshold=*/0, +/*maximalFusion=*/true)); + pm.addPass(mlir::createCanonicalizerPass()); + pm.addPass(mlir::createAffineScalarReplacementPass()); + pm.addPass(mlir::createCanonicalizerPass()); +} +void registerAffineCSPipeline() { + mlir::PassPipelineRegistration<>( + "affine-cs-pipeline", + "runs all passes for performing affine loop fusion and other " + "complimentary optimizations.", + createAffineCSPipeline); +} +} // end namespace mlir diff --git a/mlir/lib/Transforms/CMakeLists.txt b/mlir/lib/Transforms/CMakeLists.txt index 54f3693c89c69..72065445ece92 100644 --- a/mlir/lib/Transforms/CMakeLists.txt +++ b/mlir/lib/Transforms/CMakeLists.txt @@ -1,6 +1,7 @@ add_subdirectory(Utils) add_mlir_library(MLIRTransforms + AffineCSPipeline.cpp BufferDeallocation.cpp BufferOptimizations.cpp BufferResultsToOutParams.cpp diff --git a/mlir/test/Transforms/affine-cs-pipeline.mlir b/mlir/test/Transforms/affine-cs-pipeline.mlir new file mode 100644 index 0..70ed6a30473a3 --- /dev/null +++ b/mlir/test/Transforms/affine-cs-pipeline.mlir @@ -0,0 +1,71 @@ +// RUN: mlir-opt %s -affine-cs-pipeline | FileCheck %s + +// This test case checks for the maximal loop fusion. +func @simple_matmul_one(%arg0: memref<16x16xf32>, %arg1: memref<16x16xf32>, %arg2: memref<16x16xf32>) { +%cst = constant 0.00e+00 : f32 +affine.for %arg3 = 0 to 16 { +affine.for %arg4 = 0 to 16 { +affine.store %cst, %arg2[%arg3, %arg4] : memref<16x16xf32> +} +} +affine.for %arg3 = 0 to 16 { +affine.for %arg4 = 0 to 16 { +affine.for %arg5 = 0 to 16 { +%0 = affine.load %arg0[%arg3, %arg5] : memref<16x16xf32> +%1 = affine.load %arg1[%arg5, %arg4] : memref<16x16xf32> +%2 = affine.load %arg2[%arg3, %arg4] : memref<16x16xf32> +%3 = mulf %0, %1 : f32 +%4 = addf %3, %2 : f32 +
[llvm-branch-commits] [mlir] 93821ea - [MLIR] Expose affine-cs-pipeline
Author: Uday Bondhugula Date: 2021-09-27T22:33:33+05:30 New Revision: 93821eabadcad11594b6cb46cacd5681981dd119 URL: https://github.com/llvm/llvm-project/commit/93821eabadcad11594b6cb46cacd5681981dd119 DIFF: https://github.com/llvm/llvm-project/commit/93821eabadcad11594b6cb46cacd5681981dd119.diff LOG: [MLIR] Expose affine-cs-pipeline Added: Modified: mlir/include/mlir/Transforms/Passes.h Removed: diff --git a/mlir/include/mlir/Transforms/Passes.h b/mlir/include/mlir/Transforms/Passes.h index eef88b5d7a48..4296fcdc590c 100644 --- a/mlir/include/mlir/Transforms/Passes.h +++ b/mlir/include/mlir/Transforms/Passes.h @@ -24,6 +24,7 @@ namespace mlir { class AffineForOp; class GreedyRewriteConfig; +class OpPassManager; //===--===// // Passes @@ -140,6 +141,10 @@ std::unique_ptr> createNormalizeMemRefsPass(); #define GEN_PASS_REGISTRATION #include "mlir/Transforms/Passes.h.inc" +/// Creates an affine optimization pipeline including fusion and other +/// complementary passes. +void createAffineCSPipeline(OpPassManager &pm); + } // end namespace mlir #endif // MLIR_TRANSFORMS_PASSES_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] 4f5c304 - [MLIR] Add to enforce perfect nests while loop fusion
Author: Prateek Gupta Date: 2021-09-27T22:46:32+05:30 New Revision: 4f5c3045514341cd5e98bc7b84dd05d49ef37cb7 URL: https://github.com/llvm/llvm-project/commit/4f5c3045514341cd5e98bc7b84dd05d49ef37cb7 DIFF: https://github.com/llvm/llvm-project/commit/4f5c3045514341cd5e98bc7b84dd05d49ef37cb7.diff LOG: [MLIR] Add to enforce perfect nests while loop fusion This commit adds an option to the affine-cs pipeline to enforce perfect nests while loop fusion. Relevant test cases are also added. Signed-Off-By: Prateek Gupta Changes while porting to upstream by Vinayaka Bandishti: 1. Remove test case of reduction fusion into pointwise, since this was being prevented due to an incorrect reason. Added: mlir/test/Transforms/affine-cs-pipeline-perfect-nest.mlir Modified: mlir/include/mlir/Transforms/Passes.h mlir/include/mlir/Transforms/Passes.td mlir/lib/Transforms/AffineCSPipeline.cpp mlir/lib/Transforms/LoopFusion.cpp Removed: diff --git a/mlir/include/mlir/Transforms/Passes.h b/mlir/include/mlir/Transforms/Passes.h index 4296fcdc590c..3d402eb4f61c 100644 --- a/mlir/include/mlir/Transforms/Passes.h +++ b/mlir/include/mlir/Transforms/Passes.h @@ -26,6 +26,9 @@ class AffineForOp; class GreedyRewriteConfig; class OpPassManager; +// Cerebras specific options. +struct AffineCSPipelineOptions; + //===--===// // Passes //===--===// @@ -75,11 +78,11 @@ std::unique_ptr createCSEPass(); /// Creates a loop fusion pass which fuses loops. Buffers of size less than or /// equal to `localBufSizeThreshold` are promoted to memory space -/// `fastMemorySpace'. -std::unique_ptr> -createLoopFusionPass(unsigned fastMemorySpace = 0, - uint64_t localBufSizeThreshold = 0, - bool maximalFusion = false); +/// `fastMemorySpace'. If `enforcePerfectNest` is true, perfect nesting is +/// enforced while fusing. +std::unique_ptr> createLoopFusionPass( +unsigned fastMemorySpace = 0, uint64_t localBufSizeThreshold = 0, +bool maximalFusion = false, bool enforcePerfectNest = false); /// Creates a loop invariant code motion pass that hoists loop invariant /// instructions out of the loop. @@ -143,7 +146,8 @@ std::unique_ptr> createNormalizeMemRefsPass(); /// Creates an affine optimization pipeline including fusion and other /// complementary passes. -void createAffineCSPipeline(OpPassManager &pm); +void createAffineCSPipeline(OpPassManager &pm, +const AffineCSPipelineOptions &options); } // end namespace mlir diff --git a/mlir/include/mlir/Transforms/Passes.td b/mlir/include/mlir/Transforms/Passes.td index 91af2a2c56a9..479b811cbfc0 100644 --- a/mlir/include/mlir/Transforms/Passes.td +++ b/mlir/include/mlir/Transforms/Passes.td @@ -136,6 +136,8 @@ def AffineLoopFusion : FunctionPass<"affine-loop-fusion"> { "to fast memory space">, Option<"maximalFusion", "fusion-maximal", "bool", /*default=*/"false", "Enables maximal loop fusion">, +Option<"enforcePerfectNest", "enforce-perfect-nest", "bool", /*default=*/"false", + "Enforces perfect nesting while performing loop fusion."> ]; let dependentDialects = ["memref::MemRefDialect"]; } diff --git a/mlir/lib/Transforms/AffineCSPipeline.cpp b/mlir/lib/Transforms/AffineCSPipeline.cpp index c6994188b0fd..340e4ad50c5b 100644 --- a/mlir/lib/Transforms/AffineCSPipeline.cpp +++ b/mlir/lib/Transforms/AffineCSPipeline.cpp @@ -17,19 +17,32 @@ #include "mlir/Transforms/Passes.h" namespace mlir { -void createAffineCSPipeline(OpPassManager &pm) { +struct AffineCSPipelineOptions +: public PassPipelineOptions { + Option enforce_perfect_nest{ + *this, "enforce-perfect-nest", + llvm::cl::desc("Enables enforcement of perfect nesting while performing " + "loop fusion."), + llvm::cl::init(false)}; +}; + +void createAffineCSPipeline(OpPassManager &pm, +const AffineCSPipelineOptions &options) { pm.addPass(mlir::createCanonicalizerPass()); - pm.addPass(mlir::createLoopFusionPass(/*fastMemorySpace=*/0, -/*localBufSizeThreshold=*/0, -/*maximalFusion=*/true)); + pm.addPass(mlir::createLoopFusionPass( + /*fastMemorySpace=*/0, + /*localBufSizeThreshold=*/0, + /*maximalFusion=*/true, + /*enforcePerfectNest=*/options.enforce_perfect_nest)); pm.addPass(mlir::createCanonicalizerPass()); pm.addPass(mlir::createAffineScalarReplacementPass()); pm.addPass(mlir::createCanonicalizerPass()); } + void registerAffineCSPipeline() { - mlir::PassPipelineRegistration<>( + mlir::PassPipelineRegistration( "affine-cs-pipeline", - "runs a
[llvm-branch-commits] [libcxx] 6cf25de - [libc++] counting_semaphore should not be default-constructible.
Author: Arthur O'Dwyer Date: 2021-11-05T09:57:08-04:00 New Revision: 6cf25deec7d0b74a073b74048ae8f7f0c69fbfee URL: https://github.com/llvm/llvm-project/commit/6cf25deec7d0b74a073b74048ae8f7f0c69fbfee DIFF: https://github.com/llvm/llvm-project/commit/6cf25deec7d0b74a073b74048ae8f7f0c69fbfee.diff LOG: [libc++] counting_semaphore should not be default-constructible. Neither the current C++2b draft, nor any revision of [p1135], nor libstdc++, claims that `counting_semaphore` should be default-constructible. I think this was just a copy-paste issue somehow. Also, `explicit` was missing from the constructor. Also, `constexpr` remains missing; but that's probably more of a technical limitation, since apparently there are some platforms where we don't (can't??) use the atomic implementation and have to rely on pthreads, which obviously isn't constexpr. Differential Revision: https://reviews.llvm.org/D110042 (cherry picked from commit c9af0e61fa85842ce280ddab8ab491de38a7ae5b) Added: libcxx/test/std/thread/thread.semaphore/ctor.compile.pass.cpp Modified: libcxx/include/semaphore libcxx/test/std/thread/thread.semaphore/binary.pass.cpp libcxx/test/std/thread/thread.semaphore/max.pass.cpp Removed: diff --git a/libcxx/include/semaphore b/libcxx/include/semaphore index 906f62e0f07aa..4f9ecd0461b26 100644 --- a/libcxx/include/semaphore +++ b/libcxx/include/semaphore @@ -82,7 +82,7 @@ class __atomic_semaphore_base public: _LIBCPP_INLINE_VISIBILITY -__atomic_semaphore_base(ptr diff _t __count) : __a(__count) +constexpr explicit __atomic_semaphore_base(ptr diff _t __count) : __a(__count) { } _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY @@ -136,7 +136,7 @@ class __platform_semaphore_base public: _LIBCPP_INLINE_VISIBILITY -__platform_semaphore_base(ptr diff _t __count) : +explicit __platform_semaphore_base(ptr diff _t __count) : __semaphore() { __libcpp_semaphore_init(&__semaphore, __count); @@ -190,7 +190,7 @@ public: } _LIBCPP_INLINE_VISIBILITY -counting_semaphore(ptr diff _t __count = 0) : __semaphore(__count) { } +constexpr explicit counting_semaphore(ptr diff _t __count) : __semaphore(__count) { } ~counting_semaphore() = default; counting_semaphore(const counting_semaphore&) = delete; diff --git a/libcxx/test/std/thread/thread.semaphore/binary.pass.cpp b/libcxx/test/std/thread/thread.semaphore/binary.pass.cpp index b80c9fea0295c..20e4efa70ee8d 100644 --- a/libcxx/test/std/thread/thread.semaphore/binary.pass.cpp +++ b/libcxx/test/std/thread/thread.semaphore/binary.pass.cpp @@ -18,10 +18,13 @@ #include #include #include +#include #include "make_test_thread.h" #include "test_macros.h" +static_assert(std::is_same>::value, ""); + int main(int, char**) { std::binary_semaphore s(1); diff --git a/libcxx/test/std/thread/thread.semaphore/ctor.compile.pass.cpp b/libcxx/test/std/thread/thread.semaphore/ctor.compile.pass.cpp new file mode 100644 index 0..785a57e29d492 --- /dev/null +++ b/libcxx/test/std/thread/thread.semaphore/ctor.compile.pass.cpp @@ -0,0 +1,30 @@ +//===--===// +// +// 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 +// +//===--===// +// +// UNSUPPORTED: libcpp-has-no-threads +// UNSUPPORTED: c++03, c++11 + +// + +// constexpr explicit counting_semaphore(ptr diff _t desired); + +#include +#include + +#include "test_macros.h" + +static_assert(!std::is_default_constructible::value, ""); +static_assert(!std::is_default_constructible>::value, ""); + +static_assert(!std::is_convertible::value, ""); +static_assert(!std::is_convertible>::value, ""); + +#if 0 // TODO FIXME: the ctor should be constexpr when TEST_STD_VER > 17 +constinit std::binary_semaphore bs(1); +constinit std::counting_semaphore cs(1); +#endif diff --git a/libcxx/test/std/thread/thread.semaphore/max.pass.cpp b/libcxx/test/std/thread/thread.semaphore/max.pass.cpp index 8007bc1383750..8f48640a19459 100644 --- a/libcxx/test/std/thread/thread.semaphore/max.pass.cpp +++ b/libcxx/test/std/thread/thread.semaphore/max.pass.cpp @@ -18,10 +18,9 @@ int main(int, char**) { - static_assert(std::counting_semaphore<>::max() > 0, ""); + static_assert(std::counting_semaphore<>::max() >= 1, ""); static_assert(std::counting_semaphore<1>::max() >= 1, ""); - static_assert(std::counting_semaphore::max()>::max() >= 1, ""); - static_assert(std::counting_semaphore::max()>::max() >= 1, ""); - static_assert(std::counting_semaphore<1>::max() == std::binary_semaphore::max(), ""); + static_assert(std::counting_semap
[llvm-branch-commits] [libcxx] 00f64cc - [libc++] Remove non-atomic "platform" semaphore implementations.
Author: Arthur O'Dwyer Date: 2021-11-05T09:58:10-04:00 New Revision: 00f64ccb49d9049603c0581d1ab23cee52ad8e56 URL: https://github.com/llvm/llvm-project/commit/00f64ccb49d9049603c0581d1ab23cee52ad8e56 DIFF: https://github.com/llvm/llvm-project/commit/00f64ccb49d9049603c0581d1ab23cee52ad8e56.diff LOG: [libc++] Remove non-atomic "platform" semaphore implementations. These can't be made constexpr-constructible (constinit'able), so they aren't C++20-conforming. Also, the platform versions are going to be bigger than the atomic/futex version, so we'd have the awkward situation that `semaphore<42>` could be bigger than `semaphore<43>`, and that's just silly. Differential Revision: https://reviews.llvm.org/D110110 (cherry picked from commit d0eaf75320ea72c4da55060b6c42aad923870814) CHERRY-PICK NOTE BY @ldionne: I added a release note mentioning the ABI break. Added: Modified: libcxx/docs/ReleaseNotes.rst libcxx/include/__threading_support libcxx/include/semaphore libcxx/src/support/win32/thread_win32.cpp libcxx/test/std/thread/thread.semaphore/acquire.pass.cpp libcxx/test/std/thread/thread.semaphore/ctor.compile.pass.cpp libcxx/test/std/thread/thread.semaphore/release.pass.cpp Removed: diff --git a/libcxx/docs/ReleaseNotes.rst b/libcxx/docs/ReleaseNotes.rst index 79ffa42a5d28f..6763ddb364a80 100644 --- a/libcxx/docs/ReleaseNotes.rst +++ b/libcxx/docs/ReleaseNotes.rst @@ -61,8 +61,8 @@ New Features - The documentation conversion from html to restructured text has been completed. -API Changes +API and ABI Changes +--- - There has been several changes in the tuple constructors provided by libc++. Those changes were made as part of an effort to regularize libc++'s tuple @@ -95,3 +95,10 @@ API Changes - The ``std::result_of`` and ``std::is_literal_type`` type traits have been removed in C++20 mode. + +- The C++20 type ``std::counted_semaphore`` is now based on ``std::atomic`` + on all platforms, and does not use "native" semaphores such as pthreads + ``sem_t`` even on platforms that would support them. This changes the layout + of ``counted_semaphore`` notably on Linux, so it is an ABI break on that + platform. This change is needed to conform to the Standard, which requires + ``counted_semaphore``'s constructor to be constexpr. diff --git a/libcxx/include/__threading_support b/libcxx/include/__threading_support index 4d867167c2b16..2242a69085298 100644 --- a/libcxx/include/__threading_support +++ b/libcxx/include/__threading_support @@ -29,16 +29,9 @@ # include <__external_threading> #elif !defined(_LIBCPP_HAS_NO_THREADS) -#if defined(__APPLE__) || defined(__MVS__) -# define _LIBCPP_NO_NATIVE_SEMAPHORES -#endif - #if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) # include # include -# ifndef _LIBCPP_NO_NATIVE_SEMAPHORES -# include -# endif #elif defined(_LIBCPP_HAS_THREAD_API_C11) # include #endif @@ -78,12 +71,6 @@ typedef pthread_mutex_t __libcpp_recursive_mutex_t; typedef pthread_cond_t __libcpp_condvar_t; #define _LIBCPP_CONDVAR_INITIALIZER PTHREAD_COND_INITIALIZER -#ifndef _LIBCPP_NO_NATIVE_SEMAPHORES -// Semaphore -typedef sem_t __libcpp_semaphore_t; -# define _LIBCPP_SEMAPHORE_MAX SEM_VALUE_MAX -#endif - // Execute once typedef pthread_once_t __libcpp_exec_once_flag; #define _LIBCPP_EXEC_ONCE_INITIALIZER PTHREAD_ONCE_INIT @@ -149,12 +136,6 @@ typedef void* __libcpp_recursive_mutex_t[5]; typedef void* __libcpp_condvar_t; #define _LIBCPP_CONDVAR_INITIALIZER 0 -// Semaphore -typedef void* __libcpp_semaphore_t; -#if defined(_LIBCPP_HAS_THREAD_API_WIN32) -# define _LIBCPP_SEMAPHORE_MAX (::std::numeric_limits::max()) -#endif - // Execute Once typedef void* __libcpp_exec_once_flag; #define _LIBCPP_EXEC_ONCE_INITIALIZER 0 @@ -219,26 +200,6 @@ int __libcpp_condvar_timedwait(__libcpp_condvar_t *__cv, __libcpp_mutex_t *__m, _LIBCPP_THREAD_ABI_VISIBILITY int __libcpp_condvar_destroy(__libcpp_condvar_t* __cv); -#ifndef _LIBCPP_NO_NATIVE_SEMAPHORES - -// Semaphore -_LIBCPP_THREAD_ABI_VISIBILITY -bool __libcpp_semaphore_init(__libcpp_semaphore_t* __sem, int __init); - -_LIBCPP_THREAD_ABI_VISIBILITY -bool __libcpp_semaphore_destroy(__libcpp_semaphore_t* __sem); - -_LIBCPP_THREAD_ABI_VISIBILITY -bool __libcpp_semaphore_post(__libcpp_semaphore_t* __sem); - -_LIBCPP_THREAD_ABI_VISIBILITY -bool __libcpp_semaphore_wait(__libcpp_semaphore_t* __sem); - -_LIBCPP_THREAD_ABI_VISIBILITY -bool __libcpp_semaphore_wait_timed(__libcpp_semaphore_t* __sem, chrono::nanoseconds const& __ns); - -#endif // _LIBCPP_NO_NATIVE_SEMAPHORES - // Execute once _LIBCPP_THREAD_ABI_VISIBILITY int __libcpp_execute_once(__libcpp_exec_once_flag *flag, @@ -452,38 +413,6 @@ int __libcpp_condvar_destroy(__libcpp_condvar_t *__cv) return pthread_cond_destroy(__cv); } -#ifndef _LIBCPP_NO_NATIVE_SEMAPHORES - -// Semaphore -bool __libcpp_sem
[llvm-branch-commits] [libcxx] 216200a - [libc++] Fix hang in counting_semaphore::try_acquire
Author: Arthur O'Dwyer Date: 2021-11-05T15:59:12-04:00 New Revision: 216200aff2681407b5e799738b09a047771d86ec URL: https://github.com/llvm/llvm-project/commit/216200aff2681407b5e799738b09a047771d86ec DIFF: https://github.com/llvm/llvm-project/commit/216200aff2681407b5e799738b09a047771d86ec.diff LOG: [libc++] Fix hang in counting_semaphore::try_acquire Before this patch, `try_acquire` blocks instead of returning false. This is because `__libcpp_thread_poll_with_backoff` interprets zero as meaning infinite, causing `try_acquire` to wait indefinitely. Thanks to Pablo Busse (pabusse) for the patch! Differential Revision: https://reviews.llvm.org/D98334 (cherry picked from commit c92a253cf0ddcf905707b4e9265b42570ce409d9) Added: Modified: libcxx/include/semaphore libcxx/test/std/thread/thread.semaphore/try_acquire.pass.cpp Removed: diff --git a/libcxx/include/semaphore b/libcxx/include/semaphore index 1128b36d9527..db03fb967ed1 100644 --- a/libcxx/include/semaphore +++ b/libcxx/include/semaphore @@ -105,17 +105,22 @@ public: _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY bool try_acquire_for(chrono::duration const& __rel_time) { -auto const __test_fn = [this]() -> bool { -auto __old = __a.load(memory_order_acquire); -while(1) { -if (__old == 0) -return false; -if(__a.compare_exchange_strong(__old, __old - 1, memory_order_acquire, memory_order_relaxed)) -return true; -} -}; +if (__rel_time == chrono::duration::zero()) +return try_acquire(); +auto const __test_fn = [this]() { return try_acquire(); }; return __libcpp_thread_poll_with_backoff(__test_fn, __libcpp_timed_backoff_policy(), __rel_time); } +_LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY +bool try_acquire() +{ +auto __old = __a.load(memory_order_acquire); +while (true) { +if (__old == 0) +return false; +if (__a.compare_exchange_strong(__old, __old - 1, memory_order_acquire, memory_order_relaxed)) +return true; +} +} }; #define _LIBCPP_SEMAPHORE_MAX (numeric_limits::max()) @@ -156,14 +161,14 @@ public: _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY bool try_acquire() { -return try_acquire_for(chrono::nanoseconds::zero()); +return __semaphore.try_acquire(); } template _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY bool try_acquire_until(chrono::time_point const& __abs_time) { auto const current = Clock::now(); -if(current >= __abs_time) +if (current >= __abs_time) return try_acquire(); else return try_acquire_for(__abs_time - current); diff --git a/libcxx/test/std/thread/thread.semaphore/try_acquire.pass.cpp b/libcxx/test/std/thread/thread.semaphore/try_acquire.pass.cpp index 35cb6ce7dc82..5a5ab72d05df 100644 --- a/libcxx/test/std/thread/thread.semaphore/try_acquire.pass.cpp +++ b/libcxx/test/std/thread/thread.semaphore/try_acquire.pass.cpp @@ -27,14 +27,17 @@ int main(int, char**) std::counting_semaphore<> s(1); assert(s.try_acquire()); + assert(!s.try_acquire()); s.release(); assert(s.try_acquire()); + assert(!s.try_acquire()); s.release(2); std::thread t = support::make_test_thread([&](){ assert(s.try_acquire()); }); t.join(); assert(s.try_acquire()); + assert(!s.try_acquire()); return 0; } ___ 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] [lldb] e5b3dd5 - [lldb] Don't set the OS for ARMGetSupportedArchitectureAtIndex
Author: Jonas Devlieghere Date: 2021-11-05T22:07:54-07:00 New Revision: e5b3dd5e223ef4d99f905ee4ebbf982c266218bd URL: https://github.com/llvm/llvm-project/commit/e5b3dd5e223ef4d99f905ee4ebbf982c266218bd DIFF: https://github.com/llvm/llvm-project/commit/e5b3dd5e223ef4d99f905ee4ebbf982c266218bd.diff LOG: [lldb] Don't set the OS for ARMGetSupportedArchitectureAtIndex Don't set the OS when computing supported architectures in PlatformDarwin::ARMGetSupportedArchitectureAtIndex. Differential revision: https://reviews.llvm.org/D113159 Added: Modified: lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp Removed: diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp index 2a1f35c5507d..bbf6be646823 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp @@ -559,6 +559,15 @@ static llvm::ArrayRef GetCompatibleArchs(ArchSpec::Core core) { switch (core) { default: LLVM_FALLTHROUGH; + case ArchSpec::eCore_arm_arm64e: { +static const char *g_arm64e_compatible_archs[] = { +"arm64e","arm64","armv7","armv7f", "armv7k", "armv7s", +"armv7m","armv7em", "armv6m", "armv6","armv5","armv4", +"arm", "thumbv7", "thumbv7f", "thumbv7k", "thumbv7s", "thumbv7m", +"thumbv7em", "thumbv6m", "thumbv6", "thumbv5", "thumbv4t", "thumb", +}; +return {g_arm64e_compatible_archs}; + } case ArchSpec::eCore_arm_arm64: { static const char *g_arm64_compatible_archs[] = { "arm64","armv7","armv7f", "armv7k", "armv7s", "armv7m", @@ -654,38 +663,15 @@ const char *PlatformDarwin::GetCompatibleArch(ArchSpec::Core core, size_t idx) { /// processor. bool PlatformDarwin::ARMGetSupportedArchitectureAtIndex(uint32_t idx, ArchSpec &arch) { -#if TARGET_OS_OSX - if (IsHost()) { -if (idx == 0) { - arch.SetTriple("arm64e-apple-macosx"); - return true; -} else if (idx == 1) { - arch.SetTriple("arm64-apple-macosx"); - return true; -} -arch.Clear(); -return false; - } -#endif - -#if defined(TARGET_OS_TV) && TARGET_OS_TV == 1 -#define OSNAME "tvos" -#elif defined(TARGET_OS_WATCH) && TARGET_OS_WATCH == 1 -#define OSNAME "watchos" -#elif defined(TARGET_OS_BRIDGE) && TARGET_OS_BRIDGE == 1 -#define OSNAME "bridgeos" -#elif defined(TARGET_OS_OSX) && TARGET_OS_OSX == 1 -#define OSNAME "macosx" -#else -#define OSNAME "ios" -#endif - const ArchSpec system_arch = GetSystemArchitecture(); const ArchSpec::Core system_core = system_arch.GetCore(); + if (const char *compatible_arch = GetCompatibleArch(system_core, idx)) { -std::string triple = -llvm::formatv("{0}-apple-" OSNAME, compatible_arch).str(); +llvm::Triple triple; +triple.setArchName(compatible_arch); +triple.setVendor(llvm::Triple::VendorType::Apple); arch.SetTriple(triple); +return true; } arch.Clear(); ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits