Implementing the MachineFunction class

Similar to the LLVM IR FunctionBlock class, a MachineFunction class contains a series of MachineBasicBlocks classes. These MachineFunction classes map to LLVM IR functions that are given as input to the instruction selector. In addition to a list of basic blocks, the MachineFunction class contains the MachineConstantPool, MachineFrameInfo, MachineFunctionInfo, and MachineRegisterInfo classes.

How to do it…

Many functions are defined in the MachineFunction class, which does specific tasks. There are also many class member objects that keep information, such as the following:

  • RegInfo keeps information about each register that is in use in the function:
    MachineRegisterInfo *RegInfo;
  • MachineFrameInfo keeps track of objects allocated on the stack:
    MachineFrameInfo *FrameInfo;
  • ConstantPool keeps track of constants that have been spilled to the memory:
    MachineConstantPool *ConstantPool;
  • JumpTableInfo keeps track of jump tables for switch instructions:
    MachineJumpTableInfo *JumpTableInfo;
  • The list of machine basic blocks in the function:
    typedef ilist<MachineBasicBlock> BasicBlockListType;
    BasicBlockListType BasicBlocks;
  • The getFunction function returns the LLVM function that the current machine code represents:
    const Function *getFunction() const { return Fn; }
  • CreateMachineInstr allocates a new MachineInstr class:
    MachineInstr *CreateMachineInstr(const MCInstrDesc &MCID,
    DebugLoc DL,
    bool NoImp = false);

How it works…

The MachineFunction class primarily contains a list of MachineBasicBlock objects (typedef ilist<MachineBasicBlock> BasicBlockListType; BasicBlockListType BasicBlocks;), and defines various methods for retrieving information about the machine function and manipulating the objects in the basic blocks member. A very important point to note is that the MachineFunction class maintains the control flow graph (CFG) of all basic blocks in a function. Control flow information in CFG is crucial for many optimizations and analyses. So, it is important to know how the MachineFunction objects and the corresponding CFGs are constructed.

See also

  • A detailed implementation of the MachineFunction class can be found in the MachineFunction.cpp file located at lib/Codegen/
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.54.136