Daniel Dunbar | 28c251b | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 1 | //===- MCExpr.cpp - Assembly Level Expression Implementation --------------===// |
Daniel Dunbar | fc6877a | 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 | |
Chandler Carruth | e3e43d9 | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 10 | #include "llvm/MC/MCExpr.h" |
Daniel Dunbar | ff54784 | 2010-03-23 23:47:14 +0000 | [diff] [blame] | 11 | #include "llvm/ADT/Statistic.h" |
Daniel Dunbar | 4e815f8 | 2010-03-15 23:51:06 +0000 | [diff] [blame] | 12 | #include "llvm/ADT/StringSwitch.h" |
Nico Weber | 0f38c60 | 2018-04-30 14:59:11 +0000 | [diff] [blame] | 13 | #include "llvm/Config/llvm-config.h" |
Alex Bradbury | e54d539 | 2018-05-23 12:36:18 +0000 | [diff] [blame] | 14 | #include "llvm/MC/MCAsmBackend.h" |
David Peixotto | 0fc8c68 | 2013-12-04 22:43:20 +0000 | [diff] [blame] | 15 | #include "llvm/MC/MCAsmInfo.h" |
Daniel Dunbar | 979ba5b | 2010-03-11 05:53:37 +0000 | [diff] [blame] | 16 | #include "llvm/MC/MCAsmLayout.h" |
| 17 | #include "llvm/MC/MCAssembler.h" |
Daniel Dunbar | fc6877a | 2009-06-29 20:40:36 +0000 | [diff] [blame] | 18 | #include "llvm/MC/MCContext.h" |
Craig Topper | f1d0f77 | 2012-03-26 06:58:25 +0000 | [diff] [blame] | 19 | #include "llvm/MC/MCObjectWriter.h" |
Daniel Dunbar | 15d1707 | 2009-06-30 01:49:52 +0000 | [diff] [blame] | 20 | #include "llvm/MC/MCSymbol.h" |
Daniel Dunbar | fc6877a | 2009-06-29 20:40:36 +0000 | [diff] [blame] | 21 | #include "llvm/MC/MCValue.h" |
Eugene Zelenko | f31871c | 2017-02-07 23:02:00 +0000 | [diff] [blame] | 22 | #include "llvm/Support/Casting.h" |
| 23 | #include "llvm/Support/Compiler.h" |
David Greene | 5d2bcb1 | 2010-01-05 01:28:07 +0000 | [diff] [blame] | 24 | #include "llvm/Support/Debug.h" |
Chandler Carruth | 732f05c | 2012-01-10 18:08:01 +0000 | [diff] [blame] | 25 | #include "llvm/Support/ErrorHandling.h" |
Daniel Dunbar | 87392fd | 2009-08-31 08:07:33 +0000 | [diff] [blame] | 26 | #include "llvm/Support/raw_ostream.h" |
Eugene Zelenko | f31871c | 2017-02-07 23:02:00 +0000 | [diff] [blame] | 27 | #include <cassert> |
| 28 | #include <cstdint> |
| 29 | |
Daniel Dunbar | fc6877a | 2009-06-29 20:40:36 +0000 | [diff] [blame] | 30 | using namespace llvm; |
| 31 | |
Chandler Carruth | 0d338a5 | 2014-04-22 03:04:17 +0000 | [diff] [blame] | 32 | #define DEBUG_TYPE "mcexpr" |
| 33 | |
Daniel Dunbar | ff54784 | 2010-03-23 23:47:14 +0000 | [diff] [blame] | 34 | namespace { |
| 35 | namespace stats { |
Eugene Zelenko | f31871c | 2017-02-07 23:02:00 +0000 | [diff] [blame] | 36 | |
Daniel Dunbar | ff54784 | 2010-03-23 23:47:14 +0000 | [diff] [blame] | 37 | STATISTIC(MCExprEvaluate, "Number of MCExpr evaluations"); |
Eugene Zelenko | f31871c | 2017-02-07 23:02:00 +0000 | [diff] [blame] | 38 | |
| 39 | } // end namespace stats |
| 40 | } // end anonymous namespace |
Daniel Dunbar | ff54784 | 2010-03-23 23:47:14 +0000 | [diff] [blame] | 41 | |
Daniel Sanders | c8b0a11 | 2016-05-03 13:35:44 +0000 | [diff] [blame] | 42 | void MCExpr::print(raw_ostream &OS, const MCAsmInfo *MAI, bool InParens) const { |
Daniel Dunbar | 87392fd | 2009-08-31 08:07:33 +0000 | [diff] [blame] | 43 | switch (getKind()) { |
Chris Lattner | 5d917a8 | 2010-02-08 19:41:07 +0000 | [diff] [blame] | 44 | case MCExpr::Target: |
Matt Arsenault | d99ce2f | 2015-06-09 00:31:39 +0000 | [diff] [blame] | 45 | return cast<MCTargetExpr>(this)->printImpl(OS, MAI); |
Daniel Dunbar | 87392fd | 2009-08-31 08:07:33 +0000 | [diff] [blame] | 46 | case MCExpr::Constant: |
| 47 | OS << cast<MCConstantExpr>(*this).getValue(); |
| 48 | return; |
| 49 | |
Chris Lattner | d50c2b9 | 2009-09-08 23:20:50 +0000 | [diff] [blame] | 50 | case MCExpr::SymbolRef: { |
Daniel Dunbar | 4e815f8 | 2010-03-15 23:51:06 +0000 | [diff] [blame] | 51 | const MCSymbolRefExpr &SRE = cast<MCSymbolRefExpr>(*this); |
| 52 | const MCSymbol &Sym = SRE.getSymbol(); |
Chris Lattner | 1e61e69 | 2010-11-15 02:46:57 +0000 | [diff] [blame] | 53 | // Parenthesize names that start with $ so that they don't look like |
| 54 | // absolute names. |
Daniel Sanders | c8b0a11 | 2016-05-03 13:35:44 +0000 | [diff] [blame] | 55 | bool UseParens = |
Eugene Zelenko | f31871c | 2017-02-07 23:02:00 +0000 | [diff] [blame] | 56 | !InParens && !Sym.getName().empty() && Sym.getName()[0] == '$'; |
Matt Arsenault | d99ce2f | 2015-06-09 00:31:39 +0000 | [diff] [blame] | 57 | if (UseParens) { |
| 58 | OS << '('; |
| 59 | Sym.print(OS, MAI); |
| 60 | OS << ')'; |
| 61 | } else |
| 62 | Sym.print(OS, MAI); |
Daniel Dunbar | 4e815f8 | 2010-03-15 23:51:06 +0000 | [diff] [blame] | 63 | |
Benjamin Kramer | b1bba1a | 2014-10-11 17:57:27 +0000 | [diff] [blame] | 64 | if (SRE.getKind() != MCSymbolRefExpr::VK_None) |
| 65 | SRE.printVariantKind(OS); |
Daniel Dunbar | 4e815f8 | 2010-03-15 23:51:06 +0000 | [diff] [blame] | 66 | |
Daniel Dunbar | 87392fd | 2009-08-31 08:07:33 +0000 | [diff] [blame] | 67 | return; |
Chris Lattner | d50c2b9 | 2009-09-08 23:20:50 +0000 | [diff] [blame] | 68 | } |
Daniel Dunbar | 87392fd | 2009-08-31 08:07:33 +0000 | [diff] [blame] | 69 | |
| 70 | case MCExpr::Unary: { |
| 71 | const MCUnaryExpr &UE = cast<MCUnaryExpr>(*this); |
| 72 | switch (UE.getOpcode()) { |
Daniel Dunbar | 87392fd | 2009-08-31 08:07:33 +0000 | [diff] [blame] | 73 | case MCUnaryExpr::LNot: OS << '!'; break; |
| 74 | case MCUnaryExpr::Minus: OS << '-'; break; |
| 75 | case MCUnaryExpr::Not: OS << '~'; break; |
| 76 | case MCUnaryExpr::Plus: OS << '+'; break; |
| 77 | } |
Bill Wendling | 558d724 | 2018-05-14 05:25:36 +0000 | [diff] [blame] | 78 | bool Binary = UE.getSubExpr()->getKind() == MCExpr::Binary; |
| 79 | if (Binary) OS << "("; |
Matt Arsenault | d99ce2f | 2015-06-09 00:31:39 +0000 | [diff] [blame] | 80 | UE.getSubExpr()->print(OS, MAI); |
Bill Wendling | 558d724 | 2018-05-14 05:25:36 +0000 | [diff] [blame] | 81 | if (Binary) OS << ")"; |
Daniel Dunbar | 87392fd | 2009-08-31 08:07:33 +0000 | [diff] [blame] | 82 | return; |
| 83 | } |
| 84 | |
| 85 | case MCExpr::Binary: { |
| 86 | const MCBinaryExpr &BE = cast<MCBinaryExpr>(*this); |
Daniel Dunbar | 9a1d200 | 2010-03-18 00:59:10 +0000 | [diff] [blame] | 87 | |
Chris Lattner | be73e8c | 2009-09-08 06:34:07 +0000 | [diff] [blame] | 88 | // Only print parens around the LHS if it is non-trivial. |
| 89 | if (isa<MCConstantExpr>(BE.getLHS()) || isa<MCSymbolRefExpr>(BE.getLHS())) { |
Matt Arsenault | d99ce2f | 2015-06-09 00:31:39 +0000 | [diff] [blame] | 90 | BE.getLHS()->print(OS, MAI); |
Chris Lattner | be73e8c | 2009-09-08 06:34:07 +0000 | [diff] [blame] | 91 | } else { |
Matt Arsenault | d99ce2f | 2015-06-09 00:31:39 +0000 | [diff] [blame] | 92 | OS << '('; |
| 93 | BE.getLHS()->print(OS, MAI); |
| 94 | OS << ')'; |
Chris Lattner | be73e8c | 2009-09-08 06:34:07 +0000 | [diff] [blame] | 95 | } |
Daniel Dunbar | 9a1d200 | 2010-03-18 00:59:10 +0000 | [diff] [blame] | 96 | |
Daniel Dunbar | 87392fd | 2009-08-31 08:07:33 +0000 | [diff] [blame] | 97 | switch (BE.getOpcode()) { |
Chris Lattner | d19ceb9 | 2009-09-08 06:37:35 +0000 | [diff] [blame] | 98 | case MCBinaryExpr::Add: |
| 99 | // Print "X-42" instead of "X+-42". |
| 100 | if (const MCConstantExpr *RHSC = dyn_cast<MCConstantExpr>(BE.getRHS())) { |
| 101 | if (RHSC->getValue() < 0) { |
| 102 | OS << RHSC->getValue(); |
| 103 | return; |
| 104 | } |
| 105 | } |
Daniel Dunbar | 9a1d200 | 2010-03-18 00:59:10 +0000 | [diff] [blame] | 106 | |
Chris Lattner | d19ceb9 | 2009-09-08 06:37:35 +0000 | [diff] [blame] | 107 | OS << '+'; |
| 108 | break; |
Ahmed Bougacha | dac39b1 | 2015-04-28 00:21:32 +0000 | [diff] [blame] | 109 | case MCBinaryExpr::AShr: OS << ">>"; break; |
Daniel Dunbar | 87392fd | 2009-08-31 08:07:33 +0000 | [diff] [blame] | 110 | case MCBinaryExpr::And: OS << '&'; break; |
| 111 | case MCBinaryExpr::Div: OS << '/'; break; |
| 112 | case MCBinaryExpr::EQ: OS << "=="; break; |
| 113 | case MCBinaryExpr::GT: OS << '>'; break; |
| 114 | case MCBinaryExpr::GTE: OS << ">="; break; |
| 115 | case MCBinaryExpr::LAnd: OS << "&&"; break; |
| 116 | case MCBinaryExpr::LOr: OS << "||"; break; |
Ahmed Bougacha | dac39b1 | 2015-04-28 00:21:32 +0000 | [diff] [blame] | 117 | case MCBinaryExpr::LShr: OS << ">>"; break; |
Daniel Dunbar | 87392fd | 2009-08-31 08:07:33 +0000 | [diff] [blame] | 118 | case MCBinaryExpr::LT: OS << '<'; break; |
| 119 | case MCBinaryExpr::LTE: OS << "<="; break; |
| 120 | case MCBinaryExpr::Mod: OS << '%'; break; |
| 121 | case MCBinaryExpr::Mul: OS << '*'; break; |
| 122 | case MCBinaryExpr::NE: OS << "!="; break; |
| 123 | case MCBinaryExpr::Or: OS << '|'; break; |
| 124 | case MCBinaryExpr::Shl: OS << "<<"; break; |
Daniel Dunbar | 87392fd | 2009-08-31 08:07:33 +0000 | [diff] [blame] | 125 | case MCBinaryExpr::Sub: OS << '-'; break; |
| 126 | case MCBinaryExpr::Xor: OS << '^'; break; |
| 127 | } |
Daniel Dunbar | 9a1d200 | 2010-03-18 00:59:10 +0000 | [diff] [blame] | 128 | |
Chris Lattner | be73e8c | 2009-09-08 06:34:07 +0000 | [diff] [blame] | 129 | // Only print parens around the LHS if it is non-trivial. |
| 130 | if (isa<MCConstantExpr>(BE.getRHS()) || isa<MCSymbolRefExpr>(BE.getRHS())) { |
Matt Arsenault | d99ce2f | 2015-06-09 00:31:39 +0000 | [diff] [blame] | 131 | BE.getRHS()->print(OS, MAI); |
Chris Lattner | be73e8c | 2009-09-08 06:34:07 +0000 | [diff] [blame] | 132 | } else { |
Matt Arsenault | d99ce2f | 2015-06-09 00:31:39 +0000 | [diff] [blame] | 133 | OS << '('; |
| 134 | BE.getRHS()->print(OS, MAI); |
| 135 | OS << ')'; |
Chris Lattner | be73e8c | 2009-09-08 06:34:07 +0000 | [diff] [blame] | 136 | } |
Daniel Dunbar | 87392fd | 2009-08-31 08:07:33 +0000 | [diff] [blame] | 137 | return; |
| 138 | } |
| 139 | } |
| 140 | |
Craig Topper | 8581438 | 2012-02-07 05:05:23 +0000 | [diff] [blame] | 141 | llvm_unreachable("Invalid expression kind!"); |
Daniel Dunbar | 87392fd | 2009-08-31 08:07:33 +0000 | [diff] [blame] | 142 | } |
| 143 | |
Aaron Ballman | 1d03d38 | 2017-10-15 14:32:27 +0000 | [diff] [blame] | 144 | #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) |
Yaron Keren | 5530798 | 2016-01-29 20:50:44 +0000 | [diff] [blame] | 145 | LLVM_DUMP_METHOD void MCExpr::dump() const { |
Rafael Espindola | eac1f66 | 2015-05-27 13:05:42 +0000 | [diff] [blame] | 146 | dbgs() << *this; |
David Greene | 5d2bcb1 | 2010-01-05 01:28:07 +0000 | [diff] [blame] | 147 | dbgs() << '\n'; |
Daniel Dunbar | 87392fd | 2009-08-31 08:07:33 +0000 | [diff] [blame] | 148 | } |
Matthias Braun | 88d2075 | 2017-01-28 02:02:38 +0000 | [diff] [blame] | 149 | #endif |
Daniel Dunbar | 87392fd | 2009-08-31 08:07:33 +0000 | [diff] [blame] | 150 | |
| 151 | /* *** */ |
| 152 | |
Jim Grosbach | 586c004 | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 153 | const MCBinaryExpr *MCBinaryExpr::create(Opcode Opc, const MCExpr *LHS, |
Chad Rosier | b1330a5 | 2017-01-19 20:06:32 +0000 | [diff] [blame] | 154 | const MCExpr *RHS, MCContext &Ctx, |
| 155 | SMLoc Loc) { |
| 156 | return new (Ctx) MCBinaryExpr(Opc, LHS, RHS, Loc); |
Daniel Dunbar | fc6877a | 2009-06-29 20:40:36 +0000 | [diff] [blame] | 157 | } |
| 158 | |
Jim Grosbach | 586c004 | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 159 | const MCUnaryExpr *MCUnaryExpr::create(Opcode Opc, const MCExpr *Expr, |
Sanne Wouda | 9f316a5 | 2017-03-10 13:08:20 +0000 | [diff] [blame] | 160 | MCContext &Ctx, SMLoc Loc) { |
| 161 | return new (Ctx) MCUnaryExpr(Opc, Expr, Loc); |
Daniel Dunbar | 9643ac5 | 2009-08-31 08:07:22 +0000 | [diff] [blame] | 162 | } |
| 163 | |
Jim Grosbach | 586c004 | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 164 | const MCConstantExpr *MCConstantExpr::create(int64_t Value, MCContext &Ctx) { |
Daniel Dunbar | 9643ac5 | 2009-08-31 08:07:22 +0000 | [diff] [blame] | 165 | return new (Ctx) MCConstantExpr(Value); |
| 166 | } |
| 167 | |
Daniel Dunbar | 4e815f8 | 2010-03-15 23:51:06 +0000 | [diff] [blame] | 168 | /* *** */ |
| 169 | |
Benjamin Kramer | b1bba1a | 2014-10-11 17:57:27 +0000 | [diff] [blame] | 170 | MCSymbolRefExpr::MCSymbolRefExpr(const MCSymbol *Symbol, VariantKind Kind, |
Chad Rosier | b1330a5 | 2017-01-19 20:06:32 +0000 | [diff] [blame] | 171 | const MCAsmInfo *MAI, SMLoc Loc) |
| 172 | : MCExpr(MCExpr::SymbolRef, Loc), Kind(Kind), |
Benjamin Kramer | b1bba1a | 2014-10-11 17:57:27 +0000 | [diff] [blame] | 173 | UseParensForSymbolVariant(MAI->useParensForSymbolVariant()), |
| 174 | HasSubsectionsViaSymbols(MAI->hasSubsectionsViaSymbols()), |
| 175 | Symbol(Symbol) { |
| 176 | assert(Symbol); |
| 177 | } |
| 178 | |
Jim Grosbach | 586c004 | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 179 | const MCSymbolRefExpr *MCSymbolRefExpr::create(const MCSymbol *Sym, |
Daniel Dunbar | 4e815f8 | 2010-03-15 23:51:06 +0000 | [diff] [blame] | 180 | VariantKind Kind, |
Chad Rosier | b1330a5 | 2017-01-19 20:06:32 +0000 | [diff] [blame] | 181 | MCContext &Ctx, SMLoc Loc) { |
| 182 | return new (Ctx) MCSymbolRefExpr(Sym, Kind, Ctx.getAsmInfo(), Loc); |
Daniel Dunbar | 9643ac5 | 2009-08-31 08:07:22 +0000 | [diff] [blame] | 183 | } |
| 184 | |
Jim Grosbach | 586c004 | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 185 | const MCSymbolRefExpr *MCSymbolRefExpr::create(StringRef Name, VariantKind Kind, |
Daniel Dunbar | 4e815f8 | 2010-03-15 23:51:06 +0000 | [diff] [blame] | 186 | MCContext &Ctx) { |
Jim Grosbach | 586c004 | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 187 | return create(Ctx.getOrCreateSymbol(Name), Kind, Ctx); |
Chris Lattner | 4f3e7aa | 2009-09-16 01:26:31 +0000 | [diff] [blame] | 188 | } |
| 189 | |
Daniel Dunbar | 4e815f8 | 2010-03-15 23:51:06 +0000 | [diff] [blame] | 190 | StringRef MCSymbolRefExpr::getVariantKindName(VariantKind Kind) { |
| 191 | switch (Kind) { |
Daniel Dunbar | 4e815f8 | 2010-03-15 23:51:06 +0000 | [diff] [blame] | 192 | case VK_Invalid: return "<<invalid>>"; |
| 193 | case VK_None: return "<<none>>"; |
| 194 | |
Colin LeMahieu | 89dcdff | 2016-02-10 18:32:01 +0000 | [diff] [blame] | 195 | case VK_DTPOFF: return "DTPOFF"; |
| 196 | case VK_DTPREL: return "DTPREL"; |
Daniel Dunbar | 4e815f8 | 2010-03-15 23:51:06 +0000 | [diff] [blame] | 197 | case VK_GOT: return "GOT"; |
| 198 | case VK_GOTOFF: return "GOTOFF"; |
Colin LeMahieu | 3f9e772 | 2016-02-09 19:17:34 +0000 | [diff] [blame] | 199 | case VK_GOTREL: return "GOTREL"; |
Daniel Dunbar | 4e815f8 | 2010-03-15 23:51:06 +0000 | [diff] [blame] | 200 | case VK_GOTPCREL: return "GOTPCREL"; |
| 201 | case VK_GOTTPOFF: return "GOTTPOFF"; |
| 202 | case VK_INDNTPOFF: return "INDNTPOFF"; |
| 203 | case VK_NTPOFF: return "NTPOFF"; |
Rafael Espindola | a0a2f87 | 2010-10-28 14:22:44 +0000 | [diff] [blame] | 204 | case VK_GOTNTPOFF: return "GOTNTPOFF"; |
Daniel Dunbar | 4e815f8 | 2010-03-15 23:51:06 +0000 | [diff] [blame] | 205 | case VK_PLT: return "PLT"; |
| 206 | case VK_TLSGD: return "TLSGD"; |
Rafael Espindola | b4d1721 | 2010-10-28 15:02:40 +0000 | [diff] [blame] | 207 | case VK_TLSLD: return "TLSLD"; |
Rafael Espindola | a264f72 | 2010-10-28 14:37:09 +0000 | [diff] [blame] | 208 | case VK_TLSLDM: return "TLSLDM"; |
Daniel Dunbar | 4e815f8 | 2010-03-15 23:51:06 +0000 | [diff] [blame] | 209 | case VK_TPOFF: return "TPOFF"; |
Colin LeMahieu | 89dcdff | 2016-02-10 18:32:01 +0000 | [diff] [blame] | 210 | case VK_TPREL: return "TPREL"; |
Davide Italiano | 3255600 | 2016-03-15 00:25:22 +0000 | [diff] [blame] | 211 | case VK_TLSCALL: return "tlscall"; |
Davide Italiano | 87a6f75 | 2016-03-15 17:29:52 +0000 | [diff] [blame] | 212 | case VK_TLSDESC: return "tlsdesc"; |
Chris Lattner | 6135a96 | 2010-11-14 22:22:59 +0000 | [diff] [blame] | 213 | case VK_TLVP: return "TLVP"; |
Tim Northover | 7b837d8 | 2014-03-29 10:18:08 +0000 | [diff] [blame] | 214 | case VK_TLVPPAGE: return "TLVPPAGE"; |
| 215 | case VK_TLVPPAGEOFF: return "TLVPPAGEOFF"; |
| 216 | case VK_PAGE: return "PAGE"; |
| 217 | case VK_PAGEOFF: return "PAGEOFF"; |
| 218 | case VK_GOTPAGE: return "GOTPAGE"; |
| 219 | case VK_GOTPAGEOFF: return "GOTPAGEOFF"; |
Benjamin Kramer | 42734cf | 2013-03-30 16:21:50 +0000 | [diff] [blame] | 220 | case VK_SECREL: return "SECREL32"; |
Davide Italiano | 8667ab7 | 2015-03-04 06:49:39 +0000 | [diff] [blame] | 221 | case VK_SIZE: return "SIZE"; |
Rafael Espindola | 0a70f9b | 2014-03-20 02:12:01 +0000 | [diff] [blame] | 222 | case VK_WEAKREF: return "WEAKREF"; |
Peter Collingbourne | 043d1a9 | 2017-01-31 18:28:44 +0000 | [diff] [blame] | 223 | case VK_X86_ABS8: return "ABS8"; |
David Peixotto | 0fc8c68 | 2013-12-04 22:43:20 +0000 | [diff] [blame] | 224 | case VK_ARM_NONE: return "none"; |
Peter Collingbourne | 7da5357 | 2015-10-26 18:23:16 +0000 | [diff] [blame] | 225 | case VK_ARM_GOT_PREL: return "GOT_PREL"; |
David Peixotto | 0fc8c68 | 2013-12-04 22:43:20 +0000 | [diff] [blame] | 226 | case VK_ARM_TARGET1: return "target1"; |
| 227 | case VK_ARM_TARGET2: return "target2"; |
| 228 | case VK_ARM_PREL31: return "prel31"; |
Saleem Abdulrasool | 5e3c87e | 2015-01-11 04:39:18 +0000 | [diff] [blame] | 229 | case VK_ARM_SBREL: return "sbrel"; |
Kai Nacke | 843fa74 | 2014-01-20 11:00:40 +0000 | [diff] [blame] | 230 | case VK_ARM_TLSLDO: return "tlsldo"; |
Saleem Abdulrasool | 2c9ed5d | 2014-01-30 04:02:47 +0000 | [diff] [blame] | 231 | case VK_ARM_TLSDESCSEQ: return "tlsdescseq"; |
Dylan McKay | 4f04548 | 2017-12-09 08:01:28 +0000 | [diff] [blame] | 232 | case VK_AVR_NONE: return "none"; |
| 233 | case VK_AVR_LO8: return "lo8"; |
| 234 | case VK_AVR_HI8: return "hi8"; |
| 235 | case VK_AVR_HLO8: return "hlo8"; |
| 236 | case VK_AVR_DIFF8: return "diff8"; |
| 237 | case VK_AVR_DIFF16: return "diff16"; |
| 238 | case VK_AVR_DIFF32: return "diff32"; |
Ulrich Weigand | 92cfa61 | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 239 | case VK_PPC_LO: return "l"; |
Ulrich Weigand | d284957 | 2013-06-21 14:42:49 +0000 | [diff] [blame] | 240 | case VK_PPC_HI: return "h"; |
Ulrich Weigand | 92cfa61 | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 241 | case VK_PPC_HA: return "ha"; |
Sean Fertile | 80cb547 | 2018-06-15 19:47:11 +0000 | [diff] [blame] | 242 | case VK_PPC_HIGH: return "high"; |
| 243 | case VK_PPC_HIGHA: return "higha"; |
Ulrich Weigand | f7c1ee7 | 2013-06-21 14:43:42 +0000 | [diff] [blame] | 244 | case VK_PPC_HIGHER: return "higher"; |
| 245 | case VK_PPC_HIGHERA: return "highera"; |
| 246 | case VK_PPC_HIGHEST: return "highest"; |
| 247 | case VK_PPC_HIGHESTA: return "highesta"; |
Ulrich Weigand | 5de735a | 2013-06-25 16:49:50 +0000 | [diff] [blame] | 248 | case VK_PPC_GOT_LO: return "got@l"; |
| 249 | case VK_PPC_GOT_HI: return "got@h"; |
| 250 | case VK_PPC_GOT_HA: return "got@ha"; |
Ulrich Weigand | 8465659 | 2013-06-20 22:39:42 +0000 | [diff] [blame] | 251 | case VK_PPC_TOCBASE: return "tocbase"; |
Ulrich Weigand | 92cfa61 | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 252 | case VK_PPC_TOC: return "toc"; |
| 253 | case VK_PPC_TOC_LO: return "toc@l"; |
Ulrich Weigand | f8f87dc | 2013-06-21 14:43:10 +0000 | [diff] [blame] | 254 | case VK_PPC_TOC_HI: return "toc@h"; |
Ulrich Weigand | 92cfa61 | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 255 | case VK_PPC_TOC_HA: return "toc@ha"; |
Ulrich Weigand | 228e0af | 2013-07-01 23:33:29 +0000 | [diff] [blame] | 256 | case VK_PPC_DTPMOD: return "dtpmod"; |
Ulrich Weigand | 92cfa61 | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 257 | case VK_PPC_TPREL_LO: return "tprel@l"; |
Ulrich Weigand | cab0a19 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 258 | case VK_PPC_TPREL_HI: return "tprel@h"; |
Ulrich Weigand | 92cfa61 | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 259 | case VK_PPC_TPREL_HA: return "tprel@ha"; |
Sean Fertile | a244853 | 2018-06-15 19:47:16 +0000 | [diff] [blame] | 260 | case VK_PPC_TPREL_HIGH: return "tprel@high"; |
| 261 | case VK_PPC_TPREL_HIGHA: return "tprel@higha"; |
Ulrich Weigand | cab0a19 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 262 | case VK_PPC_TPREL_HIGHER: return "tprel@higher"; |
| 263 | case VK_PPC_TPREL_HIGHERA: return "tprel@highera"; |
| 264 | case VK_PPC_TPREL_HIGHEST: return "tprel@highest"; |
| 265 | case VK_PPC_TPREL_HIGHESTA: return "tprel@highesta"; |
Ulrich Weigand | 92cfa61 | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 266 | case VK_PPC_DTPREL_LO: return "dtprel@l"; |
Ulrich Weigand | cab0a19 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 267 | case VK_PPC_DTPREL_HI: return "dtprel@h"; |
Ulrich Weigand | 92cfa61 | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 268 | case VK_PPC_DTPREL_HA: return "dtprel@ha"; |
Sean Fertile | a244853 | 2018-06-15 19:47:16 +0000 | [diff] [blame] | 269 | case VK_PPC_DTPREL_HIGH: return "dtprel@high"; |
| 270 | case VK_PPC_DTPREL_HIGHA: return "dtprel@higha"; |
Ulrich Weigand | cab0a19 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 271 | case VK_PPC_DTPREL_HIGHER: return "dtprel@higher"; |
| 272 | case VK_PPC_DTPREL_HIGHERA: return "dtprel@highera"; |
| 273 | case VK_PPC_DTPREL_HIGHEST: return "dtprel@highest"; |
| 274 | case VK_PPC_DTPREL_HIGHESTA: return "dtprel@highesta"; |
| 275 | case VK_PPC_GOT_TPREL: return "got@tprel"; |
Ulrich Weigand | 92cfa61 | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 276 | case VK_PPC_GOT_TPREL_LO: return "got@tprel@l"; |
Ulrich Weigand | cab0a19 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 277 | case VK_PPC_GOT_TPREL_HI: return "got@tprel@h"; |
Ulrich Weigand | 92cfa61 | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 278 | case VK_PPC_GOT_TPREL_HA: return "got@tprel@ha"; |
Ulrich Weigand | cab0a19 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 279 | case VK_PPC_GOT_DTPREL: return "got@dtprel"; |
| 280 | case VK_PPC_GOT_DTPREL_LO: return "got@dtprel@l"; |
| 281 | case VK_PPC_GOT_DTPREL_HI: return "got@dtprel@h"; |
| 282 | case VK_PPC_GOT_DTPREL_HA: return "got@dtprel@ha"; |
Bill Schmidt | d7802bf | 2012-12-04 16:18:08 +0000 | [diff] [blame] | 283 | case VK_PPC_TLS: return "tls"; |
Ulrich Weigand | cab0a19 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 284 | case VK_PPC_GOT_TLSGD: return "got@tlsgd"; |
Ulrich Weigand | 92cfa61 | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 285 | case VK_PPC_GOT_TLSGD_LO: return "got@tlsgd@l"; |
Ulrich Weigand | cab0a19 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 286 | case VK_PPC_GOT_TLSGD_HI: return "got@tlsgd@h"; |
Ulrich Weigand | 92cfa61 | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 287 | case VK_PPC_GOT_TLSGD_HA: return "got@tlsgd@ha"; |
Ulrich Weigand | 7a34599 | 2013-07-09 16:41:09 +0000 | [diff] [blame] | 288 | case VK_PPC_TLSGD: return "tlsgd"; |
Ulrich Weigand | cab0a19 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 289 | case VK_PPC_GOT_TLSLD: return "got@tlsld"; |
Ulrich Weigand | 92cfa61 | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 290 | case VK_PPC_GOT_TLSLD_LO: return "got@tlsld@l"; |
Ulrich Weigand | cab0a19 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 291 | case VK_PPC_GOT_TLSLD_HI: return "got@tlsld@h"; |
Ulrich Weigand | 92cfa61 | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 292 | case VK_PPC_GOT_TLSLD_HA: return "got@tlsld@ha"; |
Ulrich Weigand | 7a34599 | 2013-07-09 16:41:09 +0000 | [diff] [blame] | 293 | case VK_PPC_TLSLD: return "tlsld"; |
Justin Hibbits | fcd08c2 | 2014-11-12 15:16:30 +0000 | [diff] [blame] | 294 | case VK_PPC_LOCAL: return "local"; |
Reid Kleckner | dd8ce12 | 2014-09-25 02:09:18 +0000 | [diff] [blame] | 295 | case VK_COFF_IMGREL32: return "IMGREL"; |
Colin LeMahieu | a036240 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 296 | case VK_Hexagon_PCREL: return "PCREL"; |
| 297 | case VK_Hexagon_LO16: return "LO16"; |
| 298 | case VK_Hexagon_HI16: return "HI16"; |
| 299 | case VK_Hexagon_GPREL: return "GPREL"; |
| 300 | case VK_Hexagon_GD_GOT: return "GDGOT"; |
| 301 | case VK_Hexagon_LD_GOT: return "LDGOT"; |
| 302 | case VK_Hexagon_GD_PLT: return "GDPLT"; |
| 303 | case VK_Hexagon_LD_PLT: return "LDPLT"; |
| 304 | case VK_Hexagon_IE: return "IE"; |
| 305 | case VK_Hexagon_IE_GOT: return "IEGOT"; |
Dan Gohman | d73b41a | 2016-01-11 23:38:05 +0000 | [diff] [blame] | 306 | case VK_WebAssembly_FUNCTION: return "FUNCTION"; |
Nicholas Wilson | 54c1354 | 2018-08-03 14:33:37 +0000 | [diff] [blame] | 307 | case VK_WebAssembly_GLOBAL: return "GLOBAL"; |
Dan Gohman | 53ff96a | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 308 | case VK_WebAssembly_TYPEINDEX: return "TYPEINDEX"; |
Heejin Ahn | 8bcdd04 | 2018-11-14 02:46:21 +0000 | [diff] [blame] | 309 | case VK_WebAssembly_EVENT: return "EVENT"; |
Konstantin Zhuravlyov | 84208dd | 2016-10-14 04:21:32 +0000 | [diff] [blame] | 310 | case VK_AMDGPU_GOTPCREL32_LO: return "gotpcrel32@lo"; |
| 311 | case VK_AMDGPU_GOTPCREL32_HI: return "gotpcrel32@hi"; |
| 312 | case VK_AMDGPU_REL32_LO: return "rel32@lo"; |
| 313 | case VK_AMDGPU_REL32_HI: return "rel32@hi"; |
Konstantin Zhuravlyov | db963fc | 2018-06-11 21:37:57 +0000 | [diff] [blame] | 314 | case VK_AMDGPU_REL64: return "rel64"; |
Daniel Dunbar | 4e815f8 | 2010-03-15 23:51:06 +0000 | [diff] [blame] | 315 | } |
Chandler Carruth | 732f05c | 2012-01-10 18:08:01 +0000 | [diff] [blame] | 316 | llvm_unreachable("Invalid variant kind"); |
Daniel Dunbar | 4e815f8 | 2010-03-15 23:51:06 +0000 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | MCSymbolRefExpr::VariantKind |
| 320 | MCSymbolRefExpr::getVariantKindForName(StringRef Name) { |
Roman Divacky | 4be9503 | 2014-12-18 23:12:34 +0000 | [diff] [blame] | 321 | return StringSwitch<VariantKind>(Name.lower()) |
Colin LeMahieu | 89dcdff | 2016-02-10 18:32:01 +0000 | [diff] [blame] | 322 | .Case("dtprel", VK_DTPREL) |
| 323 | .Case("dtpoff", VK_DTPOFF) |
Rafael Espindola | 54104db | 2011-01-23 16:11:25 +0000 | [diff] [blame] | 324 | .Case("got", VK_GOT) |
Rafael Espindola | 54104db | 2011-01-23 16:11:25 +0000 | [diff] [blame] | 325 | .Case("gotoff", VK_GOTOFF) |
Colin LeMahieu | 3f9e772 | 2016-02-09 19:17:34 +0000 | [diff] [blame] | 326 | .Case("gotrel", VK_GOTREL) |
Rafael Espindola | 54104db | 2011-01-23 16:11:25 +0000 | [diff] [blame] | 327 | .Case("gotpcrel", VK_GOTPCREL) |
Rafael Espindola | 54104db | 2011-01-23 16:11:25 +0000 | [diff] [blame] | 328 | .Case("gottpoff", VK_GOTTPOFF) |
Rafael Espindola | 54104db | 2011-01-23 16:11:25 +0000 | [diff] [blame] | 329 | .Case("indntpoff", VK_INDNTPOFF) |
Rafael Espindola | 54104db | 2011-01-23 16:11:25 +0000 | [diff] [blame] | 330 | .Case("ntpoff", VK_NTPOFF) |
Rafael Espindola | 54104db | 2011-01-23 16:11:25 +0000 | [diff] [blame] | 331 | .Case("gotntpoff", VK_GOTNTPOFF) |
Rafael Espindola | 54104db | 2011-01-23 16:11:25 +0000 | [diff] [blame] | 332 | .Case("plt", VK_PLT) |
Davide Italiano | 3255600 | 2016-03-15 00:25:22 +0000 | [diff] [blame] | 333 | .Case("tlscall", VK_TLSCALL) |
Davide Italiano | 87a6f75 | 2016-03-15 17:29:52 +0000 | [diff] [blame] | 334 | .Case("tlsdesc", VK_TLSDESC) |
Rafael Espindola | 54104db | 2011-01-23 16:11:25 +0000 | [diff] [blame] | 335 | .Case("tlsgd", VK_TLSGD) |
Rafael Espindola | 54104db | 2011-01-23 16:11:25 +0000 | [diff] [blame] | 336 | .Case("tlsld", VK_TLSLD) |
Rafael Espindola | 54104db | 2011-01-23 16:11:25 +0000 | [diff] [blame] | 337 | .Case("tlsldm", VK_TLSLDM) |
Rafael Espindola | 54104db | 2011-01-23 16:11:25 +0000 | [diff] [blame] | 338 | .Case("tpoff", VK_TPOFF) |
Colin LeMahieu | 89dcdff | 2016-02-10 18:32:01 +0000 | [diff] [blame] | 339 | .Case("tprel", VK_TPREL) |
Rafael Espindola | 54104db | 2011-01-23 16:11:25 +0000 | [diff] [blame] | 340 | .Case("tlvp", VK_TLVP) |
Tim Northover | 7b837d8 | 2014-03-29 10:18:08 +0000 | [diff] [blame] | 341 | .Case("tlvppage", VK_TLVPPAGE) |
Tim Northover | 7b837d8 | 2014-03-29 10:18:08 +0000 | [diff] [blame] | 342 | .Case("tlvppageoff", VK_TLVPPAGEOFF) |
Tim Northover | 7b837d8 | 2014-03-29 10:18:08 +0000 | [diff] [blame] | 343 | .Case("page", VK_PAGE) |
Tim Northover | 7b837d8 | 2014-03-29 10:18:08 +0000 | [diff] [blame] | 344 | .Case("pageoff", VK_PAGEOFF) |
Tim Northover | 7b837d8 | 2014-03-29 10:18:08 +0000 | [diff] [blame] | 345 | .Case("gotpage", VK_GOTPAGE) |
Tim Northover | 7b837d8 | 2014-03-29 10:18:08 +0000 | [diff] [blame] | 346 | .Case("gotpageoff", VK_GOTPAGEOFF) |
Nico Rieck | 18d49ac | 2013-04-10 23:28:17 +0000 | [diff] [blame] | 347 | .Case("imgrel", VK_COFF_IMGREL32) |
Rafael Espindola | 93d0b06 | 2013-04-25 19:27:05 +0000 | [diff] [blame] | 348 | .Case("secrel32", VK_SECREL) |
Davide Italiano | 8667ab7 | 2015-03-04 06:49:39 +0000 | [diff] [blame] | 349 | .Case("size", VK_SIZE) |
Peter Collingbourne | 043d1a9 | 2017-01-31 18:28:44 +0000 | [diff] [blame] | 350 | .Case("abs8", VK_X86_ABS8) |
Ulrich Weigand | 92cfa61 | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 351 | .Case("l", VK_PPC_LO) |
Ulrich Weigand | d284957 | 2013-06-21 14:42:49 +0000 | [diff] [blame] | 352 | .Case("h", VK_PPC_HI) |
Ulrich Weigand | 92cfa61 | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 353 | .Case("ha", VK_PPC_HA) |
Sean Fertile | 80cb547 | 2018-06-15 19:47:11 +0000 | [diff] [blame] | 354 | .Case("high", VK_PPC_HIGH) |
| 355 | .Case("higha", VK_PPC_HIGHA) |
Ulrich Weigand | f7c1ee7 | 2013-06-21 14:43:42 +0000 | [diff] [blame] | 356 | .Case("higher", VK_PPC_HIGHER) |
Ulrich Weigand | f7c1ee7 | 2013-06-21 14:43:42 +0000 | [diff] [blame] | 357 | .Case("highera", VK_PPC_HIGHERA) |
Ulrich Weigand | f7c1ee7 | 2013-06-21 14:43:42 +0000 | [diff] [blame] | 358 | .Case("highest", VK_PPC_HIGHEST) |
Ulrich Weigand | f7c1ee7 | 2013-06-21 14:43:42 +0000 | [diff] [blame] | 359 | .Case("highesta", VK_PPC_HIGHESTA) |
Ulrich Weigand | 5de735a | 2013-06-25 16:49:50 +0000 | [diff] [blame] | 360 | .Case("got@l", VK_PPC_GOT_LO) |
Ulrich Weigand | 5de735a | 2013-06-25 16:49:50 +0000 | [diff] [blame] | 361 | .Case("got@h", VK_PPC_GOT_HI) |
Ulrich Weigand | 5de735a | 2013-06-25 16:49:50 +0000 | [diff] [blame] | 362 | .Case("got@ha", VK_PPC_GOT_HA) |
Justin Hibbits | 5fa882a | 2014-12-17 06:23:35 +0000 | [diff] [blame] | 363 | .Case("local", VK_PPC_LOCAL) |
Ulrich Weigand | 8465659 | 2013-06-20 22:39:42 +0000 | [diff] [blame] | 364 | .Case("tocbase", VK_PPC_TOCBASE) |
Ulrich Weigand | 92cfa61 | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 365 | .Case("toc", VK_PPC_TOC) |
Ulrich Weigand | 92cfa61 | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 366 | .Case("toc@l", VK_PPC_TOC_LO) |
Ulrich Weigand | f8f87dc | 2013-06-21 14:43:10 +0000 | [diff] [blame] | 367 | .Case("toc@h", VK_PPC_TOC_HI) |
Ulrich Weigand | 92cfa61 | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 368 | .Case("toc@ha", VK_PPC_TOC_HA) |
Ulrich Weigand | a7e5e6b | 2013-05-03 19:52:35 +0000 | [diff] [blame] | 369 | .Case("tls", VK_PPC_TLS) |
Ulrich Weigand | 228e0af | 2013-07-01 23:33:29 +0000 | [diff] [blame] | 370 | .Case("dtpmod", VK_PPC_DTPMOD) |
Ulrich Weigand | 92cfa61 | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 371 | .Case("tprel@l", VK_PPC_TPREL_LO) |
Ulrich Weigand | cab0a19 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 372 | .Case("tprel@h", VK_PPC_TPREL_HI) |
Ulrich Weigand | 92cfa61 | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 373 | .Case("tprel@ha", VK_PPC_TPREL_HA) |
Sean Fertile | a244853 | 2018-06-15 19:47:16 +0000 | [diff] [blame] | 374 | .Case("tprel@high", VK_PPC_TPREL_HIGH) |
| 375 | .Case("tprel@higha", VK_PPC_TPREL_HIGHA) |
Ulrich Weigand | cab0a19 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 376 | .Case("tprel@higher", VK_PPC_TPREL_HIGHER) |
Ulrich Weigand | cab0a19 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 377 | .Case("tprel@highera", VK_PPC_TPREL_HIGHERA) |
Ulrich Weigand | cab0a19 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 378 | .Case("tprel@highest", VK_PPC_TPREL_HIGHEST) |
Ulrich Weigand | cab0a19 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 379 | .Case("tprel@highesta", VK_PPC_TPREL_HIGHESTA) |
Ulrich Weigand | 92cfa61 | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 380 | .Case("dtprel@l", VK_PPC_DTPREL_LO) |
Ulrich Weigand | cab0a19 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 381 | .Case("dtprel@h", VK_PPC_DTPREL_HI) |
Ulrich Weigand | 92cfa61 | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 382 | .Case("dtprel@ha", VK_PPC_DTPREL_HA) |
Sean Fertile | a244853 | 2018-06-15 19:47:16 +0000 | [diff] [blame] | 383 | .Case("dtprel@high", VK_PPC_DTPREL_HIGH) |
| 384 | .Case("dtprel@higha", VK_PPC_DTPREL_HIGHA) |
Ulrich Weigand | cab0a19 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 385 | .Case("dtprel@higher", VK_PPC_DTPREL_HIGHER) |
Ulrich Weigand | cab0a19 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 386 | .Case("dtprel@highera", VK_PPC_DTPREL_HIGHERA) |
Ulrich Weigand | cab0a19 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 387 | .Case("dtprel@highest", VK_PPC_DTPREL_HIGHEST) |
Ulrich Weigand | cab0a19 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 388 | .Case("dtprel@highesta", VK_PPC_DTPREL_HIGHESTA) |
Ulrich Weigand | cab0a19 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 389 | .Case("got@tprel", VK_PPC_GOT_TPREL) |
Ulrich Weigand | 92cfa61 | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 390 | .Case("got@tprel@l", VK_PPC_GOT_TPREL_LO) |
Ulrich Weigand | cab0a19 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 391 | .Case("got@tprel@h", VK_PPC_GOT_TPREL_HI) |
Ulrich Weigand | 92cfa61 | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 392 | .Case("got@tprel@ha", VK_PPC_GOT_TPREL_HA) |
Ulrich Weigand | cab0a19 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 393 | .Case("got@dtprel", VK_PPC_GOT_DTPREL) |
Ulrich Weigand | cab0a19 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 394 | .Case("got@dtprel@l", VK_PPC_GOT_DTPREL_LO) |
Ulrich Weigand | cab0a19 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 395 | .Case("got@dtprel@h", VK_PPC_GOT_DTPREL_HI) |
Ulrich Weigand | cab0a19 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 396 | .Case("got@dtprel@ha", VK_PPC_GOT_DTPREL_HA) |
Ulrich Weigand | cab0a19 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 397 | .Case("got@tlsgd", VK_PPC_GOT_TLSGD) |
Ulrich Weigand | 92cfa61 | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 398 | .Case("got@tlsgd@l", VK_PPC_GOT_TLSGD_LO) |
Ulrich Weigand | cab0a19 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 399 | .Case("got@tlsgd@h", VK_PPC_GOT_TLSGD_HI) |
Ulrich Weigand | 92cfa61 | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 400 | .Case("got@tlsgd@ha", VK_PPC_GOT_TLSGD_HA) |
Ulrich Weigand | cab0a19 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 401 | .Case("got@tlsld", VK_PPC_GOT_TLSLD) |
Ulrich Weigand | 92cfa61 | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 402 | .Case("got@tlsld@l", VK_PPC_GOT_TLSLD_LO) |
Ulrich Weigand | cab0a19 | 2013-06-21 14:44:15 +0000 | [diff] [blame] | 403 | .Case("got@tlsld@h", VK_PPC_GOT_TLSLD_HI) |
Ulrich Weigand | 92cfa61 | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 404 | .Case("got@tlsld@ha", VK_PPC_GOT_TLSLD_HA) |
Krzysztof Parzyszek | 4aba184 | 2015-12-18 18:47:27 +0000 | [diff] [blame] | 405 | .Case("gdgot", VK_Hexagon_GD_GOT) |
| 406 | .Case("gdplt", VK_Hexagon_GD_PLT) |
| 407 | .Case("iegot", VK_Hexagon_IE_GOT) |
| 408 | .Case("ie", VK_Hexagon_IE) |
| 409 | .Case("ldgot", VK_Hexagon_LD_GOT) |
| 410 | .Case("ldplt", VK_Hexagon_LD_PLT) |
| 411 | .Case("pcrel", VK_Hexagon_PCREL) |
David Peixotto | 0fc8c68 | 2013-12-04 22:43:20 +0000 | [diff] [blame] | 412 | .Case("none", VK_ARM_NONE) |
Peter Collingbourne | 7da5357 | 2015-10-26 18:23:16 +0000 | [diff] [blame] | 413 | .Case("got_prel", VK_ARM_GOT_PREL) |
David Peixotto | 0fc8c68 | 2013-12-04 22:43:20 +0000 | [diff] [blame] | 414 | .Case("target1", VK_ARM_TARGET1) |
David Peixotto | 0fc8c68 | 2013-12-04 22:43:20 +0000 | [diff] [blame] | 415 | .Case("target2", VK_ARM_TARGET2) |
David Peixotto | 0fc8c68 | 2013-12-04 22:43:20 +0000 | [diff] [blame] | 416 | .Case("prel31", VK_ARM_PREL31) |
Saleem Abdulrasool | 5e3c87e | 2015-01-11 04:39:18 +0000 | [diff] [blame] | 417 | .Case("sbrel", VK_ARM_SBREL) |
Kai Nacke | 843fa74 | 2014-01-20 11:00:40 +0000 | [diff] [blame] | 418 | .Case("tlsldo", VK_ARM_TLSLDO) |
Dylan McKay | 4f04548 | 2017-12-09 08:01:28 +0000 | [diff] [blame] | 419 | .Case("lo8", VK_AVR_LO8) |
| 420 | .Case("hi8", VK_AVR_HI8) |
| 421 | .Case("hlo8", VK_AVR_HLO8) |
Derek Schuff | a177499 | 2018-03-20 20:06:35 +0000 | [diff] [blame] | 422 | .Case("function", VK_WebAssembly_FUNCTION) |
Wouter van Oortmerssen | 11a3113 | 2018-10-04 23:48:53 +0000 | [diff] [blame] | 423 | .Case("global", VK_WebAssembly_GLOBAL) |
Derek Schuff | a177499 | 2018-03-20 20:06:35 +0000 | [diff] [blame] | 424 | .Case("typeindex", VK_WebAssembly_TYPEINDEX) |
Heejin Ahn | 8bcdd04 | 2018-11-14 02:46:21 +0000 | [diff] [blame] | 425 | .Case("event", VK_WebAssembly_EVENT) |
Konstantin Zhuravlyov | 84208dd | 2016-10-14 04:21:32 +0000 | [diff] [blame] | 426 | .Case("gotpcrel32@lo", VK_AMDGPU_GOTPCREL32_LO) |
| 427 | .Case("gotpcrel32@hi", VK_AMDGPU_GOTPCREL32_HI) |
| 428 | .Case("rel32@lo", VK_AMDGPU_REL32_LO) |
| 429 | .Case("rel32@hi", VK_AMDGPU_REL32_HI) |
Konstantin Zhuravlyov | db963fc | 2018-06-11 21:37:57 +0000 | [diff] [blame] | 430 | .Case("rel64", VK_AMDGPU_REL64) |
Daniel Dunbar | 4e815f8 | 2010-03-15 23:51:06 +0000 | [diff] [blame] | 431 | .Default(VK_Invalid); |
| 432 | } |
| 433 | |
Benjamin Kramer | b1bba1a | 2014-10-11 17:57:27 +0000 | [diff] [blame] | 434 | void MCSymbolRefExpr::printVariantKind(raw_ostream &OS) const { |
| 435 | if (UseParensForSymbolVariant) |
| 436 | OS << '(' << MCSymbolRefExpr::getVariantKindName(getKind()) << ')'; |
| 437 | else |
| 438 | OS << '@' << MCSymbolRefExpr::getVariantKindName(getKind()); |
| 439 | } |
| 440 | |
Daniel Dunbar | 4e815f8 | 2010-03-15 23:51:06 +0000 | [diff] [blame] | 441 | /* *** */ |
| 442 | |
Craig Topper | 4bb51cc | 2012-09-26 06:36:36 +0000 | [diff] [blame] | 443 | void MCTargetExpr::anchor() {} |
Chris Lattner | 4f3e7aa | 2009-09-16 01:26:31 +0000 | [diff] [blame] | 444 | |
Daniel Dunbar | 9643ac5 | 2009-08-31 08:07:22 +0000 | [diff] [blame] | 445 | /* *** */ |
| 446 | |
Jim Grosbach | 586c004 | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 447 | bool MCExpr::evaluateAsAbsolute(int64_t &Res) const { |
| 448 | return evaluateAsAbsolute(Res, nullptr, nullptr, nullptr); |
Rafael Espindola | d076482 | 2010-12-18 03:57:21 +0000 | [diff] [blame] | 449 | } |
| 450 | |
Jim Grosbach | 586c004 | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 451 | bool MCExpr::evaluateAsAbsolute(int64_t &Res, |
Rafael Espindola | d076482 | 2010-12-18 03:57:21 +0000 | [diff] [blame] | 452 | const MCAsmLayout &Layout) const { |
Jim Grosbach | 586c004 | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 453 | return evaluateAsAbsolute(Res, &Layout.getAssembler(), &Layout, nullptr); |
Rafael Espindola | d076482 | 2010-12-18 03:57:21 +0000 | [diff] [blame] | 454 | } |
| 455 | |
Jim Grosbach | 586c004 | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 456 | bool MCExpr::evaluateAsAbsolute(int64_t &Res, |
Rafael Espindola | d076482 | 2010-12-18 03:57:21 +0000 | [diff] [blame] | 457 | const MCAsmLayout &Layout, |
| 458 | const SectionAddrMap &Addrs) const { |
Jim Grosbach | 586c004 | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 459 | return evaluateAsAbsolute(Res, &Layout.getAssembler(), &Layout, &Addrs); |
Rafael Espindola | d076482 | 2010-12-18 03:57:21 +0000 | [diff] [blame] | 460 | } |
| 461 | |
Jim Grosbach | 586c004 | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 462 | bool MCExpr::evaluateAsAbsolute(int64_t &Res, const MCAssembler &Asm) const { |
| 463 | return evaluateAsAbsolute(Res, &Asm, nullptr, nullptr); |
Rafael Espindola | d076482 | 2010-12-18 03:57:21 +0000 | [diff] [blame] | 464 | } |
| 465 | |
Nirav Dave | 4d34462 | 2018-04-30 19:22:40 +0000 | [diff] [blame] | 466 | bool MCExpr::evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm) const { |
| 467 | return evaluateAsAbsolute(Res, Asm, nullptr, nullptr); |
| 468 | } |
| 469 | |
Rafael Espindola | 49dba99 | 2015-03-25 00:25:37 +0000 | [diff] [blame] | 470 | bool MCExpr::evaluateKnownAbsolute(int64_t &Res, |
| 471 | const MCAsmLayout &Layout) const { |
| 472 | return evaluateAsAbsolute(Res, &Layout.getAssembler(), &Layout, nullptr, |
| 473 | true); |
Rafael Espindola | 216fdfe | 2014-08-15 14:20:32 +0000 | [diff] [blame] | 474 | } |
| 475 | |
Jim Grosbach | 586c004 | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 476 | bool MCExpr::evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm, |
Rafael Espindola | d076482 | 2010-12-18 03:57:21 +0000 | [diff] [blame] | 477 | const MCAsmLayout *Layout, |
Rafael Espindola | 85f2ecc | 2010-12-07 00:27:36 +0000 | [diff] [blame] | 478 | const SectionAddrMap *Addrs) const { |
Rafael Espindola | 216fdfe | 2014-08-15 14:20:32 +0000 | [diff] [blame] | 479 | // FIXME: The use if InSet = Addrs is a hack. Setting InSet causes us |
| 480 | // absolutize differences across sections and that is what the MachO writer |
| 481 | // uses Addrs for. |
| 482 | return evaluateAsAbsolute(Res, Asm, Layout, Addrs, Addrs); |
| 483 | } |
| 484 | |
| 485 | bool MCExpr::evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm, |
| 486 | const MCAsmLayout *Layout, |
| 487 | const SectionAddrMap *Addrs, bool InSet) const { |
Daniel Dunbar | 15d1707 | 2009-06-30 01:49:52 +0000 | [diff] [blame] | 488 | MCValue Value; |
Daniel Dunbar | 9a1d200 | 2010-03-18 00:59:10 +0000 | [diff] [blame] | 489 | |
Daniel Dunbar | ef6e96f | 2010-03-23 23:47:07 +0000 | [diff] [blame] | 490 | // Fast path constants. |
| 491 | if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(this)) { |
| 492 | Res = CE->getValue(); |
| 493 | return true; |
| 494 | } |
| 495 | |
Rafael Espindola | d033c4b | 2015-03-25 13:16:53 +0000 | [diff] [blame] | 496 | bool IsRelocatable = |
Jim Grosbach | 586c004 | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 497 | evaluateAsRelocatableImpl(Value, Asm, Layout, nullptr, Addrs, InSet); |
Daniel Dunbar | 15d1707 | 2009-06-30 01:49:52 +0000 | [diff] [blame] | 498 | |
Rafael Espindola | 10b6d33 | 2010-12-22 22:16:24 +0000 | [diff] [blame] | 499 | // Record the current value. |
Daniel Dunbar | 15d1707 | 2009-06-30 01:49:52 +0000 | [diff] [blame] | 500 | Res = Value.getConstant(); |
Rafael Espindola | 10b6d33 | 2010-12-22 22:16:24 +0000 | [diff] [blame] | 501 | |
| 502 | return IsRelocatable && Value.isAbsolute(); |
Daniel Dunbar | 15d1707 | 2009-06-30 01:49:52 +0000 | [diff] [blame] | 503 | } |
| 504 | |
Adrian Prantl | 26b584c | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 505 | /// Helper method for \see EvaluateSymbolAdd(). |
Rafael Espindola | 55f6e3b | 2015-03-25 19:24:39 +0000 | [diff] [blame] | 506 | static void AttemptToFoldSymbolOffsetDifference( |
| 507 | const MCAssembler *Asm, const MCAsmLayout *Layout, |
| 508 | const SectionAddrMap *Addrs, bool InSet, const MCSymbolRefExpr *&A, |
| 509 | const MCSymbolRefExpr *&B, int64_t &Addend) { |
Rafael Espindola | c5b0e44 | 2010-12-19 04:18:56 +0000 | [diff] [blame] | 510 | if (!A || !B) |
| 511 | return; |
Daniel Dunbar | 17304b3 | 2010-12-17 05:50:33 +0000 | [diff] [blame] | 512 | |
Rafael Espindola | c5b0e44 | 2010-12-19 04:18:56 +0000 | [diff] [blame] | 513 | const MCSymbol &SA = A->getSymbol(); |
| 514 | const MCSymbol &SB = B->getSymbol(); |
| 515 | |
| 516 | if (SA.isUndefined() || SB.isUndefined()) |
| 517 | return; |
| 518 | |
Jim Grosbach | bc81286 | 2015-06-04 22:24:41 +0000 | [diff] [blame] | 519 | if (!Asm->getWriter().isSymbolRefDifferenceFullyResolved(*Asm, A, B, InSet)) |
Rafael Espindola | c5b0e44 | 2010-12-19 04:18:56 +0000 | [diff] [blame] | 520 | return; |
| 521 | |
Rafael Espindola | 0eba49c | 2015-10-05 12:07:05 +0000 | [diff] [blame] | 522 | if (SA.getFragment() == SB.getFragment() && !SA.isVariable() && |
Nirav Dave | 4d34462 | 2018-04-30 19:22:40 +0000 | [diff] [blame] | 523 | !SA.isUnset() && !SB.isVariable() && !SB.isUnset()) { |
Rafael Espindola | 82fdcc0 | 2015-05-29 17:48:04 +0000 | [diff] [blame] | 524 | Addend += (SA.getOffset() - SB.getOffset()); |
Daniel Dunbar | 17304b3 | 2010-12-17 05:50:33 +0000 | [diff] [blame] | 525 | |
Owen Anderson | ce3a1ba | 2011-03-21 23:13:43 +0000 | [diff] [blame] | 526 | // Pointers to Thumb symbols need to have their low-bit set to allow |
| 527 | // for interworking. |
| 528 | if (Asm->isThumbFunc(&SA)) |
| 529 | Addend |= 1; |
| 530 | |
Aleksandar Beserminji | e3a3e26 | 2018-10-16 08:27:28 +0000 | [diff] [blame] | 531 | // If symbol is labeled as micromips, we set low-bit to ensure |
| 532 | // correct offset in .gcc_except_table |
| 533 | if (Asm->getBackend().isMicroMips(&SA)) |
| 534 | Addend |= 1; |
| 535 | |
Daniel Dunbar | 17304b3 | 2010-12-17 05:50:33 +0000 | [diff] [blame] | 536 | // Clear the symbol expr pointers to indicate we have folded these |
| 537 | // operands. |
Craig Topper | 4266ae8 | 2014-04-13 04:57:38 +0000 | [diff] [blame] | 538 | A = B = nullptr; |
Rafael Espindola | c5b0e44 | 2010-12-19 04:18:56 +0000 | [diff] [blame] | 539 | return; |
Daniel Dunbar | 17304b3 | 2010-12-17 05:50:33 +0000 | [diff] [blame] | 540 | } |
Rafael Espindola | c5b0e44 | 2010-12-19 04:18:56 +0000 | [diff] [blame] | 541 | |
| 542 | if (!Layout) |
| 543 | return; |
| 544 | |
Rafael Espindola | cfac75a | 2015-05-29 21:45:01 +0000 | [diff] [blame] | 545 | const MCSection &SecA = *SA.getFragment()->getParent(); |
| 546 | const MCSection &SecB = *SB.getFragment()->getParent(); |
Rafael Espindola | c5b0e44 | 2010-12-19 04:18:56 +0000 | [diff] [blame] | 547 | |
| 548 | if ((&SecA != &SecB) && !Addrs) |
| 549 | return; |
| 550 | |
| 551 | // Eagerly evaluate. |
Duncan P. N. Exon Smith | e1fce86 | 2015-05-19 23:53:20 +0000 | [diff] [blame] | 552 | Addend += Layout->getSymbolOffset(A->getSymbol()) - |
| 553 | Layout->getSymbolOffset(B->getSymbol()); |
Rafael Espindola | c5b0e44 | 2010-12-19 04:18:56 +0000 | [diff] [blame] | 554 | if (Addrs && (&SecA != &SecB)) |
Rafael Espindola | 504473e | 2015-05-26 00:52:18 +0000 | [diff] [blame] | 555 | Addend += (Addrs->lookup(&SecA) - Addrs->lookup(&SecB)); |
Rafael Espindola | c5b0e44 | 2010-12-19 04:18:56 +0000 | [diff] [blame] | 556 | |
Jim Grosbach | 0db1241 | 2012-02-24 05:12:18 +0000 | [diff] [blame] | 557 | // Pointers to Thumb symbols need to have their low-bit set to allow |
| 558 | // for interworking. |
| 559 | if (Asm->isThumbFunc(&SA)) |
| 560 | Addend |= 1; |
| 561 | |
Hans Wennborg | eaad8e9 | 2019-02-12 11:05:22 +0000 | [diff] [blame] | 562 | // If symbol is labeled as micromips, we set low-bit to ensure |
| 563 | // correct offset in .gcc_except_table |
| 564 | if (Asm->getBackend().isMicroMips(&SA)) |
| 565 | Addend |= 1; |
| 566 | |
Rafael Espindola | c5b0e44 | 2010-12-19 04:18:56 +0000 | [diff] [blame] | 567 | // Clear the symbol expr pointers to indicate we have folded these |
| 568 | // operands. |
Craig Topper | 4266ae8 | 2014-04-13 04:57:38 +0000 | [diff] [blame] | 569 | A = B = nullptr; |
Daniel Dunbar | 17304b3 | 2010-12-17 05:50:33 +0000 | [diff] [blame] | 570 | } |
| 571 | |
Adrian Prantl | 26b584c | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 572 | /// Evaluate the result of an add between (conceptually) two MCValues. |
Daniel Dunbar | dd18e28 | 2010-12-16 18:36:25 +0000 | [diff] [blame] | 573 | /// |
| 574 | /// This routine conceptually attempts to construct an MCValue: |
| 575 | /// Result = (Result_A - Result_B + Result_Cst) |
| 576 | /// from two MCValue's LHS and RHS where |
| 577 | /// Result = LHS + RHS |
| 578 | /// and |
| 579 | /// Result = (LHS_A - LHS_B + LHS_Cst) + (RHS_A - RHS_B + RHS_Cst). |
| 580 | /// |
| 581 | /// This routine attempts to aggresively fold the operands such that the result |
| 582 | /// is representable in an MCValue, but may not always succeed. |
| 583 | /// |
| 584 | /// \returns True on success, false if the result is not representable in an |
| 585 | /// MCValue. |
Rafael Espindola | d076482 | 2010-12-18 03:57:21 +0000 | [diff] [blame] | 586 | |
| 587 | /// NOTE: It is really important to have both the Asm and Layout arguments. |
| 588 | /// They might look redundant, but this function can be used before layout |
| 589 | /// is done (see the object streamer for example) and having the Asm argument |
Rafael Espindola | f705a7e | 2010-12-18 04:01:45 +0000 | [diff] [blame] | 590 | /// lets us avoid relaxations early. |
Rafael Espindola | 55f6e3b | 2015-03-25 19:24:39 +0000 | [diff] [blame] | 591 | static bool |
| 592 | EvaluateSymbolicAdd(const MCAssembler *Asm, const MCAsmLayout *Layout, |
| 593 | const SectionAddrMap *Addrs, bool InSet, const MCValue &LHS, |
| 594 | const MCSymbolRefExpr *RHS_A, const MCSymbolRefExpr *RHS_B, |
| 595 | int64_t RHS_Cst, MCValue &Res) { |
Daniel Dunbar | f2ed62d | 2010-12-17 01:07:20 +0000 | [diff] [blame] | 596 | // FIXME: This routine (and other evaluation parts) are *incredibly* sloppy |
| 597 | // about dealing with modifiers. This will ultimately bite us, one day. |
| 598 | const MCSymbolRefExpr *LHS_A = LHS.getSymA(); |
| 599 | const MCSymbolRefExpr *LHS_B = LHS.getSymB(); |
| 600 | int64_t LHS_Cst = LHS.getConstant(); |
| 601 | |
| 602 | // Fold the result constant immediately. |
| 603 | int64_t Result_Cst = LHS_Cst + RHS_Cst; |
| 604 | |
Rafael Espindola | c5b0e44 | 2010-12-19 04:18:56 +0000 | [diff] [blame] | 605 | assert((!Layout || Asm) && |
| 606 | "Must have an assembler object if layout is given!"); |
| 607 | |
Alex Bradbury | e54d539 | 2018-05-23 12:36:18 +0000 | [diff] [blame] | 608 | // If we have a layout, we can fold resolved differences. Do not do this if |
| 609 | // the backend requires this to be emitted as individual relocations, unless |
| 610 | // the InSet flag is set to get the current difference anyway (used for |
| 611 | // example to calculate symbol sizes). |
| 612 | if (Asm && |
| 613 | (InSet || !Asm->getBackend().requiresDiffExpressionRelocations())) { |
Daniel Dunbar | 17304b3 | 2010-12-17 05:50:33 +0000 | [diff] [blame] | 614 | // First, fold out any differences which are fully resolved. By |
| 615 | // reassociating terms in |
| 616 | // Result = (LHS_A - LHS_B + LHS_Cst) + (RHS_A - RHS_B + RHS_Cst). |
| 617 | // we have the four possible differences: |
| 618 | // (LHS_A - LHS_B), |
| 619 | // (LHS_A - RHS_B), |
| 620 | // (RHS_A - LHS_B), |
| 621 | // (RHS_A - RHS_B). |
Chris Lattner | 7a2bdde | 2011-04-15 05:18:47 +0000 | [diff] [blame] | 622 | // Since we are attempting to be as aggressive as possible about folding, we |
Daniel Dunbar | 17304b3 | 2010-12-17 05:50:33 +0000 | [diff] [blame] | 623 | // attempt to evaluate each possible alternative. |
Rafael Espindola | c5b0e44 | 2010-12-19 04:18:56 +0000 | [diff] [blame] | 624 | AttemptToFoldSymbolOffsetDifference(Asm, Layout, Addrs, InSet, LHS_A, LHS_B, |
| 625 | Result_Cst); |
| 626 | AttemptToFoldSymbolOffsetDifference(Asm, Layout, Addrs, InSet, LHS_A, RHS_B, |
| 627 | Result_Cst); |
| 628 | AttemptToFoldSymbolOffsetDifference(Asm, Layout, Addrs, InSet, RHS_A, LHS_B, |
| 629 | Result_Cst); |
| 630 | AttemptToFoldSymbolOffsetDifference(Asm, Layout, Addrs, InSet, RHS_A, RHS_B, |
| 631 | Result_Cst); |
Daniel Dunbar | 17304b3 | 2010-12-17 05:50:33 +0000 | [diff] [blame] | 632 | } |
| 633 | |
Daniel Dunbar | f2ed62d | 2010-12-17 01:07:20 +0000 | [diff] [blame] | 634 | // We can't represent the addition or subtraction of two symbols. |
| 635 | if ((LHS_A && RHS_A) || (LHS_B && RHS_B)) |
Daniel Dunbar | 3597604 | 2009-06-30 02:08:27 +0000 | [diff] [blame] | 636 | return false; |
| 637 | |
Daniel Dunbar | 17304b3 | 2010-12-17 05:50:33 +0000 | [diff] [blame] | 638 | // At this point, we have at most one additive symbol and one subtractive |
| 639 | // symbol -- find them. |
Daniel Dunbar | f2ed62d | 2010-12-17 01:07:20 +0000 | [diff] [blame] | 640 | const MCSymbolRefExpr *A = LHS_A ? LHS_A : RHS_A; |
| 641 | const MCSymbolRefExpr *B = LHS_B ? LHS_B : RHS_B; |
Daniel Dunbar | 17304b3 | 2010-12-17 05:50:33 +0000 | [diff] [blame] | 642 | |
Daniel Dunbar | f2ed62d | 2010-12-17 01:07:20 +0000 | [diff] [blame] | 643 | Res = MCValue::get(A, B, Result_Cst); |
Daniel Dunbar | 3597604 | 2009-06-30 02:08:27 +0000 | [diff] [blame] | 644 | return true; |
| 645 | } |
| 646 | |
Jim Grosbach | 586c004 | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 647 | bool MCExpr::evaluateAsRelocatable(MCValue &Res, |
Joerg Sonnenberger | b2b3634 | 2014-08-10 11:35:12 +0000 | [diff] [blame] | 648 | const MCAsmLayout *Layout, |
Joerg Sonnenberger | 901a1b8 | 2014-08-10 11:37:07 +0000 | [diff] [blame] | 649 | const MCFixup *Fixup) const { |
Craig Topper | 4266ae8 | 2014-04-13 04:57:38 +0000 | [diff] [blame] | 650 | MCAssembler *Assembler = Layout ? &Layout->getAssembler() : nullptr; |
Jim Grosbach | 586c004 | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 651 | return evaluateAsRelocatableImpl(Res, Assembler, Layout, Fixup, nullptr, |
Rafael Espindola | d033c4b | 2015-03-25 13:16:53 +0000 | [diff] [blame] | 652 | false); |
Rafael Espindola | d076482 | 2010-12-18 03:57:21 +0000 | [diff] [blame] | 653 | } |
| 654 | |
Rafael Espindola | 9d2f0da | 2015-03-26 21:11:00 +0000 | [diff] [blame] | 655 | bool MCExpr::evaluateAsValue(MCValue &Res, const MCAsmLayout &Layout) const { |
| 656 | MCAssembler *Assembler = &Layout.getAssembler(); |
Jim Grosbach | 586c004 | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 657 | return evaluateAsRelocatableImpl(Res, Assembler, &Layout, nullptr, nullptr, |
Rafael Espindola | 9d2f0da | 2015-03-26 21:11:00 +0000 | [diff] [blame] | 658 | true); |
| 659 | } |
| 660 | |
Rafael Espindola | 0eba49c | 2015-10-05 12:07:05 +0000 | [diff] [blame] | 661 | static bool canExpand(const MCSymbol &Sym, bool InSet) { |
Rafael Espindola | 5eb7481 | 2015-06-03 21:52:06 +0000 | [diff] [blame] | 662 | const MCExpr *Expr = Sym.getVariableValue(); |
| 663 | const auto *Inner = dyn_cast<MCSymbolRefExpr>(Expr); |
| 664 | if (Inner) { |
| 665 | if (Inner->getKind() == MCSymbolRefExpr::VK_WEAKREF) |
| 666 | return false; |
| 667 | } |
| 668 | |
Rafael Espindola | 9d2f0da | 2015-03-26 21:11:00 +0000 | [diff] [blame] | 669 | if (InSet) |
| 670 | return true; |
Rafael Espindola | 0eba49c | 2015-10-05 12:07:05 +0000 | [diff] [blame] | 671 | return !Sym.isInSection(); |
Rafael Espindola | 1c50955 | 2014-04-28 20:53:11 +0000 | [diff] [blame] | 672 | } |
| 673 | |
Jim Grosbach | 586c004 | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 674 | bool MCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm, |
Rafael Espindola | f230df9 | 2010-10-16 18:23:53 +0000 | [diff] [blame] | 675 | const MCAsmLayout *Layout, |
Joerg Sonnenberger | b2b3634 | 2014-08-10 11:35:12 +0000 | [diff] [blame] | 676 | const MCFixup *Fixup, |
Rafael Espindola | d033c4b | 2015-03-25 13:16:53 +0000 | [diff] [blame] | 677 | const SectionAddrMap *Addrs, |
| 678 | bool InSet) const { |
Daniel Dunbar | ff54784 | 2010-03-23 23:47:14 +0000 | [diff] [blame] | 679 | ++stats::MCExprEvaluate; |
| 680 | |
Daniel Dunbar | fc6877a | 2009-06-29 20:40:36 +0000 | [diff] [blame] | 681 | switch (getKind()) { |
Chris Lattner | 5d917a8 | 2010-02-08 19:41:07 +0000 | [diff] [blame] | 682 | case Target: |
Jim Grosbach | 586c004 | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 683 | return cast<MCTargetExpr>(this)->evaluateAsRelocatableImpl(Res, Layout, |
Joerg Sonnenberger | b2b3634 | 2014-08-10 11:35:12 +0000 | [diff] [blame] | 684 | Fixup); |
Daniel Dunbar | 9a1d200 | 2010-03-18 00:59:10 +0000 | [diff] [blame] | 685 | |
Daniel Dunbar | fc6877a | 2009-06-29 20:40:36 +0000 | [diff] [blame] | 686 | case Constant: |
Daniel Dunbar | 28c251b | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 687 | Res = MCValue::get(cast<MCConstantExpr>(this)->getValue()); |
Daniel Dunbar | fc6877a | 2009-06-29 20:40:36 +0000 | [diff] [blame] | 688 | return true; |
| 689 | |
| 690 | case SymbolRef: { |
Daniel Dunbar | 9a1d200 | 2010-03-18 00:59:10 +0000 | [diff] [blame] | 691 | const MCSymbolRefExpr *SRE = cast<MCSymbolRefExpr>(this); |
| 692 | const MCSymbol &Sym = SRE->getSymbol(); |
Daniel Dunbar | 7c3600d | 2009-10-16 01:33:57 +0000 | [diff] [blame] | 693 | |
| 694 | // Evaluate recursively if this is a variable. |
Rafael Espindola | d033c4b | 2015-03-25 13:16:53 +0000 | [diff] [blame] | 695 | if (Sym.isVariable() && SRE->getKind() == MCSymbolRefExpr::VK_None && |
Rafael Espindola | 0eba49c | 2015-10-05 12:07:05 +0000 | [diff] [blame] | 696 | canExpand(Sym, InSet)) { |
Rafael Espindola | 9d2f0da | 2015-03-26 21:11:00 +0000 | [diff] [blame] | 697 | bool IsMachO = SRE->hasSubsectionsViaSymbols(); |
Jim Grosbach | 586c004 | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 698 | if (Sym.getVariableValue()->evaluateAsRelocatableImpl( |
Rafael Espindola | 9d2f0da | 2015-03-26 21:11:00 +0000 | [diff] [blame] | 699 | Res, Asm, Layout, Fixup, Addrs, InSet || IsMachO)) { |
| 700 | if (!IsMachO) |
Rafael Espindola | d033c4b | 2015-03-25 13:16:53 +0000 | [diff] [blame] | 701 | return true; |
| 702 | |
Rafael Espindola | 0a70f9b | 2014-03-20 02:12:01 +0000 | [diff] [blame] | 703 | const MCSymbolRefExpr *A = Res.getSymA(); |
| 704 | const MCSymbolRefExpr *B = Res.getSymB(); |
Rafael Espindola | d033c4b | 2015-03-25 13:16:53 +0000 | [diff] [blame] | 705 | // FIXME: This is small hack. Given |
| 706 | // a = b + 4 |
| 707 | // .long a |
| 708 | // the OS X assembler will completely drop the 4. We should probably |
| 709 | // include it in the relocation or produce an error if that is not |
| 710 | // possible. |
Evgeniy Stepanov | 8efab37 | 2017-06-08 20:49:03 +0000 | [diff] [blame] | 711 | // Allow constant expressions. |
Rafael Espindola | d033c4b | 2015-03-25 13:16:53 +0000 | [diff] [blame] | 712 | if (!A && !B) |
| 713 | return true; |
Evgeniy Stepanov | 8efab37 | 2017-06-08 20:49:03 +0000 | [diff] [blame] | 714 | // Allows aliases with zero offset. |
| 715 | if (Res.getConstant() == 0 && (!A || !B)) |
| 716 | return true; |
Rafael Espindola | 0a70f9b | 2014-03-20 02:12:01 +0000 | [diff] [blame] | 717 | } |
Rafael Espindola | 94ed5fc | 2010-11-15 16:33:49 +0000 | [diff] [blame] | 718 | } |
Daniel Dunbar | 7c3600d | 2009-10-16 01:33:57 +0000 | [diff] [blame] | 719 | |
Craig Topper | 4266ae8 | 2014-04-13 04:57:38 +0000 | [diff] [blame] | 720 | Res = MCValue::get(SRE, nullptr, 0); |
Daniel Dunbar | fc6877a | 2009-06-29 20:40:36 +0000 | [diff] [blame] | 721 | return true; |
| 722 | } |
| 723 | |
| 724 | case Unary: { |
Daniel Dunbar | 28c251b | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 725 | const MCUnaryExpr *AUE = cast<MCUnaryExpr>(this); |
Daniel Dunbar | 15d1707 | 2009-06-30 01:49:52 +0000 | [diff] [blame] | 726 | MCValue Value; |
Daniel Dunbar | fc6877a | 2009-06-29 20:40:36 +0000 | [diff] [blame] | 727 | |
Jim Grosbach | 586c004 | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 728 | if (!AUE->getSubExpr()->evaluateAsRelocatableImpl(Value, Asm, Layout, Fixup, |
Rafael Espindola | d033c4b | 2015-03-25 13:16:53 +0000 | [diff] [blame] | 729 | Addrs, InSet)) |
Daniel Dunbar | fc6877a | 2009-06-29 20:40:36 +0000 | [diff] [blame] | 730 | return false; |
| 731 | |
| 732 | switch (AUE->getOpcode()) { |
Daniel Dunbar | 28c251b | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 733 | case MCUnaryExpr::LNot: |
Daniel Dunbar | 80f62d0 | 2009-07-01 06:48:00 +0000 | [diff] [blame] | 734 | if (!Value.isAbsolute()) |
Daniel Dunbar | 15d1707 | 2009-06-30 01:49:52 +0000 | [diff] [blame] | 735 | return false; |
| 736 | Res = MCValue::get(!Value.getConstant()); |
| 737 | break; |
Daniel Dunbar | 28c251b | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 738 | case MCUnaryExpr::Minus: |
Daniel Dunbar | 15d1707 | 2009-06-30 01:49:52 +0000 | [diff] [blame] | 739 | /// -(a - b + const) ==> (b - a - const) |
Daniel Dunbar | b27a41b | 2009-08-11 17:47:52 +0000 | [diff] [blame] | 740 | if (Value.getSymA() && !Value.getSymB()) |
Daniel Dunbar | 15d1707 | 2009-06-30 01:49:52 +0000 | [diff] [blame] | 741 | return false; |
Sanjay Patel | 760078b | 2016-05-20 14:09:41 +0000 | [diff] [blame] | 742 | |
| 743 | // The cast avoids undefined behavior if the constant is INT64_MIN. |
Daniel Dunbar | 9a1d200 | 2010-03-18 00:59:10 +0000 | [diff] [blame] | 744 | Res = MCValue::get(Value.getSymB(), Value.getSymA(), |
Sanjay Patel | 760078b | 2016-05-20 14:09:41 +0000 | [diff] [blame] | 745 | -(uint64_t)Value.getConstant()); |
Daniel Dunbar | 15d1707 | 2009-06-30 01:49:52 +0000 | [diff] [blame] | 746 | break; |
Daniel Dunbar | 28c251b | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 747 | case MCUnaryExpr::Not: |
Daniel Dunbar | 80f62d0 | 2009-07-01 06:48:00 +0000 | [diff] [blame] | 748 | if (!Value.isAbsolute()) |
Daniel Dunbar | 15d1707 | 2009-06-30 01:49:52 +0000 | [diff] [blame] | 749 | return false; |
Daniel Dunbar | 9a1d200 | 2010-03-18 00:59:10 +0000 | [diff] [blame] | 750 | Res = MCValue::get(~Value.getConstant()); |
Daniel Dunbar | 15d1707 | 2009-06-30 01:49:52 +0000 | [diff] [blame] | 751 | break; |
Daniel Dunbar | 28c251b | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 752 | case MCUnaryExpr::Plus: |
Daniel Dunbar | 15d1707 | 2009-06-30 01:49:52 +0000 | [diff] [blame] | 753 | Res = Value; |
| 754 | break; |
Daniel Dunbar | fc6877a | 2009-06-29 20:40:36 +0000 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | return true; |
| 758 | } |
| 759 | |
| 760 | case Binary: { |
Daniel Dunbar | 28c251b | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 761 | const MCBinaryExpr *ABE = cast<MCBinaryExpr>(this); |
Daniel Dunbar | 15d1707 | 2009-06-30 01:49:52 +0000 | [diff] [blame] | 762 | MCValue LHSValue, RHSValue; |
Daniel Dunbar | 9a1d200 | 2010-03-18 00:59:10 +0000 | [diff] [blame] | 763 | |
Jim Grosbach | 586c004 | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 764 | if (!ABE->getLHS()->evaluateAsRelocatableImpl(LHSValue, Asm, Layout, Fixup, |
Rafael Espindola | d033c4b | 2015-03-25 13:16:53 +0000 | [diff] [blame] | 765 | Addrs, InSet) || |
Jim Grosbach | 586c004 | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 766 | !ABE->getRHS()->evaluateAsRelocatableImpl(RHSValue, Asm, Layout, Fixup, |
Nirav Dave | fd8c412 | 2018-08-16 16:31:14 +0000 | [diff] [blame] | 767 | Addrs, InSet)) { |
| 768 | // Check if both are Target Expressions, see if we can compare them. |
| 769 | if (const MCTargetExpr *L = dyn_cast<MCTargetExpr>(ABE->getLHS())) |
| 770 | if (const MCTargetExpr *R = cast<MCTargetExpr>(ABE->getRHS())) { |
| 771 | switch (ABE->getOpcode()) { |
| 772 | case MCBinaryExpr::EQ: |
| 773 | Res = MCValue::get((L->isEqualTo(R)) ? -1 : 0); |
| 774 | return true; |
| 775 | case MCBinaryExpr::NE: |
| 776 | Res = MCValue::get((R->isEqualTo(R)) ? 0 : -1); |
| 777 | return true; |
Nirav Dave | cd2d2cf | 2018-08-16 17:22:31 +0000 | [diff] [blame] | 778 | default: break; |
Nirav Dave | fd8c412 | 2018-08-16 16:31:14 +0000 | [diff] [blame] | 779 | } |
| 780 | } |
Daniel Dunbar | fc6877a | 2009-06-29 20:40:36 +0000 | [diff] [blame] | 781 | return false; |
Nirav Dave | fd8c412 | 2018-08-16 16:31:14 +0000 | [diff] [blame] | 782 | } |
Daniel Dunbar | fc6877a | 2009-06-29 20:40:36 +0000 | [diff] [blame] | 783 | |
Daniel Dunbar | 15d1707 | 2009-06-30 01:49:52 +0000 | [diff] [blame] | 784 | // We only support a few operations on non-constant expressions, handle |
| 785 | // those first. |
Daniel Dunbar | 80f62d0 | 2009-07-01 06:48:00 +0000 | [diff] [blame] | 786 | if (!LHSValue.isAbsolute() || !RHSValue.isAbsolute()) { |
Daniel Dunbar | 15d1707 | 2009-06-30 01:49:52 +0000 | [diff] [blame] | 787 | switch (ABE->getOpcode()) { |
| 788 | default: |
| 789 | return false; |
Daniel Dunbar | 28c251b | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 790 | case MCBinaryExpr::Sub: |
Daniel Dunbar | 3597604 | 2009-06-30 02:08:27 +0000 | [diff] [blame] | 791 | // Negate RHS and add. |
Sanjay Patel | 760078b | 2016-05-20 14:09:41 +0000 | [diff] [blame] | 792 | // The cast avoids undefined behavior if the constant is INT64_MIN. |
Rafael Espindola | d076482 | 2010-12-18 03:57:21 +0000 | [diff] [blame] | 793 | return EvaluateSymbolicAdd(Asm, Layout, Addrs, InSet, LHSValue, |
Daniel Dunbar | 3597604 | 2009-06-30 02:08:27 +0000 | [diff] [blame] | 794 | RHSValue.getSymB(), RHSValue.getSymA(), |
Sanjay Patel | 760078b | 2016-05-20 14:09:41 +0000 | [diff] [blame] | 795 | -(uint64_t)RHSValue.getConstant(), Res); |
Daniel Dunbar | 3597604 | 2009-06-30 02:08:27 +0000 | [diff] [blame] | 796 | |
Daniel Dunbar | 28c251b | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 797 | case MCBinaryExpr::Add: |
Rafael Espindola | d076482 | 2010-12-18 03:57:21 +0000 | [diff] [blame] | 798 | return EvaluateSymbolicAdd(Asm, Layout, Addrs, InSet, LHSValue, |
Daniel Dunbar | 3597604 | 2009-06-30 02:08:27 +0000 | [diff] [blame] | 799 | RHSValue.getSymA(), RHSValue.getSymB(), |
Rafael Espindola | 55f6e3b | 2015-03-25 19:24:39 +0000 | [diff] [blame] | 800 | RHSValue.getConstant(), Res); |
Daniel Dunbar | 15d1707 | 2009-06-30 01:49:52 +0000 | [diff] [blame] | 801 | } |
| 802 | } |
| 803 | |
Daniel Dunbar | fc6877a | 2009-06-29 20:40:36 +0000 | [diff] [blame] | 804 | // FIXME: We need target hooks for the evaluation. It may be limited in |
Ahmed Bougacha | dac39b1 | 2015-04-28 00:21:32 +0000 | [diff] [blame] | 805 | // width, and gas defines the result of comparisons differently from |
| 806 | // Apple as. |
Daniel Dunbar | b79742c | 2009-06-30 16:02:47 +0000 | [diff] [blame] | 807 | int64_t LHS = LHSValue.getConstant(), RHS = RHSValue.getConstant(); |
| 808 | int64_t Result = 0; |
Bill Wendling | 558d724 | 2018-05-14 05:25:36 +0000 | [diff] [blame] | 809 | auto Op = ABE->getOpcode(); |
| 810 | switch (Op) { |
Ahmed Bougacha | dac39b1 | 2015-04-28 00:21:32 +0000 | [diff] [blame] | 811 | case MCBinaryExpr::AShr: Result = LHS >> RHS; break; |
Daniel Dunbar | 28c251b | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 812 | case MCBinaryExpr::Add: Result = LHS + RHS; break; |
| 813 | case MCBinaryExpr::And: Result = LHS & RHS; break; |
Davide Italiano | 830d0f8 | 2015-09-11 22:04:21 +0000 | [diff] [blame] | 814 | case MCBinaryExpr::Div: |
Simon Pilgrim | 0bbd02e | 2018-02-22 18:06:48 +0000 | [diff] [blame] | 815 | case MCBinaryExpr::Mod: |
Davide Italiano | 125be70 | 2015-09-11 20:47:35 +0000 | [diff] [blame] | 816 | // Handle division by zero. gas just emits a warning and keeps going, |
| 817 | // we try to be stricter. |
| 818 | // FIXME: Currently the caller of this function has no way to understand |
| 819 | // we're bailing out because of 'division by zero'. Therefore, it will |
| 820 | // emit a 'expected relocatable expression' error. It would be nice to |
| 821 | // change this code to emit a better diagnostic. |
| 822 | if (RHS == 0) |
| 823 | return false; |
Simon Pilgrim | 0bbd02e | 2018-02-22 18:06:48 +0000 | [diff] [blame] | 824 | if (ABE->getOpcode() == MCBinaryExpr::Div) |
| 825 | Result = LHS / RHS; |
| 826 | else |
| 827 | Result = LHS % RHS; |
Davide Italiano | 830d0f8 | 2015-09-11 22:04:21 +0000 | [diff] [blame] | 828 | break; |
Daniel Dunbar | 28c251b | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 829 | case MCBinaryExpr::EQ: Result = LHS == RHS; break; |
| 830 | case MCBinaryExpr::GT: Result = LHS > RHS; break; |
| 831 | case MCBinaryExpr::GTE: Result = LHS >= RHS; break; |
| 832 | case MCBinaryExpr::LAnd: Result = LHS && RHS; break; |
| 833 | case MCBinaryExpr::LOr: Result = LHS || RHS; break; |
Ahmed Bougacha | dac39b1 | 2015-04-28 00:21:32 +0000 | [diff] [blame] | 834 | case MCBinaryExpr::LShr: Result = uint64_t(LHS) >> uint64_t(RHS); break; |
Daniel Dunbar | 28c251b | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 835 | case MCBinaryExpr::LT: Result = LHS < RHS; break; |
| 836 | case MCBinaryExpr::LTE: Result = LHS <= RHS; break; |
Daniel Dunbar | 28c251b | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 837 | case MCBinaryExpr::Mul: Result = LHS * RHS; break; |
| 838 | case MCBinaryExpr::NE: Result = LHS != RHS; break; |
| 839 | case MCBinaryExpr::Or: Result = LHS | RHS; break; |
Justin Bogner | 1e4a7e0 | 2015-06-23 07:32:55 +0000 | [diff] [blame] | 840 | case MCBinaryExpr::Shl: Result = uint64_t(LHS) << uint64_t(RHS); break; |
Daniel Dunbar | 28c251b | 2009-08-31 08:06:59 +0000 | [diff] [blame] | 841 | case MCBinaryExpr::Sub: Result = LHS - RHS; break; |
| 842 | case MCBinaryExpr::Xor: Result = LHS ^ RHS; break; |
Daniel Dunbar | fc6877a | 2009-06-29 20:40:36 +0000 | [diff] [blame] | 843 | } |
| 844 | |
Bill Wendling | 558d724 | 2018-05-14 05:25:36 +0000 | [diff] [blame] | 845 | switch (Op) { |
| 846 | default: |
| 847 | Res = MCValue::get(Result); |
| 848 | break; |
| 849 | case MCBinaryExpr::EQ: |
| 850 | case MCBinaryExpr::GT: |
| 851 | case MCBinaryExpr::GTE: |
| 852 | case MCBinaryExpr::LT: |
| 853 | case MCBinaryExpr::LTE: |
| 854 | case MCBinaryExpr::NE: |
| 855 | // A comparison operator returns a -1 if true and 0 if false. |
| 856 | Res = MCValue::get(Result ? -1 : 0); |
| 857 | break; |
| 858 | } |
| 859 | |
Daniel Dunbar | fc6877a | 2009-06-29 20:40:36 +0000 | [diff] [blame] | 860 | return true; |
| 861 | } |
| 862 | } |
Daniel Dunbar | fc6877a | 2009-06-29 20:40:36 +0000 | [diff] [blame] | 863 | |
Craig Topper | 8581438 | 2012-02-07 05:05:23 +0000 | [diff] [blame] | 864 | llvm_unreachable("Invalid assembly expression kind!"); |
Daniel Dunbar | 9643ac5 | 2009-08-31 08:07:22 +0000 | [diff] [blame] | 865 | } |
Daniel Dunbar | 0eab5c4 | 2011-04-29 18:00:03 +0000 | [diff] [blame] | 866 | |
Rafael Espindola | 0eba49c | 2015-10-05 12:07:05 +0000 | [diff] [blame] | 867 | MCFragment *MCExpr::findAssociatedFragment() const { |
Daniel Dunbar | 0eab5c4 | 2011-04-29 18:00:03 +0000 | [diff] [blame] | 868 | switch (getKind()) { |
| 869 | case Target: |
| 870 | // We never look through target specific expressions. |
Rafael Espindola | 0eba49c | 2015-10-05 12:07:05 +0000 | [diff] [blame] | 871 | return cast<MCTargetExpr>(this)->findAssociatedFragment(); |
Daniel Dunbar | 0eab5c4 | 2011-04-29 18:00:03 +0000 | [diff] [blame] | 872 | |
| 873 | case Constant: |
Rafael Espindola | 0eba49c | 2015-10-05 12:07:05 +0000 | [diff] [blame] | 874 | return MCSymbol::AbsolutePseudoFragment; |
Daniel Dunbar | 0eab5c4 | 2011-04-29 18:00:03 +0000 | [diff] [blame] | 875 | |
| 876 | case SymbolRef: { |
| 877 | const MCSymbolRefExpr *SRE = cast<MCSymbolRefExpr>(this); |
| 878 | const MCSymbol &Sym = SRE->getSymbol(); |
Rafael Espindola | 0eba49c | 2015-10-05 12:07:05 +0000 | [diff] [blame] | 879 | return Sym.getFragment(); |
Daniel Dunbar | 0eab5c4 | 2011-04-29 18:00:03 +0000 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | case Unary: |
Rafael Espindola | 0eba49c | 2015-10-05 12:07:05 +0000 | [diff] [blame] | 883 | return cast<MCUnaryExpr>(this)->getSubExpr()->findAssociatedFragment(); |
Daniel Dunbar | 0eab5c4 | 2011-04-29 18:00:03 +0000 | [diff] [blame] | 884 | |
| 885 | case Binary: { |
| 886 | const MCBinaryExpr *BE = cast<MCBinaryExpr>(this); |
Rafael Espindola | 0eba49c | 2015-10-05 12:07:05 +0000 | [diff] [blame] | 887 | MCFragment *LHS_F = BE->getLHS()->findAssociatedFragment(); |
| 888 | MCFragment *RHS_F = BE->getRHS()->findAssociatedFragment(); |
Daniel Dunbar | 0eab5c4 | 2011-04-29 18:00:03 +0000 | [diff] [blame] | 889 | |
Rafael Espindola | 0eba49c | 2015-10-05 12:07:05 +0000 | [diff] [blame] | 890 | // If either is absolute, return the other. |
| 891 | if (LHS_F == MCSymbol::AbsolutePseudoFragment) |
| 892 | return RHS_F; |
| 893 | if (RHS_F == MCSymbol::AbsolutePseudoFragment) |
| 894 | return LHS_F; |
Daniel Dunbar | 0eab5c4 | 2011-04-29 18:00:03 +0000 | [diff] [blame] | 895 | |
Peter Collingbourne | c39f5dd | 2015-04-03 01:46:11 +0000 | [diff] [blame] | 896 | // Not always correct, but probably the best we can do without more context. |
| 897 | if (BE->getOpcode() == MCBinaryExpr::Sub) |
Rafael Espindola | 0eba49c | 2015-10-05 12:07:05 +0000 | [diff] [blame] | 898 | return MCSymbol::AbsolutePseudoFragment; |
Peter Collingbourne | c39f5dd | 2015-04-03 01:46:11 +0000 | [diff] [blame] | 899 | |
Rafael Espindola | 0eba49c | 2015-10-05 12:07:05 +0000 | [diff] [blame] | 900 | // Otherwise, return the first non-null fragment. |
| 901 | return LHS_F ? LHS_F : RHS_F; |
Daniel Dunbar | 0eab5c4 | 2011-04-29 18:00:03 +0000 | [diff] [blame] | 902 | } |
| 903 | } |
| 904 | |
Craig Topper | 8581438 | 2012-02-07 05:05:23 +0000 | [diff] [blame] | 905 | llvm_unreachable("Invalid assembly expression kind!"); |
Daniel Dunbar | 0eab5c4 | 2011-04-29 18:00:03 +0000 | [diff] [blame] | 906 | } |