diff --git a/llvm/docs/WritingAnLLVMNewPMPass.rst b/llvm/docs/WritingAnLLVMNewPMPass.rst --- a/llvm/docs/WritingAnLLVMNewPMPass.rst +++ b/llvm/docs/WritingAnLLVMNewPMPass.rst @@ -207,3 +207,30 @@ $ ninja -C build check-llvm # runs our new test alongside all other llvm lit tests + +FAQs +==== + +Required passes +--------------- + +If the pass is a required pass, meaning it must run on the IR to produce +semantically valid output, add a static ``isRequired()`` method that returns +true to the pass class. + +.. code-block:: c++ + + class HelloWorldPass : public PassInfoMixin { + public: + PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); + + static bool isRequired() { return true; } + }; + +This will make it run even in the presence of something that skips +optimization passes, like the ``optnone`` function attribute. + +``AlwaysInlinerPass`` is an example of a required pass in-tree. + +For more info on how this works, see +``PassInstrumentation::runBeforePass()``.