summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-02-16 16:44:04 -0800
committerGitHub <noreply@github.com>2023-02-16 16:44:04 -0800
commit245466d89cfe54b78da486f06d470bc6daaf4625 (patch)
tree522e0af1a9d2756182e143cdc85031ea1bbc2aa0 /source
parent4c4826d47eeef4675daae4ae53ff76f4d5ebd84a (diff)
Remove `SharedIRBuilder`. (#2657)
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-emit-cpp.h3
-rw-r--r--source/slang/slang-emit-spirv.cpp18
-rw-r--r--source/slang/slang-emit.cpp4
-rw-r--r--source/slang/slang-hlsl-intrinsic-set.cpp0
-rw-r--r--source/slang/slang-hlsl-intrinsic-set.h15
-rw-r--r--source/slang/slang-ir-addr-inst-elimination.cpp17
-rw-r--r--source/slang/slang-ir-addr-inst-elimination.h2
-rw-r--r--source/slang/slang-ir-any-value-marshalling.cpp17
-rw-r--r--source/slang/slang-ir-augment-make-existential.cpp7
-rw-r--r--source/slang/slang-ir-autodiff-cfg-norm.cpp14
-rw-r--r--source/slang/slang-ir-autodiff-cfg-norm.h2
-rw-r--r--source/slang/slang-ir-autodiff-fwd.cpp2
-rw-r--r--source/slang/slang-ir-autodiff-fwd.h4
-rw-r--r--source/slang/slang-ir-autodiff-pairs.cpp9
-rw-r--r--source/slang/slang-ir-autodiff-rev.cpp24
-rw-r--r--source/slang/slang-ir-autodiff-rev.h11
-rw-r--r--source/slang/slang-ir-autodiff-transcriber-base.cpp4
-rw-r--r--source/slang/slang-ir-autodiff-transcriber-base.h5
-rw-r--r--source/slang/slang-ir-autodiff-transpose.h14
-rw-r--r--source/slang/slang-ir-autodiff-unzip.cpp20
-rw-r--r--source/slang/slang-ir-autodiff-unzip.h17
-rw-r--r--source/slang/slang-ir-autodiff.cpp33
-rw-r--r--source/slang/slang-ir-autodiff.h2
-rw-r--r--source/slang/slang-ir-bind-existentials.cpp3
-rw-r--r--source/slang/slang-ir-byte-address-legalize.cpp8
-rw-r--r--source/slang/slang-ir-check-differentiability.cpp9
-rw-r--r--source/slang/slang-ir-check-differentiability.h3
-rw-r--r--source/slang/slang-ir-cleanup-void.cpp16
-rw-r--r--source/slang/slang-ir-clone.cpp18
-rw-r--r--source/slang/slang-ir-clone.h3
-rw-r--r--source/slang/slang-ir-collect-global-uniforms.cpp4
-rw-r--r--source/slang/slang-ir-com-interface.cpp5
-rw-r--r--source/slang/slang-ir-constexpr.cpp10
-rw-r--r--source/slang/slang-ir-dce.cpp3
-rw-r--r--source/slang/slang-ir-deduplicate.cpp14
-rw-r--r--source/slang/slang-ir-dll-export.cpp5
-rw-r--r--source/slang/slang-ir-dll-import.cpp13
-rw-r--r--source/slang/slang-ir-eliminate-multilevel-break.cpp4
-rw-r--r--source/slang/slang-ir-eliminate-phis.cpp8
-rw-r--r--source/slang/slang-ir-entry-point-pass.cpp3
-rw-r--r--source/slang/slang-ir-entry-point-pass.h2
-rw-r--r--source/slang/slang-ir-entry-point-raw-ptr-params.cpp3
-rw-r--r--source/slang/slang-ir-entry-point-uniforms.cpp6
-rw-r--r--source/slang/slang-ir-explicit-global-context.cpp18
-rw-r--r--source/slang/slang-ir-explicit-global-init.cpp9
-rw-r--r--source/slang/slang-ir-generics-lowering-context.cpp2
-rw-r--r--source/slang/slang-ir-generics-lowering-context.h8
-rw-r--r--source/slang/slang-ir-glsl-legalize.cpp11
-rw-r--r--source/slang/slang-ir-glsl-liveness.cpp7
-rw-r--r--source/slang/slang-ir-hoist-constants.cpp2
-rw-r--r--source/slang/slang-ir-hoist-local-types.cpp119
-rw-r--r--source/slang/slang-ir-hoist-local-types.h18
-rw-r--r--source/slang/slang-ir-init-local-var.cpp4
-rw-r--r--source/slang/slang-ir-init-local-var.h3
-rw-r--r--source/slang/slang-ir-inline.cpp3
-rw-r--r--source/slang/slang-ir-inst-pass-base.h2
-rw-r--r--source/slang/slang-ir-insts.h32
-rw-r--r--source/slang/slang-ir-layout.cpp11
-rw-r--r--source/slang/slang-ir-legalize-array-return-type.cpp5
-rw-r--r--source/slang/slang-ir-legalize-mesh-outputs.cpp4
-rw-r--r--source/slang/slang-ir-legalize-types.cpp5
-rw-r--r--source/slang/slang-ir-legalize-varying-params.cpp25
-rw-r--r--source/slang/slang-ir-link.cpp12
-rw-r--r--source/slang/slang-ir-liveness.cpp13
-rw-r--r--source/slang/slang-ir-loop-unroll.cpp30
-rw-r--r--source/slang/slang-ir-loop-unroll.h9
-rw-r--r--source/slang/slang-ir-lower-bit-cast.cpp9
-rw-r--r--source/slang/slang-ir-lower-com-methods.cpp13
-rw-r--r--source/slang/slang-ir-lower-error-handling.cpp16
-rw-r--r--source/slang/slang-ir-lower-existential.cpp15
-rw-r--r--source/slang/slang-ir-lower-generic-call.cpp11
-rw-r--r--source/slang/slang-ir-lower-generic-function.cpp21
-rw-r--r--source/slang/slang-ir-lower-generic-type.cpp10
-rw-r--r--source/slang/slang-ir-lower-generics.cpp10
-rw-r--r--source/slang/slang-ir-lower-optional-type.cpp18
-rw-r--r--source/slang/slang-ir-lower-reinterpret.cpp9
-rw-r--r--source/slang/slang-ir-lower-result-type.cpp22
-rw-r--r--source/slang/slang-ir-lower-tuple-types.cpp14
-rw-r--r--source/slang/slang-ir-optix-entry-point-uniforms.cpp4
-rw-r--r--source/slang/slang-ir-peephole.cpp31
-rw-r--r--source/slang/slang-ir-peephole.h3
-rw-r--r--source/slang/slang-ir-remove-unused-generic-param.cpp5
-rw-r--r--source/slang/slang-ir-restructure-scoping.cpp4
-rw-r--r--source/slang/slang-ir-sccp.cpp22
-rw-r--r--source/slang/slang-ir-sccp.h3
-rw-r--r--source/slang/slang-ir-simplify-cfg.cpp3
-rw-r--r--source/slang/slang-ir-simplify-for-emit.cpp11
-rw-r--r--source/slang/slang-ir-single-return.cpp4
-rw-r--r--source/slang/slang-ir-specialize-dispatch.cpp8
-rw-r--r--source/slang/slang-ir-specialize-dynamic-associatedtype-lookup.cpp13
-rw-r--r--source/slang/slang-ir-specialize-function-call.cpp10
-rw-r--r--source/slang/slang-ir-specialize-resources.cpp19
-rw-r--r--source/slang/slang-ir-specialize.cpp43
-rw-r--r--source/slang/slang-ir-spirv-legalize.cpp12
-rw-r--r--source/slang/slang-ir-spirv-legalize.h8
-rw-r--r--source/slang/slang-ir-ssa.cpp47
-rw-r--r--source/slang/slang-ir-ssa.h3
-rw-r--r--source/slang/slang-ir-string-hash.cpp7
-rw-r--r--source/slang/slang-ir-string-hash.h4
-rw-r--r--source/slang/slang-ir-synthesize-active-mask.cpp33
-rw-r--r--source/slang/slang-ir-type-set.cpp10
-rw-r--r--source/slang/slang-ir-type-set.h12
-rw-r--r--source/slang/slang-ir-union.cpp4
-rw-r--r--source/slang/slang-ir-witness-table-wrapper.cpp11
-rw-r--r--source/slang/slang-ir-wrap-structured-buffers.cpp4
-rw-r--r--source/slang/slang-ir.cpp47
-rw-r--r--source/slang/slang-ir.h26
-rw-r--r--source/slang/slang-legalize-types.h1
-rw-r--r--source/slang/slang-lower-to-ir.cpp28
109 files changed, 384 insertions, 960 deletions
diff --git a/source/slang/slang-emit-cpp.h b/source/slang/slang-emit-cpp.h
index ec70b02b8..92780e0a4 100644
--- a/source/slang/slang-emit-cpp.h
+++ b/source/slang/slang-emit-cpp.h
@@ -5,9 +5,6 @@
#include "slang-emit-c-like.h"
#include "slang-ir-clone.h"
-#include "slang-ir-type-set.h"
-#include "slang-hlsl-intrinsic-set.h"
-
#include "../core/slang-string-slice-pool.h"
namespace Slang
diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp
index 47537b108..694f836ae 100644
--- a/source/slang/slang-emit-spirv.cpp
+++ b/source/slang/slang-emit-spirv.cpp
@@ -1226,7 +1226,7 @@ struct SPIRVEmitContext
{
if (!inst)
{
- IRBuilder builder(m_sharedIRBuilder);
+ IRBuilder builder(m_irModule);
builder.setInsertInto(m_irModule->getModuleInst());
inst = builder.getVectorType(
builder.getBasicType(baseType),
@@ -1999,7 +1999,7 @@ struct SPIRVEmitContext
{
return result;
}
- IRBuilder builder(m_sharedIRBuilder);
+ IRBuilder builder(m_irModule);
builder.setInsertBefore(type);
auto ptrType = as<IRPtrTypeBase>(type);
SLANG_ASSERT(ptrType && "`getBuiltinGlobalVar`: `type` must be ptr type.");
@@ -2023,7 +2023,7 @@ struct SPIRVEmitContext
SpvInst* maybeEmitSystemVal(IRInst* inst)
{
- IRBuilder builder(m_sharedIRBuilder);
+ IRBuilder builder(m_irModule);
builder.setInsertBefore(inst);
if (auto layout = getVarLayout(inst))
{
@@ -2241,7 +2241,7 @@ struct SPIRVEmitContext
{
for (auto storageClass : snippet->usedResultTypeStorageClasses)
{
- IRBuilder builder(m_sharedIRBuilder);
+ IRBuilder builder(m_irModule);
builder.setInsertBefore(inst);
auto newPtrType = builder.getPtrType(
oldPtrType->getOp(), oldPtrType->getValueType(), storageClass);
@@ -2260,7 +2260,7 @@ struct SPIRVEmitContext
if (m_spvSnippetConstantInsts.TryGetValue(constant, result))
return result;
- IRBuilder builder(m_sharedIRBuilder);
+ IRBuilder builder(m_irModule);
builder.setInsertInto(m_irModule->getModuleInst());
switch (constant.type)
{
@@ -2307,7 +2307,7 @@ struct SPIRVEmitContext
// Emit SPV Inst that represents a type defined in a SpvSnippet.
void emitSpvSnippetASMTypeOperand(SpvSnippet::ASMType type)
{
- IRBuilder builder(m_sharedIRBuilder);
+ IRBuilder builder(m_irModule);
builder.setInsertInto(m_irModule->getModuleInst());
IRType* irType = nullptr;
switch (type)
@@ -2473,7 +2473,7 @@ struct SPIRVEmitContext
SpvInst* emitFieldAddress(SpvInstParent* parent, IRFieldAddress* fieldAddress)
{
- IRBuilder builder(m_sharedIRBuilder);
+ IRBuilder builder(m_irModule);
builder.setInsertBefore(fieldAddress);
auto base = fieldAddress->getBase();
@@ -2516,7 +2516,7 @@ struct SPIRVEmitContext
SpvInst* emitFieldExtract(SpvInstParent* parent, IRFieldExtract* inst)
{
- IRBuilder builder(m_sharedIRBuilder);
+ IRBuilder builder(m_irModule);
builder.setInsertBefore(inst);
IRStructType* baseStructType = as<IRStructType>(inst->getBase()->getDataType());
@@ -2592,7 +2592,7 @@ struct SPIRVEmitContext
}
SLANG_ASSERT(baseArrayType && "getElement require base to be an array.");
- IRBuilder builder(m_sharedIRBuilder);
+ IRBuilder builder(m_irModule);
builder.setInsertBefore(inst);
auto ptr = emitInst(
diff --git a/source/slang/slang-emit.cpp b/source/slang/slang-emit.cpp
index ef0d062bb..e2f00bf88 100644
--- a/source/slang/slang-emit.cpp
+++ b/source/slang/slang-emit.cpp
@@ -381,9 +381,7 @@ Result linkAndOptimizeIR(
// Unroll loops.
if (codeGenContext->getSink()->getErrorCount() == 0)
{
- SharedIRBuilder sharedBuilder(irModule);
- sharedBuilder.deduplicateAndRebuildGlobalNumberingMap();
- if (!unrollLoopsInModule(&sharedBuilder, irModule, codeGenContext->getSink()))
+ if (!unrollLoopsInModule(irModule, codeGenContext->getSink()))
return SLANG_FAIL;
}
diff --git a/source/slang/slang-hlsl-intrinsic-set.cpp b/source/slang/slang-hlsl-intrinsic-set.cpp
deleted file mode 100644
index e69de29bb..000000000
--- a/source/slang/slang-hlsl-intrinsic-set.cpp
+++ /dev/null
diff --git a/source/slang/slang-hlsl-intrinsic-set.h b/source/slang/slang-hlsl-intrinsic-set.h
deleted file mode 100644
index 8368491db..000000000
--- a/source/slang/slang-hlsl-intrinsic-set.h
+++ /dev/null
@@ -1,15 +0,0 @@
-// slang-hlsl-intrinsic-set.h
-#pragma once
-
-#include "slang-ir.h"
-#include "slang-ir-insts.h"
-
-#include "slang-ir-type-set.h"
-
-#include "../core/slang-string-slice-pool.h"
-
-namespace Slang
-{
-
-
-} // namespace Slang
diff --git a/source/slang/slang-ir-addr-inst-elimination.cpp b/source/slang/slang-ir-addr-inst-elimination.cpp
index a451e24a5..42bc88106 100644
--- a/source/slang/slang-ir-addr-inst-elimination.cpp
+++ b/source/slang/slang-ir-addr-inst-elimination.cpp
@@ -12,7 +12,7 @@ namespace Slang
struct AddressInstEliminationContext
{
- SharedIRBuilder* sharedBuilder;
+ IRModule* module;
DiagnosticSink* sink;
IRInst* getValue(IRBuilder& builder, IRInst* addr)
@@ -73,7 +73,7 @@ struct AddressInstEliminationContext
auto addr = use->get();
auto load = as<IRLoad>(use->getUser());
- IRBuilder builder(sharedBuilder);
+ IRBuilder builder(module);
builder.setInsertBefore(use->getUser());
auto value = getValue(builder, addr);
load->replaceUsesWith(value);
@@ -85,7 +85,7 @@ struct AddressInstEliminationContext
auto addr = use->get();
auto store = as<IRStore>(use->getUser());
- IRBuilder builder(sharedBuilder);
+ IRBuilder builder(module);
builder.setInsertBefore(use->getUser());
storeValue(builder, addr, store->getVal());
store->removeAndDeallocate();
@@ -96,7 +96,7 @@ struct AddressInstEliminationContext
auto addr = use->get();
auto call = as<IRCall>(use->getUser());
- IRBuilder builder(sharedBuilder);
+ IRBuilder builder(module);
builder.setInsertBefore(call);
auto tempVar = builder.emitVar(cast<IRPtrTypeBase>(addr->getFullType())->getValueType());
auto callee = getResolvedInstForDecorations(call->getCallee());
@@ -121,15 +121,13 @@ struct AddressInstEliminationContext
}
SlangResult eliminateAddressInstsImpl(
- SharedIRBuilder* inSharedBuilder,
AddressConversionPolicy* policy,
IRFunc* func,
DiagnosticSink* inSink)
{
- sharedBuilder = inSharedBuilder;
sink = inSink;
- IRBuilder builder(sharedBuilder);
+ IRBuilder builder(func->getModule());
List<IRInst*> workList;
for (auto block : func->getBlocks())
@@ -184,13 +182,14 @@ struct AddressInstEliminationContext
};
SlangResult eliminateAddressInsts(
- SharedIRBuilder* sharedBuilder,
AddressConversionPolicy* policy,
IRFunc* func,
DiagnosticSink* sink)
{
AddressInstEliminationContext ctx;
- return ctx.eliminateAddressInstsImpl(sharedBuilder, policy, func, sink);
+ ctx.module = func->getModule();
+ ctx.sink = sink;
+ return ctx.eliminateAddressInstsImpl(policy, func, sink);
}
} // namespace Slang
diff --git a/source/slang/slang-ir-addr-inst-elimination.h b/source/slang/slang-ir-addr-inst-elimination.h
index 53e5628f3..6c6506bc0 100644
--- a/source/slang/slang-ir-addr-inst-elimination.h
+++ b/source/slang/slang-ir-addr-inst-elimination.h
@@ -5,7 +5,6 @@
namespace Slang
{
-struct SharedIRBuilder;
class DiagnosticSink;
struct AddressConversionPolicy
@@ -13,7 +12,6 @@ struct AddressConversionPolicy
virtual bool shouldConvertAddrInst(IRInst* addrInst) = 0;
};
SlangResult eliminateAddressInsts(
- SharedIRBuilder* sharedBuilder,
AddressConversionPolicy* policy,
IRFunc* func,
DiagnosticSink* sink);
diff --git a/source/slang/slang-ir-any-value-marshalling.cpp b/source/slang/slang-ir-any-value-marshalling.cpp
index de8fd4dd5..79a41f0d5 100644
--- a/source/slang/slang-ir-any-value-marshalling.cpp
+++ b/source/slang/slang-ir-any-value-marshalling.cpp
@@ -52,7 +52,7 @@ namespace Slang
if (auto typeInfo = generatedAnyValueTypes.TryGetValue(size))
return typeInfo->Ptr();
RefPtr<AnyValueTypeInfo> info = new AnyValueTypeInfo();
- IRBuilder builder(sharedContext->sharedBuilderStorage);
+ IRBuilder builder(sharedContext->module);
builder.setInsertBefore(type);
auto structType = builder.createStructType();
info->type = structType;
@@ -359,7 +359,7 @@ namespace Slang
IRFunc* generatePackingFunc(IRType* type, IRAnyValueType* anyValueType)
{
- IRBuilder builder(sharedContext->sharedBuilderStorage);
+ IRBuilder builder(sharedContext->module);
builder.setInsertBefore(type);
auto anyValInfo = ensureAnyValueType(anyValueType);
@@ -519,7 +519,7 @@ namespace Slang
IRFunc* generateUnpackingFunc(IRType* type, IRAnyValueType* anyValueType)
{
- IRBuilder builder(sharedContext->sharedBuilderStorage);
+ IRBuilder builder(sharedContext->module);
builder.setInsertBefore(type);
auto anyValInfo = ensureAnyValueType(anyValueType);
@@ -574,7 +574,7 @@ namespace Slang
auto func = ensureMarshallingFunc(
operand->getDataType(),
cast<IRAnyValueType>(packInst->getDataType()));
- IRBuilder builderStorage(sharedContext->sharedBuilderStorage);
+ IRBuilder builderStorage(sharedContext->module);
auto builder = &builderStorage;
builder->setInsertBefore(packInst);
auto callInst = builder->emitCallInst(packInst->getDataType(), func.packFunc, 1, &operand);
@@ -588,7 +588,7 @@ namespace Slang
auto func = ensureMarshallingFunc(
unpackInst->getDataType(),
cast<IRAnyValueType>(operand->getDataType()));
- IRBuilder builderStorage(sharedContext->sharedBuilderStorage);
+ IRBuilder builderStorage(sharedContext->module);
auto builder = &builderStorage;
builder->setInsertBefore(unpackInst);
auto callInst = builder->emitCallInst(unpackInst->getDataType(), func.unpackFunc, 1, &operand);
@@ -620,9 +620,6 @@ namespace Slang
// since we will re-use that state for any code we
// generate along the way.
//
- SharedIRBuilder* sharedBuilder = &sharedContext->sharedBuilderStorage;
- sharedBuilder->init(sharedContext->module);
-
sharedContext->addToWorkList(sharedContext->module->getModuleInst());
while (sharedContext->workList.getCount() != 0)
@@ -646,10 +643,6 @@ namespace Slang
if (auto anyValueType = as<IRAnyValueType>(inst))
processAnyValueType(anyValueType);
}
- // Because we replaced all `AnyValueType` uses, some old type definitions (e.g. PtrType(AnyValueType))
- // will become duplicates with new types we introduced (e.g. PtrType(AnyValueStruct)), and therefore
- // invalidates our `globalValueNumberingMap` hash map. We need to rebuild it.
- sharedContext->sharedBuilderStorage.deduplicateAndRebuildGlobalNumberingMap();
sharedContext->mapInterfaceRequirementKeyValue.Clear();
}
};
diff --git a/source/slang/slang-ir-augment-make-existential.cpp b/source/slang/slang-ir-augment-make-existential.cpp
index c088a1650..2ef81f1ce 100644
--- a/source/slang/slang-ir-augment-make-existential.cpp
+++ b/source/slang/slang-ir-augment-make-existential.cpp
@@ -8,8 +8,6 @@ struct AugmentMakeExistentialContext
{
IRModule* module;
- SharedIRBuilder sharedBuilderStorage;
-
List<IRInst*> workList;
HashSet<IRInst*> workListSet;
@@ -24,7 +22,7 @@ struct AugmentMakeExistentialContext
void processMakeExistential(IRMakeExistential* inst)
{
- IRBuilder builderStorage(sharedBuilderStorage);
+ IRBuilder builderStorage(module);
auto builder = &builderStorage;
builder->setInsertBefore(inst);
@@ -51,9 +49,6 @@ struct AugmentMakeExistentialContext
void processModule()
{
- SharedIRBuilder* sharedBuilder = &sharedBuilderStorage;
- sharedBuilder->init(module);
-
addToWorkList(module->getModuleInst());
while (workList.getCount() != 0)
diff --git a/source/slang/slang-ir-autodiff-cfg-norm.cpp b/source/slang/slang-ir-autodiff-cfg-norm.cpp
index 2b201466b..4014473ea 100644
--- a/source/slang/slang-ir-autodiff-cfg-norm.cpp
+++ b/source/slang/slang-ir-autodiff-cfg-norm.cpp
@@ -47,7 +47,7 @@ struct BreakableRegionInfo
struct CFGNormalizationContext
{
- SharedIRBuilder* sharedBuilder;
+ IRModule* module;
DiagnosticSink* sink;
};
@@ -155,7 +155,7 @@ struct CFGNormalizationPass
if (afterBlocks.contains(currentBlock))
return RegionEndpoint(currentBlock, currBreakRegion, currBaseRegion, true);
- IRBuilder builder(cfgContext.sharedBuilder);
+ IRBuilder builder(cfgContext.module);
List<IRBlock*> pendingAfterBlocks;
@@ -391,7 +391,7 @@ struct CFGNormalizationPass
IRBlock* normalizeBreakableRegion(
IRInst* branchInst)
{
- IRBuilder builder(cfgContext.sharedBuilder);
+ IRBuilder builder(cfgContext.module);
switch (branchInst->getOp())
{
@@ -577,7 +577,7 @@ struct CFGNormalizationPass
};
void normalizeCFG(
- SharedIRBuilder* sharedBuilder,
+ IRModule* module,
IRGlobalValueWithCode* func,
IRCFGNormalizationPass const& options)
{
@@ -586,7 +586,7 @@ void normalizeCFG(
//
eliminatePhisInFunc(LivenessMode::Disabled, func->getModule(), func);
- CFGNormalizationContext context = {sharedBuilder, options.sink};
+ CFGNormalizationContext context = {module, options.sink};
CFGNormalizationPass cfgPass(context);
List<IRBlock*> workList;
@@ -615,8 +615,8 @@ void normalizeCFG(
}
disableIRValidationAtInsert();
- constructSSA(sharedBuilder, func);
+ constructSSA(module, func);
enableIRValidationAtInsert();
}
-} \ No newline at end of file
+}
diff --git a/source/slang/slang-ir-autodiff-cfg-norm.h b/source/slang/slang-ir-autodiff-cfg-norm.h
index f256d8ce8..4edd000a1 100644
--- a/source/slang/slang-ir-autodiff-cfg-norm.h
+++ b/source/slang/slang-ir-autodiff-cfg-norm.h
@@ -19,7 +19,7 @@ namespace Slang
/// "after" block.
///
void normalizeCFG(
- SharedIRBuilder* sharedBuilder,
+ IRModule* module,
IRGlobalValueWithCode* func,
IRCFGNormalizationPass const& options = IRCFGNormalizationPass());
diff --git a/source/slang/slang-ir-autodiff-fwd.cpp b/source/slang/slang-ir-autodiff-fwd.cpp
index 1f599a344..214e97ff6 100644
--- a/source/slang/slang-ir-autodiff-fwd.cpp
+++ b/source/slang/slang-ir-autodiff-fwd.cpp
@@ -1267,7 +1267,7 @@ void ForwardDiffTranscriber::checkAutodiffInstDecorations(IRFunc* fwdFunc)
// Transcribe a function definition.
InstPair ForwardDiffTranscriber::transcribeFunc(IRBuilder* inBuilder, IRFunc* primalFunc, IRFunc* diffFunc)
{
- IRBuilder builder(inBuilder->getSharedBuilder());
+ IRBuilder builder = *inBuilder;
builder.setInsertInto(diffFunc);
differentiableTypeConformanceContext.setFunc(primalFunc);
diff --git a/source/slang/slang-ir-autodiff-fwd.h b/source/slang/slang-ir-autodiff-fwd.h
index e80b25754..9089c4412 100644
--- a/source/slang/slang-ir-autodiff-fwd.h
+++ b/source/slang/slang-ir-autodiff-fwd.h
@@ -11,8 +11,8 @@ struct ForwardDiffTranscriber : AutoDiffTranscriberBase
// Pending values to write back to inout params at the end of the current function.
OrderedDictionary<IRInst*, InstPair> mapInOutParamToWriteBackValue;
- ForwardDiffTranscriber(AutoDiffSharedContext* shared, SharedIRBuilder* inSharedBuilder, DiagnosticSink* inSink)
- : AutoDiffTranscriberBase(shared, inSharedBuilder, inSink)
+ ForwardDiffTranscriber(AutoDiffSharedContext* shared, DiagnosticSink* inSink)
+ : AutoDiffTranscriberBase(shared, inSink)
{
}
diff --git a/source/slang/slang-ir-autodiff-pairs.cpp b/source/slang/slang-ir-autodiff-pairs.cpp
index b3665f27c..9d761764c 100644
--- a/source/slang/slang-ir-autodiff-pairs.cpp
+++ b/source/slang/slang-ir-autodiff-pairs.cpp
@@ -1,5 +1,4 @@
#include "slang-ir-autodiff-pairs.h"
-#include "slang-ir-hoist-local-types.h"
namespace Slang
{
@@ -98,11 +97,6 @@ struct DiffPairLoweringPass : InstPassBase
{
bool modified = false;
- // Hoist all pair types to global scope when possible.
- hoistLocalTypes(module);
-
- autodiffContext->sharedBuilder->deduplicateAndRebuildGlobalNumberingMap();
-
processAllInsts([&](IRInst* inst)
{
// Make sure the builder is at the right level.
@@ -138,14 +132,13 @@ struct DiffPairLoweringPass : InstPassBase
replacement.Key->replaceUsesWith(replacement.Value);
replacement.Key->removeAndDeallocate();
}
- autodiffContext->sharedBuilder->deduplicateAndRebuildGlobalNumberingMap();
return modified;
}
bool processModule()
{
- IRBuilder builder(autodiffContext->sharedBuilder);
+ IRBuilder builder(module);
return processInstWithChildren(&builder, module->getModuleInst());
}
diff --git a/source/slang/slang-ir-autodiff-rev.cpp b/source/slang/slang-ir-autodiff-rev.cpp
index ff8ece76c..fa1ca8519 100644
--- a/source/slang/slang-ir-autodiff-rev.cpp
+++ b/source/slang/slang-ir-autodiff-rev.cpp
@@ -383,7 +383,7 @@ namespace Slang
if (!header.differential)
return header;
- IRBuilder builder(inBuilder->getSharedBuilder());
+ IRBuilder builder = *inBuilder;
builder.setInsertInto(header.differential);
builder.emitBlock();
auto origFuncType = as<IRFuncType>(origFunc->getFullType());
@@ -482,7 +482,7 @@ namespace Slang
// Puts parameters into their own block.
void BackwardDiffTranscriberBase::makeParameterBlock(IRBuilder* inBuilder, IRFunc* func)
{
- IRBuilder builder(inBuilder->getSharedBuilder());
+ IRBuilder builder = *inBuilder;
auto firstBlock = func->getFirstBlock();
IRParam* param = func->getFirstParam();
@@ -513,9 +513,9 @@ namespace Slang
builder.emitBranch(firstBlock);
}
- void insertTempVarForMutableParams(SharedIRBuilder* sharedBuilder, IRFunc* func)
+ void insertTempVarForMutableParams(IRModule* module, IRFunc* func)
{
- IRBuilder builder(sharedBuilder);
+ IRBuilder builder(module);
auto firstBlock = func->getFirstBlock();
builder.setInsertBefore(firstBlock->getFirstOrdinaryInst());
@@ -586,13 +586,13 @@ namespace Slang
eliminateMultiLevelBreakForFunc(func->getModule(), func);
IRCFGNormalizationPass cfgPass = {this->getSink()};
- normalizeCFG(autoDiffSharedContext->sharedBuilder, func);
+ normalizeCFG(autoDiffSharedContext->moduleInst->getModule(), func);
- insertTempVarForMutableParams(sharedBuilder, func);
+ insertTempVarForMutableParams(autoDiffSharedContext->moduleInst->getModule(), func);
AutoDiffAddressConversionPolicy cvtPolicty;
cvtPolicty.diffTypeContext = &diffTypeContext;
- auto result = eliminateAddressInsts(sharedBuilder, &cvtPolicty, func, sink);
+ auto result = eliminateAddressInsts(&cvtPolicty, func, sink);
if (SLANG_SUCCEEDED(result))
{
@@ -623,9 +623,7 @@ namespace Slang
// reversible.
if (SLANG_FAILED(prepareFuncForBackwardDiff(primalFunc)))
return diffPropagateFunc;
-
- autoDiffSharedContext->sharedBuilder->deduplicateAndRebuildGlobalNumberingMap();
-
+
// Forward transcribe the clone of the original func.
ForwardDiffTranscriber& fwdTranscriber = *static_cast<ForwardDiffTranscriber*>(
autoDiffSharedContext->transcriberSet.forwardTranscriber);
@@ -837,8 +835,8 @@ namespace Slang
builder->addBackwardDerivativePrimalDecoration(primalFunc, specializedBackwardPrimalFunc);
}
- initializeLocalVariables(builder->getSharedBuilder(), as<IRGlobalValueWithCode>(getGenericReturnVal(primalFuncGeneric)));
- initializeLocalVariables(builder->getSharedBuilder(), diffPropagateFunc);
+ initializeLocalVariables(builder->getModule(), as<IRGlobalValueWithCode>(getGenericReturnVal(primalFuncGeneric)));
+ initializeLocalVariables(builder->getModule(), diffPropagateFunc);
}
ParameterBlockTransposeInfo BackwardDiffTranscriberBase::splitAndTransposeParameterBlock(
@@ -1235,7 +1233,7 @@ namespace Slang
}
SLANG_RELEASE_ASSERT(returnInst);
- IRBuilder builder(sharedBuilder);
+ IRBuilder builder(autoDiffSharedContext->moduleInst);
builder.setInsertBefore(returnInst);
for (auto& wb : info.outDiffWritebacks)
{
diff --git a/source/slang/slang-ir-autodiff-rev.h b/source/slang/slang-ir-autodiff-rev.h
index c8e115f0e..a638b873c 100644
--- a/source/slang/slang-ir-autodiff-rev.h
+++ b/source/slang/slang-ir-autodiff-rev.h
@@ -67,9 +67,8 @@ struct BackwardDiffTranscriberBase : AutoDiffTranscriberBase
BackwardDiffTranscriberBase(
FuncBodyTranscriptionTaskType taskType,
AutoDiffSharedContext* shared,
- SharedIRBuilder* inSharedBuilder,
DiagnosticSink* inSink)
- : AutoDiffTranscriberBase(shared, inSharedBuilder, inSink)
+ : AutoDiffTranscriberBase(shared, inSink)
, diffTaskType(taskType)
, diffTransposePassStorage(shared)
, diffPropagationPassStorage(shared)
@@ -138,10 +137,9 @@ struct BackwardDiffPrimalTranscriber : BackwardDiffTranscriberBase
{
BackwardDiffPrimalTranscriber(
AutoDiffSharedContext* shared,
- SharedIRBuilder* inSharedBuilder,
DiagnosticSink* inSink)
: BackwardDiffTranscriberBase(
- FuncBodyTranscriptionTaskType::BackwardPrimal, shared, inSharedBuilder, inSink)
+ FuncBodyTranscriptionTaskType::BackwardPrimal, shared, inSink)
{ }
virtual IRFuncType* differentiateFunctionType(IRBuilder* builder, IRInst* func, IRFuncType* funcType) override;
@@ -168,12 +166,10 @@ struct BackwardDiffPropagateTranscriber : BackwardDiffTranscriberBase
{
BackwardDiffPropagateTranscriber(
AutoDiffSharedContext* shared,
- SharedIRBuilder* inSharedBuilder,
DiagnosticSink* inSink)
: BackwardDiffTranscriberBase(
FuncBodyTranscriptionTaskType::BackwardPropagate,
shared,
- inSharedBuilder,
inSink)
{ }
void generateTrivialDiffFuncFromUserDefinedDerivative(
@@ -208,10 +204,9 @@ struct BackwardDiffTranscriber : BackwardDiffTranscriberBase
{
BackwardDiffTranscriber(
AutoDiffSharedContext* shared,
- SharedIRBuilder* inSharedBuilder,
DiagnosticSink* inSink)
: BackwardDiffTranscriberBase(
- FuncBodyTranscriptionTaskType::Backward, shared, inSharedBuilder, inSink)
+ FuncBodyTranscriptionTaskType::Backward, shared, inSink)
{ }
virtual IRFuncType* differentiateFunctionType(IRBuilder* builder, IRInst* func, IRFuncType* funcType) override;
diff --git a/source/slang/slang-ir-autodiff-transcriber-base.cpp b/source/slang/slang-ir-autodiff-transcriber-base.cpp
index 10a734d65..7ab0ee692 100644
--- a/source/slang/slang-ir-autodiff-transcriber-base.cpp
+++ b/source/slang/slang-ir-autodiff-transcriber-base.cpp
@@ -682,7 +682,7 @@ IRInst* AutoDiffTranscriberBase::getDifferentialZeroOfType(IRBuilder* builder, I
InstPair AutoDiffTranscriberBase::transcribeBlockImpl(IRBuilder* builder, IRBlock* origBlock, HashSet<IRInst*>& instsToSkip)
{
- IRBuilder subBuilder(builder->getSharedBuilder());
+ IRBuilder subBuilder = *builder;
subBuilder.setInsertLoc(builder->getInsertLoc());
IRInst* diffBlock = subBuilder.emitBlock();
@@ -844,7 +844,7 @@ InstPair AutoDiffTranscriberBase::transcribeGeneric(IRBuilder* inBuilder, IRGene
IRGeneric* primalGeneric = origGeneric;
- IRBuilder builder(inBuilder->getSharedBuilder());
+ IRBuilder builder = *inBuilder;
builder.setInsertBefore(origGeneric);
auto diffGeneric = builder.emitGeneric();
diff --git a/source/slang/slang-ir-autodiff-transcriber-base.h b/source/slang/slang-ir-autodiff-transcriber-base.h
index 208bfbc28..47e568645 100644
--- a/source/slang/slang-ir-autodiff-transcriber-base.h
+++ b/source/slang/slang-ir-autodiff-transcriber-base.h
@@ -33,12 +33,9 @@ struct AutoDiffTranscriberBase
DifferentiableTypeConformanceContext differentiableTypeConformanceContext;
- SharedIRBuilder* sharedBuilder;
-
- AutoDiffTranscriberBase(AutoDiffSharedContext* shared, SharedIRBuilder* inSharedBuilder, DiagnosticSink* inSink)
+ AutoDiffTranscriberBase(AutoDiffSharedContext* shared, DiagnosticSink* inSink)
: autoDiffSharedContext(shared)
, differentiableTypeConformanceContext(shared)
- , sharedBuilder(inSharedBuilder)
, sink(inSink)
{
cloneEnv.squashChildrenMapping = true;
diff --git a/source/slang/slang-ir-autodiff-transpose.h b/source/slang/slang-ir-autodiff-transpose.h
index 4e1532153..8aca31642 100644
--- a/source/slang/slang-ir-autodiff-transpose.h
+++ b/source/slang/slang-ir-autodiff-transpose.h
@@ -160,7 +160,7 @@ struct DiffTransposePass
// We shouldn't already have a terminator for this block
SLANG_ASSERT(revBlock->getTerminator() == nullptr);
- IRBuilder builder(autodiffContext->sharedBuilder);
+ IRBuilder builder(autodiffContext->moduleInst->getModule());
auto currentBlock = block;
while (!isBlockLastInRegion(currentBlock, endBlocks))
@@ -494,8 +494,7 @@ struct DiffTransposePass
// look for insts/blocks marked with IRDifferentialInstDecoration,
// and transpose them in the revDiffFunc.
//
- IRBuilder builder;
- builder.init(autodiffContext->sharedBuilder);
+ IRBuilder builder(autodiffContext->moduleInst);
// Insert after the last block.
builder.setInsertInto(revDiffFunc);
@@ -608,7 +607,7 @@ struct DiffTransposePass
terminalPrimalBlock->getTerminator()->removeAndDeallocate();
- IRBuilder subBuilder(builder.getSharedBuilder());
+ IRBuilder subBuilder = builder;
subBuilder.setInsertInto(terminalPrimalBlock);
// There should be no parameters in the first reverse-mode block.
@@ -664,7 +663,7 @@ struct DiffTransposePass
if (revAccumulatorVarMap.ContainsKey(fwdInst))
return revAccumulatorVarMap[fwdInst];
- IRBuilder tempVarBuilder(autodiffContext->sharedBuilder);
+ IRBuilder tempVarBuilder(autodiffContext->moduleInst->getModule());
IRBlock* firstDiffBlock = firstRevDiffBlockMap[as<IRFunc>(fwdInst->getParent()->getParent())];
@@ -702,8 +701,7 @@ struct DiffTransposePass
void transposeBlock(IRBlock* fwdBlock, IRBlock* revBlock)
{
- IRBuilder builder;
- builder.init(autodiffContext->sharedBuilder);
+ IRBuilder builder(autodiffContext->moduleInst);
// Insert into our reverse block.
builder.setInsertInto(revBlock);
@@ -1283,7 +1281,7 @@ struct DiffTransposePass
IRBlock* insertPhiBlockBefore(IRBlock* revBlock, List<IRInst*> phiArgs)
{
- IRBuilder phiBlockBuilder(autodiffContext->sharedBuilder);
+ IRBuilder phiBlockBuilder(autodiffContext->moduleInst->getModule());
phiBlockBuilder.setInsertBefore(revBlock);
auto phiBlock = phiBlockBuilder.emitBlock();
diff --git a/source/slang/slang-ir-autodiff-unzip.cpp b/source/slang/slang-ir-autodiff-unzip.cpp
index 6aaa40baf..614559c9f 100644
--- a/source/slang/slang-ir-autodiff-unzip.cpp
+++ b/source/slang/slang-ir-autodiff-unzip.cpp
@@ -8,12 +8,12 @@ namespace Slang
struct ExtractPrimalFuncContext
{
- SharedIRBuilder* sharedBuilder;
+ IRModule* module;
AutoDiffTranscriberBase* backwardPrimalTranscriber;
- void init(SharedIRBuilder* inSharedBuilder, AutoDiffTranscriberBase* transcriber)
+ void init(IRModule* inModule, AutoDiffTranscriberBase* transcriber)
{
- sharedBuilder = inSharedBuilder;
+ module = inModule;
backwardPrimalTranscriber = transcriber;
}
@@ -35,7 +35,7 @@ struct ExtractPrimalFuncContext
IRInst* createGenericIntermediateType(IRGeneric* gen)
{
- IRBuilder builder(sharedBuilder);
+ IRBuilder builder(module);
builder.setInsertBefore(gen);
IRCloneEnv intermediateTypeCloneEnv;
auto clonedGen = cloneGenericHeader(builder, intermediateTypeCloneEnv, gen);
@@ -55,7 +55,7 @@ struct ExtractPrimalFuncContext
{
if (func->getOp() == kIROp_Generic)
return createGenericIntermediateType(as<IRGeneric>(func));
- IRBuilder builder(sharedBuilder);
+ IRBuilder builder(module);
builder.setInsertBefore(func);
auto intermediateType = builder.createStructType();
if (auto nameHint = func->findDecoration<IRNameHintDecoration>())
@@ -71,7 +71,7 @@ struct ExtractPrimalFuncContext
IRInst* generatePrimalFuncType(
IRGlobalValueWithCode* destFunc, IRGlobalValueWithCode* originalFunc, IRInst*& outIntermediateType)
{
- IRBuilder builder(sharedBuilder);
+ IRBuilder builder(module);
builder.setInsertBefore(destFunc);
IRFuncType* originalFuncType = nullptr;
outIntermediateType = createIntermediateType(destFunc);
@@ -243,7 +243,7 @@ struct ExtractPrimalFuncContext
IRStructField* addIntermediateContextField(IRInst* type, IRInst* intermediateOutput)
{
- IRBuilder genTypeBuilder(sharedBuilder);
+ IRBuilder genTypeBuilder(module);
auto ptrStructType = as<IRPtrTypeBase>(intermediateOutput->getDataType());
SLANG_RELEASE_ASSERT(ptrStructType);
auto structType = as<IRStructType>(ptrStructType->getValueType());
@@ -283,7 +283,7 @@ struct ExtractPrimalFuncContext
IRFunc* turnUnzippedFuncIntoPrimalFunc(IRFunc* unzippedFunc, IRFunc* originalFunc, HashSet<IRInst*>& primalParams, IRInst*& outIntermediateType)
{
- IRBuilder builder(sharedBuilder);
+ IRBuilder builder(module);
IRFunc* func = unzippedFunc;
IRInst* intermediateType = nullptr;
@@ -411,7 +411,7 @@ IRFunc* DiffUnzipPass::extractPrimalFunc(
ParameterBlockTransposeInfo& paramInfo,
IRInst*& intermediateType)
{
- IRBuilder builder(this->autodiffContext->sharedBuilder);
+ IRBuilder builder(autodiffContext->moduleInst);
builder.setInsertBefore(func);
IRCloneEnv subEnv;
@@ -440,7 +440,7 @@ IRFunc* DiffUnzipPass::extractPrimalFunc(
}
ExtractPrimalFuncContext context;
- context.init(autodiffContext->sharedBuilder, autodiffContext->transcriberSet.primalTranscriber);
+ context.init(autodiffContext->moduleInst->getModule(), autodiffContext->transcriberSet.primalTranscriber);
intermediateType = nullptr;
auto primalFunc = context.turnUnzippedFuncIntoPrimalFunc(clonedFunc, originalFunc, newPrimalParams, intermediateType);
diff --git a/source/slang/slang-ir-autodiff-unzip.h b/source/slang/slang-ir-autodiff-unzip.h
index d10a9349d..68326fd54 100644
--- a/source/slang/slang-ir-autodiff-unzip.h
+++ b/source/slang/slang-ir-autodiff-unzip.h
@@ -126,8 +126,7 @@ struct DiffUnzipPass
{
diffTypeContext.setFunc(func);
- IRBuilder builderStorage;
- builderStorage.init(autodiffContext->sharedBuilder);
+ IRBuilder builderStorage(autodiffContext->moduleInst->getModule());
IRBuilder* builder = &builderStorage;
@@ -334,8 +333,7 @@ struct DiffUnzipPass
void lowerIndexedRegions()
{
- IRBuilder builder(autodiffContext->sharedBuilder);
-
+ IRBuilder builder(autodiffContext->moduleInst->getModule());
for (auto region : indexRegions)
{
@@ -467,7 +465,7 @@ struct DiffUnzipPass
for (auto child = primalBlock->getFirstChild(); child; child = child->getNextInst())
primalInsts.add(child);
- IRBuilder builder(autodiffContext->sharedBuilder);
+ IRBuilder builder(autodiffContext->moduleInst->getModule());
// Build list of indices that this block is affected by.
List<IndexedRegion*> regions;
@@ -646,8 +644,7 @@ struct DiffUnzipPass
InstPair splitCall(IRBuilder* primalBuilder, IRBuilder* diffBuilder, IRCall* mixedCall)
{
- IRBuilder globalBuilder;
- globalBuilder.init(autodiffContext->sharedBuilder);
+ IRBuilder globalBuilder(autodiffContext->moduleInst->getModule());
auto fwdCalleeType = mixedCall->getCallee()->getDataType();
auto baseFn = _getOriginalFunc(mixedCall);
@@ -1247,12 +1244,10 @@ struct DiffUnzipPass
void splitBlock(IRBlock* block, IRBlock* primalBlock, IRBlock* diffBlock)
{
// Make two builders for primal and differential blocks.
- IRBuilder primalBuilder;
- primalBuilder.init(autodiffContext->sharedBuilder);
+ IRBuilder primalBuilder(autodiffContext->moduleInst->getModule());
primalBuilder.setInsertInto(primalBlock);
- IRBuilder diffBuilder;
- diffBuilder.init(autodiffContext->sharedBuilder);
+ IRBuilder diffBuilder(autodiffContext->moduleInst->getModule());
diffBuilder.setInsertInto(diffBlock);
List<IRInst*> splitInsts;
diff --git a/source/slang/slang-ir-autodiff.cpp b/source/slang/slang-ir-autodiff.cpp
index 2ce5a48f7..1232cf50d 100644
--- a/source/slang/slang-ir-autodiff.cpp
+++ b/source/slang/slang-ir-autodiff.cpp
@@ -214,7 +214,7 @@ IRStructKey* DifferentialPairTypeBuilder::_getOrCreateDiffStructKey()
{
if (!this->globalDiffKey)
{
- IRBuilder builder(sharedContext->sharedBuilder);
+ IRBuilder builder(sharedContext->moduleInst);
// Insert directly at top level (skip any generic scopes etc.)
builder.setInsertInto(sharedContext->moduleInst);
@@ -230,7 +230,7 @@ IRStructKey* DifferentialPairTypeBuilder::_getOrCreatePrimalStructKey()
if (!this->globalPrimalKey)
{
// Insert directly at top level (skip any generic scopes etc.)
- IRBuilder builder(sharedContext->sharedBuilder);
+ IRBuilder builder(sharedContext->moduleInst);
builder.setInsertInto(sharedContext->moduleInst);
this->globalPrimalKey = builder.createStructKey();
@@ -252,7 +252,7 @@ IRInst* DifferentialPairTypeBuilder::_createDiffPairType(IRType* origBaseType, I
break;
}
- IRBuilder builder(sharedContext->sharedBuilder);
+ IRBuilder builder(sharedContext->moduleInst);
builder.setInsertBefore(diffType);
auto pairStructType = builder.createStructType();
@@ -537,8 +537,6 @@ struct StripNoDiffTypeAttributePass : InstPassBase
}
}
});
- sharedBuilderStorage.init(module);
- sharedBuilderStorage.deduplicateAndRebuildGlobalNumberingMap();
}
};
@@ -576,7 +574,7 @@ struct AutoDiffPass : public InstPassBase
// TODO(sai): Move this call.
forwardTranscriber.differentiableTypeConformanceContext.buildGlobalWitnessDictionary();
- IRBuilder builderStorage(&sharedBuilderStorage);
+ IRBuilder builderStorage(module);
IRBuilder* builder = &builderStorage;
// Process all ForwardDifferentiate and BackwardDifferentiate instructions by
@@ -808,7 +806,6 @@ struct AutoDiffPass : public InstPassBase
if (lowerIntermediateContextType(builder))
{
- sharedBuilderStorage.deduplicateAndRebuildGlobalNumberingMap();
hasChanges = true;
}
@@ -817,7 +814,7 @@ struct AutoDiffPass : public InstPassBase
IRStringLit* getDerivativeFuncName(IRInst* func, const char* postFix)
{
- IRBuilder builder(&sharedBuilderStorage);
+ IRBuilder builder(autodiffContext->moduleInst);
builder.setInsertBefore(func);
IRStringLit* name = nullptr;
@@ -846,23 +843,17 @@ struct AutoDiffPass : public InstPassBase
AutoDiffPass(AutoDiffSharedContext* context, DiagnosticSink* sink) :
InstPassBase(context->moduleInst->getModule()),
sink(sink),
- forwardTranscriber(context, &sharedBuilderStorage, sink),
- backwardPrimalTranscriber(context, &sharedBuilderStorage, sink),
- backwardPropagateTranscriber(context, &sharedBuilderStorage, sink),
- backwardTranscriber(context, &sharedBuilderStorage, sink),
+ forwardTranscriber(context, sink),
+ backwardPrimalTranscriber(context, sink),
+ backwardPropagateTranscriber(context, sink),
+ backwardTranscriber(context, sink),
pairBuilderStorage(context),
autodiffContext(context)
{
-
// We start by initializing our shared IR building state,
// since we will re-use that state for any code we
// generate along the way.
//
- sharedBuilderStorage.init(module);
- sharedBuilderStorage.deduplicateAndRebuildGlobalNumberingMap();
-
- context->sharedBuilder = &sharedBuilderStorage;
-
forwardTranscriber.pairBuilder = &pairBuilderStorage;
backwardPrimalTranscriber.pairBuilder = &pairBuilderStorage;
backwardPropagateTranscriber.pairBuilder = &pairBuilderStorage;
@@ -924,12 +915,6 @@ bool finalizeAutoDiffPass(IRModule* module)
// Create shared context for all auto-diff related passes
AutoDiffSharedContext autodiffContext(module->getModuleInst());
- SharedIRBuilder sharedBuilder;
- sharedBuilder.init(module);
- sharedBuilder.deduplicateAndRebuildGlobalNumberingMap();
-
- autodiffContext.sharedBuilder = &sharedBuilder;
-
// Replaces IRDifferentialPairType with an auto-generated struct,
// IRDifferentialPairGetDifferential with 'differential' field access,
// IRDifferentialPairGetPrimal with 'primal' field access, and
diff --git a/source/slang/slang-ir-autodiff.h b/source/slang/slang-ir-autodiff.h
index 0662cf846..38e4636ac 100644
--- a/source/slang/slang-ir-autodiff.h
+++ b/source/slang/slang-ir-autodiff.h
@@ -61,8 +61,6 @@ struct AutoDiffSharedContext
{
IRModuleInst* moduleInst = nullptr;
- SharedIRBuilder* sharedBuilder = nullptr;
-
// A reference to the builtin IDifferentiable interface type.
// We use this to look up all the other types (and type exprs)
// that conform to a base type.
diff --git a/source/slang/slang-ir-bind-existentials.cpp b/source/slang/slang-ir-bind-existentials.cpp
index 7af93037b..35c07452a 100644
--- a/source/slang/slang-ir-bind-existentials.cpp
+++ b/source/slang/slang-ir-bind-existentials.cpp
@@ -275,8 +275,7 @@ struct BindExistentialSlots
auto fullType = inst->getFullType();
- SharedIRBuilder sharedBuilder(module);
- IRBuilder builder(sharedBuilder);
+ IRBuilder builder(module);
// Every argument that is filling an existential
// type param/slot comprises both a type and
diff --git a/source/slang/slang-ir-byte-address-legalize.cpp b/source/slang/slang-ir-byte-address-legalize.cpp
index 721efadaf..0a4339ff3 100644
--- a/source/slang/slang-ir-byte-address-legalize.cpp
+++ b/source/slang/slang-ir-byte-address-legalize.cpp
@@ -31,7 +31,7 @@ struct ByteAddressBufferLegalizationContext
// code as part of legalization (rather than create/destroy
// IR builders on the fly).
//
- SharedIRBuilder m_sharedBuilder;
+ IRModule* m_module;
IRBuilder m_builder;
// Everything starts with a request to process a module,
@@ -39,8 +39,8 @@ struct ByteAddressBufferLegalizationContext
//
void processModule(IRModule* module)
{
- m_sharedBuilder.init(module);
- m_builder.init(m_sharedBuilder);
+ m_module = module;
+ m_builder = IRBuilder(m_module);
processInstRec(module->getModuleInst());
}
@@ -699,7 +699,7 @@ struct ByteAddressBufferLegalizationContext
// of legalizing a load or store, and we don't want to mess with
// the insertion location of `m_builder`.
//
- IRBuilder paramBuilder(m_sharedBuilder);
+ IRBuilder paramBuilder(m_module);
paramBuilder.setInsertBefore(byteAddressBufferParam);
auto structuredBufferParam = paramBuilder.createGlobalParam(structuredBufferParamType);
diff --git a/source/slang/slang-ir-check-differentiability.cpp b/source/slang/slang-ir-check-differentiability.cpp
index a3f7ae7c0..98f2b2c34 100644
--- a/source/slang/slang-ir-check-differentiability.cpp
+++ b/source/slang/slang-ir-check-differentiability.cpp
@@ -11,7 +11,6 @@ struct CheckDifferentiabilityPassContext : public InstPassBase
public:
DiagnosticSink* sink;
AutoDiffSharedContext sharedContext;
- SharedIRBuilder* sharedBuilder;
enum DifferentiableLevel
{
@@ -19,8 +18,8 @@ public:
};
Dictionary<IRInst*, DifferentiableLevel> differentiableFunctions;
- CheckDifferentiabilityPassContext(SharedIRBuilder* inSharedBuilder, IRModule* inModule, DiagnosticSink* inSink)
- : InstPassBase(inModule), sharedBuilder(inSharedBuilder), sink(inSink), sharedContext(inModule->getModuleInst())
+ CheckDifferentiabilityPassContext(IRModule* inModule, DiagnosticSink* inSink)
+ : InstPassBase(inModule), sink(inSink), sharedContext(inModule->getModuleInst())
{}
bool _isFuncMarkedForAutoDiff(IRInst* func)
@@ -397,9 +396,9 @@ public:
}
};
-void checkAutoDiffUsages(SharedIRBuilder* sharedBuilder, IRModule* module, DiagnosticSink* sink)
+void checkAutoDiffUsages(IRModule* module, DiagnosticSink* sink)
{
- CheckDifferentiabilityPassContext context(sharedBuilder, module, sink);
+ CheckDifferentiabilityPassContext context(module, sink);
context.processModule();
}
diff --git a/source/slang/slang-ir-check-differentiability.h b/source/slang/slang-ir-check-differentiability.h
index 16ae16b6f..735a918c9 100644
--- a/source/slang/slang-ir-check-differentiability.h
+++ b/source/slang/slang-ir-check-differentiability.h
@@ -7,9 +7,8 @@ namespace Slang
{
struct IRModule;
class DiagnosticSink;
-struct SharedIRBuilder;
// Check all auto diff usages are valid.
-void checkAutoDiffUsages(SharedIRBuilder* sharedBuilder, IRModule* module, DiagnosticSink* sink);
+void checkAutoDiffUsages(IRModule* module, DiagnosticSink* sink);
} // namespace Slang
diff --git a/source/slang/slang-ir-cleanup-void.cpp b/source/slang/slang-ir-cleanup-void.cpp
index a76bcefad..78ca823e5 100644
--- a/source/slang/slang-ir-cleanup-void.cpp
+++ b/source/slang/slang-ir-cleanup-void.cpp
@@ -10,8 +10,6 @@ namespace Slang
{
IRModule* module;
- SharedIRBuilder sharedBuilderStorage;
-
List<IRInst*> workList;
HashSet<IRInst*> workListSet;
@@ -51,7 +49,7 @@ namespace Slang
}
if (newArgs.getCount() != (Index)inst->getOperandCount())
{
- IRBuilder builder(&sharedBuilderStorage);
+ IRBuilder builder(module);
builder.setInsertBefore(inst);
auto newCall = builder.emitIntrinsicInst(inst->getFullType(), inst->getOp(), newArgs.getCount(), newArgs.getBuffer());
inst->replaceUsesWith(newCall);
@@ -72,7 +70,7 @@ namespace Slang
paramsToRemove.add(param);
}
}
- IRBuilder builder(&sharedBuilderStorage);
+ IRBuilder builder(module);
builder.setInsertBefore(func);
for (auto param : paramsToRemove)
{
@@ -97,7 +95,7 @@ namespace Slang
}
if (newOperands.getCount() != (Index)funcType->getParamCount())
{
- IRBuilder builder(&sharedBuilderStorage);
+ IRBuilder builder(module);
builder.setInsertBefore(funcType);
auto newFuncType = builder.getFuncType(newOperands.getCount(), (IRType**)newOperands.getBuffer(), funcType->getResultType());
if (newFuncType != funcType)
@@ -143,7 +141,7 @@ namespace Slang
case kIROp_GetResultValue:
if (inst->getDataType()->getOp() == kIROp_VoidType)
{
- IRBuilder builder(&sharedBuilderStorage);
+ IRBuilder builder(module);
builder.setInsertBefore(inst);
inst->replaceUsesWith(builder.getVoidValue());
}
@@ -152,12 +150,6 @@ namespace Slang
void processModule()
{
- SharedIRBuilder* sharedBuilder = &sharedBuilderStorage;
- sharedBuilder->init(module);
-
- // Deduplicate equivalent types.
- sharedBuilder->deduplicateAndRebuildGlobalNumberingMap();
-
addToWorkList(module->getModuleInst());
while (workList.getCount() != 0)
diff --git a/source/slang/slang-ir-clone.cpp b/source/slang/slang-ir-clone.cpp
index 8b8b28f09..050d1e392 100644
--- a/source/slang/slang-ir-clone.cpp
+++ b/source/slang/slang-ir-clone.cpp
@@ -124,19 +124,18 @@ struct IRCloningOldNewPair
//
static void _cloneInstDecorationsAndChildren(
IRCloneEnv* env,
- SharedIRBuilder* sharedBuilder,
+ IRModule* module,
IRInst* oldInst,
IRInst* newInst)
{
SLANG_ASSERT(env);
- SLANG_ASSERT(sharedBuilder);
SLANG_ASSERT(oldInst);
SLANG_ASSERT(newInst);
// We will set up an IR builder that inserts
// into the new parent instruction.
//
- IRBuilder builderStorage(sharedBuilder);
+ IRBuilder builderStorage(module);
auto builder = &builderStorage;
builder->setInsertInto(newInst);
@@ -202,7 +201,7 @@ static void _cloneInstDecorationsAndChildren(
auto oldChild = pair.oldInst;
auto newChild = pair.newInst;
- _cloneInstDecorationsAndChildren(env, sharedBuilder, oldChild, newChild);
+ _cloneInstDecorationsAndChildren(env, module, oldChild, newChild);
}
}
@@ -214,11 +213,11 @@ static void _cloneInstDecorationsAndChildren(
//
void cloneInstDecorationsAndChildren(
IRCloneEnv* env,
- SharedIRBuilder* sharedBuilder,
+ IRModule* module,
IRInst* oldInst,
IRInst* newInst)
{
- SLANG_ASSERT(sharedBuilder);
+ SLANG_ASSERT(module);
SLANG_ASSERT(oldInst);
SLANG_ASSERT(newInst);
@@ -233,7 +232,7 @@ void cloneInstDecorationsAndChildren(
subEnv = &subEnvStorage;
subEnv->parent = env;
}
- _cloneInstDecorationsAndChildren(subEnv, sharedBuilder, oldInst, newInst);
+ _cloneInstDecorationsAndChildren(subEnv, module, oldInst, newInst);
}
// The convenience function `cloneInst` just sequences the
@@ -273,7 +272,7 @@ IRInst* cloneInst(
env->mapOldValToNew.Add(oldInst, newInst);
cloneInstDecorationsAndChildren(
- env, builder->getSharedBuilder(), oldInst, newInst);
+ env, builder->getModule(), oldInst, newInst);
return newInst;
}
@@ -284,8 +283,7 @@ void cloneDecoration(
IRInst* newParent,
IRModule* module)
{
- SharedIRBuilder sharedBuilder(module);
- IRBuilder builder(sharedBuilder);
+ IRBuilder builder(module);
if(auto first = newParent->getFirstDecorationOrChild())
builder.setInsertBefore(first);
diff --git a/source/slang/slang-ir-clone.h b/source/slang/slang-ir-clone.h
index f4f53ff92..0c810d518 100644
--- a/source/slang/slang-ir-clone.h
+++ b/source/slang/slang-ir-clone.h
@@ -9,7 +9,6 @@ namespace Slang
{
struct IRBuilder;
struct IRInst;
-struct SharedIRBuilder;
// This file provides an interface to simplify the task of
// correcting "cloning" IR code, whether individual
@@ -107,7 +106,7 @@ IRInst* cloneInstAndOperands(
///
void cloneInstDecorationsAndChildren(
IRCloneEnv* env,
- SharedIRBuilder* sharedBuilder,
+ IRModule* module,
IRInst* oldInst,
IRInst* newInst);
diff --git a/source/slang/slang-ir-collect-global-uniforms.cpp b/source/slang/slang-ir-collect-global-uniforms.cpp
index ad0dfda91..de806d653 100644
--- a/source/slang/slang-ir-collect-global-uniforms.cpp
+++ b/source/slang/slang-ir-collect-global-uniforms.cpp
@@ -127,8 +127,8 @@ struct CollectGlobalUniformParametersContext
// the collected global-scope parameters. The `IRBuilder` we construct
// for this will also be used when replacing the individual parameters.
//
- SharedIRBuilder sharedBuilder(module);
- IRBuilder builderStorage(sharedBuilder);
+
+ IRBuilder builderStorage(module);
IRBuilder* builder = &builderStorage;
builder->setInsertInto(module->getModuleInst());
diff --git a/source/slang/slang-ir-com-interface.cpp b/source/slang/slang-ir-com-interface.cpp
index 0684cc8e6..0c8977aa0 100644
--- a/source/slang/slang-ir-com-interface.cpp
+++ b/source/slang/slang-ir-com-interface.cpp
@@ -56,10 +56,7 @@ void lowerComInterfaces(IRModule* module, ArtifactStyle artifactStyle, Diagnosti
// For all interfaces found replace uses
{
- SharedIRBuilder sharedBuilder;
- sharedBuilder.init(module);
-
- IRBuilder builder(sharedBuilder);
+ IRBuilder builder(module);
builder.setInsertInto(module->getModuleInst());
List<IRUse*> uses;
diff --git a/source/slang/slang-ir-constexpr.cpp b/source/slang/slang-ir-constexpr.cpp
index 2bbb9618c..c1f14fe24 100644
--- a/source/slang/slang-ir-constexpr.cpp
+++ b/source/slang/slang-ir-constexpr.cpp
@@ -13,7 +13,6 @@ struct PropagateConstExprContext
DiagnosticSink* sink;
- SharedIRBuilder sharedBuilder;
IRBuilder builder;
List<IRInst*> workList;
@@ -21,7 +20,7 @@ struct PropagateConstExprContext
IRBuilder* getBuilder() { return &builder; }
- Session* getSession() { return sharedBuilder.getSession(); }
+ Session* getSession() { return module->getSession(); }
DiagnosticSink* getSink() { return sink; }
};
@@ -278,9 +277,7 @@ bool propagateConstExprBackward(
PropagateConstExprContext* context,
IRGlobalValueWithCode* code)
{
- SharedIRBuilder sharedBuilder(context->getModule());
-
- IRBuilder builder(sharedBuilder);
+ IRBuilder builder(context->getModule());
builder.setInsertInto(code);
bool anyChanges = false;
@@ -503,8 +500,7 @@ void propagateConstExpr(
PropagateConstExprContext context;
context.module = module;
context.sink = sink;
- context.sharedBuilder.init(module);
- context.builder.init(context.sharedBuilder);
+ context.builder = IRBuilder(module);
// We need to propagate information both forward and backward.
//
diff --git a/source/slang/slang-ir-dce.cpp b/source/slang/slang-ir-dce.cpp
index 251b473e0..58c9b23f1 100644
--- a/source/slang/slang-ir-dce.cpp
+++ b/source/slang/slang-ir-dce.cpp
@@ -86,8 +86,7 @@ struct DeadCodeEliminationContext
{
if (!undefInst)
{
- SharedIRBuilder builderStorage(module);
- IRBuilder builder(&builderStorage);
+ IRBuilder builder(module);
if (auto firstChild = module->getModuleInst()->getFirstChild())
builder.setInsertBefore(firstChild);
else
diff --git a/source/slang/slang-ir-deduplicate.cpp b/source/slang/slang-ir-deduplicate.cpp
index 74efc3cb3..168451479 100644
--- a/source/slang/slang-ir-deduplicate.cpp
+++ b/source/slang/slang-ir-deduplicate.cpp
@@ -2,16 +2,16 @@
namespace Slang
{
- void SharedIRBuilder::deduplicateAndRebuildGlobalNumberingMap()
+ void IRDeduplicationContext::init(IRModule* module)
{
- }
+ m_module = module;
+ m_session = module->getSession();
- void SharedIRBuilder::replaceGlobalInst(IRInst* oldInst, IRInst* newInst)
- {
- oldInst->replaceUsesWith(newInst);
+ m_globalValueNumberingMap.Clear();
+ m_constantMap.Clear();
}
- void SharedIRBuilder::removeHoistableInstFromGlobalNumberingMap(IRInst* instToRemove)
+ void IRDeduplicationContext::removeHoistableInstFromGlobalNumberingMap(IRInst* instToRemove)
{
HashSet<IRInst*> userWorkListSet;
List<IRInst*> userWorkList;
@@ -39,7 +39,7 @@ namespace Slang
IRBuilder* builder,
IRInst* inst);
- void SharedIRBuilder::tryHoistInst(IRInst* inst)
+ void IRDeduplicationContext::tryHoistInst(IRInst* inst)
{
List<IRInst*> workList;
HashSet<IRInst*> workListSet;
diff --git a/source/slang/slang-ir-dll-export.cpp b/source/slang/slang-ir-dll-export.cpp
index a8b464b43..d7a18e665 100644
--- a/source/slang/slang-ir-dll-export.cpp
+++ b/source/slang/slang-ir-dll-export.cpp
@@ -13,13 +13,11 @@ struct DllExportContext
IRModule* module;
DiagnosticSink* diagnosticSink;
- SharedIRBuilder sharedBuilder;
-
void processFunc(IRFunc* func, IRDllExportDecoration* dllExportDecoration)
{
NativeCallMarshallingContext marshalContext;
marshalContext.diagnosticSink = diagnosticSink;
- IRBuilder builder(sharedBuilder);
+ IRBuilder builder(module);
auto wrapper = marshalContext.generateDLLExportWrapperFunc(builder, func);
dllExportDecoration->removeFromParent();
dllExportDecoration->insertAtStart(wrapper);
@@ -65,7 +63,6 @@ void generateDllExportFuncs(IRModule* module, DiagnosticSink* sink)
DllExportContext context;
context.module = module;
context.diagnosticSink = sink;
- context.sharedBuilder.init(module);
return context.processModule();
}
diff --git a/source/slang/slang-ir-dll-import.cpp b/source/slang/slang-ir-dll-import.cpp
index 8b611feba..2da89ad3e 100644
--- a/source/slang/slang-ir-dll-import.cpp
+++ b/source/slang/slang-ir-dll-import.cpp
@@ -15,15 +15,13 @@ struct DllImportContext
DiagnosticSink* diagnosticSink;
TargetRequest* targetReq;
- SharedIRBuilder sharedBuilder;
-
IRFunc* loadDllFunc = nullptr;
IRFunc* loadFuncPtrFunc = nullptr;
IRFunc* stringGetBufferFunc = nullptr;
IRFunc* createBuiltinIntrinsicFunc(UInt paramCount, IRType** paramTypes, IRType* resultType, UnownedStringSlice targetIntrinsic)
{
- IRBuilder builder(sharedBuilder);
+ IRBuilder builder(module);
builder.setInsertInto(module->getModuleInst());
IRFunc* result = builder.createFunc();
builder.setInsertInto(result);
@@ -38,7 +36,7 @@ struct DllImportContext
{
if (!loadDllFunc)
{
- IRBuilder builder(sharedBuilder);
+ IRBuilder builder(module);
builder.setInsertInto(module->getModuleInst());
IRType* stringType = builder.getStringType();
loadDllFunc = createBuiltinIntrinsicFunc(
@@ -54,7 +52,7 @@ struct DllImportContext
{
if (!loadFuncPtrFunc)
{
- IRBuilder builder(sharedBuilder);
+ IRBuilder builder(module);
builder.setInsertInto(module->getModuleInst());
IRType* stringType = builder.getStringType();
@@ -73,7 +71,7 @@ struct DllImportContext
{
if (!stringGetBufferFunc)
{
- IRBuilder builder(sharedBuilder);
+ IRBuilder builder(module);
builder.setInsertInto(module->getModuleInst());
IRType* stringType = builder.getStringType();
@@ -103,7 +101,7 @@ struct DllImportContext
{
assert(func->getFirstBlock() == nullptr);
- IRBuilder builder(sharedBuilder);
+ IRBuilder builder(module);
NativeCallMarshallingContext marshalContext;
auto nativeType = marshalContext.getNativeFuncType(builder, func->getDataType());
@@ -196,7 +194,6 @@ void generateDllImportFuncs(TargetRequest* targetReq, IRModule* module, Diagnost
context.module = module;
context.targetReq = targetReq;
context.diagnosticSink = sink;
- context.sharedBuilder.init(module);
return context.processModule();
}
diff --git a/source/slang/slang-ir-eliminate-multilevel-break.cpp b/source/slang/slang-ir-eliminate-multilevel-break.cpp
index bf3f32217..3618e1326 100644
--- a/source/slang/slang-ir-eliminate-multilevel-break.cpp
+++ b/source/slang/slang-ir-eliminate-multilevel-break.cpp
@@ -196,9 +196,7 @@ struct EliminateMultiLevelBreakContext
if (funcInfo.multiLevelBreaks.getCount() == 0)
return;
- SharedIRBuilder sharedBuilder;
- sharedBuilder.init(irModule);
- IRBuilder builder(&sharedBuilder);
+ IRBuilder builder(irModule);
builder.setInsertInto(func);
OrderedHashSet<BreakableRegionInfo*> skippedOverRegions;
diff --git a/source/slang/slang-ir-eliminate-phis.cpp b/source/slang/slang-ir-eliminate-phis.cpp
index 818953152..e0d51edd3 100644
--- a/source/slang/slang-ir-eliminate-phis.cpp
+++ b/source/slang/slang-ir-eliminate-phis.cpp
@@ -66,14 +66,12 @@ struct PhiEliminationContext
// a builder it can use to generate code.
//
IRModule* m_module = nullptr;
- SharedIRBuilder m_sharedBuilder;
IRBuilder m_builder;
LivenessMode m_livenessMode;
PhiEliminationContext(LivenessMode livenessMode, IRModule* module)
: m_module(module)
- , m_sharedBuilder(module)
- , m_builder(m_sharedBuilder)
+ , m_builder(module)
, m_livenessMode(livenessMode)
{}
@@ -140,7 +138,7 @@ struct PhiEliminationContext
void convertInstDefToRegisterAssignment()
{
- IRBuilder builder(m_sharedBuilder);
+ IRBuilder builder(m_module);
for (auto instAlloc : m_registerAllocation.mapInstToRegister)
{
@@ -178,7 +176,7 @@ struct PhiEliminationContext
void replaceInstUseWithRegisterLoad()
{
- IRBuilder builder(m_sharedBuilder);
+ IRBuilder builder(m_module);
for (auto instAlloc : m_registerAllocation.mapInstToRegister)
{
diff --git a/source/slang/slang-ir-entry-point-pass.cpp b/source/slang/slang-ir-entry-point-pass.cpp
index e5bf55a44..64988cb81 100644
--- a/source/slang/slang-ir-entry-point-pass.cpp
+++ b/source/slang/slang-ir-entry-point-pass.cpp
@@ -8,9 +8,6 @@ void PerEntryPointPass::processModule(IRModule* module)
{
m_module = module;
- SharedIRBuilder sharedBuilder(module);
- m_sharedBuilder = &sharedBuilder;
-
// Note that we are only looking at true global-scope
// functions and not functions nested inside of
// IR generics. When using generic entry points, this
diff --git a/source/slang/slang-ir-entry-point-pass.h b/source/slang/slang-ir-entry-point-pass.h
index f8a1c9888..6a0193a96 100644
--- a/source/slang/slang-ir-entry-point-pass.h
+++ b/source/slang/slang-ir-entry-point-pass.h
@@ -31,8 +31,6 @@ protected:
//
IRModule* m_module = nullptr;
- SharedIRBuilder* m_sharedBuilder = nullptr;
-
EntryPointInfo m_entryPoint;
};
diff --git a/source/slang/slang-ir-entry-point-raw-ptr-params.cpp b/source/slang/slang-ir-entry-point-raw-ptr-params.cpp
index a9615a42a..0e1b001a1 100644
--- a/source/slang/slang-ir-entry-point-raw-ptr-params.cpp
+++ b/source/slang/slang-ir-entry-point-raw-ptr-params.cpp
@@ -19,8 +19,7 @@ struct ConvertEntryPointPtrParamsToRawPtrsPass
void processModule()
{
- SharedIRBuilder sharedBuilder(m_module);
- IRBuilder builder(&sharedBuilder);
+ IRBuilder builder(m_module);
// We start by getting and caching the raw pointer type.
//
diff --git a/source/slang/slang-ir-entry-point-uniforms.cpp b/source/slang/slang-ir-entry-point-uniforms.cpp
index 1f0bc13b1..d10aa7ff2 100644
--- a/source/slang/slang-ir-entry-point-uniforms.cpp
+++ b/source/slang/slang-ir-entry-point-uniforms.cpp
@@ -221,7 +221,7 @@ struct CollectEntryPointUniformParams : PerEntryPointPass
// We will set up an IR builder so that we are ready to generate code.
//
- IRBuilder builderStorage(m_sharedBuilder);
+ IRBuilder builderStorage(m_module);
auto builder = &builderStorage;
if(m_options.alwaysCreateCollectedParam)
@@ -380,7 +380,7 @@ struct CollectEntryPointUniformParams : PerEntryPointPass
if(paramStructType)
return;
- IRBuilder builder(m_sharedBuilder);
+ IRBuilder builder(m_module);
// First we create the structure to hold the parameters.
//
@@ -427,7 +427,7 @@ struct MoveEntryPointUniformParametersToGlobalScope : PerEntryPointPass
// We will set up an IR builder so that we are ready to generate code.
//
- IRBuilder builderStorage(m_sharedBuilder);
+ IRBuilder builderStorage(m_module);
auto builder = &builderStorage;
builder->setInsertBefore(entryPointFunc);
diff --git a/source/slang/slang-ir-explicit-global-context.cpp b/source/slang/slang-ir-explicit-global-context.cpp
index 6e88c4cd7..ce55bd44a 100644
--- a/source/slang/slang-ir-explicit-global-context.cpp
+++ b/source/slang/slang-ir-explicit-global-context.cpp
@@ -16,7 +16,6 @@ struct IntroduceExplicitGlobalContextPass
IRModule* m_module = nullptr;
CodeGenTarget m_target = CodeGenTarget::Unknown;
- SharedIRBuilder* m_sharedBuilder = nullptr;
IRStructType* m_contextStructType = nullptr;
IRPtrType* m_contextStructPtrType = nullptr;
@@ -26,10 +25,7 @@ struct IntroduceExplicitGlobalContextPass
void processModule()
{
- SharedIRBuilder sharedBuilder(m_module);
- m_sharedBuilder = &sharedBuilder;
-
- IRBuilder builder(&sharedBuilder);
+ IRBuilder builder(m_module);
// The transformation we will perform will need to affect
// global variables, global shader parameters, and entry-point
@@ -231,7 +227,7 @@ struct IntroduceExplicitGlobalContextPass
// Creating a field in the context struct to represent
// `originalInst` is straightforward.
- IRBuilder builder(m_sharedBuilder);
+ IRBuilder builder(m_module);
builder.setInsertBefore(m_contextStructType);
// We create a "key" for the new field, and then a field
@@ -272,7 +268,7 @@ struct IntroduceExplicitGlobalContextPass
if(!firstBlock)
return;
- IRBuilder builder(m_sharedBuilder);
+ IRBuilder builder(m_module);
// The code we introduce will all be added to the start
// of the first block of the function.
@@ -346,7 +342,7 @@ struct IntroduceExplicitGlobalContextPass
void replaceUsesOfGlobalParam(IRGlobalParam* globalParam)
{
- IRBuilder builder(m_sharedBuilder);
+ IRBuilder builder(m_module);
// A global shader parameter was mapped to a field
// in the context structure, so we find the appropriate key.
@@ -384,7 +380,7 @@ struct IntroduceExplicitGlobalContextPass
void replaceUsesOfGlobalVar(IRGlobalVar* globalVar)
{
- IRBuilder builder(m_sharedBuilder);
+ IRBuilder builder(m_module);
// A global variable was mapped to a field
// in the context structure, so we find the appropriate key.
@@ -457,7 +453,7 @@ struct IntroduceExplicitGlobalContextPass
// explicit parameter to `func` to represent the
// context.
//
- IRBuilder builder(m_sharedBuilder);
+ IRBuilder builder(m_module);
// We can safely assume that `func` has a body, because
// otherwise we wouldn't be getting a request for the
@@ -551,7 +547,7 @@ struct IntroduceExplicitGlobalContextPass
//
void addKernelContextNameHint(IRInst* inst)
{
- IRBuilder builder(m_sharedBuilder);
+ IRBuilder builder(m_module);
builder.addNameHintDecoration(inst, UnownedTerminatedStringSlice("kernelContext"));
}
};
diff --git a/source/slang/slang-ir-explicit-global-init.cpp b/source/slang/slang-ir-explicit-global-init.cpp
index 94c065514..a65118d5a 100644
--- a/source/slang/slang-ir-explicit-global-init.cpp
+++ b/source/slang/slang-ir-explicit-global-init.cpp
@@ -40,8 +40,6 @@ struct MoveGlobalVarInitializationToEntryPointsPass
{
IRModule* m_module;
- SharedIRBuilder* m_sharedBuilder;
-
// In the Slang IR, a global variable represents a pointer
// to the storage for the variable but it *also* encodes
// the logic used to compute the initial value of that
@@ -72,9 +70,6 @@ struct MoveGlobalVarInitializationToEntryPointsPass
{
m_module = module;
- SharedIRBuilder sharedBuilder(module);
- m_sharedBuilder = &sharedBuilder;
-
// We start by looking for global variables with
// initialization logic in the IR, and processing
// each to produce a split variable (now without
@@ -120,7 +115,7 @@ struct MoveGlobalVarInitializationToEntryPointsPass
void processGlobalVarWithInit(IRGlobalVar* globalVar, IRBlock* firstBlock)
{
- IRBuilder builder(m_sharedBuilder);
+ IRBuilder builder(m_module);
builder.setInsertBefore(globalVar);
// Becaue an `IRGlobalVar` reprsents a pointer to the storage
@@ -174,7 +169,7 @@ struct MoveGlobalVarInitializationToEntryPointsPass
// We are going to insert initiailization logic at the start
// of the first block of the entry point.
//
- IRBuilder builder(m_sharedBuilder);
+ IRBuilder builder(m_module);
builder.setInsertBefore(firstBlock->getFirstOrdinaryInst());
for( auto globalVarInfo : m_globalVarsWithInit )
diff --git a/source/slang/slang-ir-generics-lowering-context.cpp b/source/slang/slang-ir-generics-lowering-context.cpp
index 6c404f318..8e726cba1 100644
--- a/source/slang/slang-ir-generics-lowering-context.cpp
+++ b/source/slang/slang-ir-generics-lowering-context.cpp
@@ -58,7 +58,7 @@ namespace Slang
IRInst* result = nullptr;
if (mapTypeToRTTIObject.TryGetValue(typeInst, result))
return result;
- IRBuilder builderStorage(sharedBuilderStorage);
+ IRBuilder builderStorage(module);
auto builder = &builderStorage;
builder->setInsertBefore(typeInst->next);
diff --git a/source/slang/slang-ir-generics-lowering-context.h b/source/slang/slang-ir-generics-lowering-context.h
index fbfb42559..0c07a93c9 100644
--- a/source/slang/slang-ir-generics-lowering-context.h
+++ b/source/slang/slang-ir-generics-lowering-context.h
@@ -41,8 +41,6 @@ namespace Slang
// Map from interface requirement keys to its corresponding dispatch method.
OrderedDictionary<IRInst*, IRFunc*> mapInterfaceRequirementKeyToDispatchMethods;
- SharedIRBuilder sharedBuilderStorage;
-
// We will use a single work list of instructions that need
// to be considered for lowering.
//
@@ -111,9 +109,6 @@ namespace Slang
template<typename TFunc>
void workOnModule(SharedGenericsLoweringContext* sharedContext, const TFunc& func)
{
- SharedIRBuilder* sharedBuilder = &sharedContext->sharedBuilderStorage;
- sharedBuilder->init(sharedContext->module);
-
sharedContext->addToWorkList(sharedContext->module->getModuleInst());
while (sharedContext->workList.getCount() != 0)
@@ -135,9 +130,6 @@ namespace Slang
template<typename TFunc>
void workOnCallGraph(SharedGenericsLoweringContext* sharedContext, const TFunc& func)
{
- SharedIRBuilder* sharedBuilder = &sharedContext->sharedBuilderStorage;
- sharedBuilder->init(sharedContext->module);
-
sharedContext->addToWorkList(sharedContext->module->getModuleInst());
IRDeadCodeEliminationOptions dceOptions;
dceOptions.keepExportsAlive = true;
diff --git a/source/slang/slang-ir-glsl-legalize.cpp b/source/slang/slang-ir-glsl-legalize.cpp
index 55d120228..e111a548b 100644
--- a/source/slang/slang-ir-glsl-legalize.cpp
+++ b/source/slang/slang-ir-glsl-legalize.cpp
@@ -116,8 +116,7 @@ void legalizeImageSubscriptStoreForGLSL(IRBuilder& builder, IRInst* storeInst)
void legalizeImageSubscriptForGLSL(IRModule* module)
{
- SharedIRBuilder shared(module);
- IRBuilder builder(shared);
+ IRBuilder builder(module);
for (auto globalInst : module->getModuleInst()->getChildren())
{
auto func = as<IRFunc>(globalInst);
@@ -152,8 +151,7 @@ IRGlobalParam* addGlobalParam(
IRModule* module,
IRType* valueType)
{
- SharedIRBuilder shared(module);
- IRBuilder builder(shared);
+ IRBuilder builder(module);
return builder.createGlobalParam(valueType);
}
@@ -2345,7 +2343,7 @@ void legalizeEntryPointParameterForGLSL(
// disrupt the source location it is using for inserting
// temporary variables at the top of the function.
//
- IRBuilder terminatorBuilder(builder->getSharedBuilder());
+ IRBuilder terminatorBuilder(func);
terminatorBuilder.setInsertBefore(terminatorInst);
// Assign from the local variabel to the global output
@@ -2415,8 +2413,7 @@ void legalizeEntryPointForGLSL(
//
// TODO: make some of these free functions...
//
- SharedIRBuilder shared(module);
- IRBuilder builder(shared);
+ IRBuilder builder(module);
builder.setInsertInto(func);
context.builder = &builder;
diff --git a/source/slang/slang-ir-glsl-liveness.cpp b/source/slang/slang-ir-glsl-liveness.cpp
index d5448a788..1a42155bc 100644
--- a/source/slang/slang-ir-glsl-liveness.cpp
+++ b/source/slang/slang-ir-glsl-liveness.cpp
@@ -23,10 +23,8 @@ struct GLSLLivenessContext
void processModule();
GLSLLivenessContext(IRModule* module):
- m_module(module)
+ m_module(module), m_builder(module)
{
- m_sharedBuilder.init(module);
- m_builder.init(m_sharedBuilder);
}
void _replaceMarker(IRLiveRangeMarker* liveMarker);
@@ -64,7 +62,6 @@ struct GLSLLivenessContext
IRType* m_spirvIntLiteralType = nullptr; ///< Int type that emits as `spirv_literal`
IRModule* m_module;
- SharedIRBuilder m_sharedBuilder;
IRBuilder m_builder;
};
@@ -241,4 +238,4 @@ void applyGLSLLiveness(IRModule* module)
}
} // namespace Slang
- \ No newline at end of file
+
diff --git a/source/slang/slang-ir-hoist-constants.cpp b/source/slang/slang-ir-hoist-constants.cpp
index 2bac5c654..7a250bdb7 100644
--- a/source/slang/slang-ir-hoist-constants.cpp
+++ b/source/slang/slang-ir-hoist-constants.cpp
@@ -14,8 +14,6 @@ struct HoistConstantPass : InstPassBase
void processModule()
{
- sharedBuilderStorage.init(module);
-
processAllInsts([this](IRInst* inst)
{
diff --git a/source/slang/slang-ir-hoist-local-types.cpp b/source/slang/slang-ir-hoist-local-types.cpp
deleted file mode 100644
index d8b0eab22..000000000
--- a/source/slang/slang-ir-hoist-local-types.cpp
+++ /dev/null
@@ -1,119 +0,0 @@
-#include "slang-ir-hoist-local-types.h"
-
-#include "slang-ir-insts.h"
-#include "slang-ir.h"
-
-namespace Slang
-{
-struct HoistLocalTypesContext
-{
- IRModule* module;
-
- SharedIRBuilder sharedBuilderStorage;
-
- List<IRInst*> workList;
- HashSet<IRInst*> workListSet;
-
- void addToWorkList(IRInst* inst)
- {
- if (workListSet.Contains(inst))
- return;
-
- workList.add(inst);
- workListSet.Add(inst);
- }
-
- bool processInst(IRInst* inst)
- {
- auto sharedBuilder = &sharedBuilderStorage;
- if (!as<IRType>(inst))
- return false;
- if (inst->getParent() == module->getModuleInst())
- return false;
- switch (inst->getOp())
- {
- case kIROp_InterfaceType:
- case kIROp_StructType:
- case kIROp_ClassType:
- return false;
- default:
- break;
- }
- IRInstKey key = {inst};
- if (auto value = sharedBuilder->getGlobalValueNumberingMap().TryGetValue(key))
- {
- inst->replaceUsesWith(*value);
- inst->removeAndDeallocate();
- return true;
- }
- IRBuilder builder(sharedBuilder);
- builder.setInsertInto(module->getModuleInst());
- bool hoistable = true;
- ShortList<IRInst*> mappedOperands;
- for (UInt i = 0; i < inst->getOperandCount(); i++)
- {
- IRInstKey opKey = {inst->getOperand(i)};
- if (auto value = sharedBuilder->getGlobalValueNumberingMap().TryGetValue(opKey))
- {
- mappedOperands.add(*value);
- }
- else
- {
- hoistable = false;
- break;
- }
- }
- if (hoistable)
- {
- auto newType = builder.getType(
- inst->getOp(), mappedOperands.getCount(), mappedOperands.getArrayView().getBuffer());
- inst->transferDecorationsTo(newType);
- inst->replaceUsesWith(newType);
- inst->removeAndDeallocate();
- return true;
- }
- return false;
- }
-
- void processModule()
- {
- SharedIRBuilder* sharedBuilder = &sharedBuilderStorage;
- sharedBuilder->init(module);
-
- for (;;)
- {
- bool changed = false;
- // Deduplicate equivalent types and build numbering map for global types.
- sharedBuilder->deduplicateAndRebuildGlobalNumberingMap();
-
- addToWorkList(module->getModuleInst());
-
- while (workList.getCount() != 0)
- {
- IRInst* inst = workList.getLast();
-
- workList.removeLast();
- workListSet.Remove(inst);
-
- changed |= processInst(inst);
-
- for (auto child = inst->getLastChild(); child; child = child->getPrevInst())
- {
- addToWorkList(child);
- }
- }
-
- if (!changed)
- break;
- }
- }
-};
-
-void hoistLocalTypes(IRModule* module)
-{
- HoistLocalTypesContext context;
- context.module = module;
- context.processModule();
-}
-
-} // namespace Slang
diff --git a/source/slang/slang-ir-hoist-local-types.h b/source/slang/slang-ir-hoist-local-types.h
deleted file mode 100644
index 55e62ce57..000000000
--- a/source/slang/slang-ir-hoist-local-types.h
+++ /dev/null
@@ -1,18 +0,0 @@
-// slang-ir-hoist-local-types.h
-#pragma once
-
-#include "slang-ir.h"
-
-namespace Slang
-{
-struct IRModule;
-class DiagnosticSink;
-
-/// Hoist local types to global scope if possible.
-/// Some transformation passes may leave behind local type definitons that
-/// can be hoisted to global scope. This pass examines all local type defintions
-// and try to hoist them to global scope if the definition is no longer dependent on
-// the local context.
-void hoistLocalTypes(IRModule* module);
-
-} // namespace Slang
diff --git a/source/slang/slang-ir-init-local-var.cpp b/source/slang/slang-ir-init-local-var.cpp
index 4b28db268..645344f2e 100644
--- a/source/slang/slang-ir-init-local-var.cpp
+++ b/source/slang/slang-ir-init-local-var.cpp
@@ -6,9 +6,9 @@
namespace Slang
{
-void initializeLocalVariables(SharedIRBuilder* sharedBuilder, IRGlobalValueWithCode* func)
+void initializeLocalVariables(IRModule* module, IRGlobalValueWithCode* func)
{
- IRBuilder builder(sharedBuilder);
+ IRBuilder builder(module);
for (auto block : func->getBlocks())
{
for (auto inst : block->getChildren())
diff --git a/source/slang/slang-ir-init-local-var.h b/source/slang/slang-ir-init-local-var.h
index ad06684fc..12cbc50f7 100644
--- a/source/slang/slang-ir-init-local-var.h
+++ b/source/slang/slang-ir-init-local-var.h
@@ -5,10 +5,9 @@ namespace Slang
{
struct IRModule;
struct IRGlobalValueWithCode;
- struct SharedIRBuilder;
// Init local variables with default values if the variable isn't being initialized locally in
// the same basic block.
- void initializeLocalVariables(SharedIRBuilder* sharedBuilder, IRGlobalValueWithCode* func);
+ void initializeLocalVariables(IRModule* module, IRGlobalValueWithCode* func);
}
diff --git a/source/slang/slang-ir-inline.cpp b/source/slang/slang-ir-inline.cpp
index 643acdbb8..d8486d7aa 100644
--- a/source/slang/slang-ir-inline.cpp
+++ b/source/slang/slang-ir-inline.cpp
@@ -236,8 +236,7 @@ struct InliningPassBase
// and will set it up to insert before the `call` that
// is going to be replaced.
//
- SharedIRBuilder sharedBuilder(m_module);
- IRBuilder builder(sharedBuilder);
+ IRBuilder builder(m_module);
builder.setInsertBefore(call);
// If callee is an intrinsic op, just issue that intrinsic and be done.
diff --git a/source/slang/slang-ir-inst-pass-base.h b/source/slang/slang-ir-inst-pass-base.h
index 86c2cb0fe..3b2331963 100644
--- a/source/slang/slang-ir-inst-pass-base.h
+++ b/source/slang/slang-ir-inst-pass-base.h
@@ -12,8 +12,6 @@ namespace Slang
{
protected:
IRModule* module;
- SharedIRBuilder sharedBuilderStorage;
-
List<IRInst*> workList;
HashSet<IRInst*> workListSet;
void addToWorkList(IRInst* inst)
diff --git a/source/slang/slang-ir-insts.h b/source/slang/slang-ir-insts.h
index 7a2e1f0e2..0eef9cb43 100644
--- a/source/slang/slang-ir-insts.h
+++ b/source/slang/slang-ir-insts.h
@@ -2441,8 +2441,8 @@ struct IRBuilderSourceLocRAII;
struct IRBuilder
{
private:
- /// Shared state for all IR builders working on the same module
- SharedIRBuilder* m_sharedBuilder = nullptr;
+ /// Deduplication context from the module.
+ IRDeduplicationContext* m_dedupContext = nullptr;
IRModule* m_module = nullptr;
@@ -2458,32 +2458,14 @@ public:
explicit IRBuilder(IRModule* module)
: m_module(module)
- , m_sharedBuilder(module->getSharedBuilder())
+ , m_dedupContext(module->getDeduplicationContext())
{}
- explicit IRBuilder(SharedIRBuilder* sharedBuilder)
- : IRBuilder(sharedBuilder->getModule())
+ explicit IRBuilder(IRInst* inst)
+ : m_module(inst->getModule())
+ , m_dedupContext(inst->getModule()->getDeduplicationContext())
{}
- explicit IRBuilder(SharedIRBuilder& sharedBuilder)
- : IRBuilder(sharedBuilder.getModule())
- {}
-
- void init(SharedIRBuilder* sharedBuilder)
- {
- *this = IRBuilder(sharedBuilder);
- }
-
- void init(SharedIRBuilder& sharedBuilder)
- {
- *this = IRBuilder(sharedBuilder);
- }
-
- SharedIRBuilder* getSharedBuilder() const
- {
- return m_module->getSharedBuilder();
- }
-
Session* getSession() const
{
return m_module->getSession();
@@ -3109,7 +3091,7 @@ public:
///
IRBlock* emitBlock();
-
+ static void insertBlockAlongEdge(IRModule* module, IREdge const& edge);
IRParam* createParam(
IRType* type);
diff --git a/source/slang/slang-ir-layout.cpp b/source/slang/slang-ir-layout.cpp
index 0e4ccc1fe..ab24d3354 100644
--- a/source/slang/slang-ir-layout.cpp
+++ b/source/slang/slang-ir-layout.cpp
@@ -155,9 +155,7 @@ static Result _calcNaturalSizeAndAlignment(
// cache the field offset on the IR field
// instruction.
//
- SharedIRBuilder sharedBuilder(module);
-
- IRBuilder builder(sharedBuilder);
+ IRBuilder builder(module);
auto intType = builder.getIntType();
builder.addDecoration(
@@ -247,8 +245,7 @@ static Result _calcNaturalSizeAndAlignment(
auto matType = cast<IRMatrixType>(type);
auto rowCount = getIntegerValueFromInst(matType->getRowCount());
auto colCount = getIntegerValueFromInst(matType->getColumnCount());
- SharedIRBuilder sharedBuilder(type->getModule());
- IRBuilder builder(sharedBuilder);
+ IRBuilder builder(type->getModule());
return _calcNaturalArraySizeAndAlignment(
target, matType->getElementType(),
@@ -307,9 +304,7 @@ Result getNaturalSizeAndAlignment(TargetRequest* target, IRType* type, IRSizeAnd
if( auto module = type->getModule() )
{
- SharedIRBuilder sharedBuilder(module);
-
- IRBuilder builder(sharedBuilder);
+ IRBuilder builder(module);
auto intType = builder.getIntType();
builder.addDecoration(
diff --git a/source/slang/slang-ir-legalize-array-return-type.cpp b/source/slang/slang-ir-legalize-array-return-type.cpp
index 711b21f1c..6fb49f5ce 100644
--- a/source/slang/slang-ir-legalize-array-return-type.cpp
+++ b/source/slang/slang-ir-legalize-array-return-type.cpp
@@ -80,10 +80,7 @@ void makeFuncReturnViaOutParam(IRBuilder& builder, IRFunc* func)
void legalizeArrayReturnType(IRModule* module)
{
- SharedIRBuilder builderStorage;
- builderStorage.init(module);
- builderStorage.deduplicateAndRebuildGlobalNumberingMap();
- IRBuilder builder(&builderStorage);
+ IRBuilder builder(module);
for (auto inst : module->getGlobalInsts())
{
diff --git a/source/slang/slang-ir-legalize-mesh-outputs.cpp b/source/slang/slang-ir-legalize-mesh-outputs.cpp
index db4d74ddb..66d59aa1f 100644
--- a/source/slang/slang-ir-legalize-mesh-outputs.cpp
+++ b/source/slang/slang-ir-legalize-mesh-outputs.cpp
@@ -8,9 +8,7 @@ namespace Slang
void legalizeMeshOutputTypes(IRModule* module)
{
- SharedIRBuilder builderStorage;
- builderStorage.init(module);
- IRBuilder builder(&builderStorage);
+ IRBuilder builder(module);
for (auto inst : module->getGlobalInsts())
{
diff --git a/source/slang/slang-ir-legalize-types.cpp b/source/slang/slang-ir-legalize-types.cpp
index d916fa691..96ffb9bb2 100644
--- a/source/slang/slang-ir-legalize-types.cpp
+++ b/source/slang/slang-ir-legalize-types.cpp
@@ -98,11 +98,8 @@ IRTypeLegalizationContext::IRTypeLegalizationContext(
session = inModule->getSession();
module = inModule;
- auto sharedBuilder = &sharedBuilderStorage;
- sharedBuilder->init(module);
-
+ builderStorage = IRBuilder(inModule);
builder = &builderStorage;
- builder->init(sharedBuilder);
}
static void registerLegalizedValue(
diff --git a/source/slang/slang-ir-legalize-varying-params.cpp b/source/slang/slang-ir-legalize-varying-params.cpp
index f32fd9933..a49c61499 100644
--- a/source/slang/slang-ir-legalize-varying-params.cpp
+++ b/source/slang/slang-ir-legalize-varying-params.cpp
@@ -199,12 +199,6 @@ public:
// process, to avoid having state changes on one builder
// affect other builders that might be in use.
//
- // All of those builders will need to have a common
- // shared builder to avoid unnecessary duplication of
- // types/constants.
- //
- SharedIRBuilder sharedBuilderStorage(module);
- m_sharedBuilder = &sharedBuilderStorage;
// Once the basic initialization is done, we will allow
// the subtype to implement its own initialization logic
@@ -258,7 +252,6 @@ protected:
IRModule* m_module = nullptr;
DiagnosticSink* m_sink = nullptr;
- SharedIRBuilder* m_sharedBuilder = nullptr;
IRFunc* m_entryPointFunc = nullptr;
IRBlock* m_firstBlock = nullptr;
@@ -323,7 +316,7 @@ protected:
// any `returnVal(r)` instructions in the function body to
// instead assign `r` to `legalResult` and then `returnVoid`.
//
- IRBuilder builder(m_sharedBuilder);
+ IRBuilder builder(m_module);
for( auto block : entryPointFunc->getBlocks() )
{
auto returnValInst = as<IRReturn>(block->getTerminator());
@@ -465,7 +458,7 @@ protected:
// The replacement variable will be declared at the top of
// the function.
//
- IRBuilder builder(m_sharedBuilder);
+ IRBuilder builder(m_module);
builder.setInsertBefore(m_firstOrdinaryInst);
auto localVar = builder.emitVar(valueType);
@@ -550,7 +543,7 @@ protected:
// for things like indexing into varying arrays, but at the
// cost of more accesses to the input parameter data.
//
- IRBuilder builder(m_sharedBuilder);
+ IRBuilder builder(m_module);
builder.setInsertBefore(m_firstOrdinaryInst);
IRInst* materialized = materialize(builder, legalVal);
@@ -1149,7 +1142,7 @@ struct CUDAEntryPointVaryingParamLegalizeContext : EntryPointVaryingParamLegaliz
// definitions once per module, instead of once per
// entry point.
//
- IRBuilder builder(m_sharedBuilder);
+ IRBuilder builder(m_module);
builder.setInsertInto(m_module->getModuleInst());
// We begin by looking up the `uint` and `uint3` types.
@@ -1204,7 +1197,7 @@ struct CUDAEntryPointVaryingParamLegalizeContext : EntryPointVaryingParamLegaliz
IRInst* dispatchThreadID = nullptr;
void beginEntryPointImpl() SLANG_OVERRIDE
{
- IRBuilder builder(m_sharedBuilder);
+ IRBuilder builder(m_module);
builder.setInsertBefore(m_firstOrdinaryInst);
// Note that we can use the built-in `blockDim`
@@ -1272,7 +1265,7 @@ struct CUDAEntryPointVaryingParamLegalizeContext : EntryPointVaryingParamLegaliz
switch (layoutResourceKind)
{
case LayoutResourceKind::RayPayload: {
- IRBuilder builder(m_sharedBuilder);
+ IRBuilder builder(m_module);
builder.setInsertBefore(m_firstOrdinaryInst);
IRPtrType* ptrType = builder.getPtrType(info.type);
IRInst* getRayPayload = builder.emitIntrinsicInst(ptrType, kIROp_GetOptiXRayPayloadPtr, 0, nullptr);
@@ -1290,7 +1283,7 @@ struct CUDAEntryPointVaryingParamLegalizeContext : EntryPointVaryingParamLegaliz
}*/
}
case LayoutResourceKind::HitAttributes: {
- IRBuilder builder(m_sharedBuilder);
+ IRBuilder builder(m_module);
builder.setInsertBefore(m_firstOrdinaryInst);
int ioBaseAttributeIndex = 0;
IRInst* getHitAttributes = emitOptiXAttributeFetch(/*ioBaseAttributeIndex*/ ioBaseAttributeIndex, /* type to fetch */info.type, /*the builder in use*/ &builder);
@@ -1330,7 +1323,7 @@ struct CPUEntryPointVaryingParamLegalizeContext : EntryPointVaryingParamLegalize
void beginModuleImpl() SLANG_OVERRIDE
{
- IRBuilder builder(m_sharedBuilder);
+ IRBuilder builder(m_module);
builder.setInsertInto(m_module->getModuleInst());
uintType = builder.getBasicType(BaseType::UInt);
@@ -1377,7 +1370,7 @@ struct CPUEntryPointVaryingParamLegalizeContext : EntryPointVaryingParamLegalize
groupThreadID = nullptr;
dispatchThreadID = nullptr;
- IRBuilder builder(m_sharedBuilder);
+ IRBuilder builder(m_module);
auto varyingInputParam = builder.createParam(varyingInputStructPtrType);
varyingInputParam->insertBefore(m_firstBlock->getFirstChild());
diff --git a/source/slang/slang-ir-link.cpp b/source/slang/slang-ir-link.cpp
index 55048484f..bcff5621c 100644
--- a/source/slang/slang-ir-link.cpp
+++ b/source/slang/slang-ir-link.cpp
@@ -54,7 +54,6 @@ struct IRSharedSpecContext
typedef Dictionary<String, RefPtr<IRSpecSymbol>> SymbolDictionary;
SymbolDictionary symbols;
- SharedIRBuilder sharedBuilderStorage;
IRBuilder builderStorage;
// The "global" specialization environment.
@@ -1369,19 +1368,13 @@ void initializeSharedSpecContext(
CodeGenTarget target,
TargetRequest* targetReq)
{
-
- SharedIRBuilder* sharedBuilder = &sharedContext->sharedBuilderStorage;
-
- IRBuilder* builder = &sharedContext->builderStorage;
-
RefPtr<IRModule> module = inModule;
if( !module )
{
module = IRModule::create(session);
}
- sharedBuilder->init(module);
- builder->init(sharedBuilder);
+ sharedContext->builderStorage = IRBuilder(module);
sharedContext->module = module;
sharedContext->target = target;
@@ -1506,12 +1499,11 @@ LinkedIR linkIR(
// Combine all of the contents of IRGlobalHashedStringLiterals
{
StringSlicePool pool(StringSlicePool::Style::Empty);
- IRBuilder& builder = sharedContext->builderStorage;
for (IRModule* irModule : irModules)
{
findGlobalHashedStringLiterals(irModule, pool);
}
- addGlobalHashedStringLiterals(pool, *builder.getSharedBuilder());
+ addGlobalHashedStringLiterals(pool, state->irModule);
}
// Set up shared and builder insert point
diff --git a/source/slang/slang-ir-liveness.cpp b/source/slang/slang-ir-liveness.cpp
index 31177e29a..f2d834cc1 100644
--- a/source/slang/slang-ir-liveness.cpp
+++ b/source/slang/slang-ir-liveness.cpp
@@ -207,13 +207,11 @@ struct LivenessContext
LivenessContext(IRModule* module, LivenessMode mode):
m_module(module),
- m_livenessMode(mode)
+ m_livenessMode(mode),
+ m_builder(module)
{
// Disable warning if not used
SLANG_UNUSED(&LivenessContext::_isAnyRunInst);
-
- m_sharedBuilder.init(module);
- m_builder.init(m_sharedBuilder);
}
/// For a given live range start find it's end/s and insert a LiveRangeEnd/s
@@ -346,7 +344,6 @@ struct LivenessContext
List<IRLiveRangeEnd*> m_rangeEnds; ///< All of the ends added
IRModule* m_module;
- SharedIRBuilder m_sharedBuilder;
IRBuilder m_builder;
LivenessMode m_livenessMode;
@@ -1572,11 +1569,7 @@ static void _processFunction(IRFunc* funcInst, List<IRVar*>& ioVars)
// When we process liveness, is prior to output for a target
// So post specialization
- SharedIRBuilder sharedBuilder;
- IRBuilder builder;
-
- sharedBuilder.init(module);
- builder.init(sharedBuilder);
+ IRBuilder builder(module);
// Storage for found vars
List<IRVar*> vars;
diff --git a/source/slang/slang-ir-loop-unroll.cpp b/source/slang/slang-ir-loop-unroll.cpp
index f606f0cc1..79b00f60a 100644
--- a/source/slang/slang-ir-loop-unroll.cpp
+++ b/source/slang/slang-ir-loop-unroll.cpp
@@ -112,7 +112,7 @@ static void _foldAndSimplifyLoopIteration(
{
for (auto inst : b->getChildren())
{
- tryReplaceInstUsesWithSimplifiedValue(builder.getSharedBuilder(), inst);
+ tryReplaceInstUsesWithSimplifiedValue(builder.getModule(), inst);
}
}
@@ -120,7 +120,7 @@ static void _foldAndSimplifyLoopIteration(
// the phi arguments for next iteration evaluated (args in the new loop inst).
for (auto inst : firstIterationBreakBlock->getChildren())
{
- tryReplaceInstUsesWithSimplifiedValue(builder.getSharedBuilder(), inst);
+ tryReplaceInstUsesWithSimplifiedValue(builder.getModule(), inst);
}
// Fold conditional branches into unconditional branches if the condition is known.
@@ -182,13 +182,13 @@ static void _foldAndSimplifyLoopIteration(
// Returns true if we can statically determine that the loop terminated within the iteration limit.
// This operation assumes the loop does not have `continue` jumps, i.e. continueBlock == targetBlock.
static bool _unrollLoop(
- SharedIRBuilder* sharedBuilder,
+ IRModule* module,
IRLoop* loopInst,
List<IRBlock*>& blocks)
{
if (blocks.getCount() == 0)
{
- IRBuilder subBuilder(sharedBuilder);
+ IRBuilder subBuilder(module);
subBuilder.setInsertBefore(loopInst);
subBuilder.emitBranch(loopInst->getBreakBlock());
loopInst->removeAndDeallocate();
@@ -211,7 +211,7 @@ static bool _unrollLoop(
// After this transform, the original break block of the loop will serve as the break block for the
// outer breakable region.
- IRBuilder builder(sharedBuilder);
+ IRBuilder builder(module);
auto unreachableBlock = builder.createBlock();
builder.setInsertInto(unreachableBlock);
@@ -468,7 +468,7 @@ List<IRLoop*> collectLoopsInFunc(IRGlobalValueWithCode* func, const TFunc& filte
}
bool unrollLoopsInFunc(
- SharedIRBuilder* sharedBuilder,
+ IRModule* module,
IRGlobalValueWithCode* func,
DiagnosticSink* sink)
{
@@ -481,7 +481,7 @@ bool unrollLoopsInFunc(
for (auto loop : loops)
{
// Remove any continue jumps from the loop.
- eliminateContinueBlocks(sharedBuilder, loop);
+ eliminateContinueBlocks(module, loop);
auto postOrderReverseCFG = getPostorderOnReverseCFG(func);
Dictionary<IRBlock*, int> blockOrdering;
@@ -493,7 +493,7 @@ bool unrollLoopsInFunc(
auto blocks = _collectBlocksInLoop(blockOrdering, loop);
auto loopLoc = loop->sourceLoc;
- if (!_unrollLoop(sharedBuilder, loop, blocks))
+ if (!_unrollLoop(module, loop, blocks))
{
if (sink)
sink->diagnose(loopLoc, Diagnostics::cannotUnrollLoop);
@@ -508,7 +508,7 @@ bool unrollLoopsInFunc(
return true;
}
-bool unrollLoopsInModule(SharedIRBuilder* sharedBuilder, IRModule* module, DiagnosticSink* sink)
+bool unrollLoopsInModule(IRModule* module, DiagnosticSink* sink)
{
for (auto inst : module->getGlobalInsts())
{
@@ -516,14 +516,14 @@ bool unrollLoopsInModule(SharedIRBuilder* sharedBuilder, IRModule* module, Diagn
{
if (auto func = as<IRGlobalValueWithCode>(findGenericReturnVal(genFunc)))
{
- bool result = unrollLoopsInFunc(sharedBuilder, func, sink);
+ bool result = unrollLoopsInFunc(module, func, sink);
if (!result)
return false;
}
}
else if (auto func = as<IRGlobalValueWithCode>(inst))
{
- bool result = unrollLoopsInFunc(sharedBuilder, func, sink);
+ bool result = unrollLoopsInFunc(module, func, sink);
if (!result)
return false;
}
@@ -548,7 +548,7 @@ static void _moveParams(IRBlock* dest, IRBlock* src)
}
}
-void eliminateContinueBlocks(SharedIRBuilder* sharedBuilder, IRLoop* loopInst)
+void eliminateContinueBlocks(IRModule* module, IRLoop* loopInst)
{
// Eliminate the continue jumps by turning a loop in the form of:
// for (;;)
@@ -585,7 +585,7 @@ void eliminateContinueBlocks(SharedIRBuilder* sharedBuilder, IRLoop* loopInst)
// We have determined that there is really a non-trivial continue block in the loop body,
// we will now introduce a breakable region for each iteration.
- IRBuilder builder(sharedBuilder);
+ IRBuilder builder(module);
auto targetBlock = loopInst->getTargetBlock();
@@ -613,7 +613,7 @@ void eliminateContinueBlocks(SharedIRBuilder* sharedBuilder, IRLoop* loopInst)
builder.emitBranch(continueBlock);
}
-void eliminateContinueBlocksInFunc(SharedIRBuilder* sharedBuilder, IRGlobalValueWithCode* func)
+void eliminateContinueBlocksInFunc(IRModule* module, IRGlobalValueWithCode* func)
{
List<IRLoop*> loops = collectLoopsInFunc(
func, [](IRLoop* l) { return l->getContinueBlock() != l->getTargetBlock(); });
@@ -623,7 +623,7 @@ void eliminateContinueBlocksInFunc(SharedIRBuilder* sharedBuilder, IRGlobalValue
for (auto loop : loops)
{
- eliminateContinueBlocks(sharedBuilder, loop);
+ eliminateContinueBlocks(module, loop);
}
}
diff --git a/source/slang/slang-ir-loop-unroll.h b/source/slang/slang-ir-loop-unroll.h
index 340011cb5..d9c31e6be 100644
--- a/source/slang/slang-ir-loop-unroll.h
+++ b/source/slang/slang-ir-loop-unroll.h
@@ -5,14 +5,13 @@ namespace Slang
{
struct IRLoop;
struct IRGlobalValueWithCode;
- struct SharedIRBuilder;
class DiagnosticSink;
struct IRModule;
// Return true if successfull, false if errors occurred.
- bool unrollLoopsInFunc(SharedIRBuilder* sharedBuilder, IRGlobalValueWithCode* func, DiagnosticSink* sink);
+ bool unrollLoopsInFunc(IRModule* module, IRGlobalValueWithCode* func, DiagnosticSink* sink);
- bool unrollLoopsInModule(SharedIRBuilder* sharedBuilder, IRModule* module, DiagnosticSink* sink);
+ bool unrollLoopsInModule(IRModule* module, DiagnosticSink* sink);
// Turn a loop with continue block into a loop with only back jumps and breaks.
@@ -20,7 +19,7 @@ namespace Slang
// is within the breakable region, and everything after `continue` is outside the breakable
// region. A `continue` then becomes a `break` in the inner breakable region, and a `break`
// becomes a multi-level break out of the parent loop.
- void eliminateContinueBlocks(SharedIRBuilder* sharedBuilder, IRLoop* loopInst);
- void eliminateContinueBlocksInFunc(SharedIRBuilder* sharedBuilder, IRGlobalValueWithCode* func);
+ void eliminateContinueBlocks(IRModule* module, IRLoop* loopInst);
+ void eliminateContinueBlocksInFunc(IRModule* module, IRGlobalValueWithCode* func);
}
diff --git a/source/slang/slang-ir-lower-bit-cast.cpp b/source/slang/slang-ir-lower-bit-cast.cpp
index e7a4b661b..700d30d52 100644
--- a/source/slang/slang-ir-lower-bit-cast.cpp
+++ b/source/slang/slang-ir-lower-bit-cast.cpp
@@ -11,7 +11,6 @@ struct BitCastLoweringContext
{
TargetRequest* targetReq;
IRModule* module;
- SharedIRBuilder sharedBuilderStorage;
OrderedHashSet<IRInst*> workList;
void addToWorkList(IRInst* inst)
@@ -42,12 +41,6 @@ struct BitCastLoweringContext
void processModule()
{
- SharedIRBuilder* sharedBuilder = &sharedBuilderStorage;
- sharedBuilder->init(module);
-
- // Deduplicate equivalent types.
- sharedBuilder->deduplicateAndRebuildGlobalNumberingMap();
-
addToWorkList(module->getModuleInst());
while (workList.Count() != 0)
@@ -246,7 +239,7 @@ struct BitCastLoweringContext
return;
}
// Enumerate all fields in to-type and obtain its value from operand object.
- IRBuilder builder(sharedBuilderStorage);
+ IRBuilder builder(module);
builder.setInsertBefore(inst);
auto finalObject = readObject(builder, operand, toType, 0);
inst->replaceUsesWith(finalObject);
diff --git a/source/slang/slang-ir-lower-com-methods.cpp b/source/slang/slang-ir-lower-com-methods.cpp
index 495e20151..4ff9c1848 100644
--- a/source/slang/slang-ir-lower-com-methods.cpp
+++ b/source/slang/slang-ir-lower-com-methods.cpp
@@ -25,7 +25,7 @@ struct ComMethodLoweringContext : public InstPassBase
void processComCall(IRCall* comCall)
{
- IRBuilder builder(&sharedBuilderStorage);
+ IRBuilder builder(module);
builder.setInsertBefore(comCall);
auto callee = as<IRLookupWitnessMethod>(comCall->getCallee());
SLANG_ASSERT(callee);
@@ -101,7 +101,7 @@ struct ComMethodLoweringContext : public InstPassBase
{
if (!interfaceType->findDecoration<IRComInterfaceDecoration>())
return;
- IRBuilder builder(&sharedBuilderStorage);
+ IRBuilder builder(module);
for (UInt i = 0; i < interfaceType->getOperandCount(); i++)
{
auto entry = as<IRInterfaceRequirementEntry>(interfaceType->getOperand(i));
@@ -123,7 +123,7 @@ struct ComMethodLoweringContext : public InstPassBase
return;
auto interfaceReqDict = buildInterfaceRequirementDict(interfaceType);
- IRBuilder builder(&sharedBuilderStorage);
+ IRBuilder builder(module);
NativeCallMarshallingContext marshalContext;
marshalContext.diagnosticSink = diagnosticSink;
for (auto entry : witnessTable->getEntries())
@@ -148,18 +148,13 @@ struct ComMethodLoweringContext : public InstPassBase
void processModule()
{
- sharedBuilderStorage.init(module);
-
- // Deduplicate equivalent types.
- sharedBuilderStorage.deduplicateAndRebuildGlobalNumberingMap();
-
// Translate all Calls to interface methods.
processInstsOfType<IRCall>(kIROp_Call, [this](IRCall* inst) { processCall(inst); });
// Update functypes of com callees.
for (auto callee : comCallees)
{
- IRBuilder builder(&sharedBuilderStorage);
+ IRBuilder builder(module);
builder.setInsertBefore(callee);
auto nativeType = marshal.getNativeFuncType(builder, as<IRFuncType>(callee->getDataType()));
callee->setFullType(nativeType);
diff --git a/source/slang/slang-ir-lower-error-handling.cpp b/source/slang/slang-ir-lower-error-handling.cpp
index e9747e3b6..013f683c0 100644
--- a/source/slang/slang-ir-lower-error-handling.cpp
+++ b/source/slang/slang-ir-lower-error-handling.cpp
@@ -13,8 +13,6 @@ struct ErrorHandlingLoweringContext
IRModule* module;
DiagnosticSink* diagnosticSink;
- SharedIRBuilder sharedBuilder;
-
List<IRInst*> workList;
HashSet<IRInst*> workListSet;
@@ -32,7 +30,7 @@ struct ErrorHandlingLoweringContext
auto throwAttr = funcType->findAttr<IRFuncThrowTypeAttr>();
if (!throwAttr)
return;
- IRBuilder builder(sharedBuilder);
+ IRBuilder builder(module);
builder.setInsertBefore(funcType);
auto resultType =
builder.getResultType(funcType->getResultType(), throwAttr->getErrorType());
@@ -44,7 +42,7 @@ struct ErrorHandlingLoweringContext
paramTypes.add(funcType->getParamType(i));
}
auto newFuncType = builder.getFuncType(paramTypes, resultType);
- sharedBuilder.replaceGlobalInst(funcType, newFuncType);
+ funcType->replaceUsesWith(newFuncType);
}
void processTryCall(IRTryCall* tryCall)
@@ -80,7 +78,7 @@ struct ErrorHandlingLoweringContext
}
auto errorType = throwAttr->getErrorType();
- IRBuilder builder(sharedBuilder);
+ IRBuilder builder(module);
builder.setInsertBefore(tryCall);
auto resultType = builder.getResultType(resultValueType, errorType);
@@ -127,7 +125,7 @@ struct ErrorHandlingLoweringContext
// If we are in a throwing function and sees a `return(val)` inst,
// replace it with a `return makeResultValue(val)`, so that it returns a `Result<T,E>` type.
- IRBuilder builder(sharedBuilder);
+ IRBuilder builder(module);
builder.setInsertBefore(ret);
auto resultType =
builder.getResultType(funcType->getResultType(), throwAttr->getErrorType());
@@ -148,7 +146,7 @@ struct ErrorHandlingLoweringContext
// If we are in a throwing function and sees a `throw(e)` inst,
// replace it with a `return makeResultError(e)`.
- IRBuilder builder(sharedBuilder);
+ IRBuilder builder(module);
builder.setInsertBefore(throwInst);
auto resultType =
builder.getResultType(funcType->getResultType(), throwAttr->getErrorType());
@@ -197,9 +195,6 @@ struct ErrorHandlingLoweringContext
void processModule()
{
- // Deduplicate equivalent types.
- sharedBuilder.deduplicateAndRebuildGlobalNumberingMap();
-
// Translate all IRTryCall, IRThrow, IRReturn.
processInsts();
@@ -230,7 +225,6 @@ void lowerErrorHandling(IRModule* module, DiagnosticSink* sink)
ErrorHandlingLoweringContext context;
context.module = module;
context.diagnosticSink = sink;
- context.sharedBuilder.init(module);
return context.processModule();
}
}
diff --git a/source/slang/slang-ir-lower-existential.cpp b/source/slang/slang-ir-lower-existential.cpp
index f7669a557..9c31c0411 100644
--- a/source/slang/slang-ir-lower-existential.cpp
+++ b/source/slang/slang-ir-lower-existential.cpp
@@ -17,7 +17,7 @@ namespace Slang
void processMakeExistential(IRMakeExistentialWithRTTI* inst)
{
- IRBuilder builderStorage(sharedContext->sharedBuilderStorage);
+ IRBuilder builderStorage(sharedContext->module);
auto builder = &builderStorage;
builder->setInsertBefore(inst);
auto value = inst->getWrappedValue();
@@ -55,7 +55,7 @@ namespace Slang
// existential value.
void processCreateExistentialObject(IRCreateExistentialObject* inst)
{
- IRBuilder builderStorage(sharedContext->sharedBuilderStorage);
+ IRBuilder builderStorage(sharedContext->module);
auto builder = &builderStorage;
builder->setInsertBefore(inst);
@@ -105,7 +105,7 @@ namespace Slang
void processExtractExistentialElement(IRInst* extractInst, UInt elementId)
{
- IRBuilder builderStorage(sharedContext->sharedBuilderStorage);
+ IRBuilder builderStorage(sharedContext->module);
auto builder = &builderStorage;
builder->setInsertBefore(extractInst);
@@ -140,7 +140,7 @@ namespace Slang
void processGetValueFromBoundInterface(IRGetValueFromBoundInterface* inst)
{
- IRBuilder builderStorage(sharedContext->sharedBuilderStorage);
+ IRBuilder builderStorage(sharedContext->module);
auto builder = &builderStorage;
builder->setInsertBefore(inst);
if (inst->getDataType()->getOp() == kIROp_ClassType)
@@ -219,13 +219,6 @@ namespace Slang
void processModule()
{
- // We start by initializing our shared IR building state,
- // since we will re-use that state for any code we
- // generate along the way.
- //
- SharedIRBuilder* sharedBuilder = &sharedContext->sharedBuilderStorage;
- sharedBuilder->init(sharedContext->module);
-
sharedContext->addToWorkList(sharedContext->module->getModuleInst());
while (sharedContext->workList.getCount() != 0)
diff --git a/source/slang/slang-ir-lower-generic-call.cpp b/source/slang/slang-ir-lower-generic-call.cpp
index 3f3743f2b..0b24b2a9b 100644
--- a/source/slang/slang-ir-lower-generic-call.cpp
+++ b/source/slang/slang-ir-lower-generic-call.cpp
@@ -156,7 +156,7 @@ namespace Slang
for (UInt i = 0; i < funcType->getParamCount(); i++)
paramTypes.add(funcType->getParamType(i));
- IRBuilder builderStorage(sharedContext->sharedBuilderStorage);
+ IRBuilder builderStorage(sharedContext->module);
auto builder = &builderStorage;
builder->setInsertBefore(callInst);
@@ -288,7 +288,7 @@ namespace Slang
if (isBuiltin(interfaceType))
return;
- IRBuilder builderStorage(sharedContext->sharedBuilderStorage);
+ IRBuilder builderStorage(sharedContext->module);
auto builder = &builderStorage;
builder->setInsertBefore(callInst);
@@ -348,13 +348,6 @@ namespace Slang
void processModule()
{
- // We start by initializing our shared IR building state,
- // since we will re-use that state for any code we
- // generate along the way.
- //
- SharedIRBuilder* sharedBuilder = &sharedContext->sharedBuilderStorage;
- sharedBuilder->init(sharedContext->module);
-
sharedContext->addToWorkList(sharedContext->module->getModuleInst());
while (sharedContext->workList.getCount() != 0)
diff --git a/source/slang/slang-ir-lower-generic-function.cpp b/source/slang/slang-ir-lower-generic-function.cpp
index f2d7159d4..9f9960163 100644
--- a/source/slang/slang-ir-lower-generic-function.cpp
+++ b/source/slang/slang-ir-lower-generic-function.cpp
@@ -46,7 +46,7 @@ namespace Slang
return genericValue;
}
IRCloneEnv cloneEnv;
- IRBuilder builder(sharedContext->sharedBuilderStorage);
+ IRBuilder builder(sharedContext->module);
builder.setInsertBefore(genericParent);
// Do not clone func type (which would break IR def-use rules if we do it here)
// This is OK since we will lower the type immediately after the clone.
@@ -103,7 +103,7 @@ namespace Slang
}
}
}
- cloneInstDecorationsAndChildren(&cloneEnv, &sharedContext->sharedBuilderStorage, func, loweredFunc);
+ cloneInstDecorationsAndChildren(&cloneEnv, sharedContext->module, func, loweredFunc);
auto block = as<IRBlock>(loweredFunc->getFirstChild());
for (auto param : clonedParams)
@@ -177,7 +177,7 @@ namespace Slang
(IRType*)newOperands[0]);
IRCloneEnv cloneEnv;
- cloneInstDecorationsAndChildren(&cloneEnv, &sharedContext->sharedBuilderStorage, funcType, newFuncType);
+ cloneInstDecorationsAndChildren(&cloneEnv, sharedContext->module, funcType, newFuncType);
return newFuncType;
}
@@ -197,7 +197,7 @@ namespace Slang
List<IRInterfaceRequirementEntry*> newEntries;
- IRBuilder builder(sharedContext->sharedBuilderStorage);
+ IRBuilder builder(sharedContext->module);
builder.setInsertBefore(interfaceType);
// Translate IRFuncType in interface requirements.
@@ -240,7 +240,7 @@ namespace Slang
loweredType = builder.createInterfaceType(newEntries.getCount(), (IRInst**)newEntries.getBuffer());
loweredType->sourceLoc = interfaceType->sourceLoc;
IRCloneEnv cloneEnv;
- cloneInstDecorationsAndChildren(&cloneEnv, &sharedContext->sharedBuilderStorage,
+ cloneInstDecorationsAndChildren(&cloneEnv, sharedContext->module,
interfaceType, loweredType);
sharedContext->loweredInterfaceTypes.Add(interfaceType, loweredType);
sharedContext->mapLoweredInterfaceToOriginal[loweredType] = interfaceType;
@@ -259,7 +259,7 @@ namespace Slang
void lowerWitnessTable(IRWitnessTable* witnessTable)
{
auto interfaceType = maybeLowerInterfaceType(cast<IRInterfaceType>(witnessTable->getConformanceType()));
- IRBuilder builderStorage(sharedContext->sharedBuilderStorage);
+ IRBuilder builderStorage(sharedContext->module);
auto builder = &builderStorage;
builder->setInsertBefore(witnessTable);
if (interfaceType != witnessTable->getConformanceType())
@@ -359,20 +359,11 @@ namespace Slang
{
lowered.Key->replaceUsesWith(lowered.Value);
}
- // Update hash keys of globalNumberingMap, since the types are modified.
- sharedContext->sharedBuilderStorage.deduplicateAndRebuildGlobalNumberingMap();
sharedContext->mapInterfaceRequirementKeyValue.Clear();
}
void processModule()
{
- // We start by initializing our shared IR building state,
- // since we will re-use that state for any code we
- // generate along the way.
- //
- SharedIRBuilder* sharedBuilder = &sharedContext->sharedBuilderStorage;
- sharedBuilder->init(sharedContext->module);
-
sharedContext->addToWorkList(sharedContext->module->getModuleInst());
while (sharedContext->workList.getCount() != 0)
diff --git a/source/slang/slang-ir-lower-generic-type.cpp b/source/slang/slang-ir-lower-generic-type.cpp
index 24a8c38d8..398db4f78 100644
--- a/source/slang/slang-ir-lower-generic-type.cpp
+++ b/source/slang/slang-ir-lower-generic-type.cpp
@@ -29,7 +29,7 @@ namespace Slang
if (as<IRType>(inst))
return;
- IRBuilder builderStorage(sharedContext->sharedBuilderStorage);
+ IRBuilder builderStorage(sharedContext->module);
auto builder = &builderStorage;
builder->setInsertBefore(inst);
@@ -55,13 +55,6 @@ namespace Slang
void processModule()
{
- // We start by initializing our shared IR building state,
- // since we will re-use that state for any code we
- // generate along the way.
- //
- SharedIRBuilder* sharedBuilder = &sharedContext->sharedBuilderStorage;
- sharedBuilder->init(sharedContext->module);
-
sharedContext->addToWorkList(sharedContext->module->getModuleInst());
while (sharedContext->workList.getCount() != 0)
@@ -78,7 +71,6 @@ namespace Slang
sharedContext->addToWorkList(child);
}
}
- sharedContext->sharedBuilderStorage.deduplicateAndRebuildGlobalNumberingMap();
sharedContext->mapInterfaceRequirementKeyValue.Clear();
}
};
diff --git a/source/slang/slang-ir-lower-generics.cpp b/source/slang/slang-ir-lower-generics.cpp
index 41f9e3e59..bc6b9fff8 100644
--- a/source/slang/slang-ir-lower-generics.cpp
+++ b/source/slang/slang-ir-lower-generics.cpp
@@ -27,7 +27,7 @@ namespace Slang
uint32_t id = 0;
for (auto rtti : sharedContext->mapTypeToRTTIObject)
{
- IRBuilder builder(sharedContext->sharedBuilderStorage);
+ IRBuilder builder(sharedContext->module);
builder.setInsertBefore(rtti.Value);
IRUse* nextUse = nullptr;
auto uint2Type = builder.getVectorType(
@@ -61,7 +61,7 @@ namespace Slang
// fall through
case kIROp_RTTIHandleType:
{
- IRBuilder builder(sharedContext->sharedBuilderStorage);
+ IRBuilder builder(sharedContext->module);
builder.setInsertBefore(inst);
auto uint2Type = builder.getVectorType(
builder.getUIntType(), builder.getIntValue(builder.getIntType(), 2));
@@ -78,7 +78,7 @@ namespace Slang
// Remove all interface types from module.
void cleanUpInterfaceTypes(SharedGenericsLoweringContext* sharedContext)
{
- IRBuilder builder(sharedContext->sharedBuilderStorage);
+ IRBuilder builder(sharedContext->module);
builder.setInsertInto(sharedContext->module->getModuleInst());
auto dummyInterfaceObj = builder.getIntValue(builder.getIntType(), 0);
List<IRInst*> interfaceInsts;
@@ -107,7 +107,7 @@ namespace Slang
auto witnessTableType = as<IRWitnessTableTypeBase>(inst->getValueWitness()->getDataType());
if (witnessTableType && isComInterfaceType((IRType*)witnessTableType->getConformanceType()))
return;
- IRBuilder builder(sharedContext->sharedBuilderStorage);
+ IRBuilder builder(sharedContext->module);
builder.setInsertBefore(inst);
auto eqlInst = builder.emitEql(builder.emitGetSequentialIDInst(inst->getValueWitness()),
builder.emitGetSequentialIDInst(inst->getTargetWitness()));
@@ -133,10 +133,8 @@ namespace Slang
if (sink->getErrorCount() != 0)
return;
- sharedContext->sharedBuilderStorage.deduplicateAndRebuildGlobalNumberingMap();
sharedContext->mapInterfaceRequirementKeyValue.Clear();
-
specializeRTTIObjectReferences(sharedContext);
cleanUpRTTIHandleTypes(sharedContext);
diff --git a/source/slang/slang-ir-lower-optional-type.cpp b/source/slang/slang-ir-lower-optional-type.cpp
index c4a40774c..4156fe9e1 100644
--- a/source/slang/slang-ir-lower-optional-type.cpp
+++ b/source/slang/slang-ir-lower-optional-type.cpp
@@ -12,8 +12,6 @@ namespace Slang
IRModule* module;
DiagnosticSink* sink;
- SharedIRBuilder sharedBuilderStorage;
-
List<IRInst*> workList;
HashSet<IRInst*> workListSet;
@@ -113,7 +111,7 @@ namespace Slang
void processMakeOptionalValue(IRMakeOptionalValue* inst)
{
- IRBuilder builderStorage(sharedBuilderStorage);
+ IRBuilder builderStorage(module);
auto builder = &builderStorage;
builder->setInsertBefore(inst);
@@ -136,7 +134,7 @@ namespace Slang
void processMakeOptionalNone(IRMakeOptionalNone* inst)
{
- IRBuilder builderStorage(sharedBuilderStorage);
+ IRBuilder builderStorage(module);
auto builder = &builderStorage;
builder->setInsertBefore(inst);
@@ -178,7 +176,7 @@ namespace Slang
void processGetOptionalHasValue(IROptionalHasValue* inst)
{
- IRBuilder builderStorage(sharedBuilderStorage);
+ IRBuilder builderStorage(module);
auto builder = &builderStorage;
builder->setInsertBefore(inst);
@@ -190,7 +188,7 @@ namespace Slang
void processGetOptionalValue(IRGetOptionalValue* inst)
{
- IRBuilder builderStorage(sharedBuilderStorage);
+ IRBuilder builderStorage(module);
auto builder = &builderStorage;
builder->setInsertBefore(inst);
@@ -215,7 +213,7 @@ namespace Slang
void processOptionalType(IROptionalType* inst)
{
- IRBuilder builderStorage(sharedBuilderStorage);
+ IRBuilder builderStorage(module);
auto builder = &builderStorage;
builder->setInsertBefore(inst);
@@ -250,12 +248,6 @@ namespace Slang
void processModule()
{
- SharedIRBuilder* sharedBuilder = &sharedBuilderStorage;
- sharedBuilder->init(module);
-
- // Deduplicate equivalent types.
- sharedBuilder->deduplicateAndRebuildGlobalNumberingMap();
-
addToWorkList(module->getModuleInst());
while (workList.getCount() != 0)
diff --git a/source/slang/slang-ir-lower-reinterpret.cpp b/source/slang/slang-ir-lower-reinterpret.cpp
index b7c88e632..6fef9ee84 100644
--- a/source/slang/slang-ir-lower-reinterpret.cpp
+++ b/source/slang/slang-ir-lower-reinterpret.cpp
@@ -12,7 +12,6 @@ struct ReinterpretLoweringContext
TargetRequest* targetReq;
DiagnosticSink* sink;
IRModule* module;
- SharedIRBuilder sharedBuilderStorage;
OrderedHashSet<IRInst*> workList;
void addToWorkList(IRInst* inst)
@@ -37,12 +36,6 @@ struct ReinterpretLoweringContext
void processModule()
{
- SharedIRBuilder* sharedBuilder = &sharedBuilderStorage;
- sharedBuilder->init(module);
-
- // Deduplicate equivalent types.
- sharedBuilder->deduplicateAndRebuildGlobalNumberingMap();
-
addToWorkList(module->getModuleInst());
while (workList.Count() != 0)
@@ -77,7 +70,7 @@ struct ReinterpretLoweringContext
}
SlangInt anyValueSize = Math::Max(fromTypeSize, toTypeSize);
- IRBuilder builder(sharedBuilderStorage);
+ IRBuilder builder(module);
builder.setInsertBefore(inst);
auto anyValueType = builder.getAnyValueType(builder.getIntValue(builder.getUIntType(), anyValueSize));
auto packInst = builder.emitPackAnyValue(
diff --git a/source/slang/slang-ir-lower-result-type.cpp b/source/slang/slang-ir-lower-result-type.cpp
index 623583c7a..7b4712a18 100644
--- a/source/slang/slang-ir-lower-result-type.cpp
+++ b/source/slang/slang-ir-lower-result-type.cpp
@@ -11,8 +11,6 @@ namespace Slang
IRModule* module;
DiagnosticSink* sink;
- SharedIRBuilder sharedBuilderStorage;
-
List<IRInst*> workList;
HashSet<IRInst*> workListSet;
@@ -113,7 +111,7 @@ namespace Slang
default:
SLANG_ASSERT_FAILURE("error type is not lowered to an integer type.");
}
- IRBuilder builderStorage(sharedBuilderStorage);
+ IRBuilder builderStorage(module);
auto builder = &builderStorage;
builder->setInsertInto(module);
return builder->getIntValue(type, 0);
@@ -121,7 +119,7 @@ namespace Slang
void processMakeResultValue(IRMakeResultValue* inst)
{
- IRBuilder builderStorage(sharedBuilderStorage);
+ IRBuilder builderStorage(module);
auto builder = &builderStorage;
builder->setInsertBefore(inst);
@@ -144,7 +142,7 @@ namespace Slang
void processMakeResultError(IRMakeResultError* inst)
{
- IRBuilder builderStorage(sharedBuilderStorage);
+ IRBuilder builderStorage(module);
auto builder = &builderStorage;
builder->setInsertBefore(inst);
@@ -184,7 +182,7 @@ namespace Slang
void processGetResultError(IRGetResultError* inst)
{
- IRBuilder builderStorage(sharedBuilderStorage);
+ IRBuilder builderStorage(module);
auto builder = &builderStorage;
builder->setInsertBefore(inst);
@@ -196,7 +194,7 @@ namespace Slang
void processGetResultValue(IRGetResultValue* inst)
{
- IRBuilder builderStorage(sharedBuilderStorage);
+ IRBuilder builderStorage(module);
auto builder = &builderStorage;
builder->setInsertBefore(inst);
@@ -214,7 +212,7 @@ namespace Slang
void processIsResultError(IRIsResultError* inst)
{
- IRBuilder builderStorage(sharedBuilderStorage);
+ IRBuilder builderStorage(module);
auto builder = &builderStorage;
builder->setInsertBefore(inst);
@@ -233,7 +231,7 @@ namespace Slang
void processResultType(IRResultType* inst)
{
- IRBuilder builderStorage(sharedBuilderStorage);
+ IRBuilder builderStorage(module);
auto builder = &builderStorage;
builder->setInsertBefore(inst);
@@ -271,12 +269,6 @@ namespace Slang
void processModule()
{
- SharedIRBuilder* sharedBuilder = &sharedBuilderStorage;
- sharedBuilder->init(module);
-
- // Deduplicate equivalent types.
- sharedBuilder->deduplicateAndRebuildGlobalNumberingMap();
-
addToWorkList(module->getModuleInst());
while (workList.getCount() != 0)
diff --git a/source/slang/slang-ir-lower-tuple-types.cpp b/source/slang/slang-ir-lower-tuple-types.cpp
index 49a6a9045..bde7aea78 100644
--- a/source/slang/slang-ir-lower-tuple-types.cpp
+++ b/source/slang/slang-ir-lower-tuple-types.cpp
@@ -11,8 +11,6 @@ namespace Slang
IRModule* module;
DiagnosticSink* sink;
- SharedIRBuilder sharedBuilderStorage;
-
List<IRInst*> workList;
HashSet<IRInst*> workListSet;
@@ -85,7 +83,7 @@ namespace Slang
void processMakeTuple(IRMakeTuple* inst)
{
- IRBuilder builderStorage(sharedBuilderStorage);
+ IRBuilder builderStorage(module);
auto builder = &builderStorage;
builder->setInsertBefore(inst);
@@ -103,7 +101,7 @@ namespace Slang
void processGetTupleElement(IRGetTupleElement* inst)
{
- IRBuilder builderStorage(sharedBuilderStorage);
+ IRBuilder builderStorage(module);
auto builder = &builderStorage;
builder->setInsertBefore(inst);
@@ -121,7 +119,7 @@ namespace Slang
void processTupleType(IRTupleType* inst)
{
- IRBuilder builderStorage(sharedBuilderStorage);
+ IRBuilder builderStorage(module);
auto builder = &builderStorage;
builder->setInsertBefore(inst);
@@ -150,12 +148,6 @@ namespace Slang
void processModule()
{
- SharedIRBuilder* sharedBuilder = &sharedBuilderStorage;
- sharedBuilder->init(module);
-
- // Deduplicate equivalent types.
- sharedBuilder->deduplicateAndRebuildGlobalNumberingMap();
-
addToWorkList(module->getModuleInst());
while (workList.getCount() != 0)
diff --git a/source/slang/slang-ir-optix-entry-point-uniforms.cpp b/source/slang/slang-ir-optix-entry-point-uniforms.cpp
index 91aa30f47..ec46c3fde 100644
--- a/source/slang/slang-ir-optix-entry-point-uniforms.cpp
+++ b/source/slang/slang-ir-optix-entry-point-uniforms.cpp
@@ -79,7 +79,7 @@ struct CollectOptixEntryPointUniformParams : PerEntryPointPass {
// We will set up an IR builder so that we are ready to generate code.
//
- IRBuilder builderStorage(m_sharedBuilder);
+ IRBuilder builderStorage(m_module);
auto builder = &builderStorage;
// We will be removing any uniform parameters we run into, so we
@@ -234,7 +234,7 @@ struct CollectOptixEntryPointUniformParams : PerEntryPointPass {
if (paramStructType)
return;
- IRBuilder builder(m_sharedBuilder);
+ IRBuilder builder(m_module);
// First we create the structure to hold the parameters.
//
diff --git a/source/slang/slang-ir-peephole.cpp b/source/slang/slang-ir-peephole.cpp
index 87c31ffb7..5d5a41726 100644
--- a/source/slang/slang-ir-peephole.cpp
+++ b/source/slang/slang-ir-peephole.cpp
@@ -84,7 +84,7 @@ struct PeepholeContext : InstPassBase
}
else if (remainingKeys.getCount() > 0)
{
- IRBuilder builder(&sharedBuilderStorage);
+ IRBuilder builder(module);
builder.setInsertBefore(inst);
auto newValue = builder.emitElementExtract(updateInst->getElementValue(), remainingKeys);
inst->replaceUsesWith(newValue);
@@ -94,7 +94,7 @@ struct PeepholeContext : InstPassBase
}
else if (isAccessChainNotEqual)
{
- IRBuilder builder(&sharedBuilderStorage);
+ IRBuilder builder(module);
builder.setInsertBefore(inst);
auto newInst = builder.emitElementExtract(updateInst->getOldValue(), chainKey.getArrayView());
inst->replaceUsesWith(newInst);
@@ -189,7 +189,7 @@ struct PeepholeContext : InstPassBase
{
if (vectorType->getElementType() != replacement->getFullType())
return false;
- IRBuilder builder(sharedBuilderStorage);
+ IRBuilder builder(module);
builder.setInsertBefore(inst);
replacement = builder.emitMakeVectorFromScalar(inst->getFullType(), replacement);
}
@@ -319,14 +319,14 @@ struct PeepholeContext : InstPassBase
case kIROp_IsResultError:
if (inst->getOperand(0)->getOp() == kIROp_MakeResultError)
{
- IRBuilder builder(&sharedBuilderStorage);
+ IRBuilder builder(module);
inst->replaceUsesWith(builder.getBoolValue(true));
maybeRemoveOldInst(inst);
changed = true;
}
else if (inst->getOperand(0)->getOp() == kIROp_MakeResultValue)
{
- IRBuilder builder(&sharedBuilderStorage);
+ IRBuilder builder(module);
inst->replaceUsesWith(builder.getBoolValue(false));
maybeRemoveOldInst(inst);
changed = true;
@@ -432,7 +432,7 @@ struct PeepholeContext : InstPassBase
}
if (args.getCount() == arraySize->getValue())
{
- IRBuilder builder(&sharedBuilderStorage);
+ IRBuilder builder(module);
builder.setInsertBefore(inst);
auto makeArray = builder.emitMakeArray(arrayType, (UInt)args.getCount(), args.getBuffer());
inst->replaceUsesWith(makeArray);
@@ -471,7 +471,7 @@ struct PeepholeContext : InstPassBase
}
if (isValid)
{
- IRBuilder builder(&sharedBuilderStorage);
+ IRBuilder builder(module);
builder.setInsertBefore(inst);
auto makeStruct = builder.emitMakeStruct(structType, (UInt)args.getCount(), args.getBuffer());
inst->replaceUsesWith(makeStruct);
@@ -485,7 +485,7 @@ struct PeepholeContext : InstPassBase
case kIROp_CastPtrToBool:
{
auto ptr = inst->getOperand(0);
- IRBuilder builder(&sharedBuilderStorage);
+ IRBuilder builder(module);
builder.setInsertBefore(inst);
auto neq = builder.emitNeq(ptr, builder.getNullVoidPtrValue());
inst->replaceUsesWith(neq);
@@ -499,7 +499,7 @@ struct PeepholeContext : InstPassBase
auto actualType = isTypeInst->getValue()->getDataType();
if (isTypeEqual(actualType, (IRType*)isTypeInst->getTypeOperand()))
{
- IRBuilder builder(&sharedBuilderStorage);
+ IRBuilder builder(module);
builder.setInsertBefore(inst);
auto trueVal = builder.getBoolValue(true);
inst->replaceUsesWith(trueVal);
@@ -559,7 +559,7 @@ struct PeepholeContext : InstPassBase
{
if (inst->getOperand(0)->getOp() == kIROp_MakeOptionalValue)
{
- IRBuilder builder(&sharedBuilderStorage);
+ IRBuilder builder(module);
builder.setInsertBefore(inst);
auto trueVal = builder.getBoolValue(true);
inst->replaceUsesWith(trueVal);
@@ -568,7 +568,7 @@ struct PeepholeContext : InstPassBase
}
else if (inst->getOperand(0)->getOp() == kIROp_MakeOptionalNone)
{
- IRBuilder builder(&sharedBuilderStorage);
+ IRBuilder builder(module);
builder.setInsertBefore(inst);
auto falseVal = builder.getBoolValue(false);
inst->replaceUsesWith(falseVal);
@@ -622,7 +622,7 @@ struct PeepholeContext : InstPassBase
break;
case kIROp_DefaultConstruct:
{
- IRBuilder builder(&sharedBuilderStorage);
+ IRBuilder builder(module);
builder.setInsertBefore(inst);
// See if we can replace the default construct inst with concrete values.
if (auto newCtor = builder.emitDefaultConstruct(inst->getFullType(), false))
@@ -693,9 +693,6 @@ struct PeepholeContext : InstPassBase
bool processFunc(IRInst* func)
{
- SharedIRBuilder* sharedBuilder = &sharedBuilderStorage;
- sharedBuilder->init(module);
- sharedBuilderStorage.deduplicateAndRebuildGlobalNumberingMap();
bool result = false;
for (;;)
@@ -728,9 +725,9 @@ bool peepholeOptimize(IRInst* func)
return context.processFunc(func);
}
-bool tryReplaceInstUsesWithSimplifiedValue(SharedIRBuilder* sharedBuilder, IRInst* inst)
+bool tryReplaceInstUsesWithSimplifiedValue(IRModule* module, IRInst* inst)
{
- if (inst != tryConstantFoldInst(sharedBuilder, inst))
+ if (inst != tryConstantFoldInst(module, inst))
return true;
PeepholeContext context = PeepholeContext(inst->getModule());
diff --git a/source/slang/slang-ir-peephole.h b/source/slang/slang-ir-peephole.h
index 46ef9c80c..c0b83a715 100644
--- a/source/slang/slang-ir-peephole.h
+++ b/source/slang/slang-ir-peephole.h
@@ -6,10 +6,9 @@ namespace Slang
struct IRModule;
struct IRCall;
struct IRInst;
- struct SharedIRBuilder;
/// Apply peephole optimizations.
bool peepholeOptimize(IRModule* module);
bool peepholeOptimize(IRInst* func);
- bool tryReplaceInstUsesWithSimplifiedValue(SharedIRBuilder* sharedBuilder, IRInst* inst);
+ bool tryReplaceInstUsesWithSimplifiedValue(IRModule* module, IRInst* inst);
}
diff --git a/source/slang/slang-ir-remove-unused-generic-param.cpp b/source/slang/slang-ir-remove-unused-generic-param.cpp
index 9337a00bb..70b839db4 100644
--- a/source/slang/slang-ir-remove-unused-generic-param.cpp
+++ b/source/slang/slang-ir-remove-unused-generic-param.cpp
@@ -13,10 +13,7 @@ struct RemoveUnusedGenericParamContext : InstPassBase
bool processModule()
{
- SharedIRBuilder* sharedBuilder = &sharedBuilderStorage;
- sharedBuilder->init(module);
- sharedBuilderStorage.deduplicateAndRebuildGlobalNumberingMap();
- IRBuilder builder(sharedBuilder);
+ IRBuilder builder(module);
bool changed = false;
for (auto inst : module->getModuleInst()->getChildren())
{
diff --git a/source/slang/slang-ir-restructure-scoping.cpp b/source/slang/slang-ir-restructure-scoping.cpp
index dca1a92b6..17ed44162 100644
--- a/source/slang/slang-ir-restructure-scoping.cpp
+++ b/source/slang/slang-ir-restructure-scoping.cpp
@@ -254,9 +254,7 @@ static void fixValueScopingForInst(
//
IRModule* module = regionTree->irCode->getModule();
- SharedIRBuilder sharedBuilder(module);
-
- IRBuilder builder(sharedBuilder);
+ IRBuilder builder(module);
// Because we will be changing some of the uses of `def`
// to use other values while we iterate the list, we
diff --git a/source/slang/slang-ir-sccp.cpp b/source/slang/slang-ir-sccp.cpp
index e60d2576f..d05527e59 100644
--- a/source/slang/slang-ir-sccp.cpp
+++ b/source/slang/slang-ir-sccp.cpp
@@ -15,7 +15,6 @@ namespace Slang {
struct SharedSCCPContext
{
IRModule* module;
- SharedIRBuilder* sharedBuilder;
};
//
// Next we have a context struct that will be applied for each function (or other
@@ -1234,7 +1233,7 @@ struct SCCPContext
// Run the constant folding on global scope only.
bool applyOnGlobalScope(IRModule* module)
{
- builderStorage.init(shared->sharedBuilder);
+ builderStorage = IRBuilder(shared->module);
for (auto child : module->getModuleInst()->getChildren())
{
// Only consider evaluable opcodes.
@@ -1274,8 +1273,6 @@ struct SCCPContext
changed = true;
for (auto inst : instsToRemove)
inst->removeAndDeallocate();
- // Rebuild global value map.
- builderStorage.getSharedBuilder()->deduplicateAndRebuildGlobalNumberingMap();
}
return changed;
}
@@ -1287,7 +1284,7 @@ struct SCCPContext
bool changed = false;
// We start with the busy-work of setting up our IR builder.
//
- builderStorage.init(shared->sharedBuilder);
+ builderStorage = IRBuilder(shared->module);
// We expect the caller to have filtered out functions with
// no bodies, so there should always be at least one basic block.
@@ -1663,10 +1660,6 @@ bool applySparseConditionalConstantPropagation(
{
SharedSCCPContext shared;
shared.module = module;
- SharedIRBuilder sharedBuilderStorage;
- shared.sharedBuilder = &sharedBuilderStorage;
- sharedBuilderStorage.init(module);
- sharedBuilderStorage.deduplicateAndRebuildGlobalNumberingMap();
// First we fold constants at global scope.
SCCPContext globalContext;
@@ -1685,10 +1678,6 @@ bool applySparseConditionalConstantPropagation(IRInst* func)
{
SharedSCCPContext shared;
shared.module = func->getModule();
- SharedIRBuilder sharedBuilderStorage;
- shared.sharedBuilder = &sharedBuilderStorage;
- sharedBuilderStorage.init(shared.module);
- sharedBuilderStorage.deduplicateAndRebuildGlobalNumberingMap();
SCCPContext globalContext;
globalContext.shared = &shared;
@@ -1698,15 +1687,14 @@ bool applySparseConditionalConstantPropagation(IRInst* func)
return applySparseConditionalConstantPropagationRec(globalContext, func);
}
-IRInst* tryConstantFoldInst(SharedIRBuilder* sharedBuilder, IRInst* inst)
+IRInst* tryConstantFoldInst(IRModule* module, IRInst* inst)
{
SharedSCCPContext shared;
- shared.module = inst->getModule();
- shared.sharedBuilder = sharedBuilder;
+ shared.module = module;
SCCPContext instContext;
instContext.shared = &shared;
instContext.code = nullptr;
- instContext.builderStorage.init(sharedBuilder);
+ instContext.builderStorage = IRBuilder(module);
auto foldResult = instContext.interpretOverLattice(inst);
if (!foldResult.value)
{
diff --git a/source/slang/slang-ir-sccp.h b/source/slang/slang-ir-sccp.h
index 80b21fbbb..f97cbb366 100644
--- a/source/slang/slang-ir-sccp.h
+++ b/source/slang/slang-ir-sccp.h
@@ -5,7 +5,6 @@ namespace Slang
{
struct IRModule;
struct IRInst;
- struct SharedIRBuilder;
/// Apply Sparse Conditional Constant Propagation (SCCP) to a module.
///
@@ -20,6 +19,6 @@ namespace Slang
bool applySparseConditionalConstantPropagation(IRInst* func);
- IRInst* tryConstantFoldInst(SharedIRBuilder* sharedBuilder, IRInst* inst);
+ IRInst* tryConstantFoldInst(IRModule* module, IRInst* inst);
}
diff --git a/source/slang/slang-ir-simplify-cfg.cpp b/source/slang/slang-ir-simplify-cfg.cpp
index ed6ad9089..7e9e105e1 100644
--- a/source/slang/slang-ir-simplify-cfg.cpp
+++ b/source/slang/slang-ir-simplify-cfg.cpp
@@ -151,8 +151,7 @@ static bool processFunc(IRGlobalValueWithCode* func)
// Lazily generated region tree.
CFGSimplificationContext simplificationContext;
- SharedIRBuilder sharedBuilder(func->getModule());
- IRBuilder builder(&sharedBuilder);
+ IRBuilder builder(func->getModule());
bool changed = false;
for (;;)
diff --git a/source/slang/slang-ir-simplify-for-emit.cpp b/source/slang/slang-ir-simplify-for-emit.cpp
index 67d95c59f..a6f93f2f1 100644
--- a/source/slang/slang-ir-simplify-for-emit.cpp
+++ b/source/slang/slang-ir-simplify-for-emit.cpp
@@ -35,7 +35,7 @@ struct SimplifyForEmitContext : public InstPassBase
auto user = use->getUser();
if (auto store = as<IRStore>(user))
{
- IRBuilder builder(sharedBuilderStorage);
+ IRBuilder builder(module);
builder.setInsertBefore(user);
UInt i = 0;
for (auto field : structType->getFields())
@@ -68,7 +68,7 @@ struct SimplifyForEmitContext : public InstPassBase
auto user = use->getUser();
if (auto store = as<IRStore>(user))
{
- IRBuilder builder(sharedBuilderStorage);
+ IRBuilder builder(module);
builder.setInsertBefore(user);
for (UInt i = 0; i < makeArray->getOperandCount(); i++)
{
@@ -102,7 +102,7 @@ struct SimplifyForEmitContext : public InstPassBase
auto user = use->getUser();
if (auto store = as<IRStore>(user))
{
- IRBuilder builder(sharedBuilderStorage);
+ IRBuilder builder(module);
builder.setInsertBefore(user);
for (IRIntegerValue i = 0; i < arraySize->getValue(); i++)
{
@@ -135,7 +135,7 @@ struct SimplifyForEmitContext : public InstPassBase
}
// If we reach here, it is OK to defer the load at use site.
- IRBuilder builder(sharedBuilderStorage);
+ IRBuilder builder(module);
builder.setInsertBefore(user);
auto newLoad = builder.emitLoad(load->getPtr());
builder.replaceOperand(use, newLoad);
@@ -176,7 +176,7 @@ struct SimplifyForEmitContext : public InstPassBase
continue;
}
- IRBuilder builder(sharedBuilderStorage);
+ IRBuilder builder(module);
builder.setInsertBefore(user);
List<IRInst*> args;
for (UInt i = 0; i < inst->getOperandCount(); i++)
@@ -451,7 +451,6 @@ struct SimplifyForEmitContext : public InstPassBase
void processModule()
{
- sharedBuilderStorage.init(module);
processInstsOfType<IRFunc>(kIROp_Func, [this](IRFunc* f) { processFunc(f); });
}
};
diff --git a/source/slang/slang-ir-single-return.cpp b/source/slang/slang-ir-single-return.cpp
index 30e933133..10d8972bc 100644
--- a/source/slang/slang-ir-single-return.cpp
+++ b/source/slang/slang-ir-single-return.cpp
@@ -17,9 +17,7 @@ struct SingleReturnContext : public InstPassBase
{}
void processFunc(IRGlobalValueWithCode* func)
{
- SharedIRBuilder sharedBuilder;
- sharedBuilder.init(module);
- IRBuilder builder(&sharedBuilder);
+ IRBuilder builder(module);
simplifyCFG(func);
// We make use of the `eliminate-multi-level-break` pass to implement the transformation.
diff --git a/source/slang/slang-ir-specialize-dispatch.cpp b/source/slang/slang-ir-specialize-dispatch.cpp
index 9d557f196..4d9b15bbd 100644
--- a/source/slang/slang-ir-specialize-dispatch.cpp
+++ b/source/slang/slang-ir-specialize-dispatch.cpp
@@ -41,7 +41,7 @@ IRFunc* specializeDispatchFunction(SharedGenericsLoweringContext* sharedContext,
}
SLANG_ASSERT(callInst && lookupInst && returnInst);
- IRBuilder builderStorage(sharedContext->sharedBuilderStorage);
+ IRBuilder builderStorage(sharedContext->module);
auto builder = &builderStorage;
builder->setInsertBefore(dispatchFunc);
@@ -287,7 +287,7 @@ void ensureWitnessTableSequentialIDs(SharedGenericsLoweringContext* sharedContex
}
// Add a decoration to the inst.
- IRBuilder builder(sharedContext->sharedBuilderStorage);
+ IRBuilder builder(sharedContext->module);
builder.setInsertBefore(inst);
builder.addSequentialIDDecoration(inst, seqID);
}
@@ -309,7 +309,7 @@ void fixupDispatchFuncCall(SharedGenericsLoweringContext* sharedContext, IRFunc*
{
if (call->getCallee() != newDispatchFunc)
continue;
- IRBuilder builder(sharedContext->sharedBuilderStorage);
+ IRBuilder builder(sharedContext->module);
builder.setInsertBefore(call);
List<IRInst*> args;
for (UInt i = 0; i < call->getArgCount(); i++)
@@ -327,8 +327,6 @@ void fixupDispatchFuncCall(SharedGenericsLoweringContext* sharedContext, IRFunc*
void specializeDispatchFunctions(SharedGenericsLoweringContext* sharedContext)
{
- sharedContext->sharedBuilderStorage.deduplicateAndRebuildGlobalNumberingMap();
-
// First we ensure that all witness table objects has a sequential ID assigned.
ensureWitnessTableSequentialIDs(sharedContext);
diff --git a/source/slang/slang-ir-specialize-dynamic-associatedtype-lookup.cpp b/source/slang/slang-ir-specialize-dynamic-associatedtype-lookup.cpp
index cfc9d9c76..e68ac5b73 100644
--- a/source/slang/slang-ir-specialize-dynamic-associatedtype-lookup.cpp
+++ b/source/slang/slang-ir-specialize-dynamic-associatedtype-lookup.cpp
@@ -14,7 +14,7 @@ struct AssociatedTypeLookupSpecializationContext
IRFunc* createWitnessTableLookupFunc(IRInterfaceType* interfaceType, IRInst* key)
{
- IRBuilder builder(sharedContext->sharedBuilderStorage);
+ IRBuilder builder(sharedContext->module);
builder.setInsertBefore(interfaceType);
auto inputWitnessTableIDType = builder.getWitnessTableIDType(interfaceType);
@@ -128,7 +128,7 @@ struct AssociatedTypeLookupSpecializationContext
// Ignore lookups for RTTI objects for now, since they are not used anywhere.
if (!as<IRWitnessTableType>(inst->getDataType()))
{
- IRBuilder builder(sharedContext->sharedBuilderStorage);
+ IRBuilder builder(sharedContext->module);
builder.setInsertBefore(inst);
auto uint2Type = builder.getVectorType(
builder.getUIntType(), builder.getIntValue(builder.getIntType(), 2));
@@ -154,7 +154,7 @@ struct AssociatedTypeLookupSpecializationContext
func = createWitnessTableLookupFunc(interfaceType, key);
sharedContext->mapInterfaceRequirementKeyToDispatchMethods[key] = func;
}
- IRBuilder builder(sharedContext->sharedBuilderStorage);
+ IRBuilder builder(sharedContext->module);
builder.setInsertBefore(inst);
auto witnessTableArg = inst->getWitnessTable();
if (witnessTableArg->getDataType()->getOp() == kIROp_WitnessTableType)
@@ -172,7 +172,7 @@ struct AssociatedTypeLookupSpecializationContext
// If the operand is a witness table, it is already replaced with a uint2
// at this point, where the first element in the uint2 is the id of the
// witness table.
- IRBuilder builder(sharedContext->sharedBuilderStorage);
+ IRBuilder builder(sharedContext->module);
builder.setInsertBefore(inst);
UInt index = 0;
auto id = builder.emitSwizzle(builder.getUIntType(), inst->getRTTIOperand(), 1, &index);
@@ -206,7 +206,7 @@ struct AssociatedTypeLookupSpecializationContext
{
return;
}
- IRBuilder builder(sharedContext->sharedBuilderStorage);
+ IRBuilder builder(sharedContext->module);
builder.setInsertBefore(use->getUser());
auto uint2Type = builder.getVectorType(
builder.getUIntType(), builder.getIntValue(builder.getIntType(), 2));
@@ -224,7 +224,7 @@ struct AssociatedTypeLookupSpecializationContext
{
if (globalInst->getOp() == kIROp_WitnessTableType)
{
- IRBuilder builder(sharedContext->sharedBuilderStorage);
+ IRBuilder builder(sharedContext->module);
builder.setInsertBefore(globalInst);
auto witnessTableIDType = builder.getWitnessTableIDType(
(IRType*)cast<IRWitnessTableType>(globalInst)->getConformanceType());
@@ -234,7 +234,6 @@ struct AssociatedTypeLookupSpecializationContext
return;
builder.replaceOperand(use, witnessTableIDType);
});
- sharedContext->sharedBuilderStorage.deduplicateAndRebuildGlobalNumberingMap();
}
}
diff --git a/source/slang/slang-ir-specialize-function-call.cpp b/source/slang/slang-ir-specialize-function-call.cpp
index ecbdf9008..894d46cce 100644
--- a/source/slang/slang-ir-specialize-function-call.cpp
+++ b/source/slang/slang-ir-specialize-function-call.cpp
@@ -89,11 +89,6 @@ struct FunctionParameterSpecializationContext
//
List<IRCall*> workList;
- // Because we may need to generate specialized functions
- // and generate new calls to those functions, we'll
- // need some IR building state to get our work done.
- //
- SharedIRBuilder sharedBuilderStorage;
IRBuilder builderStorage;
IRBuilder* getBuilder() { return &builderStorage; }
@@ -104,8 +99,7 @@ struct FunctionParameterSpecializationContext
{
// We will start by initializing our IR building state.
//
- sharedBuilderStorage.init(module);
- builderStorage.init(sharedBuilderStorage);
+ builderStorage = IRBuilder(module);
// Next we will populate our initial work list by
// recursively finding every single call site in the module.
@@ -798,7 +792,7 @@ struct FunctionParameterSpecializationContext
//
cloneInstDecorationsAndChildren(
&cloneEnv,
- builder->getSharedBuilder(),
+ builder->getModule(),
oldFunc,
newFunc);
diff --git a/source/slang/slang-ir-specialize-resources.cpp b/source/slang/slang-ir-specialize-resources.cpp
index 03eda0d99..83f280d9b 100644
--- a/source/slang/slang-ir-specialize-resources.cpp
+++ b/source/slang/slang-ir-specialize-resources.cpp
@@ -115,9 +115,6 @@ struct ResourceOutputSpecializationPass
TargetRequest* targetRequest;
IRModule* module;
- SharedIRBuilder sharedBuilder;
- SharedIRBuilder* getSharedBuilder() { return &sharedBuilder; }
-
// Functions that requires specialization but are currently unspecializable.
List<IRFunc*>* unspecializableFuncs;
@@ -125,10 +122,6 @@ struct ResourceOutputSpecializationPass
{
bool changed = false;
- // We start by setting up the shared IR building state.
- //
- sharedBuilder.init(module);
-
// The main logic consists of iterating over all functions
// (which must appear at the global level) and specializing
// them if needed.
@@ -173,7 +166,7 @@ struct ResourceOutputSpecializationPass
// We start the specialization process by making a clone of the
// original function.
//
- IRBuilder builder(&sharedBuilder);
+ IRBuilder builder(module);
builder.setInsertBefore(oldFunc);
IRFunc* newFunc = builder.createFunc();
newFunc->setFullType(oldFunc->getFullType());
@@ -181,7 +174,7 @@ struct ResourceOutputSpecializationPass
IRCloneEnv cloneEnv;
cloneInstDecorationsAndChildren(
&cloneEnv,
- &sharedBuilder,
+ module,
oldFunc,
newFunc);
@@ -560,7 +553,7 @@ struct ResourceOutputSpecializationPass
auto value = returnInst->getVal();
- IRBuilder builder(getSharedBuilder());
+ IRBuilder builder(module);
builder.setInsertBefore(returnInst);
// Given the `value` being returned, we need to determine
@@ -750,14 +743,14 @@ struct ResourceOutputSpecializationPass
// replacements, and we want any replacements to end up
// at the same point in the function signature.
//
- IRBuilder paramsBuilder(getSharedBuilder());
+ IRBuilder paramsBuilder(module);
paramsBuilder.setInsertBefore(param);
// We also need to introduce new instructions into the function
// body, as part of the entry block.
//
IRBlock* block = as<IRBlock>(param->getParent());
- IRBuilder bodyBuilder(getSharedBuilder());
+ IRBuilder bodyBuilder(module);
bodyBuilder.setInsertBefore(block->getFirstOrdinaryInst());
// No matter what, we create a local variable that will be
@@ -882,7 +875,7 @@ struct ResourceOutputSpecializationPass
// Given an existing call, we will insert a new call right before
// it and then remove the old one.
//
- IRBuilder builder(getSharedBuilder());
+ IRBuilder builder(module);
builder.setInsertBefore(oldCall);
// The new callee may have additional `out` parameters that
diff --git a/source/slang/slang-ir-specialize.cpp b/source/slang/slang-ir-specialize.cpp
index 0044e5745..050c9bfc7 100644
--- a/source/slang/slang-ir-specialize.cpp
+++ b/source/slang/slang-ir-specialize.cpp
@@ -204,10 +204,6 @@ struct SpecializationContext
typedef IRSimpleSpecializationKey Key;
Dictionary<Key, IRInst*> genericSpecializations;
- // We will also use some shared IR building state across
- // all of our specialization/cloning steps.
- //
- SharedIRBuilder sharedBuilderStorage;
// Now let's look at the task of finding or generation a
// specialization of some generic `g`, given a specialization
@@ -418,7 +414,7 @@ struct SpecializationContext
for (UIndex ii = 0; ii < argCount; ii++)
args.add(specInst->getArg(ii));
- IRBuilder builder(&sharedBuilderStorage);
+ IRBuilder builder(module);
// Specialize the custom derivative function type with the original arguments.
builder.setInsertInto(module);
@@ -782,7 +778,7 @@ struct SpecializationContext
template<typename TDict>
void _writeSpecializationDictionaryImpl(TDict& dict, IROp dictOp, IRInst* moduleInst)
{
- IRBuilder builder(&sharedBuilderStorage);
+ IRBuilder builder(moduleInst);
builder.setInsertInto(moduleInst);
auto dictInst = builder.emitIntrinsicInst(nullptr, dictOp, 0, nullptr);
builder.setInsertInto(dictInst);
@@ -817,18 +813,10 @@ struct SpecializationContext
//
void processModule()
{
- // We start by initializing our shared IR building state,
- // since we will re-use that state for any code we
- // generate along the way.
- //
- SharedIRBuilder* sharedBuilder = &sharedBuilderStorage;
- sharedBuilder->init(module);
-
// Read specialization dictionary from module if it is defined.
// This prevents us from generating duplicated specializations
// when this pass is invoked iteratively.
readSpecializationDictionaries();
- sharedBuilder->deduplicateAndRebuildGlobalNumberingMap();
// The unspecialized IR we receive as input will have
// `IRBindGlobalGenericParam` instructions that associate
@@ -996,7 +984,7 @@ struct SpecializationContext
{
auto oldSpecialize = cast<IRSpecialize>(oldSpecializedCallee);
SLANG_ASSERT(oldSpecialize->getArgCount() == 1);
- IRBuilder builder(sharedBuilderStorage);
+ IRBuilder builder(module);
builder.setInsertBefore(oldSpecializedCallee);
auto calleeType = builder.getFuncType(1, &newContainerType, newElementType);
auto newSpecialize = builder.emitSpecializeInst(
@@ -1026,7 +1014,7 @@ struct SpecializationContext
auto resultType = inst->getFullType();
auto elementType = sbType->getElementType();
- IRBuilder builder(sharedBuilderStorage);
+ IRBuilder builder(module);
builder.setInsertBefore(inst);
List<IRInst*> args;
@@ -1262,7 +1250,7 @@ struct SpecializationContext
// Now that we've built up our argument list, it is simple enough
// to construct a new `call` instruction.
//
- IRBuilder builderStorage(sharedBuilderStorage);
+ IRBuilder builderStorage(module);
auto builder = &builderStorage;
builder->setInsertBefore(inst);
@@ -1421,7 +1409,7 @@ struct SpecializationContext
// We also need some IR building state, for any
// new instructions we will emit.
//
- IRBuilder builderStorage(sharedBuilderStorage);
+ IRBuilder builderStorage(module);
auto builder = &builderStorage;
// We will start out by determining what the parameters
@@ -1561,7 +1549,7 @@ struct SpecializationContext
//
cloneInstDecorationsAndChildren(
&cloneEnv,
- builder->getSharedBuilder(),
+ builder->getModule(),
oldFunc,
newFunc);
@@ -1740,7 +1728,7 @@ struct SpecializationContext
//
auto resultType = inst->getFullType();
- IRBuilder builder(sharedBuilderStorage);
+ IRBuilder builder(module);
builder.setInsertBefore(inst);
// We'd *like* to replace this instruction with
@@ -1844,7 +1832,7 @@ struct SpecializationContext
//
auto resultType = inst->getFullType();
- IRBuilder builder(sharedBuilderStorage);
+ IRBuilder builder(module);
builder.setInsertBefore(inst);
// We'd *like* to replace this instruction with
@@ -1931,7 +1919,7 @@ struct SpecializationContext
//
auto resultType = inst->getFullType();
- IRBuilder builder(sharedBuilderStorage);
+ IRBuilder builder(module);
builder.setInsertBefore(inst);
// We'd *like* to replace this instruction with
@@ -2018,7 +2006,7 @@ struct SpecializationContext
auto val = wrapInst->getWrappedValue();
auto resultType = inst->getFullType();
- IRBuilder builder(sharedBuilderStorage);
+ IRBuilder builder(module);
builder.setInsertBefore(inst);
auto elementType = cast<IRArrayTypeBase>(val->getDataType())->getElementType();
@@ -2061,7 +2049,7 @@ struct SpecializationContext
auto resultType = inst->getFullType();
- IRBuilder builder(sharedBuilderStorage);
+ IRBuilder builder(module);
builder.setInsertBefore(inst);
List<IRInst*> slotOperands;
@@ -2135,7 +2123,7 @@ struct SpecializationContext
auto baseType = type->getBaseType();
UInt slotOperandCount = type->getExistentialArgCount();
- IRBuilder builder(sharedBuilderStorage);
+ IRBuilder builder(module);
builder.setInsertBefore(type);
if( auto baseInterfaceType = as<IRInterfaceType>(baseType) )
@@ -2405,8 +2393,7 @@ IRInst* specializeGenericImpl(
// into the global scope, at the same location
// as the original generic.
//
- SharedIRBuilder sharedBuilderStorage(module);
- IRBuilder builderStorage(sharedBuilderStorage);
+ IRBuilder builderStorage(module);
IRBuilder* builder = &builderStorage;
builder->setInsertBefore(genericVal);
@@ -2440,7 +2427,7 @@ IRInst* specializeGenericImpl(
// Clone decorations on the orignal `specialize` inst over to the newly specialized
// value.
cloneInstDecorationsAndChildren(
- &env, &sharedBuilderStorage, specializeInst, specializedVal);
+ &env, module, specializeInst, specializedVal);
return specializedVal;
}
diff --git a/source/slang/slang-ir-spirv-legalize.cpp b/source/slang/slang-ir-spirv-legalize.cpp
index b92f2ca9f..f3971743f 100644
--- a/source/slang/slang-ir-spirv-legalize.cpp
+++ b/source/slang/slang-ir-spirv-legalize.cpp
@@ -70,7 +70,7 @@ struct SPIRVLegalizationContext : public SourceEmitterBase
}
}
// Make a pointer type of storageClass.
- IRBuilder builder(m_sharedContext->m_sharedIRBuilder);
+ IRBuilder builder(m_sharedContext->m_irModule);
builder.setInsertBefore(inst);
ptrType = builder.getPtrType(kIROp_PtrType, inst->getFullType(), storageClass);
inst->setFullType(ptrType);
@@ -140,7 +140,7 @@ struct SPIRVLegalizationContext : public SourceEmitterBase
{
storageClass = SpvStorageClassWorkgroup;
}
- IRBuilder builder(m_sharedContext->m_sharedIRBuilder);
+ IRBuilder builder(m_sharedContext->m_irModule);
builder.setInsertBefore(inst);
auto newPtrType =
builder.getPtrType(oldPtrType->getOp(), oldPtrType->getValueType(), storageClass);
@@ -163,7 +163,7 @@ struct SPIRVLegalizationContext : public SourceEmitterBase
auto ptrType = as<IRPtrTypeBase>(inst->getDataType());
if (!ptrType)
return;
- IRBuilder builder(m_sharedContext->m_sharedIRBuilder);
+ IRBuilder builder(m_sharedContext->m_irModule);
builder.setInsertBefore(inst);
auto qualPtrType = builder.getPtrType(
ptrType->getOp(), ptrType->getValueType(), snippet->resultStorageClass);
@@ -187,7 +187,7 @@ struct SPIRVLegalizationContext : public SourceEmitterBase
auto oldResultType = as<IRPtrTypeBase>(inst->getDataType());
if (oldResultType->getAddressSpace() != ptrType->getAddressSpace())
{
- IRBuilder builder(m_sharedContext->m_sharedIRBuilder);
+ IRBuilder builder(m_sharedContext->m_irModule);
builder.setInsertBefore(inst);
auto newPtrType = builder.getPtrType(
oldResultType->getOp(),
@@ -211,7 +211,7 @@ struct SPIRVLegalizationContext : public SourceEmitterBase
auto oldResultType = as<IRPtrTypeBase>(inst->getDataType());
if (oldResultType->getAddressSpace() != ptrType->getAddressSpace())
{
- IRBuilder builder(m_sharedContext->m_sharedIRBuilder);
+ IRBuilder builder(m_sharedContext->m_irModule);
builder.setInsertBefore(inst);
auto newPtrType = builder.getPtrType(
oldResultType->getOp(),
@@ -228,7 +228,7 @@ struct SPIRVLegalizationContext : public SourceEmitterBase
void processStructuredBufferType(IRHLSLStructuredBufferTypeBase* inst)
{
- IRBuilder builder(m_sharedContext->m_sharedIRBuilder);
+ IRBuilder builder(m_sharedContext->m_irModule);
builder.setInsertBefore(inst);
auto arrayType = builder.getUnsizedArrayType(inst->getElementType());
auto structType = builder.createStructType();
diff --git a/source/slang/slang-ir-spirv-legalize.h b/source/slang/slang-ir-spirv-legalize.h
index 499c2bff1..fbde7b780 100644
--- a/source/slang/slang-ir-spirv-legalize.h
+++ b/source/slang/slang-ir-spirv-legalize.h
@@ -15,13 +15,11 @@ class TargetRequest;
struct SPIRVEmitSharedContext
{
- SharedIRBuilder m_sharedIRBuilder;
- Dictionary<IRTargetIntrinsicDecoration*, RefPtr<SpvSnippet>> m_parsedSpvSnippets;
+ IRModule* m_irModule;
TargetRequest* m_targetRequest;
-
+ Dictionary<IRTargetIntrinsicDecoration*, RefPtr<SpvSnippet>> m_parsedSpvSnippets;
SPIRVEmitSharedContext(IRModule* module, TargetRequest* target)
- : m_sharedIRBuilder(module)
- , m_targetRequest(target)
+ : m_irModule(module), m_targetRequest(target)
{}
SpvSnippet* getParsedSpvSnippet(IRTargetIntrinsicDecoration* intrinsic)
diff --git a/source/slang/slang-ir-ssa.cpp b/source/slang/slang-ir-ssa.cpp
index b195af2cc..d8246edae 100644
--- a/source/slang/slang-ir-ssa.cpp
+++ b/source/slang/slang-ir-ssa.cpp
@@ -83,8 +83,7 @@ struct ConstructSSAContext
// Information about each basic block
Dictionary<IRBlock*, RefPtr<SSABlockInfo>> blockInfos;
- // IR building state to use during the operation
- SharedIRBuilder* sharedBuilder;
+ IRModule* module;
// Instructions to remove during cleanup
List<IRInst*> instsToRemove;
@@ -923,23 +922,15 @@ IRBlock* IREdge::getSuccessor() const
return cast<IRBlock>(getUse()->get());
}
-void SharedIRBuilder::init(IRModule* module)
-{
- m_module = module;
- m_session = module->getSession();
-
- m_globalValueNumberingMap.Clear();
- m_constantMap.Clear();
-}
-
-void SharedIRBuilder::insertBlockAlongEdge(
+void IRBuilder::insertBlockAlongEdge(
+ IRModule* module,
IREdge const& edge)
{
auto pred = edge.getPredecessor();
auto succ = edge.getSuccessor();
auto edgeUse = edge.getUse();
- IRBuilder builder(this);
+ IRBuilder builder(module);
builder.setInsertInto(pred);
// Create a new block that will sit "along" the edge
@@ -1052,7 +1043,7 @@ static void breakCriticalEdges(
for (auto edge : criticalEdges)
{
- context->sharedBuilder->insertBlockAlongEdge(edge);
+ IRBuilder::insertBlockAlongEdge(context->module, edge);
}
}
@@ -1082,7 +1073,7 @@ bool constructSSA(ConstructSSAContext* context)
auto blockInfo = new SSABlockInfo();
blockInfo->block = bb;
- blockInfo->builder.init(context->sharedBuilder);
+ blockInfo->builder = IRBuilder(context->module);
blockInfo->builder.setInsertBefore(bb->getLastInst());
context->blockInfos.Add(bb, blockInfo);
@@ -1208,34 +1199,16 @@ bool constructSSA(ConstructSSAContext* context)
return true;
}
-// Construct SSA form for a global value with code
-bool constructSSA(IRModule* module, IRGlobalValueWithCode* globalVal)
-{
- ConstructSSAContext context;
- context.globalVal = globalVal;
-
- SharedIRBuilder sharedBuilder(module);
- context.sharedBuilder = &sharedBuilder;
-
- context.builder.init(context.sharedBuilder);
- context.builder.setInsertInto(module);
-
- return constructSSA(&context);
-}
-
// Construct SSA form for a global value with code and reuse
// an existing sharedBuilder
//
-bool constructSSA(SharedIRBuilder* sharedBuilder, IRGlobalValueWithCode* globalVal)
+bool constructSSA(IRModule* module, IRGlobalValueWithCode* globalVal)
{
ConstructSSAContext context;
context.globalVal = globalVal;
-
- context.sharedBuilder = sharedBuilder;
-
- context.builder.init(sharedBuilder);
- context.builder.setInsertInto(sharedBuilder->getModule());
-
+ context.module = module;
+ context.builder = IRBuilder(module);
+ context.builder.setInsertInto(module);
return constructSSA(&context);
}
diff --git a/source/slang/slang-ir-ssa.h b/source/slang/slang-ir-ssa.h
index 02c9c4831..89b01614f 100644
--- a/source/slang/slang-ir-ssa.h
+++ b/source/slang/slang-ir-ssa.h
@@ -6,9 +6,8 @@ namespace Slang
struct IRModule;
struct IRGlobalValueWithCode;
struct IRInst;
- struct SharedIRBuilder;
+
bool constructSSA(IRModule* module, IRGlobalValueWithCode* globalVal);
- bool constructSSA(SharedIRBuilder* sharedBuilder, IRGlobalValueWithCode* globalVal);
bool constructSSA(IRModule* module);
bool constructSSA(IRInst* globalVal);
}
diff --git a/source/slang/slang-ir-string-hash.cpp b/source/slang/slang-ir-string-hash.cpp
index 8bccb97db..b7e37d21e 100644
--- a/source/slang/slang-ir-string-hash.cpp
+++ b/source/slang/slang-ir-string-hash.cpp
@@ -41,7 +41,7 @@ void findGlobalHashedStringLiterals(IRModule* module, StringSlicePool& pool)
}
}
-void addGlobalHashedStringLiterals(const StringSlicePool& pool, SharedIRBuilder& sharedBuilder)
+void addGlobalHashedStringLiterals(const StringSlicePool& pool, IRModule* module)
{
auto slices = pool.getAdded();
if (slices.getCount() == 0)
@@ -49,11 +49,8 @@ void addGlobalHashedStringLiterals(const StringSlicePool& pool, SharedIRBuilder&
return;
}
- IRBuilder builder(sharedBuilder);
+ IRBuilder builder(module);
- //
- IRModule* module = builder.getModule();
-
// We need to add a global instruction that references all of these string literals
builder.setInsertInto(module->getModuleInst());
diff --git a/source/slang/slang-ir-string-hash.h b/source/slang/slang-ir-string-hash.h
index aa724fa5c..6a4537290 100644
--- a/source/slang/slang-ir-string-hash.h
+++ b/source/slang/slang-ir-string-hash.h
@@ -9,8 +9,6 @@ namespace Slang
{
struct IRModule;
-struct SharedIRBuilder;
-
class DiagnosticSink;
// Finds the global GlobalHashedStringLiterals instruction for the module if there is one, and then
@@ -18,7 +16,7 @@ class DiagnosticSink;
void findGlobalHashedStringLiterals(IRModule* module, StringSlicePool& ioPool);
// Given a pool, with > 0 strings adds a GlobalHashedStringLiterals to the module.
-void addGlobalHashedStringLiterals(const StringSlicePool& pool, SharedIRBuilder& sharedBuilder);
+void addGlobalHashedStringLiterals(const StringSlicePool& pool, IRModule* module);
// Find all of the IRGetStringHash instructions within the module
void findGetStringHashInsts(IRModule* module, List<IRGetStringHash*>& outInsts);
diff --git a/source/slang/slang-ir-synthesize-active-mask.cpp b/source/slang/slang-ir-synthesize-active-mask.cpp
index 70d3b6180..39adb7e81 100644
--- a/source/slang/slang-ir-synthesize-active-mask.cpp
+++ b/source/slang/slang-ir-synthesize-active-mask.cpp
@@ -101,11 +101,6 @@ struct SynthesizeActiveMaskForModuleContext
IRModule* m_module;
DiagnosticSink* m_sink;
- // We use a single shared IR builder for the entire pass, to
- // make sure we deduplicate types/values as much as possible.
- //
- SharedIRBuilder m_sharedBuilder;
-
// Because we are introducing explicit masks, it is important
// for all the code to agree on the type of mask that will be
// used.
@@ -114,11 +109,6 @@ struct SynthesizeActiveMaskForModuleContext
void processModule()
{
- // When asked to process an IR module, our pass first
- // sets up the shared state.
- //
- m_sharedBuilder.init(m_module);
-
// We use the plain 32-bit `uint` type masks we
// generate here since it matches the current
// definition of `WaveMask` in the standard library.
@@ -128,7 +118,7 @@ struct SynthesizeActiveMaskForModuleContext
// so that the pass is compatible with all targets that
// support a wave mask.
//
- IRBuilder builder(m_sharedBuilder);
+ IRBuilder builder(m_module);
m_maskType = builder.getBasicType(BaseType::UInt);
// With the setup out of the way, the job of the module
@@ -329,7 +319,7 @@ struct SynthesizeActiveMaskForModuleContext
// mask = waveGetActiveMask();
// callee(arg0, arg1, arg2, ..., m);
//
- IRBuilder builder(m_sharedBuilder);
+ IRBuilder builder(m_module);
builder.setInsertBefore(call);
// First we synthesize the mask to pass down by
@@ -399,10 +389,7 @@ struct SynthesizeActiveMaskForFunctionContext
//
IRFunc* m_func;
- // Some of the state used for building up mask operations is
- // passed down form the module-level pass.
- //
- SharedIRBuilder* m_sharedBuilder;
+ IRModule* m_module;
IRType* m_maskType;
void transformFunc()
@@ -533,7 +520,7 @@ struct SynthesizeActiveMaskForFunctionContext
//
for( auto& edge : edgesToBreak )
{
- m_sharedBuilder->insertBlockAlongEdge(edge);
+ IRBuilder::insertBlockAlongEdge(m_module, edge);
}
}
@@ -731,7 +718,7 @@ struct SynthesizeActiveMaskForFunctionContext
//
// We will insert the code we generate at the start of the entry block.
//
- IRBuilder builder(m_sharedBuilder);
+ IRBuilder builder(m_module);
builder.setInsertBefore(funcEntryBlock->getFirstOrdinaryInst());
//
// A naive approach would be to set the active mask to an all-ones
@@ -829,7 +816,7 @@ struct SynthesizeActiveMaskForFunctionContext
//
SLANG_ASSERT(doesBlockNeedActiveMask(block));
- IRBuilder builder(m_sharedBuilder);
+ IRBuilder builder(m_module);
builder.setInsertBefore(block->getFirstOrdinaryInst());
auto activeMaskParam = builder.emitParam(m_maskType);
@@ -1220,7 +1207,7 @@ struct SynthesizeActiveMaskForFunctionContext
// code can take responsibility for computing the mask
// value to use for both `trueBlock` and `falseBlock`.
//
- IRBuilder builder(m_sharedBuilder);
+ IRBuilder builder(m_module);
// To establish the mask value for `trueBlock` we will
// insert a `waveMaskBallot` before the branch:
@@ -1452,7 +1439,7 @@ struct SynthesizeActiveMaskForFunctionContext
// Next, we need to establish a mask value that will
// represent the active mask on entry to a given `case`.
//
- IRBuilder builder(m_sharedBuilder);
+ IRBuilder builder(m_module);
builder.setInsertBefore(switchInst);
// For now we are computing a simple-but-inaccurate version
@@ -1685,7 +1672,7 @@ struct SynthesizeActiveMaskForFunctionContext
//
void transformUnconditionalEdge(RegionInfo* fromRegion, IRTerminatorInst* terminator, IRBlock* toBlock, IRInst* fromActiveMask)
{
- IRBuilder builder(m_sharedBuilder);
+ IRBuilder builder(m_module);
builder.setInsertBefore(terminator);
// The context here is that the `terminator` instruction,
@@ -2078,7 +2065,7 @@ void SynthesizeActiveMaskForModuleContext::transformFuncUsingActiveMask(IRFunc*
{
SynthesizeActiveMaskForFunctionContext context;
context.m_func = func;
- context.m_sharedBuilder = &m_sharedBuilder;
+ context.m_module = m_module;
context.m_maskType = m_maskType;
context.transformFunc();
diff --git a/source/slang/slang-ir-type-set.cpp b/source/slang/slang-ir-type-set.cpp
deleted file mode 100644
index 7ac617bda..000000000
--- a/source/slang/slang-ir-type-set.cpp
+++ /dev/null
@@ -1,10 +0,0 @@
-// slang-ir-type-set.cpp
-#include "slang-ir-type-set.h"
-
-#include "slang-ir.h"
-#include "slang-ir-insts.h"
-
-namespace Slang
-{
-
-}
diff --git a/source/slang/slang-ir-type-set.h b/source/slang/slang-ir-type-set.h
deleted file mode 100644
index f60088fcd..000000000
--- a/source/slang/slang-ir-type-set.h
+++ /dev/null
@@ -1,12 +0,0 @@
-// slang-ir-type-set.h
-#pragma once
-
-#include "slang-ir.h"
-#include "slang-ir-insts.h"
-
-#include "../core/slang-string-slice-pool.h"
-
-namespace Slang
-{
-
-} // namespace Slang
diff --git a/source/slang/slang-ir-union.cpp b/source/slang/slang-ir-union.cpp
index 7a7271f23..3d0ed1fe8 100644
--- a/source/slang/slang-ir-union.cpp
+++ b/source/slang/slang-ir-union.cpp
@@ -20,7 +20,6 @@ struct DesugarUnionTypesContext
// state that we will initialize once and then use throughout the pass.
//
IRModule* module;
- SharedIRBuilder sharedBuilderStorage;
IRBuilder builderStorage;
IRBuilder* getBuilder() { return &builderStorage; }
@@ -39,8 +38,7 @@ struct DesugarUnionTypesContext
{
// We start by initializing our IR building state.
//
- sharedBuilderStorage.init(module);
- builderStorage.init(sharedBuilderStorage);
+ builderStorage = IRBuilder(module);
// Next, we will search for any instruction that create or use
// union types, and process them accordingingly (usually by
diff --git a/source/slang/slang-ir-witness-table-wrapper.cpp b/source/slang/slang-ir-witness-table-wrapper.cpp
index 81527b89f..d8bfdc560 100644
--- a/source/slang/slang-ir-witness-table-wrapper.cpp
+++ b/source/slang/slang-ir-witness-table-wrapper.cpp
@@ -80,7 +80,7 @@ namespace Slang
IRStringLit* _getWitnessTableWrapperFuncName(IRFunc* func)
{
- IRBuilder builderStorage(sharedContext->sharedBuilderStorage);
+ IRBuilder builderStorage(sharedContext->module);
auto builder = &builderStorage;
builder->setInsertBefore(func);
if (auto linkageDecoration = func->findDecoration<IRLinkageDecoration>())
@@ -98,7 +98,7 @@ namespace Slang
{
auto funcTypeInInterface = cast<IRFuncType>(interfaceRequirementVal);
- IRBuilder builderStorage(sharedContext->sharedBuilderStorage);
+ IRBuilder builderStorage(sharedContext->module);
auto builder = &builderStorage;
builder->setInsertBefore(func);
@@ -219,13 +219,6 @@ namespace Slang
void processModule()
{
- // We start by initializing our shared IR building state,
- // since we will re-use that state for any code we
- // generate along the way.
- //
- SharedIRBuilder* sharedBuilder = &sharedContext->sharedBuilderStorage;
- sharedBuilder->init(sharedContext->module);
-
sharedContext->addToWorkList(sharedContext->module->getModuleInst());
while (sharedContext->workList.getCount() != 0)
diff --git a/source/slang/slang-ir-wrap-structured-buffers.cpp b/source/slang/slang-ir-wrap-structured-buffers.cpp
index 53671fa7f..0e7248320 100644
--- a/source/slang/slang-ir-wrap-structured-buffers.cpp
+++ b/source/slang/slang-ir-wrap-structured-buffers.cpp
@@ -83,9 +83,7 @@ struct WrapStructuredBuffersContext
// Having found a `*StructuredBuffer<M>` we will now
// need an IR builder to help us construct the wrapper code.
//
- SharedIRBuilder sharedBuilderStorage(m_module);
- auto sharedBuilder = &sharedBuilderStorage;
- IRBuilder builderStorage(sharedBuilder);
+ IRBuilder builderStorage(m_module);
auto builder = &builderStorage;
// We begin by constructing a structure type that wraps
diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp
index 6cf0f09a5..dc61a45af 100644
--- a/source/slang/slang-ir.cpp
+++ b/source/slang/slang-ir.cpp
@@ -750,8 +750,7 @@ namespace Slang
auto irModule = func->getModule();
SLANG_ASSERT(irModule);
- SharedIRBuilder sharedBuilder(irModule);
- IRBuilder builder(sharedBuilder);
+ IRBuilder builder(irModule);
builder.setInsertBefore(func);
List<IRType*> paramTypes;
@@ -1221,7 +1220,7 @@ namespace Slang
auto user = use->getUser();
if (user->getModule())
{
- user->getModule()->getSharedBuilder()->getInstReplacementMap().TryGetValue(newValue, newValue);
+ user->getModule()->getDeduplicationContext()->getInstReplacementMap().TryGetValue(newValue, newValue);
}
if (!getIROpInfo(user->getOp()).isHoistable())
@@ -1234,7 +1233,7 @@ namespace Slang
// perform the update, then try to reinsert it back to the global number map.
// If we find an equivalent entry already exists in the global number map,
// we return the existing entry.
- auto builder = user->getModule()->getSharedBuilder();
+ auto builder = user->getModule()->getDeduplicationContext();
builder->_removeGlobalNumberingEntry(user);
use->init(user, newValue);
@@ -1693,7 +1692,7 @@ namespace Slang
Int const* listArgCounts,
IRInst* const* const* listArgs)
{
- m_sharedBuilder->getInstReplacementMap().TryGetValue((IRInst*)(type), *(IRInst**)&type);
+ m_dedupContext->getInstReplacementMap().TryGetValue((IRInst*)(type), *(IRInst**)&type);
if (getIROpInfo(op).flags & kIROpFlag_Hoistable)
{
@@ -1727,7 +1726,7 @@ namespace Slang
if (fixedArgs)
{
auto arg = fixedArgs[aa];
- m_sharedBuilder->getInstReplacementMap().TryGetValue(arg, arg);
+ m_dedupContext->getInstReplacementMap().TryGetValue(arg, arg);
operand->init(inst, arg);
}
else
@@ -1745,7 +1744,7 @@ namespace Slang
if (listArgs[ii])
{
auto arg = listArgs[ii][jj];
- m_sharedBuilder->getInstReplacementMap().TryGetValue(arg, arg);
+ m_dedupContext->getInstReplacementMap().TryGetValue(arg, arg);
operand->init(inst, arg);
}
else
@@ -2140,7 +2139,7 @@ namespace Slang
key.inst = &keyInst;
IRConstant* irValue = nullptr;
- if( getSharedBuilder()->getConstantMap().TryGetValue(key, irValue) )
+ if (m_dedupContext->getConstantMap().TryGetValue(key, irValue))
{
// We found a match, so just use that.
return irValue;
@@ -2207,7 +2206,7 @@ namespace Slang
}
key.inst = irValue;
- getSharedBuilder()->getConstantMap().Add(key, irValue);
+ m_dedupContext->getConstantMap().Add(key, irValue);
addHoistableInst(this, irValue);
@@ -2414,7 +2413,7 @@ namespace Slang
for (Int ii = 0; ii < fixedArgCount; ++ii)
{
auto arg = fixedArgs[ii];
- m_sharedBuilder->getInstReplacementMap().TryGetValue(arg, arg);
+ m_dedupContext->getInstReplacementMap().TryGetValue(arg, arg);
operand->usedValue = arg;
operand++;
}
@@ -2424,7 +2423,7 @@ namespace Slang
for (UInt jj = 0; jj < listOperandCount; ++jj)
{
auto arg = listArgs[ii][jj];
- m_sharedBuilder->getInstReplacementMap().TryGetValue(arg, arg);
+ m_dedupContext->getInstReplacementMap().TryGetValue(arg, arg);
operand->usedValue = arg;
operand++;
}
@@ -2436,7 +2435,7 @@ namespace Slang
IRInstKey key = { inst };
// Ideally we would add if not found, else return if was found instead of testing & then adding.
- IRInst** found = getSharedBuilder()->getGlobalValueNumberingMap().TryGetValueOrAdd(key, inst);
+ IRInst** found = m_dedupContext->getGlobalValueNumberingMap().TryGetValueOrAdd(key, inst);
SLANG_ASSERT(endCursor == memoryArena.getCursor());
// If it's found, just return, and throw away the instruction
if (found)
@@ -6497,7 +6496,7 @@ namespace Slang
static void _replaceInstUsesWith(IRInst* thisInst, IRInst* other)
{
- SharedIRBuilder* sharedBuilder = nullptr;
+ IRDeduplicationContext* dedupContext = nullptr;
struct WorkItem
{
@@ -6535,12 +6534,12 @@ namespace Slang
if (getIROpInfo(thisInst->getOp()).isHoistable())
{
- if (!sharedBuilder)
+ if (!dedupContext)
{
SLANG_ASSERT(thisInst->getModule());
- sharedBuilder = thisInst->getModule()->getSharedBuilder();
+ dedupContext = thisInst->getModule()->getDeduplicationContext();
}
- sharedBuilder->getInstReplacementMap()[thisInst] = other;
+ dedupContext->getInstReplacementMap()[thisInst] = other;
}
// We will walk through the list of uses for the current
@@ -6564,12 +6563,12 @@ namespace Slang
bool userIsHoistable = getIROpInfo(user->getOp()).isHoistable();
if (userIsHoistable)
{
- if (!sharedBuilder)
+ if (!dedupContext)
{
SLANG_ASSERT(user->getModule());
- sharedBuilder = user->getModule()->getSharedBuilder();
+ dedupContext = user->getModule()->getDeduplicationContext();
}
- sharedBuilder->_removeGlobalNumberingEntry(user);
+ dedupContext->_removeGlobalNumberingEntry(user);
}
// Swap this use over to use the other value.
@@ -6580,13 +6579,13 @@ namespace Slang
// Is the updated inst already exists in the global numbering map?
// If so, we need to continue work on replacing the updated inst with the existing value.
IRInst* existingVal = nullptr;
- if (sharedBuilder->getGlobalValueNumberingMap().TryGetValue(IRInstKey{ user }, existingVal))
+ if (dedupContext->getGlobalValueNumberingMap().TryGetValue(IRInstKey{ user }, existingVal))
{
addToWorkList(user, existingVal);
}
else
{
- sharedBuilder->_addGlobalNumberingEntry(user);
+ dedupContext->_addGlobalNumberingEntry(user);
}
}
@@ -6797,13 +6796,13 @@ namespace Slang
{
if (getIROpInfo(getOp()).isHoistable())
{
- module->getSharedBuilder()->removeHoistableInstFromGlobalNumberingMap(this);
+ module->getDeduplicationContext()->removeHoistableInstFromGlobalNumberingMap(this);
}
else if (auto constInst = as<IRConstant>(this))
{
- module->getSharedBuilder()->getConstantMap().Remove(IRConstantKey{ constInst });
+ module->getDeduplicationContext()->getConstantMap().Remove(IRConstantKey{ constInst });
}
- module->getSharedBuilder()->getInstReplacementMap().Remove(this);
+ module->getDeduplicationContext()->getInstReplacementMap().Remove(this);
}
removeArguments();
removeAndDeallocateAllDecorationsAndChildren();
diff --git a/source/slang/slang-ir.h b/source/slang/slang-ir.h
index 9b8aa5cb7..63b7c4ef9 100644
--- a/source/slang/slang-ir.h
+++ b/source/slang/slang-ir.h
@@ -1911,13 +1911,12 @@ struct IRConstantKey
HashCode getHashCode() const { return inst->getHashCode(); }
};
-struct SharedIRBuilder
+// State owned by IRModule for global value deduplication.
+// Not supposed to be used/instantiated outside IRModule.
+struct IRDeduplicationContext
{
public:
- SharedIRBuilder()
- {}
-
- explicit SharedIRBuilder(IRModule* module)
+ IRDeduplicationContext(IRModule* module)
{
init(module);
}
@@ -1934,15 +1933,6 @@ public:
return m_session;
}
- void insertBlockAlongEdge(IREdge const& edge);
-
- // Rebuilds `globalValueNumberingMap`. This is necessary if any existing
- // keys are modified (thus its hash code is changed).
- void deduplicateAndRebuildGlobalNumberingMap();
-
- // Replaces all uses of oldInst with newInst, and ensures the global numbering map is valid after the replacement.
- void replaceGlobalInst(IRInst* oldInst, IRInst* newInst);
-
void removeHoistableInstFromGlobalNumberingMap(IRInst* inst);
void tryHoistInst(IRInst* inst);
@@ -2003,7 +1993,7 @@ public:
SLANG_FORCE_INLINE IRModuleInst* getModuleInst() const { return m_moduleInst; }
SLANG_FORCE_INLINE MemoryArena& getMemoryArena() { return m_memoryArena; }
- SharedIRBuilder* getSharedBuilder() const { return &m_sharedBuilder; }
+ IRDeduplicationContext* getDeduplicationContext() const { return &m_deduplicationContext; }
IRInstListBase getGlobalInsts() const { return getModuleInst()->getChildren(); }
@@ -2048,7 +2038,7 @@ private:
IRModule(Session* session)
: m_session(session)
, m_memoryArena(kMemoryArenaBlockSize)
- , m_sharedBuilder(this)
+ , m_deduplicationContext(this)
{
}
@@ -2067,8 +2057,8 @@ private:
/// The memory arena from which all IR instructions (and any associated state) in this module are allocated.
MemoryArena m_memoryArena;
- /// Shared contexts for constructing and maintaining the IR.
- mutable SharedIRBuilder m_sharedBuilder;
+ /// Shared contexts for constructing and deduplicating the IR.
+ mutable IRDeduplicationContext m_deduplicationContext;
};
struct IRSpecializationDictionaryItem : public IRInst
diff --git a/source/slang/slang-legalize-types.h b/source/slang/slang-legalize-types.h
index a24caf960..0b4acf0fe 100644
--- a/source/slang/slang-legalize-types.h
+++ b/source/slang/slang-legalize-types.h
@@ -603,7 +603,6 @@ struct IRTypeLegalizationContext
IRModule* module;
IRBuilder* builder;
- SharedIRBuilder sharedBuilderStorage;
IRBuilder builderStorage;
IRTypeLegalizationContext(
diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp
index 957f74d40..f78dd39e5 100644
--- a/source/slang/slang-lower-to-ir.cpp
+++ b/source/slang/slang-lower-to-ir.cpp
@@ -1532,7 +1532,7 @@ struct ValLoweringVisitor : ValVisitor<ValLoweringVisitor, LoweredValInfo, Lower
auto irFunc = getBuilder()->createFunc();
irSatisfyingVal = irFunc;
- IRBuilder subBuilderStorage(getBuilder()->getSharedBuilder());
+ IRBuilder subBuilderStorage = *getBuilder();
auto subBuilder = &subBuilderStorage;
subBuilder->setInsertInto(irFunc);
@@ -7593,7 +7593,7 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo>
// return f : ftype;
// }
// ```
- IRBuilder typeBuilder(subBuilder->getSharedBuilder());
+ IRBuilder typeBuilder(subBuilder->getModule());
IRCloneEnv cloneEnv = {};
if (returnType)
{
@@ -8587,7 +8587,7 @@ LoweredValInfo ensureDecl(
SLANG_UNEXPECTED("Generic type/value shouldn't be handled here!");
}
- IRBuilder subIRBuilder(context->irBuilder->getSharedBuilder());
+ IRBuilder subIRBuilder(context->irBuilder->getModule());
subIRBuilder.setInsertInto(subIRBuilder.getModule());
IRGenEnv subEnv;
@@ -9025,10 +9025,7 @@ RefPtr<IRModule> generateIRForTranslationUnit(
RefPtr<IRModule> module = IRModule::create(session);
- SharedIRBuilder sharedBuilderStorage(module);
- SharedIRBuilder* sharedBuilder = &sharedBuilderStorage;
-
- IRBuilder builderStorage(sharedBuilder);
+ IRBuilder builderStorage(module);
IRBuilder* builder = &builderStorage;
context->irBuilder = builder;
@@ -9149,7 +9146,7 @@ RefPtr<IRModule> generateIRForTranslationUnit(
checkForMissingReturns(module, compileRequest->getSink());
// Check for invalid differentiable function body.
- checkAutoDiffUsages(sharedBuilder, module, compileRequest->getSink());
+ checkAutoDiffUsages(module, compileRequest->getSink());
// The "mandatory" optimization passes may make use of the
// `IRHighLevelDeclDecoration` type to relate IR instructions
@@ -9248,10 +9245,7 @@ struct SpecializedComponentTypeIRGenContext : ComponentTypeVisitor
RefPtr<IRModule> module = IRModule::create(session);
- SharedIRBuilder sharedBuilderStorage(module);
- SharedIRBuilder* sharedBuilder = &sharedBuilderStorage;
-
- IRBuilder builderStorage(sharedBuilder);
+ IRBuilder builderStorage(module);
builder = &builderStorage;
builder->setInsertInto(module);
@@ -9385,10 +9379,7 @@ struct TypeConformanceIRGenContext
RefPtr<IRModule> module = IRModule::create(session);
- SharedIRBuilder sharedBuilderStorage(module);
- SharedIRBuilder* sharedBuilder = &sharedBuilderStorage;
-
- IRBuilder builderStorage(sharedBuilder);
+ IRBuilder builderStorage(module);
builder = &builderStorage;
builder->setInsertInto(module);
@@ -9733,10 +9724,7 @@ RefPtr<IRModule> TargetProgram::createIRModuleForLayout(DiagnosticSink* sink)
RefPtr<IRModule> irModule = IRModule::create(session);
- SharedIRBuilder sharedBuilderStorage(irModule);
- auto sharedBuilder = &sharedBuilderStorage;
-
- IRBuilder builderStorage(sharedBuilder);
+ IRBuilder builderStorage(irModule);
auto builder = &builderStorage;
builder->setInsertInto(irModule);