LLVM: include/llvm/IR/ValueMap.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25#ifndef LLVM_IR_VALUEMAP_H

26#define LLVM_IR_VALUEMAP_H

27

34#include

35#include

36#include

37#include

38#include

39#include

40#include <type_traits>

41#include

42

43namespace llvm {

44

45template <typename KeyT, typename ValueT, typename Config>

47template <typename DenseMapT, typename KeyT, bool IsConst>

49

50

51

52

53template <typename KeyT, typename MutexT = sys::Mutex> struct ValueMapConfig {

55

56

57

59

60

61

62

63

65

66 template

67 static void onRAUW(const ExtraDataT & , KeyT , KeyT ) {}

68 template

69 static void onDelete(const ExtraDataT & , KeyT ) {}

70

71

72

73

74

75 template

79};

80

81

82template <typename KeyT, typename ValueT,

83 typename Config = ValueMapConfig>

86

90

92 using ExtraData = typename Config::ExtraData;

93

94 MapT Map;

95 std::optional MDMap;

96 ExtraData Data;

97

98public:

103

104 explicit ValueMap(unsigned NumInitBuckets = 64)

105 : Map(NumInitBuckets), Data() {}

106 explicit ValueMap(const ExtraData &Data, unsigned NumInitBuckets = 64)

107 : Map(NumInitBuckets), Data(Data) {}

108

109

114

117 if (!MDMap)

118 MDMap.emplace();

119 return *MDMap;

120 }

121 std::optional &getMDMap() { return MDMap; }

122

124

125

127 if (!MDMap)

128 return std::nullopt;

129 auto Where = MDMap->find(MD);

130 if (Where == MDMap->end())

131 return std::nullopt;

132 return Where->second.get();

133 }

134

137

142

143 bool empty() const { return Map.empty(); }

145

146

148

150 Map.clear();

151 MDMap.reset();

153 }

154

155

157 return Map.find_as(Val) == Map.end() ? 0 : 1;

158 }

159

164

165

166

169 return I != Map.end() ? I->second : ValueT();

170 }

171

172

173

174

175 std::pair<iterator, bool> insert(const std::pair<KeyT, ValueT> &KV) {

176 auto MapResult = Map.insert(std::make_pair(Wrap(KV.first), KV.second));

177 return std::make_pair(iterator(MapResult.first), MapResult.second);

178 }

179

180 std::pair<iterator, bool> insert(std::pair<KeyT, ValueT> &&KV) {

181 auto MapResult =

182 Map.insert(std::make_pair(Wrap(KV.first), std::move(KV.second)));

183 return std::make_pair(iterator(MapResult.first), MapResult.second);

184 }

185

186

187 template void insert(InputIt I, InputIt E) {

188 for (; I != E; ++I)

190 }

191

194 if (I == Map.end())

195 return false;

196

197 Map.erase(I);

198 return true;

199 }

201

203 return Map.FindAndConstruct(Wrap(Key));

204 }

205

207

208

209

210

212 return Map.isPointerIntoBucketsArray(Ptr);

213 }

214

215

216

217

219 return Map.getPointerIntoBucketsArray();

220 }

221

222private:

223

224

225

226 ValueMapCVH Wrap(KeyT key) const {

227

228

229

230

231 return ValueMapCVH(key, const_cast<ValueMap *>(this));

232 }

233};

234

235

236

237template <typename KeyT, typename ValueT, typename Config>

238class ValueMapCallbackVH final : public CallbackVH {

240 friend struct DenseMapInfo;

241

243 using KeySansPointerT = std::remove_pointer_t;

244

245 ValueMapT *Map;

246

247 ValueMapCallbackVH(KeyT Key, ValueMapT *Map)

249 Map(Map) {}

250

251

252 ValueMapCallbackVH(Value *V) : CallbackVH(V), Map(nullptr) {}

253

254public:

256

258

259 ValueMapCallbackVH Copy(*this);

260 typename Config::mutex_type *M = Config::getMutex(Copy.Map->Data);

261 std::unique_lock<typename Config::mutex_type> Guard;

262 if (M)

263 Guard = std::unique_lock<typename Config::mutex_type>(*M);

264 Config::onDelete(Copy.Map->Data, Copy.Unwrap());

265 Copy.Map->Map.erase(Copy);

266 }

267

270 "Invalid RAUW on key of ValueMap<>");

271

272 ValueMapCallbackVH Copy(*this);

273 typename Config::mutex_type *M = Config::getMutex(Copy.Map->Data);

