[llvm-commits] [127732] Switch llvm-gcc over to using the LLVMBuilder class, which shrinks it

clattner at apple.com clattner at apple.com
Sun May 27 08:11:20 PDT 2007


Revision: 127732
Author:   clattner
Date:     2007-05-27 08:11:20 -0700 (Sun, 27 May 2007)

Log Message:
-----------
Switch llvm-gcc over to using the LLVMBuilder class, which shrinks it
by about 280 lines.  Also took the opportunity to simplify some of the
casting due to the type system changes.  Code review of the SSE builtin
lower pieces particularly appreciated.

Modified Paths:
--------------
     apple-local/branches/llvm/gcc/config/i386/i386.h
     apple-local/branches/llvm/gcc/config/i386/llvm-i386.cpp
     apple-local/branches/llvm/gcc/config/rs6000/llvm-rs6000.cpp
     apple-local/branches/llvm/gcc/config/rs6000/rs6000.h
     apple-local/branches/llvm/gcc/llvm-convert.cpp
     apple-local/branches/llvm/gcc/llvm-internal.h

Modified: apple-local/branches/llvm/gcc/config/i386/i386.h
===================================================================
--- apple-local/branches/llvm/gcc/config/i386/i386.h	2007-05-27  
08:09:51 UTC (rev 127731)
+++ apple-local/branches/llvm/gcc/config/i386/i386.h	2007-05-27  
15:11:20 UTC (rev 127732)
@@ -4067,11 +4067,8 @@
   *  return true.This macro is invoked from a method in the  
TreeToLLVM class.
   */
  #define LLVM_TARGET_INTRINSIC_LOWER(EXP, BUILTIN_CODE, DESTLOC,  
