Remove Value::getNameLen

llvm-svn: 77148
This commit is contained in:
Daniel Dunbar 2009-07-26 08:34:35 +00:00
parent 600dfac30a
commit ca414c7cae
6 changed files with 62 additions and 120 deletions

View File

@ -124,10 +124,6 @@ public:
return getName().end();
}
/// getNameLen - Return the length of the string, correctly handling nul
/// characters embedded into them.
unsigned getNameLen() const { return getName().size(); }
/// getName() - Return a constant reference to the value's name. This is cheap
/// and guaranteed to return the same reference as long as the value is not
/// modified.

View File

@ -617,64 +617,31 @@ llvm::canConstantFoldCallTo(const Function *F) {
}
if (!F->hasName()) return false;
const char *Str = F->getNameStart();
unsigned Len = F->getNameLen();
StringRef Name = F->getName();
// In these cases, the check of the length is required. We don't want to
// return true for a name like "cos\0blah" which strcmp would return equal to
// "cos", but has length 8.
switch (Str[0]) {
switch (Name[0]) {
default: return false;
case 'a':
if (Len == 4)
return !strcmp(Str, "acos") || !strcmp(Str, "asin") ||
!strcmp(Str, "atan");
else if (Len == 5)
return !strcmp(Str, "atan2");
return false;
return Name == "acos" || Name == "asin" ||
Name == "atan" || Name == "atan2";
case 'c':
if (Len == 3)
return !strcmp(Str, "cos");
else if (Len == 4)
return !strcmp(Str, "ceil") || !strcmp(Str, "cosf") ||
!strcmp(Str, "cosh");
return false;
return Name == "cos" || Name == "ceil" || Name == "cosf" || Name == "cosh";
case 'e':
if (Len == 3)
return !strcmp(Str, "exp");
return false;
return Name == "exp";
case 'f':
if (Len == 4)
return !strcmp(Str, "fabs") || !strcmp(Str, "fmod");
else if (Len == 5)
return !strcmp(Str, "floor");
return false;
break;
return Name == "fabs" || Name == "fmod" || Name == "floor";
case 'l':
if (Len == 3 && !strcmp(Str, "log"))
return true;
if (Len == 5 && !strcmp(Str, "log10"))
return true;
return false;
return Name == "log" || Name == "log10";
case 'p':
if (Len == 3 && !strcmp(Str, "pow"))
return true;
return false;
return Name == "pow";
case 's':
if (Len == 3)
return !strcmp(Str, "sin");
if (Len == 4)
return !strcmp(Str, "sinh") || !strcmp(Str, "sqrt") ||
!strcmp(Str, "sinf");
if (Len == 5)
return !strcmp(Str, "sqrtf");
return false;
return Name == "sin" || Name == "sinh" || Name == "sqrt" ||
Name == "sinf" || Name == "sqrtf";
case 't':
if (Len == 3 && !strcmp(Str, "tan"))
return true;
else if (Len == 4 && !strcmp(Str, "tanh"))
return true;
return false;
return Name == "tan" || Name == "tanh";
}
}
@ -722,8 +689,7 @@ llvm::ConstantFoldCall(Function *F,
Constant* const* Operands, unsigned NumOperands) {
if (!F->hasName()) return 0;
LLVMContext &Context = F->getContext();
const char *Str = F->getNameStart();
unsigned Len = F->getNameLen();
StringRef Name = F->getName();
const Type *Ty = F->getReturnType();
if (NumOperands == 1) {
@ -736,42 +702,42 @@ llvm::ConstantFoldCall(Function *F,
/// f(arg). Long double not supported yet.
double V = Ty==Type::FloatTy ? (double)Op->getValueAPF().convertToFloat():
Op->getValueAPF().convertToDouble();
switch (Str[0]) {
switch (Name[0]) {
case 'a':
if (Len == 4 && !strcmp(Str, "acos"))
if (Name == "acos")
return ConstantFoldFP(acos, V, Ty, Context);
else if (Len == 4 && !strcmp(Str, "asin"))
else if (Name == "asin")
return ConstantFoldFP(asin, V, Ty, Context);
else if (Len == 4 && !strcmp(Str, "atan"))
else if (Name == "atan")
return ConstantFoldFP(atan, V, Ty, Context);
break;
case 'c':
if (Len == 4 && !strcmp(Str, "ceil"))
if (Name == "ceil")
return ConstantFoldFP(ceil, V, Ty, Context);
else if (Len == 3 && !strcmp(Str, "cos"))
else if (Name == "cos")
return ConstantFoldFP(cos, V, Ty, Context);
else if (Len == 4 && !strcmp(Str, "cosh"))
else if (Name == "cosh")
return ConstantFoldFP(cosh, V, Ty, Context);
else if (Len == 4 && !strcmp(Str, "cosf"))
else if (Name == "cosf")
return ConstantFoldFP(cos, V, Ty, Context);
break;
case 'e':
if (Len == 3 && !strcmp(Str, "exp"))
if (Name == "exp")
return ConstantFoldFP(exp, V, Ty, Context);
break;
case 'f':
if (Len == 4 && !strcmp(Str, "fabs"))
if (Name == "fabs")
return ConstantFoldFP(fabs, V, Ty, Context);
else if (Len == 5 && !strcmp(Str, "floor"))
else if (Name == "floor")
return ConstantFoldFP(floor, V, Ty, Context);
break;
case 'l':
if (Len == 3 && !strcmp(Str, "log") && V > 0)
if (Name == "log" && V > 0)
return ConstantFoldFP(log, V, Ty, Context);
else if (Len == 5 && !strcmp(Str, "log10") && V > 0)
else if (Name == "log10" && V > 0)
return ConstantFoldFP(log10, V, Ty, Context);
else if (!strcmp(Str, "llvm.sqrt.f32") ||
!strcmp(Str, "llvm.sqrt.f64")) {
else if (Name == "llvm.sqrt.f32" ||
Name == "llvm.sqrt.f64") {
if (V >= -0.0)
return ConstantFoldFP(sqrt, V, Ty, Context);
else // Undefined
@ -779,34 +745,34 @@ llvm::ConstantFoldCall(Function *F,
}
break;
case 's':
if (Len == 3 && !strcmp(Str, "sin"))
if (Name == "sin")
return ConstantFoldFP(sin, V, Ty, Context);
else if (Len == 4 && !strcmp(Str, "sinh"))
else if (Name == "sinh")
return ConstantFoldFP(sinh, V, Ty, Context);
else if (Len == 4 && !strcmp(Str, "sqrt") && V >= 0)
else if (Name == "sqrt" && V >= 0)
return ConstantFoldFP(sqrt, V, Ty, Context);
else if (Len == 5 && !strcmp(Str, "sqrtf") && V >= 0)
else if (Name == "sqrtf" && V >= 0)
return ConstantFoldFP(sqrt, V, Ty, Context);
else if (Len == 4 && !strcmp(Str, "sinf"))
else if (Name == "sinf")
return ConstantFoldFP(sin, V, Ty, Context);
break;
case 't':
if (Len == 3 && !strcmp(Str, "tan"))
if (Name == "tan")
return ConstantFoldFP(tan, V, Ty, Context);
else if (Len == 4 && !strcmp(Str, "tanh"))
else if (Name == "tanh")
return ConstantFoldFP(tanh, V, Ty, Context);
break;
default:
break;
}
} else if (ConstantInt *Op = dyn_cast<ConstantInt>(Operands[0])) {
if (Len > 11 && !memcmp(Str, "llvm.bswap", 10))
if (Name.startswith("llvm.bswap"))
return ConstantInt::get(Context, Op->getValue().byteSwap());
else if (Len > 11 && !memcmp(Str, "llvm.ctpop", 10))
else if (Name.startswith("llvm.ctpop"))
return ConstantInt::get(Ty, Op->getValue().countPopulation());
else if (Len > 10 && !memcmp(Str, "llvm.cttz", 9))
else if (Name.startswith("llvm.cttz"))
return ConstantInt::get(Ty, Op->getValue().countTrailingZeros());
else if (Len > 10 && !memcmp(Str, "llvm.ctlz", 9))
else if (Name.startswith("llvm.ctlz"))
return ConstantInt::get(Ty, Op->getValue().countLeadingZeros());
}
} else if (NumOperands == 2) {
@ -821,18 +787,18 @@ llvm::ConstantFoldCall(Function *F,
(double)Op2->getValueAPF().convertToFloat():
Op2->getValueAPF().convertToDouble();
if (Len == 3 && !strcmp(Str, "pow")) {
if (Name == "pow") {
return ConstantFoldBinaryFP(pow, Op1V, Op2V, Ty, Context);
} else if (Len == 4 && !strcmp(Str, "fmod")) {
} else if (Name == "fmod") {
return ConstantFoldBinaryFP(fmod, Op1V, Op2V, Ty, Context);
} else if (Len == 5 && !strcmp(Str, "atan2")) {
} else if (Name == "atan2") {
return ConstantFoldBinaryFP(atan2, Op1V, Op2V, Ty, Context);
}
} else if (ConstantInt *Op2C = dyn_cast<ConstantInt>(Operands[1])) {
if (!strcmp(Str, "llvm.powi.f32")) {
if (Name == "llvm.powi.f32") {
return Context.getConstantFP(APFloat((float)std::pow((float)Op1V,
(int)Op2C->getZExtValue())));
} else if (!strcmp(Str, "llvm.powi.f64")) {
} else if (Name == "llvm.powi.f64") {
return Context.getConstantFP(APFloat((double)std::pow((double)Op1V,
(int)Op2C->getZExtValue())));
}

View File

@ -57,9 +57,6 @@ const LibCallFunctionInfo *LibCallInfo::getFunctionInfo(Function *F) const {
}
// Look up this function in the string map.
const char *ValueName = F->getNameStart();
StringMap<const LibCallFunctionInfo*>::iterator I =
Map->find(StringRef(ValueName, F->getNameLen()));
return I != Map->end() ? I->second : 0;
return Map->lookup(F->getName());
}

View File

@ -800,15 +800,11 @@ bool llvm::CannotBeNegativeZero(const Value *V, unsigned Depth) {
if (const CallInst *CI = dyn_cast<CallInst>(I))
if (const Function *F = CI->getCalledFunction()) {
if (F->isDeclaration()) {
switch (F->getNameLen()) {
case 3: // abs(x) != -0.0
if (!strcmp(F->getNameStart(), "abs")) return true;
break;
case 4: // abs[lf](x) != -0.0
if (!strcmp(F->getNameStart(), "absf")) return true;
if (!strcmp(F->getNameStart(), "absl")) return true;
break;
}
// abs(x) != -0.0
if (F->getName() == "abs") return true;
// abs[lf](x) != -0.0
if (F->getName() == "absf") return true;
if (F->getName() == "absl") return true;
}
}

View File

@ -4439,12 +4439,9 @@ void SelectionDAGLowering::visitCall(CallInst &I) {
// Check for well-known libc/libm calls. If the function is internal, it
// can't be a library call.
unsigned NameLen = F->getNameLen();
if (!F->hasLocalLinkage() && NameLen) {
const char *NameStr = F->getNameStart();
if (NameStr[0] == 'c' &&
((NameLen == 8 && !strcmp(NameStr, "copysign")) ||
(NameLen == 9 && !strcmp(NameStr, "copysignf")))) {
if (!F->hasLocalLinkage() && F->hasName()) {
StringRef Name = F->getName();
if (Name == "copysign" || Name == "copysignf") {
if (I.getNumOperands() == 3 && // Basic sanity checks.
I.getOperand(1)->getType()->isFloatingPoint() &&
I.getType() == I.getOperand(1)->getType() &&
@ -4455,10 +4452,7 @@ void SelectionDAGLowering::visitCall(CallInst &I) {
LHS.getValueType(), LHS, RHS));
return;
}
} else if (NameStr[0] == 'f' &&
((NameLen == 4 && !strcmp(NameStr, "fabs")) ||
(NameLen == 5 && !strcmp(NameStr, "fabsf")) ||
(NameLen == 5 && !strcmp(NameStr, "fabsl")))) {
} else if (Name == "fabs" || Name == "fabsf" || Name == "fabsl") {
if (I.getNumOperands() == 2 && // Basic sanity checks.
I.getOperand(1)->getType()->isFloatingPoint() &&
I.getType() == I.getOperand(1)->getType()) {
@ -4467,10 +4461,7 @@ void SelectionDAGLowering::visitCall(CallInst &I) {
Tmp.getValueType(), Tmp));
return;
}
} else if (NameStr[0] == 's' &&
((NameLen == 3 && !strcmp(NameStr, "sin")) ||
(NameLen == 4 && !strcmp(NameStr, "sinf")) ||
(NameLen == 4 && !strcmp(NameStr, "sinl")))) {
} else if (Name == "sin" || Name == "sinf" || Name == "sinl") {
if (I.getNumOperands() == 2 && // Basic sanity checks.
I.getOperand(1)->getType()->isFloatingPoint() &&
I.getType() == I.getOperand(1)->getType()) {
@ -4479,10 +4470,7 @@ void SelectionDAGLowering::visitCall(CallInst &I) {
Tmp.getValueType(), Tmp));
return;
}
} else if (NameStr[0] == 'c' &&
((NameLen == 3 && !strcmp(NameStr, "cos")) ||
(NameLen == 4 && !strcmp(NameStr, "cosf")) ||
(NameLen == 4 && !strcmp(NameStr, "cosl")))) {
} else if (Name == "cos" || Name == "cosf" || Name == "cosl") {
if (I.getNumOperands() == 2 && // Basic sanity checks.
I.getOperand(1)->getType()->isFloatingPoint() &&
I.getType() == I.getOperand(1)->getType()) {

View File

@ -31,6 +31,7 @@
#include "llvm/ADT/Statistic.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Config/config.h"
using namespace llvm;
@ -1655,20 +1656,18 @@ bool SimplifyLibCalls::runOnFunction(Function &F) {
continue;
// Ignore unknown calls.
const char *CalleeName = Callee->getNameStart();
StringMap<LibCallOptimization*>::iterator OMI =
Optimizations.find(StringRef(CalleeName, Callee->getNameLen()));
if (OMI == Optimizations.end()) continue;
LibCallOptimization *LCO = Optimizations.lookup(Callee->getName());
if (!LCO) continue;
// Set the builder to the instruction after the call.
Builder.SetInsertPoint(BB, I);
// Try to optimize this call.
Value *Result = OMI->second->OptimizeCall(CI, TD, Builder);
Value *Result = LCO->OptimizeCall(CI, TD, Builder);
if (Result == 0) continue;
DEBUG(DOUT << "SimplifyLibCalls simplified: " << *CI;
DOUT << " into: " << *Result << "\n");
DEBUG(errs() << "SimplifyLibCalls simplified: " << *CI;
errs() << " into: " << *Result << "\n");
// Something changed!
Changed = true;