[llvm] [BPF] get external linkage for calling convetion functions (PR #75439)
Yingchi Long via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 13 23:38:19 PST 2023
https://github.com/inclyc created https://github.com/llvm/llvm-project/pull/75439
NFC.
For support calling conv in gisel, sharing code with BPFISelLowering.
>From be22a6090f699f0793d87abf3d288b5549922f03 Mon Sep 17 00:00:00 2001
From: Yingchi Long <i at lyc.dev>
Date: Thu, 14 Dec 2023 15:33:55 +0800
Subject: [PATCH] [BPF] get external linkage for calling convetion functions
NFC.
For support calling conv in gisel, sharing code with BPFISelLowering.
---
llvm/lib/Target/BPF/BPFCallingConv.cpp | 19 ++++++++++++
llvm/lib/Target/BPF/BPFCallingConv.h | 39 +++++++++++++++++++++++++
llvm/lib/Target/BPF/BPFCallingConv.td | 4 +++
llvm/lib/Target/BPF/BPFISelLowering.cpp | 4 +--
llvm/lib/Target/BPF/CMakeLists.txt | 3 +-
5 files changed, 65 insertions(+), 4 deletions(-)
create mode 100644 llvm/lib/Target/BPF/BPFCallingConv.cpp
create mode 100644 llvm/lib/Target/BPF/BPFCallingConv.h
diff --git a/llvm/lib/Target/BPF/BPFCallingConv.cpp b/llvm/lib/Target/BPF/BPFCallingConv.cpp
new file mode 100644
index 00000000000000..29793b36e28b79
--- /dev/null
+++ b/llvm/lib/Target/BPF/BPFCallingConv.cpp
@@ -0,0 +1,19 @@
+//=== BPFCallingConv.cpp ---- BPF Calling Convention Routines ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements BPF Calling Convention Routines
+//
+//===----------------------------------------------------------------------===//
+
+#include "BPFCallingConv.h"
+#include "BPFRegisterInfo.h"
+#include "BPFSubtarget.h"
+
+using namespace llvm;
+
+#include "BPFGenCallingConv.inc"
diff --git a/llvm/lib/Target/BPF/BPFCallingConv.h b/llvm/lib/Target/BPF/BPFCallingConv.h
new file mode 100644
index 00000000000000..1d2eded065f059
--- /dev/null
+++ b/llvm/lib/Target/BPF/BPFCallingConv.h
@@ -0,0 +1,39 @@
+//=== BPFCallingConv.h ----- BPF Calling Convention Routines ----*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file contains BPF Calling Convention Routines declaration
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIB_TARGET_BPF_BPFCALLINGCONV_H
+#define LLVM_LIB_TARGET_BPF_BPFCALLINGCONV_H
+
+#include "llvm/CodeGen/CallingConvLower.h"
+
+namespace llvm {
+
+bool CC_BPF32(unsigned ValNo, MVT ValVT, MVT LocVT,
+ CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags,
+ CCState &State);
+
+bool CC_BPF32(unsigned ValNo, MVT ValVT, MVT LocVT,
+ CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags,
+ CCState &State);
+bool CC_BPF64(unsigned ValNo, MVT ValVT, MVT LocVT,
+ CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags,
+ CCState &State);
+bool RetCC_BPF32(unsigned ValNo, MVT ValVT, MVT LocVT,
+ CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags,
+ CCState &State);
+bool RetCC_BPF64(unsigned ValNo, MVT ValVT, MVT LocVT,
+ CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags,
+ CCState &State);
+
+} // namespace llvm
+
+#endif
diff --git a/llvm/lib/Target/BPF/BPFCallingConv.td b/llvm/lib/Target/BPF/BPFCallingConv.td
index ef4ef1930aa8fb..9e30d03b5ebe85 100644
--- a/llvm/lib/Target/BPF/BPFCallingConv.td
+++ b/llvm/lib/Target/BPF/BPFCallingConv.td
@@ -11,9 +11,11 @@
//===----------------------------------------------------------------------===//
// BPF 64-bit C return-value convention.
+let Entry = 1 in
def RetCC_BPF64 : CallingConv<[CCIfType<[i64], CCAssignToReg<[R0]>>]>;
// BPF 64-bit C Calling convention.
+let Entry = 1 in
def CC_BPF64 : CallingConv<[
// Promote i8/i16/i32 args to i64
CCIfType<[ i8, i16, i32 ], CCPromoteToType<i64>>,
@@ -26,12 +28,14 @@ def CC_BPF64 : CallingConv<[
]>;
// Return-value convention when -mattr=+alu32 enabled
+let Entry = 1 in
def RetCC_BPF32 : CallingConv<[
CCIfType<[i32], CCAssignToRegWithShadow<[W0], [R0]>>,
CCIfType<[i64], CCAssignToRegWithShadow<[R0], [W0]>>
]>;
// Calling convention when -mattr=+alu32 enabled
+let Entry = 1 in
def CC_BPF32 : CallingConv<[
// Promote i8/i16/i32 args to i64
CCIfType<[i32], CCAssignToRegWithShadow<[W1, W2, W3, W4, W5],
diff --git a/llvm/lib/Target/BPF/BPFISelLowering.cpp b/llvm/lib/Target/BPF/BPFISelLowering.cpp
index 2fe86e75ddae8f..9c24db1df86304 100644
--- a/llvm/lib/Target/BPF/BPFISelLowering.cpp
+++ b/llvm/lib/Target/BPF/BPFISelLowering.cpp
@@ -13,6 +13,7 @@
#include "BPFISelLowering.h"
#include "BPF.h"
+#include "BPFCallingConv.h"
#include "BPFSubtarget.h"
#include "BPFTargetMachine.h"
#include "llvm/CodeGen/CallingConvLower.h"
@@ -317,9 +318,6 @@ SDValue BPFTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const {
}
}
-// Calling Convention Implementation
-#include "BPFGenCallingConv.inc"
-
SDValue BPFTargetLowering::LowerFormalArguments(
SDValue Chain, CallingConv::ID CallConv, bool IsVarArg,
const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &DL,
diff --git a/llvm/lib/Target/BPF/CMakeLists.txt b/llvm/lib/Target/BPF/CMakeLists.txt
index d88e7ade40b9a0..0b9d59ed811922 100644
--- a/llvm/lib/Target/BPF/CMakeLists.txt
+++ b/llvm/lib/Target/BPF/CMakeLists.txt
@@ -24,6 +24,7 @@ add_llvm_target(BPFCodeGen
BPFAbstractMemberAccess.cpp
BPFAdjustOpt.cpp
BPFAsmPrinter.cpp
+ BPFCallingConv.cpp
BPFCheckAndAdjustIR.cpp
BPFFrameLowering.cpp
BPFInstrInfo.cpp
@@ -62,7 +63,7 @@ add_llvm_target(BPFCodeGen
ADD_TO_COMPONENT
BPF
- )
+)
add_subdirectory(AsmParser)
add_subdirectory(Disassembler)
More information about the llvm-commits
mailing list