[llvm] [CodeGen] Add OffloadBlockUniformityAnalysis for offload PGO (PR #178417)
Shilei Tian via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 29 08:29:54 PST 2026
================
@@ -0,0 +1,81 @@
+//===- OffloadBlockUniformity.h - Offload block uniformity info -*- 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
+//
+//===----------------------------------------------------------------------===//
+//
+// Provide per-(Machine)basic-block uniformity information for offload profiles.
+//
+// The source of truth is IR metadata attached during PGO use:
+// - Metadata name: "offload-block-uniformity"
+// - Payload: i1 (true = uniform, false = divergent)
+//
+// This is intentionally target-agnostic: any offload backend that produces
+// uniformity bits in the profile can attach the same metadata and reuse this
+// analysis in codegen.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CODEGEN_OFFLOADBLOCKUNIFORMITY_H
+#define LLVM_CODEGEN_OFFLOADBLOCKUNIFORMITY_H
+
+#include "llvm/ADT/BitVector.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/CodeGen/MachineFunctionAnalysis.h"
+#include "llvm/CodeGen/MachineFunctionAnalysisManager.h"
+#include "llvm/CodeGen/MachinePassManager.h"
+#include "llvm/Support/Compiler.h"
+
+namespace llvm {
+
+class MachineBasicBlock;
+class MachineFunction;
+class raw_ostream;
+
+class OffloadBlockUniformityInfo {
+public:
+ static constexpr StringLiteral MetadataName = "offload-block-uniformity";
+
+ LLVM_ABI void compute(const MachineFunction &MF);
+
+ bool hasUniformity() const { return HasAnyUniformity; }
+
+ // Returns true if the block is considered divergent. If uniformity exists for
+ // the function but a block has no explicit annotation, it is treated as
+ // divergent (conservative).
+ LLVM_ABI bool isDivergent(const MachineBasicBlock &MBB) const;
+
+ LLVM_ABI void print(raw_ostream &OS, const MachineFunction &MF) const;
+
+private:
+ bool HasAnyUniformity = false;
+ BitVector DivergentBlocks;
+};
+
+class OffloadBlockUniformityAnalysis
----------------
shiltian wrote:
Does it have to be call it `OffloadBlockUniformityAnalysis` (the "Offload" part)? I think the uniformity analysis doesn't need to be about offload.
https://github.com/llvm/llvm-project/pull/178417
More information about the llvm-commits
mailing list