Daniel Dunbar | 115e4d6 | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 1 | //===- MCExpr.cpp - Assembly Level Expression Implementation --------------===// |
Daniel Dunbar | 84bfd7b | 2009-06-29 20:40:36 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Daniel Dunbar | 115e4d6 | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 10 | #include "llvm/MC/MCExpr.h" |
Daniel Dunbar | 5376c2a | 2010-03-23 23:47:14 +0000 | [diff] [blame] | 11 | #include "llvm/ADT/Statistic.h" |
Daniel Dunbar | 5599256 | 2010-03-15 23:51:06 +0000 | [diff] [blame] | 12 | #include "llvm/ADT/StringSwitch.h" |
David Peixotto | 8ad70b3 | 2013-12-04 22:43:20 +0000 | [diff] [blame] | 13 | #include "llvm/MC/MCAsmInfo.h" |
Daniel Dunbar | 5c5228a | 2010-03-11 05:53:37 +0000 | [diff] [blame] | 14 | #include "llvm/MC/MCAsmLayout.h" |
| 15 | #include "llvm/MC/MCAssembler.h" |
Daniel Dunbar | 84bfd7b | 2009-06-29 20:40:36 +0000 | [diff] [blame] | 16 | #include "llvm/MC/MCContext.h" |
Craig Topper | 6e80c28 | 2012-03-26 06:58:25 +0000 | [diff] [blame] | 17 | #include "llvm/MC/MCObjectWriter.h" |
Daniel Dunbar | bd4bf3d | 2009-06-30 01:49:52 +0000 | [diff] [blame] | 18 | #include "llvm/MC/MCSymbol.h" |
Daniel Dunbar | 84bfd7b | 2009-06-29 20:40:36 +0000 | [diff] [blame] | 19 | #include "llvm/MC/MCValue.h" |
David Greene | a8cbfb8 | 2010-01-05 01:28:07 +0000 | [diff] [blame] | 20 | #include "llvm/Support/Debug.h" |
Chandler Carruth | f3e8502 | 2012-01-10 18:08:01 +0000 | [diff] [blame] | 21 | #include "llvm/Support/ErrorHandling.h" |
Daniel Dunbar | b34a2b9 | 2009-08-31 08:07:33 +0000 | [diff] [blame] | 22 | #include "llvm/Support/raw_ostream.h" |
Daniel Dunbar | 84bfd7b | 2009-06-29 20:40:36 +0000 | [diff] [blame] | 23 | using namespace llvm; |
| 24 | |
Chandler Carruth | f58e376 | 2014-04-22 03:04:17 +0000 | [diff] [blame] | 25 | #define DEBUG_TYPE "mcexpr" |
| 26 | |
Daniel Dunbar | 5376c2a | 2010-03-23 23:47:14 +0000 | [diff] [blame] | 27 | namespace { |
| 28 | namespace stats { |
| 29 | STATISTIC(MCExprEvaluate, "Number of MCExpr evaluations"); |
| 30 | } |
| 31 | } |
| 32 | |
Matt Arsenault | 8b64355 | 2015-06-09 00:31:39 +0000 | [diff] [blame] | 33 | void MCExpr::print(raw_ostream &OS, const MCAsmInfo *MAI) const { |
Daniel Dunbar | b34a2b9 | 2009-08-31 08:07:33 +0000 | [diff] [blame] | 34 | switch (getKind()) { |
Chris Lattner | 38d022e | 2010-02-08 19:41:07 +0000 | [diff] [blame] | 35 | case MCExpr::Target: |
Matt Arsenault | 8b64355 | 2015-06-09 00:31:39 +0000 | [diff] [blame] | 36 | return cast<MCTargetExpr>(this)->printImpl(OS, MAI); |
Daniel Dunbar | b34a2b9 | 2009-08-31 08:07:33 +0000 | [diff] [blame] | 37 | case MCExpr::Constant: |
| 38 | OS << cast<MCConstantExpr>(*this).getValue(); |
| 39 | return; |
| 40 | |
Chris Lattner | 22833a3 | 2009-09-08 23:20:50 +0000 | [diff] [blame] | 41 | case MCExpr::SymbolRef: { |
Daniel Dunbar | 5599256 | 2010-03-15 23:51:06 +0000 | [diff] [blame] | 42 | const MCSymbolRefExpr &SRE = cast<MCSymbolRefExpr>(*this); |
| 43 | const MCSymbol &Sym = SRE.getSymbol(); |
Chris Lattner | edb9d84 | 2010-11-15 02:46:57 +0000 | [diff] [blame] | 44 | // Parenthesize names that start with $ so that they don't look like |
| 45 | // absolute names. |
Matt Arsenault | 8b64355 | 2015-06-09 00:31:39 +0000 | [diff] [blame] | 46 | bool UseParens = Sym.getName()[0] == '$'; |
| 47 | if (UseParens) { |
| 48 | OS << '('; |
| 49 | Sym.print(OS, MAI); |
| 50 | OS << ')'; |
| 51 | } else |
| 52 | Sym.print(OS, MAI); |
Daniel Dunbar | 5599256 | 2010-03-15 23:51:06 +0000 | [diff] [blame] | 53 | |
Benjamin Kramer | dd13643 | 2014-10-11 17:57:27 +0000 | [diff] [blame] | 54 | if (SRE.getKind() != MCSymbolRefExpr::VK_None) |
| 55 | SRE.printVariantKind(OS); |
Daniel Dunbar | 5599256 | 2010-03-15 23:51:06 +0000 | [diff] [blame] | 56 | |
Daniel Dunbar | b34a2b9 | 2009-08-31 08:07:33 +0000 | [diff] [blame] | 57 | return; |
Chris Lattner | 22833a3 | 2009-09-08 23:20:50 +0000 | [diff] [blame] | 58 | } |
Daniel Dunbar | b34a2b9 | 2009-08-31 08:07:33 +0000 | [diff] [blame] | 59 | |
| 60 | case MCExpr::Unary: { |
| 61 | const MCUnaryExpr &UE = cast<MCUnaryExpr>(*this); |
| 62 | switch (UE.getOpcode()) { |
Daniel Dunbar | b34a2b9 | 2009-08-31 08:07:33 +0000 | [diff] [blame] | 63 | case MCUnaryExpr::LNot: OS << '!'; break; |
| 64 | case MCUnaryExpr::Minus: OS << '-'; break; |
| 65 | case MCUnaryExpr::Not: OS << '~'; break; |
| 66 | case MCUnaryExpr::Plus: OS << '+'; break; |
| 67 | } |
Matt Arsenault | 8b64355 | 2015-06-09 00:31:39 +0000 | [diff] [blame] | 68 | UE.getSubExpr()->print(OS, MAI); |
Daniel Dunbar | b34a2b9 | 2009-08-31 08:07:33 +0000 | [diff] [blame] | 69 | return; |
| 70 | } |
| 71 | |
| 72 | case MCExpr::Binary: { |
| 73 | const MCBinaryExpr &BE = cast<MCBinaryExpr>(*this); |
Daniel Dunbar | 9c64ec0 | 2010-03-18 00:59:10 +0000 | [diff] [blame] | 74 | |
Chris Lattner | 3cfc551 | 2009-09-08 06:34:07 +0000 | [diff] [blame] | 75 | // Only print parens around the LHS if it is non-trivial. |
| 76 | if (isa<MCConstantExpr>(BE.getLHS()) || isa<MCSymbolRefExpr>(BE.getLHS())) { |
Matt Arsenault | 8b64355 | 2015-06-09 00:31:39 +0000 | [diff] [blame] | 77 | BE.getLHS()->print(OS, MAI); |
Chris Lattner | 3cfc551 | 2009-09-08 06:34:07 +0000 | [diff] [blame] | 78 | } else { |
Matt Arsenault | 8b64355 | 2015-06-09 00:31:39 +0000 | [diff] [blame] | 79 | OS << '('; |
| 80 | BE.getLHS()->print(OS, MAI); |
| 81 | OS << ')'; |
Chris Lattner | 3cfc551 | 2009-09-08 06:34:07 +0000 | [diff] [blame] | 82 | } |
Daniel Dunbar | 9c64ec0 | 2010-03-18 00:59:10 +0000 | [diff] [blame] | 83 | |
Daniel Dunbar | b34a2b9 | 2009-08-31 08:07:33 +0000 | [diff] [blame] | 84 | switch (BE.getOpcode()) { |
Chris Lattner | 7975b8f | 2009-09-08 06:37:35 +0000 | [diff] [blame] | 85 | case MCBinaryExpr::Add: |
| 86 | // Print "X-42" instead of "X+-42". |
| 87 | if (const MCConstantExpr *RHSC = dyn_cast<MCConstantExpr>(BE.getRHS())) { |
| 88 | if (RHSC->getValue() < 0) { |
| 89 | OS << RHSC->getValue(); |
| 90 | return; |
| 91 | } |
| 92 | } |
Daniel Dunbar | 9c64ec0 | 2010-03-18 00:59:10 +0000 | [diff] [blame] | 93 | |
Chris Lattner | 7975b8f | 2009-09-08 06:37:35 +0000 | [diff] [blame] | 94 | OS << '+'; |
| 95 | break; |
Ahmed Bougacha | 177c148 | 2015-04-28 00:21:32 +0000 | [diff] [blame] | 96 | case MCBinaryExpr::AShr: OS << ">>"; break; |
Daniel Dunbar | b34a2b9 | 2009-08-31 08:07:33 +0000 | [diff] [blame] | 97 | case MCBinaryExpr::And: OS << '&'; break; |
| 98 | case MCBinaryExpr::Div: OS << '/'; break; |
| 99 | case MCBinaryExpr::EQ: OS << "=="; break; |
| 100 | case MCBinaryExpr::GT: OS << '>'; break; |
| 101 | case MCBinaryExpr::GTE: OS << ">="; break; |
| 102 | case MCBinaryExpr::LAnd: OS << "&&"; break; |
| 103 | case MCBinaryExpr::LOr: OS << "||"; break; |
Ahmed Bougacha | 177c148 | 2015-04-28 00:21:32 +0000 | [diff] [blame] | 104 | case MCBinaryExpr::LShr: OS << ">>"; break; |
Daniel Dunbar | b34a2b9 | 2009-08-31 08:07:33 +0000 | [diff] [blame] | 105 | case MCBinaryExpr::LT: OS << '<'; break; |
| 106 | case MCBinaryExpr::LTE: OS << "<="; break; |
| 107 | case MCBinaryExpr::Mod: OS << '%'; break; |
| 108 | case MCBinaryExpr::Mul: OS << '*'; break; |
| 109 | case MCBinaryExpr::NE: OS << "!="; break; |
| 110 | case MCBinaryExpr::Or: OS << '|'; break; |
| 111 | case MCBinaryExpr::Shl: OS << "<<"; break; |
Daniel Dunbar | b34a2b9 | 2009-08-31 08:07:33 +0000 | [diff] [blame] | 112 | case MCBinaryExpr::Sub: OS << '-'; break; |
| 113 | case MCBinaryExpr::Xor: OS << '^'; break; |
| 114 | } |
Daniel Dunbar | 9c64ec0 | 2010-03-18 00:59:10 +0000 | [diff] [blame] | 115 | |
Chris Lattner | 3cfc551 | 2009-09-08 06:34:07 +0000 | [diff] [blame] | 116 | // Only print parens around the LHS if it is non-trivial. |
| 117 | if (isa<MCConstantExpr>(BE.getRHS()) || isa<MCSymbolRefExpr>(BE.getRHS())) { |
Matt Arsenault | 8b64355 | 2015-06-09 00:31:39 +0000 | [diff] [blame] | 118 | BE.getRHS()->print(OS, MAI); |
Chris Lattner | 3cfc551 | 2009-09-08 06:34:07 +0000 | [diff] [blame] | 119 | } else { |
Matt Arsenault | 8b64355 | 2015-06-09 00:31:39 +0000 | [diff] [blame] | 120 | OS << '('; |
| 121 | BE.getRHS()->print(OS, MAI); |
| 122 | OS << ')'; |
Chris Lattner | 3cfc551 | 2009-09-08 06:34:07 +0000 | [diff] [blame] | 123 | } |
Daniel Dunbar | b34a2b9 | 2009-08-31 08:07:33 +0000 | [diff] [blame] | 124 | return; |
| 125 | } |
| 126 | } |
| 127 | |
Craig Topper | a2886c2 | 2012-02-07 05:05:23 +0000 | [diff] [blame] | 128 | llvm_unreachable("Invalid expression kind!"); |
Daniel Dunbar | b34a2b9 | 2009-08-31 08:07:33 +0000 | [diff] [blame] | 129 | } |
| 130 | |
Manman Ren | 49d684e | 2012-09-12 05:06:18 +0000 | [diff] [blame] | 131 | #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) |
Daniel Dunbar | b34a2b9 | 2009-08-31 08:07:33 +0000 | [diff] [blame] | 132 | void MCExpr::dump() const { |
Rafael Espindola | f4a1365 | 2015-05-27 13:05:42 +0000 | [diff] [blame] | 133 | dbgs() << *this; |
David Greene | a8cbfb8 | 2010-01-05 01:28:07 +0000 | [diff] [blame] | 134 | dbgs() << '\n'; |
Daniel Dunbar | b34a2b9 | 2009-08-31 08:07:33 +0000 | [diff] [blame] | 135 | } |
Manman Ren | c3366cc | 2012-09-06 19:55:56 +0000 | [diff] [blame] | 136 | #endif |
Daniel Dunbar | b34a2b9 | 2009-08-31 08:07:33 +0000 | [diff] [blame] | 137 | |
| 138 | /* *** */ |
| 139 | |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 140 | const MCBinaryExpr *MCBinaryExpr::create(Opcode Opc, const MCExpr *LHS, |
Chris Lattner | a0020be | 2009-09-08 06:27:48 +0000 | [diff] [blame] | 141 | const MCExpr *RHS, MCContext &Ctx) { |
Daniel Dunbar | f363645 | 2009-08-31 08:07:22 +0000 | [diff] [blame] | 142 | return new (Ctx) MCBinaryExpr(Opc, LHS, RHS); |
Daniel Dunbar | 84bfd7b | 2009-06-29 20:40:36 +0000 | [diff] [blame] | 143 | } |
| 144 | |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 145 | const MCUnaryExpr *MCUnaryExpr::create(Opcode Opc, const MCExpr *Expr, |
Chris Lattner | a0020be | 2009-09-08 06:27:48 +0000 | [diff] [blame] | 146 | MCContext &Ctx) { |
Daniel Dunbar | f363645 | 2009-08-31 08:07:22 +0000 | [diff] [blame] | 147 | return new (Ctx) MCUnaryExpr(Opc, Expr); |
| 148 | } |
| 149 | |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 150 | const MCConstantExpr *MCConstantExpr::create(int64_t Value, MCContext &Ctx) { |
Daniel Dunbar | f363645 | 2009-08-31 08:07:22 +0000 | [diff] [blame] | 151 | return new (Ctx) MCConstantExpr(Value); |
| 152 | } |
| 153 | |
Daniel Dunbar | 5599256 | 2010-03-15 23:51:06 +0000 | [diff] [blame] | 154 | /* *** */ |
| 155 | |
Benjamin Kramer | dd13643 | 2014-10-11 17:57:27 +0000 | [diff] [blame] | 156 | MCSymbolRefExpr::MCSymbolRefExpr(const MCSymbol *Symbol, VariantKind Kind, |
| 157 | const MCAsmInfo *MAI) |
| 158 | : MCExpr(MCExpr::SymbolRef), Kind(Kind), |
| 159 | UseParensForSymbolVariant(MAI->useParensForSymbolVariant()), |
| 160 | HasSubsectionsViaSymbols(MAI->hasSubsectionsViaSymbols()), |
| 161 | Symbol(Symbol) { |
| 162 | assert(Symbol); |
| 163 | } |
| 164 | |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 165 | const MCSymbolRefExpr *MCSymbolRefExpr::create(const MCSymbol *Sym, |
Daniel Dunbar | 5599256 | 2010-03-15 23:51:06 +0000 | [diff] [blame] | 166 | VariantKind Kind, |
Daniel Dunbar | f363645 | 2009-08-31 08:07:22 +0000 | [diff] [blame] | 167 | MCContext &Ctx) { |
David Peixotto | 8ad70b3 | 2013-12-04 22:43:20 +0000 | [diff] [blame] | 168 | return new (Ctx) MCSymbolRefExpr(Sym, Kind, Ctx.getAsmInfo()); |
Daniel Dunbar | f363645 | 2009-08-31 08:07:22 +0000 | [diff] [blame] | 169 | } |
| 170 | |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 171 | const MCSymbolRefExpr *MCSymbolRefExpr::create(StringRef Name, VariantKind Kind, |
Daniel Dunbar | 5599256 | 2010-03-15 23:51:06 +0000 | [diff] [blame] | 172 | MCContext &Ctx) { |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 173 | return create(Ctx.getOrCreateSymbol(Name), Kind, Ctx); |
Chris Lattner | 6a833f6 | 2009-09-16 01:26:31 +0000 | [diff] [blame] | 174 | } |
| 175 | |
Daniel Dunbar | 5599256 | 2010-03-15 23:51:06 +0000 | [diff] [blame] | 176 | StringRef MCSymbolRefExpr::getVariantKindName(VariantKind Kind) { |
| 177 | switch (Kind) { |
Daniel Dunbar | 5599256 | 2010-03-15 23:51:06 +0000 | [diff] [blame] | 178 | case VK_Invalid: return "<<invalid>>"; |
| 179 | case VK_None: return "<<none>>"; |
| 180 | |
| 181 | case VK_GOT: return "GOT"; |
| 182 | case VK_GOTOFF: return "GOTOFF"; |
| 183 | case VK_GOTPCREL: return "GOTPCREL"; |
| 184 | case VK_GOTTPOFF: return "GOTTPOFF"; |
| 185 | case VK_INDNTPOFF: return "INDNTPOFF"; |
| 186 | case VK_NTPOFF: return "NTPOFF"; |
Rafael Espindola | b3b49bb | 2010-10-28 14:22:44 +0000 | [diff] [blame] | 187 | case VK_GOTNTPOFF: return "GOTNTPOFF"; |
Daniel Dunbar | 5599256 | 2010-03-15 23:51:06 +0000 | [diff] [blame] | 188 | case VK_PLT: return "PLT"; |
| 189 | case VK_TLSGD: return "TLSGD"; |
Rafael Espindola | 2dbec3f | 2010-10-28 15:02:40 +0000 | [diff] [blame] | 190 | case VK_TLSLD: return "TLSLD"; |
Rafael Espindola | 6f23eb3 | 2010-10-28 14:37:09 +0000 | [diff] [blame] | 191 | case VK_TLSLDM: return "TLSLDM"; |
Daniel Dunbar | 5599256 | 2010-03-15 23:51:06 +0000 | [diff] [blame] | 192 | case VK_TPOFF: return "TPOFF"; |
Rafael Espindola | e8f08be | 2010-10-28 14:48:59 +0000 | [diff] [blame] | 193 | case VK_DTPOFF: return "DTPOFF"; |
Chris Lattner | 94f0c14 | 2010-11-14 22:22:59 +0000 | [diff] [blame] | 194 | case VK_TLVP: return "TLVP"; |
Tim Northover | 00ed996 | 2014-03-29 10:18:08 +0000 | [diff] [blame] | 195 | case VK_TLVPPAGE: return "TLVPPAGE"; |
| 196 | case VK_TLVPPAGEOFF: return "TLVPPAGEOFF"; |
| 197 | case VK_PAGE: return "PAGE"; |
| 198 | case VK_PAGEOFF: return "PAGEOFF"; |
| 199 | case VK_GOTPAGE: return "GOTPAGE"; |
| 200 | case VK_GOTPAGEOFF: return "GOTPAGEOFF"; |
Benjamin Kramer | 9c9e0a2 | 2013-03-30 16:21:50 +0000 | [diff] [blame] | 201 | case VK_SECREL: return "SECREL32"; |
Davide Italiano | fcae934 | 2015-03-04 06:49:39 +0000 | [diff] [blame] | 202 | case VK_SIZE: return "SIZE"; |
Rafael Espindola | 7fadc0e | 2014-03-20 02:12:01 +0000 | [diff] [blame] | 203 | case VK_WEAKREF: return "WEAKREF"; |
David Peixotto | 8ad70b3 | 2013-12-04 22:43:20 +0000 | [diff] [blame] | 204 | case VK_ARM_NONE: return "none"; |
| 205 | case VK_ARM_TARGET1: return "target1"; |
| 206 | case VK_ARM_TARGET2: return "target2"; |
| 207 | case VK_ARM_PREL31: return "prel31"; |
Saleem Abdulrasool | fe78197 | 2015-01-11 04:39:18 +0000 | [diff] [blame] | 208 | case VK_ARM_SBREL: return "sbrel"; |
Kai Nacke | e51c813 | 2014-01-20 11:00:40 +0000 | [diff] [blame] | 209 | case VK_ARM_TLSLDO: return "tlsldo"; |
Saleem Abdulrasool | 6e00ca8 | 2014-01-30 04:02:31 +0000 | [diff] [blame] | 210 | case VK_ARM_TLSCALL: return "tlscall"; |
Saleem Abdulrasool | a3f12bd | 2014-01-30 04:02:38 +0000 | [diff] [blame] | 211 | case VK_ARM_TLSDESC: return "tlsdesc"; |
Saleem Abdulrasool | 56e06e8 | 2014-01-30 04:02:47 +0000 | [diff] [blame] | 212 | case VK_ARM_TLSDESCSEQ: return "tlsdescseq"; |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 213 | case VK_PPC_LO: return "l"; |
Ulrich Weigand | e67c565 | 2013-06-21 14:42:49 +0000 | [diff] [blame] | 214 | case VK_PPC_HI: return "h"; |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 215 | case VK_PPC_HA: return "ha"; |
Ulrich Weigand | e9126f5 | 2013-06-21 14:43:42 +0000 | [diff] [blame] | 216 | case VK_PPC_HIGHER: return "higher"; |
| 217 | case VK_PPC_HIGHERA: return "highera"; |
| 218 | case VK_PPC_HIGHEST: return "highest"; |
| 219 | case VK_PPC_HIGHESTA: return "highesta"; |
Ulrich Weigand | 93372b4 | 2013-06-25 16:49:50 +0000 | [diff] [blame] | 220 | case VK_PPC_GOT_LO: return "got@l"; |
| 221 | case VK_PPC_GOT_HI: return "got@h"; |
| 222 | case VK_PPC_GOT_HA: return "got@ha"; |
Ulrich Weigand | 68e2e1b | 2013-06-20 22:39:42 +0000 | [diff] [blame] | 223 | case VK_PPC_TOCBASE: return "tocbase"; |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 224 | case VK_PPC_TOC: return "toc"; |
| 225 | case VK_PPC_TOC_LO: return "toc@l"; |
Ulrich Weigand | 72ddbd6 | 2013-06-21 14:43:10 +0000 | [diff] [blame] | 226 | case VK_PPC_TOC_HI: return "toc@h"; |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 227 | case VK_PPC_TOC_HA: return "toc@ha"; |
Ulrich Weigand | f11efe7 | 2013-07-01 23:33:29 +0000 | [diff] [blame] | 228 | case VK_PPC_DTPMOD: return "dtpmod"; |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 229 | case VK_PPC_TPREL: return "tprel"; |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 230 | case VK_PPC_TPREL_LO: return "tprel@l"; |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 231 | case VK_PPC_TPREL_HI: return "tprel@h"; |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 232 | case VK_PPC_TPREL_HA: return "tprel@ha"; |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 233 | case VK_PPC_TPREL_HIGHER: return "tprel@higher"; |
| 234 | case VK_PPC_TPREL_HIGHERA: return "tprel@highera"; |
| 235 | case VK_PPC_TPREL_HIGHEST: return "tprel@highest"; |
| 236 | case VK_PPC_TPREL_HIGHESTA: return "tprel@highesta"; |
| 237 | case VK_PPC_DTPREL: return "dtprel"; |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 238 | case VK_PPC_DTPREL_LO: return "dtprel@l"; |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 239 | case VK_PPC_DTPREL_HI: return "dtprel@h"; |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 240 | case VK_PPC_DTPREL_HA: return "dtprel@ha"; |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 241 | case VK_PPC_DTPREL_HIGHER: return "dtprel@higher"; |
| 242 | case VK_PPC_DTPREL_HIGHERA: return "dtprel@highera"; |
| 243 | case VK_PPC_DTPREL_HIGHEST: return "dtprel@highest"; |
| 244 | case VK_PPC_DTPREL_HIGHESTA: return "dtprel@highesta"; |
| 245 | case VK_PPC_GOT_TPREL: return "got@tprel"; |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 246 | case VK_PPC_GOT_TPREL_LO: return "got@tprel@l"; |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 247 | case VK_PPC_GOT_TPREL_HI: return "got@tprel@h"; |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 248 | case VK_PPC_GOT_TPREL_HA: return "got@tprel@ha"; |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 249 | case VK_PPC_GOT_DTPREL: return "got@dtprel"; |
| 250 | case VK_PPC_GOT_DTPREL_LO: return "got@dtprel@l"; |
| 251 | case VK_PPC_GOT_DTPREL_HI: return "got@dtprel@h"; |
| 252 | case VK_PPC_GOT_DTPREL_HA: return "got@dtprel@ha"; |
Bill Schmidt | ca4a0c9 | 2012-12-04 16:18:08 +0000 | [diff] [blame] | 253 | case VK_PPC_TLS: return "tls"; |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 254 | case VK_PPC_GOT_TLSGD: return "got@tlsgd"; |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 255 | case VK_PPC_GOT_TLSGD_LO: return "got@tlsgd@l"; |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 256 | case VK_PPC_GOT_TLSGD_HI: return "got@tlsgd@h"; |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 257 | case VK_PPC_GOT_TLSGD_HA: return "got@tlsgd@ha"; |
Ulrich Weigand | 52cf8e4 | 2013-07-09 16:41:09 +0000 | [diff] [blame] | 258 | case VK_PPC_TLSGD: return "tlsgd"; |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 259 | case VK_PPC_GOT_TLSLD: return "got@tlsld"; |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 260 | case VK_PPC_GOT_TLSLD_LO: return "got@tlsld@l"; |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 261 | case VK_PPC_GOT_TLSLD_HI: return "got@tlsld@h"; |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 262 | case VK_PPC_GOT_TLSLD_HA: return "got@tlsld@ha"; |
Ulrich Weigand | 52cf8e4 | 2013-07-09 16:41:09 +0000 | [diff] [blame] | 263 | case VK_PPC_TLSLD: return "tlsld"; |
Justin Hibbits | a88b605 | 2014-11-12 15:16:30 +0000 | [diff] [blame] | 264 | case VK_PPC_LOCAL: return "local"; |
Akira Hatanaka | e2eed96 | 2011-12-22 01:05:17 +0000 | [diff] [blame] | 265 | case VK_Mips_GPREL: return "GPREL"; |
| 266 | case VK_Mips_GOT_CALL: return "GOT_CALL"; |
| 267 | case VK_Mips_GOT16: return "GOT16"; |
| 268 | case VK_Mips_GOT: return "GOT"; |
| 269 | case VK_Mips_ABS_HI: return "ABS_HI"; |
| 270 | case VK_Mips_ABS_LO: return "ABS_LO"; |
| 271 | case VK_Mips_TLSGD: return "TLSGD"; |
| 272 | case VK_Mips_TLSLDM: return "TLSLDM"; |
| 273 | case VK_Mips_DTPREL_HI: return "DTPREL_HI"; |
| 274 | case VK_Mips_DTPREL_LO: return "DTPREL_LO"; |
| 275 | case VK_Mips_GOTTPREL: return "GOTTPREL"; |
| 276 | case VK_Mips_TPREL_HI: return "TPREL_HI"; |
| 277 | case VK_Mips_TPREL_LO: return "TPREL_LO"; |
| 278 | case VK_Mips_GPOFF_HI: return "GPOFF_HI"; |
| 279 | case VK_Mips_GPOFF_LO: return "GPOFF_LO"; |
| 280 | case VK_Mips_GOT_DISP: return "GOT_DISP"; |
| 281 | case VK_Mips_GOT_PAGE: return "GOT_PAGE"; |
| 282 | case VK_Mips_GOT_OFST: return "GOT_OFST"; |
Akira Hatanaka | f73e362 | 2012-07-21 02:15:19 +0000 | [diff] [blame] | 283 | case VK_Mips_HIGHER: return "HIGHER"; |
| 284 | case VK_Mips_HIGHEST: return "HIGHEST"; |
Akira Hatanaka | 64b52d8 | 2012-11-21 19:50:22 +0000 | [diff] [blame] | 285 | case VK_Mips_GOT_HI16: return "GOT_HI16"; |
| 286 | case VK_Mips_GOT_LO16: return "GOT_LO16"; |
| 287 | case VK_Mips_CALL_HI16: return "CALL_HI16"; |
| 288 | case VK_Mips_CALL_LO16: return "CALL_LO16"; |
Zoran Jovanovic | b355e8f | 2014-05-27 14:58:51 +0000 | [diff] [blame] | 289 | case VK_Mips_PCREL_HI16: return "PCREL_HI16"; |
| 290 | case VK_Mips_PCREL_LO16: return "PCREL_LO16"; |
Reid Kleckner | 81782f0 | 2014-09-25 02:09:18 +0000 | [diff] [blame] | 291 | case VK_COFF_IMGREL32: return "IMGREL"; |
Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 292 | case VK_Hexagon_PCREL: return "PCREL"; |
| 293 | case VK_Hexagon_LO16: return "LO16"; |
| 294 | case VK_Hexagon_HI16: return "HI16"; |
| 295 | case VK_Hexagon_GPREL: return "GPREL"; |
| 296 | case VK_Hexagon_GD_GOT: return "GDGOT"; |
| 297 | case VK_Hexagon_LD_GOT: return "LDGOT"; |
| 298 | case VK_Hexagon_GD_PLT: return "GDPLT"; |
| 299 | case VK_Hexagon_LD_PLT: return "LDPLT"; |
| 300 | case VK_Hexagon_IE: return "IE"; |
| 301 | case VK_Hexagon_IE_GOT: return "IEGOT"; |
| 302 | case VK_TPREL: return "tprel"; |
| 303 | case VK_DTPREL: return "dtprel"; |
Daniel Dunbar | 5599256 | 2010-03-15 23:51:06 +0000 | [diff] [blame] | 304 | } |
Chandler Carruth | f3e8502 | 2012-01-10 18:08:01 +0000 | [diff] [blame] | 305 | llvm_unreachable("Invalid variant kind"); |
Daniel Dunbar | 5599256 | 2010-03-15 23:51:06 +0000 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | MCSymbolRefExpr::VariantKind |
| 309 | MCSymbolRefExpr::getVariantKindForName(StringRef Name) { |
Roman Divacky | a93d002 | 2014-12-18 23:12:34 +0000 | [diff] [blame] | 310 | return StringSwitch<VariantKind>(Name.lower()) |
Rafael Espindola | 8bac423 | 2011-01-23 16:11:25 +0000 | [diff] [blame] | 311 | .Case("got", VK_GOT) |
Rafael Espindola | 8bac423 | 2011-01-23 16:11:25 +0000 | [diff] [blame] | 312 | .Case("gotoff", VK_GOTOFF) |
Rafael Espindola | 8bac423 | 2011-01-23 16:11:25 +0000 | [diff] [blame] | 313 | .Case("gotpcrel", VK_GOTPCREL) |
Joerg Sonnenberger | dd18d5b | 2014-04-29 13:42:02 +0000 | [diff] [blame] | 314 | .Case("got_prel", VK_GOTPCREL) |
Rafael Espindola | 8bac423 | 2011-01-23 16:11:25 +0000 | [diff] [blame] | 315 | .Case("gottpoff", VK_GOTTPOFF) |
Rafael Espindola | 8bac423 | 2011-01-23 16:11:25 +0000 | [diff] [blame] | 316 | .Case("indntpoff", VK_INDNTPOFF) |
Rafael Espindola | 8bac423 | 2011-01-23 16:11:25 +0000 | [diff] [blame] | 317 | .Case("ntpoff", VK_NTPOFF) |
Rafael Espindola | 8bac423 | 2011-01-23 16:11:25 +0000 | [diff] [blame] | 318 | .Case("gotntpoff", VK_GOTNTPOFF) |
Rafael Espindola | 8bac423 | 2011-01-23 16:11:25 +0000 | [diff] [blame] | 319 | .Case("plt", VK_PLT) |
Rafael Espindola | 8bac423 | 2011-01-23 16:11:25 +0000 | [diff] [blame] | 320 | .Case("tlsgd", VK_TLSGD) |
Rafael Espindola | 8bac423 | 2011-01-23 16:11:25 +0000 | [diff] [blame] | 321 | .Case("tlsld", VK_TLSLD) |
Rafael Espindola | 8bac423 | 2011-01-23 16:11:25 +0000 | [diff] [blame] | 322 | .Case("tlsldm", VK_TLSLDM) |
Rafael Espindola | 8bac423 | 2011-01-23 16:11:25 +0000 | [diff] [blame] | 323 | .Case("tpoff", VK_TPOFF) |
Rafael Espindola | 8bac423 | 2011-01-23 16:11:25 +0000 | [diff] [blame] | 324 | .Case("dtpoff", VK_DTPOFF) |
Rafael Espindola | 8bac423 | 2011-01-23 16:11:25 +0000 | [diff] [blame] | 325 | .Case("tlvp", VK_TLVP) |
Tim Northover | 00ed996 | 2014-03-29 10:18:08 +0000 | [diff] [blame] | 326 | .Case("tlvppage", VK_TLVPPAGE) |
Tim Northover | 00ed996 | 2014-03-29 10:18:08 +0000 | [diff] [blame] | 327 | .Case("tlvppageoff", VK_TLVPPAGEOFF) |
Tim Northover | 00ed996 | 2014-03-29 10:18:08 +0000 | [diff] [blame] | 328 | .Case("page", VK_PAGE) |
Tim Northover | 00ed996 | 2014-03-29 10:18:08 +0000 | [diff] [blame] | 329 | .Case("pageoff", VK_PAGEOFF) |
Tim Northover | 00ed996 | 2014-03-29 10:18:08 +0000 | [diff] [blame] | 330 | .Case("gotpage", VK_GOTPAGE) |
Tim Northover | 00ed996 | 2014-03-29 10:18:08 +0000 | [diff] [blame] | 331 | .Case("gotpageoff", VK_GOTPAGEOFF) |
Nico Rieck | 1da4529 | 2013-04-10 23:28:17 +0000 | [diff] [blame] | 332 | .Case("imgrel", VK_COFF_IMGREL32) |
Rafael Espindola | b770f89 | 2013-04-25 19:27:05 +0000 | [diff] [blame] | 333 | .Case("secrel32", VK_SECREL) |
Davide Italiano | fcae934 | 2015-03-04 06:49:39 +0000 | [diff] [blame] | 334 | .Case("size", VK_SIZE) |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 335 | .Case("l", VK_PPC_LO) |
Ulrich Weigand | e67c565 | 2013-06-21 14:42:49 +0000 | [diff] [blame] | 336 | .Case("h", VK_PPC_HI) |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 337 | .Case("ha", VK_PPC_HA) |
Ulrich Weigand | e9126f5 | 2013-06-21 14:43:42 +0000 | [diff] [blame] | 338 | .Case("higher", VK_PPC_HIGHER) |
Ulrich Weigand | e9126f5 | 2013-06-21 14:43:42 +0000 | [diff] [blame] | 339 | .Case("highera", VK_PPC_HIGHERA) |
Ulrich Weigand | e9126f5 | 2013-06-21 14:43:42 +0000 | [diff] [blame] | 340 | .Case("highest", VK_PPC_HIGHEST) |
Ulrich Weigand | e9126f5 | 2013-06-21 14:43:42 +0000 | [diff] [blame] | 341 | .Case("highesta", VK_PPC_HIGHESTA) |
Ulrich Weigand | 93372b4 | 2013-06-25 16:49:50 +0000 | [diff] [blame] | 342 | .Case("got@l", VK_PPC_GOT_LO) |
Ulrich Weigand | 93372b4 | 2013-06-25 16:49:50 +0000 | [diff] [blame] | 343 | .Case("got@h", VK_PPC_GOT_HI) |
Ulrich Weigand | 93372b4 | 2013-06-25 16:49:50 +0000 | [diff] [blame] | 344 | .Case("got@ha", VK_PPC_GOT_HA) |
Justin Hibbits | 0c0d5de | 2014-12-17 06:23:35 +0000 | [diff] [blame] | 345 | .Case("local", VK_PPC_LOCAL) |
Ulrich Weigand | 68e2e1b | 2013-06-20 22:39:42 +0000 | [diff] [blame] | 346 | .Case("tocbase", VK_PPC_TOCBASE) |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 347 | .Case("toc", VK_PPC_TOC) |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 348 | .Case("toc@l", VK_PPC_TOC_LO) |
Ulrich Weigand | 72ddbd6 | 2013-06-21 14:43:10 +0000 | [diff] [blame] | 349 | .Case("toc@h", VK_PPC_TOC_HI) |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 350 | .Case("toc@ha", VK_PPC_TOC_HA) |
Ulrich Weigand | 2c3a219 | 2013-05-03 19:52:35 +0000 | [diff] [blame] | 351 | .Case("tls", VK_PPC_TLS) |
Ulrich Weigand | f11efe7 | 2013-07-01 23:33:29 +0000 | [diff] [blame] | 352 | .Case("dtpmod", VK_PPC_DTPMOD) |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 353 | .Case("tprel", VK_PPC_TPREL) |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 354 | .Case("tprel@l", VK_PPC_TPREL_LO) |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 355 | .Case("tprel@h", VK_PPC_TPREL_HI) |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 356 | .Case("tprel@ha", VK_PPC_TPREL_HA) |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 357 | .Case("tprel@higher", VK_PPC_TPREL_HIGHER) |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 358 | .Case("tprel@highera", VK_PPC_TPREL_HIGHERA) |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 359 | .Case("tprel@highest", VK_PPC_TPREL_HIGHEST) |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 360 | .Case("tprel@highesta", VK_PPC_TPREL_HIGHESTA) |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 361 | .Case("dtprel", VK_PPC_DTPREL) |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 362 | .Case("dtprel@l", VK_PPC_DTPREL_LO) |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 363 | .Case("dtprel@h", VK_PPC_DTPREL_HI) |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 364 | .Case("dtprel@ha", VK_PPC_DTPREL_HA) |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 365 | .Case("dtprel@higher", VK_PPC_DTPREL_HIGHER) |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 366 | .Case("dtprel@highera", VK_PPC_DTPREL_HIGHERA) |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 367 | .Case("dtprel@highest", VK_PPC_DTPREL_HIGHEST) |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 368 | .Case("dtprel@highesta", VK_PPC_DTPREL_HIGHESTA) |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 369 | .Case("got@tprel", VK_PPC_GOT_TPREL) |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 370 | .Case("got@tprel@l", VK_PPC_GOT_TPREL_LO) |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 371 | .Case("got@tprel@h", VK_PPC_GOT_TPREL_HI) |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 372 | .Case("got@tprel@ha", VK_PPC_GOT_TPREL_HA) |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 373 | .Case("got@dtprel", VK_PPC_GOT_DTPREL) |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 374 | .Case("got@dtprel@l", VK_PPC_GOT_DTPREL_LO) |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 375 | .Case("got@dtprel@h", VK_PPC_GOT_DTPREL_HI) |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 376 | .Case("got@dtprel@ha", VK_PPC_GOT_DTPREL_HA) |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 377 | .Case("got@tlsgd", VK_PPC_GOT_TLSGD) |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 378 | .Case("got@tlsgd@l", VK_PPC_GOT_TLSGD_LO) |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 379 | .Case("got@tlsgd@h", VK_PPC_GOT_TLSGD_HI) |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 380 | .Case("got@tlsgd@ha", VK_PPC_GOT_TLSGD_HA) |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 381 | .Case("got@tlsld", VK_PPC_GOT_TLSLD) |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 382 | .Case("got@tlsld@l", VK_PPC_GOT_TLSLD_LO) |
Ulrich Weigand | 876a0d0 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 383 | .Case("got@tlsld@h", VK_PPC_GOT_TLSLD_HI) |
Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 384 | .Case("got@tlsld@ha", VK_PPC_GOT_TLSLD_HA) |
David Peixotto | 8ad70b3 | 2013-12-04 22:43:20 +0000 | [diff] [blame] | 385 | .Case("none", VK_ARM_NONE) |
David Peixotto | 8ad70b3 | 2013-12-04 22:43:20 +0000 | [diff] [blame] | 386 | .Case("target1", VK_ARM_TARGET1) |
David Peixotto | 8ad70b3 | 2013-12-04 22:43:20 +0000 | [diff] [blame] | 387 | .Case("target2", VK_ARM_TARGET2) |
David Peixotto | 8ad70b3 | 2013-12-04 22:43:20 +0000 | [diff] [blame] | 388 | .Case("prel31", VK_ARM_PREL31) |
Saleem Abdulrasool | fe78197 | 2015-01-11 04:39:18 +0000 | [diff] [blame] | 389 | .Case("sbrel", VK_ARM_SBREL) |
Kai Nacke | e51c813 | 2014-01-20 11:00:40 +0000 | [diff] [blame] | 390 | .Case("tlsldo", VK_ARM_TLSLDO) |
Saleem Abdulrasool | 6e00ca8 | 2014-01-30 04:02:31 +0000 | [diff] [blame] | 391 | .Case("tlscall", VK_ARM_TLSCALL) |
Saleem Abdulrasool | a3f12bd | 2014-01-30 04:02:38 +0000 | [diff] [blame] | 392 | .Case("tlsdesc", VK_ARM_TLSDESC) |
Daniel Dunbar | 5599256 | 2010-03-15 23:51:06 +0000 | [diff] [blame] | 393 | .Default(VK_Invalid); |
| 394 | } |
| 395 | |
Benjamin Kramer | dd13643 | 2014-10-11 17:57:27 +0000 | [diff] [blame] | 396 | void MCSymbolRefExpr::printVariantKind(raw_ostream &OS) const { |
| 397 | if (UseParensForSymbolVariant) |
| 398 | OS << '(' << MCSymbolRefExpr::getVariantKindName(getKind()) << ')'; |
| 399 | else |
| 400 | OS << '@' << MCSymbolRefExpr::getVariantKindName(getKind()); |
| 401 | } |
| 402 | |
Daniel Dunbar | 5599256 | 2010-03-15 23:51:06 +0000 | [diff] [blame] | 403 | /* *** */ |
| 404 | |
Craig Topper | 2a6a08b | 2012-09-26 06:36:36 +0000 | [diff] [blame] | 405 | void MCTargetExpr::anchor() {} |
Chris Lattner | 6a833f6 | 2009-09-16 01:26:31 +0000 | [diff] [blame] | 406 | |
Daniel Dunbar | f363645 | 2009-08-31 08:07:22 +0000 | [diff] [blame] | 407 | /* *** */ |
| 408 | |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 409 | bool MCExpr::evaluateAsAbsolute(int64_t &Res) const { |
| 410 | return evaluateAsAbsolute(Res, nullptr, nullptr, nullptr); |
Rafael Espindola | 5004f4a | 2010-12-18 03:57:21 +0000 | [diff] [blame] | 411 | } |
| 412 | |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 413 | bool MCExpr::evaluateAsAbsolute(int64_t &Res, |
Rafael Espindola | 5004f4a | 2010-12-18 03:57:21 +0000 | [diff] [blame] | 414 | const MCAsmLayout &Layout) const { |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 415 | return evaluateAsAbsolute(Res, &Layout.getAssembler(), &Layout, nullptr); |
Rafael Espindola | 5004f4a | 2010-12-18 03:57:21 +0000 | [diff] [blame] | 416 | } |
| 417 | |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 418 | bool MCExpr::evaluateAsAbsolute(int64_t &Res, |
Rafael Espindola | 5004f4a | 2010-12-18 03:57:21 +0000 | [diff] [blame] | 419 | const MCAsmLayout &Layout, |
| 420 | const SectionAddrMap &Addrs) const { |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 421 | return evaluateAsAbsolute(Res, &Layout.getAssembler(), &Layout, &Addrs); |
Rafael Espindola | 5004f4a | 2010-12-18 03:57:21 +0000 | [diff] [blame] | 422 | } |
| 423 | |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 424 | bool MCExpr::evaluateAsAbsolute(int64_t &Res, const MCAssembler &Asm) const { |
| 425 | return evaluateAsAbsolute(Res, &Asm, nullptr, nullptr); |
Rafael Espindola | 5004f4a | 2010-12-18 03:57:21 +0000 | [diff] [blame] | 426 | } |
| 427 | |
Rafael Espindola | dbb4021 | 2015-03-25 00:25:37 +0000 | [diff] [blame] | 428 | bool MCExpr::evaluateKnownAbsolute(int64_t &Res, |
| 429 | const MCAsmLayout &Layout) const { |
| 430 | return evaluateAsAbsolute(Res, &Layout.getAssembler(), &Layout, nullptr, |
| 431 | true); |
Rafael Espindola | adbe024 | 2014-08-15 14:20:32 +0000 | [diff] [blame] | 432 | } |
| 433 | |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 434 | bool MCExpr::evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm, |
Rafael Espindola | 5004f4a | 2010-12-18 03:57:21 +0000 | [diff] [blame] | 435 | const MCAsmLayout *Layout, |
Rafael Espindola | 93e3cf0 | 2010-12-07 00:27:36 +0000 | [diff] [blame] | 436 | const SectionAddrMap *Addrs) const { |
Rafael Espindola | adbe024 | 2014-08-15 14:20:32 +0000 | [diff] [blame] | 437 | // FIXME: The use if InSet = Addrs is a hack. Setting InSet causes us |
| 438 | // absolutize differences across sections and that is what the MachO writer |
| 439 | // uses Addrs for. |
| 440 | return evaluateAsAbsolute(Res, Asm, Layout, Addrs, Addrs); |
| 441 | } |
| 442 | |
| 443 | bool MCExpr::evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm, |
| 444 | const MCAsmLayout *Layout, |
| 445 | const SectionAddrMap *Addrs, bool InSet) const { |
Daniel Dunbar | bd4bf3d | 2009-06-30 01:49:52 +0000 | [diff] [blame] | 446 | MCValue Value; |
Daniel Dunbar | 9c64ec0 | 2010-03-18 00:59:10 +0000 | [diff] [blame] | 447 | |
Daniel Dunbar | 5cfb587 | 2010-03-23 23:47:07 +0000 | [diff] [blame] | 448 | // Fast path constants. |
| 449 | if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(this)) { |
| 450 | Res = CE->getValue(); |
| 451 | return true; |
| 452 | } |
| 453 | |
Rafael Espindola | f275ad8 | 2015-03-25 13:16:53 +0000 | [diff] [blame] | 454 | bool IsRelocatable = |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 455 | evaluateAsRelocatableImpl(Value, Asm, Layout, nullptr, Addrs, InSet); |
Daniel Dunbar | bd4bf3d | 2009-06-30 01:49:52 +0000 | [diff] [blame] | 456 | |
Rafael Espindola | 4124ab1 | 2010-12-22 22:16:24 +0000 | [diff] [blame] | 457 | // Record the current value. |
Daniel Dunbar | bd4bf3d | 2009-06-30 01:49:52 +0000 | [diff] [blame] | 458 | Res = Value.getConstant(); |
Rafael Espindola | 4124ab1 | 2010-12-22 22:16:24 +0000 | [diff] [blame] | 459 | |
| 460 | return IsRelocatable && Value.isAbsolute(); |
Daniel Dunbar | bd4bf3d | 2009-06-30 01:49:52 +0000 | [diff] [blame] | 461 | } |
| 462 | |
Daniel Dunbar | 137d422 | 2010-12-17 05:50:33 +0000 | [diff] [blame] | 463 | /// \brief Helper method for \see EvaluateSymbolAdd(). |
Rafael Espindola | 59f90b2 | 2015-03-25 19:24:39 +0000 | [diff] [blame] | 464 | static void AttemptToFoldSymbolOffsetDifference( |
| 465 | const MCAssembler *Asm, const MCAsmLayout *Layout, |
| 466 | const SectionAddrMap *Addrs, bool InSet, const MCSymbolRefExpr *&A, |
| 467 | const MCSymbolRefExpr *&B, int64_t &Addend) { |
Rafael Espindola | ee54636 | 2010-12-19 04:18:56 +0000 | [diff] [blame] | 468 | if (!A || !B) |
| 469 | return; |
Daniel Dunbar | 137d422 | 2010-12-17 05:50:33 +0000 | [diff] [blame] | 470 | |
Rafael Espindola | ee54636 | 2010-12-19 04:18:56 +0000 | [diff] [blame] | 471 | const MCSymbol &SA = A->getSymbol(); |
| 472 | const MCSymbol &SB = B->getSymbol(); |
| 473 | |
| 474 | if (SA.isUndefined() || SB.isUndefined()) |
| 475 | return; |
| 476 | |
Jim Grosbach | 36e60e9 | 2015-06-04 22:24:41 +0000 | [diff] [blame] | 477 | if (!Asm->getWriter().isSymbolRefDifferenceFullyResolved(*Asm, A, B, InSet)) |
Rafael Espindola | ee54636 | 2010-12-19 04:18:56 +0000 | [diff] [blame] | 478 | return; |
| 479 | |
Rafael Espindola | 4d37b2a | 2015-05-29 21:45:01 +0000 | [diff] [blame] | 480 | if (SA.getFragment() == SB.getFragment()) { |
Rafael Espindola | 1467250 | 2015-05-29 17:48:04 +0000 | [diff] [blame] | 481 | Addend += (SA.getOffset() - SB.getOffset()); |
Daniel Dunbar | 137d422 | 2010-12-17 05:50:33 +0000 | [diff] [blame] | 482 | |
Owen Anderson | 9746286 | 2011-03-21 23:13:43 +0000 | [diff] [blame] | 483 | // Pointers to Thumb symbols need to have their low-bit set to allow |
| 484 | // for interworking. |
| 485 | if (Asm->isThumbFunc(&SA)) |
| 486 | Addend |= 1; |
| 487 | |
Daniel Dunbar | 137d422 | 2010-12-17 05:50:33 +0000 | [diff] [blame] | 488 | // Clear the symbol expr pointers to indicate we have folded these |
| 489 | // operands. |
Craig Topper | bb694de | 2014-04-13 04:57:38 +0000 | [diff] [blame] | 490 | A = B = nullptr; |
Rafael Espindola | ee54636 | 2010-12-19 04:18:56 +0000 | [diff] [blame] | 491 | return; |
Daniel Dunbar | 137d422 | 2010-12-17 05:50:33 +0000 | [diff] [blame] | 492 | } |
Rafael Espindola | ee54636 | 2010-12-19 04:18:56 +0000 | [diff] [blame] | 493 | |
| 494 | if (!Layout) |
| 495 | return; |
| 496 | |
Rafael Espindola | 4d37b2a | 2015-05-29 21:45:01 +0000 | [diff] [blame] | 497 | const MCSection &SecA = *SA.getFragment()->getParent(); |
| 498 | const MCSection &SecB = *SB.getFragment()->getParent(); |
Rafael Espindola | ee54636 | 2010-12-19 04:18:56 +0000 | [diff] [blame] | 499 | |
| 500 | if ((&SecA != &SecB) && !Addrs) |
| 501 | return; |
| 502 | |
| 503 | // Eagerly evaluate. |
Duncan P. N. Exon Smith | 2a40483 | 2015-05-19 23:53:20 +0000 | [diff] [blame] | 504 | Addend += Layout->getSymbolOffset(A->getSymbol()) - |
| 505 | Layout->getSymbolOffset(B->getSymbol()); |
Rafael Espindola | ee54636 | 2010-12-19 04:18:56 +0000 | [diff] [blame] | 506 | if (Addrs && (&SecA != &SecB)) |
Rafael Espindola | 079027e | 2015-05-26 00:52:18 +0000 | [diff] [blame] | 507 | Addend += (Addrs->lookup(&SecA) - Addrs->lookup(&SecB)); |
Rafael Espindola | ee54636 | 2010-12-19 04:18:56 +0000 | [diff] [blame] | 508 | |
Jim Grosbach | 213039a | 2012-02-24 05:12:18 +0000 | [diff] [blame] | 509 | // Pointers to Thumb symbols need to have their low-bit set to allow |
| 510 | // for interworking. |
| 511 | if (Asm->isThumbFunc(&SA)) |
| 512 | Addend |= 1; |
| 513 | |
Rafael Espindola | ee54636 | 2010-12-19 04:18:56 +0000 | [diff] [blame] | 514 | // Clear the symbol expr pointers to indicate we have folded these |
| 515 | // operands. |
Craig Topper | bb694de | 2014-04-13 04:57:38 +0000 | [diff] [blame] | 516 | A = B = nullptr; |
Daniel Dunbar | 137d422 | 2010-12-17 05:50:33 +0000 | [diff] [blame] | 517 | } |
| 518 | |
Daniel Dunbar | 395a099 | 2010-12-16 18:36:25 +0000 | [diff] [blame] | 519 | /// \brief Evaluate the result of an add between (conceptually) two MCValues. |
| 520 | /// |
| 521 | /// This routine conceptually attempts to construct an MCValue: |
| 522 | /// Result = (Result_A - Result_B + Result_Cst) |
| 523 | /// from two MCValue's LHS and RHS where |
| 524 | /// Result = LHS + RHS |
| 525 | /// and |
| 526 | /// Result = (LHS_A - LHS_B + LHS_Cst) + (RHS_A - RHS_B + RHS_Cst). |
| 527 | /// |
| 528 | /// This routine attempts to aggresively fold the operands such that the result |
| 529 | /// is representable in an MCValue, but may not always succeed. |
| 530 | /// |
| 531 | /// \returns True on success, false if the result is not representable in an |
| 532 | /// MCValue. |
Rafael Espindola | 5004f4a | 2010-12-18 03:57:21 +0000 | [diff] [blame] | 533 | |
| 534 | /// NOTE: It is really important to have both the Asm and Layout arguments. |
| 535 | /// They might look redundant, but this function can be used before layout |
| 536 | /// is done (see the object streamer for example) and having the Asm argument |
Rafael Espindola | 1ea7f18 | 2010-12-18 04:01:45 +0000 | [diff] [blame] | 537 | /// lets us avoid relaxations early. |
Rafael Espindola | 59f90b2 | 2015-03-25 19:24:39 +0000 | [diff] [blame] | 538 | static bool |
| 539 | EvaluateSymbolicAdd(const MCAssembler *Asm, const MCAsmLayout *Layout, |
| 540 | const SectionAddrMap *Addrs, bool InSet, const MCValue &LHS, |
| 541 | const MCSymbolRefExpr *RHS_A, const MCSymbolRefExpr *RHS_B, |
| 542 | int64_t RHS_Cst, MCValue &Res) { |
Daniel Dunbar | 76793ba | 2010-12-17 01:07:20 +0000 | [diff] [blame] | 543 | // FIXME: This routine (and other evaluation parts) are *incredibly* sloppy |
| 544 | // about dealing with modifiers. This will ultimately bite us, one day. |
| 545 | const MCSymbolRefExpr *LHS_A = LHS.getSymA(); |
| 546 | const MCSymbolRefExpr *LHS_B = LHS.getSymB(); |
| 547 | int64_t LHS_Cst = LHS.getConstant(); |
| 548 | |
| 549 | // Fold the result constant immediately. |
| 550 | int64_t Result_Cst = LHS_Cst + RHS_Cst; |
| 551 | |
Rafael Espindola | ee54636 | 2010-12-19 04:18:56 +0000 | [diff] [blame] | 552 | assert((!Layout || Asm) && |
| 553 | "Must have an assembler object if layout is given!"); |
| 554 | |
Daniel Dunbar | 137d422 | 2010-12-17 05:50:33 +0000 | [diff] [blame] | 555 | // If we have a layout, we can fold resolved differences. |
Rafael Espindola | ee54636 | 2010-12-19 04:18:56 +0000 | [diff] [blame] | 556 | if (Asm) { |
Daniel Dunbar | 137d422 | 2010-12-17 05:50:33 +0000 | [diff] [blame] | 557 | // First, fold out any differences which are fully resolved. By |
| 558 | // reassociating terms in |
| 559 | // Result = (LHS_A - LHS_B + LHS_Cst) + (RHS_A - RHS_B + RHS_Cst). |
| 560 | // we have the four possible differences: |
| 561 | // (LHS_A - LHS_B), |
| 562 | // (LHS_A - RHS_B), |
| 563 | // (RHS_A - LHS_B), |
| 564 | // (RHS_A - RHS_B). |
Chris Lattner | 0ab5e2c | 2011-04-15 05:18:47 +0000 | [diff] [blame] | 565 | // Since we are attempting to be as aggressive as possible about folding, we |
Daniel Dunbar | 137d422 | 2010-12-17 05:50:33 +0000 | [diff] [blame] | 566 | // attempt to evaluate each possible alternative. |
Rafael Espindola | ee54636 | 2010-12-19 04:18:56 +0000 | [diff] [blame] | 567 | AttemptToFoldSymbolOffsetDifference(Asm, Layout, Addrs, InSet, LHS_A, LHS_B, |
| 568 | Result_Cst); |
| 569 | AttemptToFoldSymbolOffsetDifference(Asm, Layout, Addrs, InSet, LHS_A, RHS_B, |
| 570 | Result_Cst); |
| 571 | AttemptToFoldSymbolOffsetDifference(Asm, Layout, Addrs, InSet, RHS_A, LHS_B, |
| 572 | Result_Cst); |
| 573 | AttemptToFoldSymbolOffsetDifference(Asm, Layout, Addrs, InSet, RHS_A, RHS_B, |
| 574 | Result_Cst); |
Daniel Dunbar | 137d422 | 2010-12-17 05:50:33 +0000 | [diff] [blame] | 575 | } |
| 576 | |
Daniel Dunbar | 76793ba | 2010-12-17 01:07:20 +0000 | [diff] [blame] | 577 | // We can't represent the addition or subtraction of two symbols. |
| 578 | if ((LHS_A && RHS_A) || (LHS_B && RHS_B)) |
Daniel Dunbar | 19f847f | 2009-06-30 02:08:27 +0000 | [diff] [blame] | 579 | return false; |
| 580 | |
Daniel Dunbar | 137d422 | 2010-12-17 05:50:33 +0000 | [diff] [blame] | 581 | // At this point, we have at most one additive symbol and one subtractive |
| 582 | // symbol -- find them. |
Daniel Dunbar | 76793ba | 2010-12-17 01:07:20 +0000 | [diff] [blame] | 583 | const MCSymbolRefExpr *A = LHS_A ? LHS_A : RHS_A; |
| 584 | const MCSymbolRefExpr *B = LHS_B ? LHS_B : RHS_B; |
Daniel Dunbar | 137d422 | 2010-12-17 05:50:33 +0000 | [diff] [blame] | 585 | |
| 586 | // If we have a negated symbol, then we must have also have a non-negated |
| 587 | // symbol in order to encode the expression. |
| 588 | if (B && !A) |
| 589 | return false; |
Rafael Espindola | 4262a22 | 2010-10-16 18:23:53 +0000 | [diff] [blame] | 590 | |
Daniel Dunbar | 76793ba | 2010-12-17 01:07:20 +0000 | [diff] [blame] | 591 | Res = MCValue::get(A, B, Result_Cst); |
Daniel Dunbar | 19f847f | 2009-06-30 02:08:27 +0000 | [diff] [blame] | 592 | return true; |
| 593 | } |
| 594 | |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 595 | bool MCExpr::evaluateAsRelocatable(MCValue &Res, |
Joerg Sonnenberger | 752b91b | 2014-08-10 11:35:12 +0000 | [diff] [blame] | 596 | const MCAsmLayout *Layout, |
Joerg Sonnenberger | b696d46 | 2014-08-10 11:37:07 +0000 | [diff] [blame] | 597 | const MCFixup *Fixup) const { |
Craig Topper | bb694de | 2014-04-13 04:57:38 +0000 | [diff] [blame] | 598 | MCAssembler *Assembler = Layout ? &Layout->getAssembler() : nullptr; |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 599 | return evaluateAsRelocatableImpl(Res, Assembler, Layout, Fixup, nullptr, |
Rafael Espindola | f275ad8 | 2015-03-25 13:16:53 +0000 | [diff] [blame] | 600 | false); |
Rafael Espindola | 5004f4a | 2010-12-18 03:57:21 +0000 | [diff] [blame] | 601 | } |
| 602 | |
Rafael Espindola | aeed3cb | 2015-03-26 21:11:00 +0000 | [diff] [blame] | 603 | bool MCExpr::evaluateAsValue(MCValue &Res, const MCAsmLayout &Layout) const { |
| 604 | MCAssembler *Assembler = &Layout.getAssembler(); |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 605 | return evaluateAsRelocatableImpl(Res, Assembler, &Layout, nullptr, nullptr, |
Rafael Espindola | aeed3cb | 2015-03-26 21:11:00 +0000 | [diff] [blame] | 606 | true); |
| 607 | } |
| 608 | |
| 609 | static bool canExpand(const MCSymbol &Sym, const MCAssembler *Asm, bool InSet) { |
Rafael Espindola | 212fdde | 2015-06-03 21:52:06 +0000 | [diff] [blame] | 610 | const MCExpr *Expr = Sym.getVariableValue(); |
| 611 | const auto *Inner = dyn_cast<MCSymbolRefExpr>(Expr); |
| 612 | if (Inner) { |
| 613 | if (Inner->getKind() == MCSymbolRefExpr::VK_WEAKREF) |
| 614 | return false; |
| 615 | } |
| 616 | |
Rafael Espindola | aeed3cb | 2015-03-26 21:11:00 +0000 | [diff] [blame] | 617 | if (InSet) |
| 618 | return true; |
Rafael Espindola | f275ad8 | 2015-03-25 13:16:53 +0000 | [diff] [blame] | 619 | if (!Asm) |
| 620 | return false; |
Duncan P. N. Exon Smith | 5266ad9 | 2015-05-20 15:10:03 +0000 | [diff] [blame] | 621 | return !Asm->getWriter().isWeak(Sym); |
Rafael Espindola | bc91d7e | 2014-04-28 20:53:11 +0000 | [diff] [blame] | 622 | } |
| 623 | |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 624 | bool MCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm, |
Rafael Espindola | 4262a22 | 2010-10-16 18:23:53 +0000 | [diff] [blame] | 625 | const MCAsmLayout *Layout, |
Joerg Sonnenberger | 752b91b | 2014-08-10 11:35:12 +0000 | [diff] [blame] | 626 | const MCFixup *Fixup, |
Rafael Espindola | f275ad8 | 2015-03-25 13:16:53 +0000 | [diff] [blame] | 627 | const SectionAddrMap *Addrs, |
| 628 | bool InSet) const { |
Daniel Dunbar | 5376c2a | 2010-03-23 23:47:14 +0000 | [diff] [blame] | 629 | ++stats::MCExprEvaluate; |
| 630 | |
Daniel Dunbar | 84bfd7b | 2009-06-29 20:40:36 +0000 | [diff] [blame] | 631 | switch (getKind()) { |
Chris Lattner | 38d022e | 2010-02-08 19:41:07 +0000 | [diff] [blame] | 632 | case Target: |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 633 | return cast<MCTargetExpr>(this)->evaluateAsRelocatableImpl(Res, Layout, |
Joerg Sonnenberger | 752b91b | 2014-08-10 11:35:12 +0000 | [diff] [blame] | 634 | Fixup); |
Daniel Dunbar | 9c64ec0 | 2010-03-18 00:59:10 +0000 | [diff] [blame] | 635 | |
Daniel Dunbar | 84bfd7b | 2009-06-29 20:40:36 +0000 | [diff] [blame] | 636 | case Constant: |
Daniel Dunbar | 115e4d6 | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 637 | Res = MCValue::get(cast<MCConstantExpr>(this)->getValue()); |
Daniel Dunbar | 84bfd7b | 2009-06-29 20:40:36 +0000 | [diff] [blame] | 638 | return true; |
| 639 | |
| 640 | case SymbolRef: { |
Daniel Dunbar | 9c64ec0 | 2010-03-18 00:59:10 +0000 | [diff] [blame] | 641 | const MCSymbolRefExpr *SRE = cast<MCSymbolRefExpr>(this); |
| 642 | const MCSymbol &Sym = SRE->getSymbol(); |
Daniel Dunbar | 17b9027 | 2009-10-16 01:33:57 +0000 | [diff] [blame] | 643 | |
| 644 | // Evaluate recursively if this is a variable. |
Rafael Espindola | f275ad8 | 2015-03-25 13:16:53 +0000 | [diff] [blame] | 645 | if (Sym.isVariable() && SRE->getKind() == MCSymbolRefExpr::VK_None && |
Rafael Espindola | aeed3cb | 2015-03-26 21:11:00 +0000 | [diff] [blame] | 646 | canExpand(Sym, Asm, InSet)) { |
| 647 | bool IsMachO = SRE->hasSubsectionsViaSymbols(); |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 648 | if (Sym.getVariableValue()->evaluateAsRelocatableImpl( |
Rafael Espindola | aeed3cb | 2015-03-26 21:11:00 +0000 | [diff] [blame] | 649 | Res, Asm, Layout, Fixup, Addrs, InSet || IsMachO)) { |
| 650 | if (!IsMachO) |
Rafael Espindola | f275ad8 | 2015-03-25 13:16:53 +0000 | [diff] [blame] | 651 | return true; |
| 652 | |
Rafael Espindola | 7fadc0e | 2014-03-20 02:12:01 +0000 | [diff] [blame] | 653 | const MCSymbolRefExpr *A = Res.getSymA(); |
| 654 | const MCSymbolRefExpr *B = Res.getSymB(); |
Rafael Espindola | f275ad8 | 2015-03-25 13:16:53 +0000 | [diff] [blame] | 655 | // FIXME: This is small hack. Given |
| 656 | // a = b + 4 |
| 657 | // .long a |
| 658 | // the OS X assembler will completely drop the 4. We should probably |
| 659 | // include it in the relocation or produce an error if that is not |
| 660 | // possible. |
| 661 | if (!A && !B) |
| 662 | return true; |
Rafael Espindola | 7fadc0e | 2014-03-20 02:12:01 +0000 | [diff] [blame] | 663 | } |
Rafael Espindola | 8c3039b | 2010-11-15 16:33:49 +0000 | [diff] [blame] | 664 | } |
Daniel Dunbar | 17b9027 | 2009-10-16 01:33:57 +0000 | [diff] [blame] | 665 | |
Craig Topper | bb694de | 2014-04-13 04:57:38 +0000 | [diff] [blame] | 666 | Res = MCValue::get(SRE, nullptr, 0); |
Daniel Dunbar | 84bfd7b | 2009-06-29 20:40:36 +0000 | [diff] [blame] | 667 | return true; |
| 668 | } |
| 669 | |
| 670 | case Unary: { |
Daniel Dunbar | 115e4d6 | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 671 | const MCUnaryExpr *AUE = cast<MCUnaryExpr>(this); |
Daniel Dunbar | bd4bf3d | 2009-06-30 01:49:52 +0000 | [diff] [blame] | 672 | MCValue Value; |
Daniel Dunbar | 84bfd7b | 2009-06-29 20:40:36 +0000 | [diff] [blame] | 673 | |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 674 | if (!AUE->getSubExpr()->evaluateAsRelocatableImpl(Value, Asm, Layout, Fixup, |
Rafael Espindola | f275ad8 | 2015-03-25 13:16:53 +0000 | [diff] [blame] | 675 | Addrs, InSet)) |
Daniel Dunbar | 84bfd7b | 2009-06-29 20:40:36 +0000 | [diff] [blame] | 676 | return false; |
| 677 | |
| 678 | switch (AUE->getOpcode()) { |
Daniel Dunbar | 115e4d6 | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 679 | case MCUnaryExpr::LNot: |
Daniel Dunbar | 0d5fc9a | 2009-07-01 06:48:00 +0000 | [diff] [blame] | 680 | if (!Value.isAbsolute()) |
Daniel Dunbar | bd4bf3d | 2009-06-30 01:49:52 +0000 | [diff] [blame] | 681 | return false; |
| 682 | Res = MCValue::get(!Value.getConstant()); |
| 683 | break; |
Daniel Dunbar | 115e4d6 | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 684 | case MCUnaryExpr::Minus: |
Daniel Dunbar | bd4bf3d | 2009-06-30 01:49:52 +0000 | [diff] [blame] | 685 | /// -(a - b + const) ==> (b - a - const) |
Daniel Dunbar | 7f8a9eb | 2009-08-11 17:47:52 +0000 | [diff] [blame] | 686 | if (Value.getSymA() && !Value.getSymB()) |
Daniel Dunbar | bd4bf3d | 2009-06-30 01:49:52 +0000 | [diff] [blame] | 687 | return false; |
Daniel Dunbar | 9c64ec0 | 2010-03-18 00:59:10 +0000 | [diff] [blame] | 688 | Res = MCValue::get(Value.getSymB(), Value.getSymA(), |
| 689 | -Value.getConstant()); |
Daniel Dunbar | bd4bf3d | 2009-06-30 01:49:52 +0000 | [diff] [blame] | 690 | break; |
Daniel Dunbar | 115e4d6 | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 691 | case MCUnaryExpr::Not: |
Daniel Dunbar | 0d5fc9a | 2009-07-01 06:48:00 +0000 | [diff] [blame] | 692 | if (!Value.isAbsolute()) |
Daniel Dunbar | bd4bf3d | 2009-06-30 01:49:52 +0000 | [diff] [blame] | 693 | return false; |
Daniel Dunbar | 9c64ec0 | 2010-03-18 00:59:10 +0000 | [diff] [blame] | 694 | Res = MCValue::get(~Value.getConstant()); |
Daniel Dunbar | bd4bf3d | 2009-06-30 01:49:52 +0000 | [diff] [blame] | 695 | break; |
Daniel Dunbar | 115e4d6 | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 696 | case MCUnaryExpr::Plus: |
Daniel Dunbar | bd4bf3d | 2009-06-30 01:49:52 +0000 | [diff] [blame] | 697 | Res = Value; |
| 698 | break; |
Daniel Dunbar | 84bfd7b | 2009-06-29 20:40:36 +0000 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | return true; |
| 702 | } |
| 703 | |
| 704 | case Binary: { |
Daniel Dunbar | 115e4d6 | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 705 | const MCBinaryExpr *ABE = cast<MCBinaryExpr>(this); |
Daniel Dunbar | bd4bf3d | 2009-06-30 01:49:52 +0000 | [diff] [blame] | 706 | MCValue LHSValue, RHSValue; |
Daniel Dunbar | 9c64ec0 | 2010-03-18 00:59:10 +0000 | [diff] [blame] | 707 | |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 708 | if (!ABE->getLHS()->evaluateAsRelocatableImpl(LHSValue, Asm, Layout, Fixup, |
Rafael Espindola | f275ad8 | 2015-03-25 13:16:53 +0000 | [diff] [blame] | 709 | Addrs, InSet) || |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 710 | !ABE->getRHS()->evaluateAsRelocatableImpl(RHSValue, Asm, Layout, Fixup, |
Rafael Espindola | f275ad8 | 2015-03-25 13:16:53 +0000 | [diff] [blame] | 711 | Addrs, InSet)) |
Daniel Dunbar | 84bfd7b | 2009-06-29 20:40:36 +0000 | [diff] [blame] | 712 | return false; |
| 713 | |
Daniel Dunbar | bd4bf3d | 2009-06-30 01:49:52 +0000 | [diff] [blame] | 714 | // We only support a few operations on non-constant expressions, handle |
| 715 | // those first. |
Daniel Dunbar | 0d5fc9a | 2009-07-01 06:48:00 +0000 | [diff] [blame] | 716 | if (!LHSValue.isAbsolute() || !RHSValue.isAbsolute()) { |
Daniel Dunbar | bd4bf3d | 2009-06-30 01:49:52 +0000 | [diff] [blame] | 717 | switch (ABE->getOpcode()) { |
| 718 | default: |
| 719 | return false; |
Daniel Dunbar | 115e4d6 | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 720 | case MCBinaryExpr::Sub: |
Daniel Dunbar | 19f847f | 2009-06-30 02:08:27 +0000 | [diff] [blame] | 721 | // Negate RHS and add. |
Rafael Espindola | 5004f4a | 2010-12-18 03:57:21 +0000 | [diff] [blame] | 722 | return EvaluateSymbolicAdd(Asm, Layout, Addrs, InSet, LHSValue, |
Daniel Dunbar | 19f847f | 2009-06-30 02:08:27 +0000 | [diff] [blame] | 723 | RHSValue.getSymB(), RHSValue.getSymA(), |
Rafael Espindola | 59f90b2 | 2015-03-25 19:24:39 +0000 | [diff] [blame] | 724 | -RHSValue.getConstant(), Res); |
Daniel Dunbar | 19f847f | 2009-06-30 02:08:27 +0000 | [diff] [blame] | 725 | |
Daniel Dunbar | 115e4d6 | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 726 | case MCBinaryExpr::Add: |
Rafael Espindola | 5004f4a | 2010-12-18 03:57:21 +0000 | [diff] [blame] | 727 | return EvaluateSymbolicAdd(Asm, Layout, Addrs, InSet, LHSValue, |
Daniel Dunbar | 19f847f | 2009-06-30 02:08:27 +0000 | [diff] [blame] | 728 | RHSValue.getSymA(), RHSValue.getSymB(), |
Rafael Espindola | 59f90b2 | 2015-03-25 19:24:39 +0000 | [diff] [blame] | 729 | RHSValue.getConstant(), Res); |
Daniel Dunbar | bd4bf3d | 2009-06-30 01:49:52 +0000 | [diff] [blame] | 730 | } |
| 731 | } |
| 732 | |
Daniel Dunbar | 84bfd7b | 2009-06-29 20:40:36 +0000 | [diff] [blame] | 733 | // FIXME: We need target hooks for the evaluation. It may be limited in |
Ahmed Bougacha | 177c148 | 2015-04-28 00:21:32 +0000 | [diff] [blame] | 734 | // width, and gas defines the result of comparisons differently from |
| 735 | // Apple as. |
Daniel Dunbar | 3971273 | 2009-06-30 16:02:47 +0000 | [diff] [blame] | 736 | int64_t LHS = LHSValue.getConstant(), RHS = RHSValue.getConstant(); |
| 737 | int64_t Result = 0; |
Daniel Dunbar | 84bfd7b | 2009-06-29 20:40:36 +0000 | [diff] [blame] | 738 | switch (ABE->getOpcode()) { |
Ahmed Bougacha | 177c148 | 2015-04-28 00:21:32 +0000 | [diff] [blame] | 739 | case MCBinaryExpr::AShr: Result = LHS >> RHS; break; |
Daniel Dunbar | 115e4d6 | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 740 | case MCBinaryExpr::Add: Result = LHS + RHS; break; |
| 741 | case MCBinaryExpr::And: Result = LHS & RHS; break; |
Davide Italiano | 983366a | 2015-09-11 22:04:21 +0000 | [diff] [blame] | 742 | case MCBinaryExpr::Div: |
Davide Italiano | 63cee81 | 2015-09-11 20:47:35 +0000 | [diff] [blame] | 743 | // Handle division by zero. gas just emits a warning and keeps going, |
| 744 | // we try to be stricter. |
| 745 | // FIXME: Currently the caller of this function has no way to understand |
| 746 | // we're bailing out because of 'division by zero'. Therefore, it will |
| 747 | // emit a 'expected relocatable expression' error. It would be nice to |
| 748 | // change this code to emit a better diagnostic. |
| 749 | if (RHS == 0) |
| 750 | return false; |
Davide Italiano | 983366a | 2015-09-11 22:04:21 +0000 | [diff] [blame] | 751 | Result = LHS / RHS; |
| 752 | break; |
Daniel Dunbar | 115e4d6 | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 753 | case MCBinaryExpr::EQ: Result = LHS == RHS; break; |
| 754 | case MCBinaryExpr::GT: Result = LHS > RHS; break; |
| 755 | case MCBinaryExpr::GTE: Result = LHS >= RHS; break; |
| 756 | case MCBinaryExpr::LAnd: Result = LHS && RHS; break; |
| 757 | case MCBinaryExpr::LOr: Result = LHS || RHS; break; |
Ahmed Bougacha | 177c148 | 2015-04-28 00:21:32 +0000 | [diff] [blame] | 758 | case MCBinaryExpr::LShr: Result = uint64_t(LHS) >> uint64_t(RHS); break; |
Daniel Dunbar | 115e4d6 | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 759 | case MCBinaryExpr::LT: Result = LHS < RHS; break; |
| 760 | case MCBinaryExpr::LTE: Result = LHS <= RHS; break; |
| 761 | case MCBinaryExpr::Mod: Result = LHS % RHS; break; |
| 762 | case MCBinaryExpr::Mul: Result = LHS * RHS; break; |
| 763 | case MCBinaryExpr::NE: Result = LHS != RHS; break; |
| 764 | case MCBinaryExpr::Or: Result = LHS | RHS; break; |
Justin Bogner | c160215 | 2015-06-23 07:32:55 +0000 | [diff] [blame] | 765 | case MCBinaryExpr::Shl: Result = uint64_t(LHS) << uint64_t(RHS); break; |
Daniel Dunbar | 115e4d6 | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 766 | case MCBinaryExpr::Sub: Result = LHS - RHS; break; |
| 767 | case MCBinaryExpr::Xor: Result = LHS ^ RHS; break; |
Daniel Dunbar | 84bfd7b | 2009-06-29 20:40:36 +0000 | [diff] [blame] | 768 | } |
| 769 | |
Daniel Dunbar | bd4bf3d | 2009-06-30 01:49:52 +0000 | [diff] [blame] | 770 | Res = MCValue::get(Result); |
Daniel Dunbar | 84bfd7b | 2009-06-29 20:40:36 +0000 | [diff] [blame] | 771 | return true; |
| 772 | } |
| 773 | } |
Daniel Dunbar | 84bfd7b | 2009-06-29 20:40:36 +0000 | [diff] [blame] | 774 | |
Craig Topper | a2886c2 | 2012-02-07 05:05:23 +0000 | [diff] [blame] | 775 | llvm_unreachable("Invalid assembly expression kind!"); |
Daniel Dunbar | f363645 | 2009-08-31 08:07:22 +0000 | [diff] [blame] | 776 | } |
Daniel Dunbar | dc3e4cc | 2011-04-29 18:00:03 +0000 | [diff] [blame] | 777 | |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 778 | MCSection *MCExpr::findAssociatedSection() const { |
Daniel Dunbar | dc3e4cc | 2011-04-29 18:00:03 +0000 | [diff] [blame] | 779 | switch (getKind()) { |
| 780 | case Target: |
| 781 | // We never look through target specific expressions. |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 782 | return cast<MCTargetExpr>(this)->findAssociatedSection(); |
Daniel Dunbar | dc3e4cc | 2011-04-29 18:00:03 +0000 | [diff] [blame] | 783 | |
| 784 | case Constant: |
| 785 | return MCSymbol::AbsolutePseudoSection; |
| 786 | |
| 787 | case SymbolRef: { |
| 788 | const MCSymbolRefExpr *SRE = cast<MCSymbolRefExpr>(this); |
| 789 | const MCSymbol &Sym = SRE->getSymbol(); |
| 790 | |
| 791 | if (Sym.isDefined()) |
| 792 | return &Sym.getSection(); |
| 793 | |
Craig Topper | bb694de | 2014-04-13 04:57:38 +0000 | [diff] [blame] | 794 | return nullptr; |
Daniel Dunbar | dc3e4cc | 2011-04-29 18:00:03 +0000 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | case Unary: |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 798 | return cast<MCUnaryExpr>(this)->getSubExpr()->findAssociatedSection(); |
Daniel Dunbar | dc3e4cc | 2011-04-29 18:00:03 +0000 | [diff] [blame] | 799 | |
| 800 | case Binary: { |
| 801 | const MCBinaryExpr *BE = cast<MCBinaryExpr>(this); |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 802 | MCSection *LHS_S = BE->getLHS()->findAssociatedSection(); |
| 803 | MCSection *RHS_S = BE->getRHS()->findAssociatedSection(); |
Daniel Dunbar | dc3e4cc | 2011-04-29 18:00:03 +0000 | [diff] [blame] | 804 | |
| 805 | // If either section is absolute, return the other. |
| 806 | if (LHS_S == MCSymbol::AbsolutePseudoSection) |
| 807 | return RHS_S; |
| 808 | if (RHS_S == MCSymbol::AbsolutePseudoSection) |
| 809 | return LHS_S; |
| 810 | |
Peter Collingbourne | 10d362c | 2015-04-03 01:46:11 +0000 | [diff] [blame] | 811 | // Not always correct, but probably the best we can do without more context. |
| 812 | if (BE->getOpcode() == MCBinaryExpr::Sub) |
| 813 | return MCSymbol::AbsolutePseudoSection; |
| 814 | |
Daniel Dunbar | dc3e4cc | 2011-04-29 18:00:03 +0000 | [diff] [blame] | 815 | // Otherwise, return the first non-null section. |
| 816 | return LHS_S ? LHS_S : RHS_S; |
| 817 | } |
| 818 | } |
| 819 | |
Craig Topper | a2886c2 | 2012-02-07 05:05:23 +0000 | [diff] [blame] | 820 | llvm_unreachable("Invalid assembly expression kind!"); |
Daniel Dunbar | dc3e4cc | 2011-04-29 18:00:03 +0000 | [diff] [blame] | 821 | } |