Hi, I’m working with LLVM TableGen and trying to define an InstAlias for a family of instructions that inherit from a base class MyInst. Each instruction ends with an operand of type ImmOpndA, and I want to create an alternative assembly syntax that implicitly sets this last operand to 0. Here is the base instrution class:
class MyInst<...> { let AsmString = "..."; let OutOperandList = ...; let InOpernadList = (ins ..., ImmOpndA:$a); } Last operand for all inherited instructions is of type ImmOpndA. To define an alternative assembly syntax that sets $a to 0, I defined a helper multiclass like this:
multiclass AlternateSyntax<MyInst Inst> { defvar ResultPattern = !con(!setdagop(Inst.OutOperandList, Inst), !setdagop(Inst.InOperandList, Inst)); def _Alternate : Instalias<"some asm syntax", ResultPattern>; } def InstABC : MyInst<...> { ... }; defm ABC : AlternateSyntax<InstABC>; However, the tablegen does not provide operations like splice, filter or remove for DAG, I could not find a way to manipulate the ResultPattern.
Here is a workaround that I tried to set the last arg 0 and the name with an empty string:
setvar UpdatedDAG = !setdagname(!setdagarg(ResultPattern , "a", 0), "a", ""); but it causes an error in tablegen compilation here: llvm-project/llvm/utils/TableGen/Common/CodeGenInstAlias.cpp at 101ad14f535461236ba0a656554d884d6d0b25a0 · llvm/llvm-project · GitHub .
If I comment out this check, the alias works as expected. However, I’m looking for a way to achieve this without such a hacky workaround.
To support this, could we add a bang operand, such as !removedagarg? Or is there a better way to do this?