Skip to content

Commit

Permalink
Make the 'getOutsideASM' function generic as well
Browse files Browse the repository at this point in the history
  • Loading branch information
aleino-nv committed Dec 5, 2024
1 parent 338aaf2 commit df2f492
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
24 changes: 2 additions & 22 deletions source/slang/slang-ir-legalize-global-values.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,6 @@
#include "slang-ir-clone.h"
#include "slang-ir-util.h"

namespace
{
using namespace Slang;
void setInsertBeforeOutsideASM(
IRBuilder& builder, IRInst* beforeInst)
{
auto parent = beforeInst->getParent();
while (parent)
{
if (as<IRSPIRVAsm>(parent))
{
builder.setInsertBefore(parent);
return;
}
parent = parent->getParent();
}
builder.setInsertBefore(beforeInst);
}
} // namespace

namespace Slang
{

Expand All @@ -46,7 +26,7 @@ void GlobalInstInliningContextGeneric::inlineGlobalValues(IRModule * module)
{
auto user = use->getUser();
IRBuilder builder(user);
setInsertBeforeOutsideASM(builder, user);
builder.setInsertBefore(getOutsideASM(user));
IRCloneEnv cloneEnv;
auto val = maybeInlineGlobalValue(builder, use->getUser(), use->get(), cloneEnv);
if (val != use->get())
Expand Down Expand Up @@ -176,7 +156,7 @@ IRInst* GlobalInstInliningContextGeneric::inlineInst(IRBuilder& builder, IRClone
{
auto operand = inst->getOperand(i);
IRBuilder operandBuilder(builder);
setInsertBeforeOutsideASM(operandBuilder, builder.getInsertLoc().getInst());
operandBuilder.setInsertBefore(getOutsideASM(builder.getInsertLoc().getInst()));
maybeInlineGlobalValue(operandBuilder, inst, operand, cloneEnv);
}
result = cloneInstAndOperands(&cloneEnv, &builder, inst);
Expand Down
1 change: 1 addition & 0 deletions source/slang/slang-ir-legalize-global-values.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ struct GlobalInstInliningContextGeneric
virtual bool isLegalGlobalInstForTarget(IRInst* inst) =0;
virtual bool isInlinableGlobalInstForTarget(IRInst* inst) =0;
virtual bool shouldBeInlinedForTarget(IRInst* user) =0;
virtual IRInst* getOutsideASM(IRInst* beforeInst) =0;

// Inline global values that can't represented by the target to their use sites.
void inlineGlobalValues(IRModule * module);
Expand Down
13 changes: 13 additions & 0 deletions source/slang/slang-ir-spirv-legalize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1624,6 +1624,19 @@ struct SPIRVLegalizationContext : public SourceEmitterBase
return false;
}

IRInst* getOutsideASM(IRInst* beforeInst)
{
auto parent = beforeInst->getParent();
while (parent)
{
if (as<IRSPIRVAsm>(parent))
{
return parent;
}
parent = parent->getParent();
}
return beforeInst;
}
};

void processBranch(IRInst* branch) { addToWorkList(branch->getOperand(0)); }
Expand Down
6 changes: 6 additions & 0 deletions source/slang/slang-ir-wgsl-legalize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1609,6 +1609,12 @@ struct GlobalInstInliningContext: public GlobalInstInliningContextGeneric
// WGSL doesn't do any extra inlining beyond what is generically done by default.
return false;
}

IRInst* getOutsideASM(IRInst* beforeInst) override
{
// Not needed for WGSL, check e.g. the SPIR-V case to see why this is used.
return beforeInst;
}
};

void legalizeIRForWGSL(IRModule* module, DiagnosticSink* sink)
Expand Down

0 comments on commit df2f492

Please sign in to comment.