33 #include "llvm/Config/llvm-config.h" 104 unsigned size()
const {
return IDs.
size(); }
105 std::pair<unsigned, bool> &operator[](
const Value *V) {
return IDs[V]; }
107 std::pair<unsigned, bool>
lookup(
const Value *V)
const {
111 void index(
const Value *V) {
113 unsigned ID = IDs.
size() + 1;
121 if (OM.lookup(V).first)
124 if (
const Constant *
C = dyn_cast<Constant>(V))
127 if (!isa<BasicBlock>(
Op) && !isa<GlobalValue>(
Op))
141 if (
G.hasInitializer())
142 if (!isa<GlobalValue>(
G.getInitializer()))
147 if (!isa<GlobalValue>(A.getAliasee()))
152 if (!isa<GlobalValue>(
I.getResolver()))
157 for (
const Use &U :
F.operands())
158 if (!isa<GlobalValue>(U.get()))
163 if (
F.isDeclaration())
171 for (
const Value *
Op :
I.operands())
172 if ((isa<Constant>(*
Op) && !isa<GlobalValue>(*
Op)) ||
183 unsigned ID,
const OrderMap &OM,
186 using Entry = std::pair<const Use *, unsigned>;
190 if (OM.lookup(U.getUser()).
first)
198 !isa<GlobalVariable>(V) && !isa<Function>(V) && !isa<BasicBlock>(V);
199 if (
auto *BA = dyn_cast<BlockAddress>(V))
200 ID = OM.lookup(BA->getBasicBlock()).
first;
201 llvm::sort(List, [&](
const Entry &L,
const Entry &R) {
202 const Use *LU = L.first;
203 const Use *RU = R.first;
207 auto LID = OM.lookup(LU->getUser()).
first;
208 auto RID = OM.lookup(RU->getUser()).
first;
228 return LU->getOperandNo() < RU->getOperandNo();
229 return LU->getOperandNo() > RU->getOperandNo();
234 [](
const Entry &L,
const Entry &R) {
return L.second < R.second; }))
239 Stack.emplace_back(V, F, List.
size());
240 assert(List.
size() == Stack.back().Shuffle.size() &&
"Wrong size");
241 for (
size_t I = 0,
E = List.
size();
I !=
E; ++
I)
242 Stack.back().Shuffle[
I] = List[
I].second;
247 auto &IDPair = OM[V];
248 assert(IDPair.first &&
"Unmapped value");
254 IDPair.second =
true;
259 if (
const Constant *
C = dyn_cast<Constant>(V))
262 if (isa<Constant>(
Op))
280 if (
F.isDeclaration())
288 for (
const Value *
Op :
I.operands())
289 if (isa<Constant>(*
Op) || isa<InlineAsm>(*Op))
306 if (
G.hasInitializer())
313 for (
const Use &U :
F.operands())
320 if (
const Argument *MA = dyn_cast<Argument>(V))
321 return MA->getParent() ? MA->getParent()->getParent() :
nullptr;
323 if (
const BasicBlock *BB = dyn_cast<BasicBlock>(V))
324 return BB->getParent() ? BB->getParent()->getParent() :
nullptr;
327 const Function *M =
I->getParent() ?
I->getParent()->getParent() :
nullptr;
331 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V))
332 return GV->getParent();
334 if (
const auto *MAV = dyn_cast<MetadataAsValue>(V)) {
336 if (isa<Instruction>(U))
347 default: Out <<
"cc" << cc;
break;
402 bool NeedsQuotes = isdigit(static_cast<unsigned char>(Name[0]));
404 for (
unsigned i = 0, e = Name.
size(); i != e; ++i) {
409 unsigned char C = Name[i];
410 if (!isalnum(static_cast<unsigned char>(C)) && C !=
'-' && C !=
'.' &&
465 TypePrinting(
const Module *M =
nullptr) : DeferredM(M) {}
467 TypePrinting(
const TypePrinting &) =
delete;
468 TypePrinting &operator=(
const TypePrinting &) =
delete;
474 std::vector<StructType *> &getNumberedTypes();
483 void incorporateTypes();
493 std::vector<StructType *> NumberedTypes;
503 std::vector<StructType *> &TypePrinting::getNumberedTypes() {
509 if (NumberedTypes.size() == Type2Number.size())
510 return NumberedTypes;
512 NumberedTypes.resize(Type2Number.size());
513 for (
const auto &
P : Type2Number) {
514 assert(
P.second < NumberedTypes.size() &&
"Didn't get a dense numbering?");
515 assert(!NumberedTypes[
P.second] &&
"Didn't get a unique numbering?");
516 NumberedTypes[
P.second] =
P.first;
518 return NumberedTypes;
523 return NamedTypes.empty() && Type2Number.empty();
526 void TypePrinting::incorporateTypes() {
530 NamedTypes.run(*DeferredM,
false);
535 unsigned NextNumber = 0;
537 std::vector<StructType*>::iterator NextToUse = NamedTypes.begin(),
I,
E;
538 for (
I = NamedTypes.begin(), E = NamedTypes.end();
I !=
E; ++
I) {
546 Type2Number[STy] = NextNumber++;
551 NamedTypes.erase(NextToUse, NamedTypes.end());
594 return printStructBody(STy, OS);
600 const auto I = Type2Number.find(STy);
601 if (
I != Type2Number.end())
602 OS <<
'%' <<
I->second;
604 OS <<
"%\"type " << STy <<
'\"';
630 llvm_unreachable("Invalid TypeID"); 633 void TypePrinting::printStructBody(StructType *STy, raw_ostream &OS) { 634 if (STy->isOpaque()) { 642 if (STy->getNumElements() == 0) { 645 StructType::element_iterator I = STy->element_begin(); 648 for (StructType::element_iterator E = STy->element_end(); I != E; ++I) { 661 //===----------------------------------------------------------------------===// 662 // SlotTracker Class: Enumerate slot numbers for unnamed values 663 //===----------------------------------------------------------------------===// 669 using ValueMap = DenseMap<const Value *, unsigned>;
673 const Module* TheModule;
676 const Function* TheFunction = nullptr;
677 bool FunctionProcessed = false;
678 bool ShouldInitializeAllMetadata;
681 const ModuleSummaryIndex *TheIndex = nullptr;
692 DenseMap<const MDNode*, unsigned> mdnMap;
693 unsigned mdnNext = 0;
696 DenseMap<AttributeSet, unsigned> asMap;
700 StringMap<unsigned> ModulePathMap;
701 unsigned ModulePathNext = 0;
704 DenseMap<GlobalValue::GUID, unsigned> GUIDMap;
705 unsigned GUIDNext = 0;
708 StringMap<unsigned> TypeIdMap;
709 unsigned TypeIdNext = 0;
717 explicit SlotTracker(const Module *M,
718 bool ShouldInitializeAllMetadata = false);
725 explicit SlotTracker(const Function *F,
726 bool ShouldInitializeAllMetadata = false);
729 explicit SlotTracker(const ModuleSummaryIndex *Index);
731 SlotTracker(const SlotTracker &) = delete;
732 SlotTracker &operator=(const SlotTracker &) = delete;
736 int getLocalSlot(const Value *V);
737 int getGlobalSlot(const GlobalValue *V);
738 int getMetadataSlot(const MDNode *N);
739 int getAttributeGroupSlot(AttributeSet AS);
740 int getModulePathSlot(StringRef Path);
741 int getGUIDSlot(GlobalValue::GUID GUID);
742 int getTypeIdSlot(StringRef Id);
746 void incorporateFunction(const Function *F) {
748 FunctionProcessed = false;
751 const Function *getFunction() const { return TheFunction; }
756 void purgeFunction();
759 using mdn_iterator = DenseMap<const MDNode*, unsigned>::iterator;
761 mdn_iterator mdn_begin() { return mdnMap.begin(); }
762 mdn_iterator mdn_end() { return mdnMap.end(); }
763 unsigned mdn_size() const { return mdnMap.size(); }
764 bool mdn_empty() const { return mdnMap.empty(); }
767 using as_iterator = DenseMap<AttributeSet, unsigned>::iterator;
769 as_iterator as_begin() { return asMap.begin(); }
770 as_iterator as_end() { return asMap.end(); }
771 unsigned as_size() const { return asMap.size(); }
772 bool as_empty() const { return asMap.empty(); }
775 using guid_iterator = DenseMap<GlobalValue::GUID, unsigned>::iterator;
778 inline void initializeIfNeeded();
779 void initializeIndexIfNeeded();
781 // Implementation Details
784 void CreateModuleSlot(const GlobalValue *V);
787 void CreateMetadataSlot(const MDNode *N);
790 void CreateFunctionSlot(const Value *V);
793 void CreateAttributeSetSlot(AttributeSet AS);
795 inline void CreateModulePathSlot(StringRef Path);
796 void CreateGUIDSlot(GlobalValue::GUID GUID);
797 void CreateTypeIdSlot(StringRef Id);
801 void processModule();
805 void processFunction();
808 void processGlobalObjectMetadata(const GlobalObject &GO);
811 void processFunctionMetadata(const Function &F);
814 void processInstructionMetadata(const Instruction &I);
817 } // end namespace llvm
819 ModuleSlotTracker::ModuleSlotTracker(SlotTracker &Machine, const Module *M,
821 : M(M), F(F), Machine(&Machine) {}
823 ModuleSlotTracker::ModuleSlotTracker(const Module *M,
824 bool ShouldInitializeAllMetadata)
825 : ShouldCreateStorage(M),
826 ShouldInitializeAllMetadata(ShouldInitializeAllMetadata), M(M) {}
828 ModuleSlotTracker::~ModuleSlotTracker() = default;
830 SlotTracker *ModuleSlotTracker::getMachine() {
831 if (!ShouldCreateStorage)
834 ShouldCreateStorage = false;
836 llvm::make_unique<SlotTracker>(M, ShouldInitializeAllMetadata);
837 Machine = MachineStorage.get();
841 void ModuleSlotTracker::incorporateFunction(const Function &F) {
842 // Using getMachine() may lazily create the slot tracker.
846 // Nothing to do if this is the right function already.
850 Machine->purgeFunction();
851 Machine->incorporateFunction(&F);
855 int ModuleSlotTracker::getLocalSlot(const Value *V) {
856 assert(F && "No function incorporated");
857 return Machine->getLocalSlot(V);
860 static SlotTracker *createSlotTracker(const Value *V) {
861 if (const Argument *FA = dyn_cast<Argument>(V))
862 return new SlotTracker(FA->getParent());
864 if (const Instruction *I = dyn_cast<Instruction>(V))
866 return new SlotTracker(I->getParent()->getParent());
868 if (const BasicBlock *BB = dyn_cast<BasicBlock>(V))
869 return new SlotTracker(BB->getParent());
871 if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(V))
872 return new SlotTracker(GV->getParent());
874 if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(V))
875 return new SlotTracker(GA->getParent());
877 if (const GlobalIFunc *GIF = dyn_cast<GlobalIFunc>(V))
878 return new SlotTracker(GIF->getParent());
880 if (const Function *Func = dyn_cast<Function>(V))
881 return new SlotTracker(Func);
887 #define ST_DEBUG(X) dbgs() << X
892 // Module level constructor. Causes the contents of the Module (sans functions)
893 // to be added to the slot table.
894 SlotTracker::SlotTracker(const Module *M, bool ShouldInitializeAllMetadata)
895 : TheModule(M), ShouldInitializeAllMetadata(ShouldInitializeAllMetadata) {}
897 // Function level constructor. Causes the contents of the Module and the one
898 // function provided to be added to the slot table.
899 SlotTracker::SlotTracker(const Function *F, bool ShouldInitializeAllMetadata)
900 : TheModule(F ? F->getParent() : nullptr), TheFunction(F),
901 ShouldInitializeAllMetadata(ShouldInitializeAllMetadata) {}
903 SlotTracker::SlotTracker(const ModuleSummaryIndex *Index)
904 : TheModule(nullptr), ShouldInitializeAllMetadata(false), TheIndex(Index) {}
906 inline void SlotTracker::initializeIfNeeded() {
909 TheModule = nullptr; ///< Prevent re-processing next time we're called.
912 if (TheFunction && !FunctionProcessed)
925 void SlotTracker::processModule() {
931 CreateModuleSlot(&Var);
932 processGlobalObjectMetadata(Var);
933 auto Attrs = Var.getAttributes();
934 if (
Attrs.hasAttributes())
935 CreateAttributeSetSlot(
Attrs);
938 for (
const GlobalAlias &A : TheModule->aliases()) {
940 CreateModuleSlot(&A);
945 CreateModuleSlot(&
I);
949 for (
const NamedMDNode &NMD : TheModule->named_metadata()) {
950 for (
unsigned i = 0, e = NMD.getNumOperands(); i != e; ++i)
951 CreateMetadataSlot(NMD.getOperand(i));
957 CreateModuleSlot(&
F);
959 if (ShouldInitializeAllMetadata)
960 processFunctionMetadata(
F);
966 CreateAttributeSetSlot(FnAttrs);
973 void SlotTracker::processFunction() {
974 ST_DEBUG(
"begin processFunction!\n");
978 if (!ShouldInitializeAllMetadata)
979 processFunctionMetadata(*TheFunction);
983 AE = TheFunction->arg_end(); AI != AE; ++AI)
985 CreateFunctionSlot(&*AI);
987 ST_DEBUG(
"Inserting Instructions:\n");
990 for (
auto &BB : *TheFunction) {
992 CreateFunctionSlot(&BB);
995 if (!
I.getType()->isVoidTy() && !
I.hasName())
996 CreateFunctionSlot(&
I);
1000 if (
const auto *Call = dyn_cast<CallBase>(&
I)) {
1004 CreateAttributeSetSlot(Attrs);
1009 FunctionProcessed =
true;
1011 ST_DEBUG(
"end processFunction!\n");
1015 void SlotTracker::processIndex() {
1022 std::map<uint64_t, StringRef> ModuleIdToPathMap;
1023 for (
auto &ModPath : TheIndex->modulePaths())
1024 ModuleIdToPathMap[ModPath.second.first] = ModPath.first();
1025 for (
auto &ModPair : ModuleIdToPathMap)
1026 CreateModulePathSlot(ModPair.second);
1029 GUIDNext = ModulePathNext;
1031 for (
auto &GlobalList : *TheIndex)
1032 CreateGUIDSlot(GlobalList.first);
1035 TypeIdNext = GUIDNext;
1037 for (
auto TidIter = TheIndex->typeIds().begin();
1038 TidIter != TheIndex->typeIds().end(); TidIter++)
1039 CreateTypeIdSlot(TidIter->second.first);
1044 void SlotTracker::processGlobalObjectMetadata(
const GlobalObject &GO) {
1047 for (
auto &MD : MDs)
1048 CreateMetadataSlot(MD.second);
1051 void SlotTracker::processFunctionMetadata(
const Function &
F) {
1052 processGlobalObjectMetadata(F);
1053 for (
auto &BB : F) {
1055 processInstructionMetadata(
I);
1059 void SlotTracker::processInstructionMetadata(
const Instruction &
I) {
1061 if (
const CallInst *CI = dyn_cast<CallInst>(&I))
1062 if (
Function *F = CI->getCalledFunction())
1065 if (
auto *V = dyn_cast_or_null<MetadataAsValue>(
Op))
1066 if (
MDNode *
N = dyn_cast<MDNode>(V->getMetadata()))
1067 CreateMetadataSlot(
N);
1072 for (
auto &MD : MDs)
1073 CreateMetadataSlot(MD.second);
1080 ST_DEBUG(
"begin purgeFunction!\n");
1082 TheFunction =
nullptr;
1083 FunctionProcessed =
false;
1090 initializeIfNeeded();
1094 return MI == mMap.end() ? -1 : (int)MI->second;
1100 initializeIfNeeded();
1104 return MI == mdnMap.end() ? -1 : (int)MI->second;
1109 assert(!isa<Constant>(V) &&
"Can't get a constant or global slot with this!");
1112 initializeIfNeeded();
1115 return FI == fMap.end() ? -1 : (int)FI->second;
1120 initializeIfNeeded();
1124 return AI == asMap.end() ? -1 : (int)AI->second;
1129 initializeIndexIfNeeded();
1132 auto I = ModulePathMap.find(Path);
1133 return I == ModulePathMap.end() ? -1 : (int)I->second;
1138 initializeIndexIfNeeded();
1142 return I == GUIDMap.end() ? -1 : (int)I->second;
1147 initializeIndexIfNeeded();
1150 auto I = TypeIdMap.find(Id);
1151 return I == TypeIdMap.end() ? -1 : (int)I->second;
1155 void SlotTracker::CreateModuleSlot(
const GlobalValue *V) {
1156 assert(V &&
"Can't insert a null Value into SlotTracker!");
1160 unsigned DestSlot = mNext++;
1163 ST_DEBUG(
" Inserting value [" << V->
getType() <<
"] = " << V <<
" slot=" <<
1166 ST_DEBUG((isa<GlobalVariable>(V) ?
'G' :
1167 (isa<Function>(V) ?
'F' :
1168 (isa<GlobalAlias>(V) ?
'A' :
1169 (isa<GlobalIFunc>(V) ?
'I' :
'o')))) <<
"]\n");
1173 void SlotTracker::CreateFunctionSlot(
const Value *V) {
1176 unsigned DestSlot = fNext++;
1180 ST_DEBUG(
" Inserting value [" << V->
getType() <<
"] = " << V <<
" slot=" <<
1181 DestSlot <<
" [o]\n");
1185 void SlotTracker::CreateMetadataSlot(
const MDNode *
N) {
1186 assert(N &&
"Can't insert a null Value into SlotTracker!");
1189 if (isa<DIExpression>(N))
1192 unsigned DestSlot = mdnNext;
1193 if (!mdnMap.insert(std::make_pair(N, DestSlot)).second)
1200 CreateMetadataSlot(
Op);
1203 void SlotTracker::CreateAttributeSetSlot(
AttributeSet AS) {
1206 as_iterator I = asMap.find(AS);
1207 if (I != asMap.end())
1210 unsigned DestSlot = asNext++;
1211 asMap[AS] = DestSlot;
1215 void SlotTracker::CreateModulePathSlot(
StringRef Path) {
1216 ModulePathMap[Path] = ModulePathNext++;
1221 GUIDMap[GUID] = GUIDNext++;
1225 void SlotTracker::CreateTypeIdSlot(
StringRef Id) {
1226 TypeIdMap[
Id] = TypeIdNext++;
1234 TypePrinting *TypePrinter,
1239 TypePrinting *TypePrinter,
1241 bool FromValue =
false);
1244 if (
const FPMathOperator *FPO = dyn_cast<const FPMathOperator>(U)) {
1249 if (FPO->hasAllowReassoc())
1251 if (FPO->hasNoNaNs())
1253 if (FPO->hasNoInfs())
1255 if (FPO->hasNoSignedZeros())
1257 if (FPO->hasAllowReciprocal())
1259 if (FPO->hasAllowContract())
1261 if (FPO->hasApproxFunc())
1267 dyn_cast<OverflowingBinaryOperator>(U)) {
1268 if (OBO->hasNoUnsignedWrap())
1270 if (OBO->hasNoSignedWrap())
1273 dyn_cast<PossiblyExactOperator>(U)) {
1277 if (
GEP->isInBounds())
1283 TypePrinting &TypePrinter,
1286 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
1287 if (CI->getType()->isIntegerTy(1)) {
1288 Out << (CI->getZExtValue() ?
"true" :
"false");
1291 Out << CI->getValue();
1295 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
1296 const APFloat &APF = CFP->getValueAPF();
1307 bool isNaN = APF.
isNaN();
1308 if (!isInf && !isNaN) {
1316 assert(((StrVal[0] >=
'0' && StrVal[0] <=
'9') ||
1317 ((StrVal[0] ==
'-' || StrVal[0] ==
'+') &&
1318 (StrVal[1] >=
'0' && StrVal[1] <=
'9'))) &&
1319 "[-+]?[0-9] regex does not match!");
1330 static_assert(
sizeof(
double) ==
sizeof(uint64_t),
1331 "assuming that double is 64 bits!");
1374 if (isa<ConstantAggregateZero>(CV)) {
1375 Out <<
"zeroinitializer";
1379 if (
const BlockAddress *BA = dyn_cast<BlockAddress>(CV)) {
1380 Out <<
"blockaddress(";
1390 if (
const ConstantArray *CA = dyn_cast<ConstantArray>(CV)) {
1391 Type *ETy = CA->getType()->getElementType();
1393 TypePrinter.print(ETy, Out);
1398 for (
unsigned i = 1, e = CA->getNumOperands(); i != e; ++i) {
1400 TypePrinter.print(ETy, Out);
1412 if (CA->isString()) {
1419 Type *ETy = CA->getType()->getElementType();
1421 TypePrinter.print(ETy, Out);
1426 for (
unsigned i = 1, e = CA->getNumElements(); i != e; ++i) {
1428 TypePrinter.print(ETy, Out);
1438 if (CS->getType()->isPacked())
1444 TypePrinter.print(CS->getOperand(0)->getType(), Out);
1450 for (
unsigned i = 1; i <
N; i++) {
1452 TypePrinter.print(CS->getOperand(i)->getType(), Out);
1462 if (CS->getType()->isPacked())
1467 if (isa<ConstantVector>(CV) || isa<ConstantDataVector>(CV)) {
1470 TypePrinter.print(ETy, Out);
1476 TypePrinter.print(ETy, Out);
1485 if (isa<ConstantPointerNull>(CV)) { 1490 if (isa<ConstantTokenNone>(CV)) { 1495 if (isa<UndefValue>(CV)) { 1500 if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) { 1501 Out << CE->getOpcodeName(); 1502 WriteOptimizationInfo(Out, CE); 1503 if (CE->isCompare()) 1504 Out << ' ' << CmpInst::getPredicateName( 1505 static_cast<CmpInst::Predicate>(CE->getPredicate())); 1508 Optional<unsigned> InRangeOp; 1509 if (const GEPOperator *GEP = dyn_cast<GEPOperator>(CE)) { 1510 TypePrinter.print(GEP->getSourceElementType(), Out); 1512 InRangeOp = GEP->getInRangeIndex(); 1517 for (User::const_op_iterator OI=CE->op_begin(); OI != CE->op_end(); ++OI) { 1518 if (InRangeOp && unsigned(OI - CE->op_begin()) == *InRangeOp) 1520 TypePrinter.print((*OI)->getType(), Out); 1522 WriteAsOperandInternal(Out, *OI, &TypePrinter, Machine, Context); 1523 if (OI+1 != CE->op_end()) 1527 if (CE->hasIndices()) { 1528 ArrayRef<unsigned> Indices = CE->getIndices(); 1529 for (unsigned i = 0, e = Indices.size(); i != e; ++i) 1530 Out << ", " << Indices[i]; 1535 TypePrinter.print(CE->getType(), Out); 1542 Out << "<placeholder or erroneous Constant>"; 1545 static void writeMDTuple(raw_ostream &Out, const MDTuple *Node, 1546 TypePrinting *TypePrinter, SlotTracker *Machine, 1547 const Module *Context) { 1549 for (unsigned mi = 0, me = Node->getNumOperands(); mi != me; ++mi) { 1550 const Metadata *MD = Node->getOperand(mi); 1553 else if (auto *MDV = dyn_cast<ValueAsMetadata>(MD)) { 1554 Value *V = MDV->getValue(); 1555 TypePrinter->print(V->getType(), Out); 1557 WriteAsOperandInternal(Out, V, TypePrinter, Machine, Context); 1559 WriteAsOperandInternal(Out, MD, TypePrinter, Machine, Context); 1570 struct FieldSeparator { 1574 FieldSeparator(const char *Sep = ", ") : Sep(Sep) {} 1577 raw_ostream &operator<<(raw_ostream &OS, FieldSeparator &FS) { 1582 return OS << FS.Sep; 1585 struct MDFieldPrinter { 1588 TypePrinting *TypePrinter = nullptr; 1589 SlotTracker *Machine = nullptr; 1590 const Module *Context = nullptr; 1592 explicit MDFieldPrinter(raw_ostream &Out) : Out(Out) {} 1593 MDFieldPrinter(raw_ostream &Out, TypePrinting *TypePrinter, 1594 SlotTracker *Machine, const Module *Context) 1595 : Out(Out), TypePrinter(TypePrinter), Machine(Machine), Context(Context) { 1598 void printTag(const DINode *N); 1599 void printMacinfoType(const DIMacroNode *N); 1600 void printChecksum(const DIFile::ChecksumInfo<StringRef> &N); 1601 void printString(StringRef Name, StringRef Value, 1602 bool ShouldSkipEmpty = true); 1603 void printMetadata(StringRef Name, const Metadata *MD, 1604 bool ShouldSkipNull = true); 1605 template <class IntTy> 1606 void printInt(StringRef Name, IntTy Int, bool ShouldSkipZero = true); 1607 void printBool(StringRef Name, bool Value, Optional<bool> Default = None); 1608 void printDIFlags(StringRef Name, DINode::DIFlags Flags); 1609 void printDISPFlags(StringRef Name, DISubprogram::DISPFlags Flags); 1610 template <class IntTy, class Stringifier> 1611 void printDwarfEnum(StringRef Name, IntTy Value, Stringifier toString, 1612 bool ShouldSkipZero = true); 1613 void printEmissionKind(StringRef Name, DICompileUnit::DebugEmissionKind EK); 1614 void printNameTableKind(StringRef Name, 1615 DICompileUnit::DebugNameTableKind NTK); 1618 } // end anonymous namespace 1620 void MDFieldPrinter::printTag(const DINode *N) { 1621 Out << FS << "tag: "; 1622 auto Tag = dwarf::TagString(N->getTag()); 1629 void MDFieldPrinter::printMacinfoType(const DIMacroNode *N) { 1630 Out << FS << "type: "; 1631 auto Type = dwarf::MacinfoString(N->getMacinfoType()); 1635 Out << N->getMacinfoType(); 1638 void MDFieldPrinter::printChecksum( 1639 const DIFile::ChecksumInfo<StringRef> &Checksum) { 1640 Out << FS << "checksumkind: " << Checksum.getKindAsString(); 1641 printString("checksum", Checksum.Value, /* ShouldSkipEmpty */ false); 1644 void MDFieldPrinter::printString(StringRef Name, StringRef Value, 1645 bool ShouldSkipEmpty) { 1646 if (ShouldSkipEmpty && Value.empty()) 1649 Out << FS << Name << ": \""; 1650 printEscapedString(Value, Out); 1654 static void writeMetadataAsOperand(raw_ostream &Out, const Metadata *MD, 1655 TypePrinting *TypePrinter, 1656 SlotTracker *Machine, 1657 const Module *Context) { 1662 WriteAsOperandInternal(Out, MD, TypePrinter, Machine, Context); 1665 void MDFieldPrinter::printMetadata(StringRef Name, const Metadata *MD, 1666 bool ShouldSkipNull) { 1667 if (ShouldSkipNull && !MD) 1670 Out << FS << Name << ": "; 1671 writeMetadataAsOperand(Out, MD, TypePrinter, Machine, Context); 1674 template <class IntTy> 1675 void MDFieldPrinter::printInt(StringRef Name, IntTy Int, bool ShouldSkipZero) { 1676 if (ShouldSkipZero && !Int) 1679 Out << FS << Name << ": " << Int; 1682 void MDFieldPrinter::printBool(StringRef Name, bool Value, 1683 Optional<bool> Default) { 1684 if (Default && Value == *Default) 1686 Out << FS << Name << ": " << (Value ? "true" : "false"); 1689 void MDFieldPrinter::printDIFlags(StringRef Name, DINode::DIFlags Flags) { 1693 Out << FS << Name << ": "; 1695 SmallVector<DINode::DIFlags, 8> SplitFlags; 1696 auto Extra = DINode::splitFlags(Flags, SplitFlags); 1698 FieldSeparator FlagsFS(" | "); 1699 for (auto F : SplitFlags) { 1700 auto StringF = DINode::getFlagString(F); 1701 assert(!StringF.empty() && "Expected valid flag"); 1702 Out << FlagsFS << StringF; 1704 if (Extra || SplitFlags.empty()) 1705 Out << FlagsFS << Extra; 1708 void MDFieldPrinter::printDISPFlags(StringRef Name, 1709 DISubprogram::DISPFlags Flags) { 1710 // Always print this field, because no flags in the IR at all will be 1711 // interpreted as old-style isDefinition: true. 1712 Out << FS << Name << ": "; 1719 SmallVector<DISubprogram::DISPFlags, 8> SplitFlags; 1720 auto Extra = DISubprogram::splitFlags(Flags, SplitFlags); 1722 FieldSeparator FlagsFS(" | "); 1723 for (auto F : SplitFlags) { 1724 auto StringF = DISubprogram::getFlagString(F); 1725 assert(!StringF.empty() && "Expected valid flag"); 1726 Out << FlagsFS << StringF; 1728 if (Extra || SplitFlags.empty()) 1729 Out << FlagsFS << Extra; 1732 void MDFieldPrinter::printEmissionKind(StringRef Name, 1733 DICompileUnit::DebugEmissionKind EK) { 1734 Out << FS << Name << ": " << DICompileUnit::emissionKindString(EK); 1737 void MDFieldPrinter::printNameTableKind(StringRef Name, 1738 DICompileUnit::DebugNameTableKind NTK) { 1739 if (NTK == DICompileUnit::DebugNameTableKind::Default) 1741 Out << FS << Name << ": " << DICompileUnit::nameTableKindString(NTK); 1744 template <class IntTy, class Stringifier> 1745 void MDFieldPrinter::printDwarfEnum(StringRef Name, IntTy Value, 1746 Stringifier toString, bool ShouldSkipZero) { 1750 Out << FS << Name << ": "; 1751 auto S = toString(Value); 1758 static void writeGenericDINode(raw_ostream &Out, const GenericDINode *N, 1759 TypePrinting *TypePrinter, SlotTracker *Machine, 1760 const Module *Context) { 1761 Out << "!GenericDINode("; 1762 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 1763 Printer.printTag(N); 1764 Printer.printString("header", N->getHeader()); 1765 if (N->getNumDwarfOperands()) { 1766 Out << Printer.FS << "operands: {"; 1768 for (auto &I : N->dwarf_operands()) { 1770 writeMetadataAsOperand(Out, I, TypePrinter, Machine, Context); 1777 static void writeDILocation(raw_ostream &Out, const DILocation *DL, 1778 TypePrinting *TypePrinter, SlotTracker *Machine, 1779 const Module *Context) { 1780 Out << "!DILocation("; 1781 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 1782 // Always output the line, since 0 is a relevant and important value for it. 1783 Printer.printInt("line", DL->getLine(), /* ShouldSkipZero */ false); 1784 Printer.printInt("column", DL->getColumn()); 1785 Printer.printMetadata("scope", DL->getRawScope(), /* ShouldSkipNull */ false); 1786 Printer.printMetadata("inlinedAt", DL->getRawInlinedAt()); 1787 Printer.printBool("isImplicitCode", DL->isImplicitCode(), 1788 /* Default */ false); 1792 static void writeDISubrange(raw_ostream &Out, const DISubrange *N, 1793 TypePrinting *TypePrinter, SlotTracker *Machine, 1794 const Module *Context) { 1795 Out << "!DISubrange("; 1796 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 1797 if (auto *CE = N->getCount().dyn_cast<ConstantInt*>()) 1798 Printer.printInt("count", CE->getSExtValue(), /* ShouldSkipZero */ false); 1800 Printer.printMetadata("count", N->getCount().dyn_cast<DIVariable*>(), 1801 /*ShouldSkipNull */ false); 1802 Printer.printInt("lowerBound", N->getLowerBound()); 1806 static void writeDIEnumerator(raw_ostream &Out, const DIEnumerator *N, 1807 TypePrinting *, SlotTracker *, const Module *) { 1808 Out << "!DIEnumerator("; 1809 MDFieldPrinter Printer(Out); 1810 Printer.printString("name", N->getName(), /* ShouldSkipEmpty */ false); 1811 if (N->isUnsigned()) { 1812 auto Value = static_cast<uint64_t>(N->getValue()); 1813 Printer.printInt("value", Value, /* ShouldSkipZero */ false); 1814 Printer.printBool("isUnsigned", true); 1816 Printer.printInt("value", N->getValue(), /* ShouldSkipZero */ false); 1821 static void writeDIBasicType(raw_ostream &Out, const DIBasicType *N, 1822 TypePrinting *, SlotTracker *, const Module *) { 1823 Out << "!DIBasicType("; 1824 MDFieldPrinter Printer(Out); 1825 if (N->getTag() != dwarf::DW_TAG_base_type) 1826 Printer.printTag(N); 1827 Printer.printString("name", N->getName()); 1828 Printer.printInt("size", N->getSizeInBits()); 1829 Printer.printInt("align", N->getAlignInBits()); 1830 Printer.printDwarfEnum("encoding", N->getEncoding(), 1831 dwarf::AttributeEncodingString); 1832 Printer.printDIFlags("flags", N->getFlags()); 1836 static void writeDIDerivedType(raw_ostream &Out, const DIDerivedType *N, 1837 TypePrinting *TypePrinter, SlotTracker *Machine, 1838 const Module *Context) { 1839 Out << "!DIDerivedType("; 1840 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 1841 Printer.printTag(N); 1842 Printer.printString("name", N->getName()); 1843 Printer.printMetadata("scope", N->getRawScope()); 1844 Printer.printMetadata("file", N->getRawFile()); 1845 Printer.printInt("line", N->getLine()); 1846 Printer.printMetadata("baseType", N->getRawBaseType(), 1847 /* ShouldSkipNull */ false); 1848 Printer.printInt("size", N->getSizeInBits()); 1849 Printer.printInt("align", N->getAlignInBits()); 1850 Printer.printInt("offset", N->getOffsetInBits()); 1851 Printer.printDIFlags("flags", N->getFlags()); 1852 Printer.printMetadata("extraData", N->getRawExtraData()); 1853 if (const auto &DWARFAddressSpace = N->getDWARFAddressSpace()) 1854 Printer.printInt("dwarfAddressSpace", *DWARFAddressSpace, 1855 /* ShouldSkipZero */ false); 1859 static void writeDICompositeType(raw_ostream &Out, const DICompositeType *N, 1860 TypePrinting *TypePrinter, 1861 SlotTracker *Machine, const Module *Context) { 1862 Out << "!DICompositeType("; 1863 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 1864 Printer.printTag(N); 1865 Printer.printString("name", N->getName()); 1866 Printer.printMetadata("scope", N->getRawScope()); 1867 Printer.printMetadata("file", N->getRawFile()); 1868 Printer.printInt("line", N->getLine()); 1869 Printer.printMetadata("baseType", N->getRawBaseType()); 1870 Printer.printInt("size", N->getSizeInBits()); 1871 Printer.printInt("align", N->getAlignInBits()); 1872 Printer.printInt("offset", N->getOffsetInBits()); 1873 Printer.printDIFlags("flags", N->getFlags()); 1874 Printer.printMetadata("elements", N->getRawElements()); 1875 Printer.printDwarfEnum("runtimeLang", N->getRuntimeLang(), 1876 dwarf::LanguageString); 1877 Printer.printMetadata("vtableHolder", N->getRawVTableHolder()); 1878 Printer.printMetadata("templateParams", N->getRawTemplateParams()); 1879 Printer.printString("identifier", N->getIdentifier()); 1880 Printer.printMetadata("discriminator", N->getRawDiscriminator()); 1884 static void writeDISubroutineType(raw_ostream &Out, const DISubroutineType *N, 1885 TypePrinting *TypePrinter, 1886 SlotTracker *Machine, const Module *Context) { 1887 Out << "!DISubroutineType("; 1888 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 1889 Printer.printDIFlags("flags", N->getFlags()); 1890 Printer.printDwarfEnum("cc", N->getCC(), dwarf::ConventionString); 1891 Printer.printMetadata("types", N->getRawTypeArray(), 1892 /* ShouldSkipNull */ false); 1896 static void writeDIFile(raw_ostream &Out, const DIFile *N, TypePrinting *, 1897 SlotTracker *, const Module *) { 1899 MDFieldPrinter Printer(Out); 1900 Printer.printString("filename", N->getFilename(), 1901 /* ShouldSkipEmpty */ false); 1902 Printer.printString("directory", N->getDirectory(), 1903 /* ShouldSkipEmpty */ false); 1904 // Print all values for checksum together, or not at all. 1905 if (N->getChecksum()) 1906 Printer.printChecksum(*N->getChecksum()); 1907 Printer.printString("source", N->getSource().getValueOr(StringRef()), 1908 /* ShouldSkipEmpty */ true); 1912 static void writeDICompileUnit(raw_ostream &Out, const DICompileUnit *N, 1913 TypePrinting *TypePrinter, SlotTracker *Machine, 1914 const Module *Context) { 1915 Out << "!DICompileUnit("; 1916 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 1917 Printer.printDwarfEnum("language", N->getSourceLanguage(), 1918 dwarf::LanguageString, /* ShouldSkipZero */ false); 1919 Printer.printMetadata("file", N->getRawFile(), /* ShouldSkipNull */ false); 1920 Printer.printString("producer", N->getProducer()); 1921 Printer.printBool("isOptimized", N->isOptimized()); 1922 Printer.printString("flags", N->getFlags()); 1923 Printer.printInt("runtimeVersion", N->getRuntimeVersion(), 1924 /* ShouldSkipZero */ false); 1925 Printer.printString("splitDebugFilename", N->getSplitDebugFilename()); 1926 Printer.printEmissionKind("emissionKind", N->getEmissionKind()); 1927 Printer.printMetadata("enums", N->getRawEnumTypes()); 1928 Printer.printMetadata("retainedTypes", N->getRawRetainedTypes()); 1929 Printer.printMetadata("globals", N->getRawGlobalVariables()); 1930 Printer.printMetadata("imports", N->getRawImportedEntities()); 1931 Printer.printMetadata("macros", N->getRawMacros()); 1932 Printer.printInt("dwoId", N->getDWOId()); 1933 Printer.printBool("splitDebugInlining", N->getSplitDebugInlining(), true); 1934 Printer.printBool("debugInfoForProfiling", N->getDebugInfoForProfiling(), 1936 Printer.printNameTableKind("nameTableKind", N->getNameTableKind()); 1937 Printer.printBool("rangesBaseAddress", N->getRangesBaseAddress(), false); 1941 static void writeDISubprogram(raw_ostream &Out, const DISubprogram *N, 1942 TypePrinting *TypePrinter, SlotTracker *Machine, 1943 const Module *Context) { 1944 Out << "!DISubprogram("; 1945 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 1946 Printer.printString("name", N->getName()); 1947 Printer.printString("linkageName", N->getLinkageName()); 1948 Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false); 1949 Printer.printMetadata("file", N->getRawFile()); 1950 Printer.printInt("line", N->getLine()); 1951 Printer.printMetadata("type", N->getRawType()); 1952 Printer.printInt("scopeLine", N->getScopeLine()); 1953 Printer.printMetadata("containingType", N->getRawContainingType()); 1954 if (N->getVirtuality() != dwarf::DW_VIRTUALITY_none || 1955 N->getVirtualIndex() != 0) 1956 Printer.printInt("virtualIndex", N->getVirtualIndex(), false); 1957 Printer.printInt("thisAdjustment", N->getThisAdjustment()); 1958 Printer.printDIFlags("flags", N->getFlags()); 1959 Printer.printDISPFlags("spFlags", N->getSPFlags()); 1960 Printer.printMetadata("unit", N->getRawUnit()); 1961 Printer.printMetadata("templateParams", N->getRawTemplateParams()); 1962 Printer.printMetadata("declaration", N->getRawDeclaration()); 1963 Printer.printMetadata("retainedNodes", N->getRawRetainedNodes()); 1964 Printer.printMetadata("thrownTypes", N->getRawThrownTypes()); 1968 static void writeDILexicalBlock(raw_ostream &Out, const DILexicalBlock *N, 1969 TypePrinting *TypePrinter, SlotTracker *Machine, 1970 const Module *Context) { 1971 Out << "!DILexicalBlock("; 1972 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 1973 Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false); 1974 Printer.printMetadata("file", N->getRawFile()); 1975 Printer.printInt("line", N->getLine()); 1976 Printer.printInt("column", N->getColumn()); 1980 static void writeDILexicalBlockFile(raw_ostream &Out, 1981 const DILexicalBlockFile *N, 1982 TypePrinting *TypePrinter, 1983 SlotTracker *Machine, 1984 const Module *Context) { 1985 Out << "!DILexicalBlockFile("; 1986 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 1987 Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false); 1988 Printer.printMetadata("file", N->getRawFile()); 1989 Printer.printInt("discriminator", N->getDiscriminator(), 1990 /* ShouldSkipZero */ false); 1994 static void writeDINamespace(raw_ostream &Out, const DINamespace *N, 1995 TypePrinting *TypePrinter, SlotTracker *Machine, 1996 const Module *Context) { 1997 Out << "!DINamespace("; 1998 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 1999 Printer.printString("name", N->getName()); 2000 Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false); 2001 Printer.printBool("exportSymbols", N->getExportSymbols(), false); 2005 static void writeDIMacro(raw_ostream &Out, const DIMacro *N, 2006 TypePrinting *TypePrinter, SlotTracker *Machine, 2007 const Module *Context) { 2009 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 2010 Printer.printMacinfoType(N); 2011 Printer.printInt("line", N->getLine()); 2012 Printer.printString("name", N->getName()); 2013 Printer.printString("value", N->getValue()); 2017 static void writeDIMacroFile(raw_ostream &Out, const DIMacroFile *N, 2018 TypePrinting *TypePrinter, SlotTracker *Machine, 2019 const Module *Context) { 2020 Out << "!DIMacroFile("; 2021 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 2022 Printer.printInt("line", N->getLine()); 2023 Printer.printMetadata("file", N->getRawFile(), /* ShouldSkipNull */ false); 2024 Printer.printMetadata("nodes", N->getRawElements()); 2028 static void writeDIModule(raw_ostream &Out, const DIModule *N, 2029 TypePrinting *TypePrinter, SlotTracker *Machine, 2030 const Module *Context) { 2031 Out << "!DIModule("; 2032 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 2033 Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false); 2034 Printer.printString("name", N->getName()); 2035 Printer.printString("configMacros", N->getConfigurationMacros()); 2036 Printer.printString("includePath", N->getIncludePath()); 2037 Printer.printString("isysroot", N->getISysRoot()); 2042 static void writeDITemplateTypeParameter(raw_ostream &Out, 2043 const DITemplateTypeParameter *N, 2044 TypePrinting *TypePrinter, 2045 SlotTracker *Machine, 2046 const Module *Context) { 2047 Out << "!DITemplateTypeParameter("; 2048 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 2049 Printer.printString("name", N->getName()); 2050 Printer.printMetadata("type", N->getRawType(), /* ShouldSkipNull */ false); 2054 static void writeDITemplateValueParameter(raw_ostream &Out, 2055 const DITemplateValueParameter *N, 2056 TypePrinting *TypePrinter, 2057 SlotTracker *Machine, 2058 const Module *Context) { 2059 Out << "!DITemplateValueParameter("; 2060 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 2061 if (N->getTag() != dwarf::DW_TAG_template_value_parameter) 2062 Printer.printTag(N); 2063 Printer.printString("name", N->getName()); 2064 Printer.printMetadata("type", N->getRawType()); 2065 Printer.printMetadata("value", N->getValue(), /* ShouldSkipNull */ false); 2069 static void writeDIGlobalVariable(raw_ostream &Out, const DIGlobalVariable *N, 2070 TypePrinting *TypePrinter, 2071 SlotTracker *Machine, const Module *Context) { 2072 Out << "!DIGlobalVariable("; 2073 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 2074 Printer.printString("name", N->getName()); 2075 Printer.printString("linkageName", N->getLinkageName()); 2076 Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false); 2077 Printer.printMetadata("file", N->getRawFile()); 2078 Printer.printInt("line", N->getLine()); 2079 Printer.printMetadata("type", N->getRawType()); 2080 Printer.printBool("isLocal", N->isLocalToUnit()); 2081 Printer.printBool("isDefinition", N->isDefinition()); 2082 Printer.printMetadata("declaration", N->getRawStaticDataMemberDeclaration()); 2083 Printer.printMetadata("templateParams", N->getRawTemplateParams()); 2084 Printer.printInt("align", N->getAlignInBits()); 2088 static void writeDILocalVariable(raw_ostream &Out, const DILocalVariable *N, 2089 TypePrinting *TypePrinter, 2090 SlotTracker *Machine, const Module *Context) { 2091 Out << "!DILocalVariable("; 2092 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 2093 Printer.printString("name", N->getName()); 2094 Printer.printInt("arg", N->getArg()); 2095 Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false); 2096 Printer.printMetadata("file", N->getRawFile()); 2097 Printer.printInt("line", N->getLine()); 2098 Printer.printMetadata("type", N->getRawType()); 2099 Printer.printDIFlags("flags", N->getFlags()); 2100 Printer.printInt("align", N->getAlignInBits()); 2104 static void writeDILabel(raw_ostream &Out, const DILabel *N, 2105 TypePrinting *TypePrinter, 2106 SlotTracker *Machine, const Module *Context) { 2108 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 2109 Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false); 2110 Printer.printString("name", N->getName()); 2111 Printer.printMetadata("file", N->getRawFile()); 2112 Printer.printInt("line", N->getLine()); 2116 static void writeDIExpression(raw_ostream &Out, const DIExpression *N, 2117 TypePrinting *TypePrinter, SlotTracker *Machine, 2118 const Module *Context) { 2119 Out << "!DIExpression("; 2122 for (auto I = N->expr_op_begin(), E = N->expr_op_end(); I != E; ++I) { 2123 auto OpStr = dwarf::OperationEncodingString(I->getOp()); 2124 assert(!OpStr.empty() && "Expected valid opcode"); 2127 for (unsigned A = 0, AE = I->getNumArgs(); A != AE; ++A) 2128 Out << FS << I->getArg(A); 2131 for (const auto &I : N->getElements()) 2137 static void writeDIGlobalVariableExpression(raw_ostream &Out, 2138 const DIGlobalVariableExpression *N, 2139 TypePrinting *TypePrinter, 2140 SlotTracker *Machine, 2141 const Module *Context) { 2142 Out << "!DIGlobalVariableExpression("; 2143 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 2144 Printer.printMetadata("var", N->getVariable()); 2145 Printer.printMetadata("expr", N->getExpression()); 2149 static void writeDIObjCProperty(raw_ostream &Out, const DIObjCProperty *N, 2150 TypePrinting *TypePrinter, SlotTracker *Machine, 2151 const Module *Context) { 2152 Out << "!DIObjCProperty("; 2153 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 2154 Printer.printString("name", N->getName()); 2155 Printer.printMetadata("file", N->getRawFile()); 2156 Printer.printInt("line", N->getLine()); 2157 Printer.printString("setter", N->getSetterName()); 2158 Printer.printString("getter", N->getGetterName()); 2159 Printer.printInt("attributes", N->getAttributes()); 2160 Printer.printMetadata("type", N->getRawType()); 2164 static void writeDIImportedEntity(raw_ostream &Out, const DIImportedEntity *N, 2165 TypePrinting *TypePrinter, 2166 SlotTracker *Machine, const Module *Context) { 2167 Out << "!DIImportedEntity("; 2168 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 2169 Printer.printTag(N); 2170 Printer.printString("name", N->getName()); 2171 Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false); 2172 Printer.printMetadata("entity", N->getRawEntity()); 2173 Printer.printMetadata("file", N->getRawFile()); 2174 Printer.printInt("line", N->getLine()); 2178 static void WriteMDNodeBodyInternal(raw_ostream &Out, const MDNode *Node, 2179 TypePrinting *TypePrinter, 2180 SlotTracker *Machine, 2181 const Module *Context) { 2182 if (Node->isDistinct()) 2184 else if (Node->isTemporary()) 2185 Out << "<temporary!> "; // Handle broken code. 2187 switch (Node->getMetadataID()) { 2189 llvm_unreachable("Expected uniquable MDNode"); 2190 #define HANDLE_MDNODE_LEAF(CLASS) \ 2191 case Metadata::CLASS##Kind: \ 2192 write##CLASS(Out, cast<CLASS>(Node), TypePrinter, Machine, Context); \ 2194 #include "llvm/IR/Metadata.def" 2198 // Full implementation of printing a Value as an operand with support for 2199 // TypePrinting, etc. 2200 static void WriteAsOperandInternal(raw_ostream &Out, const Value *V, 2201 TypePrinting *TypePrinter, 2202 SlotTracker *Machine, 2203 const Module *Context) { 2205 PrintLLVMName(Out, V); 2209 const Constant *CV = dyn_cast<Constant>(V); 2210 if (CV && !isa<GlobalValue>(CV)) { 2211 assert(TypePrinter && "Constants require TypePrinting!"); 2212 WriteConstantInternal(Out, CV, *TypePrinter, Machine, Context); 2216 if (const InlineAsm *IA = dyn_cast<InlineAsm>(V)) { 2218 if (IA->hasSideEffects()) 2219 Out << "sideeffect "; 2220 if (IA->isAlignStack()) 2221 Out << "alignstack "; 2222 // We don't emit the AD_ATT dialect as it
's the assumed default. 2223 if (IA->getDialect() == InlineAsm::AD_Intel) 2224 Out << "inteldialect "; 2226 printEscapedString(IA->getAsmString(), Out); 2233 if (
auto *MD = dyn_cast<MetadataAsValue>(V)) {
2243 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
2244 Slot = Machine->getGlobalSlot(GV);
2247 Slot = Machine->getLocalSlot(V);
2254 Slot = Machine->getLocalSlot(V);
2260 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
2261 Slot = Machine->getGlobalSlot(GV);
2264 Slot = Machine->getLocalSlot(V);
2273 Out << Prefix << Slot;
2279 TypePrinting *TypePrinter,
2284 if (
const DIExpression *Expr = dyn_cast<DIExpression>(MD)) {
2289 if (
const MDNode *N = dyn_cast<MDNode>(MD)) {
2290 std::unique_ptr<SlotTracker> MachineStorage;
2292 MachineStorage = make_unique<SlotTracker>(
Context);
2293 Machine = MachineStorage.get();
2297 if (
const DILocation *Loc = dyn_cast<DILocation>(N)) {
2303 Out <<
"<" << N <<
">";
2309 if (
const MDString *MDS = dyn_cast<MDString>(MD)) {
2316 auto *V = cast<ValueAsMetadata>(MD);
2317 assert(TypePrinter &&
"TypePrinter required for metadata values");
2318 assert((FromValue || !isa<LocalAsMetadata>(V)) &&
2319 "Unexpected function-local metadata outside of value argument");
2321 TypePrinter->print(V->getValue()->
getType(), Out);
2328 class AssemblyWriter {
2330 const Module *TheModule =
nullptr;
2332 std::unique_ptr<SlotTracker> SlotTrackerStorage;
2334 TypePrinting TypePrinter;
2338 bool ShouldPreserveUseListOrder;
2349 bool ShouldPreserveUseListOrder =
false);
2354 void printMDNodeBody(
const MDNode *MD);
2357 void printModule(
const Module *M);
2359 void writeOperand(
const Value *
Op,
bool PrintType);
2361 void writeOperandBundles(
const CallBase *Call);
2367 void writeAtomicCmpXchg(
const LLVMContext &Context,
2372 void writeAllMDNodes();
2373 void writeMDNode(
unsigned Slot,
const MDNode *Node);
2374 void writeAllAttributeGroups();
2376 void printTypeIdentities();
2379 void printComdat(
const Comdat *
C);
2380 void printFunction(
const Function *F);
2387 void printUseLists(
const Function *F);
2389 void printModuleSummaryIndex();
2390 void printSummaryInfo(
unsigned Slot,
const ValueInfo &
VI);
2397 void printArgs(
const std::vector<uint64_t> &
Args);
2402 printNonConstVCalls(
const std::vector<FunctionSummary::VFuncId> VCallList,
2405 printConstVCalls(
const std::vector<FunctionSummary::ConstVCall> VCallList,
2410 void printMetadataAttachments(
2416 void printInfoComment(
const Value &V);
2427 bool IsForDebug,
bool ShouldPreserveUseListOrder)
2428 : Out(o), TheModule(M),
Machine(Mac), TypePrinter(M), AnnotationWriter(AAW),
2429 IsForDebug(IsForDebug),
2430 ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) {
2433 for (
const GlobalObject &GO : TheModule->global_objects())
2440 : Out(o), TheIndex(Index),
Machine(Mac), TypePrinter(
nullptr),
2441 IsForDebug(IsForDebug), ShouldPreserveUseListOrder(
false) {}
2443 void AssemblyWriter::writeOperand(
const Value *Operand,
bool PrintType) {
2445 Out <<
"<null operand!>";
2449 TypePrinter.print(Operand->
getType(), Out);
2455 void AssemblyWriter::writeSyncScope(
const LLVMContext &Context,
2465 Out <<
" syncscope(\"";
2473 void AssemblyWriter::writeAtomic(
const LLVMContext &Context,
2479 writeSyncScope(Context, SSID);
2483 void AssemblyWriter::writeAtomicCmpXchg(
const LLVMContext &Context,
2490 writeSyncScope(Context, SSID);
2495 void AssemblyWriter::writeParamOperand(
const Value *Operand,
2498 Out <<
"<null operand!>";
2503 TypePrinter.print(Operand->
getType(), Out);
2512 void AssemblyWriter::writeOperandBundles(
const CallBase *Call) {
2518 bool FirstBundle =
true;
2524 FirstBundle =
false;
2532 bool FirstInput =
true;
2533 for (
const auto &Input : BU.
Inputs) {
2538 TypePrinter.print(Input->getType(), Out);
2549 void AssemblyWriter::printModule(
const Module *M) {
2550 Machine.initializeIfNeeded();
2552 if (ShouldPreserveUseListOrder)
2562 Out <<
"source_filename = \"";
2569 Out <<
"target datalayout = \"" << DL <<
"\"\n";
2580 std::tie(Front, Asm) = Asm.
split(
'\n');
2584 Out <<
"module asm \"";
2587 }
while (!Asm.
empty());
2590 printTypeIdentities();
2593 if (!Comdats.empty())
2595 for (
const Comdat *
C : Comdats) {
2597 if (
C != Comdats.back())
2604 printGlobal(&GV); Out <<
'\n';
2610 printIndirectSymbol(&GA);
2615 printIndirectSymbol(&GI);
2618 printUseLists(
nullptr);
2623 assert(UseListOrders.empty() &&
"All use-lists should have been consumed");
2626 if (!Machine.as_empty()) {
2628 writeAllAttributeGroups();
2632 if (!M->named_metadata_empty()) Out <<
'\n';
2634 for (
const NamedMDNode &Node : M->named_metadata())
2635 printNamedMDNode(&Node);
2638 if (!Machine.mdn_empty()) {
2644 void AssemblyWriter::printModuleSummaryIndex() {
2646 Machine.initializeIndexIfNeeded();
2652 std::vector<std::pair<std::string, ModuleHash>> moduleVec;
2653 std::string RegularLTOModuleName =
"[Regular LTO]";
2654 moduleVec.resize(TheIndex->modulePaths().size());
2655 for (
auto &ModPath : TheIndex->modulePaths())
2656 moduleVec[Machine.getModulePathSlot(ModPath.first())] = std::make_pair(
2659 ModPath.second.first == -1u ? RegularLTOModuleName
2660 : (std::string)ModPath.first(),
2661 ModPath.second.second);
2664 for (
auto &ModPair : moduleVec) {
2665 Out <<
"^" << i++ <<
" = module: (";
2668 Out <<
"\", hash: (";
2670 for (
auto Hash : ModPair.second)
2677 for (
auto &GlobalList : *TheIndex) {
2678 auto GUID = GlobalList.first;
2679 for (
auto &Summary : GlobalList.second.SummaryList)
2680 SummaryToGUIDMap[Summary.get()] = GUID;
2684 for (
auto &GlobalList : *TheIndex) {
2685 auto GUID = GlobalList.first;
2686 auto VI = TheIndex->getValueInfo(GlobalList);
2687 printSummaryInfo(Machine.getGUIDSlot(GUID),
VI);
2691 for (
auto TidIter = TheIndex->typeIds().begin();
2692 TidIter != TheIndex->typeIds().end(); TidIter++) {
2693 Out <<
"^" << Machine.getTypeIdSlot(TidIter->second.first)
2694 <<
" = typeid: (name: \"" << TidIter->second.first <<
"\"";
2695 printTypeIdSummary(TidIter->second.second);
2696 Out <<
") ; guid = " << TidIter->first <<
"\n";
2706 return "singleImpl";
2708 return "branchFunnel";
2719 return "uniformRetVal";
2721 return "uniqueRetVal";
2723 return "virtualConstProp";
2751 Out <<
", alignLog2: " << TTRes.
AlignLog2;
2753 Out <<
", sizeM1: " << TTRes.
SizeM1;
2763 void AssemblyWriter::printTypeIdSummary(
const TypeIdSummary &TIS) {
2764 Out <<
", summary: (";
2765 printTypeTestResolution(TIS.
TTRes);
2766 if (!TIS.
WPDRes.empty()) {
2767 Out <<
", wpdResolutions: (";
2769 for (
auto &WPDRes : TIS.
WPDRes) {
2771 Out <<
"(offset: " << WPDRes.first <<
", ";
2772 printWPDRes(WPDRes.second);
2780 void AssemblyWriter::printArgs(
const std::vector<uint64_t> &
Args) {
2783 for (
auto arg : Args) {
2791 Out <<
"wpdRes: (kind: ";
2798 Out <<
", resByArg: (";
2800 for (
auto &ResByArg : WPDRes.
ResByArg) {
2802 printArgs(ResByArg.first);
2803 Out <<
", byArg: (kind: ";
2805 if (ResByArg.second.TheKind ==
2807 ResByArg.second.TheKind ==
2809 Out <<
", info: " << ResByArg.second.Info;
2813 if (ResByArg.second.Byte || ResByArg.second.Bit)
2814 Out <<
", byte: " << ResByArg.second.Byte
2815 <<
", bit: " << ResByArg.second.Bit;
2836 void AssemblyWriter::printAliasSummary(
const AliasSummary *AS) {
2837 Out <<
", aliasee: ";
2842 Out <<
"^" << Machine.getGUIDSlot(SummaryToGUIDMap[&AS->
getAliasee()]);
2862 return "linkonce_odr";
2872 return "extern_weak";
2874 return "available_externally";
2888 void AssemblyWriter::printFunctionSummary(
const FunctionSummary *FS) {
2894 Out <<
", funcFlags: (";
2895 Out <<
"readNone: " << FFlags.
ReadNone;
2896 Out <<
", readOnly: " << FFlags.
ReadOnly;
2897 Out <<
", noRecurse: " << FFlags.
NoRecurse;
2899 Out <<
", noInline: " << FFlags.
NoInline;
2902 if (!FS->
calls().empty()) {
2903 Out <<
", calls: (";
2905 for (
auto &Call : FS->
calls()) {
2907 Out <<
"(callee: ^" << Machine.getGUIDSlot(Call.first.getGUID());
2909 Out <<
", hotness: " <<
getHotnessName(Call.second.getHotness());
2910 else if (Call.second.RelBlockFreq)
2911 Out <<
", relbf: " << Call.second.RelBlockFreq;
2918 printTypeIdInfo(*TIdInfo);
2921 void AssemblyWriter::printTypeIdInfo(
2923 Out <<
", typeIdInfo: (";
2924 FieldSeparator TIDFS;
2927 Out <<
"typeTests: (";
2930 auto TidIter = TheIndex->typeIds().equal_range(GUID);
2931 if (TidIter.first == TidIter.second) {
2937 for (
auto It = TidIter.first; It != TidIter.second; ++It) {
2939 auto Slot = Machine.getTypeIdSlot(It->second.first);
2957 "typeTestAssumeConstVCalls");
2962 "typeCheckedLoadConstVCalls");
2968 auto TidIter = TheIndex->typeIds().equal_range(VFId.
GUID);
2969 if (TidIter.first == TidIter.second) {
2970 Out <<
"vFuncId: (";
2971 Out <<
"guid: " << VFId.
GUID;
2972 Out <<
", offset: " << VFId.
Offset;
2978 for (
auto It = TidIter.first; It != TidIter.second; ++It) {
2980 Out <<
"vFuncId: (";
2981 auto Slot = Machine.getTypeIdSlot(It->second.first);
2984 Out <<
", offset: " << VFId.
Offset;
2989 void AssemblyWriter::printNonConstVCalls(
2990 const std::vector<FunctionSummary::VFuncId> VCallList,
const char *
Tag) {
2991 Out << Tag <<
": (";
2993 for (
auto &VFuncId : VCallList) {
2995 printVFuncId(VFuncId);
3000 void AssemblyWriter::printConstVCalls(
3001 const std::vector<FunctionSummary::ConstVCall> VCallList,
const char *Tag) {
3002 Out << Tag <<
": (";
3004 for (
auto &ConstVCall : VCallList) {
3007 printVFuncId(ConstVCall.VFunc);
3008 if (!ConstVCall.Args.empty()) {
3010 printArgs(ConstVCall.Args);
3021 Out <<
"(module: ^" << Machine.getModulePathSlot(Summary.
modulePath())
3025 Out <<
", live: " << GVFlags.
Live;
3026 Out <<
", dsoLocal: " << GVFlags.
DSOLocal;
3030 printAliasSummary(cast<AliasSummary>(&Summary));
3032 printFunctionSummary(cast<FunctionSummary>(&Summary));
3034 printGlobalVarSummary(cast<GlobalVarSummary>(&Summary));
3036 auto RefList = Summary.
refs();
3037 if (!RefList.empty()) {
3040 for (
auto &
Ref : RefList) {
3042 if (
Ref.isReadOnly())
3044 Out <<
"^" << Machine.getGUIDSlot(
Ref.getGUID());
3052 void AssemblyWriter::printSummaryInfo(
unsigned Slot,
const ValueInfo &
VI) {
3053 Out <<
"^" << Slot <<
" = gv: (";
3055 Out <<
"name: \"" << VI.
name() <<
"\"";
3057 Out <<
"guid: " << VI.
getGUID();
3059 Out <<
", summaries: (";
3063 printSummary(*Summary);
3069 Out <<
" ; guid = " << VI.
getGUID();
3076 Out <<
"<empty name> ";
3078 if (isalpha(static_cast<unsigned char>(Name[0])) || Name[0] ==
'-' ||
3079 Name[0] ==
'$' || Name[0] ==
'.' || Name[0] ==
'_')
3082 Out << '\\' << hexdigit(Name[0] >> 4) <<
hexdigit(Name[0] & 0x0F);
3083 for (
unsigned i = 1, e = Name.
size(); i != e; ++i) {
3084 unsigned char C = Name[i];
3085 if (isalnum(static_cast<unsigned char>(C)) || C ==
'-' || C ==
'$' ||
3086 C ==
'.' || C ==
'_')
3089 Out << '\\' << hexdigit(C >> 4) <<
hexdigit(C & 0x0F);
3094 void AssemblyWriter::printNamedMDNode(
const NamedMDNode *NMD) {
3105 if (
auto *Expr = dyn_cast<DIExpression>(Op)) {
3110 int Slot = Machine.getMetadataSlot(Op);
3135 Out <<
"dso_local ";
3153 Out <<
"thread_local ";
3156 Out <<
"thread_local(localdynamic) ";
3159 Out <<
"thread_local(initialexec) ";
3162 Out <<
"thread_local(localexec) ";
3172 return "local_unnamed_addr";
3174 return "unnamed_addr";
3185 if (isa<GlobalVariable>(GO))
3199 Out <<
"; Materializable\n";
3219 Out << (GV->
isConstant() ?
"constant " :
"global ");
3228 Out <<
", section \"";
3238 printMetadataAttachments(MDs,
", ");
3242 Out <<
" #" << Machine.getAttributeGroupSlot(Attrs);
3244 printInfoComment(*GV);
3249 Out <<
"; Materializable\n";
3263 if (isa<GlobalAlias>(GIS))
3265 else if (isa<GlobalIFunc>(GIS))
3277 TypePrinter.print(GIS->
getType(), Out);
3278 Out <<
" <<NULL ALIASEE>>";
3280 writeOperand(IS, !isa<ConstantExpr>(IS));
3283 printInfoComment(*GIS);
3287 void AssemblyWriter::printComdat(
const Comdat *
C) {
3291 void AssemblyWriter::printTypeIdentities() {
3292 if (TypePrinter.empty())
3298 auto &NumberedTypes = TypePrinter.getNumberedTypes();
3299 for (
unsigned I = 0,
E = NumberedTypes.size(); I !=
E; ++
I) {
3300 Out <<
'%' << I <<
" = type ";
3304 TypePrinter.printStructBody(NumberedTypes[I], Out);
3308 auto &NamedTypes = TypePrinter.getNamedTypes();
3309 for (
unsigned I = 0,
E = NamedTypes.size(); I !=
E; ++
I) {
3315 TypePrinter.printStructBody(NamedTypes[I], Out);
3321 void AssemblyWriter::printFunction(
const Function *F) {
3325 if (AnnotationWriter) AnnotationWriter->emitFunctionAnnot(F, Out);
3328 Out <<
"; Materializable\n";
3333 std::string AttrStr;
3336 if (!Attr.isStringAttribute()) {
3337 if (!AttrStr.empty()) AttrStr +=
' ';
3342 if (!AttrStr.empty())
3343 Out <<
"; Function Attrs: " << AttrStr <<
'\n';
3346 Machine.incorporateFunction(F);
3352 printMetadataAttachments(MDs,
" ");
3394 if (
Arg.getArgNo() != 0)
3417 Out <<
" #" << Machine.getAttributeGroupSlot(Attrs.
getFnAttributes());
3419 Out <<
" section \"";
3427 Out <<
" gc \"" << F->
getGC() <<
'"';
3433 Out <<
" prologue ";
3437 Out <<
" personality ";
3446 printMetadataAttachments(MDs,
" ");
3451 printBasicBlock(&BB);
3459 Machine.purgeFunction();
3466 TypePrinter.print(Arg->
getType(), Out);
3480 void AssemblyWriter::printBasicBlock(
const BasicBlock *BB) {
3486 Out <<
"\n; <label>:";
3487 int Slot = Machine.getLocalSlot(BB);
3495 Out.PadToColumn(50);
3496 Out <<
"; Error: Block without parent!";
3499 Out.PadToColumn(50);
3504 Out <<
" No predecessors!";
3507 writeOperand(*PI,
false);
3508 for (++PI; PI != PE; ++PI) {
3510 writeOperand(*PI,
false);
3517 if (AnnotationWriter) AnnotationWriter->emitBasicBlockStartAnnot(BB, Out);
3521 printInstructionLine(I);
3524 if (AnnotationWriter) AnnotationWriter->emitBasicBlockEndAnnot(BB, Out);
3528 void AssemblyWriter::printInstructionLine(
const Instruction &I) {
3529 printInstruction(I);
3535 void AssemblyWriter::printGCRelocateComment(
const GCRelocateInst &Relocate) {
3545 void AssemblyWriter::printInfoComment(
const Value &V) {
3546 if (
const auto *Relocate = dyn_cast<GCRelocateInst>(&V))
3547 printGCRelocateComment(*Relocate);
3549 if (AnnotationWriter)
3550 AnnotationWriter->printInfoComment(V, Out);
3557 bool PrintAddrSpace = CallAddrSpace != 0;
3558 if (!PrintAddrSpace) {
3564 PrintAddrSpace =
true;
3567 Out <<
" addrspace(" << CallAddrSpace <<
")";
3571 void AssemblyWriter::printInstruction(
const Instruction &I) {
3572 if (AnnotationWriter) AnnotationWriter->emitInstructionAnnot(&I, Out);
3583 int SlotNum = Machine.getLocalSlot(&I);
3585 Out <<
"<badref> = ";
3587 Out <<
'%' << SlotNum <<
" = ";
3590 if (
const CallInst *CI = dyn_cast<CallInst>(&I)) {
3591 if (CI->isMustTailCall())
3593 else if (CI->isTailCall())
3595 else if (CI->isNoTailCall())
3603 if ((isa<LoadInst>(I) && cast<LoadInst>(I).
isAtomic()) ||
3604 (isa<StoreInst>(I) && cast<StoreInst>(I).
isAtomic()))
3607 if (isa<AtomicCmpXchgInst>(I) && cast<AtomicCmpXchgInst>(I).
isWeak())
3611 if ((isa<LoadInst>(I) && cast<LoadInst>(I).
isVolatile()) ||
3612 (isa<StoreInst>(I) && cast<StoreInst>(I).
isVolatile()) ||
3613 (isa<AtomicCmpXchgInst>(I) && cast<AtomicCmpXchgInst>(I).
isVolatile()) ||
3614 (isa<AtomicRMWInst>(I) && cast<AtomicRMWInst>(I).
isVolatile()))
3621 if (
const CmpInst *CI = dyn_cast<CmpInst>(&I))
3625 if (
const AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(&I))
3632 if (isa<BranchInst>(I) && cast<BranchInst>(I).isConditional()) {
3641 }
else if (isa<SwitchInst>(I)) {
3649 for (
auto Case : SI.
cases()) {
3651 writeOperand(Case.getCaseValue(),
true);
3653 writeOperand(Case.getCaseSuccessor(),
true);
3656 }
else if (isa<IndirectBrInst>(I)) {
3659 writeOperand(Operand,
true);
3668 }
else if (
const PHINode *PN = dyn_cast<PHINode>(&I)) {
3670 TypePrinter.print(I.
getType(), Out);
3673 for (
unsigned op = 0, Eop = PN->getNumIncomingValues();
op < Eop; ++
op) {
3674 if (
op) Out <<
", ";
3676 writeOperand(PN->getIncomingValue(
op),
false); Out <<
", ";
3677 writeOperand(PN->getIncomingBlock(
op),
false); Out <<
" ]";
3682 for (
const unsigned *i = EVI->idx_begin(), *e = EVI->idx_end(); i != e; ++i)
3684 }
else if (
const InsertValueInst *IVI = dyn_cast<InsertValueInst>(&I)) {
3686 writeOperand(I.
getOperand(0),
true); Out <<
", ";
3688 for (
const unsigned *i = IVI->idx_begin(), *e = IVI->idx_end(); i != e; ++i)
3690 }
else if (
const LandingPadInst *LPI = dyn_cast<LandingPadInst>(&I)) {
3692 TypePrinter.print(I.
getType(), Out);
3693 if (LPI->isCleanup() || LPI->getNumClauses() != 0)
3696 if (LPI->isCleanup())
3699 for (
unsigned i = 0, e = LPI->getNumClauses(); i != e; ++i) {
3700 if (i != 0 || LPI->isCleanup()) Out <<
"\n";
3701 if (LPI->isCatch(i))
3706 writeOperand(LPI->getClause(i),
true);
3708 }
else if (
const auto *CatchSwitch = dyn_cast<CatchSwitchInst>(&I)) {
3710 writeOperand(CatchSwitch->getParentPad(),
false);
3713 for (
const BasicBlock *PadBB : CatchSwitch->handlers()) {
3716 writeOperand(PadBB,
true);
3720 if (
const BasicBlock *UnwindDest = CatchSwitch->getUnwindDest())
3721 writeOperand(UnwindDest,
true);
3724 }
else if (
const auto *FPI = dyn_cast<FuncletPadInst>(&I)) {
3726 writeOperand(FPI->getParentPad(),
false);
3728 for (
unsigned Op = 0, NumOps = FPI->getNumArgOperands();
Op < NumOps;
3732 writeOperand(FPI->getArgOperand(
Op),
true);
3735 }
else if (isa<ReturnInst>(I) && !Operand) {
3737 }
else if (
const auto *CRI = dyn_cast<CatchReturnInst>(&I)) {
3739 writeOperand(CRI->getOperand(0),
false);
3742 writeOperand(CRI->getOperand(1),
true);
3743 }
else if (
const auto *CRI = dyn_cast<CleanupReturnInst>(&I)) {
3745 writeOperand(CRI->getOperand(0),
false);
3748 if (CRI->hasUnwindDest())
3749 writeOperand(CRI->getOperand(1),
true);
3752 }
else if (
const CallInst *CI = dyn_cast<CallInst>(&I)) {
3759 Operand = CI->getCalledValue();
3775 TypePrinter.print(FTy->
isVarArg() ? FTy : RetTy, Out);
3777 writeOperand(Operand,
false);
3779 for (
unsigned op = 0, Eop = CI->getNumArgOperands();
op < Eop; ++
op) {
3787 if (CI->isMustTailCall() && CI->getParent() &&
3788 CI->getParent()->getParent() &&
3789 CI->getParent()->getParent()->isVarArg())
3796 writeOperandBundles(CI);
3797 }
else if (
const InvokeInst *II = dyn_cast<InvokeInst>(&I)) {
3798 Operand = II->getCalledValue();
3820 TypePrinter.print(FTy->
isVarArg() ? FTy : RetTy, Out);
3822 writeOperand(Operand,
false);
3824 for (
unsigned op = 0, Eop = II->getNumArgOperands();
op < Eop; ++
op) {
3834 writeOperandBundles(II);
3837 writeOperand(II->getNormalDest(),
true);
3839 writeOperand(II->getUnwindDest(),
true);
3840 }
else if (
const AllocaInst *AI = dyn_cast<AllocaInst>(&I)) {
3842 if (AI->isUsedWithInAlloca())
3844 if (AI->isSwiftError())
3845 Out <<
"swifterror ";
3846 TypePrinter.print(AI->getAllocatedType(), Out);
3852 if (!AI->getArraySize() || AI->isArrayAllocation() ||
3853 !AI->getArraySize()->getType()->isIntegerTy(32)) {
3855 writeOperand(AI->getArraySize(),
true);
3857 if (AI->getAlignment()) {
3858 Out <<
", align " << AI->getAlignment();
3861 unsigned AddrSpace = AI->getType()->getAddressSpace();
3862 if (AddrSpace != 0) {
3863 Out <<
", addrspace(" << AddrSpace <<
')';
3865 }
else if (isa<CastInst>(I)) {
3868 writeOperand(Operand,
true);
3871 TypePrinter.print(I.
getType(), Out);
3872 }
else if (isa<VAArgInst>(I)) {
3875 writeOperand(Operand,
true);
3878 TypePrinter.print(I.
getType(), Out);
3879 }
else if (Operand) {
3880 if (
const auto *
GEP = dyn_cast<GetElementPtrInst>(&I)) {
3882 TypePrinter.print(
GEP->getSourceElementType(), Out);
3884 }
else if (
const auto *LI = dyn_cast<LoadInst>(&I)) {
3886 TypePrinter.print(LI->getType(), Out);
3893 bool PrintAllTypes =
false;
3897 if (isa<SelectInst>(I) || isa<StoreInst>(I) || isa<ShuffleVectorInst>(I)
3898 || isa<ReturnInst>(I)) {
3899 PrintAllTypes =
true;
3905 if (Operand && Operand->
getType() != TheType) {
3906 PrintAllTypes =
true;
3912 if (!PrintAllTypes) {
3914 TypePrinter.print(TheType, Out);
3920 writeOperand(I.
getOperand(i), PrintAllTypes);
3925 if (
const LoadInst *LI = dyn_cast<LoadInst>(&I)) {
3927 writeAtomic(LI->getContext(), LI->getOrdering(), LI->getSyncScopeID());
3928 if (LI->getAlignment())
3929 Out <<
", align " << LI->getAlignment();
3930 }
else if (
const StoreInst *
SI = dyn_cast<StoreInst>(&I)) {
3932 writeAtomic(
SI->getContext(),
SI->getOrdering(),
SI->getSyncScopeID());
3933 if (
SI->getAlignment())
3934 Out <<
", align " <<
SI->getAlignment();
3936 writeAtomicCmpXchg(CXI->getContext(), CXI->getSuccessOrdering(),
3937 CXI->getFailureOrdering(), CXI->getSyncScopeID());
3938 }
else if (
const AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(&I)) {
3939 writeAtomic(RMWI->getContext(), RMWI->getOrdering(),
3940 RMWI->getSyncScopeID());
3941 }
else if (
const FenceInst *FI = dyn_cast<FenceInst>(&I)) {
3942 writeAtomic(FI->getContext(), FI->getOrdering(), FI->getSyncScopeID());
3948 printMetadataAttachments(InstMD,
", ");
3951 printInfoComment(I);
3954 void AssemblyWriter::printMetadataAttachments(
3960 if (MDNames.empty())
3961 MDs[0].
second->getContext().getMDKindNames(MDNames);
3963 for (
const auto &I : MDs) {
3964 unsigned Kind = I.first;
3966 if (Kind < MDNames.size()) {
3970 Out <<
"!<unknown kind #" << Kind <<
">";
3976 void AssemblyWriter::writeMDNode(
unsigned Slot,
const MDNode *Node) {
3977 Out <<
'!' << Slot <<
" = ";
3978 printMDNodeBody(Node);
3982 void AssemblyWriter::writeAllMDNodes() {
3984 Nodes.
resize(Machine.mdn_size());
3987 Nodes[I->second] = cast<MDNode>(I->first);
3989 for (
unsigned i = 0, e = Nodes.
size(); i != e; ++i) {
3990 writeMDNode(i, Nodes[i]);
3994 void AssemblyWriter::printMDNodeBody(
const MDNode *Node) {
3998 void AssemblyWriter::writeAllAttributeGroups() {
3999 std::vector<std::pair<AttributeSet, unsigned>> asVec;
4000 asVec.resize(Machine.as_size());
4004 asVec[I->second] = *I;
4006 for (
const auto &I : asVec)
4007 Out <<
"attributes #" << I.second <<
" = { " 4008 << I.first.getAsString(
true) <<
" }\n";
4011 void AssemblyWriter::printUseListOrder(
const UseListOrder &Order) {
4016 Out <<
"uselistorder";
4018 IsInFunction ?
nullptr : dyn_cast<BasicBlock>(Order.
V)) {
4022 writeOperand(BB,
false);
4025 writeOperand(Order.
V,
true);
4031 for (
unsigned I = 1,
E = Order.
Shuffle.size(); I !=
E; ++
I)
4032 Out <<
", " << Order.
Shuffle[I];
4036 void AssemblyWriter::printUseLists(
const Function *F) {
4038 [&]() {
return !UseListOrders.empty() && UseListOrders.back().F ==
F; };
4043 Out <<
"\n; uselistorder directives\n";
4045 printUseListOrder(UseListOrders.back());
4046 UseListOrders.pop_back();
4055 bool ShouldPreserveUseListOrder,
4056 bool IsForDebug)
const {
4059 AssemblyWriter
W(OS, SlotTable, this->
getParent(), AAW,
4061 ShouldPreserveUseListOrder);
4062 W.printFunction(
this);
4066 bool ShouldPreserveUseListOrder,
bool IsForDebug)
const {
4069 AssemblyWriter
W(OS, SlotTable,
this, AAW, IsForDebug,
4070 ShouldPreserveUseListOrder);
4071 W.printModule(
this);
4077 AssemblyWriter
W(OS, SlotTable,
getParent(),
nullptr, IsForDebug);
4078 W.printNamedMDNode(
this);
4082 bool IsForDebug)
const {
4089 SlotTable = &*LocalST;
4093 AssemblyWriter
W(OS, *SlotTable,
getParent(),
nullptr, IsForDebug);
4094 W.printNamedMDNode(
this);
4099 ROS <<
" = comdat ";
4101 switch (getSelectionKind()) {
4106 ROS <<
"exactmatch";
4112 ROS <<
"noduplicates";
4124 TP.print(const_cast<Type*>(
this), OS);
4130 if (
StructType *STy = dyn_cast<StructType>(const_cast<Type*>(
this)))
4131 if (!STy->isLiteral()) {
4133 TP.printStructBody(STy, OS);
4138 if (
const auto *CI = dyn_cast<CallInst>(&I))
4139 if (
Function *F = CI->getCalledFunction())
4142 if (
auto *V = dyn_cast_or_null<MetadataAsValue>(
Op))
4143 if (isa<MDNode>(V->getMetadata()))
4149 bool ShouldInitializeAllMetadata =
false;
4150 if (
auto *I = dyn_cast<Instruction>(
this))
4152 else if (isa<Function>(
this) || isa<MetadataAsValue>(
this))
4153 ShouldInitializeAllMetadata =
true;
4156 print(ROS, MST, IsForDebug);
4160 bool IsForDebug)
const {
4162 SlotTracker EmptySlotTable(static_cast<const Module *>(
nullptr));
4165 auto incorporateFunction = [&](
const Function *
F) {
4170 if (
const Instruction *I = dyn_cast<Instruction>(
this)) {
4173 W.printInstruction(*I);
4174 }
else if (
const BasicBlock *BB = dyn_cast<BasicBlock>(
this)) {
4177 W.printBasicBlock(BB);
4178 }
else if (
const GlobalValue *GV = dyn_cast<GlobalValue>(
this)) {
4179 AssemblyWriter
W(OS, SlotTable, GV->
getParent(),
nullptr, IsForDebug);
4182 else if (
const Function *F = dyn_cast<Function>(GV))
4185 W.printIndirectSymbol(cast<GlobalIndirectSymbol>(GV));
4186 }
else if (
const MetadataAsValue *V = dyn_cast<MetadataAsValue>(
this)) {
4188 }
else if (
const Constant *C = dyn_cast<Constant>(
this)) {
4189 TypePrinting TypePrinter;
4190 TypePrinter.print(C->getType(), OS);
4193 }
else if (isa<InlineAsm>(
this) || isa<Argument>(
this)) {
4194 this->printAsOperand(OS,
true, MST);
4205 if (V.
hasName() || isa<GlobalValue>(V) ||
4206 (!isa<Constant>(V) && !isa<MetadataAsValue>(V))) {
4215 TypePrinting TypePrinter(MST.
getModule());
4235 M, isa<MetadataAsValue>(
this));
4251 bool OnlyAsOperand) {
4254 TypePrinting TypePrinter(M);
4260 if (OnlyAsOperand || !N || isa<DIExpression>(MD))
4284 const Module *M,
bool )
const {
4291 AssemblyWriter
W(OS, SlotTable,
this, IsForDebug);
4292 W.printModuleSummaryIndex();
4295 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
Type * getVectorElementType() const
AttributeSet getAttributes() const
Return the attribute set for this global.
bool hasOperandBundles() const
Return true if this User has any operand bundles.
static const fltSemantics & IEEEquad() LLVM_READNONE
StringRef getSection() const
Get the custom section of this global if it has one.
static SlotTracker * createSlotTracker(const Value *V)
bool isIntrinsic() const
isIntrinsic - Returns true if the function's name starts with "llvm.".
unsigned getAlignment() const
Used for AVR interrupt routines.
const std::string & getTargetTriple() const
Get the target triple which is a string describing the target host.
ThreadLocalMode getThreadLocalMode() const
static void WriteOptimizationInfo(raw_ostream &Out, const User *U)
This class is the base class for the comparison instructions.
unsigned Live
In per-module summary, indicate that the global value must be considered a live root for index-based ...
iterator_range< use_iterator > uses()
static std::string getLinkageName(GlobalValue::LinkageTypes LT)
ARM_AAPCS - ARM Architecture Procedure Calling Standard calling convention (aka EABI).
bool hasLocalLinkage() const
C - The default llvm calling convention, compatible with C.
Special purpose, only applies to global arrays.
uint64_t getZExtValue() const
Get zero extended value.
iterator_range< CaseIt > cases()
Iteration adapter for range-for loops.
This class represents an incoming formal argument to a Function.
void purgeFunction()
After calling incorporateFunction, use this method to remove the most recently incorporated function ...
static bool printWithoutType(const Value &V, raw_ostream &O, SlotTracker *Machine, const Module *M)
Print without a type, skipping the TypePrinting object.
Atomic ordering constants.
MDNode * getOperand(unsigned i) const
DenseMap< GlobalValue::GUID, unsigned >::iterator guid_iterator
GUID map iterators.
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
This class represents lattice values for constants.
Type * getParamType(unsigned i) const
Parameter type accessors.
unsigned Linkage
The linkage type of the associated global value.
const GlobalValueSummary & getAliasee() const
A Module instance is used to store all the information related to an LLVM module. ...
2: 32-bit floating point type
An instruction for ordering other memory operations.
Same, but only replaced by something equivalent.
static StringRef getUnnamedAddrEncoding(GlobalVariable::UnnamedAddr UA)
an instruction that atomically checks whether a specified value is in a memory location, and, if it is, stores a new value there.
FormattedNumber format_hex(uint64_t N, unsigned Width, bool Upper=false)
format_hex - Output N as a fixed width hexadecimal.
HHVM calling convention for invoking C/C++ helpers.
Global variable summary information to aid decisions and implementation of importing.
Unsatisfiable type (i.e. no global has this type metadata)
bool isMaterializable() const
If this function's Module is being lazily streamed in functions from disk or some other source...
Available for inspection, not emission.
void push_back(const T &Elt)
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
ArrayRef< ValueInfo > refs() const
Return the list of values referenced by this global value definition.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
This class represents a function call, abstracting a target machine's calling convention.
void emplace(ArgTypes &&... Args)
Create a new object by constructing it in place with the given arguments.
Value * getCondition() const
Register calling convention used for parameters transfer optimization.
The C convention as implemented on Windows/x86-64 and AArch64.
float convertToFloat() const
This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM...
Like Internal, but omit from symbol table.
static void PrintDLLStorageClass(GlobalValue::DLLStorageClassTypes SCT, formatted_raw_ostream &Out)
bool global_empty() const
Externally visible function.
void printEscapedString(StringRef Name, raw_ostream &Out)
Print each character of the specified string, escaping it if it is not printable or if it is an escap...
std::vector< VFuncId > TypeTestAssumeVCalls
List of virtual calls made by this function using (respectively) llvm.assume(llvm.type.test) or llvm.type.checked.load intrinsics that do not have all constant integer arguments.
bool hasPrologueData() const
Check whether this function has prologue data.
The data referenced by the COMDAT must be the same size.
const std::string & getDataLayoutStr() const
Get the data layout string for the module's target platform.
BasicBlock * getSuccessor(unsigned i) const
int getGlobalSlot(const GlobalValue *V)
getGlobalSlot - Get the slot number of a global value.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
4: 80-bit floating point type (X87)
const fltSemantics & getSemantics() const
const MDOperand & getOperand(unsigned I) const
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
param_iterator param_end() const
An instruction for reading from memory.
Manage lifetime of a slot tracker for printing IR.
1: 16-bit floating point type
bool hasExternalWeakLinkage() const
an instruction that atomically reads a memory location, combines it with another value, and then stores the result back.
Value * getCondition() const
Kind
Specifies which kind of type check we should emit for this byte array.
OperandBundleUse getOperandBundleAt(unsigned Index) const
Return the operand bundle at a specific index.
static void writeDILocation(raw_ostream &Out, const DILocation *DL, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
This defines the Use class.
void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode *>> &MDs) const
Appends all attachments for the global to MDs, sorting by attachment ID.
Virtual constant propagation.
int getMetadataSlot(const MDNode *N)
getMetadataSlot - Get the slot number of a MDNode.
std::map< uint64_t, WholeProgramDevirtResolution > WPDRes
Mapping from byte offset to whole-program devirt resolution for that (typeid, byte offset) pair...
static void PrintCallingConv(unsigned cc, raw_ostream &Out)
void dump() const
Dump to stderr (for debugging).
static void PrintDSOLocation(const GlobalValue &GV, formatted_raw_ostream &Out)
Constant * getPrologueData() const
Get the prologue data associated with this function.
SlotTracker * getMachine()
Lazily creates a slot tracker.
static void predictValueUseListOrder(const Value *V, const Function *F, OrderMap &OM, UseListOrderStack &Stack)
struct llvm::GlobalVarSummary::GVarFlags VarFlags
const TypeIdInfo * getTypeIdInfo() const
void print(raw_ostream &OS, bool IsForDebug=false) const
Print to an output stream.
static std::string getLinkageNameWithSpace(GlobalValue::LinkageTypes LT)
void dump() const
Support for debugging, callable in GDB: V->dump()
The address of a basic block.
Calling convention used for Mesa/AMDPAL geometry shaders.
unsigned NotEligibleToImport
Indicate if the global value cannot be imported (e.g.
GlobalValue::GUID getGUID() const
bool hasPrefixData() const
Check whether this function has prefix data.
amdgpu Simplify well known AMD library false Value Value const Twine & Name
APInt getLoBits(unsigned numBits) const
Compute an APInt containing numBits lowbits from this APInt.
std::vector< unsigned > Shuffle
static OrderMap orderModule(const Module *M)
Calling convention used for Mesa/AMDPAL compute shaders.
static void printMetadataImpl(raw_ostream &ROS, const Metadata &MD, ModuleSlotTracker &MST, const Module *M, bool OnlyAsOperand)
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
TypeID getTypeID() const
Return the type id for the type.
When retpoline mitigation is enabled, use a branch funnel that is defined in the merged module...
Class to represent struct types.
SPIR_KERNEL - Calling convention for SPIR kernel functions.
A Use represents the edge between a Value definition and its users.
bool isConstant() const
If the value is a global constant, its value is immutable throughout the runtime execution of the pro...
Value * getDerivedPtr() const
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
std::vector< ConstVCall > TypeCheckedLoadConstVCalls
const Module * getModule() const
UnnamedAddr getUnnamedAddr() const
The access may reference the value stored in memory.
static StringRef getName(Value *V)
This file contains the simple types necessary to represent the attributes associated with functions a...
Just do a regular virtual call.
The linker may choose any COMDAT.
unsigned getNumOperands() const
int getTypeIdSlot(StringRef Id)
bool hasAttributes(unsigned Index) const
Return true if attribute exists at the given index.
APInt getHiBits(unsigned numBits) const
Compute an APInt containing numBits highbits from this APInt.
uint64_t getNumElements() const
static void printMetadataIdentifier(StringRef Name, formatted_raw_ostream &Out)
static const uint16_t * lookup(unsigned opcode, unsigned domain, ArrayRef< uint16_t[3]> Table)
This file implements a class to represent arbitrary precision integral constant values and operations...
Constant * getPrefixData() const
Get the prefix data associated with this function.
AtomicOrdering
Atomic ordering for LLVM's memory model.
enum llvm::WholeProgramDevirtResolution::Kind TheKind
static StringRef getOperationName(BinOp Op)
bool hasExternalLinkage() const
Uniform return value optimization.
Fast - This calling convention attempts to make calls as fast as possible (e.g.
Class to represent function types.
Calling convention used for AMDPAL shader stage before geometry shader if geometry is in use...
Type * getType() const
All values are typed, get the type of this value.
opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
void toString(SmallVectorImpl< char > &Str, unsigned FormatPrecision=0, unsigned FormatMaxPadding=3, bool TruncateZero=true) const
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. ...
Class to represent array types.
AttributeSet getParamAttributes(unsigned ArgNo) const
The attributes for the argument or parameter at the given index are returned.
VisibilityTypes
An enumeration for the kinds of visibility of global values.
int getModulePathSlot(StringRef Path)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
const std::string & getGC() const
AttributeList getAttributes() const
Return the attribute list for this Function.
An instruction for storing to memory.
bool hasPersonalityFn() const
Check whether this function has a personality function.
COFF::MachineTypes Machine
LinkageTypes getLinkage() const
static const fltSemantics & IEEEdouble() LLVM_READNONE
char hexdigit(unsigned X, bool LowerCase=false)
hexdigit - Return the hexadecimal character for the given number X (which should be less than 16)...
static void PrintVisibility(GlobalValue::VisibilityTypes Vis, formatted_raw_ostream &Out)
unsigned getNumOperandBundles() const
Return the number of operand bundles associated with this User.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
Structure to hold a use-list order.
Class to hold module path string table and global value map, and encapsulate methods for operating on...
ArrayRef< std::unique_ptr< GlobalValueSummary > > getSummaryList() const
Calling convention used for Mesa vertex shaders, or AMDPAL last shader stage before rasterization (ve...
Value * getOperand(unsigned i) const
int getLocalSlot(const Value *V)
Return the slot number of the specified value in it's type plane.
Class to represent pointers.
const std::string & getSourceFileName() const
Get the module's original source file name.
ARM_AAPCS_VFP - Same as ARM_AAPCS, but uses hard floating point ABI.
Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
AttributeSet getAttributes(unsigned Index) const
The attributes for the specified index are returned.
11: Arbitrary bit width integers
bool isVoidTy() const
Return true if this is 'void'.
ExternalWeak linkage description.
const BasicBlock & getEntryBlock() const
This class provides computation of slot numbers for LLVM Assembly writing.
Same, but only replaced by something equivalent.
Type * getReturnType() const
Returns the type of the ret val.
No other Module may specify this COMDAT.
StringRef getName() const
const char * toIRString(AtomicOrdering ao)
String used by LLVM IR to represent atomic ordering.
The landingpad instruction holds all of the information necessary to generate correct exception handl...
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
void print(raw_ostream &OS, bool IsForDebug=false) const
DLLStorageClassTypes getDLLStorageClass() const
VisibilityTypes getVisibility() const
An array constant whose element type is a simple 1/2/4/8-byte integer or float/double, and whose elements are just simple data values (i.e.
static void predictValueUseListOrderImpl(const Value *V, const Function *F, unsigned ID, const OrderMap &OM, UseListOrderStack &Stack)
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
Conditional or Unconditional Branch instruction.
const char * getOpcodeName() const
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
SummaryKind getSummaryKind() const
Which kind of summary subclass this is.
MSVC calling convention that passes vectors and vector aggregates in SSE registers.
void dump() const
Dump the module to stderr (for debugging).
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
static StringRef getPredicateName(Predicate P)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
unsigned instCount() const
Get the instruction count recorded for this function.
PTX_Kernel - Call to a PTX kernel.
void getSyncScopeNames(SmallVectorImpl< StringRef > &SSNs) const
getSyncScopeNames - Populates client supplied SmallVector with synchronization scope names registered...
void print(raw_ostream &ROS, bool IsForDebug=false) const
std::vector< UseListOrder > UseListOrderStack
unsigned getNumParams() const
Return the number of fixed parameters this function type requires.
ConstantFP - Floating Point Values [float, double].
ARM_APCS - ARM Procedure Calling Standard calling convention (obsolete, but still used on some target...
double convertToDouble() const
Interval::pred_iterator pred_begin(Interval *I)
pred_begin/pred_end - define methods so that Intervals may be used just like BasicBlocks can with the...
BasicBlock * getDefaultDest() const
A udiv or sdiv instruction, which can be marked as "exact", indicating that no bits are destroyed...
static void WriteAsOperandInternal(raw_ostream &Out, const Value *V, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
param_iterator param_begin() const
This file declares a class to represent arbitrary precision floating point values and provide a varie...
Single element (last example in "Short Inline Bit Vectors")
unsigned getAddressSpace() const
Utility class for integer operators which may exhibit overflow - Add, Sub, Mul, and Shl...
void print(raw_ostream &O, bool IsForDebug=false) const
Implement operator<< on Value.
Calling convention used for AMDPAL vertex shader if tessellation is in use.
StringRef getName() const
Return the name for this struct type if it has an identity.
DLLStorageClassTypes
Storage classes of global values for PE targets.
6: 128-bit floating point type (two 64-bits, PowerPC)
static void printAsOperandImpl(const Value &V, raw_ostream &O, bool PrintType, ModuleSlotTracker &MST)
Interval::pred_iterator pred_end(Interval *I)
unsigned getAddressSpace() const
Return the address space of the Pointer type.
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
The C convention as specified in the x86-64 supplement to the System V ABI, used on most non-Windows ...
static const fltSemantics & x87DoubleExtended() LLVM_READNONE
bool isMaterializable() const
static const Module * getModuleFromVal(const Value *V)
The data referenced by the COMDAT must be the same.
All type identifier related information.
const Function * getFunction() const
Return the function this instruction belongs to.
std::string getAsString(unsigned Index, bool InAttrGrp=false) const
Return the attributes at the index as a string.
Function and variable summary information to aid decisions and implementation of importing.
void incorporateFunction(const Function &F)
Incorporate the given function.
Calling convention used for Mesa/AMDPAL pixel shaders.
static bool isAtomic(Instruction *I)
static void PrintThreadLocalModel(GlobalVariable::ThreadLocalMode TLM, formatted_raw_ostream &Out)
const std::string & getModuleIdentifier() const
Get the module identifier which is, essentially, the name of the module.
GVFlags flags() const
Get the flags for this GlobalValue (see struct GVFlags).
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.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
An "identifier" for a virtual function.
void sort(IteratorTy Start, IteratorTy End)
Struct that holds a reference to a particular GUID in a global value summary.
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...
constexpr bool empty(const T &RangeOrContainer)
Test whether RangeOrContainer is empty. Similar to C++17 std::empty.
reverse_iterator rbegin()
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.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
std::vector< VFuncId > TypeCheckedLoadVCalls
static const fltSemantics & IEEEsingle() LLVM_READNONE
unsigned getNumOperands() const
std::string getAsString(bool InAttrGrp=false) const
This is the shared class of boolean and integer constants.
auto size(R &&Range, typename std::enable_if< std::is_same< typename std::iterator_traits< decltype(Range.begin())>::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr) -> decltype(std::distance(Range.begin(), Range.end()))
Get the size of a range.
static const fltSemantics & IEEEhalf() LLVM_READNONE
const char * getHotnessName(CalleeInfo::HotnessType HT)
16: SIMD 'packed' format, or other vector type
X86_ThisCall - Similar to X86_StdCall.
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Calling convention used for AVR signal routines.
bool hasSection() const
Check if this global has a custom object file section.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Keep one copy of function when linking (inline)
Utility class for floating point operations which can have information about relaxed accuracy require...
Module.h This file contains the declarations for the Module class.
static void WriteConstantInternal(raw_ostream &Out, const Constant *CV, TypePrinting &TypePrinter, SlotTracker *Machine, const Module *Context)
LLVM_NODISCARD std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Type::subtype_iterator param_iterator
Single implementation devirtualization.
Type * getReturnType() const
void printLLVMNameWithoutPrefix(raw_ostream &OS, StringRef Name)
Print out a name of an LLVM value without any prefixes.
unsigned getProgramAddressSpace() const
Alias summary information.
virtual ~AssemblyAnnotationWriter()
The linker will choose the largest COMDAT.
static bool isReferencingMDNode(const Instruction &I)
void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode *>> &MDs) const
Get all metadata attached to this Instruction.
std::string SingleImplName
enum llvm::TypeTestResolution::Kind TheKind
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
The access may modify the value stored in memory.
unsigned getVectorNumElements() const
FunctionType * getFunctionType() const
Returns the FunctionType for me.
bool isLiteral() const
Return true if this type is uniqued by structural equivalence, false if it is a struct definition...
Class to represent vector types.
This file contains constants used for implementing Dwarf debug support.
ConstantArray - Constant Array Declarations.
Class for arbitrary precision integers.
X86_FastCall - 'fast' analog of X86_StdCall.
static bool isWeak(const MCSymbolELF &Sym)
LinkageTypes
An enumeration for the kinds of linkage for global values.
StringRef getName() const
A lightweight accessor for an operand bundle meant to be passed around by value.
iterator_range< user_iterator > users()
SummaryKind
Sububclass discriminator (for dyn_cast<> et al.)
static const char * getWholeProgDevirtResByArgKindName(WholeProgramDevirtResolution::ByArg::Kind K)
amdgpu Simplify well known AMD library false Value Value * Arg
void initializeIndexIfNeeded()
FFlags fflags() const
Get function summary flags.
const Comdat * getComdat() const
static const fltSemantics & PPCDoubleDouble() LLVM_READNONE
Test a byte array (first example)
Intel_OCL_BI - Calling conventions for Intel OpenCL built-ins.
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
Function to be accessible from DLL.
PTX_Device - Call to a PTX device function.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
bool hasGC() const
hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm to use during code generatio...
std::map< std::vector< uint64_t >, ByArg > ResByArg
Resolutions for calls with all constant integer arguments (excluding the first argument, "this"), where the key is the argument vector.
static const char * getTTResKindName(TypeTestResolution::Kind K)
StringRef modulePath() const
Get the path to the module containing this function.
void print(raw_ostream &O, bool IsForDebug=false, bool NoDetails=false) const
Print the current type.
static void writeDIExpression(raw_ostream &Out, const DIExpression *N, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
All-ones bit vector ("Eliminating Bit Vector Checks for All-Ones Bit Vectors") ...
unsigned DSOLocal
Indicates that the linker resolved the symbol to a definition from within the same linkage unit...
static void orderValue(const Value *V, OrderMap &OM)
Calling convention used for Mesa/AMDPAL hull shaders (= tessellation control shaders).
StringRef getName() const
Return a constant reference to the value's name.
const Function * getParent() const
Return the enclosing method, or null if none.
FormattedNumber format_hex_no_prefix(uint64_t N, unsigned Width, bool Upper=false)
format_hex_no_prefix - Output N as a fixed width hexadecimal.
StringRef getTagName() const
Return the tag of this operand bundle as a string.
static void maybePrintComdat(formatted_raw_ostream &Out, const GlobalObject &GO)
static const char * getSummaryKindName(GlobalValueSummary::SummaryKind SK)
SPIR_FUNC - Calling convention for SPIR non-kernel device functions.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
ArrayRef< EdgeTy > calls() const
Return the list of <CalleeValueInfo, CalleeInfo> pairs.
Type * getValueType() const
int getGUIDSlot(GlobalValue::GUID GUID)
Keep one copy of named function when linking (weak)
static void WriteMDNodeBodyInternal(raw_ostream &Out, const MDNode *Node, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
Rename collisions when linking (static functions).
const Constant * getIndirectSymbol() const
Flags specific to function summaries.
iterator_range< ifunc_iterator > ifuncs()
Calling convention used by HipHop Virtual Machine (HHVM) to perform calls to and from translation cac...
Inlined bit vector ("Short Inline Bit Vectors")
X86_INTR - x86 hardware interrupt context.
unsigned SizeM1BitWidth
Range of size-1 expressed as a bit width.
Function summary information to aid decisions and implementation of importing.
Function to be imported from DLL.
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
const std::string & getModuleInlineAsm() const
Get any module-scope inline assembly blocks.
This file defines passes to print out IR in various granularities.
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
3: 64-bit floating point type
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
X86_StdCall - stdcall is the calling conventions mostly used by the Win32 API.
bool hasAttributes() const
Return true if attributes exists in this set.
Represents calls to the gc.relocate intrinsic.
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
Constant * getPersonalityFn() const
Get the personality function associated with this function.
A vector that has set insertion semantics.
bool hasInitializer() const
Definitions have initializers, declarations don't.
Just do a regular virtual call.
Synchronized with respect to all concurrently executing threads.
static const Function * getParent(const Value *V)
AttributeSet getFnAttributes() const
The function attributes are returned.
Group flags (Linkage, NotEligibleToImport, etc.) as a bitfield.
This class implements an extremely fast bulk output stream that can only output to a stream...
bool hasDefaultVisibility() const
Type * getElementType() const
iterator_range< global_iterator > globals()
StringRef - Represent a constant reference to a string, i.e.
APInt bitcastToAPInt() const
Value * getBasePtr() const
static bool isVolatile(Instruction *Inst)
9: MMX vectors (64 bits, X86 specific)
unsigned getNumOperands() const
Return number of MDNode operands.
for(unsigned i=Desc.getNumOperands(), e=OldMI.getNumOperands();i !=e;++i)
static const char * getWholeProgDevirtResKindName(WholeProgramDevirtResolution::Kind K)
unsigned ReturnDoesNotAlias
TypeFinder - Walk over a module, identifying all of the types that are used by the module...
bool isExternallyInitialized() const
static UseListOrderStack predictUseListOrder(const Module *M)
Calling convention for AMDGPU code object kernels.
static void maybePrintCallAddrSpace(const Value *Operand, const Instruction *I, raw_ostream &Out)
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Type * getElementType() const
int getAttributeGroupSlot(AttributeSet AS)
PointerType * getType() const
Global values are always pointers.
iterator_range< arg_iterator > args()
Unique return value optimization.
std::vector< GlobalValue::GUID > TypeTests
List of type identifiers used by this function in llvm.type.test intrinsics referenced by something o...
const BasicBlock * getParent() const
an instruction to allocate memory on the stack
MSP430_INTR - Calling convention used for MSP430 interrupt routines.
This instruction inserts a struct field of array element value into an aggregate value.
5: 128-bit floating point type (112-bit mantissa)
iterator_range< alias_iterator > aliases()
std::vector< ConstVCall > TypeTestAssumeConstVCalls
List of virtual calls made by this function using (respectively) llvm.assume(llvm.type.test) or llvm.type.checked.load intrinsics with all constant integer arguments.