Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SimplifyLibCalls: Use default globals address space when building new global strings. #118729

Merged
merged 4 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Replace explicit address space arguments with Type*
  • Loading branch information
resistor committed Dec 5, 2024
commit c38738c5e676c9cf59338037b6c84500d1349ea4
43 changes: 20 additions & 23 deletions llvm/include/llvm/Transforms/Utils/BuildLibCalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,37 +246,34 @@ namespace llvm {
const DataLayout &DL, const TargetLibraryInfo *TLI);

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

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

/// Emit a call to the hot/cold operator new function.
Value *emitHotColdNew(Value *Num, IRBuilderBase &B,
Value *emitHotColdNew(Type *RetTy, Value *Num, IRBuilderBase &B,
const TargetLibraryInfo *TLI, LibFunc NewFunc,
uint8_t HotCold, unsigned AddrSpace);
Value *emitHotColdNewNoThrow(Value *Num, Value *NoThrow, IRBuilderBase &B,
const TargetLibraryInfo *TLI, LibFunc NewFunc,
uint8_t HotCold, unsigned AddrSpace);
Value *emitHotColdNewAligned(Value *Num, Value *Align, IRBuilderBase &B,
const TargetLibraryInfo *TLI, LibFunc NewFunc,
uint8_t HotCold, unsigned AddrSpace);
Value *emitHotColdNewAlignedNoThrow(Value *Num, Value *Align, Value *NoThrow,
IRBuilderBase &B,
uint8_t HotCold);
Value *emitHotColdNewNoThrow(Type *RetTy, Value *Num, Value *NoThrow,
IRBuilderBase &B, const TargetLibraryInfo *TLI,
LibFunc NewFunc, uint8_t HotCold);
Value *emitHotColdNewAligned(Type *RetTy, Value *Num, Value *Align,
IRBuilderBase &B, const TargetLibraryInfo *TLI,
LibFunc NewFunc, uint8_t HotCold);
Value *emitHotColdNewAlignedNoThrow(Type *RetTy, Value *Num, Value *Align,
Value *NoThrow, IRBuilderBase &B,
const TargetLibraryInfo *TLI,
LibFunc NewFunc, uint8_t HotCold,
unsigned AddrSpace);
Value *emitHotColdSizeReturningNew(Value *Num, IRBuilderBase &B,
LibFunc NewFunc, uint8_t HotCold);
Value *emitHotColdSizeReturningNew(Type *RetTy, Value *Num, IRBuilderBase &B,
const TargetLibraryInfo *TLI,
LibFunc NewFunc, uint8_t HotCold,
unsigned AddrSpace);
Value *emitHotColdSizeReturningNewAligned(Value *Num, Value *Align,
IRBuilderBase &B,
LibFunc NewFunc, uint8_t HotCold);
Value *emitHotColdSizeReturningNewAligned(Type *RetTy, Value *Num,
Value *Align, IRBuilderBase &B,
const TargetLibraryInfo *TLI,
LibFunc NewFunc, uint8_t HotCold,
unsigned AddrSpace);
LibFunc NewFunc, uint8_t HotCold);
}

