[llvm] [CodeGen] Add OffloadBlockUniformityAnalysis for offload PGO (PR #178417)
Juan Manuel Martinez CaamaƱo via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 30 07:21:15 PST 2026
================
@@ -0,0 +1,117 @@
+//===- OffloadBlockUniformity.cpp - Offload block uniformity info --------===//
+//
+// 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/CodeGen/OffloadBlockUniformity.h"
+#include "llvm/CodeGen/MachineBasicBlock.h"
+#include "llvm/CodeGen/MachineFunction.h"
+#include "llvm/IR/BasicBlock.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/Instruction.h"
+#include "llvm/IR/Metadata.h"
+#include "llvm/Support/raw_ostream.h"
+#include <optional>
+
+using namespace llvm;
+
+static std::optional<bool> getIRBlockUniformity(const BasicBlock &BB) {
+ const Instruction *TI = BB.getTerminator();
+ if (!TI)
+ return std::nullopt;
+
+ MDNode *MD = TI->getMetadata(OffloadBlockUniformityInfo::MetadataName);
+ if (!MD)
+ return std::nullopt;
+
+ // Metadata format: !{i1 IsUniform} - structural validity assumed (verifier).
+ return mdconst::extract<ConstantInt>(MD->getOperand(0))->isOne();
----------------
jmmartinez wrote:
We currently can represent 3 states: with-metadata uniform, with-metadata divergent and without-metadata (interpreted as divergent).
I'm not against this, but have you thought about not attaching metadata at all when divergent? Then we would only attach metadata for unform branches.
https://github.com/llvm/llvm-project/pull/178417
More information about the llvm-commits
mailing list