#include "llvm/CodeGen/CallBrPrepare.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/iterator.h"
#include "llvm/Analysis/CFG.h"
#include "llvm/CodeGen/Passes.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/InitializePasses.h"
#include "llvm/Pass.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/SSAUpdater.h"
usingnamespacellvm;
#define DEBUG_TYPE …
static bool SplitCriticalEdges(ArrayRef<CallBrInst *> CBRs, DominatorTree &DT);
static bool InsertIntrinsicCalls(ArrayRef<CallBrInst *> CBRs,
DominatorTree &DT);
static void UpdateSSA(DominatorTree &DT, CallBrInst *CBR, CallInst *Intrinsic,
SSAUpdater &SSAUpdate);
static SmallVector<CallBrInst *, 2> FindCallBrs(Function &Fn);
namespace {
class CallBrPrepare : public FunctionPass { … };
}
PreservedAnalyses CallBrPreparePass::run(Function &Fn,
FunctionAnalysisManager &FAM) { … }
char CallBrPrepare::ID = …;
INITIALIZE_PASS_BEGIN(CallBrPrepare, "callbrprepare", "Prepare callbr", false,
false)
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
INITIALIZE_PASS_END(CallBrPrepare, "callbrprepare", "Prepare callbr", false,
false)
FunctionPass *llvm::createCallBrPass() { … }
void CallBrPrepare::getAnalysisUsage(AnalysisUsage &AU) const { … }
SmallVector<CallBrInst *, 2> FindCallBrs(Function &Fn) { … }
bool SplitCriticalEdges(ArrayRef<CallBrInst *> CBRs, DominatorTree &DT) { … }
bool InsertIntrinsicCalls(ArrayRef<CallBrInst *> CBRs, DominatorTree &DT) { … }
static bool IsInSameBasicBlock(const Use &U, const BasicBlock *BB) { … }
#ifndef NDEBUG
static void PrintDebugDomInfo(const DominatorTree &DT, const Use &U,
const BasicBlock *BB, bool IsDefaultDest) {
if (!isa<Instruction>(U.getUser()))
return;
LLVM_DEBUG(dbgs() << "Use: " << *U.getUser() << ", in block "
<< cast<Instruction>(U.getUser())->getParent()->getName()
<< ", is " << (DT.dominates(BB, U) ? "" : "NOT ")
<< "dominated by " << BB->getName() << " ("
<< (IsDefaultDest ? "in" : "") << "direct)\n");
}
#endif
void UpdateSSA(DominatorTree &DT, CallBrInst *CBR, CallInst *Intrinsic,
SSAUpdater &SSAUpdate) { … }
bool CallBrPrepare::runOnFunction(Function &Fn) { … }