+ unsigned RegClassID = getRegClassIDOfValue( CallArg);
+ unsigned regType = getRegType( RegClassID, CallArg->getType() );
+
+ // Find whether this argument is coming in a register (if not, on stack)
+ // Also find the correct register the argument must use (UniArgReg)
+ //
+ bool isArgInReg = false;
+ unsigned UniArgReg = InvalidRegNum; // reg that LR MUST be colored with
+ unsigned regClassIDOfArgReg = MAXINT; // reg class of chosen reg
+
+ // Find the register that must be used for this arg, depending on
+ // whether it is an INT or FP value. Here we ignore whether or not it
+ // is a varargs calls, because FP arguments will be explicitly copied
+ // to an integer Value and handled under (argCopy != NULL) below.
+ int regNum = (regType == IntRegType)
+ ? regNumForIntArg(/*inCallee*/ false, /*isVarArgs*/ false,
+ argNo, intArgNo++, fpArgNo, regClassIDOfArgReg)
+ : regNumForFPArg(regType, /*inCallee*/ false, /*isVarArgs*/ false,
+ argNo, intArgNo, fpArgNo++, regClassIDOfArgReg);
+
+ if(regNum != InvalidRegNum) {
+ isArgInReg = true;
+ UniArgReg = getUnifiedRegNum( regClassIDOfArgReg, regNum);
+ assert(regClassIDOfArgReg == RegClassID &&
+ "Moving values between reg classes must happen during selection");
+ }
+
+ // not possible to have a null LR since all args (even consts)
+ // must be defined before
+ if (!LR) {
+ cerr << " ERROR: In call instr, no LR for arg: " << RAV(CallArg) <<"\n";
+ assert(LR && "NO LR for call arg");
+ }
+
+ InitializeOutgoingArg(CallMI, CallAI, PRA, LR, regType, RegClassID,
+ UniArgReg, argNo, AddedInstrnsBefore);
+
+ // Repeat for the second copy of the argument, which would be
+ // an FP argument being passed to a function with no prototype.
+ // It may either be passed as a copy in an integer register
+ // (in argCopy), or on the stack (useStackSlot).
+ const Value *argCopy = argDesc->getArgInfo(i).getArgCopy();
+ if (argCopy != NULL)
+ {
+ assert(regType != IntRegType && argCopy->getType()->isInteger()
+ && "Must be passing copy of FP argument in int register");
+
+ unsigned copyRegClassID = getRegClassIDOfValue(argCopy);
+ unsigned copyRegType = getRegType(copyRegClassID, argCopy->getType());
+
+ int copyRegNum = regNumForIntArg(/*inCallee*/false, /*isVarArgs*/false,
+ argNo, intArgNo, fpArgNo-1,
+ regClassIDOfArgReg);
+ assert(copyRegNum != InvalidRegNum);
+ assert(regClassIDOfArgReg == copyRegClassID &&
+ "Moving values between reg classes must happen during selection");
+
+ InitializeOutgoingArg(CallMI, CallAI, PRA,
+ LRI.getLiveRangeForValue(argCopy), copyRegType,
+ copyRegClassID, copyRegNum, argNo,
+ AddedInstrnsBefore);
+ }
+
+ if (regNum != InvalidRegNum &&
+ argDesc->getArgInfo(i).usesStackSlot())
+ {
+ // Pass the argument via the stack in addition to regNum
+ assert(regType != IntRegType && "Passing an integer arg. twice?");
+ assert(!argCopy && "Passing FP arg in FP reg, INT reg, and stack?");
+ InitializeOutgoingArg(CallMI, CallAI, PRA, LR, regType, RegClassID,
+ InvalidRegNum, argNo, AddedInstrnsBefore);
+ }
+ } // for each parameter in call instruction
+
+ // If we added any instruction before the call instruction, verify
+ // that they are in the proper order and if not, reorder them
+ //
+ std::vector<MachineInstr *> ReorderedVec;
+ if (!AddedInstrnsBefore.empty()) {
+
+ if (DEBUG_RA) {
+ cerr << "\nCalling reorder with instrns: \n";
+ for(unsigned i=0; i < AddedInstrnsBefore.size(); i++)
+ cerr << *(AddedInstrnsBefore[i]);
+ }
+
+ OrderAddedInstrns(AddedInstrnsBefore, ReorderedVec, PRA);
+ assert(ReorderedVec.size() >= AddedInstrnsBefore.size()
+ && "Dropped some instructions when reordering!");
+
+ if (DEBUG_RA) {
+ cerr << "\nAfter reordering instrns: \n";
+ for(unsigned i = 0; i < ReorderedVec.size(); i++)
+ cerr << *ReorderedVec[i];
+ }
+ }
+
+ // Now insert caller saving code for this call instruction
+ //
+ insertCallerSavingCode(CallAI->InstrnsBefore, CallAI->InstrnsAfter,
+ CallMI, BB, PRA);
+
+ // Then insert the final reordered code for the call arguments.
+ //
+ for(unsigned i=0; i < ReorderedVec.size(); i++)
+ CallAI->InstrnsBefore.push_back( ReorderedVec[i] );
+}
+
+//---------------------------------------------------------------------------
+// This method is called for an LLVM return instruction to identify which
+// values will be returned from this method and to suggest colors.
+//---------------------------------------------------------------------------
+void UltraSparcRegInfo::suggestReg4RetValue(MachineInstr *RetMI,
+ LiveRangeInfo &LRI) const {
+
+ assert( (target.getInstrInfo()).isReturn( RetMI->getOpCode() ) );