aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/IR')
-rw-r--r--llvm/lib/IR/AsmWriter.cpp407
-rw-r--r--llvm/lib/IR/Instruction.cpp4
-rw-r--r--llvm/lib/IR/Instructions.cpp17
-rw-r--r--llvm/lib/IR/ProfDataUtils.cpp38
-rw-r--r--llvm/lib/IR/Value.cpp2
5 files changed, 236 insertions, 232 deletions
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index e29179b..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,33 +1464,30 @@ struct AsmWriterContext {
// AsmWriter Implementation
//===----------------------------------------------------------------------===//
-static void WriteAsOperandInternal(raw_ostream &Out, const Value *V,
+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())
@@ -1515,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,
@@ -1608,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()) {
@@ -1630,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()) {
@@ -1639,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 << ")";
@@ -1652,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]?]?)
@@ -1686,25 +1683,25 @@ static void WriteConstantInternal(raw_ostream &Out, const Constant *CV,
ListSeparator LS;
for (unsigned i = 0, e = NumOpsToWrite; i != e; ++i) {
Out << LS;
- WriteAsOperandInternal(Out, CPA->getOperand(i), WriterCtx,
+ writeAsOperandInternal(Out, CPA->getOperand(i), WriterCtx,
/*PrintType=*/true);
}
Out << ')';
return;
}
- if (const ConstantArray *CA = dyn_cast<ConstantArray>(CV)) {
+ if (const auto *CA = dyn_cast<ConstantArray>(CV)) {
Out << '[';
ListSeparator LS;
for (const Value *Op : CA->operands()) {
Out << LS;
- WriteAsOperandInternal(Out, Op, WriterCtx, /*PrintType=*/true);
+ 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()) {
@@ -1718,14 +1715,14 @@ static void WriteConstantInternal(raw_ostream &Out, const Constant *CV,
ListSeparator LS;
for (uint64_t i = 0, e = CA->getNumElements(); i != e; ++i) {
Out << LS;
- 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 << '{';
@@ -1734,7 +1731,7 @@ static void WriteConstantInternal(raw_ostream &Out, const Constant *CV,
ListSeparator LS;
for (const Value *Op : CS->operands()) {
Out << LS;
- WriteAsOperandInternal(Out, Op, WriterCtx, /*PrintType=*/true);
+ writeAsOperandInternal(Out, Op, WriterCtx, /*PrintType=*/true);
}
Out << ' ';
}
@@ -1755,7 +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 (";
- WriteAsOperandInternal(Out, SplatVal, WriterCtx, /*PrintType=*/true);
+ writeAsOperandInternal(Out, SplatVal, WriterCtx, /*PrintType=*/true);
Out << ')';
return;
}
@@ -1765,7 +1762,7 @@ static void WriteConstantInternal(raw_ostream &Out, const Constant *CV,
ListSeparator LS;
for (unsigned i = 0, e = CVVTy->getNumElements(); i != e; ++i) {
Out << LS;
- WriteAsOperandInternal(Out, CV->getAggregateElement(i), WriterCtx,
+ writeAsOperandInternal(Out, CV->getAggregateElement(i), WriterCtx,
/*PrintType=*/true);
}
Out << '>';
@@ -1792,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.
@@ -1802,7 +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 (";
- WriteAsOperandInternal(Out, SplatVal, WriterCtx, /*PrintType=*/true);
+ writeAsOperandInternal(Out, SplatVal, WriterCtx, /*PrintType=*/true);
Out << ')';
return;
}
@@ -1810,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 << ", ";
}
@@ -1821,7 +1818,7 @@ static void WriteConstantInternal(raw_ostream &Out, const Constant *CV,
ListSeparator LS;
for (const Value *Op : CE->operands()) {
Out << LS;
- WriteAsOperandInternal(Out, Op, WriterCtx, /*PrintType=*/true);
+ writeAsOperandInternal(Out, Op, WriterCtx, /*PrintType=*/true);
}
if (CE->isCast()) {
@@ -1830,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;
@@ -1849,9 +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();
- WriteAsOperandInternal(Out, V, WriterCtx, /*PrintType=*/true);
+ writeAsOperandInternal(Out, V, WriterCtx, /*PrintType=*/true);
} else {
- WriteAsOperandInternal(Out, MD, WriterCtx);
+ writeAsOperandInternal(Out, MD, WriterCtx);
WriterCtx.onWriteMetadataAsOperand(MD);
}
}
@@ -1939,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);
}
@@ -2619,7 +2616,7 @@ static void writeDIArgList(raw_ostream &Out, const DIArgList *N,
MDFieldPrinter Printer(Out, WriterCtx);
for (const Metadata *Arg : N->getArgs()) {
Out << FS;
- WriteAsOperandInternal(Out, Arg, WriterCtx, true);
+ writeAsOperandInternal(Out, Arg, WriterCtx, true);
}
Out << ")";
}
@@ -2662,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 ";
@@ -2682,7 +2679,7 @@ 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,
+static void writeAsOperandInternal(raw_ostream &Out, const Value *V,
AsmWriterContext &WriterCtx,
bool PrintType) {
if (PrintType) {
@@ -2691,18 +2688,18 @@ static void WriteAsOperandInternal(raw_ostream &Out, const Value *V,
}
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 ";
@@ -2722,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;
}
@@ -2732,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 {
@@ -2749,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 {
@@ -2767,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) {
@@ -2790,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;
}
@@ -2802,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 << '"';
@@ -2814,7 +2811,7 @@ static void WriteAsOperandInternal(raw_ostream &Out, const Metadata *MD,
assert((FromValue || !isa<LocalAsMetadata>(V)) &&
"Unexpected function-local metadata outside of value argument");
- WriteAsOperandInternal(Out, V->getValue(), WriterCtx, /*PrintType=*/true);
+ writeAsOperandInternal(Out, V->getValue(), WriterCtx, /*PrintType=*/true);
}
namespace {
@@ -2889,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();
@@ -2901,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.
@@ -2953,7 +2948,7 @@ void AssemblyWriter::writeOperand(const Value *Operand, bool PrintType) {
return;
}
auto WriteCtx = getContext();
- WriteAsOperandInternal(Out, Operand, WriteCtx, PrintType);
+ writeAsOperandInternal(Out, Operand, WriteCtx, PrintType);
}
void AssemblyWriter::writeSyncScope(const LLVMContext &Context,
@@ -3013,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) {
@@ -3039,7 +3034,7 @@ void AssemblyWriter::writeOperandBundles(const CallBase *Call) {
if (Input == nullptr)
Out << "<null operand bundle!>";
else
- WriteAsOperandInternal(Out, Input, WriterCtx, /*PrintType=*/true);
+ writeAsOperandInternal(Out, Input, WriterCtx, /*PrintType=*/true);
}
Out << ')';
@@ -3311,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) {
@@ -3658,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) {
@@ -3669,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) {
@@ -3793,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;
@@ -3802,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;
@@ -3817,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:
@@ -3863,7 +3851,7 @@ static void maybePrintComdat(formatted_raw_ostream &Out,
return;
Out << '(';
- PrintLLVMName(Out, C->getName(), ComdatPrefix);
+ printLLVMName(Out, C->getName(), ComdatPrefix);
Out << ')';
}
@@ -3872,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 << ' ';
@@ -3963,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 << ' ';
@@ -4002,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 ";
@@ -4059,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
@@ -4107,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 << " ";
}
@@ -4123,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...
@@ -4239,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");
@@ -4252,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";
@@ -4370,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.
@@ -4381,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())
@@ -4409,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...
@@ -4459,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)
@@ -4540,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();
@@ -4587,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();
@@ -4596,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())
@@ -4630,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();
@@ -4639,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())
@@ -4675,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 ";
@@ -4697,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 << ' ';
@@ -4714,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);
@@ -4763,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.
@@ -4840,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 << "(";
@@ -4874,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 << ")";
}
@@ -4899,7 +4889,7 @@ void AssemblyWriter::printMetadataAttachments(
} else
Out << "!<unknown kind #" << Kind << ">";
Out << ' ';
- WriteAsOperandInternal(Out, I.second, WriterCtx);
+ writeAsOperandInternal(Out, I.second, WriterCtx);
}
}
@@ -4922,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) {
@@ -4941,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;
}
}
@@ -4963,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 << " ";
@@ -5052,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()) {
@@ -5084,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);
@@ -5120,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);
}
@@ -5141,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);
}
@@ -5158,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);
}
@@ -5185,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 {
@@ -5233,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;
@@ -5243,7 +5226,7 @@ static void printAsOperandImpl(const Value &V, raw_ostream &O, bool PrintType,
ModuleSlotTracker &MST) {
TypePrinting TypePrinter(MST.getModule());
AsmWriterContext WriterCtx(&TypePrinter, MST.getMachine(), MST.getModule());
- WriteAsOperandInternal(O, &V, WriterCtx, PrintType);
+ writeAsOperandInternal(O, &V, WriterCtx, PrintType);
}
void Value::printAsOperand(raw_ostream &O, bool PrintType,
@@ -5274,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 {
@@ -5342,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 {
diff --git a/llvm/lib/IR/Instruction.cpp b/llvm/lib/IR/Instruction.cpp
index a8bb34f..33ca46c 100644
--- a/llvm/lib/IR/Instruction.cpp
+++ b/llvm/lib/IR/Instruction.cpp
@@ -30,6 +30,8 @@
#include "llvm/Support/Compiler.h"
using namespace llvm;
+namespace llvm {
+
// FIXME: Flag used for an ablation performance test, Issue #147390. Placing it
// here because referencing IR should be feasible from anywhere. Will be
// removed after the ablation test.
@@ -38,6 +40,8 @@ cl::opt<bool> ProfcheckDisableMetadataFixes(
cl::desc(
"Disable metadata propagation fixes discovered through Issue #147390"));
+} // end namespace llvm
+
InsertPosition::InsertPosition(Instruction *InsertBefore)
: InsertAt(InsertBefore ? InsertBefore->getIterator()
: InstListType::iterator()) {}
diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp
index dd83168..941e41f 100644
--- a/llvm/lib/IR/Instructions.cpp
+++ b/llvm/lib/IR/Instructions.cpp
@@ -4141,23 +4141,6 @@ void SwitchInst::growOperands() {
growHungoffUses(ReservedSpace);
}
-MDNode *SwitchInstProfUpdateWrapper::buildProfBranchWeightsMD() {
- assert(Changed && "called only if metadata has changed");
-
- if (!Weights)
- return nullptr;
-
- assert(SI.getNumSuccessors() == Weights->size() &&
- "num of prof branch_weights must accord with num of successors");
-
- bool AllZeroes = all_of(*Weights, [](uint32_t W) { return W == 0; });
-
- if (AllZeroes || Weights->size() < 2)
- return nullptr;
-
- return MDBuilder(SI.getParent()->getContext()).createBranchWeights(*Weights);
-}
-
void SwitchInstProfUpdateWrapper::init() {
MDNode *ProfileData = getBranchWeightMDNode(SI);
if (!ProfileData)
diff --git a/llvm/lib/IR/ProfDataUtils.cpp b/llvm/lib/IR/ProfDataUtils.cpp
index 99029c1..edeca97 100644
--- a/llvm/lib/IR/ProfDataUtils.cpp
+++ b/llvm/lib/IR/ProfDataUtils.cpp
@@ -12,6 +12,7 @@
#include "llvm/IR/ProfDataUtils.h"
+#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/Function.h"
@@ -19,6 +20,7 @@
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/MDBuilder.h"
#include "llvm/IR/Metadata.h"
+#include "llvm/Support/CommandLine.h"
using namespace llvm;
@@ -84,10 +86,31 @@ static void extractFromBranchWeightMD(const MDNode *ProfileData,
}
}
+/// Push the weights right to fit in uint32_t.
+static SmallVector<uint32_t> fitWeights(ArrayRef<uint64_t> Weights) {
+ SmallVector<uint32_t> Ret;
+ Ret.reserve(Weights.size());
+ uint64_t Max = *llvm::max_element(Weights);
+ if (Max > UINT_MAX) {
+ unsigned Offset = 32 - llvm::countl_zero(Max);
+ for (const uint64_t &Value : Weights)
+ Ret.push_back(static_cast<uint32_t>(Value >> Offset));
+ } else {
+ append_range(Ret, Weights);
+ }
+ return Ret;
+}
+
} // namespace
namespace llvm {
-
+cl::opt<bool> ElideAllZeroBranchWeights("elide-all-zero-branch-weights",
+#if defined(LLVM_ENABLE_PROFCHECK)
+ cl::init(false)
+#else
+ cl::init(true)
+#endif
+);
const char *MDProfLabels::BranchWeights = "branch_weights";
const char *MDProfLabels::ExpectedBranchWeights = "expected";
const char *MDProfLabels::ValueProfile = "VP";
@@ -282,12 +305,23 @@ bool hasExplicitlyUnknownBranchWeights(const Instruction &I) {
}
void setBranchWeights(Instruction &I, ArrayRef<uint32_t> Weights,
- bool IsExpected) {
+ bool IsExpected, bool ElideAllZero) {
+ if ((ElideAllZeroBranchWeights && ElideAllZero) &&
+ llvm::all_of(Weights, [](uint32_t V) { return V == 0; })) {
+ I.setMetadata(LLVMContext::MD_prof, nullptr);
+ return;
+ }
+
MDBuilder MDB(I.getContext());
MDNode *BranchWeights = MDB.createBranchWeights(Weights, IsExpected);
I.setMetadata(LLVMContext::MD_prof, BranchWeights);
}
+void setFittedBranchWeights(Instruction &I, ArrayRef<uint64_t> Weights,
+ bool IsExpected, bool ElideAllZero) {
+ setBranchWeights(I, fitWeights(Weights), IsExpected, ElideAllZero);
+}
+
SmallVector<uint32_t> downscaleWeights(ArrayRef<uint64_t> Weights,
std::optional<uint64_t> KnownMaxCount) {
uint64_t MaxCount = KnownMaxCount.has_value() ? KnownMaxCount.value()
diff --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp
index e5e062d..a347609 100644
--- a/llvm/lib/IR/Value.cpp
+++ b/llvm/lib/IR/Value.cpp
@@ -36,7 +36,7 @@
using namespace llvm;
-cl::opt<bool> UseDerefAtPointSemantics(
+static cl::opt<bool> UseDerefAtPointSemantics(
"use-dereferenceable-at-point-semantics", cl::Hidden, cl::init(false),
cl::desc("Deref attributes and metadata infer facts at definition only"));