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
18 // Private constants, do not use.
20 // This is currently laid out so that the MCFixup fields can be efficiently
21 // accessed, while keeping the offset field large enough that the assembler
22 // backend can reasonably use the MCFixup representation for an entire fragment
23 // (splitting any overly large fragments).
25 // The division of bits between the kind and the opindex can be tweaked if we
26 // end up needing more bits for target dependent kinds.
28 MCFIXUP_NUM_GENERIC_KINDS = 128,
29 MCFIXUP_NUM_KIND_BITS = 16,
30 MCFIXUP_NUM_OFFSET_BITS = (32 - MCFIXUP_NUM_KIND_BITS)
33 /// MCFixupKind - Extensible enumeration to represent the type of a fixup.
35 FK_Data_1 = 0, ///< A one-byte fixup.
36 FK_Data_2, ///< A two-byte fixup.
37 FK_Data_4, ///< A four-byte fixup.
38 FK_Data_8, ///< A eight-byte fixup.
40 FirstTargetFixupKind = MCFIXUP_NUM_GENERIC_KINDS,
42 MaxTargetFixupKind = (1 << MCFIXUP_NUM_KIND_BITS)
45 /// MCFixup - Encode information on a single operation to perform on an byte
46 /// sequence (e.g., an encoded instruction) which requires assemble- or run-
49 /// Fixups are used any time the target instruction encoder needs to represent
50 /// some value in an instruction which is not yet concrete. The encoder will
51 /// encode the instruction assuming the value is 0, and emit a fixup which
52 /// communicates to the assembler backend how it should rewrite the encoded
55 /// During the process of relaxation, the assembler will apply fixups as
56 /// symbolic values become concrete. When relaxation is complete, any remaining
57 /// fixups become relocations in the object file (or errors, if the fixup cannot
58 /// be encoded on the target).
60 static const unsigned MaxOffset = 1 << MCFIXUP_NUM_KIND_BITS;
62 /// The value to put into the fixup location. The exact interpretation of the
63 /// expression is target dependent, usually it will one of the operands to an
64 /// instruction or an assembler directive.
67 /// The byte index of start of the relocation inside the encoded instruction.
68 unsigned Offset : MCFIXUP_NUM_OFFSET_BITS;
70 /// The target dependent kind of fixup item this is. The kind is used to
71 /// determine how the operand value should be encoded into the instruction.
72 unsigned Kind : MCFIXUP_NUM_KIND_BITS;
75 static MCFixup Create(unsigned Offset, const MCExpr *Value,
80 FI.Kind = unsigned(Kind);
82 assert(Offset == FI.getOffset() && "Offset out of range!");
83 assert(Kind == FI.getKind() && "Kind out of range!");
87 MCFixupKind getKind() const { return MCFixupKind(Kind); }
89 unsigned getOffset() const { return Offset; }
91 const MCExpr *getValue() const { return Value; }
93 /// getKindForSize - Return the generic fixup kind for a value with the given
94 /// size. It is an error to pass an unsupported size.
95 static MCFixupKind getKindForSize(unsigned Size) {
97 default: assert(0 && "Invalid generic fixup size!");
98 case 1: return FK_Data_1;
99 case 2: return FK_Data_2;
100 case 4: return FK_Data_4;
101 case 8: return FK_Data_8;
106 } // End llvm namespace