I am considering using MipsInstPrinter::printAliasInstr, which is auto-generated in MipsGenAsmWriter.inc, to print assembly idioms defined as instruction aliases. For example, an instruction which used to be printed as
“nor $1, $2, $zero”
can be printed as
“not $1, $2”
This is nice because it makes the code printed by code-gen or disassembler more readable.
However, the code in AsmWriterEmitter::EmitPrintAliasInstruction seems to ignore instruction aliases if an operand that is not a register nor an immediate appears in the result instruction DAG. For example, the folllowing instruction alias pattern is not handled in MipsGenAsmWriter.inc because the third operand of BEQ is a brtarget:
def : InstAlias<“b $offset”, (BEQ ZERO, ZERO, brtarget:$offset)>;
The code which decides not to include this alias is located near line 856 in AsmWriterEmitter.cpp:
for (unsigned i = 0, e = LastOpNo; i != e; ++i) {
…
switch (RO.Kind) {
case CodeGenInstAlias::ResultOperand::K_Record: {
…
if (Rec->isSubClassOf(“RegisterClass”)) {
…
} else {
assert(Rec->isSubClassOf(“Operand”) && “Unexpected operand!”); // ← line 856
// FIXME: We may need to handle these situations.
delete IAP;
IAP = 0;
CantHandle = true;
…
My question is, what has to be changed to make MipsInstPrinter::printAliasInstr generate the code to handle the BEQ instruction alias?
Is there a reason this part wasn’t implemented?