Skip to content

Commit 135bd09

Browse files
jurahulJaddyen
authored andcommitted
[LLVM][TableGen] Use StringRef for various members CGIOperandList::OperandInfo (llvm#140625)
- Change `Name`, `SubopNames`, `PrinterMethodName`, and `EncoderMethodNames` to be stored as StringRef. - Also changed `CheckComplexPatMatcher::Name` to StringRef as a fallout from the above. Verified that all the tablegen generated files within LLVM are unchanged.
1 parent 489c403 commit 135bd09

11 files changed

+83
-85
lines changed

llvm/utils/TableGen/AsmMatcherEmitter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1908,7 +1908,7 @@ void MatchableInfo::buildAliasResultOperands(bool AliasConstraintsAreChecked) {
19081908
}
19091909

19101910
// Handle all the suboperands for this operand.
1911-
const std::string &OpName = OpInfo.Name;
1911+
StringRef OpName = OpInfo.Name;
19121912
for (; AliasOpNo < LastOpNo &&
19131913
CGA.ResultInstOperandIndex[AliasOpNo].first == Idx;
19141914
++AliasOpNo) {

llvm/utils/TableGen/CodeEmitterGen.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ bool CodeEmitterGen::addCodeToMergeInOperand(const Record *R,
142142
}
143143

144144
std::pair<unsigned, unsigned> SO = CGI.Operands.getSubOperandNumber(OpIdx);
145-
std::string &EncoderMethodName =
145+
StringRef EncoderMethodName =
146146
CGI.Operands[SO.first].EncoderMethodNames[SO.second];
147147

148148
if (UseAPInt)
@@ -152,13 +152,14 @@ bool CodeEmitterGen::addCodeToMergeInOperand(const Record *R,
152152

153153
// If the source operand has a custom encoder, use it.
154154
if (!EncoderMethodName.empty()) {
155+
raw_string_ostream CaseOS(Case);
156+
CaseOS << indent(6);
155157
if (UseAPInt) {
156-
Case += " " + EncoderMethodName + "(MI, " + utostr(OpIdx);
157-
Case += ", op";
158+
CaseOS << EncoderMethodName << "(MI, " + utostr(OpIdx) << ", op";
158159
} else {
159-
Case += " op = " + EncoderMethodName + "(MI, " + utostr(OpIdx);
160+
CaseOS << "op = " << EncoderMethodName << "(MI, " << utostr(OpIdx);
160161
}
161-
Case += ", Fixups, STI);\n";
162+
CaseOS << ", Fixups, STI);\n";
162163
} else {
163164
if (UseAPInt) {
164165
Case +=

llvm/utils/TableGen/Common/AsmWriterInst.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ AsmWriterInst::AsmWriterInst(const CodeGenInstruction &CGI, unsigned CGIIndex,
177177
CGIOperandList::OperandInfo OpInfo = CGI.Operands[OpNo];
178178

179179
unsigned MIOp = OpInfo.MIOperandNo;
180-
Operands.emplace_back(OpInfo.PrinterMethodName, MIOp, Modifier,
180+
Operands.emplace_back(OpInfo.PrinterMethodName.str(), MIOp, Modifier,
181181
AsmWriterOperand::isMachineInstrOperand,
182182
OpInfo.OperandType == "MCOI::OPERAND_PCREL");
183183
}

llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2096,7 +2096,7 @@ void TreePatternNode::RemoveAllTypes() {
20962096
/// SubstituteFormalArguments - Replace the formal arguments in this tree
20972097
/// with actual values specified by ArgMap.
20982098
void TreePatternNode::SubstituteFormalArguments(
2099-
std::map<std::string, TreePatternNodePtr> &ArgMap) {
2099+
std::map<StringRef, TreePatternNodePtr> &ArgMap) {
21002100
if (isLeaf())
21012101
return;
21022102

@@ -2224,7 +2224,7 @@ void TreePatternNode::InlinePatternFragments(
22242224
Scope = TP.getDAGPatterns().allocateScope();
22252225

22262226
// Compute the map of formal to actual arguments.
2227-
std::map<std::string, TreePatternNodePtr> ArgMap;
2227+
std::map<StringRef, TreePatternNodePtr> ArgMap;
22282228
for (unsigned i = 0, e = Frag->getNumArgs(); i != e; ++i) {
22292229
TreePatternNodePtr Child = getChildShared(i);
22302230
if (Scope != 0) {
@@ -3441,7 +3441,7 @@ void CodeGenDAGPatterns::ParseDefaultOperands() {
34413441
/// HandleUse - Given "Pat" a leaf in the pattern, check to see if it is an
34423442
/// instruction input. Return true if this is a real use.
34433443
static bool HandleUse(TreePattern &I, TreePatternNodePtr Pat,
3444-
std::map<std::string, TreePatternNodePtr> &InstInputs) {
3444+
std::map<StringRef, TreePatternNodePtr> &InstInputs) {
34453445
// No name -> not interesting.
34463446
if (Pat->getName().empty()) {
34473447
if (Pat->isLeaf()) {
@@ -3495,11 +3495,8 @@ static bool HandleUse(TreePattern &I, TreePatternNodePtr Pat,
34953495
/// part of "I", the instruction), computing the set of inputs and outputs of
34963496
/// the pattern. Report errors if we see anything naughty.
34973497
void CodeGenDAGPatterns::FindPatternInputsAndOutputs(
3498-
TreePattern &I, TreePatternNodePtr Pat,
3499-
std::map<std::string, TreePatternNodePtr> &InstInputs,
3500-
MapVector<std::string, TreePatternNodePtr, std::map<std::string, unsigned>>
3501-
&InstResults,
3502-
std::vector<const Record *> &InstImpResults) {
3498+
TreePattern &I, TreePatternNodePtr Pat, InstInputsTy &InstInputs,
3499+
InstResultsTy &InstResults, std::vector<const Record *> &InstImpResults) {
35033500
// The instruction pattern still has unresolved fragments. For *named*
35043501
// nodes we must resolve those here. This may not result in multiple
35053502
// alternatives.
@@ -3816,11 +3813,11 @@ void CodeGenDAGPatterns::parseInstructionPattern(CodeGenInstruction &CGI,
38163813

38173814
// InstInputs - Keep track of all of the inputs of the instruction, along
38183815
// with the record they are declared as.
3819-
std::map<std::string, TreePatternNodePtr> InstInputs;
3816+
std::map<StringRef, TreePatternNodePtr> InstInputs;
38203817

38213818
// InstResults - Keep track of all the virtual registers that are 'set'
38223819
// in the instruction, including what reg class they are.
3823-
MapVector<std::string, TreePatternNodePtr, std::map<std::string, unsigned>>
3820+
MapVector<StringRef, TreePatternNodePtr, std::map<StringRef, unsigned>>
38243821
InstResults;
38253822

38263823
std::vector<const Record *> InstImpResults;
@@ -3862,18 +3859,17 @@ void CodeGenDAGPatterns::parseInstructionPattern(CodeGenInstruction &CGI,
38623859
SmallVector<TreePatternNodePtr, 2> ResNodes;
38633860
for (unsigned i = 0; i != NumResults; ++i) {
38643861
if (i == CGI.Operands.size()) {
3865-
const std::string &OpName =
3866-
llvm::find_if(
3867-
InstResults,
3868-
[](const std::pair<std::string, TreePatternNodePtr> &P) {
3869-
return P.second;
3870-
})
3862+
StringRef OpName =
3863+
llvm::find_if(InstResults,
3864+
[](const std::pair<StringRef, TreePatternNodePtr> &P) {
3865+
return P.second;
3866+
})
38713867
->first;
38723868

38733869
I.error("'" + OpName + "' set but does not appear in operand list!");
38743870
}
38753871

3876-
const std::string &OpName = CGI.Operands[i].Name;
3872+
StringRef OpName = CGI.Operands[i].Name;
38773873

38783874
// Check that it exists in InstResults.
38793875
auto InstResultIter = InstResults.find(OpName);
@@ -3906,7 +3902,7 @@ void CodeGenDAGPatterns::parseInstructionPattern(CodeGenInstruction &CGI,
39063902
std::vector<const Record *> Operands;
39073903
for (unsigned i = NumResults, e = CGI.Operands.size(); i != e; ++i) {
39083904
CGIOperandList::OperandInfo &Op = CGI.Operands[i];
3909-
const std::string &OpName = Op.Name;
3905+
StringRef OpName = Op.Name;
39103906
if (OpName.empty()) {
39113907
I.error("Operand #" + Twine(i) + " in operands list has no name!");
39123908
continue;
@@ -4050,7 +4046,7 @@ void CodeGenDAGPatterns::ParseInstructions() {
40504046
typedef std::pair<TreePatternNode *, unsigned> NameRecord;
40514047

40524048
static void FindNames(TreePatternNode &P,
4053-
std::map<std::string, NameRecord> &Names,
4049+
std::map<StringRef, NameRecord> &Names,
40544050
TreePattern *PatternTop) {
40554051
if (!P.getName().empty()) {
40564052
NameRecord &Rec = Names[P.getName()];
@@ -4088,7 +4084,7 @@ void CodeGenDAGPatterns::AddPatternToMatch(TreePattern *Pattern,
40884084

40894085
// Find all of the named values in the input and output, ensure they have the
40904086
// same type.
4091-
std::map<std::string, NameRecord> SrcNames, DstNames;
4087+
std::map<StringRef, NameRecord> SrcNames, DstNames;
40924088
FindNames(PTM.getSrcPattern(), SrcNames, Pattern);
40934089
FindNames(PTM.getDstPattern(), DstNames, Pattern);
40944090

@@ -4409,9 +4405,8 @@ void CodeGenDAGPatterns::ParsePatterns() {
44094405
"with temporaries yet!");
44104406

44114407
// Validate that the input pattern is correct.
4412-
std::map<std::string, TreePatternNodePtr> InstInputs;
4413-
MapVector<std::string, TreePatternNodePtr, std::map<std::string, unsigned>>
4414-
InstResults;
4408+
InstInputsTy InstInputs;
4409+
InstResultsTy InstResults;
44154410
std::vector<const Record *> InstImpResults;
44164411
for (unsigned j = 0, ee = Pattern.getNumTrees(); j != ee; ++j)
44174412
FindPatternInputsAndOutputs(Pattern, Pattern.getTree(j), InstInputs,

llvm/utils/TableGen/Common/CodeGenDAGPatterns.h

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ class TreePatternNode : public RefCountedBase<TreePatternNode> {
633633

634634
/// Name - The name given to this node with the :$foo notation.
635635
///
636-
std::string Name;
636+
StringRef Name;
637637

638638
std::vector<ScopedName> NamesAsPredicateArg;
639639

@@ -667,8 +667,8 @@ class TreePatternNode : public RefCountedBase<TreePatternNode> {
667667
}
668668

669669
bool hasName() const { return !Name.empty(); }
670-
const std::string &getName() const { return Name; }
671-
void setName(StringRef N) { Name.assign(N.begin(), N.end()); }
670+
StringRef getName() const { return Name; }
671+
void setName(StringRef N) { Name = N; }
672672

673673
const std::vector<ScopedName> &getNamesAsPredicateArg() const {
674674
return NamesAsPredicateArg;
@@ -826,7 +826,7 @@ class TreePatternNode : public RefCountedBase<TreePatternNode> {
826826
/// SubstituteFormalArguments - Replace the formal arguments in this tree
827827
/// with actual values specified by ArgMap.
828828
void
829-
SubstituteFormalArguments(std::map<std::string, TreePatternNodePtr> &ArgMap);
829+
SubstituteFormalArguments(std::map<StringRef, TreePatternNodePtr> &ArgMap);
830830

831831
/// InlinePatternFragments - If \p T pattern refers to any pattern
832832
/// fragments, return the set of inlined versions (this can be more than
@@ -1261,12 +1261,14 @@ class CodeGenDAGPatterns {
12611261
ArrayRef<const Record *> InstImpResults,
12621262
bool ShouldIgnore = false);
12631263
void AddPatternToMatch(TreePattern *Pattern, PatternToMatch &&PTM);
1264-
void FindPatternInputsAndOutputs(
1265-
TreePattern &I, TreePatternNodePtr Pat,
1266-
std::map<std::string, TreePatternNodePtr> &InstInputs,
1267-
MapVector<std::string, TreePatternNodePtr,
1268-
std::map<std::string, unsigned>> &InstResults,
1269-
std::vector<const Record *> &InstImpResults);
1264+
1265+
using InstInputsTy = std::map<StringRef, TreePatternNodePtr>;
1266+
using InstResultsTy =
1267+
MapVector<StringRef, TreePatternNodePtr, std::map<StringRef, unsigned>>;
1268+
void FindPatternInputsAndOutputs(TreePattern &I, TreePatternNodePtr Pat,
1269+
InstInputsTy &InstInputs,
1270+
InstResultsTy &InstResults,
1271+
std::vector<const Record *> &InstImpResults);
12701272
unsigned getNewUID();
12711273
};
12721274

llvm/utils/TableGen/Common/CodeGenInstruction.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,23 +78,23 @@ CGIOperandList::CGIOperandList(const Record *R) : TheDef(R) {
7878
"' instruction!");
7979

8080
const Record *Rec = Arg->getDef();
81-
std::string PrintMethod = "printOperand";
82-
std::string EncoderMethod;
81+
StringRef PrintMethod = "printOperand";
82+
StringRef EncoderMethod;
8383
std::string OperandType = "OPERAND_UNKNOWN";
8484
std::string OperandNamespace = "MCOI";
8585
unsigned NumOps = 1;
8686
const DagInit *MIOpInfo = nullptr;
8787
if (Rec->isSubClassOf("RegisterOperand")) {
88-
PrintMethod = Rec->getValueAsString("PrintMethod").str();
88+
PrintMethod = Rec->getValueAsString("PrintMethod");
8989
OperandType = Rec->getValueAsString("OperandType").str();
9090
OperandNamespace = Rec->getValueAsString("OperandNamespace").str();
91-
EncoderMethod = Rec->getValueAsString("EncoderMethod").str();
91+
EncoderMethod = Rec->getValueAsString("EncoderMethod");
9292
} else if (Rec->isSubClassOf("Operand")) {
93-
PrintMethod = Rec->getValueAsString("PrintMethod").str();
93+
PrintMethod = Rec->getValueAsString("PrintMethod");
9494
OperandType = Rec->getValueAsString("OperandType").str();
9595
OperandNamespace = Rec->getValueAsString("OperandNamespace").str();
9696
// If there is an explicit encoder method, use it.
97-
EncoderMethod = Rec->getValueAsString("EncoderMethod").str();
97+
EncoderMethod = Rec->getValueAsString("EncoderMethod");
9898
MIOpInfo = Rec->getValueAsDag("MIOperandInfo");
9999

100100
// Verify that MIOpInfo has an 'ops' root value.
@@ -139,8 +139,8 @@ CGIOperandList::CGIOperandList(const Record *R) : TheDef(R) {
139139
" has the same name as a previous operand!");
140140

141141
OperandInfo &OpInfo = OperandList.emplace_back(
142-
Rec, ArgName.str(), std::string(std::move(PrintMethod)),
143-
OperandNamespace + "::" + OperandType, MIOperandNo, NumOps, MIOpInfo);
142+
Rec, ArgName, PrintMethod, OperandNamespace + "::" + OperandType,
143+
MIOperandNo, NumOps, MIOpInfo);
144144

145145
if (SubArgDag) {
146146
if (SubArgDag->getNumArgs() != NumOps) {
@@ -182,7 +182,7 @@ CGIOperandList::CGIOperandList(const Record *R) : TheDef(R) {
182182
} else if (!EncoderMethod.empty()) {
183183
// If we have no explicit sub-op dag, but have an top-level encoder
184184
// method, the single encoder will multiple sub-ops, itself.
185-
OpInfo.EncoderMethodNames[0] = std::move(EncoderMethod);
185+
OpInfo.EncoderMethodNames[0] = EncoderMethod;
186186
for (unsigned j = 1; j < NumOps; ++j)
187187
OpInfo.DoNotEncode[j] = true;
188188
}

llvm/utils/TableGen/Common/CodeGenInstruction.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,18 @@ class CGIOperandList {
7777

7878
/// Name - If this operand was assigned a symbolic name, this is it,
7979
/// otherwise, it's empty.
80-
std::string Name;
80+
StringRef Name;
8181

8282
/// The names of sub-operands, if given, otherwise empty.
83-
std::vector<std::string> SubOpNames;
83+
std::vector<StringRef> SubOpNames;
8484

8585
/// PrinterMethodName - The method used to print operands of this type in
8686
/// the asmprinter.
87-
std::string PrinterMethodName;
87+
StringRef PrinterMethodName;
8888

8989
/// The method used to get the machine operand value for binary
9090
/// encoding, per sub-operand. If empty, uses "getMachineOpValue".
91-
std::vector<std::string> EncoderMethodNames;
91+
std::vector<StringRef> EncoderMethodNames;
9292

9393
/// OperandType - A value from MCOI::OperandType representing the type of
9494
/// the operand.
@@ -116,13 +116,13 @@ class CGIOperandList {
116116
/// track constraint info for each.
117117
std::vector<ConstraintInfo> Constraints;
118118

119-
OperandInfo(const Record *R, const std::string &N, const std::string &PMN,
119+
OperandInfo(const Record *R, StringRef Name, StringRef PrinterMethodName,
120120
const std::string &OT, unsigned MION, unsigned MINO,
121121
const DagInit *MIOI)
122-
: Rec(R), Name(N), SubOpNames(MINO), PrinterMethodName(PMN),
123-
EncoderMethodNames(MINO), OperandType(OT), MIOperandNo(MION),
124-
MINumOperands(MINO), DoNotEncode(MINO), MIOperandInfo(MIOI),
125-
Constraints(MINO) {}
122+
: Rec(R), Name(Name), SubOpNames(MINO),
123+
PrinterMethodName(PrinterMethodName), EncoderMethodNames(MINO),
124+
OperandType(OT), MIOperandNo(MION), MINumOperands(MINO),
125+
DoNotEncode(MINO), MIOperandInfo(MIOI), Constraints(MINO) {}
126126

127127
/// getTiedOperand - If this operand is tied to another one, return the
128128
/// other operand number. Otherwise, return -1.

llvm/utils/TableGen/Common/DAGISelMatcher.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -714,22 +714,22 @@ class CheckComplexPatMatcher : public Matcher {
714714
unsigned MatchNumber;
715715

716716
/// Name - The name of the node we're matching, for comment emission.
717-
std::string Name;
717+
StringRef Name;
718718

719719
/// FirstResult - This is the first slot in the RecordedNodes list that the
720720
/// result of the match populates.
721721
unsigned FirstResult;
722722

723723
public:
724724
CheckComplexPatMatcher(const ComplexPattern &pattern, unsigned matchnumber,
725-
const std::string &name, unsigned firstresult)
725+
StringRef name, unsigned firstresult)
726726
: Matcher(CheckComplexPat), Pattern(pattern), MatchNumber(matchnumber),
727727
Name(name), FirstResult(firstresult) {}
728728

729729
const ComplexPattern &getPattern() const { return Pattern; }
730730
unsigned getMatchNumber() const { return MatchNumber; }
731731

732-
std::string getName() const { return Name; }
732+
StringRef getName() const { return Name; }
733733
unsigned getFirstResult() const { return FirstResult; }
734734

735735
static bool classof(const Matcher *N) {

llvm/utils/TableGen/DAGISelMatcherGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ void MatcherGen::EmitMatchCode(const TreePatternNode &N,
508508
// we already saw this in the pattern, emit code to verify dagness.
509509
SmallVector<std::string, 4> Names;
510510
if (!N.getName().empty())
511-
Names.push_back(N.getName());
511+
Names.push_back(N.getName().str());
512512

513513
for (const ScopedName &Name : N.getNamesAsPredicateArg()) {
514514
Names.push_back(

llvm/utils/TableGen/DecoderEmitter.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1891,7 +1891,7 @@ static void debugDumpRecord(const Record &Rec) {
18911891
/// constant-valued bit values, and OpInfo.Fields with the ranges of bits to
18921892
/// insert from the decoded instruction.
18931893
static void addOneOperandFields(const Record &EncodingDef, const BitsInit &Bits,
1894-
std::map<std::string, std::string> &TiedNames,
1894+
std::map<StringRef, StringRef> &TiedNames,
18951895
StringRef OpName, OperandInfo &OpInfo) {
18961896
// Some bits of the operand may be required to be 1 depending on the
18971897
// instruction's encoding. Collect those bits.
@@ -1916,8 +1916,8 @@ static void addOneOperandFields(const Record &EncodingDef, const BitsInit &Bits,
19161916
} else {
19171917
Var = dyn_cast<VarInit>(Bits.getBit(J));
19181918
}
1919-
if (!Var || (Var->getName() != OpName &&
1920-
Var->getName() != TiedNames[OpName.str()]))
1919+
if (!Var ||
1920+
(Var->getName() != OpName && Var->getName() != TiedNames[OpName]))
19211921
break;
19221922
}
19231923
if (I == J)
@@ -1972,22 +1972,22 @@ populateInstruction(const CodeGenTarget &Target, const Record &EncodingDef,
19721972

19731973
// Search for tied operands, so that we can correctly instantiate
19741974
// operands that are not explicitly represented in the encoding.
1975-
std::map<std::string, std::string> TiedNames;
1976-
for (const auto &[I, Op] : enumerate(CGI.Operands)) {
1975+
std::map<StringRef, StringRef> TiedNames;
1976+
for (const auto &Op : CGI.Operands) {
19771977
for (const auto &[J, CI] : enumerate(Op.Constraints)) {
1978-
if (CI.isTied()) {
1979-
std::pair<unsigned, unsigned> SO =
1980-
CGI.Operands.getSubOperandNumber(CI.getTiedOperand());
1981-
std::string TiedName = CGI.Operands[SO.first].SubOpNames[SO.second];
1982-
if (TiedName.empty())
1983-
TiedName = CGI.Operands[SO.first].Name;
1984-
std::string MyName = Op.SubOpNames[J];
1985-
if (MyName.empty())
1986-
MyName = Op.Name;
1987-
1988-
TiedNames[MyName] = TiedName;
1989-
TiedNames[TiedName] = std::move(MyName);
1990-
}
1978+
if (!CI.isTied())
1979+
continue;
1980+
std::pair<unsigned, unsigned> SO =
1981+
CGI.Operands.getSubOperandNumber(CI.getTiedOperand());
1982+
StringRef TiedName = CGI.Operands[SO.first].SubOpNames[SO.second];
1983+
if (TiedName.empty())
1984+
TiedName = CGI.Operands[SO.first].Name;
1985+
StringRef MyName = Op.SubOpNames[J];
1986+
if (MyName.empty())
1987+
MyName = Op.Name;
1988+
1989+
TiedNames[MyName] = TiedName;
1990+
TiedNames[TiedName] = MyName;
19911991
}
19921992
}
19931993

0 commit comments

Comments
 (0)