[llvm-commits] [llvm] r78565 - in /llvm/trunk: test/MC/AsmParser/hello.s utils/TableGen/AsmMatcherEmitter.cpp
Daniel Dunbar
daniel at zuster.org
Mon Aug 10 09:05:48 PDT 2009
Author: ddunbar
Date: Mon Aug 10 11:05:47 2009
New Revision: 78565
URL: http://llvm.org/viewvc/llvm-project?rev=78565&view=rev
Log:
llvm-mc/AsmParser: Check for matches with super classes when matching
instruction operands.
Modified:
llvm/trunk/test/MC/AsmParser/hello.s
llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp
Modified: llvm/trunk/test/MC/AsmParser/hello.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/hello.s?rev=78565&r1=78564&r2=78565&view=diff
==============================================================================
--- llvm/trunk/test/MC/AsmParser/hello.s (original)
+++ llvm/trunk/test/MC/AsmParser/hello.s Mon Aug 10 11:05:47 2009
@@ -1,5 +1,4 @@
// RUN: llvm-mc -triple i386-unknown-unknown %s -o -
-// XFAIL: *
.text
.align 4,0x90
Modified: llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp?rev=78565&r1=78564&r2=78565&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp Mon Aug 10 11:05:47 2009
@@ -876,6 +876,53 @@
OS << "}\n\n";
}
+/// EmitIsSubclass - Emit the subclass predicate function.
+static void EmitIsSubclass(CodeGenTarget &Target,
+ std::vector<ClassInfo*> &Infos,
+ raw_ostream &OS) {
+ OS << "/// IsSubclass - Compute whether \\arg A is a subclass of \\arg B.\n";
+ OS << "static bool IsSubclass(MatchClassKind A, MatchClassKind B) {\n";
+ OS << " if (A == B)\n";
+ OS << " return true;\n\n";
+
+ OS << " switch (A) {\n";
+ OS << " default:\n";
+ OS << " return false;\n";
+ for (std::vector<ClassInfo*>::iterator it = Infos.begin(),
+ ie = Infos.end(); it != ie; ++it) {
+ ClassInfo &A = **it;
+
+ if (A.Kind != ClassInfo::Token) {
+ std::vector<StringRef> SuperClasses;
+ for (std::vector<ClassInfo*>::iterator it = Infos.begin(),
+ ie = Infos.end(); it != ie; ++it) {
+ ClassInfo &B = **it;
+
+ if (&A != &B && A.getRootClass() == B.getRootClass() && A < B)
+ SuperClasses.push_back(B.Name);
+ }
+
+ if (SuperClasses.empty())
+ continue;
+
+ OS << "\n case " << A.Name << ":\n";
+
+ if (SuperClasses.size() == 1) {
+ OS << " return B == " << SuperClasses.back() << ";\n\n";
+ continue;
+ }
+
+ OS << " switch (B) {\n";
+ OS << " default: return false;\n";
+ for (unsigned i = 0, e = SuperClasses.size(); i != e; ++i)
+ OS << " case " << SuperClasses[i] << ": return true;\n";
+ OS << " }\n\n";
+ }
+ }
+ OS << " }\n";
+ OS << "}\n\n";
+}
+
typedef std::pair<std::string, std::string> StringPair;
/// FindFirstNonCommonLetter - Find the first character in the keys of the
@@ -1115,6 +1162,9 @@
// Emit the routine to classify an operand.
EmitClassifyOperand(Target, Info.Classes, OS);
+ // Emit the subclass predicate routine.
+ EmitIsSubclass(Target, Info.Classes, OS);
+
// Finally, build the match function.
size_t MaxNumOperands = 0;
@@ -1188,7 +1238,8 @@
<< "*ie = MatchTable + " << Info.Instructions.size()
<< "; it != ie; ++it) {\n";
for (unsigned i = 0; i != MaxNumOperands; ++i) {
- OS << " if (Classes[" << i << "] != it->Classes[" << i << "])\n";
+ OS << " if (!IsSubclass(Classes["
+ << i << "], it->Classes[" << i << "]))\n";
OS << " continue;\n";
}
OS << "\n";
More information about the llvm-commits
mailing list