Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Transforms/Vectorize/VPlanHCFGTransforms.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- VPlanHCFGTransforms.cpp - Utility VPlan to VPlan transforms -------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
///
9
/// \file
10
/// This file implements a set of utility VPlan to VPlan transformations.
11
///
12
//===----------------------------------------------------------------------===//
13
14
#include "VPlanHCFGTransforms.h"
15
#include "llvm/ADT/PostOrderIterator.h"
16
17
using namespace llvm;
18
19
void VPlanHCFGTransforms::VPInstructionsToVPRecipes(
20
    VPlanPtr &Plan,
21
    LoopVectorizationLegality::InductionList *Inductions,
22
9
    SmallPtrSetImpl<Instruction *> &DeadInstructions) {
23
9
24
9
  VPRegionBlock *TopRegion = dyn_cast<VPRegionBlock>(Plan->getEntry());
25
9
  ReversePostOrderTraversal<VPBlockBase *> RPOT(TopRegion->getEntry());
26
9
27
9
  // Condition bit VPValues get deleted during transformation to VPRecipes.
28
9
  // Create new VPValues and save away as condition bits. These will be deleted
29
9
  // after finalizing the vector IR basic blocks.
30
43
  for (VPBlockBase *Base : RPOT) {
31
43
    VPBasicBlock *VPBB = Base->getEntryBasicBlock();
32
43
    if (auto *CondBit = VPBB->getCondBit()) {
33
17
      auto *NCondBit = new VPValue(CondBit->getUnderlyingValue());
34
17
      VPBB->setCondBit(NCondBit);
35
17
      Plan->addCBV(NCondBit);
36
17
    }
37
43
  }
38
43
  for (VPBlockBase *Base : RPOT) {
39
43
    // Do not widen instructions in pre-header and exit blocks.
40
43
    if (Base->getNumPredecessors() == 0 || 
Base->getNumSuccessors() == 034
)
41
18
      continue;
42
25
43
25
    VPBasicBlock *VPBB = Base->getEntryBasicBlock();
44
25
    VPRecipeBase *LastRecipe = nullptr;
45
25
    // Introduce each ingredient into VPlan.
46
132
    for (auto I = VPBB->begin(), E = VPBB->end(); I != E;) {
47
107
      VPRecipeBase *Ingredient = &*I++;
48
107
      // Can only handle VPInstructions.
49
107
      VPInstruction *VPInst = cast<VPInstruction>(Ingredient);
50
107
      Instruction *Inst = cast<Instruction>(VPInst->getUnderlyingValue());
51
107
      if (DeadInstructions.count(Inst)) {
52
0
        Ingredient->eraseFromParent();
53
0
        continue;
54
0
      }
55
107
56
107
      VPRecipeBase *NewRecipe = nullptr;
57
107
      // Create VPWidenMemoryInstructionRecipe for loads and stores.
58
107
      if (isa<LoadInst>(Inst) || 
isa<StoreInst>(Inst)103
)
59
20
        NewRecipe = new VPWidenMemoryInstructionRecipe(*Inst, nullptr /*Mask*/);
60
87
      else if (PHINode *Phi = dyn_cast<PHINode>(Inst)) {
61
18
        InductionDescriptor II = Inductions->lookup(Phi);
62
18
        if (II.getKind() == InductionDescriptor::IK_IntInduction ||
63
18
            
II.getKind() == InductionDescriptor::IK_FpInduction11
) {
64
7
          NewRecipe = new VPWidenIntOrFpInductionRecipe(Phi);
65
7
        } else
66
11
          NewRecipe = new VPWidenPHIRecipe(Phi);
67
69
      } else {
68
69
        // If the last recipe is a VPWidenRecipe, add Inst to it instead of
69
69
        // creating a new recipe.
70
69
        if (VPWidenRecipe *WidenRecipe =
71
28
                dyn_cast_or_null<VPWidenRecipe>(LastRecipe)) {
72
28
          WidenRecipe->appendInstruction(Inst);
73
28
          Ingredient->eraseFromParent();
74
28
          continue;
75
28
        }
76
41
        NewRecipe = new VPWidenRecipe(Inst);
77
41
      }
78
107
79
107
      NewRecipe->insertBefore(Ingredient);
80
79
      LastRecipe = NewRecipe;
81
79
      Ingredient->eraseFromParent();
82
79
    }
83
25
  }
84
9
}