RESULT,       \
-                                    DESTTY, OPS, ARGS,  
CURBB,                 \
-                                    RESISSIGNED,  
EXPISSIGNED)                 \
-        TargetIntrinsicLower(EXP, BUILTIN_CODE, DESTLOC,  
RESULT,              \
-                             DESTTY, OPS, ARGS,  
CURBB,                        \
-                             RESISSIGNED, EXPISSIGNED);
+                                    DESTTY,  
OPS)                              \
+        TargetIntrinsicLower(EXP, BUILTIN_CODE, DESTLOC, RESULT,  
DESTTY, OPS);
  /* APPLE LOCAL end LLVM */

  /*

Modified: apple-local/branches/llvm/gcc/config/i386/llvm-i386.cpp
===================================================================
--- apple-local/branches/llvm/gcc/config/i386/llvm-i386.cpp	 
2007-05-27 08:09:51 UTC (rev 127731)
+++ apple-local/branches/llvm/gcc/config/i386/llvm-i386.cpp	 
2007-05-27 15:11:20 UTC (rev 127732)
@@ -34,24 +34,6 @@
  #include "toplev.h"
  }

-/* TargetIntrinsicCastResult - This function just provides a  
frequently used
- * sequence for use inside TargetIntrinsicLower.
- */
-static void TargetIntrinsicCastResult(Value *&Result, const Type  
*ResultType,
-                                      bool ResIsSigned, bool  
ExpIsSigned,
-                                      BasicBlock *CurBB) {
-  Instruction::CastOps opcode =
-    CastInst::getCastOpcode(Result, ResIsSigned, ResultType,  
ExpIsSigned);
-  Result = CastInst::create(opcode, Result, ResultType, "tmp", CurBB);
-}
-
-/* IntrinsicOpIsSigned - This function determines if a given operand  
to the
- * intrinsic is signed or not.
- */
-static bool IntrinsicOpIsSigned(SmallVector<tree, 8> &Args, unsigned  
OpNum) {
-  return !TYPE_UNSIGNED(TREE_TYPE(Args[OpNum]));
-}
-
  /* TargetIntrinsicLower - For builtins that we want to expand to  
normal LLVM
   * code, emit the code now.  If we can handle the code, this macro  
should emit
   * the code, return true.
@@ -61,11 +43,7 @@
                                        Value *DestLoc,
                                        Value *&Result,
                                        const Type *ResultType,
-                                      std::vector<Value*> &Ops,
-                                      SmallVector<tree, 8> &Args,
-                                      BasicBlock *CurBB,
-                                      bool ResIsSigned,
-                                      bool ExpIsSigned) {
+                                      std::vector<Value*> &Ops) {
    switch (FnCode) {
    default: break;
    case IX86_BUILTIN_ADDPS:
@@ -78,7 +56,7 @@
    case IX86_BUILTIN_PADDW128:
    case IX86_BUILTIN_PADDD128:
    case IX86_BUILTIN_PADDQ128:
-    Result = BinaryOperator::createAdd(Ops[0], Ops[1], "tmp", CurBB);
+    Result = Builder.CreateAdd(Ops[0], Ops[1], "tmp");
      return true;
    case IX86_BUILTIN_SUBPS:
    case IX86_BUILTIN_SUBPD:
@@ -89,335 +67,253 @@
    case IX86_BUILTIN_PSUBW128:
    case IX86_BUILTIN_PSUBD128:
    case IX86_BUILTIN_PSUBQ128:
-    Result = BinaryOperator::createSub(Ops[0], Ops[1], "tmp", CurBB);
+    Result = Builder.CreateSub(Ops[0], Ops[1], "tmp");
      return true;
    case IX86_BUILTIN_MULPS:
    case IX86_BUILTIN_MULPD:
    case IX86_BUILTIN_PMULLW:
    case IX86_BUILTIN_PMULLW128:
-    Result = BinaryOperator::createMul(Ops[0], Ops[1], "tmp", CurBB);
+    Result = Builder.CreateMul(Ops[0], Ops[1], "tmp");
      return true;
    case IX86_BUILTIN_PSLLWI: {
-    VectorType *v2i32 = VectorType::get(Type::Int32Ty, 2);
-    VectorType *v4i16 = VectorType::get(Type::Int16Ty, 4);
-    static Constant *psllw = 0;
-    if (psllw == 0) {
-      Module *M = CurBB->getParent()->getParent();
-      psllw = M->getOrInsertFunction("llvm.x86.mmx.psll.w",
-                                     v4i16, v4i16, v2i32, NULL);
-    }
-    Value *Undef = UndefValue::get(Type::Int32Ty);
-    Ops[1] = BuildVector(Ops[1], Undef, NULL);
-    Result = new CallInst(psllw, Ops[0], Ops[1], "tmp", CurBB);
-    TargetIntrinsicCastResult(Result, ResultType,
-                              ResIsSigned, ExpIsSigned, CurBB);
+    Function *psllw =
+      Intrinsic::getDeclaration(TheModule, Intrinsic::x86_mmx_psll_w);
+    Ops[1] = BuildVector(Ops[1], UndefValue::get(Type::Int32Ty), NULL);
+    Result = Builder.CreateCall(psllw, Ops[0], Ops[1], "tmp");
+    Result = Builder.CreateBitCast(Result, ResultType, "tmp");
      return true;
    }
    case IX86_BUILTIN_PSLLWI128: {
-    VectorType *v4i32 = VectorType::get(Type::Int32Ty, 4);
-    VectorType *v8i16 = VectorType::get(Type::Int16Ty, 8);
-    static Constant *psllw = 0;
-    if (psllw == 0) {
-      Module *M = CurBB->getParent()->getParent();
-      psllw = M->getOrInsertFunction("llvm.x86.sse2.psll.w",
-                                     v8i16, v8i16, v4i32, NULL);
-    }
+    Function *psllw =
+      Intrinsic::getDeclaration(TheModule, Intrinsic::x86_sse2_psll_w);
      Value *Undef = UndefValue::get(Type::Int32Ty);
      Ops[1] = BuildVector(Ops[1], Undef, Undef, Undef, NULL);
-    Result = new CallInst(psllw, Ops[0], Ops[1], "tmp", CurBB);
-    TargetIntrinsicCastResult(Result, ResultType,
-                              ResIsSigned, ExpIsSigned, CurBB);
+    Result = Builder.CreateCall(psllw, Ops[0], Ops[1], "tmp");
+    Result = Builder.CreateBitCast(Result, ResultType, "tmp");
      return true;
    }
    case IX86_BUILTIN_PSLLDI: {
-    VectorType *v2i32 = VectorType::get(Type::Int32Ty, 2);
-    static Constant *pslld = 0;
-    if (pslld == 0) {
-      Module *M = CurBB->getParent()->getParent();
-      pslld = M->getOrInsertFunction("llvm.x86.mmx.psll.d",
-                                     v2i32, v2i32, v2i32, NULL);
-    }
-    Value *Undef = UndefValue::get(Type::Int32Ty);
-    Ops[1] = BuildVector(Ops[1], Undef, NULL);
-    Result = new CallInst(pslld, Ops[0], Ops[1], "tmp", CurBB);
-    TargetIntrinsicCastResult(Result, ResultType,
-                              ResIsSigned, ExpIsSigned, CurBB);
+    Function *pslld =
+      Intrinsic::getDeclaration(TheModule, Intrinsic::x86_mmx_psll_d);
+    Ops[1] = BuildVector(Ops[1], UndefValue::get(Type::Int32Ty), NULL);
+    Result = Builder.CreateCall(pslld, Ops[0], Ops[1], "tmp");
+    Result = Builder.CreateBitCast(Result, ResultType, "tmp");
      return true;
    }
    case IX86_BUILTIN_PSLLDI128: {
      VectorType *v4i32 = VectorType::get(Type::Int32Ty, 4);
      static Constant *pslld = 0;
-    if (pslld == 0) {
-      Module *M = CurBB->getParent()->getParent();
-      pslld = M->getOrInsertFunction("llvm.x86.sse2.psll.d",
-                                     v4i32, v4i32, v4i32, NULL);
-    }
+    if (pslld == 0)
+      pslld = TheModule->getOrInsertFunction("llvm.x86.sse2.psll.d",
+                                             v4i32, v4i32, v4i32,  
NULL);
      Value *Undef = UndefValue::get(Type::Int32Ty);
      Ops[1] = BuildVector(Ops[1], Undef, Undef, Undef, NULL);
-    Result = new CallInst(pslld, Ops[0], Ops[1], "tmp", CurBB);
-    TargetIntrinsicCastResult(Result, ResultType,
-                              ResIsSigned, ExpIsSigned, CurBB);
+    Result = Builder.CreateCall(pslld, Ops[0], Ops[1], "tmp");
+    Result = Builder.CreateBitCast(Result, ResultType, "tmp");
      return true;
    }
    case IX86_BUILTIN_PSLLQI: {
      VectorType *v2i32 = VectorType::get(Type::Int32Ty, 2);
      static Constant *psllq = 0;
-    if (psllq == 0) {
-      Module *M = CurBB->getParent()->getParent();
-      psllq = M->getOrInsertFunction("llvm.x86.mmx.psll.q",
-                                     v2i32, v2i32, v2i32, NULL);
-    }
+    if (psllq == 0)
+      psllq = TheModule->getOrInsertFunction("llvm.x86.mmx.psll.q",
+                                             v2i32, v2i32, v2i32,  
NULL);
      Value *Undef = UndefValue::get(Type::Int32Ty);
      Ops[1] = BuildVector(Ops[1], Undef, NULL);
-    Result = new CallInst(psllq, Ops[0], Ops[1], "tmp", CurBB);
-    TargetIntrinsicCastResult(Result, ResultType,
-                              ResIsSigned, ExpIsSigned, CurBB);
+    Result = Builder.CreateCall(psllq, Ops[0], Ops[1], "tmp");
+    Result = Builder.CreateBitCast(Result, ResultType, "tmp");
      return true;
    }
    case IX86_BUILTIN_PSLLQI128: {
      VectorType *v4i32 = VectorType::get(Type::Int32Ty, 4);
      VectorType *v2i64 = VectorType::get(Type::Int64Ty, 2);
      static Constant *psllq = 0;
-    if (psllq == 0) {
-      Module *M = CurBB->getParent()->getParent();
-      psllq = M->getOrInsertFunction("llvm.x86.sse2.psll.q",
-                                     v2i64, v2i64, v4i32, NULL);
-    }
+    if (psllq == 0)
+      psllq = TheModule->getOrInsertFunction("llvm.x86.sse2.psll.q",
+                                             v2i64, v2i64, v4i32,  
NULL);
      Value *Undef = UndefValue::get(Type::Int32Ty);
      Ops[1] = BuildVector(Ops[1], Undef, Undef, Undef, NULL);
-    Result = new CallInst(psllq, Ops[0], Ops[1], "tmp", CurBB);
-    TargetIntrinsicCastResult(Result, ResultType,
-                              ResIsSigned, ExpIsSigned, CurBB);
+    Result = Builder.CreateCall(psllq, Ops[0], Ops[1], "tmp");
+    Result = Builder.CreateBitCast(Result, ResultType, "tmp");
      return true;
    }
    case IX86_BUILTIN_PSRLWI: {
      VectorType *v2i32 = VectorType::get(Type::Int32Ty, 2);
      VectorType *v4i16 = VectorType::get(Type::Int16Ty, 4);
      static Constant *psrlw = 0;
-    if (psrlw == 0) {
-      Module *M = CurBB->getParent()->getParent();
-      psrlw = M->getOrInsertFunction("llvm.x86.mmx.psrl.w",
-                                     v4i16, v4i16, v2i32, NULL);
-    }
+    if (psrlw == 0)
+      psrlw = TheModule->getOrInsertFunction("llvm.x86.mmx.psrl.w",
+                                             v4i16, v4i16, v2i32,  
NULL);
      Value *Undef = UndefValue::get(Type::Int32Ty);
      Ops[1] = BuildVector(Ops[1], Undef, NULL);
-    Result = new CallInst(psrlw, Ops[0], Ops[1], "tmp", CurBB);
-    TargetIntrinsicCastResult(Result, ResultType,
-                              ResIsSigned, ExpIsSigned, CurBB);
+    Result = Builder.CreateCall(psrlw, Ops[0], Ops[1], "tmp");
+    Result = Builder.CreateBitCast(Result, ResultType, "tmp");
      return true;
    }
    case IX86_BUILTIN_PSRLWI128: {
      VectorType *v4i32 = VectorType::get(Type::Int32Ty, 4);
      VectorType *v8i16 = VectorType::get(Type::Int16Ty, 8);
      static Constant *psrlw = 0;
-    if (psrlw == 0) {
-      Module *M = CurBB->getParent()->getParent();
-      psrlw = M->getOrInsertFunction("llvm.x86.sse2.psrl.w",
-                                     v8i16, v8i16, v4i32, NULL);
-    }
+    if (psrlw == 0)
+      psrlw = TheModule->getOrInsertFunction("llvm.x86.sse2.psrl.w",
+                                             v8i16, v8i16, v4i32,  
NULL);
      Value *Undef = UndefValue::get(Type::Int32Ty);
      Ops[1] = BuildVector(Ops[1], Undef, Undef, Undef, NULL);
-    Result = new CallInst(psrlw, Ops[0], Ops[1], "tmp", CurBB);
-    TargetIntrinsicCastResult(Result, ResultType,
-                              ResIsSigned, ExpIsSigned, CurBB);
+    Result = Builder.CreateCall(psrlw, Ops[0], Ops[1], "tmp");
+    Result = Builder.CreateBitCast(Result, ResultType, "tmp");
      return true;
    }
    case IX86_BUILTIN_PSRLDI: {
      VectorType *v2i32 = VectorType::get(Type::Int32Ty, 2);
      static Constant *psrld = 0;
-    if (psrld == 0) {
-      Module *M = CurBB->getParent()->getParent();
-      psrld = M->getOrInsertFunction("llvm.x86.mmx.psrl.d",
-                                     v2i32, v2i32, v2i32, NULL);
-    }
+    if (psrld == 0)
+      psrld = TheModule->getOrInsertFunction("llvm.x86.mmx.psrl.d",
+                                             v2i32, v2i32, v2i32,  
NULL);
      Value *Undef = UndefValue::get(Type::Int32Ty);
      Ops[1] = BuildVector(Ops[1], Undef, NULL);
-    Result = new CallInst(psrld, Ops[0], Ops[1], "tmp", CurBB);
-    TargetIntrinsicCastResult(Result, ResultType,
-                              ResIsSigned, ExpIsSigned, CurBB);
+    Result = Builder.CreateCall(psrld, Ops[0], Ops[1], "tmp");
+    Result = Builder.CreateBitCast(Result, ResultType, "tmp");
      return true;
    }
    case IX86_BUILTIN_PSRLDI128: {
      VectorType *v4i32 = VectorType::get(Type::Int32Ty, 4);
      static Constant *psrld = 0;
-    if (psrld == 0) {
-      Module *M = CurBB->getParent()->getParent();
-      psrld = M->getOrInsertFunction("llvm.x86.sse2.psrl.d",
-                                     v4i32, v4i32, v4i32, NULL);
-    }
+    if (psrld == 0)
+      psrld = TheModule->getOrInsertFunction("llvm.x86.sse2.psrl.d",
+                                             v4i32, v4i32, v4i32,  
NULL);
      Value *Undef = UndefValue::get(Type::Int32Ty);
      Ops[1] = BuildVector(Ops[1], Undef, Undef, Undef, NULL);
-    Result = new CallInst(psrld, Ops[0], Ops[1], "tmp", CurBB);
-    TargetIntrinsicCastResult(Result, ResultType,
-                              ResIsSigned, ExpIsSigned, CurBB);
+    Result = Builder.CreateCall(psrld, Ops[0], Ops[1], "tmp");
+    Result = Builder.CreateBitCast(Result, ResultType, "tmp");
      return true;
    }
    case IX86_BUILTIN_PSRLQI: {
      VectorType *v2i32 = VectorType::get(Type::Int32Ty, 2);
      static Constant *psrlq = 0;
-    if (psrlq == 0) {
-      Module *M = CurBB->getParent()->getParent();
-      psrlq = M->getOrInsertFunction("llvm.x86.mmx.psrl.q",
-                                     v2i32, v2i32, v2i32, NULL);
-    }
+    if (psrlq == 0)
+      psrlq = TheModule->getOrInsertFunction("llvm.x86.mmx.psrl.q",
+                                             v2i32, v2i32, v2i32,  
NULL);
      Value *Undef = UndefValue::get(Type::Int32Ty);
      Ops[1] = BuildVector(Ops[1], Undef, NULL);
-    Result = new CallInst(psrlq, Ops[0], Ops[1], "tmp", CurBB);
-    TargetIntrinsicCastResult(Result, ResultType,
-                              ResIsSigned, ExpIsSigned, CurBB);
+    Result = Builder.CreateCall(psrlq, Ops[0], Ops[1], "tmp");
+    Result = Builder.CreateBitCast(Result, ResultType, "tmp");
      return true;
    }
    case IX86_BUILTIN_PSRLQI128: {
      VectorType *v4i32 = VectorType::get(Type::Int32Ty, 4);
      VectorType *v2i64 = VectorType::get(Type::Int64Ty, 2);
      static Constant *psrlq = 0;
-    if (psrlq == 0) {
-      Module *M = CurBB->getParent()->getParent();
-      psrlq = M->getOrInsertFunction("llvm.x86.sse2.psrl.q",
-                                     v2i64, v2i64, v4i32, NULL);
-    }
+    if (psrlq == 0)
+      psrlq = TheModule->getOrInsertFunction("llvm.x86.sse2.psrl.q",
+                                             v2i64, v2i64, v4i32,  
NULL);
      Value *Undef = UndefValue::get(Type::Int32Ty);
      Ops[1] = BuildVector(Ops[1], Undef, Undef, Undef, NULL);
-    Result = new CallInst(psrlq, Ops[0], Ops[1], "tmp", CurBB);
-    TargetIntrinsicCastResult(Result, ResultType,
-                              ResIsSigned, ExpIsSigned, CurBB);
+    Result = Builder.CreateCall(psrlq, Ops[0], Ops[1], "tmp");
+    Result = Builder.CreateBitCast(Result, ResultType, "tmp");
      return true;
    }
    case IX86_BUILTIN_PSRAWI: {
      VectorType *v2i32 = VectorType::get(Type::Int32Ty, 2);
      VectorType *v4i16 = VectorType::get(Type::Int16Ty, 4);
      static Constant *psraw = 0;
-    if (psraw == 0) {
-      Module *M = CurBB->getParent()->getParent();
-      psraw = M->getOrInsertFunction("llvm.x86.mmx.psra.w",
-                                     v4i16, v4i16, v2i32, NULL);
-    }
+    if (psraw == 0)
+      psraw = TheModule->getOrInsertFunction("llvm.x86.mmx.psra.w",
+                                             v4i16, v4i16, v2i32,  
NULL);
      Value *Undef = UndefValue::get(Type::Int32Ty);
      Ops[1] = BuildVector(Ops[1], Undef, NULL);
-    Result = new CallInst(psraw, Ops[0], Ops[1], "tmp", CurBB);
-    TargetIntrinsicCastResult(Result, ResultType,
-                              ResIsSigned, ExpIsSigned, CurBB);
+    Result = Builder.CreateCall(psraw, Ops[0], Ops[1], "tmp");
+    Result = Builder.CreateBitCast(Result, ResultType, "tmp");
      return true;
    }
    case IX86_BUILTIN_PSRAWI128: {
      VectorType *v4i32 = VectorType::get(Type::Int32Ty, 4);
      VectorType *v8i16 = VectorType::get(Type::Int16Ty, 8);
      static Constant *psraw = 0;
-    if (psraw == 0) {
-      Module *M = CurBB->getParent()->getParent();
-      psraw = M->getOrInsertFunction("llvm.x86.sse2.psra.w",
-                                     v8i16, v8i16, v4i32, NULL);
-    }
+    if (psraw == 0)
+      psraw = TheModule->getOrInsertFunction("llvm.x86.sse2.psra.w",
+                                             v8i16, v8i16, v4i32,  
NULL);
      Value *Undef = UndefValue::get(Type::Int32Ty);
      Ops[1] = BuildVector(Ops[1], Undef, Undef, Undef, NULL);
-    Result = new CallInst(psraw, Ops[0], Ops[1], "tmp", CurBB);
-    TargetIntrinsicCastResult(Result, ResultType,
-                              ResIsSigned, ExpIsSigned, CurBB);
+    Result = Builder.CreateCall(psraw, Ops[0], Ops[1], "tmp");
+    Result = Builder.CreateBitCast(Result, ResultType, "tmp");
      return true;
    }
    case IX86_BUILTIN_PSRADI: {
      VectorType *v2i32 = VectorType::get(Type::Int32Ty, 2);
      static Constant *psrad = 0;
-    if (psrad == 0) {
-      Module *M = CurBB->getParent()->getParent();
-      psrad = M->getOrInsertFunction("llvm.x86.mmx.psra.d",
-                                     v2i32, v2i32, v2i32, NULL);
-    }
+    if (psrad == 0)
+      psrad = TheModule->getOrInsertFunction("llvm.x86.mmx.psra.d",
+                                             v2i32, v2i32, v2i32,  
NULL);
      Value *Undef = UndefValue::get(Type::Int32Ty);
      Ops[1] = BuildVector(Ops[1], Undef, NULL);
-    Result = new CallInst(psrad, Ops[0], Ops[1], "tmp", CurBB);
-    TargetIntrinsicCastResult(Result, ResultType,
-                              ResIsSigned, ExpIsSigned, CurBB);
+    Result = Builder.CreateCall(psrad, Ops[0], Ops[1], "tmp");
+    Result = Builder.CreateBitCast(Result, ResultType, "tmp");
      return true;
    }
    case IX86_BUILTIN_PSRADI128: {
      VectorType *v4i32 = VectorType::get(Type::Int32Ty, 4);
      static Constant *psrad = 0;
-    if (psrad == 0) {
-      Module *M = CurBB->getParent()->getParent();
-      psrad = M->getOrInsertFunction("llvm.x86.sse2.psra.d",
-                                     v4i32, v4i32, v4i32, NULL);
-    }
+    if (psrad == 0)
+      psrad = TheModule->getOrInsertFunction("llvm.x86.sse2.psra.d",
+                                             v4i32, v4i32, v4i32,  
NULL);
      Value *Undef = UndefValue::get(Type::Int32Ty);
      Ops[1] = BuildVector(Ops[1], Undef, Undef, Undef, NULL);
-    Result = new CallInst(psrad, Ops[0], Ops[1], "tmp", CurBB);
-    TargetIntrinsicCastResult(Result, ResultType,
-                              ResIsSigned, ExpIsSigned, CurBB);
+    Result = Builder.CreateCall(psrad, Ops[0], Ops[1], "tmp");
+    Result = Builder.CreateBitCast(Result, ResultType, "tmp");
      return true;
    }
    case IX86_BUILTIN_DIVPS:
    case IX86_BUILTIN_DIVPD:
-    Result = BinaryOperator::createFDiv(Ops[0], Ops[1], "tmp", CurBB);
+    Result = Builder.CreateFDiv(Ops[0], Ops[1], "tmp");
      return true;
    case IX86_BUILTIN_PAND:
    case IX86_BUILTIN_PAND128:
-    Result = BinaryOperator::createAnd(Ops[0], Ops[1], "tmp", CurBB);
+    Result = Builder.CreateAnd(Ops[0], Ops[1], "tmp");
      return true;
    case IX86_BUILTIN_PANDN:
    case IX86_BUILTIN_PANDN128:
-    Ops[0] = BinaryOperator::createNot(Ops[0], "tmp", CurBB);
-    Result = BinaryOperator::createAnd(Ops[0], Ops[1], "tmp", CurBB);
+    Ops[0] = Builder.CreateNot(Ops[0], "tmp");
+    Result = Builder.CreateAnd(Ops[0], Ops[1], "tmp");
      return true;
    case IX86_BUILTIN_POR:
    case IX86_BUILTIN_POR128:
-    Result = BinaryOperator::createOr(Ops[0], Ops[1], "tmp", CurBB);
+    Result = Builder.CreateOr(Ops[0], Ops[1], "tmp");
      return true;
    case IX86_BUILTIN_PXOR:
    case IX86_BUILTIN_PXOR128:
-    Result = BinaryOperator::createXor(Ops[0], Ops[1], "tmp", CurBB);
+    Result = Builder.CreateXor(Ops[0], Ops[1], "tmp");
      return true;
    case IX86_BUILTIN_ANDPS:
    case IX86_BUILTIN_ORPS:
    case IX86_BUILTIN_XORPS:
-  case IX86_BUILTIN_ANDNPS: {
-    VectorType *v4i32 = VectorType::get(Type::Int32Ty, 4);
-    Ops[0] = new BitCastInst(Ops[0], v4i32, "tmp", CurBB);
-    Ops[1] = new BitCastInst(Ops[1], v4i32, "tmp", CurBB);
+  case IX86_BUILTIN_ANDNPS:
+  case IX86_BUILTIN_ANDPD:
+  case IX86_BUILTIN_ORPD:
+  case IX86_BUILTIN_XORPD:
+  case IX86_BUILTIN_ANDNPD:
+    if (cast<VectorType>(ResultType)->getNumElements() == 4)  // v4f32
+      Ops[0] = new BitCastInst(Ops[0], VectorType::get 
(Type::Int32Ty, 4),"tmp");
+    else                                                      // v2f64
+      Ops[0] = new BitCastInst(Ops[0], VectorType::get 
(Type::Int64Ty, 2),"tmp");
+
+    Ops[1] = new BitCastInst(Ops[1], Ops[0]->getType(), "tmp");
      switch (FnCode) {
        case IX86_BUILTIN_ANDPS:
-        Result = BinaryOperator::createAnd(Ops[0], Ops[1], "tmp",  
CurBB);
+        Result = Builder.CreateAnd(Ops[0], Ops[1], "tmp");
          break;
        case IX86_BUILTIN_ORPS:
-        Result = BinaryOperator::createOr (Ops[0], Ops[1], "tmp",  
CurBB);
+        Result = Builder.CreateOr (Ops[0], Ops[1], "tmp");
           break;
        case IX86_BUILTIN_XORPS:
-        Result = BinaryOperator::createXor(Ops[0], Ops[1], "tmp",  
CurBB);
+        Result = Builder.CreateXor(Ops[0], Ops[1], "tmp");
          break;
        case IX86_BUILTIN_ANDNPS:
-        Ops[0] = BinaryOperator::createNot(Ops[0], "tmp", CurBB);
-        Result = BinaryOperator::createAnd(Ops[0], Ops[1], "tmp",  
CurBB);
+        Ops[0] = Builder.CreateNot(Ops[0], "tmp");
+        Result = Builder.CreateAnd(Ops[0], Ops[1], "tmp");
          break;
      }
-    TargetIntrinsicCastResult(Result, ResultType,
-                              ResIsSigned, ExpIsSigned, CurBB);
+    Result = Builder.CreateBitCast(Result, ResultType, "tmp");
      return true;
-  }
-  case IX86_BUILTIN_ANDPD:
-  case IX86_BUILTIN_ORPD:
-  case IX86_BUILTIN_XORPD:
-  case IX86_BUILTIN_ANDNPD: {
-    VectorType *v2i64 = VectorType::get(Type::Int64Ty, 2);
-    Ops[0] = new BitCastInst(Ops[0], v2i64, "tmp", CurBB);
-    Ops[1] = new BitCastInst(Ops[1], v2i64, "tmp", CurBB);
-    switch (FnCode) {
-      case IX86_BUILTIN_ANDPD:
-        Result = BinaryOperator::createAnd(Ops[0], Ops[1], "tmp",  
CurBB);
-        break;
-      case IX86_BUILTIN_ORPD:
-        Result = BinaryOperator::createOr (Ops[0], Ops[1], "tmp",  
CurBB);
-         break;
-      case IX86_BUILTIN_XORPD:
-        Result = BinaryOperator::createXor(Ops[0], Ops[1], "tmp",  
CurBB);
-        break;
-      case IX86_BUILTIN_ANDNPD:
-        Ops[0] = BinaryOperator::createNot(Ops[0], "tmp", CurBB);
-        Result = BinaryOperator::createAnd(Ops[0], Ops[1], "tmp",  
CurBB);
-        break;
-    }
-    TargetIntrinsicCastResult(Result, ResultType,
-                              ResIsSigned, ExpIsSigned, CurBB);
-    return true;
-  }
    case IX86_BUILTIN_SHUFPS:
      if (ConstantInt *Elt = dyn_cast<ConstantInt>(Ops[2])) {
        int EV = Elt->getZExtValue();
@@ -428,7 +324,6 @@
        error("%Hmask must be an immediate", &EXPR_LOCATION(exp));
        Result = Ops[0];
      }
-
      return true;
    case IX86_BUILTIN_PSHUFW:
    case IX86_BUILTIN_PSHUFD:
@@ -527,57 +422,50 @@
    case IX86_BUILTIN_LOADQ: {
      PointerType *f64Ptr = PointerType::get(Type::DoubleTy);
      Value *Zero = ConstantFP::get(Type::DoubleTy, 0.0);
-    Ops[0] = new BitCastInst(Ops[0], f64Ptr, "tmp", CurBB);
-    Ops[0] = new LoadInst(Ops[0], "tmp", false, CurBB);
+    Ops[0] = Builder.CreateBitCast(Ops[0], f64Ptr, "tmp");
+    Ops[0] = Builder.CreateLoad(Ops[0], "tmp");
      Result = BuildVector(Ops[0], Zero, NULL);
-    TargetIntrinsicCastResult(Result, ResultType,
-                              ResIsSigned, ExpIsSigned, CurBB);
+    Result = Builder.CreateBitCast(Result, ResultType, "tmp");
      return true;
    }
    case IX86_BUILTIN_LOADHPS: {
      PointerType *f64Ptr = PointerType::get(Type::DoubleTy);
-    Ops[1] = new BitCastInst(Ops[1], f64Ptr, "tmp", CurBB);
-    Value *Load = new LoadInst(Ops[1], "tmp", false, CurBB);
+    Ops[1] = Builder.CreateBitCast(Ops[1], f64Ptr, "tmp");
+    Value *Load = Builder.CreateLoad(Ops[1], "tmp");
      Ops[1] = BuildVector(Load, UndefValue::get(Type::DoubleTy), NULL);
-    Instruction::CastOps opcode = CastInst::getCastOpcode(Ops[1],
-      IntrinsicOpIsSigned(Args, 1), ResultType, ExpIsSigned);
-    Ops[1] = CastInst::create(opcode, Ops[1], ResultType, "tmp",  
CurBB);
+    Ops[1] = Builder.CreateBitCast(Ops[1], ResultType, "tmp");
      Result = BuildVectorShuffle(Ops[0], Ops[1], 0, 1, 4, 5);
-    TargetIntrinsicCastResult(Result, ResultType,
-                              ResIsSigned, ExpIsSigned, CurBB);
+    Result = Builder.CreateBitCast(Result, ResultType, "tmp");
      return true;
    }
    case IX86_BUILTIN_LOADLPS: {
      PointerType *f64Ptr = PointerType::get(Type::DoubleTy);
-    Ops[1] = new BitCastInst(Ops[1], f64Ptr, "tmp", CurBB);
-    Value *Load = new LoadInst(Ops[1], "tmp", false, CurBB);
+    Ops[1] = Builder.CreateBitCast(Ops[1], f64Ptr, "tmp");
+    Value *Load = Builder.CreateLoad(Ops[1], "tmp");
      Ops[1] = BuildVector(Load, UndefValue::get(Type::DoubleTy), NULL);
-    Instruction::CastOps opcode = CastInst::getCastOpcode(Ops[1],
-      IntrinsicOpIsSigned(Args, 1), ResultType, ExpIsSigned);
-    Ops[1] = CastInst::create(opcode, Ops[1], ResultType, "tmp",  
CurBB);
+    Ops[1] = Builder.CreateBitCast(Ops[1], ResultType, "tmp");
      Result = BuildVectorShuffle(Ops[0], Ops[1], 4, 5, 2, 3);
-    TargetIntrinsicCastResult(Result, ResultType,
-                              ResIsSigned, ExpIsSigned, CurBB);
+    Result = Builder.CreateBitCast(Result, ResultType, "tmp");
      return true;
    }
    case IX86_BUILTIN_STOREHPS: {
      VectorType *v2f64 = VectorType::get(Type::DoubleTy, 2);
      PointerType *f64Ptr = PointerType::get(Type::DoubleTy);
-    Ops[0] = new BitCastInst(Ops[0], f64Ptr, "tmp", CurBB);
+    Ops[0] = Builder.CreateBitCast(Ops[0], f64Ptr, "tmp");
      Value *Idx = ConstantInt::get(Type::Int32Ty, 1);
-    Ops[1] = new BitCastInst(Ops[1], v2f64, "tmp", CurBB);
-    Ops[1] = new ExtractElementInst(Ops[1], Idx, "tmp", CurBB);
-    Result = new StoreInst(Ops[1], Ops[0], false, CurBB);
+    Ops[1] = Builder.CreateBitCast(Ops[1], v2f64, "tmp");
+    Ops[1] = Builder.CreateExtractElement(Ops[1], Idx, "tmp");
+    Result = Builder.CreateStore(Ops[1], Ops[0]);
      return true;
    }
    case IX86_BUILTIN_STORELPS: {
      VectorType *v2f64 = VectorType::get(Type::DoubleTy, 2);
      PointerType *f64Ptr = PointerType::get(Type::DoubleTy);
-    Ops[0] = new BitCastInst(Ops[0], f64Ptr, "tmp", CurBB);
+    Ops[0] = Builder.CreateBitCast(Ops[0], f64Ptr, "tmp");
      Value *Idx = ConstantInt::get(Type::Int32Ty, 0);
-    Ops[1] = new BitCastInst(Ops[1], v2f64, "tmp", CurBB);
-    Ops[1] = new ExtractElementInst(Ops[1], Idx, "tmp", CurBB);
-    Result = new StoreInst(Ops[1], Ops[0], false, CurBB);
+    Ops[1] = Builder.CreateBitCast(Ops[1], v2f64, "tmp");
+    Ops[1] = Builder.CreateExtractElement(Ops[1], Idx, "tmp");
+    Result = Builder.CreateStore(Ops[1], Ops[0]);
      return true;
    }
    case IX86_BUILTIN_MOVSHDUP:
@@ -587,51 +475,26 @@
      Result = BuildVectorShuffle(Ops[0], Ops[0], 0, 0, 2, 2);
      return true;
    case IX86_BUILTIN_VEC_INIT_V2SI:
-    for (unsigned i = 0; i < 2; ++i)
-      Ops[i] = CastInst::createIntegerCast(Ops[i], Type::Int32Ty,  
false, "tmp",
-                                           CurBB);
-
      Result = BuildVector(Ops[0], Ops[1], NULL);
      return true;
    case IX86_BUILTIN_VEC_INIT_V4HI:
-    for (unsigned i = 0; i < 4; ++i)
-      Ops[i] = CastInst::createIntegerCast(Ops[i], Type::Int16Ty,  
false, "tmp",
-                                           CurBB);
-
      Result = BuildVector(Ops[0], Ops[1], Ops[2], Ops[3], NULL);
      return true;
-  case IX86_BUILTIN_VEC_INIT_V8QI: {
-    for (unsigned i = 0; i < 8; ++i)
-      Ops[i] = CastInst::createIntegerCast(Ops[i], Type::Int8Ty,  
false, "tmp",
-                                           CurBB);
-
+  case IX86_BUILTIN_VEC_INIT_V8QI:
      Result = BuildVector(Ops[0], Ops[1], Ops[2], Ops[3],
                           Ops[4], Ops[5], Ops[6], Ops[7], NULL);
      return true;
-  }
    case IX86_BUILTIN_VEC_EXT_V2SI:
    case IX86_BUILTIN_VEC_EXT_V4HI:
    case IX86_BUILTIN_VEC_EXT_V2DF:
    case IX86_BUILTIN_VEC_EXT_V4SI:
    case IX86_BUILTIN_VEC_EXT_V4SF:
-  case IX86_BUILTIN_VEC_EXT_V8HI: {
-    Ops[1] = CastInst::createIntegerCast(Ops[1], Type::Int32Ty,  
false, "tmp",
-                                         CurBB);
-    Result = new ExtractElementInst(Ops[0], Ops[1], "tmp", CurBB);
-    TargetIntrinsicCastResult(Result, ResultType,
-                              ResIsSigned, ExpIsSigned, CurBB);
+  case IX86_BUILTIN_VEC_EXT_V8HI:
+    Result = Builder.CreateExtractElement(Ops[0], Ops[1], "tmp");
      return true;
-  }
-  case IX86_BUILTIN_VEC_SET_V8HI: {
-    Instruction::CastOps opcode = CastInst::getCastOpcode(Ops[1],
-      IntrinsicOpIsSigned(Args, 1),  Type::Int16Ty, true);
-    Ops[1] = CastInst::create(opcode, Ops[1], Type::Int16Ty, "tmp",  
CurBB);
-    opcode = CastInst::getCastOpcode(Ops[2],
-      IntrinsicOpIsSigned(Args, 2), Type::Int32Ty, false);
-    Ops[2] = CastInst::create(opcode, Ops[2], Type::Int32Ty,  "tmp",  
CurBB);
-    Result = new InsertElementInst(Ops[0], Ops[1], Ops[2], "tmp",  
CurBB);
+  case IX86_BUILTIN_VEC_SET_V8HI:
+    Result = Builder.CreateInsertElement(Ops[0], Ops[1], Ops[2],  
"tmp");
      return true;
-  }
    case IX86_BUILTIN_CMPEQPS:
    case IX86_BUILTIN_CMPLTPS:
    case IX86_BUILTIN_CMPLEPS:
@@ -646,62 +509,34 @@
    case IX86_BUILTIN_CMPUNORDPS: {
      VectorType *v4f32 = VectorType::get(Type::FloatTy, 4);
      static Constant *cmpps = 0;
-    if (cmpps == 0) {
-      Module *M = CurBB->getParent()->getParent();
-      cmpps = M->getOrInsertFunction("llvm.x86.sse.cmp.ps",
-                                     v4f32, v4f32, v4f32,  
Type::Int8Ty, NULL);
-    }
+    if (cmpps == 0)
+      cmpps = TheModule->getOrInsertFunction("llvm.x86.sse.cmp.ps",
+                                             v4f32, v4f32, v4f32,  
Type::Int8Ty,
+                                             NULL);
      bool flip = false;
-    Value *Pred = 0;
+    unsigned PredCode;
      switch (FnCode) {
-      case IX86_BUILTIN_CMPEQPS:
-        Pred = ConstantInt::get(Type::Int8Ty, 0);
-        break;
-      case IX86_BUILTIN_CMPLTPS:
-        Pred = ConstantInt::get(Type::Int8Ty, 1);
-        break;
-      case IX86_BUILTIN_CMPGTPS:
-        Pred = ConstantInt::get(Type::Int8Ty, 1);
-        flip = true;
-        break;
-      case IX86_BUILTIN_CMPLEPS:
-        Pred = ConstantInt::get(Type::Int8Ty, 2);
-        break;
-      case IX86_BUILTIN_CMPGEPS:
-        Pred = ConstantInt::get(Type::Int8Ty, 2);
-        flip = true;
-        break;
-      case IX86_BUILTIN_CMPUNORDPS:
-        Pred = ConstantInt::get(Type::Int8Ty, 3);
-        break;
-      case IX86_BUILTIN_CMPNEQPS:
-        Pred = ConstantInt::get(Type::Int8Ty, 4);
-        break;
-      case IX86_BUILTIN_CMPNLTPS:
-        Pred = ConstantInt::get(Type::Int8Ty, 5);
-        break;
-      case IX86_BUILTIN_CMPNGTPS:
-        Pred = ConstantInt::get(Type::Int8Ty, 5);
-        flip = true;
-        break;
-      case IX86_BUILTIN_CMPNLEPS:
-        Pred = ConstantInt::get(Type::Int8Ty, 6);
-        break;
-      case IX86_BUILTIN_CMPNGEPS:
-        Pred = ConstantInt::get(Type::Int8Ty, 6);
-        flip = true;
-        break;
-      case IX86_BUILTIN_CMPORDPS:
-        Pred = ConstantInt::get(Type::Int8Ty, 7);
-        break;
+    default: assert(0 && "Unknown fncode!");
+    case IX86_BUILTIN_CMPEQPS: PredCode = 0; break;
+    case IX86_BUILTIN_CMPLTPS: PredCode = 1; break;
+    case IX86_BUILTIN_CMPGTPS: PredCode = 1; flip = true; break;
+    case IX86_BUILTIN_CMPLEPS: PredCode = 2; break;
+    case IX86_BUILTIN_CMPGEPS: PredCode = 2; flip = true; break;
+    case IX86_BUILTIN_CMPUNORDPS: PredCode = 3; break;
+    case IX86_BUILTIN_CMPNEQPS: PredCode = 4; break;
+    case IX86_BUILTIN_CMPNLTPS: PredCode = 5; break;
+    case IX86_BUILTIN_CMPNGTPS: PredCode = 5; flip = true; break;
+    case IX86_BUILTIN_CMPNLEPS: PredCode = 6; break;
+    case IX86_BUILTIN_CMPNGEPS: PredCode = 6; flip = true; break;
+    case IX86_BUILTIN_CMPORDPS: PredCode = 7; break;
      }
-    Value *Arg0 = new BitCastInst(Ops[0], v4f32, "tmp", CurBB);
-    Value *Arg1 = new BitCastInst(Ops[1], v4f32, "tmp", CurBB);
+    Value *Pred = ConstantInt::get(Type::Int8Ty, PredCode);
+    Value *Arg0 = Builder.CreateBitCast(Ops[0], v4f32, "tmp");
+    Value *Arg1 = Builder.CreateBitCast(Ops[1], v4f32, "tmp");
      if (flip) std::swap(Arg0, Arg1);
      Value *CallOps[3] = { Arg0, Arg1, Pred };
-    Result = new CallInst(cmpps, CallOps, 3, "tmp", CurBB);
-    TargetIntrinsicCastResult(Result, ResultType,
-                              ResIsSigned, ExpIsSigned, CurBB);
+    Result = Builder.CreateCall(cmpps, CallOps, 3, "tmp");
+    Result = Builder.CreateBitCast(Result, ResultType, "tmp");
      return true;
    }
    case IX86_BUILTIN_CMPEQSS:
@@ -716,45 +551,43 @@
    case IX86_BUILTIN_CMPUNORDSS: {
      VectorType *v4f32 = VectorType::get(Type::FloatTy, 4);
      static Constant *cmpss = 0;
-    if (cmpss == 0) {
-      Module *M = CurBB->getParent()->getParent();
-      cmpss = M->getOrInsertFunction("llvm.x86.sse.cmp.ss",
-                                     v4f32, v4f32, v4f32,  
Type::Int8Ty, NULL);
-    }
+    if (cmpss == 0)
+      cmpss = TheModule->getOrInsertFunction("llvm.x86.sse.cmp.ss",
+                                             v4f32, v4f32, v4f32,  
Type::Int8Ty,
+                                             NULL);
      Value *Pred = 0;
      switch (FnCode) {
-      case IX86_BUILTIN_CMPEQSS:
-        Pred = ConstantInt::get(Type::Int8Ty, 0);
-        break;
-      case IX86_BUILTIN_CMPLTSS:
-        Pred = ConstantInt::get(Type::Int8Ty, 1);
-        break;
-      case IX86_BUILTIN_CMPLESS:
-        Pred = ConstantInt::get(Type::Int8Ty, 2);
-        break;
-      case IX86_BUILTIN_CMPUNORDSS:
-        Pred = ConstantInt::get(Type::Int8Ty, 3);
-        break;
-      case IX86_BUILTIN_CMPNEQSS:
-        Pred = ConstantInt::get(Type::Int8Ty, 4);
-        break;
-      case IX86_BUILTIN_CMPNLTSS:
-        Pred = ConstantInt::get(Type::Int8Ty, 5);
-        break;
-      case IX86_BUILTIN_CMPNLESS:
-        Pred = ConstantInt::get(Type::Int8Ty, 6);
-        break;
-      case IX86_BUILTIN_CMPORDSS:
-        Pred = ConstantInt::get(Type::Int8Ty, 7);
-        break;
+    case IX86_BUILTIN_CMPEQSS:
+      Pred = ConstantInt::get(Type::Int8Ty, 0);
+      break;
+    case IX86_BUILTIN_CMPLTSS:
+      Pred = ConstantInt::get(Type::Int8Ty, 1);
+      break;
+    case IX86_BUILTIN_CMPLESS:
+      Pred = ConstantInt::get(Type::Int8Ty, 2);
+      break;
+    case IX86_BUILTIN_CMPUNORDSS:
+      Pred = ConstantInt::get(Type::Int8Ty, 3);
+      break;
+    case IX86_BUILTIN_CMPNEQSS:
+      Pred = ConstantInt::get(Type::Int8Ty, 4);
+      break;
+    case IX86_BUILTIN_CMPNLTSS:
+      Pred = ConstantInt::get(Type::Int8Ty, 5);
+      break;
+    case IX86_BUILTIN_CMPNLESS:
+      Pred = ConstantInt::get(Type::Int8Ty, 6);
+      break;
+    case IX86_BUILTIN_CMPORDSS:
+      Pred = ConstantInt::get(Type::Int8Ty, 7);
+      break;
      }
-    Value *Arg0 = new BitCastInst(Ops[0], v4f32, "tmp", CurBB);
-    Value *Arg1 = new BitCastInst(Ops[1], v4f32, "tmp", CurBB);
+    Value *Arg0 = Builder.CreateBitCast(Ops[0], v4f32, "tmp");
+    Value *Arg1 = Builder.CreateBitCast(Ops[1], v4f32, "tmp");

      Value *CallOps[3] = { Arg0, Arg1, Pred };
-    Result = new CallInst(cmpss, CallOps, 3, "tmp", CurBB);
-    TargetIntrinsicCastResult(Result, ResultType,
-                              ResIsSigned, ExpIsSigned, CurBB);
+    Result = Builder.CreateCall(cmpss, CallOps, 3, "tmp");
+    Result = Builder.CreateBitCast(Result, ResultType, "tmp");
      return true;
    }
    case IX86_BUILTIN_CMPEQPD:
@@ -772,7 +605,7 @@
      VectorType *v2f64 = VectorType::get(Type::DoubleTy, 2);
      static Constant *cmpps = 0;
      if (cmpps == 0) {
-      Module *M = CurBB->getParent()->getParent();
+      Module *M = Builder.GetInsertBlock()->getParent()->getParent();
        cmpps = M->getOrInsertFunction("llvm.x86.sse2.cmp.pd",
                                       v2f64, v2f64, v2f64,  
Type::Int8Ty, NULL);
      }
@@ -820,14 +653,13 @@
          Pred = ConstantInt::get(Type::Int8Ty, 7);
          break;
      }
-    Value *Arg0 = new BitCastInst(Ops[0], v2f64, "tmp", CurBB);
-    Value *Arg1 = new BitCastInst(Ops[1], v2f64, "tmp", CurBB);
+    Value *Arg0 = Builder.CreateBitCast(Ops[0], v2f64, "tmp");
+    Value *Arg1 = Builder.CreateBitCast(Ops[1], v2f64, "tmp");
      if (flip) std::swap(Arg0, Arg1);

      Value *CallOps[3] = { Arg0, Arg1, Pred };
-    Result = new CallInst(cmpps, CallOps, 3, "tmp", CurBB);
-    TargetIntrinsicCastResult(Result, ResultType,
-                              ResIsSigned, ExpIsSigned, CurBB);
+    Result = Builder.CreateCall(cmpps, CallOps, 3, "tmp");
+    Result = Builder.CreateBitCast(Result, ResultType, "tmp");
      return true;
    }
    case IX86_BUILTIN_CMPEQSD:
@@ -841,7 +673,7 @@
      VectorType *v2f64 = VectorType::get(Type::DoubleTy, 2);
      static Constant *cmpss = 0;
      if (cmpss == 0) {
-      Module *M = CurBB->getParent()->getParent();
+      Module *M = Builder.GetInsertBlock()->getParent()->getParent();
        cmpss = M->getOrInsertFunction("llvm.x86.sse2.cmp.sd",
                                       v2f64, v2f64, v2f64,  
Type::Int8Ty, NULL);
      }
@@ -873,38 +705,33 @@
          break;
      }

-    Value *Arg0 = new BitCastInst(Ops[0], v2f64, "tmp", CurBB);
-    Value *Arg1 = new BitCastInst(Ops[1], v2f64, "tmp", CurBB);
+    Value *Arg0 = Builder.CreateBitCast(Ops[0], v2f64, "tmp");
+    Value *Arg1 = Builder.CreateBitCast(Ops[1], v2f64, "tmp");
      Value *CallOps[3] = { Arg0, Arg1, Pred };
-    Result = new CallInst(cmpss, CallOps, 3, "tmp", CurBB);
-    TargetIntrinsicCastResult(Result, ResultType,
-                              ResIsSigned, ExpIsSigned, CurBB);
+    Result = Builder.CreateCall(cmpss, CallOps, 3, "tmp");
+    Result = Builder.CreateBitCast(Result, ResultType, "tmp");
      return true;
    }
    case IX86_BUILTIN_LDMXCSR: {
      PointerType *u32Ptr = PointerType::get(Type::Int32Ty);
      static Constant *ldmxcsr = 0;
-    if (ldmxcsr == 0) {
-      Module *M = CurBB->getParent()->getParent();
-      ldmxcsr = M->getOrInsertFunction("llvm.x86.sse.ldmxcsr",
-                                       Type::VoidTy, u32Ptr, NULL);
-    }
+    if (ldmxcsr == 0)
+      ldmxcsr = TheModule->getOrInsertFunction("llvm.x86.sse.ldmxcsr",
+                                               Type::VoidTy, u32Ptr,  
NULL);
      Value *Ptr = CreateTemporary(Type::Int32Ty);
-    new StoreInst(Ops[0], Ptr, false, CurBB);
-    Result = new CallInst(ldmxcsr, Ptr, "", CurBB);
+    Builder.CreateStore(Ops[0], Ptr);
+    Result = Builder.CreateCall(ldmxcsr, Ptr);
      return true;
    }
    case IX86_BUILTIN_STMXCSR: {
      PointerType *u32Ptr = PointerType::get(Type::Int32Ty);
      static Constant *stmxcsr = 0;
-    if (stmxcsr == 0) {
-      Module *M = CurBB->getParent()->getParent();
-      stmxcsr = M->getOrInsertFunction("llvm.x86.sse.stmxcsr",
-                                       Type::VoidTy, u32Ptr, NULL);
-    }
+    if (stmxcsr == 0)
+      stmxcsr = TheModule->getOrInsertFunction("llvm.x86.sse.stmxcsr",
+                                               Type::VoidTy, u32Ptr,  
NULL);
      Value *Ptr = CreateTemporary(Type::Int32Ty);
-    new CallInst(stmxcsr, Ptr, "", CurBB);
-    Result = new LoadInst(Ptr, "tmp", false, CurBB);
+    Builder.CreateCall(stmxcsr, Ptr);
+    Result = Builder.CreateLoad(Ptr, "tmp");
      return true;
    }
    }

Modified: apple-local/branches/llvm/gcc/config/rs6000/llvm-rs6000.cpp
===================================================================
--- apple-local/branches/llvm/gcc/config/rs6000/llvm-rs6000.cpp	 
2007-05-27 08:09:51 UTC (rev 127731)
+++ apple-local/branches/llvm/gcc/config/rs6000/llvm-rs6000.cpp	 
2007-05-27 15:11:20 UTC (rev 127732)
@@ -44,7 +44,7 @@
                                 unsigned OpNum, const char *Name,
                                 const Type *ResultType,
                                 std::vector<Value*> &Ops,
-                               BasicBlock *CurBB, Value *&Result) {
+                               LLVMBuilder &Builder, Value *&Result) {
    const Type *VoidPtrTy = PointerType::get(Type::Int8Ty);

    if (!Cache) {
@@ -55,7 +55,7 @@
      ArgTys.erase(ArgTys.begin() + OpNum);
      ArgTys[OpNum] = VoidPtrTy;
      FunctionType *FT = FunctionType::get(ResultType, ArgTys, false);
-    Module *M = CurBB->getParent()->getParent();
+    Module *M = Builder.GetInsertBlock()->getParent()->getParent();
      Cache = M->getOrInsertFunction(Name, FT);
    }

@@ -64,11 +64,11 @@
    Ptr = TTL->CastToType(Instruction::BitCast, Ptr, VoidPtrTy);

    if (!isa<Constant>(Offset) || !cast<Constant>(Offset)->isNullValue 
())
-    Ptr = new GetElementPtrInst(Ptr, Offset, "tmp", CurBB);
+    Ptr = Builder.CreateGEP(Ptr, Offset, "tmp");

    Ops.erase(Ops.begin() + OpNum);
    Ops[OpNum] = Ptr;
-  Value *V = new CallInst(Cache, &Ops[0], Ops.size(), "", CurBB);
+  Value *V = Builder.CreateCall(Cache, &Ops[0], Ops.size());

    if (V->getType() != Type::VoidTy) {
      V->setName("tmp");
@@ -96,24 +96,6 @@
              ((Ty == Type::FloatTy) ? 'f' : 'x'))));
  }

-/* TargetIntrinsicCastResult - This function just provides a frequently
- * used sequence for use inside TargetIntrinsicLower.
- */
-static void TargetIntrinsicCastResult(Value *&Result, const Type  
*ResultType,
-                                      bool ResIsSigned, bool  
ExpIsSigned,
-                                      BasicBlock *CurBB) {
-  Instruction::CastOps opcode =
-    CastInst::getCastOpcode(Result, ResIsSigned, ResultType,  
ExpIsSigned);
-  Result = CastInst::create(opcode, Result, ResultType, "tmp", CurBB);
-}
-
-/* IntrinsicOpIsSigned - This function determines if a given operand
- * to the intrinsic is signed or not.
- */
-static bool IntrinsicOpIsSigned(SmallVector<tree, 8> &Args, unsigned  
OpNum) {
-  return !TYPE_UNSIGNED(TREE_TYPE(Args[OpNum]));
-}
-
  /* TargetIntrinsicLower - To handle builtins, we want to expand the
   * invocation into normal LLVM code.  If the target can handle the  
builtin, this
   * function should emit the expanded code and return true.
@@ -123,112 +105,108 @@
                                        Value *DestLoc,
                                        Value *&Result,
                                        const Type *ResultType,
-                                      std::vector<Value*> &Ops,
-                                      SmallVector<tree, 8> &Args,
-                                      BasicBlock *CurBB,
-                                      bool ResIsSigned,
-                                      bool ExpIsSigned) {
+                                      std::vector<Value*> &Ops) {
    switch (FnCode) {
    default: break;
    case ALTIVEC_BUILTIN_VADDFP:
    case ALTIVEC_BUILTIN_VADDUBM:
    case ALTIVEC_BUILTIN_VADDUHM:
    case ALTIVEC_BUILTIN_VADDUWM:
-    Result = BinaryOperator::createAdd(Ops[0], Ops[1], "tmp", CurBB);
+    Result = Builder.CreateAdd(Ops[0], Ops[1], "tmp");
      return true;
    case ALTIVEC_BUILTIN_VSUBFP:
    case ALTIVEC_BUILTIN_VSUBUBM:
    case ALTIVEC_BUILTIN_VSUBUHM:
    case ALTIVEC_BUILTIN_VSUBUWM:
-    Result = BinaryOperator::createSub(Ops[0], Ops[1], "tmp", CurBB);
+    Result = Builder.CreateSub(Ops[0], Ops[1], "tmp");
      return true;
    case ALTIVEC_BUILTIN_VAND:
-    Result = BinaryOperator::createAnd(Ops[0], Ops[1], "tmp", CurBB);
+    Result = Builder.CreateAnd(Ops[0], Ops[1], "tmp");
      return true;
    case ALTIVEC_BUILTIN_VANDC:
-    Ops[1] = BinaryOperator::createNot(Ops[1], "tmp", CurBB);
-    Result = BinaryOperator::createAnd(Ops[0], Ops[1], "tmp", CurBB);
+    Ops[1] = Builder.CreateNot(Ops[1], "tmp");
+    Result = Builder.CreateAnd(Ops[0], Ops[1], "tmp");
      return true;
    case ALTIVEC_BUILTIN_VOR:
-    Result = BinaryOperator::createOr(Ops[0], Ops[1], "tmp", CurBB);
+    Result = Builder.CreateOr(Ops[0], Ops[1], "tmp");
      return true;
    case ALTIVEC_BUILTIN_VNOR:
-    Result = BinaryOperator::createOr(Ops[0], Ops[1], "tmp", CurBB);
-    Result = BinaryOperator::createNot(Result, "tmp", CurBB);
+    Result = Builder.CreateOr(Ops[0], Ops[1], "tmp");
+    Result = Builder.CreateNot(Result, "tmp");
      return true;
    case ALTIVEC_BUILTIN_VXOR:
-    Result = BinaryOperator::createXor(Ops[0], Ops[1], "tmp", CurBB);
+    Result = Builder.CreateXor(Ops[0], Ops[1], "tmp");
      return true;
    case ALTIVEC_BUILTIN_LVSL: {
        static Constant *Cache = NULL;
        MergeIntPtrOperand(this, Cache, 0, "llvm.ppc.altivec.lvsl",
-                         ResultType, Ops, CurBB, Result);
+                         ResultType, Ops, Builder, Result);
      }
      return true;
    case ALTIVEC_BUILTIN_LVSR: {
        static Constant *Cache = NULL;
        MergeIntPtrOperand(this, Cache, 0, "llvm.ppc.altivec.lvsr",
-                         ResultType, Ops, CurBB, Result);
+                         ResultType, Ops, Builder, Result);
      }
      return true;
    case ALTIVEC_BUILTIN_LVX: {
        static Constant *Cache = NULL;
        MergeIntPtrOperand(this, Cache, 0, "llvm.ppc.altivec.lvx",
-                         ResultType, Ops, CurBB, Result);
+                         ResultType, Ops, Builder, Result);
      }
      return true;
    case ALTIVEC_BUILTIN_LVXL: {
        static Constant *Cache = NULL;
        MergeIntPtrOperand(this, Cache, 0, "llvm.ppc.altivec.lvxl",
-                         ResultType, Ops, CurBB, Result);
+                         ResultType, Ops, Builder, Result);
      }
      return true;
    case ALTIVEC_BUILTIN_LVEBX: {
        static Constant *Cache = NULL;
        MergeIntPtrOperand(this, Cache, 0, "llvm.ppc.altivec.lvebx",
-                         ResultType, Ops, CurBB, Result);
+                         ResultType, Ops, Builder, Result);
      }
      return true;
    case ALTIVEC_BUILTIN_LVEHX: {
        static Constant *Cache = NULL;
        MergeIntPtrOperand(this, Cache, 0, "llvm.ppc.altivec.lvehx",
-                         ResultType, Ops, CurBB, Result);
+                         ResultType, Ops, Builder, Result);
      }
      return true;
    case ALTIVEC_BUILTIN_LVEWX: {
        static Constant *Cache = NULL;
        MergeIntPtrOperand(this, Cache, 0, "llvm.ppc.altivec.lvewx",
-                         ResultType, Ops, CurBB, Result);
+                         ResultType, Ops, Builder, Result);
      }
      return true;
    case ALTIVEC_BUILTIN_STVX: {
        static Constant *Cache = NULL;
        MergeIntPtrOperand(this, Cache, 1, "llvm.ppc.altivec.stvx",
-                         ResultType, Ops, CurBB, Result);
+                         ResultType, Ops, Builder, Result);
      }
      return true;
    case ALTIVEC_BUILTIN_STVEBX: {
        static Constant *Cache = NULL;
        MergeIntPtrOperand(this, Cache, 1, "llvm.ppc.altivec.stvebx",
-                         ResultType, Ops, CurBB, Result);
+                         ResultType, Ops, Builder, Result);
      }
      return true;
    case ALTIVEC_BUILTIN_STVEHX: {
        static Constant *Cache = NULL;
        MergeIntPtrOperand(this, Cache, 1, "llvm.ppc.altivec.stvehx",
-                         ResultType, Ops, CurBB, Result);
+                         ResultType, Ops, Builder, Result);
      }
      return true;
    case ALTIVEC_BUILTIN_STVEWX: {
        static Constant *Cache = NULL;
        MergeIntPtrOperand(this, Cache, 1, "llvm.ppc.altivec.stvewx",
-                         ResultType, Ops, CurBB, Result);
+                         ResultType, Ops, Builder, Result);
      }
      return true;
    case ALTIVEC_BUILTIN_STVXL: {
        static Constant *Cache = NULL;
        MergeIntPtrOperand(this, Cache, 1, "llvm.ppc.altivec.stvxl",
-                         ResultType, Ops, CurBB, Result);
+                         ResultType, Ops, Builder, Result);
      }
      return true;
    case ALTIVEC_BUILTIN_VSPLTISB:
@@ -297,14 +275,8 @@
        /* Map all of these to a shuffle. */
        unsigned Amt = Elt->getZExtValue() & 15;
        VectorType *v16i8 = VectorType::get(Type::Int8Ty, 16);
