What is the best way to communicate between out-of-tree frontend and middle-end plugins?

I have 2 out-of-tree plugins:

  1. A Clang plugin that adds specific function attributes to the Clang.
  2. A LLVM plugin that runs specific passes according to the attributes.

Currently, I have the following workflow:

  1. Run Clang with the Clang plugin which handles the attributes by collecting them into a JSON file (basically a map - “mangled function name” => “a list of the specific attributes”).
  2. Run Clang again with the LLVM plugin which parses the JSON into a global variable (ew) Then
    the passes access later the global map and check if attributes were set for a function they were invoked for.

I do not like the following workflow because:

  1. I need to invoke the compiler twice. I tried to get it working with 2 plugins at one invocation but failed. Is there a way to invoke clang with the both plugins at once?
  2. The JSON file has a static name and the solution will break if source code is build in parallel (I mean -j flag)
  3. Global variables :frowning:

Any tips on how to make the workflow better are appreciated!

CC: @banach-space (as the author of llvm-tutor and clang-tutor)

1 Like