PSyclone icon indicating copy to clipboard operation
PSyclone copied to clipboard

[PSyIR] allow CodeBlock to be queried for inputs and outputs

Open arporter opened this issue 2 years ago • 5 comments

Currently the dependence analysis cannot do anything with CodeBlock nodes. However, in many cases it should be possible to identify which symbols are read and which are written and that will help with e.g. moving allocate statements (#1726) and determining data movement for GPU execution.

arporter avatar May 27 '22 15:05 arporter

There is basic functionality to with the CodeBlock.get_symbol_names() method. I thought about differentiating between read and write, but it is not trivial (or simply not possible? for the generic case). Consider the expression: a = myfunc(b)

You could think that looking if symbols appear at the left or right of the = could help, but it doesn't because myfunc argument can have intent(inout). And its worse because the thing about CodeBlocks is that we don't know how to semantically interpret them. For instance it may be a OO concept a = mytype.method() and the modification(write) of the symbol mytype is encapsulated inside the class.

So I think for the dependency analysis we must consider symbols have the worst-case-scenario which will be that all are written.

sergisiso avatar May 27 '22 20:05 sergisiso

Oh dear, yes, those are good points and in the general case I agree that we'll have to mark everything as written. However, there will be some simpler cases where we will know.

arporter avatar May 27 '22 20:05 arporter

I am happy to discuss this next week. There are a few things about CodeBlock symbols that are not properly designed (e.g. a symbol.rename that is also in a codeblock would currently not update the codeblock and produce wrong code)

So it will be good to think about this carefully and design something a bit more robust.

sergisiso avatar May 27 '22 20:05 sergisiso

OK, I won't start hacking just yet then :-)

arporter avatar May 27 '22 20:05 arporter

The psyad use case for allocate and dealocate will not need to know whether it is read or write, but will need to check each line in multiline codeblocks for validation purposes. But of course a general api will 🙂

rupertford avatar May 27 '22 21:05 rupertford