Chris Lattner | b89df9c | 2004-11-20 03:05:50 +0000 | [diff] [blame] | 1 | //===-- llvm/CodeGen/MachineRelocation.h - Target Relocation ----*- C++ -*-===// |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 2 | // |
Chris Lattner | b89df9c | 2004-11-20 03:05:50 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 7ed47a1 | 2007-12-29 19:59:42 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 7 | // |
Chris Lattner | b89df9c | 2004-11-20 03:05:50 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines the MachineRelocation class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef LLVM_CODEGEN_MACHINERELOCATION_H |
| 15 | #define LLVM_CODEGEN_MACHINERELOCATION_H |
| 16 | |
Michael J. Spencer | 1f6efa3 | 2010-11-29 18:16:10 +0000 | [diff] [blame] | 17 | #include "llvm/Support/DataTypes.h" |
Chris Lattner | 4e2239d | 2004-11-20 23:40:54 +0000 | [diff] [blame] | 18 | #include <cassert> |
Chris Lattner | b89df9c | 2004-11-20 03:05:50 +0000 | [diff] [blame] | 19 | |
| 20 | namespace llvm { |
| 21 | class GlobalValue; |
Evan Cheng | b4e80f8 | 2006-07-27 18:18:13 +0000 | [diff] [blame] | 22 | class MachineBasicBlock; |
Chris Lattner | b89df9c | 2004-11-20 03:05:50 +0000 | [diff] [blame] | 23 | |
| 24 | /// MachineRelocation - This represents a target-specific relocation value, |
| 25 | /// produced by the code emitter. This relocation is resolved after the has |
| 26 | /// been emitted, either to an object file or to memory, when the target of the |
| 27 | /// relocation can be resolved. |
| 28 | /// |
| 29 | /// A relocation is made up of the following logical portions: |
| 30 | /// 1. An offset in the machine code buffer, the location to modify. |
Chris Lattner | 765da91 | 2004-11-21 03:27:13 +0000 | [diff] [blame] | 31 | /// 2. A target specific relocation type (a number from 0 to 63). |
Chris Lattner | b89df9c | 2004-11-20 03:05:50 +0000 | [diff] [blame] | 32 | /// 3. A symbol being referenced, either as a GlobalValue* or as a string. |
| 33 | /// 4. An optional constant value to be added to the reference. |
Chris Lattner | 765da91 | 2004-11-21 03:27:13 +0000 | [diff] [blame] | 34 | /// 5. A bit, CanRewrite, which indicates to the JIT that a function stub is |
| 35 | /// not needed for the relocation. |
Andrew Lenharth | 6a6b2db | 2005-07-22 20:46:42 +0000 | [diff] [blame] | 36 | /// 6. An index into the GOT, if the target uses a GOT |
Chris Lattner | b89df9c | 2004-11-20 03:05:50 +0000 | [diff] [blame] | 37 | /// |
| 38 | class MachineRelocation { |
Chris Lattner | 1e3822c | 2006-05-03 18:52:31 +0000 | [diff] [blame] | 39 | enum AddressType { |
| 40 | isResult, // Relocation has be transformed into its result pointer. |
| 41 | isGV, // The Target.GV field is valid. |
Evan Cheng | 9ed2f80 | 2008-11-10 01:08:07 +0000 | [diff] [blame] | 42 | isIndirectSym, // Relocation of an indirect symbol. |
Evan Cheng | b4e80f8 | 2006-07-27 18:18:13 +0000 | [diff] [blame] | 43 | isBB, // Relocation of BB address. |
Chris Lattner | 1e3822c | 2006-05-03 18:52:31 +0000 | [diff] [blame] | 44 | isExtSym, // The Target.ExtSym field is valid. |
Evan Cheng | 52b510b | 2006-06-23 01:02:37 +0000 | [diff] [blame] | 45 | isConstPool, // Relocation of constant pool address. |
| 46 | isJumpTable, // Relocation of jump table address. |
Chris Lattner | 1e3822c | 2006-05-03 18:52:31 +0000 | [diff] [blame] | 47 | isGOTIndex // The Target.GOTIndex field is valid. |
| 48 | }; |
| 49 | |
| 50 | /// Offset - This is the offset from the start of the code buffer of the |
| 51 | /// relocation to perform. |
Evan Cheng | 5788d1a | 2008-12-10 02:32:19 +0000 | [diff] [blame] | 52 | uintptr_t Offset; |
Chris Lattner | 1e3822c | 2006-05-03 18:52:31 +0000 | [diff] [blame] | 53 | |
| 54 | /// ConstantVal - A field that may be used by the target relocation type. |
| 55 | intptr_t ConstantVal; |
| 56 | |
Chris Lattner | b89df9c | 2004-11-20 03:05:50 +0000 | [diff] [blame] | 57 | union { |
Evan Cheng | b4e80f8 | 2006-07-27 18:18:13 +0000 | [diff] [blame] | 58 | void *Result; // If this has been resolved to a resolved pointer |
Evan Cheng | 9ed2f80 | 2008-11-10 01:08:07 +0000 | [diff] [blame] | 59 | GlobalValue *GV; // If this is a pointer to a GV or an indirect ref. |
Evan Cheng | b4e80f8 | 2006-07-27 18:18:13 +0000 | [diff] [blame] | 60 | MachineBasicBlock *MBB; // If this is a pointer to a LLVM BB |
| 61 | const char *ExtSym; // If this is a pointer to a named symbol |
| 62 | unsigned Index; // Constant pool / jump table index |
| 63 | unsigned GOTIndex; // Index in the GOT of this symbol/global |
Chris Lattner | b89df9c | 2004-11-20 03:05:50 +0000 | [diff] [blame] | 64 | } Target; |
Chris Lattner | 1e3822c | 2006-05-03 18:52:31 +0000 | [diff] [blame] | 65 | |
Evan Cheng | 70ba70f | 2008-10-29 23:53:42 +0000 | [diff] [blame] | 66 | unsigned TargetReloType : 6; // The target relocation ID |
| 67 | AddressType AddrType : 4; // The field of Target to use |
Jeffrey Yasskin | 2d27441 | 2009-11-07 08:51:52 +0000 | [diff] [blame] | 68 | bool MayNeedFarStub : 1; // True if this relocation may require a far-stub |
Chris Lattner | 1e3822c | 2006-05-03 18:52:31 +0000 | [diff] [blame] | 69 | bool GOTRelative : 1; // Should this relocation be relative to the GOT? |
Evan Cheng | 70ba70f | 2008-10-29 23:53:42 +0000 | [diff] [blame] | 70 | bool TargetResolve : 1; // True if target should resolve the address |
Andrew Lenharth | 6a6b2db | 2005-07-22 20:46:42 +0000 | [diff] [blame] | 71 | |
Chris Lattner | b89df9c | 2004-11-20 03:05:50 +0000 | [diff] [blame] | 72 | public: |
Nate Begeman | 5381baa | 2006-12-11 02:19:29 +0000 | [diff] [blame] | 73 | // Relocation types used in a generic implementation. Currently, relocation |
| 74 | // entries for all things use the generic VANILLA type until they are refined |
| 75 | // into target relocation types. |
| 76 | enum RelocationType { |
| 77 | VANILLA |
| 78 | }; |
| 79 | |
Chris Lattner | 5a032de | 2006-05-03 20:30:20 +0000 | [diff] [blame] | 80 | /// MachineRelocation::getGV - Return a relocation entry for a GlobalValue. |
| 81 | /// |
Evan Cheng | 5788d1a | 2008-12-10 02:32:19 +0000 | [diff] [blame] | 82 | static MachineRelocation getGV(uintptr_t offset, unsigned RelocationType, |
Chris Lattner | 5a032de | 2006-05-03 20:30:20 +0000 | [diff] [blame] | 83 | GlobalValue *GV, intptr_t cst = 0, |
Jeffrey Yasskin | 2d27441 | 2009-11-07 08:51:52 +0000 | [diff] [blame] | 84 | bool MayNeedFarStub = 0, |
Chris Lattner | 5a032de | 2006-05-03 20:30:20 +0000 | [diff] [blame] | 85 | bool GOTrelative = 0) { |
Chris Lattner | 765da91 | 2004-11-21 03:27:13 +0000 | [diff] [blame] | 86 | assert((RelocationType & ~63) == 0 && "Relocation type too large!"); |
Chris Lattner | 5a032de | 2006-05-03 20:30:20 +0000 | [diff] [blame] | 87 | MachineRelocation Result; |
| 88 | Result.Offset = offset; |
| 89 | Result.ConstantVal = cst; |
| 90 | Result.TargetReloType = RelocationType; |
| 91 | Result.AddrType = isGV; |
Jeffrey Yasskin | 2d27441 | 2009-11-07 08:51:52 +0000 | [diff] [blame] | 92 | Result.MayNeedFarStub = MayNeedFarStub; |
Chris Lattner | 5a032de | 2006-05-03 20:30:20 +0000 | [diff] [blame] | 93 | Result.GOTRelative = GOTrelative; |
Evan Cheng | 70ba70f | 2008-10-29 23:53:42 +0000 | [diff] [blame] | 94 | Result.TargetResolve = false; |
Chris Lattner | 5a032de | 2006-05-03 20:30:20 +0000 | [diff] [blame] | 95 | Result.Target.GV = GV; |
| 96 | return Result; |
Chris Lattner | b89df9c | 2004-11-20 03:05:50 +0000 | [diff] [blame] | 97 | } |
| 98 | |
Evan Cheng | 9ed2f80 | 2008-11-10 01:08:07 +0000 | [diff] [blame] | 99 | /// MachineRelocation::getIndirectSymbol - Return a relocation entry for an |
| 100 | /// indirect symbol. |
Evan Cheng | 5788d1a | 2008-12-10 02:32:19 +0000 | [diff] [blame] | 101 | static MachineRelocation getIndirectSymbol(uintptr_t offset, |
Evan Cheng | 9ed2f80 | 2008-11-10 01:08:07 +0000 | [diff] [blame] | 102 | unsigned RelocationType, |
| 103 | GlobalValue *GV, intptr_t cst = 0, |
Jeffrey Yasskin | 2d27441 | 2009-11-07 08:51:52 +0000 | [diff] [blame] | 104 | bool MayNeedFarStub = 0, |
Evan Cheng | 9ed2f80 | 2008-11-10 01:08:07 +0000 | [diff] [blame] | 105 | bool GOTrelative = 0) { |
Evan Cheng | be8c03f | 2008-01-04 10:46:51 +0000 | [diff] [blame] | 106 | assert((RelocationType & ~63) == 0 && "Relocation type too large!"); |
| 107 | MachineRelocation Result; |
| 108 | Result.Offset = offset; |
| 109 | Result.ConstantVal = cst; |
| 110 | Result.TargetReloType = RelocationType; |
Evan Cheng | 9ed2f80 | 2008-11-10 01:08:07 +0000 | [diff] [blame] | 111 | Result.AddrType = isIndirectSym; |
Jeffrey Yasskin | 2d27441 | 2009-11-07 08:51:52 +0000 | [diff] [blame] | 112 | Result.MayNeedFarStub = MayNeedFarStub; |
Evan Cheng | be8c03f | 2008-01-04 10:46:51 +0000 | [diff] [blame] | 113 | Result.GOTRelative = GOTrelative; |
Evan Cheng | 70ba70f | 2008-10-29 23:53:42 +0000 | [diff] [blame] | 114 | Result.TargetResolve = false; |
Evan Cheng | be8c03f | 2008-01-04 10:46:51 +0000 | [diff] [blame] | 115 | Result.Target.GV = GV; |
| 116 | return Result; |
| 117 | } |
| 118 | |
Evan Cheng | b4e80f8 | 2006-07-27 18:18:13 +0000 | [diff] [blame] | 119 | /// MachineRelocation::getBB - Return a relocation entry for a BB. |
| 120 | /// |
Evan Cheng | 5788d1a | 2008-12-10 02:32:19 +0000 | [diff] [blame] | 121 | static MachineRelocation getBB(uintptr_t offset,unsigned RelocationType, |
Evan Cheng | b4e80f8 | 2006-07-27 18:18:13 +0000 | [diff] [blame] | 122 | MachineBasicBlock *MBB, intptr_t cst = 0) { |
| 123 | assert((RelocationType & ~63) == 0 && "Relocation type too large!"); |
| 124 | MachineRelocation Result; |
| 125 | Result.Offset = offset; |
| 126 | Result.ConstantVal = cst; |
| 127 | Result.TargetReloType = RelocationType; |
| 128 | Result.AddrType = isBB; |
Jeffrey Yasskin | 2d27441 | 2009-11-07 08:51:52 +0000 | [diff] [blame] | 129 | Result.MayNeedFarStub = false; |
Evan Cheng | b4e80f8 | 2006-07-27 18:18:13 +0000 | [diff] [blame] | 130 | Result.GOTRelative = false; |
Evan Cheng | 70ba70f | 2008-10-29 23:53:42 +0000 | [diff] [blame] | 131 | Result.TargetResolve = false; |
Evan Cheng | b4e80f8 | 2006-07-27 18:18:13 +0000 | [diff] [blame] | 132 | Result.Target.MBB = MBB; |
| 133 | return Result; |
| 134 | } |
| 135 | |
Chris Lattner | 5a032de | 2006-05-03 20:30:20 +0000 | [diff] [blame] | 136 | /// MachineRelocation::getExtSym - Return a relocation entry for an external |
| 137 | /// symbol, like "free". |
| 138 | /// |
Evan Cheng | 5788d1a | 2008-12-10 02:32:19 +0000 | [diff] [blame] | 139 | static MachineRelocation getExtSym(uintptr_t offset, unsigned RelocationType, |
Evan Cheng | 652f7ea | 2008-05-30 22:47:19 +0000 | [diff] [blame] | 140 | const char *ES, intptr_t cst = 0, |
Evan Phoenix | 85bb54f | 2010-02-04 19:56:59 +0000 | [diff] [blame] | 141 | bool GOTrelative = 0, |
| 142 | bool NeedStub = true) { |
Chris Lattner | 765da91 | 2004-11-21 03:27:13 +0000 | [diff] [blame] | 143 | assert((RelocationType & ~63) == 0 && "Relocation type too large!"); |
Chris Lattner | 5a032de | 2006-05-03 20:30:20 +0000 | [diff] [blame] | 144 | MachineRelocation Result; |
| 145 | Result.Offset = offset; |
| 146 | Result.ConstantVal = cst; |
| 147 | Result.TargetReloType = RelocationType; |
| 148 | Result.AddrType = isExtSym; |
Evan Phoenix | 85bb54f | 2010-02-04 19:56:59 +0000 | [diff] [blame] | 149 | Result.MayNeedFarStub = NeedStub; |
Chris Lattner | 5a032de | 2006-05-03 20:30:20 +0000 | [diff] [blame] | 150 | Result.GOTRelative = GOTrelative; |
Evan Cheng | 70ba70f | 2008-10-29 23:53:42 +0000 | [diff] [blame] | 151 | Result.TargetResolve = false; |
Evan Cheng | 652f7ea | 2008-05-30 22:47:19 +0000 | [diff] [blame] | 152 | Result.Target.ExtSym = ES; |
Chris Lattner | 5a032de | 2006-05-03 20:30:20 +0000 | [diff] [blame] | 153 | return Result; |
Chris Lattner | b89df9c | 2004-11-20 03:05:50 +0000 | [diff] [blame] | 154 | } |
| 155 | |
Chris Lattner | 5a032de | 2006-05-03 20:30:20 +0000 | [diff] [blame] | 156 | /// MachineRelocation::getConstPool - Return a relocation entry for a constant |
| 157 | /// pool entry. |
| 158 | /// |
Evan Cheng | 5788d1a | 2008-12-10 02:32:19 +0000 | [diff] [blame] | 159 | static MachineRelocation getConstPool(uintptr_t offset,unsigned RelocationType, |
Evan Cheng | 70ba70f | 2008-10-29 23:53:42 +0000 | [diff] [blame] | 160 | unsigned CPI, intptr_t cst = 0, |
| 161 | bool letTargetResolve = false) { |
Andrew Lenharth | 6a6b2db | 2005-07-22 20:46:42 +0000 | [diff] [blame] | 162 | assert((RelocationType & ~63) == 0 && "Relocation type too large!"); |
Chris Lattner | 5a032de | 2006-05-03 20:30:20 +0000 | [diff] [blame] | 163 | MachineRelocation Result; |
| 164 | Result.Offset = offset; |
| 165 | Result.ConstantVal = cst; |
| 166 | Result.TargetReloType = RelocationType; |
| 167 | Result.AddrType = isConstPool; |
Jeffrey Yasskin | 2d27441 | 2009-11-07 08:51:52 +0000 | [diff] [blame] | 168 | Result.MayNeedFarStub = false; |
Chris Lattner | 5a032de | 2006-05-03 20:30:20 +0000 | [diff] [blame] | 169 | Result.GOTRelative = false; |
Evan Cheng | 70ba70f | 2008-10-29 23:53:42 +0000 | [diff] [blame] | 170 | Result.TargetResolve = letTargetResolve; |
Evan Cheng | 52b510b | 2006-06-23 01:02:37 +0000 | [diff] [blame] | 171 | Result.Target.Index = CPI; |
| 172 | return Result; |
| 173 | } |
| 174 | |
| 175 | /// MachineRelocation::getJumpTable - Return a relocation entry for a jump |
| 176 | /// table entry. |
| 177 | /// |
Evan Cheng | 5788d1a | 2008-12-10 02:32:19 +0000 | [diff] [blame] | 178 | static MachineRelocation getJumpTable(uintptr_t offset,unsigned RelocationType, |
Evan Cheng | a27b353 | 2008-11-07 09:01:15 +0000 | [diff] [blame] | 179 | unsigned JTI, intptr_t cst = 0, |
| 180 | bool letTargetResolve = false) { |
Evan Cheng | 52b510b | 2006-06-23 01:02:37 +0000 | [diff] [blame] | 181 | assert((RelocationType & ~63) == 0 && "Relocation type too large!"); |
| 182 | MachineRelocation Result; |
| 183 | Result.Offset = offset; |
| 184 | Result.ConstantVal = cst; |
| 185 | Result.TargetReloType = RelocationType; |
| 186 | Result.AddrType = isJumpTable; |
Jeffrey Yasskin | 2d27441 | 2009-11-07 08:51:52 +0000 | [diff] [blame] | 187 | Result.MayNeedFarStub = false; |
Evan Cheng | 52b510b | 2006-06-23 01:02:37 +0000 | [diff] [blame] | 188 | Result.GOTRelative = false; |
Evan Cheng | a27b353 | 2008-11-07 09:01:15 +0000 | [diff] [blame] | 189 | Result.TargetResolve = letTargetResolve; |
Evan Cheng | 52b510b | 2006-06-23 01:02:37 +0000 | [diff] [blame] | 190 | Result.Target.Index = JTI; |
Chris Lattner | 5a032de | 2006-05-03 20:30:20 +0000 | [diff] [blame] | 191 | return Result; |
Andrew Lenharth | 6a6b2db | 2005-07-22 20:46:42 +0000 | [diff] [blame] | 192 | } |
| 193 | |
Chris Lattner | b89df9c | 2004-11-20 03:05:50 +0000 | [diff] [blame] | 194 | /// getMachineCodeOffset - Return the offset into the code buffer that the |
| 195 | /// relocation should be performed. |
Chris Lattner | 5a032de | 2006-05-03 20:30:20 +0000 | [diff] [blame] | 196 | intptr_t getMachineCodeOffset() const { |
Chris Lattner | 1e3822c | 2006-05-03 18:52:31 +0000 | [diff] [blame] | 197 | return Offset; |
Chris Lattner | b89df9c | 2004-11-20 03:05:50 +0000 | [diff] [blame] | 198 | } |
| 199 | |
Chris Lattner | fab11a7 | 2004-11-20 03:43:50 +0000 | [diff] [blame] | 200 | /// getRelocationType - Return the target-specific relocation ID for this |
| 201 | /// relocation. |
| 202 | unsigned getRelocationType() const { |
Chris Lattner | 1e3822c | 2006-05-03 18:52:31 +0000 | [diff] [blame] | 203 | return TargetReloType; |
Chris Lattner | fab11a7 | 2004-11-20 03:43:50 +0000 | [diff] [blame] | 204 | } |
| 205 | |
Chris Lattner | b89df9c | 2004-11-20 03:05:50 +0000 | [diff] [blame] | 206 | /// getConstantVal - Get the constant value associated with this relocation. |
| 207 | /// This is often an offset from the symbol. |
| 208 | /// |
| 209 | intptr_t getConstantVal() const { |
| 210 | return ConstantVal; |
| 211 | } |
| 212 | |
Nate Begeman | 5381baa | 2006-12-11 02:19:29 +0000 | [diff] [blame] | 213 | /// setConstantVal - Set the constant value associated with this relocation. |
| 214 | /// This is often an offset from the symbol. |
| 215 | /// |
| 216 | void setConstantVal(intptr_t val) { |
| 217 | ConstantVal = val; |
| 218 | } |
| 219 | |
Chris Lattner | b89df9c | 2004-11-20 03:05:50 +0000 | [diff] [blame] | 220 | /// isGlobalValue - Return true if this relocation is a GlobalValue, as |
| 221 | /// opposed to a constant string. |
| 222 | bool isGlobalValue() const { |
Chris Lattner | 1e3822c | 2006-05-03 18:52:31 +0000 | [diff] [blame] | 223 | return AddrType == isGV; |
Chris Lattner | b89df9c | 2004-11-20 03:05:50 +0000 | [diff] [blame] | 224 | } |
| 225 | |
Evan Cheng | 9ed2f80 | 2008-11-10 01:08:07 +0000 | [diff] [blame] | 226 | /// isIndirectSymbol - Return true if this relocation is the address an |
| 227 | /// indirect symbol |
| 228 | bool isIndirectSymbol() const { |
| 229 | return AddrType == isIndirectSym; |
Evan Cheng | be8c03f | 2008-01-04 10:46:51 +0000 | [diff] [blame] | 230 | } |
| 231 | |
Evan Cheng | b4e80f8 | 2006-07-27 18:18:13 +0000 | [diff] [blame] | 232 | /// isBasicBlock - Return true if this relocation is a basic block reference. |
| 233 | /// |
| 234 | bool isBasicBlock() const { |
| 235 | return AddrType == isBB; |
| 236 | } |
| 237 | |
Evan Cheng | d7398c9 | 2008-11-08 07:37:34 +0000 | [diff] [blame] | 238 | /// isExternalSymbol - Return true if this is a constant string. |
Chris Lattner | b89df9c | 2004-11-20 03:05:50 +0000 | [diff] [blame] | 239 | /// |
Evan Cheng | d7398c9 | 2008-11-08 07:37:34 +0000 | [diff] [blame] | 240 | bool isExternalSymbol() const { |
Chris Lattner | 1e3822c | 2006-05-03 18:52:31 +0000 | [diff] [blame] | 241 | return AddrType == isExtSym; |
Andrew Lenharth | 6a6b2db | 2005-07-22 20:46:42 +0000 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | /// isConstantPoolIndex - Return true if this is a constant pool reference. |
| 245 | /// |
| 246 | bool isConstantPoolIndex() const { |
Chris Lattner | 1e3822c | 2006-05-03 18:52:31 +0000 | [diff] [blame] | 247 | return AddrType == isConstPool; |
Andrew Lenharth | 6a6b2db | 2005-07-22 20:46:42 +0000 | [diff] [blame] | 248 | } |
| 249 | |
Evan Cheng | 52b510b | 2006-06-23 01:02:37 +0000 | [diff] [blame] | 250 | /// isJumpTableIndex - Return true if this is a jump table reference. |
| 251 | /// |
| 252 | bool isJumpTableIndex() const { |
| 253 | return AddrType == isJumpTable; |
| 254 | } |
| 255 | |
Andrew Lenharth | 6a6b2db | 2005-07-22 20:46:42 +0000 | [diff] [blame] | 256 | /// isGOTRelative - Return true the target wants the index into the GOT of |
| 257 | /// the symbol rather than the address of the symbol. |
| 258 | bool isGOTRelative() const { |
| 259 | return GOTRelative; |
Chris Lattner | b89df9c | 2004-11-20 03:05:50 +0000 | [diff] [blame] | 260 | } |
| 261 | |
Jeffrey Yasskin | 2d27441 | 2009-11-07 08:51:52 +0000 | [diff] [blame] | 262 | /// mayNeedFarStub - This function returns true if the JIT for this target may |
| 263 | /// need either a stub function or an indirect global-variable load to handle |
| 264 | /// the relocated GlobalValue reference. For example, the x86-64 call |
| 265 | /// instruction can only call functions within +/-2GB of the call site. |
| 266 | /// Anything farther away needs a longer mov+call sequence, which can't just |
| 267 | /// be written on top of the existing call. |
| 268 | bool mayNeedFarStub() const { |
| 269 | return MayNeedFarStub; |
Chris Lattner | 765da91 | 2004-11-21 03:27:13 +0000 | [diff] [blame] | 270 | } |
| 271 | |
Evan Cheng | 70ba70f | 2008-10-29 23:53:42 +0000 | [diff] [blame] | 272 | /// letTargetResolve - Return true if the target JITInfo is usually |
| 273 | /// responsible for resolving the address of this relocation. |
| 274 | bool letTargetResolve() const { |
| 275 | return TargetResolve; |
| 276 | } |
| 277 | |
Chris Lattner | b89df9c | 2004-11-20 03:05:50 +0000 | [diff] [blame] | 278 | /// getGlobalValue - If this is a global value reference, return the |
| 279 | /// referenced global. |
| 280 | GlobalValue *getGlobalValue() const { |
Evan Cheng | 9ed2f80 | 2008-11-10 01:08:07 +0000 | [diff] [blame] | 281 | assert((isGlobalValue() || isIndirectSymbol()) && |
Evan Cheng | be8c03f | 2008-01-04 10:46:51 +0000 | [diff] [blame] | 282 | "This is not a global value reference!"); |
Chris Lattner | b89df9c | 2004-11-20 03:05:50 +0000 | [diff] [blame] | 283 | return Target.GV; |
| 284 | } |
| 285 | |
Evan Cheng | b4e80f8 | 2006-07-27 18:18:13 +0000 | [diff] [blame] | 286 | MachineBasicBlock *getBasicBlock() const { |
| 287 | assert(isBasicBlock() && "This is not a basic block reference!"); |
| 288 | return Target.MBB; |
| 289 | } |
| 290 | |
Chris Lattner | b89df9c | 2004-11-20 03:05:50 +0000 | [diff] [blame] | 291 | /// getString - If this is a string value, return the string reference. |
| 292 | /// |
Evan Cheng | d7398c9 | 2008-11-08 07:37:34 +0000 | [diff] [blame] | 293 | const char *getExternalSymbol() const { |
| 294 | assert(isExternalSymbol() && "This is not an external symbol reference!"); |
Chris Lattner | b89df9c | 2004-11-20 03:05:50 +0000 | [diff] [blame] | 295 | return Target.ExtSym; |
| 296 | } |
| 297 | |
Andrew Lenharth | 6a6b2db | 2005-07-22 20:46:42 +0000 | [diff] [blame] | 298 | /// getConstantPoolIndex - If this is a const pool reference, return |
| 299 | /// the index into the constant pool. |
| 300 | unsigned getConstantPoolIndex() const { |
| 301 | assert(isConstantPoolIndex() && "This is not a constant pool reference!"); |
Evan Cheng | 52b510b | 2006-06-23 01:02:37 +0000 | [diff] [blame] | 302 | return Target.Index; |
| 303 | } |
| 304 | |
| 305 | /// getJumpTableIndex - If this is a jump table reference, return |
| 306 | /// the index into the jump table. |
| 307 | unsigned getJumpTableIndex() const { |
| 308 | assert(isJumpTableIndex() && "This is not a jump table reference!"); |
| 309 | return Target.Index; |
Andrew Lenharth | 6a6b2db | 2005-07-22 20:46:42 +0000 | [diff] [blame] | 310 | } |
| 311 | |
Chris Lattner | b89df9c | 2004-11-20 03:05:50 +0000 | [diff] [blame] | 312 | /// getResultPointer - Once this has been resolved to point to an actual |
| 313 | /// address, this returns the pointer. |
| 314 | void *getResultPointer() const { |
Chris Lattner | 1e3822c | 2006-05-03 18:52:31 +0000 | [diff] [blame] | 315 | assert(AddrType == isResult && "Result pointer isn't set yet!"); |
Chris Lattner | b89df9c | 2004-11-20 03:05:50 +0000 | [diff] [blame] | 316 | return Target.Result; |
| 317 | } |
| 318 | |
| 319 | /// setResultPointer - Set the result to the specified pointer value. |
| 320 | /// |
| 321 | void setResultPointer(void *Ptr) { |
| 322 | Target.Result = Ptr; |
Chris Lattner | 1e3822c | 2006-05-03 18:52:31 +0000 | [diff] [blame] | 323 | AddrType = isResult; |
Chris Lattner | b89df9c | 2004-11-20 03:05:50 +0000 | [diff] [blame] | 324 | } |
Andrew Lenharth | 6a6b2db | 2005-07-22 20:46:42 +0000 | [diff] [blame] | 325 | |
| 326 | /// setGOTIndex - Set the GOT index to a specific value. |
| 327 | void setGOTIndex(unsigned idx) { |
Chris Lattner | 1e3822c | 2006-05-03 18:52:31 +0000 | [diff] [blame] | 328 | AddrType = isGOTIndex; |
Andrew Lenharth | 6a6b2db | 2005-07-22 20:46:42 +0000 | [diff] [blame] | 329 | Target.GOTIndex = idx; |
| 330 | } |
| 331 | |
| 332 | /// getGOTIndex - Once this has been resolved to an entry in the GOT, |
Jeff Cohen | 9eb59ec | 2005-07-27 05:53:44 +0000 | [diff] [blame] | 333 | /// this returns that index. The index is from the lowest address entry |
Andrew Lenharth | 6a6b2db | 2005-07-22 20:46:42 +0000 | [diff] [blame] | 334 | /// in the GOT. |
| 335 | unsigned getGOTIndex() const { |
Chris Lattner | 1e3822c | 2006-05-03 18:52:31 +0000 | [diff] [blame] | 336 | assert(AddrType == isGOTIndex); |
Andrew Lenharth | 6a6b2db | 2005-07-22 20:46:42 +0000 | [diff] [blame] | 337 | return Target.GOTIndex; |
| 338 | } |
Chris Lattner | b89df9c | 2004-11-20 03:05:50 +0000 | [diff] [blame] | 339 | }; |
Chris Lattner | b89df9c | 2004-11-20 03:05:50 +0000 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | #endif |