diff options
Diffstat (limited to 'llvm/lib/IR/AsmWriter.cpp')
-rw-r--r-- | llvm/lib/IR/AsmWriter.cpp | 469 |
1 files changed, 212 insertions, 257 deletions
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp index 54b92c9..245129f 100644 --- a/llvm/lib/IR/AsmWriter.cpp +++ b/llvm/lib/IR/AsmWriter.cpp @@ -127,7 +127,7 @@ static void orderValue(const Value *V, OrderMap &OM) { if (OM.lookup(V)) return; - if (const Constant *C = dyn_cast<Constant>(V)) { + if (const auto *C = dyn_cast<Constant>(V)) { if (isa<ConstantData>(C)) return; @@ -146,17 +146,17 @@ static void orderValue(const Value *V, OrderMap &OM) { static OrderMap orderModule(const Module *M) { OrderMap OM; - auto orderConstantValue = [&OM](const Value *V) { + auto OrderConstantValue = [&OM](const Value *V) { if (isa<Constant>(V) || isa<InlineAsm>(V)) orderValue(V, OM); }; auto OrderConstantFromMetadata = [&](Metadata *MD) { if (const auto *VAM = dyn_cast<ValueAsMetadata>(MD)) { - orderConstantValue(VAM->getValue()); + OrderConstantValue(VAM->getValue()); } else if (const auto *AL = dyn_cast<DIArgList>(MD)) { for (const auto *VAM : AL->getArgs()) - orderConstantValue(VAM->getValue()); + OrderConstantValue(VAM->getValue()); } }; @@ -302,18 +302,18 @@ static UseListOrderMap predictUseListOrder(const Module *M) { } static const Module *getModuleFromVal(const Value *V) { - if (const Argument *MA = dyn_cast<Argument>(V)) + if (const auto *MA = dyn_cast<Argument>(V)) return MA->getParent() ? MA->getParent()->getParent() : nullptr; - if (const BasicBlock *BB = dyn_cast<BasicBlock>(V)) + if (const auto *BB = dyn_cast<BasicBlock>(V)) return BB->getParent() ? BB->getParent()->getParent() : nullptr; - if (const Instruction *I = dyn_cast<Instruction>(V)) { + if (const auto *I = dyn_cast<Instruction>(V)) { const Function *M = I->getParent() ? I->getParent()->getParent() : nullptr; return M ? M->getParent() : nullptr; } - if (const GlobalValue *GV = dyn_cast<GlobalValue>(V)) + if (const auto *GV = dyn_cast<GlobalValue>(V)) return GV->getParent(); if (const auto *MAV = dyn_cast<MetadataAsValue>(V)) { @@ -337,7 +337,7 @@ static const Module *getModuleFromDPI(const DbgRecord *DR) { return DR->getMarker() ? getModuleFromDPI(DR->getMarker()) : nullptr; } -static void PrintCallingConv(unsigned cc, raw_ostream &Out) { +static void printCallingConv(unsigned cc, raw_ostream &Out) { switch (cc) { default: Out << "cc" << cc; break; case CallingConv::Fast: Out << "fastcc"; break; @@ -484,7 +484,7 @@ void llvm::printLLVMNameWithoutPrefix(raw_ostream &OS, StringRef Name) { /// Turn the specified name into an 'LLVM name', which is either prefixed with % /// (if the string only contains simple characters) or is surrounded with ""'s /// (if it has special chars in it). Print it out. -static void PrintLLVMName(raw_ostream &OS, StringRef Name, PrefixType Prefix) { +static void printLLVMName(raw_ostream &OS, StringRef Name, PrefixType Prefix) { switch (Prefix) { case NoPrefix: break; @@ -506,12 +506,12 @@ 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 contains simple characters) or is surrounded with ""'s /// (if it has special chars in it). Print it out. -static void PrintLLVMName(raw_ostream &OS, const Value *V) { - PrintLLVMName(OS, V->getName(), +static void printLLVMName(raw_ostream &OS, const Value *V) { + printLLVMName(OS, V->getName(), isa<GlobalValue>(V) ? GlobalPrefix : LocalPrefix); } -static void PrintShuffleMask(raw_ostream &Out, Type *Ty, ArrayRef<int> Mask) { +static void printShuffleMask(raw_ostream &Out, Type *Ty, ArrayRef<int> Mask) { Out << ", <"; if (isa<ScalableVectorType>(Ty)) Out << "vscale x "; @@ -668,7 +668,7 @@ void TypePrinting::print(Type *Ty, raw_ostream &OS) { return printStructBody(STy, OS); if (!STy->getName().empty()) - return PrintLLVMName(OS, STy->getName(), LocalPrefix); + return printLLVMName(OS, STy->getName(), LocalPrefix); incorporateTypes(); const auto I = Type2Number.find(STy); @@ -999,26 +999,26 @@ void ModuleSlotTracker::setProcessHook( } static SlotTracker *createSlotTracker(const Value *V) { - if (const Argument *FA = dyn_cast<Argument>(V)) + if (const auto *FA = dyn_cast<Argument>(V)) return new SlotTracker(FA->getParent()); - if (const Instruction *I = dyn_cast<Instruction>(V)) + if (const auto *I = dyn_cast<Instruction>(V)) if (I->getParent()) return new SlotTracker(I->getParent()->getParent()); - if (const BasicBlock *BB = dyn_cast<BasicBlock>(V)) + if (const auto *BB = dyn_cast<BasicBlock>(V)) return new SlotTracker(BB->getParent()); - if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) + if (const auto *GV = dyn_cast<GlobalVariable>(V)) return new SlotTracker(GV->getParent()); - if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) + if (const auto *GA = dyn_cast<GlobalAlias>(V)) return new SlotTracker(GA->getParent()); - if (const GlobalIFunc *GIF = dyn_cast<GlobalIFunc>(V)) + if (const auto *GIF = dyn_cast<GlobalIFunc>(V)) return new SlotTracker(GIF->getParent()); - if (const Function *Func = dyn_cast<Function>(V)) + if (const auto *Func = dyn_cast<Function>(V)) return new SlotTracker(Func); return nullptr; @@ -1218,7 +1218,7 @@ void SlotTracker::processDbgRecordMetadata(const DbgRecord &DR) { // but we can have faulty metadata from debug-intrinsic days being // autoupgraded into debug records. This gets caught by the verifier, which // then will print the faulty IR, hitting this code path. - if (const DbgVariableRecord *DVR = dyn_cast<const DbgVariableRecord>(&DR)) { + if (const auto *DVR = dyn_cast<const DbgVariableRecord>(&DR)) { // Process metadata used by DbgRecords; we only specifically care about the // DILocalVariable, DILocation, and DIAssignID fields, as the Value and // Expression fields should only be printed inline and so do not use a slot. @@ -1233,7 +1233,7 @@ void SlotTracker::processDbgRecordMetadata(const DbgRecord &DR) { if (auto *Empty = dyn_cast_if_present<MDNode>(DVR->getRawAddress())) CreateMetadataSlot(Empty); } - } else if (const DbgLabelRecord *DLR = dyn_cast<const DbgLabelRecord>(&DR)) { + } else if (const auto *DLR = dyn_cast<const DbgLabelRecord>(&DR)) { CreateMetadataSlot(DLR->getRawLabel()); } else { llvm_unreachable("unsupported DbgRecord kind"); @@ -1244,12 +1244,12 @@ void SlotTracker::processDbgRecordMetadata(const DbgRecord &DR) { void SlotTracker::processInstructionMetadata(const Instruction &I) { // Process metadata used directly by intrinsics. - if (const CallInst *CI = dyn_cast<CallInst>(&I)) + if (const auto *CI = dyn_cast<CallInst>(&I)) if (Function *F = CI->getCalledFunction()) if (F->isIntrinsic()) for (auto &Op : I.operands()) if (auto *V = dyn_cast_or_null<MetadataAsValue>(Op)) - if (MDNode *N = dyn_cast<MDNode>(V->getMetadata())) + if (auto *N = dyn_cast<MDNode>(V->getMetadata())) CreateMetadataSlot(N); // Process metadata attached to this instruction. @@ -1406,7 +1406,7 @@ void SlotTracker::CreateMetadataSlot(const MDNode *N) { // Recursively add any MDNodes referenced by operands. for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) - if (const MDNode *Op = dyn_cast_or_null<MDNode>(N->getOperand(i))) + if (const auto *Op = dyn_cast_or_null<MDNode>(N->getOperand(i))) CreateMetadataSlot(Op); } @@ -1464,32 +1464,30 @@ struct AsmWriterContext { // AsmWriter Implementation //===----------------------------------------------------------------------===// -static void WriteAsOperandInternal(raw_ostream &Out, const Value *V, - AsmWriterContext &WriterCtx); +static void writeAsOperandInternal(raw_ostream &Out, const Value *V, + AsmWriterContext &WriterCtx, + bool PrintType = false); -static void WriteAsOperandInternal(raw_ostream &Out, const Metadata *MD, +static void writeAsOperandInternal(raw_ostream &Out, const Metadata *MD, AsmWriterContext &WriterCtx, bool FromValue = false); -static void WriteOptimizationInfo(raw_ostream &Out, const User *U) { - if (const FPMathOperator *FPO = dyn_cast<const FPMathOperator>(U)) +static void writeOptimizationInfo(raw_ostream &Out, const User *U) { + if (const auto *FPO = dyn_cast<const FPMathOperator>(U)) Out << FPO->getFastMathFlags(); - if (const OverflowingBinaryOperator *OBO = - dyn_cast<OverflowingBinaryOperator>(U)) { + if (const auto *OBO = dyn_cast<OverflowingBinaryOperator>(U)) { if (OBO->hasNoUnsignedWrap()) Out << " nuw"; if (OBO->hasNoSignedWrap()) Out << " nsw"; - } else if (const PossiblyExactOperator *Div = - dyn_cast<PossiblyExactOperator>(U)) { + } else if (const auto *Div = dyn_cast<PossiblyExactOperator>(U)) { if (Div->isExact()) Out << " exact"; - } else if (const PossiblyDisjointInst *PDI = - dyn_cast<PossiblyDisjointInst>(U)) { + } else if (const auto *PDI = dyn_cast<PossiblyDisjointInst>(U)) { if (PDI->isDisjoint()) Out << " disjoint"; - } else if (const GEPOperator *GEP = dyn_cast<GEPOperator>(U)) { + } else if (const auto *GEP = dyn_cast<GEPOperator>(U)) { if (GEP->isInBounds()) Out << " inbounds"; else if (GEP->hasNoUnsignedSignedWrap()) @@ -1514,7 +1512,7 @@ static void WriteOptimizationInfo(raw_ostream &Out, const User *U) { } } -static void WriteAPFloatInternal(raw_ostream &Out, const APFloat &APF) { +static void writeAPFloatInternal(raw_ostream &Out, const APFloat &APF) { if (&APF.getSemantics() == &APFloat::IEEEsingle() || &APF.getSemantics() == &APFloat::IEEEdouble()) { // We would like to output the FP constant value in exponential notation, @@ -1607,9 +1605,9 @@ static void WriteAPFloatInternal(raw_ostream &Out, const APFloat &APF) { llvm_unreachable("Unsupported floating point type"); } -static void WriteConstantInternal(raw_ostream &Out, const Constant *CV, +static void writeConstantInternal(raw_ostream &Out, const Constant *CV, AsmWriterContext &WriterCtx) { - if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) { + if (const auto *CI = dyn_cast<ConstantInt>(CV)) { Type *Ty = CI->getType(); if (Ty->isVectorTy()) { @@ -1629,7 +1627,7 @@ static void WriteConstantInternal(raw_ostream &Out, const Constant *CV, return; } - if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) { + if (const auto *CFP = dyn_cast<ConstantFP>(CV)) { Type *Ty = CFP->getType(); if (Ty->isVectorTy()) { @@ -1638,7 +1636,7 @@ static void WriteConstantInternal(raw_ostream &Out, const Constant *CV, Out << " "; } - WriteAPFloatInternal(Out, CFP->getValueAPF()); + writeAPFloatInternal(Out, CFP->getValueAPF()); if (Ty->isVectorTy()) Out << ")"; @@ -1651,28 +1649,28 @@ static void WriteConstantInternal(raw_ostream &Out, const Constant *CV, return; } - if (const BlockAddress *BA = dyn_cast<BlockAddress>(CV)) { + if (const auto *BA = dyn_cast<BlockAddress>(CV)) { Out << "blockaddress("; - WriteAsOperandInternal(Out, BA->getFunction(), WriterCtx); + writeAsOperandInternal(Out, BA->getFunction(), WriterCtx); Out << ", "; - WriteAsOperandInternal(Out, BA->getBasicBlock(), WriterCtx); + writeAsOperandInternal(Out, BA->getBasicBlock(), WriterCtx); Out << ")"; return; } if (const auto *Equiv = dyn_cast<DSOLocalEquivalent>(CV)) { Out << "dso_local_equivalent "; - WriteAsOperandInternal(Out, Equiv->getGlobalValue(), WriterCtx); + writeAsOperandInternal(Out, Equiv->getGlobalValue(), WriterCtx); return; } if (const auto *NC = dyn_cast<NoCFIValue>(CV)) { Out << "no_cfi "; - WriteAsOperandInternal(Out, NC->getGlobalValue(), WriterCtx); + writeAsOperandInternal(Out, NC->getGlobalValue(), WriterCtx); return; } - if (const ConstantPtrAuth *CPA = dyn_cast<ConstantPtrAuth>(CV)) { + if (const auto *CPA = dyn_cast<ConstantPtrAuth>(CV)) { Out << "ptrauth ("; // ptrauth (ptr CST, i32 KEY[, i64 DISC[, ptr ADDRDISC]?]?) @@ -1685,29 +1683,25 @@ static void WriteConstantInternal(raw_ostream &Out, const Constant *CV, ListSeparator LS; for (unsigned i = 0, e = NumOpsToWrite; i != e; ++i) { Out << LS; - WriterCtx.TypePrinter->print(CPA->getOperand(i)->getType(), Out); - Out << ' '; - WriteAsOperandInternal(Out, CPA->getOperand(i), WriterCtx); + writeAsOperandInternal(Out, CPA->getOperand(i), WriterCtx, + /*PrintType=*/true); } Out << ')'; return; } - if (const ConstantArray *CA = dyn_cast<ConstantArray>(CV)) { - Type *ETy = CA->getType()->getElementType(); + if (const auto *CA = dyn_cast<ConstantArray>(CV)) { Out << '['; ListSeparator LS; for (const Value *Op : CA->operands()) { Out << LS; - WriterCtx.TypePrinter->print(ETy, Out); - Out << ' '; - WriteAsOperandInternal(Out, Op, WriterCtx); + writeAsOperandInternal(Out, Op, WriterCtx, /*PrintType=*/true); } Out << ']'; return; } - if (const ConstantDataArray *CA = dyn_cast<ConstantDataArray>(CV)) { + if (const auto *CA = dyn_cast<ConstantDataArray>(CV)) { // As a special case, print the array as a string if it is an array of // i8 with ConstantInt values. if (CA->isString()) { @@ -1717,20 +1711,18 @@ static void WriteConstantInternal(raw_ostream &Out, const Constant *CV, return; } - Type *ETy = CA->getType()->getElementType(); Out << '['; ListSeparator LS; for (uint64_t i = 0, e = CA->getNumElements(); i != e; ++i) { Out << LS; - WriterCtx.TypePrinter->print(ETy, Out); - Out << ' '; - WriteAsOperandInternal(Out, CA->getElementAsConstant(i), WriterCtx); + writeAsOperandInternal(Out, CA->getElementAsConstant(i), WriterCtx, + /*PrintType=*/true); } Out << ']'; return; } - if (const ConstantStruct *CS = dyn_cast<ConstantStruct>(CV)) { + if (const auto *CS = dyn_cast<ConstantStruct>(CV)) { if (CS->getType()->isPacked()) Out << '<'; Out << '{'; @@ -1739,9 +1731,7 @@ static void WriteConstantInternal(raw_ostream &Out, const Constant *CV, ListSeparator LS; for (const Value *Op : CS->operands()) { Out << LS; - WriterCtx.TypePrinter->print(Op->getType(), Out); - Out << ' '; - WriteAsOperandInternal(Out, Op, WriterCtx); + writeAsOperandInternal(Out, Op, WriterCtx, /*PrintType=*/true); } Out << ' '; } @@ -1753,7 +1743,6 @@ static void WriteConstantInternal(raw_ostream &Out, const Constant *CV, if (isa<ConstantVector>(CV) || isa<ConstantDataVector>(CV)) { auto *CVVTy = cast<FixedVectorType>(CV->getType()); - Type *ETy = CVVTy->getElementType(); // Use the same shorthand for splat vector (i.e. "splat(Ty val)") as is // permitted on IR input to reduce the output changes when enabling @@ -1763,9 +1752,7 @@ static void WriteConstantInternal(raw_ostream &Out, const Constant *CV, if (auto *SplatVal = CV->getSplatValue()) { if (isa<ConstantInt>(SplatVal) || isa<ConstantFP>(SplatVal)) { Out << "splat ("; - WriterCtx.TypePrinter->print(ETy, Out); - Out << ' '; - WriteAsOperandInternal(Out, SplatVal, WriterCtx); + writeAsOperandInternal(Out, SplatVal, WriterCtx, /*PrintType=*/true); Out << ')'; return; } @@ -1775,9 +1762,8 @@ static void WriteConstantInternal(raw_ostream &Out, const Constant *CV, ListSeparator LS; for (unsigned i = 0, e = CVVTy->getNumElements(); i != e; ++i) { Out << LS; - WriterCtx.TypePrinter->print(ETy, Out); - Out << ' '; - WriteAsOperandInternal(Out, CV->getAggregateElement(i), WriterCtx); + writeAsOperandInternal(Out, CV->getAggregateElement(i), WriterCtx, + /*PrintType=*/true); } Out << '>'; return; @@ -1803,7 +1789,7 @@ static void WriteConstantInternal(raw_ostream &Out, const Constant *CV, return; } - if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) { + if (const auto *CE = dyn_cast<ConstantExpr>(CV)) { // Use the same shorthand for splat vector (i.e. "splat(Ty val)") as is // permitted on IR input to reduce the output changes when enabling // UseConstant{Int,FP}ForScalableSplat. @@ -1813,9 +1799,7 @@ static void WriteConstantInternal(raw_ostream &Out, const Constant *CV, if (auto *SplatVal = CE->getSplatValue()) { if (isa<ConstantInt>(SplatVal) || isa<ConstantFP>(SplatVal)) { Out << "splat ("; - WriterCtx.TypePrinter->print(SplatVal->getType(), Out); - Out << ' '; - WriteAsOperandInternal(Out, SplatVal, WriterCtx); + writeAsOperandInternal(Out, SplatVal, WriterCtx, /*PrintType=*/true); Out << ')'; return; } @@ -1823,10 +1807,10 @@ static void WriteConstantInternal(raw_ostream &Out, const Constant *CV, } Out << CE->getOpcodeName(); - WriteOptimizationInfo(Out, CE); + writeOptimizationInfo(Out, CE); Out << " ("; - if (const GEPOperator *GEP = dyn_cast<GEPOperator>(CE)) { + if (const auto *GEP = dyn_cast<GEPOperator>(CE)) { WriterCtx.TypePrinter->print(GEP->getSourceElementType(), Out); Out << ", "; } @@ -1834,9 +1818,7 @@ static void WriteConstantInternal(raw_ostream &Out, const Constant *CV, ListSeparator LS; for (const Value *Op : CE->operands()) { Out << LS; - WriterCtx.TypePrinter->print(Op->getType(), Out); - Out << ' '; - WriteAsOperandInternal(Out, Op, WriterCtx); + writeAsOperandInternal(Out, Op, WriterCtx, /*PrintType=*/true); } if (CE->isCast()) { @@ -1845,7 +1827,7 @@ static void WriteConstantInternal(raw_ostream &Out, const Constant *CV, } if (CE->getOpcode() == Instruction::ShuffleVector) - PrintShuffleMask(Out, CE->getType(), CE->getShuffleMask()); + printShuffleMask(Out, CE->getType(), CE->getShuffleMask()); Out << ')'; return; @@ -1864,11 +1846,9 @@ static void writeMDTuple(raw_ostream &Out, const MDTuple *Node, Out << "null"; } else if (auto *MDV = dyn_cast<ValueAsMetadata>(MD)) { Value *V = MDV->getValue(); - WriterCtx.TypePrinter->print(V->getType(), Out); - Out << ' '; - WriteAsOperandInternal(Out, V, WriterCtx); + writeAsOperandInternal(Out, V, WriterCtx, /*PrintType=*/true); } else { - WriteAsOperandInternal(Out, MD, WriterCtx); + writeAsOperandInternal(Out, MD, WriterCtx); WriterCtx.onWriteMetadataAsOperand(MD); } } @@ -1956,7 +1936,7 @@ static void writeMetadataAsOperand(raw_ostream &Out, const Metadata *MD, Out << "null"; return; } - WriteAsOperandInternal(Out, MD, WriterCtx); + writeAsOperandInternal(Out, MD, WriterCtx); WriterCtx.onWriteMetadataAsOperand(MD); } @@ -2634,9 +2614,9 @@ static void writeDIArgList(raw_ostream &Out, const DIArgList *N, Out << "!DIArgList("; ListSeparator FS; MDFieldPrinter Printer(Out, WriterCtx); - for (Metadata *Arg : N->getArgs()) { + for (const Metadata *Arg : N->getArgs()) { Out << FS; - WriteAsOperandInternal(Out, Arg, WriterCtx, true); + writeAsOperandInternal(Out, Arg, WriterCtx, true); } Out << ")"; } @@ -2679,7 +2659,7 @@ static void writeDIImportedEntity(raw_ostream &Out, const DIImportedEntity *N, Out << ")"; } -static void WriteMDNodeBodyInternal(raw_ostream &Out, const MDNode *Node, +static void writeMDNodeBodyInternal(raw_ostream &Out, const MDNode *Node, AsmWriterContext &Ctx) { if (Node->isDistinct()) Out << "distinct "; @@ -2699,21 +2679,27 @@ static void WriteMDNodeBodyInternal(raw_ostream &Out, const MDNode *Node, // Full implementation of printing a Value as an operand with support for // TypePrinting, etc. -static void WriteAsOperandInternal(raw_ostream &Out, const Value *V, - AsmWriterContext &WriterCtx) { +static void writeAsOperandInternal(raw_ostream &Out, const Value *V, + AsmWriterContext &WriterCtx, + bool PrintType) { + if (PrintType) { + WriterCtx.TypePrinter->print(V->getType(), Out); + Out << ' '; + } + if (V->hasName()) { - PrintLLVMName(Out, V); + printLLVMName(Out, V); return; } - const Constant *CV = dyn_cast<Constant>(V); + const auto *CV = dyn_cast<Constant>(V); if (CV && !isa<GlobalValue>(CV)) { assert(WriterCtx.TypePrinter && "Constants require TypePrinting!"); - WriteConstantInternal(Out, CV, WriterCtx); + writeConstantInternal(Out, CV, WriterCtx); return; } - if (const InlineAsm *IA = dyn_cast<InlineAsm>(V)) { + if (const auto *IA = dyn_cast<InlineAsm>(V)) { Out << "asm "; if (IA->hasSideEffects()) Out << "sideeffect "; @@ -2733,7 +2719,7 @@ static void WriteAsOperandInternal(raw_ostream &Out, const Value *V, } if (auto *MD = dyn_cast<MetadataAsValue>(V)) { - WriteAsOperandInternal(Out, MD->getMetadata(), WriterCtx, + writeAsOperandInternal(Out, MD->getMetadata(), WriterCtx, /* FromValue */ true); return; } @@ -2743,7 +2729,7 @@ static void WriteAsOperandInternal(raw_ostream &Out, const Value *V, auto *Machine = WriterCtx.Machine; // If we have a SlotTracker, use it. if (Machine) { - if (const GlobalValue *GV = dyn_cast<GlobalValue>(V)) { + if (const auto *GV = dyn_cast<GlobalValue>(V)) { Slot = Machine->getGlobalSlot(GV); Prefix = '@'; } else { @@ -2760,7 +2746,7 @@ static void WriteAsOperandInternal(raw_ostream &Out, const Value *V, } } else if ((Machine = createSlotTracker(V))) { // Otherwise, create one to get the # and then destroy it. - if (const GlobalValue *GV = dyn_cast<GlobalValue>(V)) { + if (const auto *GV = dyn_cast<GlobalValue>(V)) { Slot = Machine->getGlobalSlot(GV); Prefix = '@'; } else { @@ -2778,21 +2764,21 @@ static void WriteAsOperandInternal(raw_ostream &Out, const Value *V, Out << "<badref>"; } -static void WriteAsOperandInternal(raw_ostream &Out, const Metadata *MD, +static void writeAsOperandInternal(raw_ostream &Out, const Metadata *MD, AsmWriterContext &WriterCtx, bool FromValue) { // Write DIExpressions and DIArgLists inline when used as a value. Improves // readability of debug info intrinsics. - if (const DIExpression *Expr = dyn_cast<DIExpression>(MD)) { + if (const auto *Expr = dyn_cast<DIExpression>(MD)) { writeDIExpression(Out, Expr, WriterCtx); return; } - if (const DIArgList *ArgList = dyn_cast<DIArgList>(MD)) { + if (const auto *ArgList = dyn_cast<DIArgList>(MD)) { writeDIArgList(Out, ArgList, WriterCtx, FromValue); return; } - if (const MDNode *N = dyn_cast<MDNode>(MD)) { + if (const auto *N = dyn_cast<MDNode>(MD)) { std::unique_ptr<SlotTracker> MachineStorage; SaveAndRestore SARMachine(WriterCtx.Machine); if (!WriterCtx.Machine) { @@ -2801,7 +2787,7 @@ static void WriteAsOperandInternal(raw_ostream &Out, const Metadata *MD, } int Slot = WriterCtx.Machine->getMetadataSlot(N); if (Slot == -1) { - if (const DILocation *Loc = dyn_cast<DILocation>(N)) { + if (const auto *Loc = dyn_cast<DILocation>(N)) { writeDILocation(Out, Loc, WriterCtx); return; } @@ -2813,7 +2799,7 @@ static void WriteAsOperandInternal(raw_ostream &Out, const Metadata *MD, return; } - if (const MDString *MDS = dyn_cast<MDString>(MD)) { + if (const auto *MDS = dyn_cast<MDString>(MD)) { Out << "!\""; printEscapedString(MDS->getString(), Out); Out << '"'; @@ -2825,9 +2811,7 @@ static void WriteAsOperandInternal(raw_ostream &Out, const Metadata *MD, assert((FromValue || !isa<LocalAsMetadata>(V)) && "Unexpected function-local metadata outside of value argument"); - WriterCtx.TypePrinter->print(V->getValue()->getType(), Out); - Out << ' '; - WriteAsOperandInternal(Out, V->getValue(), WriterCtx); + writeAsOperandInternal(Out, V->getValue(), WriterCtx, /*PrintType=*/true); } namespace { @@ -2902,7 +2886,7 @@ public: void printDbgRecord(const DbgRecord &DR); void printDbgRecordLine(const DbgRecord &DR); - void printUseListOrder(const Value *V, const std::vector<unsigned> &Shuffle); + void printUseListOrder(const Value *V, ArrayRef<unsigned> Shuffle); void printUseLists(const Function *F); void printModuleSummaryIndex(); @@ -2914,16 +2898,14 @@ public: void printTypeIdSummary(const TypeIdSummary &TIS); void printTypeIdCompatibleVtableSummary(const TypeIdCompatibleVtableInfo &TI); void printTypeTestResolution(const TypeTestResolution &TTRes); - void printArgs(const std::vector<uint64_t> &Args); + void printArgs(ArrayRef<uint64_t> Args); void printWPDRes(const WholeProgramDevirtResolution &WPDRes); void printTypeIdInfo(const FunctionSummary::TypeIdInfo &TIDInfo); void printVFuncId(const FunctionSummary::VFuncId VFId); - void - printNonConstVCalls(const std::vector<FunctionSummary::VFuncId> &VCallList, - const char *Tag); - void - printConstVCalls(const std::vector<FunctionSummary::ConstVCall> &VCallList, - const char *Tag); + void printNonConstVCalls(ArrayRef<FunctionSummary::VFuncId> VCallList, + const char *Tag); + void printConstVCalls(ArrayRef<FunctionSummary::ConstVCall> VCallList, + const char *Tag); private: /// Print out metadata attachments. @@ -2965,12 +2947,8 @@ void AssemblyWriter::writeOperand(const Value *Operand, bool PrintType) { Out << "<null operand!>"; return; } - if (PrintType) { - TypePrinter.print(Operand->getType(), Out); - Out << ' '; - } - auto WriterCtx = getContext(); - WriteAsOperandInternal(Out, Operand, WriterCtx); + auto WriteCtx = getContext(); + writeAsOperandInternal(Out, Operand, WriteCtx, PrintType); } void AssemblyWriter::writeSyncScope(const LLVMContext &Context, @@ -3030,7 +3008,7 @@ void AssemblyWriter::writeParamOperand(const Value *Operand, Out << ' '; // Print the operand auto WriterCtx = getContext(); - WriteAsOperandInternal(Out, Operand, WriterCtx); + writeAsOperandInternal(Out, Operand, WriterCtx); } void AssemblyWriter::writeOperandBundles(const CallBase *Call) { @@ -3049,20 +3027,14 @@ void AssemblyWriter::writeOperandBundles(const CallBase *Call) { Out << '('; - bool FirstInput = true; + ListSeparator InnerLS; auto WriterCtx = getContext(); for (const auto &Input : BU.Inputs) { - if (!FirstInput) - Out << ", "; - FirstInput = false; - + Out << InnerLS; if (Input == nullptr) Out << "<null operand bundle!>"; - else { - TypePrinter.print(Input->getType(), Out); - Out << " "; - WriteAsOperandInternal(Out, Input, WriterCtx); - } + else + writeAsOperandInternal(Out, Input, WriterCtx, /*PrintType=*/true); } Out << ')'; @@ -3334,14 +3306,8 @@ void AssemblyWriter::printTypeIdCompatibleVtableSummary( Out << ")"; } -void AssemblyWriter::printArgs(const std::vector<uint64_t> &Args) { - Out << "args: ("; - ListSeparator FS; - for (auto arg : Args) { - Out << FS; - Out << arg; - } - Out << ")"; +void AssemblyWriter::printArgs(ArrayRef<uint64_t> Args) { + Out << "args: (" << llvm::interleaved(Args) << ')'; } void AssemblyWriter::printWPDRes(const WholeProgramDevirtResolution &WPDRes) { @@ -3681,7 +3647,7 @@ void AssemblyWriter::printVFuncId(const FunctionSummary::VFuncId VFId) { } void AssemblyWriter::printNonConstVCalls( - const std::vector<FunctionSummary::VFuncId> &VCallList, const char *Tag) { + ArrayRef<FunctionSummary::VFuncId> VCallList, const char *Tag) { Out << Tag << ": ("; ListSeparator FS; for (auto &VFuncId : VCallList) { @@ -3692,8 +3658,7 @@ void AssemblyWriter::printNonConstVCalls( } void AssemblyWriter::printConstVCalls( - const std::vector<FunctionSummary::ConstVCall> &VCallList, - const char *Tag) { + ArrayRef<FunctionSummary::ConstVCall> VCallList, const char *Tag) { Out << Tag << ": ("; ListSeparator FS; for (auto &ConstVCall : VCallList) { @@ -3816,7 +3781,7 @@ void AssemblyWriter::printNamedMDNode(const NamedMDNode *NMD) { Out << "}\n"; } -static void PrintVisibility(GlobalValue::VisibilityTypes Vis, +static void printVisibility(GlobalValue::VisibilityTypes Vis, formatted_raw_ostream &Out) { switch (Vis) { case GlobalValue::DefaultVisibility: break; @@ -3825,13 +3790,13 @@ static void PrintVisibility(GlobalValue::VisibilityTypes Vis, } } -static void PrintDSOLocation(const GlobalValue &GV, +static void printDSOLocation(const GlobalValue &GV, formatted_raw_ostream &Out) { if (GV.isDSOLocal() && !GV.isImplicitDSOLocal()) Out << "dso_local "; } -static void PrintDLLStorageClass(GlobalValue::DLLStorageClassTypes SCT, +static void printDLLStorageClass(GlobalValue::DLLStorageClassTypes SCT, formatted_raw_ostream &Out) { switch (SCT) { case GlobalValue::DefaultStorageClass: break; @@ -3840,7 +3805,7 @@ static void PrintDLLStorageClass(GlobalValue::DLLStorageClassTypes SCT, } } -static void PrintThreadLocalModel(GlobalVariable::ThreadLocalMode TLM, +static void printThreadLocalModel(GlobalVariable::ThreadLocalMode TLM, formatted_raw_ostream &Out) { switch (TLM) { case GlobalVariable::NotThreadLocal: @@ -3886,7 +3851,7 @@ static void maybePrintComdat(formatted_raw_ostream &Out, return; Out << '('; - PrintLLVMName(Out, C->getName(), ComdatPrefix); + printLLVMName(Out, C->getName(), ComdatPrefix); Out << ')'; } @@ -3895,17 +3860,17 @@ void AssemblyWriter::printGlobal(const GlobalVariable *GV) { Out << "; Materializable\n"; AsmWriterContext WriterCtx(&TypePrinter, &Machine, GV->getParent()); - WriteAsOperandInternal(Out, GV, WriterCtx); + writeAsOperandInternal(Out, GV, WriterCtx); Out << " = "; if (!GV->hasInitializer() && GV->hasExternalLinkage()) Out << "external "; Out << getLinkageNameWithSpace(GV->getLinkage()); - PrintDSOLocation(*GV, Out); - PrintVisibility(GV->getVisibility(), Out); - PrintDLLStorageClass(GV->getDLLStorageClass(), Out); - PrintThreadLocalModel(GV->getThreadLocalMode(), Out); + printDSOLocation(*GV, Out); + printVisibility(GV->getVisibility(), Out); + printDLLStorageClass(GV->getDLLStorageClass(), Out); + printThreadLocalModel(GV->getThreadLocalMode(), Out); StringRef UA = getUnnamedAddrEncoding(GV->getUnnamedAddr()); if (!UA.empty()) Out << UA << ' '; @@ -3986,14 +3951,14 @@ void AssemblyWriter::printAlias(const GlobalAlias *GA) { Out << "; Materializable\n"; AsmWriterContext WriterCtx(&TypePrinter, &Machine, GA->getParent()); - WriteAsOperandInternal(Out, GA, WriterCtx); + writeAsOperandInternal(Out, GA, WriterCtx); Out << " = "; Out << getLinkageNameWithSpace(GA->getLinkage()); - PrintDSOLocation(*GA, Out); - PrintVisibility(GA->getVisibility(), Out); - PrintDLLStorageClass(GA->getDLLStorageClass(), Out); - PrintThreadLocalModel(GA->getThreadLocalMode(), Out); + printDSOLocation(*GA, Out); + printVisibility(GA->getVisibility(), Out); + printDLLStorageClass(GA->getDLLStorageClass(), Out); + printThreadLocalModel(GA->getThreadLocalMode(), Out); StringRef UA = getUnnamedAddrEncoding(GA->getUnnamedAddr()); if (!UA.empty()) Out << UA << ' '; @@ -4025,12 +3990,12 @@ void AssemblyWriter::printIFunc(const GlobalIFunc *GI) { Out << "; Materializable\n"; AsmWriterContext WriterCtx(&TypePrinter, &Machine, GI->getParent()); - WriteAsOperandInternal(Out, GI, WriterCtx); + writeAsOperandInternal(Out, GI, WriterCtx); Out << " = "; Out << getLinkageNameWithSpace(GI->getLinkage()); - PrintDSOLocation(*GI, Out); - PrintVisibility(GI->getVisibility(), Out); + printDSOLocation(*GI, Out); + printVisibility(GI->getVisibility(), Out); Out << "ifunc "; @@ -4082,7 +4047,7 @@ void AssemblyWriter::printTypeIdentities() { auto &NamedTypes = TypePrinter.getNamedTypes(); for (StructType *NamedType : NamedTypes) { - PrintLLVMName(Out, NamedType->getName(), LocalPrefix); + printLLVMName(Out, NamedType->getName(), LocalPrefix); Out << " = type "; // Make sure we print out at least one level of the type structure, so @@ -4130,13 +4095,13 @@ void AssemblyWriter::printFunction(const Function *F) { Out << "define "; Out << getLinkageNameWithSpace(F->getLinkage()); - PrintDSOLocation(*F, Out); - PrintVisibility(F->getVisibility(), Out); - PrintDLLStorageClass(F->getDLLStorageClass(), Out); + printDSOLocation(*F, Out); + printVisibility(F->getVisibility(), Out); + printDLLStorageClass(F->getDLLStorageClass(), Out); // Print the calling convention. if (F->getCallingConv() != CallingConv::C) { - PrintCallingConv(F->getCallingConv(), Out); + printCallingConv(F->getCallingConv(), Out); Out << " "; } @@ -4146,7 +4111,7 @@ void AssemblyWriter::printFunction(const Function *F) { TypePrinter.print(F->getReturnType(), Out); AsmWriterContext WriterCtx(&TypePrinter, &Machine, F->getParent()); Out << ' '; - WriteAsOperandInternal(Out, F, WriterCtx); + writeAsOperandInternal(Out, F, WriterCtx); Out << '('; // Loop over the arguments, printing them... @@ -4262,7 +4227,7 @@ void AssemblyWriter::printArgument(const Argument *Arg, AttributeSet Attrs) { // Output name, if available... if (Arg->hasName()) { Out << ' '; - PrintLLVMName(Out, Arg); + printLLVMName(Out, Arg); } else { int Slot = Machine.getLocalSlot(Arg); assert(Slot != -1 && "expect argument in function here"); @@ -4275,7 +4240,7 @@ void AssemblyWriter::printBasicBlock(const BasicBlock *BB) { bool IsEntryBlock = BB->getParent() && BB->isEntryBlock(); if (BB->hasName()) { // Print out the label if it exists... Out << "\n"; - PrintLLVMName(Out, BB->getName(), LabelPrefix); + printLLVMName(Out, BB->getName(), LabelPrefix); Out << ':'; } else if (!IsEntryBlock) { Out << "\n"; @@ -4393,7 +4358,7 @@ void AssemblyWriter::printInstruction(const Instruction &I) { // Print out name if it exists... if (I.hasName()) { - PrintLLVMName(Out, &I); + printLLVMName(Out, &I); Out << " = "; } else if (!I.getType()->isVoidTy()) { // Print out the def slot taken. @@ -4404,7 +4369,7 @@ void AssemblyWriter::printInstruction(const Instruction &I) { Out << '%' << SlotNum << " = "; } - if (const CallInst *CI = dyn_cast<CallInst>(&I)) { + if (const auto *CI = dyn_cast<CallInst>(&I)) { if (CI->isMustTailCall()) Out << "musttail "; else if (CI->isTailCall()) @@ -4432,14 +4397,14 @@ void AssemblyWriter::printInstruction(const Instruction &I) { Out << " volatile"; // Print out optimization information. - WriteOptimizationInfo(Out, &I); + writeOptimizationInfo(Out, &I); // Print out the compare instruction predicates - if (const CmpInst *CI = dyn_cast<CmpInst>(&I)) + if (const auto *CI = dyn_cast<CmpInst>(&I)) Out << ' ' << CI->getPredicate(); // Print out the atomicrmw operation - if (const AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(&I)) + if (const auto *RMWI = dyn_cast<AtomicRMWInst>(&I)) Out << ' ' << AtomicRMWInst::getOperationName(RMWI->getOperation()); // Print out the type of the operands... @@ -4482,29 +4447,32 @@ void AssemblyWriter::printInstruction(const Instruction &I) { writeOperand(I.getOperand(i), true); } Out << ']'; - } else if (const PHINode *PN = dyn_cast<PHINode>(&I)) { + } else if (const auto *PN = dyn_cast<PHINode>(&I)) { Out << ' '; TypePrinter.print(I.getType(), Out); Out << ' '; ListSeparator LS; - for (unsigned op = 0, Eop = PN->getNumIncomingValues(); op < Eop; ++op) { + for (const auto &[V, Block] : + zip_equal(PN->incoming_values(), PN->blocks())) { Out << LS << "[ "; - writeOperand(PN->getIncomingValue(op), false); Out << ", "; - writeOperand(PN->getIncomingBlock(op), false); Out << " ]"; + writeOperand(V, false); + Out << ", "; + writeOperand(Block, false); + Out << " ]"; } - } else if (const ExtractValueInst *EVI = dyn_cast<ExtractValueInst>(&I)) { + } else if (const auto *EVI = dyn_cast<ExtractValueInst>(&I)) { Out << ' '; writeOperand(I.getOperand(0), true); - for (unsigned i : EVI->indices()) - Out << ", " << i; - } else if (const InsertValueInst *IVI = dyn_cast<InsertValueInst>(&I)) { + Out << ", "; + Out << llvm::interleaved(EVI->indices()); + } else if (const auto *IVI = dyn_cast<InsertValueInst>(&I)) { Out << ' '; writeOperand(I.getOperand(0), true); Out << ", "; writeOperand(I.getOperand(1), true); - for (unsigned i : IVI->indices()) - Out << ", " << i; - } else if (const LandingPadInst *LPI = dyn_cast<LandingPadInst>(&I)) { + Out << ", "; + Out << llvm::interleaved(IVI->indices()); + } else if (const auto *LPI = dyn_cast<LandingPadInst>(&I)) { Out << ' '; TypePrinter.print(I.getType(), Out); if (LPI->isCleanup() || LPI->getNumClauses() != 0) @@ -4563,11 +4531,11 @@ void AssemblyWriter::printInstruction(const Instruction &I) { writeOperand(CRI->getOperand(1), /*PrintType=*/true); else Out << "to caller"; - } else if (const CallInst *CI = dyn_cast<CallInst>(&I)) { + } else if (const auto *CI = dyn_cast<CallInst>(&I)) { // Print the calling convention being used. if (CI->getCallingConv() != CallingConv::C) { Out << " "; - PrintCallingConv(CI->getCallingConv(), Out); + printCallingConv(CI->getCallingConv(), Out); } Operand = CI->getCalledOperand(); @@ -4610,7 +4578,7 @@ void AssemblyWriter::printInstruction(const Instruction &I) { Out << " #" << Machine.getAttributeGroupSlot(PAL.getFnAttrs()); writeOperandBundles(CI); - } else if (const InvokeInst *II = dyn_cast<InvokeInst>(&I)) { + } else if (const auto *II = dyn_cast<InvokeInst>(&I)) { Operand = II->getCalledOperand(); FunctionType *FTy = II->getFunctionType(); Type *RetTy = FTy->getReturnType(); @@ -4619,7 +4587,7 @@ void AssemblyWriter::printInstruction(const Instruction &I) { // Print the calling convention being used. if (II->getCallingConv() != CallingConv::C) { Out << " "; - PrintCallingConv(II->getCallingConv(), Out); + printCallingConv(II->getCallingConv(), Out); } if (PAL.hasRetAttrs()) @@ -4653,7 +4621,7 @@ void AssemblyWriter::printInstruction(const Instruction &I) { writeOperand(II->getNormalDest(), true); Out << " unwind "; writeOperand(II->getUnwindDest(), true); - } else if (const CallBrInst *CBI = dyn_cast<CallBrInst>(&I)) { + } else if (const auto *CBI = dyn_cast<CallBrInst>(&I)) { Operand = CBI->getCalledOperand(); FunctionType *FTy = CBI->getFunctionType(); Type *RetTy = FTy->getReturnType(); @@ -4662,7 +4630,7 @@ void AssemblyWriter::printInstruction(const Instruction &I) { // Print the calling convention being used. if (CBI->getCallingConv() != CallingConv::C) { Out << " "; - PrintCallingConv(CBI->getCallingConv(), Out); + printCallingConv(CBI->getCallingConv(), Out); } if (PAL.hasRetAttrs()) @@ -4698,7 +4666,7 @@ void AssemblyWriter::printInstruction(const Instruction &I) { writeOperand(Dest, true); } Out << ']'; - } else if (const AllocaInst *AI = dyn_cast<AllocaInst>(&I)) { + } else if (const auto *AI = dyn_cast<AllocaInst>(&I)) { Out << ' '; if (AI->isUsedWithInAlloca()) Out << "inalloca "; @@ -4720,9 +4688,8 @@ void AssemblyWriter::printInstruction(const Instruction &I) { } unsigned AddrSpace = AI->getAddressSpace(); - if (AddrSpace != 0) { + if (AddrSpace != 0) Out << ", addrspace(" << AddrSpace << ')'; - } } else if (isa<CastInst>(I)) { if (Operand) { Out << ' '; @@ -4737,7 +4704,7 @@ void AssemblyWriter::printInstruction(const Instruction &I) { } Out << ", "; TypePrinter.print(I.getType(), Out); - } else if (Operand) { // Print the normal way. + } else if (Operand) { // Print the normal way. if (const auto *GEP = dyn_cast<GetElementPtrInst>(&I)) { Out << ' '; TypePrinter.print(GEP->getSourceElementType(), Out); @@ -4786,28 +4753,28 @@ void AssemblyWriter::printInstruction(const Instruction &I) { } // Print atomic ordering/alignment for memory operations - if (const LoadInst *LI = dyn_cast<LoadInst>(&I)) { + if (const auto *LI = dyn_cast<LoadInst>(&I)) { if (LI->isAtomic()) writeAtomic(LI->getContext(), LI->getOrdering(), LI->getSyncScopeID()); if (MaybeAlign A = LI->getAlign()) Out << ", align " << A->value(); - } else if (const StoreInst *SI = dyn_cast<StoreInst>(&I)) { + } else if (const auto *SI = dyn_cast<StoreInst>(&I)) { if (SI->isAtomic()) writeAtomic(SI->getContext(), SI->getOrdering(), SI->getSyncScopeID()); if (MaybeAlign A = SI->getAlign()) Out << ", align " << A->value(); - } else if (const AtomicCmpXchgInst *CXI = dyn_cast<AtomicCmpXchgInst>(&I)) { + } else if (const auto *CXI = dyn_cast<AtomicCmpXchgInst>(&I)) { writeAtomicCmpXchg(CXI->getContext(), CXI->getSuccessOrdering(), CXI->getFailureOrdering(), CXI->getSyncScopeID()); Out << ", align " << CXI->getAlign().value(); - } else if (const AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(&I)) { + } else if (const auto *RMWI = dyn_cast<AtomicRMWInst>(&I)) { writeAtomic(RMWI->getContext(), RMWI->getOrdering(), RMWI->getSyncScopeID()); Out << ", align " << RMWI->getAlign().value(); - } else if (const FenceInst *FI = dyn_cast<FenceInst>(&I)) { + } else if (const auto *FI = dyn_cast<FenceInst>(&I)) { writeAtomic(FI->getContext(), FI->getOrdering(), FI->getSyncScopeID()); - } else if (const ShuffleVectorInst *SVI = dyn_cast<ShuffleVectorInst>(&I)) { - PrintShuffleMask(Out, SVI->getType(), SVI->getShuffleMask()); + } else if (const auto *SVI = dyn_cast<ShuffleVectorInst>(&I)) { + printShuffleMask(Out, SVI->getType(), SVI->getShuffleMask()); } // Print Metadata info. @@ -4863,7 +4830,7 @@ void AssemblyWriter::printDbgVariableRecord(const DbgVariableRecord &DVR) { if (!M) Out << "(null)"; else - WriteAsOperandInternal(Out, M, WriterCtx, true); + writeAsOperandInternal(Out, M, WriterCtx, true); }; Out << "("; @@ -4897,9 +4864,9 @@ void AssemblyWriter::printDbgRecordLine(const DbgRecord &DR) { void AssemblyWriter::printDbgLabelRecord(const DbgLabelRecord &Label) { auto WriterCtx = getContext(); Out << "#dbg_label("; - WriteAsOperandInternal(Out, Label.getRawLabel(), WriterCtx, true); + writeAsOperandInternal(Out, Label.getRawLabel(), WriterCtx, true); Out << ", "; - WriteAsOperandInternal(Out, Label.getDebugLoc(), WriterCtx, true); + writeAsOperandInternal(Out, Label.getDebugLoc(), WriterCtx, true); Out << ")"; } @@ -4922,7 +4889,7 @@ void AssemblyWriter::printMetadataAttachments( } else Out << "!<unknown kind #" << Kind << ">"; Out << ' '; - WriteAsOperandInternal(Out, I.second, WriterCtx); + writeAsOperandInternal(Out, I.second, WriterCtx); } } @@ -4945,7 +4912,7 @@ void AssemblyWriter::writeAllMDNodes() { void AssemblyWriter::printMDNodeBody(const MDNode *Node) { auto WriterCtx = getContext(); - WriteMDNodeBodyInternal(Out, Node, WriterCtx); + writeMDNodeBodyInternal(Out, Node, WriterCtx); } void AssemblyWriter::writeAttribute(const Attribute &Attr, bool InAttrGroup) { @@ -4964,12 +4931,10 @@ void AssemblyWriter::writeAttribute(const Attribute &Attr, bool InAttrGroup) { void AssemblyWriter::writeAttributeSet(const AttributeSet &AttrSet, bool InAttrGroup) { - bool FirstAttr = true; + ListSeparator LS(" "); for (const auto &Attr : AttrSet) { - if (!FirstAttr) - Out << ' '; + Out << LS; writeAttribute(Attr, InAttrGroup); - FirstAttr = false; } } @@ -4986,7 +4951,7 @@ void AssemblyWriter::writeAllAttributeGroups() { } void AssemblyWriter::printUseListOrder(const Value *V, - const std::vector<unsigned> &Shuffle) { + ArrayRef<unsigned> Shuffle) { bool IsInFunction = Machine.getFunction(); if (IsInFunction) Out << " "; @@ -5075,7 +5040,7 @@ void NamedMDNode::print(raw_ostream &ROS, ModuleSlotTracker &MST, } void Comdat::print(raw_ostream &ROS, bool /*IsForDebug*/) const { - PrintLLVMName(ROS, getName(), ComdatPrefix); + printLLVMName(ROS, getName(), ComdatPrefix); ROS << " = comdat "; switch (getSelectionKind()) { @@ -5107,7 +5072,7 @@ void Type::print(raw_ostream &OS, bool /*IsForDebug*/, bool NoDetails) const { return; // If the type is a named struct type, print the body as well. - if (StructType *STy = dyn_cast<StructType>(const_cast<Type*>(this))) + if (auto *STy = dyn_cast<StructType>(const_cast<Type *>(this))) if (!STy->isLiteral()) { OS << " = type "; TP.printStructBody(STy, OS); @@ -5143,11 +5108,9 @@ void DbgMarker::print(raw_ostream &ROS, ModuleSlotTracker &MST, SlotTracker EmptySlotTable(static_cast<const Module *>(nullptr)); SlotTracker &SlotTable = MST.getMachine() ? *MST.getMachine() : EmptySlotTable; - auto incorporateFunction = [&](const Function *F) { - if (F) - MST.incorporateFunction(*F); - }; - incorporateFunction(getParent() ? getParent()->getParent() : nullptr); + const Function *F = getParent() ? getParent()->getParent() : nullptr; + if (F) + MST.incorporateFunction(*F); AssemblyWriter W(OS, SlotTable, getModuleFromDPI(this), nullptr, IsForDebug); W.printDbgMarker(*this); } @@ -5164,13 +5127,11 @@ void DbgVariableRecord::print(raw_ostream &ROS, ModuleSlotTracker &MST, SlotTracker EmptySlotTable(static_cast<const Module *>(nullptr)); SlotTracker &SlotTable = MST.getMachine() ? *MST.getMachine() : EmptySlotTable; - auto incorporateFunction = [&](const Function *F) { - if (F) - MST.incorporateFunction(*F); - }; - incorporateFunction(Marker && Marker->getParent() + const Function *F = Marker && Marker->getParent() ? Marker->getParent()->getParent() - : nullptr); + : nullptr; + if (F) + MST.incorporateFunction(*F); AssemblyWriter W(OS, SlotTable, getModuleFromDPI(this), nullptr, IsForDebug); W.printDbgVariableRecord(*this); } @@ -5181,12 +5142,11 @@ void DbgLabelRecord::print(raw_ostream &ROS, ModuleSlotTracker &MST, SlotTracker EmptySlotTable(static_cast<const Module *>(nullptr)); SlotTracker &SlotTable = MST.getMachine() ? *MST.getMachine() : EmptySlotTable; - auto incorporateFunction = [&](const Function *F) { - if (F) - MST.incorporateFunction(*F); - }; - incorporateFunction(Marker->getParent() ? Marker->getParent()->getParent() - : nullptr); + const Function *F = + Marker->getParent() ? Marker->getParent()->getParent() : nullptr; + if (F) + MST.incorporateFunction(*F); + AssemblyWriter W(OS, SlotTable, getModuleFromDPI(this), nullptr, IsForDebug); W.printDbgLabelRecord(*this); } @@ -5208,39 +5168,39 @@ void Value::print(raw_ostream &ROS, ModuleSlotTracker &MST, SlotTracker EmptySlotTable(static_cast<const Module *>(nullptr)); SlotTracker &SlotTable = MST.getMachine() ? *MST.getMachine() : EmptySlotTable; - auto incorporateFunction = [&](const Function *F) { + auto IncorporateFunction = [&](const Function *F) { if (F) MST.incorporateFunction(*F); }; - if (const Instruction *I = dyn_cast<Instruction>(this)) { - incorporateFunction(I->getParent() ? I->getParent()->getParent() : nullptr); + if (const auto *I = dyn_cast<Instruction>(this)) { + IncorporateFunction(I->getParent() ? I->getParent()->getParent() : nullptr); AssemblyWriter W(OS, SlotTable, getModuleFromVal(I), nullptr, IsForDebug); W.printInstruction(*I); - } else if (const BasicBlock *BB = dyn_cast<BasicBlock>(this)) { - incorporateFunction(BB->getParent()); + } else if (const auto *BB = dyn_cast<BasicBlock>(this)) { + IncorporateFunction(BB->getParent()); AssemblyWriter W(OS, SlotTable, getModuleFromVal(BB), nullptr, IsForDebug); W.printBasicBlock(BB); - } else if (const GlobalValue *GV = dyn_cast<GlobalValue>(this)) { + } else if (const auto *GV = dyn_cast<GlobalValue>(this)) { AssemblyWriter W(OS, SlotTable, GV->getParent(), nullptr, IsForDebug); - if (const GlobalVariable *V = dyn_cast<GlobalVariable>(GV)) + if (const auto *V = dyn_cast<GlobalVariable>(GV)) W.printGlobal(V); - else if (const Function *F = dyn_cast<Function>(GV)) + else if (const auto *F = dyn_cast<Function>(GV)) W.printFunction(F); - else if (const GlobalAlias *A = dyn_cast<GlobalAlias>(GV)) + else if (const auto *A = dyn_cast<GlobalAlias>(GV)) W.printAlias(A); - else if (const GlobalIFunc *I = dyn_cast<GlobalIFunc>(GV)) + else if (const auto *I = dyn_cast<GlobalIFunc>(GV)) W.printIFunc(I); else llvm_unreachable("Unknown GlobalValue to print out!"); - } else if (const MetadataAsValue *V = dyn_cast<MetadataAsValue>(this)) { + } else if (const auto *V = dyn_cast<MetadataAsValue>(this)) { V->getMetadata()->print(ROS, MST, getModuleFromVal(V)); - } else if (const Constant *C = dyn_cast<Constant>(this)) { + } else if (const auto *C = dyn_cast<Constant>(this)) { TypePrinting TypePrinter; TypePrinter.print(C->getType(), OS); OS << ' '; AsmWriterContext WriterCtx(&TypePrinter, MST.getMachine()); - WriteConstantInternal(OS, C, WriterCtx); + writeConstantInternal(OS, C, WriterCtx); } else if (isa<InlineAsm>(this) || isa<Argument>(this)) { this->printAsOperand(OS, /* PrintType */ true, MST); } else { @@ -5256,7 +5216,7 @@ static bool printWithoutType(const Value &V, raw_ostream &O, if (V.hasName() || isa<GlobalValue>(V) || (!isa<Constant>(V) && !isa<MetadataAsValue>(V))) { AsmWriterContext WriterCtx(nullptr, Machine, M); - WriteAsOperandInternal(O, &V, WriterCtx); + writeAsOperandInternal(O, &V, WriterCtx); return true; } return false; @@ -5265,13 +5225,8 @@ static bool printWithoutType(const Value &V, raw_ostream &O, static void printAsOperandImpl(const Value &V, raw_ostream &O, bool PrintType, ModuleSlotTracker &MST) { TypePrinting TypePrinter(MST.getModule()); - if (PrintType) { - TypePrinter.print(V.getType(), O); - O << ' '; - } - AsmWriterContext WriterCtx(&TypePrinter, MST.getMachine(), MST.getModule()); - WriteAsOperandInternal(O, &V, WriterCtx); + writeAsOperandInternal(O, &V, WriterCtx, PrintType); } void Value::printAsOperand(raw_ostream &O, bool PrintType, @@ -5302,14 +5257,14 @@ void Value::printAsOperand(raw_ostream &O, bool PrintType, static void printMetadataImplRec(raw_ostream &ROS, const Metadata &MD, AsmWriterContext &WriterCtx) { formatted_raw_ostream OS(ROS); - WriteAsOperandInternal(OS, &MD, WriterCtx, /* FromValue */ true); + writeAsOperandInternal(OS, &MD, WriterCtx, /* FromValue */ true); auto *N = dyn_cast<MDNode>(&MD); if (!N || isa<DIExpression>(MD)) return; OS << " = "; - WriteMDNodeBodyInternal(OS, N, WriterCtx); + writeMDNodeBodyInternal(OS, N, WriterCtx); } namespace { @@ -5370,14 +5325,14 @@ static void printMetadataImpl(raw_ostream &ROS, const Metadata &MD, WriterCtx = std::make_unique<AsmWriterContext>(&TypePrinter, MST.getMachine(), M); - WriteAsOperandInternal(OS, &MD, *WriterCtx, /* FromValue */ true); + writeAsOperandInternal(OS, &MD, *WriterCtx, /* FromValue */ true); auto *N = dyn_cast<MDNode>(&MD); if (OnlyAsOperand || !N || isa<DIExpression>(MD)) return; OS << " = "; - WriteMDNodeBodyInternal(OS, N, *WriterCtx); + writeMDNodeBodyInternal(OS, N, *WriterCtx); } void Metadata::printAsOperand(raw_ostream &OS, const Module *M) const { |