[PATCH] D108101: [M68k] Do not pass llvm::Function reference to M68kCCState

Min-Yih Hsu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 15 22:17:53 PDT 2021


myhsu created this revision.
myhsu added a reviewer: RKSimon.
Herald added a subscriber: hiraditya.
myhsu requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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 <https://bugs.llvm.org/show_bug.cgi?id=50752>.

The origin bug will only be triggered if we're using fastcc for a libcall. However, M68k is not using
fastcc for any of the libcall, so we never really trigger the bug. Therefore it makes little sense to create
a test that calls a library function using fastcc. And the existing tests already cover cases like normal fastcc
and normal libcall.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D108101

Files:
  llvm/lib/Target/M68k/M68kCallingConv.h
  llvm/lib/Target/M68k/M68kISelLowering.cpp


Index: llvm/lib/Target/M68k/M68kISelLowering.cpp
===================================================================
--- llvm/lib/Target/M68k/M68kISelLowering.cpp
+++ llvm/lib/Target/M68k/M68kISelLowering.cpp
@@ -519,9 +519,10 @@
 
   // 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 @@
 
   // 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);
 
Index: llvm/lib/Target/M68k/M68kCallingConv.h
===================================================================
--- llvm/lib/Target/M68k/M68kCallingConv.h
+++ 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;
-
-  M68kCCState(const llvm::Function &F, CallingConv::ID CC, bool IsVarArg,
-              MachineFunction &MF, SmallVectorImpl<CCValAssign> &Locs,
-              LLVMContext &C)
-      : CCState(CC, IsVarArg, MF, Locs, C), F(F) {}
+struct M68kCCState : public CCState {
+  ArrayRef<Type *> ArgTypeList;
+
+  M68kCCState(ArrayRef<Type *> ArgTypes, CallingConv::ID CC,
+              bool IsVarArg, MachineFunction &MF,
+              SmallVectorImpl<CCValAssign> &Locs, LLVMContext &C)
+      : CCState(CC, IsVarArg, MF, Locs, C), ArgTypeList(ArgTypes) {}
 };
 
 /// NOTE this function is used to select registers for formal arguments and call
@@ -52,14 +51,15 @@
       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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108101.366536.patch
Type: text/x-patch
Size: 2909 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210816/7ef8f3b0/attachment.bin>


More information about the llvm-commits mailing list