Skip to content

Commit c38738c

Browse files
committed
Replace explicit address space arguments with Type*
1 parent d10a03d commit c38738c

File tree

4 files changed

+105
-127
lines changed

4 files changed

+105
-127
lines changed

llvm/include/llvm/Transforms/Utils/BuildLibCalls.h

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -246,37 +246,34 @@ namespace llvm {
246246
const DataLayout &DL, const TargetLibraryInfo *TLI);
247247

248248
/// Emit a call to the malloc function.
249-
Value *emitMalloc(Value *Num, IRBuilderBase &B, const DataLayout &DL,
250-
const TargetLibraryInfo *TLI, unsigned AddrSpace);
249+
Value *emitMalloc(Type *RetTy, Value *Num, IRBuilderBase &B,
250+
const DataLayout &DL, const TargetLibraryInfo *TLI);
251251

252252
/// Emit a call to the calloc function.
253-
Value *emitCalloc(Value *Num, Value *Size, IRBuilderBase &B,
254-
const TargetLibraryInfo &TLI, unsigned AddrSpace);
253+
Value *emitCalloc(Type *RetTy, Value *Num, Value *Size, IRBuilderBase &B,
254+
const TargetLibraryInfo &TLI);
255255

256256
/// Emit a call to the hot/cold operator new function.
257-
Value *emitHotColdNew(Value *Num, IRBuilderBase &B,
257+
Value *emitHotColdNew(Type *RetTy, Value *Num, IRBuilderBase &B,
258258
const TargetLibraryInfo *TLI, LibFunc NewFunc,
259-
uint8_t HotCold, unsigned AddrSpace);
260-
Value *emitHotColdNewNoThrow(Value *Num, Value *NoThrow, IRBuilderBase &B,
261-
const TargetLibraryInfo *TLI, LibFunc NewFunc,
262-
uint8_t HotCold, unsigned AddrSpace);
263-
Value *emitHotColdNewAligned(Value *Num, Value *Align, IRBuilderBase &B,
264-
const TargetLibraryInfo *TLI, LibFunc NewFunc,
265-
uint8_t HotCold, unsigned AddrSpace);
266-
Value *emitHotColdNewAlignedNoThrow(Value *Num, Value *Align, Value *NoThrow,
267-
IRBuilderBase &B,
259+
uint8_t HotCold);
260+
Value *emitHotColdNewNoThrow(Type *RetTy, Value *Num, Value *NoThrow,
261+
IRBuilderBase &B, const TargetLibraryInfo *TLI,
262+
LibFunc NewFunc, uint8_t HotCold);
263+
Value *emitHotColdNewAligned(Type *RetTy, Value *Num, Value *Align,
264+
IRBuilderBase &B, const TargetLibraryInfo *TLI,
265+
LibFunc NewFunc, uint8_t HotCold);
266+
Value *emitHotColdNewAlignedNoThrow(Type *RetTy, Value *Num, Value *Align,
267+
Value *NoThrow, IRBuilderBase &B,
268268
const TargetLibraryInfo *TLI,
269-
LibFunc NewFunc, uint8_t HotCold,
270-
unsigned AddrSpace);
271-
Value *emitHotColdSizeReturningNew(Value *Num, IRBuilderBase &B,
269+
LibFunc NewFunc, uint8_t HotCold);
270+
Value *emitHotColdSizeReturningNew(Type *RetTy, Value *Num, IRBuilderBase &B,
272271
const TargetLibraryInfo *TLI,
273-
LibFunc NewFunc, uint8_t HotCold,
274-
unsigned AddrSpace);
275-
Value *emitHotColdSizeReturningNewAligned(Value *Num, Value *Align,
276-
IRBuilderBase &B,
272+
LibFunc NewFunc, uint8_t HotCold);
273+
Value *emitHotColdSizeReturningNewAligned(Type *RetTy, Value *Num,
274+
Value *Align, IRBuilderBase &B,
277275
const TargetLibraryInfo *TLI,
278-
LibFunc NewFunc, uint8_t HotCold,
279-
unsigned AddrSpace);
276+
LibFunc NewFunc, uint8_t HotCold);
280277
}
281278

282279
#endif

llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,9 +2014,8 @@ struct DSEState {
20142014
return false;
20152015
IRBuilder<> IRB(Malloc);
20162016
Type *SizeTTy = Malloc->getArgOperand(0)->getType();
2017-
auto *Calloc =
2018-
emitCalloc(ConstantInt::get(SizeTTy, 1), Malloc->getArgOperand(0), IRB,
2019-
TLI, Malloc->getType()->getPointerAddressSpace());
2017+
auto *Calloc = emitCalloc(Malloc->getType(), ConstantInt::get(SizeTTy, 1),
2018+
Malloc->getArgOperand(0), IRB, TLI);
20202019
if (!Calloc)
20212020
return false;
20222021

llvm/lib/Transforms/Utils/BuildLibCalls.cpp

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2003,16 +2003,16 @@ Value *llvm::emitFWrite(Value *Ptr, Value *Size, Value *File, IRBuilderBase &B,
20032003
return CI;
20042004
}
20052005

2006-
Value *llvm::emitMalloc(Value *Num, IRBuilderBase &B, const DataLayout &DL,
2007-
const TargetLibraryInfo *TLI, unsigned AddrSpace) {
2006+
Value *llvm::emitMalloc(Type *RetTy, Value *Num, IRBuilderBase &B,
2007+
const DataLayout &DL, const TargetLibraryInfo *TLI) {
20082008
Module *M = B.GetInsertBlock()->getModule();
20092009
if (!isLibFuncEmittable(M, TLI, LibFunc_malloc))
20102010
return nullptr;
20112011

20122012
StringRef MallocName = TLI->getName(LibFunc_malloc);
20132013
Type *SizeTTy = getSizeTTy(B, TLI);
2014-
FunctionCallee Malloc = getOrInsertLibFunc(M, *TLI, LibFunc_malloc,
2015-
B.getPtrTy(AddrSpace), SizeTTy);
2014+
FunctionCallee Malloc =
2015+
getOrInsertLibFunc(M, *TLI, LibFunc_malloc, RetTy, SizeTTy);
20162016
inferNonMandatoryLibFuncAttrs(M, MallocName, *TLI);
20172017
CallInst *CI = B.CreateCall(Malloc, Num, MallocName);
20182018

@@ -2023,16 +2023,16 @@ Value *llvm::emitMalloc(Value *Num, IRBuilderBase &B, const DataLayout &DL,
20232023
return CI;
20242024
}
20252025

2026-
Value *llvm::emitCalloc(Value *Num, Value *Size, IRBuilderBase &B,
2027-
const TargetLibraryInfo &TLI, unsigned AddrSpace) {
2026+
Value *llvm::emitCalloc(Type *RetTy, Value *Num, Value *Size, IRBuilderBase &B,
2027+
const TargetLibraryInfo &TLI) {
20282028
Module *M = B.GetInsertBlock()->getModule();
20292029
if (!isLibFuncEmittable(M, &TLI, LibFunc_calloc))
20302030
return nullptr;
20312031

20322032
StringRef CallocName = TLI.getName(LibFunc_calloc);
20332033
Type *SizeTTy = getSizeTTy(B, &TLI);
2034-
FunctionCallee Calloc = getOrInsertLibFunc(
2035-
M, TLI, LibFunc_calloc, B.getPtrTy(AddrSpace), SizeTTy, SizeTTy);
2034+
FunctionCallee Calloc =
2035+
getOrInsertLibFunc(M, TLI, LibFunc_calloc, RetTy, SizeTTy, SizeTTy);
20362036
inferNonMandatoryLibFuncAttrs(M, CallocName, TLI);
20372037
CallInst *CI = B.CreateCall(Calloc, {Num, Size}, CallocName);
20382038

@@ -2043,10 +2043,11 @@ Value *llvm::emitCalloc(Value *Num, Value *Size, IRBuilderBase &B,
20432043
return CI;
20442044
}
20452045

2046-
Value *llvm::emitHotColdSizeReturningNew(Value *Num, IRBuilderBase &B,
2046+
Value *llvm::emitHotColdSizeReturningNew(Type *RetTy, Value *Num,
2047+
IRBuilderBase &B,
20472048
const TargetLibraryInfo *TLI,
20482049
LibFunc SizeFeedbackNewFunc,
2049-
uint8_t HotCold, unsigned AddrSpace) {
2050+
uint8_t HotCold) {
20502051
Module *M = B.GetInsertBlock()->getModule();
20512052
if (!isLibFuncEmittable(M, TLI, SizeFeedbackNewFunc))
20522053
return nullptr;
@@ -2055,7 +2056,7 @@ Value *llvm::emitHotColdSizeReturningNew(Value *Num, IRBuilderBase &B,
20552056

20562057
// __sized_ptr_t struct return type { void*, size_t }
20572058
StructType *SizedPtrT =
2058-
StructType::get(M->getContext(), {B.getPtrTy(AddrSpace), Num->getType()});
2059+
StructType::get(M->getContext(), {RetTy, Num->getType()});
20592060
FunctionCallee Func =
20602061
M->getOrInsertFunction(Name, SizedPtrT, Num->getType(), B.getInt8Ty());
20612062
inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
@@ -2067,9 +2068,11 @@ Value *llvm::emitHotColdSizeReturningNew(Value *Num, IRBuilderBase &B,
20672068
return CI;
20682069
}
20692070

2070-
Value *llvm::emitHotColdSizeReturningNewAligned(
2071-
Value *Num, Value *Align, IRBuilderBase &B, const TargetLibraryInfo *TLI,
2072-
LibFunc SizeFeedbackNewFunc, uint8_t HotCold, unsigned AddrSpace) {
2071+
Value *llvm::emitHotColdSizeReturningNewAligned(Type *RetTy, Value *Num,
2072+
Value *Align, IRBuilderBase &B,
2073+
const TargetLibraryInfo *TLI,
2074+
LibFunc SizeFeedbackNewFunc,
2075+
uint8_t HotCold) {
20732076
Module *M = B.GetInsertBlock()->getModule();
20742077
if (!isLibFuncEmittable(M, TLI, SizeFeedbackNewFunc))
20752078
return nullptr;
@@ -2078,7 +2081,7 @@ Value *llvm::emitHotColdSizeReturningNewAligned(
20782081

20792082
// __sized_ptr_t struct return type { void*, size_t }
20802083
StructType *SizedPtrT =
2081-
StructType::get(M->getContext(), {B.getPtrTy(AddrSpace), Num->getType()});
2084+
StructType::get(M->getContext(), {RetTy, Num->getType()});
20822085
FunctionCallee Func = M->getOrInsertFunction(Name, SizedPtrT, Num->getType(),
20832086
Align->getType(), B.getInt8Ty());
20842087
inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
@@ -2091,16 +2094,16 @@ Value *llvm::emitHotColdSizeReturningNewAligned(
20912094
return CI;
20922095
}
20932096

2094-
Value *llvm::emitHotColdNew(Value *Num, IRBuilderBase &B,
2097+
Value *llvm::emitHotColdNew(Type *RetTy, Value *Num, IRBuilderBase &B,
20952098
const TargetLibraryInfo *TLI, LibFunc NewFunc,
2096-
uint8_t HotCold, unsigned AddrSpace) {
2099+
uint8_t HotCold) {
20972100
Module *M = B.GetInsertBlock()->getModule();
20982101
if (!isLibFuncEmittable(M, TLI, NewFunc))
20992102
return nullptr;
21002103

21012104
StringRef Name = TLI->getName(NewFunc);
2102-
FunctionCallee Func = M->getOrInsertFunction(Name, B.getPtrTy(AddrSpace),
2103-
Num->getType(), B.getInt8Ty());
2105+
FunctionCallee Func =
2106+
M->getOrInsertFunction(Name, RetTy, Num->getType(), B.getInt8Ty());
21042107
inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
21052108
CallInst *CI = B.CreateCall(Func, {Num, B.getInt8(HotCold)}, Name);
21062109

@@ -2111,18 +2114,17 @@ Value *llvm::emitHotColdNew(Value *Num, IRBuilderBase &B,
21112114
return CI;
21122115
}
21132116

2114-
Value *llvm::emitHotColdNewNoThrow(Value *Num, Value *NoThrow, IRBuilderBase &B,
2117+
Value *llvm::emitHotColdNewNoThrow(Type *RetTy, Value *Num, Value *NoThrow,
2118+
IRBuilderBase &B,
21152119
const TargetLibraryInfo *TLI,
2116-
LibFunc NewFunc, uint8_t HotCold,
2117-
unsigned AddrSpace) {
2120+
LibFunc NewFunc, uint8_t HotCold) {
21182121
Module *M = B.GetInsertBlock()->getModule();
21192122
if (!isLibFuncEmittable(M, TLI, NewFunc))
21202123
return nullptr;
21212124

21222125
StringRef Name = TLI->getName(NewFunc);
2123-
FunctionCallee Func =
2124-
M->getOrInsertFunction(Name, B.getPtrTy(AddrSpace), Num->getType(),
2125-
NoThrow->getType(), B.getInt8Ty());
2126+
FunctionCallee Func = M->getOrInsertFunction(
2127+
Name, RetTy, Num->getType(), NoThrow->getType(), B.getInt8Ty());
21262128
inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
21272129
CallInst *CI = B.CreateCall(Func, {Num, NoThrow, B.getInt8(HotCold)}, Name);
21282130

@@ -2133,18 +2135,17 @@ Value *llvm::emitHotColdNewNoThrow(Value *Num, Value *NoThrow, IRBuilderBase &B,
21332135
return CI;
21342136
}
21352137

2136-
Value *llvm::emitHotColdNewAligned(Value *Num, Value *Align, IRBuilderBase &B,
2138+
Value *llvm::emitHotColdNewAligned(Type *RetTy, Value *Num, Value *Align,
2139+
IRBuilderBase &B,
21372140
const TargetLibraryInfo *TLI,
2138-
LibFunc NewFunc, uint8_t HotCold,
2139-
unsigned AddrSpace) {
2141+
LibFunc NewFunc, uint8_t HotCold) {
21402142
Module *M = B.GetInsertBlock()->getModule();
21412143
if (!isLibFuncEmittable(M, TLI, NewFunc))
21422144
return nullptr;
21432145

21442146
StringRef Name = TLI->getName(NewFunc);
2145-
FunctionCallee Func =
2146-
M->getOrInsertFunction(Name, B.getPtrTy(AddrSpace), Num->getType(),
2147-
Align->getType(), B.getInt8Ty());
2147+
FunctionCallee Func = M->getOrInsertFunction(Name, RetTy, Num->getType(),
2148+
Align->getType(), B.getInt8Ty());
21482149
inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
21492150
CallInst *CI = B.CreateCall(Func, {Num, Align, B.getInt8(HotCold)}, Name);
21502151

@@ -2155,19 +2156,18 @@ Value *llvm::emitHotColdNewAligned(Value *Num, Value *Align, IRBuilderBase &B,
21552156
return CI;
21562157
}
21572158

2158-
Value *llvm::emitHotColdNewAlignedNoThrow(Value *Num, Value *Align,
2159+
Value *llvm::emitHotColdNewAlignedNoThrow(Type *RetTy, Value *Num, Value *Align,
21592160
Value *NoThrow, IRBuilderBase &B,
21602161
const TargetLibraryInfo *TLI,
2161-
LibFunc NewFunc, uint8_t HotCold,
2162-
unsigned AddrSpace) {
2162+
LibFunc NewFunc, uint8_t HotCold) {
21632163
Module *M = B.GetInsertBlock()->getModule();
21642164
if (!isLibFuncEmittable(M, TLI, NewFunc))
21652165
return nullptr;
21662166

21672167
StringRef Name = TLI->getName(NewFunc);
2168-
FunctionCallee Func = M->getOrInsertFunction(
2169-
Name, B.getPtrTy(AddrSpace), Num->getType(), Align->getType(),
2170-
NoThrow->getType(), B.getInt8Ty());
2168+
FunctionCallee Func =
2169+
M->getOrInsertFunction(Name, RetTy, Num->getType(), Align->getType(),
2170+
NoThrow->getType(), B.getInt8Ty());
21712171
inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
21722172
CallInst *CI =
21732173
B.CreateCall(Func, {Num, Align, NoThrow, B.getInt8(HotCold)}, Name);

0 commit comments

Comments
 (0)