FLANG
ScheduleOrderedAssignments.h
1//===- ScheduleOrderedAssignments.h --- Assignment scheduling ---*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8// This file defines a utility to analyze and schedule the evaluation of
9// of hlfir::OrderedAssignmentTreeOpInterface trees that represent Fortran
10// Forall, Where, user defined assignments and assignments to vector
11// subscripted entities.
12//===----------------------------------------------------------------------===//
13
14#ifndef OPTIMIZER_HLFIR_TRANSFORM_SCHEDULEORDEREDASSIGNMENTS_H
15#define OPTIMIZER_HLFIR_TRANSFORM_SCHEDULEORDEREDASSIGNMENTS_H
16
17#include "flang/Optimizer/HLFIR/HLFIROps.h"
18#include "mlir/Interfaces/SideEffectInterfaces.h"
19#include <list>
20
21namespace hlfir {
22
24 // build an elemental tree given a masked region terminator.
25 static ElementalTree buildElementalTree(mlir::Operation &regionTerminator);
26 // Check if op is an ElementalOpInterface that is part of this elemental tree.
27 bool contains(mlir::Operation *op) const;
28
29 std::optional<bool> isOrdered(mlir::Operation *op) const;
30
31private:
32 void gatherElementalTree(hlfir::ElementalOpInterface elemental,
33 bool isAppliedInOrder);
34 void insert(hlfir::ElementalOpInterface elementalOp, bool isAppliedInOrder);
35 // List of ElementalOpInterface operation forming this tree, as well as a
36 // Boolean to indicate if they are applied in order (that is, if their
37 // indexing space is the same as the one for the array yielded by the mask
38 // region that owns this tree).
40};
41
47struct SaveEntity {
48 mlir::Region *yieldRegion;
50 mlir::Value getSavedValue();
51};
52
58class DetailedEffectInstance {
59public:
60 DetailedEffectInstance(mlir::MemoryEffects::Effect *effect,
61 mlir::OpOperand *value = nullptr,
62 mlir::Value orderedElementalEffectOn = nullptr);
63 DetailedEffectInstance(mlir::MemoryEffects::EffectInstance effectInstance,
64 mlir::Value orderedElementalEffectOn = nullptr);
65
66 static DetailedEffectInstance getArrayReadEffect(mlir::OpOperand *array);
67 static DetailedEffectInstance getArrayWriteEffect(mlir::OpOperand *array);
68
69 mlir::Value getValue() const { return effectInstance.getValue(); }
70 mlir::MemoryEffects::Effect *getEffect() const {
71 return effectInstance.getEffect();
72 }
73 mlir::Value getOrderedElementalEffectOn() const {
74 return orderedElementalEffectOn;
75 }
76
77private:
78 mlir::MemoryEffects::EffectInstance effectInstance;
79 // Array whose elements are affected in array order by the
80 // ordered assignment iterations. Null value otherwise.
81 mlir::Value orderedElementalEffectOn;
82};
83
92struct Run {
95 using Action = std::variant<hlfir::RegionAssignOp, SaveEntity>;
98};
99
101using Schedule = std::list<Run>;
102
137
144Schedule buildEvaluationSchedule(hlfir::OrderedAssignmentTreeOpInterface root,
145 bool tryFusingAssignments);
146
147} // namespace hlfir
148#endif // OPTIMIZER_HLFIR_TRANSFORM_SCHEDULEORDERASSIGNMENTS_H
Definition OpenACC.h:20
Definition ScheduleOrderedAssignments.h:23
Definition ScheduleOrderedAssignments.h:92
std::variant< hlfir::RegionAssignOp, SaveEntity > Action
Definition ScheduleOrderedAssignments.h:95
Definition ScheduleOrderedAssignments.h:47
mlir::Value getSavedValue()
Returns the hlfir.yield op argument.
Definition ScheduleOrderedAssignments.cpp:919