LLVM  15.0.0git
ARMAttributeParser.cpp
Go to the documentation of this file.
1 //===- ARMAttributeParser.cpp - ARM Attribute Information Printer ---------===//
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 
11 #include "llvm/ADT/StringExtras.h"
13 
14 using namespace llvm;
15 using namespace llvm::ARMBuildAttrs;
16 
17 #define ATTRIBUTE_HANDLER(attr) \
18  { ARMBuildAttrs::attr, &ARMAttributeParser::attr }
19 
20 const ARMAttributeParser::DisplayHandler ARMAttributeParser::displayRoutines[] =
21  {
22  {ARMBuildAttrs::CPU_raw_name, &ARMAttributeParser::stringAttribute},
23  {ARMBuildAttrs::CPU_name, &ARMAttributeParser::stringAttribute},
65 };
66 
67 #undef ATTRIBUTE_HANDLER
68 
69 Error ARMAttributeParser::stringAttribute(AttrType tag) {
70  StringRef tagName =
71  ELFAttrs::attrTypeAsString(tag, tagToStringMap, /*hasTagPrefix=*/false);
72  StringRef desc = de.getCStrRef(cursor);
73 
74  if (sw) {
75  DictScope scope(*sw, "Attribute");
76  sw->printNumber("Tag", tag);
77  if (!tagName.empty())
78  sw->printString("TagName", tagName);
79  sw->printString("Value", desc);
80  }
81  return Error::success();
82 }
83 
84 Error ARMAttributeParser::CPU_arch(AttrType tag) {
85  static const char *strings[] = {
86  "Pre-v4", "ARM v4", "ARM v4T", "ARM v5T", "ARM v5TE", "ARM v5TEJ", "ARM v6",
87  "ARM v6KZ", "ARM v6T2", "ARM v6K", "ARM v7", "ARM v6-M", "ARM v6S-M",
88  "ARM v7E-M", "ARM v8", nullptr,
89  "ARM v8-M Baseline", "ARM v8-M Mainline", nullptr, nullptr, nullptr,
90  "ARM v8.1-M Mainline", "ARM v9-A"
91  };
92  return parseStringAttribute("CPU_arch", tag, makeArrayRef(strings));
93 }
94 
95 Error ARMAttributeParser::CPU_arch_profile(AttrType tag) {
96  uint64_t value = de.getULEB128(cursor);
97 
98  StringRef profile;
99  switch (value) {
100  default: profile = "Unknown"; break;
101  case 'A': profile = "Application"; break;
102  case 'R': profile = "Real-time"; break;
103  case 'M': profile = "Microcontroller"; break;
104  case 'S': profile = "Classic"; break;
105  case 0: profile = "None"; break;
106  }
107 
108  printAttribute(tag, value, profile);
109  return Error::success();
110 }
111 
112 Error ARMAttributeParser::ARM_ISA_use(AttrType tag) {
113  static const char *strings[] = {"Not Permitted", "Permitted"};
114  return parseStringAttribute("ARM_ISA_use", tag, makeArrayRef(strings));
115 }
116 
117 Error ARMAttributeParser::THUMB_ISA_use(AttrType tag) {
118  static const char *strings[] = {"Not Permitted", "Thumb-1", "Thumb-2", "Permitted"};
119  return parseStringAttribute("THUMB_ISA_use", tag, makeArrayRef(strings));
120 }
121 
122 Error ARMAttributeParser::FP_arch(AttrType tag) {
123  static const char *strings[] = {
124  "Not Permitted", "VFPv1", "VFPv2", "VFPv3", "VFPv3-D16",
125  "VFPv4", "VFPv4-D16", "ARMv8-a FP", "ARMv8-a FP-D16"};
126  return parseStringAttribute("FP_arch", tag, makeArrayRef(strings));
127 }
128 
129 Error ARMAttributeParser::WMMX_arch(AttrType tag) {
130  static const char *strings[] = {"Not Permitted", "WMMXv1", "WMMXv2"};
131  return parseStringAttribute("WMMX_arch", tag, makeArrayRef(strings));
132 }
133 
134 Error ARMAttributeParser::Advanced_SIMD_arch(AttrType tag) {
135  static const char *strings[] = {"Not Permitted", "NEONv1", "NEONv2+FMA",
136  "ARMv8-a NEON", "ARMv8.1-a NEON"};
137  return parseStringAttribute("Advanced_SIMD_arch", tag, makeArrayRef(strings));
138 }
139 
140 Error ARMAttributeParser::MVE_arch(AttrType tag) {
141  static const char *strings[] = {"Not Permitted", "MVE integer",
142  "MVE integer and float"};
143  return parseStringAttribute("MVE_arch", tag, makeArrayRef(strings));
144 }
145 
146 Error ARMAttributeParser::PCS_config(AttrType tag) {
147  static const char *strings[] = {
148  "None", "Bare Platform", "Linux Application", "Linux DSO", "Palm OS 2004",
149  "Reserved (Palm OS)", "Symbian OS 2004", "Reserved (Symbian OS)"};
150  return parseStringAttribute("PCS_config", tag, makeArrayRef(strings));
151 }
152 
153 Error ARMAttributeParser::ABI_PCS_R9_use(AttrType tag) {
154  static const char *strings[] = {"v6", "Static Base", "TLS", "Unused"};
155  return parseStringAttribute("ABI_PCS_R9_use", tag, makeArrayRef(strings));
156 }
157 
158 Error ARMAttributeParser::ABI_PCS_RW_data(AttrType tag) {
159  static const char *strings[] = {"Absolute", "PC-relative", "SB-relative",
160  "Not Permitted"};
161  return parseStringAttribute("ABI_PCS_RW_data", tag, makeArrayRef(strings));
162 }
163 
164 Error ARMAttributeParser::ABI_PCS_RO_data(AttrType tag) {
165  static const char *strings[] = {"Absolute", "PC-relative", "Not Permitted"};
166  return parseStringAttribute("ABI_PCS_RO_data", tag, makeArrayRef(strings));
167 }
168 
169 Error ARMAttributeParser::ABI_PCS_GOT_use(AttrType tag) {
170  static const char *strings[] = {"Not Permitted", "Direct", "GOT-Indirect"};
171  return parseStringAttribute("ABI_PCS_GOT_use", tag, makeArrayRef(strings));
172 }
173 
174 Error ARMAttributeParser::ABI_PCS_wchar_t(AttrType tag) {
175  static const char *strings[] = {"Not Permitted", "Unknown", "2-byte",
176  "Unknown", "4-byte"};
177  return parseStringAttribute("ABI_PCS_wchar_t", tag, makeArrayRef(strings));
178 }
179 
180 Error ARMAttributeParser::ABI_FP_rounding(AttrType tag) {
181  static const char *strings[] = {"IEEE-754", "Runtime"};
182  return parseStringAttribute("ABI_FP_rounding", tag, makeArrayRef(strings));
183 }
184 
185 Error ARMAttributeParser::ABI_FP_denormal(AttrType tag) {
186  static const char *strings[] = {"Unsupported", "IEEE-754", "Sign Only"};
187  return parseStringAttribute("ABI_FP_denormal", tag, makeArrayRef(strings));
188 }
189 
190 Error ARMAttributeParser::ABI_FP_exceptions(AttrType tag) {
191  static const char *strings[] = {"Not Permitted", "IEEE-754"};
192  return parseStringAttribute("ABI_FP_exceptions", tag, makeArrayRef(strings));
193 }
194 Error ARMAttributeParser::ABI_FP_user_exceptions(AttrType tag) {
195  static const char *strings[] = {"Not Permitted", "IEEE-754"};
196  return parseStringAttribute("ABI_FP_user_exceptions", tag,
197  makeArrayRef(strings));
198 }
199 
200 Error ARMAttributeParser::ABI_FP_number_model(AttrType tag) {
201  static const char *strings[] = {"Not Permitted", "Finite Only", "RTABI",
202  "IEEE-754"};
203  return parseStringAttribute("ABI_FP_number_model", tag,
204  makeArrayRef(strings));
205 }
206 
207 Error ARMAttributeParser::ABI_align_needed(AttrType tag) {
208  static const char *strings[] = {"Not Permitted", "8-byte alignment",
209  "4-byte alignment", "Reserved"};
210 
211  uint64_t value = de.getULEB128(cursor);
212 
213  std::string description;
214  if (value < array_lengthof(strings))
215  description = strings[value];
216  else if (value <= 12)
217  description = "8-byte alignment, " + utostr(1ULL << value) +
218  "-byte extended alignment";
219  else
220  description = "Invalid";
221 
222  printAttribute(tag, value, description);
223  return Error::success();
224 }
225 
226 Error ARMAttributeParser::ABI_align_preserved(AttrType tag) {
227  static const char *strings[] = {"Not Required", "8-byte data alignment",
228  "8-byte data and code alignment", "Reserved"};
229 
230  uint64_t value = de.getULEB128(cursor);
231 
232  std::string description;
233  if (value < array_lengthof(strings))
234  description = std::string(strings[value]);
235  else if (value <= 12)
236  description = std::string("8-byte stack alignment, ") +
237  utostr(1ULL << value) + std::string("-byte data alignment");
238  else
239  description = "Invalid";
240 
241  printAttribute(tag, value, description);
242  return Error::success();
243 }
244 
245 Error ARMAttributeParser::ABI_enum_size(AttrType tag) {
246  static const char *strings[] = {"Not Permitted", "Packed", "Int32",
247  "External Int32"};
248  return parseStringAttribute("ABI_enum_size", tag, makeArrayRef(strings));
249 }
250 
251 Error ARMAttributeParser::ABI_HardFP_use(AttrType tag) {
252  static const char *strings[] = {"Tag_FP_arch", "Single-Precision", "Reserved",
253  "Tag_FP_arch (deprecated)"};
254  return parseStringAttribute("ABI_HardFP_use", tag, makeArrayRef(strings));
255 }
256 
257 Error ARMAttributeParser::ABI_VFP_args(AttrType tag) {
258  static const char *strings[] = {"AAPCS", "AAPCS VFP", "Custom",
259  "Not Permitted"};
260  return parseStringAttribute("ABI_VFP_args", tag, makeArrayRef(strings));
261 }
262 
263 Error ARMAttributeParser::ABI_WMMX_args(AttrType tag) {
264  static const char *strings[] = {"AAPCS", "iWMMX", "Custom"};
265  return parseStringAttribute("ABI_WMMX_args", tag, makeArrayRef(strings));
266 }
267 
268 Error ARMAttributeParser::ABI_optimization_goals(AttrType tag) {
269  static const char *strings[] = {
270  "None", "Speed", "Aggressive Speed", "Size", "Aggressive Size", "Debugging",
271  "Best Debugging"
272  };
273  return parseStringAttribute("ABI_optimization_goals", tag,
274  makeArrayRef(strings));
275 }
276 
277 Error ARMAttributeParser::ABI_FP_optimization_goals(AttrType tag) {
278  static const char *strings[] = {
279  "None", "Speed", "Aggressive Speed", "Size", "Aggressive Size",
280  "Accuracy", "Best Accuracy"};
281  return parseStringAttribute("ABI_FP_optimization_goals", tag,
282  makeArrayRef(strings));
283 }
284 
285 Error ARMAttributeParser::compatibility(AttrType tag) {
286  uint64_t integer = de.getULEB128(cursor);
287  StringRef string = de.getCStrRef(cursor);
288 
289  if (sw) {
290  DictScope scope(*sw, "Attribute");
291  sw->printNumber("Tag", tag);
292  sw->startLine() << "Value: " << integer << ", " << string << '\n';
293  sw->printString("TagName",
294  ELFAttrs::attrTypeAsString(tag, tagToStringMap,
295  /*hasTagPrefix=*/false));
296  switch (integer) {
297  case 0:
298  sw->printString("Description", StringRef("No Specific Requirements"));
299  break;
300  case 1:
301  sw->printString("Description", StringRef("AEABI Conformant"));
302  break;
303  default:
304  sw->printString("Description", StringRef("AEABI Non-Conformant"));
305  break;
306  }
307  }
308  return Error::success();
309 }
310 
311 Error ARMAttributeParser::CPU_unaligned_access(AttrType tag) {
312  static const char *strings[] = {"Not Permitted", "v6-style"};
313  return parseStringAttribute("CPU_unaligned_access", tag,
314  makeArrayRef(strings));
315 }
316 
317 Error ARMAttributeParser::FP_HP_extension(AttrType tag) {
318  static const char *strings[] = {"If Available", "Permitted"};
319  return parseStringAttribute("FP_HP_extension", tag, makeArrayRef(strings));
320 }
321 
322 Error ARMAttributeParser::ABI_FP_16bit_format(AttrType tag) {
323  static const char *strings[] = {"Not Permitted", "IEEE-754", "VFPv3"};
324  return parseStringAttribute("ABI_FP_16bit_format", tag,
325  makeArrayRef(strings));
326 }
327 
328 Error ARMAttributeParser::MPextension_use(AttrType tag) {
329  static const char *strings[] = {"Not Permitted", "Permitted"};
330  return parseStringAttribute("MPextension_use", tag, makeArrayRef(strings));
331 }
332 
333 Error ARMAttributeParser::DIV_use(AttrType tag) {
334  static const char *strings[] = {"If Available", "Not Permitted", "Permitted"};
335  return parseStringAttribute("DIV_use", tag, makeArrayRef(strings));
336 }
337 
338 Error ARMAttributeParser::DSP_extension(AttrType tag) {
339  static const char *strings[] = {"Not Permitted", "Permitted"};
340  return parseStringAttribute("DSP_extension", tag, makeArrayRef(strings));
341 }
342 
343 Error ARMAttributeParser::T2EE_use(AttrType tag) {
344  static const char *strings[] = {"Not Permitted", "Permitted"};
345  return parseStringAttribute("T2EE_use", tag, makeArrayRef(strings));
346 }
347 
348 Error ARMAttributeParser::Virtualization_use(AttrType tag) {
349  static const char *strings[] = {"Not Permitted", "TrustZone",
350  "Virtualization Extensions",
351  "TrustZone + Virtualization Extensions"};
352  return parseStringAttribute("Virtualization_use", tag, makeArrayRef(strings));
353 }
354 
355 Error ARMAttributeParser::PAC_extension(ARMBuildAttrs::AttrType tag) {
356  static const char *strings[] = {"Not Permitted", "Permitted in NOP space",
357  "Permitted"};
358  return parseStringAttribute("PAC_extension", tag, makeArrayRef(strings));
359 }
360 
361 Error ARMAttributeParser::BTI_extension(ARMBuildAttrs::AttrType tag) {
362  static const char *strings[] = {"Not Permitted", "Permitted in NOP space",
363  "Permitted"};
364  return parseStringAttribute("BTI_extension", tag, makeArrayRef(strings));
365 }
366 
367 Error ARMAttributeParser::PACRET_use(ARMBuildAttrs::AttrType tag) {
368  static const char *strings[] = {"Not Used", "Used"};
369  return parseStringAttribute("PACRET_use", tag, makeArrayRef(strings));
370 }
371 
372 Error ARMAttributeParser::BTI_use(ARMBuildAttrs::AttrType tag) {
373  static const char *strings[] = {"Not Used", "Used"};
374  return parseStringAttribute("BTI_use", tag, makeArrayRef(strings));
375 }
376 
377 Error ARMAttributeParser::nodefaults(AttrType tag) {
378  uint64_t value = de.getULEB128(cursor);
379  printAttribute(tag, value, "Unspecified Tags UNDEFINED");
380  return Error::success();
381 }
382 
383 Error ARMAttributeParser::handler(uint64_t tag, bool &handled) {
384  handled = false;
385  for (unsigned AHI = 0, AHE = array_lengthof(displayRoutines); AHI != AHE;
386  ++AHI) {
387  if (uint64_t(displayRoutines[AHI].attribute) == tag) {
388  if (Error e =
389  (this->*displayRoutines[AHI].routine)(static_cast<AttrType>(tag)))
390  return e;
391  handled = true;
392  break;
393  }
394  }
395 
396  return Error::success();
397 }
llvm::ARMBuildAttrs::ARM_ISA_use
@ ARM_ISA_use
Definition: ARMBuildAttributes.h:41
llvm::ARMBuildAttrs::BTI_extension
@ BTI_extension
Definition: ARMBuildAttributes.h:74
llvm::ARMBuildAttrs::WMMX_arch
@ WMMX_arch
Definition: ARMBuildAttributes.h:44
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::ARMBuildAttrs::PACRET_use
@ PACRET_use
Definition: ARMBuildAttributes.h:79
llvm::ARMBuildAttrs::ABI_PCS_R9_use
@ ABI_PCS_R9_use
Definition: ARMBuildAttributes.h:47
llvm::ARMBuildAttrs::ABI_WMMX_args
@ ABI_WMMX_args
Definition: ARMBuildAttributes.h:62
llvm::ARMBuildAttrs::Advanced_SIMD_arch
@ Advanced_SIMD_arch
Definition: ARMBuildAttributes.h:45
llvm::ARMBuildAttrs::ABI_align_preserved
@ ABI_align_preserved
Definition: ARMBuildAttributes.h:58
llvm::ARMBuildAttrs::ABI_enum_size
@ ABI_enum_size
Definition: ARMBuildAttributes.h:59
llvm::ARMBuildAttrs::T2EE_use
@ T2EE_use
Definition: ARMBuildAttributes.h:87
llvm::ARMBuildAttrs::CPU_arch_profile
@ CPU_arch_profile
Definition: ARMBuildAttributes.h:40
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:329
llvm::ARMBuildAttrs::MPextension_use
@ MPextension_use
Definition: ARMBuildAttributes.h:69
llvm::ARMBuildAttrs::BTI_use
@ BTI_use
Definition: ARMBuildAttributes.h:78
llvm::ARMBuildAttrs::CPU_unaligned_access
@ CPU_unaligned_access
Definition: ARMBuildAttributes.h:66
llvm::ARMBuildAttrs::ABI_FP_exceptions
@ ABI_FP_exceptions
Definition: ARMBuildAttributes.h:54
ARMAttributeParser.h
llvm::ARMBuildAttrs::compatibility
@ compatibility
Definition: ARMBuildAttributes.h:65
llvm::ARMBuildAttrs::PAC_extension
@ PAC_extension
Definition: ARMBuildAttributes.h:73
llvm::ARMBuildAttrs::FP_arch
@ FP_arch
Definition: ARMBuildAttributes.h:43
llvm::ARMBuildAttrs::nodefaults
@ nodefaults
Definition: ARMBuildAttributes.h:86
llvm::ARMBuildAttrs::ABI_FP_rounding
@ ABI_FP_rounding
Definition: ARMBuildAttributes.h:52
llvm::array_lengthof
constexpr size_t array_lengthof(T(&)[N])
Find the length of an array.
Definition: STLArrayExtras.h:29
ATTRIBUTE_HANDLER
#define ATTRIBUTE_HANDLER(attr)
Definition: ARMAttributeParser.cpp:17
llvm::ARMBuildAttrs
Definition: ARMBuildAttributes.h:24
llvm::ARMBuildAttrs::ABI_FP_denormal
@ ABI_FP_denormal
Definition: ARMBuildAttributes.h:53
llvm::ARMBuildAttrs::ABI_VFP_args
@ ABI_VFP_args
Definition: ARMBuildAttributes.h:61
llvm::ARMBuildAttrs::THUMB_ISA_use
@ THUMB_ISA_use
Definition: ARMBuildAttributes.h:42
llvm::StringRef::empty
constexpr LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:153
STLArrayExtras.h
uint64_t
llvm::numbers::e
constexpr double e
Definition: MathExtras.h:57
StringExtras.h
llvm::ARMBuildAttrs::PCS_config
@ PCS_config
Definition: ARMBuildAttributes.h:46
llvm::ARMBuildAttrs::ABI_FP_optimization_goals
@ ABI_FP_optimization_goals
Definition: ARMBuildAttributes.h:64
llvm::ARMBuildAttrs::ABI_FP_number_model
@ ABI_FP_number_model
Definition: ARMBuildAttributes.h:56
llvm::ARMBuildAttrs::CPU_raw_name
@ CPU_raw_name
Definition: ARMBuildAttributes.h:37
llvm::ARMBuildAttrs::ABI_align_needed
@ ABI_align_needed
Definition: ARMBuildAttributes.h:57
llvm::DictScope
Definition: ScopedPrinter.h:799
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::ARMBuildAttrs::ABI_FP_user_exceptions
@ ABI_FP_user_exceptions
Definition: ARMBuildAttributes.h:55
llvm::ARMBuildAttrs::DIV_use
@ DIV_use
Definition: ARMBuildAttributes.h:70
llvm::ARMBuildAttrs::ABI_optimization_goals
@ ABI_optimization_goals
Definition: ARMBuildAttributes.h:63
llvm::ARMBuildAttrs::AttrType
AttrType
Definition: ARMBuildAttributes.h:34
llvm::ARMBuildAttrs::ABI_PCS_RO_data
@ ABI_PCS_RO_data
Definition: ARMBuildAttributes.h:49
llvm::ARMBuildAttrs::MVE_arch
@ MVE_arch
Definition: ARMBuildAttributes.h:72
llvm::ARMBuildAttrs::Virtualization_use
@ Virtualization_use
Definition: ARMBuildAttributes.h:77
llvm::ARMBuildAttrs::ABI_PCS_RW_data
@ ABI_PCS_RW_data
Definition: ARMBuildAttributes.h:48
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
llvm::ARMBuildAttrs::ABI_PCS_wchar_t
@ ABI_PCS_wchar_t
Definition: ARMBuildAttributes.h:51
llvm::ARMBuildAttrs::ABI_PCS_GOT_use
@ ABI_PCS_GOT_use
Definition: ARMBuildAttributes.h:50
llvm::ARMBuildAttrs::CPU_arch
@ CPU_arch
Definition: ARMBuildAttributes.h:39
llvm::makeArrayRef
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:475
llvm::ARMBuildAttrs::DSP_extension
@ DSP_extension
Definition: ARMBuildAttributes.h:71
llvm::ARMBuildAttrs::FP_HP_extension
@ FP_HP_extension
Definition: ARMBuildAttributes.h:67
llvm::ARMBuildAttrs::ABI_HardFP_use
@ ABI_HardFP_use
Definition: ARMBuildAttributes.h:60
llvm::ARMBuildAttrs::CPU_name
@ CPU_name
Definition: ARMBuildAttributes.h:38
llvm::ARMBuildAttrs::ABI_FP_16bit_format
@ ABI_FP_16bit_format
Definition: ARMBuildAttributes.h:68
llvm::ELFAttrs::attrTypeAsString
StringRef attrTypeAsString(unsigned attr, TagNameMap tagNameMap, bool hasTagPrefix=true)
Definition: ELFAttributes.cpp:14
ScopedPrinter.h