File tree 3 files changed +33
-2
lines changed
3 files changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -2404,3 +2404,7 @@ extern "C" void dump_operation(Operation *op, const char *filename) {
2404
2404
extern " C" bool pjrt_device_is_addressable (PjRtDevice *device) {
2405
2405
return device->IsAddressable ();
2406
2406
}
2407
+
2408
+ extern " C" mlir::Operation *mlirGetParentOfTypeFunctionOp (mlir::Operation *op) {
2409
+ return op->getParentOfType <mlir::FunctionOpInterface>();
2410
+ }
Original file line number Diff line number Diff line change 126
126
result_inference= false ,
127
127
)
128
128
129
+ parent_func_op = MLIR. IR. get_parent_of_type_function_op (cstop)
130
+ if parent_func_op == C_NULL
131
+ error (" Constant must be created inside a Function Op." )
132
+ end
133
+
129
134
res = MLIR. IR. result (cstop)
130
135
tres = TracedRArray {T,N} ((), res, size (x))
131
136
constants[value] = tres
Original file line number Diff line number Diff line change @@ -331,16 +331,38 @@ function create_operation_common(
331
331
end
332
332
end
333
333
334
+ function create_operation_common_with_checks (args... ; operands= nothing , kwargs... )
335
+ op = create_operation_common (args... ; operands, kwargs... )
336
+ # if !isnothing(operands)
337
+ # parent_function_op = get_parent_of_type_function_op(op)
338
+ # if parent_function_op != C_NULL
339
+ # function_op_region = parent_region(parent_function_op)
340
+ # # TODO : add the checks
341
+ # end
342
+ # end
343
+ return op
344
+ end
345
+
334
346
function create_operation (args... ; kwargs... )
335
- res = create_operation_common (args... ; kwargs... )
347
+ res = create_operation_common_with_checks (args... ; kwargs... )
336
348
if _has_block ()
337
349
push! (block (), res)
338
350
end
339
351
return res
340
352
end
341
353
342
354
function create_operation_at_front (args... ; kwargs... )
343
- res = create_operation_common (args... ; kwargs... )
355
+ res = create_operation_common_with_checks (args... ; kwargs... )
344
356
Base. pushfirst! (block (), res)
345
357
return res
346
358
end
359
+
360
+ function get_parent_of_type_function_op (op:: Operation )
361
+ GC. @preserve op begin
362
+ funcop = @ccall API. mlir_c. mlirGetParentOfTypeFunctionOp (
363
+ op:: API.MlirOperation
364
+ ):: API.MlirOperation
365
+ end
366
+ funcop. ptr == C_NULL && return C_NULL
367
+ return Operation (funcop, false )
368
+ end
You can’t perform that action at this time.
0 commit comments