Closed doe300 closed 7 years ago
You can add SPIRVFunction::addVariable to make sure the variable instruction is properly ordered, then modify SPIRVModuleImpl::addVariable to call it.
So, this version does everything correct, as far as I can tell and is ready to be pulled.
Please check the Travis CI build status. It should pass.
Made the requested changes. Also now the tests compile.
I'm not quite sure though about adding the new BasicBlock in SPIRVFunction::addVariable (line 70). Do I have to specify an ID? If so, where do I get it from?
Applied the style-changes and added a test case.
Is this test-case any good? If not, how should I write it?
The tests in DEBUG mode on travis CI fail with "Object type must be an integer type scalar" in SPIRVInstruction.h:1882.
I don't understand, why the pointer-type needs to be an integer. Especially, because the next line seems to accept the void*
type.
It looks like a bug in the assertion statement.
Here is the quote from the spec: "Pointer is a pointer to the object whose lifetime is starting. Its type must be an OpTypePointer with Storage Class Function.
Size must be 0 if Pointer is a pointer to a non-void type or the Addresses capability is not being used. If Size is non-zero, it is the number of bytes of memory whose lifetime is starting. Its type must be an integer type scalar. It is treated as unsigned; if its type has Signedness of 1, its sign bit cannot be set."
"Size" parameter type must be integer. "Pointer" can point to non-integer type values.
Could you fix the assertion statement, please?
There is still travis-ci build failure. Looking at the result:
Exit Code: 2
llvm-spirv: /home/travis/build/KhronosGroup/SPIRV-LLVM/lib/SPIRV/libSPIRV/SPIRVInstruction.h:1880: virtual void SPIRV::SPIRVLifetime<256>::validate() const [OC = 256]: Assertion `Obj->getType()->isTypePointer() && "Objects type must be a pointer"' failed. Stack dump:
Can you fix that?
I can't figure out, why this test fails. So, besides removing the test I don't know of any fix.
I think I know why. The type passed to addVariable is wrong. I've added inline comments about that.
Also, can you add an assertion to SPIRVVariable::validate to assert the type is pointer type? Thanks.
Applied the requested changes, the trancoding-test fails, since the method-signatures do not match for the llvm.memcpy
calls:
Fails to verify module: Call parameter type does not match function signature!
%1 = alloca i8
i8 addrspace(1)* call void @llvm.memcpy.p1i8.p1i8.i32(i8* %1, i8 addrspace(1)* %2, i32 128, i32 64, i1 false)
Call parameter type does not match function signature!
%1 = alloca i8
i8 addrspace(1)* call void @llvm.memcpy.p1i8.p1i8.i32(i8 addrspace(1)* %3, i8* %1, i32 128, i32 64, i1 false)
With the single function declaration for llvm.memcpy
:
declare void @llvm.memcpy.p1i8.p1i8.i32(i8 addrspace(1)* nocapture, i8 addrspace(1)* nocapture readonly, i32, i32, i1) #0
As far as i can tell, there should be 2 declarations, something like:
declare void @llvm.memcpy.p1i8.p1i8.i32(i8*, i8 addrspace(1)* nocapture readonly, i32, i32, i1)
declare void @llvm.memcpy.p1i8.p1i8.i32(i8 addrspace(1)* nocapture, i8* readonly, i32, i32, i1)
It seems to be more complicated than expected. One issue is the type of the temporary variable. It should be either a pointer to the object type to be moved, or a pointer to an array of chars which have the same size of the memmov operation.
Another issue is that adding an existing type to SPIR-V module may cause problem. The SPIR-V module does not have a fold set to guarantee uniqueness of types, so the user has to make sure no duplicate types are added to SPIR-V module.
For this type of transformation, it may be easier to write a pass like SPIRVLowerBool to transform memmov to memcpy in LLVM IR.
Using -O3 we transform two memcpy calls to single memmove call. For translation to SPIR-V purposes it looks reasonable to transform the memmove back to memcpy.
Maybe we just should not use -O3 in the first place? Moreover I don't see any benefits of using -O3, if we end up with the same SPIR-V code as we had with -O0.
That can be a workaround if users are using Clang. I think it is better to be able to lower memmov.
I need the other optimizations run with -O3
, so disabling optimizations is not an option.
I rewrote the pull-request using a lowering pass as suggested by @yxsamliu .
There are too many commits in this pull request. Can you squash them into one commit? Otherwise LGTM.
Closes #205.
Produces following SPIR-V output for the example given in #205:
This result is "correct" in the sense, that the code does the right thing, but:
void
and has no size specified.LifetimeStart
andLifeTimeStop
before/after theCopyMemorySized
instruction.