Skip to content

Commit 4ff8165

Browse files
Yeting Kuoveselypeta
Yeting Kuo
authored andcommitted
[RISCV] Emit .variant_cc directives for vector function calls.
The patch is splitted from D103435. The patch emits .variant_cc [0] for those function calls that have vector arguments or vector return values. [0]: riscv-non-isa/riscv-elf-psabi-doc#190 Initial authored by: HsiangKai Reviewed By: reames Differential Revision: https://reviews.llvm.org/D139414
2 parents f83776d + 982a586 commit 4ff8165

File tree

6 files changed

+77
-1
lines changed

6 files changed

+77
-1
lines changed

llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "RISCVTargetStreamer.h"
1414
#include "RISCVBaseInfo.h"
1515
#include "RISCVMCTargetDesc.h"
16+
#include "llvm/MC/MCSymbol.h"
1617
#include "llvm/Support/FormattedStream.h"
1718
#include "llvm/Support/RISCVAttributes.h"
1819
#include "llvm/Support/RISCVISAInfo.h"
@@ -108,6 +109,10 @@ void RISCVTargetAsmStreamer::emitDirectiveOptionNoCapMode() {
108109
OS << "\t.option\tnocapmode\n";
109110
}
110111

112+
void RISCVTargetAsmStreamer::emitDirectiveVariantCC(MCSymbol &Symbol) {
113+
OS << "\t.variant_cc\t" << Symbol.getName() << "\n";
114+
}
115+
111116
void RISCVTargetAsmStreamer::emitAttribute(unsigned Attribute, unsigned Value) {
112117
OS << "\t.attribute\t" << Attribute << ", " << Twine(Value) << "\n";
113118
}

llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.h

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class RISCVTargetAsmStreamer : public RISCVTargetStreamer {
7070
void emitDirectiveOptionNoRelax() override;
7171
void emitDirectiveOptionCapMode() override;
7272
void emitDirectiveOptionNoCapMode() override;
73+
void emitDirectiveVariantCC(MCSymbol &Symbol) override;
7374
};
7475

7576
}

llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "MCTargetDesc/RISCVMCExpr.h"
1616
#include "MCTargetDesc/RISCVTargetStreamer.h"
1717
#include "RISCV.h"
18+
#include "RISCVMachineFunctionInfo.h"
1819
#include "RISCVTargetMachine.h"
1920
#include "TargetInfo/RISCVTargetInfo.h"
2021
#include "llvm/ADT/Statistic.h"
@@ -229,6 +230,12 @@ void RISCVAsmPrinter::emitAttributes() {
229230
}
230231

