namespace llvm {
class CallInst;
class CCState;
+ class CCValAssign;
class FastISel;
class FunctionLoweringInfo;
class ImmutableCallSite;
class MachineInstr;
class MachineJumpTableInfo;
class MachineLoop;
+ class MachineRegisterInfo;
class Mangler;
class MCContext;
class MCExpr;
bool doesNotReturn = false,
bool isReturnValueUsed = true) const;
+ /// Check whether parameters to a call that are passed in callee saved
+ /// registers are the same as from the calling function. This needs to be
+ /// checked for tail call eligibility.
+ bool parametersInCSRMatch(const MachineRegisterInfo &MRI,
+ const uint32_t *CallerPreservedMask,
+ const SmallVectorImpl<CCValAssign> &ArgLocs,
+ const SmallVectorImpl<SDValue> &OutVals) const;
+
//===--------------------------------------------------------------------===//
// TargetLowering Optimization Methods
//
#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/CodeGen/Analysis.h"
+#include "llvm/CodeGen/CallingConvLower.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineJumpTableInfo.h"
+#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/SelectionDAG.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DerivedTypes.h"
return isUsedByReturnOnly(Node, Chain);
}
+bool TargetLowering::parametersInCSRMatch(const MachineRegisterInfo &MRI,
+ const uint32_t *CallerPreservedMask,
+ const SmallVectorImpl<CCValAssign> &ArgLocs,
+ const SmallVectorImpl<SDValue> &OutVals) const {
+ for (unsigned I = 0, E = ArgLocs.size(); I != E; ++I) {
+ const CCValAssign &ArgLoc = ArgLocs[I];
+ if (!ArgLoc.isRegLoc())
+ continue;
+ unsigned Reg = ArgLoc.getLocReg();
+ // Only look at callee saved registers.
+ if (MachineOperand::clobbersPhysReg(CallerPreservedMask, Reg))
+ continue;
+ // Check that we pass the value used for the caller.
+ // (We look for a CopyFromReg reading a virtual register that is used
+ // for the function live-in value of register Reg)
+ SDValue Value = OutVals[I];
+ if (Value->getOpcode() != ISD::CopyFromReg)
+ return false;
+ unsigned ArgReg = cast<RegisterSDNode>(Value->getOperand(1))->getReg();
+ if (MRI.getLiveInPhysReg(ArgReg) != Reg)
+ return false;
+ }
+ return true;
+}
+
/// \brief Set CallLoweringInfo attribute flags based on a call instruction
/// and called function attributes.
void TargetLowering::ArgListEntry::setAttributes(ImmutableCallSite *CS,
if (CCInfo.getNextStackOffset() > FuncInfo->getBytesInStackArgArea())
return false;
- // Parameters passed in callee saved registers must have the same value in
- // caller and callee.
- for (unsigned I = 0, E = ArgLocs.size(); I != E; ++I) {
- const CCValAssign &ArgLoc = ArgLocs[I];
- if (!ArgLoc.isRegLoc())
- continue;
- unsigned Reg = ArgLoc.getLocReg();
- // Only look at callee saved registers.
- if (MachineOperand::clobbersPhysReg(CallerPreserved, Reg))
- continue;
- // Check that we pass the value used for the caller.
- // (We look for a CopyFromReg reading a virtual register that is used
- // for the function live-in value of register Reg)
- SDValue Value = OutVals[I];
- if (Value->getOpcode() != ISD::CopyFromReg)
- return false;
- unsigned ArgReg = cast<RegisterSDNode>(Value->getOperand(1))->getReg();
- const MachineRegisterInfo &MRI = MF.getRegInfo();
- if (MRI.getLiveInPhysReg(ArgReg) != Reg)
- return false;
- }
+ const MachineRegisterInfo &MRI = MF.getRegInfo();
+ if (!parametersInCSRMatch(MRI, CallerPreserved, ArgLocs, OutVals))
+ return false;
return true;
}
}
}
- // Parameters passed in callee saved registers must have the same value in
- // caller and callee.
- for (unsigned I = 0, E = ArgLocs.size(); I != E; ++I) {
- const CCValAssign &ArgLoc = ArgLocs[I];
- if (!ArgLoc.isRegLoc())
- continue;
- unsigned Reg = ArgLoc.getLocReg();
- // Only look at callee saved registers.
- if (MachineOperand::clobbersPhysReg(CallerPreserved, Reg))
- continue;
- // Check that we pass the value used for the caller.
- // (We look for a CopyFromReg reading a virtual register that is used
- // for the function live-in value of register Reg)
- SDValue Value = OutVals[I];
- if (Value->getOpcode() != ISD::CopyFromReg)
- return false;
- unsigned ArgReg = cast<RegisterSDNode>(Value->getOperand(1))->getReg();
- const MachineRegisterInfo &MRI = MF.getRegInfo();
- if (MRI.getLiveInPhysReg(ArgReg) != Reg)
- return false;
- }
+ const MachineRegisterInfo &MRI = MF.getRegInfo();
+ if (!parametersInCSRMatch(MRI, CallerPreserved, ArgLocs, OutVals))
+ return false;
}
return true;
}
}
- // Parameters passed in callee saved registers must have the same value in
- // caller and callee.
- for (unsigned I = 0, E = ArgLocs.size(); I != E; ++I) {
- const CCValAssign &ArgLoc = ArgLocs[I];
- if (!ArgLoc.isRegLoc())
- continue;
- unsigned Reg = ArgLoc.getLocReg();
- // Only look at callee saved registers.
- if (MachineOperand::clobbersPhysReg(CallerPreserved, Reg))
- continue;
- // Check that we pass the value used for the caller.
- // (We look for a CopyFromReg reading a virtual register that is used
- // for the function live-in value of register Reg)
- SDValue Value = OutVals[I];
- if (Value->getOpcode() != ISD::CopyFromReg)
- return false;
- unsigned ArgReg = cast<RegisterSDNode>(Value->getOperand(1))->getReg();
- const MachineRegisterInfo &MRI = MF.getRegInfo();
- if (MRI.getLiveInPhysReg(ArgReg) != Reg)
- return false;
- }
+ const MachineRegisterInfo &MRI = MF.getRegInfo();
+ if (!parametersInCSRMatch(MRI, CallerPreserved, ArgLocs, OutVals))
+ return false;
}
bool CalleeWillPop =