forked from OSchip/llvm-project
Small improvements to Intrinsic::getName
While I was adding a new intrinsic instruction (not overloaded), I accidentally used CreateUnaryIntrinsic to create the intrinsics, which turns out to be passing the type list to getName, and ended up naming the intrinsics function with type suffix, which leads to wierd bugs latter on. It took me a long time to debug. It seems a good idea to add an assertion in getName so that it fails if types are passed but it's not a overloaded function. Also, the overloade version of getName is less efficient because it creates an std::string. We should avoid calling it if we know that there are no types provided. Differential Revision: https://reviews.llvm.org/D92523
This commit is contained in:
parent
55f8c2fdfb
commit
80b0f74c8c
|
@ -781,6 +781,8 @@ StringRef Intrinsic::getName(ID id) {
|
|||
|
||||
std::string Intrinsic::getName(ID id, ArrayRef<Type*> Tys) {
|
||||
assert(id < num_intrinsics && "Invalid intrinsic ID!");
|
||||
assert((Tys.empty() || Intrinsic::isOverloaded(id)) &&
|
||||
"This version of getName is for overloaded intrinsics only");
|
||||
std::string Result(IntrinsicNameTable[id]);
|
||||
for (Type *Ty : Tys) {
|
||||
Result += "." + getMangledTypeStr(Ty);
|
||||
|
@ -1243,7 +1245,7 @@ Function *Intrinsic::getDeclaration(Module *M, ID id, ArrayRef<Type*> Tys) {
|
|||
// There can never be multiple globals with the same name of different types,
|
||||
// because intrinsics must be a specific type.
|
||||
return cast<Function>(
|
||||
M->getOrInsertFunction(getName(id, Tys),
|
||||
M->getOrInsertFunction(Tys.empty() ? getName(id) : getName(id, Tys),
|
||||
getType(M->getContext(), id, Tys))
|
||||
.getCallee());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue