Index: lib/Transforms/Utils/MetaRenamer.cpp =================================================================== --- lib/Transforms/Utils/MetaRenamer.cpp +++ 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(); AU.setPreservesAll(); } @@ -110,9 +112,15 @@ } // Rename all functions + const TargetLibraryInfo &TLI = + getAnalysis().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. Index: test/Transforms/MetaRenamer/metarenamer.ll =================================================================== --- test/Transforms/MetaRenamer/metarenamer.ll +++ 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 +}