[PATCH] [TableGen][AsmMatcherEmitter] Only parse tokens following separators as registers
Ahmed Bougacha
ahmed.bougacha at gmail.com
Mon May 18 19:24:55 PDT 2015
Hi tstellarAMD, craig.topper,
This fixes [[ https://llvm.org/bugs/show_bug.cgi?id=23455 | PR23455 ]], where, when TableGen generates the matcher from the AsmString, it splits "cmp${cc}ss" into tokens, and the "ss" suffix is recognized as the SS register.
I can't think of a situation where that's a feature, not a bug, hence this patch: when a token doesn't follow a separator (and is part of a "word"; wording better than "NewTok" much appreciated), it shouldn't be parsed as a register.
Thoughts?
-Ahmed
REPOSITORY
rL LLVM
http://reviews.llvm.org/D9844
Files:
utils/TableGen/AsmMatcherEmitter.cpp
Index: utils/TableGen/AsmMatcherEmitter.cpp
===================================================================
--- utils/TableGen/AsmMatcherEmitter.cpp
+++ utils/TableGen/AsmMatcherEmitter.cpp
@@ -310,11 +310,16 @@
/// The suboperand index within SrcOpName, or -1 for the entire operand.
int SubOpIdx;
+ /// Whether the token was a "new" token, i.e., it was preceded by a token
+ /// separator (for instance whitespace).
+ bool IsNewTok;
+
/// Register record if this token is singleton register.
Record *SingletonReg;
- explicit AsmOperand(StringRef T)
- : Token(T), Class(nullptr), SubOpIdx(-1), SingletonReg(nullptr) {}
+ explicit AsmOperand(bool IsNewTok, StringRef T)
+ : Token(T), Class(nullptr), SubOpIdx(-1), IsNewTok(IsNewTok),
+ SingletonReg(nullptr) {}
};
/// ResOperand - This represents a single operand in the result instruction
@@ -805,7 +810,10 @@
void MatchableInfo::addAsmOperand(size_t Start, size_t End) {
StringRef String = AsmString;
- AsmOperands.push_back(AsmOperand(String.slice(Start, End)));
+ bool IsNewTok =
+ !Start || (isspace(String[Start - 1]) || String[Start - 1] == ',' ||
+ String[Start - 1] == '$');
+ AsmOperands.push_back(AsmOperand(IsNewTok, String.slice(Start, End)));
}
/// tokenizeAsmString - Tokenize a simplified assembly string.
@@ -960,6 +968,11 @@
std::string &RegisterPrefix) {
StringRef Tok = AsmOperands[OperandNo].Token;
+ // If wasn't separater from another token (e.g. with whitespace), don't
+ // interpret this as a register name.
+ if (!AsmOperands[OperandNo].IsNewTok)
+ return;
+
if (RegisterPrefix.empty()) {
std::string LoweredTok = Tok.lower();
if (const CodeGenRegister *Reg = Info.Target.getRegisterByName(LoweredTok))
@@ -1508,7 +1521,7 @@
// Insert remaining suboperands after AsmOpIdx in II->AsmOperands.
StringRef Token = Op->Token; // save this in case Op gets moved
for (unsigned SI = 1, SE = Operands[Idx].MINumOperands; SI != SE; ++SI) {
- MatchableInfo::AsmOperand NewAsmOp(Token);
+ MatchableInfo::AsmOperand NewAsmOp(/*IsNewTok=*/true, Token);
NewAsmOp.SubOpIdx = SI;
II->AsmOperands.insert(II->AsmOperands.begin()+AsmOpIdx+SI, NewAsmOp);
}
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D9844.26030.patch
Type: text/x-patch
Size: 2344 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150519/3dd5b0e9/attachment.bin>
More information about the llvm-commits
mailing list