[PATCH] D31304: [MetaRenamer] Don't rename library functions.
bryant via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 23 16:33:23 PDT 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL298659: [MetaRenamer] Don't rename library functions. (authored by bryant).
Changed prior to commit:
https://reviews.llvm.org/D31304?vs=92873&id=92882#toc
Repository:
rL LLVM
https://reviews.llvm.org/D31304
Files:
llvm/trunk/lib/Transforms/Utils/MetaRenamer.cpp
llvm/trunk/test/Transforms/MetaRenamer/metarenamer.ll
Index: llvm/trunk/test/Transforms/MetaRenamer/metarenamer.ll
===================================================================
--- llvm/trunk/test/Transforms/MetaRenamer/metarenamer.ll
+++ llvm/trunk/test/Transforms/MetaRenamer/metarenamer.ll
@@ -96,3 +96,18 @@
store i32 %arg_2_xxx, i32* %2, align 4
ret i32 6
}
+
+declare noalias i8* @malloc(i32)
+declare void @free(i8* nocapture)
+
+define void @dont_rename_lib_funcs() {
+; CHECK-LABEL: @foo(
+; CHECK-NEXT: bb:
+; CHECK-NEXT: [[TMP:%.*]] = call i8* @malloc(i32 23)
+; CHECK-NEXT: call void @free(i8* [[TMP]])
+; CHECK-NEXT: ret void
+;
+ %x = call i8* @malloc(i32 23)
+ call void @free(i8* %x)
+ ret void
+}
Index: llvm/trunk/lib/Transforms/Utils/MetaRenamer.cpp
===================================================================
--- llvm/trunk/lib/Transforms/Utils/MetaRenamer.cpp
+++ llvm/trunk/lib/Transforms/Utils/MetaRenamer.cpp
@@ -16,6 +16,7 @@
#include "llvm/Transforms/IPO.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallString.h"
+#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Module.h"
@@ -67,6 +68,7 @@
}
void getAnalysisUsage(AnalysisUsage &AU) const override {
+ AU.addRequired<TargetLibraryInfoWrapperPass>();
AU.setPreservesAll();
}
@@ -110,9 +112,15 @@
}
// Rename all functions
+ const TargetLibraryInfo &TLI =
+ getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
for (auto &F : M) {
StringRef Name = F.getName();
- if (Name.startswith("llvm.") || (!Name.empty() && Name[0] == 1))
+ LibFunc Tmp;
+ // Leave library functions alone because their presence or absence could
+ // affect the behavior of other passes.
+ if (Name.startswith("llvm.") || (!Name.empty() && Name[0] == 1) ||
+ TLI.getLibFunc(F, Tmp))
continue;
F.setName(renamer.newName());
@@ -139,8 +147,11 @@
}
char MetaRenamer::ID = 0;
-INITIALIZE_PASS(MetaRenamer, "metarenamer",
- "Assign new names to everything", false, false)
+INITIALIZE_PASS_BEGIN(MetaRenamer, "metarenamer",
+ "Assign new names to everything", false, false)
+INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
+INITIALIZE_PASS_END(MetaRenamer, "metarenamer",
+ "Assign new names to everything", false, false)
//===----------------------------------------------------------------------===//
//
// MetaRenamer - Rename everything with metasyntactic names.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31304.92882.patch
Type: text/x-patch
Size: 2601 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170323/f45c856f/attachment-0001.bin>
More information about the llvm-commits
mailing list