[LLVMdev] question about printAliasInstr

Akira Hatanaka ahatanak at gmail.com
Tue Dec 18 19:23:04 PST 2012

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

"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?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20121218/4aa8a1ed/attachment.html>

More information about the llvm-dev mailing list