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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

31#include "llvm/Config/llvm-config.h"

77#include

78#include

79#include

80#include

81#include

82#include

83#include

84#include

85#include

86#include

87#include

88

89using namespace llvm;

90

91

93

94

95

96

97

99

102

103

104

106 if (const auto *MAV = dyn_cast(V))

107 if (const auto *VAM = dyn_cast(MAV->getMetadata()))

108 return VAM->getValue();

109 return V;

110}

111

113 if (OM.lookup(V))

114 return;

115

116 if (const Constant *C = dyn_cast(V))

117 if (C->getNumOperands() && !isa(C))

118 for (const Value *Op : C->operands())

119 if (!isa(Op) && !isa(Op))

121

122

123

124 unsigned ID = OM.size() + 1;

125 OM[V] = ID;

126}

127

130

132 if (G.hasInitializer())

133 if (!isa(G.getInitializer()))

136 }

138 if (!isa(A.getAliasee()))

141 }

143 if (!isa(I.getResolver()))

146 }

148 for (const Use &U : F.operands())

149 if (!isa(U.get()))

151

153

154 if (F.isDeclaration())

155 continue;

156

162 for (const Value *Op : I.operands()) {

164 if ((isa(*Op) && !isa(*Op)) ||

165 isa(*Op))

167 }

169 }

170 }

171 }

172 return OM;

173}

174

175static std::vector

177

178 using Entry = std::pair<const Use *, unsigned>;

180 for (const Use &U : V->uses())

181

182 if (OM.lookup(U.getUser()))

183 List.push_back(std::make_pair(&U, List.size()));

184

185 if (List.size() < 2)

186

187 return {};

188

189

190

191

192 bool GetsReversed = !isa(V);

193 if (auto *BA = dyn_cast(V))

194 ID = OM.lookup(BA->getBasicBlock());

195 llvm::sort(List, [&](const Entry &L, const Entry &R) {

196 const Use *LU = L.first;

197 const Use *RU = R.first;

198 if (LU == RU)

199 return false;

200

201 auto LID = OM.lookup(LU->getUser());

202 auto RID = OM.lookup(RU->getUser());

203

204

205 if (LID < RID) {

206 if (GetsReversed)

207 if (RID <= ID)

208 return true;

209 return false;

210 }

211 if (RID < LID) {

212 if (GetsReversed)

213 if (LID <= ID)

214 return false;

215 return true;

216 }

217

218

219

220 if (GetsReversed)

221 if (LID <= ID)

222 return LU->getOperandNo() < RU->getOperandNo();

223 return LU->getOperandNo() > RU->getOperandNo();

224 });

225

227

228 return {};

229

230

231 std::vector Shuffle(List.size());

232 for (size_t I = 0, E = List.size(); I != E; ++I)

233 Shuffle[I] = List[I].second;

234 return Shuffle;

235}

236

240 for (const auto &Pair : OM) {

241 const Value *V = Pair.first;

242 if (V->use_empty() || std::next(V->use_begin()) == V->use_end())

243 continue;

244

245 std::vector Shuffle =

247 if (Shuffle.empty())

248 continue;

249

251 if (auto *I = dyn_cast(V))

252 F = I->getFunction();

253 if (auto *A = dyn_cast(V))

254 F = A->getParent();

255 if (auto *BB = dyn_cast(V))

256 F = BB->getParent();

257 ULOM[F][V] = std::move(Shuffle);

258 }

259 return ULOM;

260}

261

263 if (const Argument *MA = dyn_cast(V))

264 return MA->getParent() ? MA->getParent()->getParent() : nullptr;

265

266 if (const BasicBlock *BB = dyn_cast(V))

267 return BB->getParent() ? BB->getParent()->getParent() : nullptr;

268

269 if (const Instruction *I = dyn_cast(V)) {

270 const Function *M = I->getParent() ? I->getParent()->getParent() : nullptr;

271 return M ? M->getParent() : nullptr;

272 }

273

274 if (const GlobalValue *GV = dyn_cast(V))

275 return GV->getParent();

276

277 if (const auto *MAV = dyn_cast(V)) {

278 for (const User *U : MAV->users())

279 if (isa(U))

281 return M;

282 return nullptr;

283 }

284

285 return nullptr;

286}

287

291 return M ? M->getParent() : nullptr;

292}

293

296}

297

299 switch (cc) {

300 default: Out << "cc" << cc; break;

323 Out << "aarch64_sve_vector_pcs";

324 break;

326 Out << "aarch64_sme_preservemost_from_x0";

327 break;

329 Out << "aarch64_sme_preservemost_from_x1";

330 break;

332 Out << "aarch64_sme_preservemost_from_x2";

333 break;

347 Out << "hhvmcc";

348 break;

350 Out << "hhvm_ccc";

351 break;

360 Out << "amdgpu_cs_chain";

361 break;

363 Out << "amdgpu_cs_chain_preserve";

364 break;

369 Out << "riscv_vector_cc";

370 break;

371 }

372}

373

381

383 assert(Name.empty() && "Cannot get empty name!");

384

385

386 bool NeedsQuotes = isdigit(static_cast<unsigned char>(Name[0]));

387 if (!NeedsQuotes) {

388 for (unsigned char C : Name) {

389

390

391

392

393 if (!isalnum(static_cast<unsigned char>(C)) && C != '-' && C != '.' &&

394 C != '_') {

395 NeedsQuotes = true;

396 break;

397 }

398 }

399 }

400

401

402 if (!NeedsQuotes) {

404 return;

405 }

406

407

408

409 OS << '"';

410 printEscapedString(Name, OS);

411 OS << '"';

412}

413

414

415

416

418 switch (Prefix) {

420 break;

422 OS << '@';

423 break;

425 OS << '$';

426 break;

428 break;

430 OS << '%';

431 break;

432 }

434}

435

436

437

438

442}

443

445 Out << ", <";

446 if (isa(Ty))

447 Out << "vscale x ";

448 Out << Mask.size() << " x i32> ";

449 bool FirstElt = true;

450 if (all_of(Mask, [](int Elt) { return Elt == 0; })) {

451 Out << "zeroinitializer";

453 Out << "poison";

454 } else {

455 Out << "<";

456 for (int Elt : Mask) {

457 if (FirstElt)

458 FirstElt = false;

459 else

460 Out << ", ";

461 Out << "i32 ";

463 Out << "poison";

464 else

465 Out << Elt;

466 }

467 Out << ">";

468 }

469}

470

471namespace {

472

473class TypePrinting {

474public:

475 TypePrinting(const Module *M = nullptr) : DeferredM(M) {}

476

477 TypePrinting(const TypePrinting &) = delete;

478 TypePrinting &operator=(const TypePrinting &) = delete;

479

480

482

483

484 std::vector<StructType *> &getNumberedTypes();

485

486 bool empty();

487

489

491

492private:

493 void incorporateTypes();

494

495

496 const Module *DeferredM;

497

499

500

502

503 std::vector<StructType *> NumberedTypes;

504};

505

506}

507

508TypeFinder &TypePrinting::getNamedTypes() {

509 incorporateTypes();

510 return NamedTypes;

511}

512

513std::vector<StructType *> &TypePrinting::getNumberedTypes() {

514 incorporateTypes();

515

516

517

518

519 if (NumberedTypes.size() == Type2Number.size())

520 return NumberedTypes;

521

522 NumberedTypes.resize(Type2Number.size());

523 for (const auto &P : Type2Number) {

524 assert(P.second < NumberedTypes.size() && "Didn't get a dense numbering?");

525 assert(!NumberedTypes[P.second] && "Didn't get a unique numbering?");

526 NumberedTypes[P.second] = P.first;

527 }

528 return NumberedTypes;

529}

530

531bool TypePrinting::empty() {

532 incorporateTypes();

533 return NamedTypes.empty() && Type2Number.empty();

534}

535

536void TypePrinting::incorporateTypes() {

537 if (!DeferredM)

538 return;

539

540 NamedTypes.run(*DeferredM, false);

541 DeferredM = nullptr;

542

543

544

545 unsigned NextNumber = 0;

546

547 std::vector<StructType *>::iterator NextToUse = NamedTypes.begin();

549

550 if (STy->isLiteral())

551 continue;

552

553 if (STy->getName().empty())

554 Type2Number[STy] = NextNumber++;

555 else

556 *NextToUse++ = STy;

557 }

558

559 NamedTypes.erase(NextToUse, NamedTypes.end());

560}

561

562

563

576 OS << "metadata";

577 return;

581 OS << 'i' << cast(Ty)->getBitWidth();

582 return;

583

586 print(FTy->getReturnType(), OS);

587 OS << " (";

588 ListSeparator LS;

589 for (Type *Ty : FTy->params()) {

592 }

593 if (FTy->isVarArg())

594 OS << LS << "...";

595 OS << ')';

596 return;

597 }

599 StructType *STy = cast(Ty);

600

602 return printStructBody(STy, OS);

603

606

607 incorporateTypes();

608 const auto I = Type2Number.find(STy);

609 if (I != Type2Number.end())

610 OS << '%' << I->second;

611 else

612 OS << "%\"type " << STy << '\"';

613 return;

614 }

616 PointerType *PTy = cast(Ty);

617 OS << "ptr";

618 if (unsigned AddressSpace = PTy->getAddressSpace())

620 return;

621 }

623 ArrayType *ATy = cast(Ty);

624 OS << '[' << ATy->getNumElements() << " x ";

625 print(ATy->getElementType(), OS);

626 OS << ']';

627 return;

628 }

631 VectorType *PTy = cast(Ty);

633 OS << "<";

634 if (EC.isScalable())

635 OS << "vscale x ";

636 OS << EC.getKnownMinValue() << " x ";

637 print(PTy->getElementType(), OS);

638 OS << '>';

639 return;

640 }

645 return;

646 }

649 OS << "target(\"";

651 OS << "\"";

653 OS << ", ";

654 Inner->print(OS, false, true);

655 }

656 for (unsigned IntParam : TETy->int_params())

657 OS << ", " << IntParam;

658 OS << ")";

659 return;

660 }

662}

663

666 OS << "opaque";

667 return;

668 }

669

671 OS << '<';

672

674 OS << "{}";

675 } else {

676 OS << "{ ";

677 ListSeparator LS;

681 }

682

683 OS << " }";

684 }

686 OS << '>';

687}

688

690

691namespace llvm {

692

693

694

695

696

697

699public:

700

702

703private:

704

705 const Module* TheModule;

706

707

708 const Function* TheFunction = nullptr;

709 bool FunctionProcessed = false;

710 bool ShouldInitializeAllMetadata;

711

713 ProcessModuleHookFn;

715 ProcessFunctionHookFn;

716

717

719

720

722 unsigned mNext = 0;

723

724

726 unsigned fNext = 0;

727

728

730 unsigned mdnNext = 0;

731

732

734 unsigned asNext = 0;

735

736

738 unsigned ModulePathNext = 0;

739

740

742 unsigned GUIDNext = 0;

743

744

746 unsigned TypeIdNext = 0;

747

748

749

751 unsigned TypeIdCompatibleVtableNext = 0;

752

753public:

754

755

756

757

758

760 bool ShouldInitializeAllMetadata = false);

761

762

763

764

765

766

768 bool ShouldInitializeAllMetadata = false);

769

770

772

775

777

782

784

786

787

788

797

798

799

801 TheFunction = F;

802 FunctionProcessed = false;

803 }

804

806

807

808

809

811

812

814

819

820

822

827

828

830

831

834

835

836private:

837

838 void CreateModuleSlot(const GlobalValue *V);

839

840

841 void CreateMetadataSlot(const MDNode *N);

842

843

844 void CreateFunctionSlot(const Value *V);

845

846

847 void CreateAttributeSetSlot(AttributeSet AS);

848

849 inline void CreateModulePathSlot(StringRef Path);

851 void CreateTypeIdSlot(StringRef Id);

852 void CreateTypeIdCompatibleVtableSlot(StringRef Id);

853

854

855

856 void processModule();

857

858 int processIndex();

859

860

861 void processFunction();

862

863

864 void processGlobalObjectMetadata(const GlobalObject &GO);

865

866

867 void processFunctionMetadata(const Function &F);

868

869

870 void processInstructionMetadata(const Instruction &I);

871

872

873 void processDbgRecordMetadata(const DbgRecord &DVR);

874};

875

876}

877

881

883 bool ShouldInitializeAllMetadata)

884 : ShouldCreateStorage(M),

885 ShouldInitializeAllMetadata(ShouldInitializeAllMetadata), M(M) {}

886

888

890 if (!ShouldCreateStorage)

891 return Machine;

892

893 ShouldCreateStorage = false;

894 MachineStorage =

895 std::make_unique(M, ShouldInitializeAllMetadata);

896 Machine = MachineStorage.get();

897 if (ProcessModuleHookFn)

899 if (ProcessFunctionHookFn)

901 return Machine;

902}

903

905

907 return;

908

909

910 if (this->F == &F)

911 return;

912 if (this->F)

915 this->F = &F;

916}

917

919 assert(F && "No function incorporated");

921}

922

925 Fn) {

926 ProcessModuleHookFn = Fn;

927}

928

931 Fn) {

932 ProcessFunctionHookFn = Fn;

933}

934

936 if (const Argument *FA = dyn_cast(V))

938

939 if (const Instruction *I = dyn_cast(V))

940 if (I->getParent())

941 return new SlotTracker(I->getParent()->getParent());

942

943 if (const BasicBlock *BB = dyn_cast(V))

945

946 if (const GlobalVariable *GV = dyn_cast(V))

948

949 if (const GlobalAlias *GA = dyn_cast(V))

951

952 if (const GlobalIFunc *GIF = dyn_cast(V))

953 return new SlotTracker(GIF->getParent());

954

955 if (const Function *Func = dyn_cast(V))

957

958 return nullptr;

959}

960

961#if 0

962#define ST_DEBUG(X) dbgs() << X

963#else

964#define ST_DEBUG(X)

965#endif

966

967

968

970 : TheModule(M), ShouldInitializeAllMetadata(ShouldInitializeAllMetadata) {}

971

972

973

975 : TheModule(F ? F->getParent() : nullptr), TheFunction(F),

976 ShouldInitializeAllMetadata(ShouldInitializeAllMetadata) {}

977

979 : TheModule(nullptr), ShouldInitializeAllMetadata(false), TheIndex(Index) {}

980

982 if (TheModule) {

983 processModule();

984 TheModule = nullptr;

985 }

986

987 if (TheFunction && !FunctionProcessed)

988 processFunction();

989}

990

992 if (!TheIndex)

993 return 0;

994 int NumSlots = processIndex();

995 TheIndex = nullptr;

996 return NumSlots;

997}

998

999

1000

1001void SlotTracker::processModule() {

1002 ST_DEBUG("begin processModule!\n");

1003

1004

1006 if (!Var.hasName())

1007 CreateModuleSlot(&Var);

1008 processGlobalObjectMetadata(Var);

1009 auto Attrs = Var.getAttributes();

1010 if (Attrs.hasAttributes())

1011 CreateAttributeSetSlot(Attrs);

1012 }

1013

1015 if (A.hasName())

1016 CreateModuleSlot(&A);

1017 }

1018

1020 if (I.hasName())

1021 CreateModuleSlot(&I);

1022 }

1023

1024

1026 for (const MDNode *N : NMD.operands())

1027 CreateMetadataSlot(N);

1028 }

1029

1030 for (const Function &F : *TheModule) {

1031 if (F.hasName())

1032

1033 CreateModuleSlot(&F);

1034

1035 if (ShouldInitializeAllMetadata)

1036 processFunctionMetadata(F);

1037

1038

1039

1040 AttributeSet FnAttrs = F.getAttributes().getFnAttrs();

1042 CreateAttributeSetSlot(FnAttrs);

1043 }

1044

1045 if (ProcessModuleHookFn)

1046 ProcessModuleHookFn(this, TheModule, ShouldInitializeAllMetadata);

1047

1048 ST_DEBUG("end processModule!\n");

1049}

1050

1051

1052void SlotTracker::processFunction() {

1053 ST_DEBUG("begin processFunction!\n");

1054 fNext = 0;

1055

1056

1057 if (!ShouldInitializeAllMetadata)

1058 processFunctionMetadata(*TheFunction);

1059

1060

1062 AE = TheFunction->arg_end(); AI != AE; ++AI)

1063 if (!AI->hasName())

1064 CreateFunctionSlot(&*AI);

1065

1066 ST_DEBUG("Inserting Instructions:\n");

1067

1068

1069 for (auto &BB : *TheFunction) {

1070 if (!BB.hasName())

1071 CreateFunctionSlot(&BB);

1072

1073 for (auto &I : BB) {

1074 if (I.getType()->isVoidTy() && I.hasName())

1075 CreateFunctionSlot(&I);

1076

1077

1078

1079 if (const auto *Call = dyn_cast(&I)) {

1080

1082 if (Attrs.hasAttributes())

1083 CreateAttributeSetSlot(Attrs);

1084 }

1085 }

1086 }

1087

1088 if (ProcessFunctionHookFn)

1089 ProcessFunctionHookFn(this, TheFunction, ShouldInitializeAllMetadata);

1090

1091 FunctionProcessed = true;

1092

1093 ST_DEBUG("end processFunction!\n");

1094}

1095

1096

1097int SlotTracker::processIndex() {

1098 ST_DEBUG("begin processIndex!\n");

1100

1101

1102

1103

1104 std::vector ModulePaths;

1105 for (auto &[ModPath, _] : TheIndex->modulePaths())

1106 ModulePaths.push_back(ModPath);

1107 llvm::sort(ModulePaths.begin(), ModulePaths.end());

1108 for (auto &ModPath : ModulePaths)

1109 CreateModulePathSlot(ModPath);

1110

1111

1112 GUIDNext = ModulePathNext;

1113

1114 for (auto &GlobalList : *TheIndex)

1115 CreateGUIDSlot(GlobalList.first);

1116

1117

1118 TypeIdCompatibleVtableNext = GUIDNext;

1119 for (auto &TId : TheIndex->typeIdCompatibleVtableMap())

1120 CreateTypeIdCompatibleVtableSlot(TId.first);

1121

1122

1123 TypeIdNext = TypeIdCompatibleVtableNext;

1124 for (const auto &TID : TheIndex->typeIds())

1125 CreateTypeIdSlot(TID.second.first);

1126

1127 ST_DEBUG("end processIndex!\n");

1128 return TypeIdNext;

1129}

1130

1131void SlotTracker::processGlobalObjectMetadata(const GlobalObject &GO) {

1134 for (auto &MD : MDs)

1135 CreateMetadataSlot(MD.second);

1136}

1137

1138void SlotTracker::processFunctionMetadata(const Function &F) {

1139 processGlobalObjectMetadata(F);

1140 for (auto &BB : F) {

1141 for (auto &I : BB) {

1142 for (const DbgRecord &DR : I.getDbgRecordRange())

1143 processDbgRecordMetadata(DR);

1144 processInstructionMetadata(I);

1145 }

1146 }

1147}

1148

1149void SlotTracker::processDbgRecordMetadata(const DbgRecord &DR) {

1150 if (const DbgVariableRecord *DVR = dyn_cast(&DR)) {

1151

1152

1153

1154

1155 if (auto *Empty = dyn_cast(DVR->getRawLocation()))

1156 CreateMetadataSlot(Empty);

1157 CreateMetadataSlot(DVR->getRawVariable());

1158 if (DVR->isDbgAssign()) {

1159 CreateMetadataSlot(cast(DVR->getRawAssignID()));

1160 if (auto *Empty = dyn_cast(DVR->getRawAddress()))

1161 CreateMetadataSlot(Empty);

1162 }

1163 } else if (const DbgLabelRecord *DLR = dyn_cast(&DR)) {

1164 CreateMetadataSlot(DLR->getRawLabel());

1165 } else {

1167 }

1169}

1170

1171void SlotTracker::processInstructionMetadata(const Instruction &I) {

1172

1173 if (const CallInst *CI = dyn_cast(&I))

1174 if (Function *F = CI->getCalledFunction())

1175 if (F->isIntrinsic())

1176 for (auto &Op : I.operands())

1177 if (auto *V = dyn_cast_or_null(Op))

1178 if (MDNode *N = dyn_cast(V->getMetadata()))

1179 CreateMetadataSlot(N);

1180

1181

1183 I.getAllMetadata(MDs);

1184 for (auto &MD : MDs)

1185 CreateMetadataSlot(MD.second);

1186}

1187

1188

1189

1190

1192 ST_DEBUG("begin purgeFunction!\n");

1193 fMap.clear();

1194 TheFunction = nullptr;

1195 FunctionProcessed = false;

1196 ST_DEBUG("end purgeFunction!\n");

1197}

1198

1199

1201

1203

1204

1206 return MI == mMap.end() ? -1 : (int)MI->second;

1207}

1208

1211 Fn) {

1212 ProcessModuleHookFn = Fn;

1213}

1214

1217 Fn) {

1218 ProcessFunctionHookFn = Fn;

1219}

1220

1221

1223

1224

1226

1228

1229

1231 return MI == mdnMap.end() ? -1 : (int)MI->second;

1232}

1233

1234

1236 assert(!isa(V) && "Can't get a constant or global slot with this!");

1237

1238

1240

1242 return FI == fMap.end() ? -1 : (int)FI->second;

1243}

1244

1246

1248

1249

1251 return AI == asMap.end() ? -1 : (int)AI->second;

1252}

1253

1255

1257

1258

1259 auto I = ModulePathMap.find(Path);

1260 return I == ModulePathMap.end() ? -1 : (int)I->second;

1261}

1262

1264

