diff options
| author | Dietrich Geisler <dgeisler50@gmail.com> | 2020-07-07 17:46:02 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-07-07 14:46:02 -0700 |
| commit | cfb41bb61d63d45aa47ccf9580414545630f0d97 (patch) | |
| tree | 33d1ec1d94e5a88075f0735662f5bbcc29e82c4b /source | |
| parent | f8cc28c958e0d1d9701381448c05b6e79dfe4e99 (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')
| -rw-r--r-- | source/slang/slang-ir-inst-defs.h | 3 | ||||
| -rw-r--r-- | source/slang/slang-ir-insts.h | 1 | ||||
| -rw-r--r-- | source/slang/slang-ir-link.cpp | 16 | ||||
| -rw-r--r-- | source/slang/slang-lower-to-ir.cpp | 4 |
4 files changed, 23 insertions, 1 deletions
diff --git a/source/slang/slang-ir-inst-defs.h b/source/slang/slang-ir-inst-defs.h index 85c489528..5a96fd8e8 100644 --- a/source/slang/slang-ir-inst-defs.h +++ b/source/slang/slang-ir-inst-defs.h @@ -474,7 +474,8 @@ INST(HighLevelDeclDecoration, highLevelDecl, 1, 0) INST(VulkanCallablePayloadDecoration, vulkanCallablePayload, 0, 0) INST(EarlyDepthStencilDecoration, earlyDepthStencil, 0, 0) INST(GloballyCoherentDecoration, globallyCoherent, 0, 0) - INST(PreciseDecoration, precise, 0, 0) + INST(PreciseDecoration, precise, 0, 0) + INST(PublicDecoration, public, 0, 0) INST(PatchConstantFuncDecoration, patchConstantFunc, 1, 0) INST(OutputControlPointsDecoration, outputControlPoints, 1, 0) diff --git a/source/slang/slang-ir-insts.h b/source/slang/slang-ir-insts.h index c74dfb4ea..159021412 100644 --- a/source/slang/slang-ir-insts.h +++ b/source/slang/slang-ir-insts.h @@ -220,6 +220,7 @@ IR_SIMPLE_DECORATION(ReadNoneDecoration) IR_SIMPLE_DECORATION(EarlyDepthStencilDecoration) IR_SIMPLE_DECORATION(GloballyCoherentDecoration) IR_SIMPLE_DECORATION(PreciseDecoration) +IR_SIMPLE_DECORATION(PublicDecoration) struct IROutputControlPointsDecoration : IRDecoration 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 diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp index d14fbfed5..1ba99dffb 100644 --- a/source/slang/slang-lower-to-ir.cpp +++ b/source/slang/slang-lower-to-ir.cpp @@ -6716,6 +6716,10 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo> getBuilder()->addRequireCUDASMVersionDecoration(irFunc, versionMod->version); } + if (decl->findModifier<PublicModifier>()) { + getBuilder()->addSimpleDecoration<IRPublicDecoration>(irFunc); + } + if (auto attr = decl->findModifier<InstanceAttribute>()) { IRIntLit* intLit = _getIntLitFromAttribute(getBuilder(), attr); |
