diff options
author | Tim Northover <tnorthover@apple.com> | 2014-05-16 09:42:04 +0000 |
---|---|---|
committer | Tim Northover <tnorthover@apple.com> | 2014-05-16 09:42:04 +0000 |
commit | a9a94ce83924290417762594def7088bcf31d782 (patch) | |
tree | 436f499d2f6f51b21413288d8653af238307a5c9 /utils/TableGen | |
parent | fbf4058e7a94b08d9d2f1b994f2d1bef1cd80115 (diff) | |
download | llvm-a9a94ce83924290417762594def7088bcf31d782.tar.gz llvm-a9a94ce83924290417762594def7088bcf31d782.tar.bz2 llvm-a9a94ce83924290417762594def7088bcf31d782.tar.xz |
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"
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@208969 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/TableGen')
-rw-r--r-- | utils/TableGen/AsmWriterEmitter.cpp | 39 |
1 files changed, 7 insertions, 32 deletions
diff --git a/utils/TableGen/AsmWriterEmitter.cpp b/utils/TableGen/AsmWriterEmitter.cpp index 617aa82737..c31c120a2f 100644 --- a/utils/TableGen/AsmWriterEmitter.cpp +++ b/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(), |