LLVM: lib/IR/Metadata.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

51#include

52#include

53#include

54#include <type_traits>

55#include

56#include

57

58using namespace llvm;

59

60MetadataAsValue::MetadataAsValue(Type *Ty, Metadata *MD)

61 : Value(Ty, MetadataAsValueVal), MD(MD) {

62 track();

63}

64

67 untrack();

68}

69

70

71

72

73

74

75

76

77

78

79

80

83 if (!MD)

84

86

87

88 auto *N = dyn_cast(MD);

89 if (N || N->getNumOperands() != 1)

90 return MD;

91

92 if (N->getOperand(0))

93

95

96 if (auto *C = dyn_cast(N->getOperand(0)))

97

98 return C;

99

100 return MD;

101}

102

106 if (!Entry)

108 return Entry;

109}

110

115 return Store.lookup(MD);

116}

117

118void MetadataAsValue::handleChangedMetadata(Metadata *MD) {

122

123

124 Store.erase(this->MD);

125 untrack();

126 this->MD = nullptr;

127

128

129 auto *&Entry = Store[MD];

130 if (Entry) {

132 delete this;

133 return;

134 }

135

136 this->MD = MD;

137 track();

138 Entry = this;

139}

140

141void MetadataAsValue::track() {

142 if (MD)

144}

145

146void MetadataAsValue::untrack() {

147 if (MD)

149}

150

153}

156}

157

159

160

161 auto OldMD = static_cast<Metadata **>(Old);

163

164

165 if (OldMD && isa(*OldMD) && !New) {

166 auto *OldVAM = cast(*OldMD);

168 }

170}

171

172void DebugValueUser::trackDebugValue(size_t Idx) {

173 assert(Idx < 3 && "Invalid debug value index.");

175 if (MD)

177}

178

179void DebugValueUser::trackDebugValues() {

181 if (MD)

183}

184

185void DebugValueUser::untrackDebugValue(size_t Idx) {

186 assert(Idx < 3 && "Invalid debug value index.");

188 if (MD)

190}

191

192void DebugValueUser::untrackDebugValues() {

194 if (MD)

196}

197

198void DebugValueUser::retrackDebugValues(DebugValueUser &X) {

199 assert(DebugValueUser::operator==(X) && "Expected values to match");

200 for (const auto &[MD, XMD] : zip(DebugValues, X.DebugValues))

201 if (XMD)

203 X.DebugValues.fill(nullptr);

204}

205

207 assert(Ref && "Expected live reference");

209 "Reference without owner must be direct");

210 if (auto *R = ReplaceableMetadataImpl::getOrCreate(MD)) {

211 R->addRef(Ref, Owner);

212 return true;

213 }

214 if (auto *PH = dyn_cast(&MD)) {

215 assert(!PH->Use && "Placeholders can only be used once");

216 assert(!Owner && "Unexpected callback to owner");

218 return true;

219 }

220 return false;

221}

222

224 assert(Ref && "Expected live reference");

225 if (auto *R = ReplaceableMetadataImpl::getIfExists(MD))

226 R->dropRef(Ref);

227 else if (auto *PH = dyn_cast(&MD))

228 PH->Use = nullptr;

229}

230

232 assert(Ref && "Expected live reference");

233 assert(New && "Expected live reference");

234 assert(Ref != New && "Expected change");

235 if (auto *R = ReplaceableMetadataImpl::getIfExists(MD)) {

236 R->moveRef(Ref, New, MD);

237 return true;

238 }

239 assert(!isa(MD) &&

240 "Unexpected move of an MDOperand");

242 "Expected un-replaceable metadata, since we didn't move a reference");

243 return false;

244}

245

247 return ReplaceableMetadataImpl::isReplaceable(MD);

248}

249

252 for (auto Pair : UseMap) {

253 OwnerTy Owner = Pair.second.first;

255 continue;

256 if (!isa<Metadata *>(Owner))

257 continue;

258 Metadata *OwnerMD = cast<Metadata *>(Owner);

259 if (OwnerMD->getMetadataID() == Metadata::DIArgListKind)

260 MDUsersWithID.push_back(&UseMap[Pair.first]);

261 }

262 llvm::sort(MDUsersWithID, [](auto UserA, auto UserB) {

263 return UserA->second < UserB->second;

264 });

266 for (auto *UserWithID : MDUsersWithID)

267 MDUsers.push_back(cast<Metadata *>(UserWithID->first));

268 return MDUsers;

269}

270

274 for (auto Pair : UseMap) {

275 OwnerTy Owner = Pair.second.first;

277 continue;

278 if (!isa<DebugValueUser *>(Owner))

279 continue;

280 DVRUsersWithID.push_back(&UseMap[Pair.first]);

281 }

282

283

284

285

286

287 llvm::sort(DVRUsersWithID, [](auto UserA, auto UserB) {

288 return UserA->second > UserB->second;

289 });

291 for (auto UserWithID : DVRUsersWithID)

292 DVRUsers.push_back(cast<DebugValueUser *>(UserWithID->first)->getUser());

293 return DVRUsers;

294}

295

296void ReplaceableMetadataImpl::addRef(void *Ref, OwnerTy Owner) {

297 bool WasInserted =

298 UseMap.insert(std::make_pair(Ref, std::make_pair(Owner, NextIndex)))

299 .second;

300 (void)WasInserted;

301 assert(WasInserted && "Expected to add a reference");

302

303 ++NextIndex;

304 assert(NextIndex != 0 && "Unexpected overflow");

305}

306

307void ReplaceableMetadataImpl::dropRef(void *Ref) {

308 bool WasErased = UseMap.erase(Ref);

309 (void)WasErased;

310 assert(WasErased && "Expected to drop a reference");

311}

312

313void ReplaceableMetadataImpl::moveRef(void *Ref, void *New,

315 auto I = UseMap.find(Ref);

316 assert(I != UseMap.end() && "Expected to move a reference");

317 auto OwnerAndIndex = I->second;

318 UseMap.erase(I);

319 bool WasInserted = UseMap.insert(std::make_pair(New, OwnerAndIndex)).second;

320 (void)WasInserted;

321 assert(WasInserted && "Expected to add a reference");

322

323

324 (void)MD;

325 assert((OwnerAndIndex.first || *static_cast<Metadata **>(Ref) == &MD) &&

326 "Reference without owner must be direct");

327 assert((OwnerAndIndex.first || *static_cast<Metadata **>(New) == &MD) &&

328 "Reference without owner must be direct");

329}

330

332 if (C.isUsedByMetadata()) {

333 return;

334 }

335

336 LLVMContext &Context = C.getType()->getContext();

338 auto I = Store.find(&C);

340 using UseTy =

