@@ -3047,8 +3047,10 @@ bool ARMTargetLowering::IsEligibleForTailCallOptimization(
3047
3047
for (const CCValAssign &AL : ArgLocs)
3048
3048
if (AL.isRegLoc())
3049
3049
AddressRegisters.erase(AL.getLocReg());
3050
- if (AddressRegisters.empty())
3050
+ if (AddressRegisters.empty()) {
3051
+ LLVM_DEBUG(dbgs() << "false (no reg to hold function pointer)\n");
3051
3052
return false;
3053
+ }
3052
3054
}
3053
3055
3054
3056
// Look for obvious safe cases to perform tail call optimization that do not
@@ -3057,18 +3059,26 @@ bool ARMTargetLowering::IsEligibleForTailCallOptimization(
3057
3059
// Exception-handling functions need a special set of instructions to indicate
3058
3060
// a return to the hardware. Tail-calling another function would probably
3059
3061
// break this.
3060
- if (CallerF.hasFnAttribute("interrupt"))
3062
+ if (CallerF.hasFnAttribute("interrupt")) {
3063
+ LLVM_DEBUG(dbgs() << "false (interrupt attribute)\n");
3061
3064
return false;
3065
+ }
3062
3066
3063
- if (canGuaranteeTCO(CalleeCC, getTargetMachine().Options.GuaranteedTailCallOpt))
3067
+ if (canGuaranteeTCO(CalleeCC,
3068
+ getTargetMachine().Options.GuaranteedTailCallOpt)) {
3069
+ LLVM_DEBUG(dbgs() << (CalleeCC == CallerCC ? "true" : "false")
3070
+ << " (guaranteed tail-call CC)\n");
3064
3071
return CalleeCC == CallerCC;
3072
+ }
3065
3073
3066
3074
// Also avoid sibcall optimization if either caller or callee uses struct
3067
3075
// return semantics.
3068
3076
bool isCalleeStructRet = Outs.empty() ? false : Outs[0].Flags.isSRet();
3069
3077
bool isCallerStructRet = MF.getFunction().hasStructRetAttr();
3070
- if (isCalleeStructRet || isCallerStructRet)
3078
+ if (isCalleeStructRet || isCallerStructRet) {
3079
+ LLVM_DEBUG(dbgs() << "false (struct-ret)\n");
3071
3080
return false;
3081
+ }
3072
3082
3073
3083
// Externally-defined functions with weak linkage should not be
3074
3084
// tail-called on ARM when the OS does not support dynamic
@@ -3081,8 +3091,11 @@ bool ARMTargetLowering::IsEligibleForTailCallOptimization(
3081
3091
const GlobalValue *GV = G->getGlobal();
3082
3092
const Triple &TT = getTargetMachine().getTargetTriple();
3083
3093
if (GV->hasExternalWeakLinkage() &&
3084
- (!TT.isOSWindows() || TT.isOSBinFormatELF() || TT.isOSBinFormatMachO()))
3094
+ (!TT.isOSWindows() || TT.isOSBinFormatELF() ||
3095
+ TT.isOSBinFormatMachO())) {
3096
+ LLVM_DEBUG(dbgs() << "false (external weak linkage)\n");
3085
3097
return false;
3098
+ }
3086
3099
}
3087
3100
3088
3101
// Check that the call results are passed in the same way.
@@ -3091,23 +3104,29 @@ bool ARMTargetLowering::IsEligibleForTailCallOptimization(
3091
3104
getEffectiveCallingConv(CalleeCC, isVarArg),
3092
3105
getEffectiveCallingConv(CallerCC, CallerF.isVarArg()), MF, C, Ins,
3093
3106
CCAssignFnForReturn(CalleeCC, isVarArg),
3094
- CCAssignFnForReturn(CallerCC, CallerF.isVarArg())))
3107
+ CCAssignFnForReturn(CallerCC, CallerF.isVarArg()))) {
3108
+ LLVM_DEBUG(dbgs() << "false (incompatible results)\n");
3095
3109
return false;
3110
+ }
3096
3111
// The callee has to preserve all registers the caller needs to preserve.
3097
3112
const ARMBaseRegisterInfo *TRI = Subtarget->getRegisterInfo();
3098
3113
const uint32_t *CallerPreserved = TRI->getCallPreservedMask(MF, CallerCC);
3099
3114
if (CalleeCC != CallerCC) {
3100
3115
const uint32_t *CalleePreserved = TRI->getCallPreservedMask(MF, CalleeCC);
3101
- if (!TRI->regmaskSubsetEqual(CallerPreserved, CalleePreserved))
3116
+ if (!TRI->regmaskSubsetEqual(CallerPreserved, CalleePreserved)) {
3117
+ LLVM_DEBUG(dbgs() << "false (not all registers preserved)\n");
3102
3118
return false;
3119
+ }
3103
3120
}
3104
3121
3105
3122
// If Caller's vararg or byval argument has been split between registers and
3106
3123
// stack, do not perform tail call, since part of the argument is in caller's
3107
3124
// local frame.
3108
3125
const ARMFunctionInfo *AFI_Caller = MF.getInfo<ARMFunctionInfo>();
3109
- if (AFI_Caller->getArgRegsSaveSize())
3126
+ if (AFI_Caller->getArgRegsSaveSize()) {
3127
+ LLVM_DEBUG(dbgs() << "false (arg reg save area)\n");
3110
3128
return false;
3129
+ }
3111
3130
3112
3131
// If the callee takes no arguments then go on to check the results of the
3113
3132
// call.
@@ -3125,36 +3144,51 @@ bool ARMTargetLowering::IsEligibleForTailCallOptimization(
3125
3144
EVT RegVT = VA.getLocVT();
3126
3145
SDValue Arg = OutVals[realArgIdx];
3127
3146
ISD::ArgFlagsTy Flags = Outs[realArgIdx].Flags;
3128
- if (VA.getLocInfo() == CCValAssign::Indirect)
3147
+ if (VA.getLocInfo() == CCValAssign::Indirect) {
3148
+ LLVM_DEBUG(dbgs() << "false (indirect arg)\n");
3129
3149
return false;
3150
+ }
3130
3151
if (VA.needsCustom() && (RegVT == MVT::f64 || RegVT == MVT::v2f64)) {
3131
3152
// f64 and vector types are split into multiple registers or
3132
3153
// register/stack-slot combinations. The types will not match
3133
3154
// the registers; give up on memory f64 refs until we figure
3134
3155
// out what to do about this.
3135
- if (!VA.isRegLoc())
3156
+ if (!VA.isRegLoc()) {
3157
+ LLVM_DEBUG(dbgs() << "false (f64 not in register)\n");
3136
3158
return false;
3137
- if (!ArgLocs[++i].isRegLoc())
3159
+ }
3160
+ if (!ArgLocs[++i].isRegLoc()) {
3161
+ LLVM_DEBUG(dbgs() << "false (f64 not in register, second half)\n");
3138
3162
return false;
3163
+ }
3139
3164
if (RegVT == MVT::v2f64) {
3140
- if (!ArgLocs[++i].isRegLoc())
3165
+ if (!ArgLocs[++i].isRegLoc()) {
3166
+ LLVM_DEBUG(dbgs() << "false (v2f64 not in register)\n");
3141
3167
return false;
3142
- if (!ArgLocs[++i].isRegLoc())
3168
+ }
3169
+ if (!ArgLocs[++i].isRegLoc()) {
3170
+ LLVM_DEBUG(dbgs() << "false (v2f64 not in register, second half)\n");
3143
3171
return false;
3172
+ }
3144
3173
}
3145
3174
} else if (!VA.isRegLoc()) {
3146
3175
if (!MatchingStackOffset(Arg, VA.getLocMemOffset(), Flags,
3147
- MFI, MRI, TII))
3176
+ MFI, MRI, TII)) {
3177
+ LLVM_DEBUG(dbgs() << "false (non-matching stack offset)\n");
3148
3178
return false;
3179
+ }
3149
3180
}
3150
3181
}
3151
3182
}
3152
3183
3153
3184
const MachineRegisterInfo &MRI = MF.getRegInfo();
3154
- if (!parametersInCSRMatch(MRI, CallerPreserved, ArgLocs, OutVals))
3185
+ if (!parametersInCSRMatch(MRI, CallerPreserved, ArgLocs, OutVals)) {
3186
+ LLVM_DEBUG(dbgs() << "false (parameters in CSRs do not match)\n");
3155
3187
return false;
3188
+ }
3156
3189
}
3157
3190
3191
+ LLVM_DEBUG(dbgs() << "true\n");
3158
3192
return true;
3159
3193
}
3160
3194
0 commit comments