-      Value *Op0 = Ops[0];
-      Instruction::CastOps opc = CastInst::getCastOpcode(Op0,
-        IntrinsicOpIsSigned(Args,0), ResultType, false);
-      Ops[0] = CastToType(opc, Op0, v16i8);
-      Value *Op1 = Ops[1];
-      opc = CastInst::getCastOpcode(Op1,
-        IntrinsicOpIsSigned(Args,1), ResultType, false);
-      Ops[1] = CastToType(opc, Op1, v16i8);
+      Ops[0] = Builder.CreateBitCast(Op0, v16i8, "tmp");
+      Ops[1] = Builder.CreateBitCast(Op1, v16i8, "tmp");
        Result = BuildVectorShuffle(Ops[0], Ops[1],
                                    Amt, Amt+1, Amt+2, Amt+3,
                                    Amt+4, Amt+5, Amt+6, Amt+7,
@@ -317,26 +289,18 @@
      return true;
    case ALTIVEC_BUILTIN_VPKUHUM: {
      Value *Op0 = Ops[0];
-    Instruction::CastOps opc = CastInst::getCastOpcode(Op0,
-        IntrinsicOpIsSigned(Args,0), ResultType, ExpIsSigned);
-    Ops[0] = CastInst::create(opc, Op0, ResultType, Op0->getName(),  
CurBB);
+    Ops[0] = Builder.CreateBitCast(Op0, ResultType, Op0->getName 
().c_str());
      Value *Op1 = Ops[1];
-    opc = CastInst::getCastOpcode(Op1,
-        IntrinsicOpIsSigned(Args,1), ResultType, ExpIsSigned);
-    Ops[1] = CastInst::create(opc, Op1, ResultType, Op1->getName(),  
CurBB);
+    Ops[1] = Builder.CreateBitCast(Op1, ResultType, Op1->getName 
().c_str());
      Result = BuildVectorShuffle(Ops[0], Ops[1], 1, 3, 5, 7, 9, 11,  
13, 15,
                                  17, 19, 21, 23, 25, 27, 29, 31);
      return true;
    }
    case ALTIVEC_BUILTIN_VPKUWUM: {
      Value *Op0 = Ops[0];
-    Instruction::CastOps opc = CastInst::getCastOpcode(Op0,
-        IntrinsicOpIsSigned(Args,0), ResultType, ExpIsSigned);
-    Ops[0] = CastInst::create(opc, Op0, ResultType, Op0->getName(),  
CurBB);
+    Ops[0] = Builder.CreateBitCast(Op0, ResultType, Op0->getName 
().c_str());
      Value *Op1 = Ops[1];
-    opc = CastInst::getCastOpcode(Op1,
-        IntrinsicOpIsSigned(Args,1), ResultType, ExpIsSigned);
-    Ops[1] = CastInst::create(opc, Op1, ResultType, Op1->getName(),  
CurBB);
+    Ops[1] = Builder.CreateBitCast(Op1, ResultType, Op1->getName());
      Result = BuildVectorShuffle(Ops[0], Ops[1], 1, 3, 5, 7, 9, 11,  
13, 15);
      return true;
    }
@@ -365,29 +329,28 @@
    case ALTIVEC_BUILTIN_ABS_V4SF: {
      /* and out sign bits */
      VectorType *v4i32 = VectorType::get(Type::Int32Ty, 4);
-    Ops[0] = new BitCastInst(Ops[0], v4i32, Ops[0]->getName(),CurBB);
+    Ops[0] = Builder.CreateBitCast(Ops[0], v4i32, "tmp");
      Constant *C = ConstantInt::get(Type::Int32Ty, 0x7FFFFFFF);
      C = ConstantVector::get(std::vector<Constant*>(4, C));
-    Result = BinaryOperator::createAnd(Ops[0], C, "tmp", CurBB);
-    TargetIntrinsicCastResult(Result, ResultType,
-                              ResIsSigned, ExpIsSigned, CurBB);
+    Result = Builder.CreateAnd(Ops[0], C, "tmp");
+    Result = Builder.CreateBitCast(Result, ResultType, "tmp");
      return true;
    }
    case ALTIVEC_BUILTIN_ABS_V4SI:
    case ALTIVEC_BUILTIN_ABS_V8HI:
    case ALTIVEC_BUILTIN_ABS_V16QI: { /* iabs(x) -> smax(x, 0-x) */
-    Result = BinaryOperator::createNeg(Ops[0], "tmp", CurBB);
+    Result = Builder.CreateNeg(Ops[0], "tmp");
      /* get the right smax intrinsic. */
      static Constant *smax[3];
      const VectorType *PTy = cast<VectorType>(ResultType);
      unsigned N = GetAltivecTypeNumFromType(PTy->getElementType());
      if (smax[N] == 0) {
-      Module *M = CurBB->getParent()->getParent();
+      Module *M = Builder.GetInsertBlock()->getParent()->getParent();
        smax[N] = M->getOrInsertFunction(std::string 
("llvm.ppc.altivec.vmaxs")+
                           GetAltivecLetterFromType(PTy- 
 >getElementType()),
                                        ResultType, ResultType,  
ResultType, NULL);
      }
-    Result = new CallInst(smax[N], Ops[0], Result, "tmp", CurBB);
+    Result = Builder.CreateCall(smax[N], Ops[0], Result, "tmp");
      return true;
    }
    case ALTIVEC_BUILTIN_ABSS_V4SI:
@@ -398,21 +361,21 @@
      const VectorType *PTy = cast<VectorType>(ResultType);
      unsigned N = GetAltivecTypeNumFromType(PTy->getElementType());
      if (sxs[N] == 0) {
-      Module *M = CurBB->getParent()->getParent();
+      Module *M = Builder.GetInsertBlock()->getParent()->getParent();
        sxs[N] = M->getOrInsertFunction(std::string 
("llvm.ppc.altivec.vsubs")+
                       GetAltivecLetterFromType(PTy->getElementType()) 
+"s",
                                        ResultType, ResultType,  
ResultType, NULL);
      }
      Result = Constant::getNullValue(ResultType);
-    Result = new CallInst(sxs[N], Result, Ops[0], "tmp", CurBB);
+    Result = Builder.CreateCall(sxs[N], Result, Ops[0], "tmp");
      /* get the right smax intrinsic. */
      if (smax[N] == 0) {
-      Module *M = CurBB->getParent()->getParent();
+      Module *M = Builder.GetInsertBlock()->getParent()->getParent();
        smax[N] = M->getOrInsertFunction(std::string 
("llvm.ppc.altivec.vmaxs")+
                           GetAltivecLetterFromType(PTy- 
 >getElementType()),
                                        ResultType, ResultType,  
ResultType, NULL);
      }
-    Result = new CallInst(smax[N], Ops[0], Result, "tmp", CurBB);
+    Result = Builder.CreateCall(smax[N], Ops[0], Result, "tmp");
      return true;
    }
    }

