Skip to content

Commit 779d976

Browse files
committed
Fixes.
1 parent 177a9e3 commit 779d976

8 files changed

+37
-38
lines changed

source/core/slang-common.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ namespace Slang
8888
template<typename F>
8989
class SlangDeferImpl
9090
{
91-
const F& f;
91+
F f;
9292
public:
93-
SlangDeferImpl(const F& f)
94-
: f(f)
93+
SlangDeferImpl(F&& f)
94+
: f(Slang::_Move(f))
9595
{}
9696
~SlangDeferImpl()
9797
{
@@ -101,7 +101,7 @@ class SlangDeferImpl
101101

102102
#ifndef SLANG_DEFER_LAMBDA
103103
#define SLANG_DEFER_LAMBDA(x) auto SLANG_CONCAT(slang_defer_, __LINE__) = SlangDeferImpl(x)
104-
#define SLANG_DEFER(x) auto SLANG_CONCAT(slang_defer_##,__LINE__) = SlangDeferImpl([&](){x;})
104+
#define SLANG_DEFER(x) auto SLANG_CONCAT(slang_defer_,__LINE__) = SlangDeferImpl([&](){x;})
105105
#endif
106106

107107
//

source/slang/slang-compiler-options.h

+5
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,11 @@ namespace Slang
366366
return getBoolOption(CompilerOptionName::MinimumSlangOptimization);
367367
}
368368

369+
bool shouldRunNonEssentialValidation()
370+
{
371+
return !getBoolOption(CompilerOptionName::DisableNonEssentialValidations);
372+
}
373+
369374
FloatingPointMode getFloatingPointMode()
370375
{
371376
return getEnumOption<FloatingPointMode>(CompilerOptionName::FloatingPointMode);

source/slang/slang-emit.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ Result linkAndOptimizeIR(
636636
break;
637637
}
638638

639-
if (!targetProgram->getOptionSet().shouldPerformMinimumOptimizations())
639+
if (targetProgram->getOptionSet().shouldRunNonEssentialValidation())
640640
checkForRecursiveTypes(irModule, sink);
641641

642642
if (sink->getErrorCount() != 0)

source/slang/slang-ir-lower-generics.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ namespace Slang
182182

183183
void stripWrapExistential(IRModule* module)
184184
{
185-
auto& workList = *module->getContainerPool().getList<IRInst>();
185+
InstWorkList workList(module);
186+
186187
workList.add(module->getModuleInst());
187188
for (Index i = 0; i < workList.getCount(); i++)
188189
{

source/slang/slang-ir-specialize.cpp

+3-10
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ struct SpecializationContext
5656
SpecializationContext(IRModule* inModule, TargetProgram* target)
5757
: workList(*inModule->getContainerPool().getList<IRInst>())
5858
, workListSet(*inModule->getContainerPool().getHashSet<IRInst>())
59-
, cleanInsts(*module->getContainerPool().getHashSet<IRInst>())
59+
, cleanInsts(*inModule->getContainerPool().getHashSet<IRInst>())
6060
, module(inModule)
6161
, targetProgram(target)
6262
{
@@ -1250,13 +1250,9 @@ struct SpecializationContext
12501250
if (!isInstFullySpecialized(inst))
12511251
return false;
12521252

1253-
List<IRInst*>& localWorkList = *module->getContainerPool().getList<IRInst>();
1254-
HashSet<IRInst*>& processedInsts = *module->getContainerPool().getHashSet<IRInst>();
1255-
SLANG_DEFER(module->getContainerPool().free(&localWorkList));
1256-
SLANG_DEFER(module->getContainerPool().free(&processedInsts));
1253+
ShortList<IRInst*> localWorkList;
12571254

12581255
localWorkList.add(inst);
1259-
processedInsts.add(inst);
12601256

12611257
while (localWorkList.getCount() != 0)
12621258
{
@@ -1279,10 +1275,7 @@ struct SpecializationContext
12791275
for (UInt i = 0; i < curInst->getOperandCount(); ++i)
12801276
{
12811277
auto operand = curInst->getOperand(i);
1282-
if (processedInsts.add(operand))
1283-
{
1284-
localWorkList.add(operand);
1285-
}
1278+
localWorkList.add(operand);
12861279
}
12871280
}
12881281
return true;

source/slang/slang-ir-uniformity.cpp

+6-11
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,8 @@ namespace Slang
191191

192192
void propagateNonUniform(IRFunc* root, List<IRInst*>& workList)
193193
{
194-
List<IRInst*>& nextWorkList = *module->getContainerPool().getList<IRInst>();
195-
HashSet<IRInst*>& workListSet = *module->getContainerPool().getHashSet<IRInst>();
196-
SLANG_DEFER([&]() { module->getContainerPool().free(&nextWorkList); });
197-
SLANG_DEFER([&]() { module->getContainerPool().free(&workListSet); });
194+
InstWorkList nextWorkList(module);
195+
InstHashSet workListSet(module);
198196

199197
auto addToWorkList = [&](IRInst* inst)
200198
{
@@ -407,15 +405,14 @@ namespace Slang
407405
addToWorkList(user);
408406
}
409407
}
410-
workList.swapWith(nextWorkList);
408+
workList.swapWith(nextWorkList.getList());
411409
nextWorkList.clear();
412410
}
413411
}
414412

415413
void analyzeModule()
416414
{
417-
List<IRInst*>& workList = *module->getContainerPool().getList<IRInst>();
418-
SLANG_DEFER([&]() { module->getContainerPool().free(&workList); });
415+
InstWorkList workList(module);
419416

420417
for (auto globalInst : module->getGlobalInsts())
421418
{
@@ -443,7 +440,7 @@ namespace Slang
443440
}
444441
currentCallee = func;
445442
call = nullptr;
446-
propagateNonUniform(func, workList);
443+
propagateNonUniform(func, workList.getList());
447444
}
448445
}
449446
workList.clear();
@@ -453,9 +450,7 @@ namespace Slang
453450

454451
void eliminateAsDynamicUniformInst()
455452
{
456-
List<IRInst*>& workList = *module->getContainerPool().getList<IRInst>();
457-
SLANG_DEFER([&]() { module->getContainerPool().free(&workList); });
458-
453+
InstWorkList workList(module);
459454
workList.add(module->getModuleInst());
460455
for (Index i = 0; i < workList.getCount(); i++)
461456
{

source/slang/slang-ir.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -2419,6 +2419,7 @@ struct InstWorkList
24192419
other.pool = nullptr;
24202420
return *this;
24212421
}
2422+
List<IRInst*>& getList() { return *workList; }
24222423
IRInst* operator[](Index i) { return (*workList)[i]; }
24232424
Index getCount() { return workList->getCount(); }
24242425
IRInst** begin() { return workList->begin(); }
@@ -2464,7 +2465,7 @@ struct InstHashSet
24642465
other.pool = nullptr;
24652466
return *this;
24662467
}
2467-
2468+
HashSet<IRInst*>& getHashSet() { return *set; }
24682469
Index getCount() { return set->getCount(); }
24692470
bool add(IRInst* inst) { return set->add(inst); }
24702471
bool contains(IRInst* inst) { return set->contains(inst); }

source/slang/slang-lower-to-ir.cpp

+14-10
Original file line numberDiff line numberDiff line change
@@ -10829,14 +10829,20 @@ RefPtr<IRModule> generateIRForTranslationUnit(
1082910829
insertDebugValueStore(module);
1083010830
}
1083110831

10832+
1083210833
// Next, attempt to promote local variables to SSA
1083310834
// temporaries and do basic simplifications.
1083410835
//
1083510836
constructSSA(module);
10836-
simplifyCFG(module, CFGSimplificationOptions::getDefault());
1083710837
applySparseConditionalConstantPropagation(module, compileRequest->getSink());
10838-
auto peepholeOptions = PeepholeOptimizationOptions::getPrelinking();
10839-
peepholeOptimize(nullptr, module, peepholeOptions);
10838+
10839+
bool minimumOptimizations = linkage->m_optionSet.getBoolOption(CompilerOptionName::MinimumSlangOptimization);
10840+
if (!minimumOptimizations)
10841+
{
10842+
simplifyCFG(module, CFGSimplificationOptions::getFast());
10843+
auto peepholeOptions = PeepholeOptimizationOptions::getPrelinking();
10844+
peepholeOptimize(nullptr, module, peepholeOptions);
10845+
}
1084010846

1084110847
IRDeadCodeEliminationOptions dceOptions = IRDeadCodeEliminationOptions();
1084210848
dceOptions.keepExportsAlive = true;
@@ -10881,20 +10887,18 @@ RefPtr<IRModule> generateIRForTranslationUnit(
1088110887
// are eliminated from the callee, and not copied into
1088210888
// call sites.
1088310889
//
10884-
HashSet<IRInst*>* modifiedFuncs = module->getContainerPool().getHashSet<IRInst>();
10885-
SLANG_DEFER(module->getContainerPool().free(modifiedFuncs));
10886-
bool minimumOptimizations = sharedContextStorage.m_linkage->m_optionSet.getBoolOption(CompilerOptionName::MinimumSlangOptimization);
10890+
InstHashSet modifiedFuncs(module);
1088710891
for (;;)
1088810892
{
1088910893
bool changed = false;
10890-
modifiedFuncs->clear();
10891-
changed = performMandatoryEarlyInlining(module, modifiedFuncs);
10894+
modifiedFuncs.clear();
10895+
changed = performMandatoryEarlyInlining(module, &modifiedFuncs.getHashSet());
1089210896
if (changed)
1089310897
{
1089410898
changed = peepholeOptimizeGlobalScope(nullptr, module);
1089510899
if (!minimumOptimizations)
1089610900
{
10897-
for (auto func : *modifiedFuncs)
10901+
for (auto func : modifiedFuncs.getHashSet())
1089810902
{
1089910903
changed |= constructSSA(func);
1090010904
changed |= applySparseConditionalConstantPropagation(func, compileRequest->getSink());
@@ -10908,7 +10912,7 @@ RefPtr<IRModule> generateIRForTranslationUnit(
1090810912
}
1090910913

1091010914
// Check for using uninitialized out parameters.
10911-
if (!compileRequest->getLinkage()->m_optionSet.getBoolOption(CompilerOptionName::DisableNonEssentialValidations))
10915+
if (compileRequest->getLinkage()->m_optionSet.shouldRunNonEssentialValidation())
1091210916
{
1091310917
// Propagate `constexpr`-ness through the dataflow graph (and the
1091410918
// call graph) based on constraints imposed by different instructions.

0 commit comments

Comments
 (0)