Skip to content

Commit 4781a8e

Browse files
committed
MCValue: add setSpecifier to simplify code
This primarily simplifies backend evaluateAsRelocatableImpl.
1 parent dfae1f9 commit 4781a8e

File tree

13 files changed

+23
-40
lines changed

13 files changed

+23
-40
lines changed

llvm/include/llvm/MC/MCValue.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class MCValue {
4444
const MCSymbolRefExpr *getSymA() const { return SymA; }
4545
const MCSymbolRefExpr *getSymB() const { return SymB; }
4646
uint32_t getRefKind() const { return RefKind; }
47+
void setSpecifier(uint32_t S) { RefKind = S; }
4748

4849
const MCSymbol *getAddSym() const {
4950
return SymA ? &SymA->getSymbol() : nullptr;

llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,7 @@ bool AArch64MCExpr::evaluateAsRelocatableImpl(MCValue &Res,
112112
const MCAssembler *Asm) const {
113113
if (!getSubExpr()->evaluateAsRelocatable(Res, Asm))
114114
return false;
115-
116-
Res =
117-
MCValue::get(Res.getSymA(), Res.getSymB(), Res.getConstant(), getKind());
118-
115+
Res.setSpecifier(getSpecifier());
119116
return true;
120117
}
121118

llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ class AArch64MCExpr : public MCTargetExpr {
145145

146146
/// Get the kind of this expression.
147147
VariantKind getKind() const { return Kind; }
148+
VariantKind getSpecifier() const { return Kind; }
148149

149150
/// Get the expression this modifier applies to.
150151
const MCExpr *getSubExpr() const { return Expr; }

llvm/lib/Target/CSKY/MCTargetDesc/CSKYMCExpr.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ bool CSKYMCExpr::evaluateAsRelocatableImpl(MCValue &Res,
7171
const MCAssembler *Asm) const {
7272
if (!getSubExpr()->evaluateAsRelocatable(Res, Asm))
7373
return false;
74-
75-
Res =
76-
MCValue::get(Res.getSymA(), Res.getSymB(), Res.getConstant(), specifier);
74+
Res.setSpecifier(specifier);
7775
return !Res.getSymB();
7876
}

llvm/lib/Target/Lanai/MCTargetDesc/LanaiMCExpr.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ const LanaiMCExpr *LanaiMCExpr::create(VariantKind Kind, const MCExpr *Expr,
2020
}
2121

2222
void LanaiMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
23-
if (Kind == VK_Lanai_None) {
23+
if (specifier == VK_Lanai_None) {
2424
Expr->print(OS, MAI);
2525
return;
2626
}
2727

28-
switch (Kind) {
28+
switch (specifier) {
2929
default:
3030
llvm_unreachable("Invalid kind!");
3131
case VK_Lanai_ABS_HI:
@@ -50,9 +50,6 @@ bool LanaiMCExpr::evaluateAsRelocatableImpl(MCValue &Res,
5050
const MCAssembler *Asm) const {
5151
if (!getSubExpr()->evaluateAsRelocatable(Res, Asm))
5252
return false;
53-
54-
Res =
55-
MCValue::get(Res.getSymA(), Res.getSymB(), Res.getConstant(), getKind());
56-
53+
Res.setSpecifier(specifier);
5754
return true;
5855
}

llvm/lib/Target/Lanai/MCTargetDesc/LanaiMCExpr.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ class LanaiMCExpr : public MCTargetExpr {
1919
enum VariantKind { VK_Lanai_None, VK_Lanai_ABS_HI, VK_Lanai_ABS_LO };
2020

2121
private:
22-
const VariantKind Kind;
22+
const VariantKind specifier;
2323
const MCExpr *Expr;
2424

2525
explicit LanaiMCExpr(VariantKind Kind, const MCExpr *Expr)
26-
: Kind(Kind), Expr(Expr) {}
26+
: specifier(Kind), Expr(Expr) {}
2727

2828
public:
2929
static const LanaiMCExpr *create(VariantKind Kind, const MCExpr *Expr,
3030
MCContext &Ctx);
3131

3232
// Returns the kind of this expression.
33-
VariantKind getKind() const { return Kind; }
33+
VariantKind getKind() const { return specifier; }
3434

3535
// Returns the child of this expression.
3636
const MCExpr *getSubExpr() const { return Expr; }

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ bool LoongArchMCExpr::evaluateAsRelocatableImpl(
4949
if (!getSubExpr()->evaluateAsRelocatable(Res, nullptr))
5050
return false;
5151

52-
Res =
53-
MCValue::get(Res.getSymA(), Res.getSymB(), Res.getConstant(), specifier);
52+
Res.setSpecifier(specifier);
5453
// Custom fixup types are not valid with symbol difference expressions.
5554
return Res.getSymB() ? specifier == VK_None : true;
5655
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,8 @@ bool RISCVMCExpr::evaluateAsRelocatableImpl(MCValue &Res,
9191
const MCAssembler *Asm) const {
9292
if (!getSubExpr()->evaluateAsRelocatable(Res, Asm))
9393
return false;
94+
Res.setSpecifier(specifier);
9495

95-
Res = MCValue::get(Res.getSymA(), Res.getSymB(), Res.getConstant(),
96-
getSpecifier());
9796
// Custom fixup types are not valid with symbol difference expressions.
9897
return Res.getSymB() ? getSpecifier() == VK_None : true;
9998
}

llvm/lib/Target/Sparc/MCTargetDesc/SparcMCExpr.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,7 @@ bool SparcMCExpr::evaluateAsRelocatableImpl(MCValue &Res,
186186
const MCAssembler *Asm) const {
187187
if (!getSubExpr()->evaluateAsRelocatable(Res, Asm))
188188
return false;
189-
Res = MCValue::get(Res.getSymA(), Res.getSymB(), Res.getConstant(),
190-
getSpecifier());
189+
Res.setSpecifier(specifier);
191190
return true;
192191
}
193192

llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCExpr.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ bool SystemZMCExpr::evaluateAsRelocatableImpl(MCValue &Res,
4040
const MCAssembler *Asm) const {
4141
if (!getSubExpr()->evaluateAsRelocatable(Res, Asm))
4242
return false;
43-
44-
Res = MCValue::get(Res.getSymA(), Res.getSymB(), Res.getConstant(),
45-
getSpecifier());
46-
43+
Res.setSpecifier(specifier);
4744
return true;
4845
}

llvm/lib/Target/VE/MCTargetDesc/VEMCExpr.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ void VEMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
3434

3535
const MCExpr *Expr = getSubExpr();
3636
Expr->print(OS, MAI);
37-
if (Kind != VK_None && Kind != VK_REFLONG)
38-
OS << '@' << MAI->getSpecifierName(Kind);
37+
if (specifier != VK_None && specifier != VK_REFLONG)
38+
OS << '@' << MAI->getSpecifierName(specifier);
3939
}
4040

4141
VE::Fixups VEMCExpr::getFixupKind(VEMCExpr::Specifier S) {
@@ -79,10 +79,7 @@ bool VEMCExpr::evaluateAsRelocatableImpl(MCValue &Res,
7979
const MCAssembler *Asm) const {
8080
if (!getSubExpr()->evaluateAsRelocatable(Res, Asm))
8181
return false;
82-
83-
Res = MCValue::get(Res.getSymA(), Res.getSymB(), Res.getConstant(),
84-
getSpecifier());
85-
82+
Res.setSpecifier(specifier);
8683
return true;
8784
}
8885

llvm/lib/Target/VE/MCTargetDesc/VEMCExpr.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ class VEMCExpr : public MCTargetExpr {
4343
};
4444

4545
private:
46-
const Specifier Kind;
46+
const Specifier specifier;
4747
const MCExpr *Expr;
4848

49-
explicit VEMCExpr(Specifier Kind, const MCExpr *Expr)
50-
: Kind(Kind), Expr(Expr) {}
49+
explicit VEMCExpr(Specifier S, const MCExpr *Expr)
50+
: specifier(S), Expr(Expr) {}
5151

5252
public:
5353
/// @name Construction
@@ -60,13 +60,13 @@ class VEMCExpr : public MCTargetExpr {
6060
/// @{
6161

6262
/// getOpcode - Get the kind of this expression.
63-
Specifier getSpecifier() const { return Kind; }
63+
Specifier getSpecifier() const { return specifier; }
6464

6565
/// getSubExpr - Get the child of this expression.
6666
const MCExpr *getSubExpr() const { return Expr; }
6767

6868
/// getFixupKind - Get the fixup kind of this expression.
69-
VE::Fixups getFixupKind() const { return getFixupKind(Kind); }
69+
VE::Fixups getFixupKind() const { return getFixupKind(specifier); }
7070

7171
/// @}
7272
void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;

llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCExpr.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ bool XtensaMCExpr::evaluateAsRelocatableImpl(MCValue &Res,
4444
const MCAssembler *Asm) const {
4545
if (!getSubExpr()->evaluateAsRelocatable(Res, Asm))
4646
return false;
47-
48-
Res =
49-
MCValue::get(Res.getSymA(), Res.getSymB(), Res.getConstant(), specifier);
47+
Res.setSpecifier(specifier);
5048
return !Res.getSymB();
5149
}
5250

0 commit comments

Comments
 (0)