Modified: apple-local/branches/llvm/gcc/config/rs6000/rs6000.h
===================================================================
--- apple-local/branches/llvm/gcc/config/rs6000/rs6000.h	2007-05-27  
08:09:51 UTC (rev 127731)
+++ apple-local/branches/llvm/gcc/config/rs6000/rs6000.h	2007-05-27  
15:11:20 UTC (rev 127732)
@@ -3676,10 +3676,7 @@
   *  return true.This macro is invoked from a method in the  
TreeToLLVM class.
   */
  #define LLVM_TARGET_INTRINSIC_LOWER(EXP, BUILTIN_CODE, DESTLOC,  
RESULT,       \
-                                    DESTTY, OPS, ARGS,  
CURBB,                 \
-                                    RESISSIGNED,  
EXPISSIGNED)                 \
-        TargetIntrinsicLower(EXP, BUILTIN_CODE, DESTLOC,  
RESULT,              \
-                             DESTTY, OPS, ARGS,  
CURBB,                        \
-                             RESISSIGNED, EXPISSIGNED);
+                                    DESTTY, OPS)                 \
+        TargetIntrinsicLower(EXP, BUILTIN_CODE, DESTLOC, RESULT,  
DESTTY, OPS);

  /* APPLE LOCAL end LLVM */

Modified: apple-local/branches/llvm/gcc/llvm-convert.cpp
===================================================================
--- apple-local/branches/llvm/gcc/llvm-convert.cpp	2007-05-27  
08:09:51 UTC (rev 127731)
+++ apple-local/branches/llvm/gcc/llvm-convert.cpp	2007-05-27  
15:11:20 UTC (rev 127732)
@@ -330,7 +330,6 @@
    FnDecl = fndecl;
    Fn = 0;
    ReturnBB = UnwindBB = 0;
-  CurBB = 0;

    if (TheDebugInfo) {
      expanded_location Location = expand_location 
(DECL_SOURCE_LOCATION (fndecl));
@@ -375,13 +374,13 @@
    struct FunctionPrologArgumentConversion : public DefaultABIClient {
      tree FunctionDecl;
      Function::arg_iterator &AI;
-    BasicBlock *CurBB;
+    LLVMBuilder Builder;
      std::vector<Value*> LocStack;
      std::vector<std::string> NameStack;
      FunctionPrologArgumentConversion(tree FnDecl,
                                       Function::arg_iterator &ai,
-                                     BasicBlock *curbb)
-      : FunctionDecl(FnDecl), AI(ai), CurBB(curbb) {}
+                                     const LLVMBuilder &B)
+      : FunctionDecl(FnDecl), AI(ai), Builder(B) {}

      void setName(const std::string &Name) {
        NameStack.push_back(Name);
@@ -400,7 +399,8 @@
        // If the function returns a structure by value, we transform  
the function
        // to take a pointer to the result as the first argument of  
the function
        // instead.
-      assert(AI != CurBB->getParent()->arg_end() &&"No explicit  
return value?");
+      assert(AI != Builder.GetInsertBlock()->getParent()->arg_end() &&
+             "No explicit return value?");
        AI->setName("agg.result");

        tree ResultDecl = DECL_RESULT(FunctionDecl);
@@ -416,12 +416,14 @@
               "Not type match and not passing by reference?");
        // Create an alloca for the ResultDecl.
        Value *Tmp = TheTreeToLLVM->CreateTemporary(AI->getType());
-      new StoreInst(AI, Tmp, CurBB);
+      Builder.CreateStore(AI, Tmp);
+
        SET_DECL_LLVM(ResultDecl, Tmp);
        if (TheDebugInfo) {
          TheDebugInfo->EmitDeclare(ResultDecl,
                                    llvm::dwarf::DW_TAG_return_variable,
-                                  "agg.result", RetTy, Tmp, CurBB);
+                                  "agg.result", RetTy, Tmp,
+                                  Builder.GetInsertBlock());
        }
        ++AI;
      }
@@ -432,28 +434,28 @@
          if (isa<PointerType>(ArgVal->getType()) && isa<PointerType> 
(LLVMTy)) {
            // If this is GCC being sloppy about pointer types,  
insert a bitcast.
            // See PR1083 for an example.
-          ArgVal = new BitCastInst(ArgVal, LLVMTy, "tmp", CurBB);
+          ArgVal = Builder.CreateBitCast(ArgVal, LLVMTy, "tmp");
          } else if (ArgVal->getType() == Type::DoubleTy) {
            // If this is a K&R float parameter, it got promoted to  
double. Insert
            // the truncation to float now.
-          ArgVal = new FPTruncInst(ArgVal, LLVMTy, NameStack.back(),  
CurBB);
+          ArgVal = Builder.CreateFPTrunc(ArgVal, LLVMTy,
+                                         NameStack.back().c_str());
          } else {
            // If this is just a mismatch between integer types, this  
is due
            // to K&R prototypes, where the forward proto defines the  
arg as int
            // and the actual impls is a short or char.
            assert(ArgVal->getType() == Type::Int32Ty && LLVMTy- 
 >isInteger() &&
                   "Lowerings don't match?");
-          ArgVal = new TruncInst(ArgVal, LLVMTy, NameStack.back(),  
CurBB);
+          ArgVal = Builder.CreateTrunc(ArgVal, LLVMTy,NameStack.back 
().c_str());
          }
        }
        assert(!LocStack.empty());
        Value *Loc = LocStack.back();
        if (cast<PointerType>(Loc->getType())->getElementType() !=  
LLVMTy)
          // This cast only involves pointers, therefore BitCast
-        Loc = CastInst::create(Instruction::BitCast, Loc,
-                               PointerType::get(LLVMTy), "tmp", CurBB);
+        Loc = Builder.CreateBitCast(Loc, PointerType::get(LLVMTy),  
"tmp");

-      new StoreInst(ArgVal, Loc, CurBB);
+      Builder.CreateStore(ArgVal, Loc);
        AI->setName(NameStack.back());
        ++AI;
      }
@@ -461,15 +463,17 @@
      void EnterField(unsigned FieldNo, const llvm::Type *StructTy) {
        NameStack.push_back(NameStack.back()+"."+utostr(FieldNo));

-      Constant *Zero = Constant::getNullValue(Type::Int32Ty);
-      Constant *FIdx = ConstantInt::get(Type::Int32Ty, FieldNo);
        Value *Loc = LocStack.back();
        if (cast<PointerType>(Loc->getType())->getElementType() !=  
StructTy)
          // This cast only involves pointers, therefore BitCast
-        Loc = CastInst::create(Instruction::BitCast, Loc,
-                               PointerType::get(StructTy),
-                                           "tmp", CurBB);
-      Loc = new GetElementPtrInst(Loc, Zero, FIdx, "tmp", CurBB);
+        Loc = Builder.CreateBitCast(Loc, PointerType::get(StructTy),  
"tmp");
+
+      Value *Idxs[] = {
+        Constant::getNullValue(Type::Int32Ty),
+        ConstantInt::get(Type::Int32Ty, FieldNo)
+      };
+
+      Loc = Builder.CreateGEP(Loc, Idxs, 2, "tmp");
        LocStack.push_back(Loc);
      }
      void ExitField() {
@@ -588,9 +592,10 @@
      AttributeUsedGlobals.push_back(Fn);

    // Create a new basic block for the function.
-  CurBB = new BasicBlock("entry", Fn);
+  Builder.SetInsertPoint(new BasicBlock("entry", Fn));

-  if (TheDebugInfo) TheDebugInfo->EmitFunctionStart(FnDecl, Fn, CurBB);
+  if (TheDebugInfo)
+    TheDebugInfo->EmitFunctionStart(FnDecl, Fn,  
Builder.GetInsertBlock());

    // Loop over all of the arguments to the function, setting  
Argument names and
    // creating argument alloca's for the PARM_DECLs in case their  
address is
@@ -598,7 +603,7 @@
    Function::arg_iterator AI = Fn->arg_begin();

    // Rename and alloca'ify real arguments.
-  FunctionPrologArgumentConversion Client(FnDecl, AI, CurBB);
+  FunctionPrologArgumentConversion Client(FnDecl, AI, Builder);
    TheLLVMABI<FunctionPrologArgumentConversion> ABIConverter(Client);

    // Handle the DECL_RESULT.
@@ -627,7 +632,8 @@
        SET_DECL_LLVM(Args, Tmp);
        if (TheDebugInfo) {
          TheDebugInfo->EmitDeclare(Args,  
llvm::dwarf::DW_TAG_arg_variable,
-                                  Name, TREE_TYPE(Args), Tmp, CurBB);
+                                  Name, TREE_TYPE(Args), Tmp,
+                                  Builder.GetInsertBlock());
        }

        Client.setName(Name);
@@ -672,7 +678,7 @@
        // If the DECL_RESULT is a scalar type, just load out the  
return value
        // and return it.
        tree TreeRetVal = DECL_RESULT(FnDecl);
-      RetVal = new LoadInst(DECL_LLVM(TreeRetVal), "retval", CurBB);
+      RetVal = Builder.CreateLoad(DECL_LLVM(TreeRetVal), "retval");
        bool RetValSigned = !TYPE_UNSIGNED(TREE_TYPE(TreeRetVal));
        Instruction::CastOps opcode = CastInst::getCastOpcode(
            RetVal, RetValSigned, Fn->getReturnType(), RetValSigned);
@@ -684,11 +690,11 @@
        // loading.
        RetVal = BitCastToType(DECL_LLVM(DECL_RESULT(FnDecl)),
                               PointerType::get(Fn->getReturnType()));
-      RetVal = new LoadInst(RetVal, "retval", CurBB);
+      RetVal = Builder.CreateLoad(RetVal, "retval");
      }
    }
-  if (TheDebugInfo) TheDebugInfo->EmitRegionEnd(Fn, CurBB);
-  new ReturnInst(RetVal, CurBB);
+  if (TheDebugInfo) TheDebugInfo->EmitRegionEnd(Fn,  
Builder.GetInsertBlock());
+  Builder.CreateRet(RetVal);

    // If this function has exceptions, emit the lazily created  
unwind block.
    if (UnwindBB) {
@@ -697,11 +703,9 @@
      if (ExceptionValue) {
        // Fetch and store exception handler.
        std::vector<Value*> Args;
-      Args.push_back(new LoadInst(ExceptionValue, "eh_ptr", CurBB));
-      new CallInst(FuncUnwindResume,
-                   &Args[0], Args.size(), "",
-                   CurBB);
-      new UnreachableInst(CurBB);
+      Args.push_back(Builder.CreateLoad(ExceptionValue, "eh_ptr"));
+      Builder.CreateCall(FuncUnwindResume, &Args[0], Args.size());
+      Builder.CreateUnreachable();
      } else {
        new UnwindInst(UnwindBB);
      }
@@ -745,9 +749,8 @@
      }

      // These node create an artificial jump to end of block.
-    if (TREE_CODE(exp) != BIND_EXPR && TREE_CODE(exp) !=  
STATEMENT_LIST) {
-      TheDebugInfo->EmitStopPoint(Fn, CurBB);
-    }
+    if (TREE_CODE(exp) != BIND_EXPR && TREE_CODE(exp) !=  
STATEMENT_LIST)
+      TheDebugInfo->EmitStopPoint(Fn, Builder.GetInsertBlock());
    }

    switch (TREE_CODE(exp)) {
@@ -977,13 +980,13 @@
    if (Constant *C = dyn_cast<Constant>(V))
      return ConstantExpr::getCast(Instruction::CastOps(opcode), C, Ty);

-  // Handle cast (cast bool X to T2) to bool as X, because this  
occurs all over
+  // Handle 'trunc (zext i1 X to T2) to i1' as X, because this  
occurs all over
    // the place.
-  if (CastInst *CI = dyn_cast<CastInst>(V))
+  if (ZExtInst *CI = dyn_cast<ZExtInst>(V))
      if (Ty == Type::Int1Ty && CI->getOperand(0)->getType() ==  
Type::Int1Ty)
        return CI->getOperand(0);
-  return CastInst::create(Instruction::CastOps(opcode), V, Ty, V- 
 >getName(),
-                          CurBB);
+  return Builder.CreateCast(Instruction::CastOps(opcode), V, Ty,
+                            V->getName().c_str());
  }

  /// CastToAnyType - Cast the specified value to the specified type  
making no
@@ -1075,6 +1078,7 @@
  /// the previous block falls through into it, add an explicit  
branch.  Also,
  /// manage fixups for EH info.
  void TreeToLLVM::EmitBlock(BasicBlock *BB) {
+  BasicBlock *CurBB = Builder.GetInsertBlock();
    // If the previous block falls through to BB, add an explicit  
branch.
    if (CurBB->getTerminator() == 0) {
      // If the previous block has no label and is empty, remove it:  
it is a
@@ -1089,13 +1093,13 @@
        }
      } else {
        // Otherwise, fall through to this block.
-      new BranchInst(BB, CurBB);
+      Builder.CreateBr(BB);
      }
    }

    // Add this block.
    Fn->getBasicBlockList().push_back(BB);
-  CurBB = BB;  // It is now the current block.
+  Builder.SetInsertPoint(BB);  // It is now the current block.

    // If there are no exception scopes that contain this block,  
exit.  This is
    // common for C++ code and almost uniformly true for C code.
@@ -1111,31 +1115,31 @@
  /// ptrs, copying all of the elements.
  static void CopyAggregate(Value *DestPtr, Value *SrcPtr,
                            bool isDstVolatile, bool isSrcVolatile,
-                          BasicBlock *CurBB) {
+                          LLVMBuilder &Builder) {
    assert(DestPtr->getType() == SrcPtr->getType() &&
           "Cannot copy between two pointers of different type!");
    const Type *ElTy = cast<PointerType>(DestPtr->getType())- 
 >getElementType();
    if (ElTy->isFirstClassType()) {
-    Value *V = new LoadInst(SrcPtr, "tmp", isSrcVolatile, CurBB);
-    new StoreInst(V, DestPtr, isDstVolatile, CurBB);
+    LoadInst *V = Builder.CreateLoad(SrcPtr, isSrcVolatile, "tmp");
+    Builder.CreateStore(V, DestPtr, isDstVolatile);
    } else if (const StructType *STy = dyn_cast<StructType>(ElTy)) {
      Constant *Zero = ConstantInt::get(Type::Int32Ty, 0);
      for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
        if (isPaddingElement(STy, i))
          continue;
        Constant *Idx = ConstantInt::get(Type::Int32Ty, i);
-      Value *DElPtr = new GetElementPtrInst(DestPtr, Zero, Idx,  
"tmp", CurBB);
-      Value *SElPtr = new GetElementPtrInst(SrcPtr, Zero, Idx,  
"tmp", CurBB);
-      CopyAggregate(DElPtr, SElPtr, isDstVolatile, isSrcVolatile,  
CurBB);
+      Value *DElPtr = Builder.CreateGEP(DestPtr, Zero, Idx, "tmp");
+      Value *SElPtr = Builder.CreateGEP(SrcPtr, Zero, Idx, "tmp");
+      CopyAggregate(DElPtr, SElPtr, isDstVolatile, isSrcVolatile,  
Builder);
      }
    } else {
      const ArrayType *ATy = cast<ArrayType>(ElTy);
      Constant *Zero = ConstantInt::get(Type::Int32Ty, 0);
      for (unsigned i = 0, e = ATy->getNumElements(); i != e; ++i) {
        Constant *Idx = ConstantInt::get(Type::Int32Ty, i);
-      Value *DElPtr = new GetElementPtrInst(DestPtr, Zero, Idx,  
"tmp", CurBB);
-      Value *SElPtr = new GetElementPtrInst(SrcPtr, Zero, Idx,  
"tmp", CurBB);
-      CopyAggregate(DElPtr, SElPtr, isDstVolatile, isSrcVolatile,  
CurBB);
+      Value *DElPtr = Builder.CreateGEP(DestPtr, Zero, Idx, "tmp");
+      Value *SElPtr = Builder.CreateGEP(SrcPtr, Zero, Idx, "tmp");
+      CopyAggregate(DElPtr, SElPtr, isDstVolatile, isSrcVolatile,  
Builder);
      }
    }
  }
@@ -1181,7 +1185,7 @@
        // FIXME: Is this always safe?  The LLVM type might  
theoretically have
        // holes or might be suboptimal to copy this way.  It may be  
better to
        // copy the structure by the GCCType's fields.
