[clang] [CIR] Reformat Ops to use common `CIR_` prefix and definition traits style (PR #148865)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 15 08:18:23 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clangir
Author: Henrich Lauko (xlauko)
<details>
<summary>Changes</summary>
- This adds common CIR_ prefix to all operation disambiguating them when used with other dialects.
- Unifies traits style in operation definitions.
This mirrors incubator changes from https://github.com/llvm/clangir/pull/1741
---
Patch is 34.97 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/148865.diff
1 Files Affected:
- (modified) clang/include/clang/CIR/Dialect/IR/CIROps.td (+179-142)
``````````diff
diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index 676ff76dff661..2ce23dbb27ec6 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -159,9 +159,9 @@ def CIR_CastKind : CIR_I32EnumAttr<"CastKind", "cast kind", [
I32EnumAttrCase<"bool_to_float", 1000>,
]>;
-def CastOp : CIR_Op<"cast",
- [Pure,
- DeclareOpInterfaceMethods<PromotableOpInterface>]> {
+def CIR_CastOp : CIR_Op<"cast", [
+ Pure, DeclareOpInterfaceMethods<PromotableOpInterface>
+]> {
// FIXME: not all conversions are free of side effects.
let summary = "Conversion between values of different types";
let description = [{
@@ -225,8 +225,9 @@ def CastOp : CIR_Op<"cast",
// PtrStrideOp
//===----------------------------------------------------------------------===//
-def PtrStrideOp : CIR_Op<"ptr_stride",
- [Pure, AllTypesMatch<["base", "result"]>]> {
+def CIR_PtrStrideOp : CIR_Op<"ptr_stride", [
+ Pure, AllTypesMatch<["base", "result"]>
+]> {
let summary = "Pointer access with stride";
let description = [{
Given a base pointer as first operand, provides a new pointer after applying
@@ -262,8 +263,9 @@ def PtrStrideOp : CIR_Op<"ptr_stride",
// ConstantOp
//===----------------------------------------------------------------------===//
-def ConstantOp : CIR_Op<"const",
- [ConstantLike, Pure, AllTypesMatch<["value", "res"]>]> {
+def CIR_ConstantOp : CIR_Op<"const", [
+ ConstantLike, Pure, AllTypesMatch<["value", "res"]>
+]> {
let summary = "Defines a CIR constant";
let description = [{
The `cir.const` operation turns a literal into an SSA value. The data is
@@ -298,22 +300,23 @@ def ConstantOp : CIR_Op<"const",
// AllocaOp
//===----------------------------------------------------------------------===//
-class AllocaTypesMatchWith<string summary, string lhsArg, string rhsArg,
- string transform, string comparator = "std::equal_to<>()">
- : PredOpTrait<summary, CPred<
- comparator # "(" #
+class CIR_AllocaTypesMatchWith<
+ string summary, string lhsArg, string rhsArg, string transform,
+ string comparator = "std::equal_to<>()"
+> : PredOpTrait<summary, CPred<comparator # "(" #
!subst("$_self", "$" # lhsArg # ".getType()", transform) #
- ", $" # rhsArg # ")">> {
+ ", $" # rhsArg # ")">
+> {
string lhs = lhsArg;
string rhs = rhsArg;
string transformer = transform;
}
-def AllocaOp : CIR_Op<"alloca", [
- AllocaTypesMatchWith<"'allocaType' matches pointee type of 'addr'",
- "addr", "allocaType",
- "cast<PointerType>($_self).getPointee()">,
- DeclareOpInterfaceMethods<PromotableAllocationOpInterface>]> {
+def CIR_AllocaOp : CIR_Op<"alloca", [
+ CIR_AllocaTypesMatchWith<"'allocaType' matches pointee type of 'addr'",
+ "addr", "allocaType", "mlir::cast<cir::PointerType>($_self).getPointee()">,
+ DeclareOpInterfaceMethods<PromotableAllocationOpInterface>
+]> {
let summary = "Defines a scope-local variable";
let description = [{
The `cir.alloca` operation defines a scope-local variable.
@@ -374,12 +377,11 @@ def AllocaOp : CIR_Op<"alloca", [
// LoadOp
//===----------------------------------------------------------------------===//
-def LoadOp : CIR_Op<"load", [
+def CIR_LoadOp : CIR_Op<"load", [
TypesMatchWith<"type of 'result' matches pointee type of 'addr'",
- "addr", "result",
- "cast<PointerType>($_self).getPointee()">,
- DeclareOpInterfaceMethods<PromotableMemOpInterface>]> {
-
+ "addr", "result", "mlir::cast<cir::PointerType>($_self).getPointee()">,
+ DeclareOpInterfaceMethods<PromotableMemOpInterface>
+]> {
let summary = "Load value from memory adddress";
let description = [{
`cir.load` reads a value (lvalue to rvalue conversion) given an address
@@ -420,12 +422,11 @@ def LoadOp : CIR_Op<"load", [
// StoreOp
//===----------------------------------------------------------------------===//
-def StoreOp : CIR_Op<"store", [
+def CIR_StoreOp : CIR_Op<"store", [
TypesMatchWith<"type of 'value' matches pointee type of 'addr'",
- "addr", "value",
- "cast<PointerType>($_self).getPointee()">,
- DeclareOpInterfaceMethods<PromotableMemOpInterface>]> {
-
+ "addr", "value", "mlir::cast<cir::PointerType>($_self).getPointee()">,
+ DeclareOpInterfaceMethods<PromotableMemOpInterface>
+]> {
let summary = "Store value to memory address";
let description = [{
`cir.store` stores a value (first operand) to the memory address specified
@@ -461,10 +462,14 @@ def StoreOp : CIR_Op<"store", [
// ReturnOp
//===----------------------------------------------------------------------===//
-def ReturnOp : CIR_Op<"return", [ParentOneOf<["FuncOp", "ScopeOp", "IfOp",
- "SwitchOp", "DoWhileOp","WhileOp",
- "ForOp", "CaseOp"]>,
- Terminator]> {
+defvar CIR_ReturnableScopes = [
+ "FuncOp", "ScopeOp", "IfOp", "SwitchOp", "CaseOp",
+ "DoWhileOp", "WhileOp", "ForOp"
+];
+
+def CIR_ReturnOp : CIR_Op<"return", [
+ ParentOneOf<CIR_ReturnableScopes>, Terminator
+]> {
let summary = "Return from function";
let description = [{
The "return" operation represents a return operation within a function.
@@ -504,10 +509,10 @@ def ReturnOp : CIR_Op<"return", [ParentOneOf<["FuncOp", "ScopeOp", "IfOp",
// IfOp
//===----------------------------------------------------------------------===//
-def IfOp : CIR_Op<"if",
- [DeclareOpInterfaceMethods<RegionBranchOpInterface>,
- RecursivelySpeculatable, AutomaticAllocationScope, NoRegionArguments]>{
-
+def CIR_IfOp : CIR_Op<"if", [
+ DeclareOpInterfaceMethods<RegionBranchOpInterface>,
+ RecursivelySpeculatable, AutomaticAllocationScope, NoRegionArguments
+]> {
let summary = "the if-then-else operation";
let description = [{
The `cir.if` operation represents an if-then-else construct for
@@ -555,10 +560,11 @@ def IfOp : CIR_Op<"if",
// ConditionOp
//===----------------------------------------------------------------------===//
-def ConditionOp : CIR_Op<"condition", [
+def CIR_ConditionOp : CIR_Op<"condition", [
Terminator,
- DeclareOpInterfaceMethods<RegionBranchTerminatorOpInterface,
- ["getSuccessorRegions"]>
+ DeclareOpInterfaceMethods<RegionBranchTerminatorOpInterface, [
+ "getSuccessorRegions"
+ ]>
]> {
let summary = "Loop continuation condition.";
let description = [{
@@ -600,10 +606,14 @@ def ConditionOp : CIR_Op<"condition", [
// YieldOp
//===----------------------------------------------------------------------===//
-def YieldOp : CIR_Op<"yield", [ReturnLike, Terminator,
- ParentOneOf<["CaseOp", "DoWhileOp", "ForOp",
- "IfOp", "ScopeOp", "SwitchOp",
- "TernaryOp", "WhileOp"]>]> {
+defvar CIR_YieldableScopes = [
+ "CaseOp", "DoWhileOp", "ForOp", "IfOp", "ScopeOp", "SwitchOp",
+ "TernaryOp", "WhileOp"
+];
+
+def CIR_YieldOp : CIR_Op<"yield", [
+ ReturnLike, Terminator, ParentOneOf<CIR_YieldableScopes>
+]> {
let summary = "Represents the default branching behaviour of a region";
let description = [{
The `cir.yield` operation terminates regions on different CIR operations,
@@ -663,7 +673,7 @@ def YieldOp : CIR_Op<"yield", [ReturnLike, Terminator,
// BreakOp
//===----------------------------------------------------------------------===//
-def BreakOp : CIR_Op<"break", [Terminator]> {
+def CIR_BreakOp : CIR_Op<"break", [Terminator]> {
let summary = "C/C++ `break` statement equivalent";
let description = [{
The `cir.break` operation is used to cease the execution of the current loop
@@ -678,7 +688,7 @@ def BreakOp : CIR_Op<"break", [Terminator]> {
// ContinueOp
//===----------------------------------------------------------------------===//
-def ContinueOp : CIR_Op<"continue", [Terminator]> {
+def CIR_ContinueOp : CIR_Op<"continue", [Terminator]> {
let summary = "C/C++ `continue` statement equivalent";
let description = [{
The `cir.continue` operation is used to end execution of the current
@@ -693,9 +703,10 @@ def ContinueOp : CIR_Op<"continue", [Terminator]> {
// ScopeOp
//===----------------------------------------------------------------------===//
-def ScopeOp : CIR_Op<"scope", [
- DeclareOpInterfaceMethods<RegionBranchOpInterface>,
- RecursivelySpeculatable, AutomaticAllocationScope, NoRegionArguments]> {
+def CIR_ScopeOp : CIR_Op<"scope", [
+ DeclareOpInterfaceMethods<RegionBranchOpInterface>,
+ RecursivelySpeculatable, AutomaticAllocationScope, NoRegionArguments
+]> {
let summary = "Represents a C/C++ scope";
let description = [{
`cir.scope` contains one region and defines a strict "scope" for all new
@@ -757,9 +768,10 @@ def CIR_CaseOpKind : CIR_I32EnumAttr<"CaseOpKind", "case kind", [
I32EnumAttrCase<"Range", 3, "range">
]>;
-def CaseOp : CIR_Op<"case", [
- DeclareOpInterfaceMethods<RegionBranchOpInterface>,
- RecursivelySpeculatable, AutomaticAllocationScope]> {
+def CIR_CaseOp : CIR_Op<"case", [
+ DeclareOpInterfaceMethods<RegionBranchOpInterface>,
+ RecursivelySpeculatable, AutomaticAllocationScope
+]> {
let summary = "Case operation";
let description = [{
The `cir.case` operation represents a case within a C/C++ switch.
@@ -791,10 +803,11 @@ def CaseOp : CIR_Op<"case", [
];
}
-def SwitchOp : CIR_Op<"switch",
- [SameVariadicOperandSize,
- DeclareOpInterfaceMethods<RegionBranchOpInterface>,
- RecursivelySpeculatable, AutomaticAllocationScope, NoRegionArguments]> {
+def CIR_SwitchOp : CIR_Op<"switch", [
+ SameVariadicOperandSize,
+ DeclareOpInterfaceMethods<RegionBranchOpInterface>,
+ RecursivelySpeculatable, AutomaticAllocationScope, NoRegionArguments
+]> {
let summary = "Switch operation";
let description = [{
The `cir.switch` operation represents C/C++ switch functionality for
@@ -959,8 +972,10 @@ def SwitchOp : CIR_Op<"switch",
// SwitchFlatOp
//===----------------------------------------------------------------------===//
-def SwitchFlatOp : CIR_Op<"switch.flat", [AttrSizedOperandSegments,
- Terminator]> {
+def CIR_SwitchFlatOp : CIR_Op<"switch.flat", [
+ AttrSizedOperandSegments, Terminator
+]> {
+ let summary = "A flattened version of cir.switch";
let description = [{
The `cir.switch.flat` operation is a region-less and simplified
@@ -1005,9 +1020,10 @@ def SwitchFlatOp : CIR_Op<"switch.flat", [AttrSizedOperandSegments,
// BrOp
//===----------------------------------------------------------------------===//
-def BrOp : CIR_Op<"br",
- [DeclareOpInterfaceMethods<BranchOpInterface, ["getSuccessorForOperands"]>,
- Pure, Terminator]> {
+def CIR_BrOp : CIR_Op<"br",[
+ DeclareOpInterfaceMethods<BranchOpInterface, ["getSuccessorForOperands"]>,
+ Pure, Terminator
+]> {
let summary = "Unconditional branch";
let description = [{
The `cir.br` branches unconditionally to a block. Used to represent C/C++
@@ -1053,7 +1069,7 @@ def CIR_UnaryOpKind : CIR_I32EnumAttr<"UnaryOpKind", "unary operation kind", [
I32EnumAttrCase<"Not", 4, "not">
]>;
-def UnaryOp : CIR_Op<"unary", [Pure, SameOperandsAndResultType]> {
+def CIR_UnaryOp : CIR_Op<"unary", [Pure, SameOperandsAndResultType]> {
let summary = "Unary operations";
let description = [{
`cir.unary` performs the unary operation according to
@@ -1093,9 +1109,10 @@ def UnaryOp : CIR_Op<"unary", [Pure, SameOperandsAndResultType]> {
// BrCondOp
//===----------------------------------------------------------------------===//
-def BrCondOp : CIR_Op<"brcond",
- [DeclareOpInterfaceMethods<BranchOpInterface, ["getSuccessorForOperands"]>,
- Pure, Terminator, AttrSizedOperandSegments]> {
+def CIR_BrCondOp : CIR_Op<"brcond", [
+ DeclareOpInterfaceMethods<BranchOpInterface, ["getSuccessorForOperands"]>,
+ Pure, Terminator, AttrSizedOperandSegments
+]> {
let summary = "Conditional branch";
let description = [{
The `cir.brcond %cond, ^bb0, ^bb1` branches to 'bb0' block in case
@@ -1140,9 +1157,8 @@ def BrCondOp : CIR_Op<"brcond",
// Common loop op definitions
//===----------------------------------------------------------------------===//
-class LoopOpBase<string mnemonic> : CIR_Op<mnemonic, [
- LoopOpInterface,
- NoRegionArguments,
+class CIR_LoopOpBase<string mnemonic> : CIR_Op<mnemonic, [
+ LoopOpInterface, NoRegionArguments
]> {
let extraClassDefinition = [{
void $cppClass::getSuccessorRegions(
@@ -1160,7 +1176,7 @@ class LoopOpBase<string mnemonic> : CIR_Op<mnemonic, [
// While & DoWhileOp
//===----------------------------------------------------------------------===//
-class WhileOpBase<string mnemonic> : LoopOpBase<mnemonic> {
+class CIR_WhileOpBase<string mnemonic> : CIR_LoopOpBase<mnemonic> {
defvar isWhile = !eq(mnemonic, "while");
let summary = "C/C++ " # !if(isWhile, "while", "do-while") # " loop";
let builders = [
@@ -1180,7 +1196,7 @@ class WhileOpBase<string mnemonic> : LoopOpBase<mnemonic> {
];
}
-def WhileOp : WhileOpBase<"while"> {
+def CIR_WhileOp : CIR_WhileOpBase<"while"> {
let regions = (region SizedRegion<1>:$cond, MinSizedRegion<1>:$body);
let assemblyFormat = "$cond `do` $body attr-dict";
@@ -1205,7 +1221,7 @@ def WhileOp : WhileOpBase<"while"> {
}];
}
-def DoWhileOp : WhileOpBase<"do"> {
+def CIR_DoWhileOp : CIR_WhileOpBase<"do"> {
let regions = (region MinSizedRegion<1>:$body, SizedRegion<1>:$cond);
let assemblyFormat = " $body `while` $cond attr-dict";
@@ -1235,7 +1251,7 @@ def DoWhileOp : WhileOpBase<"do"> {
// ForOp
//===----------------------------------------------------------------------===//
-def ForOp : LoopOpBase<"for"> {
+def CIR_ForOp : CIR_LoopOpBase<"for"> {
let summary = "C/C++ for loop counterpart";
let description = [{
Represents a C/C++ for loop. It consists of three regions:
@@ -1311,8 +1327,7 @@ def CIR_CmpOpKind : CIR_I32EnumAttr<"CmpOpKind", "compare operation kind", [
I32EnumAttrCase<"ne", 5>
]>;
-def CmpOp : CIR_Op<"cmp", [Pure, SameTypeOperands]> {
-
+def CIR_CmpOp : CIR_Op<"cmp", [Pure, SameTypeOperands]> {
let summary = "Compare values two values and produce a boolean result";
let description = [{
`cir.cmp` compares two input operands of the same type and produces a
@@ -1355,9 +1370,9 @@ def CIR_BinOpKind : CIR_I32EnumAttr<
I32EnumAttrCase<"Max", 8, "max">
]>;
-def BinOp : CIR_Op<"binop", [Pure,
- SameTypeOperands, SameOperandsAndResultType]> {
-
+def CIR_BinOp : CIR_Op<"binop", [
+ Pure, SameTypeOperands, SameOperandsAndResultType
+]> {
let summary = "Binary operations (arith and logic)";
let description = [{
cir.binop performs the binary operation according to
@@ -1411,7 +1426,7 @@ def BinOp : CIR_Op<"binop", [Pure,
// ShiftOp
//===----------------------------------------------------------------------===//
-def ShiftOp : CIR_Op<"shift", [Pure]> {
+def CIR_ShiftOp : CIR_Op<"shift", [Pure]> {
let summary = "Shift";
let description = [{
The `cir.shift` operation performs a bitwise shift, either to the left or to
@@ -1452,8 +1467,9 @@ def ShiftOp : CIR_Op<"shift", [Pure]> {
// SelectOp
//===----------------------------------------------------------------------===//
-def SelectOp : CIR_Op<"select", [Pure,
- AllTypesMatch<["true_value", "false_value", "result"]>]> {
+def CIR_SelectOp : CIR_Op<"select", [
+ Pure, AllTypesMatch<["true_value", "false_value", "result"]>
+]> {
let summary = "Yield one of two values based on a boolean value";
let description = [{
The `cir.select` operation takes three operands. The first operand
@@ -1492,9 +1508,10 @@ def SelectOp : CIR_Op<"select", [Pure,
// TernaryOp
//===----------------------------------------------------------------------===//
-def TernaryOp : CIR_Op<"ternary",
- [DeclareOpInterfaceMethods<RegionBranchOpInterface>,
- RecursivelySpeculatable, AutomaticAllocationScope, NoRegionArguments]> {
+def CIR_TernaryOp : CIR_Op<"ternary", [
+ DeclareOpInterfaceMethods<RegionBranchOpInterface>,
+ RecursivelySpeculatable, AutomaticAllocationScope, NoRegionArguments
+]> {
let summary = "The `cond ? a : b` C/C++ ternary operation";
let description = [{
The `cir.ternary` operation represents C/C++ ternary, much like a `select`
@@ -1583,8 +1600,9 @@ def CIR_GlobalLinkageKind : CIR_I32EnumAttr<
// properties of a global variable will be added over time as more of ClangIR
// is upstreamed.
-def GlobalOp : CIR_Op<"global",
- [DeclareOpInterfaceMethods<CIRGlobalValueInterface>]> {
+def CIR_GlobalOp : CIR_Op<"global", [
+ DeclareOpInterfaceMethods<CIRGlobalValueInterface>
+]> {
let summary = "Declare or define a global variable";
let description = [{
The `cir.global` operation declares or defines a named global variable.
@@ -1645,8 +1663,9 @@ def GlobalOp : CIR_Op<"global",
// GetGlobalOp
//===----------------------------------------------------------------------===//
-def GetGlobalOp : CIR_Op<"get_global",
- [Pure, DeclareOpInterfaceMethods<SymbolUserOpInterface>]> {
+def CIR_GetGlobalOp : CIR_Op<"get_global", [
+ Pure, DeclareOpInterfaceMethods<SymbolUserOpInterface>
+]> {
let summary = "Get the address of a global variable";
let description = [{
The `cir.get_global` operation retrieves the address pointing to a
@@ -1673,7 +1692,7 @@ def GetGlobalOp : CIR_Op<"get_global",
// SetBitfieldOp
//===----------------------------------------------------------------------===//
-def SetBitfieldOp : CIR_Op<"set_bitfield"> {
+def CIR_SetBitfieldOp : CIR_Op<"set_bitfield"> {
let summary = "Set the value of a bitfield member";
let description = [{
The `cir.set_bitfield` operation provides a store-like access to
@@ -1761,7 +1780,7 @@ def SetBitfieldOp : CIR_Op<"set_bitfield"> {
// GetBitfieldOp
//===----------------------------------------------------------------------===//
-def GetBitfieldOp : CIR_Op<"get_bitfield"> {
+def CIR_GetBitfieldOp : CIR_Op<"get_bitfield"> {
let summary = "Get the information for a bitfield member";
let description = [{
The `cir.get_bitfield` operation provides a load-like access to
@@ -1843,7 +1862,7 @@ def GetBitfieldOp : CIR_Op<"get_bitfield"> {
// GetMemberOp
//===----------------------------------------------------------------------===//
-def GetMemberOp : CIR_Op<"get_member"> {
+def CIR_GetMemberOp : CIR_Op<"get_member"> {
let summary = "Get the address of a member of a record";
let description = [{
The `cir.get_member` operation gets the address of a particular named
@@ -1905,7 +1924,7 @@ def GetMemberOp : CIR_Op<"get_member"> {
// TODO(CIR): FuncOp is still a tiny shell of what it will become. Many more
// properties and attributes will be added as upstreaming continues.
-def FuncOp : CIR_Op<"func", [
+def CIR_FuncOp : CIR_Op<"func", [
AutomaticAllocationScope, CallableOpInterface, FunctionOpInterface,
DeclareOpInterfaceMethods<CIRGlobalValueInterface>,
IsolatedFromAbove
@@ -2029,10 +2048,10 @@ def CIR_SideEffect : CIR_I32EnumAttr<
}
class CIR_CallOpBase<string mnemonic, list<Trait> extra_traits = []>
- : Op<CIR_Dialect, mnemonic,
- !listconcat(extra_traits,
- [DeclareOpInterfaceMethods<CIRCallOpInterface>,
- DeclareOpInterfaceMethods<SymbolUserOpInterface>])> {
+ : CIR_Op<mnemonic, !listconcat(extra_traits, [
+ DeclareOpInterfaceMethods<CIRCallOpInterface>,
+ DeclareOpInterfaceMethods<SymbolUserOpInterface>
+ ])> {
let extraClassDeclaration = [{
/// Get the argument operands to the called function.
mlir::OperandRange getArgOperands();
@@ -2086,7 +2105,7 @@ class CIR_CallOpBase<string mnemonic, list<Trait> extra_traits = []>
DefaultValuedAttr<CIR_SideEffect, "SideEffect::All">:$side_effect);
}
-def CallOp : CIR_CallOpBase<"call", [NoRegionArguments]> {
+def CIR_CallOp : CIR_CallOpBase<"call", [NoRegionArguments]> {
let summary = "call a func...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/148865
More information about the cfe-commits
mailing list