[llvm] [AMDGPU][StructurizeCFG] Maintain branch MD_prof metadata (PR #109813)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 24 08:23:51 PDT 2024


Juan Manuel Martinez =?utf-8?q?CaamaƱo?= <juamarti at amd.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/109813 at github.com>


================
@@ -85,7 +87,46 @@ using PhiMap = MapVector<PHINode *, BBValueVector>;
 using BB2BBVecMap = MapVector<BasicBlock *, BBVector>;
 
 using BBPhiMap = DenseMap<BasicBlock *, PhiMap>;
-using BBPredicates = DenseMap<BasicBlock *, Value *>;
+
+using MaybeCondBranchWeights = std::optional<class CondBranchWeights>;
+
+class CondBranchWeights {
+  uint32_t TrueWeight;
+  uint32_t FalseWeight;
+
+public:
+  CondBranchWeights(unsigned T, unsigned F) : TrueWeight(T), FalseWeight(F) {}
+
+  static MaybeCondBranchWeights tryParse(const BranchInst &Br) {
+    assert(Br.isConditional());
+
+    SmallVector<uint32_t, 2> Weights;
+    if (!extractBranchWeights(Br, Weights))
+      return std::nullopt;
+
+    if (Weights.size() != 2)
+      return std::nullopt;
----------------
arsenm wrote:

I assume the verifier enforces the number of entries matches the number of successors, so I assume you don't need to check this.

There also looks like a variant of extractBranchWeights with 2 outputs you can use instead of the SmallVector one 

https://github.com/llvm/llvm-project/pull/109813


More information about the llvm-commits mailing list