Go to the documentation of this file.
25 #ifndef LLVM_IR_VALUEMAP_H
26 #define LLVM_IR_VALUEMAP_H
41 #include <type_traits>
46 template<
typename KeyT,
typename ValueT,
typename Config>
48 template<
typename DenseMapT,
typename KeyT>
50 template<
typename DenseMapT,
typename KeyT>
56 template<
typename KeyT,
typename MutexT = sys::Mutex>
70 template<
typename ExtraDataT>
72 template<
typename ExtraDataT>
79 template<
typename ExtraDataT>
84 template<
typename KeyT,
typename ValueT,
typename Config =ValueMapConfig<KeyT>>
91 using ExtraData =
typename Config::ExtraData;
104 : Map(NumInitBuckets),
Data() {}
106 : Map(NumInitBuckets),
Data(
Data) {}
114 bool hasMD()
const {
return bool(MDMap); }
126 auto Where = MDMap->
find(
MD);
127 if (Where == MDMap->
end())
129 return Where->second.get();
140 bool empty()
const {
return Map.empty(); }
153 return Map.find_as(Val) == Map.end() ? 0 : 1;
167 return I != Map.end() ?
I->second :
ValueT();
173 std::pair<iterator, bool>
insert(
const std::pair<KeyT, ValueT> &KV) {
174 auto MapResult = Map.insert(std::make_pair(Wrap(KV.first), KV.second));
175 return std::make_pair(
iterator(MapResult.first), MapResult.second);
178 std::pair<iterator, bool>
insert(std::pair<KeyT, ValueT> &&KV) {
180 Map.insert(std::make_pair(Wrap(KV.first),
std::move(KV.second)));
181 return std::make_pair(
iterator(MapResult.first), MapResult.second);
185 template<
typename InputIt>
200 return Map.erase(
I.base());
204 return Map.FindAndConstruct(Wrap(
Key));
208 return Map[Wrap(
Key)];
215 return Map.isPointerIntoBucketsArray(Ptr);
222 return Map.getPointerIntoBucketsArray();
229 ValueMapCVH Wrap(KeyT key)
const {
234 return ValueMapCVH(key,
const_cast<ValueMap*
>(
this));
240 template <
typename KeyT,
typename ValueT,
typename Config>
241 class ValueMapCallbackVH final :
public CallbackVH {
246 using KeySansPointerT = std::remove_pointer_t<KeyT>;
258 KeyT Unwrap()
const {
return cast_or_null<KeySansPointerT>(getValPtr()); }
263 typename Config::mutex_type *
M = Config::getMutex(Copy.Map->Data);
264 std::unique_lock<typename Config::mutex_type> Guard;
266 Guard = std::unique_lock<typename Config::mutex_type>(*
M);
267 Config::onDelete(Copy.Map->Data, Copy.Unwrap());
268 Copy.Map->Map.erase(Copy);
272 assert(isa<KeySansPointerT>(new_key) &&
273 "Invalid RAUW on key of ValueMap<>");
276 typename Config::mutex_type *
M = Config::getMutex(Copy.Map->Data);
277 std::unique_lock<typename Config::mutex_type> Guard;
279 Guard = std::unique_lock<typename Config::mutex_type>(*
M);
281 KeyT typed_new_key = cast<KeySansPointerT>(new_key);
283 Config::onRAUW(Copy.Map->Data, Copy.Unwrap(), typed_new_key);
284 if (Config::FollowRAUW) {
288 if (
I != Copy.Map->Map.end()) {
290 Copy.Map->Map.erase(
I);
297 template<
typename KeyT,
typename ValueT,
typename Config>
322 return LHS ==
RHS.getValPtr();
326 template <
typename DenseMapT,
typename KeyT>
class ValueMapIterator {
327 using BaseT =
typename DenseMapT::iterator;
328 using ValueT =
typename DenseMapT::mapped_type;
334 using value_type = std::pair<KeyT, typename DenseMapT::mapped_type>;
350 operator std::pair<KeyT, ValueT>()
const {
380 template <
typename DenseMapT,
typename KeyT>
class ValueMapConstIterator {
381 using BaseT =
typename DenseMapT::const_iterator;
382 using ValueT =
typename DenseMapT::mapped_type;
388 using value_type = std::pair<KeyT, typename DenseMapT::mapped_type>;
404 operator std::pair<KeyT, ValueT>()
const {
436 #endif // LLVM_IR_VALUEMAP_H
ValueTypeProxy operator*() const
Optional< MDMapT > & getMDMap()
const_iterator find(const KeyT &Val) const
static bool isEqual(const KeyT &LHS, const VH &RHS)
This is an optimization pass for GlobalISel generic memory operations.
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
bool operator==(const ValueMapIterator &RHS) const
Optional< Metadata * > getMappedMD(const Metadata *MD) const
Get the mapped metadata, if it's in the map.
void insert(InputIt I, InputIt E)
insert - Range insertion of pairs.
const_iterator begin() const
Target - Wrapper for Target specific information.
ValueMapConstIterator(ValueMapIterator< DenseMapT, KeyT > Other)
ValueMapIterator< MapT, KeyT > iterator
std::forward_iterator_tag iterator_category
void reserve(size_t Size)
Grow the map so that it has at least Size buckets. Does not shrink.
void allUsesReplacedWith(Value *new_key) override
std::forward_iterator_tag iterator_category
alloca< 16 x float >, align 16 %tmp2=alloca< 16 x float >, align 16 store< 16 x float > %A,< 16 x float > *%tmp %s=bitcast< 16 x float > *%tmp to i8 *%s2=bitcast< 16 x float > *%tmp2 to i8 *call void @llvm.memcpy.i64(i8 *%s, i8 *%s2, i64 64, i32 16) %R=load< 16 x float > *%tmp2 ret< 16 x float > %R } declare void @llvm.memcpy.i64(i8 *nocapture, i8 *nocapture, i64, i32) nounwind which compiles to:_foo:subl $140, %esp movaps %xmm3, 112(%esp) movaps %xmm2, 96(%esp) movaps %xmm1, 80(%esp) movaps %xmm0, 64(%esp) movl 60(%esp), %eax movl %eax, 124(%esp) movl 56(%esp), %eax movl %eax, 120(%esp) movl 52(%esp), %eax< many many more 32-bit copies > movaps(%esp), %xmm0 movaps 16(%esp), %xmm1 movaps 32(%esp), %xmm2 movaps 48(%esp), %xmm3 addl $140, %esp ret On Nehalem, it may even be cheaper to just use movups when unaligned than to fall back to lower-granularity chunks. Implement processor-specific optimizations for parity with GCC on these processors. GCC does two optimizations:1. ix86_pad_returns inserts a noop before ret instructions if immediately preceded by a conditional branch or is the target of a jump. 2. ix86_avoid_jump_misspredicts inserts noops in cases where a 16-byte block of code contains more than 3 branches. The first one is done for all AMDs, Core2, and "Generic" The second one is done for:Atom, Pentium Pro, all AMDs, Pentium 4, Nocona, Core 2, and "Generic" Testcase:int x(int a) { return(a &0xf0)> >4 tmp
static void onDelete(const ExtraDataT &, KeyT)
std::ptrdiff_t difference_type
ValueMapIterator(BaseT I)
An information struct used to provide DenseMap with the various necessary components for a given valu...
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
ValueMapConstIterator(BaseT I)
This class defines the default behavior for configurable aspects of ValueMap<>.
size_type count(const KeyT &Val) const
Return 1 if the specified key is in the map, 0 otherwise.
ValueTypeProxy * operator->()
ValueMap & operator=(const ValueMap &)=delete
bool operator!=(const ValueMapConstIterator &RHS) const
std::ptrdiff_t difference_type
static void onRAUW(const ExtraDataT &, KeyT, KeyT)
static mutex_type * getMutex(const ExtraDataT &)
Returns a mutex that should be acquired around any changes to the map.
ValueT & operator[](const KeyT &Key)
void emplace(ArgTypes &&... Args)
Create a new object by constructing it in place with the given arguments.
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
ValueTypeProxy operator->() const
bool erase(const KeyT &Val)
iterator find(const_arg_type_t< KeyT > Val)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool operator!=(const ValueMapIterator &RHS) const
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
const void * getPointerIntoBucketsArray() const
getPointerIntoBucketsArray() - Return an opaque pointer into the buckets array.
ValueTypeProxy * operator->()
ValueMapConstIterator operator++(int)
const_iterator end() const
ValueTypeProxy operator*() const
ValueMap(unsigned NumInitBuckets=64)
static unsigned getHashValue(const KeyT &Val)
ValueMapConstIterator & operator++()
iterator find(const KeyT &Val)
ValueMapIterator & operator++()
std::pair< iterator, bool > insert(std::pair< KeyT, ValueT > &&KV)
Value handle with callbacks on RAUW and destruction.
value_type & FindAndConstruct(const KeyT &Key)
static unsigned getHashValue(const VH &Val)
std::pair< KeyT, typename DenseMapT::mapped_type > value_type
std::pair< const Function *, FuncInfo > value_type
ValueMapConstIterator< MapT, KeyT > const_iterator
static bool isEqual(const VH &LHS, const VH &RHS)
bool operator==(const ValueMapConstIterator &RHS) const
ValueT lookup(const KeyT &Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
ValueMapIterator operator++(int)
LLVM Value Representation.
std::pair< KeyT, typename DenseMapT::mapped_type > value_type
ValueTypeProxy operator->() const
ValueMap(const ExtraData &Data, unsigned NumInitBuckets=64)
static VH getTombstoneKey()
Optional< std::vector< StOtherPiece > > Other
bool isPointerIntoBucketsArray(const void *Ptr) const
isPointerIntoBucketsArray - Return true if the specified pointer points somewhere into the ValueMap's...