274 std::unique_lock<typename Config::mutex_type> Guard;

275 if (M)

276 Guard = std::unique_lock<typename Config::mutex_type>(*M);

277

279

280 Config::onRAUW(Copy.Map->Data, Copy.Unwrap(), typed_new_key);

281 if (Config::FollowRAUW) {

283

284

285 if (I != Copy.Map->Map.end()) {

286 ValueT Target(std::move(I->second));

287 Copy.Map->Map.erase(I);

288 Copy.Map->insert(std::make_pair(typed_new_key, std::move(Target)));

289 }

290 }

291 }

292};

293

294template <typename KeyT, typename ValueT, typename Config>

297

301

305

309

313

315

317 return LHS == RHS.getValPtr();

318 }

319};

320

321template <typename DenseMapT, typename KeyT, bool IsConst>

323 using BaseT = std::conditional_t<IsConst, typename DenseMapT::const_iterator,

324 typename DenseMapT::iterator>;

325 using ValueT = typename DenseMapT::mapped_type;

326

327 BaseT I;

328

329public:

331 using value_type = std::pair<KeyT, typename DenseMapT::mapped_type>;

335

338

339

340 template <bool C = IsConst, typename = std::enable_if_t>

344

345 BaseT base() const { return I; }

346

349 std::conditional_t<IsConst, const ValueT &, ValueT &> second;

350

352

353 operator std::pair<KeyT, ValueT>() const {

355 }

356 };

357

359 ValueTypeProxy Result = {I->first.Unwrap(), I->second};

360 return Result;

361 }

362

364

367

369 ++I;

370 return *this;

371 }

374 ++*this;

375 return tmp;

376 }

377};

378

379template <typename DenseMapT, typename KeyT>

381

382template <typename DenseMapT, typename KeyT>

384

385}

386

387#endif

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")

This file defines DenseMapInfo traits for DenseMap.

This file defines the DenseMap class.

CallbackVH(const CallbackVH &)=default

DenseMapIterator< KeyT, ValueT, KeyInfoT, BucketT > iterator

DenseMapIterator< KeyT, ValueT, KeyInfoT, BucketT, true > const_iterator

Target - Wrapper for Target specific information.

Value * getValPtr() const

Definition ValueMap.h:238

KeyT Unwrap() const

Definition ValueMap.h:255

void allUsesReplacedWith(Value *new_key) override

Callback for Value RAUW.

Definition ValueMap.h:268

void deleted() override

Callback for Value destruction.

Definition ValueMap.h:257

Definition ValueMap.h:322

value_type * pointer

Definition ValueMap.h:333

ValueTypeProxy operator*() const

Definition ValueMap.h:358

BaseT base() const

Definition ValueMap.h:345

ValueMapIteratorImpl operator++(int)

Definition ValueMap.h:372

bool operator!=(const ValueMapIteratorImpl &RHS) const

Definition ValueMap.h:366

std::pair< KeyT, typename MapT::mapped_type > value_type

Definition ValueMap.h:331

bool operator==(const ValueMapIteratorImpl &RHS) const

Definition ValueMap.h:365

ValueTypeProxy operator->() const

Definition ValueMap.h:363

std::forward_iterator_tag iterator_category

Definition ValueMap.h:330

ValueMapIteratorImpl(const ValueMapIteratorImpl< DenseMapT, KeyT, false > &Other)

Definition ValueMap.h:341

ValueMapIteratorImpl(BaseT I)

Definition ValueMap.h:337

value_type & reference

Definition ValueMap.h:334

ValueMapIteratorImpl & operator++()

Definition ValueMap.h:368

ValueMapIteratorImpl()=default

std::ptrdiff_t difference_type

Definition ValueMap.h:332

See the file comment.

Definition ValueMap.h:84

void insert(InputIt I, InputIt E)

insert - Range insertion of pairs.

Definition ValueMap.h:187

ValueT lookup(const KeyT &Val) const

lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...

Definition ValueMap.h:167

WeakTrackingVH mapped_type

Definition ValueMap.h:100

bool isPointerIntoBucketsArray(const void *Ptr) const

isPointerIntoBucketsArray - Return true if the specified pointer points somewhere into the ValueMap's...

Definition ValueMap.h:211

unsigned size_type

Definition ValueMap.h:102

size_type count(const KeyT &Val) const

Return 1 if the specified key is in the map, 0 otherwise.

Definition ValueMap.h:156

bool empty() const

