Where should I stick these passes?

Hi all.

I am working on a project in academia where I need to write analysis and transformation passes that know about where variables are stored on the stack, what gets spilled, and where spills happen, so these things should not be changed by any passes after mine. Ideally, I would also like to have the passes work for several targets though I’m not sure how feasible this is.

I’ve read through the docs on MIR, the llvm docs, watched some developer meeting videos over the backend, and poked around the source, but I have some questions that I was having a hard time resolving myself:

  • Is the right place to put this after the block-placement pass?

  • Would targeting MachineInstrs for my passes allow this to work for multiple target architectures? Or am I misunderstanding this and architectures just end up subclassing this?

  • Could optimizations during LTO affect this?

  • Is the right place to put this after the block-placement pass?

I’d probably put it after frame lowering? (See: include/llvm/CodeGen/TargetFrameLowering.h)

  • Would targeting MachineInstr s for my passes allow this to work for multiple target architectures? Or am I misunderstanding this and architectures just end up subclassing this?

Late in the pipeline, MachineInstr is mostly target-specific. So, you’ll either end up subclassing or writing target hooks to do the target-specific bits.

  • Could optimizations during LTO affect this?

AFAIK LTO mostly impacts interprocedural stuff. Only interprocedural late pass I can think of is the outliner, but I’m not sure if it would really impact what you want to do.

1 Like