1266

1267

1269 return I == GUIDMap.end() ? -1 : (int)I->second;

1270}

1271

1273

1275

1276

1277 auto I = TypeIdMap.find(Id);

1278 return I == TypeIdMap.end() ? -1 : (int)I->second;

1279}

1280

1282

1284

1285

1286 auto I = TypeIdCompatibleVtableMap.find(Id);

1287 return I == TypeIdCompatibleVtableMap.end() ? -1 : (int)I->second;

1288}

1289

1290

1291void SlotTracker::CreateModuleSlot(const GlobalValue *V) {

1292 assert(V && "Can't insert a null Value into SlotTracker!");

1293 assert(!V->getType()->isVoidTy() && "Doesn't need a slot!");

1294 assert(!V->hasName() && "Doesn't need a slot!");

1295

1296 unsigned DestSlot = mNext++;

1297 mMap[V] = DestSlot;

1298

1299 ST_DEBUG(" Inserting value [" << V->getType() << "] = " << V << " slot=" <<

1300 DestSlot << " [");

1301

1302 ST_DEBUG((isa(V) ? 'G' :

1303 (isa(V) ? 'F' :

1304 (isa(V) ? 'A' :

1305 (isa(V) ? 'I' : 'o')))) << "]\n");

1306}

1307

1308

1309void SlotTracker::CreateFunctionSlot(const Value *V) {

1310 assert(!V->getType()->isVoidTy() && !V->hasName() && "Doesn't need a slot!");

1311

1312 unsigned DestSlot = fNext++;

1313 fMap[V] = DestSlot;

1314

1315

1316 ST_DEBUG(" Inserting value [" << V->getType() << "] = " << V << " slot=" <<

1317 DestSlot << " [o]\n");

1318}

1319

1320

1321void SlotTracker::CreateMetadataSlot(const MDNode *N) {

1322 assert(N && "Can't insert a null Value into SlotTracker!");

1323

1324

1325 if (isa(N))

1326 return;

1327

1328 unsigned DestSlot = mdnNext;

1329 if (!mdnMap.insert(std::make_pair(N, DestSlot)).second)

1330 return;

1331 ++mdnNext;

1332

1333

1334 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)

1335 if (const MDNode *Op = dyn_cast_or_null(N->getOperand(i)))

1336 CreateMetadataSlot(Op);

1337}

1338

1339void SlotTracker::CreateAttributeSetSlot(AttributeSet AS) {

1341

1342 if (asMap.try_emplace(AS, asNext).second)

1343 ++asNext;

1344}

1345

1346

1347void SlotTracker::CreateModulePathSlot(StringRef Path) {

1348 ModulePathMap[Path] = ModulePathNext++;

1349}

1350

1351

1353 GUIDMap[GUID] = GUIDNext++;

1354}

1355

1356

1357void SlotTracker::CreateTypeIdSlot(StringRef Id) {

1358 TypeIdMap[Id] = TypeIdNext++;

1359}

1360

1361

1362void SlotTracker::CreateTypeIdCompatibleVtableSlot(StringRef Id) {

1363 TypeIdCompatibleVtableMap[Id] = TypeIdCompatibleVtableNext++;

1364}

1365

1366namespace {

1367

1368struct AsmWriterContext {

1369 TypePrinting *TypePrinter = nullptr;

1371 const Module *Context = nullptr;

1372

1373 AsmWriterContext(TypePrinting *TP, SlotTracker *ST, const Module *M = nullptr)

1374 : TypePrinter(TP), Machine(ST), Context(M) {}

1375

1376 static AsmWriterContext &getEmpty() {

1377 static AsmWriterContext EmptyCtx(nullptr, nullptr);

1378 return EmptyCtx;

1379 }

1380

1381

1382

1383 virtual void onWriteMetadataAsOperand(const Metadata *) {}

1384

1385 virtual ~AsmWriterContext() = default;

1386};

1387}

1388

1389

1390

1391

1392

1394 AsmWriterContext &WriterCtx);

1395

1397 AsmWriterContext &WriterCtx,

1398 bool FromValue = false);

1399

1401 if (const FPMathOperator *FPO = dyn_cast(U))

1402 Out << FPO->getFastMathFlags();

1403

1405 dyn_cast(U)) {

1406 if (OBO->hasNoUnsignedWrap())

1407 Out << " nuw";

1408 if (OBO->hasNoSignedWrap())

1409 Out << " nsw";

1411 dyn_cast(U)) {

1412 if (Div->isExact())

1413 Out << " exact";

1415 dyn_cast(U)) {

1416 if (PDI->isDisjoint())

1417 Out << " disjoint";

1418 } else if (const GEPOperator *GEP = dyn_cast(U)) {

1419 if (GEP->isInBounds())

1420 Out << " inbounds";

1421 else if (GEP->hasNoUnsignedSignedWrap())

1422 Out << " nusw";

1423 if (GEP->hasNoUnsignedWrap())

1424 Out << " nuw";

1425 if (auto InRange = GEP->getInRange()) {

1426 Out << " inrange(" << InRange->getLower() << ", " << InRange->getUpper()

1427 << ")";

1428 }

1429 } else if (const auto *NNI = dyn_cast(U)) {

1430 if (NNI->hasNonNeg())

1431 Out << " nneg";

1432 } else if (const auto *TI = dyn_cast(U)) {

1433 if (TI->hasNoUnsignedWrap())

1434 Out << " nuw";

1435 if (TI->hasNoSignedWrap())

1436 Out << " nsw";

1437 } else if (const auto *ICmp = dyn_cast(U)) {

1438 if (ICmp->hasSameSign())

1439 Out << " samesign";

1440 }

1441}

1442

1446

1447

1448

1449

1450

1454 bool isNaN = APF.isNaN();

1455

1456 if (!isInf && !isNaN) {

1459 APF.toString(StrVal, 6, 0, false);

1460

1461

1462

1463

1465 ((StrVal[0] == '-' || StrVal[0] == '+') && isDigit(StrVal[1]))) &&

1466 "[-+]?[0-9] regex does not match!");

1467

1469 Out << StrVal;

1470 return;

1471 }

1472 }

1473

1474

1475

1476

1477

1478 static_assert(sizeof(double) == sizeof(uint64_t),

1479 "assuming that double is 64 bits!");

1481

1482

1483

1484 if (!isDouble) {

1485

1486

1490 if (IsSNAN) {

1492 apf =

1494 }

1495 }

1496

1498 return;

1499 }

1500

1501

1502

1503

1504 Out << "0x";

1507 Out << 'K';

1509 true);

1511 true);

1513 Out << 'L';

1515 true);

1517 true);

1519 Out << 'M';

1521 true);

1523 true);

1525 Out << 'H';

1527 true);

1529 Out << 'R';

1531 true);

1532 } else

1534}

1535

1537 AsmWriterContext &WriterCtx) {

1538 if (const ConstantInt *CI = dyn_cast(CV)) {

1539 Type *Ty = CI->getType();

1540

1542 Out << "splat (";

1543 WriterCtx.TypePrinter->print(Ty->getScalarType(), Out);

1544 Out << " ";

1545 }

1546

1548 Out << (CI->getZExtValue() ? "true" : "false");

1549 else

1550 Out << CI->getValue();

1551

1553 Out << ")";

1554

1555 return;

1556 }

1557

1558 if (const ConstantFP *CFP = dyn_cast(CV)) {

1559 Type *Ty = CFP->getType();

1560

1562 Out << "splat (";

1563 WriterCtx.TypePrinter->print(Ty->getScalarType(), Out);

1564 Out << " ";

1565 }

1566

1568

1570 Out << ")";

1571

1572 return;

1573 }

1574

1575 if (isa(CV) || isa(CV)) {

1576 Out << "zeroinitializer";

1577 return;

1578 }

1579

1580 if (const BlockAddress *BA = dyn_cast(CV)) {

1581 Out << "blockaddress(";

1583 Out << ", ";

1585 Out << ")";

1586 return;

1587 }

1588

1589 if (const auto *Equiv = dyn_cast(CV)) {

1590 Out << "dso_local_equivalent ";

1592 return;

1593 }

1594

1595 if (const auto *NC = dyn_cast(CV)) {

1596 Out << "no_cfi ";

1598 return;

1599 }

1600

1601 if (const ConstantPtrAuth *CPA = dyn_cast(CV)) {

1602 Out << "ptrauth (";

1603

1604

1605 unsigned NumOpsToWrite = 2;

1606 if (!CPA->getOperand(2)->isNullValue())

1607 NumOpsToWrite = 3;

1608 if (!CPA->getOperand(3)->isNullValue())

1609 NumOpsToWrite = 4;

1610

1611 ListSeparator LS;

1612 for (unsigned i = 0, e = NumOpsToWrite; i != e; ++i) {

1613 Out << LS;

1614 WriterCtx.TypePrinter->print(CPA->getOperand(i)->getType(), Out);

1615 Out << ' ';

1617 }

1618 Out << ')';

1619 return;

1620 }

1621

1622 if (const ConstantArray *CA = dyn_cast(CV)) {

1623 Type *ETy = CA->getType()->getElementType();

1624 Out << '[';

1625 WriterCtx.TypePrinter->print(ETy, Out);

1626 Out << ' ';

1628 for (unsigned i = 1, e = CA->getNumOperands(); i != e; ++i) {

1629 Out << ", ";

1630 WriterCtx.TypePrinter->print(ETy, Out);

1631 Out << ' ';

1633 }

1634 Out << ']';

1635 return;

1636 }

1637

1638 if (const ConstantDataArray *CA = dyn_cast(CV)) {

1639

1640

1641 if (CA->isString()) {

1642 Out << "c\"";

1643 printEscapedString(CA->getAsString(), Out);

1644 Out << '"';

1645 return;

1646 }

1647

1648 Type *ETy = CA->getType()->getElementType();

1649 Out << '[';

1650 WriterCtx.TypePrinter->print(ETy, Out);

1651 Out << ' ';

1653 for (unsigned i = 1, e = CA->getNumElements(); i != e; ++i) {

1654 Out << ", ";

1655 WriterCtx.TypePrinter->print(ETy, Out);

1656 Out << ' ';

1658 }

1659 Out << ']';

1660 return;

1661 }

1662

1663 if (const ConstantStruct *CS = dyn_cast(CV)) {

1664 if (CS->getType()->isPacked())

1665 Out << '<';

1666 Out << '{';

1667 unsigned N = CS->getNumOperands();

1668 if (N) {

1669 Out << ' ';

1670 WriterCtx.TypePrinter->print(CS->getOperand(0)->getType(), Out);

1671 Out << ' ';

1672

1674

1675 for (unsigned i = 1; i < N; i++) {

1676 Out << ", ";

1677 WriterCtx.TypePrinter->print(CS->getOperand(i)->getType(), Out);

1678 Out << ' ';

1679

1681 }

1682 Out << ' ';

1683 }

1684

1685 Out << '}';

1686 if (CS->getType()->isPacked())

1687 Out << '>';

1688 return;

1689 }

1690

1691 if (isa(CV) || isa(CV)) {

1692 auto *CVVTy = cast(CV->getType());

1693 Type *ETy = CVVTy->getElementType();

1694

1695

1696

1697

1698

1699

1701 if (isa(SplatVal) || isa(SplatVal)) {

1702 Out << "splat (";

1703 WriterCtx.TypePrinter->print(ETy, Out);

1704 Out << ' ';

1706 Out << ')';

1707 return;

1708 }

1709 }

1710

1711 Out << '<';

1712 WriterCtx.TypePrinter->print(ETy, Out);

1713 Out << ' ';

1715 for (unsigned i = 1, e = CVVTy->getNumElements(); i != e; ++i) {

1716 Out << ", ";

1717 WriterCtx.TypePrinter->print(ETy, Out);

1718 Out << ' ';

1720 }

1721 Out << '>';

1722 return;

1723 }

1724

1725 if (isa(CV)) {

1726 Out << "null";

1727 return;

1728 }

1729

1730 if (isa(CV)) {

1731 Out << "none";

1732 return;

1733 }

1734

1735 if (isa(CV)) {

1736 Out << "poison";

1737 return;

1738 }

1739

1740 if (isa(CV)) {

1741 Out << "undef";

1742 return;

1743 }

1744

1745 if (const ConstantExpr *CE = dyn_cast(CV)) {

1746

1747

1748

1749

1750

1751 if (CE->getOpcode() == Instruction::ShuffleVector) {

1752 if (auto *SplatVal = CE->getSplatValue()) {

1753 if (isa(SplatVal) || isa(SplatVal)) {

1754 Out << "splat (";

1755 WriterCtx.TypePrinter->print(SplatVal->getType(), Out);

1756 Out << ' ';

1758 Out << ')';

1759 return;

1760 }

1761 }

1762 }

1763

1764 Out << CE->getOpcodeName();

1766 Out << " (";

1767

1768 if (const GEPOperator *GEP = dyn_cast(CE)) {

1769 WriterCtx.TypePrinter->print(GEP->getSourceElementType(), Out);

1770 Out << ", ";

1771 }

1772

1774 ++OI) {

1775 WriterCtx.TypePrinter->print((*OI)->getType(), Out);

1776 Out << ' ';

1778 if (OI+1 != CE->op_end())

1779 Out << ", ";

1780 }

1781

1782 if (CE->isCast()) {

1783 Out << " to ";

1784 WriterCtx.TypePrinter->print(CE->getType(), Out);

1785 }

1786

1787 if (CE->getOpcode() == Instruction::ShuffleVector)

1789

1790 Out << ')';

1791 return;

1792 }

1793

1794 Out << "";

1795}

1796

1798 AsmWriterContext &WriterCtx) {

1799 Out << "!{";

1800 for (unsigned mi = 0, me = Node->getNumOperands(); mi != me; ++mi) {

1802 if (!MD)

1803 Out << "null";

1804 else if (auto *MDV = dyn_cast(MD)) {

1805 Value *V = MDV->getValue();

1806 WriterCtx.TypePrinter->print(V->getType(), Out);

1807 Out << ' ';

1809 } else {

1811 WriterCtx.onWriteMetadataAsOperand(MD);

1812 }

1813 if (mi + 1 != me)

1814 Out << ", ";

1815 }

1816

1817 Out << "}";

1818}

1819

1820namespace {

1821

1822struct FieldSeparator {

1823 bool Skip = true;

1824 const char *Sep;

1825

1826 FieldSeparator(const char *Sep = ", ") : Sep(Sep) {}

1827};

1828

1830 if (FS.Skip) {

1831 FS.Skip = false;

1832 return OS;

1833 }

1834 return OS << FS.Sep;

1835}

1836

1837struct MDFieldPrinter {

1839 FieldSeparator FS;

1840 AsmWriterContext &WriterCtx;

1841

1842 explicit MDFieldPrinter(raw_ostream &Out)

1843 : Out(Out), WriterCtx(AsmWriterContext::getEmpty()) {}

1844 MDFieldPrinter(raw_ostream &Out, AsmWriterContext &Ctx)

1845 : Out(Out), WriterCtx(Ctx) {}

1846

1847 void printTag(const DINode *N);

1848 void printMacinfoType(const DIMacroNode *N);

1851 bool ShouldSkipEmpty = true);

1853 bool ShouldSkipNull = true);

1854 template

1855 void printInt(StringRef Name, IntTy Int, bool ShouldSkipZero = true);

1857 bool ShouldSkipZero);

1859 std::optional Default = std::nullopt);

1862 template <class IntTy, class Stringifier>

1864 bool ShouldSkipZero = true);

1868};

1869

1870}

1871

1872void MDFieldPrinter::printTag(const DINode *N) {

1873 Out << FS << "tag: ";

1875 if (Tag.empty())

1876 Out << Tag;

1877 else

1878 Out << N->getTag();

1879}

1880

1881void MDFieldPrinter::printMacinfoType(const DIMacroNode *N) {

1882 Out << FS << "type: ";

1884 if (Type.empty())

1885 Out << Type;

1886 else

1887 Out << N->getMacinfoType();

1888}

1889

1890void MDFieldPrinter::printChecksum(

1893 printString("checksum", Checksum.Value, false);

1894}

1895

1897 bool ShouldSkipEmpty) {

1898 if (ShouldSkipEmpty && Value.empty())

1899 return;

1900

1901 Out << FS << Name << ": \"";

1902 printEscapedString(Value, Out);

1903 Out << "\"";

1904}

1905

1907 AsmWriterContext &WriterCtx) {

1908 if (!MD) {

1909 Out << "null";

1910 return;

1911 }

1913 WriterCtx.onWriteMetadataAsOperand(MD);

1914}

1915

1917 bool ShouldSkipNull) {

1918 if (ShouldSkipNull && !MD)

1919 return;

1920

1921 Out << FS << Name << ": ";

1923}

1924

1925template

1926void MDFieldPrinter::printInt(StringRef Name, IntTy Int, bool ShouldSkipZero) {

1927 if (ShouldSkipZero && Int)

1928 return;

1929

1930 Out << FS << Name << ": " << Int;

1931}

1932

1934 bool IsUnsigned, bool ShouldSkipZero) {

1935 if (ShouldSkipZero && Int.isZero())

1936 return;

1937

1938 Out << FS << Name << ": ";

1939 Int.print(Out, !IsUnsigned);

1940}

1941

1943 std::optional Default) {

1945 return;

1946 Out << FS << Name << ": " << (Value ? "true" : "false");

1947}

1948

1950 if (!Flags)

1951 return;

1952

1953 Out << FS << Name << ": ";

1954

1957

1958 FieldSeparator FlagsFS(" | ");

1959 for (auto F : SplitFlags) {

1961 assert(!StringF.empty() && "Expected valid flag");

1962 Out << FlagsFS << StringF;

1963 }

1964 if (Extra || SplitFlags.empty())

1965 Out << FlagsFS << Extra;

1966}

1967

1968void MDFieldPrinter::printDISPFlags(StringRef Name,

1970

1971

1972 Out << FS << Name << ": ";

1973

1974 if (!Flags) {

1975 Out << 0;

1976 return;

1977 }

1978

1981

1982 FieldSeparator FlagsFS(" | ");

1983 for (auto F : SplitFlags) {

1985 assert(!StringF.empty() && "Expected valid flag");

1986 Out << FlagsFS << StringF;

1987 }

1988 if (Extra || SplitFlags.empty())

1989 Out << FlagsFS << Extra;

1990}

1991

1992void MDFieldPrinter::printEmissionKind(StringRef Name,

1995}

1996

1997void MDFieldPrinter::printNameTableKind(StringRef Name,

2000 return;

2002}

2003

2004template <class IntTy, class Stringifier>

2006 Stringifier toString, bool ShouldSkipZero) {

2008 return;

2009

2010 Out << FS << Name << ": ";

2012 if (!S.empty())

2013 Out << S;

2014 else

2016}

2017

2019 AsmWriterContext &WriterCtx) {

2020 Out << "!GenericDINode(";

2021 MDFieldPrinter Printer(Out, WriterCtx);

2023 Printer.printString("header", N->getHeader());

2024 if (N->getNumDwarfOperands()) {

2025 Out << Printer.FS << "operands: {";

2026 FieldSeparator IFS;

2027 for (auto &I : N->dwarf_operands()) {

2028 Out << IFS;

2030 }

2031 Out << "}";

2032 }

2033 Out << ")";

2034}

2035

2037 AsmWriterContext &WriterCtx) {

2038 Out << "!DILocation(";

2039 MDFieldPrinter Printer(Out, WriterCtx);

2040

2041 Printer.printInt("line", DL->getLine(), false);

2042 Printer.printInt("column", DL->getColumn());

2043 Printer.printMetadata("scope", DL->getRawScope(), false);

2044 Printer.printMetadata("inlinedAt", DL->getRawInlinedAt());

2045 Printer.printBool("isImplicitCode", DL->isImplicitCode(),

2046 false);

2047 Out << ")";

2048}

2049

2051 AsmWriterContext &WriterCtx) {

2052 Out << "!DIAssignID()";

2053 MDFieldPrinter Printer(Out, WriterCtx);

2054}

2055

2057 AsmWriterContext &WriterCtx) {

2058 Out << "!DISubrange(";

2059 MDFieldPrinter Printer(Out, WriterCtx);

2060

2061 auto *Count = N->getRawCountNode();

2062 if (auto *CE = dyn_cast_or_null(Count)) {

2063 auto *CV = cast(CE->getValue());

2064 Printer.printInt("count", CV->getSExtValue(),

2065 false);

2066 } else

2067 Printer.printMetadata("count", Count, true);

2068

2069

2070

2071 auto *LBound = N->getRawLowerBound();

2072 if (auto *LE = dyn_cast_or_null(LBound)) {

2073 auto *LV = cast(LE->getValue());

2074 Printer.printInt("lowerBound", LV->getSExtValue(),

2075 false);

2076 } else

2077 Printer.printMetadata("lowerBound", LBound, true);

2078

2079 auto *UBound = N->getRawUpperBound();

2080 if (auto *UE = dyn_cast_or_null(UBound)) {

2081 auto *UV = cast(UE->getValue());

2082 Printer.printInt("upperBound", UV->getSExtValue(),

2083 false);

2084 } else

2085 Printer.printMetadata("upperBound", UBound, true);

2086

2087 auto *Stride = N->getRawStride();

2088 if (auto *SE = dyn_cast_or_null(Stride)) {

2089 auto *SV = cast(SE->getValue());

2090 Printer.printInt("stride", SV->getSExtValue(), false);

2091 } else

2092 Printer.printMetadata("stride", Stride, true);

2093

2094 Out << ")";

2095}

2096

