Memory-to-memory .td example?


I'm currently doing some research on instruction set architectures and have been looking for a a C compiler as a tool to assist in the work. I'm new to LLVM, have read through the documentation, and compiled the release to run some tests.

I looked over the documentation, and read through the .td files for some of the included architectures. All are register-based architectures. However, my work is looking at a memory-to-memory architecture, and I'm looking for some examples (or more documentation on writing .td files) to use as the basis for the .td files I need to write.

Any help (or pointers to examples) is appreciated!


This may help you

Thank you

Here’s an example of how we are doing this, in table gen, of a mem, mem, mem operation:

def directStore : PatFrag<(ops node:$ptr, node:$val), (store node:$ptr, node:$val), [{… we have some conditions here, etc… }]>;

class SetABDIn<string asmstr, DAGOperand srcA, DAGOperand srcB, DAGOperand dstD, list
: A_B_D<(outs), (ins srcA:$srcA, srcB:$srcB, dstD:$dstD),
!strconcat(asmstr, “\t$srcA, $srcB, $dstD”), pattern, IIAlu>
let mayStore = 1;
let mayLoad = 1;
// whatever else here

multiclass ABD<string asmstr, SDPatternOperator OpNode, RegisterClass srcAReg, RegisterClass srcBReg,
RegisterClass dstReg, ValueType srcAType, ValueType srcBType, ValueType dstType,
Operand ImmOd, ImmLeaf imm_type>
def MEM_MEM_MEM: SetABDIn<asmstr, memXX, memXX, memXX,
[{directStore (OpNode (srcAType (load addr:$srcA)), (srcBType (load addr:$srcB)), addr:$dstD)]>;
// there are other combinations here, etc…

You obviously won’t be able to use this directly but I hope this gives you an idea, I hope I understood your question correctly, apologies if I did not.



ps. If your architecture can do mem-mem operations, you will run into problems because common sub will always want to load the value into a register if it’s being used more than once, we’re having to generate a backend pass to reverse this, just fyi.