341 std::pair<void *, std::pair<MetadataTracking::OwnerTy, uint64_t>>;

342

344

345 for (const auto &Pair : Uses) {

347 if (!Owner)

348 continue;

349

350 if (isa<MetadataAsValue *>(Owner)) {

351 cast<MetadataAsValue *>(Owner)->handleChangedMetadata(

353 continue;

354 }

355 if (!isa<Metadata *>(Owner))

356 continue;

357 auto *OwnerMD = dyn_cast_if_present(cast<Metadata *>(Owner));

358 if (!OwnerMD)

359 continue;

360 if (isa(OwnerMD)) {

361 OwnerMD->handleChangedOperand(

363 }

364 }

365}

366

368 if (UseMap.empty())

369 return;

370

371

372 using UseTy = std::pair<void *, std::pair<OwnerTy, uint64_t>>;

374 llvm::sort(Uses, [](const UseTy &L, const UseTy &R) {

375 return L.second.second < R.second.second;

376 });

377 for (const auto &Pair : Uses) {

378

379

380 if (!UseMap.count(Pair.first))

381 continue;

382

383 OwnerTy Owner = Pair.second.first;

384 if (!Owner) {

385

387 Ref = MD;

388 if (MD)

390 UseMap.erase(Pair.first);

391 continue;

392 }

393

394

395 if (isa<MetadataAsValue *>(Owner)) {

396 cast<MetadataAsValue *>(Owner)->handleChangedMetadata(MD);

397 continue;

398 }

399

400 if (auto *DVU = dyn_cast<DebugValueUser *>(Owner)) {

401 DVU->handleChangedValue(Pair.first, MD);

402 continue;

403 }

404

405

406 Metadata *OwnerMD = cast<Metadata *>(Owner);

408#define HANDLE_METADATA_LEAF(CLASS) \

409 case Metadata::CLASS##Kind: \

410 cast(OwnerMD)->handleChangedOperand(Pair.first, MD); \

411 continue;

412#include "llvm/IR/Metadata.def"

413 default:

415 }

416 }

417 assert(UseMap.empty() && "Expected all uses to be replaced");

418}

419

421 if (UseMap.empty())

422 return;

423

424 if (!ResolveUsers) {

425 UseMap.clear();

426 return;

427 }

428

429

430 using UseTy = std::pair<void *, std::pair<OwnerTy, uint64_t>>;

432 llvm::sort(Uses, [](const UseTy &L, const UseTy &R) {

433 return L.second.second < R.second.second;

434 });

435 UseMap.clear();

436 for (const auto &Pair : Uses) {

437 auto Owner = Pair.second.first;

438 if (!Owner)

439 continue;

440 if (!isa<Metadata *>(Owner))

441 continue;

442

443

444 auto *OwnerMD = dyn_cast_if_present(cast<Metadata *>(Owner));

445 if (!OwnerMD)

446 continue;

447 if (OwnerMD->isResolved())

448 continue;

449 OwnerMD->decrementUnresolvedOperandCount();

450 }

451}

452

453

454

455

457 if (auto *N = dyn_cast(&MD)) {

458 return N->isResolved() || N->isAlwaysReplaceable()

459 ? N->Context.getOrCreateReplaceableUses()

460 : nullptr;

461 }

462 if (auto ArgList = dyn_cast(&MD))

463 return ArgList;

464 return dyn_cast(&MD);

465}

466

468 if (auto *N = dyn_cast(&MD)) {

469 return N->isResolved() || N->isAlwaysReplaceable()

470 ? N->Context.getReplaceableUses()

471 : nullptr;

472 }

473 if (auto ArgList = dyn_cast(&MD))

474 return ArgList;

475 return dyn_cast(&MD);

476}

477

478bool ReplaceableMetadataImpl::isReplaceable(const Metadata &MD) {

479 if (auto *N = dyn_cast(&MD))

480 return N->isResolved() || N->isAlwaysReplaceable();

481 return isa(&MD) || isa(&MD);

482}

483

485 assert(V && "Expected value");

486 if (auto *A = dyn_cast(V)) {

487 if (auto *Fn = A->getParent())

488 return Fn->getSubprogram();

489 return nullptr;

490 }

491

493 if (auto *Fn = BB->getParent())

494 return Fn->getSubprogram();

495 return nullptr;

496 }

497

498 return nullptr;

499}

500

502 assert(V && "Unexpected null Value");

503

504 auto &Context = V->getContext();

506 if (!Entry) {

507 assert((isa(V) || isa(V) || isa(V)) &&

508 "Expected constant or function-local value");

509 assert(!V->IsUsedByMD && "Expected this to be the only metadata use");

510 V->IsUsedByMD = true;

511 if (auto *C = dyn_cast(V))

513 else

515 }

516

517 return Entry;

518}

519

521 assert(V && "Unexpected null Value");

522 return V->getContext().pImpl->ValuesAsMetadata.lookup(V);

523}

524

526 assert(V && "Expected valid value");

527

528 auto &Store = V->getType()->getContext().pImpl->ValuesAsMetadata;

529 auto I = Store.find(V);

530 if (I == Store.end())

531 return;

532

533

535 assert(MD && "Expected valid metadata");

536 assert(MD->getValue() == V && "Expected valid mapping");

537 Store.erase(I);

538

539

541 delete MD;

542}

543

545 assert(From && "Expected valid value");

546 assert(To && "Expected valid value");

547 assert(From != To && "Expected changed value");

549

552 auto I = Store.find(From);

553 if (I == Store.end()) {

554 assert(From->IsUsedByMD && "Expected From not to be used by metadata");

555 return;

556 }

557

558

559 assert(From->IsUsedByMD && "Expected From to be used by metadata");

560 From->IsUsedByMD = false;

562 assert(MD && "Expected valid metadata");

564 Store.erase(I);

565

566 if (isa(MD)) {

567 if (auto *C = dyn_cast(To)) {

568

570 delete MD;

571 return;

572 }

575

577 delete MD;

579 }

580 } else if (!isa(To)) {

581

583 delete MD;

584 return;

585 }

587 auto *&Entry = Store[To];

588 if (Entry) {

589

591 delete MD;

592 return;

593 }

594

595

596 assert(!To->IsUsedByMD && "Expected this to be the only metadata use");

598 MD->V = To;

599 Entry = MD;

600}

601

602

603

604

605

608 auto I = Store.try_emplace(Str);

609 auto &MapEntry = I.first->getValue();

610 if (I.second)

611 return &MapEntry;

612 MapEntry.Entry = &*I.first;

613 return &MapEntry;

614}

615

617 assert(Entry && "Expected to find string map entry");

618 return Entry->first();

620

621

622

623

624

625

626

627#define HANDLE_MDNODE_LEAF(CLASS) \

