Skip to content

Commit

Permalink
Update batched
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Hellmuth <[email protected]>
  • Loading branch information
chellmuth committed Aug 17, 2023
1 parent c2a58ce commit 7006603
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
21 changes: 17 additions & 4 deletions src/liboslexec/batched_backendllvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,10 @@ BatchedBackendLLVM::getLLVMSymbolBase(const Symbol& sym)
llvm_ptr_type(sym.typespec().elementtype()));
}

if (sym.symtype() == SymTypeParam || sym.symtype() == SymTypeOutputParam) {
// Special case for params -- they live in the group data
if (sym.symtype() == SymTypeParam
|| sym.symtype() == SymTypeOutputParam
&& !can_treat_param_as_local(sym)) {
// Special case for most params -- they live in the group data
int fieldnum = m_param_order_map[&sym];
return groupdata_field_ptr(fieldnum,
sym.typespec().elementtype().simpletype(),
Expand Down Expand Up @@ -507,7 +509,6 @@ BatchedBackendLLVM::llvm_alloca(const TypeSpec& type, bool derivs,
}



BatchedBackendLLVM::TempScope::TempScope(BatchedBackendLLVM& backend)
: m_backend(backend)
{
Expand Down Expand Up @@ -573,14 +574,26 @@ BatchedBackendLLVM::getOrAllocateTemp(const TypeSpec& type, bool derivs,
return allocation;
}

bool
BatchedBackendLLVM::can_treat_param_as_local(const Symbol& sym)
{
if (!shadingsys().m_opt_groupdata)
return false;

// Some output parameters that are never needed before or
// after layer execution can be relocated from GroupData
// onto the stack.
return sym.symtype() == SymTypeOutputParam && !sym.renderer_output()
&& !sym.typespec().is_closure_based() && !sym.connected();
}


llvm::Value*
BatchedBackendLLVM::getOrAllocateLLVMSymbol(const Symbol& sym)
{
OSL_DASSERT(
(sym.symtype() == SymTypeLocal || sym.symtype() == SymTypeTemp
|| sym.symtype() == SymTypeConst)
|| sym.symtype() == SymTypeConst || can_treat_param_as_local(sym))
&& "getOrAllocateLLVMSymbol should only be for local, tmp, const");
Symbol* dealiased = sym.dealias();
std::string mangled_name = dealiased->mangled();
Expand Down
3 changes: 3 additions & 0 deletions src/liboslexec/batched_backendllvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,9 @@ class BatchedBackendLLVM : public OSOProcessorBase {
name);
}

/// Checks if a symbol represents a parameter that can be stored on the
/// stack instead of in GroupData
bool can_treat_param_as_local(const Symbol& sym);

/// Given the OSL symbol, return the llvm::Value* corresponding to the
/// address of the start of that symbol (first element, first component,
Expand Down
8 changes: 6 additions & 2 deletions src/liboslexec/batched_llvm_instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,10 @@ BatchedBackendLLVM::llvm_type_groupdata()
TypeSpec ts = sym.typespec();
if (ts.is_structure()) // skip the struct symbol itself
continue;

if (can_treat_param_as_local(sym))
continue;

const int arraylen = std::max(1, sym.typespec().arraylength());
const int derivSize = (sym.has_derivs() ? 3 : 1);
ts.make_array(arraylen * derivSize);
Expand Down Expand Up @@ -2042,9 +2046,9 @@ BatchedBackendLLVM::build_llvm_instance(bool groupentry)
// Skip structure placeholders
if (s.typespec().is_structure())
continue;
// Allocate space for locals, temps, aggregate constants
// Allocate space for locals, temps, aggregate constants, and some output params
if (s.symtype() == SymTypeLocal || s.symtype() == SymTypeTemp
|| s.symtype() == SymTypeConst) {
|| s.symtype() == SymTypeConst || can_treat_param_as_local(s)) {
getOrAllocateLLVMSymbol(s);
}
// Set initial value for constants, closures, and strings that are
Expand Down
2 changes: 1 addition & 1 deletion src/liboslexec/llvm_instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1242,7 +1242,7 @@ BackendLLVM::build_llvm_instance(bool groupentry)
// Skip structure placeholders
if (s.typespec().is_structure())
continue;
// Allocate space for locals, temps, aggregate constants and some output params
// Allocate space for locals, temps, aggregate constants, and some output params
if (s.symtype() == SymTypeLocal || s.symtype() == SymTypeTemp
|| s.symtype() == SymTypeConst || can_treat_param_as_local(s))
getOrAllocateLLVMSymbol(s);
Expand Down

0 comments on commit 7006603

Please sign in to comment.