Use live out sets for return values instead of imp_defs, which is cleaner and faster.
authorChris Lattner <sabre@nondot.org>
Sat, 9 Apr 2005 15:23:56 +0000 (15:23 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 9 Apr 2005 15:23:56 +0000 (15:23 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21181 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/X86/X86ISelPattern.cpp
lib/Target/X86/X86ISelSimple.cpp

index 61b7e597e1aba7a2bd1488c821671d88095f5c5e..6613ba605719dfb87c9065312f086bc2f4ef7895 100644 (file)
@@ -160,6 +160,26 @@ X86TargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) {
   if (F.isVarArg())
     VarArgsFrameIndex = MFI->CreateFixedObject(1, ArgOffset);
   ReturnAddrIndex = 0;  // No return address slot generated yet.
+
+  // Finally, inform the code generator which regs we return values in.
+  switch (getValueType(F.getReturnType())) {
+  default: assert(0 && "Unknown type!");
+  case MVT::isVoid: break;
+  case MVT::i1:
+  case MVT::i8:
+  case MVT::i16:
+  case MVT::i32:
+    MF.addLiveOut(X86::EAX);
+    break;
+  case MVT::i64:
+    MF.addLiveOut(X86::EAX);
+    MF.addLiveOut(X86::EDX);
+    break;
+  case MVT::f32:
+  case MVT::f64:
+    MF.addLiveOut(X86::ST0);
+    break;
+  }
   return ArgValues;
 }
 
@@ -2929,9 +2949,6 @@ void ISel::Select(SDOperand N) {
 
       BuildMI(BB, X86::MOV32rr, 1, X86::EAX).addReg(Tmp1);
       BuildMI(BB, X86::MOV32rr, 1, X86::EDX).addReg(Tmp2);
-      // Declare that EAX & EDX are live on exit.
-      BuildMI(BB, X86::IMPLICIT_USE, 3).addReg(X86::EAX).addReg(X86::EDX)
-       .addReg(X86::ESP);
       break;
     case 2:
       if (getRegPressure(N.getOperand(0)) > getRegPressure(N.getOperand(1))) {
@@ -2945,12 +2962,9 @@ void ISel::Select(SDOperand N) {
       default: assert(0 && "All other types should have been promoted!!");
       case MVT::f64:
        BuildMI(BB, X86::FpSETRESULT, 1).addReg(Tmp1);
-       // Declare that top-of-stack is live on exit
-       BuildMI(BB, X86::IMPLICIT_USE, 2).addReg(X86::ST0).addReg(X86::ESP);
        break;
       case MVT::i32:
        BuildMI(BB, X86::MOV32rr, 1, X86::EAX).addReg(Tmp1);
-       BuildMI(BB, X86::IMPLICIT_USE, 2).addReg(X86::EAX).addReg(X86::ESP);
        break;
       }
       break;
index 48546aa54f0083e8f15312f3defd243b00d44f10..6c37b7095f84d83975f45a85cbe95be63dc38ce9 100644 (file)
@@ -618,7 +618,8 @@ void X86ISel::LoadArgumentsToVirtualRegs(Function &Fn) {
   unsigned ArgOffset = 0;   // Frame mechanisms handle retaddr slot
   MachineFrameInfo *MFI = F->getFrameInfo();
 
-  for (Function::arg_iterator I = Fn.arg_begin(), E = Fn.arg_end(); I != E; ++I) {
+  for (Function::arg_iterator I = Fn.arg_begin(), E = Fn.arg_end();
+       I != E; ++I) {
     bool ArgLive = !I->use_empty();
     unsigned Reg = ArgLive ? getReg(*I) : 0;
     int FI;          // Frame object index
@@ -676,6 +677,25 @@ void X86ISel::LoadArgumentsToVirtualRegs(Function &Fn) {
   // llvm.va_start.
   if (Fn.getFunctionType()->isVarArg())
     VarArgsFrameIndex = MFI->CreateFixedObject(1, ArgOffset);
+
+  // Finally, inform the compiler what our live-outs will be, aka, what we will
+  // be returning in registers.
+  if (Fn.getReturnType() != Type::VoidTy)
+    switch (getClassB(Fn.getReturnType())) {
+    default: assert(0 && "Unknown type!");
+    case cByte:
+    case cShort:
+    case cInt:
+      F->addLiveOut(X86::EAX);
+      break;
+    case cLong:
+      F->addLiveOut(X86::EAX);
+      F->addLiveOut(X86::EDX);
+      break;
+    case cFP:
+      F->addLiveOut(X86::ST0);
+      break;
+    }
 }
 
 /// EmitSpecialCodeForMain - Emit any code that needs to be executed only in
@@ -1434,23 +1454,16 @@ void X86ISel::visitReturnInst(ReturnInst &I) {
   case cShort:
   case cInt:
     promote32(X86::EAX, ValueRecord(RetVal));
-    // Declare that EAX is live on exit
-    BuildMI(BB, X86::IMPLICIT_USE, 2).addReg(X86::EAX).addReg(X86::ESP);
     break;
   case cFP: {                  // Floats & Doubles: Return in ST(0)
     unsigned RetReg = getReg(RetVal);
     BuildMI(BB, X86::FpSETRESULT, 1).addReg(RetReg);
-    // Declare that top-of-stack is live on exit
-    BuildMI(BB, X86::IMPLICIT_USE, 2).addReg(X86::ST0).addReg(X86::ESP);
     break;
   }
   case cLong: {
     unsigned RetReg = getReg(RetVal);
     BuildMI(BB, X86::MOV32rr, 1, X86::EAX).addReg(RetReg);
     BuildMI(BB, X86::MOV32rr, 1, X86::EDX).addReg(RetReg+1);
-    // Declare that EAX & EDX are live on exit
-    BuildMI(BB, X86::IMPLICIT_USE, 3).addReg(X86::EAX).addReg(X86::EDX)
-      .addReg(X86::ESP);
     break;
   }
   default: