33 #include "llvm/Config/llvm-config.h" 105 unsigned size()
const {
return IDs.
size(); }
106 std::pair<unsigned, bool> &operator[](
const Value *V) {
return IDs[V]; }
108 std::pair<unsigned, bool>
lookup(
const Value *V)
const {
112 void index(
const Value *V) {
114 unsigned ID = IDs.
size() + 1;
122 if (OM.lookup(V).first)
125 if (
const Constant *
C = dyn_cast<Constant>(V))
128 if (!isa<BasicBlock>(
Op) && !isa<GlobalValue>(
Op))
142 if (
G.hasInitializer())
143 if (!isa<GlobalValue>(
G.getInitializer()))
148 if (!isa<GlobalValue>(A.getAliasee()))
153 if (!isa<GlobalValue>(
I.getResolver()))
158 for (
const Use &U :
F.operands())
159 if (!isa<GlobalValue>(U.get()))
164 if (
F.isDeclaration())
172 for (
const Value *
Op :
I.operands())
173 if ((isa<Constant>(*
Op) && !isa<GlobalValue>(*
Op)) ||
184 unsigned ID,
const OrderMap &OM,
187 using Entry = std::pair<const Use *, unsigned>;
191 if (OM.lookup(U.getUser()).
first)
199 !isa<GlobalVariable>(V) && !isa<Function>(V) && !isa<BasicBlock>(V);
200 if (
auto *BA = dyn_cast<BlockAddress>(V))
201 ID = OM.lookup(BA->getBasicBlock()).
first;
203 const Use *LU = L.first;
204 const Use *RU = R.first;
208 auto LID = OM.lookup(LU->getUser()).
first;
209 auto RID = OM.lookup(RU->getUser()).
first;
229 return LU->getOperandNo() < RU->getOperandNo();
230 return LU->getOperandNo() > RU->getOperandNo();
235 [](
const Entry &L,
const Entry &R) {
return L.second < R.second; }))
240 Stack.emplace_back(V, F, List.
size());
241 assert(List.
size() == Stack.back().Shuffle.size() &&
"Wrong size");
242 for (
size_t I = 0,
E = List.
size();
I !=
E; ++
I)
243 Stack.back().Shuffle[
I] = List[
I].second;
248 auto &IDPair = OM[V];
249 assert(IDPair.first &&
"Unmapped value");
255 IDPair.second =
true;
260 if (
const Constant *
C = dyn_cast<Constant>(V))
263 if (isa<Constant>(
Op))
281 if (
F.isDeclaration())
289 for (
const Value *
Op :
I.operands())
290 if (isa<Constant>(*
Op) || isa<InlineAsm>(*Op))
307 if (
G.hasInitializer())
314 for (
const Use &U :
F.operands())
321 if (
const Argument *MA = dyn_cast<Argument>(V))
322 return MA->getParent() ? MA->getParent()->getParent() :
nullptr;
324 if (
const BasicBlock *BB = dyn_cast<BasicBlock>(V))
325 return BB->getParent() ? BB->getParent()->getParent() :
nullptr;
328 const Function *M =
I->getParent() ?
I->getParent()->getParent() :
nullptr;
332 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V))
333 return GV->getParent();
335 if (
const auto *MAV = dyn_cast<MetadataAsValue>(V)) {
337 if (isa<Instruction>(U))
348 default: Out <<
"cc" << cc;
break;
402 bool NeedsQuotes = isdigit(static_cast<unsigned char>(Name[0]));
404 for (
unsigned i = 0, e = Name.
size(); i != e; ++i) {
409 unsigned char C = Name[i];
410 if (!isalnum(static_cast<unsigned char>(C)) && C !=
'-' && C !=
'.' &&
465 TypePrinting(
const Module *M =
nullptr) : DeferredM(M) {}
467 TypePrinting(
const TypePrinting &) =
delete;
468 TypePrinting &operator=(
const TypePrinting &) =
delete;
474 std::vector<StructType *> &getNumberedTypes();
483 void incorporateTypes();
493 std::vector<StructType *> NumberedTypes;
503 std::vector<StructType *> &TypePrinting::getNumberedTypes() {
509 if (NumberedTypes.size() == Type2Number.size())
510 return NumberedTypes;
512 NumberedTypes.resize(Type2Number.size());
513 for (
const auto &
P : Type2Number) {
514 assert(
P.second < NumberedTypes.size() &&
"Didn't get a dense numbering?");
515 assert(!NumberedTypes[
P.second] &&
"Didn't get a unique numbering?");
516 NumberedTypes[
P.second] =
P.first;
518 return NumberedTypes;
521 bool TypePrinting::empty() {
523 return NamedTypes.empty() && Type2Number.empty();
526 void TypePrinting::incorporateTypes() {
530 NamedTypes.run(*DeferredM,
false);
535 unsigned NextNumber = 0;
537 std::vector<StructType*>::iterator NextToUse = NamedTypes.begin(),
I,
E;
538 for (
I = NamedTypes.begin(), E = NamedTypes.end();
I !=
E; ++
I) {
546 Type2Number[STy] = NextNumber++;
551 NamedTypes.erase(NextToUse, NamedTypes.end());
594 return printStructBody(STy, OS);
600 const auto I = Type2Number.find(STy);
601 if (
I != Type2Number.end())
602 OS <<
'%' <<
I->second;
604 OS <<
"%\"type " << STy <<
'\"';
630 llvm_unreachable("Invalid TypeID"); 633 void TypePrinting::printStructBody(StructType *STy, raw_ostream &OS) { 634 if (STy->isOpaque()) { 642 if (STy->getNumElements() == 0) { 645 StructType::element_iterator I = STy->element_begin(); 648 for (StructType::element_iterator E = STy->element_end(); I != E; ++I) { 661 //===----------------------------------------------------------------------===// 662 // SlotTracker Class: Enumerate slot numbers for unnamed values 663 //===----------------------------------------------------------------------===// 669 using ValueMap = DenseMap<const Value *, unsigned>;
673 const Module* TheModule;
676 const Function* TheFunction = nullptr;
677 bool FunctionProcessed = false;
678 bool ShouldInitializeAllMetadata;
681 const ModuleSummaryIndex *TheIndex = nullptr;
692 DenseMap<const MDNode*, unsigned> mdnMap;
693 unsigned mdnNext = 0;
696 DenseMap<AttributeSet, unsigned> asMap;
700 StringMap<unsigned> ModulePathMap;
701 unsigned ModulePathNext = 0;
704 DenseMap<GlobalValue::GUID, unsigned> GUIDMap;
705 unsigned GUIDNext = 0;
713 explicit SlotTracker(const Module *M,
714 bool ShouldInitializeAllMetadata = false);
721 explicit SlotTracker(const Function *F,
722 bool ShouldInitializeAllMetadata = false);
725 explicit SlotTracker(const ModuleSummaryIndex *Index);
727 SlotTracker(const SlotTracker &) = delete;
728 SlotTracker &operator=(const SlotTracker &) = delete;
732 int getLocalSlot(const Value *V);
733 int getGlobalSlot(const GlobalValue *V);
734 int getMetadataSlot(const MDNode *N);
735 int getAttributeGroupSlot(AttributeSet AS);
736 int getModulePathSlot(StringRef Path);
737 int getGUIDSlot(GlobalValue::GUID GUID);
741 void incorporateFunction(const Function *F) {
743 FunctionProcessed = false;
746 const Function *getFunction() const { return TheFunction; }
751 void purgeFunction();
754 using mdn_iterator = DenseMap<const MDNode*, unsigned>::iterator;
756 mdn_iterator mdn_begin() { return mdnMap.begin(); }
757 mdn_iterator mdn_end() { return mdnMap.end(); }
758 unsigned mdn_size() const { return mdnMap.size(); }
759 bool mdn_empty() const { return mdnMap.empty(); }
762 using as_iterator = DenseMap<AttributeSet, unsigned>::iterator;
764 as_iterator as_begin() { return asMap.begin(); }
765 as_iterator as_end() { return asMap.end(); }
766 unsigned as_size() const { return asMap.size(); }
767 bool as_empty() const { return asMap.empty(); }
770 using guid_iterator = DenseMap<GlobalValue::GUID, unsigned>::iterator;
773 inline void initializeIfNeeded();
774 void initializeIndexIfNeeded();
776 // Implementation Details
779 void CreateModuleSlot(const GlobalValue *V);
782 void CreateMetadataSlot(const MDNode *N);
785 void CreateFunctionSlot(const Value *V);
788 void CreateAttributeSetSlot(AttributeSet AS);
790 inline void CreateModulePathSlot(StringRef Path);
791 void CreateGUIDSlot(GlobalValue::GUID GUID);
795 void processModule();
799 void processFunction();
802 void processGlobalObjectMetadata(const GlobalObject &GO);
805 void processFunctionMetadata(const Function &F);
808 void processInstructionMetadata(const Instruction &I);
811 } // end namespace llvm
813 ModuleSlotTracker::ModuleSlotTracker(SlotTracker &Machine, const Module *M,
815 : M(M), F(F), Machine(&Machine) {}
817 ModuleSlotTracker::ModuleSlotTracker(const Module *M,
818 bool ShouldInitializeAllMetadata)
819 : ShouldCreateStorage(M),
820 ShouldInitializeAllMetadata(ShouldInitializeAllMetadata), M(M) {}
822 ModuleSlotTracker::~ModuleSlotTracker() = default;
824 SlotTracker *ModuleSlotTracker::getMachine() {
825 if (!ShouldCreateStorage)
828 ShouldCreateStorage = false;
830 llvm::make_unique<SlotTracker>(M, ShouldInitializeAllMetadata);
831 Machine = MachineStorage.get();
835 void ModuleSlotTracker::incorporateFunction(const Function &F) {
836 // Using getMachine() may lazily create the slot tracker.
840 // Nothing to do if this is the right function already.
844 Machine->purgeFunction();
845 Machine->incorporateFunction(&F);
849 int ModuleSlotTracker::getLocalSlot(const Value *V) {
850 assert(F && "No function incorporated");
851 return Machine->getLocalSlot(V);
854 static SlotTracker *createSlotTracker(const Value *V) {
855 if (const Argument *FA = dyn_cast<Argument>(V))
856 return new SlotTracker(FA->getParent());
858 if (const Instruction *I = dyn_cast<Instruction>(V))
860 return new SlotTracker(I->getParent()->getParent());
862 if (const BasicBlock *BB = dyn_cast<BasicBlock>(V))
863 return new SlotTracker(BB->getParent());
865 if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(V))
866 return new SlotTracker(GV->getParent());
868 if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(V))
869 return new SlotTracker(GA->getParent());
871 if (const GlobalIFunc *GIF = dyn_cast<GlobalIFunc>(V))
872 return new SlotTracker(GIF->getParent());
874 if (const Function *Func = dyn_cast<Function>(V))
875 return new SlotTracker(Func);
881 #define ST_DEBUG(X) dbgs() << X
886 // Module level constructor. Causes the contents of the Module (sans functions)
887 // to be added to the slot table.
888 SlotTracker::SlotTracker(const Module *M, bool ShouldInitializeAllMetadata)
889 : TheModule(M), ShouldInitializeAllMetadata(ShouldInitializeAllMetadata) {}
891 // Function level constructor. Causes the contents of the Module and the one
892 // function provided to be added to the slot table.
893 SlotTracker::SlotTracker(const Function *F, bool ShouldInitializeAllMetadata)
894 : TheModule(F ? F->getParent() : nullptr), TheFunction(F),
895 ShouldInitializeAllMetadata(ShouldInitializeAllMetadata) {}
897 SlotTracker::SlotTracker(const ModuleSummaryIndex *Index)
898 : TheModule(nullptr), ShouldInitializeAllMetadata(false), TheIndex(Index) {}
900 inline void SlotTracker::initializeIfNeeded() {
903 TheModule = nullptr; ///< Prevent re-processing next time we're called.
906 if (TheFunction && !FunctionProcessed)
919 void SlotTracker::processModule() {
925 CreateModuleSlot(&Var);
926 processGlobalObjectMetadata(Var);
927 auto Attrs = Var.getAttributes();
928 if (
Attrs.hasAttributes())
929 CreateAttributeSetSlot(
Attrs);
932 for (
const GlobalAlias &A : TheModule->aliases()) {
934 CreateModuleSlot(&A);
939 CreateModuleSlot(&
I);
943 for (
const NamedMDNode &NMD : TheModule->named_metadata()) {
944 for (
unsigned i = 0, e = NMD.getNumOperands(); i != e; ++i)
945 CreateMetadataSlot(NMD.getOperand(i));
951 CreateModuleSlot(&
F);
953 if (ShouldInitializeAllMetadata)
954 processFunctionMetadata(
F);
960 CreateAttributeSetSlot(FnAttrs);
967 void SlotTracker::processFunction() {
968 ST_DEBUG(
"begin processFunction!\n");
972 if (!ShouldInitializeAllMetadata)
973 processFunctionMetadata(*TheFunction);
977 AE = TheFunction->arg_end(); AI != AE; ++AI)
979 CreateFunctionSlot(&*AI);
981 ST_DEBUG(
"Inserting Instructions:\n");
984 for (
auto &BB : *TheFunction) {
986 CreateFunctionSlot(&BB);
989 if (!
I.getType()->isVoidTy() && !
I.hasName())
990 CreateFunctionSlot(&
I);
998 CreateAttributeSetSlot(Attrs);
1003 FunctionProcessed =
true;
1005 ST_DEBUG(
"end processFunction!\n");
1009 void SlotTracker::processIndex() {
1016 std::map<uint64_t, StringRef> ModuleIdToPathMap;
1017 for (
auto &ModPath : TheIndex->modulePaths())
1018 ModuleIdToPathMap[ModPath.second.first] = ModPath.first();
1019 for (
auto &ModPair : ModuleIdToPathMap)
1020 CreateModulePathSlot(ModPair.second);
1023 GUIDNext = ModulePathNext;
1025 for (
auto &GlobalList : *TheIndex)
1026 CreateGUIDSlot(GlobalList.first);
1028 for (
auto &TId : TheIndex->typeIds())
1034 void SlotTracker::processGlobalObjectMetadata(
const GlobalObject &GO) {
1037 for (
auto &MD : MDs)
1038 CreateMetadataSlot(MD.second);
1041 void SlotTracker::processFunctionMetadata(
const Function &
F) {
1042 processGlobalObjectMetadata(F);
1043 for (
auto &BB : F) {
1045 processInstructionMetadata(
I);
1049 void SlotTracker::processInstructionMetadata(
const Instruction &
I) {
1051 if (
const CallInst *CI = dyn_cast<CallInst>(&I))
1052 if (
Function *F = CI->getCalledFunction())
1055 if (
auto *V = dyn_cast_or_null<MetadataAsValue>(
Op))
1056 if (
MDNode *
N = dyn_cast<MDNode>(V->getMetadata()))
1057 CreateMetadataSlot(
N);
1062 for (
auto &MD : MDs)
1063 CreateMetadataSlot(MD.second);
1070 ST_DEBUG(
"begin purgeFunction!\n");
1072 TheFunction =
nullptr;
1073 FunctionProcessed =
false;
1080 initializeIfNeeded();
1084 return MI == mMap.end() ? -1 : (int)MI->second;
1090 initializeIfNeeded();
1094 return MI == mdnMap.end() ? -1 : (int)MI->second;
1099 assert(!isa<Constant>(V) &&
"Can't get a constant or global slot with this!");
1102 initializeIfNeeded();
1105 return FI == fMap.end() ? -1 : (int)FI->second;
1110 initializeIfNeeded();
1114 return AI == asMap.end() ? -1 : (int)AI->second;
1119 initializeIndexIfNeeded();
1122 auto I = ModulePathMap.find(Path);
1123 return I == ModulePathMap.end() ? -1 : (int)I->second;
1128 initializeIndexIfNeeded();
1132 return I == GUIDMap.end() ? -1 : (int)I->second;
1136 void SlotTracker::CreateModuleSlot(
const GlobalValue *V) {
1137 assert(V &&
"Can't insert a null Value into SlotTracker!");
1141 unsigned DestSlot = mNext++;
1144 ST_DEBUG(
" Inserting value [" << V->
getType() <<
"] = " << V <<
" slot=" <<
1147 ST_DEBUG((isa<GlobalVariable>(V) ?
'G' :
1148 (isa<Function>(V) ?
'F' :
1149 (isa<GlobalAlias>(V) ?
'A' :
1150 (isa<GlobalIFunc>(V) ?
'I' :
'o')))) <<
"]\n");
1154 void SlotTracker::CreateFunctionSlot(
const Value *V) {
1157 unsigned DestSlot = fNext++;
1161 ST_DEBUG(
" Inserting value [" << V->
getType() <<
"] = " << V <<
" slot=" <<
1162 DestSlot <<
" [o]\n");
1166 void SlotTracker::CreateMetadataSlot(
const MDNode *
N) {
1167 assert(N &&
"Can't insert a null Value into SlotTracker!");
1170 if (isa<DIExpression>(N))
1173 unsigned DestSlot = mdnNext;
1174 if (!mdnMap.insert(std::make_pair(N, DestSlot)).second)
1181 CreateMetadataSlot(
Op);
1187 as_iterator I = asMap.find(AS);
1188 if (I != asMap.end())
1191 unsigned DestSlot = asNext++;
1192 asMap[
AS] = DestSlot;
1196 void SlotTracker::CreateModulePathSlot(
StringRef Path) {
1197 ModulePathMap[Path] = ModulePathNext++;
1202 GUIDMap[GUID] = GUIDNext++;
1210 TypePrinting *TypePrinter,
1215 TypePrinting *TypePrinter,
1217 bool FromValue =
false);
1222 default: Out <<
" <unknown operation " << Op <<
">";
break;
1238 if (
const FPMathOperator *FPO = dyn_cast<const FPMathOperator>(U)) {
1243 if (FPO->hasAllowReassoc())
1245 if (FPO->hasNoNaNs())
1247 if (FPO->hasNoInfs())
1249 if (FPO->hasNoSignedZeros())
1251 if (FPO->hasAllowReciprocal())
1253 if (FPO->hasAllowContract())
1255 if (FPO->hasApproxFunc())
1261 dyn_cast<OverflowingBinaryOperator>(U)) {
1262 if (OBO->hasNoUnsignedWrap())
1264 if (OBO->hasNoSignedWrap())
1267 dyn_cast<PossiblyExactOperator>(U)) {
1271 if (
GEP->isInBounds())
1277 TypePrinting &TypePrinter,
1280 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
1281 if (CI->getType()->isIntegerTy(1)) {
1282 Out << (CI->getZExtValue() ?
"true" :
"false");
1285 Out << CI->getValue();
1289 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
1290 const APFloat &APF = CFP->getValueAPF();
1301 bool isNaN = APF.
isNaN();
1302 if (!isInf && !isNaN) {
1310 assert(((StrVal[0] >=
'0' && StrVal[0] <=
'9') ||
1311 ((StrVal[0] ==
'-' || StrVal[0] ==
'+') &&
1312 (StrVal[1] >=
'0' && StrVal[1] <=
'9'))) &&
1313 "[-+]?[0-9] regex does not match!");
1324 static_assert(
sizeof(
double) ==
sizeof(uint64_t),
1325 "assuming that double is 64 bits!");
1368 if (isa<ConstantAggregateZero>(CV)) {
1369 Out <<
"zeroinitializer";
1373 if (
const BlockAddress *BA = dyn_cast<BlockAddress>(CV)) {
1374 Out <<
"blockaddress(";
1384 if (
const ConstantArray *CA = dyn_cast<ConstantArray>(CV)) {
1385 Type *ETy = CA->getType()->getElementType();
1387 TypePrinter.print(ETy, Out);
1392 for (
unsigned i = 1, e = CA->getNumOperands(); i != e; ++i) {
1394 TypePrinter.print(ETy, Out);
1406 if (CA->isString()) {
1413 Type *ETy = CA->getType()->getElementType();
1415 TypePrinter.print(ETy, Out);
1420 for (
unsigned i = 1, e = CA->getNumElements(); i != e; ++i) {
1422 TypePrinter.print(ETy, Out);
1432 if (CS->getType()->isPacked())
1438 TypePrinter.print(CS->getOperand(0)->getType(), Out);
1444 for (
unsigned i = 1; i <
N; i++) {
1446 TypePrinter.print(CS->getOperand(i)->getType(), Out);
1456 if (CS->getType()->isPacked())
1461 if (isa<ConstantVector>(CV) || isa<ConstantDataVector>(CV)) {
1464 TypePrinter.print(ETy, Out);
1470 TypePrinter.print(ETy, Out);
1479 if (isa<ConstantPointerNull>(CV)) { 1484 if (isa<ConstantTokenNone>(CV)) { 1489 if (isa<UndefValue>(CV)) { 1494 if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) { 1495 Out << CE->getOpcodeName(); 1496 WriteOptimizationInfo(Out, CE); 1497 if (CE->isCompare()) 1498 Out << ' ' << CmpInst::getPredicateName( 1499 static_cast<CmpInst::Predicate>(CE->getPredicate())); 1502 Optional<unsigned> InRangeOp; 1503 if (const GEPOperator *GEP = dyn_cast<GEPOperator>(CE)) { 1504 TypePrinter.print(GEP->getSourceElementType(), Out); 1506 InRangeOp = GEP->getInRangeIndex(); 1511 for (User::const_op_iterator OI=CE->op_begin(); OI != CE->op_end(); ++OI) { 1512 if (InRangeOp && unsigned(OI - CE->op_begin()) == *InRangeOp) 1514 TypePrinter.print((*OI)->getType(), Out); 1516 WriteAsOperandInternal(Out, *OI, &TypePrinter, Machine, Context); 1517 if (OI+1 != CE->op_end()) 1521 if (CE->hasIndices()) { 1522 ArrayRef<unsigned> Indices = CE->getIndices(); 1523 for (unsigned i = 0, e = Indices.size(); i != e; ++i) 1524 Out << ", " << Indices[i]; 1529 TypePrinter.print(CE->getType(), Out); 1536 Out << "<placeholder or erroneous Constant>"; 1539 static void writeMDTuple(raw_ostream &Out, const MDTuple *Node, 1540 TypePrinting *TypePrinter, SlotTracker *Machine, 1541 const Module *Context) { 1543 for (unsigned mi = 0, me = Node->getNumOperands(); mi != me; ++mi) { 1544 const Metadata *MD = Node->getOperand(mi); 1547 else if (auto *MDV = dyn_cast<ValueAsMetadata>(MD)) { 1548 Value *V = MDV->getValue(); 1549 TypePrinter->print(V->getType(), Out); 1551 WriteAsOperandInternal(Out, V, TypePrinter, Machine, Context); 1553 WriteAsOperandInternal(Out, MD, TypePrinter, Machine, Context); 1564 struct FieldSeparator { 1568 FieldSeparator(const char *Sep = ", ") : Sep(Sep) {} 1571 raw_ostream &operator<<(raw_ostream &OS, FieldSeparator &FS) { 1576 return OS << FS.Sep; 1579 struct MDFieldPrinter { 1582 TypePrinting *TypePrinter = nullptr; 1583 SlotTracker *Machine = nullptr; 1584 const Module *Context = nullptr; 1586 explicit MDFieldPrinter(raw_ostream &Out) : Out(Out) {} 1587 MDFieldPrinter(raw_ostream &Out, TypePrinting *TypePrinter, 1588 SlotTracker *Machine, const Module *Context) 1589 : Out(Out), TypePrinter(TypePrinter), Machine(Machine), Context(Context) { 1592 void printTag(const DINode *N); 1593 void printMacinfoType(const DIMacroNode *N); 1594 void printChecksum(const DIFile::ChecksumInfo<StringRef> &N); 1595 void printString(StringRef Name, StringRef Value, 1596 bool ShouldSkipEmpty = true); 1597 void printMetadata(StringRef Name, const Metadata *MD, 1598 bool ShouldSkipNull = true); 1599 template <class IntTy> 1600 void printInt(StringRef Name, IntTy Int, bool ShouldSkipZero = true); 1601 void printBool(StringRef Name, bool Value, Optional<bool> Default = None); 1602 void printDIFlags(StringRef Name, DINode::DIFlags Flags); 1603 template <class IntTy, class Stringifier> 1604 void printDwarfEnum(StringRef Name, IntTy Value, Stringifier toString, 1605 bool ShouldSkipZero = true); 1606 void printEmissionKind(StringRef Name, DICompileUnit::DebugEmissionKind EK); 1609 } // end anonymous namespace 1611 void MDFieldPrinter::printTag(const DINode *N) { 1612 Out << FS << "tag: "; 1613 auto Tag = dwarf::TagString(N->getTag()); 1620 void MDFieldPrinter::printMacinfoType(const DIMacroNode *N) { 1621 Out << FS << "type: "; 1622 auto Type = dwarf::MacinfoString(N->getMacinfoType()); 1626 Out << N->getMacinfoType(); 1629 void MDFieldPrinter::printChecksum( 1630 const DIFile::ChecksumInfo<StringRef> &Checksum) { 1631 Out << FS << "checksumkind: " << Checksum.getKindAsString(); 1632 printString("checksum", Checksum.Value, /* ShouldSkipEmpty */ false); 1635 void MDFieldPrinter::printString(StringRef Name, StringRef Value, 1636 bool ShouldSkipEmpty) { 1637 if (ShouldSkipEmpty && Value.empty()) 1640 Out << FS << Name << ": \""; 1641 printEscapedString(Value, Out); 1645 static void writeMetadataAsOperand(raw_ostream &Out, const Metadata *MD, 1646 TypePrinting *TypePrinter, 1647 SlotTracker *Machine, 1648 const Module *Context) { 1653 WriteAsOperandInternal(Out, MD, TypePrinter, Machine, Context); 1656 void MDFieldPrinter::printMetadata(StringRef Name, const Metadata *MD, 1657 bool ShouldSkipNull) { 1658 if (ShouldSkipNull && !MD) 1661 Out << FS << Name << ": "; 1662 writeMetadataAsOperand(Out, MD, TypePrinter, Machine, Context); 1665 template <class IntTy> 1666 void MDFieldPrinter::printInt(StringRef Name, IntTy Int, bool ShouldSkipZero) { 1667 if (ShouldSkipZero && !Int) 1670 Out << FS << Name << ": " << Int; 1673 void MDFieldPrinter::printBool(StringRef Name, bool Value, 1674 Optional<bool> Default) { 1675 if (Default && Value == *Default) 1677 Out << FS << Name << ": " << (Value ? "true" : "false"); 1680 void MDFieldPrinter::printDIFlags(StringRef Name, DINode::DIFlags Flags) { 1684 Out << FS << Name << ": "; 1686 SmallVector<DINode::DIFlags, 8> SplitFlags; 1687 auto Extra = DINode::splitFlags(Flags, SplitFlags); 1689 FieldSeparator FlagsFS(" | "); 1690 for (auto F : SplitFlags) { 1691 auto StringF = DINode::getFlagString(F); 1692 assert(!StringF.empty() && "Expected valid flag"); 1693 Out << FlagsFS << StringF; 1695 if (Extra || SplitFlags.empty()) 1696 Out << FlagsFS << Extra; 1699 void MDFieldPrinter::printEmissionKind(StringRef Name, 1700 DICompileUnit::DebugEmissionKind EK) { 1701 Out << FS << Name << ": " << DICompileUnit::emissionKindString(EK); 1704 template <class IntTy, class Stringifier> 1705 void MDFieldPrinter::printDwarfEnum(StringRef Name, IntTy Value, 1706 Stringifier toString, bool ShouldSkipZero) { 1710 Out << FS << Name << ": "; 1711 auto S = toString(Value); 1718 static void writeGenericDINode(raw_ostream &Out, const GenericDINode *N, 1719 TypePrinting *TypePrinter, SlotTracker *Machine, 1720 const Module *Context) { 1721 Out << "!GenericDINode("; 1722 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 1723 Printer.printTag(N); 1724 Printer.printString("header", N->getHeader()); 1725 if (N->getNumDwarfOperands()) { 1726 Out << Printer.FS << "operands: {"; 1728 for (auto &I : N->dwarf_operands()) { 1730 writeMetadataAsOperand(Out, I, TypePrinter, Machine, Context); 1737 static void writeDILocation(raw_ostream &Out, const DILocation *DL, 1738 TypePrinting *TypePrinter, SlotTracker *Machine, 1739 const Module *Context) { 1740 Out << "!DILocation("; 1741 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 1742 // Always output the line, since 0 is a relevant and important value for it. 1743 Printer.printInt("line", DL->getLine(), /* ShouldSkipZero */ false); 1744 Printer.printInt("column", DL->getColumn()); 1745 Printer.printMetadata("scope", DL->getRawScope(), /* ShouldSkipNull */ false); 1746 Printer.printMetadata("inlinedAt", DL->getRawInlinedAt()); 1750 static void writeDISubrange(raw_ostream &Out, const DISubrange *N, 1751 TypePrinting *TypePrinter, SlotTracker *Machine, 1752 const Module *Context) { 1753 Out << "!DISubrange("; 1754 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 1755 if (auto *CE = N->getCount().dyn_cast<ConstantInt*>()) 1756 Printer.printInt("count", CE->getSExtValue(), /* ShouldSkipZero */ false); 1758 Printer.printMetadata("count", N->getCount().dyn_cast<DIVariable*>(), 1759 /*ShouldSkipNull */ false); 1760 Printer.printInt("lowerBound", N->getLowerBound()); 1764 static void writeDIEnumerator(raw_ostream &Out, const DIEnumerator *N, 1765 TypePrinting *, SlotTracker *, const Module *) { 1766 Out << "!DIEnumerator("; 1767 MDFieldPrinter Printer(Out); 1768 Printer.printString("name", N->getName(), /* ShouldSkipEmpty */ false); 1769 if (N->isUnsigned()) { 1770 auto Value = static_cast<uint64_t>(N->getValue()); 1771 Printer.printInt("value", Value, /* ShouldSkipZero */ false); 1772 Printer.printBool("isUnsigned", true); 1774 Printer.printInt("value", N->getValue(), /* ShouldSkipZero */ false); 1779 static void writeDIBasicType(raw_ostream &Out, const DIBasicType *N, 1780 TypePrinting *, SlotTracker *, const Module *) { 1781 Out << "!DIBasicType("; 1782 MDFieldPrinter Printer(Out); 1783 if (N->getTag() != dwarf::DW_TAG_base_type) 1784 Printer.printTag(N); 1785 Printer.printString("name", N->getName()); 1786 Printer.printInt("size", N->getSizeInBits()); 1787 Printer.printInt("align", N->getAlignInBits()); 1788 Printer.printDwarfEnum("encoding", N->getEncoding(), 1789 dwarf::AttributeEncodingString); 1793 static void writeDIDerivedType(raw_ostream &Out, const DIDerivedType *N, 1794 TypePrinting *TypePrinter, SlotTracker *Machine, 1795 const Module *Context) { 1796 Out << "!DIDerivedType("; 1797 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 1798 Printer.printTag(N); 1799 Printer.printString("name", N->getName()); 1800 Printer.printMetadata("scope", N->getRawScope()); 1801 Printer.printMetadata("file", N->getRawFile()); 1802 Printer.printInt("line", N->getLine()); 1803 Printer.printMetadata("baseType", N->getRawBaseType(), 1804 /* ShouldSkipNull */ false); 1805 Printer.printInt("size", N->getSizeInBits()); 1806 Printer.printInt("align", N->getAlignInBits()); 1807 Printer.printInt("offset", N->getOffsetInBits()); 1808 Printer.printDIFlags("flags", N->getFlags()); 1809 Printer.printMetadata("extraData", N->getRawExtraData()); 1810 if (const auto &DWARFAddressSpace = N->getDWARFAddressSpace()) 1811 Printer.printInt("dwarfAddressSpace", *DWARFAddressSpace, 1812 /* ShouldSkipZero */ false); 1816 static void writeDICompositeType(raw_ostream &Out, const DICompositeType *N, 1817 TypePrinting *TypePrinter, 1818 SlotTracker *Machine, const Module *Context) { 1819 Out << "!DICompositeType("; 1820 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 1821 Printer.printTag(N); 1822 Printer.printString("name", N->getName()); 1823 Printer.printMetadata("scope", N->getRawScope()); 1824 Printer.printMetadata("file", N->getRawFile()); 1825 Printer.printInt("line", N->getLine()); 1826 Printer.printMetadata("baseType", N->getRawBaseType()); 1827 Printer.printInt("size", N->getSizeInBits()); 1828 Printer.printInt("align", N->getAlignInBits()); 1829 Printer.printInt("offset", N->getOffsetInBits()); 1830 Printer.printDIFlags("flags", N->getFlags()); 1831 Printer.printMetadata("elements", N->getRawElements()); 1832 Printer.printDwarfEnum("runtimeLang", N->getRuntimeLang(), 1833 dwarf::LanguageString); 1834 Printer.printMetadata("vtableHolder", N->getRawVTableHolder()); 1835 Printer.printMetadata("templateParams", N->getRawTemplateParams()); 1836 Printer.printString("identifier", N->getIdentifier()); 1837 Printer.printMetadata("discriminator", N->getRawDiscriminator()); 1841 static void writeDISubroutineType(raw_ostream &Out, const DISubroutineType *N, 1842 TypePrinting *TypePrinter, 1843 SlotTracker *Machine, const Module *Context) { 1844 Out << "!DISubroutineType("; 1845 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 1846 Printer.printDIFlags("flags", N->getFlags()); 1847 Printer.printDwarfEnum("cc", N->getCC(), dwarf::ConventionString); 1848 Printer.printMetadata("types", N->getRawTypeArray(), 1849 /* ShouldSkipNull */ false); 1853 static void writeDIFile(raw_ostream &Out, const DIFile *N, TypePrinting *, 1854 SlotTracker *, const Module *) { 1856 MDFieldPrinter Printer(Out); 1857 Printer.printString("filename", N->getFilename(), 1858 /* ShouldSkipEmpty */ false); 1859 Printer.printString("directory", N->getDirectory(), 1860 /* ShouldSkipEmpty */ false); 1861 // Print all values for checksum together, or not at all. 1862 if (N->getChecksum()) 1863 Printer.printChecksum(*N->getChecksum()); 1864 Printer.printString("source", N->getSource().getValueOr(StringRef()), 1865 /* ShouldSkipEmpty */ true); 1869 static void writeDICompileUnit(raw_ostream &Out, const DICompileUnit *N, 1870 TypePrinting *TypePrinter, SlotTracker *Machine, 1871 const Module *Context) { 1872 Out << "!DICompileUnit("; 1873 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 1874 Printer.printDwarfEnum("language", N->getSourceLanguage(), 1875 dwarf::LanguageString, /* ShouldSkipZero */ false); 1876 Printer.printMetadata("file", N->getRawFile(), /* ShouldSkipNull */ false); 1877 Printer.printString("producer", N->getProducer()); 1878 Printer.printBool("isOptimized", N->isOptimized()); 1879 Printer.printString("flags", N->getFlags()); 1880 Printer.printInt("runtimeVersion", N->getRuntimeVersion(), 1881 /* ShouldSkipZero */ false); 1882 Printer.printString("splitDebugFilename", N->getSplitDebugFilename()); 1883 Printer.printEmissionKind("emissionKind", N->getEmissionKind()); 1884 Printer.printMetadata("enums", N->getRawEnumTypes()); 1885 Printer.printMetadata("retainedTypes", N->getRawRetainedTypes()); 1886 Printer.printMetadata("globals", N->getRawGlobalVariables()); 1887 Printer.printMetadata("imports", N->getRawImportedEntities()); 1888 Printer.printMetadata("macros", N->getRawMacros()); 1889 Printer.printInt("dwoId", N->getDWOId()); 1890 Printer.printBool("splitDebugInlining", N->getSplitDebugInlining(), true); 1891 Printer.printBool("debugInfoForProfiling", N->getDebugInfoForProfiling(), 1893 Printer.printBool("gnuPubnames", N->getGnuPubnames(), false); 1897 static void writeDISubprogram(raw_ostream &Out, const DISubprogram *N, 1898 TypePrinting *TypePrinter, SlotTracker *Machine, 1899 const Module *Context) { 1900 Out << "!DISubprogram("; 1901 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 1902 Printer.printString("name", N->getName()); 1903 Printer.printString("linkageName", N->getLinkageName()); 1904 Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false); 1905 Printer.printMetadata("file", N->getRawFile()); 1906 Printer.printInt("line", N->getLine()); 1907 Printer.printMetadata("type", N->getRawType()); 1908 Printer.printBool("isLocal", N->isLocalToUnit()); 1909 Printer.printBool("isDefinition", N->isDefinition()); 1910 Printer.printInt("scopeLine", N->getScopeLine()); 1911 Printer.printMetadata("containingType", N->getRawContainingType()); 1912 Printer.printDwarfEnum("virtuality", N->getVirtuality(), 1913 dwarf::VirtualityString); 1914 if (N->getVirtuality() != dwarf::DW_VIRTUALITY_none || 1915 N->getVirtualIndex() != 0) 1916 Printer.printInt("virtualIndex", N->getVirtualIndex(), false); 1917 Printer.printInt("thisAdjustment", N->getThisAdjustment()); 1918 Printer.printDIFlags("flags", N->getFlags()); 1919 Printer.printBool("isOptimized", N->isOptimized()); 1920 Printer.printMetadata("unit", N->getRawUnit()); 1921 Printer.printMetadata("templateParams", N->getRawTemplateParams()); 1922 Printer.printMetadata("declaration", N->getRawDeclaration()); 1923 Printer.printMetadata("retainedNodes", N->getRawRetainedNodes()); 1924 Printer.printMetadata("thrownTypes", N->getRawThrownTypes()); 1928 static void writeDILexicalBlock(raw_ostream &Out, const DILexicalBlock *N, 1929 TypePrinting *TypePrinter, SlotTracker *Machine, 1930 const Module *Context) { 1931 Out << "!DILexicalBlock("; 1932 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 1933 Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false); 1934 Printer.printMetadata("file", N->getRawFile()); 1935 Printer.printInt("line", N->getLine()); 1936 Printer.printInt("column", N->getColumn()); 1940 static void writeDILexicalBlockFile(raw_ostream &Out, 1941 const DILexicalBlockFile *N, 1942 TypePrinting *TypePrinter, 1943 SlotTracker *Machine, 1944 const Module *Context) { 1945 Out << "!DILexicalBlockFile("; 1946 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 1947 Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false); 1948 Printer.printMetadata("file", N->getRawFile()); 1949 Printer.printInt("discriminator", N->getDiscriminator(), 1950 /* ShouldSkipZero */ false); 1954 static void writeDINamespace(raw_ostream &Out, const DINamespace *N, 1955 TypePrinting *TypePrinter, SlotTracker *Machine, 1956 const Module *Context) { 1957 Out << "!DINamespace("; 1958 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 1959 Printer.printString("name", N->getName()); 1960 Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false); 1961 Printer.printBool("exportSymbols", N->getExportSymbols(), false); 1965 static void writeDIMacro(raw_ostream &Out, const DIMacro *N, 1966 TypePrinting *TypePrinter, SlotTracker *Machine, 1967 const Module *Context) { 1969 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 1970 Printer.printMacinfoType(N); 1971 Printer.printInt("line", N->getLine()); 1972 Printer.printString("name", N->getName()); 1973 Printer.printString("value", N->getValue()); 1977 static void writeDIMacroFile(raw_ostream &Out, const DIMacroFile *N, 1978 TypePrinting *TypePrinter, SlotTracker *Machine, 1979 const Module *Context) { 1980 Out << "!DIMacroFile("; 1981 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 1982 Printer.printInt("line", N->getLine()); 1983 Printer.printMetadata("file", N->getRawFile(), /* ShouldSkipNull */ false); 1984 Printer.printMetadata("nodes", N->getRawElements()); 1988 static void writeDIModule(raw_ostream &Out, const DIModule *N, 1989 TypePrinting *TypePrinter, SlotTracker *Machine, 1990 const Module *Context) { 1991 Out << "!DIModule("; 1992 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 1993 Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false); 1994 Printer.printString("name", N->getName()); 1995 Printer.printString("configMacros", N->getConfigurationMacros()); 1996 Printer.printString("includePath", N->getIncludePath()); 1997 Printer.printString("isysroot", N->getISysRoot()); 2002 static void writeDITemplateTypeParameter(raw_ostream &Out, 2003 const DITemplateTypeParameter *N, 2004 TypePrinting *TypePrinter, 2005 SlotTracker *Machine, 2006 const Module *Context) { 2007 Out << "!DITemplateTypeParameter("; 2008 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 2009 Printer.printString("name", N->getName()); 2010 Printer.printMetadata("type", N->getRawType(), /* ShouldSkipNull */ false); 2014 static void writeDITemplateValueParameter(raw_ostream &Out, 2015 const DITemplateValueParameter *N, 2016 TypePrinting *TypePrinter, 2017 SlotTracker *Machine, 2018 const Module *Context) { 2019 Out << "!DITemplateValueParameter("; 2020 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 2021 if (N->getTag() != dwarf::DW_TAG_template_value_parameter) 2022 Printer.printTag(N); 2023 Printer.printString("name", N->getName()); 2024 Printer.printMetadata("type", N->getRawType()); 2025 Printer.printMetadata("value", N->getValue(), /* ShouldSkipNull */ false); 2029 static void writeDIGlobalVariable(raw_ostream &Out, const DIGlobalVariable *N, 2030 TypePrinting *TypePrinter, 2031 SlotTracker *Machine, const Module *Context) { 2032 Out << "!DIGlobalVariable("; 2033 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 2034 Printer.printString("name", N->getName()); 2035 Printer.printString("linkageName", N->getLinkageName()); 2036 Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false); 2037 Printer.printMetadata("file", N->getRawFile()); 2038 Printer.printInt("line", N->getLine()); 2039 Printer.printMetadata("type", N->getRawType()); 2040 Printer.printBool("isLocal", N->isLocalToUnit()); 2041 Printer.printBool("isDefinition", N->isDefinition()); 2042 Printer.printMetadata("declaration", N->getRawStaticDataMemberDeclaration()); 2043 Printer.printInt("align", N->getAlignInBits()); 2047 static void writeDILocalVariable(raw_ostream &Out, const DILocalVariable *N, 2048 TypePrinting *TypePrinter, 2049 SlotTracker *Machine, const Module *Context) { 2050 Out << "!DILocalVariable("; 2051 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 2052 Printer.printString("name", N->getName()); 2053 Printer.printInt("arg", N->getArg()); 2054 Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false); 2055 Printer.printMetadata("file", N->getRawFile()); 2056 Printer.printInt("line", N->getLine()); 2057 Printer.printMetadata("type", N->getRawType()); 2058 Printer.printDIFlags("flags", N->getFlags()); 2059 Printer.printInt("align", N->getAlignInBits()); 2063 static void writeDILabel(raw_ostream &Out, const DILabel *N, 2064 TypePrinting *TypePrinter, 2065 SlotTracker *Machine, const Module *Context) { 2067 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 2068 Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false); 2069 Printer.printString("name", N->getName()); 2070 Printer.printMetadata("file", N->getRawFile()); 2071 Printer.printInt("line", N->getLine()); 2075 static void writeDIExpression(raw_ostream &Out, const DIExpression *N, 2076 TypePrinting *TypePrinter, SlotTracker *Machine, 2077 const Module *Context) { 2078 Out << "!DIExpression("; 2081 for (auto I = N->expr_op_begin(), E = N->expr_op_end(); I != E; ++I) { 2082 auto OpStr = dwarf::OperationEncodingString(I->getOp()); 2083 assert(!OpStr.empty() && "Expected valid opcode"); 2086 for (unsigned A = 0, AE = I->getNumArgs(); A != AE; ++A) 2087 Out << FS << I->getArg(A); 2090 for (const auto &I : N->getElements()) 2096 static void writeDIGlobalVariableExpression(raw_ostream &Out, 2097 const DIGlobalVariableExpression *N, 2098 TypePrinting *TypePrinter, 2099 SlotTracker *Machine, 2100 const Module *Context) { 2101 Out << "!DIGlobalVariableExpression("; 2102 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 2103 Printer.printMetadata("var", N->getVariable()); 2104 Printer.printMetadata("expr", N->getExpression()); 2108 static void writeDIObjCProperty(raw_ostream &Out, const DIObjCProperty *N, 2109 TypePrinting *TypePrinter, SlotTracker *Machine, 2110 const Module *Context) { 2111 Out << "!DIObjCProperty("; 2112 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 2113 Printer.printString("name", N->getName()); 2114 Printer.printMetadata("file", N->getRawFile()); 2115 Printer.printInt("line", N->getLine()); 2116 Printer.printString("setter", N->getSetterName()); 2117 Printer.printString("getter", N->getGetterName()); 2118 Printer.printInt("attributes", N->getAttributes()); 2119 Printer.printMetadata("type", N->getRawType()); 2123 static void writeDIImportedEntity(raw_ostream &Out, const DIImportedEntity *N, 2124 TypePrinting *TypePrinter, 2125 SlotTracker *Machine, const Module *Context) { 2126 Out << "!DIImportedEntity("; 2127 MDFieldPrinter Printer(Out, TypePrinter, Machine, Context); 2128 Printer.printTag(N); 2129 Printer.printString("name", N->getName()); 2130 Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false); 2131 Printer.printMetadata("entity", N->getRawEntity()); 2132 Printer.printMetadata("file", N->getRawFile()); 2133 Printer.printInt("line", N->getLine()); 2137 static void WriteMDNodeBodyInternal(raw_ostream &Out, const MDNode *Node, 2138 TypePrinting *TypePrinter, 2139 SlotTracker *Machine, 2140 const Module *Context) { 2141 if (Node->isDistinct()) 2143 else if (Node->isTemporary()) 2144 Out << "<temporary!> "; // Handle broken code. 2146 switch (Node->getMetadataID()) { 2148 llvm_unreachable("Expected uniquable MDNode"); 2149 #define HANDLE_MDNODE_LEAF(CLASS) \ 2150 case Metadata::CLASS##Kind: \ 2151 write##CLASS(Out, cast<CLASS>(Node), TypePrinter, Machine, Context); \ 2153 #include "llvm/IR/Metadata.def" 2157 // Full implementation of printing a Value as an operand with support for 2158 // TypePrinting, etc. 2159 static void WriteAsOperandInternal(raw_ostream &Out, const Value *V, 2160 TypePrinting *TypePrinter, 2161 SlotTracker *Machine, 2162 const Module *Context) { 2164 PrintLLVMName(Out, V); 2168 const Constant *CV = dyn_cast<Constant>(V); 2169 if (CV && !isa<GlobalValue>(CV)) { 2170 assert(TypePrinter && "Constants require TypePrinting!"); 2171 WriteConstantInternal(Out, CV, *TypePrinter, Machine, Context); 2175 if (const InlineAsm *IA = dyn_cast<InlineAsm>(V)) { 2177 if (IA->hasSideEffects()) 2178 Out << "sideeffect "; 2179 if (IA->isAlignStack()) 2180 Out << "alignstack "; 2181 // We don't emit the AD_ATT dialect as it
's the assumed default. 2182 if (IA->getDialect() == InlineAsm::AD_Intel) 2183 Out << "inteldialect "; 2185 printEscapedString(IA->getAsmString(), Out); 2192 if (
auto *MD = dyn_cast<MetadataAsValue>(V)) {
2202 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
2203 Slot = Machine->getGlobalSlot(GV);
2206 Slot = Machine->getLocalSlot(V);
2213 Slot = Machine->getLocalSlot(V);
2219 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
2220 Slot = Machine->getGlobalSlot(GV);
2223 Slot = Machine->getLocalSlot(V);
2232 Out << Prefix << Slot;
2238 TypePrinting *TypePrinter,
2243 if (
const DIExpression *Expr = dyn_cast<DIExpression>(MD)) {
2248 if (
const MDNode *N = dyn_cast<MDNode>(MD)) {
2249 std::unique_ptr<SlotTracker> MachineStorage;
2251 MachineStorage = make_unique<SlotTracker>(
Context);
2252 Machine = MachineStorage.get();
2258 Out <<
"<" << N <<
">";
2264 if (
const MDString *MDS = dyn_cast<MDString>(MD)) {
2271 auto *V = cast<ValueAsMetadata>(MD);
2272 assert(TypePrinter &&
"TypePrinter required for metadata values");
2273 assert((FromValue || !isa<LocalAsMetadata>(V)) &&
2274 "Unexpected function-local metadata outside of value argument");
2276 TypePrinter->print(V->getValue()->
getType(), Out);
2283 class AssemblyWriter {
2285 const Module *TheModule =
nullptr;
2287 std::unique_ptr<SlotTracker> SlotTrackerStorage;
2289 TypePrinting TypePrinter;
2293 bool ShouldPreserveUseListOrder;
2304 bool ShouldPreserveUseListOrder =
false);
2309 void printMDNodeBody(
const MDNode *MD);
2312 void printModule(
const Module *M);
2314 void writeOperand(
const Value *
Op,
bool PrintType);
2322 void writeAtomicCmpXchg(
const LLVMContext &Context,
2327 void writeAllMDNodes();
2328 void writeMDNode(
unsigned Slot,
const MDNode *Node);
2329 void writeAllAttributeGroups();
2331 void printTypeIdentities();
2334 void printComdat(
const Comdat *
C);
2335 void printFunction(
const Function *F);
2342 void printUseLists(
const Function *F);
2344 void printModuleSummaryIndex();
2345 void printSummaryInfo(
unsigned Slot,
const ValueInfo &
VI);
2352 void printArgs(
const std::vector<uint64_t> &
Args);
2357 printNonConstVCalls(
const std::vector<FunctionSummary::VFuncId> VCallList,
2360 printConstVCalls(
const std::vector<FunctionSummary::ConstVCall> VCallList,
2365 void printMetadataAttachments(
2371 void printInfoComment(
const Value &V);
2382 bool IsForDebug,
bool ShouldPreserveUseListOrder)
2383 : Out(o), TheModule(M),
Machine(Mac), TypePrinter(M), AnnotationWriter(AAW),
2384 IsForDebug(IsForDebug),
2385 ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) {
2388 for (
const GlobalObject &GO : TheModule->global_objects())
2395 : Out(o), TheIndex(Index),
Machine(Mac), TypePrinter(
nullptr),
2396 IsForDebug(IsForDebug), ShouldPreserveUseListOrder(
false) {}
2398 void AssemblyWriter::writeOperand(
const Value *Operand,
bool PrintType) {
2400 Out <<
"<null operand!>";
2404 TypePrinter.print(Operand->
getType(), Out);
2410 void AssemblyWriter::writeSyncScope(
const LLVMContext &Context,
2420 Out <<
" syncscope(\"";
2428 void AssemblyWriter::writeAtomic(
const LLVMContext &Context,
2434 writeSyncScope(Context, SSID);
2438 void AssemblyWriter::writeAtomicCmpXchg(
const LLVMContext &Context,
2445 writeSyncScope(Context, SSID);
2450 void AssemblyWriter::writeParamOperand(
const Value *Operand,
2453 Out <<
"<null operand!>";
2458 TypePrinter.print(Operand->
getType(), Out);
2473 bool FirstBundle =
true;
2479 FirstBundle =
false;
2487 bool FirstInput =
true;
2488 for (
const auto &Input : BU.
Inputs) {
2493 TypePrinter.print(Input->getType(), Out);
2504 void AssemblyWriter::printModule(
const Module *M) {
2505 Machine.initializeIfNeeded();
2507 if (ShouldPreserveUseListOrder)
2517 Out <<
"source_filename = \"";
2524 Out <<
"target datalayout = \"" << DL <<
"\"\n";
2535 std::tie(Front, Asm) = Asm.
split(
'\n');
2539 Out <<
"module asm \"";
2542 }
while (!Asm.
empty());
2545 printTypeIdentities();
2548 if (!Comdats.empty())
2550 for (
const Comdat *
C : Comdats) {
2552 if (
C != Comdats.back())
2559 printGlobal(&GV); Out <<
'\n';
2565 printIndirectSymbol(&GA);
2570 printIndirectSymbol(&GI);
2573 printUseLists(
nullptr);
2578 assert(UseListOrders.empty() &&
"All use-lists should have been consumed");
2581 if (!Machine.as_empty()) {
2583 writeAllAttributeGroups();
2587 if (!M->named_metadata_empty()) Out <<
'\n';
2589 for (
const NamedMDNode &Node : M->named_metadata())
2590 printNamedMDNode(&Node);
2593 if (!Machine.mdn_empty()) {
2599 void AssemblyWriter::printModuleSummaryIndex() {
2601 Machine.initializeIndexIfNeeded();
2607 std::vector<std::pair<std::string, ModuleHash>> moduleVec;
2608 std::string RegularLTOModuleName =
"[Regular LTO]";
2609 moduleVec.resize(TheIndex->modulePaths().size());
2610 for (
auto &ModPath : TheIndex->modulePaths())
2611 moduleVec[Machine.getModulePathSlot(ModPath.first())] = std::make_pair(
2614 ModPath.second.first == -1u ? RegularLTOModuleName
2615 : (std::string)ModPath.first(),
2616 ModPath.second.second);
2619 for (
auto &ModPair : moduleVec) {
2620 Out <<
"^" << i++ <<
" = module: (";
2623 Out <<
"\", hash: (";
2625 for (
auto Hash : ModPair.second)
2632 for (
auto &GlobalList : *TheIndex) {
2633 auto GUID = GlobalList.first;
2634 for (
auto &Summary : GlobalList.second.SummaryList)
2635 SummaryToGUIDMap[Summary.get()] = GUID;
2639 for (
auto &GlobalList : *TheIndex) {
2640 auto GUID = GlobalList.first;
2641 auto VI = TheIndex->getValueInfo(GlobalList);
2642 printSummaryInfo(Machine.getGUIDSlot(GUID),
VI);
2646 for (
auto &TId : TheIndex->typeIds()) {
2648 Out <<
"^" << Machine.getGUIDSlot(GUID) <<
" = typeid: (name: \"" 2649 << TId.first <<
"\"";
2650 printTypeIdSummary(TId.second);
2651 Out <<
") ; guid = " << GUID <<
"\n";
2661 return "singleImpl";
2663 return "branchFunnel";
2674 return "uniformRetVal";
2676 return "uniqueRetVal";
2678 return "virtualConstProp";
2706 Out <<
", alignLog2: " << TTRes.
AlignLog2;
2708 Out <<
", sizeM1: " << TTRes.
SizeM1;
2718 void AssemblyWriter::printTypeIdSummary(
const TypeIdSummary &TIS) {
2719 Out <<
", summary: (";
2720 printTypeTestResolution(TIS.
TTRes);
2721 if (!TIS.
WPDRes.empty()) {
2722 Out <<
", wpdResolutions: (";
2724 for (
auto &WPDRes : TIS.
WPDRes) {
2726 Out <<
"(offset: " << WPDRes.first <<
", ";
2727 printWPDRes(WPDRes.second);
2735 void AssemblyWriter::printArgs(
const std::vector<uint64_t> &
Args) {
2738 for (
auto arg : Args) {
2746 Out <<
"wpdRes: (kind: ";
2753 Out <<
", resByArg: (";
2755 for (
auto &ResByArg : WPDRes.
ResByArg) {
2757 printArgs(ResByArg.first);
2758 Out <<
", byArg: (kind: ";
2760 if (ResByArg.second.TheKind ==
2762 ResByArg.second.TheKind ==
2764 Out <<
", info: " << ResByArg.second.Info;
2768 if (ResByArg.second.Byte || ResByArg.second.Bit)
2769 Out <<
", byte: " << ResByArg.second.Byte
2770 <<
", bit: " << ResByArg.second.Bit;
2791 void AssemblyWriter::printAliasSummary(
const AliasSummary *AS) {
2792 Out <<
", aliasee: ";
2797 Out <<
"^" << Machine.getGUIDSlot(SummaryToGUIDMap[&AS->
getAliasee()]);
2817 return "linkonce_odr";
2827 return "extern_weak";
2829 return "available_externally";
2859 void AssemblyWriter::printFunctionSummary(
const FunctionSummary *FS) {
2865 Out <<
", funcFlags: (";
2866 Out <<
"readNone: " << FFlags.
ReadNone;
2867 Out <<
", readOnly: " << FFlags.
ReadOnly;
2868 Out <<
", noRecurse: " << FFlags.
NoRecurse;
2872 if (!FS->
calls().empty()) {
2873 Out <<
", calls: (";
2875 for (
auto &Call : FS->
calls()) {
2877 Out <<
"(callee: ^" << Machine.getGUIDSlot(Call.first.getGUID());
2879 Out <<
", hotness: " <<
getHotnessName(Call.second.getHotness());
2880 else if (Call.second.RelBlockFreq)
2881 Out <<
", relbf: " << Call.second.RelBlockFreq;
2888 printTypeIdInfo(*TIdInfo);
2891 void AssemblyWriter::printTypeIdInfo(
2893 Out <<
", typeIdInfo: (";
2894 FieldSeparator TIDFS;
2897 Out <<
"typeTests: (";
2901 auto Slot = Machine.getGUIDSlot(GUID);
2920 "typeTestAssumeConstVCalls");
2925 "typeCheckedLoadConstVCalls");
2931 Out <<
"vFuncId: (";
2932 auto Slot = Machine.getGUIDSlot(VFId.
GUID);
2936 Out <<
"guid: " << VFId.
GUID;
2937 Out <<
", offset: " << VFId.
Offset;
2941 void AssemblyWriter::printNonConstVCalls(
2942 const std::vector<FunctionSummary::VFuncId> VCallList,
const char *
Tag) {
2943 Out << Tag <<
": (";
2945 for (
auto &VFuncId : VCallList) {
2947 printVFuncId(VFuncId);
2952 void AssemblyWriter::printConstVCalls(
2953 const std::vector<FunctionSummary::ConstVCall> VCallList,
const char *Tag) {
2954 Out << Tag <<
": (";
2956 for (
auto &ConstVCall : VCallList) {
2958 printVFuncId(ConstVCall.VFunc);
2959 if (!ConstVCall.Args.empty()) {
2961 printArgs(ConstVCall.Args);
2971 Out <<
"(module: ^" << Machine.getModulePathSlot(Summary.
modulePath())
2975 Out <<
", live: " << GVFlags.
Live;
2976 Out <<
", dsoLocal: " << GVFlags.
DSOLocal;
2980 printAliasSummary(cast<AliasSummary>(&Summary));
2982 printFunctionSummary(cast<FunctionSummary>(&Summary));
2984 printGlobalVarSummary(cast<GlobalVarSummary>(&Summary));
2986 auto RefList = Summary.
refs();
2987 if (!RefList.empty()) {
2990 for (
auto &
Ref : RefList) {
2992 Out <<
"^" << Machine.getGUIDSlot(
Ref.getGUID());
3000 void AssemblyWriter::printSummaryInfo(
unsigned Slot,
const ValueInfo &
VI) {
3001 Out <<
"^" << Slot <<
" = gv: (";
3003 Out <<
"name: \"" << VI.
name() <<
"\"";
3005 Out <<
"guid: " << VI.
getGUID();
3007 Out <<
", summaries: (";
3011 printSummary(*Summary);
3017 Out <<
" ; guid = " << VI.
getGUID();
3024 Out <<
"<empty name> ";
3026 if (isalpha(static_cast<unsigned char>(Name[0])) || Name[0] ==
'-' ||
3027 Name[0] ==
'$' || Name[0] ==
'.' || Name[0] ==
'_')
3030 Out << '\\' << hexdigit(Name[0] >> 4) <<
hexdigit(Name[0] & 0x0F);
3031 for (
unsigned i = 1, e = Name.
size(); i != e; ++i) {
3032 unsigned char C = Name[i];
3033 if (isalnum(static_cast<unsigned char>(C)) || C ==
'-' || C ==
'$' ||
3034 C ==
'.' || C ==
'_')
3037 Out << '\\' << hexdigit(C >> 4) <<
hexdigit(C & 0x0F);
3042 void AssemblyWriter::printNamedMDNode(
const NamedMDNode *NMD) {
3053 if (
auto *Expr = dyn_cast<DIExpression>(Op)) {
3058 int Slot = Machine.getMetadataSlot(Op);
3083 Out <<
"dso_local ";
3101 Out <<
"thread_local ";
3104 Out <<
"thread_local(localdynamic) ";
3107 Out <<
"thread_local(initialexec) ";
3110 Out <<
"thread_local(localexec) ";
3120 return "local_unnamed_addr";
3122 return "unnamed_addr";
3133 if (isa<GlobalVariable>(GO))
3147 Out <<
"; Materializable\n";
3167 Out << (GV->
isConstant() ?
"constant " :
"global ");
3176 Out <<
", section \"";
3186 printMetadataAttachments(MDs,
", ");
3190 Out <<
" #" << Machine.getAttributeGroupSlot(Attrs);
3192 printInfoComment(*GV);
3197 Out <<
"; Materializable\n";
3211 if (isa<GlobalAlias>(GIS))
3213 else if (isa<GlobalIFunc>(GIS))
3225 TypePrinter.print(GIS->
getType(), Out);
3226 Out <<
" <<NULL ALIASEE>>";
3228 writeOperand(IS, !isa<ConstantExpr>(IS));
3231 printInfoComment(*GIS);
3235 void AssemblyWriter::printComdat(
const Comdat *
C) {
3239 void AssemblyWriter::printTypeIdentities() {
3240 if (TypePrinter.empty())
3246 auto &NumberedTypes = TypePrinter.getNumberedTypes();
3247 for (
unsigned I = 0,
E = NumberedTypes.size(); I !=
E; ++
I) {
3248 Out <<
'%' << I <<
" = type ";
3252 TypePrinter.printStructBody(NumberedTypes[I], Out);
3256 auto &NamedTypes = TypePrinter.getNamedTypes();
3257 for (
unsigned I = 0,
E = NamedTypes.size(); I !=
E; ++
I) {
3263 TypePrinter.printStructBody(NamedTypes[I], Out);
3269 void AssemblyWriter::printFunction(
const Function *F) {
3273 if (AnnotationWriter) AnnotationWriter->emitFunctionAnnot(F, Out);
3276 Out <<
"; Materializable\n";
3281 std::string AttrStr;
3284 if (!Attr.isStringAttribute()) {
3285 if (!AttrStr.empty()) AttrStr +=
' ';
3290 if (!AttrStr.empty())
3291 Out <<
"; Function Attrs: " << AttrStr <<
'\n';
3294 Machine.incorporateFunction(F);
3300 printMetadataAttachments(MDs,
" ");
3342 if (
Arg.getArgNo() != 0)
3358 Out <<
" #" << Machine.getAttributeGroupSlot(Attrs.
getFnAttributes());
3360 Out <<
" section \"";
3368 Out <<
" gc \"" << F->
getGC() <<
'"';
3374 Out <<
" prologue ";
3378 Out <<
" personality ";
3387 printMetadataAttachments(MDs,
" ");
3392 printBasicBlock(&BB);
3400 Machine.purgeFunction();
3407 TypePrinter.print(Arg->
getType(), Out);
3421 void AssemblyWriter::printBasicBlock(
const BasicBlock *BB) {
3427 Out <<
"\n; <label>:";
3428 int Slot = Machine.getLocalSlot(BB);
3436 Out.PadToColumn(50);
3437 Out <<
"; Error: Block without parent!";
3440 Out.PadToColumn(50);
3445 Out <<
" No predecessors!";
3448 writeOperand(*PI,
false);
3449 for (++PI; PI != PE; ++PI) {
3451 writeOperand(*PI,
false);
3458 if (AnnotationWriter) AnnotationWriter->emitBasicBlockStartAnnot(BB, Out);
3462 printInstructionLine(I);
3465 if (AnnotationWriter) AnnotationWriter->emitBasicBlockEndAnnot(BB, Out);
3469 void AssemblyWriter::printInstructionLine(
const Instruction &I) {
3470 printInstruction(I);
3476 void AssemblyWriter::printGCRelocateComment(
const GCRelocateInst &Relocate) {
3486 void AssemblyWriter::printInfoComment(
const Value &V) {
3487 if (
const auto *Relocate = dyn_cast<GCRelocateInst>(&V))
3488 printGCRelocateComment(*Relocate);
3490 if (AnnotationWriter)
3491 AnnotationWriter->printInfoComment(V, Out);
3495 void AssemblyWriter::printInstruction(
const Instruction &I) {
3496 if (AnnotationWriter) AnnotationWriter->emitInstructionAnnot(&I, Out);
3507 int SlotNum = Machine.getLocalSlot(&I);
3509 Out <<
"<badref> = ";
3511 Out <<
'%' << SlotNum <<
" = ";
3514 if (
const CallInst *CI = dyn_cast<CallInst>(&I)) {
3515 if (CI->isMustTailCall())
3517 else if (CI->isTailCall())
3519 else if (CI->isNoTailCall())
3527 if ((isa<LoadInst>(I) && cast<LoadInst>(I).
isAtomic()) ||
3528 (isa<StoreInst>(I) && cast<StoreInst>(I).
isAtomic()))
3531 if (isa<AtomicCmpXchgInst>(I) && cast<AtomicCmpXchgInst>(I).
isWeak())
3535 if ((isa<LoadInst>(I) && cast<LoadInst>(I).
isVolatile()) ||
3536 (isa<StoreInst>(I) && cast<StoreInst>(I).
isVolatile()) ||
3537 (isa<AtomicCmpXchgInst>(I) && cast<AtomicCmpXchgInst>(I).
isVolatile()) ||
3538 (isa<AtomicRMWInst>(I) && cast<AtomicRMWInst>(I).
isVolatile()))
3545 if (
const CmpInst *CI = dyn_cast<CmpInst>(&I))
3549 if (
const AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(&I))
3556 if (isa<BranchInst>(I) && cast<BranchInst>(I).isConditional()) {
3565 }
else if (isa<SwitchInst>(I)) {
3573 for (
auto Case : SI.
cases()) {
3575 writeOperand(Case.getCaseValue(),
true);
3577 writeOperand(Case.getCaseSuccessor(),
true);
3580 }
else if (isa<IndirectBrInst>(I)) {
3583 writeOperand(Operand,
true);
3592 }
else if (
const PHINode *PN = dyn_cast<PHINode>(&I)) {
3594 TypePrinter.print(I.
getType(), Out);
3597 for (
unsigned op = 0, Eop = PN->getNumIncomingValues();
op < Eop; ++
op) {
3598 if (
op) Out <<
", ";
3600 writeOperand(PN->getIncomingValue(
op),
false); Out <<
", ";
3601 writeOperand(PN->getIncomingBlock(
op),
false); Out <<
" ]";
3606 for (
const unsigned *i = EVI->idx_begin(), *e = EVI->idx_end(); i != e; ++i)
3608 }
else if (
const InsertValueInst *IVI = dyn_cast<InsertValueInst>(&I)) {
3610 writeOperand(I.
getOperand(0),
true); Out <<
", ";
3612 for (
const unsigned *i = IVI->idx_begin(), *e = IVI->idx_end(); i != e; ++i)
3614 }
else if (
const LandingPadInst *LPI = dyn_cast<LandingPadInst>(&I)) {
3616 TypePrinter.print(I.
getType(), Out);
3617 if (LPI->isCleanup() || LPI->getNumClauses() != 0)
3620 if (LPI->isCleanup())
3623 for (
unsigned i = 0, e = LPI->getNumClauses(); i != e; ++i) {
3624 if (i != 0 || LPI->isCleanup()) Out <<
"\n";
3625 if (LPI->isCatch(i))
3630 writeOperand(LPI->getClause(i),
true);
3632 }
else if (
const auto *CatchSwitch = dyn_cast<CatchSwitchInst>(&I)) {
3634 writeOperand(CatchSwitch->getParentPad(),
false);
3637 for (
const BasicBlock *PadBB : CatchSwitch->handlers()) {
3640 writeOperand(PadBB,
true);
3644 if (
const BasicBlock *UnwindDest = CatchSwitch->getUnwindDest())
3645 writeOperand(UnwindDest,
true);
3648 }
else if (
const auto *FPI = dyn_cast<FuncletPadInst>(&I)) {
3650 writeOperand(FPI->getParentPad(),
false);
3652 for (
unsigned Op = 0, NumOps = FPI->getNumArgOperands();
Op < NumOps;
3656 writeOperand(FPI->getArgOperand(
Op),
true);
3659 }
else if (isa<ReturnInst>(I) && !Operand) {
3661 }
else if (
const auto *CRI = dyn_cast<CatchReturnInst>(&I)) {
3663 writeOperand(CRI->getOperand(0),
false);
3666 writeOperand(CRI->getOperand(1),
true);
3667 }
else if (
const auto *CRI = dyn_cast<CleanupReturnInst>(&I)) {
3669 writeOperand(CRI->getOperand(0),
false);
3672 if (CRI->hasUnwindDest())
3673 writeOperand(CRI->getOperand(1),
true);
3676 }
else if (
const CallInst *CI = dyn_cast<CallInst>(&I)) {
3683 Operand = CI->getCalledValue();
3696 TypePrinter.print(FTy->
isVarArg() ? FTy : RetTy, Out);
3698 writeOperand(Operand,
false);
3700 for (
unsigned op = 0, Eop = CI->getNumArgOperands();
op < Eop; ++
op) {
3708 if (CI->isMustTailCall() && CI->getParent() &&
3709 CI->getParent()->getParent() &&
3710 CI->getParent()->getParent()->isVarArg())
3717 writeOperandBundles(CI);
3718 }
else if (
const InvokeInst *II = dyn_cast<InvokeInst>(&I)) {
3719 Operand = II->getCalledValue();
3738 TypePrinter.print(FTy->
isVarArg() ? FTy : RetTy, Out);
3740 writeOperand(Operand,
false);
3742 for (
unsigned op = 0, Eop = II->getNumArgOperands();
op < Eop; ++
op) {
3752 writeOperandBundles(II);
3755 writeOperand(II->getNormalDest(),
true);
3757 writeOperand(II->getUnwindDest(),
true);
3758 }
else if (
const AllocaInst *AI = dyn_cast<AllocaInst>(&I)) {
3760 if (AI->isUsedWithInAlloca())
3762 if (AI->isSwiftError())
3763 Out <<
"swifterror ";
3764 TypePrinter.print(AI->getAllocatedType(), Out);
3770 if (!AI->getArraySize() || AI->isArrayAllocation() ||
3771 !AI->getArraySize()->getType()->isIntegerTy(32)) {
3773 writeOperand(AI->getArraySize(),
true);
3775 if (AI->getAlignment()) {
3776 Out <<
", align " << AI->getAlignment();
3779 unsigned AddrSpace = AI->getType()->getAddressSpace();
3780 if (AddrSpace != 0) {
3781 Out <<
", addrspace(" << AddrSpace <<
')';
3783 }
else if (isa<CastInst>(I)) {
3786 writeOperand(Operand,
true);
3789 TypePrinter.print(I.
getType(), Out);
3790 }
else if (isa<VAArgInst>(I)) {
3793 writeOperand(Operand,
true);
3796 TypePrinter.print(I.
getType(), Out);
3797 }
else if (Operand) {
3798 if (
const auto *
GEP = dyn_cast<GetElementPtrInst>(&I)) {
3800 TypePrinter.print(
GEP->getSourceElementType(), Out);
3802 }
else if (
const auto *LI = dyn_cast<LoadInst>(&I)) {
3804 TypePrinter.print(LI->getType(), Out);
3811 bool PrintAllTypes =
false;
3815 if (isa<SelectInst>(I) || isa<StoreInst>(I) || isa<ShuffleVectorInst>(I)
3816 || isa<ReturnInst>(I)) {
3817 PrintAllTypes =
true;
3823 if (Operand && Operand->
getType() != TheType) {
3824 PrintAllTypes =
true;
3830 if (!PrintAllTypes) {
3832 TypePrinter.print(TheType, Out);
3838 writeOperand(I.
getOperand(i), PrintAllTypes);
3843 if (
const LoadInst *LI = dyn_cast<LoadInst>(&I)) {
3845 writeAtomic(LI->getContext(), LI->getOrdering(), LI->getSyncScopeID());
3846 if (LI->getAlignment())
3847 Out <<
", align " << LI->getAlignment();
3848 }
else if (
const StoreInst *
SI = dyn_cast<StoreInst>(&I)) {
3850 writeAtomic(
SI->getContext(),
SI->getOrdering(),
SI->getSyncScopeID());
3851 if (
SI->getAlignment())
3852 Out <<
", align " <<
SI->getAlignment();
3854 writeAtomicCmpXchg(CXI->getContext(), CXI->getSuccessOrdering(),
3855 CXI->getFailureOrdering(), CXI->getSyncScopeID());
3856 }
else if (
const AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(&I)) {
3857 writeAtomic(RMWI->getContext(), RMWI->getOrdering(),
3858 RMWI->getSyncScopeID());
3859 }
else if (
const FenceInst *FI = dyn_cast<FenceInst>(&I)) {
3860 writeAtomic(FI->getContext(), FI->getOrdering(), FI->getSyncScopeID());
3866 printMetadataAttachments(InstMD,
", ");
3869 printInfoComment(I);
3872 void AssemblyWriter::printMetadataAttachments(
3878 if (MDNames.empty())
3879 MDs[0].
second->getContext().getMDKindNames(MDNames);
3881 for (
const auto &I : MDs) {
3882 unsigned Kind = I.first;
3884 if (Kind < MDNames.size()) {
3888 Out <<
"!<unknown kind #" << Kind <<
">";
3894 void AssemblyWriter::writeMDNode(
unsigned Slot,
const MDNode *Node) {
3895 Out <<
'!' << Slot <<
" = ";
3896 printMDNodeBody(Node);
3900 void AssemblyWriter::writeAllMDNodes() {
3902 Nodes.
resize(Machine.mdn_size());
3905 Nodes[I->second] = cast<MDNode>(I->first);
3907 for (
unsigned i = 0, e = Nodes.
size(); i != e; ++i) {
3908 writeMDNode(i, Nodes[i]);
3912 void AssemblyWriter::printMDNodeBody(
const MDNode *Node) {
3916 void AssemblyWriter::writeAllAttributeGroups() {
3917 std::vector<std::pair<AttributeSet, unsigned>> asVec;
3918 asVec.resize(Machine.as_size());
3922 asVec[I->second] = *I;
3924 for (
const auto &I : asVec)
3925 Out <<
"attributes #" << I.second <<
" = { " 3926 << I.first.getAsString(
true) <<
" }\n";
3929 void AssemblyWriter::printUseListOrder(
const UseListOrder &Order) {
3934 Out <<
"uselistorder";
3936 IsInFunction ?
nullptr : dyn_cast<BasicBlock>(Order.
V)) {
3940 writeOperand(BB,
false);
3943 writeOperand(Order.
V,
true);
3949 for (
unsigned I = 1,
E = Order.
Shuffle.size(); I !=
E; ++
I)
3950 Out <<
", " << Order.
Shuffle[I];
3954 void AssemblyWriter::printUseLists(
const Function *F) {
3956 [&]() {
return !UseListOrders.empty() && UseListOrders.back().F ==
F; };
3961 Out <<
"\n; uselistorder directives\n";
3963 printUseListOrder(UseListOrders.back());
3964 UseListOrders.pop_back();
3973 bool ShouldPreserveUseListOrder,
3974 bool IsForDebug)
const {
3977 AssemblyWriter
W(OS, SlotTable, this->
getParent(), AAW,
3979 ShouldPreserveUseListOrder);
3980 W.printFunction(
this);
3984 bool ShouldPreserveUseListOrder,
bool IsForDebug)
const {
3987 AssemblyWriter
W(OS, SlotTable,
this, AAW, IsForDebug,
3988 ShouldPreserveUseListOrder);
3989 W.printModule(
this);
3995 AssemblyWriter
W(OS, SlotTable,
getParent(),
nullptr, IsForDebug);
3996 W.printNamedMDNode(
this);
4000 bool IsForDebug)
const {
4007 SlotTable = &*LocalST;
4011 AssemblyWriter
W(OS, *SlotTable,
getParent(),
nullptr, IsForDebug);
4012 W.printNamedMDNode(
this);
4017 ROS <<
" = comdat ";
4019 switch (getSelectionKind()) {
4024 ROS <<
"exactmatch";
4030 ROS <<
"noduplicates";
4042 TP.print(const_cast<Type*>(
this), OS);
4048 if (
StructType *STy = dyn_cast<StructType>(const_cast<Type*>(
this)))
4049 if (!STy->isLiteral()) {
4051 TP.printStructBody(STy, OS);
4056 if (
const auto *CI = dyn_cast<CallInst>(&I))
4057 if (
Function *F = CI->getCalledFunction())
4060 if (
auto *V = dyn_cast_or_null<MetadataAsValue>(
Op))
4061 if (isa<MDNode>(V->getMetadata()))
4067 bool ShouldInitializeAllMetadata =
false;
4068 if (
auto *I = dyn_cast<Instruction>(
this))
4070 else if (isa<Function>(
this) || isa<MetadataAsValue>(
this))
4071 ShouldInitializeAllMetadata =
true;
4074 print(ROS, MST, IsForDebug);
4078 bool IsForDebug)
const {
4080 SlotTracker EmptySlotTable(static_cast<const Module *>(
nullptr));
4083 auto incorporateFunction = [&](
const Function *
F) {
4088 if (
const Instruction *I = dyn_cast<Instruction>(
this)) {
4091 W.printInstruction(*I);
4092 }
else if (
const BasicBlock *BB = dyn_cast<BasicBlock>(
this)) {
4095 W.printBasicBlock(BB);
4096 }
else if (
const GlobalValue *GV = dyn_cast<GlobalValue>(
this)) {
4097 AssemblyWriter
W(OS, SlotTable, GV->
getParent(),
nullptr, IsForDebug);
4100 else if (
const Function *F = dyn_cast<Function>(GV))
4103 W.printIndirectSymbol(cast<GlobalIndirectSymbol>(GV));
4104 }
else if (
const MetadataAsValue *V = dyn_cast<MetadataAsValue>(
this)) {
4106 }
else if (
const Constant *C = dyn_cast<Constant>(
this)) {
4107 TypePrinting TypePrinter;
4108 TypePrinter.print(C->getType(), OS);
4111 }
else if (isa<InlineAsm>(
this) || isa<Argument>(
this)) {
4112 this->printAsOperand(OS,
true, MST);
4123 if (V.
hasName() || isa<GlobalValue>(V) ||
4124 (!isa<Constant>(V) && !isa<MetadataAsValue>(V))) {
4133 TypePrinting TypePrinter(MST.
getModule());
4153 M, isa<MetadataAsValue>(
this));
4169 bool OnlyAsOperand) {
4172 TypePrinting TypePrinter(M);
4178 if (OnlyAsOperand || !N || isa<DIExpression>(MD))
4202 const Module *M,
bool )
const {
4209 AssemblyWriter
W(OS, SlotTable,
this, IsForDebug);
4210 W.printModuleSummaryIndex();
4213 #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.
static const fltSemantics & IEEEquad() LLVM_READNONE
StringRef getSection() const
Get the custom section of this global if it has one.
static SlotTracker * createSlotTracker(const Value *V)
bool isIntrinsic() const
isIntrinsic - Returns true if the function's name starts with "llvm.".
unsigned getAlignment() const
void push_back(const T &Elt)
const std::string & getTargetTriple() const
Get the target triple which is a string describing the target host.
ThreadLocalMode getThreadLocalMode() const
static void WriteOptimizationInfo(raw_ostream &Out, const User *U)
This class is the base class for the comparison instructions.
unsigned Live
In per-module summary, indicate that the global value must be considered a live root for index-based ...
iterator_range< use_iterator > uses()
static std::string getLinkageName(GlobalValue::LinkageTypes LT)
Calling convention used for AMDPAL shader stage before geometry shader if geometry is in use...
bool hasLocalLinkage() const
Special purpose, only applies to global arrays.
uint64_t getZExtValue() const
Get zero extended value.
*p = old <signed v ? old : v
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.
C - The default llvm calling convention, compatible with C.
MDNode * getOperand(unsigned i) const
DenseMap< GlobalValue::GUID, unsigned >::iterator guid_iterator
GUID map iterators.
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
Compute iterated dominance frontiers using a linear time algorithm.
Type * getParamType(unsigned i) const
Parameter type accessors.
unsigned Linkage
The linkage type of the associated global value.
const GlobalValueSummary & getAliasee() const
A Module instance is used to store all the information related to an LLVM module. ...
2: 32-bit floating point type
An instruction for ordering other memory operations.
Same, but only replaced by something equivalent.
static StringRef getUnnamedAddrEncoding(GlobalVariable::UnnamedAddr UA)
an instruction that atomically checks whether a specified value is in a memory location, and, if it is, stores a new value there.
FormattedNumber format_hex(uint64_t N, unsigned Width, bool Upper=false)
format_hex - Output N as a fixed width hexadecimal.
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...
ARM_AAPCS - ARM Architecture Procedure Calling Standard calling convention (aka EABI).
Available for inspection, not emission.
static void writeAtomicRMWOperation(raw_ostream &Out, AtomicRMWInst::BinOp Op)
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
ArrayRef< ValueInfo > refs() const
Return the list of values referenced by this global value definition.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
This class represents a function call, abstracting a target machine's calling convention.
void emplace(ArgTypes &&... Args)
Create a new object by constructing it in place with the given arguments.
Value * getCondition() const
*p = old <unsigned v ? old : v
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
*p = old >unsigned v ? old : v
Externally visible function.
void printEscapedString(StringRef Name, raw_ostream &Out)
Print each character of the specified string, escaping it if it is not printable or if it is an escap...
std::vector< VFuncId > TypeTestAssumeVCalls
List of virtual calls made by this function using (respectively) llvm.assume(llvm.type.test) or llvm.type.checked.load intrinsics that do not have all constant integer arguments.
bool hasPrologueData() const
Check whether this function has prologue data.
The data referenced by the COMDAT must be the same size.
const std::string & getDataLayoutStr() const
Get the data layout string for the module's target platform.
BasicBlock * getSuccessor(unsigned i) const
int getGlobalSlot(const GlobalValue *V)
getGlobalSlot - Get the slot number of a global value.
4: 80-bit floating point type (X87)
const fltSemantics & getSemantics() const
const MDOperand & getOperand(unsigned I) const
param_iterator param_end() const
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
An instruction for reading from memory.
Manage lifetime of a slot tracker for printing IR.
1: 16-bit floating point type
bool hasExternalWeakLinkage() const
an instruction that atomically reads a memory location, combines it with another value, and then stores the result back.
Value * getCondition() const
Kind
Specifies which kind of type check we should emit for this byte array.
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.
*p = old >signed v ? old : v
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...
ARM_APCS - ARM Procedure Calling Standard calling convention (obsolete, but still used on some target...
static void PrintCallingConv(unsigned cc, raw_ostream &Out)
void dump() const
Dump to stderr (for debugging).
static void PrintDSOLocation(const GlobalValue &GV, formatted_raw_ostream &Out)
Constant * getPrologueData() const
Get the prologue data associated with this function.
SlotTracker * getMachine()
Lazily creates a slot tracker.
static void predictValueUseListOrder(const Value *V, const Function *F, OrderMap &OM, UseListOrderStack &Stack)
Calling convention used for Mesa/AMDPAL pixel shaders.
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)
X86_INTR - x86 hardware interrupt context.
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.
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)
SPIR_FUNC - Calling convention for SPIR non-kernel device functions.
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.
Intel_OCL_BI - Calling conventions for Intel OpenCL built-ins.
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
PTX_Device - Call to a PTX device function.
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
bool hasAttributes(unsigned Index) const
Return true if attribute exists at the given index.
The C convention as specified in the x86-64 supplement to the System V ABI, used on most non-Windows ...
APInt getHiBits(unsigned numBits) const
Compute an APInt containing numBits highbits from this APInt.
Calling convention used by HipHop Virtual Machine (HHVM) to perform calls to and from translation cac...
uint64_t getNumElements() const
static void printMetadataIdentifier(StringRef Name, formatted_raw_ostream &Out)
static const uint16_t * lookup(unsigned opcode, unsigned domain, ArrayRef< uint16_t[3]> Table)
This file implements a class to represent arbitrary precision integral constant values and operations...
Constant * getPrefixData() const
Get the prefix data associated with this function.
AtomicOrdering
Atomic ordering for LLVM's memory model.
enum llvm::WholeProgramDevirtResolution::Kind TheKind
bool hasExternalLinkage() const
Uniform return value optimization.
SPIR_KERNEL - Calling convention for SPIR kernel functions.
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
BinOp
This enumeration lists the possible modifications atomicrmw can make.
void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW=nullptr, bool ShouldPreserveUseListOrder=false, bool IsForDebug=false) const
Print the function to an output stream with an optional AssemblyAnnotationWriter. ...
Class to represent array types.
AttributeSet getParamAttributes(unsigned ArgNo) const
The attributes for the argument or parameter at the given index are returned.
VisibilityTypes
An enumeration for the kinds of visibility of global values.
int getModulePathSlot(StringRef Path)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
const std::string & getGC() const
AttributeList getAttributes() const
Return the attribute list for this Function.
An instruction for storing to memory.
bool hasPersonalityFn() const
Check whether this function has a personality function.
COFF::MachineTypes Machine
LinkageTypes getLinkage() const
static const fltSemantics & IEEEdouble() LLVM_READNONE
char hexdigit(unsigned X, bool LowerCase=false)
hexdigit - Return the hexadecimal character for the given number X (which should be less than 16)...
static void PrintVisibility(GlobalValue::VisibilityTypes Vis, formatted_raw_ostream &Out)
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
Structure to hold a use-list order.
Class to hold module path string table and global value map, and encapsulate methods for operating on...
ArrayRef< std::unique_ptr< GlobalValueSummary > > getSummaryList() const
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...
AttributeSet getAttributes(unsigned Index) const
The attributes for the specified index are returned.
11: Arbitrary bit width integers
bool isVoidTy() const
Return true if this is 'void'.
ExternalWeak linkage description.
const BasicBlock & getEntryBlock() const
This class provides computation of slot numbers for LLVM Assembly writing.
Same, but only replaced by something equivalent.
Type * getReturnType() const
Returns the type of the ret val.
unsigned getNumOperands() const
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
X86_ThisCall - Similar to X86_StdCall.
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.
X86_FastCall - 'fast' analog of X86_StdCall.
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.
Calling convention used for AVR signal routines.
void dump() const
Dump the module to stderr (for debugging).
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
static StringRef getPredicateName(Predicate P)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
unsigned instCount() const
Get the instruction count recorded for this function.
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].
Calling convention used for AMDPAL vertex shader if tessellation is in use.
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...
X86_StdCall - stdcall is the calling conventions mostly used by the Win32 API.
bool hasOperandBundles() const
Single element (last example in "Short Inline Bit Vectors")
static const char * getHotnessName(CalleeInfo::HotnessType HT)
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)
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)
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.
ARM_AAPCS_VFP - Same as ARM_AAPCS, but uses hard floating point ABI.
static bool isAtomic(Instruction *I)
static void PrintThreadLocalModel(GlobalVariable::ThreadLocalMode TLM, formatted_raw_ostream &Out)
const std::string & getModuleIdentifier() const
Get the module identifier which is, essentially, the name of the module.
GVFlags flags() const
Get the flags for this GlobalValue (see struct GVFlags).
void printAsOperand(raw_ostream &O, bool PrintType=true, const Module *M=nullptr) const
Print the name of this Value out to the specified raw_ostream.
Fast - This calling convention attempts to make calls as fast as possible (e.g.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
An "identifier" for a virtual function.
void sort(IteratorTy Start, IteratorTy End)
Struct that holds a reference to a particular GUID in a global value summary.
static void PrintLLVMName(raw_ostream &OS, StringRef Name, PrefixType Prefix)
Turn the specified name into an 'LLVM name', which is either prefixed with % (if the string only cont...
reverse_iterator rbegin()
void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW, bool ShouldPreserveUseListOrder=false, bool IsForDebug=false) const
Print the module to an output stream with an optional AssemblyAnnotationWriter.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
std::vector< VFuncId > TypeCheckedLoadVCalls
static const fltSemantics & IEEEsingle() LLVM_READNONE
unsigned getNumOperands() const
std::string getAsString(bool InAttrGrp=false) const
This is the shared class of boolean and integer constants.
auto size(R &&Range, typename std::enable_if< std::is_same< typename std::iterator_traits< decltype(Range.begin())>::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr) -> decltype(std::distance(Range.begin(), Range.end()))
Get the size of a range.
static const fltSemantics & IEEEhalf() LLVM_READNONE
OperandBundleUse getOperandBundleAt(unsigned Index) const
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...
MSVC calling convention that passes vectors and vector aggregates in SSE registers.
bool hasSection() const
Check if this global has a custom object file section.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Keep one copy of function when linking (inline)
Utility class for floating point operations which can have information about relaxed accuracy require...
Module.h This file contains the declarations for the Module class.
static void WriteConstantInternal(raw_ostream &Out, const Constant *CV, TypePrinting &TypePrinter, SlotTracker *Machine, const Module *Context)
Register calling convention used for parameters transfer optimization.
LLVM_NODISCARD std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Type::subtype_iterator param_iterator
Single implementation devirtualization.
Type * getReturnType() const
void printLLVMNameWithoutPrefix(raw_ostream &OS, StringRef Name)
Print out a name of an LLVM value without any prefixes.
Alias summary information.
virtual ~AssemblyAnnotationWriter()
The linker will choose the largest COMDAT.
static bool isReferencingMDNode(const Instruction &I)
void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode *>> &MDs) const
Get all metadata attached to this Instruction.
std::string SingleImplName
enum llvm::TypeTestResolution::Kind TheKind
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
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.
static bool isWeak(const MCSymbolELF &Sym)
Calling convention used for Mesa/AMDPAL compute shaders.
LinkageTypes
An enumeration for the kinds of linkage for global values.
StringRef getName() const
A lightweight accessor for an operand bundle meant to be passed around by value.
iterator_range< user_iterator > users()
Calling convention for AMDGPU code object kernels.
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)
amdgpu Simplify well known AMD library false Value Value * Arg
void initializeIndexIfNeeded()
FFlags fflags() const
Get function attribute flags.
const Comdat * getComdat() const
Used for AVR interrupt routines.
static const fltSemantics & PPCDoubleDouble() LLVM_READNONE
Test a byte array (first example)
Function to be accessible from DLL.
Calling convention used for Mesa/AMDPAL geometry shaders.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
bool hasGC() const
hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm to use during code generatio...
unsigned getNumOperandBundles() const
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.
Establish a view to a call site for examination.
const Function * getParent() const
Return the enclosing method, or null if none.
FormattedNumber format_hex_no_prefix(uint64_t N, unsigned Width, bool Upper=false)
format_hex_no_prefix - Output N as a fixed width hexadecimal.
StringRef getTagName() const
Return the tag of this operand bundle as a string.
static void maybePrintComdat(formatted_raw_ostream &Out, const GlobalObject &GO)
static const char * getSummaryKindName(GlobalValueSummary::SummaryKind SK)
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).
MSP430_INTR - Calling convention used for MSP430 interrupt routines.
const Constant * getIndirectSymbol() const
Function attribute flags.
iterator_range< ifunc_iterator > ifuncs()
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.
PTX_Kernel - Call to a PTX kernel.
Function to be imported from DLL.
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
const std::string & getModuleInlineAsm() const
Get any module-scope inline assembly blocks.
This file defines passes to print out IR in various granularities.
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
3: 64-bit floating point type
Synchronized with respect to all concurrently executing threads.
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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.
Calling convention used for Mesa vertex shaders, or AMDPAL last shader stage before rasterization (ve...
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()
HHVM calling convention for invoking C/C++ helpers.
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 used for Mesa/AMDPAL hull shaders (= tessellation control shaders).
TypeFinder - Walk over a module, identifying all of the types that are used by the module...
The C convention as implemented on Windows/x86-64 and AArch64.
bool isExternallyInitialized() const
static UseListOrderStack predictUseListOrder(const Module *M)
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Type * getElementType() const
int getAttributeGroupSlot(AttributeSet AS)
PointerType * getType() const
Global values are always pointers.
iterator_range< arg_iterator > args()
Unique return value optimization.
std::vector< GlobalValue::GUID > TypeTests
List of type identifiers used by this function in llvm.type.test intrinsics referenced by something o...
const BasicBlock * getParent() const
an instruction to allocate memory on the stack
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.