Skip to content

Commit 47c596d

Browse files
committed
SIL: Use TinyPtrVector for the argument list in SILBasicBlock
A TinyPtrVector is the right choice, because ~98% of blocks have 0 or 1 arguments.
1 parent 2c7027d commit 47c596d

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

include/swift/SIL/SILBasicBlock.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "swift/SIL/SILArgumentArrayRef.h"
2323
#include "swift/SIL/SILInstruction.h"
2424
#include "swift/SIL/SILArgument.h"
25+
#include "llvm/ADT/TinyPtrVector.h"
2526

2627
namespace swift {
2728

@@ -49,7 +50,9 @@ public llvm::ilist_node<SILBasicBlock>, public SILAllocated<SILBasicBlock> {
4950
SILSuccessor *PredList;
5051

5152
/// This is the list of basic block arguments for this block.
52-
std::vector<SILArgument *> ArgumentList;
53+
/// A TinyPtrVector is the right choice, because ~98% of blocks have 0 or 1
54+
/// arguments.
55+
TinyPtrVector<SILArgument *> ArgumentList;
5356

5457
/// The ordered set of instructions in the SILBasicBlock.
5558
InstListType InstList;
@@ -178,8 +181,8 @@ public llvm::ilist_node<SILBasicBlock>, public SILAllocated<SILBasicBlock> {
178181
// SILBasicBlock Argument List Inspection and Manipulation
179182
//===--------------------------------------------------------------------===//
180183

181-
using arg_iterator = std::vector<SILArgument *>::iterator;
182-
using const_arg_iterator = std::vector<SILArgument *>::const_iterator;
184+
using arg_iterator = TinyPtrVector<SILArgument *>::iterator;
185+
using const_arg_iterator = TinyPtrVector<SILArgument *>::const_iterator;
183186

184187
bool args_empty() const { return ArgumentList.empty(); }
185188
size_t args_size() const { return ArgumentList.size(); }

lib/SIL/IR/SILBasicBlock.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ SILFunctionArgument *SILBasicBlock::replaceFunctionArgument(
193193

194194
// TODO: When we switch to malloc/free allocation we'll be leaking memory
195195
// here.
196-
ArgumentList[i] = NewArg;
196+
*(ArgumentList.begin() + i) = NewArg;
197197

198198
return NewArg;
199199
}
@@ -219,7 +219,7 @@ SILPhiArgument *SILBasicBlock::replacePhiArgument(unsigned i, SILType Ty,
219219

220220
// TODO: When we switch to malloc/free allocation we'll be leaking memory
221221
// here.
222-
ArgumentList[i] = NewArg;
222+
*(ArgumentList.begin() + i) = NewArg;
223223

224224
return NewArg;
225225
}

0 commit comments

Comments
 (0)