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 =
34 F.getContext().getLibraryOptions().get<VectorizeOptions>();
35 bool Change = false;
36 const auto &DL = F.getParent()->getDataLayout();
37
38 // TODO: Start from innermost BBs first
39 for (auto &BB : F) {
40 SeedCollector SC(&BB, A.getScalarEvolution(), CollectStores, CollectLoads,
41 AllowDiffTypes);
42 for (auto &SeedRange : {SC.getStoreSeeds(), SC.getLoadSeeds()}) {
43 for (SeedBundle &Seeds : SeedRange) {
44 if (Seeds.allUsed())
45 continue;
46 unsigned FirstUnusedIdx = Seeds.getFirstUnusedElementIdx();
47 unsigned ElmBits =
49 Seeds[FirstUnusedIdx])),
50 DL);
51 unsigned AS = getLoadStoreAddressSpace(Seeds[FirstUnusedIdx]);
52 unsigned VecRegBits = Opts.sbvec_vec_reg_bits != 0
53 ? Opts.sbvec_vec_reg_bits
54 : A.getTTI().getLoadStoreVecRegBitWidth(AS);
55
56 auto DivideBy2 = [](unsigned Num) {
57 auto Floor = VecUtils::getFloorPowerOf2(Num);
58 if (Floor == Num)
59 return Floor / 2;
60 return Floor;
61 };
62 // Try to create the largest vector supported by the target. If it fails
63 // reduce the vector size by half.
64 for (unsigned SliceElms = std::min(VecRegBits / ElmBits,
65 Seeds.getNumUnusedBits() / ElmBits);
66 SliceElms >= 2u; SliceElms = DivideBy2(SliceElms)) {
67 if (Seeds.allUsed())
68 break;
69 // Keep trying offsets after FirstUnusedElementIdx, until we vectorize
70 // the slice. This could be quite expensive, so we enforce a limit.
71 for (unsigned Offset = Seeds.getFirstUnusedElementIdx(),
72 OE = Seeds.size();
73 Offset + 1 < OE; Offset += 1) {
74 // Seeds are getting used as we vectorize, so skip them.
75 if (Seeds.isUsed(Offset))
76 continue;
77 if (Seeds.allUsed())
78 break;
79
80 auto SeedSlice = Seeds.getSlice(Offset, SliceElms * ElmBits,
81 !Opts.sbvec_allow_non_pow2);
82 if (SeedSlice.empty())
83 continue;
84
85 assert(SeedSlice.size() >= 2 && "Should have been rejected!");
86
87 // Create a region containing the seed slice.
88 auto &Ctx = F.getContext();
89 RegionWithScore Rgn(Ctx, A.getTTI());
90 Rgn.setAux(SeedSlice);
91 // Run the region pass pipeline.
92 Change |= RPM.runOnRegion(Rgn, A);
93 Rgn.clearAux();
94 }
95 }
96 }
97 }
98 }
99 return Change;
100}
101} // namespace sandboxir
102} // 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:67
static Type * getExpectedType(const Value *V)
\Returns the expected type of Value V.
Definition Utils.h:33
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:94
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