@@ -491,50 +491,45 @@ static bool isTrivialFiller(Expr *E) {
491491 return false ;
492492}
493493
494-
495-
496494// emit a flat cast where the RHS is a scalar, including vector
497495static void EmitHLSLScalarFlatCast (CodeGenFunction &CGF, Address DestVal,
498- QualType DestTy, llvm::Value *SrcVal,
499- QualType SrcTy, SourceLocation Loc) {
496+ QualType DestTy, llvm::Value *SrcVal,
497+ QualType SrcTy, SourceLocation Loc) {
500498 // Flatten our destination
501499 SmallVector<QualType> DestTypes; // Flattened type
502500 SmallVector<llvm::Value *, 4 > IdxList;
503501 SmallVector<std::pair<Address, llvm::Value *>, 16 > StoreGEPList;
504502 // ^^ Flattened accesses to DestVal we want to store into
505- CGF.FlattenAccessAndType (DestVal, DestTy, IdxList, StoreGEPList,
506- DestTypes);
503+ CGF.FlattenAccessAndType (DestVal, DestTy, IdxList, StoreGEPList, DestTypes);
507504
508505 if (const VectorType *VT = SrcTy->getAs <VectorType>()) {
509506 SrcTy = VT->getElementType ();
510507 assert (StoreGEPList.size () <= VT->getNumElements () &&
511- " Cannot perform HLSL flat cast when vector source \
508+ " Cannot perform HLSL flat cast when vector source \
512509 object has less elements than flattened destination \
513510 object." );
514- for (unsigned i = 0 ; i < StoreGEPList.size (); i ++) {
515- llvm::Value *Load = CGF.Builder .CreateExtractElement (SrcVal, i,
516- " vec.load" );
517- llvm::Value *Cast = CGF.EmitScalarConversion (Load, SrcTy,
518- DestTypes[i],
519- Loc);
520- CGF.PerformStore (StoreGEPList[i], Cast);
521- }
522- return ;
511+ for (unsigned i = 0 ; i < StoreGEPList.size (); i++) {
512+ llvm::Value *Load =
513+ CGF.Builder .CreateExtractElement (SrcVal, i, " vec.load" );
514+ llvm::Value *Cast =
515+ CGF.EmitScalarConversion (Load, SrcTy, DestTypes[i], Loc);
516+ CGF.PerformStore (StoreGEPList[i], Cast);
517+ }
518+ return ;
523519 }
524520 llvm_unreachable (" HLSL Flat cast doesn't handle splatting." );
525521}
526522
527523// emit a flat cast where the RHS is an aggregate
528524static void EmitHLSLAggregateFlatCast (CodeGenFunction &CGF, Address DestVal,
529- QualType DestTy, Address SrcVal,
530- QualType SrcTy, SourceLocation Loc) {
525+ QualType DestTy, Address SrcVal,
526+ QualType SrcTy, SourceLocation Loc) {
531527 // Flatten our destination
532528 SmallVector<QualType> DestTypes; // Flattened type
533529 SmallVector<llvm::Value *, 4 > IdxList;
534530 SmallVector<std::pair<Address, llvm::Value *>, 16 > StoreGEPList;
535531 // ^^ Flattened accesses to DestVal we want to store into
536- CGF.FlattenAccessAndType (DestVal, DestTy, IdxList, StoreGEPList,
537- DestTypes);
532+ CGF.FlattenAccessAndType (DestVal, DestTy, IdxList, StoreGEPList, DestTypes);
538533 // Flatten our src
539534 SmallVector<QualType> SrcTypes; // Flattened type
540535 SmallVector<std::pair<Address, llvm::Value *>, 16 > LoadGEPList;
@@ -543,14 +538,14 @@ static void EmitHLSLAggregateFlatCast(CodeGenFunction &CGF, Address DestVal,
543538 CGF.FlattenAccessAndType (SrcVal, SrcTy, IdxList, LoadGEPList, SrcTypes);
544539
545540 assert (StoreGEPList.size () <= LoadGEPList.size () &&
546- " Cannot perform HLSL flat cast when flattened source object \
541+ " Cannot perform HLSL flat cast when flattened source object \
547542 has less elements than flattened destination object." );
548543 // apply casts to what we load from LoadGEPList
549544 // and store result in Dest
550- for (unsigned i = 0 ; i < StoreGEPList.size (); i ++) {
545+ for (unsigned i = 0 ; i < StoreGEPList.size (); i++) {
551546 llvm::Value *Load = CGF.PerformLoad (LoadGEPList[i]);
552- llvm::Value *Cast = CGF. EmitScalarConversion (Load, SrcTypes[i],
553- DestTypes[i], Loc);
547+ llvm::Value *Cast =
548+ CGF. EmitScalarConversion (Load, SrcTypes[i], DestTypes[i], Loc);
554549 CGF.PerformStore (StoreGEPList[i], Cast);
555550 }
556551}
@@ -967,11 +962,12 @@ void AggExprEmitter::VisitCastExpr(CastExpr *E) {
967962 EmitHLSLScalarFlatCast (CGF, DestVal, DestTy, SrcVal, SrcTy, Loc);
968963 } else { // RHS is an aggregate
969964 assert (RV.isAggregate () &&
970- " Can't perform HLSL Aggregate cast on a complex type." );
965+ " Can't perform HLSL Aggregate cast on a complex type." );
971966 Address SrcVal = RV.getAggregateAddress ();
972967 EmitHLSLAggregateFlatCast (CGF, DestVal, DestTy, SrcVal, SrcTy, Loc);
973968 }
974- break ; }
969+ break ;
970+ }
975971 case CK_NoOp:
976972 case CK_UserDefinedConversion:
977973 case CK_ConstructorConversion:
0 commit comments