xref: /openbsd-src/gnu/llvm/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCAsmInfo.cpp (revision 73471bf04ceb096474c7f0fa83b1b65c70a787a1)
109467b48Spatrick //===-- AArch64MCAsmInfo.cpp - AArch64 asm properties ---------------------===//
209467b48Spatrick //
309467b48Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
409467b48Spatrick // See https://llvm.org/LICENSE.txt for license information.
509467b48Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
609467b48Spatrick //
709467b48Spatrick //===----------------------------------------------------------------------===//
809467b48Spatrick //
909467b48Spatrick // This file contains the declarations of the AArch64MCAsmInfo properties.
1009467b48Spatrick //
1109467b48Spatrick //===----------------------------------------------------------------------===//
1209467b48Spatrick 
1309467b48Spatrick #include "AArch64MCAsmInfo.h"
1409467b48Spatrick #include "llvm/ADT/Triple.h"
1509467b48Spatrick #include "llvm/MC/MCContext.h"
1609467b48Spatrick #include "llvm/MC/MCExpr.h"
1709467b48Spatrick #include "llvm/MC/MCStreamer.h"
1809467b48Spatrick #include "llvm/Support/CommandLine.h"
1909467b48Spatrick using namespace llvm;
2009467b48Spatrick 
2109467b48Spatrick enum AsmWriterVariantTy {
2209467b48Spatrick   Default = -1,
2309467b48Spatrick   Generic = 0,
2409467b48Spatrick   Apple = 1
2509467b48Spatrick };
2609467b48Spatrick 
2709467b48Spatrick static cl::opt<AsmWriterVariantTy> AsmWriterVariant(
2809467b48Spatrick     "aarch64-neon-syntax", cl::init(Default),
2909467b48Spatrick     cl::desc("Choose style of NEON code to emit from AArch64 backend:"),
3009467b48Spatrick     cl::values(clEnumValN(Generic, "generic", "Emit generic NEON assembly"),
3109467b48Spatrick                clEnumValN(Apple, "apple", "Emit Apple-style NEON assembly")));
3209467b48Spatrick 
AArch64MCAsmInfoDarwin(bool IsILP32)3309467b48Spatrick AArch64MCAsmInfoDarwin::AArch64MCAsmInfoDarwin(bool IsILP32) {
3409467b48Spatrick   // We prefer NEON instructions to be printed in the short, Apple-specific
3509467b48Spatrick   // form when targeting Darwin.
3609467b48Spatrick   AssemblerDialect = AsmWriterVariant == Default ? Apple : AsmWriterVariant;
3709467b48Spatrick 
3809467b48Spatrick   PrivateGlobalPrefix = "L";
3909467b48Spatrick   PrivateLabelPrefix = "L";
4009467b48Spatrick   SeparatorString = "%%";
4109467b48Spatrick   CommentString = ";";
4209467b48Spatrick   CalleeSaveStackSlotSize = 8;
4309467b48Spatrick   CodePointerSize = IsILP32 ? 4 : 8;
4409467b48Spatrick 
4509467b48Spatrick   AlignmentIsInBytes = false;
4609467b48Spatrick   UsesELFSectionDirectiveForBSS = true;
4709467b48Spatrick   SupportsDebugInformation = true;
4809467b48Spatrick   UseDataRegionDirectives = true;
4909467b48Spatrick 
5009467b48Spatrick   ExceptionsType = ExceptionHandling::DwarfCFI;
5109467b48Spatrick }
5209467b48Spatrick 
getExprForPersonalitySymbol(const MCSymbol * Sym,unsigned Encoding,MCStreamer & Streamer) const5309467b48Spatrick const MCExpr *AArch64MCAsmInfoDarwin::getExprForPersonalitySymbol(
5409467b48Spatrick     const MCSymbol *Sym, unsigned Encoding, MCStreamer &Streamer) const {
5509467b48Spatrick   // On Darwin, we can reference dwarf symbols with foo@GOT-., which
5609467b48Spatrick   // is an indirect pc-relative reference. The default implementation
5709467b48Spatrick   // won't reference using the GOT, so we need this target-specific
5809467b48Spatrick   // version.
5909467b48Spatrick   MCContext &Context = Streamer.getContext();
6009467b48Spatrick   const MCExpr *Res =
6109467b48Spatrick       MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_GOT, Context);
6209467b48Spatrick   MCSymbol *PCSym = Context.createTempSymbol();
63097a140dSpatrick   Streamer.emitLabel(PCSym);
6409467b48Spatrick   const MCExpr *PC = MCSymbolRefExpr::create(PCSym, Context);
6509467b48Spatrick   return MCBinaryExpr::createSub(Res, PC, Context);
6609467b48Spatrick }
6709467b48Spatrick 
AArch64MCAsmInfoELF(const Triple & T)6809467b48Spatrick AArch64MCAsmInfoELF::AArch64MCAsmInfoELF(const Triple &T) {
6909467b48Spatrick   if (T.getArch() == Triple::aarch64_be)
7009467b48Spatrick     IsLittleEndian = false;
7109467b48Spatrick 
7209467b48Spatrick   // We prefer NEON instructions to be printed in the generic form when
7309467b48Spatrick   // targeting ELF.
7409467b48Spatrick   AssemblerDialect = AsmWriterVariant == Default ? Generic : AsmWriterVariant;
7509467b48Spatrick 
76*73471bf0Spatrick   CodePointerSize = T.getEnvironment() == Triple::GNUILP32 ? 4 : 8;
7709467b48Spatrick 
7809467b48Spatrick   // ".comm align is in bytes but .align is pow-2."
7909467b48Spatrick   AlignmentIsInBytes = false;
8009467b48Spatrick 
8109467b48Spatrick   CommentString = "//";
8209467b48Spatrick   PrivateGlobalPrefix = ".L";
8309467b48Spatrick   PrivateLabelPrefix = ".L";
8409467b48Spatrick   Code32Directive = ".code\t32";
8509467b48Spatrick 
8609467b48Spatrick   Data16bitsDirective = "\t.hword\t";
8709467b48Spatrick   Data32bitsDirective = "\t.word\t";
8809467b48Spatrick   Data64bitsDirective = "\t.xword\t";
8909467b48Spatrick 
9009467b48Spatrick   UseDataRegionDirectives = false;
9109467b48Spatrick 
9209467b48Spatrick   WeakRefDirective = "\t.weak\t";
9309467b48Spatrick 
9409467b48Spatrick   SupportsDebugInformation = true;
9509467b48Spatrick 
9609467b48Spatrick   // Exceptions handling
9709467b48Spatrick   ExceptionsType = ExceptionHandling::DwarfCFI;
9809467b48Spatrick 
9909467b48Spatrick   HasIdentDirective = true;
10009467b48Spatrick }
10109467b48Spatrick 
AArch64MCAsmInfoMicrosoftCOFF()10209467b48Spatrick AArch64MCAsmInfoMicrosoftCOFF::AArch64MCAsmInfoMicrosoftCOFF() {
10309467b48Spatrick   PrivateGlobalPrefix = ".L";
10409467b48Spatrick   PrivateLabelPrefix = ".L";
10509467b48Spatrick 
10609467b48Spatrick   Data16bitsDirective = "\t.hword\t";
10709467b48Spatrick   Data32bitsDirective = "\t.word\t";
10809467b48Spatrick   Data64bitsDirective = "\t.xword\t";
10909467b48Spatrick 
11009467b48Spatrick   AlignmentIsInBytes = false;
11109467b48Spatrick   SupportsDebugInformation = true;
11209467b48Spatrick   CodePointerSize = 8;
11309467b48Spatrick 
114*73471bf0Spatrick   CommentString = "//";
11509467b48Spatrick   ExceptionsType = ExceptionHandling::WinEH;
11609467b48Spatrick   WinEHEncodingType = WinEH::EncodingType::Itanium;
11709467b48Spatrick }
11809467b48Spatrick 
AArch64MCAsmInfoGNUCOFF()11909467b48Spatrick AArch64MCAsmInfoGNUCOFF::AArch64MCAsmInfoGNUCOFF() {
12009467b48Spatrick   PrivateGlobalPrefix = ".L";
12109467b48Spatrick   PrivateLabelPrefix = ".L";
12209467b48Spatrick 
12309467b48Spatrick   Data16bitsDirective = "\t.hword\t";
12409467b48Spatrick   Data32bitsDirective = "\t.word\t";
12509467b48Spatrick   Data64bitsDirective = "\t.xword\t";
12609467b48Spatrick 
12709467b48Spatrick   AlignmentIsInBytes = false;
12809467b48Spatrick   SupportsDebugInformation = true;
12909467b48Spatrick   CodePointerSize = 8;
13009467b48Spatrick 
13109467b48Spatrick   CommentString = "//";
13209467b48Spatrick   ExceptionsType = ExceptionHandling::WinEH;
13309467b48Spatrick   WinEHEncodingType = WinEH::EncodingType::Itanium;
13409467b48Spatrick }
135