Skip to content

Commit 221bc55

Browse files
committed
Move AVR-specific MCSymbolRefExpr::VariantKind to AVRMCExpr
Note: AVR uses both VK_None and VK_AVR_NONE, which look strange.
1 parent bb69499 commit 221bc55

File tree

9 files changed

+104
-97
lines changed

9 files changed

+104
-97
lines changed

llvm/lib/Target/AVR/AVRAsmPrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ const MCExpr *AVRAsmPrinter::lowerConstant(const Constant *CV) {
206206
bool IsProgMem = GV->getAddressSpace() == AVR::ProgramMemory;
207207
if (IsProgMem) {
208208
const MCExpr *Expr = MCSymbolRefExpr::create(getSymbol(GV), Ctx);
209-
return AVRMCExpr::create(AVRMCExpr::VK_AVR_PM, Expr, false, Ctx);
209+
return AVRMCExpr::create(AVRMCExpr::VK_PM, Expr, false, Ctx);
210210
}
211211
}
212212

llvm/lib/Target/AVR/AVRMCInstLower.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,19 @@ AVRMCInstLower::lowerSymbolOperand(const MachineOperand &MO, MCSymbol *Sym,
4242

4343
if (TF & AVRII::MO_LO) {
4444
if (IsFunction) {
45-
Expr =
46-
AVRMCExpr::create(Subtarget.hasEIJMPCALL() ? AVRMCExpr::VK_AVR_LO8_GS
47-
: AVRMCExpr::VK_AVR_PM_LO8,
48-
Expr, IsNegated, Ctx);
45+
Expr = AVRMCExpr::create(Subtarget.hasEIJMPCALL() ? AVRMCExpr::VK_LO8_GS
46+
: AVRMCExpr::VK_PM_LO8,
47+
Expr, IsNegated, Ctx);
4948
} else {
50-
Expr = AVRMCExpr::create(AVRMCExpr::VK_AVR_LO8, Expr, IsNegated, Ctx);
49+
Expr = AVRMCExpr::create(AVRMCExpr::VK_LO8, Expr, IsNegated, Ctx);
5150
}
5251
} else if (TF & AVRII::MO_HI) {
5352
if (IsFunction) {
54-
Expr =
55-
AVRMCExpr::create(Subtarget.hasEIJMPCALL() ? AVRMCExpr::VK_AVR_HI8_GS
56-
: AVRMCExpr::VK_AVR_PM_HI8,
57-
Expr, IsNegated, Ctx);
53+
Expr = AVRMCExpr::create(Subtarget.hasEIJMPCALL() ? AVRMCExpr::VK_HI8_GS
54+
: AVRMCExpr::VK_PM_HI8,
55+
Expr, IsNegated, Ctx);
5856
} else {
59-
Expr = AVRMCExpr::create(AVRMCExpr::VK_AVR_HI8, Expr, IsNegated, Ctx);
57+
Expr = AVRMCExpr::create(AVRMCExpr::VK_HI8, Expr, IsNegated, Ctx);
6058
}
6159
} else if (TF != 0) {
6260
llvm_unreachable("Unknown target flag on symbol operand");

llvm/lib/Target/AVR/AsmParser/AVRAsmParser.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ bool AVRAsmParser::tryParseExpression(OperandVector &Operands, int64_t offset) {
447447

448448
bool AVRAsmParser::tryParseRelocExpression(OperandVector &Operands) {
449449
bool isNegated = false;
450-
AVRMCExpr::VariantKind ModifierKind = AVRMCExpr::VK_AVR_None;
450+
AVRMCExpr::VariantKind ModifierKind = AVRMCExpr::VK_AVR_NONE;
451451

452452
SMLoc S = Parser.getTok().getLoc();
453453

@@ -473,14 +473,14 @@ bool AVRAsmParser::tryParseRelocExpression(OperandVector &Operands) {
473473
StringRef ModifierName = Parser.getTok().getString();
474474
ModifierKind = AVRMCExpr::getKindByName(ModifierName);
475475

476-
if (ModifierKind != AVRMCExpr::VK_AVR_None) {
476+
if (ModifierKind != AVRMCExpr::VK_AVR_NONE) {
477477
Parser.Lex();
478478
Parser.Lex(); // Eat modifier name and parenthesis
479479
if (Parser.getTok().getString() == GENERATE_STUBS &&
480480
Parser.getTok().getKind() == AsmToken::Identifier) {
481481
std::string GSModName = ModifierName.str() + "_" + GENERATE_STUBS;
482482
ModifierKind = AVRMCExpr::getKindByName(GSModName);
483-
if (ModifierKind != AVRMCExpr::VK_AVR_None)
483+
if (ModifierKind != AVRMCExpr::VK_AVR_NONE)
484484
Parser.Lex(); // Eat gs modifier name
485485
}
486486
} else {
@@ -698,7 +698,7 @@ ParseStatus AVRAsmParser::parseLiteralValues(unsigned SizeInBytes, SMLoc L) {
698698
Tokens[1].getKind() == AsmToken::Identifier) {
699699
MCSymbol *Symbol = getContext().getOrCreateSymbol(".text");
700700
AVRStreamer.emitValueForModiferKind(Symbol, SizeInBytes, L,
701-
AVRMCExpr::VK_AVR_None);
701+
AVRMCExpr::VK_AVR_NONE);
702702
return ParseStatus::NoMatch;
703703
}
704704

@@ -707,7 +707,7 @@ ParseStatus AVRAsmParser::parseLiteralValues(unsigned SizeInBytes, SMLoc L) {
707707
StringRef ModifierName = Parser.getTok().getString();
708708
AVRMCExpr::VariantKind ModifierKind =
709709
AVRMCExpr::getKindByName(ModifierName);
710-
if (ModifierKind != AVRMCExpr::VK_AVR_None) {
710+
if (ModifierKind != AVRMCExpr::VK_AVR_NONE) {
711711
Parser.Lex();
712712
Parser.Lex(); // Eat the modifier and parenthesis
713713
} else {

llvm/lib/Target/AVR/MCTargetDesc/AVRELFObjectWriter.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "MCTargetDesc/AVRFixupKinds.h"
10+
#include "MCTargetDesc/AVRMCExpr.h"
1011
#include "MCTargetDesc/AVRMCTargetDesc.h"
1112

1213
#include "llvm/MC/MCAssembler.h"
@@ -39,42 +40,42 @@ unsigned AVRELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target,
3940
const unsigned Kind = Fixup.getTargetKind();
4041
if (Kind >= FirstLiteralRelocationKind)
4142
return Kind - FirstLiteralRelocationKind;
42-
MCSymbolRefExpr::VariantKind Modifier = Target.getAccessVariant();
43+
auto Modifier = AVRMCExpr::VariantKind(Target.getAccessVariant());
4344
switch ((unsigned)Fixup.getKind()) {
4445
case FK_Data_1:
4546
switch (Modifier) {
4647
default:
4748
llvm_unreachable("Unsupported Modifier");
48-
case MCSymbolRefExpr::VK_None:
49+
case AVRMCExpr::VK_None:
4950
return ELF::R_AVR_8;
50-
case MCSymbolRefExpr::VK_AVR_DIFF8:
51+
case AVRMCExpr::VK_DIFF8:
5152
return ELF::R_AVR_DIFF8;
52-
case MCSymbolRefExpr::VK_AVR_LO8:
53+
case AVRMCExpr::VK_LO8:
5354
return ELF::R_AVR_8_LO8;
54-
case MCSymbolRefExpr::VK_AVR_HI8:
55+
case AVRMCExpr::VK_HI8:
5556
return ELF::R_AVR_8_HI8;
56-
case MCSymbolRefExpr::VK_AVR_HLO8:
57+
case AVRMCExpr::VK_HH8:
5758
return ELF::R_AVR_8_HLO8;
5859
}
5960
case FK_Data_4:
6061
switch (Modifier) {
6162
default:
6263
llvm_unreachable("Unsupported Modifier");
63-
case MCSymbolRefExpr::VK_None:
64+
case AVRMCExpr::VK_None:
6465
return ELF::R_AVR_32;
65-
case MCSymbolRefExpr::VK_AVR_DIFF32:
66+
case AVRMCExpr::VK_DIFF32:
6667
return ELF::R_AVR_DIFF32;
6768
}
6869
case FK_Data_2:
6970
switch (Modifier) {
7071
default:
7172
llvm_unreachable("Unsupported Modifier");
72-
case MCSymbolRefExpr::VK_None:
73+
case AVRMCExpr::VK_None:
7374
return ELF::R_AVR_16;
74-
case MCSymbolRefExpr::VK_AVR_NONE:
75-
case MCSymbolRefExpr::VK_AVR_PM:
75+
case AVRMCExpr::VK_AVR_NONE:
76+
case AVRMCExpr::VK_PM:
7677
return ELF::R_AVR_16_PM;
77-
case MCSymbolRefExpr::VK_AVR_DIFF16:
78+
case AVRMCExpr::VK_DIFF16:
7879
return ELF::R_AVR_DIFF16;
7980
}
8081
case AVR::fixup_32:

llvm/lib/Target/AVR/MCTargetDesc/AVRMCAsmInfo.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,17 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "AVRMCAsmInfo.h"
14+
#include "AVRMCExpr.h"
1415
#include "llvm/MC/MCExpr.h"
1516
#include "llvm/TargetParser/Triple.h"
1617

1718
using namespace llvm;
1819

1920
const MCAsmInfo::VariantKindDesc variantKindDescs[] = {
20-
{MCSymbolRefExpr::VK_AVR_DIFF16, "diff16"},
21-
{MCSymbolRefExpr::VK_AVR_DIFF32, "diff32"},
22-
{MCSymbolRefExpr::VK_AVR_DIFF8, "diff8"},
23-
{MCSymbolRefExpr::VK_AVR_HI8, "hi8"},
24-
{MCSymbolRefExpr::VK_AVR_HLO8, "hlo8"},
25-
{MCSymbolRefExpr::VK_AVR_LO8, "lo8"},
26-
{MCSymbolRefExpr::VK_AVR_NONE, "none"},
27-
{MCSymbolRefExpr::VK_AVR_PM, "pm"},
21+
{AVRMCExpr::VK_DIFF16, "diff16"}, {AVRMCExpr::VK_DIFF32, "diff32"},
22+
{AVRMCExpr::VK_DIFF8, "diff8"}, {AVRMCExpr::VK_HI8, "hi8"},
23+
{AVRMCExpr::VK_HH8, "hlo8"}, {AVRMCExpr::VK_LO8, "lo8"},
24+
{AVRMCExpr::VK_PM, "pm"},
2825
};
2926

3027
AVRMCAsmInfo::AVRMCAsmInfo(const Triple &TT, const MCTargetOptions &Options) {

llvm/lib/Target/AVR/MCTargetDesc/AVRMCELFStreamer.cpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,23 @@ using namespace llvm;
2323
void AVRMCELFStreamer::emitValueForModiferKind(
2424
const MCSymbol *Sym, unsigned SizeInBytes, SMLoc Loc,
2525
AVRMCExpr::VariantKind ModifierKind) {
26-
MCSymbolRefExpr::VariantKind Kind = MCSymbolRefExpr::VK_AVR_NONE;
27-
if (ModifierKind == AVRMCExpr::VK_AVR_None) {
28-
Kind = MCSymbolRefExpr::VK_AVR_DIFF8;
26+
AVRMCExpr::VariantKind Kind = AVRMCExpr::VK_AVR_NONE;
27+
if (ModifierKind == AVRMCExpr::VK_AVR_NONE) {
28+
Kind = AVRMCExpr::VK_DIFF8;
2929
if (SizeInBytes == SIZE_LONG)
30-
Kind = MCSymbolRefExpr::VK_AVR_DIFF32;
30+
Kind = AVRMCExpr::VK_DIFF32;
3131
else if (SizeInBytes == SIZE_WORD)
32-
Kind = MCSymbolRefExpr::VK_AVR_DIFF16;
33-
} else if (ModifierKind == AVRMCExpr::VK_AVR_LO8)
34-
Kind = MCSymbolRefExpr::VK_AVR_LO8;
35-
else if (ModifierKind == AVRMCExpr::VK_AVR_HI8)
36-
Kind = MCSymbolRefExpr::VK_AVR_HI8;
37-
else if (ModifierKind == AVRMCExpr::VK_AVR_HH8)
38-
Kind = MCSymbolRefExpr::VK_AVR_HLO8;
39-
MCELFStreamer::emitValue(MCSymbolRefExpr::create(Sym, Kind, getContext()),
40-
SizeInBytes, Loc);
32+
Kind = AVRMCExpr::VK_DIFF16;
33+
} else if (ModifierKind == AVRMCExpr::VK_LO8)
34+
Kind = AVRMCExpr::VK_LO8;
35+
else if (ModifierKind == AVRMCExpr::VK_HI8)
36+
Kind = AVRMCExpr::VK_HI8;
37+
else if (ModifierKind == AVRMCExpr::VK_HH8)
38+
Kind = AVRMCExpr::VK_HH8;
39+
MCELFStreamer::emitValue(
40+
MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VariantKind(Kind),
41+
getContext()),
42+
SizeInBytes, Loc);
4143
}
4244

4345
namespace llvm {

llvm/lib/Target/AVR/MCTargetDesc/AVRMCELFStreamer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class AVRMCELFStreamer : public MCELFStreamer {
4343

4444
void emitValueForModiferKind(
4545
const MCSymbol *Sym, unsigned SizeInBytes, SMLoc Loc = SMLoc(),
46-
AVRMCExpr::VariantKind ModifierKind = AVRMCExpr::VK_AVR_None);
46+
AVRMCExpr::VariantKind ModifierKind = AVRMCExpr::VK_AVR_NONE);
4747
};
4848

4949
MCStreamer *createAVRELFStreamer(Triple const &TT, MCContext &Context,

llvm/lib/Target/AVR/MCTargetDesc/AVRMCExpr.cpp

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ const struct ModifierEntry {
2121
const char *const Spelling;
2222
AVRMCExpr::VariantKind VariantKind;
2323
} ModifierNames[] = {
24-
{"lo8", AVRMCExpr::VK_AVR_LO8}, {"hi8", AVRMCExpr::VK_AVR_HI8},
25-
{"hh8", AVRMCExpr::VK_AVR_HH8}, // synonym with hlo8
26-
{"hlo8", AVRMCExpr::VK_AVR_HH8}, {"hhi8", AVRMCExpr::VK_AVR_HHI8},
24+
{"lo8", AVRMCExpr::VK_LO8}, {"hi8", AVRMCExpr::VK_HI8},
25+
{"hh8", AVRMCExpr::VK_HH8}, // synonym with hlo8
26+
{"hlo8", AVRMCExpr::VK_HH8}, {"hhi8", AVRMCExpr::VK_HHI8},
2727

28-
{"pm", AVRMCExpr::VK_AVR_PM}, {"pm_lo8", AVRMCExpr::VK_AVR_PM_LO8},
29-
{"pm_hi8", AVRMCExpr::VK_AVR_PM_HI8}, {"pm_hh8", AVRMCExpr::VK_AVR_PM_HH8},
28+
{"pm", AVRMCExpr::VK_PM}, {"pm_lo8", AVRMCExpr::VK_PM_LO8},
29+
{"pm_hi8", AVRMCExpr::VK_PM_HI8}, {"pm_hh8", AVRMCExpr::VK_PM_HH8},
3030

31-
{"lo8_gs", AVRMCExpr::VK_AVR_LO8_GS}, {"hi8_gs", AVRMCExpr::VK_AVR_HI8_GS},
32-
{"gs", AVRMCExpr::VK_AVR_GS},
31+
{"lo8_gs", AVRMCExpr::VK_LO8_GS}, {"hi8_gs", AVRMCExpr::VK_HI8_GS},
32+
{"gs", AVRMCExpr::VK_GS},
3333
};
3434

3535
} // end of anonymous namespace
@@ -40,7 +40,7 @@ const AVRMCExpr *AVRMCExpr::create(VariantKind Kind, const MCExpr *Expr,
4040
}
4141

4242
void AVRMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
43-
assert(Kind != VK_AVR_None);
43+
assert(Kind != VK_AVR_NONE);
4444
OS << getName() << '(';
4545
if (isNegated())
4646
OS << '-' << '(';
@@ -87,8 +87,8 @@ bool AVRMCExpr::evaluateAsRelocatableImpl(MCValue &Result,
8787
MCSymbolRefExpr::VariantKind Modifier = Sym->getKind();
8888
if (Modifier != MCSymbolRefExpr::VK_None)
8989
return false;
90-
if (Kind == VK_AVR_PM) {
91-
Modifier = MCSymbolRefExpr::VK_AVR_PM;
90+
if (Kind == VK_PM) {
91+
Modifier = MCSymbolRefExpr::VariantKind(AVRMCExpr::VK_PM);
9292
}
9393

9494
Sym = MCSymbolRefExpr::create(&Sym->getSymbol(), Modifier, Context);
@@ -103,43 +103,44 @@ int64_t AVRMCExpr::evaluateAsInt64(int64_t Value) const {
103103
Value *= -1;
104104

105105
switch (Kind) {
106-
case AVRMCExpr::VK_AVR_LO8:
106+
case AVRMCExpr::VK_LO8:
107107
Value &= 0xff;
108108
break;
109-
case AVRMCExpr::VK_AVR_HI8:
109+
case AVRMCExpr::VK_HI8:
110110
Value &= 0xff00;
111111
Value >>= 8;
112112
break;
113-
case AVRMCExpr::VK_AVR_HH8:
113+
case AVRMCExpr::VK_HH8:
114114
Value &= 0xff0000;
115115
Value >>= 16;
116116
break;
117-
case AVRMCExpr::VK_AVR_HHI8:
117+
case AVRMCExpr::VK_HHI8:
118118
Value &= 0xff000000;
119119
Value >>= 24;
120120
break;
121-
case AVRMCExpr::VK_AVR_PM_LO8:
122-
case AVRMCExpr::VK_AVR_LO8_GS:
121+
case AVRMCExpr::VK_PM_LO8:
122+
case AVRMCExpr::VK_LO8_GS:
123123
Value >>= 1; // Program memory addresses must always be shifted by one.
124124
Value &= 0xff;
125125
break;
126-
case AVRMCExpr::VK_AVR_PM_HI8:
127-
case AVRMCExpr::VK_AVR_HI8_GS:
126+
case AVRMCExpr::VK_PM_HI8:
127+
case AVRMCExpr::VK_HI8_GS:
128128
Value >>= 1; // Program memory addresses must always be shifted by one.
129129
Value &= 0xff00;
130130
Value >>= 8;
131131
break;
132-
case AVRMCExpr::VK_AVR_PM_HH8:
132+
case AVRMCExpr::VK_PM_HH8:
133133
Value >>= 1; // Program memory addresses must always be shifted by one.
134134
Value &= 0xff0000;
135135
Value >>= 16;
136136
break;
137-
case AVRMCExpr::VK_AVR_PM:
138-
case AVRMCExpr::VK_AVR_GS:
137+
case AVRMCExpr::VK_PM:
138+
case AVRMCExpr::VK_GS:
139139
Value >>= 1; // Program memory addresses must always be shifted by one.
140140
break;
141141

142-
case AVRMCExpr::VK_AVR_None:
142+
case AVRMCExpr::VK_AVR_NONE:
143+
default:
143144
llvm_unreachable("Uninitialized expression.");
144145
}
145146
return static_cast<uint64_t>(Value) & 0xff;
@@ -149,40 +150,40 @@ AVR::Fixups AVRMCExpr::getFixupKind() const {
149150
AVR::Fixups Kind = AVR::Fixups::LastTargetFixupKind;
150151

151152
switch (getKind()) {
152-
case VK_AVR_LO8:
153+
case VK_LO8:
153154
Kind = isNegated() ? AVR::fixup_lo8_ldi_neg : AVR::fixup_lo8_ldi;
154155
break;
155-
case VK_AVR_HI8:
156+
case VK_HI8:
156157
Kind = isNegated() ? AVR::fixup_hi8_ldi_neg : AVR::fixup_hi8_ldi;
157158
break;
158-
case VK_AVR_HH8:
159+
case VK_HH8:
159160
Kind = isNegated() ? AVR::fixup_hh8_ldi_neg : AVR::fixup_hh8_ldi;
160161
break;
161-
case VK_AVR_HHI8:
162+
case VK_HHI8:
162163
Kind = isNegated() ? AVR::fixup_ms8_ldi_neg : AVR::fixup_ms8_ldi;
163164
break;
164165

165-
case VK_AVR_PM_LO8:
166+
case VK_PM_LO8:
166167
Kind = isNegated() ? AVR::fixup_lo8_ldi_pm_neg : AVR::fixup_lo8_ldi_pm;
167168
break;
168-
case VK_AVR_PM_HI8:
169+
case VK_PM_HI8:
169170
Kind = isNegated() ? AVR::fixup_hi8_ldi_pm_neg : AVR::fixup_hi8_ldi_pm;
170171
break;
171-
case VK_AVR_PM_HH8:
172+
case VK_PM_HH8:
172173
Kind = isNegated() ? AVR::fixup_hh8_ldi_pm_neg : AVR::fixup_hh8_ldi_pm;
173174
break;
174-
case VK_AVR_PM:
175-
case VK_AVR_GS:
175+
case VK_PM:
176+
case VK_GS:
176177
Kind = AVR::fixup_16_pm;
177178
break;
178-
case VK_AVR_LO8_GS:
179+
case VK_LO8_GS:
179180
Kind = AVR::fixup_lo8_ldi_gs;
180181
break;
181-
case VK_AVR_HI8_GS:
182+
case VK_HI8_GS:
182183
Kind = AVR::fixup_hi8_ldi_gs;
183184
break;
184185

185-
case VK_AVR_None:
186+
default:
186187
llvm_unreachable("Uninitialized expression");
187188
}
188189

@@ -214,7 +215,7 @@ AVRMCExpr::VariantKind AVRMCExpr::getKindByName(StringRef Name) {
214215
if (Modifier != std::end(ModifierNames)) {
215216
return Modifier->VariantKind;
216217
}
217-
return VK_AVR_None;
218+
return VK_AVR_NONE;
218219
}
219220

220221
} // end of namespace llvm

0 commit comments

Comments
 (0)