llvm.org GIT mirror llvm / 69af69a
[MetaRenamer] Don't rename library functions. Library functions can have specific semantics that affect the behavior of certain passes. DSE, for instance, gives special treatment to malloc-ed pointers but not to pointers returned from an equivalently typed (but differently named) function. MetaRenamer ought not to alter program semantics, so library functions must remain untouched. Reviewers: mehdi_amini, majnemer, chandlerc, davide Reviewed By: davide Subscribers: davide, llvm-commits Differential Revision: https://reviews.llvm.org/D31304 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298659 91177308-0d34-0410-b5e6-96231b3b80d8 Bryant Wong 2 years ago
2 changed file(s) with 29 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
1515 #include "llvm/Transforms/IPO.h"
1616 #include "llvm/ADT/STLExtras.h"
1717 #include "llvm/ADT/SmallString.h"
18 #include "llvm/Analysis/TargetLibraryInfo.h"
1819 #include "llvm/IR/DerivedTypes.h"
1920 #include "llvm/IR/Function.h"
2021 #include "llvm/IR/Module.h"
6667 }
6768
6869 void getAnalysisUsage(AnalysisUsage &AU) const override {
70 AU.addRequired();
6971 AU.setPreservesAll();
7072 }
7173
109111 }
110112
111113 // Rename all functions
114 const TargetLibraryInfo &TLI =
115 getAnalysis().getTLI();
112116 for (auto &F : M) {
113117 StringRef Name = F.getName();
114 if (Name.startswith("llvm.") || (!Name.empty() && Name[0] == 1))
118 LibFunc Tmp;
119 // Leave library functions alone because their presence or absence could
120 // affect the behavior of other passes.
121 if (Name.startswith("llvm.") || (!Name.empty() && Name[0] == 1) ||
122 TLI.getLibFunc(F, Tmp))
115123 continue;
116124
117125 F.setName(renamer.newName());
138146 }
139147
140148 char MetaRenamer::ID = 0;
141 INITIALIZE_PASS(MetaRenamer, "metarenamer",
142 "Assign new names to everything", false, false)
149 INITIALIZE_PASS_BEGIN(MetaRenamer, "metarenamer",
150 "Assign new names to everything", false, false)
151 INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
152 INITIALIZE_PASS_END(MetaRenamer, "metarenamer",
153 "Assign new names to everything", false, false)
143154 //===----------------------------------------------------------------------===//
144155 //
145156 // MetaRenamer - Rename everything with metasyntactic names.
9595 store i32 %arg_2_xxx, i32* %2, align 4
9696 ret i32 6
9797 }
98
99 declare noalias i8* @malloc(i32)
100 declare void @free(i8* nocapture)
101
102 define void @dont_rename_lib_funcs() {
103 ; CHECK-LABEL: @foo(
104 ; CHECK-NEXT: bb:
105 ; CHECK-NEXT: [[TMP:%.*]] = call i8* @malloc(i32 23)
106 ; CHECK-NEXT: call void @free(i8* [[TMP]])
107 ; CHECK-NEXT: ret void
108 ;
109 %x = call i8* @malloc(i32 23)
110 call void @free(i8* %x)
111 ret void
112 }