Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deduplicate constant data tables #2849

Merged
merged 1 commit into from
Nov 29, 2023
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
16 changes: 12 additions & 4 deletions llpc/lower/llpcSpirvLowerConstImmediateStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ PreservedAnalyses SpirvLowerConstImmediateStore::run(Module &module, ModuleAnaly
// Process "alloca" instructions to see if they can be optimized to a read-only global
// variable.
bool changed = false;
m_allocToGlobals.clear();
for (auto &func : module.functions()) {
if (!func.empty()) {
if (processAllocaInsts(&func))
Expand Down Expand Up @@ -222,10 +223,17 @@ bool SpirvLowerConstImmediateStore::tryProcessAlloca(AllocaInst *allocaInst) {
}

// Step 3: Create the global variable and replace the alloca
auto global = new GlobalVariable(*m_module, allocatedTy,
true, // isConstant
GlobalValue::InternalLinkage, initializer, "", nullptr, GlobalValue::NotThreadLocal,
SPIRAS_Constant);
GlobalVariable *global = nullptr;
auto iter = m_allocToGlobals.find(initializer);
if (iter == m_allocToGlobals.end()) {
AMD-dwang marked this conversation as resolved.
Show resolved Hide resolved
global = new GlobalVariable(*m_module, allocatedTy,
true, // isConstant
GlobalValue::InternalLinkage, initializer, "", nullptr, GlobalValue::NotThreadLocal,
SPIRAS_Constant);
m_allocToGlobals[initializer] = global;
} else {
global = iter->second;
}
global->takeName(allocaInst);

for (Use &use : llvm::make_early_inc_range(allocaInst->uses()))
Expand Down
2 changes: 2 additions & 0 deletions llpc/lower/llpcSpirvLowerConstImmediateStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class SpirvLowerConstImmediateStore : public SpirvLower, public llvm::PassInfoMi
private:
bool processAllocaInsts(llvm::Function *func);
bool tryProcessAlloca(llvm::AllocaInst *allocaInst);

llvm::DenseMap<llvm::Value *, llvm::GlobalVariable *> m_allocToGlobals;
};

} // namespace Llpc
Loading