Skip to content

Commit 3d53e7b

Browse files
authored
Merge pull request swiftlang#12451 from lattner/SILValue-getLoc
2 parents 89db367 + cd99f85 commit 3d53e7b

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();
@@ -903,7 +888,7 @@ void LoadableStorageAllocation::replaceLoadWithCopyAddr(
903888

904889
SILBuilder allocBuilder(pass.F->begin()->begin());
905890
AllocStackInst *allocInstr =
906-
allocBuilder.createAllocStack(getLocForValue(value), value->getType());
891+
allocBuilder.createAllocStack(value.getLoc(), value->getType());
907892

908893
SILBuilder outlinedBuilder(optimizableLoad);
909894
createOutlinedCopyCall(outlinedBuilder, value, allocInstr, pass);
@@ -1030,7 +1015,7 @@ void LoadableStorageAllocation::replaceLoadWithCopyAddrForModifiable(
10301015

10311016
SILBuilder allocBuilder(pass.F->begin()->begin());
10321017
AllocStackInst *allocInstr =
1033-
allocBuilder.createAllocStack(getLocForValue(value), value->getType());
1018+
allocBuilder.createAllocStack(value.getLoc(), value->getType());
10341019

10351020
SILBuilder outlinedBuilder(unoptimizableLoad);
10361021
createOutlinedCopyCall(outlinedBuilder, value, allocInstr, pass);
@@ -1402,7 +1387,7 @@ void LoadableStorageAllocation::allocateForArg(SILValue value) {
14021387

14031388
SILBuilder allocBuilder(pass.F->begin()->begin());
14041389
AllocStackInst *allocInstr =
1405-
allocBuilder.createAllocStack(getLocForValue(value), value->getType());
1390+
allocBuilder.createAllocStack(value.getLoc(), value->getType());
14061391

14071392
LoadInst *loadCopy = nullptr;
14081393
auto *applyOutlinedCopy =
@@ -1682,7 +1667,7 @@ static SILValue createCopyOfEnum(StructLoweringState &pass,
16821667
value = allocInstr;
16831668
}
16841669
SILBuilder allocBuilder(pass.F->begin()->begin());
1685-
auto *allocInstr = allocBuilder.createAllocStack(getLocForValue(value), type);
1670+
auto *allocInstr = allocBuilder.createAllocStack(value.getLoc(), type);
16861671

16871672
SILBuilder copyBuilder(orig);
16881673
createOutlinedCopyCall(copyBuilder, value, allocInstr, pass);

lib/SIL/SILInstruction.cpp

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

897897
// Handle LLVM intrinsic functions.
898-
const IntrinsicInfo & IInfo = BI->getIntrinsicInfo();
898+
const IntrinsicInfo &IInfo = BI->getIntrinsicInfo();
899899
if (IInfo.ID != llvm::Intrinsic::not_intrinsic) {
900900
// Read-only.
901901
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)