Skip to content

Commit 8286378

Browse files
authored
LoongArch: Remove VK_CALL/VK_CALL_PLT and don't print %plt
`%plt` is a redundant relocation specifier: `bl %plt(foo)` is identical to `bl foo`. Let's replace VK_CALL/VK_CALL_PLT with R_LARCH_B26 and remove the only specifier constants. Pull Request: #138632
1 parent 0505e37 commit 8286378

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+303
-318
lines changed

llvm/lib/Target/LoongArch/AsmParser/LoongArchAsmParser.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -517,9 +517,7 @@ class LoongArchOperand : public MCParsedAsmOperand {
517517
int64_t Imm;
518518
LoongArchMCExpr::Specifier VK = LoongArchMCExpr::VK_None;
519519
bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK);
520-
bool IsValidKind =
521-
VK == LoongArchMCExpr::VK_None || VK == LoongArchMCExpr::VK_CALL ||
522-
VK == LoongArchMCExpr::VK_CALL_PLT || VK == ELF::R_LARCH_B26;
520+
bool IsValidKind = VK == LoongArchMCExpr::VK_None || VK == ELF::R_LARCH_B26;
523521
return IsConstantImm
524522
? isShiftedInt<26, 2>(Imm) && IsValidKind
525523
: LoongArchAsmParser::classifySymbolRef(getImm(), VK) &&
@@ -793,7 +791,6 @@ ParseStatus LoongArchAsmParser::parseSImm26Operand(OperandVector &Operands) {
793791

794792
MCSymbol *Sym = getContext().getOrCreateSymbol(Identifier);
795793
Res = MCSymbolRefExpr::create(Sym, getContext());
796-
Res = LoongArchMCExpr::create(Res, LoongArchMCExpr::VK_CALL, getContext());
797794
Operands.push_back(LoongArchOperand::createImm(Res, S, E));
798795
return ParseStatus::Success;
799796
}

