//
// The LLVM Compiler Infrastructure
//
-// This file was developed by the LLVM research group and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
#include "llvm/Support/Streams.h"
#include "llvm/Target/TargetData.h"
#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/STLExtras.h"
using namespace llvm;
template <class ArgIt>
FunctionType::get(RetTy, ParamTys, false));
}
- SmallVector<Value*, 8> Operands(ArgBegin, ArgEnd);
- CallInst *NewCI = new CallInst(FCache, &Operands[0], Operands.size(),
+ SmallVector<Value *, 8> Args(ArgBegin, ArgEnd);
+ CallInst *NewCI = new CallInst(FCache, Args.begin(), Args.end(),
CI->getName(), CI);
if (!CI->use_empty())
CI->replaceAllUsesWith(NewCI);
break;
case Intrinsic::memcpy_i32:
case Intrinsic::memcpy_i64:
- M.getOrInsertFunction("memcpy", PointerType::get(Type::Int8Ty),
- PointerType::get(Type::Int8Ty),
- PointerType::get(Type::Int8Ty),
+ M.getOrInsertFunction("memcpy", PointerType::getUnqual(Type::Int8Ty),
+ PointerType::getUnqual(Type::Int8Ty),
+ PointerType::getUnqual(Type::Int8Ty),
TD.getIntPtrType(), (Type *)0);
break;
case Intrinsic::memmove_i32:
case Intrinsic::memmove_i64:
- M.getOrInsertFunction("memmove", PointerType::get(Type::Int8Ty),
- PointerType::get(Type::Int8Ty),
- PointerType::get(Type::Int8Ty),
+ M.getOrInsertFunction("memmove", PointerType::getUnqual(Type::Int8Ty),
+ PointerType::getUnqual(Type::Int8Ty),
+ PointerType::getUnqual(Type::Int8Ty),
TD.getIntPtrType(), (Type *)0);
break;
case Intrinsic::memset_i32:
case Intrinsic::memset_i64:
- M.getOrInsertFunction("memset", PointerType::get(Type::Int8Ty),
- PointerType::get(Type::Int8Ty), Type::Int32Ty,
+ M.getOrInsertFunction("memset", PointerType::getUnqual(Type::Int8Ty),
+ PointerType::getUnqual(Type::Int8Ty),
+ Type::Int32Ty,
TD.getIntPtrType(), (Type *)0);
break;
- case Intrinsic::sqrt_f32:
- case Intrinsic::sqrt_f64:
- if(I->arg_begin()->getType() == Type::FloatTy)
+ case Intrinsic::sqrt:
+ switch((int)I->arg_begin()->getType()->getTypeID()) {
+ case Type::FloatTyID:
EnsureFunctionExists(M, "sqrtf", I->arg_begin(), I->arg_end(),
Type::FloatTy);
- else
+ case Type::DoubleTyID:
EnsureFunctionExists(M, "sqrt", I->arg_begin(), I->arg_end(),
Type::DoubleTy);
+ case Type::X86_FP80TyID:
+ case Type::FP128TyID:
+ case Type::PPC_FP128TyID:
+ EnsureFunctionExists(M, "sqrtl", I->arg_begin(), I->arg_end(),
+ I->arg_begin()->getType());
+ }
+ break;
+ case Intrinsic::sin:
+ switch((int)I->arg_begin()->getType()->getTypeID()) {
+ case Type::FloatTyID:
+ EnsureFunctionExists(M, "sinf", I->arg_begin(), I->arg_end(),
+ Type::FloatTy);
+ case Type::DoubleTyID:
+ EnsureFunctionExists(M, "sin", I->arg_begin(), I->arg_end(),
+ Type::DoubleTy);
+ case Type::X86_FP80TyID:
+ case Type::FP128TyID:
+ case Type::PPC_FP128TyID:
+ EnsureFunctionExists(M, "sinl", I->arg_begin(), I->arg_end(),
+ I->arg_begin()->getType());
+ }
+ break;
+ case Intrinsic::cos:
+ switch((int)I->arg_begin()->getType()->getTypeID()) {
+ case Type::FloatTyID:
+ EnsureFunctionExists(M, "cosf", I->arg_begin(), I->arg_end(),
+ Type::FloatTy);
+ case Type::DoubleTyID:
+ EnsureFunctionExists(M, "cos", I->arg_begin(), I->arg_end(),
+ Type::DoubleTy);
+ case Type::X86_FP80TyID:
+ case Type::FP128TyID:
+ case Type::PPC_FP128TyID:
+ EnsureFunctionExists(M, "cosl", I->arg_begin(), I->arg_end(),
+ I->arg_begin()->getType());
+ }
+ break;
+ case Intrinsic::pow:
+ switch((int)I->arg_begin()->getType()->getTypeID()) {
+ case Type::FloatTyID:
+ EnsureFunctionExists(M, "powf", I->arg_begin(), I->arg_end(),
+ Type::FloatTy);
+ case Type::DoubleTyID:
+ EnsureFunctionExists(M, "pow", I->arg_begin(), I->arg_end(),
+ Type::DoubleTy);
+ case Type::X86_FP80TyID:
+ case Type::FP128TyID:
+ case Type::PPC_FP128TyID:
+ EnsureFunctionExists(M, "powl", I->arg_begin(), I->arg_end(),
+ I->arg_begin()->getType());
+ }
break;
}
}
}
}
- return CastInst::createIntegerCast(Count, Type::Int32Ty, false, "ctpop", IP);
+ return Count;
}
/// LowerCTLZ - Emit the code to lower ctlz of V before the specified
CI->getOperand(2),
CI->getOperand(3)
};
- return new CallInst(F, Args, sizeof(Args)/sizeof(Args[0]), CI->getName(), CI);
+ return new CallInst(F, Args, array_endof(Args), CI->getName(), CI);
}
/// Convert the llvm.part.set.iX.iY.iZ intrinsic. This intrinsic takes
CI->getOperand(3),
CI->getOperand(4)
};
- return new CallInst(F, Args, sizeof(Args)/sizeof(Args[0]), CI->getName(), CI);
+ return new CallInst(F, Args, array_endof(Args), CI->getName(), CI);
}
case Intrinsic::dbg_region_end:
case Intrinsic::dbg_func_start:
case Intrinsic::dbg_declare:
+ break; // Simply strip out debugging intrinsics
+
case Intrinsic::eh_exception:
- case Intrinsic::eh_selector:
- case Intrinsic::eh_filter:
- break; // Simply strip out debugging and eh intrinsics
+ case Intrinsic::eh_selector_i32:
+ case Intrinsic::eh_selector_i64:
+ CI->replaceAllUsesWith(Constant::getNullValue(CI->getType()));
+ break;
+
+ case Intrinsic::eh_typeid_for_i32:
+ case Intrinsic::eh_typeid_for_i64:
+ // Return something different to eh_selector.
+ CI->replaceAllUsesWith(ConstantInt::get(CI->getType(), 1));
+ break;
case Intrinsic::var_annotation:
break; // Strip out annotate intrinsic
MemsetFCache);
break;
}
- case Intrinsic::sqrt_f32: {
+ case Intrinsic::sqrt: {
static Constant *sqrtfFCache = 0;
- ReplaceCallWith("sqrtf", CI, CI->op_begin()+1, CI->op_end(),
- Type::FloatTy, sqrtfFCache);
- break;
- }
- case Intrinsic::sqrt_f64: {
static Constant *sqrtFCache = 0;
- ReplaceCallWith("sqrt", CI, CI->op_begin()+1, CI->op_end(),
+ static Constant *sqrtLDCache = 0;
+ switch (CI->getOperand(1)->getType()->getTypeID()) {
+ default: assert(0 && "Invalid type in sqrt"); abort();
+ case Type::FloatTyID:
+ ReplaceCallWith("sqrtf", CI, CI->op_begin()+1, CI->op_end(),
+ Type::FloatTy, sqrtfFCache);
+ break;
+ case Type::DoubleTyID:
+ ReplaceCallWith("sqrt", CI, CI->op_begin()+1, CI->op_end(),
Type::DoubleTy, sqrtFCache);
+ break;
+ case Type::X86_FP80TyID:
+ case Type::FP128TyID:
+ case Type::PPC_FP128TyID:
+ ReplaceCallWith("sqrtl", CI, CI->op_begin()+1, CI->op_end(),
+ CI->getOperand(1)->getType(), sqrtLDCache);
+ break;
+ }
break;
}
+ case Intrinsic::flt_rounds:
+ // Lower to "round to the nearest"
+ if (CI->getType() != Type::VoidTy)
+ CI->replaceAllUsesWith(ConstantInt::get(CI->getType(), 1));
+ break;
}
assert(CI->use_empty() &&