This commit is contained in:
xlauko 2025-07-15 14:17:46 +02:00
parent 7f27482a32
commit 4b75153b65
No known key found for this signature in database
8 changed files with 53 additions and 3 deletions

View File

@ -256,7 +256,6 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID,
case Builtin::BI__builtin_popcountll: case Builtin::BI__builtin_popcountll:
case Builtin::BI__builtin_popcountg: case Builtin::BI__builtin_popcountg:
return emitBuiltinBitOp<cir::BitPopcountOp>(*this, e); return emitBuiltinBitOp<cir::BitPopcountOp>(*this, e);
case Builtin::BI__builtin_expect: case Builtin::BI__builtin_expect:
case Builtin::BI__builtin_expect_with_probability: { case Builtin::BI__builtin_expect_with_probability: {
mlir::Value argValue = emitScalarExpr(e->getArg(0)); mlir::Value argValue = emitScalarExpr(e->getArg(0));

View File

@ -495,6 +495,11 @@ class EnumParameter<EnumInfo enumInfo>
!cast<EnumAttrInfo>(enumInfo).parameterPrinter, ?); !cast<EnumAttrInfo>(enumInfo).parameterPrinter, ?);
} }
class DefaultValuedEnumParameter<EnumInfo enumInfo, EnumCase value>
: EnumParameter<enumInfo> {
let defaultValue = enumInfo.cppType # "::" # value.symbol;
}
// An attribute backed by a C++ enum. The attribute contains a single // An attribute backed by a C++ enum. The attribute contains a single
// parameter `value` whose type is the C++ enum class. // parameter `value` whose type is the C++ enum class.
// //

View File

@ -16,6 +16,7 @@
#include <tuple> #include <tuple>
#include "TestEnums.h"
#include "TestTraits.h" #include "TestTraits.h"
#include "mlir/Dialect/Ptr/IR/MemorySpaceInterfaces.h" #include "mlir/Dialect/Ptr/IR/MemorySpaceInterfaces.h"
#include "mlir/Dialect/Utils/StructuredOpsUtils.h" #include "mlir/Dialect/Utils/StructuredOpsUtils.h"
@ -27,7 +28,6 @@
// generated files require above includes to come first // generated files require above includes to come first
#include "TestAttrInterfaces.h.inc" #include "TestAttrInterfaces.h.inc"
#include "TestOpEnums.h.inc"
namespace test { namespace test {
class TestDialect; class TestDialect;

View File

@ -96,4 +96,15 @@ def MultiResultOpEnum: I64EnumAttr<
MultiResultOpKind4, MultiResultOpKind5, MultiResultOpKind6 MultiResultOpKind4, MultiResultOpKind5, MultiResultOpKind6
]>; ]>;
//===----------------------------------------------------------------------===//
// Test Enum with Default Value
//===----------------------------------------------------------------------===//
def TestDefaultCase : I32EnumAttrCase<"Default", 0, "default">;
def NonDefaultCase : I32EnumAttrCase<"NonDefault", 1, "non_default">;
def TestDefaultValuedEnum : I32Enum<"TestDefaultValuedEnum", "", [
TestDefaultCase, NonDefaultCase
]>;
#endif // TEST_ENUMDEFS #endif // TEST_ENUMDEFS

View File

@ -0,0 +1,20 @@
//===----------------------------------------------------------------------===//
//
// 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 contains enum definitions for the Test dialect
//
//===----------------------------------------------------------------------===//
#ifndef MLIR_TESTENUMS_H
#define MLIR_TESTENUMS_H
#include "mlir/IR/BuiltinAttributes.h"
#include "TestOpEnums.h.inc"
#endif // MLIR_TESTENUMS_H

View File

@ -16,6 +16,7 @@
// To get the test dialect def. // To get the test dialect def.
include "TestDialect.td" include "TestDialect.td"
include "TestAttrDefs.td" include "TestAttrDefs.td"
include "TestEnumDefs.td"
include "TestInterfaces.td" include "TestInterfaces.td"
include "mlir/IR/BuiltinTypes.td" include "mlir/IR/BuiltinTypes.td"
include "mlir/Interfaces/DataLayoutInterfaces.td" include "mlir/Interfaces/DataLayoutInterfaces.td"
@ -286,6 +287,15 @@ def TestTypeOptionalGroupStruct : Test_Type<"TestTypeOptionalGroupStruct"> {
let assemblyFormat = "`<` (`(` struct(params)^ `)`) : (`x`)? `>`"; let assemblyFormat = "`<` (`(` struct(params)^ `)`) : (`x`)? `>`";
} }
def TestTypeDefaultEnumParameter
: Test_Type<"TestTypeDefaultEnumParameter"> {
let parameters = (ins
DefaultValuedEnumParameter<TestDefaultValuedEnum, TestDefaultCase>:$a
);
let mnemonic = "default_enum_parameter";
let assemblyFormat = "`<` $a `>`";
}
def TestTypeSpaces : Test_Type<"TestTypeSpaceS"> { def TestTypeSpaces : Test_Type<"TestTypeSpaceS"> {
let parameters = (ins "int":$a, "int":$b); let parameters = (ins "int":$a, "int":$b);
let mnemonic = "spaces"; let mnemonic = "spaces";

View File

@ -17,6 +17,7 @@
#include <optional> #include <optional>
#include <tuple> #include <tuple>
#include "TestEnums.h"
#include "TestTraits.h" #include "TestTraits.h"
#include "mlir/Dialect/Bufferization/IR/BufferizationTypeInterfaces.h" #include "mlir/Dialect/Bufferization/IR/BufferizationTypeInterfaces.h"
#include "mlir/IR/Diagnostics.h" #include "mlir/IR/Diagnostics.h"

View File

@ -77,6 +77,8 @@ attributes {
// CHECK: !test.optional_type_string // CHECK: !test.optional_type_string
// CHECK: !test.optional_type_string<"non default"> // CHECK: !test.optional_type_string<"non default">
// CHECK: !test.optional_type_string<"containing\0A \22escape\22 characters\0F"> // CHECK: !test.optional_type_string<"containing\0A \22escape\22 characters\0F">
// CHECK: !test.default_enum_parameter
// CHECK: !test.default_enum_parameter<"non_default">
func.func private @test_roundtrip_default_parsers_struct( func.func private @test_roundtrip_default_parsers_struct(
!test.no_parser<255, [1, 2, 3, 4, 5], "foobar", 4> !test.no_parser<255, [1, 2, 3, 4, 5], "foobar", 4>
@ -120,4 +122,6 @@ func.func private @test_roundtrip_default_parsers_struct(
!test.optional_type_string<"default">, !test.optional_type_string<"default">,
!test.optional_type_string<"non default">, !test.optional_type_string<"non default">,
!test.optional_type_string<"containing\n \"escape\" characters\0f"> !test.optional_type_string<"containing\n \"escape\" characters\0f">
!test.default_enum_parameter,
!test.default_enum_parameter<"non_default">,
) )