628 static_assert( \

629 alignof(uint64_t) >= alignof(CLASS), \

630 "Alignment is insufficient after objects prepended to " #CLASS);

631#include "llvm/IR/Metadata.def"

632

633void *MDNode::operator new(size_t Size, size_t NumOps, StorageType Storage) {

634

635

636 size_t AllocSize =

637 alignTo(Header::getAllocSize(Storage, NumOps), alignof(uint64_t));

638 char *Mem = reinterpret_cast<char *>(::operator new(AllocSize + Size));

639 Header *H = new (Mem + AllocSize - sizeof(Header)) Header(NumOps, Storage);

640 return reinterpret_cast<void *>(H + 1);

641}

642

643void MDNode::operator delete(void *N) {

644 Header *H = reinterpret_cast<Header *>(N) - 1;

645 void *Mem = H->getAllocation();

646 H->~Header();

647 ::operator delete(Mem);

648}

649

652 : Metadata(ID, Storage), Context(Context) {

653 unsigned Op = 0;

658

660 return;

661

662

663

664 countUnresolvedOperands();

665}

666

669 default:

671#define HANDLE_MDNODE_LEAF(CLASS) \

672 case CLASS##Kind: \

673 return cast(this)->cloneImpl();

674#include "llvm/IR/Metadata.def"

675 }

676}

677

678MDNode::Header::Header(size_t NumOps, StorageType Storage) {

679 IsLarge = isLarge(NumOps);

680 IsResizable = isResizable(Storage);

681 SmallSize = getSmallSize(NumOps, IsResizable, IsLarge);

682 if (IsLarge) {

683 SmallNumOps = 0;

684 new (getLargePtr()) LargeStorageVector();

685 getLarge().resize(NumOps);

686 return;

687 }

688 SmallNumOps = NumOps;

690 for (MDOperand *E = O + SmallSize; O != E;)

692}

693

694MDNode::Header::~Header() {

695 if (IsLarge) {

696 getLarge().~LargeStorageVector();

697 return;

698 }

700 for (MDOperand *E = O - SmallSize; O != E; --O)

702}

703

704void *MDNode::Header::getSmallPtr() {

705 static_assert(alignof(MDOperand) <= alignof(Header),

706 "MDOperand too strongly aligned");

707 return reinterpret_cast<char *>(const_cast<Header *>(this)) -

709}

710

711void MDNode::Header::resize(size_t NumOps) {

712 assert(IsResizable && "Node is not resizable");

713 if (operands().size() == NumOps)

714 return;

715

716 if (IsLarge)

717 getLarge().resize(NumOps);

718 else if (NumOps <= SmallSize)

719 resizeSmall(NumOps);

720 else

721 resizeSmallToLarge(NumOps);

722}

723

724void MDNode::Header::resizeSmall(size_t NumOps) {

725 assert(!IsLarge && "Expected a small MDNode");

726 assert(NumOps <= SmallSize && "NumOps too large for small resize");

727

729 assert(NumOps != ExistingOps.size() && "Expected a different size");

730

731 int NumNew = (int)NumOps - (int)ExistingOps.size();

733 for (int I = 0, E = NumNew; I < E; ++I)

734 (O++)->reset();

735 for (int I = 0, E = NumNew; I > E; --I)

736 (--O)->reset();

737 SmallNumOps = NumOps;

738 assert(O == operands().end() && "Operands not (un)initialized until the end");

739}

740

741void MDNode::Header::resizeSmallToLarge(size_t NumOps) {

742 assert(!IsLarge && "Expected a small MDNode");

743 assert(NumOps > SmallSize && "Expected NumOps to be larger than allocation");

744 LargeStorageVector NewOps;

745 NewOps.resize(NumOps);

746 llvm::move(operands(), NewOps.begin());

747 resizeSmall(0);

748 new (getLargePtr()) LargeStorageVector(std::move(NewOps));

749 IsLarge = true;

750}

751

753 if (auto *N = dyn_cast_or_null(Op))

754 return N->isResolved();

755 return false;

756}

757

758void MDNode::countUnresolvedOperands() {

762}

763

764void MDNode::makeUniqued() {

767

768

770 Op.reset(Op.get(), this);

771

772

774 countUnresolvedOperands();

776 dropReplaceableUses();

778 }

779

781}

782

783void MDNode::makeDistinct() {

786

787

788 dropReplaceableUses();

790

793}

794

798

800 dropReplaceableUses();

801

803}

804

805void MDNode::dropReplaceableUses() {

807

808

809 if (Context.hasReplaceableUses())

810 Context.takeReplaceableUses()->resolveAllUses();

811}

812

813void MDNode::resolveAfterOperandChange(Metadata *Old, Metadata *New) {

816

817

820

823 decrementUnresolvedOperandCount();

824}

825

826void MDNode::decrementUnresolvedOperandCount() {

829 return;

830

834 return;

835

836

837 dropReplaceableUses();

839}

840

843 return;

844

845

847

848

850 auto *N = dyn_cast_or_null(Op);

851 if (N)

852 continue;

853

854 assert(N->isTemporary() &&

855 "Expected all forward declarations to be resolved");

856 if (N->isResolved())

857 N->resolveCycles();

858 }

859}

860

863}

864

865MDNode *MDNode::replaceWithPermanentImpl() {

867 default:

868

869 return replaceWithDistinctImpl();

870

871#define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS) \

872 case CLASS##Kind: \

873 break;

874#include "llvm/IR/Metadata.def"

875 }

876

877

879 return replaceWithDistinctImpl();

880 return replaceWithUniquedImpl();

881}

882

883MDNode *MDNode::replaceWithUniquedImpl() {

884

885 MDNode *UniquedNode = uniquify();

886

887 if (UniquedNode == this) {

888 makeUniqued();

889 return this;

890 }

891

892

894 deleteAsSubclass();

895 return UniquedNode;

896}

897

898MDNode *MDNode::replaceWithDistinctImpl() {

899 makeDistinct();

900 return this;

901}

902

903void MDTuple::recalculateHash() {

904 setHash(MDTupleInfo::KeyTy::calculateHash(this));

905}

906

910 if (Context.hasReplaceableUses()) {

911 Context.getReplaceableUses()->resolveAllUses( false);

912 (void)Context.takeReplaceableUses();

913 }

914}

915

916void MDNode::handleChangedOperand(void *Ref, Metadata *New) {

919

921

923 return;

924 }

925

926

927 eraseFromStore();

928

931

932

933 if (New == this || (!New && Old && isa(Old))) {

937 return;

938 }

939

940

941 auto *Uniqued = uniquify();

944 resolveAfterOperandChange(Old, New);

945 return;

946 }

947

948

950

951

952

953

