Implementing the driver integration within clang – Beyond Instruction Selection-1

Integrating a new target into the clang frontendIn the previous chapters, we developed the M88k target’s backend implementation within LLVM. To complete the compiler implementation for the M88k target, we

Read More

Building newly implemented machine function passes – Beyond Instruction Selection

We’re almost done with implementing our new machine function pass! Now, we need to ensure CMake is aware of the new machine function pass within M88kDivinstr.cpp. This file is then

Read More

Developing the specifics of the machine function pass – Beyond Instruction Selection-3

bool M88kDivInstr::runOnMachineFunction(MachineFunction &MF) {const M88kSubtarget &Subtarget = MF.getSubtarget();TII = Subtarget.getInstrInfo();TRI = Subtarget.getRegisterInfo();RBI = Subtarget.getRegBankInfo();MRI = &MF.getRegInfo();AddZeroDivCheck = !TM->noZeroDivCheck();bool Changed = false;for (MachineBasicBlock &MBB : reverse(MF))Changed |= runOnMachineBasicBlock(MBB);return Changed;} bool M88kDivInstr::runOnMachineBasicBlock(MachineBasicBlock

Read More

Developing the specifics of the machine function pass – Beyond Instruction Selection-2

private:void addZeroDivCheck(MachineBasicBlock &MBB, MachineInstr *DivInst);}; class M88kBuilder {MachineBasicBlock *MBB;MachineBasicBlock::iterator I;const DebugLoc &DL;const TargetInstrInfo &TII;const TargetRegisterInfo &TRI;const RegisterBankInfo &RBI; public:M88kBuilder(M88kDivInstr &Pass, MachineBasicBlock MBB, const DebugLoc &DL) : MBB(MBB), I(MBB->end()), DL(DL), TII(Pass.TII),

Read More

Developing the specifics of the machine function pass – Beyond Instruction Selection-1

Now that the implementation in the M88k target machine is completed, the next step will be to develop the machine function pass itself. The implementation is contained within the new

Read More

Implementing the top-level interface for the M88k target – Beyond Instruction Selection

Firstly, within llvm/lib/Target/M88k/M88k.h, let’s add two prototypes inside the llvm namespace declaration that will be used later: void initializeM88kDivInstrPass(PassRegistry &); FunctionPass *createM88kDivInstr(const M88kTargetMachine &); Adding the TargetMachine implementation for machine

Read More

Adding a new machine function pass to LLVM – Beyond Instruction Selection

Now that we’ve learned about instruction selection using the SelectionDAG and GlobalISel LLVM-based frameworks in the previous chapters, we can explore other interesting concepts beyond instruction selection. This chapter encapsulates

Read More

How to further evolve the backend – Instruction Selection

With the code from this and the previous chapter, we have created a backend that can translate some LLVM IR into machine code. It is very satisfying to see the

Read More

Translating generic machine instructions – Instruction Selection

For instruction selection via the selection DAG, we added patterns to the target description, which use DAG operations and operands. To reuse those patterns, a mapping from DAG node types

Read More

Selecting a register bank for operands – Instruction Selection

Many architectures define several register banks. A register bank is a set of registers. Typical register banks are general-purpose register banks and floating-point register banks. Why is this information important?

Read More