2098 AsmWriterContext &WriterCtx) {

2099 Out << "!DIGenericSubrange(";

2100 MDFieldPrinter Printer(Out, WriterCtx);

2101

2102 auto IsConstant = [&](Metadata *Bound) -> bool {

2103 if (auto *BE = dyn_cast_or_null(Bound)) {

2104 return BE->isConstant() &&

2106 *BE->isConstant();

2107 }

2108 return false;

2109 };

2110

2111 auto GetConstant = [&](Metadata *Bound) -> int64_t {

2112 assert(IsConstant(Bound) && "Expected constant");

2113 auto *BE = dyn_cast_or_null(Bound);

2114 return static_cast<int64_t>(BE->getElement(1));

2115 };

2116

2117 auto *Count = N->getRawCountNode();

2118 if (IsConstant(Count))

2119 Printer.printInt("count", GetConstant(Count),

2120 false);

2121 else

2122 Printer.printMetadata("count", Count, true);

2123

2124 auto *LBound = N->getRawLowerBound();

2125 if (IsConstant(LBound))

2126 Printer.printInt("lowerBound", GetConstant(LBound),

2127 false);

2128 else

2129 Printer.printMetadata("lowerBound", LBound, true);

2130

2131 auto *UBound = N->getRawUpperBound();

2132 if (IsConstant(UBound))

2133 Printer.printInt("upperBound", GetConstant(UBound),

2134 false);

2135 else

2136 Printer.printMetadata("upperBound", UBound, true);

2137

2138 auto *Stride = N->getRawStride();

2139 if (IsConstant(Stride))

2140 Printer.printInt("stride", GetConstant(Stride),

2141 false);

2142 else

2143 Printer.printMetadata("stride", Stride, true);

2144

2145 Out << ")";

2146}

2147

2149 AsmWriterContext &) {

2150 Out << "!DIEnumerator(";

2151 MDFieldPrinter Printer(Out);

2152 Printer.printString("name", N->getName(), false);

2153 Printer.printAPInt("value", N->getValue(), N->isUnsigned(),

2154 false);

2155 if (N->isUnsigned())

2156 Printer.printBool("isUnsigned", true);

2157 Out << ")";

2158}

2159

2161 AsmWriterContext &) {

2162 Out << "!DIBasicType(";

2163 MDFieldPrinter Printer(Out);

2164 if (N->getTag() != dwarf::DW_TAG_base_type)

2166 Printer.printString("name", N->getName());

2167 Printer.printInt("size", N->getSizeInBits());

2168 Printer.printInt("align", N->getAlignInBits());

2169 Printer.printDwarfEnum("encoding", N->getEncoding(),

2171 Printer.printInt("num_extra_inhabitants", N->getNumExtraInhabitants());

2172 Printer.printDIFlags("flags", N->getFlags());

2173 Out << ")";

2174}

2175

2177 AsmWriterContext &WriterCtx) {

2178 Out << "!DIStringType(";

2179 MDFieldPrinter Printer(Out, WriterCtx);

2180 if (N->getTag() != dwarf::DW_TAG_string_type)

2182 Printer.printString("name", N->getName());

2183 Printer.printMetadata("stringLength", N->getRawStringLength());

2184 Printer.printMetadata("stringLengthExpression", N->getRawStringLengthExp());

2185 Printer.printMetadata("stringLocationExpression",

2186 N->getRawStringLocationExp());

2187 Printer.printInt("size", N->getSizeInBits());

2188 Printer.printInt("align", N->getAlignInBits());

2189 Printer.printDwarfEnum("encoding", N->getEncoding(),

2191 Out << ")";

2192}

2193

2195 AsmWriterContext &WriterCtx) {

2196 Out << "!DIDerivedType(";

2197 MDFieldPrinter Printer(Out, WriterCtx);

2199 Printer.printString("name", N->getName());

2200 Printer.printMetadata("scope", N->getRawScope());

2201 Printer.printMetadata("file", N->getRawFile());

2202 Printer.printInt("line", N->getLine());

2203 Printer.printMetadata("baseType", N->getRawBaseType(),

2204 false);

2205 Printer.printInt("size", N->getSizeInBits());

2206 Printer.printInt("align", N->getAlignInBits());

2207 Printer.printInt("offset", N->getOffsetInBits());

2208 Printer.printDIFlags("flags", N->getFlags());

2209 Printer.printMetadata("extraData", N->getRawExtraData());

2210 if (const auto &DWARFAddressSpace = N->getDWARFAddressSpace())

2211 Printer.printInt("dwarfAddressSpace", *DWARFAddressSpace,

2212 false);

2213 Printer.printMetadata("annotations", N->getRawAnnotations());

2214 if (auto PtrAuthData = N->getPtrAuthData()) {

2215 Printer.printInt("ptrAuthKey", PtrAuthData->key());

2216 Printer.printBool("ptrAuthIsAddressDiscriminated",

2217 PtrAuthData->isAddressDiscriminated());

2218 Printer.printInt("ptrAuthExtraDiscriminator",

2219 PtrAuthData->extraDiscriminator());

2220 Printer.printBool("ptrAuthIsaPointer", PtrAuthData->isaPointer());

2221 Printer.printBool("ptrAuthAuthenticatesNullValues",

2222 PtrAuthData->authenticatesNullValues());

2223 }

2224 Out << ")";

2225}

2226

2228 AsmWriterContext &WriterCtx) {

2229 Out << "!DICompositeType(";

2230 MDFieldPrinter Printer(Out, WriterCtx);

2232 Printer.printString("name", N->getName());

2233 Printer.printMetadata("scope", N->getRawScope());

2234 Printer.printMetadata("file", N->getRawFile());

2235 Printer.printInt("line", N->getLine());

2236 Printer.printMetadata("baseType", N->getRawBaseType());

2237 Printer.printInt("size", N->getSizeInBits());

2238 Printer.printInt("align", N->getAlignInBits());

2239 Printer.printInt("offset", N->getOffsetInBits());

2240 Printer.printInt("num_extra_inhabitants", N->getNumExtraInhabitants());

2241 Printer.printDIFlags("flags", N->getFlags());

2242 Printer.printMetadata("elements", N->getRawElements());

2243 Printer.printDwarfEnum("runtimeLang", N->getRuntimeLang(),

2245 Printer.printMetadata("vtableHolder", N->getRawVTableHolder());

2246 Printer.printMetadata("templateParams", N->getRawTemplateParams());

2247 Printer.printString("identifier", N->getIdentifier());

2248 Printer.printMetadata("discriminator", N->getRawDiscriminator());

2249 Printer.printMetadata("dataLocation", N->getRawDataLocation());

2250 Printer.printMetadata("associated", N->getRawAssociated());

2251 Printer.printMetadata("allocated", N->getRawAllocated());

2252 if (auto *RankConst = N->getRankConst())

2253 Printer.printInt("rank", RankConst->getSExtValue(),

2254 false);

2255 else

2256 Printer.printMetadata("rank", N->getRawRank(), true);

2257 Printer.printMetadata("annotations", N->getRawAnnotations());

2258 if (auto *Specification = N->getRawSpecification())

2259 Printer.printMetadata("specification", Specification);

2260 Out << ")";

2261}

2262

2264 AsmWriterContext &WriterCtx) {

2265 Out << "!DISubroutineType(";

2266 MDFieldPrinter Printer(Out, WriterCtx);

2267 Printer.printDIFlags("flags", N->getFlags());

2269 Printer.printMetadata("types", N->getRawTypeArray(),

2270 false);

2271 Out << ")";

2272}

2273

2275 Out << "!DIFile(";

2276 MDFieldPrinter Printer(Out);

2277 Printer.printString("filename", N->getFilename(),

2278 false);

2279 Printer.printString("directory", N->getDirectory(),

2280 false);

2281

2282 if (N->getChecksum())

2283 Printer.printChecksum(*N->getChecksum());

2284 Printer.printString("source", N->getSource().value_or(StringRef()),

2285 true);

2286 Out << ")";

2287}

2288

2290 AsmWriterContext &WriterCtx) {

2291 Out << "!DICompileUnit(";

2292 MDFieldPrinter Printer(Out, WriterCtx);

2293 Printer.printDwarfEnum("language", N->getSourceLanguage(),

2295 Printer.printMetadata("file", N->getRawFile(), false);

2296 Printer.printString("producer", N->getProducer());

2297 Printer.printBool("isOptimized", N->isOptimized());

2298 Printer.printString("flags", N->getFlags());

2299 Printer.printInt("runtimeVersion", N->getRuntimeVersion(),

2300 false);

2301 Printer.printString("splitDebugFilename", N->getSplitDebugFilename());

2302 Printer.printEmissionKind("emissionKind", N->getEmissionKind());

2303 Printer.printMetadata("enums", N->getRawEnumTypes());

2304 Printer.printMetadata("retainedTypes", N->getRawRetainedTypes());

2305 Printer.printMetadata("globals", N->getRawGlobalVariables());

2306 Printer.printMetadata("imports", N->getRawImportedEntities());

2307 Printer.printMetadata("macros", N->getRawMacros());

2308 Printer.printInt("dwoId", N->getDWOId());

2309 Printer.printBool("splitDebugInlining", N->getSplitDebugInlining(), true);

2310 Printer.printBool("debugInfoForProfiling", N->getDebugInfoForProfiling(),

2311 false);

2312 Printer.printNameTableKind("nameTableKind", N->getNameTableKind());

2313 Printer.printBool("rangesBaseAddress", N->getRangesBaseAddress(), false);

2314 Printer.printString("sysroot", N->getSysRoot());

2315 Printer.printString("sdk", N->getSDK());

2316 Out << ")";

2317}

2318

2320 AsmWriterContext &WriterCtx) {

2321 Out << "!DISubprogram(";

2322 MDFieldPrinter Printer(Out, WriterCtx);

2323 Printer.printString("name", N->getName());

2324 Printer.printString("linkageName", N->getLinkageName());

2325 Printer.printMetadata("scope", N->getRawScope(), false);

2326 Printer.printMetadata("file", N->getRawFile());

2327 Printer.printInt("line", N->getLine());

2328 Printer.printMetadata("type", N->getRawType());

2329 Printer.printInt("scopeLine", N->getScopeLine());

2330 Printer.printMetadata("containingType", N->getRawContainingType());

2331 if (N->getVirtuality() != dwarf::DW_VIRTUALITY_none ||

2332 N->getVirtualIndex() != 0)

2333 Printer.printInt("virtualIndex", N->getVirtualIndex(), false);

2334 Printer.printInt("thisAdjustment", N->getThisAdjustment());

2335 Printer.printDIFlags("flags", N->getFlags());

2336 Printer.printDISPFlags("spFlags", N->getSPFlags());

2337 Printer.printMetadata("unit", N->getRawUnit());

2338 Printer.printMetadata("templateParams", N->getRawTemplateParams());

2339 Printer.printMetadata("declaration", N->getRawDeclaration());

2340 Printer.printMetadata("retainedNodes", N->getRawRetainedNodes());

2341 Printer.printMetadata("thrownTypes", N->getRawThrownTypes());

2342 Printer.printMetadata("annotations", N->getRawAnnotations());

2343 Printer.printString("targetFuncName", N->getTargetFuncName());

2344 Out << ")";

2345}

2346

2348 AsmWriterContext &WriterCtx) {

2349 Out << "!DILexicalBlock(";

2350 MDFieldPrinter Printer(Out, WriterCtx);

2351 Printer.printMetadata("scope", N->getRawScope(), false);

2352 Printer.printMetadata("file", N->getRawFile());

2353 Printer.printInt("line", N->getLine());

2354 Printer.printInt("column", N->getColumn());

2355 Out << ")";

2356}

2357

2360 AsmWriterContext &WriterCtx) {

2361 Out << "!DILexicalBlockFile(";

2362 MDFieldPrinter Printer(Out, WriterCtx);

2363 Printer.printMetadata("scope", N->getRawScope(), false);

2364 Printer.printMetadata("file", N->getRawFile());

2365 Printer.printInt("discriminator", N->getDiscriminator(),

2366 false);

2367 Out << ")";

2368}

2369

2371 AsmWriterContext &WriterCtx) {

2372 Out << "!DINamespace(";

2373 MDFieldPrinter Printer(Out, WriterCtx);

2374 Printer.printString("name", N->getName());

2375 Printer.printMetadata("scope", N->getRawScope(), false);

2376 Printer.printBool("exportSymbols", N->getExportSymbols(), false);

2377 Out << ")";

2378}

2379

2381 AsmWriterContext &WriterCtx) {

2382 Out << "!DICommonBlock(";

2383 MDFieldPrinter Printer(Out, WriterCtx);

2384 Printer.printMetadata("scope", N->getRawScope(), false);

2385 Printer.printMetadata("declaration", N->getRawDecl(), false);

2386 Printer.printString("name", N->getName());

2387 Printer.printMetadata("file", N->getRawFile());

2388 Printer.printInt("line", N->getLineNo());

2389 Out << ")";

2390}

2391

2393 AsmWriterContext &WriterCtx) {

2394 Out << "!DIMacro(";

2395 MDFieldPrinter Printer(Out, WriterCtx);

2396 Printer.printMacinfoType(N);

2397 Printer.printInt("line", N->getLine());

2398 Printer.printString("name", N->getName());

2399 Printer.printString("value", N->getValue());

2400 Out << ")";

2401}

2402

2404 AsmWriterContext &WriterCtx) {

2405 Out << "!DIMacroFile(";

2406 MDFieldPrinter Printer(Out, WriterCtx);

2407 Printer.printInt("line", N->getLine());

2408 Printer.printMetadata("file", N->getRawFile(), false);

2409 Printer.printMetadata("nodes", N->getRawElements());

2410 Out << ")";

2411}

2412

2414 AsmWriterContext &WriterCtx) {

2415 Out << "!DIModule(";

2416 MDFieldPrinter Printer(Out, WriterCtx);

2417 Printer.printMetadata("scope", N->getRawScope(), false);

2418 Printer.printString("name", N->getName());

2419 Printer.printString("configMacros", N->getConfigurationMacros());

2420 Printer.printString("includePath", N->getIncludePath());

2421 Printer.printString("apinotes", N->getAPINotesFile());

2422 Printer.printMetadata("file", N->getRawFile());

2423 Printer.printInt("line", N->getLineNo());

2424 Printer.printBool("isDecl", N->getIsDecl(), false);

2425 Out << ")";

2426}

2427

2430 AsmWriterContext &WriterCtx) {

2431 Out << "!DITemplateTypeParameter(";

2432 MDFieldPrinter Printer(Out, WriterCtx);

2433 Printer.printString("name", N->getName());

2434 Printer.printMetadata("type", N->getRawType(), false);

2435 Printer.printBool("defaulted", N->isDefault(), false);

2436 Out << ")";

2437}

2438

2441 AsmWriterContext &WriterCtx) {

2442 Out << "!DITemplateValueParameter(";

2443 MDFieldPrinter Printer(Out, WriterCtx);

2444 if (N->getTag() != dwarf::DW_TAG_template_value_parameter)

2446 Printer.printString("name", N->getName());

2447 Printer.printMetadata("type", N->getRawType());

2448 Printer.printBool("defaulted", N->isDefault(), false);

2449 Printer.printMetadata("value", N->getValue(), false);

2450 Out << ")";

2451}

2452

2454 AsmWriterContext &WriterCtx) {

2455 Out << "!DIGlobalVariable(";

2456 MDFieldPrinter Printer(Out, WriterCtx);

2457 Printer.printString("name", N->getName());

2458 Printer.printString("linkageName", N->getLinkageName());

2459 Printer.printMetadata("scope", N->getRawScope(), false);

2460 Printer.printMetadata("file", N->getRawFile());

2461 Printer.printInt("line", N->getLine());

2462 Printer.printMetadata("type", N->getRawType());

2463 Printer.printBool("isLocal", N->isLocalToUnit());

2464 Printer.printBool("isDefinition", N->isDefinition());

2465 Printer.printMetadata("declaration", N->getRawStaticDataMemberDeclaration());

2466 Printer.printMetadata("templateParams", N->getRawTemplateParams());

2467 Printer.printInt("align", N->getAlignInBits());

2468 Printer.printMetadata("annotations", N->getRawAnnotations());

2469 Out << ")";

2470}

2471

2473 AsmWriterContext &WriterCtx) {

2474 Out << "!DILocalVariable(";

2475 MDFieldPrinter Printer(Out, WriterCtx);

2476 Printer.printString("name", N->getName());

2477 Printer.printInt("arg", N->getArg());

2478 Printer.printMetadata("scope", N->getRawScope(), false);

2479 Printer.printMetadata("file", N->getRawFile());

2480 Printer.printInt("line", N->getLine());

2481 Printer.printMetadata("type", N->getRawType());

2482 Printer.printDIFlags("flags", N->getFlags());

2483 Printer.printInt("align", N->getAlignInBits());

2484 Printer.printMetadata("annotations", N->getRawAnnotations());

2485 Out << ")";

2486}

2487

2489 AsmWriterContext &WriterCtx) {

2490 Out << "!DILabel(";

2491 MDFieldPrinter Printer(Out, WriterCtx);

2492 Printer.printMetadata("scope", N->getRawScope(), false);

2493 Printer.printString("name", N->getName());

2494 Printer.printMetadata("file", N->getRawFile());

2495 Printer.printInt("line", N->getLine());

2496 Out << ")";

2497}

2498

2500 AsmWriterContext &WriterCtx) {

2501 Out << "!DIExpression(";

2502 FieldSeparator FS;

2503 if (N->isValid()) {

2506 assert(!OpStr.empty() && "Expected valid opcode");

2507

2508 Out << FS << OpStr;

2510 Out << FS << Op.getArg(0);

2512 } else {

2513 for (unsigned A = 0, AE = Op.getNumArgs(); A != AE; ++A)

2514 Out << FS << Op.getArg(A);

2515 }

2516 }

2517 } else {

2518 for (const auto &I : N->getElements())

2519 Out << FS << I;

2520 }

2521 Out << ")";

2522}

2523

2525 AsmWriterContext &WriterCtx,

2526 bool FromValue = false) {

2528 "Unexpected DIArgList metadata outside of value argument");

2529 Out << "!DIArgList(";

2530 FieldSeparator FS;

2531 MDFieldPrinter Printer(Out, WriterCtx);

2532 for (Metadata *Arg : N->getArgs()) {

2533 Out << FS;

2535 }

2536 Out << ")";

2537}

2538

2541 AsmWriterContext &WriterCtx) {

2542 Out << "!DIGlobalVariableExpression(";

2543 MDFieldPrinter Printer(Out, WriterCtx);

2544 Printer.printMetadata("var", N->getVariable());

2545 Printer.printMetadata("expr", N->getExpression());

2546 Out << ")";

2547}

2548

2550 AsmWriterContext &WriterCtx) {

2551 Out << "!DIObjCProperty(";

2552 MDFieldPrinter Printer(Out, WriterCtx);

2553 Printer.printString("name", N->getName());

2554 Printer.printMetadata("file", N->getRawFile());

2555 Printer.printInt("line", N->getLine());

2556 Printer.printString("setter", N->getSetterName());

2557 Printer.printString("getter", N->getGetterName());

2558 Printer.printInt("attributes", N->getAttributes());

2559 Printer.printMetadata("type", N->getRawType());

2560 Out << ")";

2561}

2562

2564 AsmWriterContext &WriterCtx) {

2565 Out << "!DIImportedEntity(";

2566 MDFieldPrinter Printer(Out, WriterCtx);

2568 Printer.printString("name", N->getName());

2569 Printer.printMetadata("scope", N->getRawScope(), false);

2570 Printer.printMetadata("entity", N->getRawEntity());

2571 Printer.printMetadata("file", N->getRawFile());

2572 Printer.printInt("line", N->getLine());

2573 Printer.printMetadata("elements", N->getRawElements());

2574 Out << ")";

2575}

2576

2578 AsmWriterContext &Ctx) {

2579 if (Node->isDistinct())

2580 Out << "distinct ";

2581 else if (Node->isTemporary())

2582 Out << "<temporary!> ";

2583

2584 switch (Node->getMetadataID()) {

2585 default:

2587#define HANDLE_MDNODE_LEAF(CLASS) \

2588 case Metadata::CLASS##Kind: \

2589 write##CLASS(Out, cast(Node), Ctx); \

2590 break;

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

2592 }

2593}

2594

2595

2596

2598 AsmWriterContext &WriterCtx) {

2599 if (V->hasName()) {

2601 return;

2602 }

2603

2604 const Constant *CV = dyn_cast(V);

2605 if (CV && !isa(CV)) {

2606 assert(WriterCtx.TypePrinter && "Constants require TypePrinting!");

2608 return;

2609 }

2610

2611 if (const InlineAsm *IA = dyn_cast(V)) {

2612 Out << "asm ";

2613 if (IA->hasSideEffects())

2614 Out << "sideeffect ";

2615 if (IA->isAlignStack())

2616 Out << "alignstack ";

2617

2619 Out << "inteldialect ";

2620 if (IA->canThrow())

2621 Out << "unwind ";

2622 Out << '"';

2623 printEscapedString(IA->getAsmString(), Out);

2624 Out << "\", \"";

2625 printEscapedString(IA->getConstraintString(), Out);

2626 Out << '"';

2627 return;

2628 }

2629

2630 if (auto *MD = dyn_cast(V)) {

2632 true);

2633 return;

2634 }

2635

2636 char Prefix = '%';

2637 int Slot;

2638 auto *Machine = WriterCtx.Machine;

2639

