[flang-commits] [flang] [flang] Add hlfir.index op to represent index intrinsic function (PR #157575)
via flang-commits
flang-commits at lists.llvm.org
Tue Sep 9 02:17:10 PDT 2025
================
@@ -513,6 +512,35 @@ mlir::Value HlfirReshapeLowering::lowerImpl(
operands[2], operands[3]);
}
+mlir::Value HlfirIndexLowering::lowerImpl(
+ const Fortran::lower::PreparedActualArguments &loweredActuals,
+ const fir::IntrinsicArgumentLoweringRules *argLowering,
+ mlir::Type stmtResultType) {
+ auto operands = getOperandVector(loweredActuals, argLowering);
+ assert(operands.size() == 4);
+ mlir::Value substr = operands[1];
+ mlir::Value str = operands[0];
+ mlir::Value back = operands[2];
+ mlir::Value kind = operands[3];
+
+ mlir::Type resultType;
+ if (kind) {
+ auto kindCst = fir::getIntIfConstant(kind);
+ assert(kindCst &&
+ "kind argument of index must be an integer constant expression");
+ unsigned bits = builder.getKindMap().getIntegerBitsize(*kindCst);
+ assert(bits != 0 && "failed to convert kind to integer bitsize");
+ resultType = builder.getIntegerType(bits);
+ } else {
+ resultType = builder.getDefaultIntegerType();
+ }
----------------
jeanPerier wrote:
This is not needed, semantic resolution already did the type resolution for lowering (stmtResultType). If stmtResultType is not the integer type as defined by KIND, this is a semantics or lowering framework bug.
https://github.com/llvm/llvm-project/pull/157575
More information about the flang-commits
mailing list