[all-commits] [llvm/llvm-project] 18db7c: [flang] Compiler directives defined by plugins (pr...

Valentin Churavy via All-commits all-commits at lists.llvm.org
Fri Oct 2 20:24:53 PDT 2026


  Branch: refs/heads/users/vchuravy/flang-plugin-directives
  Home:   https://github.com/llvm/llvm-project
  Commit: 18db7ca9eb766c21c42fd1737194b03c2e6bf480
      https://github.com/llvm/llvm-project/commit/18db7ca9eb766c21c42fd1737194b03c2e6bf480
  Author: Valentin Churavy <v.churavy at gmail.com>
  Date:   2026-10-01 (Thu, 01 Oct 2026)

  Changed paths:
    M flang/include/flang/Parser/dump-parse-tree.h
    M flang/include/flang/Parser/parse-tree.h
    M flang/include/flang/Semantics/semantics.h
    A flang/include/flang/Support/PluginDirectives.h
    M flang/lib/Lower/Bridge.cpp
    M flang/lib/Parser/Fortran-parsers.cpp
    M flang/lib/Parser/unparse.cpp
    M flang/lib/Semantics/mod-file.cpp
    M flang/lib/Semantics/resolve-names.cpp
    M flang/lib/Support/CMakeLists.txt
    A flang/lib/Support/PluginDirectives.cpp

  Log Message:
  -----------
  [flang] Compiler directives defined by plugins (prototype)

Lets a plugin loaded with `flang -fc1 -load` define its own directives,

  !DIR$ prefix keyword [( arg [, arg]... )],  arg -> [name =] value,
  value -> name | integer | character-literal

and see them, with their names resolved to symbols, in MLIR.

- Support: a registry (flang/Support/PluginDirectives.h) where a plugin
  registers each directive with the kinds of its arguments (procedure,
  variable, integer, string) and of its subject, from a static initializer.
- Parser: CompilerDirective::Plugin, accepted only for a registered prefix,
  so other directives parse as before.
- Semantics: name arguments are resolved in the enclosing scope (procedures
  under CONTAINS can be named before they are defined), checked against the
  registered kinds, and recorded with their subject: a leading positional
  name, or the enclosing subprogram. Errors for undeclared names, wrong
  kinds, unknown keywords and missing arguments.
- Module files: the directives of a module's entities are written back in
  canonical form, so units that use the module see them. A directive read
  from a module file without its plugin is ignored silently.
- Lowering: each directive becomes a dictionary in the `fir.directives`
  attribute of its subject's func.func or fir.global, with symbol references
  for procedure and variable arguments (declaring procedures as needed).
  The plugin's passes interpret them.

Assisted-by: Claude Code (Opus 5.5)


  Commit: fca3c7ddef0ec0b26502cfa033463eeb73e6a614
      https://github.com/llvm/llvm-project/commit/fca3c7ddef0ec0b26502cfa033463eeb73e6a614
  Author: Valentin Churavy <v.churavy at gmail.com>
  Date:   2026-10-01 (Thu, 01 Oct 2026)

  Changed paths:
    M flang/include/flang/Parser/dump-parse-tree.h
    M flang/include/flang/Parser/parse-tree.h
    M flang/lib/Lower/Bridge.cpp
    M flang/lib/Parser/Fortran-parsers.cpp
    M flang/lib/Parser/unparse.cpp
    M flang/lib/Semantics/mod-file.cpp
    M flang/lib/Semantics/resolve-names.cpp

  Log Message:
  -----------
  [flang] Plugin directives: COMMON block arguments

/name/ names a COMMON block in a plugin directive, as subject or argument
of variable kind. It resolves to the block visible in the scope, is written
back in module files, and lowers to a reference to the block's fir.global.

Assisted-by: Claude Code (Opus 5.5)


  Commit: b028d61473e779f05e13814a10d1a8f2f27a8f9b
      https://github.com/llvm/llvm-project/commit/b028d61473e779f05e13814a10d1a8f2f27a8f9b
  Author: Valentin Churavy <v.churavy at gmail.com>
  Date:   2026-10-01 (Thu, 01 Oct 2026)

  Changed paths:
    M flang/include/flang/Lower/ConvertVariable.h
    M flang/include/flang/Semantics/semantics.h
    M flang/lib/Lower/Bridge.cpp
    M flang/lib/Lower/ConvertVariable.cpp
    M flang/lib/Semantics/mod-file.cpp
    M flang/lib/Semantics/resolve-names.cpp

  Log Message:
  -----------
  [flang] Plugin directives: declare subjects and arguments the unit does not use

A directive is lowered onto the operation of its subject, and its procedure
and variable arguments become symbol references. Subjects that the unit does
not define or reference had no operation, so their directives were dropped,
and use-associated module variables as arguments became strings:

- The unit that holds the directive now declares its subject (a procedure,
  e.g. an external one with an interface body, or a module variable, which
  may be another module's), as a reference would. A unit that sees the
  directive through a module file still lowers it only for what it uses.
- Procedure and module variable arguments are declared likewise.

Semantics records for each directive whether it was read from a module file;
Lower gets declareModuleVariable for a used module variable outside of any
function.

Assisted-by: Claude Code (Opus 5.5)


Compare: https://github.com/llvm/llvm-project/compare/18db7ca9eb76%5E...b028d61473e7

To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list