Emitc
emitc
Dialect to generate C/C++ from MLIR.
The EmitC dialect allows to convert operations from other MLIR dialects to EmitC ops. Those can be translated to C/C++ via the Cpp emitter.
See external documentation.
EmitCIntegerType = IntegerType[Literal[1, 8, 16, 32, 64]]
module-attribute
Type for integer types supported by EmitC. See external documentation.
EmitCIntegerTypeConstr = irdl_to_attr_constraint(EmitCIntegerType)
module-attribute
Constraint for integer types supported by EmitC. See external documentation.
EmitCFloatType = Float16Type | BFloat16Type | Float32Type | Float64Type
module-attribute
EmitCFloatTypeConstr = irdl_to_attr_constraint(EmitCFloatType)
module-attribute
Supported floating-point type in EmitC. See external documentation
EmitCPointerWideType = EmitC_PtrDiffT | EmitC_SignedSizeT | EmitC_SizeT
module-attribute
EmitCPointerWideTypeConstr = irdl_to_attr_constraint(EmitCPointerWideType)
module-attribute
Constraint for pointer-wide types supported by EmitC. These types have the same width as platform-specific pointer types.
EmitCIntegerIndexOpaqueType = EmitCIntegerType | IndexType | EmitC_OpaqueType
module-attribute
EmitCIntegerIndexOpaqueTypeConstr = irdl_to_attr_constraint(EmitCIntegerIndexOpaqueType)
module-attribute
Constraint for integer, index, or opaque types supported by EmitC.
EmitCArrayElementType = EmitCIntegerIndexOpaqueType | EmitCFloatType | EmitCPointerWideType
module-attribute
EmitCArrayElementTypeConstr = irdl_to_attr_constraint(EmitCArrayElementType)
module-attribute
Constraint for valid element types in EmitC arrays.
EmitCArrayElementTypeCovT = TypeVar('EmitCArrayElementTypeCovT', bound=EmitCArrayElementType, covariant=True, default=EmitCArrayElementType)
module-attribute
EmitCTypeConstr = EmitCTypeConstraint()
module-attribute
EmitC = Dialect('emitc', [EmitC_AddOp, EmitC_ApplyOp, EmitC_CallOpaqueOp], [EmitC_ArrayType, EmitC_LValueType, EmitC_OpaqueAttr, EmitC_OpaqueType, EmitC_PointerType, EmitC_PtrDiffT, EmitC_SignedSizeT, EmitC_SizeT])
module-attribute
EmitC_OpaqueType
dataclass
Bases: ParametrizedAttribute, TypeAttribute
EmitC opaque type
Source code in xdsl/dialects/emitc.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 | |
name = 'emitc.opaque'
class-attribute
instance-attribute
value: StringAttr
instance-attribute
verify() -> None
Source code in xdsl/dialects/emitc.py
72 73 74 75 76 77 78 | |
EmitC_PtrDiffT
dataclass
Bases: ParametrizedAttribute, TypeAttribute
EmitC signed pointer diff type.
Signed data type as wide as platform-specific pointer types. In particular, it is as wide as emitc.size_t.
It corresponds to ptrdiff_t found in
Source code in xdsl/dialects/emitc.py
81 82 83 84 85 86 87 88 89 | |
name = 'emitc.ptrdiff_t'
class-attribute
instance-attribute
EmitC_SignedSizeT
dataclass
Bases: ParametrizedAttribute, TypeAttribute
EmitC signed size type.
Data type representing all values of emitc.size_t, plus -1. It corresponds to ssize_t found in
Source code in xdsl/dialects/emitc.py
92 93 94 95 96 97 98 99 100 | |
name = 'emitc.ssize_t'
class-attribute
instance-attribute
EmitC_SizeT
dataclass
Bases: ParametrizedAttribute, TypeAttribute
EmitC unsigned size type.
Unsigned data type as wide as platform-specific pointer types. It corresponds to size_t found in
Source code in xdsl/dialects/emitc.py
103 104 105 106 107 108 109 110 | |
name = 'emitc.size_t'
class-attribute
instance-attribute
EmitC_OpaqueAttr
dataclass
Bases: ParametrizedAttribute
An opaque attribute of which the value gets emitted as is.
Source code in xdsl/dialects/emitc.py
154 155 156 157 158 159 160 161 | |
name = 'emitc.opaque'
class-attribute
instance-attribute
value: StringAttr
instance-attribute
EmitC_ArrayType
Bases: ParametrizedAttribute, TypeAttribute, ShapedType, ContainerType[EmitCArrayElementTypeCovT], Generic[EmitCArrayElementTypeCovT]
EmitC array type
Source code in xdsl/dialects/emitc.py
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | |
name = 'emitc.array'
class-attribute
instance-attribute
shape: ArrayAttr[IntAttr] = param_def(StaticShapeArrayConstr)
class-attribute
instance-attribute
element_type: EmitCArrayElementTypeCovT
instance-attribute
__init__(shape: Iterable[int | IntAttr], element_type: EmitCArrayElementType)
Source code in xdsl/dialects/emitc.py
187 188 189 190 191 192 193 194 195 | |
verify() -> None
Source code in xdsl/dialects/emitc.py
197 198 199 200 201 202 203 204 205 206 207 208 | |
get_num_dims() -> int
Source code in xdsl/dialects/emitc.py
210 211 | |
get_shape() -> tuple[int, ...]
Source code in xdsl/dialects/emitc.py
213 214 | |
get_element_type() -> EmitCArrayElementTypeCovT
Source code in xdsl/dialects/emitc.py
216 217 | |
parse_parameters(parser: AttrParser)
classmethod
Source code in xdsl/dialects/emitc.py
219 220 221 222 223 | |
print_parameters(printer: Printer) -> None
Source code in xdsl/dialects/emitc.py
225 226 227 228 229 230 231 | |
EmitCTypeConstraint
dataclass
Bases: AttrConstraint
Check if a type is supported by EmitC. See MLIR implementation.
Source code in xdsl/dialects/emitc.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | |
verify(attr: Attribute, constraint_context: ConstraintContext) -> None
Source code in xdsl/dialects/emitc.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 | |
mapping_type_vars(type_var_mapping: Mapping[TypeVar, AttrConstraint | IntConstraint]) -> AttrConstraint
Source code in xdsl/dialects/emitc.py
271 272 273 274 275 | |
EmitC_LValueType
dataclass
Bases: ParametrizedAttribute, TypeAttribute
EmitC lvalue type. Values of this type can be assigned to and their address can be taken. See tablegen definition
Source code in xdsl/dialects/emitc.py
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | |
name = 'emitc.lvalue'
class-attribute
instance-attribute
value_type: Attribute = param_def(EmitCTypeConstr)
class-attribute
instance-attribute
verify() -> None
Verify the LValueType. See MLIR implementation
Source code in xdsl/dialects/emitc.py
292 293 294 295 296 297 298 | |
EmitC_PointerType
dataclass
Bases: ParametrizedAttribute, TypeAttribute
EmitC pointer type
Source code in xdsl/dialects/emitc.py
301 302 303 304 305 306 307 308 309 310 | |
name = 'emitc.ptr'
class-attribute
instance-attribute
pointee_type: TypeAttribute
instance-attribute
verify() -> None
Source code in xdsl/dialects/emitc.py
308 309 310 | |
EmitC_BinaryOperation
Bases: IRDLOperation, ABC
Base class for EmitC binary operations.
Source code in xdsl/dialects/emitc.py
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 | |
lhs = operand_def(EmitCTypeConstr)
class-attribute
instance-attribute
rhs = operand_def(EmitCTypeConstr)
class-attribute
instance-attribute
result = result_def(EmitCTypeConstr)
class-attribute
instance-attribute
assembly_format = 'operands attr-dict `:` functional-type(operands, results)'
class-attribute
instance-attribute
__init__(lhs: SSAValue, rhs: SSAValue, result_type: Attribute)
Source code in xdsl/dialects/emitc.py
322 323 324 325 326 327 328 329 330 331 | |
EmitC_AddOp
dataclass
Bases: EmitC_BinaryOperation
Addition operation.
With the emitc.add operation the arithmetic operator + (addition) can
be applied. Supports pointer arithmetic where one operand is a pointer
and the other is an integer or opaque type.
Example:
// Custom form of the addition operation.
%0 = emitc.add %arg0, %arg1 : (i32, i32) -> i32
%1 = emitc.add %arg2, %arg3 : (!emitc.ptr<f32>, i32) -> !emitc.ptr<f32>
// Code emitted for the operations above.
int32_t v5 = v1 + v2;
float* v6 = v3 + v4;
Source code in xdsl/dialects/emitc.py
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 | |
name = 'emitc.add'
class-attribute
instance-attribute
verify_() -> None
Source code in xdsl/dialects/emitc.py
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 | |
EmitC_ApplyOp
dataclass
Bases: IRDLOperation
Apply operation
Source code in xdsl/dialects/emitc.py
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 | |
name = 'emitc.apply'
class-attribute
instance-attribute
assembly_format = '\n $applicableOperator `(` $operand `)` attr-dict `:` functional-type($operand, results)\n '
class-attribute
instance-attribute
applicableOperator = prop_def(StringAttr)
class-attribute
instance-attribute
operand = operand_def(AnyAttr())
class-attribute
instance-attribute
result = result_def(EmitCTypeConstr)
class-attribute
instance-attribute
verify_() -> None
Source code in xdsl/dialects/emitc.py
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 | |
has_side_effects() -> bool
Return True if the operation has side effects.
Source code in xdsl/dialects/emitc.py
423 424 425 | |
EmitC_CallOpaqueOp
Bases: IRDLOperation
The emitc.call_opaque operation represents a C++ function call. The callee can be an arbitrary non-empty string.
The call allows specifying order of operands and attributes in the call as follows:
- integer value of index type refers to an operand;
- attribute which will get lowered to constant value in call;
Source code in xdsl/dialects/emitc.py
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 | |
name = 'emitc.call_opaque'
class-attribute
instance-attribute
callee = prop_def(StringAttr)
class-attribute
instance-attribute
args = opt_prop_def(ArrayAttr)
class-attribute
instance-attribute
template_args = opt_prop_def(ArrayAttr)
class-attribute
instance-attribute
call_args = var_operand_def()
class-attribute
instance-attribute
res = var_result_def()
class-attribute
instance-attribute
irdl_options = (ParsePropInAttrDict(),)
class-attribute
instance-attribute
assembly_format = '$callee `(` $call_args `)` attr-dict `:` functional-type(operands, results)'
class-attribute
instance-attribute
__init__(callee: StringAttr | str, call_args: Sequence[SSAValue], result_types: Sequence[Attribute], args: ArrayAttr[Attribute] | None = None, template_args: ArrayAttr[Attribute] | None = None, attributes: dict[str, Attribute] | None = None)
Source code in xdsl/dialects/emitc.py
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 | |
verify_() -> None
Source code in xdsl/dialects/emitc.py
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 | |