Author: Eugene Epshteyn
Date: 2026-05-11T10:43:19-04:00
New Revision: cc4922b276947e95aeed779bbf6a1e41f3a96582

URL: 
https://github.com/llvm/llvm-project/commit/cc4922b276947e95aeed779bbf6a1e41f3a96582
DIFF: 
https://github.com/llvm/llvm-project/commit/cc4922b276947e95aeed779bbf6a1e41f3a96582.diff

LOG: [flang] Remove legacy (non-HLFIR) lowering and related options (#196205)

Drop the user-facing options that selected the legacy non-HLFIR lowering
path, the always-true `LowerToHighLevelFIR` lowering option, and the
descriptor-discretization debug switch:

- `-flang-experimental-hlfir` and `-flang-deprecated-no-hlfir` (flang
  driver and `-fc1`)
- `-hlfir` / `--hlfir` (bbc)
- `--use-desc-for-alloc` (bbc, debug)

Remove every `if (lowerToHighLevelFIR()) { ... } else { ... }` branch in
`lib/Lower/`, keeping the HLFIR side. Delete the now-unused legacy
helpers in `Bridge.cpp` (`copyVarFIR`, both
`genNoHLFIRPointerAssignment`
overloads, the legacy block of `genAssignment`) and the always-empty
`createMutableProperties` together with its four dead helpers in
`Allocatable.cpp`. Drop the corresponding `alwaysUseBox` parameter from
`createMutableBox`.

Note: tests were modified in
https://github.com/llvm/llvm-project/pull/196137

Assisted-by: AI

Added: 
    

Modified: 
    clang/include/clang/Options/FlangOptions.td
    clang/lib/Driver/ToolChains/Flang.cpp
    flang/include/flang/Lower/Allocatable.h
    flang/include/flang/Lower/LoweringOptions.def
    flang/lib/Frontend/CompilerInvocation.cpp
    flang/lib/Frontend/FrontendActions.cpp
    flang/lib/Lower/Allocatable.cpp
    flang/lib/Lower/Bridge.cpp
    flang/lib/Lower/CallInterface.cpp
    flang/lib/Lower/ConvertCall.cpp
    flang/lib/Lower/ConvertConstant.cpp
    flang/lib/Lower/ConvertType.cpp
    flang/lib/Lower/ConvertVariable.cpp
    flang/lib/Lower/HostAssociations.cpp
    flang/tools/bbc/bbc.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Options/FlangOptions.td 
b/clang/include/clang/Options/FlangOptions.td
index 1ab83b6ffbbad..50e4642358b71 100644
--- a/clang/include/clang/Options/FlangOptions.td
+++ b/clang/include/clang/Options/FlangOptions.td
@@ -114,18 +114,6 @@ def static_libflangrt : Flag<["-"], "static-libflangrt">,
   HelpText<"Link the flang-rt static library">, Group<Link_Group>,
   Visibility<[FlangOption]>, Flags<[NoArgumentUnused]>;
 
-//===----------------------------------------------------------------------===//
-// FlangOption + NoXarchOption
-//===----------------------------------------------------------------------===//
-
-def flang_experimental_hlfir : Flag<["-"], "flang-experimental-hlfir">,
-  Flags<[HelpHidden]>, Visibility<[FlangOption, FC1Option]>,
-  HelpText<"Use HLFIR lowering (experimental)">;
-
-def flang_deprecated_no_hlfir : Flag<["-"], "flang-deprecated-no-hlfir">,
-  Flags<[HelpHidden]>, Visibility<[FlangOption, FC1Option]>,
-  HelpText<"Do not use HLFIR lowering (deprecated)">;
-
 
//===----------------------------------------------------------------------===//
 // FlangOption + CoreOption + NoXarchOption
 
//===----------------------------------------------------------------------===//

diff  --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index ce503b74295e4..082df7beb4b85 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -252,8 +252,6 @@ void Flang::addCodegenOptions(const ArgList &Args,
   Args.addAllArgs(
       CmdArgs,
       {options::OPT_fdo_concurrent_to_openmp_EQ,
-       options::OPT_flang_experimental_hlfir,
-       options::OPT_flang_deprecated_no_hlfir,
        options::OPT_fno_ppc_native_vec_elem_order,
        options::OPT_fppc_native_vec_elem_order, options::OPT_finit_global_zero,
        options::OPT_fno_init_global_zero, options::OPT_frepack_arrays,

diff  --git a/flang/include/flang/Lower/Allocatable.h 
b/flang/include/flang/Lower/Allocatable.h
index 0e89af94af40f..515fd20b2bcb5 100644
--- a/flang/include/flang/Lower/Allocatable.h
+++ b/flang/include/flang/Lower/Allocatable.h
@@ -68,11 +68,12 @@ void genDeallocateIfAllocated(AbstractConverter &converter,
 /// Create a MutableBoxValue for an allocatable or pointer entity.
 /// If the variables is a local variable that is not a dummy, it will be
 /// initialized to unallocated/diassociated status.
-fir::MutableBoxValue
-createMutableBox(AbstractConverter &converter, mlir::Location loc,
-                 const pft::Variable &var, mlir::Value boxAddr,
-                 mlir::ValueRange nonDeferredParams, bool alwaysUseBox,
-                 unsigned allocator = kDefaultAllocator);
+fir::MutableBoxValue createMutableBox(AbstractConverter &converter,
+                                      mlir::Location loc,
+                                      const pft::Variable &var,
+                                      mlir::Value boxAddr,
+                                      mlir::ValueRange nonDeferredParams,
+                                      unsigned allocator = kDefaultAllocator);
 
 /// Assign a boxed value to a boxed variable, \p box (known as a
 /// MutableBoxValue). Expression \p source will be lowered to build the

diff  --git a/flang/include/flang/Lower/LoweringOptions.def 
b/flang/include/flang/Lower/LoweringOptions.def
index 0b829bf3e08af..e89ad75704609 100644
--- a/flang/include/flang/Lower/LoweringOptions.def
+++ b/flang/include/flang/Lower/LoweringOptions.def
@@ -24,9 +24,6 @@ LOWERINGOPT(Name, Bits, Default)
 /// If true, lower transpose without a runtime call.
 ENUM_LOWERINGOPT(OptimizeTranspose, unsigned, 1, 1)
 
-/// If true, lower to High level FIR before lowering to FIR. On by default.
-ENUM_LOWERINGOPT(LowerToHighLevelFIR, unsigned, 1, 1)
-
 /// If true, reverse PowerPC native vector element order.
 ENUM_LOWERINGOPT(NoPPCNativeVecElemOrder, unsigned, 1, 0)
 

diff  --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index e7f4762e167fb..7205eb4548968 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -1629,25 +1629,6 @@ bool CompilerInvocation::createFromArgs(
     success = false;
   }
 
-  // -flang-experimental-hlfir
-  if (args.hasArg(clang::options::OPT_flang_experimental_hlfir) ||
-      args.hasArg(clang::options::OPT_emit_hlfir)) {
-    invoc.loweringOpts.setLowerToHighLevelFIR(true);
-  }
-
-  // -flang-deprecated-no-hlfir
-  if (args.hasArg(clang::options::OPT_flang_deprecated_no_hlfir) &&
-      !args.hasArg(clang::options::OPT_emit_hlfir)) {
-    if (args.hasArg(clang::options::OPT_flang_experimental_hlfir)) {
-      const unsigned diagID = diags.getCustomDiagID(
-          clang::DiagnosticsEngine::Error,
-          "Options '-flang-experimental-hlfir' and "
-          "'-flang-deprecated-no-hlfir' cannot be both specified");
-      diags.Report(diagID);
-    }
-    invoc.loweringOpts.setLowerToHighLevelFIR(false);
-  }
-
   // -fno-ppc-native-vector-element-order
   if (args.hasArg(clang::options::OPT_fno_ppc_native_vec_elem_order)) {
     invoc.loweringOpts.setNoPPCNativeVecElemOrder(true);

diff  --git a/flang/lib/Frontend/FrontendActions.cpp 
b/flang/lib/Frontend/FrontendActions.cpp
index 4e058786a9a72..9ad1da0011ef4 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -1345,8 +1345,6 @@ void CodeGenAction::executeAction() {
   clang::DiagnosticsEngine &diags = ci.getDiagnostics();
   const CodeGenOptions &codeGenOpts = ci.getInvocation().getCodeGenOpts();
   const TargetOptions &targetOpts = ci.getInvocation().getTargetOpts();
-  Fortran::lower::LoweringOptions &loweringOpts =
-      ci.getInvocation().getLoweringOpts();
   mlir::DefaultTimingManager &timingMgr = ci.getTimingManager();
   mlir::TimingScope &timingScopeRoot = ci.getTimingScopeRoot();
 
@@ -1375,16 +1373,12 @@ void CodeGenAction::executeAction() {
   }
 
   if (action == BackendActionTy::Backend_EmitFIR) {
-    if (loweringOpts.getLowerToHighLevelFIR()) {
-      lowerHLFIRToFIR();
-    }
+    lowerHLFIRToFIR();
     mlirModule->print(ci.isOutputStreamNull() ? *os : ci.getOutputStream());
     return;
   }
 
   if (action == BackendActionTy::Backend_EmitHLFIR) {
-    assert(loweringOpts.getLowerToHighLevelFIR() &&
-           "Lowering must have been configured to emit HLFIR");
     mlirModule->print(ci.isOutputStreamNull() ? *os : ci.getOutputStream());
     return;
   }

diff  --git a/flang/lib/Lower/Allocatable.cpp b/flang/lib/Lower/Allocatable.cpp
index 5cbfba23cffdf..8ca861105ce23 100644
--- a/flang/lib/Lower/Allocatable.cpp
+++ b/flang/lib/Lower/Allocatable.cpp
@@ -48,16 +48,6 @@ static llvm::cl::opt<bool> useAllocateRuntime(
     "use-alloc-runtime",
     llvm::cl::desc("Lower allocations to fortran runtime calls"),
     llvm::cl::init(false));
-/// Switch to force lowering of allocatable and pointers to descriptors in all
-/// cases. This is now turned on by default since that is what will happen with
-/// HLFIR lowering, so this allows getting early feedback of the impact.
-/// If this turns out to cause performance regressions, a dedicated fir.box
-/// "discretization pass" would make more sense to cover all the fir.box usage
-/// (taking advantage of any future inlining for instance).
-static llvm::cl::opt<bool> useDescForMutableBox(
-    "use-desc-for-alloc",
-    llvm::cl::desc("Always use descriptors for POINTER and ALLOCATABLE"),
-    llvm::cl::init(true));
 
 
//===----------------------------------------------------------------------===//
 // Error management
@@ -1017,123 +1007,12 @@ void Fortran::lower::genDeallocateStmt(
 // MutableBoxValue creation implementation
 
//===----------------------------------------------------------------------===//
 
-/// Is this symbol a pointer to a pointer array that does not have the
-/// CONTIGUOUS attribute ?
-static inline bool
-isNonContiguousArrayPointer(const Fortran::semantics::Symbol &sym) {
-  return Fortran::semantics::IsPointer(sym) && sym.Rank() != 0 &&
-         !sym.attrs().test(Fortran::semantics::Attr::CONTIGUOUS);
-}
-
-/// Is this symbol a polymorphic pointer?
-static inline bool isPolymorphicPointer(const Fortran::semantics::Symbol &sym) 
{
-  return Fortran::semantics::IsPointer(sym) &&
-         Fortran::semantics::IsPolymorphic(sym);
-}
-
-/// Is this symbol a polymorphic allocatable?
-static inline bool
-isPolymorphicAllocatable(const Fortran::semantics::Symbol &sym) {
-  return Fortran::semantics::IsAllocatable(sym) &&
-         Fortran::semantics::IsPolymorphic(sym);
-}
-
-/// Is this a local procedure symbol in a procedure that contains internal
-/// procedures ?
-static bool mayBeCapturedInInternalProc(const Fortran::semantics::Symbol &sym) 
{
-  const Fortran::semantics::Scope &owner = sym.owner();
-  Fortran::semantics::Scope::Kind kind = owner.kind();
-  // Test if this is a procedure scope that contains a subprogram scope that is
-  // not an interface.
-  if (kind == Fortran::semantics::Scope::Kind::Subprogram ||
-      kind == Fortran::semantics::Scope::Kind::MainProgram)
-    for (const Fortran::semantics::Scope &childScope : owner.children())
-      if (childScope.kind() == Fortran::semantics::Scope::Kind::Subprogram)
-        if (const Fortran::semantics::Symbol *childSym = childScope.symbol())
-          if (const auto *details =
-                  childSym->detailsIf<Fortran::semantics::SubprogramDetails>())
-            if (!details->isInterface())
-              return true;
-  return false;
-}
-
-/// In case it is safe to track the properties in variables outside a
-/// descriptor, create the variables to hold the mutable properties of the
-/// entity var. The variables are not initialized here.
-static fir::MutableProperties
-createMutableProperties(Fortran::lower::AbstractConverter &converter,
-                        mlir::Location loc,
-                        const Fortran::lower::pft::Variable &var,
-                        mlir::ValueRange nonDeferredParams, bool alwaysUseBox) 
{
-  fir::FirOpBuilder &builder = converter.getFirOpBuilder();
-  const Fortran::semantics::Symbol &sym = var.getSymbol();
-  // Globals and dummies may be associated, creating local variables would
-  // require keeping the values and descriptor before and after every single
-  // impure calls in the current scope (not only the ones taking the variable 
as
-  // arguments. All.) Volatile means the variable may change in ways not 
defined
-  // per Fortran, so lowering can most likely not keep the descriptor and 
values
-  // in sync as needed.
-  // Pointers to non contiguous arrays need to be represented with a fir.box to
-  // account for the discontiguity.
-  // Pointer/Allocatable in internal procedure are descriptors in the host 
link,
-  // and it would increase complexity to sync this descriptor with the local
-  // values every time the host link is escaping.
-  if (alwaysUseBox || var.isGlobal() || Fortran::semantics::IsDummy(sym) ||
-      Fortran::semantics::IsFunctionResult(sym) ||
-      sym.attrs().test(Fortran::semantics::Attr::VOLATILE) ||
-      isNonContiguousArrayPointer(sym) || useAllocateRuntime ||
-      useDescForMutableBox || mayBeCapturedInInternalProc(sym) ||
-      isPolymorphicPointer(sym) || isPolymorphicAllocatable(sym))
-    return {};
-  fir::MutableProperties mutableProperties;
-  std::string name = converter.mangleName(sym);
-  mlir::Type baseAddrTy = converter.genType(sym);
-  if (auto boxType = mlir::dyn_cast<fir::BaseBoxType>(baseAddrTy))
-    baseAddrTy = boxType.getEleTy();
-  // Allocate and set a variable to hold the address.
-  // It will be set to null in setUnallocatedStatus.
-  mutableProperties.addr =
-      builder.allocateLocal(loc, baseAddrTy, name + ".addr", "",
-                            /*shape=*/{}, /*typeparams=*/{});
-  // Allocate variables to hold lower bounds and extents.
-  int rank = sym.Rank();
-  mlir::Type idxTy = builder.getIndexType();
-  for (decltype(rank) i = 0; i < rank; ++i) {
-    mlir::Value lboundVar =
-        builder.allocateLocal(loc, idxTy, name + ".lb" + std::to_string(i), "",
-                              /*shape=*/{}, /*typeparams=*/{});
-    mlir::Value extentVar =
-        builder.allocateLocal(loc, idxTy, name + ".ext" + std::to_string(i), 
"",
-                              /*shape=*/{}, /*typeparams=*/{});
-    mutableProperties.lbounds.emplace_back(lboundVar);
-    mutableProperties.extents.emplace_back(extentVar);
-  }
-
-  // Allocate variable to hold deferred length parameters.
-  mlir::Type eleTy = baseAddrTy;
-  if (auto newTy = fir::dyn_cast_ptrEleTy(eleTy))
-    eleTy = newTy;
-  if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(eleTy))
-    eleTy = seqTy.getEleTy();
-  if (auto record = mlir::dyn_cast<fir::RecordType>(eleTy))
-    if (record.getNumLenParams() != 0)
-      TODO(loc, "deferred length type parameters.");
-  if (fir::isa_char(eleTy) && nonDeferredParams.empty()) {
-    mlir::Value lenVar = builder.allocateLocal(
-        loc, builder.getCharacterLengthType(), name + ".len", "", /*shape=*/{},
-        /*typeparams=*/{});
-    mutableProperties.deferredParams.emplace_back(lenVar);
-  }
-  return mutableProperties;
-}
-
 fir::MutableBoxValue Fortran::lower::createMutableBox(
     Fortran::lower::AbstractConverter &converter, mlir::Location loc,
     const Fortran::lower::pft::Variable &var, mlir::Value boxAddr,
-    mlir::ValueRange nonDeferredParams, bool alwaysUseBox, unsigned allocator) 
{
-  fir::MutableProperties mutableProperties = createMutableProperties(
-      converter, loc, var, nonDeferredParams, alwaysUseBox);
-  fir::MutableBoxValue box(boxAddr, nonDeferredParams, mutableProperties);
+    mlir::ValueRange nonDeferredParams, unsigned allocator) {
+  fir::MutableBoxValue box(boxAddr, nonDeferredParams,
+                           /*mutableProperties=*/{});
   fir::FirOpBuilder &builder = converter.getFirOpBuilder();
   if (!var.isGlobal() && !Fortran::semantics::IsDummy(var.getSymbol()))
     fir::factory::disassociateMutableBox(builder, loc, box,
@@ -1163,22 +1042,9 @@ void Fortran::lower::associateMutableBox(
     cuf::genPointerSync(box.getAddr(), builder);
     return;
   }
-  if (converter.getLoweringOptions().getLowerToHighLevelFIR()) {
-    fir::ExtendedValue rhs = converter.genExprAddr(loc, source, stmtCtx);
-    fir::factory::associateMutableBox(builder, loc, box, rhs, lbounds);
-    cuf::genPointerSync(box.getAddr(), builder);
-    return;
-  }
-  // The right hand side is not be evaluated into a temp. Array sections can
-  // typically be represented as a value of type `!fir.box`. However, an
-  // expression that uses vector subscripts cannot be emboxed. In that case,
-  // generate a reference to avoid having to later use a fir.rebox to implement
-  // the pointer association.
-  fir::ExtendedValue rhs = isArraySectionWithoutVectorSubscript(source)
-                               ? converter.genExprBox(loc, source, stmtCtx)
-                               : converter.genExprAddr(loc, source, stmtCtx);
-
+  fir::ExtendedValue rhs = converter.genExprAddr(loc, source, stmtCtx);
   fir::factory::associateMutableBox(builder, loc, box, rhs, lbounds);
+  cuf::genPointerSync(box.getAddr(), builder);
 }
 
 bool Fortran::lower::isWholeAllocatable(const Fortran::lower::SomeExpr &expr) {

diff  --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp
index 08bb9def8ad5f..01482c1cb90b5 100644
--- a/flang/lib/Lower/Bridge.cpp
+++ b/flang/lib/Lower/Bridge.cpp
@@ -808,11 +808,8 @@ class FirConverter : public 
Fortran::lower::AbstractConverter {
               Fortran::lower::StatementContext &context,
               mlir::Location *locPtr = nullptr) override final {
     mlir::Location loc = locPtr ? *locPtr : toLocation();
-    if (lowerToHighLevelFIR())
-      return Fortran::lower::convertExprToAddress(loc, *this, expr,
-                                                  localSymbols, context);
-    return Fortran::lower::createSomeExtendedAddress(loc, *this, expr,
-                                                     localSymbols, context);
+    return Fortran::lower::convertExprToAddress(loc, *this, expr, localSymbols,
+                                                context);
   }
 
   fir::ExtendedValue
@@ -820,21 +817,15 @@ class FirConverter : public 
Fortran::lower::AbstractConverter {
                Fortran::lower::StatementContext &context,
                mlir::Location *locPtr = nullptr) override final {
     mlir::Location loc = locPtr ? *locPtr : toLocation();
-    if (lowerToHighLevelFIR())
-      return Fortran::lower::convertExprToValue(loc, *this, expr, localSymbols,
-                                                context);
-    return Fortran::lower::createSomeExtendedExpression(loc, *this, expr,
-                                                        localSymbols, context);
+    return Fortran::lower::convertExprToValue(loc, *this, expr, localSymbols,
+                                              context);
   }
 
   fir::ExtendedValue
   genExprBox(mlir::Location loc, const Fortran::lower::SomeExpr &expr,
              Fortran::lower::StatementContext &stmtCtx) override final {
-    if (lowerToHighLevelFIR())
-      return Fortran::lower::convertExprToBox(loc, *this, expr, localSymbols,
-                                              stmtCtx);
-    return Fortran::lower::createBoxValue(loc, *this, expr, localSymbols,
-                                          stmtCtx);
+    return Fortran::lower::convertExprToBox(loc, *this, expr, localSymbols,
+                                            stmtCtx);
   }
 
   Fortran::evaluate::FoldingContext &getFoldingContext() override final {
@@ -1378,56 +1369,51 @@ class FirConverter : public 
Fortran::lower::AbstractConverter {
                Fortran::lower::SymMap *symMap = nullptr,
                bool forceHlfirBase = false) {
     symMap = symMap ? symMap : &localSymbols;
-    if (lowerToHighLevelFIR()) {
-      if (std::optional<fir::FortranVariableOpInterface> var =
-              symMap->lookupVariableDefinition(sym)) {
-        auto exv = hlfir::translateToExtendedValue(toLocation(), *builder, 
*var,
-                                                   forceHlfirBase);
-        return exv.match(
-            [](mlir::Value x) -> Fortran::lower::SymbolBox {
-              return Fortran::lower::SymbolBox::Intrinsic{x};
-            },
-            [](auto x) -> Fortran::lower::SymbolBox { return x; });
-      }
-
-      // Entry character result represented as an argument pair
-      // needs to be represented in the symbol table even before
-      // we can create DeclareOp for it. The temporary mapping
-      // is EmboxCharOp that conveys the address and length information.
-      // After mapSymbolAttributes is done, the mapping is replaced
-      // with the new DeclareOp, and the following table lookups
-      // do not reach here.
-      if (sym.IsFuncResult())
-        if (const Fortran::semantics::DeclTypeSpec *declTy = sym.GetType())
-          if (declTy->category() ==
-              Fortran::semantics::DeclTypeSpec::Category::Character)
-            return symMap->lookupSymbol(sym);
-
-      // Procedure dummies are not mapped with an hlfir.declare because
-      // they are not "variable" (cannot be assigned to), and it would
-      // make hlfir.declare more complex than it needs to to allow this.
-      // Do a regular lookup.
-      if (Fortran::semantics::IsProcedure(sym))
-        return symMap->lookupSymbol(sym);
-
-      // Commonblock names are not variables, but in some lowerings (like
-      // OpenMP) it is useful to maintain the address of the commonblock in an
-      // MLIR value and query it. hlfir.declare need not be created for these.
-      if (sym.detailsIf<Fortran::semantics::CommonBlockDetails>())
-        return symMap->lookupSymbol(sym);
-
-      // For symbols to be privatized in OMP, the symbol is mapped to an
-      // instance of `SymbolBox::Intrinsic` (i.e. a direct mapping to an MLIR
-      // SSA value). This MLIR SSA value is the block argument to the
-      // `omp.private`'s `alloc` block. If this is the case, we return this
-      // `SymbolBox::Intrinsic` value.
-      if (Fortran::lower::SymbolBox v = symMap->lookupSymbol(sym))
-        return v;
-
-      return {};
-    }
+    if (std::optional<fir::FortranVariableOpInterface> var =
+            symMap->lookupVariableDefinition(sym)) {
+      auto exv = hlfir::translateToExtendedValue(toLocation(), *builder, *var,
+                                                 forceHlfirBase);
+      return exv.match(
+          [](mlir::Value x) -> Fortran::lower::SymbolBox {
+            return Fortran::lower::SymbolBox::Intrinsic{x};
+          },
+          [](auto x) -> Fortran::lower::SymbolBox { return x; });
+    }
+
+    // Entry character result represented as an argument pair
+    // needs to be represented in the symbol table even before
+    // we can create DeclareOp for it. The temporary mapping
+    // is EmboxCharOp that conveys the address and length information.
+    // After mapSymbolAttributes is done, the mapping is replaced
+    // with the new DeclareOp, and the following table lookups
+    // do not reach here.
+    if (sym.IsFuncResult())
+      if (const Fortran::semantics::DeclTypeSpec *declTy = sym.GetType())
+        if (declTy->category() ==
+            Fortran::semantics::DeclTypeSpec::Category::Character)
+          return symMap->lookupSymbol(sym);
+
+    // Procedure dummies are not mapped with an hlfir.declare because
+    // they are not "variable" (cannot be assigned to), and it would
+    // make hlfir.declare more complex than it needs to to allow this.
+    // Do a regular lookup.
+    if (Fortran::semantics::IsProcedure(sym))
+      return symMap->lookupSymbol(sym);
+
+    // Commonblock names are not variables, but in some lowerings (like
+    // OpenMP) it is useful to maintain the address of the commonblock in an
+    // MLIR value and query it. hlfir.declare need not be created for these.
+    if (sym.detailsIf<Fortran::semantics::CommonBlockDetails>())
+      return symMap->lookupSymbol(sym);
+
+    // For symbols to be privatized in OMP, the symbol is mapped to an
+    // instance of `SymbolBox::Intrinsic` (i.e. a direct mapping to an MLIR
+    // SSA value). This MLIR SSA value is the block argument to the
+    // `omp.private`'s `alloc` block. If this is the case, we return this
+    // `SymbolBox::Intrinsic` value.
     if (Fortran::lower::SymbolBox v = symMap->lookupSymbol(sym))
       return v;
+
     return {};
   }
 
@@ -1451,13 +1437,9 @@ class FirConverter : public 
Fortran::lower::AbstractConverter {
                  fir::ExtendedValue val, bool forced = false) {
     if (!forced && lookupSymbol(sym))
       return false;
-    if (lowerToHighLevelFIR()) {
-      Fortran::lower::genDeclareSymbol(*this, localSymbols, sym, val,
-                                       fir::FortranVariableFlagsEnum::None,
-                                       forced);
-    } else {
-      localSymbols.addSymbol(sym, val, forced);
-    }
+    Fortran::lower::genDeclareSymbol(*this, localSymbols, sym, val,
+                                     fir::FortranVariableFlagsEnum::None,
+                                     forced);
     return true;
   }
 
@@ -1466,17 +1448,12 @@ class FirConverter : public 
Fortran::lower::AbstractConverter {
                const Fortran::lower::SymbolBox &rhs_sb,
                Fortran::semantics::Symbol::Flags flags) {
     mlir::Location loc = genLocation(sym.name());
-    if (lowerToHighLevelFIR())
-      copyVarHLFIR(loc, lhs_sb, rhs_sb, flags);
-    else
-      copyVarFIR(loc, sym, lhs_sb, rhs_sb);
+    copyVarHLFIR(loc, lhs_sb, rhs_sb, flags);
   }
 
   void copyVarHLFIR(mlir::Location loc, Fortran::lower::SymbolBox dst,
                     Fortran::lower::SymbolBox src,
                     Fortran::semantics::Symbol::Flags flags) {
-    assert(lowerToHighLevelFIR());
-
     bool isBoxAllocatable = dst.match(
         [](const fir::MutableBoxValue &box) { return box.isAllocatable(); },
         [](const fir::FortranVariableOpInterface &box) {
@@ -1500,7 +1477,6 @@ class FirConverter : public 
Fortran::lower::AbstractConverter {
   void copyVarHLFIR(mlir::Location loc, Fortran::lower::SymbolBox dst,
                     Fortran::lower::SymbolBox src, bool isAllocatable,
                     bool isPointer, Fortran::semantics::Symbol::Flags flags) {
-    assert(lowerToHighLevelFIR());
     hlfir::Entity lhs{dst.getAddr()};
     hlfir::Entity rhs{src.getAddr()};
 
@@ -1589,26 +1565,6 @@ class FirConverter : public 
Fortran::lower::AbstractConverter {
     }
   }
 
-  void copyVarFIR(mlir::Location loc, const Fortran::semantics::Symbol &sym,
-                  const Fortran::lower::SymbolBox &lhs_sb,
-                  const Fortran::lower::SymbolBox &rhs_sb) {
-    assert(!lowerToHighLevelFIR());
-    fir::ExtendedValue lhs = symBoxToExtendedValue(lhs_sb);
-    fir::ExtendedValue rhs = symBoxToExtendedValue(rhs_sb);
-    mlir::Type symType = genType(sym);
-    if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(symType)) {
-      Fortran::lower::StatementContext stmtCtx;
-      Fortran::lower::createSomeArrayAssignment(*this, lhs, rhs, localSymbols,
-                                                stmtCtx);
-      stmtCtx.finalizeAndReset();
-    } else if (lhs.getBoxOf<fir::CharBoxValue>()) {
-      fir::factory::CharacterExprHelper{*builder, loc}.createAssign(lhs, rhs);
-    } else {
-      auto loadVal = fir::LoadOp::create(*builder, loc, fir::getBase(rhs));
-      fir::StoreOp::create(*builder, loc, loadVal, fir::getBase(lhs));
-    }
-  }
-
   /// Map a block argument to a result or dummy symbol. This is not the
   /// definitive mapping. The specification expression have not been lowered
   /// yet. The final mapping will be done using this pre-mapping in
@@ -2166,21 +2122,15 @@ class FirConverter : public 
Fortran::lower::AbstractConverter {
           dir->u);
     }
 
-    if (lowerToHighLevelFIR()) {
-      std::optional<mlir::Type> resultType;
-      if (stmt.typedCall->hasAlternateReturns())
-        resultType = builder->getIndexType();
-      auto hlfirRes = Fortran::lower::convertCallToHLFIR(
-          toLocation(), *this, *stmt.typedCall, resultType, localSymbols,
-          stmtCtx);
-      if (hlfirRes)
-        res = *hlfirRes;
-    } else {
-      // Call statement lowering shares code with function call lowering.
-      res = Fortran::lower::createSubroutineCall(
-          *this, *stmt.typedCall, explicitIterSpace, implicitIterSpace,
-          localSymbols, stmtCtx, /*isUserDefAssignment=*/false);
-    }
+    std::optional<mlir::Type> resultType;
+    if (stmt.typedCall->hasAlternateReturns())
+      resultType = builder->getIndexType();
+    auto hlfirRes =
+        Fortran::lower::convertCallToHLFIR(toLocation(), *this, 
*stmt.typedCall,
+                                           resultType, localSymbols, stmtCtx);
+    if (hlfirRes)
+      res = *hlfirRes;
+
     stmtCtx.finalizeAndReset();
     if (!res)
       return; // "Normal" subroutine call.
@@ -3426,24 +3376,7 @@ class FirConverter : public 
Fortran::lower::AbstractConverter {
     Fortran::common::visit([&](const auto &x) { genFIR(x); }, stmt.u);
   }
 
-  void genFIR(const Fortran::parser::EndForallStmt &) {
-    if (!lowerToHighLevelFIR())
-      cleanupExplicitSpace();
-  }
-
-  template <typename A>
-  void prepareExplicitSpace(const A &forall) {
-    if (!explicitIterSpace.isActive())
-      analyzeExplicitSpace(forall);
-    localSymbols.pushScope();
-    explicitIterSpace.enter();
-  }
-
-  /// Cleanup all the FORALL context information when we exit.
-  void cleanupExplicitSpace() {
-    explicitIterSpace.leave();
-    localSymbols.popScope();
-  }
+  void genFIR(const Fortran::parser::EndForallStmt &) {}
 
   /// Generate FIR for a FORALL statement.
   void genFIR(const Fortran::parser::ForallStmt &stmt) {
@@ -3452,31 +3385,19 @@ class FirConverter : public 
Fortran::lower::AbstractConverter {
             Fortran::common::Indirection<Fortran::parser::ConcurrentHeader>>(
             stmt.t)
             .value();
-    if (lowerToHighLevelFIR()) {
-      mlir::OpBuilder::InsertionGuard guard(*builder);
-      Fortran::lower::SymMapScope scope(localSymbols);
-      genForallNest(concurrentHeader);
-      genFIR(std::get<Fortran::parser::UnlabeledStatement<
-                 Fortran::parser::ForallAssignmentStmt>>(stmt.t)
-                 .statement);
-      return;
-    }
-    prepareExplicitSpace(stmt);
-    genFIR(concurrentHeader);
+    mlir::OpBuilder::InsertionGuard guard(*builder);
+    Fortran::lower::SymMapScope scope(localSymbols);
+    genForallNest(concurrentHeader);
     genFIR(std::get<Fortran::parser::UnlabeledStatement<
                Fortran::parser::ForallAssignmentStmt>>(stmt.t)
                .statement);
-    cleanupExplicitSpace();
   }
 
   /// Generate FIR for a FORALL construct.
   void genFIR(const Fortran::parser::ForallConstruct &forall) {
     setCurrentPositionAt(forall);
     mlir::OpBuilder::InsertPoint insertPt = builder->saveInsertionPoint();
-    if (lowerToHighLevelFIR())
-      localSymbols.pushScope();
-    else
-      prepareExplicitSpace(forall);
+    localSymbols.pushScope();
     genNestedStatement(
         std::get<
             Fortran::parser::Statement<Fortran::parser::ForallConstructStmt>>(
@@ -3494,10 +3415,8 @@ class FirConverter : public 
Fortran::lower::AbstractConverter {
     genNestedStatement(
         std::get<Fortran::parser::Statement<Fortran::parser::EndForallStmt>>(
             forall.t));
-    if (lowerToHighLevelFIR()) {
-      localSymbols.popScope();
-      builder->restoreInsertionPoint(insertPt);
-    }
+    localSymbols.popScope();
+    builder->restoreInsertionPoint(insertPt);
   }
 
   /// Lower the concurrent header specification.
@@ -3507,10 +3426,7 @@ class FirConverter : public 
Fortran::lower::AbstractConverter {
             Fortran::common::Indirection<Fortran::parser::ConcurrentHeader>>(
             stmt.t)
             .value();
-    if (lowerToHighLevelFIR())
-      genForallNest(concurrentHeader);
-    else
-      genFIR(concurrentHeader);
+    genForallNest(concurrentHeader);
   }
 
   /// Generate hlfir.forall and hlfir.forall_mask nest given a Forall
@@ -4345,12 +4261,7 @@ class FirConverter : public 
Fortran::lower::AbstractConverter {
   fir::ExtendedValue
   genAssociateSelector(const Fortran::lower::SomeExpr &selector,
                        Fortran::lower::StatementContext &stmtCtx) {
-    if (lowerToHighLevelFIR())
-      return genExprAddr(selector, stmtCtx);
-    return Fortran::lower::isArraySectionWithoutVectorSubscript(selector)
-               ? Fortran::lower::createSomeArrayBox(*this, selector,
-                                                    localSymbols, stmtCtx)
-               : genExprAddr(selector, stmtCtx);
+    return genExprAddr(selector, stmtCtx);
   }
 
   void genFIR(const Fortran::parser::AssociateConstruct &) {
@@ -5153,10 +5064,8 @@ class FirConverter : public 
Fortran::lower::AbstractConverter {
   inline fir::MutableBoxValue
   genExprMutableBox(mlir::Location loc,
                     const Fortran::lower::SomeExpr &expr) override final {
-    if (lowerToHighLevelFIR())
-      return Fortran::lower::convertExprToMutableBox(loc, *this, expr,
-                                                     localSymbols);
-    return Fortran::lower::createMutableBox(loc, *this, expr, localSymbols);
+    return Fortran::lower::convertExprToMutableBox(loc, *this, expr,
+                                                   localSymbols);
   }
 
   // Create the [newRank] array with the lower bounds to be passed to the
@@ -5183,61 +5092,6 @@ class FirConverter : public 
Fortran::lower::AbstractConverter {
     return fir::EmboxOp::create(*builder, loc, boxTy, boundArray, shapeOp);
   }
 
-  // Generate pointer assignment with possibly empty bounds-spec. R1035: a
-  // bounds-spec is a lower bound value.
-  void genNoHLFIRPointerAssignment(
-      mlir::Location loc, const Fortran::evaluate::Assignment &assign,
-      const Fortran::evaluate::Assignment::BoundsSpec &lbExprs) {
-    Fortran::lower::StatementContext stmtCtx;
-
-    assert(!lowerToHighLevelFIR() && "code should not be called with HFLIR");
-    if (Fortran::evaluate::IsProcedureDesignator(assign.rhs))
-      TODO(loc, "procedure pointer assignment");
-
-    std::optional<Fortran::evaluate::DynamicType> lhsType =
-        assign.lhs.GetType();
-    // Delegate pointer association to unlimited polymorphic pointer
-    // to the runtime. element size, type code, attribute and of
-    // course base_addr might need to be updated.
-    if (lhsType && lhsType->IsPolymorphic()) {
-      if (explicitIterationSpace())
-        TODO(loc, "polymorphic pointer assignment in FORALL");
-      llvm::SmallVector<mlir::Value> lbounds;
-      for (const Fortran::evaluate::ExtentExpr &lbExpr : lbExprs)
-        lbounds.push_back(
-            fir::getBase(genExprValue(toEvExpr(lbExpr), stmtCtx)));
-      fir::MutableBoxValue lhsMutableBox = genExprMutableBox(loc, assign.lhs);
-      if (Fortran::evaluate::UnwrapExpr<Fortran::evaluate::NullPointer>(
-              assign.rhs)) {
-        fir::factory::disassociateMutableBox(*builder, loc, lhsMutableBox);
-        return;
-      }
-      mlir::Value lhs = lhsMutableBox.getAddr();
-      mlir::Value rhs = fir::getBase(genExprBox(loc, assign.rhs, stmtCtx));
-      if (!lbounds.empty()) {
-        mlir::Value boundsDesc = createLboundArray(lbounds, loc);
-        Fortran::lower::genPointerAssociateLowerBounds(*builder, loc, lhs, rhs,
-                                                       boundsDesc);
-        return;
-      }
-      Fortran::lower::genPointerAssociate(*builder, loc, lhs, rhs);
-      return;
-    }
-
-    llvm::SmallVector<mlir::Value> lbounds;
-    for (const Fortran::evaluate::ExtentExpr &lbExpr : lbExprs)
-      lbounds.push_back(fir::getBase(genExprValue(toEvExpr(lbExpr), stmtCtx)));
-    if (explicitIterationSpace()) {
-      // Pointer assignment in FORALL context. Copy the rhs box value
-      // into the lhs box variable.
-      genArrayAssignment(assign, stmtCtx, lbounds);
-      return;
-    }
-    fir::MutableBoxValue lhs = genExprMutableBox(loc, assign.lhs);
-    Fortran::lower::associateMutableBox(*this, loc, lhs, assign.rhs, lbounds,
-                                        stmtCtx);
-  }
-
   void genPointerAssignment(mlir::Location loc,
                             const Fortran::evaluate::Assignment &assign) {
     if (isInsideHlfirForallOrWhere()) {
@@ -5421,75 +5275,6 @@ class FirConverter : public 
Fortran::lower::AbstractConverter {
     return fir::EmboxOp::create(*builder, loc, boxTy, boundArray, shapeOp);
   }
 
-  // Pointer assignment with bounds-remapping. R1036: a bounds-remapping is a
-  // pair, lower bound and upper bound.
-  void genNoHLFIRPointerAssignment(
-      mlir::Location loc, const Fortran::evaluate::Assignment &assign,
-      const Fortran::evaluate::Assignment::BoundsRemapping &boundExprs) {
-    assert(!lowerToHighLevelFIR() && "code should not be called with HFLIR");
-    Fortran::lower::StatementContext stmtCtx;
-    llvm::SmallVector<mlir::Value> lbounds;
-    llvm::SmallVector<mlir::Value> ubounds;
-    for (const std::pair<Fortran::evaluate::ExtentExpr,
-                         Fortran::evaluate::ExtentExpr> &pair : boundExprs) {
-      const Fortran::evaluate::ExtentExpr &lbExpr = pair.first;
-      const Fortran::evaluate::ExtentExpr &ubExpr = pair.second;
-      lbounds.push_back(fir::getBase(genExprValue(toEvExpr(lbExpr), stmtCtx)));
-      ubounds.push_back(fir::getBase(genExprValue(toEvExpr(ubExpr), stmtCtx)));
-    }
-
-    std::optional<Fortran::evaluate::DynamicType> lhsType =
-        assign.lhs.GetType();
-    std::optional<Fortran::evaluate::DynamicType> rhsType =
-        assign.rhs.GetType();
-    // Polymorphic lhs/rhs need more care. See F2018 10.2.2.3.
-    if ((lhsType && lhsType->IsPolymorphic()) ||
-        (rhsType && rhsType->IsPolymorphic())) {
-      if (explicitIterationSpace())
-        TODO(loc, "polymorphic pointer assignment in FORALL");
-
-      fir::MutableBoxValue lhsMutableBox = genExprMutableBox(loc, assign.lhs);
-      if (Fortran::evaluate::UnwrapExpr<Fortran::evaluate::NullPointer>(
-              assign.rhs)) {
-        fir::factory::disassociateMutableBox(*builder, loc, lhsMutableBox);
-        return;
-      }
-      mlir::Value lhs = lhsMutableBox.getAddr();
-      mlir::Value rhs = fir::getBase(genExprBox(loc, assign.rhs, stmtCtx));
-      mlir::Value boundsDesc = createBoundArray(lbounds, ubounds, loc);
-      Fortran::lower::genPointerAssociateRemapping(
-          *builder, loc, lhs, rhs, boundsDesc,
-          lhsType && rhsType && !lhsType->IsPolymorphic() &&
-              rhsType->IsPolymorphic());
-      return;
-    }
-    if (explicitIterationSpace()) {
-      // Pointer assignment in FORALL context. Copy the rhs box value
-      // into the lhs box variable.
-      genArrayAssignment(assign, stmtCtx, lbounds, ubounds);
-      return;
-    }
-    fir::MutableBoxValue lhs = genExprMutableBox(loc, assign.lhs);
-    if (Fortran::evaluate::UnwrapExpr<Fortran::evaluate::NullPointer>(
-            assign.rhs)) {
-      fir::factory::disassociateMutableBox(*builder, loc, lhs);
-      return;
-    }
-    // Do not generate a temp in case rhs is an array section.
-    fir::ExtendedValue rhs =
-        Fortran::lower::isArraySectionWithoutVectorSubscript(assign.rhs)
-            ? Fortran::lower::createSomeArrayBox(*this, assign.rhs,
-                                                 localSymbols, stmtCtx)
-            : genExprAddr(assign.rhs, stmtCtx);
-    fir::factory::associateMutableBoxWithRemap(*builder, loc, lhs, rhs, 
lbounds,
-                                               ubounds);
-    if (explicitIterationSpace()) {
-      mlir::ValueRange inners = explicitIterSpace.getInnerArgs();
-      if (!inners.empty())
-        fir::ResultOp::create(*builder, loc, inners);
-    }
-  }
-
   /// Given converted LHS and RHS of the assignment, materialize any
   /// implicit conversion of the RHS to the LHS type. The front-end
   /// usually already makes those explicit, except for non-standard
@@ -5871,233 +5656,23 @@ class FirConverter : public 
Fortran::lower::AbstractConverter {
                 const llvm::ArrayRef<const Fortran::parser::CompilerDirective 
*>
                     &dirs = {}) {
     mlir::Location loc = toLocation();
-    if (lowerToHighLevelFIR()) {
-      Fortran::common::visit(
-          Fortran::common::visitors{
-              [&](const Fortran::evaluate::Assignment::Intrinsic &) {
-                genDataAssignment(assign, /*userDefinedAssignment=*/nullptr,
-                                  dirs);
-              },
-              [&](const Fortran::evaluate::ProcedureRef &procRef) {
-                genDataAssignment(assign, /*userDefinedAssignment=*/&procRef,
-                                  dirs);
-              },
-              [&](const Fortran::evaluate::Assignment::BoundsSpec &lbExprs) {
-                genPointerAssignment(loc, assign);
-              },
-              [&](const Fortran::evaluate::Assignment::BoundsRemapping
-                      &boundExprs) { genPointerAssignment(loc, assign); },
-          },
-          assign.u);
-      return;
-    }
-    if (explicitIterationSpace()) {
-      Fortran::lower::createArrayLoads(*this, explicitIterSpace, localSymbols);
-      explicitIterSpace.genLoopNest();
-    }
-    Fortran::lower::StatementContext stmtCtx;
     Fortran::common::visit(
         Fortran::common::visitors{
-            // [1] Plain old assignment.
             [&](const Fortran::evaluate::Assignment::Intrinsic &) {
-              const Fortran::semantics::Symbol *sym =
-                  Fortran::evaluate::GetLastSymbol(assign.lhs);
-
-              if (!sym)
-                TODO(loc, "assignment to pointer result of function 
reference");
-
-              std::optional<Fortran::evaluate::DynamicType> lhsType =
-                  assign.lhs.GetType();
-              assert(lhsType && "lhs cannot be typeless");
-              std::optional<Fortran::evaluate::DynamicType> rhsType =
-                  assign.rhs.GetType();
-
-              // Assignment to/from polymorphic entities are done with the
-              // runtime.
-              if (lhsType->IsPolymorphic() ||
-                  lhsType->IsUnlimitedPolymorphic() ||
-                  (rhsType && (rhsType->IsPolymorphic() ||
-                               rhsType->IsUnlimitedPolymorphic()))) {
-                mlir::Value lhs;
-                if (Fortran::lower::isWholeAllocatable(assign.lhs))
-                  lhs = genExprMutableBox(loc, assign.lhs).getAddr();
-                else
-                  lhs = fir::getBase(genExprBox(loc, assign.lhs, stmtCtx));
-                mlir::Value rhs =
-                    fir::getBase(genExprBox(loc, assign.rhs, stmtCtx));
-                if ((lhsType->IsPolymorphic() ||
-                     lhsType->IsUnlimitedPolymorphic()) &&
-                    Fortran::lower::isWholeAllocatable(assign.lhs))
-                  fir::runtime::genAssignPolymorphic(*builder, loc, lhs, rhs);
-                else
-                  fir::runtime::genAssign(*builder, loc, lhs, rhs);
-                return;
-              }
-
-              // Note: No ad-hoc handling for pointers is required here. The
-              // target will be assigned as per 2018 10.2.1.3 p2. genExprAddr
-              // on a pointer returns the target address and not the address of
-              // the pointer variable.
-
-              if (assign.lhs.Rank() > 0 || explicitIterationSpace()) {
-                if (isDerivedCategory(lhsType->category()) &&
-                    Fortran::semantics::IsFinalizable(
-                        lhsType->GetDerivedTypeSpec()))
-                  TODO(loc, "derived-type finalization with array assignment");
-                // Array assignment
-                // See Fortran 2018 10.2.1.3 p5, p6, and p7
-                genArrayAssignment(assign, stmtCtx);
-                return;
-              }
-
-              // Scalar assignment
-              const bool isNumericScalar =
-                  isNumericScalarCategory(lhsType->category());
-              const bool isVector =
-                  isDerivedCategory(lhsType->category()) &&
-                  lhsType->GetDerivedTypeSpec().IsVectorType();
-              fir::ExtendedValue rhs = (isNumericScalar || isVector)
-                                           ? genExprValue(assign.rhs, stmtCtx)
-                                           : genExprAddr(assign.rhs, stmtCtx);
-              const bool lhsIsWholeAllocatable =
-                  Fortran::lower::isWholeAllocatable(assign.lhs);
-              std::optional<fir::factory::MutableBoxReallocation> lhsRealloc;
-              std::optional<fir::MutableBoxValue> lhsMutableBox;
-
-              // Set flag to know if the LHS needs finalization. Polymorphic,
-              // unlimited polymorphic assignment will be done with genAssign.
-              // Assign runtime function performs the finalization.
-              bool needFinalization = !lhsType->IsPolymorphic() &&
-                                      !lhsType->IsUnlimitedPolymorphic() &&
-                                      (isDerivedCategory(lhsType->category()) 
&&
-                                       Fortran::semantics::IsFinalizable(
-                                           lhsType->GetDerivedTypeSpec()));
-
-              auto lhs = [&]() -> fir::ExtendedValue {
-                if (lhsIsWholeAllocatable) {
-                  lhsMutableBox = genExprMutableBox(loc, assign.lhs);
-                  // Finalize if needed.
-                  if (needFinalization) {
-                    mlir::Value isAllocated =
-                        fir::factory::genIsAllocatedOrAssociatedTest(
-                            *builder, loc, *lhsMutableBox);
-                    builder->genIfThen(loc, isAllocated)
-                        .genThen([&]() {
-                          fir::runtime::genDerivedTypeDestroy(
-                              *builder, loc, fir::getBase(*lhsMutableBox));
-                        })
-                        .end();
-                    needFinalization = false;
-                  }
-
-                  llvm::SmallVector<mlir::Value> lengthParams;
-                  if (const fir::CharBoxValue *charBox = rhs.getCharBox())
-                    lengthParams.push_back(charBox->getLen());
-                  else if (fir::isDerivedWithLenParameters(rhs))
-                    TODO(loc, "assignment to derived type allocatable with "
-                              "LEN parameters");
-                  lhsRealloc = fir::factory::genReallocIfNeeded(
-                      *builder, loc, *lhsMutableBox,
-                      /*shape=*/{}, lengthParams);
-                  return lhsRealloc->newValue;
-                }
-                return genExprAddr(assign.lhs, stmtCtx);
-              }();
-
-              if (isNumericScalar || isVector) {
-                // Fortran 2018 10.2.1.3 p8 and p9
-                // Conversions should have been inserted by semantic analysis,
-                // but they can be incorrect between the rhs and lhs. Correct
-                // that here.
-                mlir::Value addr = fir::getBase(lhs);
-                mlir::Value val = fir::getBase(rhs);
-                // A function with multiple entry points returning 
diff erent
-                // types tags all result variables with one of the largest
-                // types to allow them to share the same storage. Assignment
-                // to a result variable of one of the other types requires
-                // conversion to the actual type.
-                mlir::Type toTy = genType(assign.lhs);
-
-                // If Cray pointee, need to handle the address
-                // Array is handled in genCoordinateOp.
-                if (sym->test(Fortran::semantics::Symbol::Flag::CrayPointee) &&
-                    sym->Rank() == 0) {
-                  // get the corresponding Cray pointer
-
-                  const Fortran::semantics::Symbol &ptrSym =
-                      Fortran::semantics::GetCrayPointer(*sym);
-                  fir::ExtendedValue ptr =
-                      getSymbolExtendedValue(ptrSym, nullptr);
-                  mlir::Value ptrVal = fir::getBase(ptr);
-                  mlir::Type ptrTy = genType(ptrSym);
-
-                  fir::ExtendedValue pte =
-                      getSymbolExtendedValue(*sym, nullptr);
-                  mlir::Value pteVal = fir::getBase(pte);
-                  mlir::Value cnvrt = Fortran::lower::addCrayPointerInst(
-                      loc, *builder, ptrVal, ptrTy, pteVal.getType());
-                  addr = fir::LoadOp::create(*builder, loc, cnvrt);
-                }
-                mlir::Value cast =
-                    isVector ? val
-                             : builder->convertWithSemantics(loc, toTy, val);
-                if (fir::dyn_cast_ptrEleTy(addr.getType()) != toTy) {
-                  assert(isFuncResultDesignator(assign.lhs) && "type 
mismatch");
-                  addr = builder->createConvert(
-                      toLocation(), builder->getRefType(toTy), addr);
-                }
-                fir::StoreOp::create(*builder, loc, cast, addr);
-              } else if (isCharacterCategory(lhsType->category())) {
-                // Fortran 2018 10.2.1.3 p10 and p11
-                fir::factory::CharacterExprHelper{*builder, loc}.createAssign(
-                    lhs, rhs);
-              } else if (isDerivedCategory(lhsType->category())) {
-                // Handle parent component.
-                if (Fortran::lower::isParentComponent(assign.lhs)) {
-                  if 
(!mlir::isa<fir::BaseBoxType>(fir::getBase(lhs).getType()))
-                    lhs = fir::getBase(builder->createBox(loc, lhs));
-                  lhs = Fortran::lower::updateBoxForParentComponent(*this, lhs,
-                                                                    
assign.lhs);
-                }
-
-                // Fortran 2018 10.2.1.3 p13 and p14
-                // Recursively gen an assignment on each element pair.
-                fir::factory::genRecordAssignment(*builder, loc, lhs, rhs,
-                                                  needFinalization);
-              } else {
-                llvm_unreachable("unknown category");
-              }
-              if (lhsIsWholeAllocatable) {
-                assert(lhsRealloc.has_value());
-                fir::factory::finalizeRealloc(*builder, loc, *lhsMutableBox,
-                                              /*lbounds=*/{},
-                                              /*takeLboundsIfRealloc=*/false,
-                                              *lhsRealloc);
-              }
+              genDataAssignment(assign, /*userDefinedAssignment=*/nullptr,
+                                dirs);
             },
-
-            // [2] User defined assignment. If the context is a scalar
-            // expression then call the procedure.
             [&](const Fortran::evaluate::ProcedureRef &procRef) {
-              Fortran::lower::StatementContext &ctx =
-                  explicitIterationSpace() ? explicitIterSpace.stmtContext()
-                                           : stmtCtx;
-              Fortran::lower::createSubroutineCall(
-                  *this, procRef, explicitIterSpace, implicitIterSpace,
-                  localSymbols, ctx, /*isUserDefAssignment=*/true);
+              genDataAssignment(assign, /*userDefinedAssignment=*/&procRef,
+                                dirs);
             },
-
             [&](const Fortran::evaluate::Assignment::BoundsSpec &lbExprs) {
-              return genNoHLFIRPointerAssignment(loc, assign, lbExprs);
+              genPointerAssignment(loc, assign);
             },
             [&](const Fortran::evaluate::Assignment::BoundsRemapping
-                    &boundExprs) {
-              return genNoHLFIRPointerAssignment(loc, assign, boundExprs);
-            },
+                    &boundExprs) { genPointerAssignment(loc, assign); },
         },
         assign.u);
-    if (explicitIterationSpace())
-      Fortran::lower::createArrayMergeStores(*this, explicitIterSpace);
   }
 
   // Is the insertion point of the builder directly or indirectly set
@@ -6121,26 +5696,17 @@ class FirConverter : public 
Fortran::lower::AbstractConverter {
   void genFIR(const Fortran::parser::WhereConstruct &c) {
     setCurrentPositionAt(c);
     mlir::Location loc = getCurrentLocation();
-    hlfir::WhereOp whereOp;
+    auto whereOp = hlfir::WhereOp::create(*builder, loc);
+    builder->createBlock(&whereOp.getMaskRegion());
 
-    if (!lowerToHighLevelFIR()) {
-      implicitIterSpace.growStack();
-    } else {
-      whereOp = hlfir::WhereOp::create(*builder, loc);
-      builder->createBlock(&whereOp.getMaskRegion());
-    }
-
-    // Lower the where mask. For HLFIR, this is done in the hlfir.where mask
-    // region.
+    // Lower the where mask in the hlfir.where mask region.
     genNestedStatement(
         std::get<
             Fortran::parser::Statement<Fortran::parser::WhereConstructStmt>>(
             c.t));
 
-    // Lower WHERE body. For HLFIR, this is done in the hlfir.where body
-    // region.
-    if (whereOp)
-      builder->createBlock(&whereOp.getBody());
+    // Lower WHERE body in the hlfir.where body region.
+    builder->createBlock(&whereOp.getBody());
 
     for (const auto &body :
          std::get<std::list<Fortran::parser::WhereBodyConstruct>>(c.t))
@@ -6158,12 +5724,10 @@ class FirConverter : public 
Fortran::lower::AbstractConverter {
         std::get<Fortran::parser::Statement<Fortran::parser::EndWhereStmt>>(
             c.t));
 
-    if (whereOp) {
-      // For HLFIR, create fir.end terminator in the last hlfir.elsewhere, or
-      // in the hlfir.where if it had no elsewhere.
-      fir::FirEndOp::create(*builder, loc);
-      builder->setInsertionPointAfter(whereOp);
-    }
+    // Create fir.end terminator in the last hlfir.elsewhere, or in the
+    // hlfir.where if it had no elsewhere.
+    fir::FirEndOp::create(*builder, loc);
+    builder->setInsertionPointAfter(whereOp);
   }
   void genFIR(const Fortran::parser::WhereBodyConstruct &body) {
     Fortran::common::visit(
@@ -6195,28 +5759,21 @@ class FirConverter : public 
Fortran::lower::AbstractConverter {
   void genFIR(const Fortran::parser::WhereConstructStmt &stmt) {
     const Fortran::semantics::SomeExpr *maskExpr = Fortran::semantics::GetExpr(
         std::get<Fortran::parser::LogicalExpr>(stmt.t));
-    if (lowerToHighLevelFIR())
-      lowerWhereMaskToHlfir(getCurrentLocation(), maskExpr);
-    else
-      implicitIterSpace.append(maskExpr);
+    lowerWhereMaskToHlfir(getCurrentLocation(), maskExpr);
   }
   void genFIR(const Fortran::parser::WhereConstruct::MaskedElsewhere &ew) {
     setCurrentPositionAt(ew);
     mlir::Location loc = getCurrentLocation();
-    hlfir::ElseWhereOp elsewhereOp;
-    if (lowerToHighLevelFIR()) {
-      elsewhereOp = hlfir::ElseWhereOp::create(*builder, loc);
-      // Lower mask in the mask region.
-      builder->createBlock(&elsewhereOp.getMaskRegion());
-    }
+    auto elsewhereOp = hlfir::ElseWhereOp::create(*builder, loc);
+    // Lower mask in the mask region.
+    builder->createBlock(&elsewhereOp.getMaskRegion());
     genNestedStatement(
         std::get<
             Fortran::parser::Statement<Fortran::parser::MaskedElsewhereStmt>>(
             ew.t));
 
-    // For HLFIR, lower the body in the hlfir.elsewhere body region.
-    if (elsewhereOp)
-      builder->createBlock(&elsewhereOp.getBody());
+    // Lower the body in the hlfir.elsewhere body region.
+    builder->createBlock(&elsewhereOp.getBody());
 
     for (const auto &body :
          std::get<std::list<Fortran::parser::WhereBodyConstruct>>(ew.t))
@@ -6225,18 +5782,13 @@ class FirConverter : public 
Fortran::lower::AbstractConverter {
   void genFIR(const Fortran::parser::MaskedElsewhereStmt &stmt) {
     const auto *maskExpr = Fortran::semantics::GetExpr(
         std::get<Fortran::parser::LogicalExpr>(stmt.t));
-    if (lowerToHighLevelFIR())
-      lowerWhereMaskToHlfir(getCurrentLocation(), maskExpr);
-    else
-      implicitIterSpace.append(maskExpr);
+    lowerWhereMaskToHlfir(getCurrentLocation(), maskExpr);
   }
   void genFIR(const Fortran::parser::WhereConstruct::Elsewhere &ew) {
     setCurrentPositionAt(ew);
-    if (lowerToHighLevelFIR()) {
-      auto elsewhereOp =
-          hlfir::ElseWhereOp::create(*builder, getCurrentLocation());
-      builder->createBlock(&elsewhereOp.getBody());
-    }
+    auto elsewhereOp =
+        hlfir::ElseWhereOp::create(*builder, getCurrentLocation());
+    builder->createBlock(&elsewhereOp.getBody());
     genNestedStatement(
         std::get<Fortran::parser::Statement<Fortran::parser::ElsewhereStmt>>(
             ew.t));
@@ -6244,35 +5796,22 @@ class FirConverter : public 
Fortran::lower::AbstractConverter {
          std::get<std::list<Fortran::parser::WhereBodyConstruct>>(ew.t))
       genFIR(body);
   }
-  void genFIR(const Fortran::parser::ElsewhereStmt &stmt) {
-    if (!lowerToHighLevelFIR())
-      implicitIterSpace.append(nullptr);
-  }
-  void genFIR(const Fortran::parser::EndWhereStmt &) {
-    if (!lowerToHighLevelFIR())
-      implicitIterSpace.shrinkStack();
-  }
+  void genFIR(const Fortran::parser::ElsewhereStmt &stmt) {}
+  void genFIR(const Fortran::parser::EndWhereStmt &) {}
 
   void genFIR(const Fortran::parser::WhereStmt &stmt) {
     Fortran::lower::StatementContext stmtCtx;
     const auto &assign = std::get<Fortran::parser::AssignmentStmt>(stmt.t);
     const auto *mask = Fortran::semantics::GetExpr(
         std::get<Fortran::parser::LogicalExpr>(stmt.t));
-    if (lowerToHighLevelFIR()) {
-      mlir::Location loc = getCurrentLocation();
-      auto whereOp = hlfir::WhereOp::create(*builder, loc);
-      builder->createBlock(&whereOp.getMaskRegion());
-      lowerWhereMaskToHlfir(loc, mask);
-      builder->createBlock(&whereOp.getBody());
-      genAssignment(*assign.typedAssignment->v);
-      fir::FirEndOp::create(*builder, loc);
-      builder->setInsertionPointAfter(whereOp);
-      return;
-    }
-    implicitIterSpace.growStack();
-    implicitIterSpace.append(mask);
+    mlir::Location loc = getCurrentLocation();
+    auto whereOp = hlfir::WhereOp::create(*builder, loc);
+    builder->createBlock(&whereOp.getMaskRegion());
+    lowerWhereMaskToHlfir(loc, mask);
+    builder->createBlock(&whereOp.getBody());
     genAssignment(*assign.typedAssignment->v);
-    implicitIterSpace.shrinkStack();
+    fir::FirEndOp::create(*builder, loc);
+    builder->setInsertionPointAfter(whereOp);
   }
 
   void genFIR(const Fortran::parser::PointerAssignmentStmt &stmt) {
@@ -6518,7 +6057,7 @@ class FirConverter : public 
Fortran::lower::AbstractConverter {
 
     // Always generate fir.dummy_scope even if there are no arguments.
     // It is currently used to create proper TBAA forest.
-    if (lowerToHighLevelFIR()) {
+    {
       mlir::Value scopeOp = fir::DummyScopeOp::create(*builder, toLocation());
       setDummyArgsScope(scopeOp);
     }
@@ -7308,10 +6847,6 @@ class FirConverter : public 
Fortran::lower::AbstractConverter {
 
   void createRuntimeTypeInfoGlobals() {}
 
-  bool lowerToHighLevelFIR() const {
-    return bridge.getLoweringOptions().getLowerToHighLevelFIR();
-  }
-
   // Returns the mangling prefix for the given constant expression.
   std::string getConstantExprManglePrefix(mlir::Location loc,
                                           const Fortran::lower::SomeExpr &expr,

diff  --git a/flang/lib/Lower/CallInterface.cpp 
b/flang/lib/Lower/CallInterface.cpp
index cd94f4d363061..e9059581c690a 100644
--- a/flang/lib/Lower/CallInterface.cpp
+++ b/flang/lib/Lower/CallInterface.cpp
@@ -226,8 +226,7 @@ Fortran::lower::CallerInterface::characterize() const {
   // ProcedureDesignator has no interface, or may mismatch in case of implicit
   // interface.
   if (!characteristic->HasExplicitInterface() ||
-      (converter.getLoweringOptions().getLowerToHighLevelFIR() &&
-       isExternalDefinedInSameCompilationUnit(procRef.proc()) &&
+      (isExternalDefinedInSameCompilationUnit(procRef.proc()) &&
        characteristic->CanBeCalledViaImplicitInterface())) {
     // In HLFIR lowering, calls to subprogram with implicit interfaces are
     // always prepared according to the actual arguments. This is to support
@@ -1173,9 +1172,6 @@ class Fortran::lower::CallInterfaceImpl {
       addPassedArg(PassEntityBy::MutableBox, entity, characteristics);
     } else if (obj.IsPassedByDescriptor(isBindC)) {
       // Pass as fir.box or fir.class
-      if (isValueAttr &&
-          !getConverter().getLoweringOptions().getLowerToHighLevelFIR())
-        TODO(loc, "assumed shape dummy argument with VALUE attribute");
       addFirOperand(boxType, nextPassedArgPosition(), Property::Box, attrs);
       addPassedArg(PassEntityBy::Box, entity, characteristics);
     } else if (dynamicType.category() ==
@@ -1233,11 +1229,6 @@ class Fortran::lower::CallInterfaceImpl {
       const DummyCharacteristics *characteristics,
       const Fortran::evaluate::characteristics::DummyProcedure &proc,
       const FortranEntity &entity) {
-    if (!interface.converter.getLoweringOptions().getLowerToHighLevelFIR() &&
-        proc.attrs.test(
-            Fortran::evaluate::characteristics::DummyProcedure::Attr::Pointer))
-      TODO(interface.converter.getCurrentLocation(),
-           "procedure pointer arguments");
     const Fortran::evaluate::characteristics::Procedure &procedure =
         proc.procedure.value();
     mlir::Type funcType =

diff  --git a/flang/lib/Lower/ConvertCall.cpp b/flang/lib/Lower/ConvertCall.cpp
index d9204976ea7d3..e6c89122bde23 100644
--- a/flang/lib/Lower/ConvertCall.cpp
+++ b/flang/lib/Lower/ConvertCall.cpp
@@ -145,12 +145,11 @@ static bool 
mustCastFuncOpToCopeWithImplicitInterfaceMismatch(
   // mismatch on the arguments. The argument are always prepared according
   // to the implicit interface. Cast the actual function if any of the
   // argument mismatch cannot be dealt with a simple fir.convert.
-  if (converter.getLoweringOptions().getLowerToHighLevelFIR())
-    for (auto [actualType, dummyType] :
-         llvm::zip(callSiteType.getInputs(), funcOpType.getInputs()))
-      if (actualType != dummyType &&
-          !fir::ConvertOp::canBeConverted(actualType, dummyType))
-        return true;
+  for (auto [actualType, dummyType] :
+       llvm::zip(callSiteType.getInputs(), funcOpType.getInputs()))
+    if (actualType != dummyType &&
+        !fir::ConvertOp::canBeConverted(actualType, dummyType))
+      return true;
   return false;
 }
 
@@ -408,7 +407,6 @@ Fortran::lower::genCallOpAndResult(
     }
   }
   const bool isExprCall =
-      converter.getLoweringOptions().getLowerToHighLevelFIR() &&
       callSiteType.getNumResults() == 1 &&
       llvm::isa<fir::SequenceType>(callSiteType.getResult(0));
 
@@ -622,8 +620,6 @@ Fortran::lower::genCallOpAndResult(
         // With the lowering to HLFIR, box arguments have already been built
         // according to the attributes, rank, bounds, and type they should 
have.
         // Do not attempt any reboxing here that could break this.
-        bool legacyLowering =
-            !converter.getLoweringOptions().getLowerToHighLevelFIR();
         // When dealing with a dummy character argument (fir.boxchar), the
         // effective argument might be a non-character raw pointer. This may
         // happen when calling an implicit interface that was previously called
@@ -635,7 +631,7 @@ Fortran::lower::genCallOpAndResult(
         cast = builder.createVolatileCast(loc, isVolatile, fst);
         cast = builder.convertWithSemantics(loc, snd, cast,
                                             allowCharacterConversions,
-                                            /*allowRebox=*/legacyLowering);
+                                            /*allowRebox=*/false);
       }
     }
     operands.push_back(cast);
@@ -845,9 +841,7 @@ Fortran::lower::genCallOpAndResult(
   // In HLFIR, this is skipped when the result does not need to be finalized
   // because the result is moved to an expression that will deal with the
   // finalization.
-  if (allocatedResult &&
-      (mustFinalizeResult ||
-       !converter.getLoweringOptions().getLowerToHighLevelFIR())) {
+  if (allocatedResult && mustFinalizeResult) {
     // The result must be optionally destroyed (if it is of a derived type
     // that may need finalization or deallocation of the components).
     // For an allocatable result we have to free the memory allocated

diff  --git a/flang/lib/Lower/ConvertConstant.cpp 
b/flang/lib/Lower/ConvertConstant.cpp
index 0feb78e7fe9a1..41d8703bfc8e1 100644
--- a/flang/lib/Lower/ConvertConstant.cpp
+++ b/flang/lib/Lower/ConvertConstant.cpp
@@ -497,18 +497,6 @@ static mlir::Value genInlinedStructureCtorLitImpl(
   fir::FirOpBuilder &builder = converter.getFirOpBuilder();
   auto recTy = mlir::cast<fir::RecordType>(type);
 
-  if (!converter.getLoweringOptions().getLowerToHighLevelFIR()) {
-    mlir::Value res = fir::UndefOp::create(builder, loc, recTy);
-    for (const auto &[sym, expr] : ctor.values()) {
-      // Parent components need more work because they do not appear in the
-      // fir.rec type.
-      if (sym->test(Fortran::semantics::Symbol::Flag::ParentComp))
-        TODO(loc, "parent component in structure constructor");
-      res = genStructureComponentInit(converter, loc, sym, expr.value(), res);
-    }
-    return res;
-  }
-
   auto fieldTy = fir::FieldType::get(recTy.getContext());
   mlir::Value res{};
   // When the first structure component values belong to some parent type PT

diff  --git a/flang/lib/Lower/ConvertType.cpp b/flang/lib/Lower/ConvertType.cpp
index 0d343968374f0..d2a5a978756fd 100644
--- a/flang/lib/Lower/ConvertType.cpp
+++ b/flang/lib/Lower/ConvertType.cpp
@@ -409,7 +409,7 @@ struct TypeBuilderImpl {
 
     // Gather the record type fields.
     // (1) The data components.
-    if (converter.getLoweringOptions().getLowerToHighLevelFIR()) {
+    {
       size_t prev_offset{0};
       unsigned padCounter{0};
       // In HLFIR the parent component is the first fir.type component.
@@ -454,34 +454,6 @@ struct TypeBuilderImpl {
           }
         }
       }
-    } else {
-      for (const auto &component :
-           Fortran::semantics::OrderedComponentIterator(tySpec)) {
-        // In the lowering to FIR the parent component does not appear in the
-        // fir.type and its components are inlined at the beginning of the
-        // fir.type<>.
-        // FIXME: this strategy leads to bugs because padding should be 
inserted
-        // after the component of the parents so that the next components do 
not
-        // end-up in the parent storage if the sum of the parent's component
-        // storage size is not a multiple of the parent type storage alignment.
-
-        // Lowering is assuming non deferred component lower bounds are
-        // always 1. Catch any situations where this is not true for now.
-        if (componentHasNonDefaultLowerBounds(component))
-          TODO(converter.genLocation(component.name()),
-               "derived type components with non default lower bounds");
-        if (IsProcedure(component))
-          TODO(converter.genLocation(component.name()), "procedure 
components");
-        mlir::Type ty = genSymbolType(component);
-        // Do not add the parent component (component of the parents are
-        // added and should be sufficient, the parent component would
-        // duplicate the fields). Note that genSymbolType must be called above
-        // on it so that the dispatch table for the parent type still gets
-        // emitted as needed.
-        if (component.test(Fortran::semantics::Symbol::Flag::ParentComp))
-          continue;
-        cs.emplace_back(converter.getRecordTypeFieldName(component), ty);
-      }
     }
 
     mlir::Location loc = converter.genLocation(typeSymbol.name());

diff  --git a/flang/lib/Lower/ConvertVariable.cpp 
b/flang/lib/Lower/ConvertVariable.cpp
index 05b3fb4a5d370..91222490fc395 100644
--- a/flang/lib/Lower/ConvertVariable.cpp
+++ b/flang/lib/Lower/ConvertVariable.cpp
@@ -66,15 +66,10 @@ static mlir::Value 
genScalarValue(Fortran::lower::AbstractConverter &converter,
                                   Fortran::lower::StatementContext &context) {
   // This does not use the AbstractConverter member function to override the
   // symbol mapping to be used expression lowering.
-  if (converter.getLoweringOptions().getLowerToHighLevelFIR()) {
-    hlfir::EntityWithAttributes loweredExpr =
-        Fortran::lower::convertExprToHLFIR(loc, converter, expr, symMap,
-                                           context);
-    return hlfir::loadTrivialScalar(loc, converter.getFirOpBuilder(),
-                                    loweredExpr);
-  }
-  return fir::getBase(Fortran::lower::createSomeExtendedExpression(
-      loc, converter, expr, symMap, context));
+  hlfir::EntityWithAttributes loweredExpr =
+      Fortran::lower::convertExprToHLFIR(loc, converter, expr, symMap, 
context);
+  return hlfir::loadTrivialScalar(loc, converter.getFirOpBuilder(),
+                                  loweredExpr);
 }
 
 /// Does this variable have a default initialization?
@@ -255,11 +250,8 @@ fir::ExtendedValue Fortran::lower::genExtAddrInInitializer(
                                         storeMap);
   }
 
-  if (converter.getLoweringOptions().getLowerToHighLevelFIR())
-    return Fortran::lower::convertExprToAddress(loc, converter, addr,
-                                                globalOpSymMap, stmtCtx);
-  return Fortran::lower::createInitializerAddress(loc, converter, addr,
-                                                  globalOpSymMap, stmtCtx);
+  return Fortran::lower::convertExprToAddress(loc, converter, addr,
+                                              globalOpSymMap, stmtCtx);
 }
 
 /// create initial-data-target fir.box in a global initializer region.
@@ -326,23 +318,11 @@ mlir::Value Fortran::lower::genInitialDataTarget(
 
   mlir::Value targetBox;
   mlir::Value targetShift;
-  if (converter.getLoweringOptions().getLowerToHighLevelFIR()) {
+  {
     auto target = Fortran::lower::convertExprToBox(
         loc, converter, initialTarget, globalOpSymMap, stmtCtx);
     targetBox = fir::getBase(target);
     targetShift = builder.createShape(loc, target);
-  } else {
-    if (initialTarget.Rank() > 0) {
-      auto target = Fortran::lower::createSomeArrayBox(converter, 
initialTarget,
-                                                       globalOpSymMap, 
stmtCtx);
-      targetBox = fir::getBase(target);
-      targetShift = builder.createShape(loc, target);
-    } else {
-      fir::ExtendedValue addr = Fortran::lower::createInitializerAddress(
-          loc, converter, initialTarget, globalOpSymMap, stmtCtx);
-      targetBox = builder.createBox(loc, addr);
-      // Nothing to do for targetShift, the target is a scalar.
-    }
   }
   // The targetBox is a fir.box<T>, not a fir.box<fir.ptr<T>> as it should for
   // pointers (this matters to get the POINTER attribute correctly inside the
@@ -446,36 +426,21 @@ static mlir::Value genDefaultInitializerValue(
   const Fortran::semantics::DeclTypeSpec *declTy = sym.GetType();
   assert(declTy && "var with default initialization must have a type");
 
-  if (converter.getLoweringOptions().getLowerToHighLevelFIR()) {
-    // In HLFIR, the parent type is the first component, while in FIR there is
-    // not parent component in the fir.type and the component of the parent are
-    // "inlined" at the beginning of the fir.type.
-    const Fortran::semantics::Symbol &typeSymbol =
-        declTy->derivedTypeSpec().typeSymbol();
-    const Fortran::semantics::Scope *derivedScope =
-        declTy->derivedTypeSpec().GetScope();
-    assert(derivedScope && "failed to retrieve derived type scope");
-    for (const auto &componentName :
-         typeSymbol.get<Fortran::semantics::DerivedTypeDetails>()
-             .componentNames()) {
-      auto scopeIter = derivedScope->find(componentName);
-      assert(scopeIter != derivedScope->cend() &&
-             "failed to find derived type component symbol");
-      const Fortran::semantics::Symbol &component = scopeIter->second.get();
-      initialValue = genComponentDefaultInit(converter, loc, component, recTy,
-                                             initialValue, stmtCtx);
-    }
-  } else {
-    Fortran::semantics::OrderedComponentIterator components(
-        declTy->derivedTypeSpec());
-    for (const auto &component : components) {
-      // Skip parent components, the sub-components of parent types are part of
-      // components and will be looped through right after.
-      if (component.test(Fortran::semantics::Symbol::Flag::ParentComp))
-        continue;
-      initialValue = genComponentDefaultInit(converter, loc, component, recTy,
-                                             initialValue, stmtCtx);
-    }
+  // In HLFIR, the parent type is the first component of the fir.type.
+  const Fortran::semantics::Symbol &typeSymbol =
+      declTy->derivedTypeSpec().typeSymbol();
+  const Fortran::semantics::Scope *derivedScope =
+      declTy->derivedTypeSpec().GetScope();
+  assert(derivedScope && "failed to retrieve derived type scope");
+  for (const auto &componentName :
+       typeSymbol.get<Fortran::semantics::DerivedTypeDetails>()
+           .componentNames()) {
+    auto scopeIter = derivedScope->find(componentName);
+    assert(scopeIter != derivedScope->cend() &&
+           "failed to find derived type component symbol");
+    const Fortran::semantics::Symbol &component = scopeIter->second.get();
+    initialValue = genComponentDefaultInit(converter, loc, component, recTy,
+                                           initialValue, stmtCtx);
   }
 
   if (sequenceType) {
@@ -544,10 +509,6 @@ fir::GlobalOp Fortran::lower::defineGlobal(
   if (global && globalIsInitialized(global))
     return global;
 
-  if (!converter.getLoweringOptions().getLowerToHighLevelFIR() &&
-      Fortran::semantics::IsProcedurePointer(sym))
-    TODO(loc, "procedure pointer globals");
-
   const auto *oeDetails =
       sym.detailsIf<Fortran::semantics::ObjectEntityDetails>();
 
@@ -1935,8 +1896,7 @@ static void 
genDeclareSymbol(Fortran::lower::AbstractConverter &converter,
   // Commonblock names are not variables, but in some lowerings (like OpenMP) 
it
   // is useful to maintain the address of the commonblock in an MLIR value and
   // query it. hlfir.declare need not be created for these.
-  if (converter.getLoweringOptions().getLowerToHighLevelFIR() &&
-      (!Fortran::semantics::IsProcedure(sym) ||
+  if ((!Fortran::semantics::IsProcedure(sym) ||
        Fortran::semantics::IsPointer(sym)) &&
       !sym.detailsIf<Fortran::semantics::CommonBlockDetails>()) {
     fir::FirOpBuilder &builder = converter.getFirOpBuilder();
@@ -2043,8 +2003,7 @@ void Fortran::lower::genDeclareSymbol(
     Fortran::lower::SymMap &symMap, const Fortran::semantics::Symbol &sym,
     const fir::ExtendedValue &exv, fir::FortranVariableFlagsEnum extraFlags,
     bool force) {
-  if (converter.getLoweringOptions().getLowerToHighLevelFIR() &&
-      (!Fortran::semantics::IsProcedure(sym) ||
+  if ((!Fortran::semantics::IsProcedure(sym) ||
        Fortran::semantics::IsPointer(sym.GetUltimate())) &&
       !sym.detailsIf<Fortran::semantics::CommonBlockDetails>()) {
     fir::FirOpBuilder &builder = converter.getFirOpBuilder();
@@ -2087,10 +2046,6 @@ 
genAllocatableOrPointerDeclare(Fortran::lower::AbstractConverter &converter,
                                Fortran::lower::SymMap &symMap,
                                const Fortran::semantics::Symbol &sym,
                                fir::MutableBoxValue box, bool force = false) {
-  if (!converter.getLoweringOptions().getLowerToHighLevelFIR()) {
-    symMap.addAllocatableOrPointer(sym, box, force);
-    return;
-  }
   assert(!box.isDescribedByVariables() &&
          "HLFIR alloctables/pointers must be fir.ref<fir.box>");
   mlir::Value base = box.getAddr();
@@ -2125,15 +2080,10 @@ static void 
genBoxDeclare(Fortran::lower::AbstractConverter &converter,
                           llvm::ArrayRef<mlir::Value> explicitParams,
                           llvm::ArrayRef<mlir::Value> explicitExtents,
                           bool replace = false) {
-  if (converter.getLoweringOptions().getLowerToHighLevelFIR()) {
-    fir::BoxValue boxValue{box, lbounds, explicitParams, explicitExtents};
-    Fortran::lower::genDeclareSymbol(
-        converter, symMap, sym, std::move(boxValue),
-        fir::FortranVariableFlagsEnum::None, replace);
-    return;
-  }
-  symMap.addBoxSymbol(sym, box, lbounds, explicitParams, explicitExtents,
-                      replace);
+  fir::BoxValue boxValue{box, lbounds, explicitParams, explicitExtents};
+  Fortran::lower::genDeclareSymbol(converter, symMap, sym, std::move(boxValue),
+                                   fir::FortranVariableFlagsEnum::None,
+                                   replace);
 }
 
 /// Lower specification expressions and attributes of variable \p var and
@@ -2228,8 +2178,6 @@ void Fortran::lower::mapSymbolAttributes(
     }
     fir::MutableBoxValue box = Fortran::lower::createMutableBox(
         converter, loc, var, boxAlloc, nonDeferredLenParams,
-        /*alwaysUseBox=*/
-        converter.getLoweringOptions().getLowerToHighLevelFIR(),
         Fortran::lower::getAllocatorIdx(var.getSymbol()));
     genAllocatableOrPointerDeclare(converter, symMap, var.getSymbol(), box,
                                    replace);

diff  --git a/flang/lib/Lower/HostAssociations.cpp 
b/flang/lib/Lower/HostAssociations.cpp
index ad6aba1d28ae4..93d0d748197d2 100644
--- a/flang/lib/Lower/HostAssociations.cpp
+++ b/flang/lib/Lower/HostAssociations.cpp
@@ -74,11 +74,8 @@ static void bindCapturedSymbol(const 
Fortran::semantics::Symbol &sym,
                                fir::ExtendedValue val,
                                Fortran::lower::AbstractConverter &converter,
                                Fortran::lower::SymMap &symMap) {
-  if (converter.getLoweringOptions().getLowerToHighLevelFIR())
-    Fortran::lower::genDeclareSymbol(converter, symMap, sym, val,
-                                     
fir::FortranVariableFlagsEnum::host_assoc);
-  else
-    symMap.addSymbol(sym, val);
+  Fortran::lower::genDeclareSymbol(converter, symMap, sym, val,
+                                   fir::FortranVariableFlagsEnum::host_assoc);
 }
 
 namespace {

diff  --git a/flang/tools/bbc/bbc.cpp b/flang/tools/bbc/bbc.cpp
index a21865f9c5ffe..bc6e9eb67e132 100644
--- a/flang/tools/bbc/bbc.cpp
+++ b/flang/tools/bbc/bbc.cpp
@@ -217,10 +217,6 @@ static llvm::cl::opt<bool> enableNoPPCNativeVecElemOrder(
     llvm::cl::desc("no PowerPC native vector element order."),
     llvm::cl::init(false));
 
-static llvm::cl::opt<bool> useHLFIR("hlfir",
-                                    llvm::cl::desc("Lower to high level FIR"),
-                                    llvm::cl::init(true));
-
 static llvm::cl::opt<bool> enableCUDA("fcuda",
                                       llvm::cl::desc("enable CUDA Fortran"),
                                       llvm::cl::init(false));
@@ -468,7 +464,6 @@ static llvm::LogicalResult convertFortranSourceToMLIR(
   // Use default lowering options for bbc.
   Fortran::lower::LoweringOptions loweringOptions{};
   loweringOptions.setNoPPCNativeVecElemOrder(enableNoPPCNativeVecElemOrder);
-  loweringOptions.setLowerToHighLevelFIR(useHLFIR || emitHLFIR);
   loweringOptions.setIntegerWrapAround(integerWrapAround);
   loweringOptions.setInitGlobalZero(initGlobalZero);
   loweringOptions.setReallocateLHS(reallocateLHS);
@@ -550,7 +545,7 @@ static llvm::LogicalResult convertFortranSourceToMLIR(
       return mlir::failure();
     }
 
-    if (emitFIR && useHLFIR) {
+    if (emitFIR) {
       // lower HLFIR to FIR
       fir::EnableOpenMP enableOmp =
           enableOpenMP ? fir::EnableOpenMP::Full : fir::EnableOpenMP::None;


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to