[llvm] [NFC][LLVM] Misc code cleanup in AsmWriter.cpp (PR #161522)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 1 07:54:57 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-ir
Author: Rahul Joshi (jurahul)
<details>
<summary>Changes</summary>
---
Patch is 50.16 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/161522.diff
1 Files Affected:
- (modified) llvm/lib/IR/AsmWriter.cpp (+195-212)
``````````diff
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index e29179b8f9955..245129f3f791f 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,
...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/161522
More information about the llvm-commits
mailing list