Use Intrinsic::getDeclaration in more places.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@49338 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan Sands 2008-04-07 13:45:04 +00:00
parent 3d292aca03
commit e2c4304654
4 changed files with 18 additions and 37 deletions

View File

@ -25,6 +25,7 @@
#include "BrainF.h" #include "BrainF.h"
#include "llvm/Constants.h" #include "llvm/Constants.h"
#include "llvm/Intrinsics.h"
#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/STLExtras.h"
using namespace llvm; using namespace llvm;
@ -52,11 +53,7 @@ void BrainF::header() {
//Function prototypes //Function prototypes
//declare void @llvm.memset.i32(i8 *, i8, i32, i32) //declare void @llvm.memset.i32(i8 *, i8, i32, i32)
Function *memset_func = cast<Function>(module-> Function *memset_func = Intrinsic::getDeclaration(module, Intrinsic::memset_i32);
getOrInsertFunction("llvm.memset.i32", Type::VoidTy,
PointerType::getUnqual(IntegerType::Int8Ty),
IntegerType::Int8Ty, IntegerType::Int32Ty,
IntegerType::Int32Ty, NULL));
//declare i32 @getchar() //declare i32 @getchar()
getchar_func = cast<Function>(module-> getchar_func = cast<Function>(module->

View File

@ -21,6 +21,7 @@
#include "llvm/Constants.h" #include "llvm/Constants.h"
#include "llvm/DerivedTypes.h" #include "llvm/DerivedTypes.h"
#include "llvm/Instructions.h" #include "llvm/Instructions.h"
#include "llvm/Intrinsics.h"
#include "llvm/Module.h" #include "llvm/Module.h"
#include "llvm/Pass.h" #include "llvm/Pass.h"
#include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringMap.h"
@ -320,12 +321,9 @@ public:
/// @brief Return a Function* for the memcpy libcall /// @brief Return a Function* for the memcpy libcall
Constant *get_memcpy() { Constant *get_memcpy() {
if (!memcpy_func) { if (!memcpy_func) {
const Type *SBP = PointerType::getUnqual(Type::Int8Ty); Intrinsic::ID IID = (TD->getIntPtrType() == Type::Int32Ty) ?
const char *N = TD->getIntPtrType() == Type::Int32Ty ? Intrinsic::memcpy_i32 : Intrinsic::memcpy_i64;
"llvm.memcpy.i32" : "llvm.memcpy.i64"; memcpy_func = Intrinsic::getDeclaration(M, IID);
memcpy_func = M->getOrInsertFunction(N, Type::VoidTy, SBP, SBP,
TD->getIntPtrType(), Type::Int32Ty,
NULL);
} }
return memcpy_func; return memcpy_func;
} }
@ -1696,23 +1694,11 @@ public:
// ffsl(x) -> x == 0 ? 0 : llvm.cttz(x)+1 // ffsl(x) -> x == 0 ? 0 : llvm.cttz(x)+1
// ffsll(x) -> x == 0 ? 0 : llvm.cttz(x)+1 // ffsll(x) -> x == 0 ? 0 : llvm.cttz(x)+1
const Type *ArgType = TheCall->getOperand(1)->getType(); const Type *ArgType = TheCall->getOperand(1)->getType();
const char *CTTZName;
assert(ArgType->getTypeID() == Type::IntegerTyID && assert(ArgType->getTypeID() == Type::IntegerTyID &&
"llvm.cttz argument is not an integer?"); "llvm.cttz argument is not an integer?");
unsigned BitWidth = cast<IntegerType>(ArgType)->getBitWidth(); Constant *F = Intrinsic::getDeclaration(SLC.getModule(),
if (BitWidth == 8) Intrinsic::cttz, &ArgType, 1);
CTTZName = "llvm.cttz.i8";
else if (BitWidth == 16)
CTTZName = "llvm.cttz.i16";
else if (BitWidth == 32)
CTTZName = "llvm.cttz.i32";
else {
assert(BitWidth == 64 && "Unknown bitwidth");
CTTZName = "llvm.cttz.i64";
}
Constant *F = SLC.getModule()->getOrInsertFunction(CTTZName, ArgType,
ArgType, NULL);
Value *V = CastInst::createIntegerCast(TheCall->getOperand(1), ArgType, Value *V = CastInst::createIntegerCast(TheCall->getOperand(1), ArgType,
false/*ZExt*/, "tmp", TheCall); false/*ZExt*/, "tmp", TheCall);
Value *V2 = CallInst::Create(F, V, "tmp", TheCall); Value *V2 = CallInst::Create(F, V, "tmp", TheCall);

View File

@ -37,6 +37,7 @@
#include "llvm/Instructions.h" #include "llvm/Instructions.h"
#include "llvm/Constants.h" #include "llvm/Constants.h"
#include "llvm/DerivedTypes.h" #include "llvm/DerivedTypes.h"
#include "llvm/Intrinsics.h"
#include "llvm/Transforms/Scalar.h" #include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h" #include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Support/CommandLine.h" #include "llvm/Support/CommandLine.h"
@ -301,7 +302,7 @@ void GlobalRandomCounterOpt::ProcessChoicePoint(BasicBlock* bb) {
CycleCounter::CycleCounter(Module& m, uint64_t resetmask) : rm(resetmask) { CycleCounter::CycleCounter(Module& m, uint64_t resetmask) : rm(resetmask) {
F = m.getOrInsertFunction("llvm.readcyclecounter", Type::Int64Ty, NULL); F = Intrinsic::getDeclaration(&m, Intrinsic::readcyclecounter);
} }
CycleCounter::~CycleCounter() {} CycleCounter::~CycleCounter() {}

View File

@ -1593,8 +1593,7 @@ Module* UpgradeAssembly(const std::string &infile, std::istream& in,
const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID); const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID);
const Type* ArgTy = F->getFunctionType()->getReturnType(); const Type* ArgTy = F->getFunctionType()->getReturnType();
const Type* ArgTyPtr = PointerType::getUnqual(ArgTy); const Type* ArgTyPtr = PointerType::getUnqual(ArgTy);
Function* NF = cast<Function>(Result->getOrInsertFunction( Function* NF = Intrinsic::getDeclaration(Result, Intrinsic::va_start);
"llvm.va_start", RetTy, ArgTyPtr, (Type *)0));
while (!F->use_empty()) { while (!F->use_empty()) {
CallInst* CI = cast<CallInst>(F->use_back()); CallInst* CI = cast<CallInst>(F->use_back());
@ -1620,8 +1619,7 @@ Module* UpgradeAssembly(const std::string &infile, std::istream& in,
const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID); const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID);
const Type* ArgTy = F->getFunctionType()->getParamType(0); const Type* ArgTy = F->getFunctionType()->getParamType(0);
const Type* ArgTyPtr = PointerType::getUnqual(ArgTy); const Type* ArgTyPtr = PointerType::getUnqual(ArgTy);
Function* NF = cast<Function>(Result->getOrInsertFunction( Function* NF = Intrinsic::getDeclaration(Result, Intrinsic::va_end);
"llvm.va_end", RetTy, ArgTyPtr, (Type *)0));
while (!F->use_empty()) { while (!F->use_empty()) {
CallInst* CI = cast<CallInst>(F->use_back()); CallInst* CI = cast<CallInst>(F->use_back());
@ -1649,8 +1647,7 @@ Module* UpgradeAssembly(const std::string &infile, std::istream& in,
const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID); const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID);
const Type* ArgTy = F->getFunctionType()->getReturnType(); const Type* ArgTy = F->getFunctionType()->getReturnType();
const Type* ArgTyPtr = PointerType::getUnqual(ArgTy); const Type* ArgTyPtr = PointerType::getUnqual(ArgTy);
Function* NF = cast<Function>(Result->getOrInsertFunction( Function* NF = Intrinsic::getDeclaration(Result, Intrinsic::va_copy);
"llvm.va_copy", RetTy, ArgTyPtr, ArgTyPtr, (Type *)0));
while (!F->use_empty()) { while (!F->use_empty()) {
CallInst* CI = cast<CallInst>(F->use_back()); CallInst* CI = cast<CallInst>(F->use_back());
@ -3551,8 +3548,8 @@ InstVal
const Type* ArgTy = $2.V->getType(); const Type* ArgTy = $2.V->getType();
const Type* DstTy = $4.PAT->get(); const Type* DstTy = $4.PAT->get();
ObsoleteVarArgs = true; ObsoleteVarArgs = true;
Function* NF = cast<Function>(CurModule.CurrentModule-> Function* NF = Intrinsic::getDeclaration(CurModule.CurrentModule,
getOrInsertFunction("llvm.va_copy", ArgTy, ArgTy, (Type *)0)); Intrinsic::va_copy);
//b = vaarg a, t -> //b = vaarg a, t ->
//foo = alloca 1 of t //foo = alloca 1 of t
@ -3572,8 +3569,8 @@ InstVal
const Type* ArgTy = $2.V->getType(); const Type* ArgTy = $2.V->getType();
const Type* DstTy = $4.PAT->get(); const Type* DstTy = $4.PAT->get();
ObsoleteVarArgs = true; ObsoleteVarArgs = true;
Function* NF = cast<Function>(CurModule.CurrentModule-> Function* NF = Intrinsic::getDeclaration(CurModule.CurrentModule,
getOrInsertFunction("llvm.va_copy", ArgTy, ArgTy, (Type *)0)); Intrinsic::va_copy);
//b = vanext a, t -> //b = vanext a, t ->
//foo = alloca 1 of t //foo = alloca 1 of t