Hi Everyone,
A question about using Pat
in tablegen instruction definitions.
Suppose I have an instruction STORE
defined to take 3 parameters: value, address and address space (I want to encode address space in the instruction itself, but that is probably not important). I want to write a pattern that matches SDNode store
and extracts address space from it to pass to my instruction. E.g. as follows:
def AddrSpace : SDNodeXForm<timm, [{
uint64_t Val = cast<MemSDNode>(N)->getAddressSpace();
return CurDAG->getTargetConstant(Val, SDLoc(N), MVT::i64);
}]>;
class STORE : Instruction {
...
dag InOperandList = (ins GPR:$src, MEMri:$addr, i64imm:$aspace)
...
}
def : Pat<(store (i64 imm:$src), ADDRri:$dst),
(STORE $src, ADDRri:$dst, (AddrSpace $this))>;
Details about ADDRri
/MEMri
are probably not important, but for completeness: ADDRri
is a ComplexPattern
that returns two i64
.
In the current form pattern obviously does not work, as tblgen reports an error for undefined name “this”:
Node 'this' in output pattern but not input pattern
Giving name to store as (store:$this ...)
does not work either, fails with internal assertion:
llvm-tblgen: /home/eddy/work/llvm-project/llvm/utils/TableGen/CodeGenDAGPatterns.cpp:3125: bool llvm::TreePattern::InferAllTypes(const StringMap<SmallVector<TreePatternNode *, 1>> *): Assertion `Node->getNumTypes() == 1 && InNodes[0]->getNumTypes() == 1 && "FIXME: cannot name multiple result nodes yet"' failed.
And I can’t figure out from the doc or from existing td files how to actually reference “self”, the node that actually matched, in Pat
.
Would be glad to hear an advice.
Thanks,
Eduard