-void
-ISel::visitReturnInst (ReturnInst & I)
-{
- if (I.getNumOperands () == 1)
- {
- bool unsignedReturnValue = I.getOperand(0)->getType()->isUnsigned();
- unsigned val = getReg (I.getOperand (0));
- unsigned operandSize =
- I.getOperand (0)->getType ()->getPrimitiveSize ();
- bool isFP = I.getOperand (0)->getType ()->isFloatingPoint ();
- if (isFP)
- {
- // ret float/double: top of FP stack
- // FLD <val>
- switch (operandSize)
- {
- case 4:
- BuildMI (BB, X86::FLDr4, 1, X86::NoReg).addReg (val);
- break;
- case 8:
- BuildMI (BB, X86::FLDr8, 1, X86::NoReg).addReg (val);
- break;
- default:
- visitInstruction (I);
- break;
- }
- }
- else
- {
- switch (operandSize)
- {
- case 1:
- // ret sbyte, ubyte: Extend value into EAX and return
- if (unsignedReturnValue) {
- BuildMI (BB, X86::MOVZXr32r8, 1, X86::EAX).addReg (val);
- } else {
- BuildMI (BB, X86::MOVSXr32r8, 1, X86::EAX).addReg (val);
- }
- break;
- case 2:
- // ret short, ushort: Extend value into EAX and return
- if (unsignedReturnValue) {
- BuildMI (BB, X86::MOVZXr32r16, 1, X86::EAX).addReg (val);
- } else {
- BuildMI (BB, X86::MOVSXr32r16, 1, X86::EAX).addReg (val);
- }
- break;
- case 4:
- // ret int, uint, ptr: Move value into EAX and return
- BuildMI (BB, X86::MOVrr32, 1, X86::EAX).addReg (val);
- break;
- case 8:
- // ret long: use EAX(least significant 32 bits)/EDX (most
- // significant 32)...uh, I think so Brain, but how do i call
- // up the two parts of the value from inside this mouse
- // cage? *zort*
- default:
- // abort
- visitInstruction (I);
- break;
- }
- }
+void ISel::visitReturnInst (ReturnInst & I) {
+ if (I.getNumOperands() == 0) {
+ // Emit a 'ret' instruction
+ BuildMI(BB, X86::RET, 0);
+ return;
+ }
+
+ unsigned val = getReg(I.getOperand(0));
+ unsigned Class = getClass(I.getType());
+ bool isUnsigned = I.getOperand(0)->getType()->isUnsigned();
+ switch (Class) {
+ case cByte:
+ // ret sbyte, ubyte: Extend value into EAX and return
+ if (isUnsigned) {
+ BuildMI (BB, X86::MOVZXr32r8, 1, X86::EAX).addReg (val);
+ } else {
+ BuildMI (BB, X86::MOVSXr32r8, 1, X86::EAX).addReg (val);
+ }
+ break;
+ case cShort:
+ // ret short, ushort: Extend value into EAX and return
+ if (unsignedReturnValue) {
+ BuildMI (BB, X86::MOVZXr32r16, 1, X86::EAX).addReg (val);
+ } else {
+ BuildMI (BB, X86::MOVSXr32r16, 1, X86::EAX).addReg (val);