Skip to content

Commit 3a88121

Browse files
author
Yeting Kuo
committed
[RISCV] Support .variant_cc directive for the assembler.
The patch is split from D103435. The patch supported a new directive .variant_cc that annotates function with STO_RISCV_VARIANT_CC. Symbols marked with STO_RISCV_VARIANT_CC do not use standard calling conversion or use parameter not passed in GPR/FPR. Related: riscv-non-isa/riscv-elf-psabi-doc#190 Initial authored by: HsiangKai Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D138352
1 parent 89fae41 commit 3a88121

File tree

6 files changed

+66
-0
lines changed

6 files changed

+66
-0
lines changed

llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ class RISCVAsmParser : public MCTargetAsmParser {
180180
bool parseDirectiveOption();
181181
bool parseDirectiveAttribute();
182182
bool parseDirectiveInsn(SMLoc L);
183+
bool parseDirectiveVariantCC();
183184

184185
void setFeatureBits(uint64_t Feature, StringRef FeatureString) {
185186
if (!(getSTI().getFeatureBits()[Feature])) {
@@ -2035,6 +2036,8 @@ bool RISCVAsmParser::ParseDirective(AsmToken DirectiveID) {
20352036
return parseDirectiveAttribute();
20362037
if (IDVal == ".insn")
20372038
return parseDirectiveInsn(DirectiveID.getLoc());
2039+
if (IDVal == ".variant_cc")
2040+
return parseDirectiveVariantCC();
20382041

20392042
return true;
20402043
}
@@ -2297,6 +2300,19 @@ bool RISCVAsmParser::parseDirectiveInsn(SMLoc L) {
22972300
/*MatchingInlineAsm=*/false);
22982301
}
22992302

2303+
/// parseDirectiveVariantCC
2304+
/// ::= .variant_cc symbol
2305+
bool RISCVAsmParser::parseDirectiveVariantCC() {
2306+
StringRef Name;
2307+
if (getParser().parseIdentifier(Name))
2308+
return TokError("expected symbol name");
2309+
if (parseEOL())
2310+
return false;
2311+
getTargetStreamer().emitDirectiveVariantCC(
2312+
*getContext().getOrCreateSymbol(Name));
2313+
return false;
2314+
}
2315+
23002316
void RISCVAsmParser::emitToStreamer(MCStreamer &S, const MCInst &Inst) {
23012317
MCInst CInst;
23022318
bool Res = compressInst(CInst, Inst, getSTI(), S.getContext());

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

+5
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,11 @@ void RISCVTargetELFStreamer::reset() {
187187
Contents.clear();
188188
}
189189

190+
void RISCVTargetELFStreamer::emitDirectiveVariantCC(MCSymbol &Symbol) {
191+
getStreamer().getAssembler().registerSymbol(Symbol);
192+
cast<MCSymbolELF>(Symbol).setOther(ELF::STO_RISCV_VARIANT_CC);
193+
}
194+
190195
namespace {
191196
class RISCVELFStreamer : public MCELFStreamer {
192197
static std::pair<unsigned, unsigned> getRelocPairForSize(unsigned Size) {

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

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ class RISCVTargetELFStreamer : public RISCVTargetStreamer {
106106
void emitDirectiveOptionNoRVC() override;
107107
void emitDirectiveOptionRelax() override;
108108
void emitDirectiveOptionNoRelax() override;
109+
void emitDirectiveVariantCC(MCSymbol &Symbol) override;
109110

110111
void finish() override;
111112
};

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

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ void RISCVTargetStreamer::emitDirectiveOptionRVC() {}
3232
void RISCVTargetStreamer::emitDirectiveOptionNoRVC() {}
3333
void RISCVTargetStreamer::emitDirectiveOptionRelax() {}
3434
void RISCVTargetStreamer::emitDirectiveOptionNoRelax() {}
35+
void RISCVTargetStreamer::emitDirectiveVariantCC(MCSymbol &Symbol) {}
3536
void RISCVTargetStreamer::emitAttribute(unsigned Attribute, unsigned Value) {}
3637
void RISCVTargetStreamer::finishAttributeSection() {}
3738
void RISCVTargetStreamer::emitTextAttribute(unsigned Attribute,

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

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class RISCVTargetStreamer : public MCTargetStreamer {
3333
virtual void emitDirectiveOptionNoRVC();
3434
virtual void emitDirectiveOptionRelax();
3535
virtual void emitDirectiveOptionNoRelax();
36+
virtual void emitDirectiveVariantCC(MCSymbol &Symbol);
3637
virtual void emitAttribute(unsigned Attribute, unsigned Value);
3738
virtual void finishAttributeSection();
3839
virtual void emitTextAttribute(unsigned Attribute, StringRef String);
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// RUN: llvm-mc -triple riscv64 -filetype obj -o - %s | llvm-readobj --symbols - | FileCheck %s
2+
// RUN: llvm-mc -triple riscv64 -filetype obj -defsym=OBJ=1 -o - %s | llvm-readelf -s - | FileCheck %s --check-prefix=OBJ
3+
// RUN: not llvm-mc -triple riscv64 -filetype asm -defsym=ERR=1 -o - %s 2>&1 | FileCheck %s --check-prefix=ERR
4+
5+
.text
6+
.variant_cc local
7+
local:
8+
9+
// CHECK: Name: local
10+
// CHECK: Other [ (0x80)
11+
12+
.ifdef OBJ
13+
/// Binding directive before .variant_cc.
14+
.global def1
15+
.variant_cc def1
16+
def1:
17+
18+
/// Binding directive after .variant_cc.
19+
.variant_cc def2
20+
.weak def2
21+
def2:
22+
23+
.globl alias_def1
24+
.set alias_def1, def1
25+
26+
.variant_cc undef
27+
28+
// OBJ: NOTYPE LOCAL DEFAULT [VARIANT_CC] [[#]] local
29+
// OBJ-NEXT: NOTYPE GLOBAL DEFAULT [VARIANT_CC] [[#]] def1
30+
// OBJ-NEXT: NOTYPE WEAK DEFAULT [VARIANT_CC] [[#]] def2
31+
// OBJ-NEXT: NOTYPE GLOBAL DEFAULT [[#]] alias_def1
32+
// OBJ-NEXT: NOTYPE GLOBAL DEFAULT [VARIANT_CC] UND undef
33+
.endif
34+
35+
.ifdef ERR
36+
.variant_cc
37+
// ERR: [[#@LINE-1]]:12: error: expected symbol name
38+
39+
.global fox
40+
.variant_cc fox bar
41+
// ERR: [[#@LINE-1]]:17: error: expected newline
42+
.endif

0 commit comments

Comments
 (0)