Skip to content
This repository has been archived by the owner on Oct 9, 2019. It is now read-only.

Commit

Permalink
OpVariable in OpSpecConstantOp. (#186)
Browse files Browse the repository at this point in the history
* Fixed problem with OpSpecConstantOp.
In one of last change of spirv spec was added following change:
"Public SPIRV-Headers issues #12 and #13 and Khronos SPIR-V issue #65: Allow OpVariable as an initializer for another OpVariable instruction or the Base of an OpSpecConstantOp with an AccessChain opcode."
In this way, OpVariable can be initialize before OpSpecConstantOp. To do this, it's necessary add OpSpecConstantOp in one container with OpVariable in TopologicalSort. After this change, OpSpecConstantOp and OpVariable instructions will be add to spirv file in the right order.

* Renamed InstructionVec to ConstAndVarVec and fixed indentation
  • Loading branch information
echuraev authored and yxsamliu committed Sep 29, 2016
1 parent 73e65fc commit 7771f22
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
13 changes: 6 additions & 7 deletions lib/SPIRV/libSPIRV/SPIRVModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1225,15 +1225,15 @@ class TopologicalSort {
typedef std::vector<SPIRVType *> SPIRVTypeVec;
typedef std::vector<SPIRVValue *> SPIRVConstantVector;
typedef std::vector<SPIRVVariable *> SPIRVVariableVec;
typedef std::vector<SPIRVEntry *> SPIRVConstAndVarVec;
typedef std::vector<SPIRVTypeForwardPointer *> SPIRVForwardPointerVec;
typedef std::function<bool(SPIRVEntry*, SPIRVEntry*)> IdComp;
typedef std::map<SPIRVEntry*, DFSState, IdComp> EntryStateMapTy;

SPIRVTypeVec TypeIntVec;
SPIRVConstantVector ConstIntVec;
SPIRVTypeVec TypeVec;
SPIRVConstantVector ConstVec;
SPIRVVariableVec VariableVec;
SPIRVConstAndVarVec ConstAndVarVec;
const SPIRVForwardPointerVec& ForwardPointerVec;
EntryStateMapTy EntryStateMap;

Expand Down Expand Up @@ -1269,11 +1269,11 @@ class TopologicalSort {
if (C->getType()->isTypeInt())
ConstIntVec.push_back(C);
else
ConstVec.push_back(C);
ConstAndVarVec.push_back(E);
} else if (isTypeOpCode(OC))
TypeVec.push_back(static_cast<SPIRVType*>(E));
else if (E->isVariable())
VariableVec.push_back(static_cast<SPIRVVariable*>(E));
else
ConstAndVarVec.push_back(E);
}
public:
TopologicalSort(const SPIRVTypeVec &_TypeVec,
Expand Down Expand Up @@ -1303,8 +1303,7 @@ operator<< (spv_ostream &O, const TopologicalSort &S) {
O << S.TypeIntVec
<< S.ConstIntVec
<< S.TypeVec
<< S.ConstVec
<< S.VariableVec;
<< S.ConstAndVarVec;
return O;
}

Expand Down
19 changes: 8 additions & 11 deletions test/SPIRV/layout.ll
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
; CHECK: {{[0-9]*}} TypeForwardPointer [[AFwdPtr:[0-9]+]]
; CHECK: {{[0-9]*}} TypeInt [[TypeInt:[0-9]+]]
; CHECK: {{[0-9]*}} Constant [[TypeInt]] [[Two:[0-9]+]] 2
; CHECK: {{[0-9]*}} TypePointer [[TPointer:[0-9]+]]
; CHECK: {{[0-9]*}} TypePointer [[SConstOpType:[0-9]+]]
; CHECK: {{[0-9]*}} TypeFloat [[TypeFloat:[0-9]+]]
; CHECK: {{[0-9]*}} TypeArray [[TypeArray:[0-9]+]] [[TypeFloat]] [[Two]]
; CHECK: {{[0-9]*}} TypeVector [[TypeVectorInt3:[0-9]+]] [[TypeInt]] 3
Expand All @@ -53,6 +55,9 @@
; CHECK: {{[0-9]*}} TypeVoid [[Void:[0-9]+]]
; CHECK: {{[0-9]*}} TypePointer [[Int3Ptr:[0-9]+]] {{[0-9]+}} [[TypeVectorInt3]]
; CHECK: {{[0-9]*}} TypeFunction [[TypeBar1:[0-9]+]] [[Void]] [[Int3Ptr]]
; CHECK: {{[0-9]*}} Variable [[TPointer]] [[Var:[0-9]+]]
; CHECK: {{[0-9]*}} SpecConstantOp [[SConstOpType]] [[SConstOp:[0-9]+]] 70 [[Var]]
; CHECK: {{[0-9]*}} Variable {{[0-9]+}} {{[0-9]+}} 5 [[SConstOp]]

; CHECK-NOT: {{[0-9]*}} Capability
; CHECK-NOT: {{[0-9]*}} ExtInstImport
Expand All @@ -62,17 +67,6 @@
; CHECK-NOT: {{[0-9]*}} Name
; CHECK-NOT: {{[0-9]*}} Decorate

; CHECK: {{[0-9]*}} Variable

; CHECK-NOT: {{[0-9]*}} Capability
; CHECK-NOT: {{[0-9]*}} ExtInstImport
; CHECK-NOT: {{[0-9]*}} MemoryModel
; CHECK-NOT: {{[0-9]*}} EntryPoint
; CHECK-NOT: {{[0-9]*}} Source
; CHECK-NOT: {{[0-9]*}} Name
; CHECK-NOT: {{[0-9]*}} Type
; CHECK-NOT: {{[0-9]*}} Decorate

; CHECK: {{[0-9]*}} Function
; CHECK: {{[0-9]*}} FunctionParameter
; CHECK-NOT: {{[0-9]*}} Return
Expand Down Expand Up @@ -126,6 +120,9 @@
target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
target triple = "spir"

@v = addrspace(1) global [2 x i32] [i32 1, i32 2], align 4
@s = addrspace(1) global i32 addrspace(1)* getelementptr inbounds ([2 x i32] addrspace(1)* @v, i32 0, i32 0), align 4

%struct.A = type { i32, %struct.C }
%struct.C = type { i32, %struct.B }
%struct.B = type { i32, %struct.A addrspace(4)* }
Expand Down

0 comments on commit 7771f22

Please sign in to comment.