Help with Analysis pass design

Hi all,

As part of the out-of-tree backend which I am developing, I’d like to implement an analysis pass that runs prior to RA and is then consumed post-RA. It needs to run before RA because it makes use of virtual registers and SSA, but the transformation pass using it operates on physical registers, so it must run post-RA. I can schedule the pass to run preRA and it works just fine, but the problem is that the PassManager assumes it to be invalidated between this initial run and it’s consumption, and so schedules it to run again immediately before its consumption. This second run of the pass fails because the required virtual register information is no longer available.

The particular analysis my pass does is known not to be invalidated by any of the passes between it’s initial scheduled run and its consumption. Is there any way to convey this information to the PassManager, without modifying all intervening passes? Or is there a known solution to the general problem of using pre-RA analysis in a postRA pass? Can anyone point me to an example in one of the existing targets?

I can make it work using static variables and early exit if its scheduled post-RA, e.g.:

struct MyAnalysis : public MachineFunctionPass {

static MyStruct MyAnalysisData;
static char ID;

bool runOnMachineFunction(MachineFunction &MF) override {

if (isPostRa())
return false;

MyAnalysisData = doAnalysis(MF);
return false;

… but I don’t think this is recommended. Any feedback would be greatly appreciated.