LLVM  14.0.0git
ArchitectureSet.h
Go to the documentation of this file.
1 //===- llvm/TextAPI/ArchitectureSet.h - ArchitectureSet ---------*- 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 // Defines the architecture set.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_TEXTAPI_ARCHITECTURESET_H
14 #define LLVM_TEXTAPI_ARCHITECTURESET_H
15 
17 #include <cstddef>
18 #include <iterator>
19 #include <limits>
20 #include <string>
21 #include <tuple>
22 #include <vector>
23 
24 namespace llvm {
25 class raw_ostream;
26 
27 namespace MachO {
28 
30 private:
31  using ArchSetType = uint32_t;
32 
33  const static ArchSetType EndIndexVal =
35  ArchSetType ArchSet{0};
36 
37 public:
38  constexpr ArchitectureSet() = default;
39  constexpr ArchitectureSet(ArchSetType Raw) : ArchSet(Raw) {}
41  ArchitectureSet(const std::vector<Architecture> &Archs);
42 
43  void set(Architecture Arch) {
44  if (Arch == AK_unknown)
45  return;
46  ArchSet |= 1U << static_cast<int>(Arch);
47  }
48 
49  void clear(Architecture Arch) { ArchSet &= ~(1U << static_cast<int>(Arch)); }
50 
51  bool has(Architecture Arch) const {
52  return ArchSet & (1U << static_cast<int>(Arch));
53  }
54 
55  bool contains(ArchitectureSet Archs) const {
56  return (ArchSet & Archs.ArchSet) == Archs.ArchSet;
57  }
58 
59  size_t count() const;
60 
61  bool empty() const { return ArchSet == 0; }
62 
63  ArchSetType rawValue() const { return ArchSet; }
64 
65  bool hasX86() const {
66  return has(AK_i386) || has(AK_x86_64) || has(AK_x86_64h);
67  }
68 
69  template <typename Ty> class arch_iterator {
70  public:
71  using iterator_category = std::forward_iterator_tag;
73  using difference_type = std::size_t;
74  using pointer = value_type *;
75  using reference = value_type &;
76 
77  private:
78  ArchSetType Index;
79  Ty *ArchSet;
80 
81  void findNextSetBit() {
82  if (Index == EndIndexVal)
83  return;
84  while (++Index < sizeof(Ty) * 8) {
85  if (*ArchSet & (1UL << Index))
86  return;
87  }
88 
89  Index = EndIndexVal;
90  }
91 
92  public:
93  arch_iterator(Ty *ArchSet, ArchSetType Index = 0)
94  : Index(Index), ArchSet(ArchSet) {
95  if (Index != EndIndexVal && !(*ArchSet & (1UL << Index)))
96  findNextSetBit();
97  }
98 
99  Architecture operator*() const { return static_cast<Architecture>(Index); }
100 
102  findNextSetBit();
103  return *this;
104  }
105 
107  auto tmp = *this;
108  findNextSetBit();
109  return tmp;
110  }
111 
112  bool operator==(const arch_iterator &o) const {
113  return std::tie(Index, ArchSet) == std::tie(o.Index, o.ArchSet);
114  }
115 
116  bool operator!=(const arch_iterator &o) const { return !(*this == o); }
117  };
118 
120  return {ArchSet & o.ArchSet};
121  }
122 
124  return {ArchSet | o.ArchSet};
125  }
126 
128  ArchSet |= o.ArchSet;
129  return *this;
130  }
131 
133  set(Arch);
134  return *this;
135  }
136 
137  bool operator==(const ArchitectureSet &o) const {
138  return ArchSet == o.ArchSet;
139  }
140 
141  bool operator!=(const ArchitectureSet &o) const {
142  return ArchSet != o.ArchSet;
143  }
144 
145  bool operator<(const ArchitectureSet &o) const { return ArchSet < o.ArchSet; }
146 
149 
150  iterator begin() { return {&ArchSet}; }
151  iterator end() { return {&ArchSet, EndIndexVal}; }
152 
153  const_iterator begin() const { return {&ArchSet}; }
154  const_iterator end() const { return {&ArchSet, EndIndexVal}; }
155 
156  operator std::string() const;
157  operator std::vector<Architecture>() const;
158  void print(raw_ostream &OS) const;
159 };
160 
162  const Architecture &rhs) {
163  return ArchitectureSet(lhs) | ArchitectureSet(rhs);
164 }
165 
166 raw_ostream &operator<<(raw_ostream &OS, ArchitectureSet Set);
167 
168 } // end namespace MachO.
169 } // end namespace llvm.
170 
171 #endif // LLVM_TEXTAPI_ARCHITECTURESET_H
llvm::MachO::ArchitectureSet::arch_iterator
Definition: ArchitectureSet.h:69
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
llvm::MachO::ArchitectureSet::arch_iterator::arch_iterator
arch_iterator(Ty *ArchSet, ArchSetType Index=0)
Definition: ArchitectureSet.h:93
llvm::MachO::ArchitectureSet::ArchitectureSet
ArchitectureSet(Architecture Arch)
Definition: ArchitectureSet.h:40
llvm::MachO::AK_unknown
@ AK_unknown
Definition: Architecture.h:31
llvm::MachO::ArchitectureSet::begin
iterator begin()
Definition: ArchitectureSet.h:150
llvm::MachO::operator|
ArchitectureSet operator|(const Architecture &lhs, const Architecture &rhs)
Definition: ArchitectureSet.h:161
llvm::MachO::ArchitectureSet::clear
void clear(Architecture Arch)
Definition: ArchitectureSet.h:49
llvm::MachO::ArchitectureSet::begin
const_iterator begin() const
Definition: ArchitectureSet.h:153
Architecture.h
llvm::MachO::ArchitectureSet::rawValue
ArchSetType rawValue() const
Definition: ArchitectureSet.h:63
llvm::MachO::ArchitectureSet::arch_iterator::operator++
arch_iterator operator++(int)
Definition: ArchitectureSet.h:106
tmp
alloca< 16 x float >, align 16 %tmp2=alloca< 16 x float >, align 16 store< 16 x float > %A,< 16 x float > *%tmp %s=bitcast< 16 x float > *%tmp to i8 *%s2=bitcast< 16 x float > *%tmp2 to i8 *call void @llvm.memcpy.i64(i8 *%s, i8 *%s2, i64 64, i32 16) %R=load< 16 x float > *%tmp2 ret< 16 x float > %R } declare void @llvm.memcpy.i64(i8 *nocapture, i8 *nocapture, i64, i32) nounwind which compiles to:_foo:subl $140, %esp movaps %xmm3, 112(%esp) movaps %xmm2, 96(%esp) movaps %xmm1, 80(%esp) movaps %xmm0, 64(%esp) movl 60(%esp), %eax movl %eax, 124(%esp) movl 56(%esp), %eax movl %eax, 120(%esp) movl 52(%esp), %eax< many many more 32-bit copies > movaps(%esp), %xmm0 movaps 16(%esp), %xmm1 movaps 32(%esp), %xmm2 movaps 48(%esp), %xmm3 addl $140, %esp ret On Nehalem, it may even be cheaper to just use movups when unaligned than to fall back to lower-granularity chunks. Implement processor-specific optimizations for parity with GCC on these processors. GCC does two optimizations:1. ix86_pad_returns inserts a noop before ret instructions if immediately preceded by a conditional branch or is the target of a jump. 2. ix86_avoid_jump_misspredicts inserts noops in cases where a 16-byte block of code contains more than 3 branches. The first one is done for all AMDs, Core2, and "Generic" The second one is done for:Atom, Pentium Pro, all AMDs, Pentium 4, Nocona, Core 2, and "Generic" Testcase:int x(int a) { return(a &0xf0)> >4 tmp
Definition: README.txt:1347
llvm::MachO::ArchitectureSet::arch_iterator::operator!=
bool operator!=(const arch_iterator &o) const
Definition: ArchitectureSet.h:116
llvm::MachO::ArchitectureSet::arch_iterator::iterator_category
std::forward_iterator_tag iterator_category
Definition: ArchitectureSet.h:71
llvm::MachO::ArchitectureSet::operator|
ArchitectureSet operator|(const ArchitectureSet &o)
Definition: ArchitectureSet.h:123
llvm::MachO::ArchitectureSet::has
bool has(Architecture Arch) const
Definition: ArchitectureSet.h:51
llvm::MachO::ArchitectureSet::empty
bool empty() const
Definition: ArchitectureSet.h:61
llvm::MachO::ArchitectureSet::ArchitectureSet
constexpr ArchitectureSet(ArchSetType Raw)
Definition: ArchitectureSet.h:39
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::MachO::ArchitectureSet::arch_iterator::operator*
Architecture operator*() const
Definition: ArchitectureSet.h:99
llvm::MachO::ArchitectureSet::arch_iterator::operator++
arch_iterator & operator++()
Definition: ArchitectureSet.h:101
llvm::MachO::ArchitectureSet::arch_iterator::difference_type
std::size_t difference_type
Definition: ArchitectureSet.h:73
llvm::MachO::ArchitectureSet
Definition: ArchitectureSet.h:29
llvm::MachO::ArchitectureSet::print
void print(raw_ostream &OS) const
Definition: ArchitectureSet.cpp:62
llvm::MachO::Architecture
Architecture
Defines the architecture slices that are supported by Text-based Stub files.
Definition: Architecture.h:27
llvm::MachO::operator<<
raw_ostream & operator<<(raw_ostream &OS, Architecture Arch)
Definition: Architecture.cpp:92
llvm::MachO::ArchitectureSet::ArchitectureSet
constexpr ArchitectureSet()=default
llvm::MachO::ArchitectureSet::operator&
ArchitectureSet operator&(const ArchitectureSet &o)
Definition: ArchitectureSet.h:119
llvm::MachO::ArchitectureSet::hasX86
bool hasX86() const
Definition: ArchitectureSet.h:65
llvm::MachO::ArchitectureSet::operator!=
bool operator!=(const ArchitectureSet &o) const
Definition: ArchitectureSet.h:141
llvm::MachO::ArchitectureSet::count
size_t count() const
Definition: ArchitectureSet.cpp:28
llvm::MachO::ArchitectureSet::contains
bool contains(ArchitectureSet Archs) const
Definition: ArchitectureSet.h:55
uint32_t
llvm::MachO::ArchitectureSet::operator|=
ArchitectureSet & operator|=(const ArchitectureSet &o)
Definition: ArchitectureSet.h:127
llvm::MachO::ArchitectureSet::set
void set(Architecture Arch)
Definition: ArchitectureSet.h:43
llvm::MachO::ArchitectureSet::end
const_iterator end() const
Definition: ArchitectureSet.h:154
llvm::MachO::ArchitectureSet::arch_iterator::operator==
bool operator==(const arch_iterator &o) const
Definition: ArchitectureSet.h:112
llvm::MachO::ArchitectureSet::operator|=
ArchitectureSet & operator|=(const Architecture &Arch)
Definition: ArchitectureSet.h:132
llvm::MachO::ArchitectureSet::operator==
bool operator==(const ArchitectureSet &o) const
Definition: ArchitectureSet.h:137
llvm::max
Align max(MaybeAlign Lhs, Align Rhs)
Definition: Alignment.h:340
llvm::MachO::ArchitectureSet::operator<
bool operator<(const ArchitectureSet &o) const
Definition: ArchitectureSet.h:145
llvm::MachO::ArchitectureSet::end
iterator end()
Definition: ArchitectureSet.h:151