35 RISCVAsmBackend(
const MCSubtargetInfo &STI, uint8_t OSABI,
bool Is64Bit)
38 ~RISCVAsmBackend()
override {}
42 bool requiresDiffExpressionRelocations()
const override {
47 uint64_t
Value,
bool IsResolved,
50 std::unique_ptr<MCObjectTargetWriter>
51 createObjectTargetWriter()
const override;
61 bool fixupNeedsRelaxation(
const MCFixup &Fixup, uint64_t
Value,
67 bool fixupNeedsRelaxationAdvanced(
const MCFixup &Fixup,
bool Resolved,
71 const bool WasForced)
const override;
73 unsigned getNumFixupKinds()
const override {
83 {
"fixup_riscv_hi20", 12, 20, 0 },
84 {
"fixup_riscv_lo12_i", 20, 12, 0 },
85 {
"fixup_riscv_lo12_s", 0, 32, 0 },
94 {
"fixup_riscv_relax", 0, 0, 0 }
97 "Not all fixup kinds added to Infos array");
107 bool mayNeedRelaxation(
const MCInst &Inst,
112 MCInst &Res)
const override;
115 bool writeNopData(
raw_ostream &OS, uint64_t Count)
const override;
119 bool RISCVAsmBackend::fixupNeedsRelaxationAdvanced(
const MCFixup &Fixup,
124 const bool WasForced)
const {
129 if (!Resolved && !WasForced)
132 int64_t
Offset = int64_t(Value);
133 switch ((
unsigned)Fixup.
getKind()) {
139 return Offset > 254 || Offset < -256;
143 return Offset > 2046 || Offset < -2048;
147 void RISCVAsmBackend::relaxInstruction(
const MCInst &Inst,
199 bool RISCVAsmBackend::mayNeedRelaxation(
const MCInst &Inst,
204 bool RISCVAsmBackend::writeNopData(
raw_ostream &OS, uint64_t Count)
const {
206 unsigned MinNopLen = HasStdExtC ? 2 : 4;
208 if ((Count % MinNopLen) != 0)
212 uint64_t Nop32Count = Count / 4;
213 for (uint64_t i = Nop32Count; i != 0; --i)
214 OS.
write(
"\x13\0\0\0", 4);
218 uint64_t Nop16Count = (Count - Nop32Count * 4) / 2;
219 for (uint64_t i = Nop16Count; i != 0; --i)
220 OS.
write(
"\x01\0", 2);
228 unsigned Kind = Fixup.
getKind();
239 return Value & 0xfff;
242 return (((Value >> 5) & 0x7f) << 25) | ((Value & 0x1f) << 7);
246 return ((Value + 0x800) >> 12) & 0xfffff;
248 if (!isInt<21>(Value))
253 unsigned Sbit = (Value >> 20) & 0x1;
254 unsigned Hi8 = (Value >> 12) & 0xff;
255 unsigned Mid1 = (Value >> 11) & 0x1;
256 unsigned Lo10 = (Value >> 1) & 0x3ff;
261 Value = (Sbit << 19) | (Lo10 << 9) | (Mid1 << 8) | Hi8;
265 if (!isInt<13>(Value))
271 unsigned Sbit = (Value >> 12) & 0x1;
272 unsigned Hi1 = (Value >> 11) & 0x1;
273 unsigned Mid6 = (Value >> 5) & 0x3f;
274 unsigned Lo4 = (Value >> 1) & 0xf;
279 Value = (Sbit << 31) | (Mid6 << 25) | (Lo4 << 8) | (Hi1 << 7);
286 uint64_t UpperImm = (Value + 0x800ULL) & 0xfffff000ULL;
287 uint64_t LowerImm = Value & 0xfffULL;
288 return UpperImm | ((LowerImm << 20) << 32);
292 unsigned Bit11 = (Value >> 11) & 0x1;
293 unsigned Bit4 = (Value >> 4) & 0x1;
294 unsigned Bit9_8 = (Value >> 8) & 0x3;
295 unsigned Bit10 = (Value >> 10) & 0x1;
296 unsigned Bit6 = (Value >> 6) & 0x1;
297 unsigned Bit7 = (Value >> 7) & 0x1;
298 unsigned Bit3_1 = (Value >> 1) & 0x7;
299 unsigned Bit5 = (Value >> 5) & 0x1;
300 Value = (Bit11 << 10) | (Bit4 << 9) | (Bit9_8 << 7) | (Bit10 << 6) |
301 (Bit6 << 5) | (Bit7 << 4) | (Bit3_1 << 1) | Bit5;
306 unsigned Bit8 = (Value >> 8) & 0x1;
307 unsigned Bit7_6 = (Value >> 6) & 0x3;
308 unsigned Bit5 = (Value >> 5) & 0x1;
309 unsigned Bit4_3 = (Value >> 3) & 0x3;
310 unsigned Bit2_1 = (Value >> 1) & 0x3;
311 Value = (Bit8 << 12) | (Bit4_3 << 10) | (Bit7_6 << 5) | (Bit2_1 << 3) |
337 assert(Offset + NumBytes <= Data.
size() &&
"Invalid fixup offset!");
341 for (
unsigned i = 0; i != NumBytes; ++i) {
342 Data[Offset + i] |= uint8_t((Value >> (i * 8)) & 0xff);
346 std::unique_ptr<MCObjectTargetWriter>
347 RISCVAsmBackend::createObjectTargetWriter()
const {
359 return new RISCVAsmBackend(STI, OSABI, TT.
isArch64Bit());
std::unique_ptr< MCObjectTargetWriter > createRISCVELFObjectWriter(uint8_t OSABI, bool Is64Bit)
MCAsmBackend * createRISCVAsmBackend(const Target &T, const MCSubtargetInfo &STI, const MCRegisterInfo &MRI, const MCTargetOptions &Options)
Compute iterated dominance frontiers using a linear time algorithm.
This represents an "assembler immediate".
OSType getOS() const
getOS - Get the parsed operating system type of this triple.
virtual const MCFixupKindInfo & getFixupKindInfo(MCFixupKind Kind) const
Get information on a fixup kind.
uint64_t alignTo(uint64_t Value, uint64_t Align, uint64_t Skew=0)
Returns the next integer (mod 2**64) that is greater than or equal to Value and is a multiple of Alig...
unsigned TargetOffset
The bit offset to write the relocation into.
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
const Triple & getTargetTriple() const
Is this fixup kind PCrelative? This is used by the assembler backend to evaluate fixup values in a ta...
MCContext & getContext() const
static MCOperand createReg(unsigned Reg)
const FeatureBitset & getFeatureBits() const
Encapsulates the layout of an assembly file at a particular point in time.
This file implements a class to represent arbitrary precision integral constant values and operations...
Context object for machine code objects.
Instances of this class represent a single low-level machine instruction.
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
A relaxable fragment holds on to its MCInst, since it may need to be relaxed during the assembler lay...
unsigned const MachineRegisterInfo * MRI
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
size_t size() const
size - Get the array size.
MCFixupKind
Extensible enumeration to represent the type of a fixup.
void reportError(SMLoc L, const Twine &Msg)
uint32_t getOffset() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Triple - Helper class for working with autoconf configuration names.
raw_ostream & write(unsigned char C)
void setOpcode(unsigned Op)
const MCOperand & getOperand(unsigned i) const
constexpr size_t array_lengthof(T(&)[N])
Find the length of an array.
unsigned TargetSize
The number of bits written by this fixup.
Target - Wrapper for Target specific information.
static unsigned getRelaxedOpcode(const MCInst &Inst, bool is16BitMode)
bool isArch64Bit() const
Test whether the architecture is 64-bit.
Generic base class for all target subtargets.
static uint64_t adjustFixupValue(const MCFixup &Fixup, uint64_t Value, MCContext &Ctx, const Triple &TheTriple, bool IsResolved)
Target independent information on a fixup kind.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
Generic interface to target specific assembler backends.
This class implements an extremely fast bulk output stream that can only output to a stream...
void addOperand(const MCOperand &Op)
unsigned getOpcode() const
MCFixupKind getKind() const