2641 if (const GlobalValue *GV = dyn_cast(V)) {

2642 Slot = Machine->getGlobalSlot(GV);

2643 Prefix = '@';

2644 } else {

2645 Slot = Machine->getLocalSlot(V);

2646

2647

2648

2649

2650 if (Slot == -1)

2652 Slot = Machine->getLocalSlot(V);

2654 }

2655 }

2657

2658 if (const GlobalValue *GV = dyn_cast(V)) {

2659 Slot = Machine->getGlobalSlot(GV);

2660 Prefix = '@';

2661 } else {

2662 Slot = Machine->getLocalSlot(V);

2663 }

2666 } else {

2667 Slot = -1;

2668 }

2669

2670 if (Slot != -1)

2671 Out << Prefix << Slot;

2672 else

2673 Out << "";

2674}

2675

2677 AsmWriterContext &WriterCtx,

2678 bool FromValue) {

2679

2680

2681 if (const DIExpression *Expr = dyn_cast(MD)) {

2683 return;

2684 }

2685 if (const DIArgList *ArgList = dyn_cast(MD)) {

2687 return;

2688 }

2689

2690 if (const MDNode *N = dyn_cast(MD)) {

2691 std::unique_ptr MachineStorage;

2693 if (!WriterCtx.Machine) {

2694 MachineStorage = std::make_unique(WriterCtx.Context);

2695 WriterCtx.Machine = MachineStorage.get();

2696 }

2697 int Slot = WriterCtx.Machine->getMetadataSlot(N);

2698 if (Slot == -1) {

2699 if (const DILocation *Loc = dyn_cast(N)) {

2701 return;

2702 }

2703

2704

2705 Out << "<" << N << ">";

2706 } else

2707 Out << '!' << Slot;

2708 return;

2709 }

2710

2711 if (const MDString *MDS = dyn_cast(MD)) {

2712 Out << "!\"";

2713 printEscapedString(MDS->getString(), Out);

2714 Out << '"';

2715 return;

2716 }

2717

2718 auto *V = cast(MD);

2719 assert(WriterCtx.TypePrinter && "TypePrinter required for metadata values");

2720 assert((FromValue || !isa(V)) &&

2721 "Unexpected function-local metadata outside of value argument");

2722

2723 WriterCtx.TypePrinter->print(V->getValue()->getType(), Out);

2724 Out << ' ';

2726}

2727

2728namespace {

2729

2730class AssemblyWriter {

2732 const Module *TheModule = nullptr;

2734 std::unique_ptr SlotTrackerStorage;

2736 TypePrinting TypePrinter;

2739 bool IsForDebug;

2740 bool ShouldPreserveUseListOrder;

2743

2746

2747public:

2748

2751 bool ShouldPreserveUseListOrder = false);

2752

2755

2756 AsmWriterContext getContext() {

2757 return AsmWriterContext(&TypePrinter, &Machine, TheModule);

2758 }

2759

2760 void printMDNodeBody(const MDNode *MD);

2761 void printNamedMDNode(const NamedMDNode *NMD);

2762

2763 void printModule(const Module *M);

2764

2765 void writeOperand(const Value *Op, bool PrintType);

2766 void writeParamOperand(const Value *Operand, AttributeSet Attrs);

2767 void writeOperandBundles(const CallBase *Call);

2768 void writeSyncScope(const LLVMContext &Context,

2770 void writeAtomic(const LLVMContext &Context,

2773 void writeAtomicCmpXchg(const LLVMContext &Context,

2777

2778 void writeAllMDNodes();

2779 void writeMDNode(unsigned Slot, const MDNode *Node);

2780 void writeAttribute(const Attribute &Attr, bool InAttrGroup = false);

2781 void writeAttributeSet(const AttributeSet &AttrSet, bool InAttrGroup = false);

2782 void writeAllAttributeGroups();

2783

2784 void printTypeIdentities();

2788 void printComdat(const Comdat *C);

2789 void printFunction(const Function *F);

2791 void printBasicBlock(const BasicBlock *BB);

2792 void printInstructionLine(const Instruction &I);

2793 void printInstruction(const Instruction &I);

2794 void printDbgMarker(const DbgMarker &DPI);

2796 void printDbgLabelRecord(const DbgLabelRecord &DLR);

2797 void printDbgRecord(const DbgRecord &DR);

2798 void printDbgRecordLine(const DbgRecord &DR);

2799

2800 void printUseListOrder(const Value *V, const std::vector &Shuffle);

2801 void printUseLists(const Function *F);

2802

2803 void printModuleSummaryIndex();

2804 void printSummaryInfo(unsigned Slot, const ValueInfo &VI);

2806 void printAliasSummary(const AliasSummary *AS);

2809 void printTypeIdSummary(const TypeIdSummary &TIS);

2812 void printArgs(const std::vector<uint64_t> &Args);

2816 void

2817 printNonConstVCalls(const std::vectorFunctionSummary::VFuncId &VCallList,

2818 const char *Tag);

2819 void

2820 printConstVCalls(const std::vectorFunctionSummary::ConstVCall &VCallList,

2821 const char *Tag);

2822

2823private:

2824

2825 void printMetadataAttachments(

2826 const SmallVectorImpl<std::pair<unsigned, MDNode *>> &MDs,

2828

2829

2830

2831 void printInfoComment(const Value &V);

2832

2833

2834

2835 void printGCRelocateComment(const GCRelocateInst &Relocate);

2836};

2837

2838}

2839

2842 bool IsForDebug, bool ShouldPreserveUseListOrder)

2843 : Out(o), TheModule(M), Machine(Mac), TypePrinter(M), AnnotationWriter(AAW),

2844 IsForDebug(IsForDebug),

2845 ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) {

2846 if (!TheModule)

2847 return;

2848 for (const GlobalObject &GO : TheModule->global_objects())

2850 Comdats.insert(C);

2851}

2852

2855 : Out(o), TheIndex(Index), Machine(Mac), TypePrinter(nullptr),

2856 IsForDebug(IsForDebug), ShouldPreserveUseListOrder(false) {}

2857

2858void AssemblyWriter::writeOperand(const Value *Operand, bool PrintType) {

2859 if (!Operand) {

2860 Out << "<null operand!>";

2861 return;

2862 }

2863 if (PrintType) {

2864 TypePrinter.print(Operand->getType(), Out);

2865 Out << ' ';

2866 }

2867 auto WriterCtx = getContext();

2869}

2870

2871void AssemblyWriter::writeSyncScope(const LLVMContext &Context,

2873 switch (SSID) {

2875 break;

2876 }

2877 default: {

2878 if (SSNs.empty())

2880

2881 Out << " syncscope(\"";

2882 printEscapedString(SSNs[SSID], Out);

2883 Out << "\")";

2884 break;

2885 }

2886 }

2887}

2888

2889void AssemblyWriter::writeAtomic(const LLVMContext &Context,

2892 if (Ordering == AtomicOrdering::NotAtomic)

2893 return;

2894

2895 writeSyncScope(Context, SSID);

2897}

2898

2899void AssemblyWriter::writeAtomicCmpXchg(const LLVMContext &Context,

2903 assert(SuccessOrdering != AtomicOrdering::NotAtomic &&

2904 FailureOrdering != AtomicOrdering::NotAtomic);

2905

2906 writeSyncScope(Context, SSID);

2907 Out << " " << toIRString(SuccessOrdering);

2908 Out << " " << toIRString(FailureOrdering);

2909}

2910

2911void AssemblyWriter::writeParamOperand(const Value *Operand,

2913 if (!Operand) {

2914 Out << "<null operand!>";

2915 return;

2916 }

2917

2918

2919 TypePrinter.print(Operand->getType(), Out);

2920

2921 if (Attrs.hasAttributes()) {

2922 Out << ' ';

2923 writeAttributeSet(Attrs);

2924 }

2925 Out << ' ';

2926

2927 auto WriterCtx = getContext();

2929}

2930

2931void AssemblyWriter::writeOperandBundles(const CallBase *Call) {

2932 if (Call->hasOperandBundles())

2933 return;

2934

2935 Out << " [ ";

2936

2937 bool FirstBundle = true;

2938 for (unsigned i = 0, e = Call->getNumOperandBundles(); i != e; ++i) {

2940

2941 if (!FirstBundle)

2942 Out << ", ";

2943 FirstBundle = false;

2944

2945 Out << '"';

2946 printEscapedString(BU.getTagName(), Out);

2947 Out << '"';

2948

2949 Out << '(';

2950

2951 bool FirstInput = true;

2952 auto WriterCtx = getContext();

2953 for (const auto &Input : BU.Inputs) {

2954 if (!FirstInput)

2955 Out << ", ";

2956 FirstInput = false;

2957

2958 if (Input == nullptr)

2959 Out << "<null operand bundle!>";

2960 else {

2961 TypePrinter.print(Input->getType(), Out);

2962 Out << " ";

2964 }

2965 }

2966

2967 Out << ')';

2968 }

2969

2970 Out << " ]";

2971}

2972

2973void AssemblyWriter::printModule(const Module *M) {

2974 Machine.initializeIfNeeded();

2975

2976 if (ShouldPreserveUseListOrder)

2978

2979 if (M->getModuleIdentifier().empty() &&

2980

2981

2982 M->getModuleIdentifier().find('\n') == std:🧵:npos)

2983 Out << "; ModuleID = '" << M->getModuleIdentifier() << "'\n";

2984

2985 if (M->getSourceFileName().empty()) {

2986 Out << "source_filename = \"";

2987 printEscapedString(M->getSourceFileName(), Out);

2988 Out << "\"\n";

2989 }

2990

2991 const std::string &DL = M->getDataLayoutStr();

2993 Out << "target datalayout = \"" << DL << "\"\n";

2994 if (M->getTargetTriple().empty())

2995 Out << "target triple = \"" << M->getTargetTriple() << "\"\n";

2996

2997 if (M->getModuleInlineAsm().empty()) {

2998 Out << '\n';

2999

3000

3002 do {

3004 std::tie(Front, Asm) = Asm.split('\n');

3005

3006

3007

3008 Out << "module asm \"";

3009 printEscapedString(Front, Out);

3010 Out << "\"\n";

3011 } while (Asm.empty());

3012 }

3013

3014 printTypeIdentities();

3015

3016

3017 if (!Comdats.empty())

3018 Out << '\n';

3019 for (const Comdat *C : Comdats) {

3020 printComdat(C);

3021 if (C != Comdats.back())

3022 Out << '\n';

3023 }

3024

3025

3026 if (M->global_empty()) Out << '\n';

3028 printGlobal(&GV); Out << '\n';

3029 }

3030

3031

3032 if (M->alias_empty()) Out << "\n";

3034 printAlias(&GA);

3035

3036

3037 if (M->ifunc_empty()) Out << "\n";

3039 printIFunc(&GI);

3040

3041

3043 Out << '\n';

3044 printFunction(&F);

3045 }

3046

3047

3048 printUseLists(nullptr);

3049

3050

3051 if (Machine.as_empty()) {

3052 Out << '\n';

3053 writeAllAttributeGroups();

3054 }

3055

3056

3057 if (M->named_metadata_empty()) Out << '\n';

3058

3060 printNamedMDNode(&Node);

3061

3062

3063 if (Machine.mdn_empty()) {

3064 Out << '\n';

3065 writeAllMDNodes();

3066 }

3067}

3068

3069void AssemblyWriter::printModuleSummaryIndex() {

3071 int NumSlots = Machine.initializeIndexIfNeeded();

3072

3073 Out << "\n";

3074

3075

3076

3077 std::vector<std::pair<std::string, ModuleHash>> moduleVec;

3078 std::string RegularLTOModuleName =

3080 moduleVec.resize(TheIndex->modulePaths().size());

3081 for (auto &[ModPath, ModHash] : TheIndex->modulePaths())

3082 moduleVec[Machine.getModulePathSlot(ModPath)] = std::make_pair(

3083

3084

3085 ModPath.empty() ? RegularLTOModuleName : std::string(ModPath), ModHash);

3086

3087 unsigned i = 0;

3088 for (auto &ModPair : moduleVec) {

3089 Out << "^" << i++ << " = module: (";

3090 Out << "path: \"";

3091 printEscapedString(ModPair.first, Out);

3092 Out << "\", hash: (";

3093 FieldSeparator FS;

3094 for (auto Hash : ModPair.second)

3095 Out << FS << Hash;

3096 Out << "))\n";

3097 }

3098

3099

3100

3101 for (auto &GlobalList : *TheIndex) {

3102 auto GUID = GlobalList.first;

3103 for (auto &Summary : GlobalList.second.SummaryList)

3105 }

3106

3107

3108 for (auto &GlobalList : *TheIndex) {

3109 auto GUID = GlobalList.first;

3110 auto VI = TheIndex->getValueInfo(GlobalList);

3111 printSummaryInfo(Machine.getGUIDSlot(GUID), VI);

3112 }

3113

3114

3115 for (const auto &TID : TheIndex->typeIds()) {

3116 Out << "^" << Machine.getTypeIdSlot(TID.second.first)

3117 << " = typeid: (name: \"" << TID.second.first << "\"";

3118 printTypeIdSummary(TID.second.second);

3119 Out << ") ; guid = " << TID.first << "\n";

3120 }

3121

3122

3123 for (auto &TId : TheIndex->typeIdCompatibleVtableMap()) {

3125 Out << "^" << Machine.getTypeIdCompatibleVtableSlot(TId.first)

3126 << " = typeidCompatibleVTable: (name: \"" << TId.first << "\"";

3127 printTypeIdCompatibleVtableSummary(TId.second);

3128 Out << ") ; guid = " << GUID << "\n";

3129 }

3130

3131

3132 if (TheIndex->getFlags()) {

3133 Out << "^" << NumSlots << " = flags: " << TheIndex->getFlags() << "\n";

3134 ++NumSlots;

3135 }

3136

3137 Out << "^" << NumSlots << " = blockcount: " << TheIndex->getBlockCount()

3138 << "\n";

3139}

3140

3141static const char *

3143 switch (K) {

3145 return "indir";

3147 return "singleImpl";

3149 return "branchFunnel";

3150 }

3151 llvm_unreachable("invalid WholeProgramDevirtResolution kind");

3152}

3153

3156 switch (K) {

3158 return "indir";

3160 return "uniformRetVal";

3162 return "uniqueRetVal";

3164 return "virtualConstProp";

3165 }

3166 llvm_unreachable("invalid WholeProgramDevirtResolution::ByArg kind");

3167}

3168

3170 switch (K) {

3172 return "unknown";

3174 return "unsat";

3176 return "byteArray";

3178 return "inline";

3180 return "single";

3182 return "allOnes";

3183 }

3185}

3186

3187void AssemblyWriter::printTypeTestResolution(const TypeTestResolution &TTRes) {

3190

3191

3192

3194 Out << ", alignLog2: " << TTRes.AlignLog2;

3196 Out << ", sizeM1: " << TTRes.SizeM1;

3198

3201 Out << ", inlineBits: " << TTRes.InlineBits;

3202

3203 Out << ")";

3204}

3205

3206void AssemblyWriter::printTypeIdSummary(const TypeIdSummary &TIS) {

3207 Out << ", summary: (";

3208 printTypeTestResolution(TIS.TTRes);

3209 if (!TIS.WPDRes.empty()) {

3210 Out << ", wpdResolutions: (";

3211 FieldSeparator FS;

3212 for (auto &WPDRes : TIS.WPDRes) {

3213 Out << FS;

3214 Out << "(offset: " << WPDRes.first << ", ";

3215 printWPDRes(WPDRes.second);

3216 Out << ")";

3217 }

3218 Out << ")";

3219 }

3220 Out << ")";

3221}

3222

3223void AssemblyWriter::printTypeIdCompatibleVtableSummary(

3225 Out << ", summary: (";

3226 FieldSeparator FS;

3227 for (auto &P : TI) {

3228 Out << FS;

3229 Out << "(offset: " << P.AddressPointOffset << ", ";

3230 Out << "^" << Machine.getGUIDSlot(P.VTableVI.getGUID());

3231 Out << ")";

3232 }

3233 Out << ")";

3234}

3235

3236void AssemblyWriter::printArgs(const std::vector<uint64_t> &Args) {

3237 Out << "args: (";

3238 FieldSeparator FS;

3239 for (auto arg : Args) {

3240 Out << FS;

3241 Out << arg;

3242 }

3243 Out << ")";

3244}

3245

3247 Out << "wpdRes: (kind: ";

3249

3251 Out << ", singleImplName: \"" << WPDRes.SingleImplName << "\"";

3252

3253 if (!WPDRes.ResByArg.empty()) {

3254 Out << ", resByArg: (";

3255 FieldSeparator FS;

3256 for (auto &ResByArg : WPDRes.ResByArg) {

3257 Out << FS;

3258 printArgs(ResByArg.first);

3259 Out << ", byArg: (kind: ";

3261 if (ResByArg.second.TheKind ==

3263 ResByArg.second.TheKind ==

3265 Out << ", info: " << ResByArg.second.Info;

3266

3267

3268

3269 if (ResByArg.second.Byte || ResByArg.second.Bit)

3270 Out << ", byte: " << ResByArg.second.Byte

3271 << ", bit: " << ResByArg.second.Bit;

3272

3273 Out << ")";

3274 }

3275 Out << ")";

3276 }

3277 Out << ")";

3278}

3279

3281 switch (SK) {

3283 return "alias";

3285 return "function";

3287 return "variable";

3288 }

3290}

3291

3292void AssemblyWriter::printAliasSummary(const AliasSummary *AS) {

3293 Out << ", aliasee: ";

3294

3295

3296

3298 Out << "^" << Machine.getGUIDSlot(SummaryToGUIDMap[&AS->getAliasee()]);

3299 else

3300 Out << "null";

3301}

3302

3303void AssemblyWriter::printGlobalVarSummary(const GlobalVarSummary *GS) {

3304 auto VTableFuncs = GS->vTableFuncs();

3305 Out << ", varFlags: (readonly: " << GS->VarFlags.MaybeReadOnly << ", "

3306 << "writeonly: " << GS->VarFlags.MaybeWriteOnly << ", "

3307 << "constant: " << GS->VarFlags.Constant;

3308 if (!VTableFuncs.empty())

3309 Out << ", "

3310 << "vcall_visibility: " << GS->VarFlags.VCallVisibility;

3311 Out << ")";

3312

3313 if (!VTableFuncs.empty()) {

3314 Out << ", vTableFuncs: (";

3315 FieldSeparator FS;

3316 for (auto &P : VTableFuncs) {

3317 Out << FS;

3318 Out << "(virtFunc: ^" << Machine.getGUIDSlot(P.FuncVI.getGUID())

3319 << ", offset: " << P.VTableOffset;

3320 Out << ")";

3321 }

3322 Out << ")";

3323 }

3324}

3325

3327 switch (LT) {

3329 return "external";

3331 return "private";

3333 return "internal";

3335 return "linkonce";

3337 return "linkonce_odr";

3339 return "weak";

3341 return "weak_odr";

3343 return "common";

3345 return "appending";

3347 return "extern_weak";

3349 return "available_externally";

3350 }

3352}

3353

3354

3355

3356

3359 return "";

3361}

3362

3364 switch (Vis) {

3366 return "default";

3368 return "hidden";

3370 return "protected";

3371 }

3373}

3374

3376 switch (IK) {

3378 return "definition";

3380 return "declaration";

3381 }

3383}

3384

3385void AssemblyWriter::printFunctionSummary(const FunctionSummary *FS) {

3386 Out << ", insts: " << FS->instCount();

3387 if (FS->fflags().anyFlagSet())

3388 Out << ", " << FS->fflags();

3389

3390 if (FS->calls().empty()) {

3391 Out << ", calls: (";

3392 FieldSeparator IFS;

3393 for (auto &Call : FS->calls()) {

3394 Out << IFS;

3395 Out << "(callee: ^" << Machine.getGUIDSlot(Call.first.getGUID());

3396 if (Call.second.getHotness() != CalleeInfo::HotnessType::Unknown)

3398 else if (Call.second.RelBlockFreq)

3399 Out << ", relbf: " << Call.second.RelBlockFreq;

3400

3401

3402 if (Call.second.HasTailCall)

3403 Out << ", tail: 1";

3404 Out << ")";

3405 }

3406 Out << ")";

3407 }

3408

3409 if (const auto *TIdInfo = FS->getTypeIdInfo())

3410 printTypeIdInfo(*TIdInfo);

3411

3412

3413

3414 auto AllocTypeName = [](uint8_t Type) -> const char * {

3415 switch (Type) {

3416 case (uint8_t)AllocationType::None:

3417 return "none";

3418 case (uint8_t)AllocationType::NotCold:

3419 return "notcold";

3420 case (uint8_t)AllocationType::Cold:

3421 return "cold";

3422 case (uint8_t)AllocationType::Hot:

3423 return "hot";

3424 }

3426 };

3427

3428 if (FS->allocs().empty()) {

3429 Out << ", allocs: (";

3430 FieldSeparator AFS;

3431 for (auto &AI : FS->allocs()) {

3432 Out << AFS;

3433 Out << "(versions: (";

3434 FieldSeparator VFS;

3435 for (auto V : AI.Versions) {

3436 Out << VFS;

3437 Out << AllocTypeName(V);

3438 }

3439 Out << "), memProf: (";

3440 FieldSeparator MIBFS;

3441 for (auto &MIB : AI.MIBs) {

3442 Out << MIBFS;

3443 Out << "(type: " << AllocTypeName((uint8_t)MIB.AllocType);

3444 Out << ", stackIds: (";

3445 FieldSeparator SIDFS;

3446 for (auto Id : MIB.StackIdIndices) {

3447 Out << SIDFS;

3448 Out << TheIndex->getStackIdAtIndex(Id);

3449 }

3450 Out << "))";

3451 }

3452 Out << "))";

3453 }

3454 Out << ")";

3455 }

3456

3457 if (FS->callsites().empty()) {

3458 Out << ", callsites: (";

3459 FieldSeparator SNFS;

3460 for (auto &CI : FS->callsites()) {

3461 Out << SNFS;

3462 if (CI.Callee)

3463 Out << "(callee: ^" << Machine.getGUIDSlot(CI.Callee.getGUID());

3464 else

3465 Out << "(callee: null";

3466 Out << ", clones: (";

3467 FieldSeparator VFS;

3468 for (auto V : CI.Clones) {

3469 Out << VFS;

3470 Out << V;

3471 }

3472 Out << "), stackIds: (";

3473 FieldSeparator SIDFS;

3474 for (auto Id : CI.StackIdIndices) {

3475 Out << SIDFS;

3476 Out << TheIndex->getStackIdAtIndex(Id);

3477 }

3478 Out << "))";

3479 }

3480 Out << ")";

3481 }

3482

3485 };

