<div class="gmail_extra"><div class="gmail_extra" style>Hi Peter,</div><div class="gmail_extra" style><br></div><div class="gmail_extra" style>I think the problem is that you did not explicitly define stack alignment in Z80TargetMachine.cpp </div>
<div class="gmail_extra" style><br></div><div class="gmail_extra" style>DataLayout("e-p:16:8:8-i8:8:8-i16:8:8-i32:8:8-n8")</div><div class="gmail_extra" style><br></div><div class="gmail_extra" style>Try to add S16 to the string if your stack is 2-byte aligned. Refer to  <a href="http://llvm.org/docs/LangRef.html#datalayout" target="_blank" style="color:rgb(17,85,204)">http://llvm.org/docs/LangRef.html#datalayout</a> .</div>
<div class="gmail_extra" style><br></div><div class="gmail_extra" style>If it does not work, try to specify the layout in the input module using target layout directive.</div><div class="gmail_extra" style><br></div><div class="gmail_extra" style>
David</div><br><div class="gmail_quote">On Wed, Apr 25, 2012 at 4:57 PM, Peter Hanzel <span dir="ltr"><<a href="mailto:hanzelpeter@gmail.com" target="_blank">hanzelpeter@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello.<br>
<br>
I am playing with LLVM and trying to make Z80 (Zilog Z80) backend.<br>
The source code is attached.<br>
<br>
I have succesfully made some simple test. But now I have problem with ADD instruction.<br>
The source C code is:<br>
<br>
typedef struct<br>
{<br>
unsigned char id1;<br>
unsigned char id2;<br>
unsigned char id3;<br>
<br>
} testS;<br>
<br>
void simple()<br>
{<br>
testS test;<br>
test.id1 = 0x40;<br>
test.id2 = 0x80;<br>
test.id3 = 0xc0;<br>
}<br>
<br>
It produces this LLVM IR:<br>
<br>
%struct.testS = type { i8, i8, i8 }<br>
<br>
define void @simple() nounwind {<br>
entry:<br>
 %test = alloca %struct.testS, align 1<br>
 %id1 = getelementptr inbounds %struct.testS* %test, i32 0, i32 0<br>
 store i8 64, i8* %id1, align 1<br>
 %id2 = getelementptr inbounds %struct.testS* %test, i32 0, i32 1<br>
 store i8 -128, i8* %id2, align 1<br>
 %id3 = getelementptr inbounds %struct.testS* %test, i32 0, i32 2<br>
 store i8 -64, i8* %id3, align 1<br>
 ret void<br>
}<br>
<br>
And with llc -filetype=asm -march=z80 a get this .s file:<br>
<br>
.file "simple4.bc"<br>
.text<br>
.globl simple<br>
.type simple,@function<br>
simple:                                 # @simple<br>
# BB#0:                                 # %entry<br>
ld HL, 8<br>
add HL,SP                        <--- problem line<br>
ld DE, 1<br>
ld BC, 2<br>
ld (SP+6), BC<br>
ld B, H<br>
ld C, L<br>
or BC, DE<br>
ld (SP+4), BC<br>
ld (HL),64<br>
ld D, H<br>
ld E, L<br>
ld BC, (SP+6)<br>
or DE, BC<br>
ld BC, (SP+4)<br>
ld H, B<br>
ld L, C<br>
ld (HL),-128<br>
ld H, D<br>
ld L, E<br>
ld (HL),-64<br>
$tmp0:<br>
.size simple, ($tmp0)-simple<br>
<br>
<br>
The problem is that llc replaces ADD instruction with OR.<br>
<br>
Without defining OR16 function, the .S is not generated and claims that it cannot select OR instruction.<br>
So I added OR16 (that's the or BC,DE piece of code).<br>
<br>
But problem is that I am using the first two lines:<br>
<br>
ld HL, 8<br>
add HL,SP<br>
<br>
For FrameIndex and the HL register will contain SP which is only two 2bytes aligned.<br>
So "OR with 1" will work, but for second assigned :OR with 2" will not work.<br>
<br>
I suspect that llc is assuming that HL will contain 8 (that's the start) and or-ing 8 with 1 or with 2 is ok.<br>
But my HL has also added SP to it.<br>
This is how my ISD::FrameIndex instruction look like:<br>
<br>
def addHLdisp : Z80Instr<(outs HL16:$dst), (ins i16imm:$disp, GPR16:$src),<br>
"ld $dst, $disp\n\tadd $dst,$src",<br>
[(set HL16:$dst, (add GPR16:$src, (i16 imm:$disp)))]>;<br>
<br>
So it say that HL16:$dst wich is only HL register, will be changed.<br>
I also tried to change it to<br>
<(outs HL16:$dst), (ins i16imm:$disp, SP16:$src),<br>
<br>
But the output is the same.<br>
<br>
Can someone tell me what I am doing wrong?<span class="HOEnZb"><font color="#888888"><br>
<br>
Peter.<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
</font></span><br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br></div>