956 if (Context.hasReplaceableUses())

957 Context.getReplaceableUses()->replaceAllUsesWith(Uniqued);

958 deleteAsSubclass();

959 return;

960 }

961

962

964}

965

966void MDNode::deleteAsSubclass() {

968 default:

970#define HANDLE_MDNODE_LEAF(CLASS) \

971 case CLASS##Kind: \

972 delete cast(this); \

973 break;

974#include "llvm/IR/Metadata.def"

975 }

976}

977

978template <class T, class InfoT>

981 return U;

982

983 Store.insert(N);

984 return N;

985}

986

987template struct MDNode::HasCachedHash {

989 using No = char[2];

990 template <class U, U Val> struct SFINAE {};

991

992 template

993 static Yes &check(SFINAE<void (U::*)(unsigned), &U::setHash> *);

994 template static No &check(...);

995

996 static const bool value = sizeof(check(nullptr)) == sizeof(Yes);

997};

998

999MDNode *MDNode::uniquify() {

1001

1002

1004 default:

1005 llvm_unreachable("Invalid or non-uniquable subclass of MDNode");

1006#define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS) \

1007 case CLASS##Kind: { \

1008 CLASS *SubclassThis = cast(this); \

1009 std::integral_constant<bool, HasCachedHash::value> \

1010 ShouldRecalculateHash; \

1011 dispatchRecalculateHash(SubclassThis, ShouldRecalculateHash); \

1012 return uniquifyImpl(SubclassThis, getContext().pImpl->CLASS##s); \

1013 }

1014#include "llvm/IR/Metadata.def"

1015 }

1016}

1017

1018void MDNode::eraseFromStore() {

1020 default:

1021 llvm_unreachable("Invalid or non-uniquable subclass of MDNode");

1022#define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS) \

1023 case CLASS##Kind: \

1024 getContext().pImpl->CLASS##s.erase(cast(this)); \

1025 break;

1026#include "llvm/IR/Metadata.def"

1027 }

1028}

1029

1031 StorageType Storage, bool ShouldCreate) {

1032 unsigned Hash = 0;

1034 MDTupleInfo::KeyTy Key(MDs);

1036 return N;

1037 if (!ShouldCreate)

1038 return nullptr;

1039 Hash = Key.getHash();

1040 } else {

1041 assert(ShouldCreate && "Expected non-uniqued nodes to always be created");

1042 }

1043

1047}

1048

1050 assert(N->isTemporary() && "Expected temporary node");

1051 N->replaceAllUsesWith(nullptr);

1052 N->deleteAsSubclass();

1053}

1054

1056 assert(!Context.hasReplaceableUses() && "Unexpected replaceable uses");

1060

1061

1063 default:

1065#define HANDLE_MDNODE_LEAF(CLASS) \

1066 case CLASS##Kind: { \

1067 std::integral_constant<bool, HasCachedHash::value> ShouldResetHash; \

1068 dispatchResetHash(cast(this), ShouldResetHash); \

1069 break; \

1070 }

1071#include "llvm/IR/Metadata.def"

1072 }

1073

1075}

1076

1079 return;

1080

1083 return;

1084 }

1085

1087}

1088

1092}

1093

1094

1095

1096

1097

1098

1099

1102 if (!Ops.empty())

1103 if (MDNode *N = dyn_cast_or_null(Ops[0]))

1104 if (N->getNumOperands() == Ops.size() && N == N->getOperand(0)) {

1105 for (unsigned I = 1, E = Ops.size(); I != E; ++I)

1106 if (Ops[I] != N->getOperand(I))

1108 return N;

1109 }

1110

1112}

1113

1115 if (A)

1116 return B;

1117 if (B)

1118 return A;

1119

1121 MDs.insert(B->op_begin(), B->op_end());

1122

1123

1124

1126}

1127

1129 if (A || B)

1130 return nullptr;

1131

1135

1136

1137

1139}

1140

1142 if (A || B)

1143 return nullptr;

1144

1145

1146

1150 for (const MDOperand &MDOp : A->operands())

1151 if (const MDNode *NAMD = dyn_cast(MDOp))

1154

1155 for (const MDOperand &MDOp : B->operands())

1156 if (const MDNode *NAMD = dyn_cast(MDOp))

1161 }

1162

1163 for (const MDOperand &MDOp : A->operands())

1164 if (const MDNode *NAMD = dyn_cast(MDOp))

1168

1169 return MDs.empty() ? nullptr

1171}

1172

1174 if (A || B)

1175 return nullptr;

1176

1177 APFloat AVal = mdconst::extract(A->getOperand(0))->getValueAPF();

1178 APFloat BVal = mdconst::extract(B->getOperand(0))->getValueAPF();

1179 if (AVal < BVal)

1180 return A;

1181 return B;

1182}

1183

1184

1185

1186

1190 assert(A && B && AInstr && BInstr && "Caller should guarantee");

1193

1194

1195 assert(A->getNumOperands() >= 2 && B->getNumOperands() >= 2 &&

1196 "!prof annotations should have no less than 2 operands");

1197 MDString *AMDS = dyn_cast(A->getOperand(0));

1198 MDString *BMDS = dyn_cast(B->getOperand(0));

1199

1200 assert(AMDS != nullptr && BMDS != nullptr &&

1201 "first operand should be a non-null MDString");

1204 if (AProfName == "branch_weights" && BProfName == "branch_weights") {

1205 ConstantInt *AInstrWeight = mdconst::dyn_extract(

1207 ConstantInt *BInstrWeight = mdconst::dyn_extract(

1209 assert(AInstrWeight && BInstrWeight && "verified by LLVM verifier");

1211 {MDHelper.createString("branch_weights"),

1212 MDHelper.createConstant(ConstantInt::get(

1216 }

1217 return nullptr;

1218}

1219

1220

1221

1225 if (!(A && B)) {

1226 return A ? A : B;

1227 }

1228

1230 "Caller should guarantee");

1232 "Caller should guarantee");

1233

1234 const CallInst *ACall = dyn_cast(AInstr);

1235 const CallInst *BCall = dyn_cast(BInstr);

1236

1237

1240 return mergeDirectCallProfMetadata(A, B, AInstr, BInstr);

1241

1242

1243

1244 return nullptr;

1245}

1246

1248 return A.getUpper() == B.getLower() || A.getLower() == B.getUpper();

1249}

1250

1252 return A.intersectWith(B).isEmptySet() || isContiguous(A, B);

1253}

1254

1258 unsigned Size = EndPoints.size();

1259 const APInt &LB = EndPoints[Size - 2]->getValue();

1260 const APInt &LE = EndPoints[Size - 1]->getValue();

1265 EndPoints[Size - 2] =

1266 cast(ConstantInt::get(Ty, Union.getLower()));

