Question about how MC and MI layers may share data structures.

Hi all,

We have some code in Hexagon that needs to be run on MC instructions, as well as on MI instruction.

Here is some background for why we have this need:

Some Hexagon instructions can be converted to a more compact bit representation, with the exact same functionality, if the properties of its operands meet certain criteria. Thus on the MI layer, we check the properties of the instruction’s operands, and use the information for scheduling, and on the MC layer, we check the properties of the instruction’s operands, and perform the conversion to the MCInstr’s more compact form.

The API to access Operands was similar enough such that I was able to write a template where I could use a construct:

template unsigned

myFunc(T Mx) {

Mx->getOperand(0).getReg();

Mx->getOperand(1).getReg();

Mx->getOperand(2).isImm();

Mx->getOperand(2).getImm();

Etc….

}

  • to access the data from both MC and MI layers.

However, templating here may not be safest way to share code implementing the same functionality between MC and MI.

Other possibilities include using virtual functions like:

getOperand(0).getReg() replaced by opreg(0),

Where opreg(x) would be a virtual function in a base class, which TargetMCInst/TargetMachineInstruction would implement (and avoid MCOperands/MIOperands).

Another option would be to use function pointers.

Is there a preferred way to share code between MI and MC?

Thanks and Regards,

David Young