Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 1 addition & 19 deletions tools/clang/lib/SPIRV/DeclResultIdMapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t, 4> *indices) {
if (!decl)
return nullptr;
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 3 additions & 9 deletions tools/clang/lib/SPIRV/DeclResultIdMapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t, 4> *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.
Expand Down
8 changes: 4 additions & 4 deletions tools/clang/lib/SPIRV/SpirvEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand All @@ -5230,7 +5230,7 @@ SpirvEmitter::getFinalACSBufferCounter(const Expr *expr) {
(base && isa<CXXThisExpr>(base))
? getOrCreateDeclForMethodObject(cast<CXXMethodDecl>(curFunction))
: getReferencedDef(base);
return declIdMapper.getCounterIdAliasPair(decl, &rawIndices);
return declIdMapper.getOrCreateCounterIdAliasPair(decl, &rawIndices);
}

const CounterVarFields *SpirvEmitter::getIntermediateACSBufferCounter(
Expand Down
Loading