LLVM  8.0.1
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 
28  // Condition bit VPValues get deleted during transformation to VPRecipes.
29  // Create new VPValues and save away as condition bits. These will be deleted
30  // after finalizing the vector IR basic blocks.
31  for (VPBlockBase *Base : RPOT) {
32  VPBasicBlock *VPBB = Base->getEntryBasicBlock();
33  if (auto *CondBit = VPBB->getCondBit()) {
34  auto *NCondBit = new VPValue(CondBit->getUnderlyingValue());
35  VPBB->setCondBit(NCondBit);
36  Plan->addCBV(NCondBit);
37  }
38  }
39  for (VPBlockBase *Base : RPOT) {
40  // Do not widen instructions in pre-header and exit blocks.
41  if (Base->getNumPredecessors() == 0 || Base->getNumSuccessors() == 0)
42  continue;
43 
44  VPBasicBlock *VPBB = Base->getEntryBasicBlock();
45  VPRecipeBase *LastRecipe = nullptr;
46  // Introduce each ingredient into VPlan.
47  for (auto I = VPBB->begin(), E = VPBB->end(); I != E;) {
48  VPRecipeBase *Ingredient = &*I++;
49  // Can only handle VPInstructions.
50  VPInstruction *VPInst = cast<VPInstruction>(Ingredient);
51  Instruction *Inst = cast<Instruction>(VPInst->getUnderlyingValue());
52  if (DeadInstructions.count(Inst)) {
53  Ingredient->eraseFromParent();
54  continue;
55  }
56 
57  VPRecipeBase *NewRecipe = nullptr;
58  // Create VPWidenMemoryInstructionRecipe for loads and stores.
59  if (isa<LoadInst>(Inst) || isa<StoreInst>(Inst))
60  NewRecipe = new VPWidenMemoryInstructionRecipe(*Inst, nullptr /*Mask*/);
61  else if (PHINode *Phi = dyn_cast<PHINode>(Inst)) {
62  InductionDescriptor II = Inductions->lookup(Phi);
65  NewRecipe = new VPWidenIntOrFpInductionRecipe(Phi);
66  } else
67  NewRecipe = new VPWidenPHIRecipe(Phi);
68  } else {
69  // If the last recipe is a VPWidenRecipe, add Inst to it instead of
70  // creating a new recipe.
71  if (VPWidenRecipe *WidenRecipe =
72  dyn_cast_or_null<VPWidenRecipe>(LastRecipe)) {
73  WidenRecipe->appendInstruction(Inst);
74  Ingredient->eraseFromParent();
75  continue;
76  }
77  NewRecipe = new VPWidenRecipe(Inst);
78  }
79 
80  NewRecipe->insertBefore(Ingredient);
81  LastRecipe = NewRecipe;
82  Ingredient->eraseFromParent();
83  }
84  }
85 }
This class represents lattice values for constants.
Definition: AllocatorList.h:24
VPRegionBlock represents a collection of VPBasicBlocks and VPRegionBlocks which form a Single-Entry-S...
Definition: VPlan.h:1050
iplist< VPRecipeBase >::iterator eraseFromParent()
This method unlinks &#39;this&#39; from the containing basic block and deletes it.
Definition: VPlan.cpp:283
A Recipe for widening load/store operations.
Definition: VPlan.h:938
InductionKind getKind() const
VPRecipeBase is a base class modeling a sequence of one or more output IR instructions.
Definition: VPlan.h:551
A recipe for handling all phi nodes except for integer and FP inductions.
Definition: VPlan.h:748
void insertBefore(VPRecipeBase *InsertPos)
Insert an unlinked recipe into a basic block immediately before the specified recipe.
Definition: VPlan.cpp:278
This file provides utility VPlan to VPlan transformations.
iterator begin()
Recipe iterator methods.
Definition: VPlan.h:991
Value * getUnderlyingValue()
Return the underlying Value attached to this VPValue.
Definition: VPlanValue.h:65
Integer induction variable. Step = C.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
std::unique_ptr< VPlan > VPlanPtr
Definition: VPlan.h:76
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:965
A struct for saving information about induction variables.
VPBlockBase is the building block of the Hierarchical Control-Flow Graph.
Definition: VPlan.h:334
void setCondBit(VPValue *CV)
Definition: VPlan.h:492
const VPBlockBase * getEntry() const
Definition: VPlan.h:1086
VPValue * getCondBit()
Definition: VPlan.h:488
ValueT lookup(const KeyT &Key) const
Definition: MapVector.h:111
Floating point induction variable.
#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:724
iterator end()
Definition: VPlan.h:993
VPWidenRecipe is a recipe for producing a copy of vector type for each Instruction in its ingredients...
Definition: VPlan.h:688
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:611