Finally, we can implement the M88kTargetMachine class. This class holds all used sub-target instances. It also owns a subclass of TargetLoweringObjectFile, which provides details such as section names to the lowering process. Lastly, it creates the configuration of the passes that runs in this backend.
The declaration in the M88kTargetMachine.h file is as follows:

  1. The M88kTargetMachine class derives from the LLVMTargetMachine class. The only members are an instance of TargetLoweringObjectFile and the sub-target map:

namespace llvm {
class M88kTargetMachine : public LLVMTargetMachine {
std::unique_ptr TLOF;
mutable StringMap>
SubtargetMap;

  1. The parameters of the constructor completely describe the target configuration for which we will generate code. With the TargetOptions class, many details of the code generations can be controlled – for example, if floating-point multiply-and-add instructions can be used or not. Also, the relocation model, the code model, and the optimization level are passed to the constructor. Notably, the JIT parameter is set to true if the target machine is used for just-in-time compilation.

public:
M88kTargetMachine(const Target &T, const Triple &TT,
StringRef CPU, StringRef FS,
const TargetOptions &Options,
std::optional RM,
std::optional CM,
CodeGenOpt::Level OL, bool JIT);

  1. We also need to override some methods. The getSubtargetImpl() method returns the sub-target instance to use for the given function, and the getObjFileLowering() method just returns the member variable. In addition, we override the createPassConfig() method, which returns our configuration for the backend passes: ~M88kTargetMachine() override;
    const M88kSubtarget *
    getSubtargetImpl(const Function &) const override;
    TargetPassConfig *
    createPassConfig(PassManagerBase &PM) override;
    TargetLoweringObjectFile *
    getObjFileLowering() const override {
    return TLOF.get();
    }
    };
    } // end namespace llvm

Leave a Reply

Your email address will not be published. Required fields are marked *