summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-ir-lower-existential.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2020-09-04 10:18:44 -0700
committerGitHub <noreply@github.com>2020-09-04 10:18:44 -0700
commit8f962894fd38edb47d782d303ac9ff87b3a3bb6a (patch)
tree449d0d58ca7d90a11759372c9dc82650a565f96a /source/slang/slang-ir-lower-existential.cpp
parent5e10f1b4f0654515af1fcb29e8d1f35e691c8aa3 (diff)
Allow mixing unspecialized and specialized existential parameters. (#1533)
* Allow mixing unspecialized and specialized existential parameters. * Fixes.
Diffstat (limited to 'source/slang/slang-ir-lower-existential.cpp')
-rw-r--r--source/slang/slang-ir-lower-existential.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/source/slang/slang-ir-lower-existential.cpp b/source/slang/slang-ir-lower-existential.cpp
index a6db2b781..0dce96de2 100644
--- a/source/slang/slang-ir-lower-existential.cpp
+++ b/source/slang/slang-ir-lower-existential.cpp
@@ -7,6 +7,9 @@
namespace Slang
{
+ bool isCPUTarget(TargetRequest* targetReq);
+ bool isCUDATarget(TargetRequest* targetReq);
+
struct ExistentialLoweringContext
{
SharedGenericsLoweringContext* sharedContext;
@@ -79,12 +82,40 @@ namespace Slang
processExtractExistentialElement(inst, 0);
}
+ void processGetValueFromExistentialBox(IRGetValueFromExistentialBox* inst)
+ {
+ // Currently we do not translate on HLSL/GLSL targets,
+ // since we don't attempt to actually layout the value inside an fixed sized
+ // existential box for these targets.
+ if (isCPUTarget(sharedContext->targetReq) || isCUDATarget(sharedContext->targetReq))
+ {
+ IRBuilder builderStorage;
+ auto builder = &builderStorage;
+ builder->sharedBuilder = &sharedContext->sharedBuilderStorage;
+ builder->setInsertBefore(inst);
+
+ auto element = extractTupleElement(builder, inst->getOperand(0), 2);
+ // TODO: it is not technically sound to use `getAddress` on a temporary value.
+ // We probably need to develop a mechanism to allow a temporary value to be used
+ // in the place of a pointer.
+ auto elementAddr =
+ builder->emitGetAddress(builder->getPtrType(element->getDataType()), element);
+ auto reinterpretAddr = builder->emitBitCast(inst->getDataType(), elementAddr);
+ inst->replaceUsesWith(reinterpretAddr);
+ inst->removeAndDeallocate();
+ }
+ }
+
void processInst(IRInst* inst)
{
if (auto makeExistential = as<IRMakeExistentialWithRTTI>(inst))
{
processMakeExistential(makeExistential);
}
+ else if (auto getExistentialValue = as<IRGetValueFromExistentialBox>(inst))
+ {
+ processGetValueFromExistentialBox(getExistentialValue);
+ }
else if (auto extractExistentialVal = as<IRExtractExistentialValue>(inst))
{
processExtractExistentialValue(extractExistentialVal);