-      CopyAggregate(DestPtr, SrcPtr, isDstVolatile, isSrcVolatile,  
CurBB);
+      CopyAggregate(DestPtr, SrcPtr, isDstVolatile, isSrcVolatile,  
Builder);
        return;
      }
    }
@@ -1193,24 +1197,22 @@

  /// ZeroAggregate - Recursively traverse the potientially aggregate  
dest
  /// ptr, zero'ing all of the elements.
-static void ZeroAggregate(Value *DestPtr, BasicBlock *CurBB) {
+static void ZeroAggregate(Value *DestPtr, LLVMBuilder &Builder) {
    const Type *ElTy = cast<PointerType>(DestPtr->getType())- 
 >getElementType();
    if (ElTy->isFirstClassType()) {
-    new StoreInst(Constant::getNullValue(ElTy), DestPtr, CurBB);
+    Builder.CreateStore(Constant::getNullValue(ElTy), DestPtr);
    } else if (const StructType *STy = dyn_cast<StructType>(ElTy)) {
      Constant *Zero = ConstantInt::get(Type::Int32Ty, 0);
      for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
        Constant *Idx = ConstantInt::get(Type::Int32Ty, i);
-      Value *DElPtr = new GetElementPtrInst(DestPtr, Zero, Idx,  
"tmp", CurBB);
-      ZeroAggregate(DElPtr, CurBB);
+      ZeroAggregate(Builder.CreateGEP(DestPtr, Zero, Idx, "tmp"),  
Builder);
      }
    } else {
      const ArrayType *ATy = cast<ArrayType>(ElTy);
      Constant *Zero = ConstantInt::get(Type::Int32Ty, 0);
      for (unsigned i = 0, e = ATy->getNumElements(); i != e; ++i) {
        Constant *Idx = ConstantInt::get(Type::Int32Ty, i);
-      Value *DElPtr = new GetElementPtrInst(DestPtr, Zero, Idx,  
"tmp", CurBB);
-      ZeroAggregate(DElPtr, CurBB);
+      ZeroAggregate(Builder.CreateGEP(DestPtr, Zero, Idx, "tmp"),  
Builder);
      }
    }
  }
@@ -1228,7 +1230,7 @@
      // FIXME: Is this always safe?  The LLVM type might  
theoretically have holes
      // or might be suboptimal to copy this way.  It may be better  
to copy the
      // structure by the GCCType's fields.
-    ZeroAggregate(DestPtr, CurBB);
+    ZeroAggregate(DestPtr, Builder);
      return;
    }

@@ -1248,11 +1250,9 @@
      ConstantInt::get(Type::Int32Ty, Align)
    };

-  new CallInst(Intrinsic::getDeclaration(TheModule,
-                                         (IntPtr == Type::Int32Ty) ?
-                                         Intrinsic::memcpy_i32 :
-                                         Intrinsic::memcpy_i64),
-               Ops, 4, "", CurBB);
+  Intrinsic::ID IID =
+    (IntPtr == Type::Int32Ty) ? Intrinsic::memcpy_i32 :  
Intrinsic::memcpy_i64;
+  Builder.CreateCall(Intrinsic::getDeclaration(TheModule, IID), Ops,  
4);
  }

  void TreeToLLVM::EmitMemMove(Value *DestPtr, Value *SrcPtr, Value  
*Size,
@@ -1266,11 +1266,9 @@
      ConstantInt::get(Type::Int32Ty, Align)
    };

-  new CallInst(Intrinsic::getDeclaration(TheModule,
-                                         (IntPtr == Type::Int32Ty) ?
-                                         Intrinsic::memmove_i32 :
-                                         Intrinsic::memmove_i64),
-               Ops, 4, "", CurBB);
+  Intrinsic::ID IID =
+    (IntPtr == Type::Int32Ty) ? Intrinsic::memmove_i32 :  
Intrinsic::memmove_i64;
+  Builder.CreateCall(Intrinsic::getDeclaration(TheModule, IID), Ops,  
4);
  }

  void TreeToLLVM::EmitMemSet(Value *DestPtr, Value *SrcVal, Value  
*Size,
@@ -1284,11 +1282,10 @@
      ConstantInt::get(Type::Int32Ty, Align)
    };

-  new CallInst(Intrinsic::getDeclaration(TheModule,
-                                         (IntPtr == Type::Int32Ty) ?
-                                         Intrinsic::memset_i32 :
-                                         Intrinsic::memset_i64),
-               Ops, 4, "", CurBB);
+  Intrinsic::ID IID =
+    (IntPtr == Type::Int32Ty) ? Intrinsic::memset_i32 :  
Intrinsic::memset_i64;
+
+  Builder.CreateCall(Intrinsic::getDeclaration(TheModule, IID), Ops,  
4);
  }


@@ -1319,7 +1316,7 @@
  ///
  void TreeToLLVM::EmitBranchInternal(BasicBlock *Dest, bool  
IsExceptionEdge) {
    // Insert the branch.
-  BranchInst *BI = new BranchInst(Dest, CurBB);
+  BranchInst *BI = Builder.CreateBr(Dest);

    // If there are no current exception scopes, this edge *couldn't*  
need
    // cleanups.  It is not possible to jump into a scope that  
requires a cleanup.
@@ -1363,10 +1360,10 @@
          return;
        }

-      if (&CurBB->front() == BI) {
+      if (&Builder.GetInsertBlock()->front() == BI) {
          // Otherwise, if this block is empty except for the branch,  
change the
          // fixup to jump here and change the fixup to fix this branch.
-        Fixup.SrcBranch->setSuccessor(0, CurBB);
+        Fixup.SrcBranch->setSuccessor(0, Builder.GetInsertBlock());
          Fixup.SrcBranch = BI;
          return;
        }
@@ -1374,9 +1371,9 @@
        // Finally, if neither block is empty, create a new (empty)  
one and
        // revector BOTH branches to the new block.
        EmitBlock(new BasicBlock("cleanup"));
-      BranchInst *NewBI = new BranchInst(Dest, CurBB);
-      BI->setSuccessor(0, CurBB);
-      Fixup.SrcBranch->setSuccessor(0, CurBB);
+      BranchInst *NewBI = Builder.CreateBr(Dest);
+      BI->setSuccessor(0, Builder.GetInsertBlock());
+      Fixup.SrcBranch->setSuccessor(0, Builder.GetInsertBlock());
        Fixup.SrcBranch = NewBI;
        return;
      }
@@ -1483,7 +1480,7 @@
      AI = CreateTemporary(Ty);
      AI->setName(Name);
    } else {
-    AI = new AllocaInst(Ty, Size, Name, CurBB);
+    AI = Builder.CreateAlloca(Ty, Size, Name);
    }

    AI->setAlignment(Alignment);
@@ -1493,10 +1490,12 @@
    if (TheDebugInfo) {
      if (DECL_NAME(decl)) {
        TheDebugInfo->EmitDeclare(decl,  
llvm::dwarf::DW_TAG_auto_variable,
-                                Name, TREE_TYPE(decl), AI, CurBB);
+                                Name, TREE_TYPE(decl), AI,
+                                Builder.GetInsertBlock());
      } else if (TREE_CODE(decl) == RESULT_DECL) {
        TheDebugInfo->EmitDeclare(decl,  
llvm::dwarf::DW_TAG_return_variable,
-                                Name, TREE_TYPE(decl), AI, CurBB);
+                                Name, TREE_TYPE(decl), AI,
+                                Builder.GetInsertBlock());
      }
    }
  }
@@ -1504,7 +1503,7 @@
  Value *TreeToLLVM::EmitBIND_EXPR(tree exp, Value *DestLoc) {
    // Start region only if not top level.
    if (TheDebugInfo && DECL_SAVED_TREE(FnDecl) != exp)
-    TheDebugInfo->EmitRegionStart(Fn, CurBB);
+    TheDebugInfo->EmitRegionStart(Fn, Builder.GetInsertBlock());

    // Mark the corresponding BLOCK for output in its proper place.
    if (BIND_EXPR_BLOCK(exp) != 0 && !TREE_USED(BIND_EXPR_BLOCK(exp)))
@@ -1539,7 +1538,7 @@

    // End region only if not top level.
    if (TheDebugInfo && DECL_SAVED_TREE(FnDecl) != exp)
-    TheDebugInfo->EmitRegionEnd(Fn, CurBB);
+    TheDebugInfo->EmitRegionEnd(Fn, Builder.GetInsertBlock());

    return Result;
  }
@@ -1640,7 +1639,7 @@
      // Store the destination block to the GotoValue alloca.
      Value *V = Emit(TREE_OPERAND(exp, 0), 0);
      V = CastToType(Instruction::PtrToInt, V, TD.getIntPtrType());
-    new StoreInst(V, IndirectGotoValue, CurBB);
+    Builder.CreateStore(V, IndirectGotoValue);

      // NOTE: This is HORRIBLY INCORRECT in the presence of  
exception handlers.
      // There should be one collector block per cleanup level!  Note  
that
@@ -1672,13 +1671,12 @@
  }

  Value *TreeToLLVM::EmitCOND_EXPR(tree exp) {
-  // Emit the conditional expression and trunc/bitcast to Int1Ty
+  // Emit the conditional expression.
    Value *Cond = Emit(COND_EXPR_COND(exp), 0);
    // If its not already a bool, insert a comparison against zero to  
make it so.
    if (Cond->getType() != Type::Int1Ty)
-    Cond = new ICmpInst(ICmpInst::ICMP_NE, Cond,
-                        Constant::getNullValue(Cond->getType()),  
"toBool",
-                           CurBB);
+    Cond = Builder.CreateICmpNE(Cond, Constant::getNullValue(Cond- 
 >getType()),
+                                "toBool");
    tree Then = COND_EXPR_THEN(exp);
    tree Else = COND_EXPR_ELSE(exp);

@@ -1709,7 +1707,7 @@
          BasicBlock *ElseDest = getLabelDeclBlock(TREE_OPERAND 
(ElseStmt, 0));

          // Okay, we have success. Output the conditional branch.
-        new BranchInst(ThenDest, ElseDest, Cond, CurBB);
+        Builder.CreateCondBr(Cond, ThenDest, ElseDest);
          // Emit a "fallthrough" block, which is almost certainly dead.
          EmitBlock(new BasicBlock(""));
          return 0;
@@ -1738,7 +1736,7 @@
      FalseBlock = new BasicBlock("cond_false");

    // Emit the branch based on the condition.
-  new BranchInst(TrueBlock, FalseBlock, Cond, CurBB);
+  Builder.CreateCondBr(Cond, TrueBlock, FalseBlock);

    // Emit the true code.
    EmitBlock(TrueBlock);
@@ -1748,10 +1746,10 @@
    // If this is an if/then/else cond-expr, emit the else part,  
otherwise, just
    // fall through to the ContBlock.
    if (!HasEmptyElse) {
-    if (CurBB->getTerminator() == 0 &&
-        (!CurBB->getName().empty() ||
-         !CurBB->use_empty()))
-      new BranchInst(ContBlock, CurBB);  // Branch to continue block.
+    if (Builder.GetInsertBlock()->getTerminator() == 0 &&
+        (!Builder.GetInsertBlock()->getName().empty() ||
+         !Builder.GetInsertBlock()->use_empty()))
+      Builder.CreateBr(ContBlock);  // Branch to continue block.

      EmitBlock(FalseBlock);

@@ -1770,10 +1768,11 @@
    bool ExpIsSigned = !TYPE_UNSIGNED(TREE_TYPE(SWITCH_COND(exp)));

    // Emit the switch instruction.
-  SwitchInst *SI = new SwitchInst(SwitchExp, CurBB,
-                                  TREE_VEC_LENGTH(Cases), CurBB);
+  SwitchInst *SI = Builder.CreateSwitch(SwitchExp,  
Builder.GetInsertBlock(),
+                                        TREE_VEC_LENGTH(Cases));
    EmitBlock(new BasicBlock(""));
-  SI->setSuccessor(0, CurBB);   // Default location starts out as  
fall-through
+  // Default location starts out as fall-through
+  SI->setSuccessor(0, Builder.GetInsertBlock());

    assert(!SWITCH_BODY(exp) && "not a gimple switch?");

@@ -1818,21 +1817,19 @@
        }
      } else {
        // The range is too big to add to the switch - emit an "if".
-      Value *Diff = BinaryOperator::create(Instruction::Sub,  
SwitchExp, LowC,
-                                           "tmp", CurBB);
-      Value *Cond = new ICmpInst(ICmpInst::ICMP_ULE, Diff,
-                                 ConstantInt::get(Range), "tmp",  
CurBB);
+      Value *Diff = Builder.CreateSub(SwitchExp, LowC, "tmp");
+      Value *Cond = Builder.CreateICmpULE(Diff, ConstantInt::get 
(Range), "tmp");
        BasicBlock *False_Block = new BasicBlock("case_false");
-      new BranchInst(Dest, False_Block, Cond, CurBB);
+      Builder.CreateCondBr(Cond, Dest, False_Block);
        EmitBlock(False_Block);
      }
    }

    if (DefaultDest)
-    if (SI->getSuccessor(0) == CurBB)
+    if (SI->getSuccessor(0) == Builder.GetInsertBlock())
        SI->setSuccessor(0, DefaultDest);
      else {
-      new BranchInst(DefaultDest, CurBB);
+      Builder.CreateBr(DefaultDest);
        // Emit a "fallthrough" block, which is almost certainly dead.
        EmitBlock(new BasicBlock(""));
      }
@@ -1962,18 +1959,18 @@
    }

    // Fetch and store the exception.
-  Value *Ex = new CallInst(FuncEHException, "eh_ptr", CurBB);
-  new StoreInst(Ex, ExceptionValue, CurBB);
+  Value *Ex = Builder.CreateCall(FuncEHException, "eh_ptr");
+  Builder.CreateStore(Ex, ExceptionValue);

    // Fetch and store exception handler.
    std::vector<Value*> Args;
-  Args.push_back(new LoadInst(ExceptionValue, "eh_ptr", CurBB));
+  Args.push_back(Builder.CreateLoad(ExceptionValue, "eh_ptr"));
    Args.push_back(CastToType(Instruction::BitCast, FuncCPPPersonality,
                              PointerType::get(Type::Int8Ty)));
    for (unsigned i = 0, N = TypeInfos.size(); i < N; ++i)
      Args.push_back(TypeInfos[i]);
-  Value *Select = new CallInst(F, &Args[0], Args.size(),  
"eh_select", CurBB);
-  new StoreInst(Select, ExceptionSelectorValue, CurBB);
+  Value *Select = Builder.CreateCall(F, &Args[0], Args.size(),  
"eh_select");
+  Builder.CreateStore(Select, ExceptionSelectorValue);
  }


@@ -2139,9 +2136,9 @@


      // Catches will supply own terminator.
-    if (!CurBB->getTerminator()) {
+    if (!Builder.GetInsertBlock()->getTerminator()) {
        // Emit a branch to the new target.
-      BranchInst *BI = new BranchInst(FixupBr->getSuccessor(0), CurBB);
+      BranchInst *BI = Builder.CreateBr(FixupBr->getSuccessor(0));

        // The old branch now goes to the cleanup block.
        FixupBr->setSuccessor(0, CleanupBB);
@@ -2162,7 +2159,7 @@
    // emitting code into it.
    Fn->getBasicBlockList().splice(Fn->end(), Fn->getBasicBlockList(),
                                   FinallyBlock);
-  CurBB = FinallyBlock;
+  Builder.SetInsertPoint(FinallyBlock);

    // Now that all of the cleanup blocks have been expanded, remove  
the temporary
    // terminator we put on the FinallyBlock.
@@ -2209,18 +2206,17 @@
      // Call get eh type id.
      std::vector<Value*> Args;
      Args.push_back(TypeInfo);
-    Value *TypeID = new CallInst(cast<Value>(FuncEHGetTypeID),
-                                 &Args[0], Args.size(), "eh_typeid",  
CurBB);
-    Value *Select = new LoadInst(ExceptionSelectorValue, "tmp", CurBB);
+    Value *TypeID = Builder.CreateCall(FuncEHGetTypeID, &Args[0],  
Args.size(),
+                                       "eh_typeid");
+    Value *Select = Builder.CreateLoad(ExceptionSelectorValue, "tmp");

      // Compare with the exception selector.
-    Value *Compare =
-           new ICmpInst(ICmpInst::ICMP_EQ, Select, TypeID, "tmp",  
CurBB);
+    Value *Compare = Builder.CreateICmpEQ(Select, TypeID, "tmp");
      ThenBlock = new BasicBlock("eh_then");
      ElseBlock = new BasicBlock("eh_else");

      // Branch on the compare.
-    new BranchInst(ThenBlock, ElseBlock, Compare, CurBB);
+    Builder.CreateCondBr(Compare, ThenBlock, ElseBlock);
    } else {
      ThenBlock = new BasicBlock("eh_then");

@@ -2237,17 +2233,16 @@
        // Call get eh type id.
        std::vector<Value*> Args;
        Args.push_back(TypeInfo);
-      Value *TypeID = new CallInst(cast<Value>(FuncEHGetTypeID),
-                                 &Args[0], Args.size(), "eh_typeid",  
CurBB);
-      Value *Select = new LoadInst(ExceptionSelectorValue, "tmp",  
CurBB);
+      Value *TypeID = Builder.CreateCall(FuncEHGetTypeID, &Args[0],  
Args.size(),
+                                         "eh_typeid");
+      Value *Select = Builder.CreateLoad(ExceptionSelectorValue,  
"tmp");

        // Compare with the exception selector.
-      Value *Compare =
-             new ICmpInst(ICmpInst::ICMP_EQ, Select, TypeID, "tmp",  
CurBB);
+      Value *Compare = Builder.CreateICmpEQ(Select, TypeID, "tmp");
        ElseBlock = new BasicBlock("eh_else");

        // Branch on the compare.
-      new BranchInst(ThenBlock, ElseBlock, Compare, CurBB);
+      Builder.CreateCondBr(Compare, ThenBlock, ElseBlock);
      }
    }

@@ -2259,8 +2254,8 @@

    // Branch to the try exit.
    assert(!FinallyStack.empty() && "Need an exit point");
-  if (!CurBB->getTerminator())
-    new BranchInst(FinallyStack.back(), CurBB);
+  if (!Builder.GetInsertBlock()->getTerminator())
+    Builder.CreateBr(FinallyStack.back());

    // Start the else block.
    if (ElseBlock) EmitBlock(ElseBlock);
@@ -2277,7 +2272,7 @@

    // Load exception address.
    CreateExceptionValues();
-  return new LoadInst(ExceptionValue, "eh_value", CurBB);
+  return Builder.CreateLoad(ExceptionValue, "eh_value");
  }

  /// EmitEH_FILTER_EXPR - Handle EH_FILTER_EXPR.
@@ -2291,17 +2286,16 @@

    // The result of a filter landing pad will be a negative index if  
there is
    // a match.
-  Value *Select = new LoadInst(ExceptionSelectorValue, "tmp", CurBB);
+  Value *Select = Builder.CreateLoad(ExceptionSelectorValue, "tmp");

    // Compare with the filter action value.
    Value *Zero = ConstantInt::get(Type::Int32Ty, 0);
-  Value *Compare =
-         new ICmpInst(ICmpInst::ICMP_SLT, Select, Zero, "tmp", CurBB);
+  Value *Compare = Builder.CreateICmpSLT(Select, Zero, "tmp");

    // Branch on the compare.
    BasicBlock *FilterBB = new BasicBlock("filter");
    BasicBlock *NoFilterBB = new BasicBlock("nofilter");
-  new BranchInst(FilterBB, NoFilterBB, Compare, CurBB);
+  Builder.CreateCondBr(Compare, FilterBB, NoFilterBB);

    EmitBlock(FilterBB);
    Emit(EH_FILTER_FAILURE(exp), 0);
@@ -2358,14 +2352,14 @@
        // Scalar value: emit a load.
        Value *Ptr = CastToType(Instruction::BitCast, LV.Ptr,
                                PointerType::get(Ty));
-      return new LoadInst(Ptr, "tmp", isVolatile, CurBB);
+      return Builder.CreateLoad(Ptr, isVolatile, "tmp");
      } else {
        EmitAggregateCopy(DestLoc, LV.Ptr, TREE_TYPE(exp), false,  
isVolatile);
        return 0;
      }
    } else {
      // This is a bitfield reference.
-    Value *Val = new LoadInst(LV.Ptr, "tmp", isVolatile, CurBB);
+    Value *Val = Builder.CreateLoad(LV.Ptr, isVolatile, "tmp");
      unsigned ValSizeInBits = Val->getType()->getPrimitiveSizeInBits();

      assert(Val->getType()->isInteger() && "Invalid bitfield lvalue!");
@@ -2384,14 +2378,16 @@
      if (LV.BitStart+LV.BitSize != ValSizeInBits) {
        Value *ShAmt = ConstantInt::get(Val->getType(),
                                         ValSizeInBits-(LV.BitStart 
+LV.BitSize));
-      Val = BinaryOperator::createShl(Val, ShAmt, "tmp", CurBB);
+      Val = Builder.CreateShl(Val, ShAmt, "tmp");
      }

      // Shift right required?
      if (ValSizeInBits-LV.BitSize) {
        Value *ShAmt = ConstantInt::get(Val->getType(), ValSizeInBits- 
LV.BitSize);
-      Val = BinaryOperator::create(TYPE_UNSIGNED(TREE_TYPE(exp)) ?
-        Instruction::LShr : Instruction::AShr, Val, ShAmt, "tmp",  
CurBB);
+      if (TYPE_UNSIGNED(TREE_TYPE(exp)))
+        Val = Builder.CreateLShr(Val, ShAmt, "tmp");
+      else
+        Val = Builder.CreateAShr(Val, ShAmt, "tmp");
      }

      if (TYPE_UNSIGNED(TREE_TYPE(exp)))
@@ -2451,7 +2447,7 @@
    // from thinking that control flow will fall into the subsequent  
block.
    //
    if (fndecl && TREE_THIS_VOLATILE(fndecl)) {
-    new UnreachableInst(CurBB);
+    Builder.CreateUnreachable();
      EmitBlock(new BasicBlock(""));
    }
    return Result;
@@ -2466,15 +2462,15 @@
      SmallVector<Value*, 16> &CallOperands;
      CallingConv::ID &CallingConvention;
      bool isStructRet;
-    BasicBlock *CurBB;
+    LLVMBuilder &Builder;
      Value *DestLoc;
      std::vector<Value*> LocStack;

      FunctionCallArgumentConversion(tree exp, SmallVector<Value*,  
16> &ops,
                                     CallingConv::ID &cc,
-                                   BasicBlock *bb, Value *destloc)
+                                   LLVMBuilder &b, Value *destloc)
        : CallExpression(exp), CallOperands(ops), CallingConvention(cc),
