lib/HLSL/HLMatrixLowerPass.cpp
// Store flattened init list elements into matrix array.
Store flattened init list elements into matrix array.
Store flattened init list elements into matrix array .
static void GenerateMatArrayInit(ArrayRef<Value *> elts, Value *ptr,
                                 unsigned &offset, IRBuilder<> &Builder) {
  Type *Ty = ptr->getType()->getPointerElementType();
  if (Ty->isVectorTy()) {
    unsigned vecSize = Ty->getVectorNumElements();
    Type *eltTy = Ty->getVectorElementType();
    Value *result = UndefValue::get(Ty);
    for (unsigned i = 0; i < vecSize; i++) {
      Value *elt = elts[offset + i];
      if (elt->getType() != eltTy) {
        elt = CreateTypeCast(HLCastOpcode::DefaultCast, eltTy, elt, Builder);
      }
      result = Builder.CreateInsertElement(result, elt, i);
    }
    offset += vecSize;
    Builder.CreateStore(result, ptr);
  } else {
    DXASSERT(Ty->isArrayTy(), "must be array type");
    Type *i32Ty = Type::getInt32Ty(Ty->getContext());
    Constant *zero = ConstantInt::get(i32Ty, 0);
    unsigned arraySize = Ty->getArrayNumElements();
    for (unsigned i = 0; i < arraySize; i++) {
      Value *GEP =
          Builder.CreateInBoundsGEP(ptr, {zero, ConstantInt::get(i32Ty, i)});
      GenerateMatArrayInit(elts, GEP, offset, Builder);
    }
  }
}
static void GenerateMatArrayInit ( ArrayRef < Value * > elts , Value * ptr , unsigned & offset , IRBuilder < > & Builder ) { Type * Ty = ptr -> getType ( ) -> getPointerElementType ( ) ; if ( Ty -> isVectorTy ( ) ) { unsigned vecSize = Ty -> getVectorNumElements ( ) ; Type * eltTy = Ty -> getVectorElementType ( ) ; Value * result = UndefValue :: get ( Ty ) ; for ( unsigned i = 0 ; i < vecSize ; i ++ ) { Value * elt = elts [ offset + i ] ; if ( elt -> getType ( ) != eltTy ) { elt = CreateTypeCast ( HLCastOpcode :: DefaultCast , eltTy , elt , Builder ) ; } result = Builder . CreateInsertElement ( result , elt , i ) ; } offset += vecSize ; Builder . CreateStore ( result , ptr ) ; } else { DXASSERT ( Ty -> isArrayTy ( ) , " " ) ; Type * i32Ty = Type :: getInt32Ty ( Ty -> getContext ( ) ) ; Constant * zero = ConstantInt :: get ( i32Ty , 0 ) ; unsigned arraySize = Ty -> getArrayNumElements ( ) ; for ( unsigned i = 0 ; i < arraySize ; i ++ ) { Value * GEP = Builder . CreateInBoundsGEP ( ptr , { zero , ConstantInt :: get ( i32Ty , i ) } ) ; GenerateMatArrayInit ( elts , GEP , offset , Builder ) ; } } }
Store flattened init list elements into matrix array.
Store flattened init list elements into matrix array .
// FIXME: get signed/unsigned info. // Update offset.