LLVM API Documentation
00001 //=--- AArch64MCExpr.h - AArch64 specific MC expression classes ---*- C++ -*-=// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file describes AArch64-specific MCExprs, used for modifiers like 00011 // ":lo12:" or ":gottprel_g1:". 00012 // 00013 //===----------------------------------------------------------------------===// 00014 00015 #ifndef LLVM_LIB_TARGET_AARCH64_MCTARGETDESC_AARCH64MCEXPR_H 00016 #define LLVM_LIB_TARGET_AARCH64_MCTARGETDESC_AARCH64MCEXPR_H 00017 00018 #include "llvm/MC/MCExpr.h" 00019 #include "llvm/Support/ErrorHandling.h" 00020 00021 namespace llvm { 00022 00023 class AArch64MCExpr : public MCTargetExpr { 00024 public: 00025 enum VariantKind { 00026 VK_NONE = 0x000, 00027 00028 // Symbol locations specifying (roughly speaking) what calculation should be 00029 // performed to construct the final address for the relocated 00030 // symbol. E.g. direct, via the GOT, ... 00031 VK_ABS = 0x001, 00032 VK_SABS = 0x002, 00033 VK_GOT = 0x003, 00034 VK_DTPREL = 0x004, 00035 VK_GOTTPREL = 0x005, 00036 VK_TPREL = 0x006, 00037 VK_TLSDESC = 0x007, 00038 VK_SymLocBits = 0x00f, 00039 00040 // Variants specifying which part of the final address calculation is 00041 // used. E.g. the low 12 bits for an ADD/LDR, the middle 16 bits for a 00042 // MOVZ/MOVK. 00043 VK_PAGE = 0x010, 00044 VK_PAGEOFF = 0x020, 00045 VK_HI12 = 0x030, 00046 VK_G0 = 0x040, 00047 VK_G1 = 0x050, 00048 VK_G2 = 0x060, 00049 VK_G3 = 0x070, 00050 VK_AddressFragBits = 0x0f0, 00051 00052 // Whether the final relocation is a checked one (where a linker should 00053 // perform a range-check on the final address) or not. Note that this field 00054 // is unfortunately sometimes omitted from the assembly syntax. E.g. :lo12: 00055 // on its own is a non-checked relocation. We side with ELF on being 00056 // explicit about this! 00057 VK_NC = 0x100, 00058 00059 // Convenience definitions for referring to specific textual representations 00060 // of relocation specifiers. Note that this means the "_NC" is sometimes 00061 // omitted in line with assembly syntax here (VK_LO12 rather than VK_LO12_NC 00062 // since a user would write ":lo12:"). 00063 VK_CALL = VK_ABS, 00064 VK_ABS_PAGE = VK_ABS | VK_PAGE, 00065 VK_ABS_G3 = VK_ABS | VK_G3, 00066 VK_ABS_G2 = VK_ABS | VK_G2, 00067 VK_ABS_G2_S = VK_SABS | VK_G2, 00068 VK_ABS_G2_NC = VK_ABS | VK_G2 | VK_NC, 00069 VK_ABS_G1 = VK_ABS | VK_G1, 00070 VK_ABS_G1_S = VK_SABS | VK_G1, 00071 VK_ABS_G1_NC = VK_ABS | VK_G1 | VK_NC, 00072 VK_ABS_G0 = VK_ABS | VK_G0, 00073 VK_ABS_G0_S = VK_SABS | VK_G0, 00074 VK_ABS_G0_NC = VK_ABS | VK_G0 | VK_NC, 00075 VK_LO12 = VK_ABS | VK_PAGEOFF | VK_NC, 00076 VK_GOT_LO12 = VK_GOT | VK_PAGEOFF | VK_NC, 00077 VK_GOT_PAGE = VK_GOT | VK_PAGE, 00078 VK_DTPREL_G2 = VK_DTPREL | VK_G2, 00079 VK_DTPREL_G1 = VK_DTPREL | VK_G1, 00080 VK_DTPREL_G1_NC = VK_DTPREL | VK_G1 | VK_NC, 00081 VK_DTPREL_G0 = VK_DTPREL | VK_G0, 00082 VK_DTPREL_G0_NC = VK_DTPREL | VK_G0 | VK_NC, 00083 VK_DTPREL_HI12 = VK_DTPREL | VK_HI12, 00084 VK_DTPREL_LO12 = VK_DTPREL | VK_PAGEOFF, 00085 VK_DTPREL_LO12_NC = VK_DTPREL | VK_PAGEOFF | VK_NC, 00086 VK_GOTTPREL_PAGE = VK_GOTTPREL | VK_PAGE, 00087 VK_GOTTPREL_LO12_NC = VK_GOTTPREL | VK_PAGEOFF | VK_NC, 00088 VK_GOTTPREL_G1 = VK_GOTTPREL | VK_G1, 00089 VK_GOTTPREL_G0_NC = VK_GOTTPREL | VK_G0 | VK_NC, 00090 VK_TPREL_G2 = VK_TPREL | VK_G2, 00091 VK_TPREL_G1 = VK_TPREL | VK_G1, 00092 VK_TPREL_G1_NC = VK_TPREL | VK_G1 | VK_NC, 00093 VK_TPREL_G0 = VK_TPREL | VK_G0, 00094 VK_TPREL_G0_NC = VK_TPREL | VK_G0 | VK_NC, 00095 VK_TPREL_HI12 = VK_TPREL | VK_HI12, 00096 VK_TPREL_LO12 = VK_TPREL | VK_PAGEOFF, 00097 VK_TPREL_LO12_NC = VK_TPREL | VK_PAGEOFF | VK_NC, 00098 VK_TLSDESC_LO12 = VK_TLSDESC | VK_PAGEOFF | VK_NC, 00099 VK_TLSDESC_PAGE = VK_TLSDESC | VK_PAGE, 00100 00101 VK_INVALID = 0xfff 00102 }; 00103 00104 private: 00105 const MCExpr *Expr; 00106 const VariantKind Kind; 00107 00108 explicit AArch64MCExpr(const MCExpr *Expr, VariantKind Kind) 00109 : Expr(Expr), Kind(Kind) {} 00110 00111 public: 00112 /// @name Construction 00113 /// @{ 00114 00115 static const AArch64MCExpr *Create(const MCExpr *Expr, VariantKind Kind, 00116 MCContext &Ctx); 00117 00118 /// @} 00119 /// @name Accessors 00120 /// @{ 00121 00122 /// Get the kind of this expression. 00123 VariantKind getKind() const { return static_cast<VariantKind>(Kind); } 00124 00125 /// Get the expression this modifier applies to. 00126 const MCExpr *getSubExpr() const { return Expr; } 00127 00128 /// @} 00129 /// @name VariantKind information extractors. 00130 /// @{ 00131 00132 static VariantKind getSymbolLoc(VariantKind Kind) { 00133 return static_cast<VariantKind>(Kind & VK_SymLocBits); 00134 } 00135 00136 static VariantKind getAddressFrag(VariantKind Kind) { 00137 return static_cast<VariantKind>(Kind & VK_AddressFragBits); 00138 } 00139 00140 static bool isNotChecked(VariantKind Kind) { return Kind & VK_NC; } 00141 00142 /// @} 00143 00144 /// Convert the variant kind into an ELF-appropriate modifier 00145 /// (e.g. ":got:", ":lo12:"). 00146 StringRef getVariantKindName() const; 00147 00148 void PrintImpl(raw_ostream &OS) const override; 00149 00150 void visitUsedExpr(MCStreamer &Streamer) const override; 00151 00152 const MCSection *FindAssociatedSection() const override; 00153 00154 bool EvaluateAsRelocatableImpl(MCValue &Res, 00155 const MCAsmLayout *Layout, 00156 const MCFixup *Fixup) const override; 00157 00158 void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override; 00159 00160 static bool classof(const MCExpr *E) { 00161 return E->getKind() == MCExpr::Target; 00162 } 00163 00164 static bool classof(const AArch64MCExpr *) { return true; } 00165 00166 }; 00167 } // end namespace llvm 00168 00169 #endif