1267 EndPoints[Size - 1] =

1268 cast(ConstantInt::get(Ty, Union.getUpper()));

1269 return true;

1270 }

1271 return false;

1272}

1273

1276 if (!EndPoints.empty())

1278 return;

1279

1282}

1283

1285

1286

1287

1288

1289 if (A || B)

1290 return nullptr;

1291

1292 if (A == B)

1293 return A;

1294

1295

1296

1298 unsigned AI = 0;

1299 unsigned BI = 0;

1300 unsigned AN = A->getNumOperands() / 2;

1301 unsigned BN = B->getNumOperands() / 2;

1302 while (AI < AN && BI < BN) {

1303 ConstantInt *ALow = mdconst::extract(A->getOperand(2 * AI));

1304 ConstantInt *BLow = mdconst::extract(B->getOperand(2 * BI));

1305

1308 mdconst::extract(A->getOperand(2 * AI + 1)));

1309 ++AI;

1310 } else {

1312 mdconst::extract(B->getOperand(2 * BI + 1)));

1313 ++BI;

1314 }

1315 }

1316 while (AI < AN) {

1317 addRange(EndPoints, mdconst::extract(A->getOperand(2 * AI)),

1318 mdconst::extract(A->getOperand(2 * AI + 1)));

1319 ++AI;

1320 }

1321 while (BI < BN) {

1322 addRange(EndPoints, mdconst::extract(B->getOperand(2 * BI)),

1323 mdconst::extract(B->getOperand(2 * BI + 1)));

1324 ++BI;

1325 }

1326

1327

1328

1329

1330 unsigned Size = EndPoints.size();

1331 if (Size > 2) {

1335 for (unsigned i = 0; i < Size - 2; ++i) {

1336 EndPoints[i] = EndPoints[i + 2];

1337 }

1339 }

1340 }

1341

1342

1343

1344 if (EndPoints.size() == 2) {

1345 ConstantRange Range(EndPoints[0]->getValue(), EndPoints[1]->getValue());

1347 return nullptr;

1348 }

1349

1352 for (auto *I : EndPoints)

1355}

1356

1358 if (A || B)

1359 return nullptr;

1360

1361 if (A == B)

1362 return A;

1363

1365 for (unsigned I = 0, E = A->getNumOperands() / 2; I != E; ++I) {

1366 auto *LowA = mdconst::extract(A->getOperand(2 * I + 0));

1367 auto *HighA = mdconst::extract(A->getOperand(2 * I + 1));

1369 }

1370

1371 for (unsigned I = 0, E = B->getNumOperands() / 2; I != E; ++I) {

1372 auto *LowB = mdconst::extract(B->getOperand(2 * I + 0));

1373 auto *HighB = mdconst::extract(B->getOperand(2 * I + 1));

1375 }

1376

1380 if (Result.empty())

1381 return nullptr;

1382

1386 ConstantInt::get(A->getContext(), CR.getLower())));

1388 ConstantInt::get(A->getContext(), CR.getUpper())));

1389 }

1390

1392}

1393

1395 if (A || B)

1396 return nullptr;

1397

1398 ConstantInt *AVal = mdconst::extract(A->getOperand(0));

1399 ConstantInt *BVal = mdconst::extract(B->getOperand(0));

1401 return A;

1402 return B;

1403}

1404

1405

1406

1407

1408

1411}

1412

1413NamedMDNode::NamedMDNode(const Twine &N)

1415

1419}

1420

1422 return (unsigned)getNMDOps(Operands).size();

1423}

1424

1427 auto *N = getNMDOps(Operands)[i].get();

1428 return cast_or_null(N);

1429}

1430

1432

1436}

1437

1439

1441

1443

1444

1445

1446

1447

1449 for (const auto &A : Attachments)

1450 if (A.MDKind == ID)

1451 return A.Node;

1452 return nullptr;

1453}

1454

1456 for (const auto &A : Attachments)

1457 if (A.MDKind == ID)

1458 Result.push_back(A.Node);

1459}

1460

1462 SmallVectorImpl<std::pair<unsigned, MDNode *>> &Result) const {

1463 for (const auto &A : Attachments)

1464 Result.emplace_back(A.MDKind, A.Node);

1465

1466

1467

1468 if (Result.size() > 1)

1470}

1471

1474 if (MD)

1476}

1477

1480}

1481

1484 return false;

1485

1486

1487 if (Attachments.size() == 1 && Attachments.back().MDKind == ID) {

1488 Attachments.pop_back();

1489 return true;

1490 }

1491

1492 auto OldSize = Attachments.size();

1495 return OldSize != Attachments.size();

1496}

1497

1500 return nullptr;

1503}

1504

1508 return Attachements.lookup(KindID);

1509}

1510

1514}

1515

1519}

1520

1522 SmallVectorImpl<std::pair<unsigned, MDNode *>> &MDs) const {

1525 "bit out of sync with hash table");

1527 Info.getAll(MDs);

1528 }

1529}

1530

1532 assert(isa(this) || isa(this));

1533

1534

1535 if (Node) {

1538 if (Info.empty())

1540 Info.set(KindID, Node);

1541 return;

1542 }

1543

1544

1546 "bit out of sync with hash table");

1548 return;

1550

1551

1552 Info.erase(KindID);

1553 if (Info.empty())

1554 return;

1557}

1558

1561 return;

1563}

1564

1566 assert(isa(this) || isa(this));

1570}

1571

1574}

1575

1577

1579 return false;

1580

1582 bool Changed = Store.erase(KindID);

1583 if (Store.empty())

1585 return Changed;

1586}

1587

1590 return;

1591

1594 assert(Info.empty() && "bit out of sync with hash table");

1596 return Pred(I.MDKind, I.Node);

1597 });

1598

1599 if (Info.empty())

1601}

1602

1605 return;

1607 "bit out of sync with hash table");

1610}

1611

1614 return;

1616}

1617

1618MDNode *Instruction::getMetadataImpl(StringRef Kind) const {

1620 unsigned KindID = Ctx.getMDKindID(Kind);

1621 if (KindID == LLVMContext::MD_dbg)

1624}

1625

1627 if (DbgLoc && Pred(LLVMContext::MD_dbg, DbgLoc.getAsMDNode()))

1628 DbgLoc = {};

1629

1631}

1632

1635 return;

1636

1639

1640

1641 KnownSet.insert(LLVMContext::MD_DIAssignID);

1642

1644 return !KnownSet.count(MDKind);

1645 });

1646}

1647

