MCPcopy Create free account
hub / github.com/csyonghe/Spire / EliminateDeadCode

Method EliminateDeadCode

Source/SpireCore/VariantIR.cpp:10–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8 namespace Compiler
9 {
10 void ShaderIR::EliminateDeadCode()
11 {
12 // mark entry points
13 auto MarkUsing = [&](String compName, String userWorld)
14 {
15 if (auto defs = DefinitionsByComponent.TryGetValue(compName))
16 {
17 if (auto def = defs->TryGetValue(userWorld))
18 (*def)->IsEntryPoint = true;
19 else
20 {
21 for (auto & world : Shader->Pipeline->WorldDependency[userWorld]())
22 {
23 if (auto def2 = defs->TryGetValue(world))
24 {
25 (*def2)->IsEntryPoint = true;
26 break;
27 }
28 }
29 }
30 }
31 };
32 for (auto & impOp : Shader->Pipeline->SyntaxNode->GetImportOperators())
33 for (auto & ref : impOp->Usings)
34 MarkUsing(ref, impOp->DestWorld.Content);
35 for (auto & req : Shader->Pipeline->Components)
36 if (req.Value->IsRequire())
37 {
38 for (auto & impl : req.Value->Implementations)
39 {
40 if (impl->Worlds.Count())
41 {
42 for (auto & world : impl->Worlds)
43 MarkUsing(req.Key, world);
44 }
45 else
46 {
47 for (auto & world : Shader->Pipeline->Worlds)
48 MarkUsing(req.Key, world.Key);
49 }
50 }
51 }
52 for (auto & def : Definitions)
53 if (def->SyntaxNode->HasSimpleAttribute("FragDepth"))
54 def->IsEntryPoint = true;
55 List<ComponentDefinitionIR*> workList;
56 HashSet<ComponentDefinitionIR*> referencedDefs;
57 for (auto & def : Definitions)
58 {
59 if (def->IsEntryPoint)
60 {
61 if (referencedDefs.Add(def.Ptr()))
62 workList.Add(def.Ptr());
63 }
64 }
65 for (int i = 0; i < workList.Count(); i++)
66 {
67 auto def = workList[i];

Callers 1

Calls 10

GetImportOperatorsMethod · 0.80
HasSimpleAttributeMethod · 0.80
TryGetValueMethod · 0.45
IsRequireMethod · 0.45
CountMethod · 0.45
AddMethod · 0.45
PtrMethod · 0.45
ContainsMethod · 0.45
ClearMethod · 0.45
RemoveMethod · 0.45

Tested by

no test coverage detected