From 57a984753d05fc9bccbc3788df970b8ca66a5d45 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Fri, 15 Jan 2021 13:59:36 +0300 Subject: [PATCH 01/19] [Support] Format provider improvements * Remove `std::forward` call for `iterator_range` iterator de-reference. * Use exact type `T` in `has_StreamOperator` instead of constant reference. It fixes formatting usage for some tricky cases, like special ranges, which de-reference to value type. It fixes formatting usage with `mlir::Operation` type, which is always passed by non-const reference. Differential Revision: https://reviews.llvm.org/D94769 --- llvm/include/llvm/Support/FormatProviders.h | 7 +-- .../llvm/Support/FormatVariadicDetails.h | 5 +- llvm/unittests/Support/FormatVariadicTest.cpp | 46 +++++++++++++++++++ 3 files changed, 50 insertions(+), 8 deletions(-) diff --git a/llvm/include/llvm/Support/FormatProviders.h b/llvm/include/llvm/Support/FormatProviders.h index 3edd8844bc7a..8cc184d74a20 100644 --- a/llvm/include/llvm/Support/FormatProviders.h +++ b/llvm/include/llvm/Support/FormatProviders.h @@ -355,7 +355,6 @@ struct range_item_has_provider template class format_provider> { using value = typename std::iterator_traits::value_type; - using reference = typename std::iterator_traits::reference; static StringRef consumeOneOption(StringRef &Style, char Indicator, StringRef Default) { @@ -403,15 +402,13 @@ template class format_provider> { auto Begin = V.begin(); auto End = V.end(); if (Begin != End) { - auto Adapter = - detail::build_format_adapter(std::forward(*Begin)); + auto Adapter = detail::build_format_adapter(*Begin); Adapter.format(Stream, ArgStyle); ++Begin; } while (Begin != End) { Stream << Sep; - auto Adapter = - detail::build_format_adapter(std::forward(*Begin)); + auto Adapter = detail::build_format_adapter(*Begin); Adapter.format(Stream, ArgStyle); ++Begin; } diff --git a/llvm/include/llvm/Support/FormatVariadicDetails.h b/llvm/include/llvm/Support/FormatVariadicDetails.h index 2204cff13a64..c17d0fe2f204 100644 --- a/llvm/include/llvm/Support/FormatVariadicDetails.h +++ b/llvm/include/llvm/Support/FormatVariadicDetails.h @@ -76,8 +76,6 @@ template class has_FormatProvider { // Test if raw_ostream& << T -> raw_ostream& is findable via ADL. template class has_StreamOperator { public: - using ConstRefT = const std::decay_t &; - template static char test( std::enable_if_t() @@ -87,7 +85,8 @@ template class has_StreamOperator { template static double test(...); - static bool const value = (sizeof(test(nullptr)) == 1); + // NOLINTNEXTLINE(readability-identifier-naming) + static bool const value = (sizeof(test(nullptr)) == 1); }; // Simple template that decides whether a type T should use the member-function diff --git a/llvm/unittests/Support/FormatVariadicTest.cpp b/llvm/unittests/Support/FormatVariadicTest.cpp index 37946165e365..6cc5793ef7bc 100644 --- a/llvm/unittests/Support/FormatVariadicTest.cpp +++ b/llvm/unittests/Support/FormatVariadicTest.cpp @@ -698,3 +698,49 @@ TEST(FormatVariadicTest, FormatError) { EXPECT_EQ("X", formatv("{0}", fmt_consume(std::move(E1))).str()); EXPECT_FALSE(E1.isA()); // consumed } + +TEST(FormatVariadicTest, FormatFilterRange) { + std::vector Vec{0, 1, 2}; + auto Range = map_range(Vec, [](int V) { return V + 1; }); + EXPECT_EQ("1, 2, 3", formatv("{0}", Range).str()); +} + +namespace { + +class IntegerValuesRange final + : public indexed_accessor_range { +public: + using indexed_accessor_range::indexed_accessor_range; + + static int dereference(const NoneType &, ptrdiff_t Index) { + return static_cast(Index); + } +}; + +TEST(FormatVariadicTest, FormatRangeNonRef) { + IntegerValuesRange Range(None, 0, 3); + EXPECT_EQ("0, 1, 2", + formatv("{0}", make_range(Range.begin(), Range.end())).str()); +} + +class PassByRef { +public: + int Val = 0; + PassByRef(int Val) : Val(Val) {} +}; + +raw_ostream &operator<<(raw_ostream &OS, PassByRef &Obj) { + return OS << Obj.Val; +} + +static_assert(detail::has_StreamOperator::value, ""); +static_assert(detail::uses_stream_operator::value, ""); + +TEST(FormatVariadicTest, StreamOperatorPassByRef) { + PassByRef Obj(10); + EXPECT_EQ("10", formatv("{0}", Obj).str()); +} + +} // namespace From 986c67fe9b94bb59598544b5e6e654658b07e78b Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Wed, 13 Oct 2021 18:00:44 +0300 Subject: [PATCH 02/19] Reset state to upstream main branch --- llvm/include/llvm/Support/FormatProviders.h | 7 ++- .../llvm/Support/FormatVariadicDetails.h | 5 +- llvm/unittests/Support/FormatVariadicTest.cpp | 46 ------------------- 3 files changed, 8 insertions(+), 50 deletions(-) diff --git a/llvm/include/llvm/Support/FormatProviders.h b/llvm/include/llvm/Support/FormatProviders.h index 8cc184d74a20..3edd8844bc7a 100644 --- a/llvm/include/llvm/Support/FormatProviders.h +++ b/llvm/include/llvm/Support/FormatProviders.h @@ -355,6 +355,7 @@ struct range_item_has_provider template class format_provider> { using value = typename std::iterator_traits::value_type; + using reference = typename std::iterator_traits::reference; static StringRef consumeOneOption(StringRef &Style, char Indicator, StringRef Default) { @@ -402,13 +403,15 @@ template class format_provider> { auto Begin = V.begin(); auto End = V.end(); if (Begin != End) { - auto Adapter = detail::build_format_adapter(*Begin); + auto Adapter = + detail::build_format_adapter(std::forward(*Begin)); Adapter.format(Stream, ArgStyle); ++Begin; } while (Begin != End) { Stream << Sep; - auto Adapter = detail::build_format_adapter(*Begin); + auto Adapter = + detail::build_format_adapter(std::forward(*Begin)); Adapter.format(Stream, ArgStyle); ++Begin; } diff --git a/llvm/include/llvm/Support/FormatVariadicDetails.h b/llvm/include/llvm/Support/FormatVariadicDetails.h index c17d0fe2f204..2204cff13a64 100644 --- a/llvm/include/llvm/Support/FormatVariadicDetails.h +++ b/llvm/include/llvm/Support/FormatVariadicDetails.h @@ -76,6 +76,8 @@ template class has_FormatProvider { // Test if raw_ostream& << T -> raw_ostream& is findable via ADL. template class has_StreamOperator { public: + using ConstRefT = const std::decay_t &; + template static char test( std::enable_if_t() @@ -85,8 +87,7 @@ template class has_StreamOperator { template static double test(...); - // NOLINTNEXTLINE(readability-identifier-naming) - static bool const value = (sizeof(test(nullptr)) == 1); + static bool const value = (sizeof(test(nullptr)) == 1); }; // Simple template that decides whether a type T should use the member-function diff --git a/llvm/unittests/Support/FormatVariadicTest.cpp b/llvm/unittests/Support/FormatVariadicTest.cpp index 6cc5793ef7bc..37946165e365 100644 --- a/llvm/unittests/Support/FormatVariadicTest.cpp +++ b/llvm/unittests/Support/FormatVariadicTest.cpp @@ -698,49 +698,3 @@ TEST(FormatVariadicTest, FormatError) { EXPECT_EQ("X", formatv("{0}", fmt_consume(std::move(E1))).str()); EXPECT_FALSE(E1.isA()); // consumed } - -TEST(FormatVariadicTest, FormatFilterRange) { - std::vector Vec{0, 1, 2}; - auto Range = map_range(Vec, [](int V) { return V + 1; }); - EXPECT_EQ("1, 2, 3", formatv("{0}", Range).str()); -} - -namespace { - -class IntegerValuesRange final - : public indexed_accessor_range { -public: - using indexed_accessor_range::indexed_accessor_range; - - static int dereference(const NoneType &, ptrdiff_t Index) { - return static_cast(Index); - } -}; - -TEST(FormatVariadicTest, FormatRangeNonRef) { - IntegerValuesRange Range(None, 0, 3); - EXPECT_EQ("0, 1, 2", - formatv("{0}", make_range(Range.begin(), Range.end())).str()); -} - -class PassByRef { -public: - int Val = 0; - PassByRef(int Val) : Val(Val) {} -}; - -raw_ostream &operator<<(raw_ostream &OS, PassByRef &Obj) { - return OS << Obj.Val; -} - -static_assert(detail::has_StreamOperator::value, ""); -static_assert(detail::uses_stream_operator::value, ""); - -TEST(FormatVariadicTest, StreamOperatorPassByRef) { - PassByRef Obj(10); - EXPECT_EQ("10", formatv("{0}", Obj).str()); -} - -} // namespace From a2961f84ac6d2828c3356adc445a336c7997118f Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Fri, 15 Jan 2021 13:59:36 +0300 Subject: [PATCH 03/19] [Support] Format provider improvements Remove `std::forward` call for `iterator_range` iterator de-reference. It fixes formatting usage for some tricky cases, like special ranges, which de-reference to value type. Differential Revision: https://reviews.llvm.org/D94769 --- llvm/include/llvm/Support/FormatProviders.h | 7 ++--- llvm/unittests/Support/FormatVariadicTest.cpp | 28 +++++++++++++++++++ 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/llvm/include/llvm/Support/FormatProviders.h b/llvm/include/llvm/Support/FormatProviders.h index 3edd8844bc7a..8cc184d74a20 100644 --- a/llvm/include/llvm/Support/FormatProviders.h +++ b/llvm/include/llvm/Support/FormatProviders.h @@ -355,7 +355,6 @@ struct range_item_has_provider template class format_provider> { using value = typename std::iterator_traits::value_type; - using reference = typename std::iterator_traits::reference; static StringRef consumeOneOption(StringRef &Style, char Indicator, StringRef Default) { @@ -403,15 +402,13 @@ template class format_provider> { auto Begin = V.begin(); auto End = V.end(); if (Begin != End) { - auto Adapter = - detail::build_format_adapter(std::forward(*Begin)); + auto Adapter = detail::build_format_adapter(*Begin); Adapter.format(Stream, ArgStyle); ++Begin; } while (Begin != End) { Stream << Sep; - auto Adapter = - detail::build_format_adapter(std::forward(*Begin)); + auto Adapter = detail::build_format_adapter(*Begin); Adapter.format(Stream, ArgStyle); ++Begin; } diff --git a/llvm/unittests/Support/FormatVariadicTest.cpp b/llvm/unittests/Support/FormatVariadicTest.cpp index 37946165e365..10e7be5acdaf 100644 --- a/llvm/unittests/Support/FormatVariadicTest.cpp +++ b/llvm/unittests/Support/FormatVariadicTest.cpp @@ -698,3 +698,31 @@ TEST(FormatVariadicTest, FormatError) { EXPECT_EQ("X", formatv("{0}", fmt_consume(std::move(E1))).str()); EXPECT_FALSE(E1.isA()); // consumed } + +TEST(FormatVariadicTest, FormatFilterRange) { + std::vector Vec{0, 1, 2}; + auto Range = map_range(Vec, [](int V) { return V + 1; }); + EXPECT_EQ("1, 2, 3", formatv("{0}", Range).str()); +} + +namespace { + +class IntegerValuesRange final + : public indexed_accessor_range { +public: + using indexed_accessor_range::indexed_accessor_range; + + static int dereference(const NoneType &, ptrdiff_t Index) { + return static_cast(Index); + } +}; + +TEST(FormatVariadicTest, FormatRangeNonRef) { + IntegerValuesRange Range(None, 0, 3); + EXPECT_EQ("0, 1, 2", + formatv("{0}", make_range(Range.begin(), Range.end())).str()); +} + +} // namespace From 4e21f4cea609fdda47937fc0113755dd342c370a Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Thu, 21 Oct 2021 13:47:09 +0300 Subject: [PATCH 04/19] [mlir] Pass output file name in mlir-translate callbacks It is added to callbacks for MLIR -> outer format conversion. Can be used for the transations that can't work with `raw_ostream`. --- mlir/include/mlir/Translation.h | 7 ++++--- mlir/lib/Target/Cpp/TranslateRegistration.cpp | 2 +- mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp | 2 +- mlir/lib/Target/SPIRV/TranslateRegistration.cpp | 6 +++--- mlir/lib/Translation/Translation.cpp | 9 +++++---- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/mlir/include/mlir/Translation.h b/mlir/include/mlir/Translation.h index 202681c8c602..2fdb3ae65c63 100644 --- a/mlir/include/mlir/Translation.h +++ b/mlir/include/mlir/Translation.h @@ -44,8 +44,8 @@ using TranslateStringRefToMLIRFunction = /// Interface of the function that translates MLIR to a different format and /// outputs the result to a stream. It is allowed to modify the module. -using TranslateFromMLIRFunction = - std::function; +using TranslateFromMLIRFunction = std::function; /// Interface of the function that performs file-to-file translation involving /// MLIR. The input file is held in the given MemoryBuffer; the output file @@ -53,7 +53,8 @@ using TranslateFromMLIRFunction = /// all MLIR constructs needed during the process inside the given context. This /// can be used for round-tripping external formats through the MLIR system. using TranslateFunction = std::function; + llvm::SourceMgr &sourceMgr, llvm::raw_ostream &output, + llvm::StringRef outputFileName, MLIRContext *)>; /// Use Translate[ToMLIR|FromMLIR]Registration as an initializer that /// registers a function and associates it with name. This requires that a diff --git a/mlir/lib/Target/Cpp/TranslateRegistration.cpp b/mlir/lib/Target/Cpp/TranslateRegistration.cpp index 7bdcd96b0407..de30b0027126 100644 --- a/mlir/lib/Target/Cpp/TranslateRegistration.cpp +++ b/mlir/lib/Target/Cpp/TranslateRegistration.cpp @@ -33,7 +33,7 @@ void registerToCppTranslation() { TranslateFromMLIRRegistration reg( "mlir-to-cpp", - [](ModuleOp module, raw_ostream &output) { + [](ModuleOp module, raw_ostream &output, StringRef) { return emitc::translateToCpp( module, output, /*declareVariablesAtTop=*/declareVariablesAtTop); diff --git a/mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp b/mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp index ef9de9490956..5a1347694935 100644 --- a/mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp +++ b/mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp @@ -23,7 +23,7 @@ namespace mlir { void registerToLLVMIRTranslation() { TranslateFromMLIRRegistration registration( "mlir-to-llvmir", - [](ModuleOp module, raw_ostream &output) { + [](ModuleOp module, raw_ostream &output, StringRef) { llvm::LLVMContext llvmContext; auto llvmModule = translateModuleToLLVMIR(module, llvmContext); if (!llvmModule) diff --git a/mlir/lib/Target/SPIRV/TranslateRegistration.cpp b/mlir/lib/Target/SPIRV/TranslateRegistration.cpp index aee4ad3bba99..260b01e35bc9 100644 --- a/mlir/lib/Target/SPIRV/TranslateRegistration.cpp +++ b/mlir/lib/Target/SPIRV/TranslateRegistration.cpp @@ -107,7 +107,7 @@ namespace mlir { void registerToSPIRVTranslation() { TranslateFromMLIRRegistration toBinary( "serialize-spirv", - [](ModuleOp module, raw_ostream &output) { + [](ModuleOp module, raw_ostream &output, StringRef) { return serializeModule(module, output); }, [](DialectRegistry ®istry) { @@ -160,7 +160,7 @@ namespace mlir { void registerTestRoundtripSPIRV() { TranslateFromMLIRRegistration roundtrip( "test-spirv-roundtrip", - [](ModuleOp module, raw_ostream &output) { + [](ModuleOp module, raw_ostream &output, StringRef) { return roundTripModule(module, /*emitDebugInfo=*/false, output); }, [](DialectRegistry ®istry) { @@ -171,7 +171,7 @@ void registerTestRoundtripSPIRV() { void registerTestRoundtripDebugSPIRV() { TranslateFromMLIRRegistration roundtrip( "test-spirv-roundtrip-debug", - [](ModuleOp module, raw_ostream &output) { + [](ModuleOp module, raw_ostream &output, StringRef) { return roundTripModule(module, /*emitDebugInfo=*/true, output); }, [](DialectRegistry ®istry) { diff --git a/mlir/lib/Translation/Translation.cpp b/mlir/lib/Translation/Translation.cpp index 5a8812ab49b2..fe59ad899772 100644 --- a/mlir/lib/Translation/Translation.cpp +++ b/mlir/lib/Translation/Translation.cpp @@ -61,7 +61,7 @@ TranslateRegistration::TranslateRegistration( static void registerTranslateToMLIRFunction( StringRef name, const TranslateSourceMgrToMLIRFunction &function) { auto wrappedFn = [function](llvm::SourceMgr &sourceMgr, raw_ostream &output, - MLIRContext *context) { + StringRef, MLIRContext *context) { OwningOpRef module = function(sourceMgr, context); if (!module || failed(verify(*module))) return failure(); @@ -97,6 +97,7 @@ TranslateFromMLIRRegistration::TranslateFromMLIRRegistration( const std::function &dialectRegistration) { registerTranslation(name, [function, dialectRegistration]( llvm::SourceMgr &sourceMgr, raw_ostream &output, + StringRef outputFileName, MLIRContext *context) { DialectRegistry registry; dialectRegistration(registry); @@ -104,7 +105,7 @@ TranslateFromMLIRRegistration::TranslateFromMLIRRegistration( auto module = OwningOpRef(parseSourceFile(sourceMgr, context)); if (!module || failed(verify(*module))) return failure(); - return function(module.get(), output); + return function(module.get(), output, outputFileName); }); } @@ -185,14 +186,14 @@ LogicalResult mlir::mlirTranslateMain(int argc, char **argv, if (!verifyDiagnostics) { SourceMgrDiagnosticHandler sourceMgrHandler(sourceMgr, &context); - return (*translationRequested)(sourceMgr, os, &context); + return (*translationRequested)(sourceMgr, os, outputFilename, &context); } // In the diagnostic verification flow, we ignore whether the translation // failed (in most cases, it is expected to fail). Instead, we check if the // diagnostics were produced as expected. SourceMgrDiagnosticVerifierHandler sourceMgrHandler(sourceMgr, &context); - (void)(*translationRequested)(sourceMgr, os, &context); + (void)(*translationRequested)(sourceMgr, os, outputFilename, &context); return sourceMgrHandler.verify(); }; From 5490ce50ffc782b92426cf01310a6312f2ccf72f Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Tue, 12 Oct 2021 18:10:14 +0300 Subject: [PATCH 05/19] [mlir][RFC] Allow to skip operands type specification in ASM form Based on the following discussion: https://llvm.discourse.group/t/declarative-assembly-format-requirement-for-type-presence/4399 Relax checks in `OperationParser` - it allows to skip value type specification, if the value was already defined in the same block. Differential Revision: https://reviews.llvm.org/D111650 --- mlir/lib/Parser/Parser.cpp | 37 ++++++++++++++++------ mlir/test/IR/invalid.mlir | 28 ++++++++++++++++ mlir/test/IR/parser.mlir | 10 ++++++ mlir/test/lib/Dialect/Test/TestDialect.cpp | 29 +++++++++++++++++ mlir/test/lib/Dialect/Test/TestOps.td | 3 ++ 5 files changed, 98 insertions(+), 9 deletions(-) diff --git a/mlir/lib/Parser/Parser.cpp b/mlir/lib/Parser/Parser.cpp index 54e4e762d564..56a3d78873f4 100644 --- a/mlir/lib/Parser/Parser.cpp +++ b/mlir/lib/Parser/Parser.cpp @@ -741,16 +741,35 @@ Value OperationParser::resolveSSAUse(SSAUseInfo useInfo, Type type) { // If we have already seen a value of this name, return it. if (useInfo.number < entries.size() && entries[useInfo.number].value) { Value result = entries[useInfo.number].value; + // Check that the type matches the other uses. - if (result.getType() == type) - return maybeRecordUse(result); - - emitError(useInfo.loc, "use of value '") - .append(useInfo.name, - "' expects different type than prior uses: ", type, " vs ", - result.getType()) - .attachNote(getEncodedSourceLocation(entries[useInfo.number].loc)) - .append("prior use here"); + if (type && result.getType() != type) { + emitError(useInfo.loc, "use of value '") + .append(useInfo.name, + "' expects different type than prior uses: ", type, " vs ", + result.getType()) + .attachNote(getEncodedSourceLocation(entries[useInfo.number].loc)) + .append("prior use here"); + return nullptr; + } + + // Explicit type specification can be omitted, only if the Value was already + // defined prior in the same block. + if (!type && result.getParentBlock() != opBuilder.getBlock()) { + emitError(useInfo.loc, "value '") + .append(useInfo.name, "' was defined in separate block and requires " + "explicit type definition") + .attachNote(getEncodedSourceLocation(entries[useInfo.number].loc)) + .append("defined here"); + return nullptr; + } + + return maybeRecordUse(result); + } + + if (!type) { + emitError(useInfo.loc, "forward reference of value '") + .append(useInfo.name, "' requires explicit type specification"); return nullptr; } diff --git a/mlir/test/IR/invalid.mlir b/mlir/test/IR/invalid.mlir index bfd655a5820d..002f43f455c4 100644 --- a/mlir/test/IR/invalid.mlir +++ b/mlir/test/IR/invalid.mlir @@ -1638,3 +1638,31 @@ func @invalid_region_dominance_with_dominance_free_regions() { // ----- func @foo() {} // expected-error {{expected non-empty function body}} + +// ----- + +// expected-note@+1 {{defined here}} +func @foo(%arg0: i64, %arg1: memref<1xf64>) { + br ^bb1 + + ^bb1: + // expected-error@+1 {{value '%arg1' was defined in separate block and requires explicit type definition}} + test.format_operand_optional_type_op %arg0, %arg1 + return +} + +// ----- + +func @foo() { + br ^bb2 + + ^bb1: + // expected-error@+1 {{forward reference of value '%1' requires explicit type specification}} + test.format_operand_optional_type_op %0, %1 + return + + ^bb2: + %0 = arith.constant 0 : i64 + %1 = memref.alloc() : memref<1xf64> + br ^bb1 +} diff --git a/mlir/test/IR/parser.mlir b/mlir/test/IR/parser.mlir index 0c7bdd1e08ba..8ed7746a4564 100644 --- a/mlir/test/IR/parser.mlir +++ b/mlir/test/IR/parser.mlir @@ -1427,3 +1427,13 @@ test.dialect_custom_printer custom_format // be handled by the dialect. // CHECK: test.dialect_custom_format_fallback custom_format_fallback test.dialect_custom_format_fallback custom_format_fallback + +// Can skip type definition for operands, if they are already defined in the same block +// CHECK-LABEL: func @optional_operand_types +func @optional_operand_types(%arg0: i64, %arg1: memref<1xf64>) { + // CHECK: test.format_operand_optional_type_op %arg0, %arg1 + test.format_operand_optional_type_op %arg0, %arg1 + // CHECK: test.format_operand_optional_type_op %arg0, %arg1 + test.format_operand_optional_type_op %arg0, %arg1 : memref<1xf64> + return +} diff --git a/mlir/test/lib/Dialect/Test/TestDialect.cpp b/mlir/test/lib/Dialect/Test/TestDialect.cpp index 21db4e0a9d11..2fe0bcae8a84 100644 --- a/mlir/test/lib/Dialect/Test/TestDialect.cpp +++ b/mlir/test/lib/Dialect/Test/TestDialect.cpp @@ -16,6 +16,7 @@ #include "mlir/Dialect/Tensor/IR/Tensor.h" #include "mlir/IR/BuiltinOps.h" #include "mlir/IR/DialectImplementation.h" +#include "mlir/IR/OpImplementation.h" #include "mlir/IR/PatternMatch.h" #include "mlir/IR/TypeUtilities.h" #include "mlir/Reducer/ReductionPatternInterface.h" @@ -1237,6 +1238,34 @@ static void print(SingleNoTerminatorCustomAsmOp op, OpAsmPrinter &printer) { /*printBlockTerminators=*/false); } +//===----------------------------------------------------------------------===// +// FormatOperandOptionalTypeOp +//===----------------------------------------------------------------------===// + +static bool isDefinedAbove(Value val, Operation *op) { + if (val.isa()) + return true; + + return val.getDefiningOp()->getBlock() == op->getBlock() && + val.getDefiningOp()->isBeforeInBlock(op); +} + +static void printOptionalType(OpAsmPrinter &printer, + FormatOperandOptionalTypeOp op, Type type) { + if (isDefinedAbove(op.getOperand(), op)) + return; + + printer << ":"; + printer.printType(type); +} + +static ParseResult parseOptionalType(OpAsmParser &parser, Type &type) { + if (parser.parseOptionalColon()) + return success(); + + return parser.parseType(type); +} + #include "TestOpEnums.cpp.inc" #include "TestOpInterfaces.cpp.inc" #include "TestOpStructs.cpp.inc" diff --git a/mlir/test/lib/Dialect/Test/TestOps.td b/mlir/test/lib/Dialect/Test/TestOps.td index c37007f9ab0e..44f881c14c09 100644 --- a/mlir/test/lib/Dialect/Test/TestOps.td +++ b/mlir/test/lib/Dialect/Test/TestOps.td @@ -1836,6 +1836,9 @@ def FormatOperandDOp : FormatOperandBase<"d", [{ def FormatOperandEOp : FormatOperandBase<"e", [{ $buildable `,` $operand `:` type($buildable) `,` type($operand) attr-dict }]>; +def FormatOperandOptionalTypeOp : FormatOperandBase<"optional_type", [{ + $buildable `,` $operand custom(type($operand)) attr-dict +}]>; def FormatSuccessorAOp : TEST_Op<"format_successor_a_op", [Terminator]> { let successors = (successor VariadicSuccessor:$targets); From bea1e0afee3e36fa26166913c79a679108795963 Mon Sep 17 00:00:00 2001 From: Nikita Kudriavtsev Date: Tue, 21 Dec 2021 11:17:06 +0300 Subject: [PATCH 06/19] Add FlatSymbolRefAttr for memory space representation (#44) --- mlir/lib/IR/BuiltinTypes.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mlir/lib/IR/BuiltinTypes.cpp b/mlir/lib/IR/BuiltinTypes.cpp index 6d3ed12cedf2..5933f35f2f80 100644 --- a/mlir/lib/IR/BuiltinTypes.cpp +++ b/mlir/lib/IR/BuiltinTypes.cpp @@ -472,7 +472,7 @@ bool mlir::detail::isSupportedMemorySpace(Attribute memorySpace) { return true; // Supported built-in attributes. - if (memorySpace.isa()) + if (memorySpace.isa()) return true; // Allow custom dialect attributes. From 9e66925bcb11bba562c5039b074b5d94997e156a Mon Sep 17 00:00:00 2001 From: Nikita Kudriavtsev Date: Thu, 13 Jan 2022 10:02:28 +0300 Subject: [PATCH 07/19] Add ArrayAttr for memory space representation (#45) --- mlir/lib/IR/BuiltinTypes.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mlir/lib/IR/BuiltinTypes.cpp b/mlir/lib/IR/BuiltinTypes.cpp index 5933f35f2f80..e92ace843bf0 100644 --- a/mlir/lib/IR/BuiltinTypes.cpp +++ b/mlir/lib/IR/BuiltinTypes.cpp @@ -472,7 +472,7 @@ bool mlir::detail::isSupportedMemorySpace(Attribute memorySpace) { return true; // Supported built-in attributes. - if (memorySpace.isa()) + if (memorySpace.isa()) return true; // Allow custom dialect attributes. From 3fd8c1e19c74630ad36da02197bf005c06cf8e64 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Mon, 10 Jan 2022 15:30:34 +0300 Subject: [PATCH 08/19] [mlir][ODS] Use fully qualified type names with namespaces --- mlir/tools/mlir-tblgen/OpFormatGen.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mlir/tools/mlir-tblgen/OpFormatGen.cpp b/mlir/tools/mlir-tblgen/OpFormatGen.cpp index 3e395c2f7731..f69c39ad2755 100644 --- a/mlir/tools/mlir-tblgen/OpFormatGen.cpp +++ b/mlir/tools/mlir-tblgen/OpFormatGen.cpp @@ -1613,7 +1613,7 @@ static void genCustomDirectiveParameterPrinter(FormatElement *element, if (var->isVariadic()) body << name << "().getTypes()"; else if (var->isOptional()) - body << llvm::formatv("({0}() ? {0}().getType() : Type())", name); + body << llvm::formatv("({0}() ? {0}().getType() : ::mlir::Type())", name); else body << name << "().getType()"; } else { From 5d32060dea1a173141632135704042e670e8c016 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Fri, 14 Jan 2022 15:38:34 +0300 Subject: [PATCH 09/19] [mlir] Relax ASM parser requirements about operands Type presence --- mlir/include/mlir/IR/OpImplementation.h | 23 +++++++++++++++-------- mlir/lib/Parser/Parser.cpp | 11 ----------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/mlir/include/mlir/IR/OpImplementation.h b/mlir/include/mlir/IR/OpImplementation.h index 20310201fd8e..381467aad140 100644 --- a/mlir/include/mlir/IR/OpImplementation.h +++ b/mlir/include/mlir/IR/OpImplementation.h @@ -627,14 +627,14 @@ class AsmParser { /// unlike `OpBuilder::getType`, this method does not implicitly insert a /// context parameter. template - T getChecked(SMLoc loc, ParamsT &&... params) { + T getChecked(SMLoc loc, ParamsT &&...params) { return T::getChecked([&] { return emitError(loc); }, std::forward(params)...); } /// A variant of `getChecked` that uses the result of `getNameLoc` to emit /// errors. template - T getChecked(ParamsT &&... params) { + T getChecked(ParamsT &&...params) { return T::getChecked([&] { return emitError(getNameLoc()); }, std::forward(params)...); } @@ -1154,13 +1154,14 @@ class OpAsmParser : public AsmParser { ParseResult resolveOperands(ArrayRef operands, ArrayRef types, SMLoc loc, SmallVectorImpl &result) { - if (operands.size() != types.size()) + if (!types.empty() && operands.size() != types.size()) return emitError(loc) << operands.size() << " operands present, but expected " << types.size(); for (unsigned i = 0, e = operands.size(); i != e; ++i) - if (resolveOperand(operands[i], types[i], result)) + if (resolveOperand(operands[i], types.empty() ? Type() : types[i], + result)) return failure(); return success(); } @@ -1176,13 +1177,19 @@ class OpAsmParser : public AsmParser { SmallVectorImpl &result) { size_t operandSize = std::distance(operands.begin(), operands.end()); size_t typeSize = std::distance(types.begin(), types.end()); - if (operandSize != typeSize) + if (typeSize != 0 && operandSize != typeSize) return emitError(loc) << operandSize << " operands present, but expected " << typeSize; - for (auto it : llvm::zip(operands, types)) - if (resolveOperand(std::get<0>(it), std::get<1>(it), result)) - return failure(); + if (typeSize == 0) { + for (auto it : operands) + if (resolveOperand(it, Type(), result)) + return failure(); + } else { + for (auto it : llvm::zip(operands, types)) + if (resolveOperand(std::get<0>(it), std::get<1>(it), result)) + return failure(); + } return success(); } diff --git a/mlir/lib/Parser/Parser.cpp b/mlir/lib/Parser/Parser.cpp index 56a3d78873f4..3177025b4762 100644 --- a/mlir/lib/Parser/Parser.cpp +++ b/mlir/lib/Parser/Parser.cpp @@ -753,17 +753,6 @@ Value OperationParser::resolveSSAUse(SSAUseInfo useInfo, Type type) { return nullptr; } - // Explicit type specification can be omitted, only if the Value was already - // defined prior in the same block. - if (!type && result.getParentBlock() != opBuilder.getBlock()) { - emitError(useInfo.loc, "value '") - .append(useInfo.name, "' was defined in separate block and requires " - "explicit type definition") - .attachNote(getEncodedSourceLocation(entries[useInfo.number].loc)) - .append("defined here"); - return nullptr; - } - return maybeRecordUse(result); } From f7ca8564bc274bfc3352f911af5a476c3374358d Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Fri, 21 Jan 2022 10:32:43 +0300 Subject: [PATCH 10/19] [mlir] Remove LIT tests affected by ASM simplification --- mlir/test/Dialect/LLVMIR/invalid.mlir | 14 -------------- mlir/test/IR/invalid.mlir | 12 ------------ 2 files changed, 26 deletions(-) diff --git a/mlir/test/Dialect/LLVMIR/invalid.mlir b/mlir/test/Dialect/LLVMIR/invalid.mlir index 6b91f20441db..aedbecefa718 100644 --- a/mlir/test/Dialect/LLVMIR/invalid.mlir +++ b/mlir/test/Dialect/LLVMIR/invalid.mlir @@ -104,20 +104,6 @@ func @alloca_non_integer_alignment() { // ----- -func @gep_missing_input_result_type(%pos : i64, %base : !llvm.ptr) { - // expected-error@+1 {{2 operands present, but expected 0}} - llvm.getelementptr %base[%pos] : () -> () -} - -// ----- - -func @gep_missing_input_type(%pos : i64, %base : !llvm.ptr) { - // expected-error@+1 {{2 operands present, but expected 0}} - llvm.getelementptr %base[%pos] : () -> (!llvm.ptr) -} - -// ----- - func @gep_missing_result_type(%pos : i64, %base : !llvm.ptr) { // expected-error@+1 {{op requires one result}} llvm.getelementptr %base[%pos] : (!llvm.ptr, i64) -> () diff --git a/mlir/test/IR/invalid.mlir b/mlir/test/IR/invalid.mlir index 002f43f455c4..7c18c50f2beb 100644 --- a/mlir/test/IR/invalid.mlir +++ b/mlir/test/IR/invalid.mlir @@ -1641,18 +1641,6 @@ func @foo() {} // expected-error {{expected non-empty function body}} // ----- -// expected-note@+1 {{defined here}} -func @foo(%arg0: i64, %arg1: memref<1xf64>) { - br ^bb1 - - ^bb1: - // expected-error@+1 {{value '%arg1' was defined in separate block and requires explicit type definition}} - test.format_operand_optional_type_op %arg0, %arg1 - return -} - -// ----- - func @foo() { br ^bb2 From aaf5c6ab8b533831eeef593f84f52c51f134c464 Mon Sep 17 00:00:00 2001 From: Orest Chura Date: Mon, 22 Aug 2022 13:57:28 +0100 Subject: [PATCH 11/19] Fix MLIR-TblGen to fix KW issues (#1) * - fixed uninitialized array declaration in `mlir-tblgen/OpFormatGen.cpp` - fixed creating `void` methods returning value in `mlir-tblgen/OpInterfacesGen.cpp` * Apply comment on OpInterfacesGen.cpp by nikita-kud --- mlir/tools/mlir-tblgen/OpFormatGen.cpp | 4 +- mlir/tools/mlir-tblgen/OpInterfacesGen.cpp | 46 +++++++++++++++------- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/mlir/tools/mlir-tblgen/OpFormatGen.cpp b/mlir/tools/mlir-tblgen/OpFormatGen.cpp index f69c39ad2755..e99eef40ac5e 100644 --- a/mlir/tools/mlir-tblgen/OpFormatGen.cpp +++ b/mlir/tools/mlir-tblgen/OpFormatGen.cpp @@ -751,7 +751,7 @@ static void genElementParserStorage(FormatElement *element, const Operator &op, } } else { body << " ::mlir::OpAsmParser::OperandType " << name - << "RawOperands[1];\n" + << "RawOperands[1] = { };\n" << " ::llvm::ArrayRef<::mlir::OpAsmParser::OperandType> " << name << "Operands(" << name << "RawOperands);"; } @@ -788,7 +788,7 @@ static void genElementParserStorage(FormatElement *element, const Operator &op, if (lengthKind != ArgumentLengthKind::Single) body << " ::mlir::SmallVector<::mlir::Type, 1> " << name << "Types;\n"; else - body << llvm::formatv(" ::mlir::Type {0}RawTypes[1];\n", name) + body << llvm::formatv(" ::mlir::Type {0}RawTypes[1] = {{ };\n", name) << llvm::formatv( " ::llvm::ArrayRef<::mlir::Type> {0}Types({0}RawTypes);\n", name); diff --git a/mlir/tools/mlir-tblgen/OpInterfacesGen.cpp b/mlir/tools/mlir-tblgen/OpInterfacesGen.cpp index 0513c5e7b1ab..0938ec42acf9 100644 --- a/mlir/tools/mlir-tblgen/OpInterfacesGen.cpp +++ b/mlir/tools/mlir-tblgen/OpInterfacesGen.cpp @@ -167,7 +167,8 @@ static void emitInterfaceDef(const Interface &interface, StringRef valueType, // Insert the method definitions. bool isOpInterface = isa(interface); for (auto &method : interface.getMethods()) { - emitCPPType(method.getReturnType(), os); + auto returnType = method.getReturnType(); + emitCPPType(returnType, os); if (!cppNamespace.empty()) os << cppNamespace << "::"; os << interfaceName << "::"; @@ -175,7 +176,11 @@ static void emitInterfaceDef(const Interface &interface, StringRef valueType, /*addConst=*/!isOpInterface); // Forward to the method on the concrete operation type. - os << " {\n return getImpl()->" << method.getName() << '('; + os << " {\n "; + if (returnType != "void") { + os << "return "; + } + os << "getImpl()->" << method.getName() << '('; if (!method.isStatic()) { os << "getImpl(), "; os << (isOpInterface ? "getOperation()" : "*this"); @@ -283,7 +288,8 @@ void InterfaceGenerator::emitModelDecl(const Interface &interface) { void InterfaceGenerator::emitModelMethodsDef(const Interface &interface) { for (auto &method : interface.getMethods()) { os << "template\n"; - emitCPPType(method.getReturnType(), os); + auto returnType = method.getReturnType(); + emitCPPType(returnType, os); os << "detail::" << interface.getName() << "InterfaceTraits::Model<" << valueTemplate << ">::"; emitMethodNameAndArgs(method, os, valueType, @@ -302,10 +308,15 @@ void InterfaceGenerator::emitModelMethodsDef(const Interface &interface) { } // Forward to the method on the concrete operation type. - if (method.isStatic()) - os << "return " << valueTemplate << "::"; - else - os << tblgen::tgfmt("return $_self.", &nonStaticMethodFmt); + if (returnType != "void") { + os << "return "; + } + + if (method.isStatic()) { + os << valueTemplate << "::"; + } else { + os << tblgen::tgfmt("$_self.", &nonStaticMethodFmt); + } // Add the arguments to the call. os << method.getName() << '('; @@ -317,7 +328,8 @@ void InterfaceGenerator::emitModelMethodsDef(const Interface &interface) { for (auto &method : interface.getMethods()) { os << "template\n"; - emitCPPType(method.getReturnType(), os); + auto returnType = method.getReturnType(); + emitCPPType(returnType, os); os << "detail::" << interface.getName() << "InterfaceTraits::FallbackModel<" << valueTemplate << ">::"; emitMethodNameAndArgs(method, os, valueType, @@ -326,11 +338,15 @@ void InterfaceGenerator::emitModelMethodsDef(const Interface &interface) { os << " {\n "; // Forward to the method on the concrete Model implementation. - if (method.isStatic()) - os << "return " << valueTemplate << "::"; - else - os << "return static_cast(impl)->"; - + if (returnType != "void") { + os << "return "; + } + + if (method.isStatic()) { + os << valueTemplate << "::"; + } else { + os << "static_cast(impl)->"; + } // Add the arguments to the call. os << method.getName() << '('; if (!method.isStatic()) @@ -368,7 +384,7 @@ void InterfaceGenerator::emitModelMethodsDef(const Interface &interface) { if (!method.isStatic()) os << " const"; - os << " {\n"; + os << " {\n "; // Use the empty context for static methods. tblgen::FmtContext ctx; @@ -443,7 +459,7 @@ void InterfaceGenerator::emitInterfaceDecl(const Interface &interface) { << "struct " << interfaceTraitsName << " {\n"; emitConceptDecl(interface); emitModelDecl(interface); - os << "};"; + os << "};\n"; // Emit the derived trait for the interface. os << "template \n"; From c8b0f3ae937cabe106b0c5a42e155d1202bd9ebb Mon Sep 17 00:00:00 2001 From: OrestChura Date: Mon, 3 Oct 2022 08:40:59 +0000 Subject: [PATCH 12/19] Fix compilation warnings --- llvm/include/llvm/ADT/Hashing.h | 2 +- llvm/include/llvm/ADT/SmallVector.h | 9 +++++---- llvm/include/llvm/Support/FormatCommon.h | 4 ++-- llvm/include/llvm/Support/SwapByteOrder.h | 8 ++++---- llvm/include/llvm/Support/type_traits.h | 8 ++++++++ 5 files changed, 20 insertions(+), 11 deletions(-) diff --git a/llvm/include/llvm/ADT/Hashing.h b/llvm/include/llvm/ADT/Hashing.h index 74a87a3d8dbb..bd1bd2e64475 100644 --- a/llvm/include/llvm/ADT/Hashing.h +++ b/llvm/include/llvm/ADT/Hashing.h @@ -681,7 +681,7 @@ hash_code hash_value(const std::basic_string &arg) { template <> struct DenseMapInfo { static inline hash_code getEmptyKey() { return hash_code(-1); } static inline hash_code getTombstoneKey() { return hash_code(-2); } - static unsigned getHashValue(hash_code val) { return val; } + static unsigned getHashValue(hash_code val) { return static_cast(val); } static bool isEqual(hash_code LHS, hash_code RHS) { return LHS == RHS; } }; diff --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h index a4a790323a6b..131da06508ee 100644 --- a/llvm/include/llvm/ADT/SmallVector.h +++ b/llvm/include/llvm/ADT/SmallVector.h @@ -54,7 +54,7 @@ template class SmallVectorBase { SmallVectorBase() = delete; SmallVectorBase(void *FirstEl, size_t TotalCapacity) - : BeginX(FirstEl), Capacity(TotalCapacity) {} + : BeginX(FirstEl), Capacity(static_cast(TotalCapacity)) {} /// This is a helper for \a grow() that's out of line to reduce code /// duplication. This function will report a fatal error if it can't grow at @@ -78,8 +78,9 @@ template class SmallVectorBase { /// /// This does not construct or destroy any elements in the vector. void set_size(size_t N) { - assert(N <= capacity()); - Size = N; + auto n = static_cast(N); + assert(n <= capacity()); + Size = n; } }; @@ -444,7 +445,7 @@ void SmallVectorTemplateBase::takeAllocationForGrow( free(this->begin()); this->BeginX = NewElts; - this->Capacity = NewCapacity; + this->Capacity = static_cast>(NewCapacity); } /// SmallVectorTemplateBase - This is where we put diff --git a/llvm/include/llvm/Support/FormatCommon.h b/llvm/include/llvm/Support/FormatCommon.h index 3c119d12529a..24a40c325e13 100644 --- a/llvm/include/llvm/Support/FormatCommon.h +++ b/llvm/include/llvm/Support/FormatCommon.h @@ -66,8 +66,8 @@ struct FmtAlign { } private: - void fill(llvm::raw_ostream &S, uint32_t Count) { - for (uint32_t I = 0; I < Count; ++I) + void fill(llvm::raw_ostream &S, size_t Count) { + for (size_t I = 0; I < Count; ++I) S << Fill; } }; diff --git a/llvm/include/llvm/Support/SwapByteOrder.h b/llvm/include/llvm/Support/SwapByteOrder.h index e8612ba6654b..383c4c328025 100644 --- a/llvm/include/llvm/Support/SwapByteOrder.h +++ b/llvm/include/llvm/Support/SwapByteOrder.h @@ -112,13 +112,13 @@ inline signed int getSwappedBytes( signed int C) { return ByteSwap_32(C); inline unsigned long getSwappedBytes(unsigned long C) { // Handle LLP64 and LP64 platforms. - return sizeof(long) == sizeof(int) ? ByteSwap_32((uint32_t)C) - : ByteSwap_64((uint64_t)C); + return static_cast(sizeof(long) == sizeof(int) ? ByteSwap_32((uint32_t)C) + : ByteSwap_64((uint64_t)C)); } inline signed long getSwappedBytes(signed long C) { // Handle LLP64 and LP64 platforms. - return sizeof(long) == sizeof(int) ? ByteSwap_32((uint32_t)C) - : ByteSwap_64((uint64_t)C); + return static_cast(sizeof(long) == sizeof(int) ? ByteSwap_32((uint32_t)C) + : ByteSwap_64((uint64_t)C)); } inline unsigned long long getSwappedBytes(unsigned long long C) { diff --git a/llvm/include/llvm/Support/type_traits.h b/llvm/include/llvm/Support/type_traits.h index 7b7d5d991f3f..78771dc53c48 100644 --- a/llvm/include/llvm/Support/type_traits.h +++ b/llvm/include/llvm/Support/type_traits.h @@ -70,6 +70,11 @@ struct const_pointer_or_const_ref` +# pragma warning(disable : 4624) +#endif /// Internal utility to detect trivial copy construction. template union copy_construction_triviality_helper { T t; @@ -84,6 +89,9 @@ template union move_construction_triviality_helper { move_construction_triviality_helper(move_construction_triviality_helper&&) = default; ~move_construction_triviality_helper() = default; }; +#if defined(_MSC_VER) +# pragma warning(pop) +#endif template union trivial_helper { From 2b2bb26d9c66e49d5abd2d7158941841426bdd15 Mon Sep 17 00:00:00 2001 From: "Skrebkov, Artemy" Date: Sun, 27 Nov 2022 18:24:52 +0100 Subject: [PATCH 13/19] Do not set CMAKE_CXX_FLAGS_ with FORCE --- llvm/cmake/modules/ChooseMSVCCRT.cmake | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/llvm/cmake/modules/ChooseMSVCCRT.cmake b/llvm/cmake/modules/ChooseMSVCCRT.cmake index 0e6e1aa55254..df9775a38b53 100644 --- a/llvm/cmake/modules/ChooseMSVCCRT.cmake +++ b/llvm/cmake/modules/ChooseMSVCCRT.cmake @@ -43,11 +43,8 @@ macro(set_flag_in_var flagsvar regex flag) string(REGEX REPLACE "${${regex}}" "${${flag}}" ${flagsvar} "${${flagsvar}}") endif() string(STRIP "${${flagsvar}}" ${flagsvar}) - # Make sure this change gets reflected in the cache/gui. - # CMake requires the docstring parameter whenever set() touches the cache, - # so get the existing docstring and re-use that. - get_property(flagsvar_docs CACHE ${flagsvar} PROPERTY HELPSTRING) - set(${flagsvar} "${${flagsvar}}" CACHE STRING "${flagsvar_docs}" FORCE) + + set(${flagsvar} "${${flagsvar}}") endmacro(set_flag_in_var) From 78fce0b06c96747668f1286f8e4155a644f9ac5b Mon Sep 17 00:00:00 2001 From: Anastasiya Pronina Date: Thu, 26 Jan 2023 11:16:36 +0000 Subject: [PATCH 14/19] Fixed CWARN.COPY.NOASSIGN for vpux-plugin project --- mlir/include/mlir/Pass/Pass.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mlir/include/mlir/Pass/Pass.h b/mlir/include/mlir/Pass/Pass.h index ebc92414e617..48db2cc6d34e 100644 --- a/mlir/include/mlir/Pass/Pass.h +++ b/mlir/include/mlir/Pass/Pass.h @@ -164,6 +164,13 @@ class Pass { : passID(passID), opName(opName) {} Pass(const Pass &other) : Pass(other.passID, other.opName) {} + Pass& operator=(const Pass &other) { + this->passID = other.passID; + this->opName = other.opName; + + return *this; + } + /// Returns the current pass state. detail::PassExecutionState &getPassState() { assert(passState && "pass state was never initialized"); From a2f0b0d618629b476087d72e398de2c312c6684f Mon Sep 17 00:00:00 2001 From: Jack Clarke Date: Wed, 1 Feb 2023 12:58:28 +0000 Subject: [PATCH 15/19] Add flag to disable unused GPU dialects in MLIR --- mlir/CMakeLists.txt | 4 ++ mlir/include/mlir/Dialect/CMakeLists.txt | 4 +- mlir/lib/Conversion/CMakeLists.txt | 36 +++++++++---- .../lib/Conversion/GPUToVulkan/CMakeLists.txt | 54 +++++++++++++------ mlir/lib/Dialect/CMakeLists.txt | 4 +- mlir/lib/Target/CMakeLists.txt | 4 +- 6 files changed, 77 insertions(+), 29 deletions(-) diff --git a/mlir/CMakeLists.txt b/mlir/CMakeLists.txt index e049702ce4b1..08ca64aeeac8 100644 --- a/mlir/CMakeLists.txt +++ b/mlir/CMakeLists.txt @@ -106,6 +106,10 @@ set(MLIR_ENABLE_ROCM_RUNNER 0 CACHE BOOL "Enable building the mlir ROCm runner") set(MLIR_ENABLE_SPIRV_CPU_RUNNER 0 CACHE BOOL "Enable building the mlir SPIR-V cpu runner") set(MLIR_ENABLE_VULKAN_RUNNER 0 CACHE BOOL "Enable building the mlir Vulkan runner") +option(MLIR_DIALECT_SPIRV_ENABLE + "Enable build targets related to SPIR-V dialect." + ON) + option(MLIR_INCLUDE_TESTS "Generate build targets for the MLIR unit tests." ${LLVM_INCLUDE_TESTS}) diff --git a/mlir/include/mlir/Dialect/CMakeLists.txt b/mlir/include/mlir/Dialect/CMakeLists.txt index 40fc101862e0..c17efbe75bbd 100644 --- a/mlir/include/mlir/Dialect/CMakeLists.txt +++ b/mlir/include/mlir/Dialect/CMakeLists.txt @@ -21,7 +21,9 @@ add_subdirectory(Quant) add_subdirectory(SCF) add_subdirectory(Shape) add_subdirectory(SparseTensor) -add_subdirectory(SPIRV) +if(MLIR_DIALECT_SPIRV_ENABLE) + add_subdirectory(SPIRV) +endif() add_subdirectory(StandardOps) add_subdirectory(Tensor) add_subdirectory(Tosa) diff --git a/mlir/lib/Conversion/CMakeLists.txt b/mlir/lib/Conversion/CMakeLists.txt index 602b9e72b330..80cdc9b5961c 100644 --- a/mlir/lib/Conversion/CMakeLists.txt +++ b/mlir/lib/Conversion/CMakeLists.txt @@ -1,6 +1,8 @@ add_subdirectory(AffineToStandard) add_subdirectory(ArithmeticToLLVM) -add_subdirectory(ArithmeticToSPIRV) +if(MLIR_DIALECT_SPIRV_ENABLE) + add_subdirectory(ArithmeticToSPIRV) +endif() add_subdirectory(ArmNeon2dToIntr) add_subdirectory(AsyncToLLVM) add_subdirectory(BufferizationToMemRef) @@ -9,17 +11,25 @@ add_subdirectory(ComplexToStandard) add_subdirectory(GPUCommon) add_subdirectory(GPUToNVVM) add_subdirectory(GPUToROCDL) -add_subdirectory(GPUToSPIRV) +if(MLIR_DIALECT_SPIRV_ENABLE) + add_subdirectory(GPUToSPIRV) +endif() add_subdirectory(GPUToVulkan) add_subdirectory(LinalgToLLVM) -add_subdirectory(LinalgToSPIRV) +if(MLIR_DIALECT_SPIRV_ENABLE) + add_subdirectory(LinalgToSPIRV) +endif() add_subdirectory(LinalgToStandard) add_subdirectory(LLVMCommon) add_subdirectory(MathToLibm) add_subdirectory(MathToLLVM) -add_subdirectory(MathToSPIRV) +if(MLIR_DIALECT_SPIRV_ENABLE) + add_subdirectory(MathToSPIRV) +endif() add_subdirectory(MemRefToLLVM) -add_subdirectory(MemRefToSPIRV) +if(MLIR_DIALECT_SPIRV_ENABLE) + add_subdirectory(MemRefToSPIRV) +endif() add_subdirectory(OpenACCToLLVM) add_subdirectory(OpenACCToSCF) add_subdirectory(OpenMPToLLVM) @@ -27,12 +37,18 @@ add_subdirectory(PDLToPDLInterp) add_subdirectory(ReconcileUnrealizedCasts) add_subdirectory(SCFToGPU) add_subdirectory(SCFToOpenMP) -add_subdirectory(SCFToSPIRV) +if(MLIR_DIALECT_SPIRV_ENABLE) + add_subdirectory(SCFToSPIRV) +endif() add_subdirectory(SCFToStandard) add_subdirectory(ShapeToStandard) -add_subdirectory(SPIRVToLLVM) +if(MLIR_DIALECT_SPIRV_ENABLE) + add_subdirectory(SPIRVToLLVM) +endif() add_subdirectory(StandardToLLVM) -add_subdirectory(StandardToSPIRV) +if(MLIR_DIALECT_SPIRV_ENABLE) + add_subdirectory(StandardToSPIRV) +endif() add_subdirectory(TosaToLinalg) add_subdirectory(TosaToSCF) add_subdirectory(TosaToStandard) @@ -40,4 +56,6 @@ add_subdirectory(VectorToROCDL) add_subdirectory(VectorToLLVM) add_subdirectory(VectorToGPU) add_subdirectory(VectorToSCF) -add_subdirectory(VectorToSPIRV) +if(MLIR_DIALECT_SPIRV_ENABLE) + add_subdirectory(VectorToSPIRV) +endif() diff --git a/mlir/lib/Conversion/GPUToVulkan/CMakeLists.txt b/mlir/lib/Conversion/GPUToVulkan/CMakeLists.txt index c2249ae8333e..2216b4f70f17 100644 --- a/mlir/lib/Conversion/GPUToVulkan/CMakeLists.txt +++ b/mlir/lib/Conversion/GPUToVulkan/CMakeLists.txt @@ -1,19 +1,39 @@ -add_mlir_conversion_library(MLIRGPUToVulkanTransforms - ConvertLaunchFuncToVulkanCalls.cpp - ConvertGPULaunchFuncToVulkanLaunchFunc.cpp +if(MLIR_DIALECT_SPIRV_ENABLE) + add_mlir_conversion_library(MLIRGPUToVulkanTransforms + ConvertLaunchFuncToVulkanCalls.cpp + ConvertGPULaunchFuncToVulkanLaunchFunc.cpp - DEPENDS - MLIRConversionPassIncGen + DEPENDS + MLIRConversionPassIncGen - LINK_LIBS PUBLIC - MLIRGPUOps - MLIRIR - MLIRLLVMIR - MLIRPass - MLIRSPIRV - MLIRSPIRVSerialization - MLIRStandard - MLIRSupport - MLIRTransforms - MLIRTranslation - ) + LINK_LIBS PUBLIC + MLIRGPUOps + MLIRIR + MLIRLLVMIR + MLIRPass + MLIRSPIRV + MLIRSPIRVSerialization + MLIRStandard + MLIRSupport + MLIRTransforms + MLIRTranslation + ) +else() + add_mlir_conversion_library(MLIRGPUToVulkanTransforms + ConvertLaunchFuncToVulkanCalls.cpp + ConvertGPULaunchFuncToVulkanLaunchFunc.cpp + + DEPENDS + MLIRConversionPassIncGen + + LINK_LIBS PUBLIC + MLIRGPUOps + MLIRIR + MLIRLLVMIR + MLIRPass + MLIRStandard + MLIRSupport + MLIRTransforms + MLIRTranslation + ) +endif() diff --git a/mlir/lib/Dialect/CMakeLists.txt b/mlir/lib/Dialect/CMakeLists.txt index da2be111e208..0a8062ed1bd6 100644 --- a/mlir/lib/Dialect/CMakeLists.txt +++ b/mlir/lib/Dialect/CMakeLists.txt @@ -21,7 +21,9 @@ add_subdirectory(Quant) add_subdirectory(SCF) add_subdirectory(Shape) add_subdirectory(SparseTensor) -add_subdirectory(SPIRV) +if(MLIR_DIALECT_SPIRV_ENABLE) + add_subdirectory(SPIRV) +endif() add_subdirectory(StandardOps) add_subdirectory(Tensor) add_subdirectory(Tosa) diff --git a/mlir/lib/Target/CMakeLists.txt b/mlir/lib/Target/CMakeLists.txt index acc3985cc80e..48985a0fe25f 100644 --- a/mlir/lib/Target/CMakeLists.txt +++ b/mlir/lib/Target/CMakeLists.txt @@ -1,3 +1,5 @@ add_subdirectory(Cpp) -add_subdirectory(SPIRV) +if(MLIR_DIALECT_SPIRV_ENABLE) + add_subdirectory(SPIRV) +endif() add_subdirectory(LLVMIR) From a7a1f1586d9c1361e6766e3942eadab607d536c7 Mon Sep 17 00:00:00 2001 From: Anastasiya Pronina Date: Fri, 27 Jan 2023 15:53:26 +0000 Subject: [PATCH 16/19] Propagated copy-assignment operator down to the hierarchy --- mlir/include/mlir/Pass/Pass.h | 3 +++ mlir/tools/mlir-tblgen/PassGen.cpp | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/mlir/include/mlir/Pass/Pass.h b/mlir/include/mlir/Pass/Pass.h index 48db2cc6d34e..91d694a2ed64 100644 --- a/mlir/include/mlir/Pass/Pass.h +++ b/mlir/include/mlir/Pass/Pass.h @@ -347,6 +347,7 @@ template class OperationPass : public Pass { protected: OperationPass(TypeID passID) : Pass(passID, OpT::getOperationName()) {} OperationPass(const OperationPass &) = default; + OperationPass& operator=(const OperationPass &) = default; /// Support isa/dyn_cast functionality. static bool classof(const Pass *pass) { @@ -380,6 +381,7 @@ template <> class OperationPass : public Pass { protected: OperationPass(TypeID passID) : Pass(passID) {} OperationPass(const OperationPass &) = default; + OperationPass& operator=(const OperationPass &) = default; }; /// NOTICE: This class is deprecated in favor of `OperationPass` @@ -397,6 +399,7 @@ class [[deprecated( : public OperationPass { public: using OperationPass::OperationPass; + FunctionPass& operator=(const FunctionPass &) = default; /// The polymorphic API that runs the pass over the currently held function. virtual void runOnFunction() = 0; diff --git a/mlir/tools/mlir-tblgen/PassGen.cpp b/mlir/tools/mlir-tblgen/PassGen.cpp index 7d98a600519f..ed93d687f3d1 100644 --- a/mlir/tools/mlir-tblgen/PassGen.cpp +++ b/mlir/tools/mlir-tblgen/PassGen.cpp @@ -49,6 +49,10 @@ class {0}Base : public {1} { {0}Base() : {1}(::mlir::TypeID::get()) {{} {0}Base(const {0}Base &other) : {1}(other) {{} + {0}Base& operator=(const {0}Base &other) { + {1}::operator=(other); + return *this; + } /// Returns the command-line argument attached to this pass. static constexpr ::llvm::StringLiteral getArgumentName() { From 343ded9127088584cff90202416ae9d94ee2b654 Mon Sep 17 00:00:00 2001 From: Daria Mityagina Date: Tue, 14 Feb 2023 15:00:58 +0000 Subject: [PATCH 17/19] [OS] - license --- LICENSE | 201 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 201 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 000000000000..261eeb9e9f8b --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. From e318eb76f5e41fcc931bdfb79b94b4d4a4a6abbf Mon Sep 17 00:00:00 2001 From: Daria Mityagina Date: Tue, 14 Feb 2023 19:32:40 +0000 Subject: [PATCH 18/19] [OS] - license - as in original LLVM repo --- LICENSE | 119 ++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 98 insertions(+), 21 deletions(-) diff --git a/LICENSE b/LICENSE index 261eeb9e9f8b..5715176572a4 100644 --- a/LICENSE +++ b/LICENSE @@ -1,10 +1,14 @@ +============================================================================== +The LLVM Project is under the Apache License v2.0 with LLVM Exceptions: +============================================================================== + Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - 1. Definitions. + 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. @@ -63,14 +67,14 @@ on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. - 2. Grant of Copyright License. Subject to the terms and conditions of + 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. - 3. Grant of Patent License. Subject to the terms and conditions of + 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, @@ -86,7 +90,7 @@ granted to You under this License for that Work shall terminate as of the date such litigation is filed. - 4. Redistribution. You may reproduce and distribute copies of the + 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: @@ -127,7 +131,7 @@ reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. - 5. Submission of Contributions. Unless You explicitly state otherwise, + 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. @@ -135,12 +139,12 @@ the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. - 6. Trademarks. This License does not grant permission to use the trade + 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. - 7. Disclaimer of Warranty. Unless required by applicable law or + 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or @@ -150,7 +154,7 @@ appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. - 8. Limitation of Liability. In no event and under no legal theory, + 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be @@ -162,7 +166,7 @@ other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. - 9. Accepting Warranty or Additional Liability. While redistributing + 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this @@ -173,9 +177,9 @@ incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. - END OF TERMS AND CONDITIONS + END OF TERMS AND CONDITIONS - APPENDIX: How to apply the Apache License to your work. + APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" @@ -186,16 +190,89 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright [yyyy] [name of copyright owner] + Copyright [yyyy] [name of copyright owner] - 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 + 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. + 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. + + +---- LLVM Exceptions to the Apache 2.0 License ---- + +As an exception, if, as a result of your compiling your source code, portions +of this Software are embedded into an Object form of such source code, you +may redistribute such embedded portions in such Object form without complying +with the conditions of Sections 4(a), 4(b) and 4(d) of the License. + +In addition, if you combine or link compiled forms of this Software with +software that is licensed under the GPLv2 ("Combined Software") and if a +court of competent jurisdiction determines that the patent provision (Section +3), the indemnity provision (Section 9) or other Section of the License +conflicts with the conditions of the GPLv2, you may retroactively and +prospectively choose to deem waived or otherwise exclude such Section(s) of +the License, but only in their entirety and only with respect to the Combined +Software. + +============================================================================== +Software from third parties included in the LLVM Project: +============================================================================== +The LLVM Project contains third party software which is under different license +terms. All such code will be identified clearly using at least one of two +mechanisms: +1) It will be in a separate directory tree with its own `LICENSE.txt` or + `LICENSE` file at the top containing the specific license and restrictions + which apply to that software, or +2) It will contain specific license and restriction terms at the top of every + file. + +============================================================================== +Legacy LLVM License (https://llvm.org/docs/DeveloperPolicy.html#legacy): +============================================================================== +University of Illinois/NCSA +Open Source License + +Copyright (c) 2003-2019 University of Illinois at Urbana-Champaign. +All rights reserved. + +Developed by: + + LLVM Team + + University of Illinois at Urbana-Champaign + + http://llvm.org + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal with +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimers. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimers in the + documentation and/or other materials provided with the distribution. + + * Neither the names of the LLVM Team, University of Illinois at + Urbana-Champaign, nor the names of its contributors may be used to + endorse or promote products derived from this Software without specific + prior written permission. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE +SOFTWARE. From 394590e71794040b2734f2d26d31b090f930fe2f Mon Sep 17 00:00:00 2001 From: Robert Dower Date: Sun, 12 Feb 2023 19:19:13 -0800 Subject: [PATCH 19/19] add code_of_conduct, contributing agreement, and security.md file --- CODE_OF_CONDUCT.md | 131 +++++++++++++++++++++++++++++++++++++++++++++ CONTRIBUTING.md | 62 ++++++++++++++++++--- security.md | 5 ++ 3 files changed, 191 insertions(+), 7 deletions(-) create mode 100644 CODE_OF_CONDUCT.md create mode 100644 security.md diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 000000000000..58dba18db6db --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,131 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, caste, color, religion, or sexual +identity and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the overall + community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or advances of + any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email address, + without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at +CommunityCodeOfConduct AT intel DOT com. +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series of +actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or permanent +ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within the +community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.1, available at +[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]. + +Community Impact Guidelines were inspired by +[Mozilla's code of conduct enforcement ladder][Mozilla CoC]. + +For answers to common questions about this code of conduct, see the FAQ at +[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at +[https://www.contributor-covenant.org/translations][translations]. + +[homepage]: https://www.contributor-covenant.org +[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html +[Mozilla CoC]: https://github.com/mozilla/diversity +[FAQ]: https://www.contributor-covenant.org/faq diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index bbd4502f8db5..f682f4e4cca9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,9 +1,57 @@ -# Contributing to LLVM +# Contributing -Thank you for your interest in contributing to LLVM! There are many ways to -contribute, and we appreciate all contributions. +### License -To get started with contributing, please take a look at the -[Contributing to LLVM](https://llvm.org/docs/Contributing.html) guide. It -describes how to get involved, raise issues and submit patches. Please note -that at the moment the LLVM project does not use GitHub pull requests. + is licensed under the terms in [LICENSE]. By contributing to the project, you agree to the license and copyright terms therein and release your contribution under these terms. + +### Sign your work + +Please use the sign-off line at the end of the patch. Your signature certifies that you wrote the patch or otherwise have the right to pass it on as an open-source patch. The rules are pretty simple: if you can certify +the below (from [developercertificate.org](http://developercertificate.org/)): + +``` +Developer Certificate of Origin +Version 1.1 + +Copyright (C) 2004, 2006 The Linux Foundation and its contributors. +660 York Street, Suite 102, +San Francisco, CA 94110 USA + +Everyone is permitted to copy and distribute verbatim copies of this +license document, but changing it is not allowed. + +Developer's Certificate of Origin 1.1 + +By making a contribution to this project, I certify that: + +(a) The contribution was created in whole or in part by me and I + have the right to submit it under the open source license + indicated in the file; or + +(b) The contribution is based upon previous work that, to the best + of my knowledge, is covered under an appropriate open source + license and I have the right under that license to submit that + work with modifications, whether created in whole or in part + by me, under the same open source license (unless I am + permitted to submit under a different license), as indicated + in the file; or + +(c) The contribution was provided directly to me by some other + person who certified (a), (b) or (c) and I have not modified + it. + +(d) I understand and agree that this project and the contribution + are public and that a record of the contribution (including all + personal information I submit with it, including my sign-off) is + maintained indefinitely and may be redistributed consistent with + this project or the open source license(s) involved. +``` + +Then you just add a line to every git commit message: + + Signed-off-by: Joe Smith + +Use your real name (sorry, no pseudonyms or anonymous contributions.) + +If you set your `user.name` and `user.email` git configs, you can sign your +commit automatically with `git commit -s`. diff --git a/security.md b/security.md new file mode 100644 index 000000000000..cb59eb8938b1 --- /dev/null +++ b/security.md @@ -0,0 +1,5 @@ +# Security Policy +Intel is committed to rapidly addressing security vulnerabilities affecting our customers and providing clear guidance on the solution, impact, severity and mitigation. + +## Reporting a Vulnerability +Please report any security vulnerabilities in this project utilizing the guidelines [here](https://www.intel.com/content/www/us/en/security-center/vulnerability-handling-guidelines.html).