[Mlir-commits] [mlir] [XeVM] Add translation for XeVM cache-control attributes. (PR #181856)

Md Abdullah Shahneous Bari llvmlistbot at llvm.org
Sun Mar 1 12:41:25 PST 2026


================
@@ -17,19 +17,148 @@
 #include "mlir/IR/Operation.h"
 #include "mlir/Target/LLVMIR/ModuleTranslation.h"
 
+#include "mlir/Support/LLVM.h"
 #include "llvm/ADT/TypeSwitch.h"
+#include "llvm/IR/ConstantRange.h"
 #include "llvm/IR/Constants.h"
+#include "llvm/IR/DebugInfoMetadata.h"
+#include "llvm/IR/DebugLoc.h"
+#include "llvm/IR/GlobalVariable.h"
+#include "llvm/IR/IRBuilder.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Metadata.h"
-
-#include "llvm/IR/ConstantRange.h"
-#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/Module.h"
 #include "llvm/Support/raw_ostream.h"
 
 using namespace mlir;
 using namespace mlir::LLVM;
 
 namespace {
+//===----------------------------------------------------------------------===//
+// Utility functions for the translation
+//===----------------------------------------------------------------------===//
+// Extract the source filename from the debug location of \p inst, if available.
+static std::string getSourceFilename(const llvm::Instruction *inst) {
+  if (const llvm::DebugLoc &dbgLoc = inst->getDebugLoc()) {
+    if (auto *loc = dbgLoc.get()) {
+      if (llvm::DIFile *file = loc->getFile()) {
+        if (!file->getDirectory().empty())
+          return (file->getDirectory() + "/" + file->getFilename()).str();
+        return file->getFilename().str();
+      }
+    }
+  }
+  return "";
+}
+
+// Build one cache-control payload string per attribute.
+//
+// Each mlir::Attribute is expected to be an ArrayAttr of (at least) 3
+// IntegerAttr values: [SPIR-V token number of that attribute, value for L1
+// cache, value for L3 cache].
+//
+// A single entry produces a string that appears in LLVM IR as:
+//   {6442:\220,1\22}\00
+static llvm::SmallVector<std::string>
+buildCacheControlPayloads(llvm::ArrayRef<mlir::Attribute> attrs) {
+  llvm::SmallVector<std::string> payloads;
+  llvm::StringMap<bool> seen;
+
+  for (mlir::Attribute a : attrs) {
+    auto arr = mlir::dyn_cast<mlir::ArrayAttr>(a);
+    if (!arr)
+      continue;
+
+    auto vals = arr.getValue();
+    // Assert that the attribute has at most 4 integer values: [SPIR-V token, L1
+    // value, L3 value, optional extra value].
+    assert(vals.size() <= 4 &&
+           "Expected at most 4 integer values in cache control attribute.");
----------------
mshahneo wrote:

Fixed. Removed the ammendOperation logic since the cahce_control meta-data handling in now resides in XeVMToLLVM.

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


More information about the Mlir-commits mailing list