Use IRBuilder.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@139156 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Devang Patel 2011-09-06 18:49:53 +00:00
parent 98447daa95
commit 2048c379dd

View File

@ -811,7 +811,7 @@ bool CodeGenPrepare::OptimizeMemoryInst(Instruction *MemoryInst, Value *Addr,
// Insert this computation right after this user. Since our caller is // Insert this computation right after this user. Since our caller is
// scanning from the top of the BB to the bottom, reuse of the expr are // scanning from the top of the BB to the bottom, reuse of the expr are
// guaranteed to happen later. // guaranteed to happen later.
BasicBlock::iterator InsertPt = MemoryInst; IRBuilder<> Builder(MemoryInst);
// Now that we determined the addressing expression we want to use and know // Now that we determined the addressing expression we want to use and know
// that we have to sink it into this block. Check to see if we have already // that we have to sink it into this block. Check to see if we have already
@ -822,7 +822,7 @@ bool CodeGenPrepare::OptimizeMemoryInst(Instruction *MemoryInst, Value *Addr,
DEBUG(dbgs() << "CGP: Reusing nonlocal addrmode: " << AddrMode << " for " DEBUG(dbgs() << "CGP: Reusing nonlocal addrmode: " << AddrMode << " for "
<< *MemoryInst); << *MemoryInst);
if (SunkAddr->getType() != Addr->getType()) if (SunkAddr->getType() != Addr->getType())
SunkAddr = new BitCastInst(SunkAddr, Addr->getType(), "tmp", InsertPt); SunkAddr = Builder.CreateBitCast(SunkAddr, Addr->getType(), "tmp");
} else { } else {
DEBUG(dbgs() << "CGP: SINKING nonlocal addrmode: " << AddrMode << " for " DEBUG(dbgs() << "CGP: SINKING nonlocal addrmode: " << AddrMode << " for "
<< *MemoryInst); << *MemoryInst);
@ -839,10 +839,9 @@ bool CodeGenPrepare::OptimizeMemoryInst(Instruction *MemoryInst, Value *Addr,
if (AddrMode.BaseReg) { if (AddrMode.BaseReg) {
Value *V = AddrMode.BaseReg; Value *V = AddrMode.BaseReg;
if (V->getType()->isPointerTy()) if (V->getType()->isPointerTy())
V = new PtrToIntInst(V, IntPtrTy, "sunkaddr", InsertPt); V = Builder.CreatePtrToInt(V, IntPtrTy, "sunkaddr");
if (V->getType() != IntPtrTy) if (V->getType() != IntPtrTy)
V = CastInst::CreateIntegerCast(V, IntPtrTy, /*isSigned=*/true, V = Builder.CreateIntCast(V, IntPtrTy, /*isSigned=*/true, "sunkaddr");
"sunkaddr", InsertPt);
Result = V; Result = V;
} }
@ -852,29 +851,27 @@ bool CodeGenPrepare::OptimizeMemoryInst(Instruction *MemoryInst, Value *Addr,
if (V->getType() == IntPtrTy) { if (V->getType() == IntPtrTy) {
// done. // done.
} else if (V->getType()->isPointerTy()) { } else if (V->getType()->isPointerTy()) {
V = new PtrToIntInst(V, IntPtrTy, "sunkaddr", InsertPt); V = Builder.CreatePtrToInt(V, IntPtrTy, "sunkaddr");
} else if (cast<IntegerType>(IntPtrTy)->getBitWidth() < } else if (cast<IntegerType>(IntPtrTy)->getBitWidth() <
cast<IntegerType>(V->getType())->getBitWidth()) { cast<IntegerType>(V->getType())->getBitWidth()) {
V = new TruncInst(V, IntPtrTy, "sunkaddr", InsertPt); V = Builder.CreateTrunc(V, IntPtrTy, "sunkaddr");
} else { } else {
V = new SExtInst(V, IntPtrTy, "sunkaddr", InsertPt); V = Builder.CreateSExt(V, IntPtrTy, "sunkaddr");
} }
if (AddrMode.Scale != 1) if (AddrMode.Scale != 1)
V = BinaryOperator::CreateMul(V, ConstantInt::get(IntPtrTy, V = Builder.CreateMul(V, ConstantInt::get(IntPtrTy, AddrMode.Scale),
AddrMode.Scale), "sunkaddr");
"sunkaddr", InsertPt);
if (Result) if (Result)
Result = BinaryOperator::CreateAdd(Result, V, "sunkaddr", InsertPt); Result = Builder.CreateAdd(Result, V, "sunkaddr");
else else
Result = V; Result = V;
} }
// Add in the BaseGV if present. // Add in the BaseGV if present.
if (AddrMode.BaseGV) { if (AddrMode.BaseGV) {
Value *V = new PtrToIntInst(AddrMode.BaseGV, IntPtrTy, "sunkaddr", Value *V = Builder.CreatePtrToInt(AddrMode.BaseGV, IntPtrTy, "sunkaddr");
InsertPt);
if (Result) if (Result)
Result = BinaryOperator::CreateAdd(Result, V, "sunkaddr", InsertPt); Result = Builder.CreateAdd(Result, V, "sunkaddr");
else else
Result = V; Result = V;
} }
@ -883,7 +880,7 @@ bool CodeGenPrepare::OptimizeMemoryInst(Instruction *MemoryInst, Value *Addr,
if (AddrMode.BaseOffs) { if (AddrMode.BaseOffs) {
Value *V = ConstantInt::get(IntPtrTy, AddrMode.BaseOffs); Value *V = ConstantInt::get(IntPtrTy, AddrMode.BaseOffs);
if (Result) if (Result)
Result = BinaryOperator::CreateAdd(Result, V, "sunkaddr", InsertPt); Result = Builder.CreateAdd(Result, V, "sunkaddr");
else else
Result = V; Result = V;
} }
@ -891,7 +888,7 @@ bool CodeGenPrepare::OptimizeMemoryInst(Instruction *MemoryInst, Value *Addr,
if (Result == 0) if (Result == 0)
SunkAddr = Constant::getNullValue(Addr->getType()); SunkAddr = Constant::getNullValue(Addr->getType());
else else
SunkAddr = new IntToPtrInst(Result, Addr->getType(), "sunkaddr",InsertPt); SunkAddr = Builder.CreateIntToPtr(Result, Addr->getType(), "sunkaddr");
} }
MemoryInst->replaceUsesOfWith(Repl, SunkAddr); MemoryInst->replaceUsesOfWith(Repl, SunkAddr);