//===----------------------------------------------------------------------===//
#include "AMDGPU.h"
-
-#include "llvm/Pass.h"
-#include "llvm/Module.h"
+#include "llvm/ADT/DepthFirstIterator.h"
#include "llvm/Analysis/Dominators.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/Instructions.h"
+#include "llvm/IR/Module.h"
+#include "llvm/Pass.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
-#include "llvm/ADT/DepthFirstIterator.h"
#include "llvm/Transforms/Utils/SSAUpdater.h"
using namespace llvm;
}
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
-
AU.addRequired<DominatorTree>();
AU.addPreserved<DominatorTree>();
FunctionPass::getAnalysisUsage(AU);
/// \brief Initialize all the types and constants used in the pass
bool SIAnnotateControlFlow::doInitialization(Module &M) {
-
LLVMContext &Context = M.getContext();
Void = Type::getVoidTy(Context);
/// \brief Is BB the last block saved on the stack ?
bool SIAnnotateControlFlow::isTopOfStack(BasicBlock *BB) {
- return Stack.back().first == BB;
+ return !Stack.empty() && Stack.back().first == BB;
}
/// \brief Pop the last saved value from the control flow stack
/// \brief Can the condition represented by this PHI node treated like
/// an "Else" block?
bool SIAnnotateControlFlow::isElse(PHINode *Phi) {
-
BasicBlock *IDom = DT->getNode(Phi->getParent())->getIDom()->getBlock();
for (unsigned i = 0, e = Phi->getNumIncomingValues(); i != e; ++i) {
if (Phi->getIncomingBlock(i) == IDom) {
/// \brief Recursively handle the condition leading to a loop
void SIAnnotateControlFlow::handleLoopCondition(Value *Cond) {
-
if (PHINode *Phi = dyn_cast<PHINode>(Cond)) {
// Handle all non constant incoming values first
/// \brief Handle a back edge (loop)
void SIAnnotateControlFlow::handleLoop(BranchInst *Term) {
-
BasicBlock *Target = Term->getSuccessor(1);
PHINode *Broken = PHINode::Create(Int64, 0, "", &Target->front());
/// \brief Annotate the control flow with intrinsics so the backend can
/// recognize if/then/else and loops.
bool SIAnnotateControlFlow::runOnFunction(Function &F) {
-
DT = &getAnalysis<DominatorTree>();
for (df_iterator<BasicBlock *> I = df_begin(&F.getEntryBlock()),
/// \brief Create the annotation pass
FunctionPass *llvm::createSIAnnotateControlFlowPass() {
-
return new SIAnnotateControlFlow();
}