This pass allows to convert operations
which use functions with abstract results to ones that do not.
Depends on D130087
Differential D130088
[flang] Introduce `AbstractResultOnGlobalOpt` pass unterumarmung on Jul 19 2022, 7:13 AM. Authored by
Details This pass allows to convert operations Depends on D130087
Diff Detail
Event TimelineComment Actions I wonder if there's a chance that there'll be a function type with abstract results inside fir.global type. Is it possible? If so, how should it be handled? Comment Actions That is a good point, I think it will probably happen once procedure pointers are lowered, and if the related function types are represented (currently, for dummy procedures, we always cast the function type before calls to the interface know at the call site). In my opinion, it is fine if you leave a TODO for this case until we know more how we want to deal with procedure pointers (one difficulty I foresee if we fully type them, if how we will deal with derived type rewrites for function pointer components. I am not sure how one can replace a named type in MLIR.). Comment Actions Ok! What is the best way to do this?
global.getType().cast<FunctionType>()
Any help is appreciated, thanks! Comment Actions Yes, although I do not know yet if we will lower the function type to something else than () -> () in the procedure pointer types or if we will keep relying on function type cast on the call site. Rewriting types, especially in nested structures involving named types does not look like a fun journey, so we may want to keep the types as () -> (), we should weight the pros and cons when dealing with procedure pointers. Right now you could probably check if the global type needs to be rewritten (if it contains a nested function type), in which case you could emit a TODO(loc, ....).
I do not think there is anything required here on top of what you have done. The issue with procedure components was that:
%3 = fir.address_of(@_QMaPfoo) : (!fir.box<!fir.type<_QMaTf>>) -> !fir.box<!fir.heap<!fir.char<1,?>>> %c-1 = arith.constant -1 : index %4 = fir.field_index __address, !fir.type<_QM__fortran_builtinsT__builtin_c_funptr{__address:i64}> %5 = fir.convert %3 : ((!fir.box<!fir.type<_QMaTf>>) -> !fir.box<!fir.heap<!fir.char<1,?>>>) -> i64 %6 = fir.undefined !fir.type<_QM__fortran_builtinsT__builtin_c_funptr{__address:i64}> %7 = fir.insert_value %6, %5, ["__address", !fir.type<_QM__fortran_builtinsT__builtin_c_funptr{__address:i64}>] : (!fir.type<_QM__fortran_builtinsT__builtin_c_funptr{__address:i64}>, i64) -> !fir.type<_QM__fortran_builtinsT__builtin_c_funptr{__address:i64}> .... Hence, the fir.address_of inside the GlobalOp needed to be rewritten if it dealt with functions returning arrays or descriptors, which is what your patch should enable. Note that procedure components are not represented in FIR fir.type derived types because they are not data objects. So There is no rewrite needed in the related fir.type.
Comment Actions What is the motivating Fortran example here?
Comment Actions The motivating example code is here: https://reviews.llvm.org/D130369#3672155 I decided to implement this because there have been code written for FuncOp, so all I needed to do is to refactor some things and handling of the GlobalOp.
Comment Actions @jeanPerier, thank you for the detailed reply, It has been really helpful! Ok! But I got stuck on this. Interesting, so what I've been trying to do here is completely wrong.. Comment Actions @jeanPerier, since there is no generic way to iterate through type parameters, I added a type switch for the TODO Comment Actions The closest thing that will give you what you want is the SubElement interfaces: https://github.com/llvm/llvm-project/blob/main/mlir/include/mlir/IR/SubElementInterfaces.td They provide API for walking sub attributes/types.
Comment Actions Yes, but to use this, I need to change the definitions of the types I want to iterate through, which is overkill in this particular situation. Comment Actions Thanks for pointing that out @rriddle, we will definitely want to use this in flang to ease all the passes that need to visit types, and to get nice type aliasing when printing nested types. I agree that adding the generic visit is outside of the scope of your patch. Your "containsFunctionTypeWithAbstractResult" function does the job of making to insert the TODO, we will take it when it is clear of Procedure pointer types should be represented.
Comment Actions Hey, @jeanPerier @schweitz! Sorry for the delay I rebased my patch and addressed most of the review comment. Could you please take a look?
|
Small style question, it looks like clang-format is happy with your change, but is it from MLIR/LLVM style to add blank lines between the headers from different parts ? I am not sure we are doing it in other files.