231232
void RISCVAsmPrinter::emitFunctionEntryLabel() {
233+
const auto *RMFI = MF->getInfo<RISCVMachineFunctionInfo>();
234+
if (RMFI->isVectorCall()) {
235+
auto &RTS =
236+
static_cast<RISCVTargetStreamer &>(*OutStreamer->getTargetStreamer());
237+
RTS.emitDirectiveVariantCC(*CurrentFnSym);
238+
}
232239
AsmPrinter::emitFunctionEntryLabel();
233240
auto &Subtarget = MF->getSubtarget<RISCVSubtarget>();
234241
const MachineJumpTableInfo *MJTI = MF->getJumpTableInfo();

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -12595,6 +12595,9 @@ SDValue RISCVTargetLowering::LowerFormalArguments(
1259512595
MachineFrameInfo &MFI = MF.getFrameInfo();
1259612596
RISCVMachineFunctionInfo *RVFI = MF.getInfo<RISCVMachineFunctionInfo>();
1259712597
unsigned XLenInBytes = Subtarget.getXLen() / 8;
12598+
if (any_of(ArgLocs,
12599+
[](CCValAssign &VA) { return VA.getLocVT().isScalableVector(); }))
12600+
MF.getInfo<RISCVMachineFunctionInfo>()->setIsVectorCall();
1259812601
if (IsVarArg && RISCVABI::isCheriPureCapABI(Subtarget.getTargetABI())) {
1259912602
// Record the frame index of the first variable argument
1260012603
// which is a value necessary to VASTART.
@@ -13106,7 +13109,7 @@ RISCVTargetLowering::LowerReturn(SDValue Chain, CallingConv::ID CallConv,
1310613109
const SmallVectorImpl<ISD::OutputArg> &Outs,
1310713110
const SmallVectorImpl<SDValue> &OutVals,
1310813111
const SDLoc &DL, SelectionDAG &DAG) const {
13109-
const MachineFunction &MF = DAG.getMachineFunction();
13112+
MachineFunction &MF = DAG.getMachineFunction();
1311013113
const RISCVSubtarget &STI = MF.getSubtarget<RISCVSubtarget>();
1311113114

1311213115
// Stores the assignment of the return value to a location.
@@ -13177,6 +13180,10 @@ RISCVTargetLowering::LowerReturn(SDValue Chain, CallingConv::ID CallConv,
1317713180
RetOps.push_back(Glue);
1317813181
}
1317913182

13183+
if (any_of(RVLocs,
13184+
[](CCValAssign &VA) { return VA.getLocVT().isScalableVector(); }))
13185+
MF.getInfo<RISCVMachineFunctionInfo>()->setIsVectorCall();
13186+
1318013187
unsigned RetOpc = RISCVISD::RET_FLAG;
1318113188
// Interrupt service routines use different return instructions.
1318213189
const Function &Func = DAG.getMachineFunction().getFunction();

llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.h

+5
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ class RISCVMachineFunctionInfo : public MachineFunctionInfo {
6565
uint64_t RVVPadding = 0;
6666
/// Size of stack frame to save callee saved registers
6767
unsigned CalleeSavedStackSize = 0;
68+
/// Is there any vector argument or return?
69+
bool IsVectorCall = false;
6870

6971
/// Registers that have been sign extended from i32.
7072
SmallVector<Register, 8> SExt32Registers;
@@ -124,6 +126,9 @@ class RISCVMachineFunctionInfo : public MachineFunctionInfo {
124126

125127
void addSExt32Register(Register Reg);
126128
bool isSExt32Register(Register Reg) const;
129+
130+
bool isVectorCall() const { return IsVectorCall; }
131+
void setIsVectorCall() { IsVectorCall = true; }
127132
};
128133

129134
} // end namespace llvm
+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
; RUN: llc -mtriple=riscv64 -mattr=+v -o - %s | FileCheck %s --check-prefix=CHECK-ASM
2+
; RUN: llc -mtriple=riscv64 -mattr=+v -filetype=obj -o - %s \
3+
; RUN: | llvm-readobj --symbols - | FileCheck %s --check-prefix=CHECK-OBJ
4+
5+
define i32 @base_cc() {
6+
; CHECK-ASM-LABEL: base_cc:
7+
; CHECK-ASM-NOT: .variant_cc
8+
; CHECK-OBJ-LABEL: Name: base_cc
9+
; CHECK-OBJ: Other: 0
10+
ret i32 42
11+
}
12+
13+
define <4 x i32> @fixed_vector_cc_1(<4 x i32> %arg) {
14+
; CHECK-ASM: .variant_cc fixed_vector_cc_1
15+
; CHECK-ASM-NEXT: fixed_vector_cc_1:
16+
; CHECK-OBJ-LABEL: Name: fixed_vector_cc_1
17+
; CHECK-OBJ: Other [ (0x80)
18+
ret <4 x i32> %arg
19+
}
20+
21+
define <vscale x 4 x i32> @rvv_vector_cc_1() {
22+
; CHECK-ASM: .variant_cc rvv_vector_cc_1
23+
; CHECK-ASM-NEXT: rvv_vector_cc_1:
24+
; CHECK-OBJ-LABEL: Name: rvv_vector_cc_1
25+
; CHECK-OBJ: Other [ (0x80)
26+
ret <vscale x 4 x i32> undef
27+
}
28+
29+
define <vscale x 4 x i1> @rvv_vector_cc_2() {
30+
; CHECK-ASM: .variant_cc rvv_vector_cc_2
31+
; CHECK-ASM-NEXT: rvv_vector_cc_2:
32+
; CHECK-OBJ-LABEL: Name: rvv_vector_cc_2
33+
; CHECK-OBJ: Other [ (0x80)
34+
ret <vscale x 4 x i1> undef
35+
}
36+
37+
define void @rvv_vector_cc_3(<vscale x 4 x i32> %arg) {
38+
; CHECK-ASM: .variant_cc rvv_vector_cc_3
39+
; CHECK-ASM-NEXT: rvv_vector_cc_3:
40+
; CHECK-OBJ-LABEL: Name: rvv_vector_cc_3
41+
; CHECK-OBJ: Other [ (0x80)
42+
ret void
43+
}
44+
45+
define void @rvv_vector_cc_4(<vscale x 4 x i1> %arg) {
46+
; CHECK-ASM: .variant_cc rvv_vector_cc_4
47+
; CHECK-ASM-NEXT: rvv_vector_cc_4:
48+
; CHECK-OBJ-LABEL: Name: rvv_vector_cc_4
49+
; CHECK-OBJ: Other [ (0x80)
50+
ret void
51+
}

0 commit comments

Comments
 (0)