/// The rationale is that it is more efficient for the optimizers
/// to be able to assume that the mapping of the ith operand is
/// at the index i.
+ ///
+ /// \pre ID != InvalidMappingID
InstructionMapping(unsigned ID, unsigned Cost, unsigned NumOperands)
: ID(ID), Cost(Cost), NumOperands(NumOperands) {
+ assert(getID() != InvalidMappingID &&
+ "Use the default constructor for invalid mapping");
OperandsMapping.reset(new ValueMapping[getNumOperands()]);
}
+ /// Default constructor.
+ /// Use this constructor to express that the mapping is invalid.
+ InstructionMapping() : ID(InvalidMappingID), Cost(0), NumOperands(0) {}
+
/// Get the cost.
unsigned getCost() const { return Cost; }
getOperandMapping(i) = ValMapping;
}
+ /// Check whether this object is valid.
+ /// This is a lightweight check for obvious wrong instance.
+ bool isValid() const { return getID() != InvalidMappingID; }
+
/// Verifiy that this mapping makes sense for \p MI.
void verify(const MachineInstr &MI) const;
};
/// Make sure not to use that identifier to avoid possible collision.
static const unsigned DefaultMappingID;
+ /// Identifier used when the related instruction mapping instance
+ /// is generated by the default constructor.
+ /// Make sure not to use that identifier.
+ static const unsigned InvalidMappingID;
+
/// Get the mapping of the different operands of \p MI
/// on the register bank.
/// This mapping should be the direct translation of \p MI.