//===----------------------------------------------------------------------===// // Eliminating the 'void' Type //===----------------------------------------------------------------------===// 4/26/2008 - initial revision The 'void' type in llvm is a weird beast. People often expect to use it to make void pointers, but this is not allowed: the only place void is currently allowed to exist is as the return value of a function. Having a type and concept for such a special case thing, seems strange. In the old days, this was a necesity, but since we now have support for multiple return values from functions, we can eliminate 'void' in favor of '{}': a multiple return value with no elements. //===----------------------------------------------------------------------===// // The plan // The idea here is pretty simple. In the LLVM IR, instead of ever seeing void, we would now see '{}': the empty struct type. However, having {} everywhere in .ll files would be very ugly. As such, I propose that we continue using 'void' in the same ways we do now, it's just that the asmparser will turn 'void' as '{}' everywhere it is used. We can even make 'Type::VoidTy' be a pointer to '{}', which makes forming prototypes as simple as before. The only significant change this entails is that 'ret void' is now a synonym for 'ret {} {}', which is a return instruction with one operand, instead of a return instruction with zero operands. This means that existing code which does: if (RI->getNumOperands() == 0) ... may need to become: if (RI->getOperand(0)->getType() == Type::VoidTy) OTOH, since that code should already be handling multiple return values, this may mean that the special case for void may be completely deleted: a return of zero values should be able to be handled just like a return of 15 values. This may end up being a net reduction of code in various transformations that hack on LLVM IR.