Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID,
case Builtin::BI__builtin_popcountll:
case Builtin::BI__builtin_popcountg:
return emitBuiltinBitOp<cir::BitPopcountOp>(*this, e);

case Builtin::BI__builtin_expect:
case Builtin::BI__builtin_expect_with_probability: {
mlir::Value argValue = emitScalarExpr(e->getArg(0));
Expand Down
7 changes: 6 additions & 1 deletion mlir/include/mlir/IR/EnumAttr.td
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class IntEnumAttrCaseBase<I intType, string sym, string strVal, int intVal> :
let predicate = CPred<[{
::llvm::cast<::mlir::IntegerAttr>($_self).getValue().eq(::llvm::APInt(}]
# intType.bitwidth # ", "
# intVal #
# intVal #
"))">;
}

Expand Down Expand Up @@ -495,6 +495,11 @@ class EnumParameter<EnumInfo enumInfo>
!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
// parameter `value` whose type is the C++ enum class.
//
Expand Down
2 changes: 1 addition & 1 deletion mlir/test/lib/Dialect/Test/TestAttributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include <tuple>

#include "TestEnums.h"
#include "TestTraits.h"
#include "mlir/Dialect/Ptr/IR/MemorySpaceInterfaces.h"
#include "mlir/Dialect/Utils/StructuredOpsUtils.h"
Expand All @@ -27,7 +28,6 @@

// generated files require above includes to come first
#include "TestAttrInterfaces.h.inc"
#include "TestOpEnums.h.inc"

namespace test {
class TestDialect;
Expand Down
11 changes: 11 additions & 0 deletions mlir/test/lib/Dialect/Test/TestEnumDefs.td
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,15 @@ def MultiResultOpEnum: I64EnumAttr<
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
20 changes: 20 additions & 0 deletions mlir/test/lib/Dialect/Test/TestEnums.h
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions mlir/test/lib/Dialect/Test/TestTypeDefs.td
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// To get the test dialect def.
include "TestDialect.td"
include "TestAttrDefs.td"
include "TestEnumDefs.td"
include "TestInterfaces.td"
include "mlir/IR/BuiltinTypes.td"
include "mlir/Interfaces/DataLayoutInterfaces.td"
Expand Down Expand Up @@ -286,6 +287,15 @@ def TestTypeOptionalGroupStruct : Test_Type<"TestTypeOptionalGroupStruct"> {
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"> {
let parameters = (ins "int":$a, "int":$b);
let mnemonic = "spaces";
Expand Down
1 change: 1 addition & 0 deletions mlir/test/lib/Dialect/Test/TestTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <optional>
#include <tuple>

#include "TestEnums.h"
#include "TestTraits.h"
#include "mlir/Dialect/Bufferization/IR/BufferizationTypeInterfaces.h"
#include "mlir/IR/Diagnostics.h"
Expand Down
4 changes: 4 additions & 0 deletions mlir/test/mlir-tblgen/attr-or-type-format-roundtrip.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ attributes {
// CHECK: !test.optional_type_string
// CHECK: !test.optional_type_string<"non default">
// 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(
!test.no_parser<255, [1, 2, 3, 4, 5], "foobar", 4>
Expand Down Expand Up @@ -120,4 +122,6 @@ func.func private @test_roundtrip_default_parsers_struct(
!test.optional_type_string<"default">,
!test.optional_type_string<"non default">,
!test.optional_type_string<"containing\n \"escape\" characters\0f">
!test.default_enum_parameter,
!test.default_enum_parameter<"non_default">,
)
Loading