LLVM  7.0.0
VPlanHCFGTransforms.cpp
Go to the documentation of this file.
1 //===-- VPlanHCFGTransforms.cpp - Utility VPlan to VPlan transforms -------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 ///
10 /// \file
11 /// This file implements a set of utility VPlan to VPlan transformations.
12 ///
13 //===----------------------------------------------------------------------===//
14 
15 #include "VPlanHCFGTransforms.h"
17 
18 using namespace llvm;
19 
21  VPlanPtr &Plan,
23  SmallPtrSetImpl<Instruction *> &DeadInstructions) {
24 
25  VPRegionBlock *TopRegion = dyn_cast<VPRegionBlock>(Plan->getEntry());
27  for (VPBlockBase *Base : RPOT) {
28  // Do not widen instructions in pre-header and exit blocks.
29  if (Base->getNumPredecessors() == 0 || Base->getNumSuccessors() == 0)
30  continue;
31 
32  VPBasicBlock *VPBB = Base->getEntryBasicBlock();
33  VPRecipeBase *LastRecipe = nullptr;
34  // Introduce each ingredient into VPlan.
35  for (auto I = VPBB->begin(), E = VPBB->end(); I != E;) {
36  VPRecipeBase *Ingredient = &*I++;
37  // Can only handle VPInstructions.
38  VPInstruction *VPInst = cast<VPInstruction>(Ingredient);
39  Instruction *Inst = cast<Instruction>(VPInst->getUnderlyingValue());
40  if (DeadInstructions.count(Inst)) {
41  Ingredient->eraseFromParent();
42  continue;
43  }
44 
45  VPRecipeBase *NewRecipe = nullptr;
46  // Create VPWidenMemoryInstructionRecipe for loads and stores.
47  if (isa<LoadInst>(Inst) || isa<StoreInst>(Inst))
48  NewRecipe = new VPWidenMemoryInstructionRecipe(*Inst, nullptr /*Mask*/);
49  else if (PHINode *Phi = dyn_cast<PHINode>(Inst)) {
50  InductionDescriptor II = Inductions->lookup(Phi);
53  NewRecipe = new VPWidenIntOrFpInductionRecipe(Phi);
54  } else
55  NewRecipe = new VPWidenPHIRecipe(Phi);
56  } else {
57  // If the last recipe is a VPWidenRecipe, add Inst to it instead of
58  // creating a new recipe.
59  if (VPWidenRecipe *WidenRecipe =
60  dyn_cast_or_null<VPWidenRecipe>(LastRecipe)) {
61  WidenRecipe->appendInstruction(Inst);
62  Ingredient->eraseFromParent();
63  continue;
64  }
65  NewRecipe = new VPWidenRecipe(Inst);
66  }
67 
68  NewRecipe->insertBefore(Ingredient);
69  LastRecipe = NewRecipe;
70  Ingredient->eraseFromParent();
71  }
72  }
73 }
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
VPRegionBlock represents a collection of VPBasicBlocks and VPRegionBlocks which form a Single-Entry-S...
Definition: VPlan.h:1010
iplist< VPRecipeBase >::iterator eraseFromParent()
This method unlinks &#39;this&#39; from the containing basic block and deletes it.
Definition: VPlan.cpp:229
A Recipe for widening load/store operations.
Definition: VPlan.h:898
InductionKind getKind() const
Definition: LoopUtils.h:284
VPRecipeBase is a base class modeling a sequence of one or more output IR instructions.
Definition: VPlan.h:541
A recipe for handling all phi nodes except for integer and FP inductions.
Definition: VPlan.h:712
void insertBefore(VPRecipeBase *InsertPos)
Insert an unlinked recipe into a basic block immediately before the specified recipe.
Definition: VPlan.cpp:224
This file provides utility VPlan to VPlan transformations.
iterator begin()
Recipe iterator methods.
Definition: VPlan.h:951
Value * getUnderlyingValue()
Return the underlying Value attached to this VPValue.
Definition: VPlanValue.h:61
Integer induction variable. Step = C.
Definition: LoopUtils.h:259
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
std::unique_ptr< VPlan > VPlanPtr
Definition: VPlan.h:73
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
Definition: SmallPtrSet.h:382
VPBasicBlock serves as the leaf of the Hierarchical Control-Flow Graph.
Definition: VPlan.h:925
A struct for saving information about induction variables.
Definition: LoopUtils.h:254
VPBlockBase is the building block of the Hierarchical Control-Flow Graph.
Definition: VPlan.h:324
const VPBlockBase * getEntry() const
Definition: VPlan.h:1046
ValueT lookup(const KeyT &Key) const
Definition: MapVector.h:111
Floating point induction variable.
Definition: LoopUtils.h:261
#define I(x, y, z)
Definition: MD5.cpp:58
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:323
A recipe for handling phi nodes of integer and floating-point inductions, producing their vector and ...
Definition: VPlan.h:688
iterator end()
Definition: VPlan.h:953
VPWidenRecipe is a recipe for producing a copy of vector type for each Instruction in its ingredients...
Definition: VPlan.h:652
static void VPInstructionsToVPRecipes(VPlanPtr &Plan, LoopVectorizationLegality::InductionList *Inductions, SmallPtrSetImpl< Instruction *> &DeadInstructions)
Replaces the VPInstructions in Plan with corresponding widen recipes.
This is a concrete Recipe that models a single VPlan-level instruction.
Definition: VPlan.h:601