[Hexagon] Factor out some common code in HexagonEarlyIfConv.cpp, NFC
authorKrzysztof Parzyszek <kparzysz@codeaurora.org>
Mon, 3 Apr 2017 17:26:40 +0000 (17:26 +0000)
committerKrzysztof Parzyszek <kparzysz@codeaurora.org>
Mon, 3 Apr 2017 17:26:40 +0000 (17:26 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@299367 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/Hexagon/HexagonEarlyIfConv.cpp

index 7ee2e43bf96dd36ab2f9afb1032ece83d88f431d..67af947e089dd6db718ce2a1da577315d861d099 100644 (file)
@@ -537,18 +537,16 @@ bool HexagonEarlyIfConversion::isProfitable(const FlowPattern &FP) const {
   // the code size. If the predicated blocks are smaller than a packet size,
   // approximate the spare room in the packet that could be filled with the
   // predicated/speculated instructions.
-  unsigned TS = 0, FS = 0, Spare = 0;
-  if (FP.TrueB) {
-    TS = std::distance(FP.TrueB->begin(), FP.TrueB->getFirstTerminator());
-    if (TS < HEXAGON_PACKET_SIZE)
-      Spare += HEXAGON_PACKET_SIZE-TS;
-  }
-  if (FP.FalseB) {
-    FS = std::distance(FP.FalseB->begin(), FP.FalseB->getFirstTerminator());
-    if (FS < HEXAGON_PACKET_SIZE)
-      Spare += HEXAGON_PACKET_SIZE-FS;
-  }
-  unsigned TotalIn = TS+FS;
+  auto TotalCount = [] (const MachineBasicBlock *B, unsigned &Spare) {
+    if (!B)
+      return 0u;
+    unsigned T = std::distance(B->begin(), B->getFirstTerminator());
+    if (T < HEXAGON_PACKET_SIZE)
+      Spare += HEXAGON_PACKET_SIZE-T;
+    return T;
+  };
+  unsigned Spare = 0;
+  unsigned TotalIn = TotalCount(FP.TrueB, Spare) + TotalCount(FP.FalseB, Spare);
   DEBUG(dbgs() << "Total number of instructions to be predicated/speculated: "
                << TotalIn << ", spare room: " << Spare << "\n");
   if (TotalIn >= SizeLimit+Spare)