Skip to content

Commit 8dfd263

Browse files
authored
[SPIR-V][NFC] Remove useless function (#8409)
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.
1 parent ec9d97a commit 8dfd263

3 files changed

Lines changed: 8 additions & 32 deletions

File tree

tools/clang/lib/SPIRV/DeclResultIdMapper.cpp

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1838,7 +1838,7 @@ SpirvFunction *DeclResultIdMapper::getOrRegisterFn(const FunctionDecl *fn) {
18381838
return spirvFunction;
18391839
}
18401840

1841-
const CounterIdAliasPair *DeclResultIdMapper::getCounterIdAliasPair(
1841+
const CounterIdAliasPair *DeclResultIdMapper::getOrCreateCounterIdAliasPair(
18421842
const DeclaratorDecl *decl, const llvm::SmallVector<uint32_t, 4> *indices) {
18431843
if (!decl)
18441844
return nullptr;
@@ -1867,24 +1867,6 @@ const CounterIdAliasPair *DeclResultIdMapper::getCounterIdAliasPair(
18671867
return nullptr;
18681868
}
18691869

1870-
const CounterIdAliasPair *
1871-
DeclResultIdMapper::createOrGetCounterIdAliasPair(const DeclaratorDecl *decl) {
1872-
auto counterPair = getCounterIdAliasPair(decl);
1873-
if (counterPair)
1874-
return counterPair;
1875-
if (!decl)
1876-
return nullptr;
1877-
// If deferred RWStructuredBuffer, try creating the counter now
1878-
auto declInstr = declRWSBuffers[decl];
1879-
if (declInstr) {
1880-
createCounterVar(decl, declInstr, /*isAlias*/ false);
1881-
auto counter = counterVars.find(decl);
1882-
assert(counter != counterVars.end() && "counter not found");
1883-
return &counter->second;
1884-
}
1885-
return nullptr;
1886-
}
1887-
18881870
const CounterVarFields *
18891871
DeclResultIdMapper::getCounterVarFields(const DeclaratorDecl *decl) {
18901872
if (!decl)

tools/clang/lib/SPIRV/DeclResultIdMapper.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -492,18 +492,12 @@ class DeclResultIdMapper {
492492
/// \brief Returns the associated counter's (instr-ptr, is-alias-or-not)
493493
/// pair for the given {RW|Append|Consume}StructuredBuffer variable.
494494
/// If indices is not nullptr, walks trhough the fields of the decl, expected
495-
/// to be of struct type, using the indices to find the field. Returns nullptr
496-
/// if the given decl has no associated counter variable created.
497-
const CounterIdAliasPair *getCounterIdAliasPair(
495+
/// to be of struct type, using the indices to find the field.
496+
/// Creates counter for RW buffer if not already created.
497+
const CounterIdAliasPair *getOrCreateCounterIdAliasPair(
498498
const DeclaratorDecl *decl,
499499
const llvm::SmallVector<uint32_t, 4> *indices = nullptr);
500500

501-
/// \brief Returns the associated counter's (instr-ptr, is-alias-or-not)
502-
/// pair for the given {RW|Append|Consume}StructuredBuffer variable. Creates
503-
/// counter for RW buffer if not already created.
504-
const CounterIdAliasPair *
505-
createOrGetCounterIdAliasPair(const DeclaratorDecl *decl);
506-
507501
/// \brief Returns all the associated counters for the given decl. The decl is
508502
/// expected to be a struct containing alias RW/Append/Consume structured
509503
/// buffers. Returns nullptr if it does not.

tools/clang/lib/SPIRV/SpirvEmitter.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5105,7 +5105,7 @@ bool SpirvEmitter::tryToAssignCounterVar(const DeclaratorDecl *dstDecl,
51055105

51065106
// Handle AssocCounter#1 (see CounterVarFields comment)
51075107
if (const auto *dstPair =
5108-
declIdMapper.createOrGetCounterIdAliasPair(dstDecl)) {
5108+
declIdMapper.getOrCreateCounterIdAliasPair(dstDecl)) {
51095109
auto *srcCounter = getFinalACSBufferCounterInstruction(srcExpr);
51105110
if (!srcCounter) {
51115111
emitFatalError("cannot find the associated counter variable",
@@ -5213,13 +5213,13 @@ const CounterIdAliasPair *
52135213
SpirvEmitter::getFinalACSBufferCounter(const Expr *expr) {
52145214
// AssocCounter#1: referencing some stand-alone variable
52155215
if (const auto *decl = getReferencedDef(expr))
5216-
return declIdMapper.createOrGetCounterIdAliasPair(decl);
5216+
return declIdMapper.getOrCreateCounterIdAliasPair(decl);
52175217

52185218
const Expr *expr_withoutcasts = expr->IgnoreParenCasts();
52195219
if (isResourceDescriptorHeap(expr_withoutcasts->getType())) {
52205220
const Expr *base = nullptr;
52215221
getDescriptorHeapOperands(expr_withoutcasts, &base, /* index= */ nullptr);
5222-
return declIdMapper.createOrGetCounterIdAliasPair(getReferencedDef(base));
5222+
return declIdMapper.getOrCreateCounterIdAliasPair(getReferencedDef(base));
52235223
}
52245224

52255225
// AssocCounter#2: referencing some non-struct field
@@ -5230,7 +5230,7 @@ SpirvEmitter::getFinalACSBufferCounter(const Expr *expr) {
52305230
(base && isa<CXXThisExpr>(base))
52315231
? getOrCreateDeclForMethodObject(cast<CXXMethodDecl>(curFunction))
52325232
: getReferencedDef(base);
5233-
return declIdMapper.getCounterIdAliasPair(decl, &rawIndices);
5233+
return declIdMapper.getOrCreateCounterIdAliasPair(decl, &rawIndices);
52345234
}
52355235

52365236
const CounterVarFields *SpirvEmitter::getIntermediateACSBufferCounter(

0 commit comments

Comments
 (0)