-        CurBB(bb), DestLoc(destloc) {
+        Builder(b), DestLoc(destloc) {
        CallingConvention = CallingConv::C;
        isStructRet = false;
  #ifdef TARGET_ADJUST_LLVM_CC
@@ -2545,11 +2541,9 @@
        Value *Loc = LocStack.back();
        if (cast<PointerType>(Loc->getType())->getElementType() !=  
LLVMTy)
          // This always deals with pointer types so BitCast is  
appropriate
-        Loc = CastInst::create(Instruction::BitCast, Loc,
-                               PointerType::get(LLVMTy), "tmp", CurBB);
+        Loc = Builder.CreateBitCast(Loc, PointerType::get(LLVMTy),  
"tmp");

-      Value *V = new LoadInst(Loc, "tmp", CurBB);
-      CallOperands.push_back(V);
+      CallOperands.push_back(Builder.CreateLoad(Loc, "tmp"));
      }

      void EnterField(unsigned FieldNo, const llvm::Type *StructTy) {
@@ -2558,11 +2552,9 @@
        Value *Loc = LocStack.back();
        if (cast<PointerType>(Loc->getType())->getElementType() !=  
StructTy)
          // This always deals with pointer types so BitCast is  
appropriate
-        Loc = CastInst::create(Instruction::BitCast, Loc,
-                               PointerType::get(StructTy), "tmp",  
CurBB);
+        Loc = Builder.CreateBitCast(Loc, PointerType::get(StructTy),  
"tmp");

-      Loc = new GetElementPtrInst(Loc, Zero, FIdx, "tmp", CurBB);
-      LocStack.push_back(Loc);
+      LocStack.push_back(Builder.CreateGEP(Loc, Zero, FIdx, "tmp"));
      }
      void ExitField() {
        LocStack.pop_back();
@@ -2591,7 +2583,7 @@
    SmallVector<Value*, 16> CallOperands;
    CallingConv::ID CallingConvention;
    FunctionCallArgumentConversion Client(exp, CallOperands,  
CallingConvention,
-                                        CurBB, DestLoc);
+                                        Builder, DestLoc);
    TheLLVMABI<FunctionCallArgumentConversion> ABIConverter(Client);

    // Handle the result, including struct returns.
@@ -2660,13 +2652,12 @@

    Value *Call;
    if (!UnwindBlock) {
-    Call = new CallInst(Callee, &CallOperands[0], CallOperands.size(),
-                        "", CurBB);
+    Call = Builder.CreateCall(Callee, &CallOperands[0],  
CallOperands.size());
      cast<CallInst>(Call)->setCallingConv(CallingConvention);
    } else {
      BasicBlock *NextBlock = new BasicBlock("invcont");
-    Call = new InvokeInst(Callee, NextBlock, UnwindBlock,
-                          &CallOperands[0], CallOperands.size(), "",  
CurBB);
+    Call = Builder.CreateInvoke(Callee, NextBlock, UnwindBlock,
+                                &CallOperands[0], CallOperands.size());
      cast<InvokeInst>(Call)->setCallingConv(CallingConvention);

      // Lazily create an unwind block for this scope, which we can  
emit a fixup
@@ -2702,7 +2693,7 @@
      return Call;   // Normal scalar return.

    DestLoc = BitCastToType(DestLoc, PointerType::get(Call->getType()));
-  new StoreInst(Call, DestLoc, CurBB);
+  Builder.CreateStore(Call, DestLoc);
    return 0;
  }

@@ -2810,7 +2801,7 @@
          RHS = CastToAnyType(RHS, Op1Signed, PT->getElementType(),  
Op0Signed);
        else
          LV.Ptr = BitCastToType(LV.Ptr, PointerType::get(RHS->getType 
()));
-      new StoreInst(RHS, LV.Ptr, isVolatile, CurBB);
+      Builder.CreateStore(RHS, LV.Ptr, isVolatile);
        return RHS;
      }

@@ -2837,7 +2828,7 @@

    // Last case, this is a store to a bitfield, so we have to emit a
    // read/modify/write sequence.
-  Value *OldVal = new LoadInst(LV.Ptr, "tmp", isVolatile, CurBB);
+  Value *OldVal = Builder.CreateLoad(LV.Ptr, isVolatile, "tmp");

    // If the target is big-endian, invert the bit in the word.
    unsigned ValSizeInBits = TD.getTypeSize(OldVal->getType())*8;
@@ -2849,8 +2840,8 @@
    Value *RetVal = RHS;
    RHS = CastToAnyType(RHS, Op1Signed, OldVal->getType(), Op0Signed);
    if (LV.BitStart)
-    RHS = BinaryOperator::createShl(RHS, ConstantInt::get(RHS- 
 >getType(),
-                                    LV.BitStart), "tmp", CurBB);
+    RHS = Builder.CreateShl(RHS, ConstantInt::get(RHS->getType(),  
LV.BitStart),
+                            "tmp");

    // Next, if this doesn't touch the top bit, mask out any bits  
that shouldn't
    // be set in the result.
@@ -2858,15 +2849,15 @@
    Constant *Mask = ConstantInt::get(Type::Int64Ty, MaskVal);
    Mask = ConstantExpr::getTruncOrBitCast(Mask, RHS->getType());
    if (LV.BitStart+LV.BitSize != ValSizeInBits)
-    RHS = BinaryOperator::createAnd(RHS, Mask, "tmp", CurBB);
+    RHS = Builder.CreateAnd(RHS, Mask, "tmp");

    // Next, mask out the bits this bit-field should include from the  
old value.
    Mask = ConstantExpr::getNot(Mask);
-  OldVal = BinaryOperator::createAnd(OldVal, Mask, "tmp", CurBB);
+  OldVal = Builder.CreateAnd(OldVal, Mask, "tmp");

    // Finally, merge the two together and store it.
-  Value *Val = BinaryOperator::createOr(OldVal, RHS, "tmp", CurBB);
-  new StoreInst(Val, LV.Ptr, isVolatile, CurBB);
+  Value *Val = Builder.CreateOr(OldVal, RHS, "tmp");
+  Builder.CreateStore(Val, LV.Ptr, isVolatile);
    return RetVal;
  }

@@ -2897,7 +2888,7 @@
    Value *OpVal = Emit(Op, 0);
    DestLoc = CastToType(Instruction::BitCast, DestLoc,
                         PointerType::get(OpVal->getType()));
-  new StoreInst(OpVal, DestLoc, CurBB);
+  Builder.CreateStore(OpVal, DestLoc);
    return 0;
  }

@@ -2953,8 +2944,8 @@
        return 0;

      const Type *ExpTy = ConvertType(TREE_TYPE(exp));
-    return new LoadInst(CastToType(Instruction::BitCast, Target,
-                                   PointerType::get(ExpTy)), "tmp",  
CurBB);
+    return Builder.CreateLoad(CastToType(Instruction::BitCast, Target,
+                                         PointerType::get(ExpTy)),  
"tmp");
    }

    if (DestLoc) {
@@ -2964,7 +2955,7 @@
      assert(OpVal && "Expected a scalar result!");
      DestLoc = CastToType(Instruction::BitCast, DestLoc,
                           PointerType::get(OpVal->getType()));
-    new StoreInst(OpVal, DestLoc, CurBB);
+    Builder.CreateStore(OpVal, DestLoc);
      return 0;
    }

@@ -2977,23 +2968,22 @@
    // bitcast'able.  This supports things like v_c_e(foo*, float).
    if (isa<PointerType>(OpVal->getType())) {
      if (isa<PointerType>(DestTy))   // ptr->ptr is a simple bitcast.
-      return new BitCastInst(OpVal, DestTy, "tmp", CurBB);
+      return Builder.CreateBitCast(OpVal, DestTy, "tmp");
      // Otherwise, ptrtoint to intptr_t first.
-    OpVal = new PtrToIntInst(OpVal, TD.getIntPtrType(), "tmp", CurBB);
+    OpVal = Builder.CreatePtrToInt(OpVal, TD.getIntPtrType(), "tmp");
    }

    // If the destination type is a pointer, use inttoptr.
    if (isa<PointerType>(DestTy))
-    return new IntToPtrInst(OpVal, DestTy, "tmp", CurBB);
+    return Builder.CreateIntToPtr(OpVal, DestTy, "tmp");

    // Otherwise, use a bitcast.
-  return new BitCastInst(OpVal, DestTy, "tmp", CurBB);
+  return Builder.CreateBitCast(OpVal, DestTy, "tmp");
  }

  Value *TreeToLLVM::EmitNEGATE_EXPR(tree exp, Value *DestLoc) {
    if (!DestLoc)
-    return BinaryOperator::createNeg(Emit(TREE_OPERAND(exp, 0), 0),
-                                     "tmp", CurBB);
+    return Builder.CreateNeg(Emit(TREE_OPERAND(exp, 0), 0), "tmp");

    // Emit the operand to a temporary.
    const Type *ComplexTy=cast<PointerType>(DestLoc->getType())- 
 >getElementType();
@@ -3003,8 +2993,8 @@
    // Handle complex numbers: -(a+ib) = -a + i*-b
    Value *R, *I;
    EmitLoadFromComplex(R, I, Tmp, TREE_THIS_VOLATILE(TREE_OPERAND 
(exp, 0)));
-  R = BinaryOperator::createNeg(R, "tmp", CurBB);
-  I = BinaryOperator::createNeg(I, "tmp", CurBB);
+  R = Builder.CreateNeg(R, "tmp");
+  I = Builder.CreateNeg(I, "tmp");
    EmitStoreToComplex(DestLoc, R, I, false);
    return 0;
  }
@@ -3019,7 +3009,7 @@
    // Handle complex numbers: ~(a+ib) = a + i*-b
    Value *R, *I;
    EmitLoadFromComplex(R, I, Tmp, TREE_THIS_VOLATILE(TREE_OPERAND 
(exp, 0)));
-  I = BinaryOperator::createNeg(I, "tmp", CurBB);
+  I = Builder.CreateNeg(I, "tmp");
    EmitStoreToComplex(DestLoc, R, I, false);
    return 0;
  }
@@ -3027,11 +3017,11 @@
  Value *TreeToLLVM::EmitABS_EXPR(tree exp) {
    Value *Op = Emit(TREE_OPERAND(exp, 0), 0);
    if (!Op->getType()->isFloatingPoint()) {
-    Instruction *OpN = BinaryOperator::createNeg(Op, Op->getName() 
+"neg",CurBB);
-    ICmpInst::Predicate pred = TYPE_UNSIGNED(TREE_TYPE(TREE_OPERAND 
(exp,0))) ?
+    Instruction *OpN = Builder.CreateNeg(Op, (Op->getName() 
+"neg").c_str());
+    ICmpInst::Predicate pred = TYPE_UNSIGNED(TREE_TYPE(TREE_OPERAND 
(exp, 0))) ?
        ICmpInst::ICMP_UGE : ICmpInst::ICMP_SGE;
-    Value *Cmp = new ICmpInst(pred, Op, OpN->getOperand(0),  
"abscond", CurBB);
-    return new SelectInst(Cmp, Op, OpN, "abs", CurBB);
+    Value *Cmp = Builder.CreateICmp(pred, Op, OpN->getOperand(0),  
"abscond");
+    return Builder.CreateSelect(Cmp, Op, OpN, "abs");
    } else {
      // Turn FP abs into fabs/fabsf.
      return EmitBuiltinUnaryFPOp(Op, "fabsf", "fabs");
@@ -3045,15 +3035,14 @@
              "Expected integer type here");
      Op = CastToType(Instruction::PtrToInt, Op, TREE_TYPE(exp));
    }
-  return BinaryOperator::createNot(Op, Op->getName()+"not", CurBB);
+  return Builder.CreateNot(Op, (Op->getName()+"not").c_str());
  }

  Value *TreeToLLVM::EmitTRUTH_NOT_EXPR(tree exp) {
    Value *V = Emit(TREE_OPERAND(exp, 0), 0);
    if (V->getType() != Type::Int1Ty)
-    V = new ICmpInst(ICmpInst::ICMP_NE, V,
-                     Constant::getNullValue(V->getType()), "toBool",  
CurBB);
-  V = BinaryOperator::createNot(V, V->getName()+"not", CurBB);
+    V = Builder.CreateICmpNE(V, Constant::getNullValue(V->getType 
()), "toBool");
+  V = Builder.CreateNot(V, (V->getName()+"not").c_str());
    return CastToUIntType(V, ConvertType(TREE_TYPE(exp)));
  }

@@ -3086,15 +3075,15 @@
        ICmpInst::Predicate(TYPE_UNSIGNED(Op0Ty) ? UIOpc : SIOpc);

      // Get the compare instructions
-    Value *Result = new ICmpInst(pred, LHS, RHS, "tmp", CurBB);
+    Value *Result = Builder.CreateICmp(pred, LHS, RHS, "tmp");

      // The GCC type is probably an int, not a bool.
      return CastToUIntType(Result, ConvertType(TREE_TYPE(exp)));
    }

    // Handle floating point comparisons, if we get here.
-  Value *Result =
-    new FCmpInst(FCmpInst::Predicate(FPPred), LHS, RHS, "tmp", CurBB);
+  Value *Result = Builder.CreateFCmp(FCmpInst::Predicate(FPPred),
+                                     LHS, RHS, "tmp");

    // The GCC type is probably an int, not a bool.
    return CastToUIntType(Result, ConvertType(TREE_TYPE(exp)));
@@ -3123,8 +3112,7 @@
    LHS = CastToAnyType(LHS, LHSIsSigned, Ty, TyIsSigned);
    RHS = CastToAnyType(RHS, RHSIsSigned, Ty, TyIsSigned);

-  return BinaryOperator::create((Instruction::BinaryOps)Opc, LHS, RHS,
-                                "tmp", CurBB);
+  return Builder.CreateBinOp((Instruction::BinaryOps)Opc, LHS, RHS,  
"tmp");
  }

  /// EmitPtrBinOp - Handle binary expressions involving pointers,  
e.g. "P+4".
@@ -3157,7 +3145,7 @@
          if (Opc == Instruction::Sub)
            EltOffset = -EltOffset;
          Constant *C = ConstantInt::get(Type::Int64Ty, EltOffset);
-        Value *V = new GetElementPtrInst(LHS, C, "tmp", CurBB);
+        Value *V = Builder.CreateGEP(LHS, C, "tmp");
          return CastToType(Instruction::BitCast, V, TREE_TYPE(exp));
        }
      }
@@ -3171,8 +3159,7 @@
    bool RHSIsSigned = !TYPE_UNSIGNED(TREE_TYPE(TREE_OPERAND(exp, 1)));
    LHS = CastToAnyType(LHS, LHSIsSigned, IntPtrTy, false);
    RHS = CastToAnyType(RHS, RHSIsSigned, IntPtrTy, false);
-  Value *V = BinaryOperator::create((Instruction::BinaryOps)Opc,  
LHS, RHS,
-                                    "tmp", CurBB);
+  Value *V = Builder.CreateBinOp((Instruction::BinaryOps)Opc, LHS,  
RHS, "tmp");
    return CastToType(Instruction::IntToPtr, V, ConvertType(TREE_TYPE 
(exp)));
  }

@@ -3185,13 +3172,12 @@

    // This is a truth operation like the strict &&,||,^^.  Convert  
to bool as
    // a test against zero
-  LHS = new ICmpInst(ICmpInst::ICMP_NE, LHS,
-                     Constant::getNullValue(LHS->getType()),  
"toBool", CurBB);
-  RHS = new ICmpInst(ICmpInst::ICMP_NE, RHS,
-                     Constant::getNullValue(RHS->getType()),  
"toBool", CurBB);
+  LHS = Builder.CreateICmpNE(LHS, Constant::getNullValue(LHS->getType 
()),
+                             "toBool");
+  RHS = Builder.CreateICmpNE(RHS, Constant::getNullValue(RHS->getType 
()),
+                             "toBool");

-  Value *Res = BinaryOperator::create((Instruction::BinaryOps)Opc,  
LHS, RHS,
-                                      "tmp", CurBB);
+  Value *Res = Builder.CreateBinOp((Instruction::BinaryOps)Opc, LHS,  
RHS,"tmp");
    return CastToType(Instruction::ZExt, Res, ConvertType(TREE_TYPE 
(exp)));
  }

@@ -3204,32 +3190,30 @@
    Value *LHS = Emit(TREE_OPERAND(exp, 0), 0);
    Value *RHS = Emit(TREE_OPERAND(exp, 1), 0);
    if (RHS->getType() != LHS->getType())
-    RHS = CastInst::createIntegerCast(RHS, LHS->getType(), false,
-                                      RHS->getName()+".cast", CurBB);
+    RHS = Builder.CreateIntCast(RHS, LHS->getType(), false,
+                                (RHS->getName()+".cast").c_str());

-  return BinaryOperator::create((Instruction::BinaryOps)Opc, LHS,  
RHS, "tmp",
-                                 CurBB);
+  return Builder.CreateBinOp((Instruction::BinaryOps)Opc, LHS, RHS,  
"tmp");
  }

  Value *TreeToLLVM::EmitRotateOp(tree exp, unsigned Opc1, unsigned  
Opc2) {
    Value *In  = Emit(TREE_OPERAND(exp, 0), 0);
-  Value* Amt = Emit(TREE_OPERAND(exp, 1), 0);
+  Value *Amt = Emit(TREE_OPERAND(exp, 1), 0);
    if (Amt->getType() != In->getType())
-    Amt = CastInst::createIntegerCast(Amt, In->getType(), false,
-                                      Amt->getName()+".cast", CurBB);
+    Amt = Builder.CreateIntCast(Amt, In->getType(), false,
+                                (Amt->getName()+".cast").c_str());

    Value *TypeSize =
      ConstantInt::get(In->getType(), In->getType()- 
 >getPrimitiveSizeInBits());

    // Do the two shifts.
-  Value *V1 = BinaryOperator::create((Instruction::BinaryOps)Opc1,  
In, Amt,
-                                     "tmp", CurBB);
-  Value *OtherShift = BinaryOperator::createSub(TypeSize, Amt,  
"tmp", CurBB);
-  Value *V2 = BinaryOperator::create((Instruction::BinaryOps)Opc2, In,
-                                     OtherShift, "tmp", CurBB);
+  Value *V1 = Builder.CreateBinOp((Instruction::BinaryOps)Opc1, In,  
Amt, "tmp");
+  Value *OtherShift = Builder.CreateSub(TypeSize, Amt, "tmp");
+  Value *V2 = Builder.CreateBinOp((Instruction::BinaryOps)Opc2, In,
+                                  OtherShift, "tmp");

    // Or the two together to return them.
-  Value *Merge = BinaryOperator::createOr(V1, V2, "tmp", CurBB);
+  Value *Merge = Builder.CreateOr(V1, V2, "tmp");
    return CastToUIntType(Merge, ConvertType(TREE_TYPE(exp)));
  }

@@ -3254,14 +3238,14 @@

    Value *Compare;
    if (LHS->getType()->isFloatingPoint())
-    Compare = new FCmpInst(FCmpInst::Predicate(FPPred), LHS, RHS,  
"tmp", CurBB);
+    Compare = Builder.CreateFCmp(FCmpInst::Predicate(FPPred), LHS,  
RHS, "tmp");
    else if TYPE_UNSIGNED(TREE_TYPE(TREE_OPERAND(exp, 0)))
-    Compare = new ICmpInst(ICmpInst::Predicate(UIPred), LHS, RHS,  
"tmp", CurBB);
+    Compare = Builder.CreateICmp(ICmpInst::Predicate(UIPred), LHS,  
RHS, "tmp");
    else
-    Compare = new ICmpInst(ICmpInst::Predicate(SIPred), LHS, RHS,  
"tmp", CurBB);
+    Compare = Builder.CreateICmp(ICmpInst::Predicate(SIPred), LHS,  
RHS, "tmp");

-  return new SelectInst(Compare, LHS, RHS,
-                        TREE_CODE(exp) == MAX_EXPR ? "max" : "min",  
CurBB);
+  return Builder.CreateSelect(Compare, LHS, RHS,
+                              TREE_CODE(exp) == MAX_EXPR ? "max" :  
"min");
  }


@@ -3272,7 +3256,6 @@
    // or the values of LHS and RHS have the same sign, then Mod  
equals Rem.
    // Otherwise Mod equals Rem + RHS.  This means that LHS Mod RHS  
traps iff
    // LHS Rem RHS traps.
-
    if (TYPE_UNSIGNED(TREE_TYPE(exp)))
      // LHS and RHS values must have the same sign if their type is  
unsigned.
      return EmitBinOp(exp, DestLoc, Instruction::URem);