#endif
5 changes: 2 additions & 3 deletions llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2014,9 +2014,8 @@ struct DSEState {
return false;
IRBuilder<> IRB(Malloc);
Type *SizeTTy = Malloc->getArgOperand(0)->getType();
auto *Calloc =
emitCalloc(ConstantInt::get(SizeTTy, 1), Malloc->getArgOperand(0), IRB,
TLI, Malloc->getType()->getPointerAddressSpace());
auto *Calloc = emitCalloc(Malloc->getType(), ConstantInt::get(SizeTTy, 1),
Malloc->getArgOperand(0), IRB, TLI);
if (!Calloc)
return false;

Expand Down
74 changes: 37 additions & 37 deletions llvm/lib/Transforms/Utils/BuildLibCalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2003,16 +2003,16 @@ Value *llvm::emitFWrite(Value *Ptr, Value *Size, Value *File, IRBuilderBase &B,
return CI;
}

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

StringRef MallocName = TLI->getName(LibFunc_malloc);
Type *SizeTTy = getSizeTTy(B, TLI);
FunctionCallee Malloc = getOrInsertLibFunc(M, *TLI, LibFunc_malloc,
B.getPtrTy(AddrSpace), SizeTTy);
FunctionCallee Malloc =
getOrInsertLibFunc(M, *TLI, LibFunc_malloc, RetTy, SizeTTy);
inferNonMandatoryLibFuncAttrs(M, MallocName, *TLI);
CallInst *CI = B.CreateCall(Malloc, Num, MallocName);

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

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

StringRef CallocName = TLI.getName(LibFunc_calloc);
Type *SizeTTy = getSizeTTy(B, &TLI);
FunctionCallee Calloc = getOrInsertLibFunc(
M, TLI, LibFunc_calloc, B.getPtrTy(AddrSpace), SizeTTy, SizeTTy);
FunctionCallee Calloc =
getOrInsertLibFunc(M, TLI, LibFunc_calloc, RetTy, SizeTTy, SizeTTy);
inferNonMandatoryLibFuncAttrs(M, CallocName, TLI);
CallInst *CI = B.CreateCall(Calloc, {Num, Size}, CallocName);

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

Value *llvm::emitHotColdSizeReturningNew(Value *Num, IRBuilderBase &B,
Value *llvm::emitHotColdSizeReturningNew(Type *RetTy, Value *Num,
IRBuilderBase &B,
const TargetLibraryInfo *TLI,
LibFunc SizeFeedbackNewFunc,
uint8_t HotCold, unsigned AddrSpace) {
uint8_t HotCold) {
Module *M = B.GetInsertBlock()->getModule();
if (!isLibFuncEmittable(M, TLI, SizeFeedbackNewFunc))
return nullptr;
Expand All @@ -2055,7 +2056,7 @@ Value *llvm::emitHotColdSizeReturningNew(Value *Num, IRBuilderBase &B,

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

Value *llvm::emitHotColdSizeReturningNewAligned(
Value *Num, Value *Align, IRBuilderBase &B, const TargetLibraryInfo *TLI,
LibFunc SizeFeedbackNewFunc, uint8_t HotCold, unsigned AddrSpace) {
Value *llvm::emitHotColdSizeReturningNewAligned(Type *RetTy, Value *Num,
Value *Align, IRBuilderBase &B,
const TargetLibraryInfo *TLI,
LibFunc SizeFeedbackNewFunc,
uint8_t HotCold) {
Module *M = B.GetInsertBlock()->getModule();
if (!isLibFuncEmittable(M, TLI, SizeFeedbackNewFunc))
return nullptr;
Expand All @@ -2078,7 +2081,7 @@ Value *llvm::emitHotColdSizeReturningNewAligned(

// __sized_ptr_t struct return type { void*, size_t }
StructType *SizedPtrT =
StructType::get(M->getContext(), {B.getPtrTy(AddrSpace), Num->getType()});
StructType::get(M->getContext(), {RetTy, Num->getType()});
FunctionCallee Func = M->getOrInsertFunction(Name, SizedPtrT, Num->getType(),
Align->getType(), B.getInt8Ty());
inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
Expand All @@ -2091,16 +2094,16 @@ Value *llvm::emitHotColdSizeReturningNewAligned(
return CI;
}

Value *llvm::emitHotColdNew(Value *Num, IRBuilderBase &B,
Value *llvm::emitHotColdNew(Type *RetTy, Value *Num, IRBuilderBase &B,
const TargetLibraryInfo *TLI, LibFunc NewFunc,
uint8_t HotCold, unsigned AddrSpace) {
uint8_t HotCold) {
Module *M = B.GetInsertBlock()->getModule();
if (!isLibFuncEmittable(M, TLI, NewFunc))
return nullptr;

StringRef Name = TLI->getName(NewFunc);
FunctionCallee Func = M->getOrInsertFunction(Name, B.getPtrTy(AddrSpace),
Num->getType(), B.getInt8Ty());
FunctionCallee Func =
M->getOrInsertFunction(Name, RetTy, Num->getType(), B.getInt8Ty());
inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
CallInst *CI = B.CreateCall(Func, {Num, B.getInt8(HotCold)}, Name);

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

Value *llvm::emitHotColdNewNoThrow(Value *Num, Value *NoThrow, IRBuilderBase &B,
Value *llvm::emitHotColdNewNoThrow(Type *RetTy, Value *Num, Value *NoThrow,
IRBuilderBase &B,
const TargetLibraryInfo *TLI,
LibFunc NewFunc, uint8_t HotCold,
unsigned AddrSpace) {
LibFunc NewFunc, uint8_t HotCold) {
Module *M = B.GetInsertBlock()->getModule();
if (!isLibFuncEmittable(M, TLI, NewFunc))
return nullptr;

StringRef Name = TLI->getName(NewFunc);
FunctionCallee Func =
M->getOrInsertFunction(Name, B.getPtrTy(AddrSpace), Num->getType(),
NoThrow->getType(), B.getInt8Ty());
FunctionCallee Func = M->getOrInsertFunction(
Name, RetTy, Num->getType(), NoThrow->getType(), B.getInt8Ty());
inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
CallInst *CI = B.CreateCall(Func, {Num, NoThrow, B.getInt8(HotCold)}, Name);

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

Value *llvm::emitHotColdNewAligned(Value *Num, Value *Align, IRBuilderBase &B,
Value *llvm::emitHotColdNewAligned(Type *RetTy, Value *Num, Value *Align,
IRBuilderBase &B,
const TargetLibraryInfo *TLI,
LibFunc NewFunc, uint8_t HotCold,
unsigned AddrSpace) {
LibFunc NewFunc, uint8_t HotCold) {
Module *M = B.GetInsertBlock()->getModule();
if (!isLibFuncEmittable(M, TLI, NewFunc))
return nullptr;

StringRef Name = TLI->getName(NewFunc);
FunctionCallee Func =
M->getOrInsertFunction(Name, B.getPtrTy(AddrSpace), Num->getType(),
Align->getType(), B.getInt8Ty());
FunctionCallee Func = M->getOrInsertFunction(Name, RetTy, Num->getType(),
Align->getType(), B.getInt8Ty());
inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
CallInst *CI = B.CreateCall(Func, {Num, Align, B.getInt8(HotCold)}, Name);

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

Value *llvm::emitHotColdNewAlignedNoThrow(Value *Num, Value *Align,
Value *llvm::emitHotColdNewAlignedNoThrow(Type *RetTy, Value *Num, Value *Align,
Value *NoThrow, IRBuilderBase &B,
const TargetLibraryInfo *TLI,
LibFunc NewFunc, uint8_t HotCold,
unsigned AddrSpace) {
LibFunc NewFunc, uint8_t HotCold) {
Module *M = B.GetInsertBlock()->getModule();
if (!isLibFuncEmittable(M, TLI, NewFunc))
return nullptr;

StringRef Name = TLI->getName(NewFunc);
FunctionCallee Func = M->getOrInsertFunction(
Name, B.getPtrTy(AddrSpace), Num->getType(), Align->getType(),
NoThrow->getType(), B.getInt8Ty());
FunctionCallee Func =
M->getOrInsertFunction(Name, RetTy, Num->getType(), Align->getType(),
NoThrow->getType(), B.getInt8Ty());
inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
CallInst *CI =
B.CreateCall(Func, {Num, Align, NoThrow, B.getInt8(HotCold)}, Name);
Expand Down
Loading
Loading