1648void Instruction::updateDIAssignIDMapping(DIAssignID *ID) {

1651 cast_or_null(getMetadata(LLVMContext::MD_DIAssignID))) {

1652

1653 if (ID == CurrentID)

1654 return;

1655

1656

1657 auto InstrsIt = IDToInstrs.find(CurrentID);

1658 assert(InstrsIt != IDToInstrs.end() &&

1659 "Expect existing attachment to be mapped");

1660

1661 auto &InstVec = InstrsIt->second;

1662 auto *InstIt = llvm::find(InstVec, this);

1663 assert(InstIt != InstVec.end() &&

1664 "Expect instruction to be mapped to attachment");

1665

1666

1667

1668 if (InstVec.size() == 1)

1669 IDToInstrs.erase(InstrsIt);

1670 else

1671 InstVec.erase(InstIt);

1672 }

1673

1674

1675 if (ID)

1676 IDToInstrs[ID].push_back(this);

1677}

1678

1681 return;

1682

1683

1684 if (KindID == LLVMContext::MD_dbg) {

1686 return;

1687 }

1688

1689

1690 if (KindID == LLVMContext::MD_DIAssignID) {

1691

1692

1693

1694 assert((!Node || !Node->isTemporary()) &&

1695 "Temporary DIAssignIDs are invalid");

1696 updateDIAssignIDMapping(cast_or_null(Node));

1697 }

1698

1700}

1701

1704 if (auto *Existing = getMetadata(LLVMContext::MD_annotation)) {

1707 auto *Tuple = cast(Existing);

1708 for (auto &N : Tuple->operands()) {

1709 if (isa(N.get())) {

1711 continue;

1712 }

1713 auto *MDAnnotationTuple = cast(N);

1714 if (any_of(MDAnnotationTuple->operands(), [&AnnotationsSet](auto &Op) {

1715 return AnnotationsSet.contains(cast(Op)->getString());

1716 }))

1717 return;

1719 }

1720 }

1721

1729 setMetadata(LLVMContext::MD_annotation, MD);

1730}

1731

1734 if (auto *Existing = getMetadata(LLVMContext::MD_annotation)) {

1735 auto *Tuple = cast(Existing);

1736 for (auto &N : Tuple->operands()) {

1737 if (isa(N.get()) &&

1738 cast(N.get())->getString() == Name)

1739 return;

1741 }

1742 }

1743

1747 setMetadata(LLVMContext::MD_annotation, MD);

1748}

1749

1752

1753

1756 Result.TBAA = Info.lookup(LLVMContext::MD_tbaa);

1757 Result.TBAAStruct = Info.lookup(LLVMContext::MD_tbaa_struct);

1758 Result.Scope = Info.lookup(LLVMContext::MD_alias_scope);

1759 Result.NoAlias = Info.lookup(LLVMContext::MD_noalias);

1760 }

1761 return Result;

1762}

1763

1766 setMetadata(LLVMContext::MD_tbaa_struct, N.TBAAStruct);

1767 setMetadata(LLVMContext::MD_alias_scope, N.Scope);

1768 setMetadata(LLVMContext::MD_noalias, N.NoAlias);

1769}

1770

1772 setMetadata(llvm::LLVMContext::MD_nosanitize,

1774}

1775

1776void Instruction::getAllMetadataImpl(

1777 SmallVectorImpl<std::pair<unsigned, MDNode *>> &Result) const {

1778 Result.clear();

1779

1780

1781 if (DbgLoc) {

1782 Result.push_back(

1783 std::make_pair((unsigned)LLVMContext::MD_dbg, DbgLoc.getAsMDNode()));

1784 }

1786}

1787

1790 (getOpcode() == Instruction::Br || getOpcode() == Instruction::Select ||

1791 getOpcode() == Instruction::Call || getOpcode() == Instruction::Invoke ||

1792 getOpcode() == Instruction::IndirectBr ||

1793 getOpcode() == Instruction::Switch) &&

1794 "Looking for branch weights on something besides branch");

1795

1796 return ::extractProfTotalWeight(*this, TotalVal);

1797}

1798

1801 Other->getAllMetadata(MDs);

1802 for (auto &MD : MDs) {

1803

1804 if (Offset != 0 && MD.first == LLVMContext::MD_type) {

1805 auto *OffsetConst = cast(

1806 cast(MD.second->getOperand(0))->getValue());

1807 Metadata *TypeId = MD.second->getOperand(1);

1809 OffsetConst->getType(), OffsetConst->getValue() + Offset));

1812 continue;

1813 }

1814

1815

1816

1817 auto *Attachment = MD.second;

1818 if (Offset != 0 && MD.first == LLVMContext::MD_dbg) {

1819 DIGlobalVariable *GV = dyn_cast(Attachment);

1821 if (!GV) {

1822 auto *GVE = cast(Attachment);

1823 GV = GVE->getVariable();

1824 E = GVE->getExpression();

1825 }

1827 if (E)

1829 std::vector<uint64_t> Elements(OrigElements.size() + 2);

1830 Elements[0] = dwarf::DW_OP_plus_uconst;

1831 Elements[1] = Offset;

1832 llvm::copy(OrigElements, Elements.begin() + 2);

1835 }

1837 }

1838}

1839

1842 LLVMContext::MD_type,

1847}

1848

1850

1851

1852 eraseMetadata(LLVMContext::MD_vcall_visibility);

1853 addMetadata(LLVMContext::MD_vcall_visibility,

1857}

1858

1860 if (MDNode *MD = getMetadata(LLVMContext::MD_vcall_visibility)) {

1861 uint64_t Val = cast(

1862 cast(MD->getOperand(0))->getValue())

1863 ->getZExtValue();

1864 assert(Val <= 2 && "unknown vcall visibility!");

1866 }

1868}

1869

1872}

1873

1875 return cast_or_null(getMetadata(LLVMContext::MD_dbg));

1876}

1877

1881 return CU->getDebugInfoForProfiling();

1882 }

1883 }

1884 return false;

1885}

1886

1889}

1890

1895 for (MDNode *MD : MDs)

1896 GVs.push_back(cast(MD));

1897}

This file defines the StringMap class.

This file declares a class to represent arbitrary precision floating point values and provide a varie...

This file implements a class to represent arbitrary precision integral constant values and operations...

static const Function * getParent(const Value *V)

BlockVerifier::State From

static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")

static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")

Analysis containing CSE Info

This file contains the declarations for the subclasses of Constant, which represent the different fla...

Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx

Given that RA is a live value

This file defines the DenseSet and SmallDenseSet classes.

static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")

Module.h This file contains the declarations for the Module class.

mir Rename Register Operands

ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))

This file contains the declarations for profiling metadata utility functions.

Remove Loads Into Fake Uses

assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())

This file implements a set that has insertion order iteration characteristics.

This file defines the SmallPtrSet class.

This file defines the SmallSet class.

This file defines the SmallVector class.

