Skip to content

[pmo] InsertionPoints are always stores, so just represent this expli… #22029

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions lib/SILOptimizer/Mandatory/PredictableMemOpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,12 @@ class AvailableValueAggregator;
struct AvailableValue {
friend class AvailableValueAggregator;

/// If this gets too expensive in terms of copying, we can use an arena and a
/// FrozenPtrSet like we do in ARC.
using SetVector = llvm::SmallSetVector<SILInstruction *, 1>;

SILValue Value;
unsigned SubElementNumber;
SetVector InsertionPoints;

/// If this gets too expensive in terms of copying, we can use an arena and a
/// FrozenPtrSet like we do in ARC.
SmallSetVector<StoreInst *, 1> InsertionPoints;

/// Just for updating.
SmallVectorImpl<PMOMemoryUse> *Uses;
Expand All @@ -181,7 +180,7 @@ struct AvailableValue {
/// *NOTE* We assume that all available values start with a singular insertion
/// point and insertion points are added by merging.
AvailableValue(SILValue Value, unsigned SubElementNumber,
SILInstruction *InsertPoint)
StoreInst *InsertPoint)
: Value(Value), SubElementNumber(SubElementNumber), InsertionPoints() {
InsertionPoints.insert(InsertPoint);
}
Expand Down Expand Up @@ -221,7 +220,7 @@ struct AvailableValue {
SILValue getValue() const { return Value; }
SILType getType() const { return Value->getType(); }
unsigned getSubElementNumber() const { return SubElementNumber; }
ArrayRef<SILInstruction *> getInsertionPoints() const {
ArrayRef<StoreInst *> getInsertionPoints() const {
return InsertionPoints.getArrayRef();
}

Expand All @@ -230,16 +229,14 @@ struct AvailableValue {
InsertionPoints.set_union(Other.InsertionPoints);
}

void addInsertionPoint(SILInstruction *I) & { InsertionPoints.insert(I); }
void addInsertionPoint(StoreInst *I) & { InsertionPoints.insert(I); }

/// TODO: This needs a better name.
AvailableValue emitStructExtract(SILBuilder &B, SILLocation Loc, VarDecl *D,
unsigned SubElementNumber) const {
SILValue NewValue = B.emitStructExtract(Loc, Value, D);
return {NewValue, SubElementNumber, InsertionPoints};
}

/// TODO: This needs a better name.
AvailableValue emitTupleExtract(SILBuilder &B, SILLocation Loc,
unsigned EltNo,
unsigned SubElementNumber) const {
Expand All @@ -253,7 +250,7 @@ struct AvailableValue {
private:
/// Private constructor.
AvailableValue(SILValue Value, unsigned SubElementNumber,
const SetVector &InsertPoints)
const decltype(InsertionPoints) &InsertPoints)
: Value(Value), SubElementNumber(SubElementNumber),
InsertionPoints(InsertPoints) {}
};
Expand Down Expand Up @@ -524,7 +521,7 @@ SILValue AvailableValueAggregator::handlePrimitiveValue(SILType LoadTy,
//
// This saves us from having to spend compile time in the SSA updater in this
// case.
ArrayRef<SILInstruction *> InsertPts = Val.getInsertionPoints();
ArrayRef<StoreInst *> InsertPts = Val.getInsertionPoints();
if (InsertPts.size() == 1) {
// Use the scope and location of the store at the insertion point.
SILBuilderWithScope Builder(InsertPts[0]);
Expand Down Expand Up @@ -679,15 +676,15 @@ void AvailableValueDataflowContext::updateAvailableValues(
// conflict, then we're ok.
auto &Entry = Result[StartSubElt+i];
if (!Entry) {
Entry = {SI->getSrc(), i, Inst};
Entry = {SI->getSrc(), i, SI};
} else {
// TODO: This is /really/, /really/, conservative. This basically means
// that if we do not have an identical store, we will not promote.
if (Entry.getValue() != SI->getSrc() ||
Entry.getSubElementNumber() != i) {
ConflictingValues[StartSubElt + i] = true;
} else {
Entry.addInsertionPoint(Inst);
Entry.addInsertionPoint(SI);
}
}

Expand Down