32 #include "llvm/Config/llvm-config.h" 103 unsigned size()
const {
return IDs.
size(); }
104 std::pair<unsigned, bool> &operator[](
const Value *V) {
return IDs[V]; }
106 std::pair<unsigned, bool>
lookup(
const Value *V)
const {
110 void index(
const Value *V) {
112 unsigned ID = IDs.
size() + 1;
120 if (OM.lookup(V).first)
123 if (
const Constant *
C = dyn_cast<Constant>(V))
126 if (!isa<BasicBlock>(
Op) && !isa<GlobalValue>(
Op))
140 if (
G.hasInitializer())
141 if (!isa<GlobalValue>(
G.getInitializer()))
146 if (!isa<GlobalValue>(A.getAliasee()))
151 if (!isa<GlobalValue>(
I.getResolver()))
156 for (
const Use &U :
F.operands())
157 if (!isa<GlobalValue>(U.get()))
162 if (
F.isDeclaration())
170 for (
const Value *
Op :
I.operands())
171 if ((isa<Constant>(*
Op) && !isa<GlobalValue>(*
Op)) ||
182 unsigned ID,
const OrderMap &OM,
185 using Entry = std::pair<const Use *, unsigned>;
189 if (OM.lookup(U.getUser()).
first)
197 !isa<GlobalVariable>(V) && !isa<Function>(V) && !isa<BasicBlock>(V);
198 if (
auto *BA = dyn_cast<BlockAddress>(V))
199 ID = OM.lookup(BA->getBasicBlock()).
first;
201 const Use *LU = L.first;
202 const Use *RU = R.first;
206 auto LID = OM.lookup(LU->getUser()).
first;
207 auto RID = OM.lookup(RU->getUser()).
first;
227 return LU->getOperandNo() < RU->getOperandNo();
228 return LU->getOperandNo() > RU->getOperandNo();
233 [](
const Entry &L,
const Entry &R) {
return L.second < R.second; }))
238 Stack.emplace_back(V, F, List.
size());
239 assert(List.
size() == Stack.back().Shuffle.size() &&
"Wrong size");
240 for (
size_t I = 0,
E = List.
size();
I !=
E; ++
I)
241 Stack.back().Shuffle[
I] = List[
I].second;
246 auto &IDPair = OM[V];
247 assert(IDPair.first &&
"Unmapped value");
253 IDPair.second =
true;
258 if (
const Constant *
C = dyn_cast<Constant>(V))
261 if (isa<Constant>(
Op))
279 if (
F.isDeclaration())
287 for (
const Value *
Op :
I.operands())
288 if (isa<Constant>(*
Op) || isa<InlineAsm>(*Op))
305 if (
G.hasInitializer())
312 for (
const Use &U :
F.operands())
319 if (
const Argument *MA = dyn_cast<Argument>(V))
320 return MA->getParent() ? MA->getParent()->getParent() :
nullptr;
322 if (
const BasicBlock *BB = dyn_cast<BasicBlock>(V))
323 return BB->getParent() ? BB->getParent()->getParent() :
nullptr;
326 const Function *M =
I->getParent() ?
I->getParent()->getParent() :
nullptr;
330 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V))
331 return GV->getParent();
333 if (
const auto *MAV = dyn_cast<MetadataAsValue>(V)) {
335 if (isa<Instruction>(U))
346 default: Out <<
"cc" << cc;
break;
368 Out <<
"aarch64_sve_vector_pcs";
406 bool NeedsQuotes = isdigit(static_cast<unsigned char>(Name[0]));
408 for (
unsigned i = 0,
e = Name.
size(); i !=
e; ++i) {
413 unsigned char C = Name[i];
414 if (!isalnum(static_cast<unsigned char>(C)) && C !=
'-' && C !=
'.' &&
469 TypePrinting(
const Module *M =
nullptr) : DeferredM(M) {}
471 TypePrinting(
const TypePrinting &) =
delete;
472 TypePrinting &operator=(
const TypePrinting &) =
delete;
478 std::vector<StructType *> &getNumberedTypes();
487 void incorporateTypes();
497 std::vector<StructType *> NumberedTypes;
507 std::vector<StructType *> &TypePrinting::getNumberedTypes() {
513 if (NumberedTypes.size() == Type2Number.size())
514 return NumberedTypes;
516 NumberedTypes.resize(Type2Number.size());
517 for (
const auto &
P : Type2Number) {
518 assert(
P.second < NumberedTypes.size() &&
"Didn't get a dense numbering?");
519 assert(!NumberedTypes[
P.second] &&
"Didn't get a unique numbering?");
520 NumberedTypes[
P.second] =
P.first;
522 return NumberedTypes;
527 return NamedTypes.empty() && Type2Number.empty();
530 void TypePrinting::incorporateTypes() {
534 NamedTypes.run(*DeferredM,
false);
539 unsigned NextNumber = 0;
541 std::vector<StructType*>::iterator NextToUse = NamedTypes.begin(),
I,
E;
542 for (
I = NamedTypes.begin(), E = NamedTypes.end();
I !=
E; ++
I) {
550 Type2Number[STy] = NextNumber++;
555 NamedTypes.erase(NextToUse, NamedTypes.end());
598 return printStructBody(STy, OS);
604 const auto I = Type2Number.find(STy);
605 if (
I != Type2Number.end())
606 OS <<
'%' <<
I->second;
608 OS <<
"%\"type " << STy <<
'\"';
637 llvm_unreachable("Invalid TypeID"); 640 void TypePrinting::printStructBody(StructType *STy, raw_ostream &OS) { 641 if (STy->isOpaque()) { 649 if (STy->getNumElements() == 0) { 652 StructType::element_iterator I = STy->element_begin(); 655 for (StructType::element_iterator E = STy->element_end(); I != E; ++I) { 668 //===----------------------------------------------------------------------===// 669 // SlotTracker Class: Enumerate slot numbers for unnamed values 670 //===----------------------------------------------------------------------===// 676 using ValueMap = DenseMap<const Value *, unsigned>;
680 const Module* TheModule;
683 const Function* TheFunction = nullptr;
684 bool FunctionProcessed = false;
685 bool ShouldInitializeAllMetadata;
688 const ModuleSummaryIndex *TheIndex = nullptr;
699 DenseMap<const MDNode*, unsigned> mdnMap;
700 unsigned mdnNext = 0;
703 DenseMap<AttributeSet, unsigned> asMap;
707 StringMap<unsigned> ModulePathMap;
708 unsigned ModulePathNext = 0;
711 DenseMap<GlobalValue::GUID, unsigned> GUIDMap;
712 unsigned GUIDNext = 0;
715 StringMap<unsigned> TypeIdMap;
716 unsigned TypeIdNext = 0;
724 explicit SlotTracker(const Module *M,
725 bool ShouldInitializeAllMetadata = false);
732 explicit SlotTracker(const Function *F,
733 bool ShouldInitializeAllMetadata = false);
736 explicit SlotTracker(const ModuleSummaryIndex *Index);
738 SlotTracker(const SlotTracker &) = delete;
739 SlotTracker &operator=(const SlotTracker &) = delete;
743 int getLocalSlot(const Value *V);
744 int getGlobalSlot(const GlobalValue *V);
745 int getMetadataSlot(const MDNode *N);
746 int getAttributeGroupSlot(AttributeSet AS);
747 int getModulePathSlot(StringRef Path);
748 int getGUIDSlot(GlobalValue::GUID GUID);
749 int getTypeIdSlot(StringRef Id);
753 void incorporateFunction(const Function *F) {
755 FunctionProcessed = false;
758 const Function *getFunction() const { return TheFunction; }
763 void purgeFunction();
766 using mdn_iterator = DenseMap<const MDNode*, unsigned>::iterator;
768 mdn_iterator mdn_begin() { return mdnMap.begin(); }
769 mdn_iterator mdn_end() { return mdnMap.end(); }
770 unsigned mdn_size() const { return mdnMap.size(); }
771 bool mdn_empty() const { return mdnMap.empty(); }
774 using as_iterator = DenseMap<AttributeSet, unsigned>::iterator;
776 as_iterator as_begin() { return asMap.begin(); }
777 as_iterator as_end() { return asMap.end(); }
778 unsigned as_size() const { return asMap.size(); }
779 bool as_empty() const { return asMap.empty(); }
782 using guid_iterator = DenseMap<GlobalValue::GUID, unsigned>::iterator;
785 inline void initializeIfNeeded();
786 void initializeIndexIfNeeded();
788 // Implementation Details
791 void CreateModuleSlot(const GlobalValue *V);
794 void CreateMetadataSlot(const MDNode *N);
797 void CreateFunctionSlot(const Value *V);
800 void CreateAttributeSetSlot(AttributeSet AS);
802 inline void CreateModulePathSlot(StringRef Path);
803 void CreateGUIDSlot(GlobalValue::GUID GUID);
804 void CreateTypeIdSlot(StringRef Id);
808 void processModule();
812 void processFunction();
815 void processGlobalObjectMetadata(const GlobalObject &GO);
818 void processFunctionMetadata(const Function &F);
821 void processInstructionMetadata(const Instruction &I);
824 } // end namespace llvm
826 ModuleSlotTracker::ModuleSlotTracker(SlotTracker &Machine, const Module *M,
828 : M(M), F(F), Machine(&Machine) {}
830 ModuleSlotTracker::ModuleSlotTracker(const Module *M,
831 bool ShouldInitializeAllMetadata)
832 : ShouldCreateStorage(M),
833 ShouldInitializeAllMetadata(ShouldInitializeAllMetadata), M(M) {}
835 ModuleSlotTracker::~ModuleSlotTracker() = default;
837 SlotTracker *ModuleSlotTracker::getMachine() {
838 if (!ShouldCreateStorage)
841 ShouldCreateStorage = false;
843 std::make_unique<SlotTracker>(M, ShouldInitializeAllMetadata);
844 Machine = MachineStorage.get();
848 void ModuleSlotTracker::incorporateFunction(const Function &F) {
849 // Using getMachine() may lazily create the slot tracker.
853 // Nothing to do if this is the right function already.
857 Machine->purgeFunction();
858 Machine->incorporateFunction(&F);
862 int ModuleSlotTracker::getLocalSlot(const Value *V) {
863 assert(F && "No function incorporated");
864 return Machine->getLocalSlot(V);
867 static SlotTracker *createSlotTracker(const Value *V) {
868 if (const Argument *FA = dyn_cast<Argument>(V))
869 return new SlotTracker(FA->getParent());
871 if (const Instruction *I = dyn_cast<Instruction>(V))
873 return new SlotTracker(I->getParent()->getParent());
875 if (const BasicBlock *BB = dyn_cast<BasicBlock>(V))
876 return new SlotTracker(BB->getParent());
878 if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(V))
879 return new SlotTracker(GV->getParent());
881 if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(V))
882 return new SlotTracker(GA->getParent());
884 if (const GlobalIFunc *GIF = dyn_cast<GlobalIFunc>(V))
885 return new SlotTracker(GIF->getParent());
887 if (const Function *Func = dyn_cast<Function>(V))
888 return new SlotTracker(Func);
894 #define ST_DEBUG(X) dbgs() << X
899 // Module level constructor. Causes the contents of the Module (sans functions)
900 // to be added to the slot table.
901 SlotTracker::SlotTracker(const Module *M, bool ShouldInitializeAllMetadata)
902 : TheModule(M), ShouldInitializeAllMetadata(ShouldInitializeAllMetadata) {}
904 // Function level constructor. Causes the contents of the Module and the one
905 // function provided to be added to the slot table.
906 SlotTracker::SlotTracker(const Function *F, bool ShouldInitializeAllMetadata)
907 : TheModule(F ? F->getParent() : nullptr), TheFunction(F),
908 ShouldInitializeAllMetadata(ShouldInitializeAllMetadata) {}
910 SlotTracker::SlotTracker(const ModuleSummaryIndex *Index)
911 : TheModule(nullptr), ShouldInitializeAllMetadata(false), TheIndex(Index) {}
913 inline void SlotTracker::initializeIfNeeded() {
916 TheModule = nullptr; ///< Prevent re-processing next time we're called.
919 if (TheFunction && !FunctionProcessed)
932 void SlotTracker::processModule() {
938 CreateModuleSlot(&Var);
939 processGlobalObjectMetadata(Var);
940 auto Attrs = Var.getAttributes();
941 if (
Attrs.hasAttributes())
942 CreateAttributeSetSlot(
Attrs);
945 for (
const GlobalAlias &A : TheModule->aliases()) {
947 CreateModuleSlot(&A);
952 CreateModuleSlot(&
I);
956 for (
const NamedMDNode &NMD : TheModule->named_metadata()) {
957 for (
unsigned i = 0,
e = NMD.getNumOperands(); i !=
e; ++i)
958 CreateMetadataSlot(NMD.getOperand(i));
964 CreateModuleSlot(&
F);
966 if (ShouldInitializeAllMetadata)
967 processFunctionMetadata(
F);
973 CreateAttributeSetSlot(FnAttrs);
980 void SlotTracker::processFunction() {
981 ST_DEBUG(
"begin processFunction!\n");
985 if (!ShouldInitializeAllMetadata)
986 processFunctionMetadata(*TheFunction);
990 AE = TheFunction->arg_end(); AI != AE; ++AI)
992 CreateFunctionSlot(&*AI);
994 ST_DEBUG(
"Inserting Instructions:\n");
997 for (
auto &BB : *TheFunction) {
999 CreateFunctionSlot(&BB);
1001 for (
auto &
I : BB) {
1002 if (!
I.getType()->isVoidTy() && !
I.hasName())
1003 CreateFunctionSlot(&
I);
1007 if (
const auto *Call = dyn_cast<CallBase>(&
I)) {
1011 CreateAttributeSetSlot(Attrs);
1016 FunctionProcessed =
true;
1018 ST_DEBUG(
"end processFunction!\n");
1022 void SlotTracker::processIndex() {
1029 std::map<uint64_t, StringRef> ModuleIdToPathMap;
1030 for (
auto &ModPath : TheIndex->modulePaths())
1031 ModuleIdToPathMap[ModPath.second.first] = ModPath.first();
1032 for (
auto &ModPair : ModuleIdToPathMap)
1033 CreateModulePathSlot(ModPair.second);
1036 GUIDNext = ModulePathNext;
1038 for (
auto &GlobalList : *TheIndex)
1039 CreateGUIDSlot(GlobalList.first);
1042 TypeIdNext = GUIDNext;
1044 for (
auto TidIter = TheIndex->typeIds().begin();
1045 TidIter != TheIndex->typeIds().end(); TidIter++)
1046 CreateTypeIdSlot(TidIter->second.first);
1048 for (
auto &TId : TheIndex->typeIdCompatibleVtableMap())
1054 void SlotTracker::processGlobalObjectMetadata(
const GlobalObject &GO) {
1057 for (
auto &MD : MDs)
1058 CreateMetadataSlot(MD.second);
1061 void SlotTracker::processFunctionMetadata(
const Function &
F) {
1062 processGlobalObjectMetadata(F);
1063 for (
auto &BB : F) {
1065 processInstructionMetadata(
I);
1069 void SlotTracker::processInstructionMetadata(
const Instruction &
I) {
1071 if (
const CallInst *CI = dyn_cast<CallInst>(&I))
1072 if (
Function *F = CI->getCalledFunction())
1075 if (
auto *V = dyn_cast_or_null<MetadataAsValue>(
Op))
1076 if (
MDNode *
N = dyn_cast<MDNode>(V->getMetadata()))
1077 CreateMetadataSlot(
N);
1082 for (
auto &MD : MDs)
1083 CreateMetadataSlot(MD.second);
1090 ST_DEBUG(
"begin purgeFunction!\n");
1092 TheFunction =
nullptr;
1093 FunctionProcessed =
false;
1100 initializeIfNeeded();
1104 return MI == mMap.end() ? -1 : (int)MI->second;
1110 initializeIfNeeded();
1114 return MI == mdnMap.end() ? -1 : (int)MI->second;
1119 assert(!isa<Constant>(V) &&
"Can't get a constant or global slot with this!");
1122 initializeIfNeeded();
1125 return FI == fMap.end() ? -1 : (int)FI->second;
1130 initializeIfNeeded();
1134 return AI == asMap.end() ? -1 : (int)AI->second;
1139 initializeIndexIfNeeded();
1142 auto I = ModulePathMap.find(Path);
1143 return I == ModulePathMap.end() ? -1 : (int)I->second;
1148 initializeIndexIfNeeded();
1152 return I == GUIDMap.end() ? -1 : (int)I->second;
1157 initializeIndexIfNeeded();
1160 auto I = TypeIdMap.find(Id);
1161 return I == TypeIdMap.end() ? -1 : (int)I->second;
1165 void SlotTracker::CreateModuleSlot(
const GlobalValue *V) {
1166 assert(V &&
"Can't insert a null Value into SlotTracker!");
1170 unsigned DestSlot = mNext++;
1173 ST_DEBUG(
" Inserting value [" << V->
getType() <<
"] = " << V <<
" slot=" <<
1176 ST_DEBUG((isa<GlobalVariable>(V) ?
'G' :
1177 (isa<Function>(V) ?
'F' :
1178 (isa<GlobalAlias>(V) ?
'A' :
1179 (isa<GlobalIFunc>(V) ?
'I' :
'o')))) <<
"]\n");
1183 void SlotTracker::CreateFunctionSlot(
const Value *V) {
1186 unsigned DestSlot = fNext++;
1190 ST_DEBUG(
" Inserting value [" << V->
getType() <<
"] = " << V <<
" slot=" <<
1191 DestSlot <<
" [o]\n");
1195 void SlotTracker::CreateMetadataSlot(
const MDNode *
N) {
1196 assert(N &&
"Can't insert a null Value into SlotTracker!");
1199 if (isa<DIExpression>(N))
1202 unsigned DestSlot = mdnNext;
1203 if (!mdnMap.insert(std::make_pair(N, DestSlot)).second)
1210 CreateMetadataSlot(
Op);
1213 void SlotTracker::CreateAttributeSetSlot(
AttributeSet AS) {
1216 as_iterator I = asMap.find(AS);
1217 if (I != asMap.end())
1220 unsigned DestSlot = asNext++;
1221 asMap[AS] = DestSlot;
1225 void SlotTracker::CreateModulePathSlot(
StringRef Path) {
1226 ModulePathMap[Path] = ModulePathNext++;
1231 GUIDMap[GUID] = GUIDNext++;
1235 void SlotTracker::CreateTypeIdSlot(
StringRef Id) {
1236 TypeIdMap[
Id] = TypeIdNext++;
1244 TypePrinting *TypePrinter,
1249 TypePrinting *TypePrinter,
1251 bool FromValue =
false);
1254 if (
const FPMathOperator *FPO = dyn_cast<const FPMathOperator>(U)) {
1259 if (FPO->hasAllowReassoc())
1261 if (FPO->hasNoNaNs())
1263 if (FPO->hasNoInfs())
1265 if (FPO->hasNoSignedZeros())
1267 if (FPO->hasAllowReciprocal())
1269 if (FPO->hasAllowContract())
1271 if (FPO->hasApproxFunc())
1277 dyn_cast<OverflowingBinaryOperator>(U)) {
1278 if (OBO->hasNoUnsignedWrap())
1280 if (OBO->hasNoSignedWrap())
1283 dyn_cast<PossiblyExactOperator>(U)) {
1287 if (
GEP->isInBounds())
1293 TypePrinting &TypePrinter,
1296 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
1297 if (CI->getType()->isIntegerTy(1)) {
1298 Out << (CI->getZExtValue() ?
"true" :
"false");
1301 Out << CI->getValue();
1305 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
1306 const APFloat &APF = CFP->getValueAPF();
1317 bool isNaN = APF.
isNaN();
1318 if (!isInf && !isNaN) {
1326 assert(((StrVal[0] >=
'0' && StrVal[0] <=
'9') ||
1327 ((StrVal[0] ==
'-' || StrVal[0] ==
'+') &&
1328 (StrVal[1] >=
'0' && StrVal[1] <=
'9'))) &&
1329 "[-+]?[0-9] regex does not match!");
1340 static_assert(
sizeof(
double) ==
sizeof(uint64_t),
1341 "assuming that double is 64 bits!");
1384 if (isa<ConstantAggregateZero>(CV)) {
1385 Out <<
"zeroinitializer";
1389 if (
const BlockAddress *BA = dyn_cast<BlockAddress>(CV)) {
1390 Out <<
"blockaddress(";
1400 if (
const ConstantArray *CA = dyn_cast<ConstantArray>(CV)) {
1401 Type *ETy = CA->getType()->getElementType();
1403 TypePrinter.print(ETy, Out);
1408 for (
unsigned i = 1,
e = CA->getNumOperands(); i !=
e; ++i) {
1410 TypePrinter.print(ETy, Out);
1422 if (CA->isString()) {
1429 Type *ETy = CA->getType()->getElementType();
1431 TypePrinter.print(ETy, Out);
1436 for (
unsigned i = 1,
e = CA->getNumElements(); i !=
e; ++i) {
1438 TypePrinter.print(ETy, Out);
1448 if (CS->getType()->isPacked())
1454 TypePrinter.print(CS->getOperand(0)->getType(), Out);
1460 for (
unsigned i = 1; i <
N; i++) {
1462 TypePrinter.print(CS->getOperand(i)->getType(), Out);
1472 if (CS->getType()->isPacked())
1477 if (isa<ConstantVector>(CV) || isa<ConstantDataVector>(CV)) {
1480 TypePrinter.print(ETy, Out);
1486 TypePrinter.print(ETy, Out);
1495 if (isa<ConstantPointerNull>(CV)) { 1500 if (isa<ConstantTokenNone>(CV)) { 1505 if (isa<UndefValue>(CV)) { 1510 if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) { 1511 Out << CE->getOpcodeName(); 1512 WriteOptimizationInfo(Out, CE); 1513 if (CE->isCompare()) 1514 Out << ' ' << CmpInst::getPredicateName( 1515 static_cast<CmpInst::Predicate>(CE->getPredicate())); 1518 Optional<unsigned> InRangeOp; 1519 if (const GEPOperator *GEP = dyn_cast<GEPOperator>(CE)) { 1520 TypePrinter.print(GEP->getSourceElementType(), Out); 1522 InRangeOp = GEP->getInRangeIndex(); 1527 for (User::const_op_iterator OI=CE->op_begin(); OI != CE->op_end(); ++OI) { 1528 if (InRangeOp && unsigned(OI - CE->op_begin()) == *InRangeOp) 1530 TypePrinter.print((*OI)->getType(), Out); 1532 WriteAsOperandInternal(Out, *OI, &TypePrinter, Machine, Context); 1533 if (OI+1 != CE->op_end()) 1537 if (CE->hasIndices()) { 1538 ArrayRef<unsigned> Indices = CE->getIndices(); 1539 for (unsigned i = 0, e = Indices.size(); i != e; ++i) 1540 Out << ", " << Indices[i]; 1545 TypePrinter.print(CE->getType(), Out); 1552 Out << "<placeholder or erroneous Constant>"; 1555 static void writeMDTuple(raw_ostream &Out, const MDTuple *Node, 1556 TypePrinting *TypePrinter, SlotTracker *Machine, 1557 const Module *Context) { 1559 for (unsigned mi = 0, me = Node->getNumOperands(); mi != me; ++mi) { 1560 const Metadata *MD = Node->getOperand(mi); 1563 else if (auto *MDV = dyn_cast<ValueAsMetadata>(MD)) { 1564 Value *V = MDV->getValue(); 1565 TypePrinter->print(V->getType(), Out); 1567 WriteAsOperandInternal(Out, V, TypePrinter, Machine, Context); 1569 WriteAsOperandInternal(Out, MD, TypePrinter, Machine, Context); 1580 struct FieldSeparator { 1584 FieldSeparator(const char *Sep = ", ") : Sep(Sep) {} 1587 raw_ostream &operator<<(raw_ostream &OS, FieldSeparator &FS) { 1592 return OS << FS.Sep; 1595 struct MDFieldPrinter { 1598 TypePrinting *TypePrinter = nullptr; 1599 SlotTracker *Machine = nullptr; 1600 const Module *Context = nullptr; 1602 explicit MDFieldPrinter(raw_ostream &Out) : Out(Out) {} 1603 MDFieldPrinter(raw_ostream &Out, TypePrinting *TypePrinter, 1604 SlotTracker *Machine, const Module *Context) 1605 : Out(Out), TypePrinter(TypePrinter), Machine(Machine), Context(Context) { 1608 void printTag(const DINode *N); 1609 void printMacinfoType(const DIMacroNode *N); 1610 void printChecksum(const DIFile::ChecksumInfo<StringRef> &N); 1611 void printString(StringRef Name, StringRef Value, 1612 bool ShouldSkipEmpty = true); 1613 void printMetadata(StringRef Name, const Metadata *MD, 1614 bool ShouldSkipNull = true); 1615 template <class IntTy> 1616 void printInt(StringRef Name, IntTy Int, bool ShouldSkipZero = true); 1617 void printBool(StringRef Name, bool Value, Optional<bool> Default = None); 1618 void printDIFlags(StringRef Name, DINode::DIFlags Flags); 1619 void printDISPFlags(StringRef Name, DISubprogram::DISPFlags Flags); 1620 template <class IntTy, class Stringifier> 1621 void printDwarfEnum(StringRef Name, IntTy Value, Stringifier toString, 1622 bool ShouldSkipZero = true); 1623 void printEmissionKind(StringRef Name, DICompileUnit::DebugEmissionKind EK); 1624 void printNameTableKind(StringRef Name, 1625 DICompileUnit::DebugNameTableKind NTK); 1628 } // end anonymous namespace 1630 void MDFieldPrinter::printTag(const DINode *N) { 1631 Out << FS << "tag: "; 1632 auto Tag = dwarf::TagString(N->getTag()); 1639 void MDFieldPrinter::printMacinfoType(const DIMacroNode *N) { 1640 Out << FS << "type: "; 1641 auto Type = dwarf::MacinfoString(N->getMacinfoType()); 1645 Out << N->getMacinfoType(); 1648 void MDFieldPrinter::printChecksum( 1649 const DIFile::ChecksumInfo<StringRef> &Checksum) { 1650 Out << FS << "checksumkind: " << Checksum.getKindAsString(); 1651 printString("checksum", Checksum.Value, /* ShouldSkipEmpty */ false); 1654 void MDFieldPrinter::printString(StringRef Name, StringRef Value, 1655 bool ShouldSkipEmpty) { 1656 if (ShouldSkipEmpty && Value.empty()) 1659 Out << FS << Name << ": \""; 1660 printEscapedString(Value, Out); 1664 static void writeMetadataAsOperand(raw_ostream &Out, const Metadata *MD, 1665 TypePrinting *TypePrinter, 1666 SlotTracker *Machine, 1667 const Module *Context) { 1672 WriteAsOperandInternal(Out, MD, TypePrinter, Machine, Context); 1675 void MDFieldPrinter::printMetadata(StringRef Name, const Metadata *MD, 1676 bool ShouldSkipNull) { 1677 if (ShouldSkipNull && !MD) 1680 Out << FS << Name << ": "; 1681 writeMetadataAsOperand(Out, MD, TypePrinter, Machine, Context); 1684 template <class IntTy> 1685 void MDFieldPrinter::printInt(StringRef Name, IntTy Int, bool ShouldSkipZero) { 1686 if (ShouldSkipZero && !Int) 1689 Out << FS << Name << ": " << Int; 1692 void MDFieldPrinter::printBool(StringRef Name, bool Value, 1693 Optional<bool> Default) { 1694 if (Default && Value == *Default) 1696 Out << FS << Name << ": " << (Value ? "true" : "false"); 1699 void MDFieldPrinter::printDIFlags(StringRef Name, DINode::DIFlags Flags) { 1703 Out << FS << Name << ": "; 1705 SmallVector<DINode::DIFlags, 8> SplitFlags; 1706 auto Extra = DINode::splitFlags(Flags, SplitFlags); 1708 FieldSeparator FlagsFS(" | "); 1709 for (auto F : SplitFlags) { 1710 auto StringF = DINode::getFlagString(F); 1711 assert(!StringF.empty() && "Expected valid flag"); 1712 Out << FlagsFS << StringF; 1714 if (Extra || SplitFlags.empty()) 1715 Out << FlagsFS << Extra; 1718 void MDFieldPrinter::printDISPFlags(StringRef Name, 1719 DISubprogram::DISPFlags Flags) { 1720 // Always print this field, because no flags in the IR at all will be 1721 // interpreted as old-style isDefinition: true. 1722 Out << FS << Name << ": "; 1729 SmallVector<DISubprogram::DISPFlags, 8> SplitFlags; 1730 auto Extra = DISubprogram::splitFlags(Flags, SplitFlags); 1732 FieldSeparator FlagsFS(" | "); 1733 for (auto F : SplitFlags) { 1734 auto StringF = DISubprogram::getFlagString(F); 1735 assert(!StringF.empty() && "Expected valid flag"); 1736 Out << FlagsFS << StringF; 1738 if (Extra || SplitFlags.empty()) 1739 Out << FlagsFS << Extra; 1742 void MDFieldPrinter::printEmissionKind(StringRef Name, 1743 DICompileUnit::DebugEmissionKind EK) { 1744 Out << FS << Name << ": " << DICompileUnit::emissionKindString(EK); 1747 void MDFieldPrinter::printNameTableKind(StringRef Name, 1748 DICompileUnit::DebugNameTableKind NTK) { 1749 if (NTK == DICompileUnit::DebugNameTableKind::Default) 1751 Out << FS << Name << ": " << DICompileUnit::nameTableKindString(NTK); 1754 template <class IntTy, class Stringifier> 1755 void MDFieldPrinter::printDwarfEnum(StringRef Name, IntTy Value, 1756 Stringifier toString, bool ShouldSkipZero) { 1760 Out << FS << Name << ": "; 1761 auto S = toString(Value); 1768 static void writeGenericDINode(raw_ostream &Out, const GenericDINode *N, 1769 TypePrinting *TypePrinter, SlotTracker *Machine, 1770 const Module *Context) { 1771 Out << "!GenericDINode("; 1772 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 1773 Printer.printTag(N); 1774 Printer.printString("header", N->getHeader()); 1775 if (N->getNumDwarfOperands()) { 1776 Out << Printer.FS << "operands: {"; 1778 for (auto &I : N->dwarf_operands()) { 1780 writeMetadataAsOperand(Out, I, TypePrinter, Machine, Context); 1787 static void writeDILocation(raw_ostream &Out, const DILocation *DL, 1788 TypePrinting *TypePrinter, SlotTracker *Machine, 1789 const Module *Context) { 1790 Out << "!DILocation("; 1791 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 1792 // Always output the line, since 0 is a relevant and important value for it. 1793 Printer.printInt("line", DL->getLine(), /* ShouldSkipZero */ false); 1794 Printer.printInt("column", DL->getColumn()); 1795 Printer.printMetadata("scope", DL->getRawScope(), /* ShouldSkipNull */ false); 1796 Printer.printMetadata("inlinedAt", DL->getRawInlinedAt()); 1797 Printer.printBool("isImplicitCode", DL->isImplicitCode(), 1798 /* Default */ false); 1802 static void writeDISubrange(raw_ostream &Out, const DISubrange *N, 1803 TypePrinting *TypePrinter, SlotTracker *Machine, 1804 const Module *Context) { 1805 Out << "!DISubrange("; 1806 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 1807 if (auto *CE = N->getCount().dyn_cast<ConstantInt*>()) 1808 Printer.printInt("count", CE->getSExtValue(), /* ShouldSkipZero */ false); 1810 Printer.printMetadata("count", N->getCount().dyn_cast<DIVariable*>(), 1811 /*ShouldSkipNull */ false); 1812 Printer.printInt("lowerBound", N->getLowerBound()); 1816 static void writeDIEnumerator(raw_ostream &Out, const DIEnumerator *N, 1817 TypePrinting *, SlotTracker *, const Module *) { 1818 Out << "!DIEnumerator("; 1819 MDFieldPrinter Printer(Out); 1820 Printer.printString("name", N->getName(), /* ShouldSkipEmpty */ false); 1821 if (N->isUnsigned()) { 1822 auto Value = static_cast<uint64_t>(N->getValue()); 1823 Printer.printInt("value", Value, /* ShouldSkipZero */ false); 1824 Printer.printBool("isUnsigned", true); 1826 Printer.printInt("value", N->getValue(), /* ShouldSkipZero */ false); 1831 static void writeDIBasicType(raw_ostream &Out, const DIBasicType *N, 1832 TypePrinting *, SlotTracker *, const Module *) { 1833 Out << "!DIBasicType("; 1834 MDFieldPrinter Printer(Out); 1835 if (N->getTag() != dwarf::DW_TAG_base_type) 1836 Printer.printTag(N); 1837 Printer.printString("name", N->getName()); 1838 Printer.printInt("size", N->getSizeInBits()); 1839 Printer.printInt("align", N->getAlignInBits()); 1840 Printer.printDwarfEnum("encoding", N->getEncoding(), 1841 dwarf::AttributeEncodingString); 1842 Printer.printDIFlags("flags", N->getFlags()); 1846 static void writeDIDerivedType(raw_ostream &Out, const DIDerivedType *N, 1847 TypePrinting *TypePrinter, SlotTracker *Machine, 1848 const Module *Context) { 1849 Out << "!DIDerivedType("; 1850 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 1851 Printer.printTag(N); 1852 Printer.printString("name", N->getName()); 1853 Printer.printMetadata("scope", N->getRawScope()); 1854 Printer.printMetadata("file", N->getRawFile()); 1855 Printer.printInt("line", N->getLine()); 1856 Printer.printMetadata("baseType", N->getRawBaseType(), 1857 /* ShouldSkipNull */ false); 1858 Printer.printInt("size", N->getSizeInBits()); 1859 Printer.printInt("align", N->getAlignInBits()); 1860 Printer.printInt("offset", N->getOffsetInBits()); 1861 Printer.printDIFlags("flags", N->getFlags()); 1862 Printer.printMetadata("extraData", N->getRawExtraData()); 1863 if (const auto &DWARFAddressSpace = N->getDWARFAddressSpace()) 1864 Printer.printInt("dwarfAddressSpace", *DWARFAddressSpace, 1865 /* ShouldSkipZero */ false); 1869 static void writeDICompositeType(raw_ostream &Out, const DICompositeType *N, 1870 TypePrinting *TypePrinter, 1871 SlotTracker *Machine, const Module *Context) { 1872 Out << "!DICompositeType("; 1873 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 1874 Printer.printTag(N); 1875 Printer.printString("name", N->getName()); 1876 Printer.printMetadata("scope", N->getRawScope()); 1877 Printer.printMetadata("file", N->getRawFile()); 1878 Printer.printInt("line", N->getLine()); 1879 Printer.printMetadata("baseType", N->getRawBaseType()); 1880 Printer.printInt("size", N->getSizeInBits()); 1881 Printer.printInt("align", N->getAlignInBits()); 1882 Printer.printInt("offset", N->getOffsetInBits()); 1883 Printer.printDIFlags("flags", N->getFlags()); 1884 Printer.printMetadata("elements", N->getRawElements()); 1885 Printer.printDwarfEnum("runtimeLang", N->getRuntimeLang(), 1886 dwarf::LanguageString); 1887 Printer.printMetadata("vtableHolder", N->getRawVTableHolder()); 1888 Printer.printMetadata("templateParams", N->getRawTemplateParams()); 1889 Printer.printString("identifier", N->getIdentifier()); 1890 Printer.printMetadata("discriminator", N->getRawDiscriminator()); 1894 static void writeDISubroutineType(raw_ostream &Out, const DISubroutineType *N, 1895 TypePrinting *TypePrinter, 1896 SlotTracker *Machine, const Module *Context) { 1897 Out << "!DISubroutineType("; 1898 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 1899 Printer.printDIFlags("flags", N->getFlags()); 1900 Printer.printDwarfEnum("cc", N->getCC(), dwarf::ConventionString); 1901 Printer.printMetadata("types", N->getRawTypeArray(), 1902 /* ShouldSkipNull */ false); 1906 static void writeDIFile(raw_ostream &Out, const DIFile *N, TypePrinting *, 1907 SlotTracker *, const Module *) { 1909 MDFieldPrinter Printer(Out); 1910 Printer.printString("filename", N->getFilename(), 1911 /* ShouldSkipEmpty */ false); 1912 Printer.printString("directory", N->getDirectory(), 1913 /* ShouldSkipEmpty */ false); 1914 // Print all values for checksum together, or not at all. 1915 if (N->getChecksum()) 1916 Printer.printChecksum(*N->getChecksum()); 1917 Printer.printString("source", N->getSource().getValueOr(StringRef()), 1918 /* ShouldSkipEmpty */ true); 1922 static void writeDICompileUnit(raw_ostream &Out, const DICompileUnit *N, 1923 TypePrinting *TypePrinter, SlotTracker *Machine, 1924 const Module *Context) { 1925 Out << "!DICompileUnit("; 1926 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 1927 Printer.printDwarfEnum("language", N->getSourceLanguage(), 1928 dwarf::LanguageString, /* ShouldSkipZero */ false); 1929 Printer.printMetadata("file", N->getRawFile(), /* ShouldSkipNull */ false); 1930 Printer.printString("producer", N->getProducer()); 1931 Printer.printBool("isOptimized", N->isOptimized()); 1932 Printer.printString("flags", N->getFlags()); 1933 Printer.printInt("runtimeVersion", N->getRuntimeVersion(), 1934 /* ShouldSkipZero */ false); 1935 Printer.printString("splitDebugFilename", N->getSplitDebugFilename()); 1936 Printer.printEmissionKind("emissionKind", N->getEmissionKind()); 1937 Printer.printMetadata("enums", N->getRawEnumTypes()); 1938 Printer.printMetadata("retainedTypes", N->getRawRetainedTypes()); 1939 Printer.printMetadata("globals", N->getRawGlobalVariables()); 1940 Printer.printMetadata("imports", N->getRawImportedEntities()); 1941 Printer.printMetadata("macros", N->getRawMacros()); 1942 Printer.printInt("dwoId", N->getDWOId()); 1943 Printer.printBool("splitDebugInlining", N->getSplitDebugInlining(), true); 1944 Printer.printBool("debugInfoForProfiling", N->getDebugInfoForProfiling(), 1946 Printer.printNameTableKind("nameTableKind", N->getNameTableKind()); 1947 Printer.printBool("rangesBaseAddress", N->getRangesBaseAddress(), false); 1951 static void writeDISubprogram(raw_ostream &Out, const DISubprogram *N, 1952 TypePrinting *TypePrinter, SlotTracker *Machine, 1953 const Module *Context) { 1954 Out << "!DISubprogram("; 1955 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 1956 Printer.printString("name", N->getName()); 1957 Printer.printString("linkageName", N->getLinkageName()); 1958 Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false); 1959 Printer.printMetadata("file", N->getRawFile()); 1960 Printer.printInt("line", N->getLine()); 1961 Printer.printMetadata("type", N->getRawType()); 1962 Printer.printInt("scopeLine", N->getScopeLine()); 1963 Printer.printMetadata("containingType", N->getRawContainingType()); 1964 if (N->getVirtuality() != dwarf::DW_VIRTUALITY_none || 1965 N->getVirtualIndex() != 0) 1966 Printer.printInt("virtualIndex", N->getVirtualIndex(), false); 1967 Printer.printInt("thisAdjustment", N->getThisAdjustment()); 1968 Printer.printDIFlags("flags", N->getFlags()); 1969 Printer.printDISPFlags("spFlags", N->getSPFlags()); 1970 Printer.printMetadata("unit", N->getRawUnit()); 1971 Printer.printMetadata("templateParams", N->getRawTemplateParams()); 1972 Printer.printMetadata("declaration", N->getRawDeclaration()); 1973 Printer.printMetadata("retainedNodes", N->getRawRetainedNodes()); 1974 Printer.printMetadata("thrownTypes", N->getRawThrownTypes()); 1978 static void writeDILexicalBlock(raw_ostream &Out, const DILexicalBlock *N, 1979 TypePrinting *TypePrinter, SlotTracker *Machine, 1980 const Module *Context) { 1981 Out << "!DILexicalBlock("; 1982 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 1983 Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false); 1984 Printer.printMetadata("file", N->getRawFile()); 1985 Printer.printInt("line", N->getLine()); 1986 Printer.printInt("column", N->getColumn()); 1990 static void writeDILexicalBlockFile(raw_ostream &Out, 1991 const DILexicalBlockFile *N, 1992 TypePrinting *TypePrinter, 1993 SlotTracker *Machine, 1994 const Module *Context) { 1995 Out << "!DILexicalBlockFile("; 1996 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 1997 Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false); 1998 Printer.printMetadata("file", N->getRawFile()); 1999 Printer.printInt("discriminator", N->getDiscriminator(), 2000 /* ShouldSkipZero */ false); 2004 static void writeDINamespace(raw_ostream &Out, const DINamespace *N, 2005 TypePrinting *TypePrinter, SlotTracker *Machine, 2006 const Module *Context) { 2007 Out << "!DINamespace("; 2008 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 2009 Printer.printString("name", N->getName()); 2010 Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false); 2011 Printer.printBool("exportSymbols", N->getExportSymbols(), false); 2015 static void writeDICommonBlock(raw_ostream &Out, const DICommonBlock *N, 2016 TypePrinting *TypePrinter, SlotTracker *Machine, 2017 const Module *Context) { 2018 Out << "!DICommonBlock("; 2019 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 2020 Printer.printMetadata("scope", N->getRawScope(), false); 2021 Printer.printMetadata("declaration", N->getRawDecl(), false); 2022 Printer.printString("name", N->getName()); 2023 Printer.printMetadata("file", N->getRawFile()); 2024 Printer.printInt("line", N->getLineNo()); 2028 static void writeDIMacro(raw_ostream &Out, const DIMacro *N, 2029 TypePrinting *TypePrinter, SlotTracker *Machine, 2030 const Module *Context) { 2032 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 2033 Printer.printMacinfoType(N); 2034 Printer.printInt("line", N->getLine()); 2035 Printer.printString("name", N->getName()); 2036 Printer.printString("value", N->getValue()); 2040 static void writeDIMacroFile(raw_ostream &Out, const DIMacroFile *N, 2041 TypePrinting *TypePrinter, SlotTracker *Machine, 2042 const Module *Context) { 2043 Out << "!DIMacroFile("; 2044 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 2045 Printer.printInt("line", N->getLine()); 2046 Printer.printMetadata("file", N->getRawFile(), /* ShouldSkipNull */ false); 2047 Printer.printMetadata("nodes", N->getRawElements()); 2051 static void writeDIModule(raw_ostream &Out, const DIModule *N, 2052 TypePrinting *TypePrinter, SlotTracker *Machine, 2053 const Module *Context) { 2054 Out << "!DIModule("; 2055 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 2056 Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false); 2057 Printer.printString("name", N->getName()); 2058 Printer.printString("configMacros", N->getConfigurationMacros()); 2059 Printer.printString("includePath", N->getIncludePath()); 2060 Printer.printString("sysroot", N->getSysRoot()); 2065 static void writeDITemplateTypeParameter(raw_ostream &Out, 2066 const DITemplateTypeParameter *N, 2067 TypePrinting *TypePrinter, 2068 SlotTracker *Machine, 2069 const Module *Context) { 2070 Out << "!DITemplateTypeParameter("; 2071 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 2072 Printer.printString("name", N->getName()); 2073 Printer.printMetadata("type", N->getRawType(), /* ShouldSkipNull */ false); 2077 static void writeDITemplateValueParameter(raw_ostream &Out, 2078 const DITemplateValueParameter *N, 2079 TypePrinting *TypePrinter, 2080 SlotTracker *Machine, 2081 const Module *Context) { 2082 Out << "!DITemplateValueParameter("; 2083 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 2084 if (N->getTag() != dwarf::DW_TAG_template_value_parameter) 2085 Printer.printTag(N); 2086 Printer.printString("name", N->getName()); 2087 Printer.printMetadata("type", N->getRawType()); 2088 Printer.printMetadata("value", N->getValue(), /* ShouldSkipNull */ false); 2092 static void writeDIGlobalVariable(raw_ostream &Out, const DIGlobalVariable *N, 2093 TypePrinting *TypePrinter, 2094 SlotTracker *Machine, const Module *Context) { 2095 Out << "!DIGlobalVariable("; 2096 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 2097 Printer.printString("name", N->getName()); 2098 Printer.printString("linkageName", N->getLinkageName()); 2099 Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false); 2100 Printer.printMetadata("file", N->getRawFile()); 2101 Printer.printInt("line", N->getLine()); 2102 Printer.printMetadata("type", N->getRawType()); 2103 Printer.printBool("isLocal", N->isLocalToUnit()); 2104 Printer.printBool("isDefinition", N->isDefinition()); 2105 Printer.printMetadata("declaration", N->getRawStaticDataMemberDeclaration()); 2106 Printer.printMetadata("templateParams", N->getRawTemplateParams()); 2107 Printer.printInt("align", N->getAlignInBits()); 2111 static void writeDILocalVariable(raw_ostream &Out, const DILocalVariable *N, 2112 TypePrinting *TypePrinter, 2113 SlotTracker *Machine, const Module *Context) { 2114 Out << "!DILocalVariable("; 2115 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 2116 Printer.printString("name", N->getName()); 2117 Printer.printInt("arg", N->getArg()); 2118 Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false); 2119 Printer.printMetadata("file", N->getRawFile()); 2120 Printer.printInt("line", N->getLine()); 2121 Printer.printMetadata("type", N->getRawType()); 2122 Printer.printDIFlags("flags", N->getFlags()); 2123 Printer.printInt("align", N->getAlignInBits()); 2127 static void writeDILabel(raw_ostream &Out, const DILabel *N, 2128 TypePrinting *TypePrinter, 2129 SlotTracker *Machine, const Module *Context) { 2131 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 2132 Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false); 2133 Printer.printString("name", N->getName()); 2134 Printer.printMetadata("file", N->getRawFile()); 2135 Printer.printInt("line", N->getLine()); 2139 static void writeDIExpression(raw_ostream &Out, const DIExpression *N, 2140 TypePrinting *TypePrinter, SlotTracker *Machine, 2141 const Module *Context) { 2142 Out << "!DIExpression("; 2145 for (auto I = N->expr_op_begin(), E = N->expr_op_end(); I != E; ++I) { 2146 auto OpStr = dwarf::OperationEncodingString(I->getOp()); 2147 assert(!OpStr.empty() && "Expected valid opcode"); 2150 if (I->getOp() == dwarf::DW_OP_LLVM_convert) { 2151 Out << FS << I->getArg(0); 2152 Out << FS << dwarf::AttributeEncodingString(I->getArg(1)); 2154 for (unsigned A = 0, AE = I->getNumArgs(); A != AE; ++A) 2155 Out << FS << I->getArg(A); 2159 for (const auto &I : N->getElements()) 2165 static void writeDIGlobalVariableExpression(raw_ostream &Out, 2166 const DIGlobalVariableExpression *N, 2167 TypePrinting *TypePrinter, 2168 SlotTracker *Machine, 2169 const Module *Context) { 2170 Out << "!DIGlobalVariableExpression("; 2171 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 2172 Printer.printMetadata("var", N->getVariable()); 2173 Printer.printMetadata("expr", N->getExpression()); 2177 static void writeDIObjCProperty(raw_ostream &Out, const DIObjCProperty *N, 2178 TypePrinting *TypePrinter, SlotTracker *Machine, 2179 const Module *Context) { 2180 Out << "!DIObjCProperty("; 2181 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 2182 Printer.printString("name", N->getName()); 2183 Printer.printMetadata("file", N->getRawFile()); 2184 Printer.printInt("line", N->getLine()); 2185 Printer.printString("setter", N->getSetterName()); 2186 Printer.printString("getter", N->getGetterName()); 2187 Printer.printInt("attributes", N->getAttributes()); 2188 Printer.printMetadata("type", N->getRawType()); 2192 static void writeDIImportedEntity(raw_ostream &Out, const DIImportedEntity *N, 2193 TypePrinting *TypePrinter, 2194 SlotTracker *Machine, const Module *Context) { 2195 Out << "!DIImportedEntity("; 2196 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 2197 Printer.printTag(N); 2198 Printer.printString("name", N->getName()); 2199 Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false); 2200 Printer.printMetadata("entity", N->getRawEntity()); 2201 Printer.printMetadata("file", N->getRawFile()); 2202 Printer.printInt("line", N->getLine()); 2206 static void WriteMDNodeBodyInternal(raw_ostream &Out, const MDNode *Node, 2207 TypePrinting *TypePrinter, 2208 SlotTracker *Machine, 2209 const Module *Context) { 2210 if (Node->isDistinct()) 2212 else if (Node->isTemporary()) 2213 Out << "<temporary!> "; // Handle broken code. 2215 switch (Node->getMetadataID()) { 2217 llvm_unreachable("Expected uniquable MDNode"); 2218 #define HANDLE_MDNODE_LEAF(CLASS) \ 2219 case Metadata::CLASS##Kind: \ 2220 write##CLASS(Out, cast<CLASS>(Node), TypePrinter, Machine, Context); \ 2222 #include "llvm/IR/Metadata.def" 2226 // Full implementation of printing a Value as an operand with support for 2227 // TypePrinting, etc. 2228 static void WriteAsOperandInternal(raw_ostream &Out, const Value *V, 2229 TypePrinting *TypePrinter, 2230 SlotTracker *Machine, 2231 const Module *Context) { 2233 PrintLLVMName(Out, V); 2237 const Constant *CV = dyn_cast<Constant>(V); 2238 if (CV && !isa<GlobalValue>(CV)) { 2239 assert(TypePrinter && "Constants require TypePrinting!"); 2240 WriteConstantInternal(Out, CV, *TypePrinter, Machine, Context); 2244 if (const InlineAsm *IA = dyn_cast<InlineAsm>(V)) { 2246 if (IA->hasSideEffects()) 2247 Out << "sideeffect "; 2248 if (IA->isAlignStack()) 2249 Out << "alignstack "; 2250 // We don't emit the AD_ATT dialect as it
's the assumed default. 2251 if (IA->getDialect() == InlineAsm::AD_Intel) 2252 Out << "inteldialect "; 2254 printEscapedString(IA->getAsmString(), Out); 2261 if (
auto *MD = dyn_cast<MetadataAsValue>(V)) {
2271 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
2272 Slot = Machine->getGlobalSlot(GV);
2275 Slot = Machine->getLocalSlot(V);
2282 Slot = Machine->getLocalSlot(V);
2288 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
2289 Slot = Machine->getGlobalSlot(GV);
2292 Slot = Machine->getLocalSlot(V);
2301 Out << Prefix << Slot;
2307 TypePrinting *TypePrinter,
2312 if (
const DIExpression *Expr = dyn_cast<DIExpression>(MD)) {
2317 if (
const MDNode *N = dyn_cast<MDNode>(MD)) {
2318 std::unique_ptr<SlotTracker> MachineStorage;
2320 MachineStorage = std::make_unique<SlotTracker>(
Context);
2321 Machine = MachineStorage.get();
2325 if (
const DILocation *Loc = dyn_cast<DILocation>(N)) {
2331 Out <<
"<" << N <<
">";
2337 if (
const MDString *MDS = dyn_cast<MDString>(MD)) {
2344 auto *V = cast<ValueAsMetadata>(MD);
2345 assert(TypePrinter &&
"TypePrinter required for metadata values");
2346 assert((FromValue || !isa<LocalAsMetadata>(V)) &&
2347 "Unexpected function-local metadata outside of value argument");
2349 TypePrinter->print(V->getValue()->
getType(), Out);
2356 class AssemblyWriter {
2358 const Module *TheModule =
nullptr;
2360 std::unique_ptr<SlotTracker> SlotTrackerStorage;
2362 TypePrinting TypePrinter;
2366 bool ShouldPreserveUseListOrder;
2377 bool ShouldPreserveUseListOrder =
false);
2382 void printMDNodeBody(
const MDNode *MD);
2385 void printModule(
const Module *M);
2387 void writeOperand(
const Value *
Op,
bool PrintType);
2389 void writeOperandBundles(
const CallBase *Call);
2395 void writeAtomicCmpXchg(
const LLVMContext &Context,
2400 void writeAllMDNodes();
2401 void writeMDNode(
unsigned Slot,
const MDNode *Node);
2402 void writeAttribute(
const Attribute &Attr,
bool InAttrGroup =
false);
2403 void writeAttributeSet(
const AttributeSet &AttrSet,
bool InAttrGroup =
false);
2404 void writeAllAttributeGroups();
2406 void printTypeIdentities();
2409 void printComdat(
const Comdat *
C);
2410 void printFunction(
const Function *F);
2417 void printUseLists(
const Function *F);
2419 void printModuleSummaryIndex();
2420 void printSummaryInfo(
unsigned Slot,
const ValueInfo &
VI);
2428 void printArgs(
const std::vector<uint64_t> &
Args);
2433 printNonConstVCalls(
const std::vector<FunctionSummary::VFuncId> VCallList,
2436 printConstVCalls(
const std::vector<FunctionSummary::ConstVCall> VCallList,
2441 void printMetadataAttachments(
2447 void printInfoComment(
const Value &V);
2458 bool IsForDebug,
bool ShouldPreserveUseListOrder)
2459 : Out(o), TheModule(M),
Machine(Mac), TypePrinter(M), AnnotationWriter(AAW),
2460 IsForDebug(IsForDebug),
2461 ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) {
2464 for (
const GlobalObject &GO : TheModule->global_objects())
2471 : Out(o), TheIndex(Index),
Machine(Mac), TypePrinter(
nullptr),
2472 IsForDebug(IsForDebug), ShouldPreserveUseListOrder(
false) {}
2474 void AssemblyWriter::writeOperand(
const Value *Operand,
bool PrintType) {
2476 Out <<
"<null operand!>";
2480 TypePrinter.print(Operand->
getType(), Out);
2486 void AssemblyWriter::writeSyncScope(
const LLVMContext &Context,
2496 Out <<
" syncscope(\"";
2504 void AssemblyWriter::writeAtomic(
const LLVMContext &Context,
2510 writeSyncScope(Context, SSID);
2514 void AssemblyWriter::writeAtomicCmpXchg(
const LLVMContext &Context,
2521 writeSyncScope(Context, SSID);
2526 void AssemblyWriter::writeParamOperand(
const Value *Operand,
2529 Out <<
"<null operand!>";
2534 TypePrinter.print(Operand->
getType(), Out);
2538 writeAttributeSet(Attrs);
2545 void AssemblyWriter::writeOperandBundles(
const CallBase *Call) {
2551 bool FirstBundle =
true;
2557 FirstBundle =
false;
2565 bool FirstInput =
true;
2566 for (
const auto &Input : BU.
Inputs) {
2571 TypePrinter.print(Input->getType(), Out);
2582 void AssemblyWriter::printModule(
const Module *M) {
2583 Machine.initializeIfNeeded();
2585 if (ShouldPreserveUseListOrder)
2595 Out <<
"source_filename = \"";
2602 Out <<
"target datalayout = \"" << DL <<
"\"\n";
2613 std::tie(Front, Asm) = Asm.
split(
'\n');
2617 Out <<
"module asm \"";
2620 }
while (!Asm.
empty());
2623 printTypeIdentities();
2626 if (!Comdats.empty())
2628 for (
const Comdat *
C : Comdats) {
2630 if (
C != Comdats.back())
2637 printGlobal(&GV); Out <<
'\n';
2643 printIndirectSymbol(&GA);
2648 printIndirectSymbol(&GI);
2651 printUseLists(
nullptr);
2658 assert(UseListOrders.empty() &&
"All use-lists should have been consumed");
2661 if (!Machine.as_empty()) {
2663 writeAllAttributeGroups();
2667 if (!M->named_metadata_empty()) Out <<
'\n';
2669 for (
const NamedMDNode &Node : M->named_metadata())
2670 printNamedMDNode(&Node);
2673 if (!Machine.mdn_empty()) {
2679 void AssemblyWriter::printModuleSummaryIndex() {
2681 Machine.initializeIndexIfNeeded();
2687 std::vector<std::pair<std::string, ModuleHash>> moduleVec;
2688 std::string RegularLTOModuleName =
"[Regular LTO]";
2689 moduleVec.resize(TheIndex->modulePaths().size());
2690 for (
auto &ModPath : TheIndex->modulePaths())
2691 moduleVec[Machine.getModulePathSlot(ModPath.first())] = std::make_pair(
2694 ModPath.second.first == -1u ? RegularLTOModuleName
2695 : (std::string)ModPath.first(),
2696 ModPath.second.second);
2699 for (
auto &ModPair : moduleVec) {
2700 Out <<
"^" << i++ <<
" = module: (";
2703 Out <<
"\", hash: (";
2705 for (
auto Hash : ModPair.second)
2712 for (
auto &GlobalList : *TheIndex) {
2713 auto GUID = GlobalList.first;
2714 for (
auto &Summary : GlobalList.second.SummaryList)
2715 SummaryToGUIDMap[Summary.get()] = GUID;
2719 for (
auto &GlobalList : *TheIndex) {
2720 auto GUID = GlobalList.first;
2721 auto VI = TheIndex->getValueInfo(GlobalList);
2722 printSummaryInfo(Machine.getGUIDSlot(GUID),
VI);
2726 for (
auto TidIter = TheIndex->typeIds().begin();
2727 TidIter != TheIndex->typeIds().end(); TidIter++) {
2728 Out <<
"^" << Machine.getTypeIdSlot(TidIter->second.first)
2729 <<
" = typeid: (name: \"" << TidIter->second.first <<
"\"";
2730 printTypeIdSummary(TidIter->second.second);
2731 Out <<
") ; guid = " << TidIter->first <<
"\n";
2735 for (
auto &TId : TheIndex->typeIdCompatibleVtableMap()) {
2737 Out <<
"^" << Machine.getGUIDSlot(GUID)
2738 <<
" = typeidCompatibleVTable: (name: \"" << TId.first <<
"\"";
2739 printTypeIdCompatibleVtableSummary(TId.second);
2740 Out <<
") ; guid = " << GUID <<
"\n";
2750 return "singleImpl";
2752 return "branchFunnel";
2763 return "uniformRetVal";
2765 return "uniqueRetVal";
2767 return "virtualConstProp";
2795 Out <<
", alignLog2: " << TTRes.
AlignLog2;
2797 Out <<
", sizeM1: " << TTRes.
SizeM1;
2807 void AssemblyWriter::printTypeIdSummary(
const TypeIdSummary &TIS) {
2808 Out <<
", summary: (";
2809 printTypeTestResolution(TIS.
TTRes);
2810 if (!TIS.
WPDRes.empty()) {
2811 Out <<
", wpdResolutions: (";
2813 for (
auto &WPDRes : TIS.
WPDRes) {
2815 Out <<
"(offset: " << WPDRes.first <<
", ";
2816 printWPDRes(WPDRes.second);
2824 void AssemblyWriter::printTypeIdCompatibleVtableSummary(
2826 Out <<
", summary: (";
2828 for (
auto &
P : TI) {
2830 Out <<
"(offset: " <<
P.AddressPointOffset <<
", ";
2831 Out <<
"^" << Machine.getGUIDSlot(
P.VTableVI.getGUID());
2837 void AssemblyWriter::printArgs(
const std::vector<uint64_t> &
Args) {
2840 for (
auto arg : Args) {
2848 Out <<
"wpdRes: (kind: ";
2855 Out <<
", resByArg: (";
2857 for (
auto &ResByArg : WPDRes.
ResByArg) {
2859 printArgs(ResByArg.first);
2860 Out <<
", byArg: (kind: ";
2862 if (ResByArg.second.TheKind ==
2864 ResByArg.second.TheKind ==
2866 Out <<
", info: " << ResByArg.second.Info;
2870 if (ResByArg.second.Byte || ResByArg.second.Bit)
2871 Out <<
", byte: " << ResByArg.second.Byte
2872 <<
", bit: " << ResByArg.second.Bit;
2893 void AssemblyWriter::printAliasSummary(
const AliasSummary *AS) {
2894 Out <<
", aliasee: ";
2899 Out <<
"^" << Machine.getGUIDSlot(SummaryToGUIDMap[&AS->
getAliasee()]);
2909 if (!VTableFuncs.empty()) {
2910 Out <<
", vTableFuncs: (";
2912 for (
auto &
P : VTableFuncs) {
2914 Out <<
"(virtFunc: ^" << Machine.getGUIDSlot(
P.FuncVI.getGUID())
2915 <<
", offset: " <<
P.VTableOffset;
2933 return "linkonce_odr";
2943 return "extern_weak";
2945 return "available_externally";
2965 Out <<
", funcFlags: (";
2966 Out <<
"readNone: " << FFlags.
ReadNone;
2967 Out <<
", readOnly: " << FFlags.
ReadOnly;
2968 Out <<
", noRecurse: " << FFlags.
NoRecurse;
2970 Out <<
", noInline: " << FFlags.
NoInline;
2974 if (!FS->
calls().empty()) {
2975 Out <<
", calls: (";
2977 for (
auto &Call : FS->
calls()) {
2979 Out <<
"(callee: ^" << Machine.getGUIDSlot(Call.first.getGUID());
2981 Out <<
", hotness: " <<
getHotnessName(Call.second.getHotness());
2982 else if (Call.second.RelBlockFreq)
2983 Out <<
", relbf: " << Call.second.RelBlockFreq;
2990 printTypeIdInfo(*TIdInfo);
2993 void AssemblyWriter::printTypeIdInfo(
2995 Out <<
", typeIdInfo: (";
2996 FieldSeparator TIDFS;
2999 Out <<
"typeTests: (";
3002 auto TidIter = TheIndex->typeIds().equal_range(GUID);
3003 if (TidIter.first == TidIter.second) {
3009 for (
auto It = TidIter.first; It != TidIter.second; ++It) {
3011 auto Slot = Machine.getTypeIdSlot(It->second.first);
3029 "typeTestAssumeConstVCalls");
3034 "typeCheckedLoadConstVCalls");
3040 auto TidIter = TheIndex->typeIds().equal_range(VFId.
GUID);
3041 if (TidIter.first == TidIter.second) {
3042 Out <<
"vFuncId: (";
3043 Out <<
"guid: " << VFId.
GUID;
3044 Out <<
", offset: " << VFId.
Offset;
3050 for (
auto It = TidIter.first; It != TidIter.second; ++It) {
3052 Out <<
"vFuncId: (";
3053 auto Slot = Machine.getTypeIdSlot(It->second.first);
3056 Out <<
", offset: " << VFId.
Offset;
3061 void AssemblyWriter::printNonConstVCalls(
3062 const std::vector<FunctionSummary::VFuncId> VCallList,
const char *
Tag) {
3063 Out << Tag <<
": (";
3065 for (
auto &VFuncId : VCallList) {
3067 printVFuncId(VFuncId);
3072 void AssemblyWriter::printConstVCalls(
3073 const std::vector<FunctionSummary::ConstVCall> VCallList,
const char *Tag) {
3074 Out << Tag <<
": (";
3076 for (
auto &ConstVCall : VCallList) {
3079 printVFuncId(ConstVCall.VFunc);
3080 if (!ConstVCall.Args.empty()) {
3082 printArgs(ConstVCall.Args);
3093 Out <<
"(module: ^" << Machine.getModulePathSlot(Summary.
modulePath())
3097 Out <<
", live: " << GVFlags.
Live;
3098 Out <<
", dsoLocal: " << GVFlags.
DSOLocal;
3103 printAliasSummary(cast<AliasSummary>(&Summary));
3105 printFunctionSummary(cast<FunctionSummary>(&Summary));
3107 printGlobalVarSummary(cast<GlobalVarSummary>(&Summary));
3109 auto RefList = Summary.
refs();
3110 if (!RefList.empty()) {
3113 for (
auto &
Ref : RefList) {
3115 if (
Ref.isReadOnly())
3117 else if (
Ref.isWriteOnly())
3118 Out <<
"writeonly ";
3119 Out <<
"^" << Machine.getGUIDSlot(
Ref.getGUID());
3127 void AssemblyWriter::printSummaryInfo(
unsigned Slot,
const ValueInfo &
VI) {
3128 Out <<
"^" << Slot <<
" = gv: (";
3130 Out <<
"name: \"" << VI.
name() <<
"\"";
3132 Out <<
"guid: " << VI.
getGUID();
3134 Out <<
", summaries: (";
3138 printSummary(*Summary);
3144 Out <<
" ; guid = " << VI.
getGUID();
3151 Out <<
"<empty name> ";
3153 if (isalpha(static_cast<unsigned char>(Name[0])) || Name[0] ==
'-' ||
3154 Name[0] ==
'$' || Name[0] ==
'.' || Name[0] ==
'_')
3157 Out << '\\' << hexdigit(Name[0] >> 4) <<
hexdigit(Name[0] & 0x0F);
3158 for (
unsigned i = 1,
e = Name.
size(); i !=
e; ++i) {
3159 unsigned char C = Name[i];
3160 if (isalnum(static_cast<unsigned char>(C)) || C ==
'-' || C ==
'$' ||
3161 C ==
'.' || C ==
'_')
3164 Out << '\\' << hexdigit(C >> 4) <<
hexdigit(C & 0x0F);
3169 void AssemblyWriter::printNamedMDNode(
const NamedMDNode *NMD) {
3180 if (
auto *Expr = dyn_cast<DIExpression>(Op)) {
3185 int Slot = Machine.getMetadataSlot(Op);
3210 Out <<
"dso_local ";
3228 Out <<
"thread_local ";
3231 Out <<
"thread_local(localdynamic) ";
3234 Out <<
"thread_local(initialexec) ";
3237 Out <<
"thread_local(localexec) ";
3247 return "local_unnamed_addr";
3249 return "unnamed_addr";
3260 if (isa<GlobalVariable>(GO))
3274 Out <<
"; Materializable\n";
3294 Out << (GV->
isConstant() ?
"constant " :
"global ");
3303 Out <<
", section \"";
3308 Out <<
", partition \"";
3319 printMetadataAttachments(MDs,
", ");
3323 Out <<
" #" << Machine.getAttributeGroupSlot(Attrs);
3325 printInfoComment(*GV);
3330 Out <<
"; Materializable\n";
3344 if (isa<GlobalAlias>(GIS))
3346 else if (isa<GlobalIFunc>(GIS))
3358 TypePrinter.print(GIS->
getType(), Out);
3359 Out <<
" <<NULL ALIASEE>>";
3361 writeOperand(IS, !isa<ConstantExpr>(IS));
3365 Out <<
", partition \"";
3370 printInfoComment(*GIS);
3374 void AssemblyWriter::printComdat(
const Comdat *
C) {
3378 void AssemblyWriter::printTypeIdentities() {
3379 if (TypePrinter.empty())
3385 auto &NumberedTypes = TypePrinter.getNumberedTypes();
3386 for (
unsigned I = 0,
E = NumberedTypes.size(); I !=
E; ++
I) {
3387 Out <<
'%' << I <<
" = type ";
3391 TypePrinter.printStructBody(NumberedTypes[I], Out);
3395 auto &NamedTypes = TypePrinter.getNamedTypes();
3396 for (
unsigned I = 0,
E = NamedTypes.size(); I !=
E; ++
I) {
3402 TypePrinter.printStructBody(NamedTypes[I], Out);
3408 void AssemblyWriter::printFunction(
const Function *F) {
3409 if (AnnotationWriter) AnnotationWriter->emitFunctionAnnot(F, Out);
3412 Out <<
"; Materializable\n";
3417 std::string AttrStr;
3420 if (!Attr.isStringAttribute()) {
3421 if (!AttrStr.empty()) AttrStr +=
' ';
3426 if (!AttrStr.empty())
3427 Out <<
"; Function Attrs: " << AttrStr <<
'\n';
3430 Machine.incorporateFunction(F);
3436 printMetadataAttachments(MDs,
" ");
3473 writeAttributeSet(ArgAttrs);
3480 if (
Arg.getArgNo() != 0)
3503 Out <<
" #" << Machine.getAttributeGroupSlot(Attrs.
getFnAttributes());
3505 Out <<
" section \"";
3510 Out <<
" partition \"";
3518 Out <<
" gc \"" << F->
getGC() <<
'"';
3524 Out <<
" prologue ";
3528 Out <<
" personality ";
3537 printMetadataAttachments(MDs,
" ");
3542 printBasicBlock(&BB);
3550 Machine.purgeFunction();
3557 TypePrinter.print(Arg->
getType(), Out);
3562 writeAttributeSet(Attrs);
3570 int Slot = Machine.getLocalSlot(Arg);
3571 assert(Slot != -1 &&
"expect argument in function here");
3572 Out <<
" %" << Slot;
3577 void AssemblyWriter::printBasicBlock(
const BasicBlock *BB) {
3584 }
else if (!IsEntryBlock) {
3586 int Slot = Machine.getLocalSlot(BB);
3593 if (!IsEntryBlock) {
3595 Out.PadToColumn(50);
3600 Out <<
" No predecessors!";
3603 writeOperand(*PI,
false);
3604 for (++PI; PI != PE; ++PI) {
3606 writeOperand(*PI,
false);
3613 if (AnnotationWriter) AnnotationWriter->emitBasicBlockStartAnnot(BB, Out);
3617 printInstructionLine(I);
3620 if (AnnotationWriter) AnnotationWriter->emitBasicBlockEndAnnot(BB, Out);
3624 void AssemblyWriter::printInstructionLine(
const Instruction &I) {
3625 printInstruction(I);
3631 void AssemblyWriter::printGCRelocateComment(
const GCRelocateInst &Relocate) {
3641 void AssemblyWriter::printInfoComment(
const Value &V) {
3642 if (
const auto *Relocate = dyn_cast<GCRelocateInst>(&V))
3643 printGCRelocateComment(*Relocate);
3645 if (AnnotationWriter)
3646 AnnotationWriter->printInfoComment(V, Out);
3653 bool PrintAddrSpace = CallAddrSpace != 0;
3654 if (!PrintAddrSpace) {
3660 PrintAddrSpace =
true;
3663 Out <<
" addrspace(" << CallAddrSpace <<
")";
3667 void AssemblyWriter::printInstruction(
const Instruction &I) {
3668 if (AnnotationWriter) AnnotationWriter->emitInstructionAnnot(&I, Out);
3679 int SlotNum = Machine.getLocalSlot(&I);
3681 Out <<
"<badref> = ";
3683 Out <<
'%' << SlotNum <<
" = ";
3686 if (
const CallInst *CI = dyn_cast<CallInst>(&I)) {
3687 if (CI->isMustTailCall())
3689 else if (CI->isTailCall())
3691 else if (CI->isNoTailCall())
3699 if ((isa<LoadInst>(I) && cast<LoadInst>(I).
isAtomic()) ||
3700 (isa<StoreInst>(I) && cast<StoreInst>(I).
isAtomic()))
3703 if (isa<AtomicCmpXchgInst>(I) && cast<AtomicCmpXchgInst>(I).isWeak())
3707 if ((isa<LoadInst>(I) && cast<LoadInst>(I).
isVolatile()) ||
3708 (isa<StoreInst>(I) && cast<StoreInst>(I).
isVolatile()) ||
3709 (isa<AtomicCmpXchgInst>(I) && cast<AtomicCmpXchgInst>(I).
isVolatile()) ||
3710 (isa<AtomicRMWInst>(I) && cast<AtomicRMWInst>(I).
isVolatile()))
3717 if (
const CmpInst *CI = dyn_cast<CmpInst>(&I))
3721 if (
const AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(&I))
3728 if (isa<BranchInst>(I) && cast<BranchInst>(I).isConditional()) {
3737 }
else if (isa<SwitchInst>(I)) {
3745 for (
auto Case : SI.
cases()) {
3747 writeOperand(Case.getCaseValue(),
true);
3749 writeOperand(Case.getCaseSuccessor(),
true);
3752 }
else if (isa<IndirectBrInst>(I)) {
3755 writeOperand(Operand,
true);
3764 }
else if (
const PHINode *PN = dyn_cast<PHINode>(&I)) {
3766 TypePrinter.print(I.
getType(), Out);
3769 for (
unsigned op = 0, Eop = PN->getNumIncomingValues();
op < Eop; ++
op) {
3770 if (
op) Out <<
", ";
3772 writeOperand(PN->getIncomingValue(
op),
false); Out <<
", ";
3773 writeOperand(PN->getIncomingBlock(
op),
false); Out <<
" ]";
3778 for (
const unsigned *i = EVI->idx_begin(), *
e = EVI->idx_end(); i !=
e; ++i)
3780 }
else if (
const InsertValueInst *IVI = dyn_cast<InsertValueInst>(&I)) {
3782 writeOperand(I.
getOperand(0),
true); Out <<
", ";
3784 for (
const unsigned *i = IVI->idx_begin(), *
e = IVI->idx_end(); i !=
e; ++i)
3786 }
else if (
const LandingPadInst *LPI = dyn_cast<LandingPadInst>(&I)) {
3788 TypePrinter.print(I.
getType(), Out);
3789 if (LPI->isCleanup() || LPI->getNumClauses() != 0)
3792 if (LPI->isCleanup())
3795 for (
unsigned i = 0,
e = LPI->getNumClauses(); i !=
e; ++i) {
3796 if (i != 0 || LPI->isCleanup()) Out <<
"\n";
3797 if (LPI->isCatch(i))
3802 writeOperand(LPI->getClause(i),
true);
3804 }
else if (
const auto *CatchSwitch = dyn_cast<CatchSwitchInst>(&I)) {
3806 writeOperand(CatchSwitch->getParentPad(),
false);
3809 for (
const BasicBlock *PadBB : CatchSwitch->handlers()) {
3812 writeOperand(PadBB,
true);
3816 if (
const BasicBlock *UnwindDest = CatchSwitch->getUnwindDest())
3817 writeOperand(UnwindDest,
true);
3820 }
else if (
const auto *FPI = dyn_cast<FuncletPadInst>(&I)) {
3822 writeOperand(FPI->getParentPad(),
false);
3824 for (
unsigned Op = 0, NumOps = FPI->getNumArgOperands();
Op < NumOps;
3828 writeOperand(FPI->getArgOperand(
Op),
true);
3831 }
else if (isa<ReturnInst>(I) && !Operand) {
3833 }
else if (
const auto *CRI = dyn_cast<CatchReturnInst>(&I)) {
3835 writeOperand(CRI->getOperand(0),
false);
3838 writeOperand(CRI->getOperand(1),
true);
3839 }
else if (
const auto *CRI = dyn_cast<CleanupReturnInst>(&I)) {
3841 writeOperand(CRI->getOperand(0),
false);
3844 if (CRI->hasUnwindDest())
3845 writeOperand(CRI->getOperand(1),
true);
3848 }
else if (
const CallInst *CI = dyn_cast<CallInst>(&I)) {
3855 Operand = CI->getCalledValue();
3871 TypePrinter.print(FTy->
isVarArg() ? FTy : RetTy, Out);
3873 writeOperand(Operand,
false);
3875 for (
unsigned op = 0, Eop = CI->getNumArgOperands();
op < Eop; ++
op) {
3883 if (CI->isMustTailCall() && CI->getParent() &&
3884 CI->getParent()->getParent() &&
3885 CI->getParent()->getParent()->isVarArg())
3892 writeOperandBundles(CI);
3893 }
else if (
const InvokeInst *II = dyn_cast<InvokeInst>(&I)) {
3894 Operand = II->getCalledValue();
3916 TypePrinter.print(FTy->
isVarArg() ? FTy : RetTy, Out);
3918 writeOperand(Operand,
false);
3920 for (
unsigned op = 0, Eop = II->getNumArgOperands();
op < Eop; ++
op) {
3930 writeOperandBundles(II);
3933 writeOperand(II->getNormalDest(),
true);
3935 writeOperand(II->getUnwindDest(),
true);
3936 }
else if (
const CallBrInst *CBI = dyn_cast<CallBrInst>(&I)) {
3937 Operand = CBI->getCalledValue();
3956 TypePrinter.print(FTy->
isVarArg() ? FTy : RetTy, Out);
3958 writeOperand(Operand,
false);
3960 for (
unsigned op = 0, Eop = CBI->getNumArgOperands();
op < Eop; ++
op) {
3970 writeOperandBundles(CBI);
3973 writeOperand(CBI->getDefaultDest(),
true);
3975 for (
unsigned i = 0,
e = CBI->getNumIndirectDests(); i !=
e; ++i) {
3978 writeOperand(CBI->getIndirectDest(i),
true);
3981 }
else if (
const AllocaInst *AI = dyn_cast<AllocaInst>(&I)) {
3983 if (AI->isUsedWithInAlloca())
3985 if (AI->isSwiftError())
3986 Out <<
"swifterror ";
3987 TypePrinter.print(AI->getAllocatedType(), Out);
3993 if (!AI->getArraySize() || AI->isArrayAllocation() ||
3994 !AI->getArraySize()->getType()->isIntegerTy(32)) {
3996 writeOperand(AI->getArraySize(),
true);
3998 if (AI->getAlignment()) {
3999 Out <<
", align " << AI->getAlignment();
4002 unsigned AddrSpace = AI->getType()->getAddressSpace();
4003 if (AddrSpace != 0) {
4004 Out <<
", addrspace(" << AddrSpace <<
')';
4006 }
else if (isa<CastInst>(I)) {
4009 writeOperand(Operand,
true);
4012 TypePrinter.print(I.
getType(), Out);
4013 }
else if (isa<VAArgInst>(I)) {
4016 writeOperand(Operand,
true);
4019 TypePrinter.print(I.
getType(), Out);
4020 }
else if (Operand) {
4021 if (
const auto *
GEP = dyn_cast<GetElementPtrInst>(&I)) {
4023 TypePrinter.print(
GEP->getSourceElementType(), Out);
4025 }
else if (
const auto *LI = dyn_cast<LoadInst>(&I)) {
4027 TypePrinter.print(LI->getType(), Out);
4034 bool PrintAllTypes =
false;
4038 if (isa<SelectInst>(I) || isa<StoreInst>(I) || isa<ShuffleVectorInst>(I)
4039 || isa<ReturnInst>(I)) {
4040 PrintAllTypes =
true;
4046 if (Operand && Operand->
getType() != TheType) {
4047 PrintAllTypes =
true;
4053 if (!PrintAllTypes) {
4055 TypePrinter.print(TheType, Out);
4061 writeOperand(I.
getOperand(i), PrintAllTypes);
4066 if (
const LoadInst *LI = dyn_cast<LoadInst>(&I)) {
4068 writeAtomic(LI->getContext(), LI->getOrdering(), LI->getSyncScopeID());
4069 if (LI->getAlignment())
4070 Out <<
", align " << LI->getAlignment();
4071 }
else if (
const StoreInst *
SI = dyn_cast<StoreInst>(&I)) {
4073 writeAtomic(
SI->getContext(),
SI->getOrdering(),
SI->getSyncScopeID());
4074 if (
SI->getAlignment())
4075 Out <<
", align " <<
SI->getAlignment();
4077 writeAtomicCmpXchg(CXI->getContext(), CXI->getSuccessOrdering(),
4078 CXI->getFailureOrdering(), CXI->getSyncScopeID());
4079 }
else if (
const AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(&I)) {
4080 writeAtomic(RMWI->getContext(), RMWI->getOrdering(),
4081 RMWI->getSyncScopeID());
4082 }
else if (
const FenceInst *FI = dyn_cast<FenceInst>(&I)) {
4083 writeAtomic(FI->getContext(), FI->getOrdering(), FI->getSyncScopeID());
4089 printMetadataAttachments(InstMD,
", ");
4092 printInfoComment(I);
4095 void AssemblyWriter::printMetadataAttachments(
4101 if (MDNames.empty())
4102 MDs[0].
second->getContext().getMDKindNames(MDNames);
4104 for (
const auto &I : MDs) {
4105 unsigned Kind = I.first;
4107 if (Kind < MDNames.size()) {
4111 Out <<
"!<unknown kind #" << Kind <<
">";
4117 void AssemblyWriter::writeMDNode(
unsigned Slot,
const MDNode *Node) {
4118 Out <<
'!' << Slot <<
" = ";
4119 printMDNodeBody(Node);
4123 void AssemblyWriter::writeAllMDNodes() {
4125 Nodes.
resize(Machine.mdn_size());
4128 Nodes[I->second] = cast<MDNode>(I->first);
4130 for (
unsigned i = 0,
e = Nodes.
size(); i !=
e; ++i) {
4131 writeMDNode(i, Nodes[i]);
4135 void AssemblyWriter::printMDNodeBody(
const MDNode *Node) {
4139 void AssemblyWriter::writeAttribute(
const Attribute &Attr,
bool InAttrGroup) {
4150 TypePrinter.print(Ty, Out);
4155 void AssemblyWriter::writeAttributeSet(
const AttributeSet &AttrSet,
4157 bool FirstAttr =
true;
4158 for (
const auto &Attr : AttrSet) {
4161 writeAttribute(Attr, InAttrGroup);
4166 void AssemblyWriter::writeAllAttributeGroups() {
4167 std::vector<std::pair<AttributeSet, unsigned>> asVec;
4168 asVec.resize(Machine.as_size());
4172 asVec[I->second] = *I;
4174 for (
const auto &I : asVec)
4175 Out <<
"attributes #" << I.second <<
" = { " 4176 << I.first.getAsString(
true) <<
" }\n";
4179 void AssemblyWriter::printUseListOrder(
const UseListOrder &Order) {
4184 Out <<
"uselistorder";
4186 IsInFunction ?
nullptr : dyn_cast<BasicBlock>(Order.
V)) {
4190 writeOperand(BB,
false);
4193 writeOperand(Order.
V,
true);
4199 for (
unsigned I = 1,
E = Order.
Shuffle.size(); I !=
E; ++
I)
4200 Out <<
", " << Order.
Shuffle[I];
4204 void AssemblyWriter::printUseLists(
const Function *F) {
4206 [&]() {
return !UseListOrders.empty() && UseListOrders.back().F ==
F; };
4211 Out <<
"\n; uselistorder directives\n";
4213 printUseListOrder(UseListOrders.back());
4214 UseListOrders.pop_back();
4223 bool ShouldPreserveUseListOrder,
4224 bool IsForDebug)
const {
4227 AssemblyWriter
W(OS, SlotTable, this->
getParent(), AAW,
4229 ShouldPreserveUseListOrder);
4230 W.printFunction(
this);
4234 bool ShouldPreserveUseListOrder,
bool IsForDebug)
const {
4237 AssemblyWriter
W(OS, SlotTable,
this, AAW, IsForDebug,
4238 ShouldPreserveUseListOrder);
4239 W.printModule(
this);
4245 AssemblyWriter
W(OS, SlotTable,
getParent(),
nullptr, IsForDebug);
4246 W.printNamedMDNode(
this);
4250 bool IsForDebug)
const {
4257 SlotTable = &*LocalST;
4261 AssemblyWriter
W(OS, *SlotTable,
getParent(),
nullptr, IsForDebug);
4262 W.printNamedMDNode(
this);
4267 ROS <<
" = comdat ";
4269 switch (getSelectionKind()) {
4274 ROS <<
"exactmatch";
4280 ROS <<
"noduplicates";
4292 TP.print(const_cast<Type*>(
this), OS);
4298 if (
StructType *STy = dyn_cast<StructType>(const_cast<Type*>(
this)))
4299 if (!STy->isLiteral()) {
4301 TP.printStructBody(STy, OS);
4306 if (
const auto *CI = dyn_cast<CallInst>(&I))
4307 if (
Function *F = CI->getCalledFunction())
4310 if (
auto *V = dyn_cast_or_null<MetadataAsValue>(
Op))
4311 if (isa<MDNode>(V->getMetadata()))
4317 bool ShouldInitializeAllMetadata =
false;
4318 if (
auto *I = dyn_cast<Instruction>(
this))
4320 else if (isa<Function>(
this) || isa<MetadataAsValue>(
this))
4321 ShouldInitializeAllMetadata =
true;
4324 print(ROS, MST, IsForDebug);
4328 bool IsForDebug)
const {
4330 SlotTracker EmptySlotTable(static_cast<const Module *>(
nullptr));
4333 auto incorporateFunction = [&](
const Function *
F) {
4338 if (
const Instruction *I = dyn_cast<Instruction>(
this)) {
4341 W.printInstruction(*I);
4342 }
else if (
const BasicBlock *BB = dyn_cast<BasicBlock>(
this)) {
4345 W.printBasicBlock(BB);
4346 }
else if (
const GlobalValue *GV = dyn_cast<GlobalValue>(
this)) {
4347 AssemblyWriter
W(OS, SlotTable, GV->
getParent(),
nullptr, IsForDebug);
4350 else if (
const Function *F = dyn_cast<Function>(GV))
4353 W.printIndirectSymbol(cast<GlobalIndirectSymbol>(GV));
4354 }
else if (
const MetadataAsValue *V = dyn_cast<MetadataAsValue>(
this)) {
4356 }
else if (
const Constant *C = dyn_cast<Constant>(
this)) {
4357 TypePrinting TypePrinter;
4358 TypePrinter.print(C->getType(), OS);
4361 }
else if (isa<InlineAsm>(
this) || isa<Argument>(
this)) {
4362 this->printAsOperand(OS,
true, MST);
4373 if (V.
hasName() || isa<GlobalValue>(V) ||
4374 (!isa<Constant>(V) && !isa<MetadataAsValue>(V))) {
4383 TypePrinting TypePrinter(MST.
getModule());
4403 M, isa<MetadataAsValue>(
this));
4419 bool OnlyAsOperand) {
4422 TypePrinting TypePrinter(M);
4428 if (OnlyAsOperand || !N || isa<DIExpression>(MD))
4452 const Module *M,
bool )
const {
4459 AssemblyWriter
W(OS, SlotTable,
this, IsForDebug);
4460 W.printModuleSummaryIndex();
4463 #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.".
MSVC calling convention that passes vectors and vector aggregates in SSE registers.
unsigned getAlignment() const
const std::string & getTargetTriple() const
Get the target triple which is a string describing the target host.
std::vector< TypeIdOffsetVtableInfo > TypeIdCompatibleVtableInfo
List of vtable definitions decorated by a particular type identifier, and their corresponding offsets...
ThreadLocalMode getThreadLocalMode() const
static void WriteOptimizationInfo(raw_ostream &Out, const User *U)
This class is the base class for the comparison instructions.
Calling convention used for Mesa/AMDPAL hull shaders (= tessellation control shaders).
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)
bool hasLocalLinkage() const
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
The C convention as specified in the x86-64 supplement to the System V ABI, used on most non-Windows ...
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.
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
Type * getParamType(unsigned i) const
Parameter type accessors.
unsigned Linkage
The linkage type of the associated global value.
Calling convention used by HipHop Virtual Machine (HHVM) to perform calls to and from translation cac...
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)
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
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.
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.
This class represents a function call, abstracting a target machine's calling convention.
static bool lookup(const GsymReader &GR, DataExtractor &Data, uint64_t &Offset, uint64_t BaseAddr, uint64_t Addr, SourceLocations &SrcLocs, llvm::Error &Err)
A Lookup helper functions.
void emplace(ArgTypes &&... Args)
Create a new object by constructing it in place with the given arguments.
Value * getCondition() const
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.
C - The default llvm calling convention, compatible with C.
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
Calling convention used for AMDPAL vertex shader if tessellation is in use.
Kind
Specifies which kind of type check we should emit for this byte array.
Calling convention between AArch64 SVE functions.
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)
Calling convention used for Mesa/AMDPAL geometry shaders.
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.
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.
APInt getLoBits(unsigned numBits) const
Compute an APInt containing numBits lowbits from this APInt.
SPIR_KERNEL - Calling convention for SPIR kernel functions.
std::vector< unsigned > Shuffle
static OrderMap orderModule(const Module *M)
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.
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
For scalable vectors, this will return the minimum number of elements in the vector.
static void printMetadataIdentifier(StringRef Name, formatted_raw_ostream &Out)
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
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.
Class to represent function types.
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.
Type * getValueAsType() const
Return the attribute's value as a Type.
int getModulePathSlot(StringRef Path)
LLVM_NODISCARD size_t size() const
size - Get the string size.
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.
PTX_Kernel - Call to a PTX kernel.
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 AVR signal routines.
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.
Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
Calling convention used for Mesa/AMDPAL compute shaders.
AttributeSet getAttributes(unsigned Index) const
The attributes for the specified index are returned.
The C convention as implemented on Windows/x86-64 and AArch64.
11: Arbitrary bit width integers
X86_INTR - x86 hardware interrupt context.
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.
Intel_OCL_BI - Calling conventions for Intel OpenCL built-ins.
Type * getReturnType() const
Returns the type of the ret val.
bool hasAttribute(AttrKind Val) const
Return true if the attribute is present.
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.
void dump() const
Dump the module to stderr (for debugging).
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.
ARM_AAPCS - ARM Architecture Procedure Calling Standard calling convention (aka EABI).
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].
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.
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)
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
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)
MSP430_INTR - Calling convention used for MSP430 interrupt routines.
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.
static bool isAtomic(Instruction *I)
static void PrintThreadLocalModel(GlobalVariable::ThreadLocalMode TLM, formatted_raw_ostream &Out)
PTX_Device - Call to a PTX device function.
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.
CallBr instruction, tracking function calls that may not return control but instead transfer it to a ...
Synchronized with respect to all concurrently executing threads.
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.
Register calling convention used for parameters transfer optimization.
StringRef getPartition() const
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.
bool isScalable() const
Returns whether or not this is a scalable vector (meaning the total element count is a multiple of th...
static const fltSemantics & IEEEhalf() LLVM_READNONE
const char * getHotnessName(CalleeInfo::HotnessType HT)
ARM_AAPCS_VFP - Same as ARM_AAPCS, but uses hard floating point ABI.
16: SIMD 'packed' format, or other vector type
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
ARM_APCS - ARM Procedure Calling Standard calling convention (obsolete, but still used on some target...
bool hasSection() const
Check if this global has a custom object file section.
Calling convention used for Mesa/AMDPAL pixel shaders.
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
X86_StdCall - stdcall is the calling conventions mostly used by the Win32 API.
Single implementation devirtualization.
Type * getReturnType() const
bool isTypeAttribute() const
Return true if the attribute is a type attribute.
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)
ArrayRef< VirtFuncOffset > vTableFuncs() const
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.
LinkageTypes
An enumeration for the kinds of linkage for global values.
X86_FastCall - 'fast' analog of X86_StdCall.
StringRef getName() const
A lightweight accessor for an operand bundle meant to be passed around by value.
iterator_range< user_iterator > users()
SPIR_FUNC - Calling convention for SPIR non-kernel device functions.
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
SummaryKind
Sububclass discriminator (for dyn_cast<> et al.)
static const char * getWholeProgDevirtResByArgKindName(WholeProgramDevirtResolution::ByArg::Kind K)
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)
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
Function to be accessible from DLL.
bool hasPartition() const
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)
StringRef getName() const
Return a constant reference to the value's name.
const Function * getParent() const
Return the enclosing method, or null if none.
unsigned CanAutoHide
In the per-module summary, indicates that the global value is linkonce_odr and global unnamed addr (s...
FormattedNumber format_hex_no_prefix(uint64_t N, unsigned Width, bool Upper=false)
format_hex_no_prefix - Output N as a fixed width hexadecimal.
Calling convention used for Mesa vertex shaders, or AMDPAL last shader stage before rasterization (ve...
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)
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()
Tail - This calling convention attemps to make calls as fast as possible while guaranteeing that tail...
Inlined bit vector ("Short Inline Bit Vectors")
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...
std::string getAsString(bool InAttrGrp=false) const
The Attribute is converted to a string of equivalent mnemonic.
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())
Special calling convention on Windows for calling the Control Guard Check ICall funtion.
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.
Fast - This calling convention attempts to make calls as fast as possible (e.g.
A vector that has set insertion semantics.
bool hasInitializer() const
Definitions have initializers, declarations don't.
Just do a regular virtual call.
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
Calling convention for AMDGPU code object kernels.
Used for AVR interrupt routines.
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)
HHVM calling convention for invoking C/C++ helpers.
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.
X86_ThisCall - Similar to X86_StdCall.
iterator_range< arg_iterator > args()
Unique return value optimization.
Calling convention used for AMDPAL shader stage before geometry shader if geometry is in use...
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
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.