llvm/llvm/lib/Transforms/Coroutines/SuspendCrossingInfo.cpp

//===- SuspendCrossingInfo.cpp - Utility for suspend crossing values ------===//
//
// 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
//
//===----------------------------------------------------------------------===//
// The SuspendCrossingInfo maintains data that allows to answer a question
// whether given two BasicBlocks A and B there is a path from A to B that
// passes through a suspend point. Note, SuspendCrossingInfo is invalidated
// by changes to the CFG including adding/removing BBs due to its use of BB
// ptrs in the BlockToIndexMapping.
//===----------------------------------------------------------------------===//

#include "llvm/Transforms/Coroutines/SuspendCrossingInfo.h"

// 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 llvm {
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
static std::string getBasicBlockLabel(const BasicBlock *BB) {
  if (BB->hasName())
    return BB->getName().str();

  std::string S;
  raw_string_ostream OS(S);
  BB->printAsOperand(OS, false);
  return OS.str().substr(1);
}

LLVM_DUMP_METHOD void SuspendCrossingInfo::dump(
    StringRef Label, BitVector const &BV,
    const ReversePostOrderTraversal<Function *> &RPOT) const {
  dbgs() << Label << ":";
  for (const BasicBlock *BB : RPOT) {
    auto BBNo = Mapping.blockToIndex(BB);
    if (BV[BBNo])
      dbgs() << " " << getBasicBlockLabel(BB);
  }
  dbgs() << "\n";
}

LLVM_DUMP_METHOD void SuspendCrossingInfo::dump() const {
  if (Block.empty())
    return;

  BasicBlock *const B = Mapping.indexToBlock(0);
  Function *F = B->getParent();

  ReversePostOrderTraversal<Function *> RPOT(F);
  for (const BasicBlock *BB : RPOT) {
    auto BBNo = Mapping.blockToIndex(BB);
    dbgs() << getBasicBlockLabel(BB) << ":\n";
    dump("   Consumes", Block[BBNo].Consumes, RPOT);
    dump("      Kills", Block[BBNo].Kills, RPOT);
  }
  dbgs() << "\n";
}
#endif

bool SuspendCrossingInfo::hasPathCrossingSuspendPoint(BasicBlock *From,
                                                      BasicBlock *To) const {}

bool SuspendCrossingInfo::hasPathOrLoopCrossingSuspendPoint(
    BasicBlock *From, BasicBlock *To) const {}

template <bool Initialize>
bool SuspendCrossingInfo::computeBlockData(
    const ReversePostOrderTraversal<Function *> &RPOT) {}

SuspendCrossingInfo::SuspendCrossingInfo(
    Function &F, const SmallVectorImpl<AnyCoroSuspendInst *> &CoroSuspends,
    const SmallVectorImpl<AnyCoroEndInst *> &CoroEnds)
    :{}

} // namespace llvm