Skip to content

Commit eec3495

Browse files
committed
[M68k] Do not pass llvm::Function& to M68kCCState
Previously we're passing `llvm::Function&` into `M68kCCState` to lower arguments in fastcc. However, that reference might not be available if it's a library call and we only need its argument types. Therefore, now we're simply passing a list of argument llvm::Type-s. This fixes PR-50752. Differential Revision: https://reviews.llvm.org/D108101
1 parent 913b5d2 commit eec3495

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

llvm/lib/Target/M68k/M68kCallingConv.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,21 @@
2424
namespace llvm {
2525

2626
/// Custom state to propagate llvm type info to register CC assigner
27-
class M68kCCState : public CCState {
28-
public:
29-
const llvm::Function &F;
27+
struct M68kCCState : public CCState {
28+
ArrayRef<Type *> ArgTypeList;
3029

31-
M68kCCState(const llvm::Function &F, CallingConv::ID CC, bool IsVarArg,
30+
M68kCCState(ArrayRef<Type *> ArgTypes, CallingConv::ID CC, bool IsVarArg,
3231
MachineFunction &MF, SmallVectorImpl<CCValAssign> &Locs,
3332
LLVMContext &C)
34-
: CCState(CC, IsVarArg, MF, Locs, C), F(F) {}
33+
: CCState(CC, IsVarArg, MF, Locs, C), ArgTypeList(ArgTypes) {}
3534
};
3635

3736
/// NOTE this function is used to select registers for formal arguments and call
3837
/// FIXME: Handling on pointer arguments is not complete
3938
inline bool CC_M68k_Any_AssignToReg(unsigned &ValNo, MVT &ValVT, MVT &LocVT,
4039
CCValAssign::LocInfo &LocInfo,
4140
ISD::ArgFlagsTy &ArgFlags, CCState &State) {
42-
M68kCCState CCInfo = static_cast<M68kCCState &>(State);
41+
const M68kCCState &CCInfo = static_cast<M68kCCState &>(State);
4342

4443
static const MCPhysReg DataRegList[] = {M68k::D0, M68k::D1, M68k::A0,
4544
M68k::A1};
@@ -52,14 +51,15 @@ inline bool CC_M68k_Any_AssignToReg(unsigned &ValNo, MVT &ValVT, MVT &LocVT,
5251
M68k::D1,
5352
};
5453

55-
auto I = CCInfo.F.arg_begin();
54+
const auto &ArgTypes = CCInfo.ArgTypeList;
55+
auto I = ArgTypes.begin(), End = ArgTypes.end();
5656
int No = ValNo;
57-
while (No > 0) {
58-
No -= I->getType()->isIntegerTy(64) ? 2 : 1;
59-
I++;
57+
while (No > 0 && I != End) {
58+
No -= (*I)->isIntegerTy(64) ? 2 : 1;
59+
++I;
6060
}
6161

62-
bool IsPtr = I != CCInfo.F.arg_end() && I->getType()->isPointerTy();
62+
bool IsPtr = I != End && (*I)->isPointerTy();
6363

6464
unsigned Reg =
6565
IsPtr ? State.AllocateReg(AddrRegList) : State.AllocateReg(DataRegList);

llvm/lib/Target/M68k/M68kISelLowering.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -519,9 +519,10 @@ SDValue M68kTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
519519

520520
// Analyze operands of the call, assigning locations to each operand.
521521
SmallVector<CCValAssign, 16> ArgLocs;
522-
// It is empty for LibCall
523-
const Function *CalleeFunc = CLI.CB ? CLI.CB->getCalledFunction() : nullptr;
524-
M68kCCState CCInfo(*CalleeFunc, CallConv, IsVarArg, MF, ArgLocs,
522+
SmallVector<Type *, 4> ArgTypes;
523+
for (const auto &Arg : CLI.getArgs())
524+
ArgTypes.emplace_back(Arg.Ty);
525+
M68kCCState CCInfo(ArgTypes, CallConv, IsVarArg, MF, ArgLocs,
525526
*DAG.getContext());
526527
CCInfo.AnalyzeCallOperands(Outs, CC_M68k);
527528

@@ -876,8 +877,10 @@ SDValue M68kTargetLowering::LowerFormalArguments(
876877

877878
// Assign locations to all of the incoming arguments.
878879
SmallVector<CCValAssign, 16> ArgLocs;
879-
M68kCCState CCInfo(MF.getFunction(), CCID, IsVarArg, MF, ArgLocs,
880-
*DAG.getContext());
880+
SmallVector<Type *, 4> ArgTypes;
881+
for (const Argument &Arg : MF.getFunction().args())
882+
ArgTypes.emplace_back(Arg.getType());
883+
M68kCCState CCInfo(ArgTypes, CCID, IsVarArg, MF, ArgLocs, *DAG.getContext());
881884

882885
CCInfo.AnalyzeFormalArguments(Ins, CC_M68k);
883886

0 commit comments

Comments
 (0)