GlobalISel: add implicit defs & uses when mutating an instruction.

Otherwise a scheduler might do bad things to the code we produce.

llvm-svn: 298311
This commit is contained in:
Tim Northover 2017-03-20 21:58:23 +00:00
parent 3cbce5d278
commit 4340d64f91
2 changed files with 20 additions and 3 deletions

View File

@ -224,7 +224,7 @@ registers:
# CHECK: body:
# CHECK: %0 = COPY %w0
# CHECK: %1 = COPY %w1
# CHECK: %2 = SUBSWrr %0, %1
# CHECK: %2 = SUBSWrr %0, %1, implicit-def %nzcv
body: |
bb.0:
liveins: %w0, %w1
@ -254,7 +254,7 @@ registers:
# CHECK: body:
# CHECK: %0 = COPY %x0
# CHECK: %1 = COPY %x1
# CHECK: %2 = SUBSXrr %0, %1
# CHECK: %2 = SUBSXrr %0, %1, implicit-def %nzcv
body: |
bb.0:
liveins: %x0, %x1

View File

@ -835,8 +835,25 @@ public:
void emitCxxActionStmts(raw_ostream &OS, RuleMatcher &Rule,
StringRef RecycleVarName) const override {
if (canMutate()) {
OS << RecycleVarName << ".setDesc(TII.get(" << I->Namespace
OS << " " << RecycleVarName << ".setDesc(TII.get(" << I->Namespace
<< "::" << I->TheDef->getName() << "));\n";
if (!I->ImplicitDefs.empty() || !I->ImplicitUses.empty()) {
OS << " auto MIB = MachineInstrBuilder(MF, &" << RecycleVarName
<< ");\n";
for (auto Def : I->ImplicitDefs) {
auto Namespace = Def->getValueAsString("Namespace");
OS << " MIB.addDef(" << Namespace << "::" << Def->getName()
<< ", RegState::Implicit);\n";
}
for (auto Use : I->ImplicitUses) {
auto Namespace = Use->getValueAsString("Namespace");
OS << " MIB.addUse(" << Namespace << "::" << Use->getName()
<< ", RegState::Implicit);\n";
}
}
OS << " MachineInstr &NewI = " << RecycleVarName << ";\n";
return;
}