[llvm] [SPIR-V] Fix BB ordering & register lifetime (PR #111026)
Steven Perron via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 28 09:57:57 PDT 2024
Nathan =?utf-8?q?Gauër?= <brioche at google.com>,
Nathan =?utf-8?q?Gauër?= <brioche at google.com>,
Nathan =?utf-8?q?Gauër?= <brioche at google.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/111026 at github.com>
================
@@ -447,55 +439,51 @@ class SPIRVStructurizer : public FunctionPass {
// clang-format on
std::vector<Edge>
createAliasBlocksForComplexEdges(std::vector<Edge> Edges) {
- std::unordered_map<BasicBlock *, BasicBlock *> Seen;
+ std::unordered_set<BasicBlock *> Seen;
std::vector<Edge> Output;
Output.reserve(Edges.size());
for (auto &[Src, Dst] : Edges) {
- auto [iterator, inserted] = Seen.insert({Src, Dst});
- if (inserted) {
- Output.emplace_back(Src, Dst);
- continue;
+ auto [iterator, inserted] = Seen.insert(Src);
+ if (!inserted) {
+ // Src already a source node. Cannot have 2 edges from A to B.
+ // Creating alias source block.
+ BasicBlock *NewSrc =
+ BasicBlock::Create(F.getContext(), "new.src", &F);
+ replaceBranchTargets(Src, Dst, NewSrc);
+ IRBuilder<> Builder(NewSrc);
+ Builder.CreateBr(Dst);
+ Src = NewSrc;
}
- // The exact same edge was already seen. Ignoring.
- if (iterator->second == Dst)
- continue;
-
- // The same Src block branches to 2 distinct blocks. This will be an
- // issue for the generated OpPhi. Creating alias block.
- BasicBlock *NewSrc =
- BasicBlock::Create(F.getContext(), "new.exit.src", &F);
- replaceBranchTargets(Src, Dst, NewSrc);
- replacePhiTargets(Dst, Src, NewSrc);
-
- IRBuilder<> Builder(NewSrc);
- Builder.CreateBr(Dst);
-
- Seen.emplace(NewSrc, Dst);
- Output.emplace_back(NewSrc, Dst);
+ Output.emplace_back(Src, Dst);
}
return Output;
}
+ AllocaInst *CreateVariable(Function &F, Type *Type,
+ BasicBlock::iterator Position) {
+ const DataLayout &DL = F.getDataLayout();
+ return new AllocaInst(Type, DL.getAllocaAddrSpace(), nullptr, "reg",
+ Position);
+ }
+
// Given a construct defined by |Header|, and a list of exiting edges
// |Edges|, creates a new single exit node, fixing up those edges.
BasicBlock *createSingleExitNode(BasicBlock *Header,
std::vector<Edge> &Edges) {
- auto NewExit = BasicBlock::Create(F.getContext(), "new.exit", &F);
- IRBuilder<> ExitBuilder(NewExit);
-
- std::vector<BasicBlock *> Dsts;
- std::unordered_map<BasicBlock *, ConstantInt *> DstToIndex;
-
// Given 2 edges: Src1 -> Dst, Src2 -> Dst:
// If Dst has an PHI node, and Src1 and Src2 are both operands, both Src1
// and Src2 cannot be hidden by NewExit. Create 2 new nodes: Alias1,
// Alias2 to which NewExit will branch before going to Dst. Then, patchup
// Dst PHI node to look for Alias1 and Alias2.
----------------
s-perron wrote:
Please check all of the comments. I don't think these comment are still valid because you remove Phi nodes before running this pass right?
https://github.com/llvm/llvm-project/pull/111026
More information about the llvm-commits
mailing list