This is beginnerish but I thought other backends might find it useful.
modernize/replace reset() with std::make_unique<>
GlobalISel was designed+implemented circa 2015+16. LLVM then didn’t allow C++14. Consequently (and for example) the AArch64 backend’s Subtarget constructor looks like:
CallLoweringInfo.reset(new AArch64CallLowering(*getTargetLowering())); InlineAsmLoweringInfo.reset(new InlineAsmLowering(getTargetLowering())); Legalizer.reset(new AArch64LegalizerInfo(*this)); auto *RBI = new AArch64RegisterBankInfo(*getRegisterInfo()); InstSelector.reset(createAArch64InstructionSelector( *static_cast<const AArch64TargetMachine *>(&TM), *this, *RBI));
The LLVM codebase now allows C++14 and so reset() can be replaced by std::make_unique<>. To do this, AArch64InstructionSelector also needs to be refactored to have a AArch64InstructionSelector.h file. clang-tidy even offers a check for the reset() → make_unique<> conversion, modernize-make-unique. I think the result looks cleaner:
CallLoweringInfo = std::make_unique<AArch64CallLowering>(*getTargetLowering()); Legalizer = std::make_unique<AArch64LegalizerInfo>(*this); RegBankInfo = std::make_unique<AArch64RegisterBankInfo>(*getRegisterInfo()); InstSelector = std::make_unique<AArch64InstructionSelector>( *static_cast<const AArch64TargetMachine *>(&TM), *this, (AArch64RegisterBankInfo&) *RegBankInfo);
TargetOpcode shouldn’t appear in a backend
TargetOpcode is a namespace for “Invariant opcodes: All instruction sets have these as their low opcodes.” However, these opcodes are also copied into the backend’s namespace by TableGen, for example, into AArch64GenInstrInfo.inc.
Using both namespaces gets a little messy. As an example, AArch64 uses both AArch64::CFI_INSTRUCTION and TargetOpcode::CFI_INSTRUCTION. You can also get namespace collisions for using both at the same time which you can’t if you restrict the backend to its own namespace.
So I think that the TargetOpcode namespace shouldn’t appear in a backend. A backend should just use its own namespace. It’s not hard to make this change (grep) but I suppose a clang-tidy rule restricted for backends could help.
I also use using namespace wherever possible to further simplify the code.
using namespace llvm;
using namespace AArch64;