Skip to content

[NFC] Add a specialization of DenseMapInfo for SmallVector #140380

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
Merged
Show file tree
Hide file tree
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
21 changes: 21 additions & 0 deletions llvm/include/llvm/ADT/SmallVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#ifndef LLVM_ADT_SMALLVECTOR_H
#define LLVM_ADT_SMALLVECTOR_H

#include "llvm/ADT/DenseMapInfo.h"
#include "llvm/Support/Compiler.h"
#include <algorithm>
#include <cassert>
Expand Down Expand Up @@ -1319,6 +1320,26 @@ extern template class llvm::SmallVectorBase<uint32_t>;
extern template class llvm::SmallVectorBase<uint64_t>;
#endif

// Provide DenseMapInfo for SmallVector of a type which has info.
template <typename T, unsigned N> struct DenseMapInfo<llvm::SmallVector<T, N>> {
static SmallVector<T, N> getEmptyKey() {
return {DenseMapInfo<T>::getEmptyKey()};
}

static SmallVector<T, N> getTombstoneKey() {
return {DenseMapInfo<T>::getTombstoneKey()};
}

static unsigned getHashValue(const SmallVector<T, N> &V) {
return static_cast<unsigned>(hash_combine_range(V));
}

static bool isEqual(const SmallVector<T, N> &LHS,
const SmallVector<T, N> &RHS) {
return LHS == RHS;
}
};

} // end namespace llvm

namespace std {
Expand Down
30 changes: 2 additions & 28 deletions llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1275,38 +1275,13 @@ struct LSRFixup {
void dump() const;
};

/// A DenseMapInfo implementation for holding DenseMaps and DenseSets of sorted
/// SmallVectors of const SCEV*.
struct UniquifierDenseMapInfo {
static SmallVector<const SCEV *, 4> getEmptyKey() {
SmallVector<const SCEV *, 4> V;
V.push_back(reinterpret_cast<const SCEV *>(-1));
return V;
}

static SmallVector<const SCEV *, 4> getTombstoneKey() {
SmallVector<const SCEV *, 4> V;
V.push_back(reinterpret_cast<const SCEV *>(-2));
return V;
}

static unsigned getHashValue(const SmallVector<const SCEV *, 4> &V) {
return static_cast<unsigned>(hash_combine_range(V));
}

static bool isEqual(const SmallVector<const SCEV *, 4> &LHS,
const SmallVector<const SCEV *, 4> &RHS) {
return LHS == RHS;
}
};

/// This class holds the state that LSR keeps for each use in IVUsers, as well
/// as uses invented by LSR itself. It includes information about what kinds of
/// things can be folded into the user, information about the user itself, and
/// information about how the use may be satisfied. TODO: Represent multiple
/// users of the same expression in common?
class LSRUse {
DenseSet<SmallVector<const SCEV *, 4>, UniquifierDenseMapInfo> Uniquifier;
DenseSet<SmallVector<const SCEV *, 4>> Uniquifier;

public:
/// An enum for a kind of use, indicating what types of scaled and immediate
Expand Down Expand Up @@ -4754,8 +4729,7 @@ void LSRInstance::FilterOutUndesirableDedicatedRegisters() {

// Collect the best formula for each unique set of shared registers. This
// is reset for each use.
using BestFormulaeTy =
DenseMap<SmallVector<const SCEV *, 4>, size_t, UniquifierDenseMapInfo>;
using BestFormulaeTy = DenseMap<SmallVector<const SCEV *, 4>, size_t>;

BestFormulaeTy BestFormulae;

Expand Down
24 changes: 1 addition & 23 deletions llvm/lib/Transforms/Vectorize/VPlanSLP.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,30 +73,8 @@ class VPInterleavedAccessInfo {
class VPlanSlp {
enum class OpMode { Failed, Load, Opcode };

/// A DenseMapInfo implementation for using SmallVector<VPValue *, 4> as
/// DenseMap keys.
struct BundleDenseMapInfo {
static SmallVector<VPValue *, 4> getEmptyKey() {
return {reinterpret_cast<VPValue *>(-1)};
}

static SmallVector<VPValue *, 4> getTombstoneKey() {
return {reinterpret_cast<VPValue *>(-2)};
}

static unsigned getHashValue(const SmallVector<VPValue *, 4> &V) {
return static_cast<unsigned>(hash_combine_range(V));
}

static bool isEqual(const SmallVector<VPValue *, 4> &LHS,
const SmallVector<VPValue *, 4> &RHS) {
return LHS == RHS;
}
};

/// Mapping of values in the original VPlan to a combined VPInstruction.
DenseMap<SmallVector<VPValue *, 4>, VPInstruction *, BundleDenseMapInfo>
BundleToCombined;
DenseMap<SmallVector<VPValue *, 4>, VPInstruction *> BundleToCombined;

VPInterleavedAccessInfo &IAI;

Expand Down
Loading