[clang] [llvm] [NVPTX] Change the alloca address space in NVPTXLowerAlloca (PR #154814)

Theodoros Theodoridis via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 1 08:43:23 PDT 2025


================
@@ -502,3 +497,27 @@ void NVPTXPassConfig::addMachineSSAOptimization() {
   addPass(&PeepholeOptimizerLegacyID);
   printAndVerify("After codegen peephole optimization pass");
 }
+
+bool NVPTXTargetMachine::isCompatibleDataLayout(
+    const DataLayout &Candidate) const {
+  // XXX: Should we enforce that the Candidate DataLayout has the same address
+  // space for allocas?
+  if (DL == Candidate)
+    return true;
+
+  auto DLStr = DL.getStringRepresentation();
+  if (!StringRef(DLStr).contains("A"))
+    DLStr = DLStr.empty() ? "A" + std::to_string(ADDRESS_SPACE_LOCAL)
+                          : DLStr + "-A" + std::to_string(ADDRESS_SPACE_LOCAL);
+  auto NewDL = DataLayout(DLStr);
+
+  return NewDL == Candidate;
----------------
thetheodor wrote:

The reason I've added this is: 
```
llc: /work/llvm-project/llvm/lib/CodeGen/MachineFunction.cpp:241: void llvm::MachineFunction::init(): Assertion `Target.isCompatibleDataLayout(getDataLayout()) && "Can't create a MachineFunction using a Module with a " "Target-incompatible DataLayout attached\n"' failed.
```
maybe a better alternative would be to instead change the `NVPTXTargetMachine`'s DL in `static std::string computeDataLayout(bool is64Bit, bool UseShortPointers)` ?

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


More information about the llvm-commits mailing list