From 8ef58939c041e1c3a04786edbbdd844d3458dda7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nathan=20Gau=C3=ABr?= Date: Mon, 27 Apr 2026 15:51:08 +0200 Subject: [PATCH] [SPIR-V][NFC] Remove useless function The removed function was getting or creating a counter. But the called function (called *get* counter) was also creating the counter with the same pattern if no counter was found. This essentially meant the parent create code was dead code. --- tools/clang/lib/SPIRV/DeclResultIdMapper.cpp | 20 +------------------- tools/clang/lib/SPIRV/DeclResultIdMapper.h | 12 +++--------- tools/clang/lib/SPIRV/SpirvEmitter.cpp | 8 ++++---- 3 files changed, 8 insertions(+), 32 deletions(-) diff --git a/tools/clang/lib/SPIRV/DeclResultIdMapper.cpp b/tools/clang/lib/SPIRV/DeclResultIdMapper.cpp index 97d81844fb..1a1078bf0b 100644 --- a/tools/clang/lib/SPIRV/DeclResultIdMapper.cpp +++ b/tools/clang/lib/SPIRV/DeclResultIdMapper.cpp @@ -1838,7 +1838,7 @@ SpirvFunction *DeclResultIdMapper::getOrRegisterFn(const FunctionDecl *fn) { return spirvFunction; } -const CounterIdAliasPair *DeclResultIdMapper::getCounterIdAliasPair( +const CounterIdAliasPair *DeclResultIdMapper::getOrCreateCounterIdAliasPair( const DeclaratorDecl *decl, const llvm::SmallVector *indices) { if (!decl) return nullptr; @@ -1867,24 +1867,6 @@ const CounterIdAliasPair *DeclResultIdMapper::getCounterIdAliasPair( return nullptr; } -const CounterIdAliasPair * -DeclResultIdMapper::createOrGetCounterIdAliasPair(const DeclaratorDecl *decl) { - auto counterPair = getCounterIdAliasPair(decl); - if (counterPair) - return counterPair; - if (!decl) - return nullptr; - // If deferred RWStructuredBuffer, try creating the counter now - auto declInstr = declRWSBuffers[decl]; - if (declInstr) { - createCounterVar(decl, declInstr, /*isAlias*/ false); - auto counter = counterVars.find(decl); - assert(counter != counterVars.end() && "counter not found"); - return &counter->second; - } - return nullptr; -} - const CounterVarFields * DeclResultIdMapper::getCounterVarFields(const DeclaratorDecl *decl) { if (!decl) diff --git a/tools/clang/lib/SPIRV/DeclResultIdMapper.h b/tools/clang/lib/SPIRV/DeclResultIdMapper.h index 17ea739fee..6e8177edf2 100644 --- a/tools/clang/lib/SPIRV/DeclResultIdMapper.h +++ b/tools/clang/lib/SPIRV/DeclResultIdMapper.h @@ -492,18 +492,12 @@ class DeclResultIdMapper { /// \brief Returns the associated counter's (instr-ptr, is-alias-or-not) /// pair for the given {RW|Append|Consume}StructuredBuffer variable. /// If indices is not nullptr, walks trhough the fields of the decl, expected - /// to be of struct type, using the indices to find the field. Returns nullptr - /// if the given decl has no associated counter variable created. - const CounterIdAliasPair *getCounterIdAliasPair( + /// to be of struct type, using the indices to find the field. + /// Creates counter for RW buffer if not already created. + const CounterIdAliasPair *getOrCreateCounterIdAliasPair( const DeclaratorDecl *decl, const llvm::SmallVector *indices = nullptr); - /// \brief Returns the associated counter's (instr-ptr, is-alias-or-not) - /// pair for the given {RW|Append|Consume}StructuredBuffer variable. Creates - /// counter for RW buffer if not already created. - const CounterIdAliasPair * - createOrGetCounterIdAliasPair(const DeclaratorDecl *decl); - /// \brief Returns all the associated counters for the given decl. The decl is /// expected to be a struct containing alias RW/Append/Consume structured /// buffers. Returns nullptr if it does not. diff --git a/tools/clang/lib/SPIRV/SpirvEmitter.cpp b/tools/clang/lib/SPIRV/SpirvEmitter.cpp index 936359e25c..8da3a3e6a0 100644 --- a/tools/clang/lib/SPIRV/SpirvEmitter.cpp +++ b/tools/clang/lib/SPIRV/SpirvEmitter.cpp @@ -5105,7 +5105,7 @@ bool SpirvEmitter::tryToAssignCounterVar(const DeclaratorDecl *dstDecl, // Handle AssocCounter#1 (see CounterVarFields comment) if (const auto *dstPair = - declIdMapper.createOrGetCounterIdAliasPair(dstDecl)) { + declIdMapper.getOrCreateCounterIdAliasPair(dstDecl)) { auto *srcCounter = getFinalACSBufferCounterInstruction(srcExpr); if (!srcCounter) { emitFatalError("cannot find the associated counter variable", @@ -5213,13 +5213,13 @@ const CounterIdAliasPair * SpirvEmitter::getFinalACSBufferCounter(const Expr *expr) { // AssocCounter#1: referencing some stand-alone variable if (const auto *decl = getReferencedDef(expr)) - return declIdMapper.createOrGetCounterIdAliasPair(decl); + return declIdMapper.getOrCreateCounterIdAliasPair(decl); const Expr *expr_withoutcasts = expr->IgnoreParenCasts(); if (isResourceDescriptorHeap(expr_withoutcasts->getType())) { const Expr *base = nullptr; getDescriptorHeapOperands(expr_withoutcasts, &base, /* index= */ nullptr); - return declIdMapper.createOrGetCounterIdAliasPair(getReferencedDef(base)); + return declIdMapper.getOrCreateCounterIdAliasPair(getReferencedDef(base)); } // AssocCounter#2: referencing some non-struct field @@ -5230,7 +5230,7 @@ SpirvEmitter::getFinalACSBufferCounter(const Expr *expr) { (base && isa(base)) ? getOrCreateDeclForMethodObject(cast(curFunction)) : getReferencedDef(base); - return declIdMapper.getCounterIdAliasPair(decl, &rawIndices); + return declIdMapper.getOrCreateCounterIdAliasPair(decl, &rawIndices); } const CounterVarFields *SpirvEmitter::getIntermediateACSBufferCounter(