Inline assembler in D and LDC, round 2

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Fri Feb 6 05:56:06 PST 2009


Walter Bright wrote:
> Frits van Bommel wrote:
>> His approach depends on DMD directly emitting x86 machine code, so it 
>> can just emit 'RET' and be done with it.
>>
>> LDC on the other hand needs to emit LLVM asm, which requires it to 
>> specify an explicit return value. My approach is a way to extract that 
>> return value from the inline asm, allowing it to emulate DMD behavior 
>> within the LLVM IR.
> 
> Ok, so why not, for a function that returns an int, simply have the 
> compiler silently tack on the LLVM equivalent of "return EAX"?

Because LLVM doesn't allow specification of hardware registers in the 
IR. Everything must be a virtual register. The way I proposed LDC 
implement this is basically to tell the inline-asm IR "Put EAX in 
%virtual-eax" and to then return that register.
It will in all likelyhood have the same effect though, assuming a tiny 
bit of optimization and a minimally competent register allocator.



More information about the Digitalmars-d mailing list