LLVM 22.0.0git
ARMTargetStreamer.cpp
Go to the documentation of this file.
1//===- ARMTargetStreamer.cpp - ARMTargetStreamer class --*- C++ -*---------===//
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 implements the ARMTargetStreamer class.
10//
11//===----------------------------------------------------------------------===//
12
15#include "llvm/MC/MCAsmInfo.h"
16#include "llvm/MC/MCContext.h"
17#include "llvm/MC/MCExpr.h"
18#include "llvm/MC/MCStreamer.h"
21
22using namespace llvm;
23
24//
25// ARMTargetStreamer Implemenation
26//
27
30
32
33// The constant pool handling is shared by all ARMTargetStreamer
34// implementations.
36 return ConstantPools->addEntry(Streamer, Expr, 4, Loc);
37}
38
40 ConstantPools->emitForCurrentSection(Streamer);
41 ConstantPools->clearCacheForCurrentSection(Streamer);
42}
43
44// finish() - write out any non-empty assembler constant pools.
46 ConstantPools->emitAll(Streamer);
47}
48
49// reset() - Reset any state
51
52void ARMTargetStreamer::emitInst(uint32_t Inst, char Suffix) {
53 unsigned Size;
54 char Buffer[4];
55 const bool LittleEndian = getContext().getAsmInfo()->isLittleEndian();
56
57 switch (Suffix) {
58 case '\0':
59 Size = 4;
60
61 for (unsigned II = 0, IE = Size; II != IE; II++) {
62 const unsigned I = LittleEndian ? (Size - II - 1) : II;
63 Buffer[Size - II - 1] = uint8_t(Inst >> I * CHAR_BIT);
64 }
65
66 break;
67 case 'n':
68 case 'w':
69 Size = (Suffix == 'n' ? 2 : 4);
70
71 // Thumb wide instructions are emitted as a pair of 16-bit words of the
72 // appropriate endianness.
73 for (unsigned II = 0, IE = Size; II != IE; II = II + 2) {
74 const unsigned I0 = LittleEndian ? II + 0 : II + 1;
75 const unsigned I1 = LittleEndian ? II + 1 : II + 0;
76 Buffer[Size - II - 2] = uint8_t(Inst >> I0 * CHAR_BIT);
77 Buffer[Size - II - 1] = uint8_t(Inst >> I1 * CHAR_BIT);
78 }
79
80 break;
81 default:
82 llvm_unreachable("Invalid Suffix");
83 }
85}
86
87// The remaining callbacks should be handled separately by each
88// streamer.
96 int64_t Offset) {}
100 bool isVector) {}
109 unsigned IntValue,
110 StringRef StringValue) {}
123
125void ARMTargetStreamer::emitARMWinCFISaveRegMask(unsigned Mask, bool Wide) {}
134
136 if (STI.getCPU() == "xscale")
138
139 if (STI.hasFeature(ARM::HasV9_0aOps))
140 return ARMBuildAttrs::v9_A;
141 else if (STI.hasFeature(ARM::HasV8Ops)) {
142 if (STI.hasFeature(ARM::FeatureRClass))
143 return ARMBuildAttrs::v8_R;
144 return ARMBuildAttrs::v8_A;
145 } else if (STI.hasFeature(ARM::HasV8_1MMainlineOps))
147 else if (STI.hasFeature(ARM::HasV8MMainlineOps))
149 else if (STI.hasFeature(ARM::HasV7Ops)) {
150 if (STI.hasFeature(ARM::FeatureMClass) && STI.hasFeature(ARM::FeatureDSP))
152 return ARMBuildAttrs::v7;
153 } else if (STI.hasFeature(ARM::HasV6T2Ops))
154 return ARMBuildAttrs::v6T2;
155 else if (STI.hasFeature(ARM::HasV8MBaselineOps))
157 else if (STI.hasFeature(ARM::HasV6MOps))
159 else if (STI.hasFeature(ARM::HasV6Ops))
160 return ARMBuildAttrs::v6;
161 else if (STI.hasFeature(ARM::HasV5TEOps))
162 return ARMBuildAttrs::v5TE;
163 else if (STI.hasFeature(ARM::HasV5TOps))
164 return ARMBuildAttrs::v5T;
165 else if (STI.hasFeature(ARM::HasV4TOps))
166 return ARMBuildAttrs::v4T;
167 else
168 return ARMBuildAttrs::v4;
169}
170
171static bool isV8M(const MCSubtargetInfo &STI) {
172 // Note that v8M Baseline is a subset of v6T2!
173 return (STI.hasFeature(ARM::HasV8MBaselineOps) &&
174 !STI.hasFeature(ARM::HasV6T2Ops)) ||
175 STI.hasFeature(ARM::HasV8MMainlineOps);
176}
177
178/// Emit the build attributes that only depend on the hardware that we expect
179// /to be available, and not on the ABI, or any source-language choices.
181 switchVendor("aeabi");
182
183 const StringRef CPUString = STI.getCPU();
184 if (!CPUString.empty() && !CPUString.starts_with("generic")) {
185 // FIXME: remove krait check when GNU tools support krait cpu
186 if (STI.hasFeature(ARM::ProcKrait)) {
188 // We consider krait as a "cortex-a9" + hwdiv CPU
189 // Enable hwdiv through ".arch_extension idiv"
190 if (STI.hasFeature(ARM::FeatureHWDivThumb) ||
191 STI.hasFeature(ARM::FeatureHWDivARM))
193 } else {
195 }
196 }
197
199
200 if (STI.hasFeature(ARM::FeatureAClass)) {
203 } else if (STI.hasFeature(ARM::FeatureRClass)) {
206 } else if (STI.hasFeature(ARM::FeatureMClass)) {
209 }
210
214
215 if (isV8M(STI)) {
218 } else if (STI.hasFeature(ARM::FeatureThumb2)) {
221 } else if (STI.hasFeature(ARM::HasV4TOps)) {
223 }
224
225 if (STI.hasFeature(ARM::FeatureNEON)) {
226 /* NEON is not exactly a VFP architecture, but GAS emit one of
227 * neon/neon-fp-armv8/neon-vfpv4/vfpv3/vfpv2 for .fpu parameters */
228 if (STI.hasFeature(ARM::FeatureFPARMv8)) {
229 if (STI.hasFeature(ARM::FeatureCrypto))
230 emitFPU(ARM::FK_CRYPTO_NEON_FP_ARMV8);
231 else
232 emitFPU(ARM::FK_NEON_FP_ARMV8);
233 } else if (STI.hasFeature(ARM::FeatureVFP4))
234 emitFPU(ARM::FK_NEON_VFPV4);
235 else
236 emitFPU(STI.hasFeature(ARM::FeatureFP16) ? ARM::FK_NEON_FP16
237 : ARM::FK_NEON);
238 // Emit Tag_Advanced_SIMD_arch for ARMv8 architecture
239 if (STI.hasFeature(ARM::HasV8Ops))
241 STI.hasFeature(ARM::HasV8_1aOps)
244 } else {
245 if (STI.hasFeature(ARM::FeatureFPARMv8_D16_SP)) {
246 // FPv5 and FP-ARMv8 have the same instructions, so are modeled as one
247 // FPU, but there are two different names for it depending on the CPU.
248 if (STI.hasFeature(ARM::FeatureD32))
249 emitFPU(ARM::FK_FP_ARMV8);
250 else {
251 emitFPU(STI.hasFeature(ARM::FeatureFP64) ? ARM::FK_FPV5_D16
252 : ARM::FK_FPV5_SP_D16);
253 if (STI.hasFeature(ARM::HasMVEFloatOps))
255 }
256 } else if (STI.hasFeature(ARM::FeatureVFP4_D16_SP))
257 emitFPU(STI.hasFeature(ARM::FeatureD32)
258 ? ARM::FK_VFPV4
259 : (STI.hasFeature(ARM::FeatureFP64) ? ARM::FK_VFPV4_D16
260 : ARM::FK_FPV4_SP_D16));
261 else if (STI.hasFeature(ARM::FeatureVFP3_D16_SP))
262 emitFPU(
263 STI.hasFeature(ARM::FeatureD32)
264 // +d32
265 ? (STI.hasFeature(ARM::FeatureFP16) ? ARM::FK_VFPV3_FP16
266 : ARM::FK_VFPV3)
267 // -d32
268 : (STI.hasFeature(ARM::FeatureFP64)
269 ? (STI.hasFeature(ARM::FeatureFP16)
270 ? ARM::FK_VFPV3_D16_FP16
271 : ARM::FK_VFPV3_D16)
272 : (STI.hasFeature(ARM::FeatureFP16) ? ARM::FK_VFPV3XD_FP16
273 : ARM::FK_VFPV3XD)));
274 else if (STI.hasFeature(ARM::FeatureVFP2_SP))
275 emitFPU(ARM::FK_VFPV2);
276 }
277
278 // ABI_HardFP_use attribute to indicate single precision FP.
279 if (STI.hasFeature(ARM::FeatureVFP2_SP) && !STI.hasFeature(ARM::FeatureFP64))
282
283 if (STI.hasFeature(ARM::FeatureFP16))
285
286 if (STI.hasFeature(ARM::FeatureMP))
288
289 if (STI.hasFeature(ARM::HasMVEFloatOps))
291 else if (STI.hasFeature(ARM::HasMVEIntegerOps))
293
294 // Hardware divide in ARM mode is part of base arch, starting from ARMv8.
295 // If only Thumb hwdiv is present, it must also be in base arch (ARMv7-R/M).
296 // It is not possible to produce DisallowDIV: if hwdiv is present in the base
297 // arch, supplying -hwdiv downgrades the effective arch, via ClearImpliedBits.
298 // AllowDIVExt is only emitted if hwdiv isn't available in the base arch;
299 // otherwise, the default value (AllowDIVIfExists) applies.
300 if (STI.hasFeature(ARM::FeatureHWDivARM) && !STI.hasFeature(ARM::HasV8Ops))
302
303 if (STI.hasFeature(ARM::FeatureDSP) && isV8M(STI))
305
306 if (STI.hasFeature(ARM::FeatureStrictAlign))
309 else
312
313 if (STI.hasFeature(ARM::FeatureTrustZone) &&
314 STI.hasFeature(ARM::FeatureVirtualization))
317 else if (STI.hasFeature(ARM::FeatureTrustZone))
319 else if (STI.hasFeature(ARM::FeatureVirtualization))
322
323 if (STI.hasFeature(ARM::FeaturePACBTI)) {
326 }
327}
328
331 const Triple &TT = STI.getTargetTriple();
332 if (TT.isOSBinFormatELF())
334 if (TT.isOSBinFormatCOFF())
336 if (TT.isOSBinFormatMachO())
338 return new ARMTargetStreamer(S);
339}
static bool isV8M(const MCSubtargetInfo &STI)
static ARMBuildAttrs::CPUArch getArchForCPU(const MCSubtargetInfo &STI)
#define I(x, y, z)
Definition MD5.cpp:58
uint64_t IntrinsicInst * II
virtual void emitUnwindRaw(int64_t StackOffset, const SmallVectorImpl< uint8_t > &Opcodes)
~ARMTargetStreamer() override
void emitTargetAttributes(const MCSubtargetInfo &STI)
Emit the build attributes that only depend on the hardware that we expect.
virtual void reset()
Reset any state between object emissions, i.e.
virtual void emitSetFP(MCRegister FpReg, MCRegister SpReg, int64_t Offset=0)
virtual void annotateTLSDescriptorSequence(const MCSymbolRefExpr *SRE)
virtual void finishAttributeSection()
virtual void emitMovSP(MCRegister Reg, int64_t Offset=0)
virtual void emitARMWinCFISaveSP(unsigned Reg)
virtual void emitPersonalityIndex(unsigned Index)
virtual void emitInst(uint32_t Inst, char Suffix='\0')
virtual void emitARMWinCFISaveLR(unsigned Offset)
virtual void emitArchExtension(uint64_t ArchExt)
virtual void emitTextAttribute(unsigned Attribute, StringRef String)
virtual void emitARMWinCFIAllocStack(unsigned Size, bool Wide)
virtual void emitARMWinCFICustom(unsigned Opcode)
virtual void emitARMWinCFISaveRegMask(unsigned Mask, bool Wide)
virtual void emitRegSave(const SmallVectorImpl< MCRegister > &RegList, bool isVector)
virtual void emitARMWinCFIEpilogEnd()
virtual void emitARMWinCFIPrologEnd(bool Fragment)
virtual void switchVendor(StringRef Vendor)
virtual void emitPersonality(const MCSymbol *Personality)
virtual void emitObjectArch(ARM::ArchKind Arch)
const MCExpr * addConstantPoolEntry(const MCExpr *, SMLoc Loc)
Callback used to implement the ldr= pseudo.
virtual void emitIntTextAttribute(unsigned Attribute, unsigned IntValue, StringRef StringValue="")
virtual void emitThumbSet(MCSymbol *Symbol, const MCExpr *Value)
virtual void emitThumbFunc(MCSymbol *Symbol)
virtual void emitFPU(ARM::FPUKind FPU)
virtual void emitARMWinCFISaveFRegs(unsigned First, unsigned Last)
virtual void emitARMWinCFIEpilogStart(unsigned Condition)
virtual void emitPad(int64_t Offset)
void emitCurrentConstantPool()
Callback used to implement the .ltorg directive.
virtual void emitAttribute(unsigned Attribute, unsigned Value)
virtual void emitARMWinCFINop(bool Wide)
void emitConstantPools() override
virtual void emitArch(ARM::ArchKind Arch)
Functions, function parameters, and return types can have attributes to indicate how they should be t...
Definition Attributes.h:69
bool isLittleEndian() const
True if the target is little endian.
Definition MCAsmInfo.h:452
const MCAsmInfo * getAsmInfo() const
Definition MCContext.h:412
Base class for the full range of assembler expressions which are needed for parsing.
Definition MCExpr.h:34
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:33
Streaming machine code generation interface.
Definition MCStreamer.h:220
virtual void emitBytes(StringRef Data)
Emit the bytes in Data into the output.
Generic base class for all target subtargets.
bool hasFeature(unsigned Feature) const
const Triple & getTargetTriple() const
StringRef getCPU() const
Represent a reference to a symbol from inside an expression.
Definition MCExpr.h:190
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition MCSymbol.h:42
Target specific streamer interface.
Definition MCStreamer.h:93
MCStreamer & getStreamer()
Definition MCStreamer.h:101
MCContext & getContext()
MCStreamer & Streamer
Definition MCStreamer.h:95
MCTargetStreamer(MCStreamer &S)
Represents a location in source code.
Definition SMLoc.h:23
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
StackOffset holds a fixed and a scalable offset in bytes.
Definition TypeSize.h:31
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition StringRef.h:269
constexpr bool empty() const
empty - Check if the string is empty.
Definition StringRef.h:151
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:47
LLVM Value Representation.
Definition Value.h:75
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:477
MCTargetStreamer * createARMObjectTargetMachOStreamer(MCStreamer &S)
MCTargetStreamer * createARMObjectTargetELFStreamer(MCStreamer &S)
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
Definition ModRef.h:71
MCTargetStreamer * createARMObjectTargetWinCOFFStreamer(MCStreamer &S)
MCTargetStreamer * createARMObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI)