• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- AMDGPUIntrinsicInfo.cpp - AMDGPU Intrinsic Information ---*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //==-----------------------------------------------------------------------===//
9 //
10 /// \file
11 /// \brief AMDGPU Implementation of the IntrinsicInfo class.
12 //
13 //===-----------------------------------------------------------------------===//
14 
15 #include "AMDGPUIntrinsicInfo.h"
16 #include "AMDGPUSubtarget.h"
17 #include "llvm/IR/DerivedTypes.h"
18 #include "llvm/IR/Intrinsics.h"
19 #include "llvm/IR/Module.h"
20 
21 using namespace llvm;
22 
AMDGPUIntrinsicInfo()23 AMDGPUIntrinsicInfo::AMDGPUIntrinsicInfo()
24     : TargetIntrinsicInfo() {}
25 
26 static const char *const IntrinsicNameTable[] = {
27 #define GET_INTRINSIC_NAME_TABLE
28 #include "AMDGPUGenIntrinsics.inc"
29 #undef GET_INTRINSIC_NAME_TABLE
30 };
31 
getName(unsigned IntrID,Type ** Tys,unsigned numTys) const32 std::string AMDGPUIntrinsicInfo::getName(unsigned IntrID, Type **Tys,
33                                          unsigned numTys) const {
34   if (IntrID < Intrinsic::num_intrinsics) {
35     return nullptr;
36   }
37   assert(IntrID < AMDGPUIntrinsic::num_AMDGPU_intrinsics &&
38          "Invalid intrinsic ID");
39 
40   std::string Result(IntrinsicNameTable[IntrID - Intrinsic::num_intrinsics]);
41   return Result;
42 }
43 
lookupName(const char * NameData,unsigned Len) const44 unsigned AMDGPUIntrinsicInfo::lookupName(const char *NameData,
45                                          unsigned Len) const {
46   StringRef Name(NameData, Len);
47   if (!Name.startswith("llvm."))
48     return 0; // All intrinsics start with 'llvm.'
49 
50   // Look for a name match in our table.  If the intrinsic is not overloaded,
51   // require an exact match. If it is overloaded, require a prefix match. The
52   // AMDGPU enum enum starts at Intrinsic::num_intrinsics.
53   int Idx = Intrinsic::lookupLLVMIntrinsicByName(IntrinsicNameTable, Name);
54   if (Idx >= 0) {
55     bool IsPrefixMatch = Name.size() > strlen(IntrinsicNameTable[Idx]);
56     return IsPrefixMatch == isOverloaded(Idx + 1)
57                ? Intrinsic::num_intrinsics + Idx
58                : 0;
59   }
60 
61   return 0;
62 }
63 
isOverloaded(unsigned id) const64 bool AMDGPUIntrinsicInfo::isOverloaded(unsigned id) const {
65 // Overload Table
66 #define GET_INTRINSIC_OVERLOAD_TABLE
67 #include "AMDGPUGenIntrinsics.inc"
68 #undef GET_INTRINSIC_OVERLOAD_TABLE
69 }
70 
getDeclaration(Module * M,unsigned IntrID,Type ** Tys,unsigned numTys) const71 Function *AMDGPUIntrinsicInfo::getDeclaration(Module *M, unsigned IntrID,
72                                               Type **Tys,
73                                               unsigned numTys) const {
74   llvm_unreachable("Not implemented");
75 }
76