[LLVMdev] Symbol folding with MC

Borja Ferrer
Tue, 26 Apr 2011 20:27:30 -0000

Hello Jim thanks for the reply,

For normal additions with immediates I've done the same as ARM does,
basically transforming add(x, imm) nodes to sub(x, -imm) with a pattern in
the .td file like this:
def : Pat<(add DLDREGS:$src1, imm:$src2),
              (SUBIWRdK DLDREGS:$src1, (imm16_neg_XFORM imm:$src2))>;

Now, the typical pattern concerning additions with global addresses looks
like this: (taken from x86)
def : Pat<(add GR32:$src1, (X86Wrapper tglobaladdr :$src2)),
              (ADD32ri GR32:$src1, tglobaladdr:$src2)>;

but i can't write that since i dont have an add with imm instr, and doing:

def : Pat<(add DREGS:$src, (Wrapper tglobaladdr:$src2)),
              (SUBIWRdK DREGS:$src, tglobaladdr:$src2)>;
is wrong because the tglobaladdr has to be negated somehow, so i don't
understand how should I negate the symbol reference using patterns, if it's
even possible. The obvious hack is adding a "-" char when lowering the
symbol reference into text.

Regarding my second question, as you mentioned all symbols have static
addresses so no relocations are performed, so it should be safe to fold
immediate operations with the symbol reference. My problem here is that i
don't know how to fold an arbitrary expression on a global (initially in the
form of a DAG) to something that can be translated later into an expression
with MC. It's something weird because operations are performed in the
operand of an instruction, and since it has to support any arbitrary
expression you can't have all combinations of operations using custom
instructions. So how should i proceed in here using custom lowering or
target dag combines?

Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20110426/9289d36a/attachment.html>