3486

3487 if (FS->paramAccesses().empty()) {

3488 Out << ", params: (";

3489 FieldSeparator IFS;

3490 for (auto &PS : FS->paramAccesses()) {

3491 Out << IFS;

3492 Out << "(param: " << PS.ParamNo;

3493 Out << ", offset: ";

3494 PrintRange(PS.Use);

3495 if (!PS.Calls.empty()) {

3496 Out << ", calls: (";

3497 FieldSeparator IFS;

3498 for (auto &Call : PS.Calls) {

3499 Out << IFS;

3500 Out << "(callee: ^" << Machine.getGUIDSlot(Call.Callee.getGUID());

3501 Out << ", param: " << Call.ParamNo;

3502 Out << ", offset: ";

3503 PrintRange(Call.Offsets);

3504 Out << ")";

3505 }

3506 Out << ")";

3507 }

3508 Out << ")";

3509 }

3510 Out << ")";

3511 }

3512}

3513

3514void AssemblyWriter::printTypeIdInfo(

3516 Out << ", typeIdInfo: (";

3517 FieldSeparator TIDFS;

3518 if (!TIDInfo.TypeTests.empty()) {

3519 Out << TIDFS;

3520 Out << "typeTests: (";

3521 FieldSeparator FS;

3522 for (auto &GUID : TIDInfo.TypeTests) {

3523 auto TidIter = TheIndex->typeIds().equal_range(GUID);

3524 if (TidIter.first == TidIter.second) {

3525 Out << FS;

3526 Out << GUID;

3527 continue;

3528 }

3529

3530 for (const auto &[GUID, TypeIdPair] : make_range(TidIter)) {

3531 Out << FS;

3532 auto Slot = Machine.getTypeIdSlot(TypeIdPair.first);

3534 Out << "^" << Slot;

3535 }

3536 }

3537 Out << ")";

3538 }

3540 Out << TIDFS;

3542 }

3544 Out << TIDFS;

3546 }

3548 Out << TIDFS;

3550 "typeTestAssumeConstVCalls");

3551 }

3553 Out << TIDFS;

3555 "typeCheckedLoadConstVCalls");

3556 }

3557 Out << ")";

3558}

3559

3561 auto TidIter = TheIndex->typeIds().equal_range(VFId.GUID);

3562 if (TidIter.first == TidIter.second) {

3563 Out << "vFuncId: (";

3564 Out << "guid: " << VFId.GUID;

3565 Out << ", offset: " << VFId.Offset;

3566 Out << ")";

3567 return;

3568 }

3569

3570 FieldSeparator FS;

3571 for (const auto &[GUID, TypeIdPair] : make_range(TidIter)) {

3572 Out << FS;

3573 Out << "vFuncId: (";

3574 auto Slot = Machine.getTypeIdSlot(TypeIdPair.first);

3576 Out << "^" << Slot;

3577 Out << ", offset: " << VFId.Offset;

3578 Out << ")";

3579 }

3580}

3581

3582void AssemblyWriter::printNonConstVCalls(

3583 const std::vectorFunctionSummary::VFuncId &VCallList, const char *Tag) {

3584 Out << Tag << ": (";

3585 FieldSeparator FS;

3586 for (auto &VFuncId : VCallList) {

3587 Out << FS;

3588 printVFuncId(VFuncId);

3589 }

3590 Out << ")";

3591}

3592

3593void AssemblyWriter::printConstVCalls(

3594 const std::vectorFunctionSummary::ConstVCall &VCallList,

3595 const char *Tag) {

3596 Out << Tag << ": (";

3597 FieldSeparator FS;

3598 for (auto &ConstVCall : VCallList) {

3599 Out << FS;

3600 Out << "(";

3601 printVFuncId(ConstVCall.VFunc);

3602 if (!ConstVCall.Args.empty()) {

3603 Out << ", ";

3604 printArgs(ConstVCall.Args);

3605 }

3606 Out << ")";

3607 }

3608 Out << ")";

3609}

3610

3611void AssemblyWriter::printSummary(const GlobalValueSummary &Summary) {

3615 Out << "(module: ^" << Machine.getModulePathSlot(Summary.modulePath())

3616 << ", flags: (";

3618 Out << ", visibility: "

3621 Out << ", live: " << GVFlags.Live;

3622 Out << ", dsoLocal: " << GVFlags.DSOLocal;

3623 Out << ", canAutoHide: " << GVFlags.CanAutoHide;

3624 Out << ", importType: "

3626 Out << ")";

3627

3629 printAliasSummary(cast(&Summary));

3631 printFunctionSummary(cast(&Summary));

3632 else

3633 printGlobalVarSummary(cast(&Summary));

3634

3635 auto RefList = Summary.refs();

3636 if (!RefList.empty()) {

3637 Out << ", refs: (";

3638 FieldSeparator FS;

3639 for (auto &Ref : RefList) {

3640 Out << FS;

3641 if (Ref.isReadOnly())

3642 Out << "readonly ";

3643 else if (Ref.isWriteOnly())

3644 Out << "writeonly ";

3645 Out << "^" << Machine.getGUIDSlot(Ref.getGUID());

3646 }

3647 Out << ")";

3648 }

3649

3650 Out << ")";

3651}

3652

3653void AssemblyWriter::printSummaryInfo(unsigned Slot, const ValueInfo &VI) {

3654 Out << "^" << Slot << " = gv: (";

3655 if (VI.hasName() && VI.name().empty())

3656 Out << "name: \"" << VI.name() << "\"";

3657 else

3658 Out << "guid: " << VI.getGUID();

3659 if (VI.getSummaryList().empty()) {

3660 Out << ", summaries: (";

3661 FieldSeparator FS;

3662 for (auto &Summary : VI.getSummaryList()) {

3663 Out << FS;

3664 printSummary(*Summary);

3665 }

3666 Out << ")";

3667 }

3668 Out << ")";

3669 if (VI.hasName() && VI.name().empty())

3670 Out << " ; guid = " << VI.getGUID();

3671 Out << "\n";

3672}

3673

3676 if (Name.empty()) {

3677 Out << " ";

3678 } else {

3679 unsigned char FirstC = static_cast<unsigned char>(Name[0]);

3680 if (isalpha(FirstC) || FirstC == '-' || FirstC == '$' || FirstC == '.' ||

3681 FirstC == '_')

3682 Out << FirstC;

3683 else

3684 Out << '\\' << hexdigit(FirstC >> 4) << hexdigit(FirstC & 0x0F);

3685 for (unsigned i = 1, e = Name.size(); i != e; ++i) {

3686 unsigned char C = Name[i];

3687 if (isalnum(C) || C == '-' || C == '$' || C == '.' || C == '_')

3688 Out << C;

3689 else

3690 Out << '\\' << hexdigit(C >> 4) << hexdigit(C & 0x0F);

3691 }

3692 }

3693}

3694

3695void AssemblyWriter::printNamedMDNode(const NamedMDNode *NMD) {

3696 Out << '!';

3698 Out << " = !{";

3699 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {

3700 if (i)

3701 Out << ", ";

3702

3703

3704

3706 if (auto *Expr = dyn_cast(Op)) {

3708 continue;

3709 }

3710

3712 if (Slot == -1)

3713 Out << "";

3714 else

3715 Out << '!' << Slot;

3716 }

3717 Out << "}\n";

3718}

3719

3722 switch (Vis) {

3726 }

3727}

3728

3732 Out << "dso_local ";

3733}

3734

3737 switch (SCT) {

3741 }

3742}

3743

3746 switch (TLM) {

3747 case GlobalVariable::NotThreadLocal:

3748 break;

3749 case GlobalVariable::GeneralDynamicTLSModel:

3750 Out << "thread_local ";

3751 break;

3752 case GlobalVariable::LocalDynamicTLSModel:

3753 Out << "thread_local(localdynamic) ";

3754 break;

3755 case GlobalVariable::InitialExecTLSModel:

3756 Out << "thread_local(initialexec) ";

3757 break;

3758 case GlobalVariable::LocalExecTLSModel:

3759 Out << "thread_local(localexec) ";

3760 break;

3761 }

3762}

3763

3765 switch (UA) {

3766 case GlobalVariable::UnnamedAddr::None:

3767 return "";

3768 case GlobalVariable::UnnamedAddr::Local:

3769 return "local_unnamed_addr";

3770 case GlobalVariable::UnnamedAddr::Global:

3771 return "unnamed_addr";

3772 }

3774}

3775

3779 if (C)

3780 return;

3781

3782 if (isa(GO))

3783 Out << ',';

3784 Out << " comdat";

3785

3786 if (GO.getName() == C->getName())

3787 return;

3788

3789 Out << '(';

3791 Out << ')';

3792}

3793

3794void AssemblyWriter::printGlobal(const GlobalVariable *GV) {

3796 Out << "; Materializable\n";

3797

3798 AsmWriterContext WriterCtx(&TypePrinter, &Machine, GV->getParent());

3800 Out << " = ";

3801

3803 Out << "external ";

3804

3811 if (!UA.empty())

3812 Out << UA << ' ';

3813

3815 Out << "addrspace(" << AddressSpace << ") ";

3817 Out << (GV->isConstant() ? "constant " : "global ");

3819

3821 Out << ' ';

3823 }

3824

3826 Out << ", section \"";

3827 printEscapedString(GV->getSection(), Out);

3828 Out << '"';

3829 }

3831 Out << ", partition \"";

3832 printEscapedString(GV->getPartition(), Out);

3833 Out << '"';

3834 }

3836 Out << ", code_model \"";

3837 switch (*CM) {

3839 Out << "tiny";

3840 break;

3842 Out << "small";

3843 break;

3845 Out << "kernel";

3846 break;

3848 Out << "medium";

3849 break;

3851 Out << "large";

3852 break;

3853 }

3854 Out << '"';

3855 }

3856

3861 Out << ", no_sanitize_address";

3863 Out << ", no_sanitize_hwaddress";

3865 Out << ", sanitize_memtag";

3867 Out << ", sanitize_address_dyninit";

3868 }

3869

3872 Out << ", align " << A->value();

3873

3876 printMetadataAttachments(MDs, ", ");

3877

3879 if (Attrs.hasAttributes())

3880 Out << " #" << Machine.getAttributeGroupSlot(Attrs);

3881

3882 printInfoComment(*GV);

3883}

3884

3885void AssemblyWriter::printAlias(const GlobalAlias *GA) {

3887 Out << "; Materializable\n";

3888

3889 AsmWriterContext WriterCtx(&TypePrinter, &Machine, GA->getParent());

3891 Out << " = ";

3892

3899 if (!UA.empty())

3900 Out << UA << ' ';

3901

3902 Out << "alias ";

3903

3905 Out << ", ";

3906

3908 writeOperand(Aliasee, !isa(Aliasee));

3909 } else {

3910 TypePrinter.print(GA->getType(), Out);

3911 Out << " <>";

3912 }

3913

3915 Out << ", partition \"";

3916 printEscapedString(GA->getPartition(), Out);

3917 Out << '"';

3918 }

3919

3920 printInfoComment(*GA);

3921 Out << '\n';

3922}

3923

3924void AssemblyWriter::printIFunc(const GlobalIFunc *GI) {

3926 Out << "; Materializable\n";

3927

3928 AsmWriterContext WriterCtx(&TypePrinter, &Machine, GI->getParent());

3930 Out << " = ";

3931

3935

3936 Out << "ifunc ";

3937

3939 Out << ", ";

3940

3943 } else {

3944 TypePrinter.print(GI->getType(), Out);

3945 Out << " <>";

3946 }

3947

3949 Out << ", partition \"";

3950 printEscapedString(GI->getPartition(), Out);

3951 Out << '"';

3952 }

3953

3954 printInfoComment(*GI);

3955 Out << '\n';

3956}

3957

3958void AssemblyWriter::printComdat(const Comdat *C) {

3959 C->print(Out);

3960}

3961

3962void AssemblyWriter::printTypeIdentities() {

3963 if (TypePrinter.empty())

3964 return;

3965

3966 Out << '\n';

3967

3968

3969 auto &NumberedTypes = TypePrinter.getNumberedTypes();

3970 for (unsigned I = 0, E = NumberedTypes.size(); I != E; ++I) {

3971 Out << '%' << I << " = type ";

3972

3973

3974

3975 TypePrinter.printStructBody(NumberedTypes[I], Out);

3976 Out << '\n';

3977 }

3978

3979 auto &NamedTypes = TypePrinter.getNamedTypes();

3980 for (StructType *NamedType : NamedTypes) {

3982 Out << " = type ";

3983

3984

3985

3986 TypePrinter.printStructBody(NamedType, Out);

3987 Out << '\n';

3988 }

3989}

3990

3991

3992void AssemblyWriter::printFunction(const Function *F) {

3993 if (AnnotationWriter) AnnotationWriter->emitFunctionAnnot(F, Out);

3994

3995 if (F->isMaterializable())

3996 Out << "; Materializable\n";

3997

3999 if (Attrs.hasFnAttrs()) {

4001 std::string AttrStr;

4002

4003 for (const Attribute &Attr : AS) {

4004 if (!Attr.isStringAttribute()) {

4005 if (!AttrStr.empty()) AttrStr += ' ';

4006 AttrStr += Attr.getAsString();

4007 }

4008 }

4009

4010 if (!AttrStr.empty())

4011 Out << "; Function Attrs: " << AttrStr << '\n';

4012 }

4013

4014 Machine.incorporateFunction(F);

4015

4016 if (F->isDeclaration()) {

4017 Out << "declare";

4019 F->getAllMetadata(MDs);

4020 printMetadataAttachments(MDs, " ");

4021 Out << ' ';

4022 } else

4023 Out << "define ";

4024

4029

4030

4033 Out << " ";

4034 }

4035

4037 if (Attrs.hasRetAttrs())

4039 TypePrinter.print(F->getReturnType(), Out);

4040 AsmWriterContext WriterCtx(&TypePrinter, &Machine, F->getParent());

4041 Out << ' ';

4043 Out << '(';

4044

4045

4046 if (F->isDeclaration() && !IsForDebug) {

4047

4048 for (unsigned I = 0, E = FT->getNumParams(); I != E; ++I) {

4049

4050 if (I)

4051 Out << ", ";

4052

4053 TypePrinter.print(FT->getParamType(I), Out);

4054

4057 Out << ' ';

4058 writeAttributeSet(ArgAttrs);

4059 }

4060 }

4061 } else {

4062

4063 for (const Argument &Arg : F->args()) {

4064

4065 if (Arg.getArgNo() != 0)

4066 Out << ", ";

4067 printArgument(&Arg, Attrs.getParamAttrs(Arg.getArgNo()));

4068 }

4069 }

4070

4071

4072 if (FT->isVarArg()) {

4073 if (FT->getNumParams()) Out << ", ";

4074 Out << "...";

4075 }

4076 Out << ')';

4078 if (!UA.empty())

4079 Out << ' ' << UA;

4080

4081

4082

4084 if (F->getAddressSpace() != 0 || Mod ||

4085 Mod->getDataLayout().getProgramAddressSpace() != 0)

4086 Out << " addrspace(" << F->getAddressSpace() << ")";

4087 if (Attrs.hasFnAttrs())

4088 Out << " #" << Machine.getAttributeGroupSlot(Attrs.getFnAttrs());

4089 if (F->hasSection()) {

4090 Out << " section \"";

4091 printEscapedString(F->getSection(), Out);

4092 Out << '"';

4093 }

4094 if (F->hasPartition()) {

4095 Out << " partition \"";

4096 printEscapedString(F->getPartition(), Out);

4097 Out << '"';

4098 }

4101 Out << " align " << A->value();

4102 if (F->hasGC())

4103 Out << " gc \"" << F->getGC() << '"';

4104 if (F->hasPrefixData()) {

4105 Out << " prefix ";

4106 writeOperand(F->getPrefixData(), true);

4107 }

4108 if (F->hasPrologueData()) {

4109 Out << " prologue ";

4110 writeOperand(F->getPrologueData(), true);

4111 }

4112 if (F->hasPersonalityFn()) {

4113 Out << " personality ";

4114 writeOperand(F->getPersonalityFn(), true);

4115 }

4116

4117 if (F->isDeclaration()) {

4118 Out << '\n';

4119 } else {

4121 F->getAllMetadata(MDs);

4122 printMetadataAttachments(MDs, " ");

4123

4124 Out << " {";

4125

4127 printBasicBlock(&BB);

4128

4129

4130 printUseLists(F);

4131

4132 Out << "}\n";

4133 }

4134

4135 Machine.purgeFunction();

4136}

4137

4138

4139

4140void AssemblyWriter::printArgument(const Argument *Arg, AttributeSet Attrs) {

4141

4142 TypePrinter.print(Arg->getType(), Out);

4143

4144

4145 if (Attrs.hasAttributes()) {

4146 Out << ' ';

4147 writeAttributeSet(Attrs);

4148 }

4149

4150

4152 Out << ' ';

4154 } else {

4156 assert(Slot != -1 && "expect argument in function here");

4157 Out << " %" << Slot;

4158 }

4159}

4160

4161

4162void AssemblyWriter::printBasicBlock(const BasicBlock *BB) {

4164 if (BB->hasName()) {

4165 Out << "\n";

4167 Out << ':';

4168 } else if (!IsEntryBlock) {

4169 Out << "\n";

4171 if (Slot != -1)

4172 Out << Slot << ":";

4173 else

4174 Out << ":";

4175 }

4176

4177 if (!IsEntryBlock) {

4178

4179 Out.PadToColumn(50);

4180 Out << ";";

4182

4183 if (PI == PE) {

4184 Out << " No predecessors!";

4185 } else {

4186 Out << " preds = ";

4187 writeOperand(*PI, false);

4188 for (++PI; PI != PE; ++PI) {

4189 Out << ", ";

4190 writeOperand(*PI, false);

4191 }

4192 }

4193 }

4194

4195 Out << "\n";

4196

4197 if (AnnotationWriter) AnnotationWriter->emitBasicBlockStartAnnot(BB, Out);

4198

4199

4201 for (const DbgRecord &DR : I.getDbgRecordRange())

4202 printDbgRecordLine(DR);

4203 printInstructionLine(I);

4204 }

4205

4206 if (AnnotationWriter) AnnotationWriter->emitBasicBlockEndAnnot(BB, Out);

4207}

4208

4209

4210void AssemblyWriter::printInstructionLine(const Instruction &I) {

4211 printInstruction(I);

4212 Out << '\n';

4213}

4214

4215

4216

4217void AssemblyWriter::printGCRelocateComment(const GCRelocateInst &Relocate) {

4218 Out << " ; (";

4219 writeOperand(Relocate.getBasePtr(), false);

4220 Out << ", ";

4222 Out << ")";

4223}

4224

4225

4226

4227void AssemblyWriter::printInfoComment(const Value &V) {

4228 if (const auto *Relocate = dyn_cast(&V))

4229 printGCRelocateComment(*Relocate);

4230

4231 if (AnnotationWriter) {

4232 AnnotationWriter->printInfoComment(V, Out);

4233 }

4234}

4235

4238

4239 if (Operand == nullptr) {

4240 Out << " <cannot get addrspace!>";

4241 return;

4242 }

4244 bool PrintAddrSpace = CallAddrSpace != 0;

4245 if (!PrintAddrSpace) {

4247

4248

4249

4250 if (Mod || Mod->getDataLayout().getProgramAddressSpace() != 0)

4251 PrintAddrSpace = true;

4252 }

4253 if (PrintAddrSpace)

4254 Out << " addrspace(" << CallAddrSpace << ")";

4255}

4256

4257

