mirror of
https://github.com/RPCSX/llvm.git
synced 2025-02-02 18:42:36 +00:00
[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
This commit is contained in:
parent
261eb1f850
commit
69af69a8ff
@ -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 @@ namespace {
|
||||
}
|
||||
|
||||
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
||||
AU.addRequired<TargetLibraryInfoWrapperPass>();
|
||||
AU.setPreservesAll();
|
||||
}
|
||||
|
||||
@ -110,9 +112,15 @@ namespace {
|
||||
}
|
||||
|
||||
// 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 @@ namespace {
|
||||
}
|
||||
|
||||
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.
|
||||
|
@ -96,3 +96,18 @@ define i32 @varargs_func_6_xxx(i32 %arg_1_xxx, i32 %arg_2_xxx, ...) nounwind uwt
|
||||
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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user