[llvm-dev] Why do backend pass definitions call a seperate function just to call the constructor?

Tim Northover via llvm-dev llvm-dev at lists.llvm.org
Tue Jan 16 13:32:18 PST 2018

On 16 January 2018 at 20:40, Ahmed Samara via llvm-dev
<llvm-dev at lists.llvm.org> wrote:
> Things like this in `lib/Target/ARM/ARMExpandPseudoInsts.cpp`
>> FunctionPass *llvm::createARMExpandPseudoPass() {
>>   return new ARMExpandPseudo();
>> }
> And other functions have basically the same style.
> What's the point of doing it this way instead of just calling `new
> ARMExpandPseudo` in any place that you would have called this function?

Mostly it's so that everything that relies on knowing the class
definition and layout is restricted to a single file. The interface to
the rest of LLVM is just a single "createXYZ" standalone function.
That speeds up build times and is generally good for abstraction.



More information about the llvm-dev mailing list