From 36c0c6db3fcaef4bfebe3b49a294fe8058ed0e92 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Wed, 15 Jun 2011 04:31:19 +0000 Subject: Improve the heuristic to emit the alias if the number of hard-coded registers are also greater than the alias. llvm-svn: 133038 --- llvm/utils/TableGen/AsmWriterEmitter.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'llvm/utils/TableGen/AsmWriterEmitter.cpp') diff --git a/llvm/utils/TableGen/AsmWriterEmitter.cpp b/llvm/utils/TableGen/AsmWriterEmitter.cpp index 3eedf10f7cb..bfc63c0cf85 100644 --- a/llvm/utils/TableGen/AsmWriterEmitter.cpp +++ b/llvm/utils/TableGen/AsmWriterEmitter.cpp @@ -842,6 +842,26 @@ static unsigned CountNumOperands(StringRef AsmString) { return NumOps; } +static unsigned CountResultNumOperands(StringRef AsmString) { + unsigned NumOps = 0; + std::pair 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; +} void AsmWriterEmitter::EmitPrintAliasInstruction(raw_ostream &O) { CodeGenTarget Target(Records); @@ -887,9 +907,11 @@ void AsmWriterEmitter::EmitPrintAliasInstruction(raw_ostream &O) { II = Aliases.begin(), IE = Aliases.end(); II != IE; ++II) { const CodeGenInstAlias *CGA = *II; unsigned LastOpNo = CGA->ResultInstOperandIndex.size(); + unsigned NumResultOps = + CountResultNumOperands(CGA->ResultInst->AsmString); // Don't emit the alias if it has more operands than what it's aliasing. - if (LastOpNo < CountNumOperands(CGA->AsmString)) + if (NumResultOps < CountNumOperands(CGA->AsmString)) continue; IAPrinter *IAP = new IAPrinter(AWI, CGA->Result->getAsString(), -- cgit v1.2.3