4258void AssemblyWriter::printInstruction(const Instruction &I) {

4259 if (AnnotationWriter) AnnotationWriter->emitInstructionAnnot(&I, Out);

4260

4261

4262 Out << " ";

4263

4264

4265 if (I.hasName()) {

4267 Out << " = ";

4268 } else if (I.getType()->isVoidTy()) {

4269

4270 int SlotNum = Machine.getLocalSlot(&I);

4271 if (SlotNum == -1)

4272 Out << " = ";

4273 else

4274 Out << '%' << SlotNum << " = ";

4275 }

4276

4277 if (const CallInst *CI = dyn_cast(&I)) {

4278 if (CI->isMustTailCall())

4279 Out << "musttail ";

4280 else if (CI->isTailCall())

4281 Out << "tail ";

4282 else if (CI->isNoTailCall())

4283 Out << "notail ";

4284 }

4285

4286

4287 Out << I.getOpcodeName();

4288

4289

4290 if ((isa(I) && cast(I).isAtomic()) ||

4291 (isa(I) && cast(I).isAtomic()))

4292 Out << " atomic";

4293

4294 if (isa(I) && cast(I).isWeak())

4295 Out << " weak";

4296

4297

4298 if ((isa(I) && cast(I).isVolatile()) ||

4299 (isa(I) && cast(I).isVolatile()) ||

4300 (isa(I) && cast(I).isVolatile()) ||

4301 (isa(I) && cast(I).isVolatile()))

4302 Out << " volatile";

4303

4304

4306

4307

4308 if (const CmpInst *CI = dyn_cast(&I))

4309 Out << ' ' << CI->getPredicate();

4310

4311

4312 if (const AtomicRMWInst *RMWI = dyn_cast(&I))

4314

4315

4316 const Value *Operand = I.getNumOperands() ? I.getOperand(0) : nullptr;

4317

4318

4319 if (isa(I) && cast(I).isConditional()) {

4320 const BranchInst &BI(cast(I));

4321 Out << ' ';

4322 writeOperand(BI.getCondition(), true);

4323 Out << ", ";

4324 writeOperand(BI.getSuccessor(0), true);

4325 Out << ", ";

4326 writeOperand(BI.getSuccessor(1), true);

4327

4328 } else if (isa(I)) {

4330

4331 Out << ' ';

4332 writeOperand(SI.getCondition(), true);

4333 Out << ", ";

4334 writeOperand(SI.getDefaultDest(), true);

4335 Out << " [";

4336 for (auto Case : SI.cases()) {

4337 Out << "\n ";

4338 writeOperand(Case.getCaseValue(), true);

4339 Out << ", ";

4340 writeOperand(Case.getCaseSuccessor(), true);

4341 }

4342 Out << "\n ]";

4343 } else if (isa(I)) {

4344

4345 Out << ' ';

4346 writeOperand(Operand, true);

4347 Out << ", [";

4348

4349 for (unsigned i = 1, e = I.getNumOperands(); i != e; ++i) {

4350 if (i != 1)

4351 Out << ", ";

4352 writeOperand(I.getOperand(i), true);

4353 }

4354 Out << ']';

4355 } else if (const PHINode *PN = dyn_cast(&I)) {

4356 Out << ' ';

4357 TypePrinter.print(I.getType(), Out);

4358 Out << ' ';

4359

4360 for (unsigned op = 0, Eop = PN->getNumIncomingValues(); op < Eop; ++op) {

4361 if (op) Out << ", ";

4362 Out << "[ ";

4363 writeOperand(PN->getIncomingValue(op), false); Out << ", ";

4364 writeOperand(PN->getIncomingBlock(op), false); Out << " ]";

4365 }

4366 } else if (const ExtractValueInst *EVI = dyn_cast(&I)) {

4367 Out << ' ';

4368 writeOperand(I.getOperand(0), true);

4369 for (unsigned i : EVI->indices())

4370 Out << ", " << i;

4371 } else if (const InsertValueInst *IVI = dyn_cast(&I)) {

4372 Out << ' ';

4373 writeOperand(I.getOperand(0), true); Out << ", ";

4374 writeOperand(I.getOperand(1), true);

4375 for (unsigned i : IVI->indices())

4376 Out << ", " << i;

4377 } else if (const LandingPadInst *LPI = dyn_cast(&I)) {

4378 Out << ' ';

4379 TypePrinter.print(I.getType(), Out);

4380 if (LPI->isCleanup() || LPI->getNumClauses() != 0)

4381 Out << '\n';

4382

4383 if (LPI->isCleanup())

4384 Out << " cleanup";

4385

4386 for (unsigned i = 0, e = LPI->getNumClauses(); i != e; ++i) {

4387 if (i != 0 || LPI->isCleanup()) Out << "\n";

4388 if (LPI->isCatch(i))

4389 Out << " catch ";

4390 else

4391 Out << " filter ";

4392

4393 writeOperand(LPI->getClause(i), true);

4394 }

4395 } else if (const auto *CatchSwitch = dyn_cast(&I)) {

4396 Out << " within ";

4397 writeOperand(CatchSwitch->getParentPad(), false);

4398 Out << " [";

4399 unsigned Op = 0;

4400 for (const BasicBlock *PadBB : CatchSwitch->handlers()) {

4401 if (Op > 0)

4402 Out << ", ";

4403 writeOperand(PadBB, true);

4404 ++Op;

4405 }

4406 Out << "] unwind ";

4407 if (const BasicBlock *UnwindDest = CatchSwitch->getUnwindDest())

4408 writeOperand(UnwindDest, true);

4409 else

4410 Out << "to caller";

4411 } else if (const auto *FPI = dyn_cast(&I)) {

4412 Out << " within ";

4413 writeOperand(FPI->getParentPad(), false);

4414 Out << " [";

4415 for (unsigned Op = 0, NumOps = FPI->arg_size(); Op < NumOps; ++Op) {

4416 if (Op > 0)

4417 Out << ", ";

4418 writeOperand(FPI->getArgOperand(Op), true);

4419 }

4420 Out << ']';

4421 } else if (isa(I) && !Operand) {

4422 Out << " void";

4423 } else if (const auto *CRI = dyn_cast(&I)) {

4424 Out << " from ";

4425 writeOperand(CRI->getOperand(0), false);

4426

4427 Out << " to ";

4428 writeOperand(CRI->getOperand(1), true);

4429 } else if (const auto *CRI = dyn_cast(&I)) {

4430 Out << " from ";

4431 writeOperand(CRI->getOperand(0), false);

4432

4433 Out << " unwind ";

4434 if (CRI->hasUnwindDest())

4435 writeOperand(CRI->getOperand(1), true);

4436 else

4437 Out << "to caller";

4438 } else if (const CallInst *CI = dyn_cast(&I)) {

4439

4441 Out << " ";

4443 }

4444

4445 Operand = CI->getCalledOperand();

4447 Type *RetTy = FTy->getReturnType();

4449

4452

4453

4455

4456

4457

4458

4459 Out << ' ';

4460 TypePrinter.print(FTy->isVarArg() ? FTy : RetTy, Out);

4461 Out << ' ';

4462 writeOperand(Operand, false);

4463 Out << '(';

4464 for (unsigned op = 0, Eop = CI->arg_size(); op < Eop; ++op) {

4465 if (op > 0)

4466 Out << ", ";

4467 writeParamOperand(CI->getArgOperand(op), PAL.getParamAttrs(op));

4468 }

4469

4470

4471

4472 if (CI->isMustTailCall() && CI->getParent() &&

4473 CI->getParent()->getParent() &&

4474 CI->getParent()->getParent()->isVarArg()) {

4475 if (CI->arg_size() > 0)

4476 Out << ", ";

4477 Out << "...";

4478 }

4479

4480 Out << ')';

4483

4484 writeOperandBundles(CI);

4485 } else if (const InvokeInst *II = dyn_cast(&I)) {

4486 Operand = II->getCalledOperand();

4488 Type *RetTy = FTy->getReturnType();

4490

4491

4493 Out << " ";

4495 }

4496

4499

4500

4502

4503

4504

4505

4506

4507 Out << ' ';

4508 TypePrinter.print(FTy->isVarArg() ? FTy : RetTy, Out);

4509 Out << ' ';

4510 writeOperand(Operand, false);

4511 Out << '(';

4512 for (unsigned op = 0, Eop = II->arg_size(); op < Eop; ++op) {

4513 if (op)

4514 Out << ", ";

4516 }

4517

4518 Out << ')';

4521

4522 writeOperandBundles(II);

4523

4524 Out << "\n to ";

4525 writeOperand(II->getNormalDest(), true);

4526 Out << " unwind ";

4527 writeOperand(II->getUnwindDest(), true);

4528 } else if (const CallBrInst *CBI = dyn_cast(&I)) {

4529 Operand = CBI->getCalledOperand();

4531 Type *RetTy = FTy->getReturnType();

4533

4534

4536 Out << " ";

4538 }

4539

4542

4543

4544

4545

4546

4547 Out << ' ';

4548 TypePrinter.print(FTy->isVarArg() ? FTy : RetTy, Out);

4549 Out << ' ';

4550 writeOperand(Operand, false);

4551 Out << '(';

4552 for (unsigned op = 0, Eop = CBI->arg_size(); op < Eop; ++op) {

4553 if (op)

4554 Out << ", ";

4555 writeParamOperand(CBI->getArgOperand(op), PAL.getParamAttrs(op));

4556 }

4557

4558 Out << ')';

4561

4562 writeOperandBundles(CBI);

4563

4564 Out << "\n to ";

4565 writeOperand(CBI->getDefaultDest(), true);

4566 Out << " [";

4567 for (unsigned i = 0, e = CBI->getNumIndirectDests(); i != e; ++i) {

4568 if (i != 0)

4569 Out << ", ";

4570 writeOperand(CBI->getIndirectDest(i), true);

4571 }

4572 Out << ']';

4573 } else if (const AllocaInst *AI = dyn_cast(&I)) {

4574 Out << ' ';

4575 if (AI->isUsedWithInAlloca())

4576 Out << "inalloca ";

4577 if (AI->isSwiftError())

4578 Out << "swifterror ";

4579 TypePrinter.print(AI->getAllocatedType(), Out);

4580

4581

4582

4583

4584

4585 if (!AI->getArraySize() || AI->isArrayAllocation() ||

4586 !AI->getArraySize()->getType()->isIntegerTy(32)) {

4587 Out << ", ";

4588 writeOperand(AI->getArraySize(), true);

4589 }

4591 Out << ", align " << A->value();

4592 }

4593

4594 unsigned AddrSpace = AI->getAddressSpace();

4595 if (AddrSpace != 0) {

4596 Out << ", addrspace(" << AddrSpace << ')';

4597 }

4598 } else if (isa(I)) {

4599 if (Operand) {

4600 Out << ' ';

4601 writeOperand(Operand, true);

4602 }

4603 Out << " to ";

4604 TypePrinter.print(I.getType(), Out);

4605 } else if (isa(I)) {

4606 if (Operand) {

4607 Out << ' ';

4608 writeOperand(Operand, true);

4609 }

4610 Out << ", ";

4611 TypePrinter.print(I.getType(), Out);

4612 } else if (Operand) {

4613 if (const auto *GEP = dyn_cast(&I)) {

4614 Out << ' ';

4615 TypePrinter.print(GEP->getSourceElementType(), Out);

4616 Out << ',';

4617 } else if (const auto *LI = dyn_cast(&I)) {

4618 Out << ' ';

4619 TypePrinter.print(LI->getType(), Out);

4620 Out << ',';

4621 }

4622

4623

4624

4625

4626 bool PrintAllTypes = false;

4628

4629

4630

4631 if (isa(I) || isa(I) || isa(I) ||

4632 isa(I) || isa(I) ||

4633 isa(I)) {

4634 PrintAllTypes = true;

4635 } else {

4636 for (unsigned i = 1, E = I.getNumOperands(); i != E; ++i) {

4637 Operand = I.getOperand(i);

4638

4639

4640 if (Operand && Operand->getType() != TheType) {

4641 PrintAllTypes = true;

4642 break;

4643 }

4644 }

4645 }

4646

4647 if (!PrintAllTypes) {

4648 Out << ' ';

4649 TypePrinter.print(TheType, Out);

4650 }

4651

4652 Out << ' ';

4653 for (unsigned i = 0, E = I.getNumOperands(); i != E; ++i) {

4654 if (i) Out << ", ";

4655 writeOperand(I.getOperand(i), PrintAllTypes);

4656 }

4657 }

4658

4659

4660 if (const LoadInst *LI = dyn_cast(&I)) {

4661 if (LI->isAtomic())

4662 writeAtomic(LI->getContext(), LI->getOrdering(), LI->getSyncScopeID());

4664 Out << ", align " << A->value();

4665 } else if (const StoreInst *SI = dyn_cast(&I)) {

4666 if (SI->isAtomic())

4667 writeAtomic(SI->getContext(), SI->getOrdering(), SI->getSyncScopeID());

4669 Out << ", align " << A->value();

4670 } else if (const AtomicCmpXchgInst *CXI = dyn_cast(&I)) {

4671 writeAtomicCmpXchg(CXI->getContext(), CXI->getSuccessOrdering(),

4672 CXI->getFailureOrdering(), CXI->getSyncScopeID());

4673 Out << ", align " << CXI->getAlign().value();

4674 } else if (const AtomicRMWInst *RMWI = dyn_cast(&I)) {

4675 writeAtomic(RMWI->getContext(), RMWI->getOrdering(),

4676 RMWI->getSyncScopeID());

4677 Out << ", align " << RMWI->getAlign().value();

4678 } else if (const FenceInst *FI = dyn_cast(&I)) {

4679 writeAtomic(FI->getContext(), FI->getOrdering(), FI->getSyncScopeID());

4680 } else if (const ShuffleVectorInst *SVI = dyn_cast(&I)) {

4681 PrintShuffleMask(Out, SVI->getType(), SVI->getShuffleMask());

4682 }

4683

4684

4686 I.getAllMetadata(InstMD);

4687 printMetadataAttachments(InstMD, ", ");

4688

4689

4690 printInfoComment(I);

4691}

4692

4693void AssemblyWriter::printDbgMarker(const DbgMarker &Marker) {

4694

4695

4697 printDbgRecord(DPR);

4698 Out << "\n";

4699 }

4700

4701 Out << " DbgMarker -> { ";

4703 Out << " }";

4704}

4705

4706void AssemblyWriter::printDbgRecord(const DbgRecord &DR) {

4707 if (auto *DVR = dyn_cast(&DR))

4708 printDbgVariableRecord(*DVR);

4709 else if (auto *DLR = dyn_cast(&DR))

4710 printDbgLabelRecord(*DLR);

4711 else

4713}

4714

4715void AssemblyWriter::printDbgVariableRecord(const DbgVariableRecord &DVR) {

4716 auto WriterCtx = getContext();

4717 Out << "#dbg_";

4718 switch (DVR.getType()) {

4719 case DbgVariableRecord::LocationType::Value:

4720 Out << "value";

4721 break;

4722 case DbgVariableRecord::LocationType::Declare:

4723 Out << "declare";

4724 break;

4725 case DbgVariableRecord::LocationType::Assign:

4726 Out << "assign";

4727 break;

4728 default:

4730 "Tried to print a DbgVariableRecord with an invalid LocationType!");

4731 }

4732 Out << "(";

4734 Out << ", ";

4736 Out << ", ";

4738 Out << ", ";

4741 Out << ", ";

4743 Out << ", ";

4745 Out << ", ";

4746 }

4748 Out << ")";

4749}

4750

4751

4752

4753void AssemblyWriter::printDbgRecordLine(const DbgRecord &DR) {

4754

4755 Out << " ";

4756 printDbgRecord(DR);

4757 Out << '\n';

4758}

4759

4760void AssemblyWriter::printDbgLabelRecord(const DbgLabelRecord &Label) {

4761 auto WriterCtx = getContext();

4762 Out << "#dbg_label(";

4764 Out << ", ";

4766 Out << ")";

4767}

4768

4769void AssemblyWriter::printMetadataAttachments(

4770 const SmallVectorImpl<std::pair<unsigned, MDNode *>> &MDs,

4772 if (MDs.empty())

4773 return;

4774

4775 if (MDNames.empty())

4776 MDs[0].second->getContext().getMDKindNames(MDNames);

4777

4778 auto WriterCtx = getContext();

4779 for (const auto &I : MDs) {

4780 unsigned Kind = I.first;

4781 Out << Separator;

4782 if (Kind < MDNames.size()) {

4783 Out << "!";

4785 } else

4786 Out << "!<unknown kind #" << Kind << ">";

4787 Out << ' ';

4789 }

4790}

4791

4792void AssemblyWriter::writeMDNode(unsigned Slot, const MDNode *Node) {

4793 Out << '!' << Slot << " = ";

4794 printMDNodeBody(Node);

4795 Out << "\n";

4796}

4797

4798void AssemblyWriter::writeAllMDNodes() {

4802 Nodes[I.second] = cast(I.first);

4803

4804 for (unsigned i = 0, e = Nodes.size(); i != e; ++i) {

4805 writeMDNode(i, Nodes[i]);

4806 }

4807}

4808

4809void AssemblyWriter::printMDNodeBody(const MDNode *Node) {

4810 auto WriterCtx = getContext();

4812}

4813

4814void AssemblyWriter::writeAttribute(const Attribute &Attr, bool InAttrGroup) {

4817 return;

4818 }

4819

4822 Out << '(';

4823 TypePrinter.print(Ty, Out);

4824 Out << ')';

4825 }

4826}

4827

4828void AssemblyWriter::writeAttributeSet(const AttributeSet &AttrSet,

4829 bool InAttrGroup) {

4830 bool FirstAttr = true;

4831 for (const auto &Attr : AttrSet) {

4832 if (!FirstAttr)

4833 Out << ' ';

4834 writeAttribute(Attr, InAttrGroup);

4835 FirstAttr = false;

4836 }

4837}

4838

4839void AssemblyWriter::writeAllAttributeGroups() {

4840 std::vector<std::pair<AttributeSet, unsigned>> asVec;

4841 asVec.resize(Machine.as_size());

4842

4844 asVec[I.second] = I;

4845

4846 for (const auto &I : asVec)

4847 Out << "attributes #" << I.second << " = { "

4848 << I.first.getAsString(true) << " }\n";

4849}

4850

4851void AssemblyWriter::printUseListOrder(const Value *V,

4852 const std::vector &Shuffle) {

4853 bool IsInFunction = Machine.getFunction();

4854 if (IsInFunction)

4855 Out << " ";

4856

4857 Out << "uselistorder";

4858 if (const BasicBlock *BB = IsInFunction ? nullptr : dyn_cast(V)) {

4859 Out << "_bb ";

4860 writeOperand(BB->getParent(), false);

4861 Out << ", ";

4862 writeOperand(BB, false);

4863 } else {

4864 Out << " ";

4865 writeOperand(V, true);

4866 }

4867 Out << ", { ";

4868

4869 assert(Shuffle.size() >= 2 && "Shuffle too small");

4870 Out << Shuffle[0];

4871 for (unsigned I = 1, E = Shuffle.size(); I != E; ++I)

4872 Out << ", " << Shuffle[I];

4873 Out << " }\n";

4874}

4875

4876void AssemblyWriter::printUseLists(const Function *F) {

4877 auto It = UseListOrders.find(F);

4878 if (It == UseListOrders.end())

4879 return;

4880

4881 Out << "\n; uselistorder directives\n";

4882 for (const auto &Pair : It->second)

4883 printUseListOrder(Pair.first, Pair.second);

4884}

4885

4886

4887

4888

4889

4891 bool ShouldPreserveUseListOrder,

4892 bool IsForDebug) const {

4895 AssemblyWriter W(OS, SlotTable, this->getParent(), AAW,

4896 IsForDebug,

4897 ShouldPreserveUseListOrder);

4898 W.printFunction(this);

4899}

4900

4902 bool ShouldPreserveUseListOrder,

4903 bool IsForDebug) const {

4906 AssemblyWriter W(OS, SlotTable, this->getModule(), AAW,

4907 IsForDebug,

4908 ShouldPreserveUseListOrder);

4909 W.printBasicBlock(this);

4910}

4911

4913 bool ShouldPreserveUseListOrder, bool IsForDebug) const {

4916 AssemblyWriter W(OS, SlotTable, this, AAW, IsForDebug,

4917 ShouldPreserveUseListOrder);

4918 W.printModule(this);

4919}

4920

4924 AssemblyWriter W(OS, SlotTable, getParent(), nullptr, IsForDebug);

4925 W.printNamedMDNode(this);

4926}

4927

4929 bool IsForDebug) const {

4930 std::optional LocalST;

4933 SlotTable = ST;

4934 else {

4936 SlotTable = &*LocalST;

4937 }

4938

4940 AssemblyWriter W(OS, *SlotTable, getParent(), nullptr, IsForDebug);

4941 W.printNamedMDNode(this);

4942}

4943

4946 ROS << " = comdat ";

4947

4950 ROS << "any";

4951 break;

4953 ROS << "exactmatch";

4954 break;

4956 ROS << "largest";

4957 break;

4959 ROS << "nodeduplicate";

4960 break;

4962 ROS << "samesize";

4963 break;

4964 }

4965

4966 ROS << '\n';

4967}

4968

4970 TypePrinting TP;

4971 TP.print(const_cast<Type*>(this), OS);

4972

4973 if (NoDetails)

4974 return;

4975

4976

4977 if (StructType *STy = dyn_cast(const_cast<Type*>(this)))

4979 OS << " = type ";

4980 TP.printStructBody(STy, OS);

4981 }

4982}

4983

4985 if (const auto *CI = dyn_cast(&I))

4986 if (Function *F = CI->getCalledFunction())

4987 if (F->isIntrinsic())

4988 for (auto &Op : I.operands())

4989 if (auto *V = dyn_cast_or_null(Op))

4990 if (isa(V->getMetadata()))

4991 return true;

4992 return false;

4993}

4994

4996

4998 print(ROS, MST, IsForDebug);

4999}

5000

5002

5004 print(ROS, MST, IsForDebug);

5005}

5006

5008 bool IsForDebug) const {

5010 SlotTracker EmptySlotTable(static_cast<const Module *>(nullptr));

5013 auto incorporateFunction = [&](const Function *F) {

5014 if (F)

5016 };

5018 AssemblyWriter W(OS, SlotTable, getModuleFromDPI(this), nullptr, IsForDebug);

5019 W.printDbgMarker(*this);

5020}

5021

5023

5025 print(ROS, MST, IsForDebug);

