MIPS ISel Passes

References:

3 Passes for Mips ISel

  • MipsModuleDAGToDAGISel, a pass used to change the subtarget for the Mips Instruction selector.
  • Mips16DAGToDAGISel, Subclass of MipsDAGToDAGISel specialized for mips16.
  • MipsSEDAGToDAGISel, Subclass of MipsDAGToDAGISel specialized for mips32/64.

The core passes are Mips16DAGToDAGISel for 16-bit mips and MipsSEDAGToDAGISel for 3264 bit mips. Both of them finally calls the parent pass entry (SelectionDAGISel::runOnMachineFunction) in their implementation. See more impl details on SelectionDAGISel.

Pass registeration:

pass creation and registration

MipsSEDAGToDAGISel

Inheritance: parent->child

MachineFunctionPass
 -> SelectionDAGISel
  -> MipsDAGToDAGISel
   -> MipsSEDAGToDAGISel
// llvm/lib/Target/Mips/MipsSEISelDAGToDAG.cpp

bool MipsSEDAGToDAGISel::runOnMachineFunction(MachineFunction &MF) {
  Subtarget = &static_cast<const MipsSubtarget &>(MF.getSubtarget());
  if (Subtarget->inMips16Mode())
    return false;
  return MipsDAGToDAGISel::runOnMachineFunction(MF);
}

// MipsDAGToDAGISel::runOnMachineFunction
// llvm/lib/Target/Mips/MipsISelDAGToDAG.cpp

bool MipsDAGToDAGISel::runOnMachineFunction(MachineFunction &MF) {
  Subtarget = &static_cast<const MipsSubtarget &>(MF.getSubtarget());

  DebugLL("MipsDAGToDAGISel pass on MF: "<< MF.getName() << "\n")

  bool Ret = SelectionDAGISel::runOnMachineFunction(MF);

  processFunctionAfterISel(MF);

  return Ret;
}

MipsModuleDAGToDAGISel

Set the subtarget for MipsTargetMachine

// llvm/lib/Target/Mips/MipsModuleISelDAGToDAG.cpp

bool MipsModuleDAGToDAGISel::runOnMachineFunction(MachineFunction &MF) {
  LLVM_DEBUG(errs() << "In MipsModuleDAGToDAGISel::runMachineFunction\n");
  auto &TPC = getAnalysis<TargetPassConfig>();
  auto &TM = TPC.getTM<MipsTargetMachine>();
  TM.resetSubtarget(&MF);
  return false;
}

// MipsTargetMachine::resetSubTarget()
// llvm/lib/Target/Mips/MipsTargetMachine.cpp
void MipsTargetMachine::resetSubtarget(MachineFunction *MF) {
  LLVM_DEBUG(dbgs() << "resetSubtarget\n");

  Subtarget = &MF->getSubtarget<MipsSubtarget>();
}

Mips16DAGToDAGISel

Inheritance: parent->child

MachineFunctionPass
 -> SelectionDAGISel
  -> MipsDAGToDAGISel 
    -> Mips16DAGToDAGISel
// llvm/lib/Target/Mips/Mips16ISelDAGToDAG.cpp

bool Mips16DAGToDAGISel::runOnMachineFunction(MachineFunction &MF) {
  Subtarget = &static_cast<const MipsSubtarget &>(MF.getSubtarget());

  DebugLL("Mips16DAGToDAGISel pass on MF: "<< MF.getName() << "\n");

  if (!Subtarget->inMips16Mode())
    return false;
  return MipsDAGToDAGISel::runOnMachineFunction(MF);
}
Created Jul 22, 2020 // Last Updated Jul 22, 2020

If you could revise
the fundmental principles of
computer system design
to improve security...

... what would you change?