LLVM Backend for Z80

Hello.

I am playing with LLVM and trying to create Zilog Z80 Backend.
I have succesfully created basic infrastructure and now trying to extend Z80InstrInfo.td to handle more and more C code.
I have done some work with FrameIndex and now I am stuck with assert.

llc: SelectionDAG.cpp:645: bool llvm::SelectionDAG::RemoveNodeFromCSEMaps(llvm::SDNode*): Assertion `N->getOpcode() != ISD::EntryToken && "EntryToken in CSEMap!"' failed.

This code works:

void simple()
{
unsigned char i=10;
unsigned char a = 20;
}

and produces my somewhat not VERY REAL z80 assembly:

.file "simple.bc"
.text
.globl simple
.type simple,@function
simple: # @simple
# BB#0: # %entry
ld HL, SP+5
ld (SP+0), HL
ld HL, SP+4
ld (SP+2), HL
ld HL, (SP+0)
ld (HL),10
ld HL, (SP+2)
ld (HL),20
$tmp0:
.size simple, ($tmp0)-simple

But when I add one line to c:

void simple()
{
unsigned char i=10;
unsigned char a = 20;
a = a+i;
}

the llc fails to generate .S file.
I have only added this instruction to Z80InstrInfo.td

def STORE16_trunc: Z80Instr<(outs), (ins GPR16:$src, GPR16:$dst),
"ld_b ($dst),$src",
[(truncstorei8 GPR16:$src, GPR16:$dst)]>;

This is also MY PSEUDO instruction on Z80.
Next I will try to handle this is real instructions, but for now I cannot make futher due to that assertions.
Attached is my whole code + test files.

I have tried to debug but the breakpoints and showing SDNodes deesn't helped me too much.
I have observed that it is truying to remove EntryToken from proccess, but I can't figure what is in that EntryToken. According to llvm source code
EntryToken is marker used to indicate the start of the region.

Is there any magic option to get some more debug info, what is going on. And why it tries to remove EntryToken?

Thanks, Peter.

llvm_to_send.tgz (28.7 KB)

Hi Peter,

(I'm CC'ing the LLVMdev list as there might be others able to help you)

I don't know this assertion, so can't help you with that particular problem.
But concerning "more debug info": Do you know the following two links?

http://llvm.org/releases/3.0/docs/ProgrammersManual.html#DEBUG
You can find some example debug code e.g. in method Select(SDNode *Node)
in source file lib/Target/MSP430/MSP430ISelDAGToDAG.cpp

http://llvm.org/releases/3.0/docs/ProgrammersManual.html#ViewGraph
(and the -view… options in http://llvm.org/releases/3.0/docs/CodeGenerator.html#selectiondag_process)
This takes some minimal effort to setup but is incredibly useful:
Run llc with all -view… options on. This will get you a first idea on where the problem occurs.
Then if you find the causing SelectionDAG pass, let's say your Select method in Z80IselDAGToDAG,
then you can set a breakpoint there and watch the state of the selection DAG on each iteration
via CurDAG->viewGraph().

Maybe that gives you an idea where the problem could be.

Cheers,
Jonas