5026}

5027

5029 bool IsForDebug) const {

5031 SlotTracker EmptySlotTable(static_cast<const Module *>(nullptr));

5034 auto incorporateFunction = [&](const Function *F) {

5035 if (F)

5037 };

5040 : nullptr);

5041 AssemblyWriter W(OS, SlotTable, getModuleFromDPI(this), nullptr, IsForDebug);

5042 W.printDbgVariableRecord(*this);

5043}

5044

5046 bool IsForDebug) const {

5048 SlotTracker EmptySlotTable(static_cast<const Module *>(nullptr));

5051 auto incorporateFunction = [&](const Function *F) {

5052 if (F)

5054 };

5056 : nullptr);

5057 AssemblyWriter W(OS, SlotTable, getModuleFromDPI(this), nullptr, IsForDebug);

5058 W.printDbgLabelRecord(*this);

5059}

5060

5062 bool ShouldInitializeAllMetadata = false;

5063 if (auto *I = dyn_cast(this))

5065 else if (isa(this) || isa(this))

5066 ShouldInitializeAllMetadata = true;

5067

5069 print(ROS, MST, IsForDebug);

5070}

5071

5073 bool IsForDebug) const {

5075 SlotTracker EmptySlotTable(static_cast<const Module *>(nullptr));

5078 auto incorporateFunction = [&](const Function *F) {

5079 if (F)

5081 };

5082

5083 if (const Instruction *I = dyn_cast(this)) {

5084 incorporateFunction(I->getParent() ? I->getParent()->getParent() : nullptr);

5085 AssemblyWriter W(OS, SlotTable, getModuleFromVal(I), nullptr, IsForDebug);

5086 W.printInstruction(*I);

5087 } else if (const BasicBlock *BB = dyn_cast(this)) {

5088 incorporateFunction(BB->getParent());

5089 AssemblyWriter W(OS, SlotTable, getModuleFromVal(BB), nullptr, IsForDebug);

5090 W.printBasicBlock(BB);

5091 } else if (const GlobalValue *GV = dyn_cast(this)) {

5092 AssemblyWriter W(OS, SlotTable, GV->getParent(), nullptr, IsForDebug);

5093 if (const GlobalVariable *V = dyn_cast(GV))

5094 W.printGlobal(V);

5095 else if (const Function *F = dyn_cast(GV))

5096 W.printFunction(F);

5097 else if (const GlobalAlias *A = dyn_cast(GV))

5098 W.printAlias(A);

5099 else if (const GlobalIFunc *I = dyn_cast(GV))

5100 W.printIFunc(I);

5101 else

5103 } else if (const MetadataAsValue *V = dyn_cast(this)) {

5105 } else if (const Constant *C = dyn_cast(this)) {

5106 TypePrinting TypePrinter;

5107 TypePrinter.print(C->getType(), OS);

5108 OS << ' ';

5109 AsmWriterContext WriterCtx(&TypePrinter, MST.getMachine());

5111 } else if (isa(this) || isa(this)) {

5112 this->printAsOperand(OS, true, MST);

5113 } else {

5115 }

5116}

5117

5118

5119

5120

5123 if (V.hasName() || isa(V) ||

5124 (!isa(V) && !isa(V))) {

5125 AsmWriterContext WriterCtx(nullptr, Machine, M);

5127 return true;

5128 }

5129 return false;

5130}

5131

5134 TypePrinting TypePrinter(MST.getModule());

5135 if (PrintType) {

5136 TypePrinter.print(V.getType(), O);

5137 O << ' ';

5138 }

5139

5140 AsmWriterContext WriterCtx(&TypePrinter, MST.getMachine(), MST.getModule());

5142}

5143

5145 const Module *M) const {

5146 if (!M)

5148

5149 if (!PrintType)

5151 return;

5152

5154 M, isa(this));

5157}

5158

5161 if (!PrintType)

5163 return;

5164

5166}

5167

5168

5170 AsmWriterContext &WriterCtx) {

5173

5174 auto *N = dyn_cast(&MD);

5175 if (N || isa(MD))

5176 return;

5177

5178 OS << " = ";

5180}

5181

5182namespace {

5183struct MDTreeAsmWriterContext : public AsmWriterContext {

5184 unsigned Level;

5185

5186 using EntryTy = std::pair<unsigned, std::string>;

5188

5189

5191

5193

5194 MDTreeAsmWriterContext(TypePrinting *TP, SlotTracker *ST, const Module *M,

5196 : AsmWriterContext(TP, ST, M), Level(0U), Visited({InitMD}), MainOS(OS) {}

5197

5198 void onWriteMetadataAsOperand(const Metadata *MD) override {

5199 if (!Visited.insert(MD).second)

5200 return;

5201

5202 std::string Str;

5204 ++Level;

5205

5206

5207 Buffer.emplace_back(std::make_pair(Level, ""));

5208 unsigned InsertIdx = Buffer.size() - 1;

5209

5211 Buffer[InsertIdx].second = std::move(SS.str());

5212 --Level;

5213 }

5214

5215 ~MDTreeAsmWriterContext() {

5216 for (const auto &Entry : Buffer) {

5217 MainOS << "\n";

5218 unsigned NumIndent = Entry.first * 2U;

5219 MainOS.indent(NumIndent) << Entry.second;

5220 }

5221 }

5222};

5223}

5224

5227 bool OnlyAsOperand, bool PrintAsTree = false) {

5229

5230 TypePrinting TypePrinter(M);

5231

5232 std::unique_ptr WriterCtx;

5233 if (PrintAsTree && !OnlyAsOperand)

5234 WriterCtx = std::make_unique(

5235 &TypePrinter, MST.getMachine(), M, OS, &MD);

5236 else

5237 WriterCtx =

5238 std::make_unique(&TypePrinter, MST.getMachine(), M);

5239

5241

5242 auto *N = dyn_cast(&MD);

5243 if (OnlyAsOperand || N || isa(MD))

5244 return;

5245

5246 OS << " = ";

5248}

5249

5253}

5254

5256 const Module *M) const {

5258}

5259

5261 bool ) const {

5264}

5265

5267 const Module *M, bool ) const {

5269}

5270

5274 true);

5275}

5276

5278 const Module *M) const {

5280 true);

5281}

5282

5286 AssemblyWriter W(OS, SlotTable, this, IsForDebug);

5287 W.printModuleSummaryIndex();

5288}

5289

5291 unsigned UB) const {

5293 if (!ST)

5294 return;

5295

5296 for (auto &I : llvm::make_range(ST->mdn_begin(), ST->mdn_end()))

5297 if (I.second >= LB && I.second < UB)

5298 L.push_back(std::make_pair(I.second, I.first));

5299}

5300

5301#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)

5302

5305

5306

5309 print(dbgs(), true);

5310 dbgs() << '\n';

5311}

5312

5313

5316

5317

5320

5321

5325 false, true);

5326}

5327

5328

5331

5332

5335

5338

5341 print(dbgs(), M, true);

5342 dbgs() << '\n';

5343}

5344

5347

5351 dbgs() << '\n';

5352}

5353

5354

5357#endif

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...

MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL

static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)

static void writeDIMacro(raw_ostream &Out, const DIMacro *N, AsmWriterContext &WriterCtx)

static void writeMetadataAsOperand(raw_ostream &Out, const Metadata *MD, AsmWriterContext &WriterCtx)

static void writeDIGlobalVariableExpression(raw_ostream &Out, const DIGlobalVariableExpression *N, AsmWriterContext &WriterCtx)

MapVector< const Value *, unsigned > OrderMap

static void PrintCallingConv(unsigned cc, raw_ostream &Out)

static void writeDICompositeType(raw_ostream &Out, const DICompositeType *N, AsmWriterContext &WriterCtx)

static const char * getWholeProgDevirtResKindName(WholeProgramDevirtResolution::Kind K)

static void printMetadataImpl(raw_ostream &ROS, const Metadata &MD, ModuleSlotTracker &MST, const Module *M, bool OnlyAsOperand, bool PrintAsTree=false)

static void WriteOptimizationInfo(raw_ostream &Out, const User *U)

static void writeDIStringType(raw_ostream &Out, const DIStringType *N, AsmWriterContext &WriterCtx)

static std::string getLinkageNameWithSpace(GlobalValue::LinkageTypes LT)

static std::vector< unsigned > predictValueUseListOrder(const Value *V, unsigned ID, const OrderMap &OM)

static void writeDIGlobalVariable(raw_ostream &Out, const DIGlobalVariable *N, AsmWriterContext &WriterCtx)

static void orderValue(const Value *V, OrderMap &OM)

static void PrintThreadLocalModel(GlobalVariable::ThreadLocalMode TLM, formatted_raw_ostream &Out)

static void PrintLLVMName(raw_ostream &OS, StringRef Name, PrefixType Prefix)

Turn the specified name into an 'LLVM name', which is either prefixed with % (if the string only cont...

static StringRef getUnnamedAddrEncoding(GlobalVariable::UnnamedAddr UA)

static const char * getWholeProgDevirtResByArgKindName(WholeProgramDevirtResolution::ByArg::Kind K)

static void PrintShuffleMask(raw_ostream &Out, Type *Ty, ArrayRef< int > Mask)

static void writeDIModule(raw_ostream &Out, const DIModule *N, AsmWriterContext &WriterCtx)

static void writeDIFile(raw_ostream &Out, const DIFile *N, AsmWriterContext &)

static void writeDISubroutineType(raw_ostream &Out, const DISubroutineType *N, AsmWriterContext &WriterCtx)

static bool isReferencingMDNode(const Instruction &I)

static void writeDILabel(raw_ostream &Out, const DILabel *N, AsmWriterContext &WriterCtx)

static void WriteMDNodeBodyInternal(raw_ostream &Out, const MDNode *Node, AsmWriterContext &Ctx)

static void writeDIDerivedType(raw_ostream &Out, const DIDerivedType *N, AsmWriterContext &WriterCtx)

static void printMetadataIdentifier(StringRef Name, formatted_raw_ostream &Out)

static void writeDIImportedEntity(raw_ostream &Out, const DIImportedEntity *N, AsmWriterContext &WriterCtx)

static const Module * getModuleFromDPI(const DbgMarker *Marker)

static void printAsOperandImpl(const Value &V, raw_ostream &O, bool PrintType, ModuleSlotTracker &MST)

static void writeDIObjCProperty(raw_ostream &Out, const DIObjCProperty *N, AsmWriterContext &WriterCtx)

static void PrintDLLStorageClass(GlobalValue::DLLStorageClassTypes SCT, formatted_raw_ostream &Out)

static void writeDISubprogram(raw_ostream &Out, const DISubprogram *N, AsmWriterContext &WriterCtx)

static const char * getSummaryKindName(GlobalValueSummary::SummaryKind SK)

static OrderMap orderModule(const Module *M)

static const char * getVisibilityName(GlobalValue::VisibilityTypes Vis)

static void printMetadataImplRec(raw_ostream &ROS, const Metadata &MD, AsmWriterContext &WriterCtx)

Recursive version of printMetadataImpl.

static SlotTracker * createSlotTracker(const Value *V)

static void WriteAPFloatInternal(raw_ostream &Out, const APFloat &APF)

static void writeDILocation(raw_ostream &Out, const DILocation *DL, AsmWriterContext &WriterCtx)

static void writeDINamespace(raw_ostream &Out, const DINamespace *N, AsmWriterContext &WriterCtx)

static void writeDICommonBlock(raw_ostream &Out, const DICommonBlock *N, AsmWriterContext &WriterCtx)

static UseListOrderMap predictUseListOrder(const Module *M)

static void WriteConstantInternal(raw_ostream &Out, const Constant *CV, AsmWriterContext &WriterCtx)

static void WriteAsOperandInternal(raw_ostream &Out, const Value *V, AsmWriterContext &WriterCtx)

static std::string getLinkageName(GlobalValue::LinkageTypes LT)

static void writeDIBasicType(raw_ostream &Out, const DIBasicType *N, AsmWriterContext &)

static void writeGenericDINode(raw_ostream &Out, const GenericDINode *N, AsmWriterContext &WriterCtx)

static void writeDILocalVariable(raw_ostream &Out, const DILocalVariable *N, AsmWriterContext &WriterCtx)

static const char * getTTResKindName(TypeTestResolution::Kind K)

static void writeDITemplateTypeParameter(raw_ostream &Out, const DITemplateTypeParameter *N, AsmWriterContext &WriterCtx)

static const char * getImportTypeName(GlobalValueSummary::ImportKind IK)

static void writeDICompileUnit(raw_ostream &Out, const DICompileUnit *N, AsmWriterContext &WriterCtx)

static const Module * getModuleFromVal(const Value *V)

static void maybePrintCallAddrSpace(const Value *Operand, const Instruction *I, raw_ostream &Out)

static void writeDIGenericSubrange(raw_ostream &Out, const DIGenericSubrange *N, AsmWriterContext &WriterCtx)

static void writeDISubrange(raw_ostream &Out, const DISubrange *N, AsmWriterContext &WriterCtx)

static void PrintVisibility(GlobalValue::VisibilityTypes Vis, formatted_raw_ostream &Out)

static void writeDILexicalBlockFile(raw_ostream &Out, const DILexicalBlockFile *N, AsmWriterContext &WriterCtx)

static void writeDIEnumerator(raw_ostream &Out, const DIEnumerator *N, AsmWriterContext &)

static void writeMDTuple(raw_ostream &Out, const MDTuple *Node, AsmWriterContext &WriterCtx)

static void writeDIExpression(raw_ostream &Out, const DIExpression *N, AsmWriterContext &WriterCtx)

static void PrintDSOLocation(const GlobalValue &GV, formatted_raw_ostream &Out)

static void writeDIAssignID(raw_ostream &Out, const DIAssignID *DL, AsmWriterContext &WriterCtx)

static void writeDILexicalBlock(raw_ostream &Out, const DILexicalBlock *N, AsmWriterContext &WriterCtx)

static void maybePrintComdat(formatted_raw_ostream &Out, const GlobalObject &GO)

static bool printWithoutType(const Value &V, raw_ostream &O, SlotTracker *Machine, const Module *M)

Print without a type, skipping the TypePrinting object.

static void writeDIArgList(raw_ostream &Out, const DIArgList *N, AsmWriterContext &WriterCtx, bool FromValue=false)

static void writeDITemplateValueParameter(raw_ostream &Out, const DITemplateValueParameter *N, AsmWriterContext &WriterCtx)

static const Value * skipMetadataWrapper(const Value *V)

Look for a value that might be wrapped as metadata, e.g.

static void writeDIMacroFile(raw_ostream &Out, const DIMacroFile *N, AsmWriterContext &WriterCtx)

Atomic ordering constants.

This file contains the simple types necessary to represent the attributes associated with functions a...

static const Function * getParent(const Value *V)

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

COFF::MachineTypes Machine

#define LLVM_DUMP_METHOD

Mark debug helper function definitions like dump() that should not be stripped from debug builds.

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

dxil pretty DXIL Metadata Pretty Printer

Looks at all the uses of the given value Returns the Liveness deduced from the uses of this value Adds all uses that cause the result to be MaybeLive to MaybeLiveRetUses If the result is MaybeLiveUses might be modified but its content should be ignored(since it might not be complete). DeadArgumentEliminationPass

This file defines the DenseMap class.

This file contains constants used for implementing Dwarf debug support.

This file contains the declaration of the GlobalIFunc class, which represents a single indirect funct...

This file provides various utilities for inspecting and working with the control flow graph in LLVM I...

This file contains an interface for creating legacy passes to print out IR in various granularities.

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

This defines the Use class.

static bool InRange(int64_t Value, unsigned short Shift, int LBound, int HBound)

ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...

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

uint64_t IntrinsicInst * II

if(auto Err=PB.parsePassPipeline(MPM, Passes)) return wrap(std MPM run * Mod

static bool isDigit(const char C)

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

This file provides utility classes that use RAII to save and restore values.

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

This file defines the SmallPtrSet class.

This file defines the SmallString class.

This file defines the SmallVector class.

static APFloat getSNaN(const fltSemantics &Sem, bool Negative=false, const APInt *payload=nullptr)

Factory for SNaN values.

opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)

double convertToDouble() const

Converts this APFloat to host double value.

void toString(SmallVectorImpl< char > &Str, unsigned FormatPrecision=0, unsigned FormatMaxPadding=3, bool TruncateZero=true) const

const fltSemantics & getSemantics() const

APInt bitcastToAPInt() const

Class for arbitrary precision integers.

APInt getLoBits(unsigned numBits) const

Compute an APInt containing numBits lowbits from this APInt.

uint64_t getZExtValue() const

Get zero extended value.

APInt getHiBits(unsigned numBits) const

Compute an APInt containing numBits highbits from this APInt.

Abstract interface of slot tracker storage.

virtual ~AbstractSlotTrackerStorage()

Alias summary information.

const GlobalValueSummary & getAliasee() const

an instruction to allocate memory on the stack

This class represents an incoming formal argument to a Function.

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

virtual ~AssemblyAnnotationWriter()

An instruction that atomically checks whether a specified value is in a memory location,...

an instruction that atomically reads a memory location, combines it with another value,...

static StringRef getOperationName(BinOp Op)

AttributeSet getFnAttrs() const

The function attributes are returned.

std::string getAsString(unsigned Index, bool InAttrGrp=false) const

Return the attributes at the index as a string.

bool hasRetAttrs() const

Return true if attributes exist for the return value.

AttributeSet getAttributes(unsigned Index) const

The attributes for the specified index are returned.

bool hasFnAttrs() const

Return true the attributes exist for the function.

AttributeSet getParamAttrs(unsigned ArgNo) const

The attributes for the argument or parameter at the given index are returned.

bool hasAttributes() const

Return true if attributes exists in this set.

std::string getAsString(bool InAttrGrp=false) const

The Attribute is converted to a string of equivalent mnemonic.

Attribute::AttrKind getKindAsEnum() const

Return the attribute's kind as an enum (Attribute::AttrKind).

static StringRef getNameFromAttrKind(Attribute::AttrKind AttrKind)

bool isTypeAttribute() const

Return true if the attribute is a type attribute.

Type * getValueAsType() const

Return the attribute's value as a Type.

LLVM Basic Block Representation.

void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW=nullptr, bool ShouldPreserveUseListOrder=false, bool IsForDebug=false) const

Print the basic block to an output stream with an optional AssemblyAnnotationWriter.

bool isEntryBlock() const

Return true if this is the entry block of the containing function.

const Function * getParent() const

Return the enclosing method, or null if none.

const Module * getModule() const

Return the module owning the function this basic block belongs to, or nullptr if the function does no...

The address of a basic block.

Conditional or Unconditional Branch instruction.

Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...

CallBr instruction, tracking function calls that may not return control but instead transfer it to a ...

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

This class is the base class for the comparison instructions.

void print(raw_ostream &OS, bool IsForDebug=false) const

StringRef getName() const

@ Largest

The linker will choose the largest COMDAT.

@ SameSize

The data referenced by the COMDAT must be the same size.

@ Any

The linker may choose any COMDAT.

@ NoDeduplicate

No deduplication is performed.

@ ExactMatch

The data referenced by the COMDAT must be the same.

SelectionKind getSelectionKind() const

ConstantArray - Constant Array Declarations.

An array constant whose element type is a simple 1/2/4/8-byte integer or float/double,...

A constant value that is initialized with an expression using other constant values.

ConstantFP - Floating Point Values [float, double].

This is the shared class of boolean and integer constants.

A signed pointer, in the ptrauth sense.

This class represents a range of values.

APInt getSignedMin() const

Return the smallest signed value contained in the ConstantRange.

APInt getSignedMax() const

Return the largest signed value contained in the ConstantRange.

This is an important base class in LLVM.

Constant * getSplatValue(bool AllowPoison=false) const

If all elements of the vector constant have the same value, return that value.

Constant * getAggregateElement(unsigned Elt) const

For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...

List of ValueAsMetadata, to be used as an argument to a dbg.value intrinsic.

Basic type, like 'int' or 'float'.

static const char * nameTableKindString(DebugNameTableKind PK)

static const char * emissionKindString(DebugEmissionKind EK)

A lightweight wrapper around an expression operand.

A pair of DIGlobalVariable and DIExpression.

An imported module (C++ using directive or similar).

Macro Info DWARF-like metadata node.

Represents a module in the programming language, for example, a Clang module, or a Fortran module.

Tagged DWARF-like metadata node.

static DIFlags splitFlags(DIFlags Flags, SmallVectorImpl< DIFlags > &SplitFlags)

Split up a flags bitfield.

static StringRef getFlagString(DIFlags Flag)

String type, Fortran CHARACTER(n)

static DISPFlags splitFlags(DISPFlags Flags, SmallVectorImpl< DISPFlags > &SplitFlags)

Split up a flags bitfield for easier printing.

static StringRef getFlagString(DISPFlags Flag)

DISPFlags

Debug info subprogram flags.

Type array for a subprogram.

This class represents an Operation in the Expression.

Records a position in IR for a source label (DILabel).

void print(raw_ostream &O, bool IsForDebug=false) const

Per-instruction record of debug-info.

Instruction * MarkedInstr

Link back to the Instruction that owns this marker.

void print(raw_ostream &O, bool IsForDebug=false) const

Implement operator<< on DbgMarker.

const BasicBlock * getParent() const

simple_ilist< DbgRecord > StoredDbgRecords

List of DbgRecords, the non-instruction equivalent of llvm.dbg.

Base class for non-instruction debug metadata records that have positions within IR.

void print(raw_ostream &O, bool IsForDebug=false) const

DebugLoc getDebugLoc() const

