Add analysis pass support for OpLoad and OpAccessChain
These are our first instructions which yield ssavalues.
For OpAccessChain, also track the base pointer (which we always know at
compile time, until we do full variable pointers support).
The value representation for OpAccessChain's result has two parts:
- per-lane Int offset into whatever the thing is
- shared (and statically known) base reference.
Bug: b/124388146
Change-Id: I364375719b6e396b802de06093454c8f0e76adb6
Reviewed-on: https://swiftshader-review.googlesource.com/c/24598
Reviewed-by: Ben Clayton <bclayton@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Tested-by: Chris Forbes <chrisforbes@google.com>
diff --git a/src/Pipeline/SpirvShader.cpp b/src/Pipeline/SpirvShader.cpp
index dfc18ce..368cf32 100644
--- a/src/Pipeline/SpirvShader.cpp
+++ b/src/Pipeline/SpirvShader.cpp
@@ -215,6 +215,27 @@
UNIMPLEMENTED("These instructions should have already been lowered.");
break;
+ case spv::OpLoad:
+ case spv::OpAccessChain:
+ // Instructions that yield an ssavalue.
+ {
+ auto typeId = insn.word(1);
+ auto resultId = insn.word(2);
+ auto &object = defs[resultId];
+ object.kind = Object::Kind::Value;
+ object.definition = insn;
+ object.sizeInComponents = getType(typeId).sizeInComponents;
+
+ if (insn.opcode() == spv::OpAccessChain)
+ {
+ // interior ptr has two parts:
+ // - logical base ptr, common across all lanes and known at compile time
+ // - per-lane offset
+ object.pointerBase = insn.word(3);
+ }
+ break;
+ }
+
case spv::OpStore:
case spv::OpReturn:
// Don't need to do anything during analysis pass
diff --git a/src/Pipeline/SpirvShader.hpp b/src/Pipeline/SpirvShader.hpp
index 7382061..7c3f4f8 100644
--- a/src/Pipeline/SpirvShader.hpp
+++ b/src/Pipeline/SpirvShader.hpp
@@ -116,6 +116,7 @@
spv::StorageClass storageClass;
uint32_t sizeInComponents = 0;
bool isBuiltInBlock = false;
+ uint32_t pointerBase = 0;
enum class Kind
{