Definition ValueMap.h:143

std::pair< const Value *, WeakTrackingVH > value_type

Definition ValueMap.h:101

void clear()

Definition ValueMap.h:149

std::optional< MDMapT > & getMDMap()

Definition ValueMap.h:121

ValueMap & operator=(ValueMap &&)=delete

value_type & FindAndConstruct(const KeyT &Key)

Definition ValueMap.h:202

bool hasMD() const

Definition ValueMap.h:115

ValueMapIteratorImpl< MapT, const Value *, true > const_iterator

Definition ValueMap.h:136

iterator find(const KeyT &Val)

Definition ValueMap.h:160

iterator begin()

Definition ValueMap.h:138

const Value * key_type

Definition ValueMap.h:99

std::optional< Metadata * > getMappedMD(const Metadata *MD) const

Get the mapped metadata, if it's in the map.

Definition ValueMap.h:126

std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)

Definition ValueMap.h:175

const void * getPointerIntoBucketsArray() const

getPointerIntoBucketsArray() - Return an opaque pointer into the buckets array.

Definition ValueMap.h:218

MDMapT & MD()

Definition ValueMap.h:116

std::pair< iterator, bool > insert(std::pair< KeyT, ValueT > &&KV)

Definition ValueMap.h:180

size_type size() const

Definition ValueMap.h:144

const_iterator find(const KeyT &Val) const

Definition ValueMap.h:161

ValueMap(unsigned NumInitBuckets=64)

Definition ValueMap.h:104

ValueT & operator[](const KeyT &Key)

Definition ValueMap.h:206

iterator end()

Definition ValueMap.h:139

void reserve(size_t Size)

Grow the map so that it has at least Size buckets. Does not shrink.

Definition ValueMap.h:147

ValueMap(const ExtraData &Data, unsigned NumInitBuckets=64)

Definition ValueMap.h:106

const_iterator end() const

Definition ValueMap.h:141

void erase(iterator I)

Definition ValueMap.h:200

const_iterator begin() const

Definition ValueMap.h:140

ValueMapIteratorImpl< MapT, const Value *, false > iterator

Definition ValueMap.h:135

bool erase(const KeyT &Val)

Definition ValueMap.h:192

DMAtomT AtomMap

Definition ValueMap.h:123

ValueMap & operator=(const ValueMap &)=delete

ValueMap(const ValueMap &)=delete

ValueMap(ValueMap &&)=delete

LLVM Value Representation.

This is an optimization pass for GlobalISel generic memory operations.

ValueMapIteratorImpl< DenseMapT, KeyT, false > ValueMapIterator

Definition ValueMap.h:380

auto cast_or_null(const Y &Val)

bool isa(const From &Val)

isa - Return true if the parameter to the template is an instance of one of the template type argu...

LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key

decltype(auto) cast(const From &Val)

cast - Return the argument parameter cast to the specified type.

ValueMapIteratorImpl< DenseMapT, KeyT, true > ValueMapConstIterator

Definition ValueMap.h:383

static unsigned getHashValue(const KeyT &Val)

Definition ValueMap.h:310

static VH getTombstoneKey()

Definition ValueMap.h:302

ValueMapCallbackVH< KeyT, ValueT, Config > VH

Definition ValueMap.h:296

static VH getEmptyKey()

Definition ValueMap.h:298

static bool isEqual(const KeyT &LHS, const VH &RHS)

Definition ValueMap.h:316

static unsigned getHashValue(const VH &Val)

Definition ValueMap.h:306

static bool isEqual(const VH &LHS, const VH &RHS)

Definition ValueMap.h:314

An information struct used to provide DenseMap with the various necessary components for a given valu...

This class defines the default behavior for configurable aspects of ValueMap<>.

Definition ValueMap.h:53

static mutex_type * getMutex(const ExtraDataT &)

Returns a mutex that should be acquired around any changes to the map.

Definition ValueMap.h:76

@ FollowRAUW

Definition ValueMap.h:58

static void onDelete(const ExtraDataT &, KeyT)

Definition ValueMap.h:69

MutexT mutex_type

Definition ValueMap.h:54

static void onRAUW(const ExtraDataT &, KeyT, KeyT)

Definition ValueMap.h:67

Definition ValueMap.h:347

ValueTypeProxy * operator->()

Definition ValueMap.h:351

std::conditional_t< IsConst, const ValueT &, ValueT & > second

Definition ValueMap.h:349

const KeyT first

Definition ValueMap.h:348