mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-25 13:24:46 +00:00
Enable double to float shrinking optimizations for binary functions like 'fmin/fmax'. Fix radar:15283121
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@197434 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -286,6 +286,21 @@ Value *llvm::EmitMemCmp(Value *Ptr1, Value *Ptr2,
|
||||
return CI;
|
||||
}
|
||||
|
||||
/// Append a suffix to the function name according to the type of 'Op'.
|
||||
static void AppendTypeSuffix(Value *Op, StringRef &Name, SmallString<20> &NameBuffer) {
|
||||
if (!Op->getType()->isDoubleTy()) {
|
||||
NameBuffer += Name;
|
||||
|
||||
if (Op->getType()->isFloatTy())
|
||||
NameBuffer += 'f';
|
||||
else
|
||||
NameBuffer += 'l';
|
||||
|
||||
Name = NameBuffer;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/// EmitUnaryFloatFnCall - Emit a call to the unary function named 'Name' (e.g.
|
||||
/// 'floor'). This function is known to take a single of type matching 'Op' and
|
||||
/// returns one value with the same type. If 'Op' is a long double, 'l' is
|
||||
@@ -293,15 +308,7 @@ Value *llvm::EmitMemCmp(Value *Ptr1, Value *Ptr2,
|
||||
Value *llvm::EmitUnaryFloatFnCall(Value *Op, StringRef Name, IRBuilder<> &B,
|
||||
const AttributeSet &Attrs) {
|
||||
SmallString<20> NameBuffer;
|
||||
if (!Op->getType()->isDoubleTy()) {
|
||||
// If we need to add a suffix, copy into NameBuffer.
|
||||
NameBuffer += Name;
|
||||
if (Op->getType()->isFloatTy())
|
||||
NameBuffer += 'f'; // floorf
|
||||
else
|
||||
NameBuffer += 'l'; // floorl
|
||||
Name = NameBuffer;
|
||||
}
|
||||
AppendTypeSuffix(Op, Name, NameBuffer);
|
||||
|
||||
Module *M = B.GetInsertBlock()->getParent()->getParent();
|
||||
Value *Callee = M->getOrInsertFunction(Name, Op->getType(),
|
||||
@@ -314,6 +321,27 @@ Value *llvm::EmitUnaryFloatFnCall(Value *Op, StringRef Name, IRBuilder<> &B,
|
||||
return CI;
|
||||
}
|
||||
|
||||
/// EmitBinaryFloatFnCall - Emit a call to the binary function named 'Name'
|
||||
/// (e.g. 'fmin'). This function is known to take type matching 'Op1' and 'Op2'
|
||||
/// and return one value with the same type. If 'Op1/Op2' are long double, 'l'
|
||||
/// is added as the suffix of name, if 'Op1/Op2' is a float, we add a 'f'
|
||||
/// suffix.
|
||||
Value *llvm::EmitBinaryFloatFnCall(Value *Op1, Value *Op2, StringRef Name,
|
||||
IRBuilder<> &B, const AttributeSet &Attrs) {
|
||||
SmallString<20> NameBuffer;
|
||||
AppendTypeSuffix(Op1, Name, NameBuffer);
|
||||
|
||||
Module *M = B.GetInsertBlock()->getParent()->getParent();
|
||||
Value *Callee = M->getOrInsertFunction(Name, Op1->getType(),
|
||||
Op1->getType(), Op2->getType(), NULL);
|
||||
CallInst *CI = B.CreateCall2(Callee, Op1, Op2, Name);
|
||||
CI->setAttributes(Attrs);
|
||||
if (const Function *F = dyn_cast<Function>(Callee->stripPointerCasts()))
|
||||
CI->setCallingConv(F->getCallingConv());
|
||||
|
||||
return CI;
|
||||
}
|
||||
|
||||
/// EmitPutChar - Emit a call to the putchar function. This assumes that Char
|
||||
/// is an integer.
|
||||
Value *llvm::EmitPutChar(Value *Char, IRBuilder<> &B, const DataLayout *TD,
|
||||
|
Reference in New Issue
Block a user