Skip to content

Commit 7a189fb

Browse files
committed
Revert "[fir] Add fir.extract_value and fir.insert_value conversion"
This reverts commit ea55503.
1 parent 456a7e5 commit 7a189fb

File tree

4 files changed

+4
-330
lines changed

4 files changed

+4
-330
lines changed

flang/lib/Optimizer/CodeGen/CodeGen.cpp

Lines changed: 4 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -296,105 +296,6 @@ struct ZeroOpConversion : public FIROpConversion<fir::ZeroOp> {
296296
}
297297
};
298298

299-
// Code shared between insert_value and extract_value Ops.
300-
struct ValueOpCommon {
301-
// Translate the arguments pertaining to any multidimensional array to
302-
// row-major order for LLVM-IR.
303-
static void toRowMajor(SmallVectorImpl<mlir::Attribute> &attrs,
304-
mlir::Type ty) {
305-
assert(ty && "type is null");
306-
const auto end = attrs.size();
307-
for (std::remove_const_t<decltype(end)> i = 0; i < end; ++i) {
308-
if (auto seq = ty.dyn_cast<mlir::LLVM::LLVMArrayType>()) {
309-
const auto dim = getDimension(seq);
310-
if (dim > 1) {
311-
auto ub = std::min(i + dim, end);
312-
std::reverse(attrs.begin() + i, attrs.begin() + ub);
313-
i += dim - 1;
314-
}
315-
ty = getArrayElementType(seq);
316-
} else if (auto st = ty.dyn_cast<mlir::LLVM::LLVMStructType>()) {
317-
ty = st.getBody()[attrs[i].cast<mlir::IntegerAttr>().getInt()];
318-
} else {
319-
llvm_unreachable("index into invalid type");
320-
}
321-
}
322-
}
323-
324-
static llvm::SmallVector<mlir::Attribute>
325-
collectIndices(mlir::ConversionPatternRewriter &rewriter,
326-
mlir::ArrayAttr arrAttr) {
327-
llvm::SmallVector<mlir::Attribute> attrs;
328-
for (auto i = arrAttr.begin(), e = arrAttr.end(); i != e; ++i) {
329-
if (i->isa<mlir::IntegerAttr>()) {
330-
attrs.push_back(*i);
331-
} else {
332-
auto fieldName = i->cast<mlir::StringAttr>().getValue();
333-
++i;
334-
auto ty = i->cast<mlir::TypeAttr>().getValue();
335-
auto index = ty.cast<fir::RecordType>().getFieldIndex(fieldName);
336-
attrs.push_back(mlir::IntegerAttr::get(rewriter.getI32Type(), index));
337-
}
338-
}
339-
return attrs;
340-
}
341-
342-
private:
343-
static unsigned getDimension(mlir::LLVM::LLVMArrayType ty) {
344-
unsigned result = 1;
345-
for (auto eleTy = ty.getElementType().dyn_cast<mlir::LLVM::LLVMArrayType>();
346-
eleTy;
347-
eleTy = eleTy.getElementType().dyn_cast<mlir::LLVM::LLVMArrayType>())
348-
++result;
349-
return result;
350-
}
351-
352-
static mlir::Type getArrayElementType(mlir::LLVM::LLVMArrayType ty) {
353-
auto eleTy = ty.getElementType();
354-
while (auto arrTy = eleTy.dyn_cast<mlir::LLVM::LLVMArrayType>())
355-
eleTy = arrTy.getElementType();
356-
return eleTy;
357-
}
358-
};
359-
360-
/// Extract a subobject value from an ssa-value of aggregate type
361-
struct ExtractValueOpConversion
362-
: public FIROpAndTypeConversion<fir::ExtractValueOp>,
363-
public ValueOpCommon {
364-
using FIROpAndTypeConversion::FIROpAndTypeConversion;
365-
366-
mlir::LogicalResult
367-
doRewrite(fir::ExtractValueOp extractVal, mlir::Type ty, OpAdaptor adaptor,
368-
mlir::ConversionPatternRewriter &rewriter) const override {
369-
auto attrs = collectIndices(rewriter, extractVal.coor());
370-
toRowMajor(attrs, adaptor.getOperands()[0].getType());
371-
auto position = mlir::ArrayAttr::get(extractVal.getContext(), attrs);
372-
rewriter.replaceOpWithNewOp<mlir::LLVM::ExtractValueOp>(
373-
extractVal, ty, adaptor.getOperands()[0], position);
374-
return success();
375-
}
376-
};
377-
378-
/// InsertValue is the generalized instruction for the composition of new
379-
/// aggregate type values.
380-
struct InsertValueOpConversion
381-
: public FIROpAndTypeConversion<fir::InsertValueOp>,
382-
public ValueOpCommon {
383-
using FIROpAndTypeConversion::FIROpAndTypeConversion;
384-
385-
mlir::LogicalResult
386-
doRewrite(fir::InsertValueOp insertVal, mlir::Type ty, OpAdaptor adaptor,
387-
mlir::ConversionPatternRewriter &rewriter) const override {
388-
auto attrs = collectIndices(rewriter, insertVal.coor());
389-
toRowMajor(attrs, adaptor.getOperands()[0].getType());
390-
auto position = mlir::ArrayAttr::get(insertVal.getContext(), attrs);
391-
rewriter.replaceOpWithNewOp<mlir::LLVM::InsertValueOp>(
392-
insertVal, ty, adaptor.getOperands()[0], adaptor.getOperands()[1],
393-
position);
394-
return success();
395-
}
396-
};
397-
398299
/// InsertOnRange inserts a value into a sequence over a range of offsets.
399300
struct InsertOnRangeOpConversion
400301
: public FIROpAndTypeConversion<fir::InsertOnRangeOp> {
@@ -488,11 +389,10 @@ class FIRToLLVMLowering : public fir::FIRToLLVMLoweringBase<FIRToLLVMLowering> {
488389
auto *context = getModule().getContext();
489390
fir::LLVMTypeConverter typeConverter{getModule()};
490391
mlir::OwningRewritePatternList pattern(context);
491-
pattern.insert<
492-
AddrOfOpConversion, ExtractValueOpConversion, HasValueOpConversion,
493-
GlobalOpConversion, InsertOnRangeOpConversion, InsertValueOpConversion,
494-
SelectOpConversion, SelectRankOpConversion, UndefOpConversion,
495-
UnreachableOpConversion, ZeroOpConversion>(typeConverter);
392+
pattern.insert<AddrOfOpConversion, HasValueOpConversion, GlobalOpConversion,
393+
InsertOnRangeOpConversion, SelectOpConversion,
394+
SelectRankOpConversion, UnreachableOpConversion,
395+
ZeroOpConversion, UndefOpConversion>(typeConverter);
496396
mlir::populateStdToLLVMConversionPatterns(typeConverter, pattern);
497397
mlir::arith::populateArithmeticToLLVMConversionPatterns(typeConverter,
498398
pattern);

flang/lib/Optimizer/CodeGen/DescriptorModel.h

Lines changed: 0 additions & 134 deletions
This file was deleted.

flang/lib/Optimizer/CodeGen/TypeConverter.h

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
#ifndef FORTRAN_OPTIMIZER_CODEGEN_TYPECONVERTER_H
1414
#define FORTRAN_OPTIMIZER_CODEGEN_TYPECONVERTER_H
1515

16-
#include "DescriptorModel.h"
17-
#include "flang/Lower/Todo.h" // remove when TODO's are done
18-
#include "llvm/ADT/StringMap.h"
1916
#include "llvm/Support/Debug.h"
2017

2118
namespace fir {
@@ -29,35 +26,10 @@ class LLVMTypeConverter : public mlir::LLVMTypeConverter {
2926
LLVM_DEBUG(llvm::dbgs() << "FIR type converter\n");
3027

3128
// Each conversion should return a value of type mlir::Type.
32-
addConversion(
33-
[&](fir::RecordType derived) { return convertRecordType(derived); });
3429
addConversion(
3530
[&](fir::ReferenceType ref) { return convertPointerLike(ref); });
3631
addConversion(
3732
[&](SequenceType sequence) { return convertSequenceType(sequence); });
38-
addConversion([&](mlir::TupleType tuple) {
39-
LLVM_DEBUG(llvm::dbgs() << "type convert: " << tuple << '\n');
40-
llvm::SmallVector<mlir::Type> inMembers;
41-
tuple.getFlattenedTypes(inMembers);
42-
llvm::SmallVector<mlir::Type> members;
43-
for (auto mem : inMembers)
44-
members.push_back(convertType(mem).cast<mlir::Type>());
45-
return mlir::LLVM::LLVMStructType::getLiteral(&getContext(), members,
46-
/*isPacked=*/false);
47-
});
48-
}
49-
50-
// fir.type<name(p : TY'...){f : TY...}> --> llvm<"%name = { ty... }">
51-
mlir::Type convertRecordType(fir::RecordType derived) {
52-
auto name = derived.getName();
53-
auto st = mlir::LLVM::LLVMStructType::getIdentified(&getContext(), name);
54-
llvm::SmallVector<mlir::Type> members;
55-
for (auto mem : derived.getTypeList()) {
56-
members.push_back(convertType(mem.second).cast<mlir::Type>());
57-
}
58-
if (mlir::succeeded(st.setBody(members, /*isPacked=*/false)))
59-
return st;
60-
return mlir::Type();
6133
}
6234

6335
template <typename A>

flang/test/Fir/convert-to-llvm.fir

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -259,67 +259,3 @@ func @select_rank(%arg : i32, %arg2 : i32) -> i32 {
259259
// CHECK: 3: ^bb3(%[[ARG1]], %[[C2]] : i32, i32),
260260
// CHECK: 4: ^bb4(%[[C1]] : i32)
261261
// CHECK: ]
262-
263-
// -----
264-
265-
// Test fir.extract_value operation conversion with derived type.
266-
267-
func @extract_derived_type() -> f32 {
268-
%0 = fir.undefined !fir.type<derived{f:f32}>
269-
%1 = fir.extract_value %0, ["f", !fir.type<derived{f:f32}>] : (!fir.type<derived{f:f32}>) -> f32
270-
return %1 : f32
271-
}
272-
273-
// CHECK-LABEL: llvm.func @extract_derived_type
274-
// CHECK: %[[STRUCT:.*]] = llvm.mlir.undef : !llvm.struct<"derived", (f32)>
275-
// CHECK: %[[VALUE:.*]] = llvm.extractvalue %[[STRUCT]][0 : i32] : !llvm.struct<"derived", (f32)>
276-
// CHECK: llvm.return %[[VALUE]] : f32
277-
278-
// -----
279-
280-
// Test fir.extract_value operation conversion with a multi-dimensional array
281-
// of tuple.
282-
283-
func @extract_array(%a : !fir.array<10x10xtuple<i32, f32>>) -> f32 {
284-
%0 = fir.extract_value %a, [5 : index, 4 : index, 1 : index] : (!fir.array<10x10xtuple<i32, f32>>) -> f32
285-
return %0 : f32
286-
}
287-
288-
// CHECK-LABEL: llvm.func @extract_array(
289-
// CHECK-SAME: %[[ARR:.*]]: !llvm.array<10 x array<10 x struct<(i32, f32)>>>
290-
// CHECK: %[[VALUE:.*]] = llvm.extractvalue %[[ARR]][4 : index, 5 : index, 1 : index] : !llvm.array<10 x array<10 x struct<(i32, f32)>>>
291-
// CHECK: llvm.return %[[VALUE]] : f32
292-
293-
// -----
294-
295-
// Test fir.insert_value operation conversion with a multi-dimensional array
296-
// of tuple.
297-
298-
func @extract_array(%a : !fir.array<10x10xtuple<i32, f32>>) {
299-
%f = arith.constant 2.0 : f32
300-
%i = arith.constant 1 : i32
301-
%0 = fir.insert_value %a, %i, [5 : index, 4 : index, 0 : index] : (!fir.array<10x10xtuple<i32, f32>>, i32) -> !fir.array<10x10xtuple<i32, f32>>
302-
%1 = fir.insert_value %a, %f, [5 : index, 4 : index, 1 : index] : (!fir.array<10x10xtuple<i32, f32>>, f32) -> !fir.array<10x10xtuple<i32, f32>>
303-
return
304-
}
305-
306-
// CHECK-LABEL: llvm.func @extract_array(
307-
// CHECK-SAME: %[[ARR:.*]]: !llvm.array<10 x array<10 x struct<(i32, f32)>>>
308-
// CHECK: %{{.*}} = llvm.insertvalue %{{.*}}, %[[ARR]][4 : index, 5 : index, 0 : index] : !llvm.array<10 x array<10 x struct<(i32, f32)>>>
309-
// CHECK: %{{.*}} = llvm.insertvalue %{{.*}}, %[[ARR]][4 : index, 5 : index, 1 : index] : !llvm.array<10 x array<10 x struct<(i32, f32)>>>
310-
// CHECK: llvm.return
311-
312-
// -----
313-
314-
// Test fir.insert_value operation conversion with derived type.
315-
316-
func @insert_tuple(%a : tuple<i32, f32>) {
317-
%f = arith.constant 2.0 : f32
318-
%1 = fir.insert_value %a, %f, [1 : index] : (tuple<i32, f32>, f32) -> tuple<i32, f32>
319-
return
320-
}
321-
322-
// CHECK-LABEL: func @insert_tuple(
323-
// CHECK-SAME: %[[TUPLE:.*]]: !llvm.struct<(i32, f32)>
324-
// CHECK: %{{.*}} = llvm.insertvalue %{{.*}}, %[[TUPLE]][1 : index] : !llvm.struct<(i32, f32)>
325-
// CHECK: llvm.return

0 commit comments

Comments
 (0)