2014-06-24 02:00:31 +08:00
|
|
|
//===- AMDGPUIntrinsicInfo.cpp - AMDGPU Intrinsic Information ---*- C++ -*-===//
|
2012-12-12 05:25:42 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//==-----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
/// \file
|
|
|
|
/// \brief AMDGPU Implementation of the IntrinsicInfo class.
|
|
|
|
//
|
|
|
|
//===-----------------------------------------------------------------------===//
|
|
|
|
|
2014-06-24 02:00:31 +08:00
|
|
|
#include "AMDGPUIntrinsicInfo.h"
|
2012-12-12 05:25:42 +08:00
|
|
|
#include "AMDGPUSubtarget.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/DerivedTypes.h"
|
|
|
|
#include "llvm/IR/Intrinsics.h"
|
|
|
|
#include "llvm/IR/Module.h"
|
2012-12-12 05:25:42 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2014-07-26 06:22:39 +08:00
|
|
|
AMDGPUIntrinsicInfo::AMDGPUIntrinsicInfo()
|
2014-06-24 02:00:31 +08:00
|
|
|
: TargetIntrinsicInfo() {}
|
2012-12-12 05:25:42 +08:00
|
|
|
|
2016-01-27 07:01:21 +08:00
|
|
|
static const char *const IntrinsicNameTable[] = {
|
2012-12-12 05:25:42 +08:00
|
|
|
#define GET_INTRINSIC_NAME_TABLE
|
|
|
|
#include "AMDGPUGenIntrinsics.inc"
|
|
|
|
#undef GET_INTRINSIC_NAME_TABLE
|
2016-01-27 07:01:21 +08:00
|
|
|
};
|
2012-12-12 05:25:42 +08:00
|
|
|
|
2016-07-20 07:16:53 +08:00
|
|
|
namespace {
|
|
|
|
#define GET_INTRINSIC_ATTRIBUTES
|
|
|
|
#include "AMDGPUGenIntrinsics.inc"
|
|
|
|
#undef GET_INTRINSIC_ATTRIBUTES
|
|
|
|
}
|
|
|
|
|
|
|
|
StringRef AMDGPUIntrinsicInfo::getName(unsigned IntrID,
|
|
|
|
ArrayRef<Type *> Tys) const {
|
|
|
|
if (IntrID < Intrinsic::num_intrinsics)
|
|
|
|
return StringRef();
|
|
|
|
|
2014-06-24 02:00:31 +08:00
|
|
|
assert(IntrID < AMDGPUIntrinsic::num_AMDGPU_intrinsics &&
|
|
|
|
"Invalid intrinsic ID");
|
2012-12-12 05:25:42 +08:00
|
|
|
|
2016-07-20 07:16:53 +08:00
|
|
|
return IntrinsicNameTable[IntrID - Intrinsic::num_intrinsics];
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string AMDGPUIntrinsicInfo::getName(unsigned IntrID, Type **Tys,
|
|
|
|
unsigned NumTys) const {
|
|
|
|
return getName(IntrID, makeArrayRef(Tys, NumTys)).str();
|
|
|
|
}
|
|
|
|
|
|
|
|
FunctionType *AMDGPUIntrinsicInfo::getType(LLVMContext &Context, unsigned ID,
|
|
|
|
ArrayRef<Type*> Tys) const {
|
|
|
|
// FIXME: Re-use Intrinsic::getType machinery
|
|
|
|
switch (ID) {
|
|
|
|
case AMDGPUIntrinsic::amdgcn_fdiv_fast: {
|
|
|
|
Type *F32Ty = Type::getFloatTy(Context);
|
|
|
|
return FunctionType::get(F32Ty, { F32Ty, F32Ty }, false);
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
llvm_unreachable("unhandled intrinsic");
|
|
|
|
}
|
2012-12-12 05:25:42 +08:00
|
|
|
}
|
|
|
|
|
2016-01-27 07:01:21 +08:00
|
|
|
unsigned AMDGPUIntrinsicInfo::lookupName(const char *NameData,
|
2014-06-24 02:00:31 +08:00
|
|
|
unsigned Len) const {
|
2016-01-27 07:01:21 +08:00
|
|
|
StringRef Name(NameData, Len);
|
|
|
|
if (!Name.startswith("llvm."))
|
2013-05-22 22:57:42 +08:00
|
|
|
return 0; // All intrinsics start with 'llvm.'
|
|
|
|
|
2016-01-27 07:01:21 +08:00
|
|
|
// Look for a name match in our table. If the intrinsic is not overloaded,
|
|
|
|
// require an exact match. If it is overloaded, require a prefix match. The
|
|
|
|
// AMDGPU enum enum starts at Intrinsic::num_intrinsics.
|
|
|
|
int Idx = Intrinsic::lookupLLVMIntrinsicByName(IntrinsicNameTable, Name);
|
|
|
|
if (Idx >= 0) {
|
|
|
|
bool IsPrefixMatch = Name.size() > strlen(IntrinsicNameTable[Idx]);
|
|
|
|
return IsPrefixMatch == isOverloaded(Idx + 1)
|
|
|
|
? Intrinsic::num_intrinsics + Idx
|
|
|
|
: 0;
|
2012-12-12 05:25:42 +08:00
|
|
|
}
|
2016-01-27 07:01:21 +08:00
|
|
|
|
2016-01-27 09:43:12 +08:00
|
|
|
return 0;
|
2012-12-12 05:25:42 +08:00
|
|
|
}
|
|
|
|
|
2014-06-24 02:00:31 +08:00
|
|
|
bool AMDGPUIntrinsicInfo::isOverloaded(unsigned id) const {
|
|
|
|
// Overload Table
|
2012-12-12 05:25:42 +08:00
|
|
|
#define GET_INTRINSIC_OVERLOAD_TABLE
|
|
|
|
#include "AMDGPUGenIntrinsics.inc"
|
|
|
|
#undef GET_INTRINSIC_OVERLOAD_TABLE
|
|
|
|
}
|
|
|
|
|
2016-07-20 07:16:53 +08:00
|
|
|
Function *AMDGPUIntrinsicInfo::getDeclaration(Module *M, unsigned IntrID,
|
|
|
|
ArrayRef<Type *> Tys) const {
|
|
|
|
FunctionType *FTy = getType(M->getContext(), IntrID, Tys);
|
|
|
|
Function *F
|
|
|
|
= cast<Function>(M->getOrInsertFunction(getName(IntrID, Tys), FTy));
|
|
|
|
|
|
|
|
AttributeSet AS = getAttributes(M->getContext(),
|
|
|
|
static_cast<AMDGPUIntrinsic::ID>(IntrID));
|
|
|
|
F->setAttributes(AS);
|
|
|
|
return F;
|
|
|
|
}
|
|
|
|
|
2014-06-24 02:00:31 +08:00
|
|
|
Function *AMDGPUIntrinsicInfo::getDeclaration(Module *M, unsigned IntrID,
|
|
|
|
Type **Tys,
|
2016-07-20 07:16:53 +08:00
|
|
|
unsigned NumTys) const {
|
|
|
|
return getDeclaration(M, IntrID, makeArrayRef(Tys, NumTys));
|
2012-12-12 05:25:42 +08:00
|
|
|
}
|