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

via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 12 08:12:03 PDT 2023


Author: Natalie Chouinard
Date: 2023-09-12T17:11:59+02:00
New Revision: c8d405323e2f7c4ce6d65168ad8e79f669feece2

URL: https://github.com/llvm/llvm-project/commit/c8d405323e2f7c4ce6d65168ad8e79f669feece2
DIFF: https://github.com/llvm/llvm-project/commit/c8d405323e2f7c4ce6d65168ad8e79f669feece2.diff

LOG: [SPIRV] Get pointer size from datalayout (#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.

Added: 
    

Modified: 
    llvm/lib/Target/SPIRV/SPIRVSubtarget.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/SPIRV/SPIRVSubtarget.cpp b/llvm/lib/Target/SPIRV/SPIRVSubtarget.cpp
index ced17aaeb17fe14..1bad1d8109623b6 100644
--- a/llvm/lib/Target/SPIRV/SPIRVSubtarget.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVSubtarget.cpp
@@ -47,28 +47,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