-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[SandboxVec][BottomUpVec] Implement InstrMaps #122848
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/InstrMaps.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| //===- InstrMaps.h ----------------------------------------------*- C++ -*-===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef LLVM_TRANSFORMS_VECTORIZE_SANDBOXVEC_PASSES_INSTRMAPS_H | ||
| #define LLVM_TRANSFORMS_VECTORIZE_SANDBOXVEC_PASSES_INSTRMAPS_H | ||
|
|
||
| #include "llvm/ADT/ArrayRef.h" | ||
| #include "llvm/ADT/DenseMap.h" | ||
| #include "llvm/ADT/SmallSet.h" | ||
| #include "llvm/ADT/SmallVector.h" | ||
| #include "llvm/SandboxIR/Value.h" | ||
| #include "llvm/Support/Casting.h" | ||
| #include "llvm/Support/raw_ostream.h" | ||
|
|
||
| namespace llvm::sandboxir { | ||
|
|
||
| /// Maps the original instructions to the vectorized instrs and the reverse. | ||
| /// For now an original instr can only map to a single vector. | ||
| class InstrMaps { | ||
| /// A map from the original values that got combined into vectors, to the | ||
| /// vector value(s). | ||
| DenseMap<Value *, Value *> OrigToVectorMap; | ||
| /// A map from the vector value to a map of the original value to its lane. | ||
| /// Please note that for constant vectors, there may multiple original values | ||
| /// with the same lane, as they may be coming from vectorizing different | ||
| /// original values. | ||
| DenseMap<Value *, DenseMap<Value *, unsigned>> VectorToOrigLaneMap; | ||
|
|
||
| public: | ||
| /// \Returns the vector value that we got from vectorizing \p Orig, or | ||
| /// nullptr if not found. | ||
| Value *getVectorForOrig(Value *Orig) const { | ||
| auto It = OrigToVectorMap.find(Orig); | ||
| return It != OrigToVectorMap.end() ? It->second : nullptr; | ||
| } | ||
| /// \Returns the lane of \p Orig before it got vectorized into \p Vec, or | ||
| /// nullopt if not found. | ||
| std::optional<unsigned> getOrigLane(Value *Vec, Value *Orig) const { | ||
| auto It1 = VectorToOrigLaneMap.find(Vec); | ||
| if (It1 == VectorToOrigLaneMap.end()) | ||
| return std::nullopt; | ||
| const auto &OrigToLaneMap = It1->second; | ||
| auto It2 = OrigToLaneMap.find(Orig); | ||
| if (It2 == OrigToLaneMap.end()) | ||
| return std::nullopt; | ||
| return It2->second; | ||
| } | ||
| /// Update the map to reflect that \p Origs got vectorized into \p Vec. | ||
| void registerVector(ArrayRef<Value *> Origs, Value *Vec) { | ||
| auto &OrigToLaneMap = VectorToOrigLaneMap[Vec]; | ||
| for (auto [Lane, Orig] : enumerate(Origs)) { | ||
| auto Pair = OrigToVectorMap.try_emplace(Orig, Vec); | ||
| assert(Pair.second && "Orig already exists in the map!"); | ||
| OrigToLaneMap[Orig] = Lane; | ||
| } | ||
| } | ||
| void clear() { | ||
| OrigToVectorMap.clear(); | ||
| VectorToOrigLaneMap.clear(); | ||
| } | ||
| #ifndef NDEBUG | ||
| void print(raw_ostream &OS) const { | ||
| OS << "OrigToVectorMap:\n"; | ||
| for (auto [Orig, Vec] : OrigToVectorMap) | ||
| OS << *Orig << " : " << *Vec << "\n"; | ||
| } | ||
| LLVM_DUMP_METHOD void dump() const; | ||
| #endif | ||
| }; | ||
| } // namespace llvm::sandboxir | ||
|
|
||
| #endif // LLVM_TRANSFORMS_VECTORIZE_SANDBOXVEC_PASSES_INSTRMAPS_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
llvm/lib/Transforms/Vectorize/SandboxVectorizer/InstrMaps.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| //===- InstructionMaps.cpp - Maps scalars to vectors and reverse ----------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "llvm/Transforms/Vectorize/SandboxVectorizer/InstrMaps.h" | ||
| #include "llvm/Support/Debug.h" | ||
|
|
||
| namespace llvm::sandboxir { | ||
|
|
||
| #ifndef NDEBUG | ||
| void InstrMaps::dump() const { | ||
| print(dbgs()); | ||
| dbgs() << "\n"; | ||
| } | ||
| #endif // NDEBUG | ||
|
|
||
| } // namespace llvm::sandboxir |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.