@@ -1025,44 +1025,37 @@ class VectorExtractOpConversion
1025
1025
auto loc = extractOp->getLoc ();
1026
1026
auto resultType = extractOp.getResult ().getType ();
1027
1027
auto llvmResultType = typeConverter->convertType (resultType);
1028
- auto positionArrayAttr = extractOp.getPosition ();
1028
+ ArrayRef< int64_t > positionArray = extractOp.getPosition ();
1029
1029
1030
1030
// Bail if result type cannot be lowered.
1031
1031
if (!llvmResultType)
1032
1032
return failure ();
1033
1033
1034
1034
// Extract entire vector. Should be handled by folder, but just to be safe.
1035
- if (positionArrayAttr .empty ()) {
1035
+ if (positionArray .empty ()) {
1036
1036
rewriter.replaceOp (extractOp, adaptor.getVector ());
1037
1037
return success ();
1038
1038
}
1039
1039
1040
1040
// One-shot extraction of vector from array (only requires extractvalue).
1041
1041
if (isa<VectorType>(resultType)) {
1042
- SmallVector<int64_t > indices;
1043
- for (auto idx : positionArrayAttr.getAsRange <IntegerAttr>())
1044
- indices.push_back (idx.getInt ());
1045
1042
Value extracted = rewriter.create <LLVM::ExtractValueOp>(
1046
- loc, adaptor.getVector (), indices );
1043
+ loc, adaptor.getVector (), positionArray );
1047
1044
rewriter.replaceOp (extractOp, extracted);
1048
1045
return success ();
1049
1046
}
1050
1047
1051
1048
// Potential extraction of 1-D vector from array.
1052
1049
Value extracted = adaptor.getVector ();
1053
- auto positionAttrs = positionArrayAttr.getValue ();
1054
- if (positionAttrs.size () > 1 ) {
1055
- SmallVector<int64_t > nMinusOnePosition;
1056
- for (auto idx : positionAttrs.drop_back ())
1057
- nMinusOnePosition.push_back (cast<IntegerAttr>(idx).getInt ());
1058
- extracted = rewriter.create <LLVM::ExtractValueOp>(loc, extracted,
1059
- nMinusOnePosition);
1050
+ if (positionArray.size () > 1 ) {
1051
+ extracted = rewriter.create <LLVM::ExtractValueOp>(
1052
+ loc, extracted, positionArray.drop_back ());
1060
1053
}
1061
1054
1062
1055
// Remaining extraction of element from 1-D LLVM vector
1063
- auto position = cast<IntegerAttr>(positionAttrs.back ());
1064
1056
auto i64Type = IntegerType::get (rewriter.getContext (), 64 );
1065
- auto constant = rewriter.create <LLVM::ConstantOp>(loc, i64Type, position);
1057
+ auto constant =
1058
+ rewriter.create <LLVM::ConstantOp>(loc, i64Type, positionArray.back ());
1066
1059
extracted =
1067
1060
rewriter.create <LLVM::ExtractElementOp>(loc, extracted, constant);
1068
1061
rewriter.replaceOp (extractOp, extracted);
@@ -1147,52 +1140,48 @@ class VectorInsertOpConversion
1147
1140
auto sourceType = insertOp.getSourceType ();
1148
1141
auto destVectorType = insertOp.getDestVectorType ();
1149
1142
auto llvmResultType = typeConverter->convertType (destVectorType);
1150
- auto positionArrayAttr = insertOp.getPosition ();
1143
+ ArrayRef< int64_t > positionArray = insertOp.getPosition ();
1151
1144
1152
1145
// Bail if result type cannot be lowered.
1153
1146
if (!llvmResultType)
1154
1147
return failure ();
1155
1148
1156
1149
// Overwrite entire vector with value. Should be handled by folder, but
1157
1150
// just to be safe.
1158
- if (positionArrayAttr .empty ()) {
1151
+ if (positionArray .empty ()) {
1159
1152
rewriter.replaceOp (insertOp, adaptor.getSource ());
1160
1153
return success ();
1161
1154
}
1162
1155
1163
1156
// One-shot insertion of a vector into an array (only requires insertvalue).
1164
1157
if (isa<VectorType>(sourceType)) {
1165
1158
Value inserted = rewriter.create <LLVM::InsertValueOp>(
1166
- loc, adaptor.getDest (), adaptor.getSource (),
1167
- LLVM::convertArrayToIndices (positionArrayAttr));
1159
+ loc, adaptor.getDest (), adaptor.getSource (), positionArray);
1168
1160
rewriter.replaceOp (insertOp, inserted);
1169
1161
return success ();
1170
1162
}
1171
1163
1172
1164
// Potential extraction of 1-D vector from array.
1173
1165
Value extracted = adaptor.getDest ();
1174
- auto positionAttrs = positionArrayAttr.getValue ();
1175
- auto position = cast<IntegerAttr>(positionAttrs.back ());
1176
1166
auto oneDVectorType = destVectorType;
1177
- if (positionAttrs .size () > 1 ) {
1167
+ if (positionArray .size () > 1 ) {
1178
1168
oneDVectorType = reducedVectorTypeBack (destVectorType);
1179
1169
extracted = rewriter.create <LLVM::ExtractValueOp>(
1180
- loc, extracted,
1181
- LLVM::convertArrayToIndices (positionAttrs.drop_back ()));
1170
+ loc, extracted, positionArray.drop_back ());
1182
1171
}
1183
1172
1184
1173
// Insertion of an element into a 1-D LLVM vector.
1185
1174
auto i64Type = IntegerType::get (rewriter.getContext (), 64 );
1186
- auto constant = rewriter.create <LLVM::ConstantOp>(loc, i64Type, position);
1175
+ auto constant =
1176
+ rewriter.create <LLVM::ConstantOp>(loc, i64Type, positionArray.back ());
1187
1177
Value inserted = rewriter.create <LLVM::InsertElementOp>(
1188
1178
loc, typeConverter->convertType (oneDVectorType), extracted,
1189
1179
adaptor.getSource (), constant);
1190
1180
1191
1181
// Potential insertion of resulting 1-D vector into array.
1192
- if (positionAttrs .size () > 1 ) {
1182
+ if (positionArray .size () > 1 ) {
1193
1183
inserted = rewriter.create <LLVM::InsertValueOp>(
1194
- loc, adaptor.getDest (), inserted,
1195
- LLVM::convertArrayToIndices (positionAttrs.drop_back ()));
1184
+ loc, adaptor.getDest (), inserted, positionArray.drop_back ());
1196
1185
}
1197
1186
1198
1187
rewriter.replaceOp (insertOp, inserted);
0 commit comments