summaryrefslogtreecommitdiff
path: root/source/slang/slang-lower-to-ir.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2019-12-03 09:58:59 -0500
committerGitHub <noreply@github.com>2019-12-03 09:58:59 -0500
commit9653dcc2c9d5d20d3d0e8918aaf1d5b09e963060 (patch)
treeaa1b42132361b2920d9f9301f0b0e44ea82d6b8c /source/slang/slang-lower-to-ir.cpp
parenta3651d99fb8f3a046365d60751d1f3f806e48f7a (diff)
getStringHash on string literals (#1140)
* WIP getStringHash * Have a use. * Add slang-string-hash.h/.cpp * Use StringSlicePool for holding strings for StringHash. Add outputBuffer to string-literal-hash.slang so value can be tested. Ignore the GlobalHashedStringLiterals instruction on emit. * Add all the hashed string literals to ProgramLayout. * Add reflection support for hashed string literals to reflection test. * Fix string literal hash test. * Small fixes to pass test suite. * Fix issue in serialization where IRUse is not correctly initialized. * Fix problem initializing IRUse for string hash pass. Remove hack from slang-ir-specialize - specially handling if user is not null. * * Use shared builder when replacing getStringHash * Comments for functions in slang-ir-string-hash * Do not allow zero length string literals. Could be allowed, but doing so would require StringSlicePool to have a special case (or some other mechanism)
Diffstat (limited to 'source/slang/slang-lower-to-ir.cpp')
-rw-r--r--source/slang/slang-lower-to-ir.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp
index 2a04b53b2..8b8a67f1e 100644
--- a/source/slang/slang-lower-to-ir.cpp
+++ b/source/slang/slang-lower-to-ir.cpp
@@ -14,6 +14,8 @@
#include "slang-ir-ssa.h"
#include "slang-ir-strip.h"
#include "slang-ir-validate.h"
+#include "slang-ir-string-hash.h"
+
#include "slang-mangle.h"
#include "slang-type-layout.h"
#include "slang-visitor.h"
@@ -776,6 +778,24 @@ LoweredValInfo emitCallToDeclRef(
}
else
{
+ switch (intrinsicOp)
+ {
+ case kIROp_GetStringHash:
+ {
+ IRStringLit* stringLit = as<IRStringLit>(args[0]);
+
+ if (stringLit == nullptr || stringLit->getStringSlice() == UnownedStringSlice())
+ {
+ auto sink = context->getSink();
+
+ sink->diagnose(funcDecl, Diagnostics::getStringHashRequiresStringLiteral);
+
+ return LoweredValInfo();
+ }
+
+ }
+ }
+
// The intrinsic op maps to a single IR instruction,
// so we will emit an instruction with the chosen
// opcode, and the arguments to the call as its operands.
@@ -6737,6 +6757,9 @@ IRModule* generateIRForTranslationUnit(
// call graph) based on constraints imposed by different instructions.
propagateConstExpr(module, compileRequest->getSink());
+ // Replace calls to getStringHash, and save all the unique string lits in a GlobalHashedStringLiterals inst
+ replaceGetStringHashWithGlobal(module, *sharedBuilder);
+
// TODO: give error messages if any `undefined` or
// `unreachable` instructions remain.