Remove some redundant checks, add a couple of new ones. This allows us to
[oota-llvm.git] / lib / Target / CBackend / CBackend.cpp
index 254b5a488ff2b015752b48d640ce7bd3bca577f2..2e3e9a9edd169cdb33708f8afc5571d6becbc517 100644 (file)
@@ -33,6 +33,7 @@
 #include "llvm/Support/InstVisitor.h"
 #include "llvm/Support/Mangler.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Config/config.h"
 #include <algorithm>
@@ -1079,7 +1080,7 @@ void CWriter::printFunctionSignature(const Function *F, bool Prototype) {
       std::string ArgName;
       if (F->arg_begin()->hasName() || !Prototype)
         ArgName = Mang->getValueName(F->arg_begin());
-      printType(FunctionInnards, F->arg_front().getType(), ArgName);
+      printType(FunctionInnards, F->arg_begin()->getType(), ArgName);
       for (Function::const_arg_iterator I = ++F->arg_begin(), E = F->arg_end();
            I != E; ++I) {
         FunctionInnards << ", ";
@@ -1246,7 +1247,7 @@ void CWriter::visitSwitchInst(SwitchInst &SI) {
     BasicBlock *Succ = cast<BasicBlock>(SI.getOperand(i+1));
     printPHICopiesForSuccessor (SI.getParent(), Succ, 2);
     printBranchToBlock(SI.getParent(), Succ, 2);
-    if (Succ == SI.getParent()->getNext())
+    if (Function::iterator(Succ) == next(Function::iterator(SI.getParent())))
       Out << "    break;\n";
   }
   Out << "  }\n";
@@ -1260,12 +1261,11 @@ bool CWriter::isGotoCodeNecessary(BasicBlock *From, BasicBlock *To) {
   /// FIXME: This should be reenabled, but loop reordering safe!!
   return true;
 
-  if (From->getNext() != To) // Not the direct successor, we need a goto
-    return true; 
+  if (next(Function::iterator(From)) != Function::iterator(To))
+    return true;  // Not the direct successor, we need a goto.
 
   //isa<SwitchInst>(From->getTerminator())
 
-
   if (LI->getLoopFor(From) != LI->getLoopFor(To))
     return true;
   return false;
@@ -1443,7 +1443,10 @@ void CWriter::lowerIntrinsics(Function &F) {
             break;
           default:
             // All other intrinsic calls we must lower.
-            Instruction *Before = CI->getPrev();
+            Instruction *Before = 0;
+            if (CI != &BB->front()) 
+              Before = prior(BasicBlock::iterator(CI));
+              
             IL.LowerIntrinsicCall(CI);
             if (Before) {        // Move iterator to instruction after call
               I = Before; ++I;