@@ -3284,24 +3267,19 @@
    Value *RHS = Emit(TREE_OPERAND(exp, 1), 0);

    // The two possible values for Mod.
-  Value *Rem = BinaryOperator::create(Instruction::SRem, LHS, RHS,  
"rem",CurBB);
-  Value *RemPlusRHS = BinaryOperator::create(Instruction::Add, Rem,  
RHS, "tmp",
-                                             CurBB);
+  Value *Rem = Builder.CreateSRem(LHS, RHS, "rem");
+  Value *RemPlusRHS = Builder.CreateAdd(Rem, RHS, "tmp");

    // HaveSameSign: (LHS >= 0) == (RHS >= 0).
-  Value *LHSIsPositive = new ICmpInst(ICmpInst::ICMP_SGE, LHS, Zero,  
"tmp",
-                                      CurBB);
-  Value *RHSIsPositive = new ICmpInst(ICmpInst::ICMP_SGE, RHS, Zero,  
"tmp",
-                                      CurBB);
-  Value *HaveSameSign = new ICmpInst(ICmpInst::ICMP_EQ, LHSIsPositive,
-                                     RHSIsPositive, "tmp", CurBB);
+  Value *LHSIsPositive = Builder.CreateICmpSGE(LHS, Zero, "tmp");
+  Value *RHSIsPositive = Builder.CreateICmpSGE(RHS, Zero, "tmp");
+  Value *HaveSameSign = Builder.CreateICmpEQ 
(LHSIsPositive,RHSIsPositive,"tmp");

    // RHS exactly divides LHS iff Rem is zero.
-  Value *RemIsZero = new ICmpInst(ICmpInst::ICMP_EQ, Rem, Zero,  
"tmp", CurBB);
+  Value *RemIsZero = Builder.CreateICmpEQ(Rem, Zero, "tmp");

-  Value *SameAsRem = BinaryOperator::create(Instruction::Or,  
HaveSameSign,
-                                            RemIsZero, "tmp", CurBB);
-  return new SelectInst(SameAsRem, Rem, RemPlusRHS, "mod", CurBB);
+  Value *SameAsRem = Builder.CreateOr(HaveSameSign, RemIsZero, "tmp");
+  return Builder.CreateSelect(SameAsRem, Rem, RemPlusRHS, "mod");
  }

  Value *TreeToLLVM::EmitCEIL_DIV_EXPR(tree exp) {
@@ -3332,52 +3310,42 @@
      // Quick quiz question: what value is returned for INT_MIN CDiv  
-1?

      // Determine the signs of LHS and RHS, and whether they have  
the same sign.
-    Value *LHSIsPositive = new ICmpInst(ICmpInst::ICMP_SGE, LHS,  
Zero, "tmp",
-                                        CurBB);
-    Value *RHSIsPositive = new ICmpInst(ICmpInst::ICMP_SGE, RHS,  
Zero, "tmp",
-                                        CurBB);
-    Value *HaveSameSign = new ICmpInst(ICmpInst::ICMP_EQ,  
LHSIsPositive,
-                                       RHSIsPositive, "tmp", CurBB);
+    Value *LHSIsPositive = Builder.CreateICmpSGE(LHS, Zero, "tmp");
+    Value *RHSIsPositive = Builder.CreateICmpSGE(RHS, Zero, "tmp");
+    Value *HaveSameSign = Builder.CreateICmpEQ(LHSIsPositive,  
RHSIsPositive,
+                                             "tmp");

-    // Offset equals 1 if LHS and RHS have the same sign and LHS is  
not zero ...
-    Value *LHSNotZero = new ICmpInst(ICmpInst::ICMP_NE, LHS, Zero,  
"tmp",
-                                     CurBB);
-    Value *OffsetOne = BinaryOperator::create(Instruction::And,  
HaveSameSign,
-                                              LHSNotZero, "tmp",  
CurBB);
+    // Offset equals 1 if LHS and RHS have the same sign and LHS is  
not zero.
+    Value *LHSNotZero = Builder.CreateICmpNE(LHS, Zero, "tmp");
+    Value *OffsetOne = Builder.CreateAnd(HaveSameSign, LHSNotZero,  
"tmp");
      // ... otherwise it is 0.
-    Value *Offset = new SelectInst(OffsetOne, One, Zero, "tmp", CurBB);
+    Value *Offset = Builder.CreateSelect(OffsetOne, One, Zero, "tmp");

      // Calculate Sign(RHS) ...
-    Value *SignRHS = new SelectInst(RHSIsPositive, One, MinusOne,  
"tmp", CurBB);
+    Value *SignRHS = Builder.CreateSelect(RHSIsPositive, One,  
MinusOne, "tmp");
      // ... and Sign(RHS) * Offset
      Value *SignedOffset = CastToType(Instruction::SExt, OffsetOne,  
Ty);
-    SignedOffset = BinaryOperator::create(Instruction::And, SignRHS,
-                                          SignedOffset, "tmp", CurBB);
+    SignedOffset = Builder.CreateAnd(SignRHS, SignedOffset, "tmp");

      // Return CDiv = (LHS - Sign(RHS) * Offset) Div RHS + Offset.
-    Value *CDiv = BinaryOperator::create(Instruction::Sub, LHS,  
SignedOffset,
-                                         "tmp", CurBB);
-    CDiv = BinaryOperator::create(Instruction::SDiv, CDiv, RHS,  
"tmp", CurBB);
-    return BinaryOperator::create(Instruction::Add, CDiv, Offset,  
"cdiv",
-                                  CurBB);
-  } else {
-    // In the case of unsigned arithmetic, LHS and RHS necessarily  
have the
-    // same sign, so we can use
-    //   LHS CDiv RHS = (LHS - 1) Div RHS + 1
-    // as long as LHS is non-zero.
+    Value *CDiv = Builder.CreateSub(LHS, SignedOffset, "tmp");
+    CDiv = Builder.CreateSDiv(CDiv, RHS, "tmp");
+    return Builder.CreateAdd(CDiv, Offset, "cdiv");
+  }

-    // Offset is 1 if LHS is non-zero, 0 otherwise.
-    Value *LHSNotZero = new ICmpInst(ICmpInst::ICMP_NE, LHS, Zero,  
"tmp",
-                                     CurBB);
-    Value *Offset = new SelectInst(LHSNotZero, One, Zero, "tmp",  
CurBB);
+  // In the case of unsigned arithmetic, LHS and RHS necessarily  
have the
+  // same sign, so we can use
+  //   LHS CDiv RHS = (LHS - 1) Div RHS + 1
+  // as long as LHS is non-zero.

-    // Return CDiv = (LHS - Offset) Div RHS + Offset.
-    Value *CDiv = BinaryOperator::create(Instruction::Sub, LHS,  
Offset, "tmp",
-                                         CurBB);
-    CDiv = BinaryOperator::create(Instruction::UDiv, CDiv, RHS,  
"tmp", CurBB);
-    return BinaryOperator::create(Instruction::Add, CDiv, Offset,  
"cdiv",
-                                  CurBB);
-  }
+  // Offset is 1 if LHS is non-zero, 0 otherwise.
+  Value *LHSNotZero = Builder.CreateICmpNE(LHS, Zero, "tmp");
+  Value *Offset = Builder.CreateSelect(LHSNotZero, One, Zero, "tmp");
+
+  // Return CDiv = (LHS - Offset) Div RHS + Offset.
+  Value *CDiv = Builder.CreateSub(LHS, Offset, "tmp");
+  CDiv = Builder.CreateUDiv(CDiv, RHS, "tmp");
+  return Builder.CreateAdd(CDiv, Offset, "cdiv");
  }

  Value *TreeToLLVM::EmitROUND_DIV_EXPR(tree exp) {
@@ -3412,69 +3380,56 @@
      // Quick quiz question: what value is returned for INT_MIN RDiv  
-1?

      // Determine the signs of LHS and RHS, and whether they have  
the same sign.
-    Value *LHSIsPositive = new ICmpInst(ICmpInst::ICMP_SGE, LHS,  
Zero, "tmp",
-                                        CurBB);
-    Value *RHSIsPositive = new ICmpInst(ICmpInst::ICMP_SGE, RHS,  
Zero, "tmp",
-                                        CurBB);
-    Value *HaveSameSign = new ICmpInst(ICmpInst::ICMP_EQ,  
LHSIsPositive,
-                                       RHSIsPositive, "tmp", CurBB);
+    Value *LHSIsPositive = Builder.CreateICmpSGE(LHS, Zero, "tmp");
+    Value *RHSIsPositive = Builder.CreateICmpSGE(RHS, Zero, "tmp");
+    Value *HaveSameSign = Builder.CreateICmpEQ(LHSIsPositive,  
RHSIsPositive,
+                                               "tmp");

      // Calculate |LHS| ...
-    Value *MinusLHS = BinaryOperator::createNeg(LHS, "tmp", CurBB);
-    Value *AbsLHS = new SelectInst(LHSIsPositive, LHS, MinusLHS,  
"abs_" +
-                                   LHS->getName(), CurBB);
+    Value *MinusLHS = Builder.CreateNeg(LHS, "tmp");
+    Value *AbsLHS = Builder.CreateSelect(LHSIsPositive, LHS, MinusLHS,
+                                         (LHS->getNameStr() 
+".abs").c_str());
      // ... and |RHS|
-    Value *MinusRHS = BinaryOperator::createNeg(RHS, "tmp", CurBB);
-    Value *AbsRHS = new SelectInst(RHSIsPositive, RHS, MinusRHS,  
"abs_" +
-                                   RHS->getName(), CurBB);
+    Value *MinusRHS = Builder.CreateNeg(RHS, "tmp");
+    Value *AbsRHS = Builder.CreateSelect(RHSIsPositive, RHS, MinusRHS,
+                                         (RHS->getNameStr() 
+".abs").c_str());

      // Calculate AbsRDiv = (|LHS| + (|RHS| UDiv 2)) UDiv |RHS|.
-    Value *HalfAbsRHS = BinaryOperator::create(Instruction::UDiv,  
AbsRHS, Two,
-                                               "tmp", CurBB);
-    Value *Numerator = BinaryOperator::create(Instruction::Add, AbsLHS,
-                                              HalfAbsRHS, "tmp",  
CurBB);
-    Value *AbsRDiv = BinaryOperator::create(Instruction::UDiv,  
Numerator,
-                                            AbsRHS, "tmp", CurBB);
+    Value *HalfAbsRHS = Builder.CreateUDiv(AbsRHS, Two, "tmp");
+    Value *Numerator = Builder.CreateAdd(AbsLHS, HalfAbsRHS, "tmp");
+    Value *AbsRDiv = Builder.CreateUDiv(Numerator, AbsRHS, "tmp");

      // Return AbsRDiv or -AbsRDiv according to whether LHS and RHS  
have the
      // same sign or not.
-    Value *MinusAbsRDiv = BinaryOperator::createNeg(AbsRDiv, "tmp",  
CurBB);
-    return new SelectInst(HaveSameSign, AbsRDiv, MinusAbsRDiv,  
"rdiv", CurBB);
-  } else {
-    // In the case of unsigned arithmetic, LHS and RHS necessarily  
have the
-    // same sign, however overflow is a problem.  We want to use the  
formula
-    //   LHS RDiv RHS = (LHS + (RHS Div 2)) Div RHS,
-    // but if LHS + (RHS Div 2) overflows then we get the wrong  
result.  Since
-    // the use of a conditional branch seems to be unavoidable, we  
choose the
-    // simple solution of explicitly checking for overflow, and using
-    //   LHS RDiv RHS = ((LHS + (RHS Div 2)) - RHS) Div RHS + 1
-    // if it occurred.
-
-    // Usually the numerator is LHS + (RHS Div 2); calculate this.
-    Value *HalfRHS = BinaryOperator::create(Instruction::UDiv, RHS,  
Two, "tmp",
-                                            CurBB);
-    Value *Numerator = BinaryOperator::create(Instruction::Add, LHS,  
HalfRHS,
-                                              "tmp", CurBB);
-
-    // Did the calculation overflow?
-    Value *Overflowed = new ICmpInst(ICmpInst::ICMP_ULT, Numerator,  
HalfRHS,
-                                     "tmp", CurBB);
-
-    // If so, use (LHS + (RHS Div 2)) - RHS for the numerator instead.
-    Value *AltNumerator = BinaryOperator::create(Instruction::Sub,  
Numerator,
-                                                 RHS, "tmp", CurBB);
-    Numerator = new SelectInst(Overflowed, AltNumerator, Numerator,  
"tmp",
-                               CurBB);
-
-    // Quotient = Numerator / RHS.
-    Value *Quotient = BinaryOperator::create(Instruction::UDiv,  
Numerator, RHS,
-                                             "tmp", CurBB);
-
-    // Return Quotient unless we overflowed, in which case return  
Quotient + 1.
-    return BinaryOperator::create(Instruction::Add, Quotient,
-                                  CastToUIntType(Overflowed, Ty),  
"rdiv",
-                                  CurBB);
+    Value *MinusAbsRDiv = Builder.CreateNeg(AbsRDiv, "tmp");
+    return Builder.CreateSelect(HaveSameSign, AbsRDiv, MinusAbsRDiv,  
"rdiv");
    }
+
+  // In the case of unsigned arithmetic, LHS and RHS necessarily  
have the
+  // same sign, however overflow is a problem.  We want to use the  
formula
+  //   LHS RDiv RHS = (LHS + (RHS Div 2)) Div RHS,
+  // but if LHS + (RHS Div 2) overflows then we get the wrong  
result.  Since
+  // the use of a conditional branch seems to be unavoidable, we  
choose the
+  // simple solution of explicitly checking for overflow, and using
+  //   LHS RDiv RHS = ((LHS + (RHS Div 2)) - RHS) Div RHS + 1
+  // if it occurred.
+
+  // Usually the numerator is LHS + (RHS Div 2); calculate this.
+  Value *HalfRHS = Builder.CreateUDiv(RHS, Two, "tmp");
+  Value *Numerator = Builder.CreateAdd(LHS, HalfRHS, "tmp");
+
+  // Did the calculation overflow?
+  Value *Overflowed = Builder.CreateICmpULT(Numerator, HalfRHS, "tmp");
+
+  // If so, use (LHS + (RHS Div 2)) - RHS for the numerator instead.
+  Value *AltNumerator = Builder.CreateSub(Numerator, RHS, "tmp");
+  Numerator = Builder.CreateSelect(Overflowed, AltNumerator,  
Numerator, "tmp");
+
+  // Quotient = Numerator / RHS.
+  Value *Quotient = Builder.CreateUDiv(Numerator, RHS, "tmp");
+
+  // Return Quotient unless we overflowed, in which case return  
Quotient + 1.
+  return Builder.CreateAdd(Quotient, CastToUIntType(Overflowed, Ty),  
"rdiv");
  }

  // 
===--------------------------------------------------------------------- 
-===//
@@ -3499,7 +3454,7 @@

    const char *Name = IDENTIFIER_POINTER(DECL_ASSEMBLER_NAME(decl));
    InlineAsm *IA = InlineAsm::get(FTy, "", "={"+std::string(Name) 
+"}", false);
-  return new CallInst(IA, "tmp", CurBB);
+  return Builder.CreateCall(IA, "tmp");
  }

  /// Stores to register variables are handled by emitting an inline  
asm node
@@ -3516,7 +3471,7 @@

    const char *Name = IDENTIFIER_POINTER(DECL_ASSEMBLER_NAME(decl));
    InlineAsm *IA = InlineAsm::get(FTy, "", "{"+std::string(Name) 
+"}", true);
-  new CallInst(IA, RHS, "", CurBB);
+  Builder.CreateCall(IA, &RHS, 1);
  }

  /// ConvertInlineAsmStr - Convert the specified inline asm string  
to an LLVM
@@ -3830,8 +3785,8 @@
          if (TySize == 1 || TySize == 8 || TySize == 16 ||
              TySize == 32 || TySize == 64) {
            LLVMTy = IntegerType::get(TySize);
-          Op = new LoadInst(CastToType(Instruction::BitCast, LV.Ptr,
-                                       PointerType::get(LLVMTy)),  
"tmp", CurBB);
+          Op = Builder.CreateLoad(CastToType(Instruction::BitCast,  
LV.Ptr,
+                                             PointerType::get 
(LLVMTy)), "tmp");
          } else {
            // Otherwise, emit our value as a lvalue and let the  
codegen deal with
            // it.
@@ -3921,12 +3876,12 @@

    Value *Asm = InlineAsm::get(FTy, NewAsmStr, ConstraintStr,
                                ASM_VOLATILE_P(exp) || !ASM_OUTPUTS 
(exp));
-  CallInst *CV = new CallInst(Asm, &CallOps[0], CallOps.size(),
-                              StoreCallResultAddr ? "tmp" : "", CurBB);
+  CallInst *CV = Builder.CreateCall(Asm, &CallOps[0], CallOps.size(),
+                                    StoreCallResultAddr ? "tmp" : "");

    // If the call produces a value, store it into the destination.
    if (StoreCallResultAddr)
-    new StoreInst(CV, StoreCallResultAddr, CurBB);
+    Builder.CreateStore(CV, StoreCallResultAddr);

    // Give the backend a chance to upgrade the inline asm to LLVM  
code.  This
    // handles some common cases that LLVM has intrinsics for, e.g.  
x86 bswap ->
@@ -3961,9 +3916,9 @@
      UndefValue::get(VectorType::get(Ops[0]->getType(), Ops.size()));

    for (unsigned i = 0, e = Ops.size(); i != e; ++i)
-    Result = new InsertElementInst(Result, Ops[i],
-                                   ConstantInt::get(Type::Int32Ty, i),
-                                   "tmp", CurBB);
+    Result = Builder.CreateInsertElement(Result, Ops[i],
+                                         ConstantInt::get 
(Type::Int32Ty, i),
+                                         "tmp");

    return Result;
  }
@@ -4012,8 +3967,8 @@
    va_end(VA);

    // Turn this into the appropriate shuffle operation.
-  return new ShuffleVectorInst(InVec1, InVec2, ConstantVector::get 
(Idxs),
-                               "tmp", CurBB);
+  return Builder.CreateShuffleVector(InVec1, InVec2,  
ConstantVector::get(Idxs),
+                                     "tmp");
  }

  // 
===--------------------------------------------------------------------- 
-===//
@@ -4033,19 +3988,12 @@
    // Get the result type and oeprand line in an easy to consume  
format.
    const Type *ResultType = ConvertType(TREE_TYPE(TREE_TYPE(fndecl)));
    std::vector<Value*> Operands;
-  SmallVector<tree, 8> Args;
-  for (tree Op = TREE_OPERAND(exp, 1); Op; Op = TREE_CHAIN(Op)) {
-    tree Arg = TREE_VALUE(Op);
-    Args.push_back(Arg);
-    Operands.push_back(Emit(Arg, 0));
-  }
+  for (tree Op = TREE_OPERAND(exp, 1); Op; Op = TREE_CHAIN(Op))
+    Operands.push_back(Emit(TREE_VALUE(Op), 0));

-  bool ResIsSigned = !TYPE_UNSIGNED(TREE_TYPE(TREE_TYPE(fndecl)));
-  bool ExpIsSigned = !TYPE_UNSIGNED(TREE_TYPE(exp));
    unsigned FnCode = DECL_FUNCTION_CODE(fndecl);
    return LLVM_TARGET_INTRINSIC_LOWER(exp, FnCode, DestLoc, Result,  
ResultType,
-                                     Operands, Args, CurBB,  
ResIsSigned,
-                                     ExpIsSigned);
+                                     Operands);
  #endif
    return false;
  }
@@ -4179,19 +4127,12 @@
      // the ffs, but should ignore the return type of ffs.
      Value *Amt = Emit(TREE_VALUE(TREE_OPERAND(exp, 1)), 0);
      EmitBuiltinUnaryIntOp(Amt, Result, Intrinsic::cttz);
-    Result = BinaryOperator::createAdd(Result,
-                                       ConstantInt::get 
(Type::Int32Ty, 1),
-                                       "tmp", CurBB);
-    Value *Cond;
-    if (Amt->getType()->isFloatingPoint())
-      Cond = new FCmpInst(FCmpInst::FCMP_OEQ, Amt,
-                          Constant::getNullValue(Amt->getType()),  
"tmp", CurBB);
-    else
-      Cond = new ICmpInst(ICmpInst::ICMP_EQ, Amt,
-                          Constant::getNullValue(Amt->getType()),  
"tmp", CurBB);
-
-    Result = new SelectInst(Cond, Constant::getNullValue 
(Type::Int32Ty),
-                            Result, "tmp", CurBB);
+    Result = Builder.CreateAdd(Result, ConstantInt::get 
(Type::Int32Ty, 1),
+                               "tmp");
+    Value *Cond =
+      Builder.CreateICmpEQ(Amt, Constant::getNullValue(Amt->getType 
()), "tmp");
+    Result = Builder.CreateSelect(Cond, Constant::getNullValue 
(Type::Int32Ty),
+                                  Result, "tmp");
      return true;
    }

@@ -4244,9 +4185,9 @@
    const Type* Tys[] = {
      InVal->getType()
    };
-  Result = new CallInst(Intrinsic::getDeclaration(TheModule, Id, Tys,
-                                                  sizeof(Tys)/sizeof 
(Tys[0])),
-                        InVal, "tmp", CurBB);
+  Result = Builder.CreateCall(Intrinsic::getDeclaration(TheModule,  
Id, Tys,
+                                                    sizeof(Tys)/ 
sizeof(Tys[0])),
+                              InVal, "tmp");

    return true;
  }
@@ -4261,10 +4202,9 @@
    case Type::DoubleTyID: Name = F64Name; break;
    }

