Load/Store Instruction Error

Hi all,

I started to write an LLVM backend for custom CPU. I created XXXInstrInfo but there are some problems. I searched for it but I couldn’t find anything. Can anyone help me?

include “XXXInstrFormats.td”
def simm16 : Operand {
let DecoderMethod = “DecodeSimm16”;
}
def mem : Operand {
let PrintMethod = “printMemOperand”;
let MIOperandInfo = (ops GPRegs, GPRegs);
let EncoderMethod = “getMemEncoding”;
}
def addr : ComplexPattern<i32, 2, “SelectAddr”, [frameindex], [SDNPWantParent]>;

def LDRAM : FG1<0b000001, (outs GPRegs:$dst), (ins mem:$src), “ldram $dst,$src”, [(set GPRegs:$dst, (load addr:$src))]>;
def STRAM : FG1<0b000010, (outs), (ins GPRegs:$src, mem:$dst), “stram $dst,$src”, [(store GPRegs:$src, addr:$dst)]>;
def ADD : FG2<0b000000, (outs GPRegs:$dst), (ins GPRegs:$src1, GPRegs:$src2), “add $dst,$src1,$src2”, [(set GPRegs:$dst, (add GPRegs:$src1, GPRegs:$src2))]>;

Error Message:
LDRAM: (set GPRegs:{i32:f32}:$dst, (ld:{i32:f32} addr:iPTR:$src)<<P:Predicate_unindexedload>><<P:Predicate_load>>)
Included from /home/jwon/Desktop/llvmTest/llvm-3.4/lib/Target/XXX/XXXOther.td:10:
Included from /home/jwon/Desktop/llvmTest/llvm-3.4/lib/Target/XXX/XXX.td:1:
/home/jwon/Desktop/llvmTest/llvm-3.4/lib/Target/XXX/XXXInstrInfo.td:34:1: error: In LDRAM: Could not infer all types in pattern!
def LDRAM : FG1<0b000001, (outs GPRegs:$dst), (ins mem:$src), “ldram $dst,$src”, [(set GPRegs:$dst, (load addr:$src))]>;
^
STRAM: (st GPRegs:{i32:f32}:$src, addr:iPTR:$dst)<<P:Predicate_unindexedstore>><<P:Predicate_store>>
Included from /home/jwon/Desktop/llvmTest/llvm-3.4/lib/Target/XXX/XXXOther.td:10:
Included from /home/jwon/Desktop/llvmTest/llvm-3.4/lib/Target/XXX/XXX.td:1:
/home/jwon/Desktop/llvmTest/llvm-3.4/lib/Target/XXX/XXXInstrInfo.td:36:1: error: In STRAM: Could not infer all types in pattern!
def STRAM : FG1<0b000010, (outs), (ins GPRegs:$src, mem:$dst), “stram $dst,$src”, [(store GPRegs:$src, addr:$dst)]>;
^

Thanks in advance.

Hi!

There is doc
http://llvm.org/docs/WritingAnLLVMBackend.html
look for ComplexPattern:

def STrr : F3_1< 3, 0b000100, (outs), (ins MEMrr:$addr, IntRegs:$src),
“st $src, [$addr]”, [(store i32:$src, ADDRrr:$addr)]>;
ADDRrr is a memory mode that is also defined in SparcInstrInfo.td:
def ADDRrr : ComplexPattern<i32, 2, “SelectADDRrr”, , >;

Maybe ComplexPattern is what you want…

Hi Ramin,

Error Message:
LDRAM: (set GPRegs:{i32:f32}:$dst, (ld:{i32:f32}
addr:iPTR:$src)<<P:Predicate_unindexedload>><<P:Predicate_load>>)
Included from

Each particular instance of a pattern has to be well-typed. In this
case you can see that LLVM can't decide whether you intended the
pattern to be loading i32 or f32 (the "{i32:f32}" tags).

So you have to explicitly pick one and annotate the type. In this case
(and for the LD only), you'd probably end up writing something like:

def LDRAM : FG1<0b000001, (outs GPRegs:$dst), (ins mem:$src), "ldram
$dst,$src", [(set GPRegs:$dst, (i32 (load addr:$src)))]>;
def : Pat<(f32 (load addr:$src)), (LDRAM addr:$src)>;

using the second "Pat" instantiation to get the other version of the load.

Cheers.

Tim.

In the first definition, I think you defined that the loaded data contains an i32. But the second definition (Pat) is not clear.

Actually, I do not too much knowledge about Patters, PatFrags and ComplexPatterns etc. and there is no document about them.

Some explanation will be good for me.

Thanks.

In the first definition, I think you defined that the loaded data contains
an i32. But the second definition (Pat) is not clear.

Yep. The second definition was *just* a code-generation pattern so
that the backend knows what do do if it needs to load a float (f32).
The end result is that in the table (in
build/lib/Target/XXX/XXXGenDAGISel.inc) there'll now be two entries:
one that triggers when the type is i32, and one that triggers when
it's f32.

The main oddity comes from the fact that you don't ever write "(set
ABC, ...)" in patterns that appear in separate Pats, that's only for
patterns in the Instruction itself.

It's all a bit messy, unfortunately, but it works in the end.

Actually, I do not too much knowledge about Patters, PatFrags and
ComplexPatterns etc. and there is no document about them.

The closest is include/llvm/Target/TargetSelectionDAG.td, and the
existing backends to see what's possible of course.

Cheers.

Tim.