[llvm] [NFC][ADT/Support] Add {} for else when if body has {} (PR #140758)
Rahul Joshi via llvm-commits
llvm-commits at lists.llvm.org
Tue May 20 09:32:08 PDT 2025
https://github.com/jurahul created https://github.com/llvm/llvm-project/pull/140758
None
>From 89624c116a04b96fc3d1a1b5360cbaf3c8474c45 Mon Sep 17 00:00:00 2001
From: Rahul Joshi <rjoshi at nvidia.com>
Date: Mon, 19 May 2025 07:56:58 -0700
Subject: [PATCH 1/3] [LLVM][TableGen] Use StringRef
---
llvm/utils/TableGen/AsmMatcherEmitter.cpp | 2 +-
llvm/utils/TableGen/CodeEmitterGen.cpp | 4 +-
llvm/utils/TableGen/Common/AsmWriterInst.cpp | 2 +-
.../TableGen/Common/CodeGenDAGPatterns.cpp | 41 ++++++++-----------
.../TableGen/Common/CodeGenDAGPatterns.h | 22 +++++-----
.../TableGen/Common/CodeGenInstruction.cpp | 18 ++++----
.../TableGen/Common/CodeGenInstruction.h | 18 ++++----
llvm/utils/TableGen/Common/DAGISelMatcher.h | 6 +--
llvm/utils/TableGen/DAGISelMatcherGen.cpp | 2 +-
llvm/utils/TableGen/DecoderEmitter.cpp | 36 ++++++++--------
llvm/utils/TableGen/GlobalISelEmitter.cpp | 10 ++---
11 files changed, 79 insertions(+), 82 deletions(-)
diff --git a/llvm/utils/TableGen/AsmMatcherEmitter.cpp b/llvm/utils/TableGen/AsmMatcherEmitter.cpp
index 2771facb004cc..9792eb41ea5d7 100644
--- a/llvm/utils/TableGen/AsmMatcherEmitter.cpp
+++ b/llvm/utils/TableGen/AsmMatcherEmitter.cpp
@@ -1908,7 +1908,7 @@ void MatchableInfo::buildAliasResultOperands(bool AliasConstraintsAreChecked) {
}
// Handle all the suboperands for this operand.
- const std::string &OpName = OpInfo.Name;
+ StringRef OpName = OpInfo.Name;
for (; AliasOpNo < LastOpNo &&
CGA.ResultInstOperandIndex[AliasOpNo].first == Idx;
++AliasOpNo) {
diff --git a/llvm/utils/TableGen/CodeEmitterGen.cpp b/llvm/utils/TableGen/CodeEmitterGen.cpp
index 83c0330f7d3eb..0e19b4d60c5c2 100644
--- a/llvm/utils/TableGen/CodeEmitterGen.cpp
+++ b/llvm/utils/TableGen/CodeEmitterGen.cpp
@@ -142,8 +142,8 @@ bool CodeEmitterGen::addCodeToMergeInOperand(const Record *R,
}
std::pair<unsigned, unsigned> SO = CGI.Operands.getSubOperandNumber(OpIdx);
- std::string &EncoderMethodName =
- CGI.Operands[SO.first].EncoderMethodNames[SO.second];
+ const std::string EncoderMethodName =
+ CGI.Operands[SO.first].EncoderMethodNames[SO.second].str();
if (UseAPInt)
Case += " op.clearAllBits();\n";
diff --git a/llvm/utils/TableGen/Common/AsmWriterInst.cpp b/llvm/utils/TableGen/Common/AsmWriterInst.cpp
index 1fa609e900051..3629247751d2f 100644
--- a/llvm/utils/TableGen/Common/AsmWriterInst.cpp
+++ b/llvm/utils/TableGen/Common/AsmWriterInst.cpp
@@ -177,7 +177,7 @@ AsmWriterInst::AsmWriterInst(const CodeGenInstruction &CGI, unsigned CGIIndex,
CGIOperandList::OperandInfo OpInfo = CGI.Operands[OpNo];
unsigned MIOp = OpInfo.MIOperandNo;
- Operands.emplace_back(OpInfo.PrinterMethodName, MIOp, Modifier,
+ Operands.emplace_back(OpInfo.PrinterMethodName.str(), MIOp, Modifier,
AsmWriterOperand::isMachineInstrOperand,
OpInfo.OperandType == "MCOI::OPERAND_PCREL");
}
diff --git a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
index f03cbd9a170e2..3029604adcc36 100644
--- a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
+++ b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
@@ -2096,7 +2096,7 @@ void TreePatternNode::RemoveAllTypes() {
/// SubstituteFormalArguments - Replace the formal arguments in this tree
/// with actual values specified by ArgMap.
void TreePatternNode::SubstituteFormalArguments(
- std::map<std::string, TreePatternNodePtr> &ArgMap) {
+ std::map<StringRef, TreePatternNodePtr> &ArgMap) {
if (isLeaf())
return;
@@ -2224,7 +2224,7 @@ void TreePatternNode::InlinePatternFragments(
Scope = TP.getDAGPatterns().allocateScope();
// Compute the map of formal to actual arguments.
- std::map<std::string, TreePatternNodePtr> ArgMap;
+ std::map<StringRef, TreePatternNodePtr> ArgMap;
for (unsigned i = 0, e = Frag->getNumArgs(); i != e; ++i) {
TreePatternNodePtr Child = getChildShared(i);
if (Scope != 0) {
@@ -3441,7 +3441,7 @@ void CodeGenDAGPatterns::ParseDefaultOperands() {
/// HandleUse - Given "Pat" a leaf in the pattern, check to see if it is an
/// instruction input. Return true if this is a real use.
static bool HandleUse(TreePattern &I, TreePatternNodePtr Pat,
- std::map<std::string, TreePatternNodePtr> &InstInputs) {
+ std::map<StringRef, TreePatternNodePtr> &InstInputs) {
// No name -> not interesting.
if (Pat->getName().empty()) {
if (Pat->isLeaf()) {
@@ -3495,11 +3495,8 @@ static bool HandleUse(TreePattern &I, TreePatternNodePtr Pat,
/// part of "I", the instruction), computing the set of inputs and outputs of
/// the pattern. Report errors if we see anything naughty.
void CodeGenDAGPatterns::FindPatternInputsAndOutputs(
- TreePattern &I, TreePatternNodePtr Pat,
- std::map<std::string, TreePatternNodePtr> &InstInputs,
- MapVector<std::string, TreePatternNodePtr, std::map<std::string, unsigned>>
- &InstResults,
- std::vector<const Record *> &InstImpResults) {
+ TreePattern &I, TreePatternNodePtr Pat, InstInputsTy &InstInputs,
+ InstResultsTy &InstResults, std::vector<const Record *> &InstImpResults) {
// The instruction pattern still has unresolved fragments. For *named*
// nodes we must resolve those here. This may not result in multiple
// alternatives.
@@ -3816,11 +3813,11 @@ void CodeGenDAGPatterns::parseInstructionPattern(CodeGenInstruction &CGI,
// InstInputs - Keep track of all of the inputs of the instruction, along
// with the record they are declared as.
- std::map<std::string, TreePatternNodePtr> InstInputs;
+ std::map<StringRef, TreePatternNodePtr> InstInputs;
// InstResults - Keep track of all the virtual registers that are 'set'
// in the instruction, including what reg class they are.
- MapVector<std::string, TreePatternNodePtr, std::map<std::string, unsigned>>
+ MapVector<StringRef, TreePatternNodePtr, std::map<StringRef, unsigned>>
InstResults;
std::vector<const Record *> InstImpResults;
@@ -3862,18 +3859,17 @@ void CodeGenDAGPatterns::parseInstructionPattern(CodeGenInstruction &CGI,
SmallVector<TreePatternNodePtr, 2> ResNodes;
for (unsigned i = 0; i != NumResults; ++i) {
if (i == CGI.Operands.size()) {
- const std::string &OpName =
- llvm::find_if(
- InstResults,
- [](const std::pair<std::string, TreePatternNodePtr> &P) {
- return P.second;
- })
+ StringRef OpName =
+ llvm::find_if(InstResults,
+ [](const std::pair<StringRef, TreePatternNodePtr> &P) {
+ return P.second;
+ })
->first;
I.error("'" + OpName + "' set but does not appear in operand list!");
}
- const std::string &OpName = CGI.Operands[i].Name;
+ StringRef OpName = CGI.Operands[i].Name;
// Check that it exists in InstResults.
auto InstResultIter = InstResults.find(OpName);
@@ -3906,7 +3902,7 @@ void CodeGenDAGPatterns::parseInstructionPattern(CodeGenInstruction &CGI,
std::vector<const Record *> Operands;
for (unsigned i = NumResults, e = CGI.Operands.size(); i != e; ++i) {
CGIOperandList::OperandInfo &Op = CGI.Operands[i];
- const std::string &OpName = Op.Name;
+ StringRef OpName = Op.Name;
if (OpName.empty()) {
I.error("Operand #" + Twine(i) + " in operands list has no name!");
continue;
@@ -4050,7 +4046,7 @@ void CodeGenDAGPatterns::ParseInstructions() {
typedef std::pair<TreePatternNode *, unsigned> NameRecord;
static void FindNames(TreePatternNode &P,
- std::map<std::string, NameRecord> &Names,
+ std::map<StringRef, NameRecord> &Names,
TreePattern *PatternTop) {
if (!P.getName().empty()) {
NameRecord &Rec = Names[P.getName()];
@@ -4088,7 +4084,7 @@ void CodeGenDAGPatterns::AddPatternToMatch(TreePattern *Pattern,
// Find all of the named values in the input and output, ensure they have the
// same type.
- std::map<std::string, NameRecord> SrcNames, DstNames;
+ std::map<StringRef, NameRecord> SrcNames, DstNames;
FindNames(PTM.getSrcPattern(), SrcNames, Pattern);
FindNames(PTM.getDstPattern(), DstNames, Pattern);
@@ -4409,9 +4405,8 @@ void CodeGenDAGPatterns::ParsePatterns() {
"with temporaries yet!");
// Validate that the input pattern is correct.
- std::map<std::string, TreePatternNodePtr> InstInputs;
- MapVector<std::string, TreePatternNodePtr, std::map<std::string, unsigned>>
- InstResults;
+ InstInputsTy InstInputs;
+ InstResultsTy InstResults;
std::vector<const Record *> InstImpResults;
for (unsigned j = 0, ee = Pattern.getNumTrees(); j != ee; ++j)
FindPatternInputsAndOutputs(Pattern, Pattern.getTree(j), InstInputs,
diff --git a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.h b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.h
index 364c82e1233bd..725414f8f68d9 100644
--- a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.h
+++ b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.h
@@ -633,7 +633,7 @@ class TreePatternNode : public RefCountedBase<TreePatternNode> {
/// Name - The name given to this node with the :$foo notation.
///
- std::string Name;
+ StringRef Name;
std::vector<ScopedName> NamesAsPredicateArg;
@@ -667,8 +667,8 @@ class TreePatternNode : public RefCountedBase<TreePatternNode> {
}
bool hasName() const { return !Name.empty(); }
- const std::string &getName() const { return Name; }
- void setName(StringRef N) { Name.assign(N.begin(), N.end()); }
+ StringRef getName() const { return Name; }
+ void setName(StringRef N) { Name = N; }
const std::vector<ScopedName> &getNamesAsPredicateArg() const {
return NamesAsPredicateArg;
@@ -826,7 +826,7 @@ class TreePatternNode : public RefCountedBase<TreePatternNode> {
/// SubstituteFormalArguments - Replace the formal arguments in this tree
/// with actual values specified by ArgMap.
void
- SubstituteFormalArguments(std::map<std::string, TreePatternNodePtr> &ArgMap);
+ SubstituteFormalArguments(std::map<StringRef, TreePatternNodePtr> &ArgMap);
/// InlinePatternFragments - If \p T pattern refers to any pattern
/// fragments, return the set of inlined versions (this can be more than
@@ -1261,12 +1261,14 @@ class CodeGenDAGPatterns {
ArrayRef<const Record *> InstImpResults,
bool ShouldIgnore = false);
void AddPatternToMatch(TreePattern *Pattern, PatternToMatch &&PTM);
- void FindPatternInputsAndOutputs(
- TreePattern &I, TreePatternNodePtr Pat,
- std::map<std::string, TreePatternNodePtr> &InstInputs,
- MapVector<std::string, TreePatternNodePtr,
- std::map<std::string, unsigned>> &InstResults,
- std::vector<const Record *> &InstImpResults);
+
+ using InstInputsTy = std::map<StringRef, TreePatternNodePtr>;
+ using InstResultsTy =
+ MapVector<StringRef, TreePatternNodePtr, std::map<StringRef, unsigned>>;
+ void FindPatternInputsAndOutputs(TreePattern &I, TreePatternNodePtr Pat,
+ InstInputsTy &InstInputs,
+ InstResultsTy &InstResults,
+ std::vector<const Record *> &InstImpResults);
unsigned getNewUID();
};
diff --git a/llvm/utils/TableGen/Common/CodeGenInstruction.cpp b/llvm/utils/TableGen/Common/CodeGenInstruction.cpp
index 281df2302605e..0dfcf200d7e4b 100644
--- a/llvm/utils/TableGen/Common/CodeGenInstruction.cpp
+++ b/llvm/utils/TableGen/Common/CodeGenInstruction.cpp
@@ -78,23 +78,23 @@ CGIOperandList::CGIOperandList(const Record *R) : TheDef(R) {
"' instruction!");
const Record *Rec = Arg->getDef();
- std::string PrintMethod = "printOperand";
- std::string EncoderMethod;
+ StringRef PrintMethod = "printOperand";
+ StringRef EncoderMethod;
std::string OperandType = "OPERAND_UNKNOWN";
std::string OperandNamespace = "MCOI";
unsigned NumOps = 1;
const DagInit *MIOpInfo = nullptr;
if (Rec->isSubClassOf("RegisterOperand")) {
- PrintMethod = Rec->getValueAsString("PrintMethod").str();
+ PrintMethod = Rec->getValueAsString("PrintMethod");
OperandType = Rec->getValueAsString("OperandType").str();
OperandNamespace = Rec->getValueAsString("OperandNamespace").str();
- EncoderMethod = Rec->getValueAsString("EncoderMethod").str();
+ EncoderMethod = Rec->getValueAsString("EncoderMethod");
} else if (Rec->isSubClassOf("Operand")) {
- PrintMethod = Rec->getValueAsString("PrintMethod").str();
+ PrintMethod = Rec->getValueAsString("PrintMethod");
OperandType = Rec->getValueAsString("OperandType").str();
OperandNamespace = Rec->getValueAsString("OperandNamespace").str();
// If there is an explicit encoder method, use it.
- EncoderMethod = Rec->getValueAsString("EncoderMethod").str();
+ EncoderMethod = Rec->getValueAsString("EncoderMethod");
MIOpInfo = Rec->getValueAsDag("MIOperandInfo");
// Verify that MIOpInfo has an 'ops' root value.
@@ -139,8 +139,8 @@ CGIOperandList::CGIOperandList(const Record *R) : TheDef(R) {
" has the same name as a previous operand!");
OperandInfo &OpInfo = OperandList.emplace_back(
- Rec, ArgName.str(), std::string(std::move(PrintMethod)),
- OperandNamespace + "::" + OperandType, MIOperandNo, NumOps, MIOpInfo);
+ Rec, ArgName, PrintMethod, OperandNamespace + "::" + OperandType,
+ MIOperandNo, NumOps, MIOpInfo);
if (SubArgDag) {
if (SubArgDag->getNumArgs() != NumOps) {
@@ -182,7 +182,7 @@ CGIOperandList::CGIOperandList(const Record *R) : TheDef(R) {
} else if (!EncoderMethod.empty()) {
// If we have no explicit sub-op dag, but have an top-level encoder
// method, the single encoder will multiple sub-ops, itself.
- OpInfo.EncoderMethodNames[0] = std::move(EncoderMethod);
+ OpInfo.EncoderMethodNames[0] = EncoderMethod;
for (unsigned j = 1; j < NumOps; ++j)
OpInfo.DoNotEncode[j] = true;
}
diff --git a/llvm/utils/TableGen/Common/CodeGenInstruction.h b/llvm/utils/TableGen/Common/CodeGenInstruction.h
index 44c0ab70dc615..e38979af3909d 100644
--- a/llvm/utils/TableGen/Common/CodeGenInstruction.h
+++ b/llvm/utils/TableGen/Common/CodeGenInstruction.h
@@ -77,18 +77,18 @@ class CGIOperandList {
/// Name - If this operand was assigned a symbolic name, this is it,
/// otherwise, it's empty.
- std::string Name;
+ StringRef Name;
/// The names of sub-operands, if given, otherwise empty.
- std::vector<std::string> SubOpNames;
+ std::vector<StringRef> SubOpNames;
/// PrinterMethodName - The method used to print operands of this type in
/// the asmprinter.
- std::string PrinterMethodName;
+ StringRef PrinterMethodName;
/// The method used to get the machine operand value for binary
/// encoding, per sub-operand. If empty, uses "getMachineOpValue".
- std::vector<std::string> EncoderMethodNames;
+ std::vector<StringRef> EncoderMethodNames;
/// OperandType - A value from MCOI::OperandType representing the type of
/// the operand.
@@ -116,13 +116,13 @@ class CGIOperandList {
/// track constraint info for each.
std::vector<ConstraintInfo> Constraints;
- OperandInfo(const Record *R, const std::string &N, const std::string &PMN,
+ OperandInfo(const Record *R, StringRef Name, StringRef PrinterMethodName,
const std::string &OT, unsigned MION, unsigned MINO,
const DagInit *MIOI)
- : Rec(R), Name(N), SubOpNames(MINO), PrinterMethodName(PMN),
- EncoderMethodNames(MINO), OperandType(OT), MIOperandNo(MION),
- MINumOperands(MINO), DoNotEncode(MINO), MIOperandInfo(MIOI),
- Constraints(MINO) {}
+ : Rec(R), Name(Name), SubOpNames(MINO),
+ PrinterMethodName(PrinterMethodName), EncoderMethodNames(MINO),
+ OperandType(OT), MIOperandNo(MION), MINumOperands(MINO),
+ DoNotEncode(MINO), MIOperandInfo(MIOI), Constraints(MINO) {}
/// getTiedOperand - If this operand is tied to another one, return the
/// other operand number. Otherwise, return -1.
diff --git a/llvm/utils/TableGen/Common/DAGISelMatcher.h b/llvm/utils/TableGen/Common/DAGISelMatcher.h
index 07c00d3c8c53b..b11c1366ef5f0 100644
--- a/llvm/utils/TableGen/Common/DAGISelMatcher.h
+++ b/llvm/utils/TableGen/Common/DAGISelMatcher.h
@@ -714,7 +714,7 @@ class CheckComplexPatMatcher : public Matcher {
unsigned MatchNumber;
/// Name - The name of the node we're matching, for comment emission.
- std::string Name;
+ StringRef Name;
/// FirstResult - This is the first slot in the RecordedNodes list that the
/// result of the match populates.
@@ -722,14 +722,14 @@ class CheckComplexPatMatcher : public Matcher {
public:
CheckComplexPatMatcher(const ComplexPattern &pattern, unsigned matchnumber,
- const std::string &name, unsigned firstresult)
+ StringRef name, unsigned firstresult)
: Matcher(CheckComplexPat), Pattern(pattern), MatchNumber(matchnumber),
Name(name), FirstResult(firstresult) {}
const ComplexPattern &getPattern() const { return Pattern; }
unsigned getMatchNumber() const { return MatchNumber; }
- std::string getName() const { return Name; }
+ StringRef getName() const { return Name; }
unsigned getFirstResult() const { return FirstResult; }
static bool classof(const Matcher *N) {
diff --git a/llvm/utils/TableGen/DAGISelMatcherGen.cpp b/llvm/utils/TableGen/DAGISelMatcherGen.cpp
index aec9a8796870b..a1ab06defb456 100644
--- a/llvm/utils/TableGen/DAGISelMatcherGen.cpp
+++ b/llvm/utils/TableGen/DAGISelMatcherGen.cpp
@@ -508,7 +508,7 @@ void MatcherGen::EmitMatchCode(const TreePatternNode &N,
// we already saw this in the pattern, emit code to verify dagness.
SmallVector<std::string, 4> Names;
if (!N.getName().empty())
- Names.push_back(N.getName());
+ Names.push_back(N.getName().str());
for (const ScopedName &Name : N.getNamesAsPredicateArg()) {
Names.push_back(
diff --git a/llvm/utils/TableGen/DecoderEmitter.cpp b/llvm/utils/TableGen/DecoderEmitter.cpp
index 3f00cd8229f7c..bf1802e5e06cd 100644
--- a/llvm/utils/TableGen/DecoderEmitter.cpp
+++ b/llvm/utils/TableGen/DecoderEmitter.cpp
@@ -1891,7 +1891,7 @@ static void debugDumpRecord(const Record &Rec) {
/// constant-valued bit values, and OpInfo.Fields with the ranges of bits to
/// insert from the decoded instruction.
static void addOneOperandFields(const Record &EncodingDef, const BitsInit &Bits,
- std::map<std::string, std::string> &TiedNames,
+ std::map<StringRef, StringRef> &TiedNames,
StringRef OpName, OperandInfo &OpInfo) {
// Some bits of the operand may be required to be 1 depending on the
// instruction's encoding. Collect those bits.
@@ -1916,8 +1916,8 @@ static void addOneOperandFields(const Record &EncodingDef, const BitsInit &Bits,
} else {
Var = dyn_cast<VarInit>(Bits.getBit(J));
}
- if (!Var || (Var->getName() != OpName &&
- Var->getName() != TiedNames[OpName.str()]))
+ if (!Var ||
+ (Var->getName() != OpName && Var->getName() != TiedNames[OpName]))
break;
}
if (I == J)
@@ -1972,22 +1972,22 @@ populateInstruction(const CodeGenTarget &Target, const Record &EncodingDef,
// Search for tied operands, so that we can correctly instantiate
// operands that are not explicitly represented in the encoding.
- std::map<std::string, std::string> TiedNames;
- for (const auto &[I, Op] : enumerate(CGI.Operands)) {
+ std::map<StringRef, StringRef> TiedNames;
+ for (const auto &Op : CGI.Operands) {
for (const auto &[J, CI] : enumerate(Op.Constraints)) {
- if (CI.isTied()) {
- std::pair<unsigned, unsigned> SO =
- CGI.Operands.getSubOperandNumber(CI.getTiedOperand());
- std::string TiedName = CGI.Operands[SO.first].SubOpNames[SO.second];
- if (TiedName.empty())
- TiedName = CGI.Operands[SO.first].Name;
- std::string MyName = Op.SubOpNames[J];
- if (MyName.empty())
- MyName = Op.Name;
-
- TiedNames[MyName] = TiedName;
- TiedNames[TiedName] = std::move(MyName);
- }
+ if (!CI.isTied())
+ continue;
+ std::pair<unsigned, unsigned> SO =
+ CGI.Operands.getSubOperandNumber(CI.getTiedOperand());
+ StringRef TiedName = CGI.Operands[SO.first].SubOpNames[SO.second];
+ if (TiedName.empty())
+ TiedName = CGI.Operands[SO.first].Name;
+ StringRef MyName = Op.SubOpNames[J];
+ if (MyName.empty())
+ MyName = Op.Name;
+
+ TiedNames[MyName] = TiedName;
+ TiedNames[TiedName] = MyName;
}
}
diff --git a/llvm/utils/TableGen/GlobalISelEmitter.cpp b/llvm/utils/TableGen/GlobalISelEmitter.cpp
index d516879f088d3..edaf5299efc39 100644
--- a/llvm/utils/TableGen/GlobalISelEmitter.cpp
+++ b/llvm/utils/TableGen/GlobalISelEmitter.cpp
@@ -849,7 +849,7 @@ Expected<InstructionMatcher &> GlobalISelEmitter::createAndImportSelDAGMatcher(
const Init *SrcInit = Src.getLeafValue();
if (const IntInit *SrcIntInit = dyn_cast<IntInit>(SrcInit)) {
OperandMatcher &OM =
- InsnMatcher.addOperand(OpIdx++, Src.getName(), TempOpIdx);
+ InsnMatcher.addOperand(OpIdx++, Src.getName().str(), TempOpIdx);
OM.addPredicate<LiteralIntOperandMatcher>(SrcIntInit->getValue());
} else {
return failedImport(
@@ -883,8 +883,8 @@ Expected<InstructionMatcher &> GlobalISelEmitter::createAndImportSelDAGMatcher(
if (!CCDef || !CCDef->isSubClassOf("CondCode"))
return failedImport("Unable to handle CondCode");
- OperandMatcher &OM =
- InsnMatcher.addOperand(OpIdx++, SrcChild.getName(), TempOpIdx);
+ OperandMatcher &OM = InsnMatcher.addOperand(
+ OpIdx++, SrcChild.getName().str(), TempOpIdx);
StringRef PredType = IsFCmp ? CCDef->getValueAsString("FCmpPredicate")
: CCDef->getValueAsString("ICmpPredicate");
@@ -930,8 +930,8 @@ Expected<InstructionMatcher &> GlobalISelEmitter::createAndImportSelDAGMatcher(
// For G_INTRINSIC/G_INTRINSIC_W_SIDE_EFFECTS, the operand immediately
// following the defs is an intrinsic ID.
if (I == 0) {
- OperandMatcher &OM =
- InsnMatcher.addOperand(OpIdx++, SrcChild.getName(), TempOpIdx);
+ OperandMatcher &OM = InsnMatcher.addOperand(
+ OpIdx++, SrcChild.getName().str(), TempOpIdx);
OM.addPredicate<IntrinsicIDOperandMatcher>(II);
continue;
}
>From 503401773f7502473a470184bf80263e8298d8c0 Mon Sep 17 00:00:00 2001
From: Rahul Joshi <rjoshi at nvidia.com>
Date: Tue, 20 May 2025 08:21:10 -0700
Subject: [PATCH 2/3] Review feedback
---
llvm/utils/TableGen/CodeEmitterGen.cpp | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/llvm/utils/TableGen/CodeEmitterGen.cpp b/llvm/utils/TableGen/CodeEmitterGen.cpp
index 0e19b4d60c5c2..2fe40450abfda 100644
--- a/llvm/utils/TableGen/CodeEmitterGen.cpp
+++ b/llvm/utils/TableGen/CodeEmitterGen.cpp
@@ -142,8 +142,8 @@ bool CodeEmitterGen::addCodeToMergeInOperand(const Record *R,
}
std::pair<unsigned, unsigned> SO = CGI.Operands.getSubOperandNumber(OpIdx);
- const std::string EncoderMethodName =
- CGI.Operands[SO.first].EncoderMethodNames[SO.second].str();
+ StringRef EncoderMethodName =
+ CGI.Operands[SO.first].EncoderMethodNames[SO.second];
if (UseAPInt)
Case += " op.clearAllBits();\n";
@@ -152,13 +152,14 @@ bool CodeEmitterGen::addCodeToMergeInOperand(const Record *R,
// If the source operand has a custom encoder, use it.
if (!EncoderMethodName.empty()) {
+ raw_string_ostream CaseOS(Case);
+ CaseOS << indent(6);
if (UseAPInt) {
- Case += " " + EncoderMethodName + "(MI, " + utostr(OpIdx);
- Case += ", op";
+ CaseOS << EncoderMethodName << "(MI, " + utostr(OpIdx) << ", op";
} else {
- Case += " op = " + EncoderMethodName + "(MI, " + utostr(OpIdx);
+ CaseOS << "op = " << EncoderMethodName << "(MI, " << utostr(OpIdx);
}
- Case += ", Fixups, STI);\n";
+ CaseOS << ", Fixups, STI);\n";
} else {
if (UseAPInt) {
Case +=
>From 1cfa93db2360128897115a183895e35d428633cf Mon Sep 17 00:00:00 2001
From: Rahul Joshi <rjoshi at nvidia.com>
Date: Tue, 20 May 2025 09:29:11 -0700
Subject: [PATCH 3/3] [NFC][ADT/Support] Add {} for else when if body has {}
---
llvm/include/llvm/ADT/IntervalMap.h | 3 ++-
llvm/include/llvm/ADT/STLExtras.h | 6 +++--
llvm/include/llvm/ADT/SmallBitVector.h | 6 +++--
llvm/include/llvm/ADT/Twine.h | 3 ++-
llvm/include/llvm/Support/Error.h | 6 +++--
.../llvm/Support/GenericLoopInfoImpl.h | 5 ++--
llvm/include/llvm/Support/GraphWriter.h | 3 ++-
llvm/include/llvm/Support/YAMLParser.h | 3 ++-
llvm/lib/Support/APFixedPoint.cpp | 15 ++++++++----
llvm/lib/Support/APFloat.cpp | 13 ++++++----
llvm/lib/Support/APInt.cpp | 6 +++--
llvm/lib/Support/CommandLine.cpp | 3 ++-
llvm/lib/Support/Mustache.cpp | 3 ++-
llvm/lib/Support/PrettyStackTrace.cpp | 3 ++-
llvm/lib/Support/ScaledNumber.cpp | 6 +++--
llvm/lib/Support/Unix/Path.inc | 6 +++--
llvm/lib/Support/Windows/Path.inc | 6 +++--
llvm/lib/Support/YAMLParser.cpp | 24 ++++++++++---------
llvm/lib/Support/regcomp.c | 24 +++++++++++--------
19 files changed, 90 insertions(+), 54 deletions(-)
diff --git a/llvm/include/llvm/ADT/IntervalMap.h b/llvm/include/llvm/ADT/IntervalMap.h
index 3463194fb301a..cb5943dc60e0e 100644
--- a/llvm/include/llvm/ADT/IntervalMap.h
+++ b/llvm/include/llvm/ADT/IntervalMap.h
@@ -2132,9 +2132,10 @@ class IntervalMapOverlaps {
posB.advanceTo(posA.start());
if (!posB.valid() || !Traits::stopLess(posA.stop(), posB.start()))
return;
- } else
+ } else {
// Already overlapping.
return;
+ }
while (true) {
// Make a.end > b.start.
diff --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h
index 8926489faf391..897dc76a420b2 100644
--- a/llvm/include/llvm/ADT/STLExtras.h
+++ b/llvm/include/llvm/ADT/STLExtras.h
@@ -1804,8 +1804,9 @@ T *find_singleton(R &&Range, Predicate P, bool AllowRepeats = false) {
if (RC) {
if (!AllowRepeats || PRC != RC)
return nullptr;
- } else
+ } else {
RC = PRC;
+ }
}
}
return RC;
@@ -1835,8 +1836,9 @@ std::pair<T *, bool> find_singleton_nested(R &&Range, Predicate P,
if (RC) {
if (!AllowRepeats || PRC.first != RC)
return {nullptr, true};
- } else
+ } else {
RC = PRC.first;
+ }
}
}
return {RC, false};
diff --git a/llvm/include/llvm/ADT/SmallBitVector.h b/llvm/include/llvm/ADT/SmallBitVector.h
index c538a4d4023b2..5b2a5221b791f 100644
--- a/llvm/include/llvm/ADT/SmallBitVector.h
+++ b/llvm/include/llvm/ADT/SmallBitVector.h
@@ -393,8 +393,9 @@ class SmallBitVector {
uintptr_t IMask = ((uintptr_t)1) << I;
uintptr_t Mask = EMask - IMask;
setSmallBits(getSmallBits() | Mask);
- } else
+ } else {
getPointer()->set(I, E);
+ }
return *this;
}
@@ -424,8 +425,9 @@ class SmallBitVector {
uintptr_t IMask = ((uintptr_t)1) << I;
uintptr_t Mask = EMask - IMask;
setSmallBits(getSmallBits() & ~Mask);
- } else
+ } else {
getPointer()->reset(I, E);
+ }
return *this;
}
diff --git a/llvm/include/llvm/ADT/Twine.h b/llvm/include/llvm/ADT/Twine.h
index 7718150780e3a..4501f928834e2 100644
--- a/llvm/include/llvm/ADT/Twine.h
+++ b/llvm/include/llvm/ADT/Twine.h
@@ -275,8 +275,9 @@ namespace llvm {
if (Str[0] != '\0') {
LHS.cString = Str;
LHSKind = CStringKind;
- } else
+ } else {
LHSKind = EmptyKind;
+ }
assert(isValid() && "Invalid twine!");
}
diff --git a/llvm/include/llvm/Support/Error.h b/llvm/include/llvm/Support/Error.h
index b0bcdd55e4831..9bb952ceb0dc2 100644
--- a/llvm/include/llvm/Support/Error.h
+++ b/llvm/include/llvm/Support/Error.h
@@ -418,8 +418,9 @@ class LLVM_ABI ErrorList final : public ErrorInfo<ErrorList> {
auto &E2List = static_cast<ErrorList &>(*E2Payload);
for (auto &Payload : E2List.Payloads)
E1List.Payloads.push_back(std::move(Payload));
- } else
+ } else {
E1List.Payloads.push_back(E2.takePayload());
+ }
return E1;
}
@@ -714,10 +715,11 @@ template <class T> class [[nodiscard]] Expected {
if (HasError) {
dbgs() << "Unchecked Expected<T> contained error:\n";
(*getErrorStorage())->log(dbgs());
- } else
+ } else {
dbgs() << "Expected<T> value was in success state. (Note: Expected<T> "
"values in success mode must still be checked prior to being "
"destroyed).\n";
+ }
abort();
}
#endif
diff --git a/llvm/include/llvm/Support/GenericLoopInfoImpl.h b/llvm/include/llvm/Support/GenericLoopInfoImpl.h
index dd5d805544eaa..6fc508b0e0cca 100644
--- a/llvm/include/llvm/Support/GenericLoopInfoImpl.h
+++ b/llvm/include/llvm/Support/GenericLoopInfoImpl.h
@@ -425,8 +425,9 @@ void LoopBase<BlockT, LoopT>::print(raw_ostream &OS, bool Verbose,
if (i)
OS << ",";
BB->printAsOperand(OS, false);
- } else
- OS << "\n";
+ } else {
+ OS << '\n';
+ }
if (BB == H)
OS << "<header>";
diff --git a/llvm/include/llvm/Support/GraphWriter.h b/llvm/include/llvm/Support/GraphWriter.h
index 8b619a3a9c3ce..39a4c0befbb89 100644
--- a/llvm/include/llvm/Support/GraphWriter.h
+++ b/llvm/include/llvm/Support/GraphWriter.h
@@ -200,8 +200,9 @@ class GraphWriter {
O << "<<table border=\"0\" cellborder=\"1\" cellspacing=\"0\""
<< " cellpadding=\"0\"><tr><td align=\"text\" colspan=\"" << ColSpan
<< "\">";
- } else
+ } else {
O << "\"{";
+ }
if (!DTraits.renderGraphFromBottomUp()) {
if (RenderUsingHTML)
diff --git a/llvm/include/llvm/Support/YAMLParser.h b/llvm/include/llvm/Support/YAMLParser.h
index da645f2848e90..c64ef53c3afaa 100644
--- a/llvm/include/llvm/Support/YAMLParser.h
+++ b/llvm/include/llvm/Support/YAMLParser.h
@@ -27,8 +27,9 @@
// yaml::Node *n = di->getRoot();
// if (n) {
// // Do something with n...
-// } else
+// } else {
// break;
+// }
// }
//
//===----------------------------------------------------------------------===//
diff --git a/llvm/lib/Support/APFixedPoint.cpp b/llvm/lib/Support/APFixedPoint.cpp
index 9a7caa4112625..e8f0e786fcfda 100644
--- a/llvm/lib/Support/APFixedPoint.cpp
+++ b/llvm/lib/Support/APFixedPoint.cpp
@@ -289,8 +289,9 @@ APFixedPoint APFixedPoint::mul(const APFixedPoint &Other,
Result = Min;
else if (Result > Max)
Result = Max;
- } else
+ } else {
Overflowed = Result < Min || Result > Max;
+ }
if (Overflow)
*Overflow = Overflowed;
@@ -335,8 +336,9 @@ APFixedPoint APFixedPoint::div(const APFixedPoint &Other,
// towards negative infinity by subtracting epsilon from the result.
if (ThisVal.isNegative() != OtherVal.isNegative() && !Rem.isZero())
Result = Result - 1;
- } else
+ } else {
Result = ThisVal.udiv(OtherVal);
+ }
Result.setIsSigned(CommonFXSema.isSigned());
// If our result lies outside of the representative range of the common
@@ -350,8 +352,9 @@ APFixedPoint APFixedPoint::div(const APFixedPoint &Other,
Result = Min;
else if (Result > Max)
Result = Max;
- } else
+ } else {
Overflowed = Result < Min || Result > Max;
+ }
if (Overflow)
*Overflow = Overflowed;
@@ -385,8 +388,9 @@ APFixedPoint APFixedPoint::shl(unsigned Amt, bool *Overflow) const {
Result = Min;
else if (Result > Max)
Result = Max;
- } else
+ } else {
Overflowed = Result < Min || Result > Max;
+ }
if (Overflow)
*Overflow = Overflowed;
@@ -612,8 +616,9 @@ APFixedPoint::getFromFloatValue(const APFloat &Value,
Res = getMax(DstFXSema).getValue();
else if (Val < FloatMin)
Res = getMin(DstFXSema).getValue();
- } else
+ } else {
Overflowed = Val > FloatMax || Val < FloatMin;
+ }
if (Overflow)
*Overflow = Overflowed;
diff --git a/llvm/lib/Support/APFloat.cpp b/llvm/lib/Support/APFloat.cpp
index e99649d26ce88..5e0b29ffb2590 100644
--- a/llvm/lib/Support/APFloat.cpp
+++ b/llvm/lib/Support/APFloat.cpp
@@ -893,8 +893,9 @@ writeSignedDecimal (char *dst, int value)
if (value < 0) {
*dst++ = '-';
dst = writeUnsignedDecimal(dst, -(unsigned) value);
- } else
+ } else {
dst = writeUnsignedDecimal(dst, value);
+ }
return dst;
}
@@ -2814,8 +2815,8 @@ APFloat::opStatus IEEEFloat::convertToSignExtendedInteger(
if (lost_fraction == lfExactlyZero) {
*isExact = true;
return opOK;
- } else
- return opInexact;
+ }
+ return opInexact;
}
/* Same as convertToSignExtendedInteger, except we provide
@@ -3302,8 +3303,9 @@ bool IEEEFloat::convertFromStringSpecials(StringRef str) {
if (str.size() > 1 && tolower(str[1]) == 'x') {
str = str.drop_front(2);
Radix = 16;
- } else
+ } else {
Radix = 8;
+ }
}
// Parse the payload and make the NaN.
@@ -4529,8 +4531,9 @@ void IEEEFloat::toString(SmallVectorImpl<char> &Str, unsigned FormatPrecision,
Str.append(FormatPrecision - 1, '0');
append(Str, "e+00");
}
- } else
+ } else {
Str.push_back('0');
+ }
return;
case fcNormal:
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp
index 0119cb2f6e1f7..a9f6f11ab5673 100644
--- a/llvm/lib/Support/APInt.cpp
+++ b/llvm/lib/Support/APInt.cpp
@@ -885,8 +885,9 @@ double APInt::roundToDouble(bool isSigned) const {
if (isSigned) {
int64_t sext = SignExtend64(getWord(0), BitWidth);
return double(sext);
- } else
+ } else {
return double(getWord(0));
+ }
}
// Determine if the value is negative.
@@ -2578,8 +2579,9 @@ int APInt::tcMultiplyPart(WordType *dst, const WordType *src,
if (low + dst[i] < low)
high++;
dst[i] += low;
- } else
+ } else {
dst[i] = low;
+ }
carry = high;
}
diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp
index ced7e7bc8a028..d5c3cba13e030 100644
--- a/llvm/lib/Support/CommandLine.cpp
+++ b/llvm/lib/Support/CommandLine.cpp
@@ -2692,8 +2692,9 @@ void HelpPrinterWrapper::operator=(bool Value) {
CommonOptions->HLOp.setHiddenFlag(NotHidden);
CategorizedPrinter = true; // Invoke categorized printer
- } else
+ } else {
UncategorizedPrinter = true; // Invoke uncategorized printer
+ }
}
// Print the value of each option.
diff --git a/llvm/lib/Support/Mustache.cpp b/llvm/lib/Support/Mustache.cpp
index 222587e19b31f..89900ed4d03a5 100644
--- a/llvm/lib/Support/Mustache.cpp
+++ b/llvm/lib/Support/Mustache.cpp
@@ -660,8 +660,9 @@ const json::Value *ASTNode::findContext() {
CurrentContext = CurrentValue->getAsObject();
if (!CurrentContext)
return nullptr;
- } else
+ } else {
Context = CurrentValue;
+ }
}
return Context;
}
diff --git a/llvm/lib/Support/PrettyStackTrace.cpp b/llvm/lib/Support/PrettyStackTrace.cpp
index 9b09384e95bfe..3f03368c5d22e 100644
--- a/llvm/lib/Support/PrettyStackTrace.cpp
+++ b/llvm/lib/Support/PrettyStackTrace.cpp
@@ -185,8 +185,9 @@ static void CrashHandler(void *) {
if (!crashHandlerString.empty()) {
setCrashLogMessage(crashHandlerString.c_str());
errs() << crashHandlerString.str();
- } else
+ } else {
setCrashLogMessage("No crash information.");
+ }
#endif
}
diff --git a/llvm/lib/Support/ScaledNumber.cpp b/llvm/lib/Support/ScaledNumber.cpp
index 85d7afbea5c69..4d5923e3634b1 100644
--- a/llvm/lib/Support/ScaledNumber.cpp
+++ b/llvm/lib/Support/ScaledNumber.cpp
@@ -240,8 +240,9 @@ std::string ScaledNumberBase::toString(uint64_t D, int16_t E, int Width,
if (Above0) {
appendNumber(Str, Above0);
DigitsOut = Str.size();
- } else
+ } else {
appendDigit(Str, 0);
+ }
std::reverse(Str.begin(), Str.end());
// Return early if there's nothing after the decimal.
@@ -262,8 +263,9 @@ std::string ScaledNumberBase::toString(uint64_t D, int16_t E, int Width,
if (ExtraShift) {
--ExtraShift;
Error *= 5;
- } else
+ } else {
Error *= 10;
+ }
Below0 *= 10;
Extra *= 10;
diff --git a/llvm/lib/Support/Unix/Path.inc b/llvm/lib/Support/Unix/Path.inc
index fae12f7efffe8..0728413f4db6e 100644
--- a/llvm/lib/Support/Unix/Path.inc
+++ b/llvm/lib/Support/Unix/Path.inc
@@ -389,8 +389,9 @@ std::error_code current_path(SmallVectorImpl<char> &result) {
}
// Otherwise there just wasn't enough space.
result.resize_for_overwrite(result.capacity() * 2);
- } else
+ } else {
break;
+ }
}
result.truncate(strlen(result.data()));
@@ -938,8 +939,9 @@ std::error_code detail::directory_iterator_increment(detail::DirIterState &It) {
(Name.size() == 2 && Name[0] == '.' && Name[1] == '.'))
return directory_iterator_increment(It);
It.CurrentEntry.replace_filename(Name, direntType(CurDir));
- } else
+ } else {
return directory_iterator_destruct(It);
+ }
return std::error_code();
}
diff --git a/llvm/lib/Support/Windows/Path.inc b/llvm/lib/Support/Windows/Path.inc
index 5b311e7c475c5..0afd0141b525a 100644
--- a/llvm/lib/Support/Windows/Path.inc
+++ b/llvm/lib/Support/Windows/Path.inc
@@ -118,8 +118,9 @@ std::error_code widenPath(const Twine &Path8, SmallVectorImpl<wchar_t> &Path16,
if (RootName[1] != ':') { // Check if UNC.
FullPath.append("UNC\\");
FullPath.append(Path8Str.begin() + 2, Path8Str.end());
- } else
+ } else {
FullPath.append(Path8Str);
+ }
return UTF8ToUTF16(FullPath, Path16);
}
@@ -1057,8 +1058,9 @@ std::error_code detail::directory_iterator_construct(detail::DirIterState &IT,
if (LastError == ERROR_NO_MORE_FILES)
return detail::directory_iterator_destruct(IT);
return mapWindowsError(LastError);
- } else
+ } else {
FilenameLen = ::wcslen(FirstFind.cFileName);
+ }
// Construct the current directory entry.
SmallString<128> DirectoryEntryNameUTF8;
diff --git a/llvm/lib/Support/YAMLParser.cpp b/llvm/lib/Support/YAMLParser.cpp
index d2bedbaf0119f..fa5db46598905 100644
--- a/llvm/lib/Support/YAMLParser.cpp
+++ b/llvm/lib/Support/YAMLParser.cpp
@@ -761,8 +761,9 @@ std::string yaml::escape(StringRef Input, bool EscapePrintable) {
EscapedInput += "\\U" + std::string(8 - HexStr.size(), '0') + HexStr;
}
i += UnicodeScalarValue.second - 1;
- } else
+ } else {
EscapedInput.push_back(*i);
+ }
}
return EscapedInput;
}
@@ -1011,17 +1012,16 @@ void Scanner::scan_ns_uri_char() {
while (true) {
if (Current == End)
break;
- if (( *Current == '%'
- && Current + 2 < End
- && is_ns_hex_digit(*(Current + 1))
- && is_ns_hex_digit(*(Current + 2)))
- || is_ns_word_char(*Current)
- || StringRef(Current, 1).find_first_of("#;/?:@&=+$,_.!~*'()[]")
- != StringRef::npos) {
+ if ((*Current == '%' && Current + 2 < End &&
+ is_ns_hex_digit(*(Current + 1)) && is_ns_hex_digit(*(Current + 2))) ||
+ is_ns_word_char(*Current) ||
+ StringRef(Current, 1).find_first_of("#;/?:@&=+$,_.!~*'()[]") !=
+ StringRef::npos) {
++Current;
++Column;
- } else
+ } else {
break;
+ }
}
}
@@ -1105,8 +1105,9 @@ void Scanner::removeStaleSimpleKeyCandidates() {
setError( "Could not find expected : for simple key"
, i->Tok->Range.begin());
i = SimpleKeys.erase(i);
- } else
+ } else {
++i;
+ }
}
}
@@ -2631,8 +2632,9 @@ bool Document::parseDirectives() {
} else if (T.Kind == Token::TK_VersionDirective) {
parseYAMLDirective();
isDirective = true;
- } else
+ } else {
break;
+ }
}
return isDirective;
}
diff --git a/llvm/lib/Support/regcomp.c b/llvm/lib/Support/regcomp.c
index daa41eb4912ef..ab0b581c6db4c 100644
--- a/llvm/lib/Support/regcomp.c
+++ b/llvm/lib/Support/regcomp.c
@@ -311,10 +311,11 @@ llvm_regcomp(llvm_regex_t *preg, const char *pattern, int cflags)
if (preg->re_endp < pattern)
return(REG_INVARG);
len = preg->re_endp - pattern;
- } else
- len = strlen((const char *)pattern);
+ } else {
+ len = strlen((const char *)pattern);
+ }
- /* do the mallocs early so failure handling is easy */
+ /* do the mallocs early so failure handling is easy */
g = (struct re_guts *)malloc(sizeof(struct re_guts) +
(NC-1)*sizeof(cat_t));
if (g == NULL)
@@ -728,9 +729,10 @@ p_simp_re(struct parse *p,
assert(OP(p->strip[p->pend[i]]) == ORPAREN);
(void) dupl(p, p->pbegin[i]+1, p->pend[i]);
EMIT(O_BACK, i);
- } else
- SETERROR(REG_ESUBREG);
- p->g->backrefs = 1;
+ } else {
+ SETERROR(REG_ESUBREG);
+ }
+ p->g->backrefs = 1;
break;
case '*':
REQUIRE(starordinary, REG_BADRPT);
@@ -867,8 +869,9 @@ p_bracket(struct parse *p)
if (nch(p, cs) == 1) { /* optimize singleton sets */
ordinary(p, firstch(p, cs));
freeset(p, cs);
- } else
- EMIT(OANYOF, freezeset(p, cs));
+ } else {
+ EMIT(OANYOF, freezeset(p, cs));
+ }
}
/*
@@ -924,8 +927,9 @@ p_b_term(struct parse *p, cset *cs)
finish = '-';
else
finish = p_b_symbol(p);
- } else
- finish = start;
+ } else {
+ finish = start;
+ }
/* xxx what about signed chars here... */
REQUIRE(start <= finish, REG_ERANGE);
for (i = start; i <= finish; i++)
More information about the llvm-commits
mailing list