-  return new CallInst(cast<Function>(
-      TheModule->getOrInsertFunction(Name,Amt->getType(),
-                                     Amt->getType(),
-                                     NULL)), Amt, "tmp", CurBB);
+  return Builder.CreateCall(cast<Function>(
+    TheModule->getOrInsertFunction(Name, Amt->getType(), Amt->getType 
(), NULL)),
+                            Amt, "tmp");
  }

  Value *TreeToLLVM::EmitBuiltinUnaryFPOp(Value *Amt,
@@ -4278,8 +4218,8 @@
    case Type::DoubleTyID: Id = F64ID; break;
    }

-  return new CallInst(Intrinsic::getDeclaration(TheModule, Id),
-                      Amt, "tmp", CurBB);
+  return Builder.CreateCall(Intrinsic::getDeclaration(TheModule, Id),
+                            Amt, "tmp");
  }

  Value *TreeToLLVM::EmitBuiltinPOWI(tree exp) {
@@ -4299,8 +4239,8 @@
    case Type::DoubleTyID: Id = Intrinsic::powi_f64; break;
    }

-  return new CallInst(Intrinsic::getDeclaration(TheModule, Id),
-                      Val, Pow, "tmp", CurBB);
+  return Builder.CreateCall(Intrinsic::getDeclaration(TheModule, Id),
+                            Val, Pow, "tmp");
  }


@@ -4432,8 +4372,8 @@
    Ptr = CastToType(Instruction::BitCast, Ptr, PointerType::get 
(Type::Int8Ty));

    Value *Ops[3] = { Ptr, ReadWrite, Locality };
-  new CallInst(Intrinsic::getDeclaration(TheModule,  
Intrinsic::prefetch),
-               Ops, 3, "", CurBB);
+  Builder.CreateCall(Intrinsic::getDeclaration(TheModule,  
Intrinsic::prefetch),
+                     Ops, 3);
    return true;
  }

@@ -4453,11 +4393,10 @@
      return false;
    }

-  Result = new CallInst(Intrinsic::getDeclaration(TheModule,
-                                                  !isFrame ?
-                                                   
Intrinsic::returnaddress :
-                                                   
Intrinsic::frameaddress),
-                        Level, "tmp", CurBB);
+  Intrinsic::ID IID =
+    !isFrame ? Intrinsic::returnaddress : Intrinsic::frameaddress;
+  Result = Builder.CreateCall(Intrinsic::getDeclaration(TheModule,  
IID),
+                              Level, "tmp");
    Result = CastToType(Instruction::BitCast, Result, TREE_TYPE(exp));
    return true;
  }
@@ -4500,9 +4439,9 @@
    if (!validate_arglist(arglist, VOID_TYPE))
      return false;

-  Result = new CallInst(Intrinsic::getDeclaration(TheModule,
-                                                   
Intrinsic::stacksave),
-                        "tmp", CurBB);
+  Result = Builder.CreateCall(Intrinsic::getDeclaration(TheModule,
+                                                         
Intrinsic::stacksave),
+                              "tmp");
    return true;
  }

@@ -4514,8 +4453,8 @@
    Value *Ptr = Emit(TREE_VALUE(arglist), 0);
    Ptr = CastToType(Instruction::BitCast, Ptr, PointerType::get 
(Type::Int8Ty));

-  new CallInst(Intrinsic::getDeclaration(TheModule,  
Intrinsic::stackrestore),
-               Ptr, "", CurBB);
+  Builder.CreateCall(Intrinsic::getDeclaration(TheModule,
+                                                
Intrinsic::stackrestore), Ptr);
    return true;
  }

@@ -4526,7 +4465,7 @@
      return false;
    Value *Amt = Emit(TREE_VALUE(arglist), 0);
    Amt = CastToSIntType(Amt, Type::Int32Ty);
-  Result = new AllocaInst(Type::Int8Ty, Amt, "tmp", CurBB);
+  Result = Builder.CreateAlloca(Type::Int8Ty, Amt, "tmp");
    return true;
  }

@@ -4567,7 +4506,7 @@
      cast<PointerType>(llvm_va_start_fn->getType())->getElementType();
    ArgVal = CastToType(Instruction::BitCast, ArgVal,
                        PointerType::get(Type::Int8Ty));
-  new CallInst(llvm_va_start_fn, ArgVal, "", CurBB);
+  Builder.CreateCall(llvm_va_start_fn, ArgVal);
    return true;
  }

@@ -4575,8 +4514,8 @@
    Value *Arg = Emit(TREE_VALUE(TREE_OPERAND(exp, 1)), 0);
    Arg = CastToType(Instruction::BitCast, Arg,
                     PointerType::get(Type::Int8Ty));
-  new CallInst(Intrinsic::getDeclaration(TheModule, Intrinsic::vaend),
-               Arg, "", CurBB);
+  Builder.CreateCall(Intrinsic::getDeclaration(TheModule,  
Intrinsic::vaend),
+                     Arg);
    return true;
  }

@@ -4591,7 +4530,7 @@
      // Emit it as a value, then store it to a temporary slot.
      Value *V2 = Emit(Arg2T, 0);
      Arg2 = CreateTemporary(V2->getType());
-    new StoreInst(V2, Arg2, CurBB);
+    Builder.CreateStore(V2, Arg2);
    } else {
      // If the target has aggregate valists, emit the srcval  
directly into a
      // temporary.
@@ -4605,8 +4544,8 @@
    Arg1 = CastToType(Instruction::BitCast, Arg1, VPTy);
    Arg2 = CastToType(Instruction::BitCast, Arg2, VPTy);

-  new CallInst(Intrinsic::getDeclaration(TheModule, Intrinsic::vacopy),
-               Arg1, Arg2, "", CurBB);
+  Builder.CreateCall(Intrinsic::getDeclaration(TheModule,  
Intrinsic::vacopy),
+                     Arg1, Arg2);
    return true;
  }

@@ -4620,11 +4559,11 @@
    Value *I0 = ConstantInt::get(Type::Int32Ty, 0);
    Value *I1 = ConstantInt::get(Type::Int32Ty, 1);

-  Value *RealPtr = new GetElementPtrInst(SrcComplex, I0, I0, "real",  
CurBB);
-  Real = new LoadInst(RealPtr, "real", isVolatile, CurBB);
+  Value *RealPtr = Builder.CreateGEP(SrcComplex, I0, I0, "real");
+  Real = Builder.CreateLoad(RealPtr, isVolatile, "real");

-  Value *ImagPtr = new GetElementPtrInst(SrcComplex, I0, I1, "real",  
CurBB);
-  Imag = new LoadInst(ImagPtr, "imag", isVolatile, CurBB);
+  Value *ImagPtr = Builder.CreateGEP(SrcComplex, I0, I1, "real");
+  Imag = Builder.CreateLoad(ImagPtr, isVolatile, "imag");
  }

  void TreeToLLVM::EmitStoreToComplex(Value *DestComplex, Value *Real,
@@ -4632,11 +4571,11 @@
    Value *I0 = ConstantInt::get(Type::Int32Ty, 0);
    Value *I1 = ConstantInt::get(Type::Int32Ty, 1);

-  Value *RealPtr = new GetElementPtrInst(DestComplex, I0, I0,  
"real", CurBB);
-  new StoreInst(Real, RealPtr, isVolatile, CurBB);
+  Value *RealPtr = Builder.CreateGEP(DestComplex, I0, I0, "real");
+  Builder.CreateStore(Real, RealPtr, isVolatile);

-  Value *ImagPtr = new GetElementPtrInst(DestComplex, I0, I1,  
"real", CurBB);
-  new StoreInst(Imag, ImagPtr, isVolatile, CurBB);
+  Value *ImagPtr = Builder.CreateGEP(DestComplex, I0, I1, "real");
+  Builder.CreateStore(Imag, ImagPtr, isVolatile);
  }


@@ -4673,47 +4612,50 @@
    switch (TREE_CODE(exp)) {
    default: TODO(exp);
    case PLUS_EXPR: // (a+ib) + (c+id) = (a+c) + i(b+d)
-    DSTr = BinaryOperator::createAdd(LHSr, RHSr, "tmpr", CurBB);
-    DSTi = BinaryOperator::createAdd(LHSi, RHSi, "tmpi", CurBB);
+    DSTr = Builder.CreateAdd(LHSr, RHSr, "tmpr");
+    DSTi = Builder.CreateAdd(LHSi, RHSi, "tmpi");
      break;
    case MINUS_EXPR: // (a+ib) - (c+id) = (a-c) + i(b-d)
-    DSTr = BinaryOperator::createSub(LHSr, RHSr, "tmpr", CurBB);
-    DSTi = BinaryOperator::createSub(LHSi, RHSi, "tmpi", CurBB);
+    DSTr = Builder.CreateSub(LHSr, RHSr, "tmpr");
+    DSTi = Builder.CreateSub(LHSi, RHSi, "tmpi");
      break;
    case MULT_EXPR: { // (a+ib) * (c+id) = (ac-bd) + i(ad+cb)
-    Value *Tmp1 = BinaryOperator::createMul(LHSr, RHSr, "tmp",  
CurBB); // a*c
-    Value *Tmp2 = BinaryOperator::createMul(LHSi, RHSi, "tmp",  
CurBB); // b*d
-    DSTr = BinaryOperator::createSub(Tmp1, Tmp2, "tmp", CurBB);  //  
ac-bd
+    Value *Tmp1 = Builder.CreateMul(LHSr, RHSr, "tmp"); // a*c
+    Value *Tmp2 = Builder.CreateMul(LHSi, RHSi, "tmp"); // b*d
+    DSTr = Builder.CreateSub(Tmp1, Tmp2, "tmp");  // ac-bd

-    Value *Tmp3 = BinaryOperator::createMul(LHSr, RHSi, "tmp",  
CurBB); // a*d
-    Value *Tmp4 = BinaryOperator::createMul(RHSr, LHSi, "tmp",  
CurBB); // c*b
-    DSTi = BinaryOperator::createAdd(Tmp3, Tmp4, "tmp", CurBB); // ad 
+cb
+    Value *Tmp3 = Builder.CreateMul(LHSr, RHSi, "tmp"); // a*d
+    Value *Tmp4 = Builder.CreateMul(RHSr, LHSi, "tmp"); // c*b
+    DSTi = Builder.CreateAdd(Tmp3, Tmp4, "tmp"); // ad+cb
      break;
    }
    case RDIV_EXPR: { // (a+ib) / (c+id) = ((ac+bd)/(cc+dd)) + i((bc- 
ad)/(cc+dd))
-    Value *Tmp1 = BinaryOperator::createMul(LHSr, RHSr, "tmp",  
CurBB); // a*c
-    Value *Tmp2 = BinaryOperator::createMul(LHSi, RHSi, "tmp",  
CurBB); // b*d
-    Value *Tmp3 = BinaryOperator::createAdd(Tmp1, Tmp2, "tmp",  
CurBB); // ac+bd
+    Value *Tmp1 = Builder.CreateMul(LHSr, RHSr, "tmp"); // a*c
+    Value *Tmp2 = Builder.CreateMul(LHSi, RHSi, "tmp"); // b*d
+    Value *Tmp3 = Builder.CreateAdd(Tmp1, Tmp2, "tmp"); // ac+bd

-    Value *Tmp4 = BinaryOperator::createMul(RHSr, RHSr, "tmp",  
CurBB); // c*c
-    Value *Tmp5 = BinaryOperator::createMul(RHSi, RHSi, "tmp",  
CurBB); // d*d
-    Value *Tmp6 = BinaryOperator::createAdd(Tmp4, Tmp5, "tmp",  
CurBB); // cc+dd
-    DSTr = BinaryOperator::createFDiv(Tmp3, Tmp6, "tmp", CurBB);
+    Value *Tmp4 = Builder.CreateMul(RHSr, RHSr, "tmp"); // c*c
+    Value *Tmp5 = Builder.CreateMul(RHSi, RHSi, "tmp"); // d*d
+    Value *Tmp6 = Builder.CreateAdd(Tmp4, Tmp5, "tmp"); // cc+dd
+    // FIXME: What about integer complex?
+    DSTr = Builder.CreateFDiv(Tmp3, Tmp6, "tmp");

-    Value *Tmp7 = BinaryOperator::createMul(LHSi, RHSr, "tmp",  
CurBB); // b*c
-    Value *Tmp8 = BinaryOperator::createMul(LHSr, RHSi, "tmp",  
CurBB); // a*d
-    Value *Tmp9 = BinaryOperator::createSub(Tmp7, Tmp8, "tmp",  
CurBB); // bc-ad
-    DSTi = BinaryOperator::createFDiv(Tmp9, Tmp6, "tmp", CurBB);
+    Value *Tmp7 = Builder.CreateMul(LHSi, RHSr, "tmp"); // b*c
+    Value *Tmp8 = Builder.CreateMul(LHSr, RHSi, "tmp"); // a*d
+    Value *Tmp9 = Builder.CreateSub(Tmp7, Tmp8, "tmp"); // bc-ad
+    DSTi = Builder.CreateFDiv(Tmp9, Tmp6, "tmp");
      break;
    }
    case EQ_EXPR:   // (a+ib) == (c+id) = (a == c) & (b == d)
-    DSTr = new FCmpInst(FCmpInst::FCMP_OEQ, LHSr, RHSr, "tmpr", CurBB);
-    DSTi = new FCmpInst(FCmpInst::FCMP_OEQ, LHSi, RHSi, "tmpi", CurBB);
-    return BinaryOperator::createAnd(DSTr, DSTi, "tmp", CurBB);
+    // FIXME: What about integer complex?
+    DSTr = Builder.CreateFCmpOEQ(LHSr, RHSr, "tmpr");
+    DSTi = Builder.CreateFCmpOEQ(LHSi, RHSi, "tmpi");
+    return Builder.CreateAnd(DSTr, DSTi, "tmp");
    case NE_EXPR:   // (a+ib) != (c+id) = (a != c) | (b != d)
-    DSTr = new FCmpInst(FCmpInst::FCMP_ONE, LHSr, RHSr, "tmpr", CurBB);
-    DSTi = new FCmpInst(FCmpInst::FCMP_ONE, LHSi, RHSi, "tmpi", CurBB);
-    return BinaryOperator::createOr(DSTr, DSTi, "tmp", CurBB);
+    // FIXME: What about integer complex?
+    DSTr = Builder.CreateFCmpUNE(LHSr, RHSr, "tmpr");
+    DSTi = Builder.CreateFCmpUNE(LHSi, RHSi, "tmpi");
+    return Builder.CreateOr(DSTr, DSTi, "tmp");
    }

    EmitStoreToComplex(DestLoc, DSTr, DSTi, false);
@@ -4841,9 +4783,8 @@

    // If this is an index into an LLVM array, codegen as a GEP.
    if (isArrayCompatible(ArrayType)) {
-    Value *Ptr = new GetElementPtrInst(ArrayAddr,
-                                       ConstantInt::get 
(Type::Int32Ty, 0),
-                                       IndexVal, "tmp", CurBB);
+    Value *Ptr = Builder.CreateGEP(ArrayAddr,ConstantInt::get 
(Type::Int32Ty, 0),
+                                   IndexVal, "tmp");
      return BitCastToType(Ptr, PointerType::get(ConvertType(TREE_TYPE 
(exp))));
    }

@@ -4851,7 +4792,7 @@
    if (isSequentialCompatible(ArrayType)) {
      const Type *PtrElementTy = PointerType::get(ConvertType 
(ElementType));
      ArrayAddr = BitCastToType(ArrayAddr, PtrElementTy);
-    Value *Ptr = new GetElementPtrInst(ArrayAddr, IndexVal, "tmp",  
CurBB);
+    Value *Ptr = Builder.CreateGEP(ArrayAddr, IndexVal, "tmp");
      return BitCastToType(Ptr, PointerType::get(ConvertType(TREE_TYPE 
(exp))));
    }

@@ -4863,8 +4804,8 @@
    Value *TypeSize = Emit(array_ref_element_size(exp), 0);
    TypeSize = CastToUIntType(TypeSize, IntPtrTy);

-  IndexVal = BinaryOperator::createMul(IndexVal, TypeSize, "tmp",  
CurBB);
-  Value *Ptr = new GetElementPtrInst(ArrayAddr, IndexVal, "tmp",  
CurBB);
+  IndexVal = Builder.CreateMul(IndexVal, TypeSize, "tmp");
+  Value *Ptr = Builder.CreateGEP(ArrayAddr, IndexVal, "tmp");

    return BitCastToType(Ptr, PointerType::get(ConvertType(TREE_TYPE 
(exp))));
  }
@@ -4926,9 +4867,9 @@
      uint32_t MemberIndex = CI->getZExtValue();
      assert(MemberIndex < StructTy->getNumContainedTypes() &&
             "Field Idx out of range!");
-    FieldPtr = new GetElementPtrInst(StructAddrLV.Ptr,
-                                     Constant::getNullValue 
(Type::Int32Ty), CI,
-                                     "tmp", CurBB);
+    FieldPtr = Builder.CreateGEP(StructAddrLV.Ptr,
+                                 Constant::getNullValue 
(Type::Int32Ty), CI,
+                                 "tmp");

      // Now that we did an offset from the start of the struct,  
subtract off
      // the offset from BitStart.
@@ -4941,7 +4882,7 @@
      Value *Offset = Emit(field_offset, 0);
      Value *Ptr = CastToType(Instruction::PtrToInt, StructAddrLV.Ptr,
                              Offset->getType());
-    Ptr = BinaryOperator::createAdd(Ptr, Offset, "tmp", CurBB);
+    Ptr = Builder.CreateAdd(Ptr, Offset, "tmp");
      FieldPtr = CastToType(Instruction::IntToPtr,  
Ptr,PointerType::get(FieldTy));
    }

@@ -5011,7 +4952,7 @@
          Constant *Offset = ConstantInt::get(TD.getIntPtrType(),  
ByteOffset);
          FieldPtr = CastToType(Instruction::PtrToInt, FieldPtr,
                                Offset->getType());
-        FieldPtr = BinaryOperator::createAdd(FieldPtr, Offset,  
"tmp", CurBB);
+        FieldPtr = Builder.CreateAdd(FieldPtr, Offset, "tmp");
          FieldPtr = CastToType(Instruction::IntToPtr, FieldPtr,
                                PointerType::get(FieldTy));

@@ -5061,9 +5002,9 @@
      // than this.  e.g. check out when compiling unwind-dw2-fde- 
darwin.c.
      Ptr.Ptr = CastToType(Instruction::BitCast, Ptr.Ptr,
                           PointerType::get(ValTy));
-    Ptr.Ptr = new GetElementPtrInst(Ptr.Ptr,
-                                    ConstantInt::get(Type::Int32Ty,  
UnitOffset),
-                                    "tmp", CurBB);
+    Ptr.Ptr = Builder.CreateGEP(Ptr.Ptr,
+                                ConstantInt::get(Type::Int32Ty,  
UnitOffset),
+                                "tmp");
      BitStart -= UnitOffset*ValueSizeInBits;
    }

@@ -5079,10 +5020,9 @@
    LValue Ptr = EmitLV(TREE_OPERAND(exp, 0));
    assert(!Ptr.isBitfield() && "BIT_FIELD_REF operands cannot be  
bitfields!");

-  return LValue(new GetElementPtrInst(Ptr.Ptr,
-                                      ConstantInt::get 
(Type::Int32Ty, 0),
-                                      ConstantInt::get 
(Type::Int32Ty, Idx),
-                                      "tmp", CurBB));
+  return LValue(Builder.CreateGEP(Ptr.Ptr,
+                                  ConstantInt::get(Type::Int32Ty, 0),
+                                  ConstantInt::get(Type::Int32Ty,  
Idx), "tmp"));
  }

  LValue TreeToLLVM::EmitLV_VIEW_CONVERT_EXPR(tree exp) {
@@ -5156,7 +5096,7 @@
        Value *V = Emit(TREE_VALUE(elt), 0);
        DestLoc = CastToType(Instruction::BitCast, DestLoc,
                             PointerType::get(V->getType()));
-      new StoreInst(V, DestLoc, CurBB);
+      Builder.CreateStore(V, DestLoc);
      }
      break;
    }

Modified: apple-local/branches/llvm/gcc/llvm-internal.h
===================================================================
--- apple-local/branches/llvm/gcc/llvm-internal.h	2007-05-27 08:09:51  
UTC (rev 127731)
+++ apple-local/branches/llvm/gcc/llvm-internal.h	2007-05-27 15:11:20  
UTC (rev 127732)
@@ -35,6 +35,7 @@
  #include "llvm/Intrinsics.h"
  #include "llvm/ADT/SmallVector.h"
  #include "llvm/Support/DataTypes.h"
+#include "llvm/Support/LLVMBuilder.h"
  #include "llvm/Support/Streams.h"

  extern "C" {
@@ -217,9 +218,9 @@

    // State that changes as the function is emitted.

-  /// CurBB - Always the same as &Fn->back() - the current basic  
block to insert
-  /// code into.
-  BasicBlock *CurBB;
+  /// Builder - Instruction creator, the location to insert into is  
always the
+  /// same as &Fn->back().
+  LLVMBuilder Builder;

    // AllocaInsertionPoint - Place to insert alloca instructions.   
Lazily created
    // and managed by CreateTemporary.
@@ -561,11 +562,7 @@
                              Value *DestLoc,
                              Value *&Result,
                              const Type *ResultType,
-                            std::vector<Value*> &Ops,
-                            SmallVector<tree_node *, 8> &Args,
-                            BasicBlock *CurBB,
-                            bool ResIsSigned,
-                            bool ExpIsSigned);
+                            std::vector<Value*> &Ops);
  };

  /// TreeConstantToLLVM - An instance of this class is created and  
used to





More information about the llvm-commits mailing list