Class for arbitrary precision integers.

bool slt(const APInt &RHS) const

Signed less than comparison.

This is a simple wrapper around an MDNode which provides a higher-level interface by hiding the detai...

Annotations lets you mark points and ranges inside source code, for tests:

ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...

size_t size() const

size - Get the array size.

bool empty() const

empty - Check if the array is empty.

LLVM Basic Block Representation.

Function * getCalledFunction() const

Returns the function called, or null if this is an indirect function invocation or the function signa...

This class represents a function call, abstracting a target machine's calling convention.

This is the shared class of boolean and integer constants.

uint64_t getZExtValue() const

Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...

const APInt & getValue() const

Return the constant as an APInt value reference.

This class represents a list of constant ranges.

ConstantRangeList intersectWith(const ConstantRangeList &CRL) const

Return the range list that results from the intersection of this ConstantRangeList with another Const...

This class represents a range of values.

bool isFullSet() const

Return true if this set contains all of the elements possible for this data-type.

ConstantRange unionWith(const ConstantRange &CR, PreferredRangeType Type=Smallest) const

Return the range that results from the union of this range with another range.

This is an important base class in LLVM.

ArrayRef< uint64_t > getElements() const

A pair of DIGlobalVariable and DIExpression.

This class represents an Operation in the Expression.

Record of a variable value-assignment, aka a non instruction representation of the dbg....

MDNode * getAsMDNode() const

Return this as a bar MDNode.

Base class for tracking ValueAsMetadata/DIArgLists with user lookups and Owner callbacks outside of V...

void handleChangedValue(void *Old, Metadata *NewDebugValue)

To be called by ReplaceableMetadataImpl::replaceAllUsesWith, where Old is a pointer to one of the poi...

std::array< Metadata *, 3 > DebugValues

void resetDebugValue(size_t Idx, Metadata *DebugValue)

DbgVariableRecord * getUser()

Implements a dense probed hash-table based set.

void setSubprogram(DISubprogram *SP)

Set the attached subprogram.

DISubprogram * getSubprogram() const

Get the attached subprogram.

bool shouldEmitDebugInfoForProfiling() const

Returns true if we should emit debug info for profiling.

void addTypeMetadata(unsigned Offset, Metadata *TypeID)

void setMetadata(unsigned KindID, MDNode *Node)

Set a particular kind of metadata attachment.

void copyMetadata(const GlobalObject *Src, unsigned Offset)

Copy metadata from Src, adjusting offsets by Offset.

VCallVisibility getVCallVisibility() const

bool eraseMetadata(unsigned KindID)

Erase all metadata attachments with the given kind.

void addMetadata(unsigned KindID, MDNode &MD)

Add a metadata attachment.

MDNode * getMetadata(unsigned KindID) const

Get the current metadata attachments for the given kind, if any.

void setVCallVisibilityMetadata(VCallVisibility Visibility)

void getDebugInfo(SmallVectorImpl< DIGlobalVariableExpression * > &GVs) const

Fill the vector with all debug info attachements.

void addDebugInfo(DIGlobalVariableExpression *GV)

Attach a DIGlobalVariableExpression.

void setAAMetadata(const AAMDNodes &N)

Sets the AA metadata on this instruction from the AAMDNodes structure.

bool extractProfTotalWeight(uint64_t &TotalVal) const

Retrieve total raw weight values of a branch.

bool hasMetadata() const

Return true if this instruction has any metadata attached to it.

void addAnnotationMetadata(StringRef Annotation)

Adds an !annotation metadata node with Annotation to this instruction.

MDNode * getMetadata(unsigned KindID) const

Get the metadata of given kind attached to this Instruction.

void setMetadata(unsigned KindID, MDNode *Node)

Set the metadata of the specified kind to the specified node.

void setNoSanitizeMetadata()

Sets the nosanitize metadata on this instruction.

void dropUnknownNonDebugMetadata(ArrayRef< unsigned > KnownIDs={})

Drop all unknown metadata except for debug locations.

AAMDNodes getAAMetadata() const

Returns the AA metadata for this instruction.

unsigned getOpcode() const

Returns a member of one of the enums like Instruction::Add.

void eraseMetadataIf(function_ref< bool(unsigned, MDNode *)> Pred)

Erase all metadata that matches the predicate.

DenseMap< Metadata *, MetadataAsValue * > MetadataAsValues

StringMap< MDString, BumpPtrAllocator > MDStringCache

DenseMap< DIAssignID *, SmallVector< Instruction *, 1 > > AssignmentIDToInstrs

Map DIAssignID -> Instructions with that attachment.

std::vector< MDNode * > DistinctMDNodes

DenseMap< const Value *, MDAttachments > ValueMetadata

Collection of metadata used in this context.

DenseMap< Value *, ValueAsMetadata * > ValuesAsMetadata

This is an important class for using LLVM in a threaded context.

unsigned getMDKindID(StringRef Name) const

getMDKindID - Return a unique non-zero ID for the specified metadata kind.

LLVMContextImpl *const pImpl

Multimap-like storage for metadata attachments.

void insert(unsigned ID, MDNode &MD)

Adds an attachment to a particular node.

void get(unsigned ID, SmallVectorImpl< MDNode * > &Result) const

Appends all attachments with the given ID to Result in insertion order.

void getAll(SmallVectorImpl< std::pair< unsigned, MDNode * > > &Result) const

Appends all attachments for the global to Result, sorting by attachment ID.

void set(unsigned ID, MDNode *MD)

Set an attachment to a particular node.

MDNode * lookup(unsigned ID) const

Returns the first attachment with the given ID or nullptr if no such attachment exists.

bool erase(unsigned ID)

Remove attachments with the given ID.

MDString * createString(StringRef Str)

Return the given string as metadata.

static MDNode * getMostGenericAliasScope(MDNode *A, MDNode *B)

void replaceOperandWith(unsigned I, Metadata *New)

Replace a specific operand.

void resolveCycles()

Resolve cycles.

mutable_op_range mutable_operands()

void replaceAllUsesWith(Metadata *MD)

RAUW a temporary.

static MDNode * concatenate(MDNode *A, MDNode *B)

Methods for metadata merging.

static void deleteTemporary(MDNode *N)

Deallocate a node created by getTemporary.

void resolve()

Resolve a unique, unresolved node.

const MDOperand & getOperand(unsigned I) const

static MDNode * getMostGenericNoaliasAddrspace(MDNode *A, MDNode *B)

void storeDistinctInContext()

ArrayRef< MDOperand > operands() const

static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)

static MDNode * getMergedProfMetadata(MDNode *A, MDNode *B, const Instruction *AInstr, const Instruction *BInstr)

Merge !prof metadata from two instructions.

