1//===-- AArch64MCAsmInfo.cpp - AArch64 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 AArch64MCAsmInfo properties.
10//
11//===----------------------------------------------------------------------===//
12
13#include "AArch64MCAsmInfo.h"
14#include "llvm/MC/MCContext.h"
15#include "llvm/MC/MCExpr.h"
16#include "llvm/MC/MCStreamer.h"
17#include "llvm/Support/CommandLine.h"
18#include "llvm/TargetParser/Triple.h"
19using namespace llvm;
20
21enum AsmWriterVariantTy {
22 Default = -1,
23 Generic = 0,
24 Apple = 1
25};
26
27static cl::opt<AsmWriterVariantTy> AsmWriterVariant(
28 "aarch64-neon-syntax", cl::init(Val: Default),
29 cl::desc("Choose style of NEON code to emit from AArch64 backend:"),
30 cl::values(clEnumValN(Generic, "generic", "Emit generic NEON assembly"),
31 clEnumValN(Apple, "apple", "Emit Apple-style NEON assembly")));
32
33AArch64MCAsmInfoDarwin::AArch64MCAsmInfoDarwin(bool IsILP32) {
34 // We prefer NEON instructions to be printed in the short, Apple-specific
35 // form when targeting Darwin.
36 AssemblerDialect = AsmWriterVariant == Default ? Apple : AsmWriterVariant;
37
38 PrivateGlobalPrefix = "L";
39 PrivateLabelPrefix = "L";
40 SeparatorString = "%%";
41 CommentString = ";";
42 CalleeSaveStackSlotSize = 8;
43 CodePointerSize = IsILP32 ? 4 : 8;
44
45 AlignmentIsInBytes = false;
46 UsesELFSectionDirectiveForBSS = true;
47 SupportsDebugInformation = true;
48 UseDataRegionDirectives = true;
49
50 ExceptionsType = ExceptionHandling::DwarfCFI;
51}
52
53const MCExpr *AArch64MCAsmInfoDarwin::getExprForPersonalitySymbol(
54 const MCSymbol *Sym, unsigned Encoding, MCStreamer &Streamer) const {
55 // On Darwin, we can reference dwarf symbols with foo@GOT-., which
56 // is an indirect pc-relative reference. The default implementation
57 // won't reference using the GOT, so we need this target-specific
58 // version.
59 MCContext &Context = Streamer.getContext();
60 const MCExpr *Res =
61 MCSymbolRefExpr::create(Symbol: Sym, Kind: MCSymbolRefExpr::VK_GOT, Ctx&: Context);
62 MCSymbol *PCSym = Context.createTempSymbol();
63 Streamer.emitLabel(Symbol: PCSym);
64 const MCExpr *PC = MCSymbolRefExpr::create(Symbol: PCSym, Ctx&: Context);
65 return MCBinaryExpr::createSub(LHS: Res, RHS: PC, Ctx&: Context);
66}
67
68AArch64MCAsmInfoELF::AArch64MCAsmInfoELF(const Triple &T) {
69 if (T.getArch() == Triple::aarch64_be)
70 IsLittleEndian = false;
71
72 // We prefer NEON instructions to be printed in the generic form when
73 // targeting ELF.
74 AssemblerDialect = AsmWriterVariant == Default ? Generic : AsmWriterVariant;
75
76 CodePointerSize = T.getEnvironment() == Triple::GNUILP32 ? 4 : 8;
77
78 // ".comm align is in bytes but .align is pow-2."
79 AlignmentIsInBytes = false;
80
81 CommentString = "//";
82 PrivateGlobalPrefix = ".L";
83 PrivateLabelPrefix = ".L";
84 Code32Directive = ".code\t32";
85
86 Data16bitsDirective = "\t.hword\t";
87 Data32bitsDirective = "\t.word\t";
88 Data64bitsDirective = "\t.xword\t";
89
90 UseDataRegionDirectives = false;
91
92 WeakRefDirective = "\t.weak\t";
93
94 SupportsDebugInformation = true;
95
96 // Exceptions handling
97 ExceptionsType = ExceptionHandling::DwarfCFI;
98
99 HasIdentDirective = true;
100}
101
102AArch64MCAsmInfoMicrosoftCOFF::AArch64MCAsmInfoMicrosoftCOFF() {
103 PrivateGlobalPrefix = ".L";
104 PrivateLabelPrefix = ".L";
105
106 Data16bitsDirective = "\t.hword\t";
107 Data32bitsDirective = "\t.word\t";
108 Data64bitsDirective = "\t.xword\t";
109
110 AlignmentIsInBytes = false;
111 SupportsDebugInformation = true;
112 CodePointerSize = 8;
113
114 CommentString = "//";
115 ExceptionsType = ExceptionHandling::WinEH;
116 WinEHEncodingType = WinEH::EncodingType::Itanium;
117}
118
119AArch64MCAsmInfoGNUCOFF::AArch64MCAsmInfoGNUCOFF() {
120 PrivateGlobalPrefix = ".L";
121 PrivateLabelPrefix = ".L";
122
123 Data16bitsDirective = "\t.hword\t";
124 Data32bitsDirective = "\t.word\t";
125 Data64bitsDirective = "\t.xword\t";
126
127 AlignmentIsInBytes = false;
128 SupportsDebugInformation = true;
129 CodePointerSize = 8;
130
131 CommentString = "//";
132 ExceptionsType = ExceptionHandling::WinEH;
133 WinEHEncodingType = WinEH::EncodingType::Itanium;
134}
135