Skip to content

Commit ecc4474

Browse files
committed
Define critical SILInstruction and SILBasicBlock getters inline.
It makes no sense to operate on the block's instruction list without also including SILBasicBlock.h anyway. Similarly, it doesn't make sense to query the entry block without including SILFunction.h. Now we can call these simple getters in critical-path loops assuming they are as cheap as a load. I was avoiding calling these in critical path code, which resulted in less readability and consistency across the code base.
1 parent bc37208 commit ecc4474

File tree

4 files changed

+38
-22
lines changed

4 files changed

+38
-22
lines changed

include/swift/SIL/SILBasicBlock.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,4 +659,26 @@ template <> struct DenseMapInfo<swift::PhiValue> {
659659

660660
} // end namespace llvm
661661

662+
//===----------------------------------------------------------------------===//
663+
// Inline SILInstruction implementations
664+
//===----------------------------------------------------------------------===//
665+
666+
namespace swift {
667+
668+
inline SILFunction *SILInstruction::getFunction() const {
669+
return getParent()->getParent();
670+
}
671+
672+
inline SILInstruction *SILInstruction::getPreviousInstruction() {
673+
auto pos = getIterator();
674+
return pos == getParent()->begin() ? nullptr : &*std::prev(pos);
675+
}
676+
677+
inline SILInstruction *SILInstruction::getNextInstruction() {
678+
auto nextPos = std::next(getIterator());
679+
return nextPos == getParent()->end() ? nullptr : &*nextPos;
680+
}
681+
682+
} // end swift namespace
683+
662684
#endif

include/swift/SIL/SILFunction.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,4 +1461,20 @@ public ilist_node_traits<::swift::SILFunction> {
14611461

14621462
} // end llvm namespace
14631463

1464+
//===----------------------------------------------------------------------===//
1465+
// Inline SIL implementations
1466+
//===----------------------------------------------------------------------===//
1467+
1468+
namespace swift {
1469+
1470+
inline bool SILBasicBlock::isEntry() const {
1471+
return this == &*getParent()->begin();
1472+
}
1473+
1474+
inline SILModule &SILInstruction::getModule() const {
1475+
return getFunction()->getModule();
1476+
}
1477+
1478+
} // end swift namespace
1479+
14641480
#endif

lib/SIL/IR/SILBasicBlock.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,10 +361,6 @@ ScopeCloner::getOrCreateClonedScope(const SILDebugScope *OrigScope) {
361361
return ClonedScope;
362362
}
363363

364-
bool SILBasicBlock::isEntry() const {
365-
return this == &*getParent()->begin();
366-
}
367-
368364
/// Declared out of line so we can have a declaration of SILArgument.
369365
#define ARGUMENT(NAME, PARENT) \
370366
NAME##ArrayRef SILBasicBlock::get##NAME##s() const { \

lib/SIL/IR/SILInstruction.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -104,24 +104,6 @@ transferNodesFromList(llvm::ilist_traits<SILInstruction> &L2,
104104
ASSERT_IMPLEMENTS_STATIC(CLASS, PARENT, classof, bool(SILNodePointer));
105105
#include "swift/SIL/SILNodes.def"
106106

107-
SILFunction *SILInstruction::getFunction() const {
108-
return getParent()->getParent();
109-
}
110-
111-
SILModule &SILInstruction::getModule() const {
112-
return getFunction()->getModule();
113-
}
114-
115-
SILInstruction *SILInstruction::getPreviousInstruction() {
116-
auto pos = getIterator();
117-
return pos == getParent()->begin() ? nullptr : &*std::prev(pos);
118-
}
119-
120-
SILInstruction *SILInstruction::getNextInstruction() {
121-
auto nextPos = std::next(getIterator());
122-
return nextPos == getParent()->end() ? nullptr : &*nextPos;
123-
}
124-
125107
void SILInstruction::removeFromParent() {
126108
#ifndef NDEBUG
127109
for (auto result : getResults()) {

0 commit comments

Comments
 (0)