[llvm] [SPIRV] Get pointer size from datalayout (PR #66096)

Natalie Chouinard via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 12 08:05:23 PDT 2023


https://github.com/sudonatalie created https://github.com/llvm/llvm-project/pull/66096:

Get the pointer size from the datalayout via the TargetMachine and remove the helper function that hardcoded it. This fixes an issue caused by mismatched pointer sizes between the two for logical SPIR-V, since the computePointerSize function still defaulted to 32-bit ptr sizes.

>From 996ca0dc79f2121b3d415d7040e8faa29e6be9d5 Mon Sep 17 00:00:00 2001
From: Natalie Chouinard <chouinard at google.com>
Date: Tue, 12 Sep 2023 15:00:23 +0000
Subject: [PATCH] [SPIRV] Get pointer size from datalayout

Get the pointer size from the datalayout via the TargetMachine and
remove the helper function that hardcoded it. This fixes an issue caused
by mismatched pointer sizes between the two for logical SPIR-V, since
the computePointerSize function still defaulted to 32-bit ptr sizes.
---
 llvm/lib/Target/SPIRV/SPIRVSubtarget.cpp | 22 ++++------------------
 1 file changed, 4 insertions(+), 18 deletions(-)

diff --git a/llvm/lib/Target/SPIRV/SPIRVSubtarget.cpp b/llvm/lib/Target/SPIRV/SPIRVSubtarget.cpp
index d1d7a31dbaf48c9..4383b9762ccb004 100644
--- a/llvm/lib/Target/SPIRV/SPIRVSubtarget.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVSubtarget.cpp
@@ -32,28 +32,14 @@ static bool isAtLeastVer(uint32_t Target, uint32_t VerToCompareTo) {
   return Target == 0 || Target >= VerToCompareTo;
 }
 
-static unsigned computePointerSize(const Triple &TT) {
-  const auto Arch = TT.getArch();
-  // TODO: unify this with pointers legalization.
-  assert(TT.isSPIRV());
-
-  if (Arch == Triple::spirv64)
-    return 64;
-
-  // TODO: this probably needs to be revisited:
-  //  AFAIU Logical SPIR-V has no pointer size. So falling-back on ID size.
-  //  Addressing mode can change how some pointers are handled
-  //  (PhysicalStorageBuffer64).
-  return 32;
-}
-
 SPIRVSubtarget::SPIRVSubtarget(const Triple &TT, const std::string &CPU,
                                const std::string &FS,
                                const SPIRVTargetMachine &TM)
     : SPIRVGenSubtargetInfo(TT, CPU, /*TuneCPU=*/CPU, FS),
-      PointerSize(computePointerSize(TT)), SPIRVVersion(0), OpenCLVersion(0),
-      InstrInfo(), FrameLowering(initSubtargetDependencies(CPU, FS)),
-      TLInfo(TM, *this), TargetTriple(TT) {
+      PointerSize(TM.getPointerSizeInBits(/* AS= */ 0)), SPIRVVersion(0),
+      OpenCLVersion(0), InstrInfo(),
+      FrameLowering(initSubtargetDependencies(CPU, FS)), TLInfo(TM, *this),
+      TargetTriple(TT) {
   // The order of initialization is important.
   initAvailableExtensions();
   initAvailableExtInstSets();



More information about the llvm-commits mailing list