LLVM  12.0.0git
VPlanTransforms.cpp
Go to the documentation of this file.
1 //===-- VPlanTransforms.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 "VPlanTransforms.h"
16 
17 using namespace llvm;
18 
20  Loop *OrigLoop, VPlanPtr &Plan,
22  SmallPtrSetImpl<Instruction *> &DeadInstructions) {
23 
24  auto *TopRegion = cast<VPRegionBlock>(Plan->getEntry());
25  ReversePostOrderTraversal<VPBlockBase *> RPOT(TopRegion->getEntry());
26 
27  // Condition bit VPValues get deleted during transformation to VPRecipes.
28  // Create new VPValues and save away as condition bits. These will be deleted
29  // after finalizing the vector IR basic blocks.
30  for (VPBlockBase *Base : RPOT) {
31  VPBasicBlock *VPBB = Base->getEntryBasicBlock();
32  if (auto *CondBit = VPBB->getCondBit()) {
33  auto *NCondBit = new VPValue(CondBit->getUnderlyingValue());
34  VPBB->setCondBit(NCondBit);
35  Plan->addCBV(NCondBit);
36  }
37  }
38  for (VPBlockBase *Base : RPOT) {
39  // Do not widen instructions in pre-header and exit blocks.
40  if (Base->getNumPredecessors() == 0 || Base->getNumSuccessors() == 0)
41  continue;
42 
43  VPBasicBlock *VPBB = Base->getEntryBasicBlock();
44  // Introduce each ingredient into VPlan.
45  for (auto I = VPBB->begin(), E = VPBB->end(); I != E;) {
46  VPRecipeBase *Ingredient = &*I++;
47  // Can only handle VPInstructions.
48  VPInstruction *VPInst = cast<VPInstruction>(Ingredient);
49  Instruction *Inst = cast<Instruction>(VPInst->getUnderlyingValue());
50  if (DeadInstructions.count(Inst)) {
51  Ingredient->eraseFromParent();
52  continue;
53  }
54 
55  VPRecipeBase *NewRecipe = nullptr;
56  // Create VPWidenMemoryInstructionRecipe for loads and stores.
57  if (LoadInst *Load = dyn_cast<LoadInst>(Inst))
58  NewRecipe = new VPWidenMemoryInstructionRecipe(
59  *Load, Plan->getOrAddVPValue(getLoadStorePointerOperand(Inst)),
60  nullptr /*Mask*/);
61  else if (StoreInst *Store = dyn_cast<StoreInst>(Inst))
62  NewRecipe = new VPWidenMemoryInstructionRecipe(
63  *Store, Plan->getOrAddVPValue(getLoadStorePointerOperand(Inst)),
64  Plan->getOrAddVPValue(Store->getValueOperand()), nullptr /*Mask*/);
65  else if (PHINode *Phi = dyn_cast<PHINode>(Inst)) {
66  InductionDescriptor II = Inductions.lookup(Phi);
69  NewRecipe = new VPWidenIntOrFpInductionRecipe(Phi);
70  } else
71  NewRecipe = new VPWidenPHIRecipe(Phi);
72  } else if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(Inst)) {
73  NewRecipe = new VPWidenGEPRecipe(
74  GEP, Plan->mapToVPValues(GEP->operands()), OrigLoop);
75  } else
76  NewRecipe =
77  new VPWidenRecipe(*Inst, Plan->mapToVPValues(Inst->operands()));
78 
79  NewRecipe->insertBefore(Ingredient);
80  Ingredient->eraseFromParent();
81  }
82  }
83 }
This class represents lattice values for constants.
Definition: AllocatorList.h:23
iplist< VPRecipeBase >::iterator eraseFromParent()
This method unlinks &#39;this&#39; from the containing basic block and deletes it.
Definition: VPlan.cpp:339
A Recipe for widening load/store operations.
Definition: VPlan.h:1161
InductionKind getKind() const
An instruction for reading from memory.
Definition: Instructions.h:173
Hexagon Common GEP
A recipe for handling GEP instructions.
Definition: VPlan.h:866
VPRecipeBase is a base class modeling a sequence of one or more output IR instructions.
Definition: VPlan.h:601
const Value * getLoadStorePointerOperand(const Value *V)
A helper function that returns the pointer operand of a load or store instruction.
static void VPInstructionsToVPRecipes(Loop *OrigLoop, VPlanPtr &Plan, LoopVectorizationLegality::InductionList &Inductions, SmallPtrSetImpl< Instruction *> &DeadInstructions)
Replaces the VPInstructions in Plan with corresponding widen recipes.
A recipe for handling all phi nodes except for integer and FP inductions.
Definition: VPlan.h:927
This file provides utility VPlan to VPlan transformations.
void insertBefore(VPRecipeBase *InsertPos)
Insert an unlinked recipe into a basic block immediately before the specified recipe.
Definition: VPlan.cpp:317
An instruction for storing to memory.
Definition: Instructions.h:302
iterator begin()
Recipe iterator methods.
Definition: VPlan.h:1279
an instruction for type-safe pointer arithmetic to access elements of arrays and structs ...
Definition: Instructions.h:904
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:75
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
Definition: SmallPtrSet.h:375
VPBasicBlock serves as the leaf of the Hierarchical Control-Flow Graph.
Definition: VPlan.h:1253
A struct for saving information about induction variables.
VPBlockBase is the building block of the Hierarchical Control-Flow Graph.
Definition: VPlan.h:355
void setCondBit(VPValue *CV)
Definition: VPlan.h:527
VPValue * getCondBit()
Definition: VPlan.h:523
ValueT lookup(const KeyT &Key) const
Definition: MapVector.h:110
Floating point induction variable.
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:516
#define I(x, y, z)
Definition: MD5.cpp:59
A recipe for handling phi nodes of integer and floating-point inductions, producing their vector and ...
Definition: VPlan.h:903
iterator end()
Definition: VPlan.h:1281
VPWidenRecipe is a recipe for producing a copy of vector type its ingredient.
Definition: VPlan.h:776
This is a concrete Recipe that models a single VPlan-level instruction.
Definition: VPlan.h:678