llvm.org GIT mirror llvm / e2c4304
Use Intrinsic::getDeclaration in more places. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@49338 91177308-0d34-0410-b5e6-96231b3b80d8 Duncan Sands 11 years ago
4 changed file(s) with 18 addition(s) and 37 deletion(s). Raw diff Collapse all Expand all
2424
2525 #include "BrainF.h"
2626 #include "llvm/Constants.h"
27 #include "llvm/Intrinsics.h"
2728 #include "llvm/ADT/STLExtras.h"
2829
2930 using namespace llvm;
5152 //Function prototypes
5253
5354 //declare void @llvm.memset.i32(i8 *, i8, i32, i32)
54 Function *memset_func = cast(module->
55 getOrInsertFunction("llvm.memset.i32", Type::VoidTy,
56 PointerType::getUnqual(IntegerType::Int8Ty),
57 IntegerType::Int8Ty, IntegerType::Int32Ty,
58 IntegerType::Int32Ty, NULL));
55 Function *memset_func = Intrinsic::getDeclaration(module, Intrinsic::memset_i32);
5956
6057 //declare i32 @getchar()
6158 getchar_func = cast(module->
2020 #include "llvm/Constants.h"
2121 #include "llvm/DerivedTypes.h"
2222 #include "llvm/Instructions.h"
23 #include "llvm/Intrinsics.h"
2324 #include "llvm/Module.h"
2425 #include "llvm/Pass.h"
2526 #include "llvm/ADT/StringMap.h"
319320 /// @brief Return a Function* for the memcpy libcall
320321 Constant *get_memcpy() {
321322 if (!memcpy_func) {
322 const Type *SBP = PointerType::getUnqual(Type::Int8Ty);
323 const char *N = TD->getIntPtrType() == Type::Int32Ty ?
324 "llvm.memcpy.i32" : "llvm.memcpy.i64";
325 memcpy_func = M->getOrInsertFunction(N, Type::VoidTy, SBP, SBP,
326 TD->getIntPtrType(), Type::Int32Ty,
327 NULL);
323 Intrinsic::ID IID = (TD->getIntPtrType() == Type::Int32Ty) ?
324 Intrinsic::memcpy_i32 : Intrinsic::memcpy_i64;
325 memcpy_func = Intrinsic::getDeclaration(M, IID);
328326 }
329327 return memcpy_func;
330328 }
16951693 // ffsl(x) -> x == 0 ? 0 : llvm.cttz(x)+1
16961694 // ffsll(x) -> x == 0 ? 0 : llvm.cttz(x)+1
16971695 const Type *ArgType = TheCall->getOperand(1)->getType();
1698 const char *CTTZName;
16991696 assert(ArgType->getTypeID() == Type::IntegerTyID &&
17001697 "llvm.cttz argument is not an integer?");
1701 unsigned BitWidth = cast(ArgType)->getBitWidth();
1702 if (BitWidth == 8)
1703 CTTZName = "llvm.cttz.i8";
1704 else if (BitWidth == 16)
1705 CTTZName = "llvm.cttz.i16";
1706 else if (BitWidth == 32)
1707 CTTZName = "llvm.cttz.i32";
1708 else {
1709 assert(BitWidth == 64 && "Unknown bitwidth");
1710 CTTZName = "llvm.cttz.i64";
1711 }
1712
1713 Constant *F = SLC.getModule()->getOrInsertFunction(CTTZName, ArgType,
1714 ArgType, NULL);
1698 Constant *F = Intrinsic::getDeclaration(SLC.getModule(),
1699 Intrinsic::cttz, &ArgType, 1);
1700
17151701 Value *V = CastInst::createIntegerCast(TheCall->getOperand(1), ArgType,
17161702 false/*ZExt*/, "tmp", TheCall);
17171703 Value *V2 = CallInst::Create(F, V, "tmp", TheCall);
3636 #include "llvm/Instructions.h"
3737 #include "llvm/Constants.h"
3838 #include "llvm/DerivedTypes.h"
39 #include "llvm/Intrinsics.h"
3940 #include "llvm/Transforms/Scalar.h"
4041 #include "llvm/Transforms/Utils/BasicBlockUtils.h"
4142 #include "llvm/Support/CommandLine.h"
300301
301302
302303 CycleCounter::CycleCounter(Module& m, uint64_t resetmask) : rm(resetmask) {
303 F = m.getOrInsertFunction("llvm.readcyclecounter", Type::Int64Ty, NULL);
304 F = Intrinsic::getDeclaration(&m, Intrinsic::readcyclecounter);
304305 }
305306
306307 CycleCounter::~CycleCounter() {}
15921592 const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID);
15931593 const Type* ArgTy = F->getFunctionType()->getReturnType();
15941594 const Type* ArgTyPtr = PointerType::getUnqual(ArgTy);
1595 Function* NF = cast(Result->getOrInsertFunction(
1596 "llvm.va_start", RetTy, ArgTyPtr, (Type *)0));
1595 Function* NF = Intrinsic::getDeclaration(Result, Intrinsic::va_start);
15971596
15981597 while (!F->use_empty()) {
15991598 CallInst* CI = cast(F->use_back());
16191618 const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID);
16201619 const Type* ArgTy = F->getFunctionType()->getParamType(0);
16211620 const Type* ArgTyPtr = PointerType::getUnqual(ArgTy);
1622 Function* NF = cast(Result->getOrInsertFunction(
1623 "llvm.va_end", RetTy, ArgTyPtr, (Type *)0));
1621 Function* NF = Intrinsic::getDeclaration(Result, Intrinsic::va_end);
16241622
16251623 while (!F->use_empty()) {
16261624 CallInst* CI = cast(F->use_back());
16481646 const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID);
16491647 const Type* ArgTy = F->getFunctionType()->getReturnType();
16501648 const Type* ArgTyPtr = PointerType::getUnqual(ArgTy);
1651 Function* NF = cast(Result->getOrInsertFunction(
1652 "llvm.va_copy", RetTy, ArgTyPtr, ArgTyPtr, (Type *)0));
1649 Function* NF = Intrinsic::getDeclaration(Result, Intrinsic::va_copy);
16531650
16541651 while (!F->use_empty()) {
16551652 CallInst* CI = cast(F->use_back());
35503547 const Type* ArgTy = $2.V->getType();
35513548 const Type* DstTy = $4.PAT->get();
35523549 ObsoleteVarArgs = true;
3553 Function* NF = cast(CurModule.CurrentModule->
3554 getOrInsertFunction("llvm.va_copy", ArgTy, ArgTy, (Type *)0));
3550 Function* NF = Intrinsic::getDeclaration(CurModule.CurrentModule,
3551 Intrinsic::va_copy);
35553552
35563553 //b = vaarg a, t ->
35573554 //foo = alloca 1 of t
35713568 const Type* ArgTy = $2.V->getType();
35723569 const Type* DstTy = $4.PAT->get();
35733570 ObsoleteVarArgs = true;
3574 Function* NF = cast(CurModule.CurrentModule->
3575 getOrInsertFunction("llvm.va_copy", ArgTy, ArgTy, (Type *)0));
3571 Function* NF = Intrinsic::getDeclaration(CurModule.CurrentModule,
3572 Intrinsic::va_copy);
35763573
35773574 //b = vanext a, t ->
35783575 //foo = alloca 1 of t