[NewPM] Retrieve TargetMachine

How can I get the TargetMachine object within a NewPM implementation? CodeGenPrepare implements TM = &getAnalysis<TargetPassConfig>().getTM<TargetMachine>();, I am finding a way to translate it to conform with the New Pass Manager.

In PassRegistry.def you’ll see some passes with the TM parameter. This is the TM in PassBuilder. So currently, the pass stores a pointer to the TargetMachine which the PassBuilder will pass when constructing the pass (or you can construct the pass yourself manually with the TargetMachine).

Perhaps we should have an analysis that returns a TargetMachine and make PassBuilder users override the analysis if they have a TargetMachine (or some more ergonomic version of this).