[PATCH] D92523: Small improvements to Intrinsic::getName
Xun Li via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 2 16:35:19 PST 2020
lxfind created this revision.
Herald added subscribers: llvm-commits, hoy, dexonsmith, modimo, wenlei, hiraditya.
Herald added a project: LLVM.
lxfind requested review of this revision.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D92523
Files:
llvm/lib/IR/Function.cpp
Index: llvm/lib/IR/Function.cpp
===================================================================
--- llvm/lib/IR/Function.cpp
+++ llvm/lib/IR/Function.cpp
@@ -775,6 +775,8 @@
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);
@@ -1237,7 +1239,7 @@
// 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());
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92523.309098.patch
Type: text/x-patch
Size: 945 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201203/3f1e36e2/attachment.bin>
More information about the llvm-commits
mailing list