Don't use a potentially expensive shift if all we want is one set bit.
[oota-llvm.git] / lib / Target / R600 / SIAnnotateControlFlow.cpp
index d13183557d21fcf3789e82a849f108dcb02d9633..9791ef43893877615f52856129aa4bc1aa568390 100644 (file)
 //===----------------------------------------------------------------------===//
 
 #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;
@@ -97,7 +98,6 @@ public:
   }
 
   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
-
     AU.addRequired<DominatorTree>();
     AU.addPreserved<DominatorTree>();
     FunctionPass::getAnalysisUsage(AU);
@@ -111,7 +111,6 @@ char SIAnnotateControlFlow::ID = 0;
 
 /// \brief Initialize all the types and constants used in the pass
 bool SIAnnotateControlFlow::doInitialization(Module &M) {
-
   LLVMContext &Context = M.getContext();
 
   Void = Type::getVoidTy(Context);
@@ -150,7 +149,7 @@ bool SIAnnotateControlFlow::doInitialization(Module &M) {
 
 /// \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
@@ -166,7 +165,6 @@ void SIAnnotateControlFlow::push(BasicBlock *BB, Value *Saved) {
 /// \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) {
@@ -205,7 +203,6 @@ void SIAnnotateControlFlow::insertElse(BranchInst *Term) {
 
 /// \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
@@ -262,7 +259,6 @@ void SIAnnotateControlFlow::handleLoopCondition(Value *Cond) {
 
 /// \brief Handle a back edge (loop)
 void SIAnnotateControlFlow::handleLoop(BranchInst *Term) {
-
   BasicBlock *Target = Term->getSuccessor(1);
   PHINode *Broken = PHINode::Create(Int64, 0, "", &Target->front());
 
@@ -293,7 +289,6 @@ void SIAnnotateControlFlow::closeControlFlow(BasicBlock *BB) {
 /// \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()),
@@ -332,6 +327,5 @@ bool SIAnnotateControlFlow::runOnFunction(Function &F) {
 
 /// \brief Create the annotation pass
 FunctionPass *llvm::createSIAnnotateControlFlowPass() {
-
   return new SIAnnotateControlFlow();
 }