Working on a very CISC GobalISel target for fun.
It would be “helpful” to have a GlobalISel only target in-tree with the most minimal other content eg. nothing in TargetLowering that isn’t needed.
The SPIRV target is about as close as you’ll get to that today as far as upstream goes, though it is a bit different than typical backends that target an actual machine ISA.
ex. I probably have to register the register classes, and implement some support routines but expect not to need lowerFormalArguments, lowerReturn, etc. Which I have to implement, and which I don’t would be helpful.
Given that i don’t really have a functioning SelectionDAG implementation ,I’d love to dispense entirely with DAG, converted DAG patterns, etc. All this may be possible but isn’t clearly documented.
Yes, it is possible, and this is what we do in the GISel backend I discussed earlier in this thread[**]. Other than some very minimal TargetLoweringBasesupport, you can completely remove any of the other DAG infrastructure[*]. Something along these lines:
XXTargetLowering::XXXTargetLowering(const TargetMachine &TM,
const XXXSubtarget &STI)
: TargetLowering(TM), Subtarget(STI) {
// Set up some register classes.
addRegisterClass(MVT::i32, &XXX::GPRRegClass);
...
// Compute derived properties from the register classes.
computeRegisterProperties(Subtarget.getRegisterInfo());
// Note: GlobalISel back-ends will not have any op actions here!
setJumpIsExpensive(...); // E.g., any configuration settings needed.
}
Depending on your input IR and any finalization, you might need, e.g., getTgtMemIntrinsic and/or finalizeLowering.
Beyond that, you “just” implement the primary GlobalISel APIs. You will at least need to stub out CallLowering, even if you don’t intend to support calls initially.
[*] Although you can completely write your XXXInstructionSelector in C++, it is still very convenient to use “selection DAG” patterns in TableGen. GlobalISel has a compatibility layer/importer so that one can either use existing TD files (with some minor editing) or write anew for GI using familiar syntax. Instead of operating on SDNodes, it operates on MI under the hood.
[**] FWIW, I do hope to start upstreaming that target early next year. There is still some planning, prep work, and corporate hoops to jump through.