summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--source/slang/slang-emit.cpp9
-rw-r--r--source/slang/slang-ir-dce.cpp5
-rw-r--r--source/slang/slang-ir-dce.h1
-rw-r--r--source/slang/slang-lower-to-ir.cpp23
4 files changed, 24 insertions, 14 deletions
diff --git a/source/slang/slang-emit.cpp b/source/slang/slang-emit.cpp
index 670848002..345dfe9b2 100644
--- a/source/slang/slang-emit.cpp
+++ b/source/slang/slang-emit.cpp
@@ -474,15 +474,6 @@ String emitEntryPoint(
break;
}
- // If we have obfuscation strip
- if (compileRequest->getLinkage()->m_obfuscateCode)
- {
- IRStripOptions options;
- options.shouldStripNameHints = true;
- options.stripSourceLocs = true;
- stripFrontEndOnlyInstructions(irModule, options);
- }
-
// The resource-based specialization pass above
// may create specialized versions of functions, but
// it does not try to completely eliminate the original
diff --git a/source/slang/slang-ir-dce.cpp b/source/slang/slang-ir-dce.cpp
index 4359e7e92..7c1cda75f 100644
--- a/source/slang/slang-ir-dce.cpp
+++ b/source/slang/slang-ir-dce.cpp
@@ -256,6 +256,11 @@ struct DeadCodeEliminationContext
}
}
+ if (options.keepLayoutsAlive && inst->findDecoration<IRLayoutDecoration>())
+ {
+ return true;
+ }
+
// A basic block is an interesting case. Knowing that a function
// is live means that its entry block is live, but the liveness
// of any other blocks is determined by whether they are referenced
diff --git a/source/slang/slang-ir-dce.h b/source/slang/slang-ir-dce.h
index 6d4ae9d08..007905486 100644
--- a/source/slang/slang-ir-dce.h
+++ b/source/slang/slang-ir-dce.h
@@ -8,6 +8,7 @@ namespace Slang
struct IRDeadCodeEliminationOptions
{
bool keepExportsAlive = false;
+ bool keepLayoutsAlive = false;
};
/// Eliminate "dead" code from the given IR module.
diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp
index f9d39993a..93084fedd 100644
--- a/source/slang/slang-lower-to-ir.cpp
+++ b/source/slang/slang-lower-to-ir.cpp
@@ -1846,11 +1846,6 @@ static void addNameHint(
IRInst* inst,
Decl* decl)
{
- if (context->shared->m_obfuscateCode)
- {
- return;
- }
-
String name = getNameForNameHint(context, decl);
if(name.getLength() == 0)
return;
@@ -7294,6 +7289,24 @@ RefPtr<IRModule> TargetProgram::createIRModuleForLayout(DiagnosticSink* sink)
builder->addLayoutDecoration(irType, irTypeLayout);
}
+ // Lets strip and run DCE here
+ if (linkage->m_obfuscateCode)
+ {
+ IRStripOptions stripOptions;
+
+ stripOptions.shouldStripNameHints = linkage->m_obfuscateCode;
+ stripOptions.stripSourceLocs = linkage->m_obfuscateCode;
+
+ stripFrontEndOnlyInstructions(irModule, stripOptions);
+
+ IRDeadCodeEliminationOptions options;
+ options.keepExportsAlive = true;
+ options.keepLayoutsAlive = true;
+
+ // Eliminate any dead code
+ eliminateDeadCode(irModule, options);
+ }
+
m_irModuleForLayout = irModule;
return irModule;
}