[MIPS GlobalISel] Select MSA vector generic and builtin add
[llvm-complete.git] / lib / TextAPI / MachO / ArchitectureSet.cpp
blobc589671199b798ad85175aa19f38625de7314bb6
1 //===- ArchitectureSet.cpp ------------------------------------------------===//
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 // Implements the architecture set.
11 //===----------------------------------------------------------------------===//
13 #include "llvm/TextAPI/MachO/ArchitectureSet.h"
15 namespace llvm {
16 namespace MachO {
18 ArchitectureSet::ArchitectureSet(const std::vector<Architecture> &Archs)
19 : ArchitectureSet() {
20 for (auto Arch : Archs) {
21 if (Arch == AK_unknown)
22 continue;
23 set(Arch);
27 size_t ArchitectureSet::count() const {
28 // popcnt
29 size_t Cnt = 0;
30 for (unsigned i = 0; i < sizeof(ArchSetType) * 8; ++i)
31 if (ArchSet & (1U << i))
32 ++Cnt;
33 return Cnt;
36 ArchitectureSet::operator std::string() const {
37 if (empty())
38 return "[(empty)]";
40 std::string result;
41 auto size = count();
42 for (auto arch : *this) {
43 result.append(getArchitectureName(arch));
44 size -= 1;
45 if (size)
46 result.append(" ");
48 return result;
51 ArchitectureSet::operator std::vector<Architecture>() const {
52 std::vector<Architecture> archs;
53 for (auto arch : *this) {
54 if (arch == AK_unknown)
55 continue;
56 archs.emplace_back(arch);
58 return archs;
61 void ArchitectureSet::print(raw_ostream &os) const { os << std::string(*this); }
63 raw_ostream &operator<<(raw_ostream &os, ArchitectureSet set) {
64 set.print(os);
65 return os;
68 } // end namespace MachO.
69 } // end namespace llvm.