Skip to content

Commit 68c696d

Browse files
committed
[SIL] NFC: Replace boilerplate projection with swift::ArrayRefView
1 parent 4d83e8c commit 68c696d

File tree

4 files changed

+10
-61
lines changed

4 files changed

+10
-61
lines changed

include/swift/Basic/ArrayRefView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class ArrayRefView {
4444
typedef std::random_access_iterator_tag iterator_category;
4545

4646
Projected operator*() const { return Project(*Ptr); }
47+
Projected operator->() const { return operator*(); }
4748
iterator &operator++() { Ptr++; return *this; }
4849
iterator operator++(int) { return iterator(Ptr++); }
4950
bool operator==(iterator rhs) const { return Ptr == rhs.Ptr; }

include/swift/SIL/SILValue.h

Lines changed: 5 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define SWIFT_SIL_SILVALUE_H
1919

2020
#include "swift/Basic/Range.h"
21+
#include "swift/Basic/ArrayRefView.h"
2122
#include "swift/SIL/SILNode.h"
2223
#include "swift/SIL/SILType.h"
2324
#include "llvm/ADT/ArrayRef.h"
@@ -419,64 +420,10 @@ class Operand {
419420
///
420421
/// The intent is that this should basically act exactly like
421422
/// ArrayRef except projecting away the Operand-ness.
422-
class OperandValueArrayRef {
423-
ArrayRef<Operand> Operands;
424-
public:
425-
explicit OperandValueArrayRef(ArrayRef<Operand> operands)
426-
: Operands(operands) {}
427-
428-
/// A simple iterator adapter.
429-
class iterator : public std::iterator<std::forward_iterator_tag,
430-
SILValue, ptrdiff_t> {
431-
const Operand *Ptr;
432-
public:
433-
iterator() = default;
434-
iterator(const Operand *ptr) : Ptr(ptr) {}
435-
SILValue operator*() const { assert(Ptr); return Ptr->get(); }
436-
SILValue operator->() const { return operator*(); }
437-
iterator &operator++() { ++Ptr; return *this; }
438-
iterator operator++(int) { iterator copy = *this; ++Ptr; return copy; }
439-
440-
friend bool operator==(iterator lhs, iterator rhs) {
441-
return lhs.Ptr == rhs.Ptr;
442-
}
443-
friend bool operator!=(iterator lhs, iterator rhs) {
444-
return lhs.Ptr != rhs.Ptr;
445-
}
446-
};
447-
448-
iterator begin() const { return iterator(Operands.begin()); }
449-
iterator end() const { return iterator(Operands.end()); }
450-
size_t size() const { return Operands.size(); }
451-
bool empty() const { return Operands.empty(); }
452-
453-
SILValue front() const { return Operands.front().get(); }
454-
SILValue back() const { return Operands.back().get(); }
455-
456-
SILValue operator[](unsigned i) const { return Operands[i].get(); }
457-
OperandValueArrayRef slice(unsigned begin, unsigned length) const {
458-
return OperandValueArrayRef(Operands.slice(begin, length));
459-
}
460-
OperandValueArrayRef slice(unsigned begin) const {
461-
return OperandValueArrayRef(Operands.slice(begin));
462-
}
463-
OperandValueArrayRef drop_back() const {
464-
return OperandValueArrayRef(Operands.drop_back());
465-
}
466-
467-
bool operator==(const OperandValueArrayRef RHS) const {
468-
if (size() != RHS.size())
469-
return false;
470-
for (auto L = begin(), LE = end(), R = RHS.begin(); L != LE; ++L, ++R)
471-
if (*L != *R)
472-
return false;
473-
return true;
474-
}
475-
476-
bool operator!=(const OperandValueArrayRef RHS) const {
477-
return !(*this == RHS);
478-
}
479-
};
423+
inline SILValue getSILValueType(const Operand &op) {
424+
return op.get();
425+
}
426+
typedef ArrayRefView<Operand,SILValue,getSILValueType> OperandValueArrayRef;
480427

481428
/// An iterator over all uses of a ValueBase.
482429
class ValueBaseUseIterator : public std::iterator<std::forward_iterator_tag,

lib/SIL/SILInstructions.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1309,7 +1309,6 @@ SELECT_ENUM_INST *SelectEnumInstBase::createSelectEnum(
13091309
// Allocate enough room for the instruction with tail-allocated
13101310
// EnumElementDecl and operand arrays. There are `CaseBBs.size()` decls
13111311
// and `CaseBBs.size() + (DefaultBB ? 1 : 0)` values.
1312-
unsigned numCases = DeclsAndValues.size();
13131312
SmallVector<SILValue, 4> CaseValues;
13141313
SmallVector<EnumElementDecl*, 4> CaseDecls;
13151314
for (auto &pair : DeclsAndValues) {

lib/SILOptimizer/Transforms/SimplifyCFG.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,8 @@ class ThreadInfo {
360360
"Argument types must match");
361361
Builder.createBranch(SEI->getLoc(), ThreadedSuccessorBlock, {UED});
362362
} else
363-
Builder.createBranch(SEI->getLoc(), ThreadedSuccessorBlock, {});
363+
Builder.createBranch(SEI->getLoc(), ThreadedSuccessorBlock,
364+
ArrayRef<SILValue>());
364365
SEI->eraseFromParent();
365366

366367
// Split the edge from 'Dest' to 'ThreadedSuccessorBlock' it is now
@@ -2123,7 +2124,8 @@ bool SimplifyCFG::simplifyTermWithIdenticalDestBlocks(SILBasicBlock *BB) {
21232124

21242125
TermInst *Term = BB->getTerminator();
21252126
DEBUG(llvm::dbgs() << "replace term with identical dests: " << *Term);
2126-
SILBuilderWithScope(Term).createBranch(Term->getLoc(), commonDest, {});
2127+
SILBuilderWithScope(Term).createBranch(Term->getLoc(), commonDest,
2128+
ArrayRef<SILValue>());
21272129
Term->eraseFromParent();
21282130
addToWorklist(BB);
21292131
addToWorklist(commonDest);

0 commit comments

Comments
 (0)