summaryrefslogtreecommitdiffstats
path: root/llvm/utils/TableGen
diff options
context:
space:
mode:
authorTim Northover <tnorthover@apple.com>2014-05-16 09:42:04 +0000
committerTim Northover <tnorthover@apple.com>2014-05-16 09:42:04 +0000
commit5896b066e65bd7a6392ffde1a74104ba1d5a6a00 (patch)
tree9610345375e13662ecde5b8045459d6dfe4bb184 /llvm/utils/TableGen
parent28aef9e05d6dca63b412e9a16311f9fd0040a012 (diff)
downloadbcm5719-llvm-5896b066e65bd7a6392ffde1a74104ba1d5a6a00.tar.gz
bcm5719-llvm-5896b066e65bd7a6392ffde1a74104ba1d5a6a00.zip
TableGen: fix operand counting for aliases
TableGen has a fairly dubious heuristic to decide whether an alias should be printed: does the alias have lest operands than the real instruction. This is bad enough (particularly with no way to override it), but it should at least be calculated consistently for both strings. This patch implements that logic: first get the *correct* string for the variant, in the same way as the Matcher, without guessing; then count the number of whitespace chars. There are basically 4 changes this brings about after the previous commits; all of these appear to be good, so I have changed the tests: + ARM64: we print "neg X, Y" instead of "sub X, xzr, Y". + ARM64: we skip implicit "uxtx" and "uxtw" modifiers. + Sparc: we print "mov A, B" instead of "or %g0, A, B". + Sparc: we print "fcmpX A, B" instead of "fcmpX %fcc0, A, B" llvm-svn: 208969
Diffstat (limited to 'llvm/utils/TableGen')
-rw-r--r--llvm/utils/TableGen/AsmWriterEmitter.cpp39
1 files changed, 7 insertions, 32 deletions
diff --git a/llvm/utils/TableGen/AsmWriterEmitter.cpp b/llvm/utils/TableGen/AsmWriterEmitter.cpp
index 617aa827376..c31c120a2f7 100644
--- a/llvm/utils/TableGen/AsmWriterEmitter.cpp
+++ b/llvm/utils/TableGen/AsmWriterEmitter.cpp
@@ -742,37 +742,12 @@ public:
} // end anonymous namespace
-static unsigned CountNumOperands(StringRef AsmString) {
- unsigned NumOps = 0;
- std::pair<StringRef, StringRef> ASM = AsmString.split(' ');
+static unsigned CountNumOperands(StringRef AsmString, unsigned Variant) {
+ std::string FlatAsmString =
+ CodeGenInstruction::FlattenAsmStringVariants(AsmString, Variant);
+ AsmString = FlatAsmString;
- while (!ASM.second.empty()) {
- ++NumOps;
- ASM = ASM.second.split(' ');
- }
-
- return NumOps;
-}
-
-static unsigned CountResultNumOperands(StringRef AsmString) {
- unsigned NumOps = 0;
- std::pair<StringRef, StringRef> ASM = AsmString.split('\t');
-
- if (!ASM.second.empty()) {
- size_t I = ASM.second.find('{');
- StringRef Str = ASM.second;
- if (I != StringRef::npos)
- Str = ASM.second.substr(I, ASM.second.find('|', I));
-
- ASM = Str.split(' ');
-
- do {
- ++NumOps;
- ASM = ASM.second.split(' ');
- } while (!ASM.second.empty());
- }
-
- return NumOps;
+ return AsmString.count(' ') + AsmString.count('\t');
}
void AsmWriterEmitter::EmitPrintAliasInstruction(raw_ostream &O) {
@@ -818,10 +793,10 @@ void AsmWriterEmitter::EmitPrintAliasInstruction(raw_ostream &O) {
const CodeGenInstAlias *CGA = *II;
unsigned LastOpNo = CGA->ResultInstOperandIndex.size();
unsigned NumResultOps =
- CountResultNumOperands(CGA->ResultInst->AsmString);
+ CountNumOperands(CGA->ResultInst->AsmString, Variant);
// Don't emit the alias if it has more operands than what it's aliasing.
- if (NumResultOps < CountNumOperands(CGA->AsmString))
+ if (NumResultOps < CountNumOperands(CGA->AsmString, Variant))
continue;
IAPrinter *IAP = new IAPrinter(CGA->Result->getAsString(),
OpenPOWER on IntegriCloud