I’m working on writing a backend for a processor that only has one Branch instruction, a BRnzp, where it branches on a status register (NZP: Negative, Zero, Positive) based on what the result of the last arithmetic operation was. It’s implicitly set, nowhere in userspace.
Basically, it follows the format of:
BR 010 … (Branches if the result of the ADD was zero).
Unconditional branches are given as a 111 argument.
How can I use tablegen to describe this in a way that the scheduler also understands that it’s ‘attached’ to the last instruction?
You could try instruction bundles (though bundling before RA is very uncommon and I'm at least aware of some cases where the regallocator cannot handle when the last instruction (bundle) of a function produces a new value because it tries to place a spill behind the definition.
Or you model it with a pseudo that expands into a sub with 0 / br (like cmp/branch on other targets) and try to eliminate the sub via late peepholes where possible.
You can add the status register as an implicit use to all such branches, and as an implicit def to all instructions that modify it.
Check "Defs" and "Uses" in the definition of "Instruction" in include/Target/Target.td.