earl1k / llvm-z80

LLVM backend for Z80
Other
88 stars 13 forks source link

Error when instantiating ints #1

Closed thirtythreeforty closed 11 years ago

thirtythreeforty commented 11 years ago

After building LLVM and Clang from these repos, I wrote a test program:

int main(void)
{
        int i = 0;
        return i;
}

Then I attempted to compile it. Note that I only want the assembly (I have my own assembler):

$ clang -S -emit-llvm hello.c
$ llc -march=z80 hello.ll
LLVM ERROR: Cannot select: 0x21434a0: i16 = FrameIndex<1> [ID=4]
In function: main
$

If I replace all the ints with chars or unsigned chars, llc doesn't complain (although clang warns about main's return type).

Is this an issue, or has it just not been implemented?

earl1k commented 11 years ago

You need add some clang options. Try compile like this: clang -target z80 -S -emit-llvm Or like this (with optimization code option): clang -target z80 -S -emit-llvm -Os By default clang generate code to x86, where int size is 32 bits. z80 backend can return only 8 or 16 bits result from function, now.

thirtythreeforty commented 11 years ago

:+1: that fixed the issue. (I was unaware that LLVM bytecode was that specific; I thought it was more generic. :)

A more general question regarding -target z80. If I use that switch, is this usable as a C compiler, for experimental day-to-day use?

earl1k commented 11 years ago

Yes. Use this llvm z80 backend and clang only as experimental, because not all llvm bytecode may be lowered to the z80 native code.

thirtythreeforty commented 11 years ago

What won't work? Is it something I would be able to write?

earl1k commented 11 years ago

A list of feature, which need write is not small. If you want, you can join to this project and help me write it.

tommythorn commented 11 years ago

On Nov 8, 2013, at 08:13 , Dmitriy Limonov notifications@github.com wrote:

A list of feature, which need write is not small. If you want, you can join to this project and help me write it.

I can't remember what I ran into that didn't work, but general C support was pretty good, but unfortunately the generated code is less efficient than what I got from sdcc.

I think the Z80 is hard in general to compile for (as many pre-RISC architectures) and the best sequences are rarely obvious, see fx. http://www.chilliant.com/z80shift.html. I think a a super optimizer-like solution could help here, but I haven't had time to do much about it.

Tommy

thirtythreeforty commented 11 years ago

Less efficient than SDCC? That's worrisome; SDCC isn't very bright at all.

Alas, I'm not very familiar with compiler internals, although I am pretty good at assembly.

tommythorn commented 11 years ago

On Nov 8, 2013, at 12:17 , thirtythreeforty notifications@github.com wrote:

Less efficient than SDCC? That's worrisome; SDCC isn't very bright at all.

I apologize not having the time to produce examples of what I'm talking about, but let me try elaborate none the less:

While LLVM obviously have real and respectable optimizations, at the micro level, the instruction selection is in many instances worse than the, hardly-optimizing and very limited, sdcc.

It's quite possible that, in the large, the former more than compensates for the latter, but on my code it didn't.

For a simple RISC, generating near-optimal code is so much easier.

Note, this isn't a complaint! I think llvm-z80 is fantastic and holds great potential.

Ayymoose commented 7 years ago

@thirtythreeforty I know this is an old post but could you tell me how you built clang from this repository?

thirtythreeforty commented 7 years ago

@Ayymoose I have no idea anymore, sorry. Your best bet is to look through the LLVM documentation.

earl1k commented 7 years ago

@Ayymoose, clang can be built in a standard way for projects using cmake. How do you build it?