eliminate a bunch of vector-related heap traffic

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34222 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2007-02-13 05:58:53 +00:00
parent 9d2fda6883
commit c18470cb00

View File

@ -512,12 +512,12 @@ public:
// We have enough information to now generate the memcpy call to // We have enough information to now generate the memcpy call to
// do the concatenation for us. // do the concatenation for us.
std::vector<Value*> vals; Value *vals[4];
vals.push_back(gep); // destination vals[0] = gep; // destination
vals.push_back(ci->getOperand(2)); // source vals[1] = ci->getOperand(2); // source
vals.push_back(ConstantInt::get(SLC.getIntPtrType(),len)); // length vals[2] = ConstantInt::get(SLC.getIntPtrType(),len); // length
vals.push_back(ConstantInt::get(Type::Int32Ty,1)); // alignment vals[3] = ConstantInt::get(Type::Int32Ty,1); // alignment
new CallInst(SLC.get_memcpy(), vals, "", ci); new CallInst(SLC.get_memcpy(), vals, 4, "", ci);
// Finally, substitute the first operand of the strcat call for the // Finally, substitute the first operand of the strcat call for the
// strcat call itself since strcat returns its first operand; and, // strcat call itself since strcat returns its first operand; and,
@ -565,11 +565,12 @@ public:
// The second operand is not constant, or not signed. Just lower this to // The second operand is not constant, or not signed. Just lower this to
// memchr since we know the length of the string since it is constant. // memchr since we know the length of the string since it is constant.
Constant *f = SLC.get_memchr(); Constant *f = SLC.get_memchr();
std::vector<Value*> args; Value* args[3] = {
args.push_back(ci->getOperand(1)); ci->getOperand(1),
args.push_back(ci->getOperand(2)); ci->getOperand(2),
args.push_back(ConstantInt::get(SLC.getIntPtrType(), len)); ConstantInt::get(SLC.getIntPtrType(), len)
ci->replaceAllUsesWith(new CallInst(f, args, ci->getName(), ci)); };
ci->replaceAllUsesWith(new CallInst(f, args, 3, ci->getName(), ci));
ci->eraseFromParent(); ci->eraseFromParent();
return true; return true;
} }
@ -841,12 +842,12 @@ public:
// We have enough information to now generate the memcpy call to // We have enough information to now generate the memcpy call to
// do the concatenation for us. // do the concatenation for us.
std::vector<Value*> vals; Value *vals[4] = {
vals.push_back(dest); // destination dest, src,
vals.push_back(src); // source ConstantInt::get(SLC.getIntPtrType(),len), // length
vals.push_back(ConstantInt::get(SLC.getIntPtrType(),len)); // length ConstantInt::get(Type::Int32Ty, 1) // alignment
vals.push_back(ConstantInt::get(Type::Int32Ty,1)); // alignment };
new CallInst(SLC.get_memcpy(), vals, "", ci); new CallInst(SLC.get_memcpy(), vals, 4, "", ci);
// Finally, substitute the first operand of the strcat call for the // Finally, substitute the first operand of the strcat call for the
// strcat call itself since strcat returns its first operand; and, // strcat call itself since strcat returns its first operand; and,
@ -1423,12 +1424,13 @@ public:
if (ci->getOperand(2)->getType() != PointerType::get(Type::Int8Ty)) if (ci->getOperand(2)->getType() != PointerType::get(Type::Int8Ty))
return false; return false;
std::vector<Value*> args; Value* args[4] = {
args.push_back(ci->getOperand(2)); ci->getOperand(2),
args.push_back(ConstantInt::get(SLC.getIntPtrType(),len)); ConstantInt::get(SLC.getIntPtrType(),len),
args.push_back(ConstantInt::get(SLC.getIntPtrType(),1)); ConstantInt::get(SLC.getIntPtrType(),1),
args.push_back(ci->getOperand(1)); ci->getOperand(1)
new CallInst(SLC.get_fwrite(FILEptr_type), args, ci->getName(), ci); };
new CallInst(SLC.get_fwrite(FILEptr_type), args, 4, ci->getName(), ci);
ci->replaceAllUsesWith(ConstantInt::get(Type::Int32Ty,len)); ci->replaceAllUsesWith(ConstantInt::get(Type::Int32Ty,len));
ci->eraseFromParent(); ci->eraseFromParent();
return true; return true;
@ -1454,12 +1456,13 @@ public:
if (getConstantStringLength(ci->getOperand(3), len, &CA)) { if (getConstantStringLength(ci->getOperand(3), len, &CA)) {
// fprintf(file,"%s",str) -> fwrite(str,strlen(str),1,file) // fprintf(file,"%s",str) -> fwrite(str,strlen(str),1,file)
const Type* FILEptr_type = ci->getOperand(1)->getType(); const Type* FILEptr_type = ci->getOperand(1)->getType();
std::vector<Value*> args; Value* args[4] = {
args.push_back(CastToCStr(ci->getOperand(3), *ci)); CastToCStr(ci->getOperand(3), *ci),
args.push_back(ConstantInt::get(SLC.getIntPtrType(), len)); ConstantInt::get(SLC.getIntPtrType(), len),
args.push_back(ConstantInt::get(SLC.getIntPtrType(), 1)); ConstantInt::get(SLC.getIntPtrType(), 1),
args.push_back(ci->getOperand(1)); ci->getOperand(1)
new CallInst(SLC.get_fwrite(FILEptr_type), args, ci->getName(), ci); };
new CallInst(SLC.get_fwrite(FILEptr_type), args, 4,ci->getName(), ci);
ci->replaceAllUsesWith(ConstantInt::get(Type::Int32Ty, len)); ci->replaceAllUsesWith(ConstantInt::get(Type::Int32Ty, len));
} else { } else {
// fprintf(file,"%s",str) -> fputs(str,file) // fprintf(file,"%s",str) -> fputs(str,file)
@ -1542,12 +1545,13 @@ public:
len++; len++;
// sprintf(str,fmt) -> llvm.memcpy(str,fmt,strlen(fmt),1) // sprintf(str,fmt) -> llvm.memcpy(str,fmt,strlen(fmt),1)
std::vector<Value*> args; Value *args[4] = {
args.push_back(ci->getOperand(1)); ci->getOperand(1),
args.push_back(ci->getOperand(2)); ci->getOperand(2),
args.push_back(ConstantInt::get(SLC.getIntPtrType(),len)); ConstantInt::get(SLC.getIntPtrType(),len),
args.push_back(ConstantInt::get(Type::Int32Ty,1)); ConstantInt::get(Type::Int32Ty, 1)
new CallInst(SLC.get_memcpy(), args, "", ci); };
new CallInst(SLC.get_memcpy(), args, 4, "", ci);
ci->replaceAllUsesWith(ConstantInt::get(Type::Int32Ty,len)); ci->replaceAllUsesWith(ConstantInt::get(Type::Int32Ty,len));
ci->eraseFromParent(); ci->eraseFromParent();
return true; return true;
@ -1577,12 +1581,13 @@ public:
if (Len1->getType() != SLC.getIntPtrType()) if (Len1->getType() != SLC.getIntPtrType())
Len1 = CastInst::createIntegerCast(Len1, SLC.getIntPtrType(), false, Len1 = CastInst::createIntegerCast(Len1, SLC.getIntPtrType(), false,
Len1->getName(), ci); Len1->getName(), ci);
std::vector<Value*> args; Value *args[4] = {
args.push_back(CastToCStr(ci->getOperand(1), *ci)); CastToCStr(ci->getOperand(1), *ci),
args.push_back(CastToCStr(ci->getOperand(3), *ci)); CastToCStr(ci->getOperand(3), *ci),
args.push_back(Len1); Len1,
args.push_back(ConstantInt::get(Type::Int32Ty,1)); ConstantInt::get(Type::Int32Ty,1)
new CallInst(SLC.get_memcpy(), args, "", ci); };
new CallInst(SLC.get_memcpy(), args, 4, "", ci);
// The strlen result is the unincremented number of bytes in the string. // The strlen result is the unincremented number of bytes in the string.
if (!ci->use_empty()) { if (!ci->use_empty()) {
@ -1660,12 +1665,13 @@ public:
{ {
// fputs(s,F) -> fwrite(s,1,len,F) (if s is constant and strlen(s) > 1) // fputs(s,F) -> fwrite(s,1,len,F) (if s is constant and strlen(s) > 1)
const Type* FILEptr_type = ci->getOperand(2)->getType(); const Type* FILEptr_type = ci->getOperand(2)->getType();
std::vector<Value*> parms; Value *parms[4] = {
parms.push_back(ci->getOperand(1)); ci->getOperand(1),
parms.push_back(ConstantInt::get(SLC.getIntPtrType(),len)); ConstantInt::get(SLC.getIntPtrType(),len),
parms.push_back(ConstantInt::get(SLC.getIntPtrType(),1)); ConstantInt::get(SLC.getIntPtrType(),1),
parms.push_back(ci->getOperand(2)); ci->getOperand(2)
new CallInst(SLC.get_fwrite(FILEptr_type), parms, "", ci); };
new CallInst(SLC.get_fwrite(FILEptr_type), parms, 4, "", ci);
break; break;
} }
} }