2012-02-18 12:03:15 +00:00
|
|
|
//===-- MBlazeIntrinsicInfo.cpp - Intrinsic Information -------------------===//
|
2010-02-23 19:15:24 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains the MBlaze implementation of TargetIntrinsicInfo.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "MBlazeIntrinsicInfo.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/DerivedTypes.h"
|
|
|
|
#include "llvm/IR/Function.h"
|
|
|
|
#include "llvm/IR/Intrinsics.h"
|
|
|
|
#include "llvm/IR/Module.h"
|
|
|
|
#include "llvm/IR/Type.h"
|
2012-02-05 07:21:30 +00:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2010-02-23 19:15:24 +00:00
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace mblazeIntrinsic {
|
|
|
|
|
|
|
|
enum ID {
|
|
|
|
last_non_mblaze_intrinsic = Intrinsic::num_intrinsics-1,
|
|
|
|
#define GET_INTRINSIC_ENUM_VALUES
|
|
|
|
#include "MBlazeGenIntrinsics.inc"
|
|
|
|
#undef GET_INTRINSIC_ENUM_VALUES
|
|
|
|
, num_mblaze_intrinsics
|
|
|
|
};
|
|
|
|
|
2010-02-24 20:16:27 +00:00
|
|
|
#define GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN
|
|
|
|
#include "MBlazeGenIntrinsics.inc"
|
|
|
|
#undef GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN
|
2010-02-23 19:15:24 +00:00
|
|
|
}
|
|
|
|
|
2011-07-18 04:54:35 +00:00
|
|
|
std::string MBlazeIntrinsicInfo::getName(unsigned IntrID, Type **Tys,
|
2010-02-23 19:15:24 +00:00
|
|
|
unsigned numTys) const {
|
|
|
|
static const char *const names[] = {
|
|
|
|
#define GET_INTRINSIC_NAME_TABLE
|
|
|
|
#include "MBlazeGenIntrinsics.inc"
|
|
|
|
#undef GET_INTRINSIC_NAME_TABLE
|
|
|
|
};
|
|
|
|
|
|
|
|
assert(!isOverloaded(IntrID) && "MBlaze intrinsics are not overloaded");
|
|
|
|
if (IntrID < Intrinsic::num_intrinsics)
|
|
|
|
return 0;
|
2010-11-08 19:40:01 +00:00
|
|
|
assert(IntrID < mblazeIntrinsic::num_mblaze_intrinsics &&
|
2010-02-23 19:15:24 +00:00
|
|
|
"Invalid intrinsic ID");
|
|
|
|
|
|
|
|
std::string Result(names[IntrID - Intrinsic::num_intrinsics]);
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned MBlazeIntrinsicInfo::
|
|
|
|
lookupName(const char *Name, unsigned Len) const {
|
2010-03-18 16:52:15 +00:00
|
|
|
if (Len < 5 || Name[4] != '.' || Name[0] != 'l' || Name[1] != 'l'
|
|
|
|
|| Name[2] != 'v' || Name[3] != 'm')
|
|
|
|
return 0; // All intrinsics start with 'llvm.'
|
|
|
|
|
2010-02-23 19:15:24 +00:00
|
|
|
#define GET_FUNCTION_RECOGNIZER
|
|
|
|
#include "MBlazeGenIntrinsics.inc"
|
|
|
|
#undef GET_FUNCTION_RECOGNIZER
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-02-24 20:16:27 +00:00
|
|
|
unsigned MBlazeIntrinsicInfo::
|
|
|
|
lookupGCCName(const char *Name) const {
|
|
|
|
return mblazeIntrinsic::getIntrinsicForGCCBuiltin("mblaze",Name);
|
|
|
|
}
|
|
|
|
|
2010-02-23 19:15:24 +00:00
|
|
|
bool MBlazeIntrinsicInfo::isOverloaded(unsigned IntrID) const {
|
2012-03-01 02:16:57 +00:00
|
|
|
if (IntrID == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
unsigned id = IntrID - Intrinsic::num_intrinsics + 1;
|
2010-02-23 19:15:24 +00:00
|
|
|
#define GET_INTRINSIC_OVERLOAD_TABLE
|
|
|
|
#include "MBlazeGenIntrinsics.inc"
|
|
|
|
#undef GET_INTRINSIC_OVERLOAD_TABLE
|
|
|
|
}
|
|
|
|
|
2012-10-15 04:46:55 +00:00
|
|
|
/// This defines the "getAttributes(LLVMContext &C, ID id)" method.
|
2010-02-23 19:15:24 +00:00
|
|
|
#define GET_INTRINSIC_ATTRIBUTES
|
|
|
|
#include "MBlazeGenIntrinsics.inc"
|
|
|
|
#undef GET_INTRINSIC_ATTRIBUTES
|
|
|
|
|
2011-07-18 04:54:35 +00:00
|
|
|
static FunctionType *getType(LLVMContext &Context, unsigned id) {
|
|
|
|
Type *ResultTy = NULL;
|
2011-10-17 21:33:26 +00:00
|
|
|
SmallVector<Type*, 8> ArgTys;
|
2010-02-23 19:15:24 +00:00
|
|
|
bool IsVarArg = false;
|
2010-11-08 19:40:01 +00:00
|
|
|
|
2010-02-23 19:15:24 +00:00
|
|
|
#define GET_INTRINSIC_GENERATOR
|
|
|
|
#include "MBlazeGenIntrinsics.inc"
|
|
|
|
#undef GET_INTRINSIC_GENERATOR
|
|
|
|
|
2010-11-08 19:40:01 +00:00
|
|
|
return FunctionType::get(ResultTy, ArgTys, IsVarArg);
|
2010-02-23 19:15:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Function *MBlazeIntrinsicInfo::getDeclaration(Module *M, unsigned IntrID,
|
2011-07-18 04:54:35 +00:00
|
|
|
Type **Tys,
|
2010-02-23 19:15:24 +00:00
|
|
|
unsigned numTy) const {
|
|
|
|
assert(!isOverloaded(IntrID) && "MBlaze intrinsics are not overloaded");
|
2012-12-07 23:16:57 +00:00
|
|
|
AttributeSet AList = getAttributes(M->getContext(),
|
2012-10-15 04:46:55 +00:00
|
|
|
(mblazeIntrinsic::ID) IntrID);
|
2010-02-23 19:15:24 +00:00
|
|
|
return cast<Function>(M->getOrInsertFunction(getName(IntrID),
|
|
|
|
getType(M->getContext(), IntrID),
|
|
|
|
AList));
|
|
|
|
}
|