static MDNode * getMostGenericFPMath(MDNode *A, MDNode *B)

void setNumUnresolved(unsigned N)

unsigned getNumOperands() const

Return number of MDNode operands.

MDOperand * mutable_begin()

MDNode(LLVMContext &Context, unsigned ID, StorageType Storage, ArrayRef< Metadata * > Ops1, ArrayRef< Metadata * > Ops2={})

TempMDNode clone() const

Create a (temporary) clone of this.

static MDNode * getMostGenericRange(MDNode *A, MDNode *B)

void setOperand(unsigned I, Metadata *New)

Set an operand.

bool isResolved() const

Check if node is fully resolved.

op_iterator op_begin() const

static MDNode * intersect(MDNode *A, MDNode *B)

static T * storeImpl(T *N, StorageType Storage, StoreT &Store)

LLVMContext & getContext() const

static MDNode * getMostGenericAlignmentOrDereferenceable(MDNode *A, MDNode *B)

unsigned getNumUnresolved() const

Tracking metadata reference owned by Metadata.

StringRef getString() const

static MDString * get(LLVMContext &Context, StringRef Str)

static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)

void eraseNamedMetadata(NamedMDNode *NMD)

Remove the given NamedMDNode from this module and delete it.

MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...

void setOperand(unsigned I, MDNode *New)

StringRef getName() const

void dropAllReferences()

Remove all uses and clear node vector.

void eraseFromParent()

Drop all references and remove the node from parent module.

MDNode * getOperand(unsigned i) const

unsigned getNumOperands() const

void clearOperands()

Drop all references to this node's operands.

Module * getParent()

Get the module that holds this named metadata collection.

void addOperand(MDNode *M)

A discriminated union of two or more pointer types, with the discriminator in the low bit of the poin...

bool isNull() const

Test if the pointer held in the union is null, regardless of which type it is.

static PoisonValue * get(Type *T)

Static factory methods - Return an 'poison' object of the specified type.

ArrayRef< value_type > getArrayRef() const

bool remove_if(UnaryPredicate P)

Remove items from the set vector based on a predicate function.

bool empty() const

Determine if the SetVector is empty or not.

bool insert(const value_type &X)

Insert a new element into the SetVector.

size_type count(ConstPtrType Ptr) const

count - Return 1 if the specified pointer is in the set, 0 otherwise.

std::pair< iterator, bool > insert(PtrType Ptr)

Inserts Ptr if and only if there is no element in the container equal to Ptr.

bool contains(ConstPtrType Ptr) const

SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.

A SetVector that performs no allocations if smaller than a certain size.

SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...

size_type count(const T &V) const

count - Return 1 if the element is in the set, 0 otherwise.

std::pair< const_iterator, bool > insert(const T &V)

insert - Insert an element into the set if it isn't already there.

This class consists of common code factored out of the SmallVector class to reduce code duplication b...

void reserve(size_type N)

void push_back(const T &Elt)

This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.

StringRef - Represent a constant reference to a string, i.e.

Tracking metadata reference.

Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...

The instances of the Type class are immutable: once they are created, they are never changed.

static Type * getMetadataTy(LLVMContext &C)

TypeID

Definitions of all of the base types for the Type system.

LLVMContext & getContext() const

Return the LLVMContext in which this type was uniqued.

static IntegerType * getInt64Ty(LLVMContext &C)

static UndefValue * get(Type *T)

Static factory methods - Return an 'undef' object of the specified type.

LLVM Value Representation.

Type * getType() const

All values are typed, get the type of this value.

bool hasMetadata() const

Return true if this value has any metadata attached to it.

void setMetadata(unsigned KindID, MDNode *Node)

Set a particular kind of metadata attachment.

void replaceAllUsesWith(Value *V)

Change all uses of this to point to a new Value.

void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode * > > &MDs) const

Appends all metadata attached to this value to MDs, sorting by KindID.

MDNode * getMetadataImpl(unsigned KindID) const

Get metadata for the given kind, if any.

bool eraseMetadata(unsigned KindID)

Erase all metadata attachments with the given kind.

void addMetadata(unsigned KindID, MDNode &MD)

Add a metadata attachment.

void eraseMetadataIf(function_ref< bool(unsigned, MDNode *)> Pred)

Erase all metadata attachments matching the given predicate.

LLVMContext & getContext() const

All values hold a context through their type.

void clearMetadata()

Erase all metadata attached to this Value.

MDNode * getMetadata(unsigned KindID) const

Get the current metadata attachments for the given kind, if any.

An efficient, type-erasing, non-owning reference to a callable.

#define llvm_unreachable(msg)

Marks that the current location is not supposed to be reachable.

@ C

The default llvm calling convention, compatible with C.

unsigned ID

LLVM IR allows to use arbitrary numbers as calling convention identifiers.

const_iterator end(StringRef path LLVM_LIFETIME_BOUND)

Get end iterator over path.

This is an optimization pass for GlobalISel generic memory operations.

@ Low

Lower the current thread's priority such that it does not affect foreground tasks significantly.

detail::zippy< detail::zip_shortest, T, U, Args... > zip(T &&t, U &&u, Args &&...args)

zip iterator for two or more iteratable types.

void stable_sort(R &&Range)

auto find(R &&Range, const T &Val)

Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.

auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)

Get the size of a range.

unsigned getBranchWeightOffset(const MDNode *ProfileData)

Return the offset to the first branch weight data.

static T * getUniqued(DenseSet< T *, InfoT > &Store, const typename InfoT::KeyTy &Key)

TypedTrackingMDRef< MDNode > TrackingMDNodeRef

bool any_of(R &&range, UnaryPredicate P)

Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.

void sort(IteratorTy Start, IteratorTy End)

@ Ref

The access may reference the value stored in memory.

uint64_t alignTo(uint64_t Size, Align A)

Returns a multiple of A needed to store Size bytes.

OutputIt copy(R &&Range, OutputIt Out)

OutputIt move(R &&Range, OutputIt Out)

Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.

auto count_if(R &&Range, UnaryPredicate P)

Wrapper function around std::count_if to count the number of times an element satisfying a given pred...

void erase_if(Container &C, UnaryPredicate P)

Provide a container algorithm similar to C++ Library Fundamentals v2's erase_if which is equivalent t...

bool is_contained(R &&Range, const E &Element)

Returns true if Element is found in Range.

std::enable_if_t< std::is_unsigned_v< T >, T > SaturatingAdd(T X, T Y, bool *ResultOverflowed=nullptr)

Add two unsigned integers, X and Y, of type T.

static Yes & check(SFINAE< void(U::*)(unsigned), &U::setHash > *)

A collection of metadata nodes that might be associated with a memory access used by the alias-analys...

Function object to check whether the first component of a container supported by std::get (like std::...