]> granicus.if.org Git - llvm/commitdiff
GlobalISel: add implicit defs & uses when mutating an instruction.
authorTim Northover <tnorthover@apple.com>
Mon, 20 Mar 2017 21:58:23 +0000 (21:58 +0000)
committerTim Northover <tnorthover@apple.com>
Mon, 20 Mar 2017 21:58:23 +0000 (21:58 +0000)
Otherwise a scheduler might do bad things to the code we produce.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298311 91177308-0d34-0410-b5e6-96231b3b80d8

test/CodeGen/AArch64/GlobalISel/select-binop.mir
utils/TableGen/GlobalISelEmitter.cpp

index a15b56fe2d63b4f07cd3e1f140a38bbce0fc4eeb..8ae2e1b2eb7d2da8859d3dce8c13d353f6d3c874 100644 (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
index 596cd3cddb99e863a8ab780e1c209efd39c212d0..169dd32daa67af77e99a79c2ab25c0c89b642571 100644 (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;
     }