================
@@ -34,6 +37,87 @@ enum GPUKind : uint8_t {
#include "llvm/TargetParser/IntelGPUTargetParser.def"
};
+/// Represents an IGCA feature set, including whether or not it is exact. The
+/// values are bitfields where the last bit represents exact. See IGCA Target
+/// representation below for more info.
+enum class IGCAFeatureSet : uint8_t {
+ Core = 0b000,
+ Compute = 0b010,
+ ComputeExact = 0b011,
+ Render = 0b100,
+ RenderExact = 0b101,
+};
+
+/// Wrapper around an IGCA target's uint32_t representation, packed using the
+/// following format:
+///
+/// 31 16 15 3 2 1 0 0
+/// +------------------+--------------+-------------+-----------+
+/// | Target | Reserved | Feature set | Is Exact? |
+/// +------------------+--------------+-------------+-----------+
+/// 16 bits 13 bits 2 bits 1 bit
+///
+/// Target == 0 denotes an invalid IGCA Target.
+class IGCATarget {
+ uint32_t V = 0;
+ constexpr explicit IGCATarget(uint32_t V) : V(V) {}
+
+public:
+ static constexpr uint32_t TargetShift = 16;
+ static constexpr uint32_t FeatureSetMask = 0x7;
+ static constexpr uint32_t IsExactMask = 0x1;
+
+ constexpr IGCATarget(uint16_t Target, IGCAFeatureSet FeatureSet)
+ : V(uint32_t(Target) << TargetShift |
+ (llvm::to_underlying(FeatureSet) & FeatureSetMask)) {}
+
+ /// \return an invalid IGCATarget.
+ static constexpr IGCATarget invalid() { return IGCATarget(0); }
+
+ /// \return the packed uint32_t representation of the IGCA target.
+ constexpr uint32_t pack() const { return V; }
+ /// Wrap a packed uint32_t IGCA target with an IGCATarget class.
+ static constexpr IGCATarget unpack(uint32_t V) { return IGCATarget(V); }
+
+ uint16_t getTarget() const { return uint16_t(V >> TargetShift); }
+ /// \return the feature set, including whether it is exact.
+ ///
+ /// To check if a target has a feature set regardless of exactness, use
+ /// hasCompute() or hasRender() instead of raw comparison between
+ /// IGCAFeatureSet enums.
+ IGCAFeatureSet getFeatureSet() const {
+ return IGCAFeatureSet(V & FeatureSetMask);
+ }
+ bool isExact() const { return V & IsExactMask; }
+ bool isValid() const { return getTarget() != 0; }
----------------
ianayl wrote:
I've gone ahead and made it such that `IGCATarget` constructed with a value
combination that isn't in the `INTEL_IGCA_TARGET` table automatically defaults
to 0 / invalid: This means now any `IGCATarget` object with a target != 0 is a
truly "valid" IGCA target.
I've also fixed some of my handwritten comments, thanks for the catch 😅
https://github.com/llvm/llvm-project/pull/227468
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits