Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
#ifndef LLVM_TRANSFORMS_COROUTINES_MATERIALIZATIONUTILS_H
#define LLVM_TRANSFORMS_COROUTINES_MATERIALIZATIONUTILS_H

namespace llvm {

namespace coro {
namespace llvm::coro {

// True if I is trivially rematerialzable, e.g. InsertElementInst
LLVM_ABI bool isTriviallyMaterializable(Instruction &I);
Expand All @@ -24,8 +22,6 @@ LLVM_ABI void
doRematerializations(Function &F, SuspendCrossingInfo &Checker,
std::function<bool(Instruction &)> IsMaterializable);

} // namespace coro

} // namespace llvm
} // namespace llvm::coro

#endif // LLVM_TRANSFORMS_COROUTINES_MATERIALIZATIONUTILS_H
9 changes: 3 additions & 6 deletions llvm/include/llvm/Transforms/Coroutines/SpillUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
#ifndef LLVM_TRANSFORMS_COROUTINES_SPILLINGINFO_H
#define LLVM_TRANSFORMS_COROUTINES_SPILLINGINFO_H

namespace llvm {

namespace coro {
namespace llvm::coro {

using SpillInfo = SmallMapVector<Value *, SmallVector<Instruction *, 2>, 8>;

Expand All @@ -38,6 +36,7 @@ void collectSpillsAndAllocasFromInsts(
SmallVector<CoroAllocaAllocInst *, 4> &LocalAllocas, Function &F,
const SuspendCrossingInfo &Checker, const DominatorTree &DT,
const coro::Shape &Shape);

void collectSpillsFromDbgInfo(SpillInfo &Spills, Function &F,
const SuspendCrossingInfo &Checker);

Expand All @@ -52,8 +51,6 @@ void sinkSpillUsesAfterCoroBegin(const DominatorTree &DT,
BasicBlock::iterator getSpillInsertionPt(const coro::Shape &, Value *Def,
const DominatorTree &DT);

} // namespace coro

} // namespace llvm
} // namespace llvm::coro

#endif // LLVM_TRANSFORMS_COROUTINES_SPILLINGINFO_H
9 changes: 3 additions & 6 deletions llvm/lib/Transforms/Coroutines/CoroCloner.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand All @@ -19,9 +20,7 @@
#include "llvm/Transforms/Coroutines/CoroInstr.h"
#include "llvm/Transforms/Utils/ValueMapper.h"

namespace llvm {

namespace coro {
namespace llvm::coro {

enum class CloneKind {
/// The shared resume function for a switch lowering.
Expand Down Expand Up @@ -149,8 +148,6 @@ class SwitchCloner : public BaseCloner {
}
};

} // end namespace coro

} // end namespace llvm
} // end namespace llvm::coro

#endif // LLVM_LIB_TRANSFORMS_COROUTINES_COROCLONER_H
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Coroutines/CoroEarly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Lowerer : public coro::LowererBase {
AnyResumeFnPtrTy(PointerType::getUnqual(Context)) {}
void lowerEarlyIntrinsics(Function &F);
};
}
} // namespace

// Replace a direct call to coro.resume or coro.destroy with an indirect call to
// an address returned by coro.subfn.addr intrinsic. This is done so that
Expand Down
9 changes: 2 additions & 7 deletions llvm/lib/Transforms/Coroutines/CoroInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@
#include "llvm/Transforms/Coroutines/CoroInstr.h"
#include "llvm/Transforms/Coroutines/CoroShape.h"

namespace llvm {

class CallGraph;

namespace coro {
namespace llvm::coro {

bool isSuspendBlock(BasicBlock *BB);
bool declaresAnyIntrinsic(const Module &M);
Expand Down Expand Up @@ -61,7 +57,6 @@ void normalizeCoroutine(Function &F, coro::Shape &Shape,
CallInst *createMustTailCall(DebugLoc Loc, Function *MustTailCallFn,
TargetTransformInfo &TTI,
ArrayRef<Value *> Arguments, IRBuilder<> &);
} // End namespace coro.
} // End namespace llvm
} // End namespace llvm::coro

#endif
5 changes: 1 addition & 4 deletions llvm/lib/Transforms/Coroutines/MaterializationUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ struct RematGraph {

} // namespace

namespace llvm {
template <> struct GraphTraits<RematGraph *> {
template <> struct llvm::GraphTraits<RematGraph *> {
using NodeRef = RematGraph::RematNode *;
using ChildIteratorType = RematGraph::RematNode **;

Expand All @@ -149,8 +148,6 @@ template <> struct GraphTraits<RematGraph *> {
static ChildIteratorType child_end(NodeRef N) { return N->Operands.end(); }
};

} // 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.
Expand Down
37 changes: 14 additions & 23 deletions llvm/lib/Transforms/Coroutines/SpillUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@
#include "llvm/IR/InstIterator.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"

namespace llvm {

namespace coro {

namespace {
using namespace llvm;
using namespace llvm::coro;

typedef SmallPtrSet<BasicBlock *, 8> VisitedBlocksSet;

Expand Down Expand Up @@ -71,7 +68,7 @@ static bool isLocalAlloca(CoroAllocaAllocInst *AI) {
/// This happens during the all-instructions iteration, so it must not
/// delete the call.
static Instruction *
lowerNonLocalAlloca(CoroAllocaAllocInst *AI, const coro::Shape &Shape,
lowerNonLocalAlloca(CoroAllocaAllocInst *AI, const Shape &Shape,
SmallVectorImpl<Instruction *> &DeadInsts) {
IRBuilder<> Builder(AI);
auto Alloc = Shape.emitAlloc(Builder, AI->getSize(), nullptr);
Expand Down Expand Up @@ -450,18 +447,16 @@ static void collectFrameAlloca(AllocaInst *AI, const coro::Shape &Shape,
Visitor.getMayWriteBeforeCoroBegin());
}

} // namespace

void collectSpillsFromArgs(SpillInfo &Spills, Function &F,
const SuspendCrossingInfo &Checker) {
void coro::collectSpillsFromArgs(SpillInfo &Spills, Function &F,
const SuspendCrossingInfo &Checker) {
// Collect the spills for arguments and other not-materializable values.
for (Argument &A : F.args())
for (User *U : A.users())
if (Checker.isDefinitionAcrossSuspend(A, U))
Spills[&A].push_back(cast<Instruction>(U));
}

void collectSpillsAndAllocasFromInsts(
void coro::collectSpillsAndAllocasFromInsts(
SpillInfo &Spills, SmallVector<AllocaInfo, 8> &Allocas,
SmallVector<Instruction *, 4> &DeadInstructions,
SmallVector<CoroAllocaAllocInst *, 4> &LocalAllocas, Function &F,
Expand Down Expand Up @@ -516,8 +511,8 @@ void collectSpillsAndAllocasFromInsts(
}
}

void collectSpillsFromDbgInfo(SpillInfo &Spills, Function &F,
const SuspendCrossingInfo &Checker) {
void coro::collectSpillsFromDbgInfo(SpillInfo &Spills, Function &F,
const SuspendCrossingInfo &Checker) {
// We don't want the layout of coroutine frame to be affected
// by debug information. So we only choose to salvage dbg.values for
// whose value is already in the frame.
Expand All @@ -535,10 +530,9 @@ void collectSpillsFromDbgInfo(SpillInfo &Spills, Function &F,

/// Async and Retcon{Once} conventions assume that all spill uses can be sunk
/// after the coro.begin intrinsic.
void sinkSpillUsesAfterCoroBegin(const DominatorTree &Dom,
CoroBeginInst *CoroBegin,
coro::SpillInfo &Spills,
SmallVectorImpl<coro::AllocaInfo> &Allocas) {
void coro::sinkSpillUsesAfterCoroBegin(
const DominatorTree &Dom, CoroBeginInst *CoroBegin, coro::SpillInfo &Spills,
SmallVectorImpl<coro::AllocaInfo> &Allocas) {
SmallSetVector<Instruction *, 32> ToMove;
SmallVector<Instruction *, 32> Worklist;

Expand Down Expand Up @@ -582,8 +576,9 @@ void sinkSpillUsesAfterCoroBegin(const DominatorTree &Dom,
Inst->moveBefore(InsertPt->getIterator());
}

BasicBlock::iterator getSpillInsertionPt(const coro::Shape &Shape, Value *Def,
const DominatorTree &DT) {
BasicBlock::iterator coro::getSpillInsertionPt(const coro::Shape &Shape,
Value *Def,
const DominatorTree &DT) {
BasicBlock::iterator InsertPt;
if (auto *Arg = dyn_cast<Argument>(Def)) {
// For arguments, we will place the store instruction right after
Expand Down Expand Up @@ -625,7 +620,3 @@ BasicBlock::iterator getSpillInsertionPt(const coro::Shape &Shape, Value *Def,

return InsertPt;
}

} // End namespace coro.

} // End namespace llvm.