@@ -1669,41 +1669,41 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
1669
1669
bool IsConst = BVar->isConstant ();
1670
1670
llvm::GlobalValue::LinkageTypes LinkageTy = transLinkageType (BVar);
1671
1671
SPIRVStorageClassKind BS = BVar->getStorageClass ();
1672
- Constant *Initializer = nullptr ;
1673
1672
SPIRVValue *Init = BVar->getInitializer ();
1674
- if (Init)
1675
- Initializer = dyn_cast<Constant>(transValue (Init, F, BB, false ));
1676
- else if (LinkageTy == GlobalValue::CommonLinkage)
1677
- // In LLVM, variables with common linkage type must be initialized to 0.
1678
- Initializer = Constant::getNullValue (Ty);
1679
- else if (BS == SPIRVStorageClassKind::StorageClassWorkgroup)
1680
- Initializer = dyn_cast<Constant>(UndefValue::get (Ty));
1681
- else if ((LinkageTy != GlobalValue::ExternalLinkage) &&
1682
- (BS == SPIRVStorageClassKind::StorageClassCrossWorkgroup))
1683
- Initializer = Constant::getNullValue (Ty);
1684
-
1685
1673
if (BS == StorageClassFunction && !Init) {
1686
1674
assert (BB && " Invalid BB" );
1687
1675
return mapValue (BV, new AllocaInst (Ty, 0 , BV->getName (), BB));
1688
1676
}
1689
- SPIRAddressSpace AddrSpace;
1690
1677
1678
+ SPIRAddressSpace AddrSpace;
1691
1679
bool IsVectorCompute =
1692
1680
BVar->hasDecorate (DecorationVectorComputeVariableINTEL);
1681
+ Constant *Initializer = nullptr ;
1693
1682
if (IsVectorCompute) {
1694
1683
AddrSpace = VectorComputeUtil::getVCGlobalVarAddressSpace (BS);
1695
- if (!Initializer)
1696
- Initializer = UndefValue::get (Ty);
1684
+ Initializer = UndefValue::get (Ty);
1697
1685
} else
1698
1686
AddrSpace = SPIRSPIRVAddrSpaceMap::rmap (BS);
1699
-
1700
- auto LVar = new GlobalVariable (*M, Ty, IsConst, LinkageTy, Initializer,
1701
- BV->getName (), 0 ,
1687
+ auto LVar = new GlobalVariable (*M, Ty, IsConst, LinkageTy,
1688
+ /* Initializer=*/ nullptr , BV->getName (), 0 ,
1702
1689
GlobalVariable::NotThreadLocal, AddrSpace);
1690
+ auto Res = mapValue (BV, LVar);
1691
+ if (Init)
1692
+ Initializer = dyn_cast<Constant>(transValue (Init, F, BB, false ));
1693
+ else if (LinkageTy == GlobalValue::CommonLinkage)
1694
+ // In LLVM, variables with common linkage type must be initialized to 0.
1695
+ Initializer = Constant::getNullValue (Ty);
1696
+ else if (BS == SPIRVStorageClassKind::StorageClassWorkgroup)
1697
+ Initializer = dyn_cast<Constant>(UndefValue::get (Ty));
1698
+ else if ((LinkageTy != GlobalValue::ExternalLinkage) &&
1699
+ (BS == SPIRVStorageClassKind::StorageClassCrossWorkgroup))
1700
+ Initializer = Constant::getNullValue (Ty);
1701
+
1703
1702
LVar->setUnnamedAddr ((IsConst && Ty->isArrayTy () &&
1704
1703
Ty->getArrayElementType ()->isIntegerTy (8 ))
1705
1704
? GlobalValue::UnnamedAddr::Global
1706
1705
: GlobalValue::UnnamedAddr::None);
1706
+ LVar->setInitializer (Initializer);
1707
1707
1708
1708
if (IsVectorCompute) {
1709
1709
LVar->addAttribute (kVCMetadata ::VCGlobalVariable);
@@ -1717,7 +1717,7 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
1717
1717
SPIRVBuiltinVariableKind BVKind;
1718
1718
if (BVar->isBuiltin (&BVKind))
1719
1719
BuiltinGVMap[LVar] = BVKind;
1720
- return mapValue (BV, LVar) ;
1720
+ return Res ;
1721
1721
}
1722
1722
1723
1723
case OpVariableLengthArrayINTEL: {
0 commit comments