LLVM 24.0.0git
SeedCollection.cpp
Go to the documentation of this file.
1//===- SeedCollection.cpp - Seed collection pass --------------------------===//
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
17
18namespace llvm {
19
20namespace sandboxir {
21
23 : FunctionPass("seed-collection"),
24 RPM("rpm", Pipeline, SandboxVectorizerPassBuilder::createRegionPass) {
25 ArgsRegistry.parse(AuxArg);
26 // If the user has not specified seed types default to stores.
27 if (!CollectStores && !CollectLoads) {
28 CollectStores = true;
29 }
30}
31
33 const VectorizeOptions &Opts = getVectorizeOptions(F.getContext());
34 bool Change = false;
35 const auto &DL = F.getParent()->getDataLayout();
36
37 // TODO: Start from innermost BBs first
38 for (auto &BB : F) {
39 SeedCollector SC(&BB, A.getScalarEvolution(), CollectStores, CollectLoads,
40 AllowDiffTypes);
41 for (auto &SeedRange : {SC.getStoreSeeds(), SC.getLoadSeeds()}) {
42 for (SeedBundle &Seeds : SeedRange) {
43 if (Seeds.allUsed())
44 continue;
45 unsigned FirstUnusedIdx = Seeds.getFirstUnusedElementIdx();
46 unsigned ElmBits =
48 Seeds[FirstUnusedIdx])),
49 DL);
50 unsigned AS = getLoadStoreAddressSpace(Seeds[FirstUnusedIdx]);
51 unsigned VecRegBits = Opts.sbvec_vec_reg_bits != 0
52 ? Opts.sbvec_vec_reg_bits
53 : A.getTTI().getLoadStoreVecRegBitWidth(AS);
54
55 auto DivideBy2 = [](unsigned Num) {
56 auto Floor = VecUtils::getFloorPowerOf2(Num);
57 if (Floor == Num)
58 return Floor / 2;
59 return Floor;
60 };
61 // Try to create the largest vector supported by the target. If it fails
62 // reduce the vector size by half.
63 for (unsigned SliceElms = std::min(VecRegBits / ElmBits,
64 Seeds.getNumUnusedBits() / ElmBits);
65 SliceElms >= 2u; SliceElms = DivideBy2(SliceElms)) {
66 if (Seeds.allUsed())
67 break;
68 // Keep trying offsets after FirstUnusedElementIdx, until we vectorize
69 // the slice. This could be quite expensive, so we enforce a limit.
70 for (unsigned Offset = Seeds.getFirstUnusedElementIdx(),
71 OE = Seeds.size();
72 Offset + 1 < OE; Offset += 1) {
73 // Seeds are getting used as we vectorize, so skip them.
74 if (Seeds.isUsed(Offset))
75 continue;
76 if (Seeds.allUsed())
77 break;
78
79 auto SeedSlice = Seeds.getSlice(Offset, SliceElms * ElmBits,
80 !Opts.sbvec_allow_non_pow2);
81 if (SeedSlice.empty())
82 continue;
83
84 assert(SeedSlice.size() >= 2 && "Should have been rejected!");
85
86 // Create a region containing the seed slice.
87 auto &Ctx = F.getContext();
88 RegionWithScore Rgn(Ctx, A.getTTI());
89 Rgn.setAux(SeedSlice);
90 // Run the region pass pipeline.
91 Change |= RPM.runOnRegion(Rgn, A);
92 Rgn.clearAux();
93 }
94 }
95 }
96 }
97 }
98 return Change;
99}
100} // namespace sandboxir
101} // namespace llvm
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define F(x, y, z)
Definition MD5.cpp:54
This pass exposes codegen information to IR-level passes.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
FunctionPass(StringRef Name)
Name can't contain any spaces or start with '-'.
Definition Pass.h:79
A Region class that tracks its instructions score.
void clearAux()
Clears all auxiliary data.
Definition Region.cpp:75
void setAux(unsigned Idx, Instruction *I)
Set I as the Idx'th element in the auxiliary vector.
Definition Region.cpp:46
A set of candidate Instructions for vectorizing together.
SeedCollection(StringRef Pipeline, StringRef AuxArg)
bool runOnFunction(Function &F, const Analyses &A) final
\Returns true if it modifies F.
iterator_range< SeedContainer::iterator > getLoadSeeds()
iterator_range< SeedContainer::iterator > getStoreSeeds()
static unsigned getNumBits(Type *Ty, const DataLayout &DL)
\Returns the number of bits of Ty.
Definition Utils.h:68
static Type * getExpectedType(const Value *V)
\Returns the expected type of Value V.
Definition Utils.h:34
static Type * getElementType(Type *Ty)
Returns Ty if scalar or its element type if vector.
Definition VecUtils.h:94
static LLVM_ABI unsigned getFloorPowerOf2(unsigned Num)
\Returns the first integer power of 2 that is <= Num.
Definition VecUtils.cpp:93
unsigned getLoadStoreAddressSpace(const Instruction *I)
A helper function that returns the address space of the pointer operand of load or store instruction.
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
const VectorizeOptions & getVectorizeOptions(const LLVMContext &C)