|
10 | 10 | #define LLVM_TRANSFORMS_VECTORIZE_VPLANUTILS_H |
11 | 11 |
|
12 | 12 | #include "VPlan.h" |
| 13 | +#include "llvm/ADT/TypeSwitch.h" |
13 | 14 |
|
14 | 15 | namespace llvm { |
15 | 16 | class ScalarEvolution; |
@@ -59,29 +60,37 @@ inline bool isSingleScalar(const VPValue *VPV) { |
59 | 60 | if (VPV->isLiveIn()) |
60 | 61 | return true; |
61 | 62 |
|
62 | | - if (auto *Rep = dyn_cast<VPReplicateRecipe>(VPV)) { |
63 | | - const VPRegionBlock *RegionOfR = Rep->getParent()->getParent(); |
64 | | - // Don't consider recipes in replicate regions as uniform yet; their first |
65 | | - // lane cannot be accessed when executing the replicate region for other |
66 | | - // lanes. |
67 | | - if (RegionOfR && RegionOfR->isReplicator()) |
68 | | - return false; |
69 | | - return Rep->isSingleScalar() || (PreservesUniformity(Rep->getOpcode()) && |
70 | | - all_of(Rep->operands(), isSingleScalar)); |
71 | | - } |
72 | | - if (isa<VPWidenGEPRecipe, VPDerivedIVRecipe, VPBlendRecipe>(VPV)) |
73 | | - return all_of(VPV->getDefiningRecipe()->operands(), isSingleScalar); |
74 | | - if (auto *WidenR = dyn_cast<VPWidenRecipe>(VPV)) { |
75 | | - return PreservesUniformity(WidenR->getOpcode()) && |
76 | | - all_of(WidenR->operands(), isSingleScalar); |
77 | | - } |
78 | | - if (auto *VPI = dyn_cast<VPInstruction>(VPV)) |
79 | | - return VPI->isSingleScalar() || VPI->isVectorToScalar() || |
80 | | - (PreservesUniformity(VPI->getOpcode()) && |
81 | | - all_of(VPI->operands(), isSingleScalar)); |
82 | | - |
83 | | - // VPExpandSCEVRecipes must be placed in the entry and are alway uniform. |
84 | | - return isa<VPExpandSCEVRecipe>(VPV); |
| 63 | + return TypeSwitch<const VPValue *, bool>(VPV) |
| 64 | + .Case<VPReplicateRecipe>([&](const auto *Rep) { |
| 65 | + const VPRegionBlock *RegionOfR = Rep->getParent()->getParent(); |
| 66 | + // Don't consider recipes in replicate regions as uniform yet; their |
| 67 | + // first lane cannot be accessed when executing the replicate region for |
| 68 | + // other lanes. |
| 69 | + if (RegionOfR && RegionOfR->isReplicator()) |
| 70 | + return false; |
| 71 | + return Rep->isSingleScalar() || |
| 72 | + (PreservesUniformity(Rep->getOpcode()) && |
| 73 | + all_of(Rep->operands(), isSingleScalar)); |
| 74 | + }) |
| 75 | + .Case<VPWidenGEPRecipe, VPDerivedIVRecipe, VPBlendRecipe>( |
| 76 | + [&](const auto *R) { |
| 77 | + return all_of(R->getDefiningRecipe()->operands(), isSingleScalar); |
| 78 | + }) |
| 79 | + .Case<VPWidenRecipe>([&](const auto *WidenR) { |
| 80 | + return PreservesUniformity(WidenR->getOpcode()) && |
| 81 | + all_of(WidenR->operands(), isSingleScalar); |
| 82 | + }) |
| 83 | + .Case<VPInstruction>([&](const auto *VPI) { |
| 84 | + return VPI->isSingleScalar() || VPI->isVectorToScalar() || |
| 85 | + (PreservesUniformity(VPI->getOpcode()) && |
| 86 | + all_of(VPI->operands(), isSingleScalar)); |
| 87 | + }) |
| 88 | + .Case<VPExpandSCEVRecipe>([](const VPValue *) { |
| 89 | + // VPExpandSCEVRecipes must be placed in the entry and are alway |
| 90 | + // uniform. |
| 91 | + return true; |
| 92 | + }) |
| 93 | + .Default([](const VPValue *) { return false; }); |
85 | 94 | } |
86 | 95 |
|
87 | 96 | /// Return true if \p V is a header mask in \p Plan. |
|
0 commit comments