mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-02-04 16:26:46 +00:00
[TableGen] Prevent double flattening of InstAlias asm strings in the asm matcher emitter.
Unlike CodeGenInstruction, CodeGenInstAlias was flatting asm strings in its constructor. For instructions it was the users responsibility to flatten the string. AsmMatcherEmitter didn't know this and treated them the same. This caused double flattening of InstAliases. This is mostly harmless unless the desired assembly string contains curly braces. The second flattening wouldn't know to ignore these and would remove the curly braces. And for variant 1 it would remove the contents of them as well. To mitigate this, this patch makes removes the flattening from the CodeGenIntAlias constructor and modifies AsmWriterEmitter to account for the flattening not having been done. llvm-svn: 334919
This commit is contained in:
parent
0705ee8dc2
commit
2be74395cf
@ -17196,6 +17196,14 @@ vpermilpd $0x23, 0x400(%rbx), %zmm2
|
||||
// CHECK: encoding: [0x62,0xf1,0xff,0x18,0x2c,0xc1]
|
||||
vcvttsd2si {sae}, %xmm1, %rax
|
||||
|
||||
// CHECK: vcvttsd2si {sae}, %xmm3, %eax
|
||||
// CHECK: encoding: [0x62,0xf1,0x7f,0x18,0x2c,0xc3]
|
||||
vcvttsd2sil {sae}, %xmm3, %eax
|
||||
|
||||
// CHECK: vcvttsd2si {sae}, %xmm1, %rax
|
||||
// CHECK: encoding: [0x62,0xf1,0xff,0x18,0x2c,0xc1]
|
||||
vcvttsd2siq {sae}, %xmm1, %rax
|
||||
|
||||
// CHECK: vcvttsd2usi %xmm21, %eax
|
||||
// CHECK: encoding: [0x62,0xb1,0x7f,0x08,0x78,0xc5]
|
||||
vcvttsd2usi %xmm21, %eax
|
||||
|
@ -1538,7 +1538,6 @@ void AsmMatcherInfo::buildInfo() {
|
||||
Records.getAllDerivedDefinitions("InstAlias");
|
||||
for (unsigned i = 0, e = AllInstAliases.size(); i != e; ++i) {
|
||||
auto Alias = llvm::make_unique<CodeGenInstAlias>(AllInstAliases[i],
|
||||
Variant.AsmVariantNo,
|
||||
Target);
|
||||
|
||||
// If the tblgen -match-prefix option is specified (for tblgen hackers),
|
||||
|
@ -727,10 +727,6 @@ public:
|
||||
} // end anonymous namespace
|
||||
|
||||
static unsigned CountNumOperands(StringRef AsmString, unsigned Variant) {
|
||||
std::string FlatAsmString =
|
||||
CodeGenInstruction::FlattenAsmStringVariants(AsmString, Variant);
|
||||
AsmString = FlatAsmString;
|
||||
|
||||
return AsmString.count(' ') + AsmString.count('\t');
|
||||
}
|
||||
|
||||
@ -782,7 +778,7 @@ void AsmWriterEmitter::EmitPrintAliasInstruction(raw_ostream &O) {
|
||||
const DagInit *DI = R->getValueAsDag("ResultInst");
|
||||
const DefInit *Op = cast<DefInit>(DI->getOperator());
|
||||
AliasMap[getQualifiedName(Op->getDef())].insert(
|
||||
std::make_pair(CodeGenInstAlias(R, Variant, Target), Priority));
|
||||
std::make_pair(CodeGenInstAlias(R, Target), Priority));
|
||||
}
|
||||
|
||||
// A map of which conditions need to be met for each instruction operand
|
||||
@ -799,14 +795,20 @@ void AsmWriterEmitter::EmitPrintAliasInstruction(raw_ostream &O) {
|
||||
for (auto &Alias : Aliases.second) {
|
||||
const CodeGenInstAlias &CGA = Alias.first;
|
||||
unsigned LastOpNo = CGA.ResultInstOperandIndex.size();
|
||||
unsigned NumResultOps =
|
||||
CountNumOperands(CGA.ResultInst->AsmString, Variant);
|
||||
std::string FlatInstAsmString =
|
||||
CodeGenInstruction::FlattenAsmStringVariants(CGA.ResultInst->AsmString,
|
||||
Variant);
|
||||
unsigned NumResultOps = CountNumOperands(FlatInstAsmString, Variant);
|
||||
|
||||
std::string FlatAliasAsmString =
|
||||
CodeGenInstruction::FlattenAsmStringVariants(CGA.AsmString,
|
||||
Variant);
|
||||
|
||||
// Don't emit the alias if it has more operands than what it's aliasing.
|
||||
if (NumResultOps < CountNumOperands(CGA.AsmString, Variant))
|
||||
if (NumResultOps < CountNumOperands(FlatAliasAsmString, Variant))
|
||||
continue;
|
||||
|
||||
IAPrinter IAP(CGA.Result->getAsString(), CGA.AsmString);
|
||||
IAPrinter IAP(CGA.Result->getAsString(), FlatAliasAsmString);
|
||||
|
||||
StringRef Namespace = Target.getName();
|
||||
std::vector<Record *> ReqFeatures;
|
||||
|
@ -590,12 +590,10 @@ unsigned CodeGenInstAlias::ResultOperand::getMINumOperands() const {
|
||||
return MIOpInfo->getNumArgs();
|
||||
}
|
||||
|
||||
CodeGenInstAlias::CodeGenInstAlias(Record *R, unsigned Variant,
|
||||
CodeGenTarget &T)
|
||||
CodeGenInstAlias::CodeGenInstAlias(Record *R, CodeGenTarget &T)
|
||||
: TheDef(R) {
|
||||
Result = R->getValueAsDag("ResultInst");
|
||||
AsmString = R->getValueAsString("AsmString");
|
||||
AsmString = CodeGenInstruction::FlattenAsmStringVariants(AsmString, Variant);
|
||||
|
||||
|
||||
// Verify that the root of the result is an instruction.
|
||||
|
@ -352,7 +352,7 @@ template <typename T> class ArrayRef;
|
||||
/// of them are matched by the operand, the second value should be -1.
|
||||
std::vector<std::pair<unsigned, int> > ResultInstOperandIndex;
|
||||
|
||||
CodeGenInstAlias(Record *R, unsigned Variant, CodeGenTarget &T);
|
||||
CodeGenInstAlias(Record *R, CodeGenTarget &T);
|
||||
|
||||
bool tryAliasOpMatch(DagInit *Result, unsigned AliasOpNo,
|
||||
Record *InstOpRec, bool hasSubOps, ArrayRef<SMLoc> Loc,
|
||||
|
Loading…
x
Reference in New Issue
Block a user