[llvm-dev] Replace MCTargetOptionsCommandFlags.inc and CommandFlags.inc by runtime registration

Serge Guelton via llvm-dev llvm-dev at lists.llvm.org
Wed Mar 18 04:11:43 PDT 2020

Hi Folks,

Commit ac1d23ed7de01fb3a18b340536842a419b504d86 introduces a change in the way
CodeGen and MC CommandFlags are handled. It's a change that may impact some
devs, so I'd better give a small notice here.

Basically previous approach was to bundle all options in a .inc file that
declares a bunch of llvm::cl options. This file was lying in include/llvm and
was to be included in client code. To avoid duplicate registration of llvm::cl
options, this was meant to be only included in binaries, and not libraries.

This rule of thumb was no respected by at least libclang-cpp and liblldCommon,
which led to situation like this:

And overall, having static options registred in « header » file is not the

Current situation has moved to a more robust approach. options are registered
through static objects declared in the constructor of
codegen::RegisterCodeGenFlags that lies in libLLVMCodeGen. That way, when a static instance of
codegen::RegisterCodeGenFlags is created, all options are registered, and they
can only be registered once. If codegen::RegisterCodeGenFlags is not created,
the options are not registered.

Note that this approach could be used for *all* cl options.

More information about the llvm-dev mailing list