From 245466d89cfe54b78da486f06d470bc6daaf4625 Mon Sep 17 00:00:00 2001 From: Yong He Date: Thu, 16 Feb 2023 16:44:04 -0800 Subject: Remove `SharedIRBuilder`. (#2657) Co-authored-by: Yong He --- source/slang/slang-ir-specialize.cpp | 43 +++++++++++++----------------------- 1 file changed, 15 insertions(+), 28 deletions(-) (limited to 'source/slang/slang-ir-specialize.cpp') 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 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 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(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 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(val->getDataType())->getElementType(); @@ -2061,7 +2049,7 @@ struct SpecializationContext auto resultType = inst->getFullType(); - IRBuilder builder(sharedBuilderStorage); + IRBuilder builder(module); builder.setInsertBefore(inst); List 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(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; } -- cgit v1.2.3