This is an archive of the discontinued LLVM Phabricator instance.

[flang] Update the plugin API
ClosedPublic

Authored by awarzynski on Mar 4 2022, 8:23 AM.

Details

Summary

This patch adds a new member method in the PluginParseTreeAction
frontend action base class: getParsing. As plugins are meant as a
convenient interface for analysing the parse tree, this method is key.
With this new method, plugins no longer need to include
CompilerInstance.h to retrieve e.g. parse trees. As a result, the
plugins are more independent of the driver's implementation's details
(e.g. CompilerInstance).

Diff Detail

Event Timeline

awarzynski created this revision.Mar 4 2022, 8:23 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald Transcript
awarzynski requested review of this revision.Mar 4 2022, 8:23 AM
Herald added a project: Restricted Project. · View Herald Transcript

Can you check why the patch application failed?

Rebase

@kiranchandramohan My bad, I forgot to squash before sending to Phab!

Fix formatting

Leporacanthicus added inline comments.
flang/examples/FlangOmpReport/FlangOmpReport.cpp
56

Just out of curiosity, why is the parsing not a constructor argument?

flang/examples/FlangOmpReport/FlangOmpReport.cpp
64–65

I was thinking that flang-omp-report will run on all the source files and generate a lot of YAML files whose name is derived from the name of the source file. Then the summary python script collects a summary from all these info.

This code looks like it dumps everything to output, wouldn't it affect the running of the summarize python script?

awarzynski added inline comments.Apr 1 2022, 8:59 AM
flang/examples/FlangOmpReport/FlangOmpReport.cpp
56

Of PluginParseTreeAction? Parsing is not available until BeginSourceFileAction is run. That's after this object is constructed.

64–65

I was thinking that flang-omp-report will run on all the source files and generate a lot of YAML files whose name is derived from the name of the source file.

Not quite. You will have to run the plugin manually for every file. But you can automate this by "hacking" a Makefile of the project that you are interested in. Currently, you will need these extra flags:

FFLAGS=-fsyntax-only -I /.../llvm-project/flang/module -Xflang -load -Xflang /.../llvm-project/build/Release/lib/flangOmpReport.so -Xflang -plugin -Xflang flang-omp-report -fopenmp

With this change, you will also have to pipe the output to a file (so that it does not end up in stdout):

FFLAGS=-fsyntax-only -I /.../llvm-project/flang/module -Xflang -load -Xflang /.../llvm-project/build/Release/lib/flangOmpReport.so -Xflang -plugin -Xflang flang-omp-report -fopenmp -o output.yaml

This does make using the plugin on larger projects a bit more tricky, but I feel that the API should be independent of the internals of the driver. In particular, the driver depends on various TableGen files from Clang that define diagnostics. So, in general, so does this plugin because it includes "CompilerInstance.h" from the driver. I'm trying to remove this dependency.

As for the script, it's independent of the plugin and all it needs are some *.yaml files (i.e. it does not care how you generate them).

flang/examples/FlangOmpReport/FlangOmpReport.cpp
64–65

but I feel that the API should be independent of the internals of the driver

That is a good goal for plugins. But at the same time the advantage of running flang-omp-report as a plugin is the fact that we can run it on large projects. Most drivers default to using the file name as the default. Why can't we ask the driver to provide the output stream just like you did for Parsing?

awarzynski added inline comments.Apr 4 2022, 8:06 AM
flang/examples/FlangOmpReport/FlangOmpReport.cpp
64–65

That is a good goal for plugins. But at the same time the advantage of running flang-omp-report as a plugin is the fact that we can run it on large projects.

This change does not affect this.

Recall that in order to run FlangOmpReporton a project (note that we changed the name from flang-omp-report for consistency with other libs), you need to modify the corresponding build script. This is the case _with_ and _without_ this change. However, this update does mean that you will need one additional change in the build script though. For example, for SNAP I needed this:

@@ -187,7 +187,7 @@ translv.o : global.o plib.o geom.o sn.o data.o control.o utils.o \
        $(FORTRAN) $(FFLAGS) -c $*.f90

 %.o:   %.f90
-       $(FORTRAN) $(FFLAGS) -c $<
+       $(FORTRAN) $(FFLAGS) -c $< >> $(basename $@).yaml

 #

But still, I'm not removing the possibility of running this plugin on a project (i.e. for multiple files).

Most drivers default to using the file name as the default.

Yes, that's a good point. But I felt that that's not "mission critical". First, I want to get rid of the dependency on "CompilerInstance.h". That has caused build failures for people (CC @DavidSpickett ).

I do agree that plugins should inherit the drivers' behavior. I just didn't have the time to look into this. Anyway, let me fix that (update coming shortly).

awarzynski updated this revision to Diff 420186.Apr 4 2022, 8:08 AM

Make plugins respect drivers' -o <output-file>

This revision is now accepted and ready to land.Apr 5 2022, 3:56 PM

@awarzynski Did you forget about this?

(I'm not waiting on it for any reason just happened to be looking through my phab queues)

@awarzynski Did you forget about this?

I did :) Thanks for the ping, merging now!