Skip to content

Commit cd99f85

Browse files
committed
NFC code cleanup changes:
- Hoist a duplicated static function with a fixme out to SILValue::getLoc() - Fix a whitespace issue.
1 parent 0918780 commit cd99f85

File tree

5 files changed

+23
-36
lines changed

5 files changed

+23
-36
lines changed

include/swift/SIL/SILValue.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,9 @@ class SILValue {
271271
/// false otherwise.
272272
explicit operator bool() const { return Value != nullptr; }
273273

274+
/// Get a location for this value.
275+
SILLocation getLoc() const;
276+
274277
/// Convert this SILValue into an opaque pointer like type. For use with
275278
/// PointerLikeTypeTraits.
276279
void *getOpaqueValue() const {

lib/IRGen/LoadableByAddress.cpp

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,6 @@
3737
using namespace swift;
3838
using namespace swift::irgen;
3939

40-
/// Utility to derive SILLocation.
41-
///
42-
/// TODO: This should be a common utility.
43-
static SILLocation getLocForValue(SILValue value) {
44-
if (auto *instr = value->getDefiningInstruction()) {
45-
return instr->getLoc();
46-
}
47-
if (auto *arg = dyn_cast<SILArgument>(value)) {
48-
if (arg->getDecl())
49-
return RegularLocation(const_cast<ValueDecl *>(arg->getDecl()));
50-
}
51-
// TODO: bbargs should probably use one of their operand locations.
52-
return value->getFunction()->getLocation();
53-
}
54-
5540
static GenericEnvironment *getGenericEnvironment(SILModule &Mod,
5641
CanSILFunctionType loweredTy) {
5742
return loweredTy->getGenericSignature()->createGenericEnvironment(
@@ -875,7 +860,7 @@ void LoadableStorageAllocation::replaceLoadWithCopyAddr(
875860

876861
SILBuilder allocBuilder(pass.F->begin()->begin());
877862
AllocStackInst *allocInstr =
878-
allocBuilder.createAllocStack(getLocForValue(value), value->getType());
863+
allocBuilder.createAllocStack(value.getLoc(), value->getType());
879864

880865
SILBuilder outlinedBuilder(optimizableLoad);
881866
createOutlinedCopyCall(outlinedBuilder, value, allocInstr, pass);
@@ -1002,7 +987,7 @@ void LoadableStorageAllocation::replaceLoadWithCopyAddrForModifiable(
1002987

1003988
SILBuilder allocBuilder(pass.F->begin()->begin());
1004989
AllocStackInst *allocInstr =
1005-
allocBuilder.createAllocStack(getLocForValue(value), value->getType());
990+
allocBuilder.createAllocStack(value.getLoc(), value->getType());
1006991

1007992
SILBuilder outlinedBuilder(unoptimizableLoad);
1008993
createOutlinedCopyCall(outlinedBuilder, value, allocInstr, pass);
@@ -1367,7 +1352,7 @@ void LoadableStorageAllocation::allocateForArg(SILValue value) {
13671352

13681353
SILBuilder allocBuilder(pass.F->begin()->begin());
13691354
AllocStackInst *allocInstr =
1370-
allocBuilder.createAllocStack(getLocForValue(value), value->getType());
1355+
allocBuilder.createAllocStack(value.getLoc(), value->getType());
13711356

13721357
LoadInst *loadCopy = nullptr;
13731358
auto *applyOutlinedCopy =
@@ -1647,7 +1632,7 @@ static SILValue createCopyOfEnum(StructLoweringState &pass,
16471632
value = allocInstr;
16481633
}
16491634
SILBuilder allocBuilder(pass.F->begin()->begin());
1650-
auto *allocInstr = allocBuilder.createAllocStack(getLocForValue(value), type);
1635+
auto *allocInstr = allocBuilder.createAllocStack(value.getLoc(), type);
16511636

16521637
SILBuilder copyBuilder(orig);
16531638
createOutlinedCopyCall(copyBuilder, value, allocInstr, pass);

lib/SIL/SILInstruction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@ SILInstruction::MemoryBehavior SILInstruction::getMemoryBehavior() const {
877877
: MemoryBehavior::MayHaveSideEffects;
878878

879879
// Handle LLVM intrinsic functions.
880-
const IntrinsicInfo & IInfo = BI->getIntrinsicInfo();
880+
const IntrinsicInfo &IInfo = BI->getIntrinsicInfo();
881881
if (IInfo.ID != llvm::Intrinsic::not_intrinsic) {
882882
// Read-only.
883883
if (IInfo.hasAttribute(llvm::Attribute::ReadOnly) &&

lib/SIL/SILValue.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,20 @@ const SILNode *SILNode::getCanonicalSILNodeSlowPath() const {
110110
static_cast<const ValueBase &>(*this)));
111111
}
112112

113+
/// Get a location for this value.
114+
SILLocation SILValue::getLoc() const {
115+
if (auto *instr = Value->getDefiningInstruction())
116+
return instr->getLoc();
117+
118+
if (auto *arg = dyn_cast<SILArgument>(*this)) {
119+
if (arg->getDecl())
120+
return RegularLocation(const_cast<ValueDecl *>(arg->getDecl()));
121+
}
122+
// TODO: bbargs should probably use one of their operand locations.
123+
return Value->getFunction()->getLocation();
124+
}
125+
126+
113127
//===----------------------------------------------------------------------===//
114128
// ValueOwnershipKind
115129
//===----------------------------------------------------------------------===//

lib/SILOptimizer/Mandatory/AddressLowering.cpp

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -474,21 +474,6 @@ unsigned OpaqueStorageAllocation::insertIndirectReturnArgs() {
474474
return argIdx;
475475
}
476476

477-
/// Utility to derive SILLocation.
478-
///
479-
/// TODO: This should be a common utility.
480-
static SILLocation getLocForValue(SILValue value) {
481-
if (auto *instr = value->getDefiningInstruction()) {
482-
return instr->getLoc();
483-
}
484-
if (auto *arg = dyn_cast<SILArgument>(value)) {
485-
if (arg->getDecl())
486-
return RegularLocation(const_cast<ValueDecl *>(arg->getDecl()));
487-
}
488-
// TODO: bbargs should probably use one of their operand locations.
489-
return value->getFunction()->getLocation();
490-
}
491-
492477
/// Is this operand composing an aggregate from a subobject, or simply
493478
/// forwarding the operand's value to storage defined elsewhere?
494479
///
@@ -587,7 +572,7 @@ void OpaqueStorageAllocation::allocateForValue(SILValue value,
587572
allocBuilder.setSILConventions(
588573
SILModuleConventions::getLoweredAddressConventions());
589574
AllocStackInst *allocInstr =
590-
allocBuilder.createAllocStack(getLocForValue(value), value->getType());
575+
allocBuilder.createAllocStack(value.getLoc(), value->getType());
591576

592577
storage.storageAddress = allocInstr;
593578

0 commit comments

Comments
 (0)