Got it. Thank you. I tried using the new pass manager from the new tutorial as well but was having an issue where the ‘helloworld’ pass would only work if I manually removed all the metadata from my hello.ll file to where the only thing in it was the function. Otherwise, it would run silently and not print out any function names. Any solution to that?
Adding the -debug-pass-manager flag to the opt commands shows what’s going on:
Starting llvm::Module pass manager run.
Running pass: VerifierPass on C:/src/tmp/a.ll
Running analysis: VerifierAnalysis on C:/src/tmp/a.ll
Running analysis: InnerAnalysisManagerProxy<llvm::FunctionAnalysisManager, llvm::Module> on C:/src/tmp/a.ll
Starting llvm::Function pass manager run.
Skipping pass HelloWorldPass on foo due to optnone attribute
Skipping pass: HelloWorldPass on foo
Finished llvm::Function pass manager run.
Running pass: VerifierPass on C:/src/tmp/a.ll
Finished llvm::Module pass manager run.
The optnone attribute on a function makes most function passes skip running on the function. You got the IR from the output of clang -O0 which adds that attribute. This is actually briefly mentioned at the end of https://llvm.org/docs/WritingAnLLVMNewPMPass.html.
Perhaps we can make HelloWorldPass required for demonstration purposes and to avoid this specific problem in the future.