1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
/*========================== begin_copyright_notice ============================
Copyright (C) 2017-2022 Intel Corporation
SPDX-License-Identifier: MIT
============================= end_copyright_notice ===========================*/
#include "GenIntrinsics.h"
#include "GenIntrinsicFunctions.h"
#include "GenIntrinsicLookup.h"
#include "Probe/Assertion.h"
#include "Compiler/CodeGenPublic.h"
#include "common/LLVMWarningsPush.hpp"
#include <llvm/IR/Function.h>
#include "common/LLVMWarningsPop.hpp"
namespace IGC {
static llvm::GenISAIntrinsic::ID GetID(const llvm::Function &func, bool useContextWrapper) {
if (useContextWrapper) {
LLVMContextWrapper &ctxWrapper = static_cast<LLVMContextWrapper &>(func.getContext());
LLVMContextWrapper::SafeIntrinsicIDCacheTy &SafeIntrinsicIdCache = ctxWrapper.m_SafeIntrinsicIDCache;
// If you do not find the function ptr as key corresponding to the GenISAIntrinsic::ID add the new key
auto it = SafeIntrinsicIdCache.find(&func);
if (it == SafeIntrinsicIdCache.end()) {
llvm::GenISAIntrinsic::ID id = llvm::GenISAIntrinsic::ID::no_intrinsic;
const llvm::ValueName *const pValueName = func.getValueName();
if (nullptr != pValueName) {
llvm::StringRef prefix = GetIntrinsicPrefixName();
llvm::StringRef Name = pValueName->getKey();
if (Name.size() > prefix.size() && Name.startswith(prefix)) {
id = static_cast<llvm::GenISAIntrinsic::ID>(LookupIntrinsicId(Name.data()));
SafeIntrinsicIdCache[&func] = static_cast<uint32_t>(id);
}
}
return id;
} else {
// If you have an entry for the function ptr corresponding to the GenISAIntrinsic::ID return it back,
// instead of going through a lengthy look-up.
return (static_cast<llvm::GenISAIntrinsic::ID>(it->second));
}
} else {
llvm::GenISAIntrinsic::ID id = llvm::GenISAIntrinsic::ID::no_intrinsic;
const llvm::ValueName *const pValueName = func.getValueName();
if (nullptr != pValueName) {
llvm::StringRef prefix = GetIntrinsicPrefixName();
llvm::StringRef Name = pValueName->getKey();
if (Name.size() > prefix.size() && Name.startswith(prefix)) {
id = static_cast<llvm::GenISAIntrinsic::ID>(LookupIntrinsicId(Name.data()));
}
}
return id;
}
}
} // namespace IGC
namespace llvm {
namespace GenISAIntrinsic {
std::string getName(ID id, ArrayRef<Type *> OverloadedTys /*= None*/,
ArrayRef<Type *> OverloadedPointeeTys /*= None*/) {
return IGC::GetName(id, OverloadedTys, OverloadedPointeeTys);
}
IntrinsicComments getIntrinsicComments(ID id) { return IGC::GetIntrinsicComments(id); }
Function *getDeclaration(Module *M, ID id, ArrayRef<Type *> OverloadedTys /*= None*/,
ArrayRef<Type *> OverloadedPointeeTys /*= None*/) {
return IGC::GetDeclaration(M, id, OverloadedTys, OverloadedPointeeTys);
}
ID getIntrinsicID(const Function *F, bool useContextWrapper /*= true*/) {
if (F != nullptr) {
return IGC::GetID(*F, useContextWrapper);
}
return ID::no_intrinsic;
}
} // namespace GenISAIntrinsic
} // namespace llvm
|