1//===- VEMCAsmInfo.cpp - VE asm properties --------------------------------===//
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 declarations of the VEMCAsmInfo properties.
10//
11//===----------------------------------------------------------------------===//
12
13#include "VEMCAsmInfo.h"
14#include "llvm/ADT/Enum.h"
15#include "llvm/MC/MCExpr.h"
16#include "llvm/MC/MCStreamer.h"
17#include "llvm/MC/MCValue.h"
18#include "llvm/TargetParser/Triple.h"
19
20using namespace llvm;
21
22constexpr EnumStringDef<MCAsmInfo::AtSpecifierKind> AtSpecifierDefs[] = {
23 {.Names: {"hi"}, .Value: VE::S_HI32},
24 {.Names: {"lo"}, .Value: VE::S_LO32},
25 {.Names: {"pc_hi"}, .Value: VE::S_PC_HI32},
26 {.Names: {"pc_lo"}, .Value: VE::S_PC_LO32},
27 {.Names: {"got_hi"}, .Value: VE::S_GOT_HI32},
28 {.Names: {"got_lo"}, .Value: VE::S_GOT_LO32},
29 {.Names: {"gotoff_hi"}, .Value: VE::S_GOTOFF_HI32},
30 {.Names: {"gotoff_lo"}, .Value: VE::S_GOTOFF_LO32},
31 {.Names: {"plt_hi"}, .Value: VE::S_PLT_HI32},
32 {.Names: {"plt_lo"}, .Value: VE::S_PLT_LO32},
33 {.Names: {"tls_gd_hi"}, .Value: VE::S_TLS_GD_HI32},
34 {.Names: {"tls_gd_lo"}, .Value: VE::S_TLS_GD_LO32},
35 {.Names: {"tpoff_hi"}, .Value: VE::S_TPOFF_HI32},
36 {.Names: {"tpoff_lo"}, .Value: VE::S_TPOFF_LO32},
37};
38constexpr auto atSpecifiers = BUILD_ENUM_STRINGS(AtSpecifierDefs);
39
40VE::Fixups VE::getFixupKind(uint8_t S) {
41 switch (S) {
42 default:
43 llvm_unreachable("Unhandled VEMCExpr::Specifier");
44 case VE::S_REFLONG:
45 return VE::fixup_ve_reflong;
46 case VE::S_HI32:
47 return VE::fixup_ve_hi32;
48 case VE::S_LO32:
49 return VE::fixup_ve_lo32;
50 case VE::S_PC_HI32:
51 return VE::fixup_ve_pc_hi32;
52 case VE::S_PC_LO32:
53 return VE::fixup_ve_pc_lo32;
54 case VE::S_GOT_HI32:
55 return VE::fixup_ve_got_hi32;
56 case VE::S_GOT_LO32:
57 return VE::fixup_ve_got_lo32;
58 case VE::S_GOTOFF_HI32:
59 return VE::fixup_ve_gotoff_hi32;
60 case VE::S_GOTOFF_LO32:
61 return VE::fixup_ve_gotoff_lo32;
62 case VE::S_PLT_HI32:
63 return VE::fixup_ve_plt_hi32;
64 case VE::S_PLT_LO32:
65 return VE::fixup_ve_plt_lo32;
66 case VE::S_TLS_GD_HI32:
67 return VE::fixup_ve_tls_gd_hi32;
68 case VE::S_TLS_GD_LO32:
69 return VE::fixup_ve_tls_gd_lo32;
70 case VE::S_TPOFF_HI32:
71 return VE::fixup_ve_tpoff_hi32;
72 case VE::S_TPOFF_LO32:
73 return VE::fixup_ve_tpoff_lo32;
74 }
75}
76
77void VEELFMCAsmInfo::anchor() {}
78
79VEELFMCAsmInfo::VEELFMCAsmInfo(const Triple &TheTriple,
80 const MCTargetOptions &Options)
81 : MCAsmInfoELF(Options) {
82
83 CodePointerSize = CalleeSaveStackSlotSize = 8;
84 MaxInstLength = MinInstAlignment = 8;
85
86 // VE uses ".*byte" directive for unaligned data.
87 Data8bitsDirective = "\t.byte\t";
88 Data16bitsDirective = "\t.2byte\t";
89 Data32bitsDirective = "\t.4byte\t";
90 Data64bitsDirective = "\t.8byte\t";
91
92 // Uses '.section' before '.bss' directive. VE requires this although
93 // assembler manual says sinple '.bss' is supported.
94 UsesELFSectionDirectiveForBSS = true;
95
96 SupportsDebugInformation = true;
97
98 initializeAtSpecifiers(atSpecifiers);
99}
100
101void VEELFMCAsmInfo::printSpecifierExpr(raw_ostream &OS,
102 const MCSpecifierExpr &Expr) const {
103 printExpr(OS, *Expr.getSubExpr());
104 auto specifier = Expr.getSpecifier();
105 if (specifier && specifier != VE::S_REFLONG)
106 OS << '@' << getSpecifierName(S: specifier);
107}
108
109bool VEELFMCAsmInfo::evaluateAsRelocatableImpl(const MCSpecifierExpr &Expr,
110 MCValue &Res,
111 const MCAssembler *Asm) const {
112 if (!Expr.getSubExpr()->evaluateAsRelocatable(Res, Asm))
113 return false;
114 Res.setSpecifier(Expr.getSpecifier());
115 return true;
116}
117