1 //===-- llvm/MC/MCFixup.h - Instruction Relocation and Patching -*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_MC_MCFIXUP_H
11 #define LLVM_MC_MCFIXUP_H
17 // Private constants, do not use.
19 // This is currently laid out so that the MCFixup fields can be efficiently
20 // accessed, while keeping the offset field large enough that the assembler
21 // backend can reasonably use the MCFixup representation for an entire fragment
22 // (splitting any overly large fragments).
24 // The division of bits between the kind and the opindex can be tweaked if we
25 // end up needing more bits for target dependent kinds.
27 MCFIXUP_NUM_GENERIC_KINDS = 128,
28 MCFIXUP_NUM_KIND_BITS = 8,
29 MCFIXUP_NUM_OPINDEX_BITS = 8,
30 MCFIXUP_NUM_OFFSET_BITS = (32 - MCFIXUP_NUM_OPINDEX_BITS -
31 MCFIXUP_NUM_OPINDEX_BITS)
34 /// MCFixupKind - Extensible enumeration to represent the type of a fixup.
36 FK_Data_1 = 0, ///< A one-byte fixup.
37 FK_Data_2, ///< A two-byte fixup.
38 FK_Data_4, ///< A four-byte fixup.
39 FK_Data_8, ///< A eight-byte fixup.
41 FirstTargetFixupKind = MCFIXUP_NUM_GENERIC_KINDS,
43 MaxTargetFixupKind = (1 << MCFIXUP_NUM_KIND_BITS)
46 /// MCFixup - Encode information on a single operation to perform on an byte
47 /// sequence (e.g., an encoded instruction) which requires assemble- or run-
50 /// Fixups are used any time the target instruction encoder needs to represent
51 /// some value in an instruction which is not yet concrete. The encoder will
52 /// encode the instruction assuming the value is 0, and emit a fixup which
53 /// communicates to the assembler backend how it should rewrite the encoded
56 /// During the process of relaxation, the assembler will apply fixups as
57 /// symbolic values become concrete. When relaxation is complete, any remaining
58 /// fixups become relocations in the object file (or errors, if the fixup cannot
59 /// be encoded on the target).
61 static const unsigned MaxOffset = 1 << MCFIXUP_NUM_KIND_BITS;
63 /// The byte index of start of the relocation inside the encoded instruction.
64 unsigned Offset : MCFIXUP_NUM_OFFSET_BITS;
66 /// The index of the operand to encode into the instruction.
67 unsigned OpIndex : MCFIXUP_NUM_OPINDEX_BITS;
69 /// The target dependent kind of fixup item this is. The kind is used to
70 /// determine how the operand value should be encoded into the instruction.
71 unsigned Kind : MCFIXUP_NUM_KIND_BITS;
74 static MCFixup Create(unsigned Offset, unsigned OpIndex, MCFixupKind Kind) {
78 FI.Kind = unsigned(Kind);
80 assert(Offset == FI.getOffset() && "Offset out of range!");
81 assert(OpIndex == FI.getOpIndex() && "Operand index out of range!");
82 assert(Kind == FI.getKind() && "Kind out of range!");
86 unsigned getOffset() const { return Offset; }
88 unsigned getOpIndex() const { return OpIndex; }
90 MCFixupKind getKind() const { return MCFixupKind(Kind); }
93 } // End llvm namespace