Skip to content

Commit 5bd2725

Browse files
committed
[basic] Add an operator<<(llvm::raw_ostream &os, const SmallBitVector &) implementation.
For some reason LLVM doesn't provide this. I have written a few versions of this in the Swift codebase. Makes sense to factor it out before I make another one.
1 parent f237fba commit 5bd2725

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

include/swift/Basic/SmallBitVector.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//===--- SmallBitVector.h -------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef SWIFT_BASIC_SMALLBITVECTOR_H
14+
#define SWIFT_BASIC_SMALLBITVECTOR_H
15+
16+
#include "llvm/ADT/SmallBitVector.h"
17+
#include "llvm/Support/raw_ostream.h"
18+
19+
namespace llvm {
20+
21+
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
22+
const SmallBitVector &bv) {
23+
for (unsigned i = 0, e = bv.size(); i != e; ++i)
24+
os << (bv[i] ? '1' : '0');
25+
return os;
26+
}
27+
28+
} // namespace llvm
29+
30+
#endif

lib/SILOptimizer/Mandatory/MoveKillsCopyableAddressesChecker.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@
141141
#include "swift/Basic/Defer.h"
142142
#include "swift/Basic/FrozenMultiMap.h"
143143
#include "swift/Basic/GraphNodeWorklist.h"
144+
#include "swift/Basic/SmallBitVector.h"
144145
#include "swift/SIL/BasicBlockBits.h"
145146
#include "swift/SIL/BasicBlockDatastructures.h"
146147
#include "swift/SIL/Consumption.h"
@@ -183,15 +184,6 @@ static void diagnose(ASTContext &Context, SourceLoc loc, Diag<T...> diag,
183184
Context.Diags.diagnose(loc, diag, std::forward<U>(args)...);
184185
}
185186

186-
namespace llvm {
187-
llvm::raw_ostream &operator<<(llvm::raw_ostream &os, const SmallBitVector &bv) {
188-
for (unsigned index : range(bv.size())) {
189-
os << (bv[index] ? 1 : 0);
190-
}
191-
return os;
192-
}
193-
} // namespace llvm
194-
195187
static SourceLoc getSourceLocFromValue(SILValue value) {
196188
if (auto *defInst = value->getDefiningInstruction())
197189
return defInst->getLoc().getSourceLoc();

0 commit comments

Comments
 (0)