llvm.org GIT mirror llvm / 0c517c8
TableGen: Use StringRef instead of const std::string& in return vals. This will allow to switch to a different string storage in an upcoming commit. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288612 91177308-0d34-0410-b5e6-96231b3b80d8 Matthias Braun 3 years ago
20 changed file(s) with 52 addition(s) and 49 deletion(s). Raw diff Collapse all Expand all
616616
617617 static StringInit *get(StringRef);
618618
619 const std::string &getValue() const { return Value; }
619 StringRef getValue() const { return Value; }
620620
621621 Init *convertInitializerTo(RecTy *Ty) const override;
622622
654654
655655 static CodeInit *get(StringRef);
656656
657 const std::string &getValue() const { return Value; }
657 StringRef getValue() const { return Value; }
658658
659659 Init *convertInitializerTo(RecTy *Ty) const override;
660660
963963 static VarInit *get(StringRef VN, RecTy *T);
964964 static VarInit *get(Init *VN, RecTy *T);
965965
966 const std::string &getName() const;
966 StringRef getName() const;
967967 Init *getNameInit() const { return VarName; }
968968
969969 std::string getNameInitAsString() const {
11781178
11791179 Init *getOperator() const { return Val; }
11801180
1181 const std::string &getName() const { return ValName; }
1181 StringRef getName() const { return ValName; }
11821182
11831183 unsigned getNumArgs() const { return Args.size(); }
11841184 Init *getArg(unsigned Num) const {
11851185 assert(Num < Args.size() && "Arg number out of range!");
11861186 return Args[Num];
11871187 }
1188 const std::string &getArgName(unsigned Num) const {
1188 StringRef getArgName(unsigned Num) const {
11891189 assert(Num < ArgNames.size() && "Arg number out of range!");
11901190 return ArgNames[Num];
11911191 }
12321232 RecordVal(Init *N, RecTy *T, bool P);
12331233 RecordVal(StringRef N, RecTy *T, bool P);
12341234
1235 const std::string &getName() const;
1235 StringRef getName() const;
12361236 const Init *getNameInit() const { return NameAndPrefix.getPointer(); }
12371237
12381238 std::string getNameInitAsString() const {
13231323
13241324 unsigned getID() const { return ID; }
13251325
1326 const std::string &getName() const;
1326 StringRef getName() const;
13271327 Init *getNameInit() const {
13281328 return Name;
13291329 }
4646 TableGenStringKey(StringRef str) : data(str) {}
4747 TableGenStringKey(const char *str) : data(str) {}
4848
49 const std::string &str() const { return data; }
49 StringRef str() const { return data; }
5050
5151 friend hash_code hash_value(const TableGenStringKey &Value) {
5252 using llvm::hash_value;
666666 return StringInit::get(LHSi->getAsString());
667667 } else {
668668 if (StringInit *LHSs = dyn_cast(LHS)) {
669 const std::string &Name = LHSs->getValue();
669 StringRef Name = LHSs->getValue();
670670
671671 // From TGParser::ParseIDValue
672672 if (CurRec) {
12971297 return I.get();
12981298 }
12991299
1300 const std::string &VarInit::getName() const {
1300 StringRef VarInit::getName() const {
13011301 StringInit *NameString = cast(getNameInit());
13021302 return NameString->getValue();
13031303 }
16111611 assert(Value && "Cannot create unset value for current type!");
16121612 }
16131613
1614 const std::string &RecordVal::getName() const {
1614 StringRef RecordVal::getName() const {
16151615 return cast(getNameInit())->getValue();
16161616 }
16171617
16511651 return TheInit.get();
16521652 }
16531653
1654 const std::string &Record::getName() const {
1654 StringRef Record::getName() const {
16551655 return cast(Name)->getValue();
16561656 }
16571657
12881288
12891289 if (CI->ValueName.empty()) {
12901290 CI->ClassName = Rec->getName();
1291 CI->Name = "MCK_" + Rec->getName();
1291 CI->Name = "MCK_" + Rec->getName().str();
12921292 CI->ValueName = Rec->getName();
12931293 } else
1294 CI->ValueName = CI->ValueName + "," + Rec->getName();
1294 CI->ValueName = CI->ValueName + "," + Rec->getName().str();
12951295 }
12961296 }
12971297
18181818 size_t MaxRowLength = 2; // minimum is custom converter plus terminator.
18191819
18201820 // TargetOperandClass - This is the target's operand class, like X86Operand.
1821 std::string TargetOperandClass = Target.getName() + "Operand";
1821 std::string TargetOperandClass = Target.getName().str() + "Operand";
18221822
18231823 // Write the convert function to a separate stream, so we can drop it after
18241824 // the enum. We'll build up the conversion handlers for the individual
20532053 Reg = "0";
20542054 } else {
20552055 Reg = getQualifiedName(OpInfo.Register);
2056 Name = "reg" + OpInfo.Register->getName();
2056 Name = "reg" + OpInfo.Register->getName().str();
20572057 }
20582058 Signature += "__" + Name;
20592059 Name = "CVT_" + Name;
137137 O << " default: llvm_unreachable(\"Unexpected opcode.\");\n";
138138 std::vector> OpsToPrint;
139139 OpsToPrint.push_back(std::make_pair(FirstInst.CGI->Namespace + "::" +
140 FirstInst.CGI->TheDef->getName(),
140 FirstInst.CGI->TheDef->getName().str(),
141141 FirstInst.Operands[i]));
142142
143143 for (const AsmWriterInst &AWI : SimilarInsts) {
144 OpsToPrint.push_back(std::make_pair(AWI.CGI->Namespace+"::"+
145 AWI.CGI->TheDef->getName(),
144 OpsToPrint.push_back(std::make_pair(AWI.CGI->Namespace+"::" +
145 AWI.CGI->TheDef->getName().str(),
146146 AWI.Operands[i]));
147147 }
148148 std::reverse(OpsToPrint.begin(), OpsToPrint.end());
864864 Record *R = CGA.ResultOperands[i].getRecord();
865865 if (R->isSubClassOf("RegisterOperand"))
866866 R = R->getValueAsDef("RegClass");
867 Cond = std::string("MRI.getRegClass(") + Target.getName() + "::" +
868 R->getName() + "RegClassID)"
869 ".contains(" + Op + ".getReg())";
867 Cond = std::string("MRI.getRegClass(") + Target.getName().str() +
868 "::" + R->getName().str() + "RegClassID).contains(" + Op +
869 ".getReg())";
870870 } else {
871871 Cond = Op + ".getReg() == MI->getOperand(" +
872872 utostr(IAP.getOpIndex(ROName)) + ").getReg()";
886886 } else
887887 break; // No conditions on this operand at all
888888 }
889 Cond = Target.getName() + ClassName + "ValidateMCOperand(" +
889 Cond = Target.getName().str() + ClassName + "ValidateMCOperand(" +
890890 Op + ", STI, " + utostr(Entry) + ")";
891891 }
892892 // for all subcases of ResultOperand::K_Record:
910910 break;
911911 }
912912
913 Cond = Op + ".getReg() == " + Target.getName() + "::" +
914 CGA.ResultOperands[i].getRegister()->getName();
913 Cond = Op + ".getReg() == " + Target.getName().str() + "::" +
914 CGA.ResultOperands[i].getRegister()->getName().str();
915915 IAP.addCond(Cond);
916916 break;
917917 }
278278 R->getValueAsBit("isPseudo"))
279279 continue;
280280 const std::string &InstName = R->getValueAsString("Namespace") + "::"
281 + R->getName();
281 + R->getName().str();
282282 std::string Case = getInstructionCase(R, Target);
283283
284284 CaseMap[Case].push_back(InstName);
754754 /// Return the name to use in the generated code to reference this, this is
755755 /// "Predicate_foo" if from a pattern fragment "foo".
756756 std::string TreePredicateFn::getFnName() const {
757 return "Predicate_" + PatFragRec->getRecord()->getName();
757 return "Predicate_" + PatFragRec->getRecord()->getName().str();
758758 }
759759
760760 /// getCodeToRunOnSDNode - Return the code for the function body that
646646
647647 // Take care to instantiate each of the suboperands with the correct
648648 // nomenclature: $foo.bar
649 ResultOperands.emplace_back(Result->getArgName(AliasOpNo) + "." +
650 MIOI->getArgName(SubOp),
649 ResultOperands.emplace_back(Result->getArgName(AliasOpNo).str()
650 + "." + MIOI->getArgName(SubOp).str(),
651651 SubRec);
652652 ResultInstOperandIndex.push_back(std::make_pair(i, SubOp));
653653 }
164164 }
165165 }
166166
167 const std::string &CodeGenRegister::getName() const {
167 const StringRef CodeGenRegister::getName() const {
168168 assert(TheDef && "no def");
169169 return TheDef->getName();
170170 }
144144
145145 CodeGenRegister(Record *R, unsigned Enum);
146146
147 const std::string &getName() const;
147 const StringRef getName() const;
148148
149149 // Extract more information from TheDef. This is used to build an object
150150 // graph after all CodeGenRegister objects have been created.
137137 if (R->getValue("Namespace"))
138138 Namespace = R->getValueAsString("Namespace");
139139 if (Namespace.empty()) return R->getName();
140 return Namespace + "::" + R->getName();
140 return Namespace + "::" + R->getName().str();
141141 }
142142
143143
156156 CodeGenTarget::~CodeGenTarget() {
157157 }
158158
159 const std::string &CodeGenTarget::getName() const {
159 const StringRef CodeGenTarget::getName() const {
160160 return TargetRec->getName();
161161 }
162162
8181 ~CodeGenTarget();
8282
8383 Record *getTargetRecord() const { return TargetRec; }
84 const std::string &getName() const;
84 const StringRef getName() const;
8585
8686 /// getInstNamespace - Return the target-specific instruction namespace.
8787 ///
120120
121121 void DAGISelEmitter::run(raw_ostream &OS) {
122122 emitSourceFileHeader("DAG Instruction Selector for the " +
123 CGP.getTargetInfo().getName() + " target", OS);
123 CGP.getTargetInfo().getName().str() + " target", OS);
124124
125125 OS << "// *** NOTE: This file is #included into the middle of the target\n"
126126 << "// *** instruction selector class. These functions are really "
249249 // If we have a physreg reference like (mul gpr:$src, EAX) then we need to
250250 // record the register
251251 if (LeafRec->isSubClassOf("Register")) {
252 AddMatcher(new RecordMatcher("physreg input "+LeafRec->getName(),
252 AddMatcher(new RecordMatcher("physreg input "+LeafRec->getName().str(),
253253 NextRecordedOperandNo));
254254 PhysRegInputs.push_back(std::make_pair(LeafRec, NextRecordedOperandNo++));
255255 return;
353353 unsigned OpNo = 0;
354354 if (N->NodeHasProperty(SDNPHasChain, CGP)) {
355355 // Record the node and remember it in our chained nodes list.
356 AddMatcher(new RecordMatcher("'" + N->getOperator()->getName() +
356 AddMatcher(new RecordMatcher("'" + N->getOperator()->getName().str() +
357357 "' chained node",
358358 NextRecordedOperandNo));
359359 // Remember all of the input chains our pattern will match.
417417 // TODO: This redundantly records nodes with both glues and chains.
418418
419419 // Record the node and remember it in our chained nodes list.
420 AddMatcher(new RecordMatcher("'" + N->getOperator()->getName() +
420 AddMatcher(new RecordMatcher("'" + N->getOperator()->getName().str() +
421421 "' glue output node",
422422 NextRecordedOperandNo));
423423 }
886886 assert((!ResultVTs.empty() || TreeHasOutGlue || NodeHasChain) &&
887887 "Node has no result");
888888
889 AddMatcher(new EmitNodeMatcher(II.Namespace+"::"+II.TheDef->getName(),
889 AddMatcher(new EmitNodeMatcher(II.Namespace+"::"+II.TheDef->getName().str(),
890890 ResultVTs, InstOps,
891891 NodeHasChain, TreeHasInGlue, TreeHasOutGlue,
892892 NodeHasMemRefs, NumFixedArityOperands,
103103
104104 void EmitDisassembler(RecordKeeper &Records, raw_ostream &OS) {
105105 CodeGenTarget Target(Records);
106 emitSourceFileHeader(" * " + Target.getName() + " Disassembler", OS);
106 emitSourceFileHeader(" * " + Target.getName().str() + " Disassembler", OS);
107107
108108 // X86 uses a custom disassembler.
109109 if (Target.getName() == "X86") {
872872 CodeGenDAGPatterns CGP(RK);
873873 const CodeGenTarget &Target = CGP.getTargetInfo();
874874 emitSourceFileHeader("\"Fast\" Instruction Selector for the " +
875 Target.getName() + " target", OS);
875 Target.getName().str() + " target", OS);
876876
877877 // Determine the target's namespace name.
878878 std::string InstNS = Target.getInstNamespace() + "::";
399399 }
400400
401401 // Returns the record name.
402 const std::string &nameWithID(unsigned Opcode) const {
402 const StringRef nameWithID(unsigned Opcode) const {
403403 return AllInstructions[Opcode]->TheDef->getName();
404404 }
405405
17191719 TypeRecord = TypeRecord->getValueAsDef("RegClass");
17201720
17211721 if (TypeRecord->isSubClassOf("RegisterClass")) {
1722 Decoder = "Decode" + TypeRecord->getName() + "RegisterClass";
1722 Decoder = "Decode" + TypeRecord->getName().str() + "RegisterClass";
17231723 } else if (TypeRecord->isSubClassOf("PointerLikeRegClass")) {
17241724 Decoder = "DecodePointerLikeRegClass" +
17251725 utostr(TypeRecord->getValueAsInt("RegClassKind"));
18881888 if (TypeRecord->isSubClassOf("RegisterOperand"))
18891889 TypeRecord = TypeRecord->getValueAsDef("RegClass");
18901890 if (TypeRecord->isSubClassOf("RegisterClass")) {
1891 Decoder = "Decode" + TypeRecord->getName() + "RegisterClass";
1891 Decoder = "Decode" + TypeRecord->getName().str() + "RegisterClass";
18921892 isReg = true;
18931893 } else if (TypeRecord->isSubClassOf("PointerLikeRegClass")) {
18941894 Decoder = "DecodePointerLikeRegClass" +
216216 }
217217 OpList[I->second] = Info.MIOperandNo;
218218 }
219 OperandMap[OpList].push_back(Namespace + "::" + Inst->TheDef->getName());
219 OperandMap[OpList].push_back(Namespace + "::" +
220 Inst->TheDef->getName().str());
220221 }
221222 }
222223
13601360 OS << "};\n"; // End of register descriptors...
13611361
13621362
1363 std::string ClassName = Target.getName() + "GenRegisterInfo";
1363 std::string ClassName = Target.getName().str() + "GenRegisterInfo";
13641364
13651365 auto SubRegIndicesSize =
13661366 std::distance(SubRegIndices.begin(), SubRegIndices.end());
293293 // For each unit
294294 for (unsigned j = 0, M = UnitList.size(); j < M;) {
295295 // Add name and bitwise or
296 ItinString += Name + "FU::" + UnitList[j]->getName();
296 ItinString += Name + "FU::" + UnitList[j]->getName().str();
297297 if (++j < M) ItinString += " | ";
298298 }
299299
340340 unsigned N = BypassList.size();
341341 unsigned i = 0;
342342 for (; i < N;) {
343 ItinString += Name + "Bypass::" + BypassList[i]->getName();
343 ItinString += Name + "Bypass::" + BypassList[i]->getName().str();
344344 if (++i < NOperandCycles) ItinString += ", ";
345345 }
346346 for (; i < NOperandCycles;) {
3232 SubtargetFeatureInfo(Record *D, uint64_t Idx) : TheDef(D), Index(Idx) {}
3333
3434 /// \brief The name of the enumerated constant identifying this feature.
35 std::string getEnumName() const { return "Feature_" + TheDef->getName(); }
35 std::string getEnumName() const {
36 return "Feature_" + TheDef->getName().str();
37 }
3638
3739 void dump() const;
3840 static std::vector>