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