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