summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-ir-inline.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/slang/slang-ir-inline.cpp')
-rw-r--r--source/slang/slang-ir-inline.cpp92
1 files changed, 91 insertions, 1 deletions
diff --git a/source/slang/slang-ir-inline.cpp b/source/slang/slang-ir-inline.cpp
index 13221ee8c..f49b52975 100644
--- a/source/slang/slang-ir-inline.cpp
+++ b/source/slang/slang-ir-inline.cpp
@@ -34,7 +34,7 @@ struct InliningPassBase
{
}
- /// Consider all the call sites in the module for inliing
+ /// Consider all the call sites in the module for inlining
bool considerAllCallSites()
{
return considerAllCallSitesRec(m_module->getModuleInst());
@@ -517,6 +517,96 @@ void performMandatoryEarlyInlining(IRModule* module)
pass.considerAllCallSites();
}
+namespace { // anonymous
+
+// Inlines calls that involve String types
+struct StringInliningPass : InliningPassBase
+{
+ typedef InliningPassBase Super;
+
+ StringInliningPass(IRModule* module)
+ : Super(module)
+ {}
+
+ bool doesTypeRequireInline(IRType* type)
+ {
+ // TODO(JS):
+ // I guess there is a question here about what type around string requires
+ // inlining.
+ // For example if we had an array of strings etc.
+ // For now we just consider just basic string types.
+ const auto op = type->getOp();
+ switch (op)
+ {
+ case kIROp_StringType:
+ case kIROp_NativeStringType:
+ {
+ return true;
+ }
+ default: break;
+ }
+
+ return false;
+ }
+
+ bool shouldInline(CallSiteInfo const& info)
+ {
+ auto callee = info.callee;
+
+ if (doesTypeRequireInline(callee->getResultType()))
+ {
+ return true;
+ }
+
+ const auto count = Count(callee->getParamCount());
+ for (Index i = 0; i < count; ++i)
+ {
+ if (doesTypeRequireInline(callee->getParamType(UInt(i))))
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+};
+
+} // anonymous
+
+Result performStringInlining(IRModule* module, DiagnosticSink* sink)
+{
+ SLANG_UNUSED(sink);
+
+ // TODO(JS):
+ // This is perhaps not as efficient as might be desirable.
+ // A more optimized version might not need to pass over all of the module
+ // to find new call sites.
+ //
+ // Another problem here is recursion. Right now Slang compiler doesn't accept recursive input,
+ // but the Slang language is supposed to support recursion on targets that support it.
+ // There are GPU targets that allow recursion such as CUDA.
+ //
+ // Another approach would be (when enabled) when inlining occurs, would be instead of continuing
+ // *after*, to start the checks/inlining from where the inline took place.
+ //
+ while(true)
+ {
+ StringInliningPass pass(module);
+ if (pass.considerAllCallSites())
+ {
+ // If there was a change try inlining again
+ continue;
+ }
+
+ // Done.
+ break;
+ }
+
+
+
+ return SLANG_OK;
+}
+
struct ForceInliningPass : InliningPassBase
{
typedef InliningPassBase Super;