FYI, cheat sheet for updating out-of-tree targets for TTI changes

Just wanted to help folks out, as the structure of the changes I made to the in-tree targets was somewhat optimized for code review and handling reverts. Not necessarily the efficient way to update an out-of-tree target.

First, update your TTI:

  • Move the class definition into a header
  • Rip out the base class, remove all override and const qualifiers from methods
  • Derive from BasicTTIImpl so you pick up all the target-independent code generator implementation
  • friend the CRTP base class so it can call a couple of private methods in your TTI
  • define getST() and getTLI() private methods that return pointers to your target’s subtarget and TLI respectively. you probably want to cache those pointers in members and make these methods simple getters. these are called by BasicTTIImpl
  • Provide a boring constructor for your TTI, you’ll directly construct it for a specific function with your TargetMachine available.

Once you have the TTI updated, update your target machine:

  • Nuke the addAnalysisPasses override, that method is gone
  • add an override for getTargetIRAnalysis that returns a TargetIRAnalysis object (you’ll need to include TargetTransformInfo.h)
  • in your implementation of this override, return a TargetIRAnalysis object constructed from a lambda, the lambda should be callable with a function reference, and should return a TargetTransformInfo object wrapping your target’s TTIImpl; you can construct your Impl directly and pass it to the TargetTransformInfo constructor, it will do all the wrapping for you

AArch64TargetTransformInfo.{h,cpp} and AArch64TargetMachine.cpp are good examples to emulate.

Lemme know if you hit problems.