Skip to content

[LLVM] Make more use of IRBuilder::CreateIntrinsic. NFC. #112546

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

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 1 addition & 2 deletions llvm/lib/CodeGen/SafeStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,7 @@ Value *SafeStack::getStackGuard(IRBuilder<> &IRB, Function &F) {

if (!StackGuardVar) {
TL.insertSSPDeclarations(*M);
return IRB.CreateCall(
Intrinsic::getOrInsertDeclaration(M, Intrinsic::stackguard));
return IRB.CreateIntrinsic(Intrinsic::stackguard, {}, {});
}

return IRB.CreateLoad(StackPtrTy, StackGuardVar, "StackGuard");
Expand Down
6 changes: 2 additions & 4 deletions llvm/lib/CodeGen/StackProtector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,7 @@ static Value *getStackGuard(const TargetLoweringBase *TLI, Module *M,
if (SupportsSelectionDAGSP)
*SupportsSelectionDAGSP = true;
TLI->insertSSPDeclarations(*M);
return B.CreateCall(
Intrinsic::getOrInsertDeclaration(M, Intrinsic::stackguard));
return B.CreateIntrinsic(Intrinsic::stackguard, {}, {});
}

/// Insert code into the entry block that stores the stack guard
Expand All @@ -541,8 +540,7 @@ static bool CreatePrologue(Function *F, Module *M, Instruction *CheckLoc,
AI = B.CreateAlloca(PtrTy, nullptr, "StackGuardSlot");

Value *GuardSlot = getStackGuard(TLI, M, B, &SupportsSelectionDAGSP);
B.CreateCall(Intrinsic::getOrInsertDeclaration(M, Intrinsic::stackprotector),
{GuardSlot, AI});
B.CreateIntrinsic(Intrinsic::stackprotector, {}, {GuardSlot, AI});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we could use an overload where we do not need to specify Types or RetTy (for non-overloaded intrinsics).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, there could certainly be more useful overloads, and maybe more default arguments. But I didn't really want to do that in this patch.

return SupportsSelectionDAGSP;
}

Expand Down
150 changes: 55 additions & 95 deletions llvm/lib/IR/AutoUpgrade.cpp

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27284,8 +27284,7 @@ Value *AArch64TargetLowering::emitLoadLinked(IRBuilderBase &Builder,
void AArch64TargetLowering::emitAtomicCmpXchgNoStoreLLBalance(
IRBuilderBase &Builder) const {
Module *M = Builder.GetInsertBlock()->getParent()->getParent();
Builder.CreateCall(
Intrinsic::getOrInsertDeclaration(M, Intrinsic::aarch64_clrex));
Builder.CreateIntrinsic(Intrinsic::aarch64_clrex, {}, {});
}

Value *AArch64TargetLowering::emitStoreConditional(IRBuilderBase &Builder,
Expand Down
5 changes: 2 additions & 3 deletions llvm/lib/Target/AMDGPU/AMDGPUSwLowerLDS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -921,9 +921,8 @@ void AMDGPUSwLowerLDS::lowerKernelLDSAccesses(Function *Func,
FunctionCallee AsanFreeFunc = M.getOrInsertFunction(
StringRef("__asan_free_impl"),
FunctionType::get(IRB.getVoidTy(), {Int64Ty, Int64Ty}, false));
Value *ReturnAddr = IRB.CreateCall(
Intrinsic::getOrInsertDeclaration(&M, Intrinsic::returnaddress),
IRB.getInt32(0));
Value *ReturnAddr =
IRB.CreateIntrinsic(Intrinsic::returnaddress, {}, IRB.getInt32(0));
Value *RAPToInt = IRB.CreatePtrToInt(ReturnAddr, Int64Ty);
Value *MallocPtrToInt = IRB.CreatePtrToInt(LoadMallocPtr, Int64Ty);
IRB.CreateCall(AsanFreeFunc, {MallocPtrToInt, RAPToInt});
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Target/ARM/ARMISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21446,8 +21446,7 @@ void ARMTargetLowering::emitAtomicCmpXchgNoStoreLLBalance(
if (!Subtarget->hasV7Ops())
return;
Module *M = Builder.GetInsertBlock()->getParent()->getParent();
Builder.CreateCall(
Intrinsic::getOrInsertDeclaration(M, Intrinsic::arm_clrex));
Builder.CreateIntrinsic(Intrinsic::arm_clrex, {}, {});
}

Value *ARMTargetLowering::emitStoreConditional(IRBuilderBase &Builder,
Expand Down
7 changes: 2 additions & 5 deletions llvm/lib/Target/PowerPC/PPCISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12205,11 +12205,8 @@ Instruction *PPCTargetLowering::emitTrailingFence(IRBuilderBase &Builder,
// http://www.rdrop.com/users/paulmck/scalability/paper/N2745r.2011.03.04a.html
// and http://www.cl.cam.ac.uk/~pes20/cppppc/ for justification.
if (isa<LoadInst>(Inst))
return Builder.CreateCall(
Intrinsic::getOrInsertDeclaration(
Builder.GetInsertBlock()->getParent()->getParent(),
Intrinsic::ppc_cfence, {Inst->getType()}),
{Inst});
return Builder.CreateIntrinsic(Intrinsic::ppc_cfence, {Inst->getType()},
{Inst});
// FIXME: Can use isync for rmw operation.
return callIntrinsic(Builder, Intrinsic::ppc_lwsync);
}
Expand Down
21 changes: 7 additions & 14 deletions llvm/lib/Target/X86/X86WinEHState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,12 +333,10 @@ void WinEHStatePass::emitExceptionRegistrationRecord(Function *F) {
// If using _except_handler4, the EHGuard contains: FramePtr xor Cookie.
if (UseStackGuard) {
Value *Val = Builder.CreateLoad(Int32Ty, Cookie);
Value *FrameAddr = Builder.CreateCall(
Intrinsic::getOrInsertDeclaration(
TheModule, Intrinsic::frameaddress,
Builder.getPtrTy(
TheModule->getDataLayout().getAllocaAddrSpace())),
Builder.getInt32(0), "frameaddr");
Value *FrameAddr = Builder.CreateIntrinsic(
Intrinsic::frameaddress,
Builder.getPtrTy(TheModule->getDataLayout().getAllocaAddrSpace()),
Builder.getInt32(0), /*FMFSource=*/nullptr, "frameaddr");
Value *FrameAddrI32 = Builder.CreatePtrToInt(FrameAddr, Int32Ty);
FrameAddrI32 = Builder.CreateXor(FrameAddrI32, Val);
Builder.CreateStore(FrameAddrI32, EHGuardNode);
Expand Down Expand Up @@ -369,8 +367,7 @@ void WinEHStatePass::emitExceptionRegistrationRecord(Function *F) {
}

Value *WinEHStatePass::emitEHLSDA(IRBuilder<> &Builder, Function *F) {
return Builder.CreateCall(
Intrinsic::getOrInsertDeclaration(TheModule, Intrinsic::x86_seh_lsda), F);
return Builder.CreateIntrinsic(Intrinsic::x86_seh_lsda, {}, F);
}

/// Generate a thunk that puts the LSDA of ParentFunc in EAX and then calls
Expand Down Expand Up @@ -624,17 +621,13 @@ void WinEHStatePass::addStateStores(Function &F, WinEHFuncInfo &FuncInfo) {
// that it can recover the original frame pointer.
IRBuilder<> Builder(RegNode->getNextNode());
Value *RegNodeI8 = Builder.CreateBitCast(RegNode, Builder.getPtrTy());
Builder.CreateCall(Intrinsic::getOrInsertDeclaration(
TheModule, Intrinsic::x86_seh_ehregnode),
{RegNodeI8});
Builder.CreateIntrinsic(Intrinsic::x86_seh_ehregnode, {}, {RegNodeI8});

if (EHGuardNode) {
IRBuilder<> Builder(EHGuardNode->getNextNode());
Value *EHGuardNodeI8 =
Builder.CreateBitCast(EHGuardNode, Builder.getPtrTy());
Builder.CreateCall(Intrinsic::getOrInsertDeclaration(
TheModule, Intrinsic::x86_seh_ehguard),
{EHGuardNodeI8});
Builder.CreateIntrinsic(Intrinsic::x86_seh_ehguard, {}, {EHGuardNodeI8});
}

// Calculate state numbers.
Expand Down
7 changes: 3 additions & 4 deletions llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1866,10 +1866,9 @@ void AddressSanitizer::instrumentAddress(Instruction *OrigIns,
if (UseCalls && ClOptimizeCallbacks) {
const ASanAccessInfo AccessInfo(IsWrite, CompileKernel, AccessSizeIndex);
Module *M = IRB.GetInsertBlock()->getParent()->getParent();
IRB.CreateCall(
Intrinsic::getOrInsertDeclaration(M, Intrinsic::asan_check_memaccess),
{IRB.CreatePointerCast(Addr, PtrTy),
ConstantInt::get(Int32Ty, AccessInfo.Packed)});
IRB.CreateIntrinsic(Intrinsic::asan_check_memaccess, {},
{IRB.CreatePointerCast(Addr, PtrTy),
ConstantInt::get(Int32Ty, AccessInfo.Packed)});
return;
}

Expand Down
19 changes: 9 additions & 10 deletions llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1041,19 +1041,18 @@ void HWAddressSanitizer::instrumentMemAccessOutline(Value *Ptr, bool IsWrite,
}

if (UseFixedShadowIntrinsic) {
IRB.CreateCall(
Intrinsic::getOrInsertDeclaration(
M, UseShortGranules
? Intrinsic::hwasan_check_memaccess_shortgranules_fixedshadow
: Intrinsic::hwasan_check_memaccess_fixedshadow),
IRB.CreateIntrinsic(
UseShortGranules
? Intrinsic::hwasan_check_memaccess_shortgranules_fixedshadow
: Intrinsic::hwasan_check_memaccess_fixedshadow,
{},
{Ptr, ConstantInt::get(Int32Ty, AccessInfo),
ConstantInt::get(Int64Ty, Mapping.offset())});
} else {
IRB.CreateCall(Intrinsic::getOrInsertDeclaration(
M, UseShortGranules
? Intrinsic::hwasan_check_memaccess_shortgranules
: Intrinsic::hwasan_check_memaccess),
{ShadowBase, Ptr, ConstantInt::get(Int32Ty, AccessInfo)});
IRB.CreateIntrinsic(
UseShortGranules ? Intrinsic::hwasan_check_memaccess_shortgranules
: Intrinsic::hwasan_check_memaccess,
{}, {ShadowBase, Ptr, ConstantInt::get(Int32Ty, AccessInfo)});
}
}

Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Transforms/Instrumentation/KCFI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ PreservedAnalyses KCFIPass::run(Function &F, FunctionAnalysisManager &AM) {
Instruction *ThenTerm =
SplitBlockAndInsertIfThen(Test, Call, false, VeryUnlikelyWeights);
Builder.SetInsertPoint(ThenTerm);
Builder.CreateCall(
Intrinsic::getOrInsertDeclaration(&M, Intrinsic::debugtrap));
Builder.CreateIntrinsic(Intrinsic::debugtrap, {}, {});
++NumKCFIChecks;
}

Expand Down
32 changes: 16 additions & 16 deletions llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -918,8 +918,8 @@ void FunctionInstrumenter::instrument() {
IRBuilder<> Builder(&EntryBB, EntryBB.getFirstInsertionPt());
// llvm.instrprof.cover(i8* <name>, i64 <hash>, i32 <num-counters>,
// i32 <index>)
Builder.CreateCall(
Intrinsic::getOrInsertDeclaration(&M, Intrinsic::instrprof_cover),
Builder.CreateIntrinsic(
Intrinsic::instrprof_cover, {},
{NormalizedNamePtr, CFGHash, Builder.getInt32(1), Builder.getInt32(0)});
return;
}
Expand Down Expand Up @@ -971,10 +971,10 @@ void FunctionInstrumenter::instrument() {
IRBuilder<> Builder(&EntryBB, EntryBB.getFirstInsertionPt());
// llvm.instrprof.timestamp(i8* <name>, i64 <hash>, i32 <num-counters>,
// i32 <index>)
Builder.CreateCall(
Intrinsic::getOrInsertDeclaration(&M, Intrinsic::instrprof_timestamp),
{NormalizedNamePtr, CFGHash, Builder.getInt32(NumCounters),
Builder.getInt32(I)});
Builder.CreateIntrinsic(Intrinsic::instrprof_timestamp, {},
{NormalizedNamePtr, CFGHash,
Builder.getInt32(NumCounters),
Builder.getInt32(I)});
I += PGOBlockCoverage ? 8 : 1;
}

Expand All @@ -984,12 +984,12 @@ void FunctionInstrumenter::instrument() {
"Cannot get the Instrumentation point");
// llvm.instrprof.increment(i8* <name>, i64 <hash>, i32 <num-counters>,
// i32 <index>)
Builder.CreateCall(Intrinsic::getOrInsertDeclaration(
&M, PGOBlockCoverage
? Intrinsic::instrprof_cover
: Intrinsic::instrprof_increment),
{NormalizedNamePtr, CFGHash,
Builder.getInt32(NumCounters), Builder.getInt32(I++)});
Builder.CreateIntrinsic(PGOBlockCoverage ? Intrinsic::instrprof_cover
: Intrinsic::instrprof_increment,
{},
{NormalizedNamePtr, CFGHash,
Builder.getInt32(NumCounters),
Builder.getInt32(I++)});
}

// Now instrument select instructions:
Expand Down Expand Up @@ -1726,10 +1726,10 @@ void SelectInstVisitor::instrumentOneSelectInst(SelectInst &SI) {
auto *NormalizedFuncNameVarPtr =
ConstantExpr::getPointerBitCastOrAddrSpaceCast(
FuncNameVar, PointerType::get(M->getContext(), 0));
Builder.CreateCall(
Intrinsic::getOrInsertDeclaration(M, Intrinsic::instrprof_increment_step),
{NormalizedFuncNameVarPtr, Builder.getInt64(FuncHash),
Builder.getInt32(TotalNumCtrs), Builder.getInt32(*CurCtrIdx), Step});
Builder.CreateIntrinsic(Intrinsic::instrprof_increment_step, {},
{NormalizedFuncNameVarPtr, Builder.getInt64(FuncHash),
Builder.getInt32(TotalNumCtrs),
Builder.getInt32(*CurCtrIdx), Step});
++(*CurCtrIdx);
}

Expand Down
4 changes: 1 addition & 3 deletions llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,9 +572,7 @@ bool ThreadSanitizer::sanitizeFunction(Function &F,
if ((Res || HasCalls) && ClInstrumentFuncEntryExit) {
InstrumentationIRBuilder IRB(F.getEntryBlock().getFirstNonPHI());
Value *ReturnAddress =
IRB.CreateCall(Intrinsic::getOrInsertDeclaration(
F.getParent(), Intrinsic::returnaddress),
IRB.getInt32(0));
IRB.CreateIntrinsic(Intrinsic::returnaddress, {}, IRB.getInt32(0));
IRB.CreateCall(TsanFuncEntry, ReturnAddress);

EscapeEnumerator EE(F, "tsan_cleanup", ClHandleCxxExceptions);
Expand Down
Loading