summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-ir-link.cpp
diff options
context:
space:
mode:
authorDietrich Geisler <dgeisler50@gmail.com>2020-07-07 17:46:02 -0400
committerGitHub <noreply@github.com>2020-07-07 14:46:02 -0700
commitcfb41bb61d63d45aa47ccf9580414545630f0d97 (patch)
tree33d1ec1d94e5a88075f0735662f5bbcc29e82c4b /source/slang/slang-ir-link.cpp
parentf8cc28c958e0d1d9701381448c05b6e79dfe4e99 (diff)
Public Keyword for Functions (#1432)
This PR introduces support for the public modifier for functions. This keyword allows labelled functions to be written to the compiled without having a link to an entry point. The goal of this change is to help support heterogeneous design of Slang by permitting C++ code to interact with CPU slang functions. Internally, this PR adds the public decoration to the IR and defines a lowering from the public modifier in the AST to this decoration. Additionally, the Keep Alive decoration is added to any public modifier being lowered, which prevents DCE from eliminating functions labelled with the public keyword. Co-authored-by: Tim Foley <tfoleyNV@users.noreply.github.com>
Diffstat (limited to 'source/slang/slang-ir-link.cpp')
-rw-r--r--source/slang/slang-ir-link.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/source/slang/slang-ir-link.cpp b/source/slang/slang-ir-link.cpp
index 7acdac40b..3935eab07 100644
--- a/source/slang/slang-ir-link.cpp
+++ b/source/slang/slang-ir-link.cpp
@@ -1479,6 +1479,22 @@ LinkedIR linkIR(
}
}
+ for (IRModule* irModule : irModules)
+ {
+ for (auto inst : irModule->getGlobalInsts())
+ {
+ auto hasPublic = inst->findDecoration<IRPublicDecoration>();
+ if (!hasPublic)
+ continue;
+
+ auto cloned = cloneValue(context, inst);
+ if (!cloned->findDecorationImpl(kIROp_KeepAliveDecoration))
+ {
+ context->builder->addKeepAliveDecoration(cloned);
+ }
+ }
+ }
+
// TODO: *technically* we should consider the case where
// we have global variables with initializers, since
// these should get run whether or not the entry point