Chris Lattner | 3b66ecb | 2003-12-28 08:19:41 +0000 | [diff] [blame] | 1 | //===-- IntrinsicLowering.cpp - Intrinsic Lowering default implementation -===// |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2 | // |
Chris Lattner | 3b66ecb | 2003-12-28 08:19:41 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by the LLVM research group and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 7 | // |
Chris Lattner | 3b66ecb | 2003-12-28 08:19:41 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the default intrinsic lowering implementation. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Chris Lattner | 3048373 | 2004-06-20 07:49:54 +0000 | [diff] [blame] | 14 | #include "llvm/CodeGen/IntrinsicLowering.h" |
Chris Lattner | cf89908 | 2004-02-14 02:47:17 +0000 | [diff] [blame] | 15 | #include "llvm/Constants.h" |
Chris Lattner | 5fe51cc | 2004-02-12 17:01:09 +0000 | [diff] [blame] | 16 | #include "llvm/DerivedTypes.h" |
Chris Lattner | 3b66ecb | 2003-12-28 08:19:41 +0000 | [diff] [blame] | 17 | #include "llvm/Module.h" |
Misha Brukman | 47b14a4 | 2004-07-29 17:30:56 +0000 | [diff] [blame] | 18 | #include "llvm/Instructions.h" |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 19 | #include "llvm/Type.h" |
Reid Spencer | 954da37 | 2004-07-04 12:19:56 +0000 | [diff] [blame] | 20 | #include <iostream> |
| 21 | |
Chris Lattner | 3b66ecb | 2003-12-28 08:19:41 +0000 | [diff] [blame] | 22 | using namespace llvm; |
| 23 | |
Chris Lattner | 0979ca7 | 2004-05-09 04:29:57 +0000 | [diff] [blame] | 24 | template <class ArgIt> |
| 25 | static Function *EnsureFunctionExists(Module &M, const char *Name, |
| 26 | ArgIt ArgBegin, ArgIt ArgEnd, |
| 27 | const Type *RetTy) { |
| 28 | if (Function *F = M.getNamedFunction(Name)) return F; |
| 29 | // It doesn't already exist in the program, insert a new definition now. |
| 30 | std::vector<const Type *> ParamTys; |
| 31 | for (ArgIt I = ArgBegin; I != ArgEnd; ++I) |
| 32 | ParamTys.push_back(I->getType()); |
| 33 | return M.getOrInsertFunction(Name, FunctionType::get(RetTy, ParamTys, false)); |
| 34 | } |
| 35 | |
Chris Lattner | 588e72d | 2004-02-15 22:16:39 +0000 | [diff] [blame] | 36 | /// ReplaceCallWith - This function is used when we want to lower an intrinsic |
| 37 | /// call to a call of an external function. This handles hard cases such as |
| 38 | /// when there was already a prototype for the external function, and if that |
| 39 | /// prototype doesn't match the arguments we expect to pass in. |
| 40 | template <class ArgIt> |
| 41 | static CallInst *ReplaceCallWith(const char *NewFn, CallInst *CI, |
| 42 | ArgIt ArgBegin, ArgIt ArgEnd, |
| 43 | const Type *RetTy, Function *&FCache) { |
| 44 | if (!FCache) { |
| 45 | // If we haven't already looked up this function, check to see if the |
| 46 | // program already contains a function with this name. |
| 47 | Module *M = CI->getParent()->getParent()->getParent(); |
| 48 | FCache = M->getNamedFunction(NewFn); |
| 49 | if (!FCache) { |
| 50 | // It doesn't already exist in the program, insert a new definition now. |
| 51 | std::vector<const Type *> ParamTys; |
| 52 | for (ArgIt I = ArgBegin; I != ArgEnd; ++I) |
| 53 | ParamTys.push_back((*I)->getType()); |
| 54 | FCache = M->getOrInsertFunction(NewFn, |
| 55 | FunctionType::get(RetTy, ParamTys, false)); |
| 56 | } |
Chris Lattner | 0979ca7 | 2004-05-09 04:29:57 +0000 | [diff] [blame] | 57 | } |
Chris Lattner | 588e72d | 2004-02-15 22:16:39 +0000 | [diff] [blame] | 58 | |
| 59 | const FunctionType *FT = FCache->getFunctionType(); |
| 60 | std::vector<Value*> Operands; |
| 61 | unsigned ArgNo = 0; |
| 62 | for (ArgIt I = ArgBegin; I != ArgEnd && ArgNo != FT->getNumParams(); |
| 63 | ++I, ++ArgNo) { |
| 64 | Value *Arg = *I; |
| 65 | if (Arg->getType() != FT->getParamType(ArgNo)) |
| 66 | Arg = new CastInst(Arg, FT->getParamType(ArgNo), Arg->getName(), CI); |
| 67 | Operands.push_back(Arg); |
| 68 | } |
| 69 | // Pass nulls into any additional arguments... |
| 70 | for (; ArgNo != FT->getNumParams(); ++ArgNo) |
| 71 | Operands.push_back(Constant::getNullValue(FT->getParamType(ArgNo))); |
| 72 | |
| 73 | std::string Name = CI->getName(); CI->setName(""); |
| 74 | if (FT->getReturnType() == Type::VoidTy) Name.clear(); |
Chris Lattner | 02348ca | 2004-06-11 02:54:02 +0000 | [diff] [blame] | 75 | CallInst *NewCI = new CallInst(FCache, Operands, Name, CI); |
| 76 | if (!CI->use_empty()) { |
| 77 | Value *V = NewCI; |
| 78 | if (CI->getType() != NewCI->getType()) |
| 79 | V = new CastInst(NewCI, CI->getType(), Name, CI); |
| 80 | CI->replaceAllUsesWith(V); |
| 81 | } |
| 82 | return NewCI; |
Chris Lattner | 588e72d | 2004-02-15 22:16:39 +0000 | [diff] [blame] | 83 | } |
| 84 | |
Chris Lattner | 0979ca7 | 2004-05-09 04:29:57 +0000 | [diff] [blame] | 85 | void DefaultIntrinsicLowering::AddPrototypes(Module &M) { |
| 86 | for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) |
| 87 | if (I->isExternal() && !I->use_empty()) |
| 88 | switch (I->getIntrinsicID()) { |
| 89 | default: break; |
| 90 | case Intrinsic::setjmp: |
Chris Lattner | 1f243e9 | 2005-05-08 19:46:29 +0000 | [diff] [blame] | 91 | EnsureFunctionExists(M, "setjmp", I->arg_begin(), I->arg_end(), |
| 92 | Type::IntTy); |
Chris Lattner | 0979ca7 | 2004-05-09 04:29:57 +0000 | [diff] [blame] | 93 | break; |
| 94 | case Intrinsic::longjmp: |
Chris Lattner | 1f243e9 | 2005-05-08 19:46:29 +0000 | [diff] [blame] | 95 | EnsureFunctionExists(M, "longjmp", I->arg_begin(), I->arg_end(), |
| 96 | Type::VoidTy); |
Chris Lattner | 0979ca7 | 2004-05-09 04:29:57 +0000 | [diff] [blame] | 97 | break; |
| 98 | case Intrinsic::siglongjmp: |
Chris Lattner | 1f243e9 | 2005-05-08 19:46:29 +0000 | [diff] [blame] | 99 | EnsureFunctionExists(M, "abort", I->arg_end(), I->arg_end(), |
| 100 | Type::VoidTy); |
Chris Lattner | 0979ca7 | 2004-05-09 04:29:57 +0000 | [diff] [blame] | 101 | break; |
| 102 | case Intrinsic::memcpy: |
Chris Lattner | e4d5c44 | 2005-03-15 04:54:21 +0000 | [diff] [blame] | 103 | EnsureFunctionExists(M, "memcpy", I->arg_begin(), --I->arg_end(), |
| 104 | I->arg_begin()->getType()); |
Chris Lattner | 0979ca7 | 2004-05-09 04:29:57 +0000 | [diff] [blame] | 105 | break; |
| 106 | case Intrinsic::memmove: |
Chris Lattner | e4d5c44 | 2005-03-15 04:54:21 +0000 | [diff] [blame] | 107 | EnsureFunctionExists(M, "memmove", I->arg_begin(), --I->arg_end(), |
| 108 | I->arg_begin()->getType()); |
Chris Lattner | 0979ca7 | 2004-05-09 04:29:57 +0000 | [diff] [blame] | 109 | break; |
| 110 | case Intrinsic::memset: |
Chris Lattner | 1f243e9 | 2005-05-08 19:46:29 +0000 | [diff] [blame] | 111 | M.getOrInsertFunction("memset", PointerType::get(Type::SByteTy), |
| 112 | PointerType::get(Type::SByteTy), |
| 113 | Type::IntTy, (--(--I->arg_end()))->getType(), 0); |
Chris Lattner | 0979ca7 | 2004-05-09 04:29:57 +0000 | [diff] [blame] | 114 | break; |
Chris Lattner | be78ac4 | 2004-06-15 21:42:23 +0000 | [diff] [blame] | 115 | case Intrinsic::isunordered: |
Chris Lattner | 1f243e9 | 2005-05-08 19:46:29 +0000 | [diff] [blame] | 116 | EnsureFunctionExists(M, "isunordered", I->arg_begin(), I->arg_end(), |
| 117 | Type::BoolTy); |
Chris Lattner | 02348ca | 2004-06-11 02:54:02 +0000 | [diff] [blame] | 118 | break; |
Chris Lattner | b42a9ff | 2005-04-30 04:07:50 +0000 | [diff] [blame] | 119 | case Intrinsic::sqrt: |
Alkis Evlogimenos | b1beff0 | 2005-04-30 07:13:31 +0000 | [diff] [blame] | 120 | if(I->arg_begin()->getType() == Type::FloatTy) |
Chris Lattner | 1f243e9 | 2005-05-08 19:46:29 +0000 | [diff] [blame] | 121 | EnsureFunctionExists(M, "sqrtf", I->arg_begin(), I->arg_end(), |
| 122 | Type::FloatTy); |
Chris Lattner | b42a9ff | 2005-04-30 04:07:50 +0000 | [diff] [blame] | 123 | else |
Chris Lattner | 1f243e9 | 2005-05-08 19:46:29 +0000 | [diff] [blame] | 124 | EnsureFunctionExists(M, "sqrt", I->arg_begin(), I->arg_end(), |
| 125 | Type::DoubleTy); |
Chris Lattner | b42a9ff | 2005-04-30 04:07:50 +0000 | [diff] [blame] | 126 | break; |
Chris Lattner | 0979ca7 | 2004-05-09 04:29:57 +0000 | [diff] [blame] | 127 | } |
Chris Lattner | 0979ca7 | 2004-05-09 04:29:57 +0000 | [diff] [blame] | 128 | } |
Chris Lattner | 588e72d | 2004-02-15 22:16:39 +0000 | [diff] [blame] | 129 | |
Chris Lattner | 86f3e0c | 2005-05-11 19:42:05 +0000 | [diff] [blame^] | 130 | /// LowerCTPOP - Emit the code to lower ctpop of V before the specified |
| 131 | /// instruction. |
| 132 | static Value *LowerCTPOP(Value *V, Instruction *IP) { |
| 133 | assert(V->getType()->isInteger() && "Can't ctpop a non-integer type!"); |
| 134 | unsigned BitSize = V->getType()->getPrimitiveSizeInBits(); |
| 135 | |
| 136 | static const uint64_t MaskValues[6] = { |
| 137 | 0x5555555555555555ULL, 0x3333333333333333ULL, |
| 138 | 0x0F0F0F0F0F0F0F0FULL, 0x00FF00FF00FF00FFULL, |
| 139 | 0x0000FFFF0000FFFFULL, 0x00000000FFFFFFFFULL |
| 140 | }; |
| 141 | |
| 142 | const Type *DestTy = V->getType(); |
| 143 | |
| 144 | // Force to unsigned so that the shift rights are logical. |
| 145 | if (DestTy->isSigned()) |
| 146 | V = new CastInst(V, DestTy->getUnsignedVersion(), V->getName(), IP); |
| 147 | |
| 148 | for (unsigned i = 1, ct = 0; i != BitSize; i <<= 1, ++ct) { |
| 149 | Value *MaskCst = |
| 150 | ConstantExpr::getCast(ConstantUInt::get(Type::ULongTy, |
| 151 | MaskValues[ct]), V->getType()); |
| 152 | Value *LHS = BinaryOperator::createAnd(V, MaskCst, "cppop.and1", IP); |
| 153 | Value *VShift = new ShiftInst(Instruction::Shr, V, |
| 154 | ConstantInt::get(Type::UByteTy, i), "ctpop.sh", IP); |
| 155 | Value *RHS = BinaryOperator::createAnd(VShift, MaskCst, "cppop.and2", IP); |
| 156 | V = BinaryOperator::createAdd(LHS, RHS, "ctpop.step", IP); |
| 157 | } |
| 158 | |
| 159 | if (V->getType() != DestTy) |
| 160 | V = new CastInst(V, DestTy, V->getName(), IP); |
| 161 | return V; |
| 162 | } |
| 163 | |
Chris Lattner | 3b66ecb | 2003-12-28 08:19:41 +0000 | [diff] [blame] | 164 | void DefaultIntrinsicLowering::LowerIntrinsicCall(CallInst *CI) { |
| 165 | Function *Callee = CI->getCalledFunction(); |
| 166 | assert(Callee && "Cannot lower an indirect call!"); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 167 | |
Chris Lattner | 3b66ecb | 2003-12-28 08:19:41 +0000 | [diff] [blame] | 168 | switch (Callee->getIntrinsicID()) { |
| 169 | case Intrinsic::not_intrinsic: |
| 170 | std::cerr << "Cannot lower a call to a non-intrinsic function '" |
| 171 | << Callee->getName() << "'!\n"; |
| 172 | abort(); |
| 173 | default: |
| 174 | std::cerr << "Error: Code generator does not support intrinsic function '" |
| 175 | << Callee->getName() << "'!\n"; |
| 176 | abort(); |
| 177 | |
Chris Lattner | 588e72d | 2004-02-15 22:16:39 +0000 | [diff] [blame] | 178 | // The setjmp/longjmp intrinsics should only exist in the code if it was |
| 179 | // never optimized (ie, right out of the CFE), or if it has been hacked on |
| 180 | // by the lowerinvoke pass. In both cases, the right thing to do is to |
| 181 | // convert the call to an explicit setjmp or longjmp call. |
Chris Lattner | 9b700f7 | 2004-02-15 22:24:51 +0000 | [diff] [blame] | 182 | case Intrinsic::setjmp: { |
| 183 | static Function *SetjmpFCache = 0; |
| 184 | Value *V = ReplaceCallWith("setjmp", CI, CI->op_begin()+1, CI->op_end(), |
| 185 | Type::IntTy, SetjmpFCache); |
Chris Lattner | 3b66ecb | 2003-12-28 08:19:41 +0000 | [diff] [blame] | 186 | if (CI->getType() != Type::VoidTy) |
Chris Lattner | 9b700f7 | 2004-02-15 22:24:51 +0000 | [diff] [blame] | 187 | CI->replaceAllUsesWith(V); |
Chris Lattner | 3b66ecb | 2003-12-28 08:19:41 +0000 | [diff] [blame] | 188 | break; |
Chris Lattner | 9b700f7 | 2004-02-15 22:24:51 +0000 | [diff] [blame] | 189 | } |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 190 | case Intrinsic::sigsetjmp: |
Chris Lattner | 9b700f7 | 2004-02-15 22:24:51 +0000 | [diff] [blame] | 191 | if (CI->getType() != Type::VoidTy) |
| 192 | CI->replaceAllUsesWith(Constant::getNullValue(CI->getType())); |
| 193 | break; |
Chris Lattner | 3b66ecb | 2003-12-28 08:19:41 +0000 | [diff] [blame] | 194 | |
Chris Lattner | f0a3e6c | 2004-06-05 01:05:19 +0000 | [diff] [blame] | 195 | case Intrinsic::longjmp: { |
Chris Lattner | 9b700f7 | 2004-02-15 22:24:51 +0000 | [diff] [blame] | 196 | static Function *LongjmpFCache = 0; |
| 197 | ReplaceCallWith("longjmp", CI, CI->op_begin()+1, CI->op_end(), |
| 198 | Type::VoidTy, LongjmpFCache); |
| 199 | break; |
Chris Lattner | f0a3e6c | 2004-06-05 01:05:19 +0000 | [diff] [blame] | 200 | } |
Chris Lattner | 9b700f7 | 2004-02-15 22:24:51 +0000 | [diff] [blame] | 201 | |
Chris Lattner | f0a3e6c | 2004-06-05 01:05:19 +0000 | [diff] [blame] | 202 | case Intrinsic::siglongjmp: { |
Chris Lattner | 3b66ecb | 2003-12-28 08:19:41 +0000 | [diff] [blame] | 203 | // Insert the call to abort |
Chris Lattner | 588e72d | 2004-02-15 22:16:39 +0000 | [diff] [blame] | 204 | static Function *AbortFCache = 0; |
| 205 | ReplaceCallWith("abort", CI, CI->op_end(), CI->op_end(), Type::VoidTy, |
| 206 | AbortFCache); |
Chris Lattner | 3b66ecb | 2003-12-28 08:19:41 +0000 | [diff] [blame] | 207 | break; |
Chris Lattner | f0a3e6c | 2004-06-05 01:05:19 +0000 | [diff] [blame] | 208 | } |
Chris Lattner | 86f3e0c | 2005-05-11 19:42:05 +0000 | [diff] [blame^] | 209 | case Intrinsic::ctpop: |
| 210 | CI->replaceAllUsesWith(LowerCTPOP(CI->getOperand(1), CI)); |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 211 | break; |
Chris Lattner | 86f3e0c | 2005-05-11 19:42:05 +0000 | [diff] [blame^] | 212 | |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 213 | case Intrinsic::ctlz: { |
| 214 | Value *Src = CI->getOperand(1); |
| 215 | Value* SA; |
| 216 | switch (CI->getOperand(0)->getType()->getTypeID()) |
| 217 | { |
| 218 | case Type::LongTyID: |
| 219 | case Type::ULongTyID: |
| 220 | SA = ConstantUInt::get(Type::UByteTy, 32); |
Chris Lattner | 86f3e0c | 2005-05-11 19:42:05 +0000 | [diff] [blame^] | 221 | Src = BinaryOperator::createOr(Src, new ShiftInst(Instruction::Shr, Src, |
| 222 | SA, "", CI), "", CI); |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 223 | case Type::IntTyID: |
| 224 | case Type::UIntTyID: |
| 225 | SA = ConstantUInt::get(Type::UByteTy, 16); |
Chris Lattner | 86f3e0c | 2005-05-11 19:42:05 +0000 | [diff] [blame^] | 226 | Src = BinaryOperator::createOr(Src, new ShiftInst(Instruction::Shr, |
| 227 | Src, SA, "", CI), |
| 228 | "", CI); |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 229 | case Type::ShortTyID: |
| 230 | case Type::UShortTyID: |
| 231 | SA = ConstantUInt::get(Type::UByteTy, 8); |
Chris Lattner | 86f3e0c | 2005-05-11 19:42:05 +0000 | [diff] [blame^] | 232 | Src = BinaryOperator::createOr(Src, new ShiftInst(Instruction::Shr, |
| 233 | Src, SA, "", CI), |
| 234 | "", CI); |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 235 | default: |
| 236 | SA = ConstantUInt::get(Type::UByteTy, 1); |
Chris Lattner | 86f3e0c | 2005-05-11 19:42:05 +0000 | [diff] [blame^] | 237 | Src = BinaryOperator::createOr(Src, new ShiftInst(Instruction::Shr, Src, |
| 238 | SA, "", CI), "", CI); |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 239 | SA = ConstantUInt::get(Type::UByteTy, 2); |
Chris Lattner | 86f3e0c | 2005-05-11 19:42:05 +0000 | [diff] [blame^] | 240 | Src = BinaryOperator::createOr(Src, new ShiftInst(Instruction::Shr, Src, |
| 241 | SA, "", CI), "", CI); |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 242 | SA = ConstantUInt::get(Type::UByteTy, 4); |
Chris Lattner | 86f3e0c | 2005-05-11 19:42:05 +0000 | [diff] [blame^] | 243 | Src = BinaryOperator::createOr(Src, new ShiftInst(Instruction::Shr, Src, |
| 244 | SA, "", CI), "", CI); |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 245 | }; |
Chris Lattner | 86f3e0c | 2005-05-11 19:42:05 +0000 | [diff] [blame^] | 246 | Src = BinaryOperator::createNot(Src, "", CI); |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 247 | |
Chris Lattner | 86f3e0c | 2005-05-11 19:42:05 +0000 | [diff] [blame^] | 248 | |
| 249 | Src = LowerCTPOP(Src, CI); |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 250 | CI->replaceAllUsesWith(Src); |
| 251 | break; |
| 252 | } |
| 253 | case Intrinsic::cttz: { |
| 254 | Value *Src = CI->getOperand(1); |
Chris Lattner | 86f3e0c | 2005-05-11 19:42:05 +0000 | [diff] [blame^] | 255 | Value *NotSrc = BinaryOperator::createNot(Src, Src->getName()+".not", CI); |
| 256 | Src = BinaryOperator::createAnd(NotSrc, |
| 257 | BinaryOperator::createSub(Src, |
| 258 | ConstantUInt::get(CI->getOperand(0)->getType(), 1), "", CI)); |
| 259 | |
| 260 | Src = LowerCTPOP(Src, CI); |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 261 | CI->replaceAllUsesWith(Src); |
| 262 | break; |
| 263 | } |
Chris Lattner | 77b1330 | 2004-01-05 05:36:30 +0000 | [diff] [blame] | 264 | |
Chris Lattner | cf89908 | 2004-02-14 02:47:17 +0000 | [diff] [blame] | 265 | case Intrinsic::returnaddress: |
| 266 | case Intrinsic::frameaddress: |
Chris Lattner | cc42d2c | 2004-02-14 04:52:06 +0000 | [diff] [blame] | 267 | std::cerr << "WARNING: this target does not support the llvm." |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 268 | << (Callee->getIntrinsicID() == Intrinsic::returnaddress ? |
Chris Lattner | cc42d2c | 2004-02-14 04:52:06 +0000 | [diff] [blame] | 269 | "return" : "frame") << "address intrinsic.\n"; |
Chris Lattner | cf89908 | 2004-02-14 02:47:17 +0000 | [diff] [blame] | 270 | CI->replaceAllUsesWith(ConstantPointerNull::get( |
| 271 | cast<PointerType>(CI->getType()))); |
| 272 | break; |
| 273 | |
Chris Lattner | 0942b7c | 2005-02-28 19:27:23 +0000 | [diff] [blame] | 274 | case Intrinsic::prefetch: |
| 275 | break; // Simply strip out prefetches on unsupported architectures |
| 276 | |
Andrew Lenharth | 7f4ec3b | 2005-03-28 20:05:49 +0000 | [diff] [blame] | 277 | case Intrinsic::pcmarker: |
| 278 | break; // Simply strip out pcmarker on unsupported architectures |
| 279 | |
Chris Lattner | 77b1330 | 2004-01-05 05:36:30 +0000 | [diff] [blame] | 280 | case Intrinsic::dbg_stoppoint: |
| 281 | case Intrinsic::dbg_region_start: |
| 282 | case Intrinsic::dbg_region_end: |
Chris Lattner | f907bac | 2004-01-14 20:41:29 +0000 | [diff] [blame] | 283 | case Intrinsic::dbg_declare: |
Chris Lattner | 77b1330 | 2004-01-05 05:36:30 +0000 | [diff] [blame] | 284 | case Intrinsic::dbg_func_start: |
| 285 | if (CI->getType() != Type::VoidTy) |
| 286 | CI->replaceAllUsesWith(Constant::getNullValue(CI->getType())); |
| 287 | break; // Simply strip out debugging intrinsics |
Chris Lattner | 5fe51cc | 2004-02-12 17:01:09 +0000 | [diff] [blame] | 288 | |
Chris Lattner | f0a3e6c | 2004-06-05 01:05:19 +0000 | [diff] [blame] | 289 | case Intrinsic::memcpy: { |
Chris Lattner | 5fe51cc | 2004-02-12 17:01:09 +0000 | [diff] [blame] | 290 | // The memcpy intrinsic take an extra alignment argument that the memcpy |
| 291 | // libc function does not. |
Chris Lattner | 588e72d | 2004-02-15 22:16:39 +0000 | [diff] [blame] | 292 | static Function *MemcpyFCache = 0; |
| 293 | ReplaceCallWith("memcpy", CI, CI->op_begin()+1, CI->op_end()-1, |
| 294 | (*(CI->op_begin()+1))->getType(), MemcpyFCache); |
Chris Lattner | 5fe51cc | 2004-02-12 17:01:09 +0000 | [diff] [blame] | 295 | break; |
Chris Lattner | f0a3e6c | 2004-06-05 01:05:19 +0000 | [diff] [blame] | 296 | } |
| 297 | case Intrinsic::memmove: { |
Chris Lattner | cf89908 | 2004-02-14 02:47:17 +0000 | [diff] [blame] | 298 | // The memmove intrinsic take an extra alignment argument that the memmove |
Chris Lattner | 2751e76 | 2004-02-12 18:11:20 +0000 | [diff] [blame] | 299 | // libc function does not. |
Chris Lattner | 588e72d | 2004-02-15 22:16:39 +0000 | [diff] [blame] | 300 | static Function *MemmoveFCache = 0; |
| 301 | ReplaceCallWith("memmove", CI, CI->op_begin()+1, CI->op_end()-1, |
| 302 | (*(CI->op_begin()+1))->getType(), MemmoveFCache); |
Chris Lattner | 2751e76 | 2004-02-12 18:11:20 +0000 | [diff] [blame] | 303 | break; |
Chris Lattner | f0a3e6c | 2004-06-05 01:05:19 +0000 | [diff] [blame] | 304 | } |
| 305 | case Intrinsic::memset: { |
Chris Lattner | cf89908 | 2004-02-14 02:47:17 +0000 | [diff] [blame] | 306 | // The memset intrinsic take an extra alignment argument that the memset |
| 307 | // libc function does not. |
Chris Lattner | 588e72d | 2004-02-15 22:16:39 +0000 | [diff] [blame] | 308 | static Function *MemsetFCache = 0; |
| 309 | ReplaceCallWith("memset", CI, CI->op_begin()+1, CI->op_end()-1, |
| 310 | (*(CI->op_begin()+1))->getType(), MemsetFCache); |
Chris Lattner | cf89908 | 2004-02-14 02:47:17 +0000 | [diff] [blame] | 311 | break; |
| 312 | } |
Alkis Evlogimenos | 9685372 | 2004-06-12 19:19:14 +0000 | [diff] [blame] | 313 | case Intrinsic::isunordered: { |
Alkis Evlogimenos | d0656fc | 2005-03-01 02:07:58 +0000 | [diff] [blame] | 314 | Value *L = CI->getOperand(1); |
| 315 | Value *R = CI->getOperand(2); |
| 316 | |
| 317 | Value *LIsNan = new SetCondInst(Instruction::SetNE, L, L, "LIsNan", CI); |
| 318 | Value *RIsNan = new SetCondInst(Instruction::SetNE, R, R, "RIsNan", CI); |
| 319 | CI->replaceAllUsesWith( |
| 320 | BinaryOperator::create(Instruction::Or, LIsNan, RIsNan, |
| 321 | "isunordered", CI)); |
Alkis Evlogimenos | 9685372 | 2004-06-12 19:19:14 +0000 | [diff] [blame] | 322 | break; |
| 323 | } |
Chris Lattner | b42a9ff | 2005-04-30 04:07:50 +0000 | [diff] [blame] | 324 | case Intrinsic::sqrt: { |
| 325 | static Function *sqrtFCache = 0; |
| 326 | static Function *sqrtfFCache = 0; |
| 327 | if(CI->getType() == Type::FloatTy) |
| 328 | ReplaceCallWith("sqrtf", CI, CI->op_begin()+1, CI->op_end(), |
| 329 | Type::FloatTy, sqrtfFCache); |
| 330 | else |
| 331 | ReplaceCallWith("sqrt", CI, CI->op_begin()+1, CI->op_end(), |
| 332 | Type::DoubleTy, sqrtFCache); |
| 333 | break; |
| 334 | } |
Chris Lattner | f0a3e6c | 2004-06-05 01:05:19 +0000 | [diff] [blame] | 335 | } |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 336 | |
Chris Lattner | 3b66ecb | 2003-12-28 08:19:41 +0000 | [diff] [blame] | 337 | assert(CI->use_empty() && |
| 338 | "Lowering should have eliminated any uses of the intrinsic call!"); |
Chris Lattner | 86f3e0c | 2005-05-11 19:42:05 +0000 | [diff] [blame^] | 339 | CI->eraseFromParent(); |
Chris Lattner | 3b66ecb | 2003-12-28 08:19:41 +0000 | [diff] [blame] | 340 | } |