LoopVectorize: Clean up ValueMap a bit and avoid double lookups.

No intended functionality change.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@173809 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Benjamin Kramer 2013-01-29 17:31:33 +00:00
parent 86651e4db5
commit 8c3a411cd6

View File

@ -223,31 +223,34 @@ private:
ValueMap(unsigned UnrollFactor) : UF(UnrollFactor) {} ValueMap(unsigned UnrollFactor) : UF(UnrollFactor) {}
/// \return True if 'Key' is saved in the Value Map. /// \return True if 'Key' is saved in the Value Map.
bool has(Value *Key) { return MapStoreage.count(Key); } bool has(Value *Key) const { return MapStorage.count(Key); }
/// Initializes a new entry in the map. Sets all of the vector parts to the /// Initializes a new entry in the map. Sets all of the vector parts to the
/// save value in 'Val'. /// save value in 'Val'.
/// \return A reference to a vector with splat values. /// \return A reference to a vector with splat values.
VectorParts &splat(Value *Key, Value *Val) { VectorParts &splat(Value *Key, Value *Val) {
MapStoreage[Key].clear(); VectorParts &Entry = MapStorage[Key];
MapStoreage[Key].append(UF, Val); Entry.assign(UF, Val);
return MapStoreage[Key]; return Entry;
} }
///\return A reference to the value that is stored at 'Key'. ///\return A reference to the value that is stored at 'Key'.
VectorParts &get(Value *Key) { VectorParts &get(Value *Key) {
if (!has(Key)) VectorParts &Entry = MapStorage[Key];
MapStoreage[Key].resize(UF); if (Entry.empty())
return MapStoreage[Key]; Entry.resize(UF);
assert(Entry.size() == UF);
return Entry;
} }
private:
/// The unroll factor. Each entry in the map stores this number of vector /// The unroll factor. Each entry in the map stores this number of vector
/// elements. /// elements.
unsigned UF; unsigned UF;
/// Map storage. We use std::map and not DenseMap because insertions to a /// Map storage. We use std::map and not DenseMap because insertions to a
/// dense map invalidates its iterators. /// dense map invalidates its iterators.
std::map<Value*, VectorParts> MapStoreage; std::map<Value *, VectorParts> MapStorage;
}; };
/// The original loop. /// The original loop.
@ -824,8 +827,7 @@ InnerLoopVectorizer::getVectorValue(Value *V) {
// If this scalar is unknown, assume that it is a constant or that it is // If this scalar is unknown, assume that it is a constant or that it is
// loop invariant. Broadcast V and save the value for future uses. // loop invariant. Broadcast V and save the value for future uses.
Value *B = getBroadcastInstrs(V); Value *B = getBroadcastInstrs(V);
WidenMap.splat(V, B); return WidenMap.splat(V, B);
return WidenMap.get(V);
} }
Value *InnerLoopVectorizer::reverseVector(Value *Vec) { Value *InnerLoopVectorizer::reverseVector(Value *Vec) {