Skip to content

Commit a0f5473

Browse files
committed
address pr comments
1 parent 20bab28 commit a0f5473

File tree

4 files changed

+22
-27
lines changed

4 files changed

+22
-27
lines changed

clang/lib/AST/ExprConstant.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14857,7 +14857,6 @@ bool IntExprEvaluator::VisitCastExpr(const CastExpr *E) {
1485714857
case CK_FixedPointCast:
1485814858
case CK_IntegralToFixedPoint:
1485914859
case CK_MatrixCast:
14860-
// TODO does CK_HLSLAggregateCast belong here?
1486114860
llvm_unreachable("invalid cast kind for integral value");
1486214861

1486314862
case CK_BitCast:
@@ -14876,6 +14875,7 @@ bool IntExprEvaluator::VisitCastExpr(const CastExpr *E) {
1487614875
case CK_NoOp:
1487714876
case CK_LValueToRValueBitCast:
1487814877
case CK_HLSLArrayRValue:
14878+
case CK_HLSLAggregateCast:
1487914879
return ExprEvaluatorBaseTy::VisitCastExpr(E);
1488014880

1488114881
case CK_MemberPointerToBoolean:

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6370,25 +6370,19 @@ void CodeGenFunction::FlattenAccessAndType(
63706370
16>
63716371
WorkList;
63726372
llvm::IntegerType *IdxTy = llvm::IntegerType::get(getLLVMContext(), 32);
6373-
WorkList.push_back(
6374-
{AddrType,
6375-
{llvm::ConstantInt::get(
6376-
IdxTy,
6377-
0)}}); // Addr should be a pointer so we need to 'dereference' it
6373+
// Addr should be a pointer so we need to 'dereference' it
6374+
WorkList.push_back({AddrType, {llvm::ConstantInt::get(IdxTy, 0)}});
63786375

63796376
while (!WorkList.empty()) {
6380-
std::pair<QualType, llvm::SmallVector<llvm::Value *, 4>> P =
6381-
WorkList.pop_back_val();
6382-
QualType T = P.first;
6383-
llvm::SmallVector<llvm::Value *, 4> IdxList = P.second;
6377+
auto [T, IdxList] = WorkList.pop_back_val();
63846378
T = T.getCanonicalType().getUnqualifiedType();
63856379
assert(!isa<MatrixType>(T) && "Matrix types not yet supported in HLSL");
63866380
if (const auto *CAT = dyn_cast<ConstantArrayType>(T)) {
63876381
uint64_t Size = CAT->getZExtSize();
63886382
for (int64_t I = Size - 1; I > -1; I--) {
63896383
llvm::SmallVector<llvm::Value *, 4> IdxListCopy = IdxList;
63906384
IdxListCopy.push_back(llvm::ConstantInt::get(IdxTy, I));
6391-
WorkList.insert(WorkList.end(), {CAT->getElementType(), IdxListCopy});
6385+
WorkList.emplace_back(CAT->getElementType(), IdxListCopy);
63926386
}
63936387
} else if (const auto *RT = dyn_cast<RecordType>(T)) {
63946388
const RecordDecl *Record = RT->getDecl();
@@ -6419,8 +6413,8 @@ void CodeGenFunction::FlattenAccessAndType(
64196413
CharUnits Align = getContext().getTypeAlignInChars(T);
64206414
Address GEP =
64216415
Builder.CreateInBoundsGEP(Addr, IdxList, LLVMT, Align, "vector.gep");
6422-
for (unsigned i = 0; i < VT->getNumElements(); i++) {
6423-
llvm::Value *Idx = llvm::ConstantInt::get(IdxTy, i);
6416+
for (unsigned I = 0, E = VT->getNumElements(); I < E; I++) {
6417+
llvm::Value *Idx = llvm::ConstantInt::get(IdxTy, I);
64246418
// gep on vector fields is not recommended so combine gep with
64256419
// extract/insert
64266420
AccessList.push_back({GEP, Idx});
@@ -6432,7 +6426,7 @@ void CodeGenFunction::FlattenAccessAndType(
64326426
CharUnits Align = getContext().getTypeAlignInChars(T);
64336427
Address GEP =
64346428
Builder.CreateInBoundsGEP(Addr, IdxList, LLVMT, Align, "gep");
6435-
AccessList.push_back({GEP, NULL});
6429+
AccessList.emplace_back(GEP, nullptr);
64366430
FlatTypes.push_back(T);
64376431
}
64386432
}

clang/lib/CodeGen/CGExprAgg.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -508,19 +508,19 @@ static void EmitHLSLScalarFlatCast(CodeGenFunction &CGF, Address DestVal,
508508
"Cannot perform HLSL flat cast when vector source \
509509
object has less elements than flattened destination \
510510
object.");
511-
for (unsigned i = 0; i < StoreGEPList.size(); i++) {
512-
llvm::Value *Load = CGF.Builder.CreateExtractElement(SrcVal, i, "vec.load");
511+
for (unsigned I = 0, Size = StoreGEPList.size(); I < Size; I++) {
512+
llvm::Value *Load = CGF.Builder.CreateExtractElement(SrcVal, I, "vec.load");
513513
llvm::Value *Cast =
514-
CGF.EmitScalarConversion(Load, SrcTy, DestTypes[i], Loc);
514+
CGF.EmitScalarConversion(Load, SrcTy, DestTypes[I], Loc);
515515

516516
// store back
517-
llvm::Value *Idx = StoreGEPList[i].second;
517+
llvm::Value *Idx = StoreGEPList[I].second;
518518
if (Idx) {
519519
llvm::Value *V =
520-
CGF.Builder.CreateLoad(StoreGEPList[i].first, "load.for.insert");
520+
CGF.Builder.CreateLoad(StoreGEPList[I].first, "load.for.insert");
521521
Cast = CGF.Builder.CreateInsertElement(V, Cast, Idx);
522522
}
523-
CGF.Builder.CreateStore(Cast, StoreGEPList[i].first);
523+
CGF.Builder.CreateStore(Cast, StoreGEPList[I].first);
524524
}
525525
return;
526526
}
@@ -974,7 +974,7 @@ void AggExprEmitter::VisitCastExpr(CastExpr *E) {
974974
if (RV.isScalar()) {
975975
llvm::Value *SrcVal = RV.getScalarVal();
976976
EmitHLSLScalarFlatCast(CGF, DestVal, DestTy, SrcVal, SrcTy, Loc);
977-
} else { // RHS is an aggregate
977+
} else {
978978
assert(RV.isAggregate() &&
979979
"Can't perform HLSL Aggregate cast on a complex type.");
980980
Address SrcVal = RV.getAggregateAddress();

clang/lib/CodeGen/CGExprScalar.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2272,24 +2272,25 @@ static Value *EmitHLSLAggregateFlatCast(CodeGenFunction &CGF, Address RHSVal,
22722272
// LHS is either a vector or a builtin?
22732273
// if its a vector create a temp alloca to store into and return that
22742274
if (auto *VecTy = LHSTy->getAs<VectorType>()) {
2275+
assert(SrcTypes.size() >= VecTy->getNumElements() &&
2276+
"Flattened type on RHS must have more elements than vector on LHS.");
22752277
llvm::Value *V =
22762278
CGF.Builder.CreateLoad(CGF.CreateIRTemp(LHSTy, "flatcast.tmp"));
22772279
// write to V.
2278-
for (unsigned i = 0; i < VecTy->getNumElements(); i++) {
2279-
llvm::Value *Load = CGF.Builder.CreateLoad(LoadGEPList[i].first, "load");
2280-
llvm::Value *Idx = LoadGEPList[i].second;
2280+
for (unsigned I = 0, E = VecTy->getNumElements(); I < E; I++) {
2281+
llvm::Value *Load = CGF.Builder.CreateLoad(LoadGEPList[I].first, "load");
2282+
llvm::Value *Idx = LoadGEPList[I].second;
22812283
Load = Idx ? CGF.Builder.CreateExtractElement(Load, Idx, "vec.extract")
22822284
: Load;
22832285
llvm::Value *Cast = CGF.EmitScalarConversion(
2284-
Load, SrcTypes[i], VecTy->getElementType(), Loc);
2285-
V = CGF.Builder.CreateInsertElement(V, Cast, i);
2286+
Load, SrcTypes[I], VecTy->getElementType(), Loc);
2287+
V = CGF.Builder.CreateInsertElement(V, Cast, I);
22862288
}
22872289
return V;
22882290
}
22892291
// i its a builtin just do an extract element or load.
22902292
assert(LHSTy->isBuiltinType() &&
22912293
"Destination type must be a vector or builtin type.");
2292-
// TODO add asserts about things being long enough
22932294
llvm::Value *Load = CGF.Builder.CreateLoad(LoadGEPList[0].first, "load");
22942295
llvm::Value *Idx = LoadGEPList[0].second;
22952296
Load =

0 commit comments

Comments
 (0)