//===- MaterializationUtils.cpp - Builds and manipulates coroutine frame //-------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // This file contains classes used to materialize insts after suspends points. //===----------------------------------------------------------------------===// #include "llvm/Transforms/Coroutines/MaterializationUtils.h" #include "CoroInternal.h" #include "llvm/ADT/PostOrderIterator.h" #include "llvm/IR/Dominators.h" #include "llvm/IR/InstIterator.h" #include "llvm/IR/Instruction.h" #include "llvm/Transforms/Coroutines/SpillUtils.h" #include <deque> usingnamespacellvm; usingnamespacecoro; // The "coro-suspend-crossing" flag is very noisy. There is another debug type, // "coro-frame", which results in leaner debug spew. #define DEBUG_TYPE … namespace { // RematGraph is used to construct a DAG for rematerializable instructions // When the constructor is invoked with a candidate instruction (which is // materializable) it builds a DAG of materializable instructions from that // point. // Typically, for each instruction identified as re-materializable across a // suspend point, a RematGraph will be created. struct RematGraph { … }; } // namespace namespace llvm { template <> struct GraphTraits<RematGraph *> { … }; } // end namespace llvm // For each instruction identified as materializable across the suspend point, // and its associated DAG of other rematerializable instructions, // recreate the DAG of instructions after the suspend point. static void rewriteMaterializableInstructions( const SmallMapVector<Instruction *, std::unique_ptr<RematGraph>, 8> &AllRemats) { … } /// Default materializable callback // Check for instructions that we can recreate on resume as opposed to spill // the result into a coroutine frame. bool llvm::coro::defaultMaterializable(Instruction &V) { … } bool llvm::coro::isTriviallyMaterializable(Instruction &V) { … } #ifndef NDEBUG static void dumpRemats( StringRef Title, const SmallMapVector<Instruction *, std::unique_ptr<RematGraph>, 8> &RM) { dbgs() << "------------- " << Title << "--------------\n"; for (const auto &E : RM) { E.second->dump(); dbgs() << "--\n"; } } #endif void coro::doRematerializations( Function &F, SuspendCrossingInfo &Checker, std::function<bool(Instruction &)> IsMaterializable) { … }