-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[SandboxVectorizer] Add MemSeed bundle types #111584
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -123,5 +123,44 @@ class SeedBundle { | |
| } | ||
| #endif // NDEBUG | ||
| }; | ||
|
|
||
| /// Specialization of SeedBundle for memory access instructions. Keeps | ||
| /// seeds sorted in ascending memory order, which is convenient for slicing | ||
| /// these bundles into vectorizable groups. | ||
| template <typename LoadOrStoreT> class MemSeedBundle : public SeedBundle { | ||
| public: | ||
| explicit MemSeedBundle(SmallVector<Instruction *> &&SV, ScalarEvolution &SE) | ||
| : SeedBundle(std::move(SV)) { | ||
| static_assert(std::is_same<LoadOrStoreT, LoadInst>::value || | ||
| std::is_same<LoadOrStoreT, StoreInst>::value, | ||
| "Expected LoadInst or StoreInst!"); | ||
| assert(all_of(Seeds, [](auto *S) { return isa<LoadOrStoreT>(S); }) && | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps a static assert?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| "Expected Load or Store instructions!"); | ||
| auto Cmp = [&SE](Instruction *I0, Instruction *I1) { | ||
| return Utils::atLowerAddress(cast<LoadOrStoreT>(I0), | ||
| cast<LoadOrStoreT>(I1), SE); | ||
| }; | ||
| std::sort(Seeds.begin(), Seeds.end(), Cmp); | ||
| } | ||
| explicit MemSeedBundle(LoadOrStoreT *MemI) : SeedBundle(MemI) { | ||
| static_assert(std::is_same<LoadOrStoreT, LoadInst>::value || | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm actually don't we actually need only one static assert? The compiler should crash if we keep the one in the constructor.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are two constructors. One for a single instruction, one for a list. Not sure which will end up being more used. |
||
| std::is_same<LoadOrStoreT, StoreInst>::value, | ||
| "Expected LoadInst or StoreInst!"); | ||
| assert(isa<LoadOrStoreT>(MemI) && "Expected Load or Store!"); | ||
| } | ||
| void insert(sandboxir::Instruction *I, ScalarEvolution &SE) { | ||
| assert(isa<LoadOrStoreT>(I) && "Expected a Store or a Load!"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same, static_assert.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| auto Cmp = [&SE](Instruction *I0, Instruction *I1) { | ||
| return Utils::atLowerAddress(cast<LoadOrStoreT>(I0), | ||
| cast<LoadOrStoreT>(I1), SE); | ||
| }; | ||
| // Find the first element after I in mem. Then insert I before it. | ||
| insertAt(std::upper_bound(begin(), end(), I, Cmp), I); | ||
| } | ||
| }; | ||
|
|
||
| using StoreSeedBundle = MemSeedBundle<sandboxir::StoreInst>; | ||
| using LoadSeedBundle = MemSeedBundle<sandboxir::LoadInst>; | ||
|
|
||
| } // namespace llvm::sandboxir | ||
| #endif // LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_SEEDCOLLECTOR_H | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A brief description comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done