Skip to content

Commit 1c7126d

Browse files
authored
[VPlan] Combine LiveIns fields into MapVector (NFC) (#170220)
Combine Value2VPValue and VPLiveIns into a single MapVector LiveIns field, simplifying users.
1 parent 5489010 commit 1c7126d

File tree

2 files changed

+7
-24
lines changed

2 files changed

+7
-24
lines changed

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#define LLVM_TRANSFORMS_VECTORIZE_VPLAN_H
2626

2727
#include "VPlanValue.h"
28-
#include "llvm/ADT/DenseMap.h"
28+
#include "llvm/ADT/MapVector.h"
2929
#include "llvm/ADT/SmallPtrSet.h"
3030
#include "llvm/ADT/SmallVector.h"
3131
#include "llvm/ADT/Twine.h"
@@ -4325,13 +4325,9 @@ class VPlan {
43254325
/// Represents the loop-invariant VF * UF of the vector loop region.
43264326
VPValue VFxUF;
43274327

4328-
/// Holds a mapping between Values and their corresponding VPValue inside
4329-
/// VPlan.
4330-
Value2VPValueTy Value2VPValue;
4331-
4332-
/// Contains all the external definitions created for this VPlan. External
4333-
/// definitions are VPValues that hold a pointer to their underlying IR.
4334-
SmallVector<VPValue *, 16> VPLiveIns;
4328+
/// Contains all the external definitions created for this VPlan, as a mapping
4329+
/// from IR Values to VPValues.
4330+
SmallMapVector<Value *, VPValue *, 16> LiveIns;
43354331

43364332
/// Blocks allocated and owned by the VPlan. They will be deleted once the
43374333
/// VPlan is destroyed.
@@ -4528,10 +4524,9 @@ class VPlan {
45284524
/// yet) for \p V.
45294525
VPValue *getOrAddLiveIn(Value *V) {
45304526
assert(V && "Trying to get or add the VPValue of a null Value");
4531-
auto [It, Inserted] = Value2VPValue.try_emplace(V);
4527+
auto [It, Inserted] = LiveIns.try_emplace(V);
45324528
if (Inserted) {
45334529
VPValue *VPV = new VPValue(V);
4534-
VPLiveIns.push_back(VPV);
45354530
assert(VPV->isLiveIn() && "VPV must be a live-in.");
45364531
It->second = VPV;
45374532
}
@@ -4563,17 +4558,10 @@ class VPlan {
45634558
}
45644559

45654560
/// Return the live-in VPValue for \p V, if there is one or nullptr otherwise.
4566-
VPValue *getLiveIn(Value *V) const { return Value2VPValue.lookup(V); }
4561+
VPValue *getLiveIn(Value *V) const { return LiveIns.lookup(V); }
45674562

45684563
/// Return the list of live-in VPValues available in the VPlan.
4569-
ArrayRef<VPValue *> getLiveIns() const {
4570-
assert(all_of(Value2VPValue,
4571-
[this](const auto &P) {
4572-
return is_contained(VPLiveIns, P.second);
4573-
}) &&
4574-
"all VPValues in Value2VPValue must also be in VPLiveIns");
4575-
return VPLiveIns;
4576-
}
4564+
auto getLiveIns() const { return LiveIns.values(); }
45774565

45784566
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
45794567
/// Print the live-ins of this VPlan to \p O.

llvm/lib/Transforms/Vectorize/VPlanValue.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@
2020
#ifndef LLVM_TRANSFORMS_VECTORIZE_VPLAN_VALUE_H
2121
#define LLVM_TRANSFORMS_VECTORIZE_VPLAN_VALUE_H
2222

23-
#include "llvm/ADT/DenseMap.h"
2423
#include "llvm/ADT/STLExtras.h"
2524
#include "llvm/ADT/SmallVector.h"
26-
#include "llvm/ADT/StringMap.h"
2725
#include "llvm/ADT/TinyPtrVector.h"
2826
#include "llvm/ADT/iterator_range.h"
2927
#include "llvm/Support/Compiler.h"
@@ -196,9 +194,6 @@ class LLVM_ABI_FOR_TEST VPValue {
196194
}
197195
};
198196

199-
typedef DenseMap<Value *, VPValue *> Value2VPValueTy;
200-
typedef DenseMap<VPValue *, Value *> VPValue2ValueTy;
201-
202197
LLVM_ABI_FOR_TEST raw_ostream &operator<<(raw_ostream &OS,
203198
const VPRecipeBase &R);
204199

0 commit comments

Comments
 (0)