Commit 5e40f2cf authored by Vitaly Buka's avatar Vitaly Buka
Browse files

[CodeMoverUtils] clang-format the test

parent ad58d1a9
Loading
Loading
Loading
Loading
+55 −45
Original line number Diff line number Diff line
@@ -65,8 +65,7 @@ TEST(CodeMoverUtils, BasicTest) {
  //   }
  // }
  std::unique_ptr<Module> M = parseIR(
      C,
      "define void @foo(i32* noalias %A, i32* noalias %B, i32* noalias %C\n"
      C, "define void @foo(i32* noalias %A, i32* noalias %B, i32* noalias %C\n"
         "                  , i64 %N) {\n"
         "entry:\n"
         "  %X = sdiv i64 1, %N\n"
@@ -106,9 +105,11 @@ TEST(CodeMoverUtils, BasicTest) {
        BasicBlock *Entry = &*(FI++);
        assert(Entry->getName() == "entry" && "Expecting BasicBlock entry");
        Instruction *CI_safecall = Entry->front().getNextNode();
        assert(isa<CallInst>(CI_safecall) && "Expecting CI_safecall to be a CallInst");
        assert(isa<CallInst>(CI_safecall) &&
               "Expecting CI_safecall to be a CallInst");
        Instruction *CI_unsafecall = CI_safecall->getNextNode()->getNextNode();
        assert(isa<CallInst>(CI_unsafecall) && "Expecting CI_unsafecall to be a CallInst");
        assert(isa<CallInst>(CI_unsafecall) &&
               "Expecting CI_unsafecall to be a CallInst");
        BasicBlock *ForBody = &*(FI++);
        assert(ForBody->getName() == "for.body" &&
               "Expecting BasicBlock for.body");
@@ -126,39 +127,48 @@ TEST(CodeMoverUtils, BasicTest) {
        assert(LI1->getName() == "load1" && "Expecting LI1 to be load1");
        Instruction *LI2 = LI1->getNextNode()->getNextNode()->getNextNode();
        assert(LI2->getName() == "load2" && "Expecting LI2 to be load2");
        Instruction *SI_A6 = LI2->getNextNode()->getNextNode()->getNextNode()->getNextNode();
        Instruction *SI_A6 =
            LI2->getNextNode()->getNextNode()->getNextNode()->getNextNode();
        assert(isa<StoreInst>(SI_A6) &&
               SI_A6->getOperand(1)->getName() == "arrayidx_A6" &&
               "Expecting store to arrayidx_A6");

        // Can move after CI_safecall, as it does not throw, not synchronize, or must return.
        EXPECT_TRUE(isSafeToMoveBefore(*CI_safecall->getPrevNode(), *CI_safecall->getNextNode(), DT, PDT, DI));
        // Can move after CI_safecall, as it does not throw, not synchronize, or
        // must return.
        EXPECT_TRUE(isSafeToMoveBefore(*CI_safecall->getPrevNode(),
                                       *CI_safecall->getNextNode(), DT, PDT,
                                       DI));

        // Cannot move CI_unsafecall, as it may throw.
        EXPECT_FALSE(isSafeToMoveBefore(*CI_unsafecall->getNextNode(), *CI_unsafecall, DT, PDT, DI));
        EXPECT_FALSE(isSafeToMoveBefore(*CI_unsafecall->getNextNode(),
                                        *CI_unsafecall, DT, PDT, DI));

        // Moving instruction to non control flow equivalent places are not
        // supported.
        EXPECT_FALSE(isSafeToMoveBefore(*SI_A5, *Entry->getTerminator(), DT, PDT, DI));
        EXPECT_FALSE(
            isSafeToMoveBefore(*SI_A5, *Entry->getTerminator(), DT, PDT, DI));

        // Moving PHINode is not supported.
        EXPECT_FALSE(isSafeToMoveBefore(PN, *PN.getNextNode()->getNextNode(), DT, PDT, DI));
        EXPECT_FALSE(isSafeToMoveBefore(PN, *PN.getNextNode()->getNextNode(),
                                        DT, PDT, DI));

        // Cannot move non-PHINode before PHINode.
        EXPECT_FALSE(isSafeToMoveBefore(*PN.getNextNode(), PN, DT, PDT, DI));

        // Moving Terminator is not supported.
        EXPECT_FALSE(isSafeToMoveBefore(*Entry->getTerminator(), *PN.getNextNode(), DT,
                                PDT, DI));
        EXPECT_FALSE(isSafeToMoveBefore(*Entry->getTerminator(),
                                        *PN.getNextNode(), DT, PDT, DI));

        // Cannot move %arrayidx_A after SI, as SI is its user.
        EXPECT_FALSE(isSafeToMoveBefore(*SI->getPrevNode(), *SI->getNextNode(), DT, PDT, DI));
        EXPECT_FALSE(isSafeToMoveBefore(*SI->getPrevNode(), *SI->getNextNode(),
                                        DT, PDT, DI));

        // Cannot move SI before %arrayidx_A, as %arrayidx_A is its operand.
        EXPECT_FALSE(isSafeToMoveBefore(*SI, *SI->getPrevNode(), DT, PDT, DI));

        // Cannot move LI2 after SI_A6, as there is a flow dependence.
        EXPECT_FALSE(isSafeToMoveBefore(*LI2, *SI_A6->getNextNode(), DT, PDT, DI));
        EXPECT_FALSE(
            isSafeToMoveBefore(*LI2, *SI_A6->getNextNode(), DT, PDT, DI));

        // Cannot move SI after LI1, as there is a anti dependence.
        EXPECT_FALSE(isSafeToMoveBefore(*SI, *LI1->getNextNode(), DT, PDT, DI));