Closed thirtythreeforty closed 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.
:+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?
Yes. Use this llvm z80 backend and clang only as experimental, because not all llvm bytecode may be lowered to the z80 native code.
What won't work? Is it something I would be able to write?
A list of feature, which need write is not small. If you want, you can join to this project and help me write it.
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
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.
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.
@thirtythreeforty I know this is an old post but could you tell me how you built clang from this repository?
@Ayymoose I have no idea anymore, sorry. Your best bet is to look through the LLVM documentation.
@Ayymoose, clang can be built in a standard way for projects using cmake. How do you build it?
After building LLVM and Clang from these repos, I wrote a test program:
Then I attempted to compile it. Note that I only want the assembly (I have my own assembler):
If I replace all the
int
s withchar
s orunsigned char
s, llc doesn't complain (although clang warns aboutmain
's return type).Is this an issue, or has it just not been implemented?