diff --git a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVCLOps.td b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVCLOps.td --- a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVCLOps.td +++ b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVCLOps.td @@ -73,6 +73,14 @@ let hasVerifier = 0; } +// Base class for OpenCL misc ops. +class SPIRV_CLMiscOp traits = []> : + SPIRV_CLOp { + + let hasVerifier = 0; +} + // Base class for OpenCL Binary arithmetic ops where operand types and // return type matches. class SPIRV_CLBinaryArithmeticOp { + let summary = [{ + The printf extended instruction writes output to an implementation- + defined stream such as stdout under control of the string pointed to by + format that specifies how subsequent arguments are converted for output. + If there are insufficient arguments for the format, the behavior is + undefined. If the format is exhausted while arguments remain, the excess + arguments are evaluated (as always) but are otherwise ignored. The + printf instruction returns when the end of the format string is + encountered + }]; + + let description = [{ + printf returns 0 if it was executed successfully and -1 otherwise + + Result Type must be i32. + + format must be a pointer(constant) to i8. + + + + ``` + [TODO] + ``` + + #### Example: + + ```mlir + # TODO - add rest of definitions + # %ptr = OpTypePointer UniformConstant %uchar + # %0 = OpInBoundsPtrAccessChain + # %1 = OpConstant + # %2 = OpConstant + + %2 = spirv.CL.printf %0 %1 %2 : (!spirv.ptr, (i32, i32)) -> i32 + + ``` + }]; + + let arguments = (ins + SPIRV_AnyPtr:$format, + Variadic:$arguments + ); + + let results = (outs + SPIRV_ScalarOrVectorOf:$result + ); + + let assemblyFormat = [{ + $format `,` $arguments attr-dict `:` `(` type($format) `,` `(` type($arguments) `)` `)` `->` type($result) + }]; + + let hasVerifier = 0; +} #endif // MLIR_DIALECT_SPIRV_IR_CL_OPS diff --git a/mlir/test/Dialect/SPIRV/IR/ocl-ops.mlir b/mlir/test/Dialect/SPIRV/IR/ocl-ops.mlir --- a/mlir/test/Dialect/SPIRV/IR/ocl-ops.mlir +++ b/mlir/test/Dialect/SPIRV/IR/ocl-ops.mlir @@ -247,3 +247,24 @@ %0 = spirv.CL.rint %arg0 : vector<3xf16> return } + +// ----- + +//===----------------------------------------------------------------------===// +// spirv.CL.printf +//===----------------------------------------------------------------------===// + +// spirv.GlobalVariable @global_var : !spirv.ptr + +func.func @printf(%ptr : !spirv.ptr, %arg1 : i32) -> () { + // CHECK: spirv.CL.printf {{%.*}}, {{%.*}} : i32 + %0 = spirv.CL.printf %ptr, %arg1 : i32 + return +} + +func.func @printf(%ptr : !spirv.ptr, %arg1 : i32) -> () { + // expected-error @+1 {{op operand #0 must be pointr to constant i8}} + %0 = spirv.CL.printf %ptr, %arg1 : i32 + return +} +