LLVM 23.0.0git
RISCVMCExpr.cpp
Go to the documentation of this file.
1//===-- RISCVMCExpr.cpp - RISC-V specific MC expression classes -----------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains the implementation of the assembly expression modifiers
10// accepted by the RISC-V architecture (e.g. ":lo12:", ":gottprel_g1:", ...).
11//
12//===----------------------------------------------------------------------===//
13
18
19using namespace llvm;
20
21#define DEBUG_TYPE "riscvmcexpr"
22
25 .Case("lo", RISCV::S_LO)
26 .Case("hi", ELF::R_RISCV_HI20)
27 .Case("pcrel_lo", RISCV::S_PCREL_LO)
28 .Case("pcrel_hi", RISCV::S_PCREL_HI)
29 .Case("got_pcrel_hi", RISCV::S_GOT_HI)
30 .Case("tprel_lo", RISCV::S_TPREL_LO)
31 .Case("tprel_hi", ELF::R_RISCV_TPREL_HI20)
32 .Case("tprel_add", ELF::R_RISCV_TPREL_ADD)
33 .Case("tls_ie_pcrel_hi", ELF::R_RISCV_TLS_GOT_HI20)
34 .Case("tls_gd_pcrel_hi", ELF::R_RISCV_TLS_GD_HI20)
35 .Case("tlsdesc_hi", ELF::R_RISCV_TLSDESC_HI20)
36 .Case("tlsdesc_load_lo", ELF::R_RISCV_TLSDESC_LOAD_LO12)
37 .Case("tlsdesc_add_lo", ELF::R_RISCV_TLSDESC_ADD_LO12)
38 .Case("tlsdesc_call", ELF::R_RISCV_TLSDESC_CALL)
39 .Case("qc.abs20", RISCV::S_QC_ABS20)
40 .Case("qc.access", RISCV::S_QC_ACCESS)
41 // Used in data directives
42 .Case("pltpcrel", ELF::R_RISCV_PLT32)
43 .Case("gotpcrel", ELF::R_RISCV_GOT32_PCREL)
44 .Default(0);
45}
46
48 switch (S) {
49 case RISCV::S_None:
50 llvm_unreachable("not used as %specifier()");
51 case RISCV::S_LO:
52 return "lo";
53 case ELF::R_RISCV_HI20:
54 return "hi";
56 return "pcrel_lo";
58 return "pcrel_hi";
59 case RISCV::S_GOT_HI:
60 return "got_pcrel_hi";
62 return "tprel_lo";
63 case ELF::R_RISCV_TPREL_HI20:
64 return "tprel_hi";
65 case ELF::R_RISCV_TPREL_ADD:
66 return "tprel_add";
67 case ELF::R_RISCV_TLS_GOT_HI20:
68 return "tls_ie_pcrel_hi";
69 case ELF::R_RISCV_TLSDESC_HI20:
70 return "tlsdesc_hi";
71 case ELF::R_RISCV_TLSDESC_LOAD_LO12:
72 return "tlsdesc_load_lo";
73 case ELF::R_RISCV_TLSDESC_ADD_LO12:
74 return "tlsdesc_add_lo";
75 case ELF::R_RISCV_TLSDESC_CALL:
76 return "tlsdesc_call";
77 case ELF::R_RISCV_TLS_GD_HI20:
78 return "tls_gd_pcrel_hi";
80 return "call_plt";
81 case ELF::R_RISCV_32_PCREL:
82 return "32_pcrel";
83 case ELF::R_RISCV_GOT32_PCREL:
84 return "gotpcrel";
85 case ELF::R_RISCV_PLT32:
86 return "pltpcrel";
88 return "qc.abs20";
90 return "qc.access";
91 }
92 llvm_unreachable("Invalid ELF symbol kind");
93}
static const char * name
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
A switch()-like statement whose cases are string literals.
StringSwitch & Case(StringLiteral S, T Value)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Specifier parseSpecifierName(StringRef name)
StringRef getSpecifierName(Specifier Kind)
uint16_t Specifier
This is an optimization pass for GlobalISel generic memory operations.