llvm/lib/Target/LoongArch/LoongArchMCInstLower.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,8 @@ static MCOperand lowerSymbolOperand(const MachineOperand &MO, MCSymbol *Sym,
3535
Kind = LoongArchMCExpr::VK_None;
3636
break;
3737
case LoongArchII::MO_CALL:
38-
Kind = LoongArchMCExpr::VK_CALL;
39-
break;
4038
case LoongArchII::MO_CALL_PLT:
41-
Kind = LoongArchMCExpr::VK_CALL_PLT;
39+
Kind = ELF::R_LARCH_B26;
4240
break;
4341
case LoongArchII::MO_PCREL_HI:
4442
Kind = ELF::R_LARCH_PCALA_HI20;

llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCCodeEmitter.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,6 @@ LoongArchMCCodeEmitter::getExprOpValue(const MCInst &MI, const MCOperand &MO,
147147
FixupKind = LoongArch::fixup_loongarch_b21;
148148
break;
149149
case ELF::R_LARCH_B26:
150-
case LoongArchMCExpr::VK_CALL:
151-
case LoongArchMCExpr::VK_CALL_PLT:
152150
FixupKind = LoongArch::fixup_loongarch_b26;
153151
break;
154152
case ELF::R_LARCH_ABS_HI20:

llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCExpr.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const LoongArchMCExpr *LoongArchMCExpr::create(const MCExpr *Expr, uint16_t S,
3232

3333
void LoongArchMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
3434
Specifier S = getSpecifier();
35-
bool HasVariant = S != VK_None && S != VK_CALL;
35+
bool HasVariant = S != VK_None && S != ELF::R_LARCH_B26;
3636

3737
if (HasVariant)
3838
OS << '%' << getSpecifierName(specifier) << '(';
@@ -63,14 +63,10 @@ StringRef LoongArchMCExpr::getSpecifierName(uint16_t S) {
6363
switch (S) {
6464
default:
6565
llvm_unreachable("Invalid ELF symbol kind");
66-
case VK_CALL_PLT:
67-
return "plt";
6866
case ELF::R_LARCH_B16:
6967
return "b16";
7068
case ELF::R_LARCH_B21:
7169
return "b21";
72-
case ELF::R_LARCH_B26:
73-
return "b26";
7470
case ELF::R_LARCH_ABS_HI20:
7571
return "abs_hi20";
7672
case ELF::R_LARCH_ABS_LO12:
@@ -176,7 +172,7 @@ StringRef LoongArchMCExpr::getSpecifierName(uint16_t S) {
176172

177173
LoongArchMCExpr::Specifier LoongArchMCExpr::parseSpecifier(StringRef name) {
178174
return StringSwitch<LoongArchMCExpr::Specifier>(name)
179-
.Case("plt", VK_CALL_PLT)
175+
.Case("plt", ELF::R_LARCH_B26)
180176
.Case("b16", ELF::R_LARCH_B16)
181177
.Case("b21", ELF::R_LARCH_B21)
182178
.Case("b26", ELF::R_LARCH_B26)

llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCExpr.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,7 @@ class StringRef;
2323
class LoongArchMCExpr : public MCTargetExpr {
2424
public:
2525
using Specifier = uint16_t;
26-
enum {
27-
VK_None,
28-
VK_CALL = 1000, // larger than relocation types
29-
VK_CALL_PLT,
30-
};
26+
enum { VK_None };
3127

3228
private:
3329
const MCExpr *Expr;

llvm/test/CodeGen/LoongArch/addrspacecast.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ define void @cast1(ptr %ptr) {
2424
; LA32-NEXT: .cfi_def_cfa_offset 16
2525
; LA32-NEXT: st.w $ra, $sp, 12 # 4-byte Folded Spill
2626
; LA32-NEXT: .cfi_offset 1, -4
27-
; LA32-NEXT: bl %plt(foo)
27+
; LA32-NEXT: bl foo
2828
; LA32-NEXT: ld.w $ra, $sp, 12 # 4-byte Folded Reload
2929
; LA32-NEXT: addi.w $sp, $sp, 16
3030
; LA32-NEXT: ret

llvm/test/CodeGen/LoongArch/alloca.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ define void @simple_alloca(i32 %n) nounwind {
2020
; LA32-NEXT: bstrins.w $a0, $zero, 3, 0
2121
; LA32-NEXT: sub.w $a0, $sp, $a0
2222
; LA32-NEXT: move $sp, $a0
23-
; LA32-NEXT: bl %plt(notdead)
23+
; LA32-NEXT: bl notdead
2424
; LA32-NEXT: addi.w $sp, $fp, -16
2525
; LA32-NEXT: ld.w $fp, $sp, 8 # 4-byte Folded Reload
2626
; LA32-NEXT: ld.w $ra, $sp, 12 # 4-byte Folded Reload
@@ -67,7 +67,7 @@ define void @scoped_alloca(i32 %n) nounwind {
6767
; LA32-NEXT: bstrins.w $a0, $zero, 3, 0
6868
; LA32-NEXT: sub.w $a0, $sp, $a0
6969
; LA32-NEXT: move $sp, $a0
70-
; LA32-NEXT: bl %plt(notdead)
70+
; LA32-NEXT: bl notdead
7171
; LA32-NEXT: move $sp, $s0
7272
; LA32-NEXT: addi.w $sp, $fp, -16
7373
; LA32-NEXT: ld.w $s0, $sp, 4 # 4-byte Folded Reload
@@ -137,7 +137,7 @@ define void @alloca_callframe(i32 %n) nounwind {
137137
; LA32-NEXT: ori $a6, $zero, 7
138138
; LA32-NEXT: ori $a7, $zero, 8
139139
; LA32-NEXT: st.w $t0, $sp, 0
140-
; LA32-NEXT: bl %plt(func)
140+
; LA32-NEXT: bl func
141141
; LA32-NEXT: addi.w $sp, $sp, 16
142142
; LA32-NEXT: addi.w $sp, $fp, -16
143143
; LA32-NEXT: ld.w $fp, $sp, 8 # 4-byte Folded Reload

llvm/test/CodeGen/LoongArch/bnez-beqz.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ define void @bnez_i32(i32 signext %0) nounwind {
1111
; LA32-NEXT: # %bb.1: # %f
1212
; LA32-NEXT: ret
1313
; LA32-NEXT: .LBB0_2: # %t
14-
; LA32-NEXT: b %plt(bar)
14+
; LA32-NEXT: b bar
1515
;
1616
; LA64-LABEL: bnez_i32:
1717
; LA64: # %bb.0: # %start
@@ -38,7 +38,7 @@ define void @beqz_i32(i32 signext %0) nounwind {
3838
; LA32: # %bb.0: # %start
3939
; LA32-NEXT: beqz $a0, .LBB1_2
4040
; LA32-NEXT: # %bb.1: # %t
41-
; LA32-NEXT: b %plt(bar)
41+
; LA32-NEXT: b bar
4242
; LA32-NEXT: .LBB1_2: # %f
4343
; LA32-NEXT: ret
4444
;
@@ -70,7 +70,7 @@ define void @bnez_i64(i64 %0) nounwind {
7070
; LA32-NEXT: # %bb.1: # %f
7171
; LA32-NEXT: ret
7272
; LA32-NEXT: .LBB2_2: # %t
73-
; LA32-NEXT: b %plt(bar)
73+
; LA32-NEXT: b bar
7474
;
7575
; LA64-LABEL: bnez_i64:
7676
; LA64: # %bb.0: # %start
@@ -98,7 +98,7 @@ define void @beqz_i64(i64 %0) nounwind {
9898
; LA32-NEXT: or $a0, $a0, $a1
9999
; LA32-NEXT: beqz $a0, .LBB3_2
100100
; LA32-NEXT: # %bb.1: # %t
101-
; LA32-NEXT: b %plt(bar)
101+
; LA32-NEXT: b bar
102102
; LA32-NEXT: .LBB3_2: # %f
103103
; LA32-NEXT: ret
104104
;

llvm/test/CodeGen/LoongArch/code-models.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ define i32 @call_globaladdress(i32 %a) nounwind {
1414
; SMALL: # %bb.0:
1515
; SMALL-NEXT: addi.d $sp, $sp, -16
1616
; SMALL-NEXT: st.d $ra, $sp, 8 # 8-byte Folded Spill
17-
; SMALL-NEXT: bl %plt(callee)
17+
; SMALL-NEXT: bl callee
1818
; SMALL-NEXT: ld.d $ra, $sp, 8 # 8-byte Folded Reload
1919
; SMALL-NEXT: addi.d $sp, $sp, 16
2020
; SMALL-NEXT: ret
@@ -55,7 +55,7 @@ define void @call_external_sym(ptr %dst) {
5555
; SMALL-NEXT: .cfi_offset 1, -8
5656
; SMALL-NEXT: ori $a2, $zero, 1000
5757
; SMALL-NEXT: move $a1, $zero
58-
; SMALL-NEXT: bl %plt(memset)
58+
; SMALL-NEXT: bl memset
5959
; SMALL-NEXT: ld.d $ra, $sp, 8 # 8-byte Folded Reload
6060
; SMALL-NEXT: addi.d $sp, $sp, 16
6161
; SMALL-NEXT: ret
@@ -101,7 +101,7 @@ declare i32 @callee_tail(i32 %i)
101101
define i32 @caller_tail(i32 %i) nounwind {
102102
; SMALL-LABEL: caller_tail:
103103
; SMALL: # %bb.0: # %entry
104-
; SMALL-NEXT: b %plt(callee_tail)
104+
; SMALL-NEXT: b callee_tail
105105
;
106106
; MEDIUM-LABEL: caller_tail:
107107
; MEDIUM: # %bb.0: # %entry

0 commit comments

Comments
 (0)