1//===-- ARMMCAsmInfo.cpp - ARM 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 ARMMCAsmInfo properties.
10//
11//===----------------------------------------------------------------------===//
12
13#include "ARMMCAsmInfo.h"
14#include "ARMMCTargetDesc.h"
15#include "llvm/ADT/Enum.h"
16#include "llvm/MC/MCExpr.h"
17#include "llvm/MC/MCSubtargetInfo.h"
18#include "llvm/Support/raw_ostream.h"
19#include "llvm/TargetParser/Triple.h"
20
21using namespace llvm;
22
23constexpr EnumStringDef<MCAsmInfo::AtSpecifierKind> AtSpecifierDefs[] = {
24 {.Names: {"GOT_PREL"}, .Value: ARM::S_GOT_PREL},
25 {.Names: {"none"}, .Value: ARM::S_ARM_NONE},
26 {.Names: {"prel31"}, .Value: ARM::S_PREL31},
27 {.Names: {"sbrel"}, .Value: ARM::S_SBREL},
28 {.Names: {"target1"}, .Value: ARM::S_TARGET1},
29 {.Names: {"target2"}, .Value: ARM::S_TARGET2},
30 {.Names: {"TLSLDO"}, .Value: ARM::S_TLSLDO},
31 {.Names: {"imgrel"}, .Value: MCSymbolRefExpr::VK_COFF_IMGREL32},
32 {.Names: {"FUNCDESC"}, .Value: ARM::S_FUNCDESC},
33 {.Names: {"GOT"}, .Value: ARM::S_GOT},
34 {.Names: {"GOTFUNCDESC"}, .Value: ARM::S_GOTFUNCDESC},
35 {.Names: {"GOTOFF"}, .Value: ARM::S_GOTOFF},
36 {.Names: {"GOTOFFFUNCDESC"}, .Value: ARM::S_GOTOFFFUNCDESC},
37 {.Names: {"GOTTPOFF"}, .Value: ARM::S_GOTTPOFF},
38 {.Names: {"gottpoff_fdpic"}, .Value: ARM::S_GOTTPOFF_FDPIC},
39 {.Names: {"PLT"}, .Value: ARM::S_PLT},
40 {.Names: {"SECREL32"}, .Value: ARM::S_COFF_SECREL},
41 {.Names: {"tlscall"}, .Value: ARM::S_TLSCALL},
42 {.Names: {"tlsdesc"}, .Value: ARM::S_TLSDESC},
43 {.Names: {"TLSGD"}, .Value: ARM::S_TLSGD},
44 {.Names: {"tlsgd_fdpic"}, .Value: ARM::S_TLSGD_FDPIC},
45 {.Names: {"TLSLDM"}, .Value: ARM::S_TLSLDM},
46 {.Names: {"tlsldm_fdpic"}, .Value: ARM::S_TLSLDM_FDPIC},
47 {.Names: {"TPOFF"}, .Value: ARM::S_TPOFF},
48};
49constexpr auto atSpecifiers = BUILD_ENUM_STRINGS(AtSpecifierDefs);
50
51void ARMMCAsmInfoDarwin::anchor() { }
52
53ARMMCAsmInfoDarwin::ARMMCAsmInfoDarwin(const Triple &TheTriple,
54 const MCTargetOptions &Options)
55 : MCAsmInfoDarwin(Options) {
56 if ((TheTriple.getArch() == Triple::armeb) ||
57 (TheTriple.getArch() == Triple::thumbeb))
58 IsLittleEndian = false;
59
60 Data64bitsDirective = nullptr;
61 CommentString = "@";
62 UseDataRegionDirectives = true;
63
64 SupportsDebugInformation = true;
65
66 // Conditional Thumb 4-byte instructions can have an implicit IT.
67 MaxInstLength = 6;
68
69 initializeAtSpecifiers(atSpecifiers);
70}
71
72void ARMELFMCAsmInfo::anchor() { }
73
74ARMELFMCAsmInfo::ARMELFMCAsmInfo(const Triple &TheTriple,
75 const MCTargetOptions &Options)
76 : MCAsmInfoELF(Options) {
77 if ((TheTriple.getArch() == Triple::armeb) ||
78 (TheTriple.getArch() == Triple::thumbeb))
79 IsLittleEndian = false;
80
81 // ".comm align is in bytes but .align is pow-2."
82 AlignmentIsInBytes = false;
83
84 Data64bitsDirective = nullptr;
85 CommentString = "@";
86
87 SupportsDebugInformation = true;
88
89 // Conditional Thumb 4-byte instructions can have an implicit IT.
90 MaxInstLength = 6;
91
92 initializeAtSpecifiers(atSpecifiers);
93 // foo(plt) instead of foo@plt
94 UseAtForSpecifier = false;
95 UseParensForSpecifier = true;
96}
97
98void ARMELFMCAsmInfo::setUseIntegratedAssembler(bool Value) {
99 UseIntegratedAssembler = Value;
100 if (!UseIntegratedAssembler) {
101 // gas doesn't handle VFP register names in cfi directives,
102 // so don't use register names with external assembler.
103 // See https://sourceware.org/bugzilla/show_bug.cgi?id=16694
104 DwarfRegNumForCFI = true;
105 }
106}
107
108bool ARMELFMCAsmInfo::usesCompInstByteOrder(const MCSubtargetInfo &STI) const {
109 // Thumb encoding uses compressed instruction byte-order
110 return STI.hasFeature(Feature: ARM::ModeThumb);
111}
112
113void ARMCOFFMCAsmInfoMicrosoft::anchor() { }
114
115ARMCOFFMCAsmInfoMicrosoft::ARMCOFFMCAsmInfoMicrosoft(
116 const MCTargetOptions &Options)
117 : MCAsmInfoMicrosoft(Options) {
118 AlignmentIsInBytes = false;
119 SupportsDebugInformation = true;
120 WinEHEncodingType = WinEH::EncodingType::Itanium;
121 InternalSymbolPrefix = "$M";
122 CommentString = "@";
123
124 // Conditional Thumb 4-byte instructions can have an implicit IT.
125 MaxInstLength = 6;
126
127 initializeAtSpecifiers(atSpecifiers);
128}
129
130void ARMCOFFMCAsmInfoGNU::anchor() { }
131
132ARMCOFFMCAsmInfoGNU::ARMCOFFMCAsmInfoGNU(const MCTargetOptions &Options)
133 : MCAsmInfoGNUCOFF(Options) {
134 AlignmentIsInBytes = false;
135 HasSingleParameterDotFile = true;
136
137 CommentString = "@";
138 InternalSymbolPrefix = ".L";
139
140 SupportsDebugInformation = true;
141 WinEHEncodingType = WinEH::EncodingType::Itanium;
142 DwarfRegNumForCFI = false;
143
144 // Conditional Thumb 4-byte instructions can have an implicit IT.
145 MaxInstLength = 6;
146
147 initializeAtSpecifiers(atSpecifiers);
148 UseAtForSpecifier = false;
149 UseParensForSpecifier = true;
150}
151
152void ARM::printSpecifierExpr(const MCAsmInfo &MAI, raw_ostream &OS,
153 const MCSpecifierExpr &Expr) {
154 switch (Expr.getSpecifier()) {
155 default:
156 llvm_unreachable("Invalid kind!");
157 case ARM::S_HI16:
158 OS << ":upper16:";
159 break;
160 case ARM::S_LO16:
161 OS << ":lower16:";
162 break;
163 case ARM::S_HI_8_15:
164 OS << ":upper8_15:";
165 break;
166 case ARM::S_HI_0_7:
167 OS << ":upper0_7:";
168 break;
169 case ARM::S_LO_8_15:
170 OS << ":lower8_15:";
171 break;
172 case ARM::S_LO_0_7:
173 OS << ":lower0_7:";
174 break;
175 }
176
177 const MCExpr *Sub = Expr.getSubExpr();
178 if (Sub->getKind() != MCExpr::SymbolRef)
179 OS << '(';
180 MAI.printExpr(OS, *Sub);
181 if (Sub->getKind() != MCExpr::SymbolRef)
182 OS << ')';
183}
184
185const MCSpecifierExpr *ARM::createUpper16(const MCExpr *Expr, MCContext &Ctx) {
186 return MCSpecifierExpr::create(Expr, S: ARM::S_HI16, Ctx);
187}
188
189const MCSpecifierExpr *ARM::createLower16(const MCExpr *Expr, MCContext &Ctx) {
190 return MCSpecifierExpr::create(Expr, S: ARM::S_LO16, Ctx);
191}
192
193const MCSpecifierExpr *ARM::createUpper8_15(const MCExpr *Expr,
194 MCContext &Ctx) {
195 return MCSpecifierExpr::create(Expr, S: ARM::S_HI_8_15, Ctx);
196}
197
198const MCSpecifierExpr *ARM::createUpper0_7(const MCExpr *Expr, MCContext &Ctx) {
199 return MCSpecifierExpr::create(Expr, S: ARM::S_HI_0_7, Ctx);
200}
201
202const MCSpecifierExpr *ARM::createLower8_15(const MCExpr *Expr,
203 MCContext &Ctx) {
204 return MCSpecifierExpr::create(Expr, S: ARM::S_LO_8_15, Ctx);
205}
206
207const MCSpecifierExpr *ARM::createLower0_7(const MCExpr *Expr, MCContext &Ctx) {
208 return MCSpecifierExpr::create(Expr, S: ARM::S_LO_0_7, Ctx);
209}
210