Skip to content

Commit 34ce16c

Browse files
committed
rebase
Created using spr 1.3.5-bogner
2 parents ae33010 + 6ec27f1 commit 34ce16c

File tree

9 files changed

+207
-219
lines changed

9 files changed

+207
-219
lines changed

llvm/include/llvm/MC/MCFixup.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ class MCFixup {
7575

7676
/// True if this is a PC-relative fixup. The relocatable expression is
7777
/// typically resolved When SymB is nullptr and SymA is a local symbol defined
78-
/// within the current section. While MCAssembler currently sets this based on
79-
/// FKF_IsPCRel, targets should ideally set it at creation.
78+
/// within the current section.
8079
bool PCRel = false;
8180

8281
/// Used by RISC-V style linker relaxation. Whether the fixup is

llvm/include/llvm/MC/MCFixupKindInfo.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ namespace llvm {
1616
/// Target independent information on a fixup kind.
1717
struct MCFixupKindInfo {
1818
enum FixupKindFlags {
19-
/// Is this fixup kind PCrelative? This is used by the assembler backend to
20-
/// evaluate fixup values in a target independent manner when possible.
21-
FKF_IsPCRel = (1 << 0),
22-
2319
/// Should this fixup kind force a 4-byte aligned effective PC value?
2420
FKF_IsAlignedDownTo32Bits = (1 << 1),
2521

llvm/lib/MC/MCAsmBackend.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,22 +87,24 @@ std::optional<MCFixupKind> MCAsmBackend::getFixupKind(StringRef Name) const {
8787
}
8888

8989
MCFixupKindInfo MCAsmBackend::getFixupKindInfo(MCFixupKind Kind) const {
90+
// clang-format off
9091
static const MCFixupKindInfo Builtins[] = {
9192
{"FK_NONE", 0, 0, 0},
9293
{"FK_Data_1", 0, 8, 0},
9394
{"FK_Data_2", 0, 16, 0},
9495
{"FK_Data_4", 0, 32, 0},
9596
{"FK_Data_8", 0, 64, 0},
9697
{"FK_Data_leb128", 0, 0, 0},
97-
{"FK_PCRel_1", 0, 8, MCFixupKindInfo::FKF_IsPCRel},
98-
{"FK_PCRel_2", 0, 16, MCFixupKindInfo::FKF_IsPCRel},
99-
{"FK_PCRel_4", 0, 32, MCFixupKindInfo::FKF_IsPCRel},
100-
{"FK_PCRel_8", 0, 64, MCFixupKindInfo::FKF_IsPCRel},
98+
{"FK_PCRel_1", 0, 8, 0},
99+
{"FK_PCRel_2", 0, 16, 0},
100+
{"FK_PCRel_4", 0, 32, 0},
101+
{"FK_PCRel_8", 0, 64, 0},
101102
{"FK_SecRel_1", 0, 8, 0},
102103
{"FK_SecRel_2", 0, 16, 0},
103104
{"FK_SecRel_4", 0, 32, 0},
104105
{"FK_SecRel_8", 0, 64, 0},
105106
};
107+
// clang-format on
106108

107109
assert(size_t(Kind - FK_NONE) < std::size(Builtins) && "Unknown fixup kind");
108110
return Builtins[Kind - FK_NONE];

llvm/lib/MC/MCAssembler.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,7 @@ bool MCAssembler::evaluateFixup(const MCFragment &F, MCFixup &Fixup,
161161
return true;
162162
}
163163

164-
// TODO: Require targets to set PCRel at fixup creation time.
165164
unsigned FixupFlags = getBackend().getFixupKindInfo(Fixup.getKind()).Flags;
166-
if (FixupFlags & MCFixupKindInfo::FKF_IsPCRel)
167-
Fixup.setPCRel();
168165
bool IsResolved = false;
169166
if (auto State = getBackend().evaluateFixup(Fixup, Target, Value)) {
170167
IsResolved = *State;

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

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,34 +32,30 @@ MCFixupKindInfo CSKYAsmBackend::getFixupKindInfo(MCFixupKind Kind) const {
3232
{CSKY::Fixups::fixup_csky_addr_hi16, {"fixup_csky_addr_hi16", 0, 32, 0}},
3333
{CSKY::Fixups::fixup_csky_addr_lo16, {"fixup_csky_addr_lo16", 0, 32, 0}},
3434
{CSKY::Fixups::fixup_csky_pcrel_imm16_scale2,
35-
{"fixup_csky_pcrel_imm16_scale2", 0, 32, MCFixupKindInfo::FKF_IsPCRel}},
35+
{"fixup_csky_pcrel_imm16_scale2", 0, 32, 0}},
3636
{CSKY::Fixups::fixup_csky_pcrel_uimm16_scale4,
3737
{"fixup_csky_pcrel_uimm16_scale4", 0, 32,
38-
MCFixupKindInfo::FKF_IsPCRel |
39-
MCFixupKindInfo::FKF_IsAlignedDownTo32Bits}},
38+
MCFixupKindInfo::FKF_IsAlignedDownTo32Bits}},
4039
{CSKY::Fixups::fixup_csky_pcrel_uimm8_scale4,
4140
{"fixup_csky_pcrel_uimm8_scale4", 0, 32,
42-
MCFixupKindInfo::FKF_IsPCRel |
43-
MCFixupKindInfo::FKF_IsAlignedDownTo32Bits}},
41+
MCFixupKindInfo::FKF_IsAlignedDownTo32Bits}},
4442
{CSKY::Fixups::fixup_csky_pcrel_imm26_scale2,
45-
{"fixup_csky_pcrel_imm26_scale2", 0, 32, MCFixupKindInfo::FKF_IsPCRel}},
43+
{"fixup_csky_pcrel_imm26_scale2", 0, 32, 0}},
4644
{CSKY::Fixups::fixup_csky_pcrel_imm18_scale2,
47-
{"fixup_csky_pcrel_imm18_scale2", 0, 32, MCFixupKindInfo::FKF_IsPCRel}},
45+
{"fixup_csky_pcrel_imm18_scale2", 0, 32, 0}},
4846
{CSKY::Fixups::fixup_csky_got32, {"fixup_csky_got32", 0, 32, 0}},
4947
{CSKY::Fixups::fixup_csky_got_imm18_scale4,
5048
{"fixup_csky_got_imm18_scale4", 0, 32, 0}},
5149
{CSKY::Fixups::fixup_csky_gotoff, {"fixup_csky_gotoff", 0, 32, 0}},
52-
{CSKY::Fixups::fixup_csky_gotpc,
53-
{"fixup_csky_gotpc", 0, 32, MCFixupKindInfo::FKF_IsPCRel}},
50+
{CSKY::Fixups::fixup_csky_gotpc, {"fixup_csky_gotpc", 0, 32, 0}},
5451
{CSKY::Fixups::fixup_csky_plt32, {"fixup_csky_plt32", 0, 32, 0}},
5552
{CSKY::Fixups::fixup_csky_plt_imm18_scale4,
5653
{"fixup_csky_plt_imm18_scale4", 0, 32, 0}},
5754
{CSKY::Fixups::fixup_csky_pcrel_imm10_scale2,
58-
{"fixup_csky_pcrel_imm10_scale2", 0, 16, MCFixupKindInfo::FKF_IsPCRel}},
55+
{"fixup_csky_pcrel_imm10_scale2", 0, 16, 0}},
5956
{CSKY::Fixups::fixup_csky_pcrel_uimm7_scale4,
6057
{"fixup_csky_pcrel_uimm7_scale4", 0, 16,
61-
MCFixupKindInfo::FKF_IsPCRel |
62-
MCFixupKindInfo::FKF_IsAlignedDownTo32Bits}},
58+
MCFixupKindInfo::FKF_IsAlignedDownTo32Bits}},
6359
{CSKY::Fixups::fixup_csky_doffset_imm18,
6460
{"fixup_csky_doffset_imm18", 0, 18, 0}},
6561
{CSKY::Fixups::fixup_csky_doffset_imm18_scale2,

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

Lines changed: 184 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#include "CSKYMCCodeEmitter.h"
1413
#include "CSKYMCAsmInfo.h"
14+
#include "MCTargetDesc/CSKYFixupKinds.h"
15+
#include "MCTargetDesc/CSKYMCAsmInfo.h"
1516
#include "MCTargetDesc/CSKYMCTargetDesc.h"
1617
#include "llvm/ADT/Statistic.h"
18+
#include "llvm/MC/MCCodeEmitter.h"
19+
#include "llvm/MC/MCContext.h"
1720
#include "llvm/MC/MCInstBuilder.h"
1821
#include "llvm/MC/MCInstrInfo.h"
1922
#include "llvm/MC/MCRegisterInfo.h"
@@ -27,6 +30,186 @@ using namespace llvm;
2730

2831
STATISTIC(MCNumEmitted, "Number of MC instructions emitted");
2932

33+
static void addFixup(SmallVectorImpl<MCFixup> &Fixups, uint32_t Offset,
34+
const MCExpr *Value, uint16_t Kind) {
35+
bool PCRel = false;
36+
switch (Kind) {
37+
case CSKY::Fixups::fixup_csky_pcrel_imm16_scale2:
38+
case CSKY::Fixups::fixup_csky_pcrel_uimm16_scale4:
39+
case CSKY::Fixups::fixup_csky_pcrel_imm26_scale2:
40+
case CSKY::Fixups::fixup_csky_pcrel_imm18_scale2:
41+
case CSKY::Fixups::fixup_csky_gotpc:
42+
case CSKY::Fixups::fixup_csky_pcrel_imm10_scale2:
43+
case CSKY::Fixups::fixup_csky_pcrel_uimm7_scale4:
44+
case CSKY::Fixups::fixup_csky_pcrel_uimm8_scale4:
45+
PCRel = true;
46+
}
47+
Fixups.push_back(MCFixup::create(Offset, Value, Kind, PCRel));
48+
}
49+
50+
namespace {
51+
class CSKYMCCodeEmitter : public MCCodeEmitter {
52+
MCContext &Ctx;
53+
const MCInstrInfo &MII;
54+
55+
public:
56+
CSKYMCCodeEmitter(MCContext &Ctx, const MCInstrInfo &MII)
57+
: Ctx(Ctx), MII(MII) {}
58+
59+
~CSKYMCCodeEmitter() {}
60+
61+
void encodeInstruction(const MCInst &Inst, SmallVectorImpl<char> &CB,
62+
SmallVectorImpl<MCFixup> &Fixups,
63+
const MCSubtargetInfo &STI) const override;
64+
65+
// Generated by tablegen.
66+
uint64_t getBinaryCodeForInstr(const MCInst &MI,
67+
SmallVectorImpl<MCFixup> &Fixups,
68+
const MCSubtargetInfo &STI) const;
69+
70+
// Default encoding method used by tablegen.
71+
unsigned getMachineOpValue(const MCInst &MI, const MCOperand &MO,
72+
SmallVectorImpl<MCFixup> &Fixups,
73+
const MCSubtargetInfo &STI) const;
74+
75+
template <int shift = 0>
76+
unsigned getImmOpValue(const MCInst &MI, unsigned Idx,
77+
SmallVectorImpl<MCFixup> &Fixups,
78+
const MCSubtargetInfo &STI) const {
79+
const MCOperand &MO = MI.getOperand(Idx);
80+
if (MO.isImm())
81+
return (MO.getImm() >> shift);
82+
83+
assert(MO.isExpr() && "Unexpected MO type.");
84+
85+
MCFixupKind Kind = getTargetFixup(MO.getExpr());
86+
addFixup(Fixups, 0, MO.getExpr(), Kind);
87+
return 0;
88+
}
89+
90+
unsigned getRegSeqImmOpValue(const MCInst &MI, unsigned Idx,
91+
SmallVectorImpl<MCFixup> &Fixups,
92+
const MCSubtargetInfo &STI) const;
93+
94+
unsigned getRegisterSeqOpValue(const MCInst &MI, unsigned Op,
95+
SmallVectorImpl<MCFixup> &Fixups,
96+
const MCSubtargetInfo &STI) const;
97+
98+
unsigned getOImmOpValue(const MCInst &MI, unsigned Idx,
99+
SmallVectorImpl<MCFixup> &Fixups,
100+
const MCSubtargetInfo &STI) const;
101+
102+
unsigned getImmOpValueIDLY(const MCInst &MI, unsigned Idx,
103+
SmallVectorImpl<MCFixup> &Fixups,
104+
const MCSubtargetInfo &STI) const;
105+
106+
unsigned getImmJMPIX(const MCInst &MI, unsigned Idx,
107+
SmallVectorImpl<MCFixup> &Fixups,
108+
const MCSubtargetInfo &STI) const;
109+
110+
unsigned getImmOpValueMSBSize(const MCInst &MI, unsigned Idx,
111+
SmallVectorImpl<MCFixup> &Fixups,
112+
const MCSubtargetInfo &STI) const;
113+
114+
unsigned getImmShiftOpValue(const MCInst &MI, unsigned Idx,
115+
SmallVectorImpl<MCFixup> &Fixups,
116+
const MCSubtargetInfo &STI) const {
117+
const MCOperand &MO = MI.getOperand(Idx);
118+
assert(MO.isImm() && "Unexpected MO type.");
119+
return 1 << MO.getImm();
120+
}
121+
122+
MCFixupKind getTargetFixup(const MCExpr *Expr) const;
123+
124+
template <llvm::CSKY::Fixups FIXUP>
125+
unsigned getBranchSymbolOpValue(const MCInst &MI, unsigned Idx,
126+
SmallVectorImpl<MCFixup> &Fixups,
127+
const MCSubtargetInfo &STI) const {
128+
const MCOperand &MO = MI.getOperand(Idx);
129+
130+
if (MO.isImm())
131+
return MO.getImm() >> 1;
132+
133+
assert(MO.isExpr() && "Unexpected MO type.");
134+
135+
MCFixupKind Kind = MCFixupKind(FIXUP);
136+
if (MO.getExpr()->getKind() == MCExpr::Specifier)
137+
Kind = getTargetFixup(MO.getExpr());
138+
139+
addFixup(Fixups, 0, MO.getExpr(), Kind);
140+
return 0;
141+
}
142+
143+
template <llvm::CSKY::Fixups FIXUP>
144+
unsigned getConstpoolSymbolOpValue(const MCInst &MI, unsigned Idx,
145+
SmallVectorImpl<MCFixup> &Fixups,
146+
const MCSubtargetInfo &STI) const {
147+
const MCOperand &MO = MI.getOperand(Idx);
148+
assert(MO.isExpr() && "Unexpected MO type.");
149+
150+
MCFixupKind Kind = MCFixupKind(FIXUP);
151+
if (MO.getExpr()->getKind() == MCExpr::Specifier)
152+
Kind = getTargetFixup(MO.getExpr());
153+
154+
addFixup(Fixups, 0, MO.getExpr(), Kind);
155+
return 0;
156+
}
157+
158+
template <llvm::CSKY::Fixups FIXUP>
159+
unsigned getDataSymbolOpValue(const MCInst &MI, unsigned Idx,
160+
SmallVectorImpl<MCFixup> &Fixups,
161+
const MCSubtargetInfo &STI) const {
162+
const MCOperand &MO = MI.getOperand(Idx);
163+
assert(MO.isExpr() && "Unexpected MO type.");
164+
165+
MCFixupKind Kind = MCFixupKind(FIXUP);
166+
if (MO.getExpr()->getKind() == MCExpr::Specifier)
167+
Kind = getTargetFixup(MO.getExpr());
168+
169+
addFixup(Fixups, 0, MO.getExpr(), Kind);
170+
return 0;
171+
}
172+
173+
unsigned getCallSymbolOpValue(const MCInst &MI, unsigned Idx,
174+
SmallVectorImpl<MCFixup> &Fixups,
175+
const MCSubtargetInfo &STI) const {
176+
const MCOperand &MO = MI.getOperand(Idx);
177+
assert(MO.isExpr() && "Unexpected MO type.");
178+
179+
MCFixupKind Kind = MCFixupKind(CSKY::fixup_csky_pcrel_imm26_scale2);
180+
if (MO.getExpr()->getKind() == MCExpr::Specifier)
181+
Kind = getTargetFixup(MO.getExpr());
182+
183+
addFixup(Fixups, 0, MO.getExpr(), Kind);
184+
return 0;
185+
}
186+
187+
unsigned getBareSymbolOpValue(const MCInst &MI, unsigned Idx,
188+
SmallVectorImpl<MCFixup> &Fixups,
189+
const MCSubtargetInfo &STI) const {
190+
const MCOperand &MO = MI.getOperand(Idx);
191+
assert(MO.isExpr() && "Unexpected MO type.");
192+
193+
MCFixupKind Kind = MCFixupKind(CSKY::fixup_csky_pcrel_imm18_scale2);
194+
if (MO.getExpr()->getKind() == MCExpr::Specifier)
195+
Kind = getTargetFixup(MO.getExpr());
196+
197+
addFixup(Fixups, 0, MO.getExpr(), Kind);
198+
return 0;
199+
}
200+
201+
void expandJBTF(const MCInst &MI, SmallVectorImpl<char> &CB,
202+
SmallVectorImpl<MCFixup> &Fixups,
203+
const MCSubtargetInfo &STI) const;
204+
void expandNEG(const MCInst &MI, SmallVectorImpl<char> &CB,
205+
SmallVectorImpl<MCFixup> &Fixups,
206+
const MCSubtargetInfo &STI) const;
207+
void expandRSUBI(const MCInst &MI, SmallVectorImpl<char> &CB,
208+
SmallVectorImpl<MCFixup> &Fixups,
209+
const MCSubtargetInfo &STI) const;
210+
};
211+
} // namespace
212+
30213
unsigned CSKYMCCodeEmitter::getOImmOpValue(const MCInst &MI, unsigned Idx,
31214
SmallVectorImpl<MCFixup> &Fixups,
32215
const MCSubtargetInfo &STI) const {

0 commit comments

Comments
 (0)