DbgMarker * Marker

Marker that this DbgRecord is linked into.

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

LocationType getType() const

void print(raw_ostream &O, bool IsForDebug=false) const

MDNode * getRawExpression() const

MDNode * getRawAddressExpression() const

Metadata * getRawAssignID() const

MDNode * getRawVariable() const

Metadata * getRawLocation() const

Returns the metadata operand for the first location description.

Metadata * getRawAddress() const

MDNode * getAsMDNode() const

Return this as a bar MDNode.

iterator find(const_arg_type_t< KeyT > Val)

std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&...Args)

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

Utility class for floating point operations which can have information about relaxed accuracy require...

An instruction for ordering other memory operations.

Function summary information to aid decisions and implementation of importing.

void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW=nullptr, bool ShouldPreserveUseListOrder=false, bool IsForDebug=false) const

Print the function to an output stream with an optional AssemblyAnnotationWriter.

Represents calls to the gc.relocate intrinsic.

Value * getBasePtr() const

Value * getDerivedPtr() const

Generic tagged DWARF-like metadata node.

const Constant * getAliasee() const

const Constant * getResolver() const

StringRef getSection() const

Get the custom section of this global if it has one.

MaybeAlign getAlign() const

Returns the alignment of the given variable or function.

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

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

const Comdat * getComdat() const

bool hasSection() const

Check if this global has a custom object file section.

Function and variable summary information to aid decisions and implementation of importing.

SummaryKind

Sububclass discriminator (for dyn_cast<> et al.)

bool hasPartition() const

const SanitizerMetadata & getSanitizerMetadata() const

bool hasExternalLinkage() const

VisibilityTypes getVisibility() const

bool isImplicitDSOLocal() const

LinkageTypes getLinkage() const

ThreadLocalMode getThreadLocalMode() const

DLLStorageClassTypes

Storage classes of global values for PE targets.

@ DLLExportStorageClass

Function to be accessible from DLL.

@ DLLImportStorageClass

Function to be imported from DLL.

bool hasSanitizerMetadata() const

GUID getGUID() const

Return a 64-bit global unique ID constructed from global value name (i.e.

StringRef getPartition() const

Module * getParent()

Get the module that this global value is contained inside of...

PointerType * getType() const

Global values are always pointers.

VisibilityTypes

An enumeration for the kinds of visibility of global values.

@ DefaultVisibility

The GV is visible.

@ HiddenVisibility

The GV is hidden.

@ ProtectedVisibility

The GV is protected.

bool isMaterializable() const

If this function's Module is being lazily streamed in functions from disk or some other source,...

UnnamedAddr getUnnamedAddr() const

LinkageTypes

An enumeration for the kinds of linkage for global values.

@ PrivateLinkage

Like Internal, but omit from symbol table.

@ CommonLinkage

Tentative definitions.

@ InternalLinkage

Rename collisions when linking (static functions).

@ LinkOnceAnyLinkage

Keep one copy of function when linking (inline)

@ WeakODRLinkage

Same, but only replaced by something equivalent.

@ ExternalLinkage

Externally visible function.

@ WeakAnyLinkage

Keep one copy of named function when linking (weak)

@ AppendingLinkage

Special purpose, only applies to global arrays.

@ AvailableExternallyLinkage

Available for inspection, not emission.

@ ExternalWeakLinkage

ExternalWeak linkage description.

@ LinkOnceODRLinkage

Same, but only replaced by something equivalent.

DLLStorageClassTypes getDLLStorageClass() const

Type * getValueType() const

Global variable summary information to aid decisions and implementation of importing.

const Constant * getInitializer() const

getInitializer - Return the initializer for this global variable.

bool isExternallyInitialized() const

bool hasInitializer() const

Definitions have initializers, declarations don't.

AttributeSet getAttributes() const

Return the attribute set for this global.

std::optional< CodeModel::Model > getCodeModel() const

Get the custom code model of this global if it has one.

bool isConstant() const

If the value is a global constant, its value is immutable throughout the runtime execution of the pro...

This instruction inserts a struct field of array element value into an aggregate value.

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

void getSyncScopeNames(SmallVectorImpl< StringRef > &SSNs) const

getSyncScopeNames - Populates client supplied SmallVector with synchronization scope names registered...

The landingpad instruction holds all of the information necessary to generate correct exception handl...

An instruction for reading from memory.

void printTree(raw_ostream &OS, const Module *M=nullptr) const

Print in tree shape.

void dumpTree() const

User-friendly dump in tree shape.

This class implements a map that also provides access to all stored values in a deterministic order.

Manage lifetime of a slot tracker for printing IR.

std::vector< std::pair< unsigned, const MDNode * > > MachineMDNodeListType

const Module * getModule() const

ModuleSlotTracker(SlotTracker &Machine, const Module *M, const Function *F=nullptr)

Wrap a preinitialized SlotTracker.

virtual ~ModuleSlotTracker()

Destructor to clean up storage.

int getLocalSlot(const Value *V)

Return the slot number of the specified local value.

void collectMDNodes(MachineMDNodeListType &L, unsigned LB, unsigned UB) const

SlotTracker * getMachine()

Lazily creates a slot tracker.

void setProcessHook(std::function< void(AbstractSlotTrackerStorage *, const Module *, bool)>)

void incorporateFunction(const Function &F)

Incorporate the given function.

Class to hold module path string table and global value map, and encapsulate methods for operating on...

static constexpr const char * getRegularLTOModuleName()

const StringMap< ModuleHash > & modulePaths() const

Table of modules, containing module hash and id.

void dump() const

Dump to stderr (for debugging).

void print(raw_ostream &OS, bool IsForDebug=false) const

Print to an output stream.

A Module instance is used to store all the information related to an LLVM module.

iterator_range< ifunc_iterator > ifuncs()

iterator_range< named_metadata_iterator > named_metadata()

iterator_range< alias_iterator > aliases()

iterator_range< global_iterator > globals()

void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW, bool ShouldPreserveUseListOrder=false, bool IsForDebug=false) const

Print the module to an output stream with an optional AssemblyAnnotationWriter.

void dump() const

Dump the module to stderr (for debugging).

StringRef getName() const

void print(raw_ostream &ROS, bool IsForDebug=false) const

MDNode * getOperand(unsigned i) const

unsigned getNumOperands() const

Module * getParent()

Get the module that holds this named metadata collection.

Utility class for integer operators which may exhibit overflow - Add, Sub, Mul, and Shl.

unsigned getAddressSpace() const

Return the address space of the Pointer type.

An or instruction, which can be marked as "disjoint", indicating that the inputs don't have a 1 in th...

A udiv or sdiv instruction, which can be marked as "exact", indicating that no bits are destroyed.

Interface for looking up the initializer for a variable name, used by Init::resolveReferences.

A vector that has set insertion semantics.

This instruction constructs a fixed permutation of two input vectors.

This class provides computation of slot numbers for LLVM Assembly writing.

int getMetadataSlot(const MDNode *N) override

getMetadataSlot - Get the slot number of a MDNode.

int getTypeIdCompatibleVtableSlot(StringRef Id)

int getModulePathSlot(StringRef Path)

unsigned mdn_size() const

SlotTracker(const SlotTracker &)=delete

void purgeFunction()

After calling incorporateFunction, use this method to remove the most recently incorporated function ...

int getTypeIdSlot(StringRef Id)

void initializeIfNeeded()

These functions do the actual initialization.

int getGlobalSlot(const GlobalValue *V)

getGlobalSlot - Get the slot number of a global value.

const Function * getFunction() const

unsigned getNextMetadataSlot() override

void incorporateFunction(const Function *F)

If you'd like to deal with a function instead of just a module, use this method to get its data into ...

int getLocalSlot(const Value *V)

Return the slot number of the specified value in it's type plane.

int getAttributeGroupSlot(AttributeSet AS)

SlotTracker(const Module *M, bool ShouldInitializeAllMetadata=false)

Construct from a module.

void createMetadataSlot(const MDNode *N) override

getMetadataSlot - Get the slot number of a MDNode.

void setProcessHook(std::function< void(AbstractSlotTrackerStorage *, const Module *, bool)>)

SlotTracker & operator=(const SlotTracker &)=delete

int getGUIDSlot(GlobalValue::GUID GUID)

int initializeIndexIfNeeded()

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

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

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

SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...

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

reference emplace_back(ArgTypes &&... Args)

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

An instruction for storing to memory.

StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...

iterator find(StringRef Key)

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

constexpr bool empty() const

empty - Check if the string is empty.

Class to represent struct types.

ArrayRef< Type * > elements() const

unsigned getNumElements() const

Random access to the elements.

bool isLiteral() const

Return true if this type is uniqued by structural equivalence, false if it is a struct definition.

bool isOpaque() const

Return true if this is a type with an identity that has no body specified yet.

StringRef getName() const

Return the name for this struct type if it has an identity.

Class to represent target extensions types, which are generally unintrospectable from target-independ...

ArrayRef< Type * > type_params() const

Return the type parameters for this particular target extension type.

ArrayRef< unsigned > int_params() const

Return the integer parameters for this particular target extension type.

TypeFinder - Walk over a module, identifying all of the types that are used by the module.

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

bool isVectorTy() const

True if this is an instance of VectorType.

unsigned getPointerAddressSpace() const

Get the address space of this pointer or pointer vector type.

@ X86_AMXTyID

AMX vectors (8192 bits, X86 specific)

@ TypedPointerTyID

Typed pointer used by some GPU targets.

@ HalfTyID

16-bit floating point type

@ TargetExtTyID

Target extension type.

@ VoidTyID

type with no size

@ ScalableVectorTyID

Scalable SIMD vector type.

@ FloatTyID

32-bit floating point type

@ IntegerTyID

Arbitrary bit width integers.

@ FixedVectorTyID

Fixed width SIMD vector type.

@ BFloatTyID

16-bit floating point type (7-bit significand)

@ DoubleTyID

64-bit floating point type

@ X86_FP80TyID

80-bit floating point type (X87)

@ PPC_FP128TyID

128-bit floating point type (two 64-bits, PowerPC)

@ FP128TyID

128-bit floating point type (112-bit significand)

void print(raw_ostream &O, bool IsForDebug=false, bool NoDetails=false) const

Print the current type.

StringRef getTargetExtName() const

bool isIntegerTy() const

True if this is an instance of IntegerType.

TypeID getTypeID() const

Return the type id for the type.

Type * getScalarType() const

If this is a vector type, return the element type, otherwise return 'this'.

A few GPU targets, such as DXIL and SPIR-V, have typed pointers.

Type * getElementType() const

unsigned getAddressSpace() const

Return the address space of the Pointer type.

A Use represents the edge between a Value definition and its users.

LLVM Value Representation.

Type * getType() const

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

void print(raw_ostream &O, bool IsForDebug=false) const

Implement operator<< on Value.

void printAsOperand(raw_ostream &O, bool PrintType=true, const Module *M=nullptr) const

Print the name of this Value out to the specified raw_ostream.

StringRef getName() const

Return a constant reference to the value's name.

void dump() const

Support for debugging, callable in GDB: V->dump()

formatted_raw_ostream - A raw_ostream that wraps another one and keeps track of line and column posit...

This class implements an extremely fast bulk output stream that can only output to a stream.

raw_ostream & indent(unsigned NumSpaces)

indent - Insert 'NumSpaces' spaces.

A raw_ostream that writes to an std::string.

StringRef LanguageString(unsigned Language)

StringRef AttributeEncodingString(unsigned Encoding)

StringRef ConventionString(unsigned Convention)

StringRef MacinfoString(unsigned Encoding)

StringRef OperationEncodingString(unsigned Encoding)

StringRef TagString(unsigned Tag)

This provides a very simple, boring adaptor for a begin and end iterator into a range type.

This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM.

#define llvm_unreachable(msg)

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

constexpr char Attrs[]

Key for Kernel::Metadata::mAttrs.

@ AArch64_VectorCall

Used between AArch64 Advanced SIMD functions.

@ X86_64_SysV

The C convention as specified in the x86-64 supplement to the System V ABI, used on most non-Windows ...

@ RISCV_VectorCall

Calling convention used for RISC-V V-extension.

@ AMDGPU_CS

Used for Mesa/AMDPAL compute shaders.

@ AMDGPU_VS

Used for Mesa vertex shaders, or AMDPAL last shader stage before rasterization (vertex shader if tess...

@ AVR_SIGNAL

Used for AVR signal routines.

@ Swift

Calling convention for Swift.

@ AMDGPU_KERNEL

Used for AMDGPU code object kernels.

@ AArch64_SVE_VectorCall

Used between AArch64 SVE functions.

@ ARM_APCS

ARM Procedure Calling Standard (obsolete, but still used on some targets).

@ CFGuard_Check

Special calling convention on Windows for calling the Control Guard Check ICall funtion.

@ AVR_INTR

Used for AVR interrupt routines.

@ PreserveMost

Used for runtime calls that preserves most registers.

@ AnyReg

OBSOLETED - Used for stack based JavaScript calls.

@ AMDGPU_Gfx

Used for AMD graphics targets.

@ DUMMY_HHVM

Placeholders for HHVM calling conventions (deprecated, removed).

@ AMDGPU_CS_ChainPreserve

Used on AMDGPUs to give the middle-end more control over argument placement.

@ AMDGPU_HS

Used for Mesa/AMDPAL hull shaders (= tessellation control shaders).

@ ARM_AAPCS

ARM Architecture Procedure Calling Standard calling convention (aka EABI).

@ AMDGPU_GS

Used for Mesa/AMDPAL geometry shaders.

@ AArch64_SME_ABI_Support_Routines_PreserveMost_From_X2

Preserve X2-X15, X19-X29, SP, Z0-Z31, P0-P15.

@ CXX_FAST_TLS

Used for access functions.

@ X86_INTR

x86 hardware interrupt context.

@ AArch64_SME_ABI_Support_Routines_PreserveMost_From_X0

Preserve X0-X13, X19-X29, SP, Z0-Z31, P0-P15.

@ AMDGPU_CS_Chain

Used on AMDGPUs to give the middle-end more control over argument placement.

@ GHC

Used by the Glasgow Haskell Compiler (GHC).

@ AMDGPU_PS

Used for Mesa/AMDPAL pixel shaders.

@ Cold

Attempts to make code in the caller as efficient as possible under the assumption that the call is no...

@ AArch64_SME_ABI_Support_Routines_PreserveMost_From_X1

Preserve X1-X15, X19-X29, SP, Z0-Z31, P0-P15.

@ X86_ThisCall

Similar to X86_StdCall.

@ PTX_Device

Call to a PTX device function.

@ SPIR_KERNEL

Used for SPIR kernel functions.

@ PreserveAll

Used for runtime calls that preserves (almost) all registers.

@ X86_StdCall

stdcall is mostly used by the Win32 API.

@ SPIR_FUNC

Used for SPIR non-kernel device functions.

@ Fast

Attempts to make calls as fast as possible (e.g.

@ MSP430_INTR

Used for MSP430 interrupt routines.

@ X86_VectorCall

MSVC calling convention that passes vectors and vector aggregates in SSE registers.

@ Intel_OCL_BI

Used for Intel OpenCL built-ins.

@ PreserveNone

Used for runtime calls that preserves none general registers.

@ AMDGPU_ES

Used for AMDPAL shader stage before geometry shader if geometry is in use.

@ Tail

Attemps to make calls as fast as possible while guaranteeing that tail call optimization can always b...

@ Win64

The C convention as implemented on Windows/x86-64 and AArch64.

@ PTX_Kernel

Call to a PTX kernel. Passes all arguments in parameter space.

@ SwiftTail

This follows the Swift calling convention in how arguments are passed but guarantees tail calls will ...

@ GRAAL

Used by GraalVM. Two additional registers are reserved.

@ AMDGPU_LS

Used for AMDPAL vertex shader if tessellation is in use.

@ ARM_AAPCS_VFP

Same as ARM_AAPCS, but uses hard floating point ABI.

@ X86_RegCall

Register calling convention used for parameters transfer optimization.

@ M68k_RTD

Used for M68k rtd-based CC (similar to X86's stdcall).

@ C

The default llvm calling convention, compatible with C.

@ X86_FastCall

'fast' analog of X86_StdCall.

unsigned ID

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

@ System

Synchronized with respect to all concurrently executing threads.

@ DW_OP_LLVM_convert

Only used in LLVM metadata.

This is an optimization pass for GlobalISel generic memory operations.

bool all_of(R &&range, UnaryPredicate P)

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

auto pred_end(const MachineBasicBlock *BB)

const char * getHotnessName(CalleeInfo::HotnessType HT)

iterator_range< T > make_range(T x, T y)

Convenience function for iterating over sub-ranges.

const char * toIRString(AtomicOrdering ao)

String used by LLVM IR to represent atomic ordering.

void sort(IteratorTy Start, IteratorTy End)

raw_ostream & dbgs()

dbgs() - This returns a reference to a raw_ostream for debugging messages.

bool is_sorted(R &&Range, Compare C)

Wrapper function around std::is_sorted to check if elements in a range R are sorted with respect to a...

FormattedNumber format_hex(uint64_t N, unsigned Width, bool Upper=false)

format_hex - Output N as a fixed width hexadecimal.

FormattedNumber format_hex_no_prefix(uint64_t N, unsigned Width, bool Upper=false)

format_hex_no_prefix - Output N as a fixed width hexadecimal.

constexpr int PoisonMaskElem

AtomicOrdering

Atomic ordering for LLVM's memory model.

@ Ref

The access may reference the value stored in memory.

DWARFExpression::Operation Op

raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)

auto pred_begin(const MachineBasicBlock *BB)

const char * toString(DWARFSectionKind Kind)

@ Default

The result values are uniform if and only if all operands are uniform.

std::vector< TypeIdOffsetVtableInfo > TypeIdCompatibleVtableInfo

List of vtable definitions decorated by a particular type identifier, and their corresponding offsets...

void printLLVMNameWithoutPrefix(raw_ostream &OS, StringRef Name)

Print out a name of an LLVM value without any prefixes.

static const fltSemantics & IEEEsingle() LLVM_READNONE

static constexpr roundingMode rmNearestTiesToEven

static const fltSemantics & PPCDoubleDouble() LLVM_READNONE

static const fltSemantics & x87DoubleExtended() LLVM_READNONE

static const fltSemantics & IEEEquad() LLVM_READNONE

static const fltSemantics & IEEEdouble() LLVM_READNONE

static const fltSemantics & IEEEhalf() LLVM_READNONE

static const fltSemantics & BFloat() LLVM_READNONE

A single checksum, represented by a Kind and a Value (a string).

T Value

The string value of the checksum.

StringRef getKindAsString() const

All type identifier related information.

std::vector< ConstVCall > TypeCheckedLoadConstVCalls

std::vector< VFuncId > TypeCheckedLoadVCalls

std::vector< ConstVCall > TypeTestAssumeConstVCalls

List of virtual calls made by this function using (respectively) llvm.assume(llvm....

std::vector< GlobalValue::GUID > TypeTests

List of type identifiers used by this function in llvm.type.test intrinsics referenced by something o...

std::vector< VFuncId > TypeTestAssumeVCalls

List of virtual calls made by this function using (respectively) llvm.assume(llvm....

An "identifier" for a virtual function.

Group flags (Linkage, NotEligibleToImport, etc.) as a bitfield.

unsigned DSOLocal

Indicates that the linker resolved the symbol to a definition from within the same linkage unit.

unsigned CanAutoHide

In the per-module summary, indicates that the global value is linkonce_odr and global unnamed addr (s...

unsigned ImportType

This field is written by the ThinLTO indexing step to postlink combined summary.

unsigned NotEligibleToImport

Indicate if the global value cannot be imported (e.g.

unsigned Linkage

The linkage type of the associated global value.

unsigned Visibility

Indicates the visibility.

unsigned Live

In per-module summary, indicate that the global value must be considered a live root for index-based ...

This struct is a compact representation of a valid (power of two) or undefined (0) alignment.

A lightweight accessor for an operand bundle meant to be passed around by value.

StringRef getTagName() const

Return the tag of this operand bundle as a string.

A utility class that uses RAII to save and restore the value of a variable.

std::map< uint64_t, WholeProgramDevirtResolution > WPDRes

Mapping from byte offset to whole-program devirt resolution for that (typeid, byte offset) pair.

Kind

Specifies which kind of type check we should emit for this byte array.

@ Unknown

Unknown (analysis not performed, don't lower)

@ Single

Single element (last example in "Short Inline Bit Vectors")

@ Inline

Inlined bit vector ("Short Inline Bit Vectors")

@ Unsat

Unsatisfiable type (i.e. no global has this type metadata)

@ AllOnes

All-ones bit vector ("Eliminating Bit Vector Checks for All-Ones Bit Vectors")

@ ByteArray

Test a byte array (first example)

unsigned SizeM1BitWidth

Range of size-1 expressed as a bit width.

enum llvm::TypeTestResolution::Kind TheKind

Struct that holds a reference to a particular GUID in a global value summary.

@ UniformRetVal

Uniform return value optimization.

@ VirtualConstProp

Virtual constant propagation.

@ UniqueRetVal

Unique return value optimization.

@ Indir

Just do a regular virtual call.

enum llvm::WholeProgramDevirtResolution::Kind TheKind

std::map< std::vector< uint64_t >, ByArg > ResByArg

Resolutions for calls with all constant integer arguments (excluding the first argument,...

std::string SingleImplName

@ SingleImpl

Single implementation devirtualization.

@ Indir

Just do a regular virtual call.

@ BranchFunnel

When retpoline mitigation is enabled, use a branch funnel that is defined in the merged module.

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