summaryrefslogtreecommitdiff
path: root/lib/TableGen
diff options
context:
space:
mode:
authorAlex Bradbury <asb@lowrisc.org>2017-12-07 09:51:55 +0000
committerAlex Bradbury <asb@lowrisc.org>2017-12-07 09:51:55 +0000
commit2bd791038b53582293a9a6e9704af1c790f2f0b7 (patch)
treed737d97cc50b4069d5d4fff00abcc59806fa688e /lib/TableGen
parent1d4832bccf885b1a592834018545343a56efec4a (diff)
[TableGen] Give the option of tolerating duplicate register names
A number of architectures re-use the same register names (e.g. for both 32-bit FPRs and 64-bit FPRs). They are currently unable to use the tablegen'erated MatchRegisterName and MatchRegisterAltName, as tablegen (when built with asserts enabled) will fail. When the AllowDuplicateRegisterNames in AsmParser is set, duplicated register names will be tolerated. A backend can then coerce registers to the desired register class by (for instance) implementing validateTargetOperandClass. At least the in-tree Sparc backend could benefit from this, as does RISC-V (single and double precision floating point registers). Differential Revision: https://reviews.llvm.org/D39845 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320018 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/TableGen')
-rw-r--r--lib/TableGen/StringMatcher.cpp25
1 files changed, 14 insertions, 11 deletions
diff --git a/lib/TableGen/StringMatcher.cpp b/lib/TableGen/StringMatcher.cpp
index 7e510f0c2fd..32599104f6a 100644
--- a/lib/TableGen/StringMatcher.cpp
+++ b/lib/TableGen/StringMatcher.cpp
@@ -46,17 +46,18 @@ FindFirstNonCommonLetter(const std::vector<const
/// code to verify that CharNo and later are the same.
///
/// \return - True if control can leave the emitted code fragment.
-bool StringMatcher::
-EmitStringMatcherForChar(const std::vector<const StringPair*> &Matches,
- unsigned CharNo, unsigned IndentCount) const {
+bool StringMatcher::EmitStringMatcherForChar(
+ const std::vector<const StringPair *> &Matches, unsigned CharNo,
+ unsigned IndentCount, bool IgnoreDuplicates) const {
assert(!Matches.empty() && "Must have at least one string to match!");
- std::string Indent(IndentCount*2+4, ' ');
+ std::string Indent(IndentCount * 2 + 4, ' ');
// If we have verified that the entire string matches, we're done: output the
// matching code.
if (CharNo == Matches[0]->first.size()) {
- assert(Matches.size() == 1 && "Had duplicate keys to match on");
-
+ if (Matches.size() > 1 && !IgnoreDuplicates)
+ report_fatal_error("Had duplicate keys to match on");
+
// If the to-execute code has \n's in it, indent each subsequent line.
StringRef Code = Matches[0]->second;
@@ -100,8 +101,9 @@ EmitStringMatcherForChar(const std::vector<const StringPair*> &Matches,
<< NumChars << ") != 0)\n";
OS << Indent << " break;\n";
}
-
- return EmitStringMatcherForChar(Matches, FirstNonCommonLetter, IndentCount);
+
+ return EmitStringMatcherForChar(Matches, FirstNonCommonLetter, IndentCount,
+ IgnoreDuplicates);
}
// Otherwise, we have multiple possible things, emit a switch on the
@@ -116,7 +118,8 @@ EmitStringMatcherForChar(const std::vector<const StringPair*> &Matches,
<< LI->second.size() << " string";
if (LI->second.size() != 1) OS << 's';
OS << " to match.\n";
- if (EmitStringMatcherForChar(LI->second, CharNo+1, IndentCount+1))
+ if (EmitStringMatcherForChar(LI->second, CharNo + 1, IndentCount + 1,
+ IgnoreDuplicates))
OS << Indent << " break;\n";
}
@@ -126,7 +129,7 @@ EmitStringMatcherForChar(const std::vector<const StringPair*> &Matches,
/// Emit - Top level entry point.
///
-void StringMatcher::Emit(unsigned Indent) const {
+void StringMatcher::Emit(unsigned Indent, bool IgnoreDuplicates) const {
// If nothing to match, just fall through.
if (Matches.empty()) return;
@@ -146,7 +149,7 @@ void StringMatcher::Emit(unsigned Indent) const {
OS.indent(Indent*2+2) << "case " << LI->first << ":\t // "
<< LI->second.size()
<< " string" << (LI->second.size() == 1 ? "" : "s") << " to match.\n";
- if (EmitStringMatcherForChar(LI->second, 0, Indent))
+ if (EmitStringMatcherForChar(LI->second, 0, Indent, IgnoreDuplicates))
OS.indent(Indent*2+4) << "break;\n";
}