[llvm] eec3495 - [M68k] Do not pass llvm::Function& to M68kCCState
Min-Yih Hsu via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 16 15:41:30 PDT 2021
Author: Min-Yih Hsu
Date: 2021-08-16T15:33:08-07:00
New Revision: eec3495a9d8060ebd0a90fb8b84f51ed24cf8c9d
URL: https://github.com/llvm/llvm-project/commit/eec3495a9d8060ebd0a90fb8b84f51ed24cf8c9d
DIFF: https://github.com/llvm/llvm-project/commit/eec3495a9d8060ebd0a90fb8b84f51ed24cf8c9d.diff
LOG: [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
Added:
Modified:
llvm/lib/Target/M68k/M68kCallingConv.h
llvm/lib/Target/M68k/M68kISelLowering.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/M68k/M68kCallingConv.h b/llvm/lib/Target/M68k/M68kCallingConv.h
index 18f72c95cedb2..20ffa993897f0 100644
--- a/llvm/lib/Target/M68k/M68kCallingConv.h
+++ b/llvm/lib/Target/M68k/M68kCallingConv.h
@@ -24,14 +24,13 @@
namespace llvm {
/// Custom state to propagate llvm type info to register CC assigner
-class M68kCCState : public CCState {
-public:
- const llvm::Function &F;
+struct M68kCCState : public CCState {
+ ArrayRef<Type *> ArgTypeList;
- M68kCCState(const llvm::Function &F, CallingConv::ID CC, bool IsVarArg,
+ M68kCCState(ArrayRef<Type *> ArgTypes, CallingConv::ID CC, bool IsVarArg,
MachineFunction &MF, SmallVectorImpl<CCValAssign> &Locs,
LLVMContext &C)
- : CCState(CC, IsVarArg, MF, Locs, C), F(F) {}
+ : CCState(CC, IsVarArg, MF, Locs, C), ArgTypeList(ArgTypes) {}
};
/// NOTE this function is used to select registers for formal arguments and call
@@ -39,7 +38,7 @@ class M68kCCState : public CCState {
inline bool CC_M68k_Any_AssignToReg(unsigned &ValNo, MVT &ValVT, MVT &LocVT,
CCValAssign::LocInfo &LocInfo,
ISD::ArgFlagsTy &ArgFlags, CCState &State) {
- M68kCCState CCInfo = static_cast<M68kCCState &>(State);
+ const M68kCCState &CCInfo = static_cast<M68kCCState &>(State);
static const MCPhysReg DataRegList[] = {M68k::D0, M68k::D1, M68k::A0,
M68k::A1};
@@ -52,14 +51,15 @@ inline bool CC_M68k_Any_AssignToReg(unsigned &ValNo, MVT &ValVT, MVT &LocVT,
M68k::D1,
};
- auto I = CCInfo.F.arg_begin();
+ const auto &ArgTypes = CCInfo.ArgTypeList;
+ auto I = ArgTypes.begin(), End = ArgTypes.end();
int No = ValNo;
- while (No > 0) {
- No -= I->getType()->isIntegerTy(64) ? 2 : 1;
- I++;
+ while (No > 0 && I != End) {
+ No -= (*I)->isIntegerTy(64) ? 2 : 1;
+ ++I;
}
- bool IsPtr = I != CCInfo.F.arg_end() && I->getType()->isPointerTy();
+ bool IsPtr = I != End && (*I)->isPointerTy();
unsigned Reg =
IsPtr ? State.AllocateReg(AddrRegList) : State.AllocateReg(DataRegList);
diff --git a/llvm/lib/Target/M68k/M68kISelLowering.cpp b/llvm/lib/Target/M68k/M68kISelLowering.cpp
index 3e7cee9889d7c..f00083aaa1d89 100644
--- a/llvm/lib/Target/M68k/M68kISelLowering.cpp
+++ b/llvm/lib/Target/M68k/M68kISelLowering.cpp
@@ -519,9 +519,10 @@ SDValue M68kTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
// Analyze operands of the call, assigning locations to each operand.
SmallVector<CCValAssign, 16> ArgLocs;
- // It is empty for LibCall
- const Function *CalleeFunc = CLI.CB ? CLI.CB->getCalledFunction() : nullptr;
- M68kCCState CCInfo(*CalleeFunc, CallConv, IsVarArg, MF, ArgLocs,
+ SmallVector<Type *, 4> ArgTypes;
+ for (const auto &Arg : CLI.getArgs())
+ ArgTypes.emplace_back(Arg.Ty);
+ M68kCCState CCInfo(ArgTypes, CallConv, IsVarArg, MF, ArgLocs,
*DAG.getContext());
CCInfo.AnalyzeCallOperands(Outs, CC_M68k);
@@ -876,8 +877,10 @@ SDValue M68kTargetLowering::LowerFormalArguments(
// Assign locations to all of the incoming arguments.
SmallVector<CCValAssign, 16> ArgLocs;
- M68kCCState CCInfo(MF.getFunction(), CCID, IsVarArg, MF, ArgLocs,
- *DAG.getContext());
+ SmallVector<Type *, 4> ArgTypes;
+ for (const Argument &Arg : MF.getFunction().args())
+ ArgTypes.emplace_back(Arg.getType());
+ M68kCCState CCInfo(ArgTypes, CCID, IsVarArg, MF, ArgLocs, *DAG.getContext());
CCInfo.AnalyzeFormalArguments(Ins, CC_M68k);
More information about the llvm-commits
mailing list