I'm implementing llvm-mc
in downstream compiler for VLIW architecture. Before encoding a bundle, I need to check that the instructions in that bundle are in correct order. To check this order I need to get scheduling units from MCInst
, but I don't see a way to do it.
In Hexagon
target there is a method HexagonInstrInfo::getUnits()
, which implemented like this:
InstrStage::FuncUnits HexagonInstrInfo::getUnits(const MachineInstr &MI) const {
const InstrItineraryData &II = *Subtarget.getInstrItineraryData();
const InstrStage &IS = *II.beginStage(MI.getDesc().getSchedClass());
return IS.getUnits();
}
But TargetInstructionInfo
is not available inside MCCodeEmitter
. I have access to MCInstr
, MCSubtargetInfo
, MCInstrInfo
and MCContext
. (that's the method, I'm trying to implement.)
Turns out, that I can access InstStage
via:
const InstrItineraryData &II = /*MCSubtargetInfo*/STI.getInstrItineraryForCPU(STI.getCPU());
InstrStage &IS = II
.beginStage(
MCII/* MCInstrInfo */
.get(
/* MCInstr& */MI.getOpcode().getSchedClass());
InstrStage::FuncUnits Units = II.getUnits();