summaryrefslogtreecommitdiff
path: root/source/slang/slang-lower-to-ir.cpp
diff options
context:
space:
mode:
authorEllie Hermaszewska <ellieh@nvidia.com>2024-03-01 01:50:19 +0800
committerGitHub <noreply@github.com>2024-03-01 01:50:19 +0800
commitd979b5048009c3909cfc13476a78a12ae5f4d61b (patch)
tree550815d37916be845fb0aa1dcc6131960c2bf517 /source/slang/slang-lower-to-ir.cpp
parent21f86773771c26da8bf3c458642e51b1728d419c (diff)
Add support for bitfields (#3639)
* Add support for bitfields Closes https://github.com/shader-slang/slang/issues/3559 * Set scopes for syntsized bitfield accessors * Simplify generated code for bitfield accessors * spelling * regenerate vs project * warnings
Diffstat (limited to 'source/slang/slang-lower-to-ir.cpp')
-rw-r--r--source/slang/slang-lower-to-ir.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp
index cb9c8fc40..e4e324def 100644
--- a/source/slang/slang-lower-to-ir.cpp
+++ b/source/slang/slang-lower-to-ir.cpp
@@ -9,6 +9,7 @@
#include "../core/slang-performance-profiler.h"
#include "slang-check.h"
+#include "slang-ir-bit-field-accessors.h"
#include "slang-ir-loop-inversion.h"
#include "slang-ir.h"
#include "slang-ir-constexpr.h"
@@ -8872,6 +8873,25 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo>
}
}
+ void addBitFieldAccessorDecorations(IRInst* irFunc, Decl* decl)
+ {
+ // If this is an accessor under a property we can move the bitfield
+ // modifiers on the property to the accessor function.
+ if(as<AccessorDecl>(decl) && as<PropertyDecl>(decl->parentDecl))
+ {
+ if(const auto bfm = decl->parentDecl->findModifier<BitFieldModifier>())
+ {
+ getBuilder()->addDecoration(
+ irFunc,
+ kIROp_BitFieldAccessorDecoration,
+ getSimpleVal(context, ensureDecl(context, bfm->backingDeclRef.getDecl())),
+ getBuilder()->getIntValue(getBuilder()->getIntType(), bfm->width),
+ getBuilder()->getIntValue(getBuilder()->getIntType(), bfm->offset)
+ );
+ }
+ }
+ }
+
/// Is `decl` a member function (or effectively a member function) when considered as a stdlib declaration?
bool isStdLibMemberFuncDecl(
Decl* inDecl)
@@ -9345,6 +9365,8 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo>
bool isInline = false;
+ addBitFieldAccessorDecorations(irFunc, decl);
+
for (auto modifier : decl->modifiers)
{
if (as<RequiresNVAPIAttribute>(modifier))
@@ -10360,6 +10382,9 @@ RefPtr<IRModule> generateIRForTranslationUnit(
// normal `call` + `ifElse`, etc.
lowerErrorHandling(module, compileRequest->getSink());
+ // Synthesize some code we want to make sure is inlined and simplified
+ synthesizeBitFieldAccessors(module);
+
// Generate DebugValue insts to store values into debug variables,
// if debug symbols are enabled.
if (compileRequest->getLinkage()->m_optionSet.getEnumOption<DebugInfoLevel>(CompilerOptionName::DebugInformation) != DebugInfoLevel::None)