19 std::string debugString(
"{");
24 debugString += isFirst ?
"" :
", ";
25 debugString += variable.name();
43 ReadSet().DebugString(),
46 AllWriteSet().DebugString(),
49 FullWriteSet().DebugString(),
52 TopSet_.DebugString(),
61 &&
TopSet_ == otherEntryDemandSet->TopSet_;
71 ReadSet().DebugString(),
74 AllWriteSet().DebugString(),
77 FullWriteSet().DebugString(),
95 ReadSet().DebugString(),
98 AllWriteSet().DebugString(),
101 FullWriteSet().DebugString(),
119 ReadSet().DebugString(),
122 AllWriteSet().DebugString(),
125 FullWriteSet().DebugString(),
143 ReadSet().DebugString(),
146 AllWriteSet().DebugString(),
149 FullWriteSet().DebugString(),
152 InputVariables().DebugString(),
155 OutputVariables().DebugString(),
175 ReadSet().DebugString(),
178 AllWriteSet().DebugString(),
181 FullWriteSet().DebugString(),
184 LoopVariables_.DebugString(),
204 for (
auto & argument : entryAggregationNode)
206 allWriteSet.
Insert(argument);
207 fullWriteSet.
Insert(argument);
212 demandMap.
Insert(entryAggregationNode, std::move(demandSet));
219 for (
auto & result : exitAggregationNode)
223 demandMap.
Insert(exitAggregationNode, std::move(demandSet));
231 auto & threeAddressCodeList = basicBlockAggregationNode.
tacs();
236 for (
auto it = threeAddressCodeList.rbegin(); it != threeAddressCodeList.rend(); it++)
239 if (is<AssignmentOperation>(tac->operation()))
245 JLM_ASSERT(tac->noperands() == 2 && tac->nresults() == 0);
246 readSet.
Remove(*tac->operand(0));
247 allWriteSet.
Insert(*tac->operand(0));
248 fullWriteSet.
Insert(*tac->operand(0));
249 readSet.
Insert(*tac->operand(1));
253 for (
size_t n = 0; n < tac->nresults(); n++)
255 readSet.
Remove(*tac->result(n));
256 allWriteSet.
Insert(*tac->result(n));
257 fullWriteSet.
Insert(*tac->result(n));
259 for (
size_t n = 0; n < tac->noperands(); n++)
260 readSet.
Insert(*tac->operand(n));
266 std::move(allWriteSet),
267 std::move(fullWriteSet));
268 demandMap.
Insert(basicBlockAggregationNode, std::move(demandSet));
277 for (
size_t n = linearAggregationNode.
nchildren() - 1; n !=
static_cast<size_t>(-1); n--)
281 readSet.
Remove(childDemandSet.FullWriteSet());
282 readSet.
Insert(childDemandSet.ReadSet());
283 allWriteSet.
Insert(childDemandSet.AllWriteSet());
284 fullWriteSet.
Insert(childDemandSet.FullWriteSet());
289 std::move(allWriteSet),
290 std::move(fullWriteSet));
291 demandMap.
Insert(linearAggregationNode, std::move(demandSet));
298 auto & case0ReadSet = case0DemandSet.
ReadSet();
299 auto & case0AllWriteSet = case0DemandSet.AllWriteSet();
300 auto & case0FullWriteSet = case0DemandSet.FullWriteSet();
305 for (
size_t n = 1; n < branchAggregationNode.
nchildren(); n++)
309 branchAllWriteSet.
Insert(caseDemandSet.AllWriteSet());
310 branchFullWriteSet.
Intersect(caseDemandSet.FullWriteSet());
311 branchReadSet.
Insert(caseDemandSet.ReadSet());
315 std::move(branchReadSet),
316 std::move(branchAllWriteSet),
317 std::move(branchFullWriteSet));
318 demandMap.
Insert(branchAggregationNode, std::move(branchDemandSet));
324 auto & loopBody = *loopAggregationNode.
child(0);
328 bodyDemandSet.ReadSet(),
329 bodyDemandSet.AllWriteSet(),
330 bodyDemandSet.FullWriteSet());
331 demandMap.
Insert(loopAggregationNode, std::move(demandSet));
337 for (
size_t n = 0; n < aggregationNode.
nchildren(); n++)
381 workingSet.
Remove(demandSet.FullWriteSet());
383 demandSet.TopSet_ = workingSet;
393 workingSet.
Insert(demandSet.ReadSet());
403 workingSet.
Remove(demandSet.FullWriteSet());
404 workingSet.
Insert(demandSet.ReadSet());
415 for (
size_t n = linearAggregationNode.
nchildren() - 1; n !=
static_cast<size_t>(-1); n--)
418 workingSet.
Remove(demandSet.FullWriteSet());
419 workingSet.
Insert(demandSet.ReadSet());
431 branchWorkingSet.
Intersect(demandSet.AllWriteSet());
432 demandSet.SetOutputVariables(branchWorkingSet);
434 for (
size_t n = 0; n < branchAggregationNode.
nchildren(); n++)
436 auto caseWorkingSet = branchWorkingSet;
440 branchWorkingSet.Remove(demandSet.FullWriteSet());
441 branchWorkingSet.Insert(demandSet.ReadSet());
442 demandSet.SetInputVariables(branchWorkingSet);
444 workingSet.
Insert(branchWorkingSet);
455 workingSet.
Insert(demandSet.ReadSet());
456 demandSet.SetLoopVariables(workingSet);
468 AnnotateDemandSet(*
static_cast<const T *
>(aggregationNode), workingSet, demandMap);
477 static std::unordered_map<
487 JLM_ASSERT(map.find(
typeid(aggregationNode)) != map.end());
488 return map[
typeid(aggregationNode)](&aggregationNode, workingSet, demandMap);
491 std::unique_ptr<AnnotationMap>
size_t nchildren() const noexcept
AggregationNode * child(size_t n) const noexcept
T & Lookup(const AggregationNode &aggregationNode) const noexcept
static std::unique_ptr< AnnotationMap > Create()
void Insert(const AggregationNode &aggregationNode, std::unique_ptr< AnnotationSet > annotationSet)
virtual ~AnnotationSet() noexcept
const VariableSet & ReadSet() const noexcept
virtual bool operator==(const AnnotationSet &other) const
const ThreeAddressCodeList & tacs() const noexcept
~BasicBlockAnnotationSet() noexcept override
bool operator==(const AnnotationSet &other) const override
static std::unique_ptr< BasicBlockAnnotationSet > Create(VariableSet readSet, VariableSet allWriteSet, VariableSet fullWriteSet)
VariableSet InputVariables_
bool operator==(const AnnotationSet &other) const override
VariableSet OutputVariables_
static std::unique_ptr< BranchAnnotationSet > Create(VariableSet readSet, VariableSet allWriteSet, VariableSet fullWriteSet)
~BranchAnnotationSet() noexcept override
static std::unique_ptr< EntryAnnotationSet > Create(VariableSet readSet, VariableSet allWriteSet, VariableSet fullWriteSet)
bool operator==(const AnnotationSet &other) const override
~ExitAnnotationSet() noexcept override
bool operator==(const AnnotationSet &other) const override
static std::unique_ptr< ExitAnnotationSet > Create(VariableSet readSet, VariableSet allWriteSet, VariableSet fullWriteSet)
~LinearAnnotationSet() noexcept override
static std::unique_ptr< LinearAnnotationSet > Create(VariableSet readSet, VariableSet allWriteSet, VariableSet fullWriteSet)
bool operator==(const AnnotationSet &other) const override
~LoopAnnotationSet() noexcept override
static std::unique_ptr< LoopAnnotationSet > Create(VariableSet readSet, VariableSet allWriteSet, VariableSet fullWriteSet)
VariableSet LoopVariables_
bool operator==(const AnnotationSet &other) const override
void Insert(const Variable &v)
std::string DebugString() const noexcept
ConstRange Variables() const noexcept
void Remove(const Variable &v)
void Intersect(const VariableSet &variableSet)
#define JLM_UNREACHABLE(msg)
Global memory state passed between functions.
static void AnnotateReadWrite(const AggregationNode &, AnnotationMap &)
static void AnnotateDemandSet(const AggregationNode &, VariableSet &, AnnotationMap &)
std::unique_ptr< AnnotationMap > Annotate(const AggregationNode &aggregationTreeRoot)
static std::string strfmt(Args... args)