Skip to content

Commit 7ca135c

Browse files
committed
[Instrumentation] Remove unneeded pointer casts and migrate away from getInt8PtrTy. NFC
After opaque pointer migration, getInt8PtrTy() is considered legacy. Replace it with getPtrTy(), and while here, remove some unneeded pointer casts.
1 parent d0ae239 commit 7ca135c

File tree

4 files changed

+36
-48
lines changed

4 files changed

+36
-48
lines changed

llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,7 +1288,7 @@ void DataFlowSanitizer::buildExternWeakCheckIfNeeded(IRBuilder<> &IRB,
12881288
// for a extern weak function, add a check here to help identify the issue.
12891289
if (GlobalValue::isExternalWeakLinkage(F->getLinkage())) {
12901290
std::vector<Value *> Args;
1291-
Args.push_back(IRB.CreatePointerCast(F, IRB.getInt8PtrTy()));
1291+
Args.push_back(F);
12921292
Args.push_back(IRB.CreateGlobalStringPtr(F->getName()));
12931293
IRB.CreateCall(DFSanWrapperExternWeakNullFn, Args);
12941294
}
@@ -2270,8 +2270,7 @@ std::pair<Value *, Value *> DFSanFunction::loadShadowOriginSansLoadTracking(
22702270
IRBuilder<> IRB(Pos);
22712271
CallInst *Call =
22722272
IRB.CreateCall(DFS.DFSanLoadLabelAndOriginFn,
2273-
{IRB.CreatePointerCast(Addr, IRB.getInt8PtrTy()),
2274-
ConstantInt::get(DFS.IntptrTy, Size)});
2273+
{Addr, ConstantInt::get(DFS.IntptrTy, Size)});
22752274
Call->addRetAttr(Attribute::ZExt);
22762275
return {IRB.CreateTrunc(IRB.CreateLShr(Call, DFS.OriginWidthBits),
22772276
DFS.PrimitiveShadowTy),
@@ -2527,10 +2526,9 @@ void DFSanFunction::storeOrigin(Instruction *Pos, Value *Addr, uint64_t Size,
25272526
}
25282527

25292528
if (shouldInstrumentWithCall()) {
2530-
IRB.CreateCall(DFS.DFSanMaybeStoreOriginFn,
2531-
{CollapsedShadow,
2532-
IRB.CreatePointerCast(Addr, IRB.getInt8PtrTy()),
2533-
ConstantInt::get(DFS.IntptrTy, Size), Origin});
2529+
IRB.CreateCall(
2530+
DFS.DFSanMaybeStoreOriginFn,
2531+
{CollapsedShadow, Addr, ConstantInt::get(DFS.IntptrTy, Size), Origin});
25342532
} else {
25352533
Value *Cmp = convertToBool(CollapsedShadow, IRB, "_dfscmp");
25362534
DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Lazy);
@@ -2924,8 +2922,7 @@ void DFSanVisitor::visitMemTransferInst(MemTransferInst &I) {
29242922
if (DFSF.DFS.shouldTrackOrigins()) {
29252923
IRB.CreateCall(
29262924
DFSF.DFS.DFSanMemOriginTransferFn,
2927-
{IRB.CreatePointerCast(I.getArgOperand(0), IRB.getInt8PtrTy()),
2928-
IRB.CreatePointerCast(I.getArgOperand(1), IRB.getInt8PtrTy()),
2925+
{I.getArgOperand(0), I.getArgOperand(1),
29292926
IRB.CreateIntCast(I.getArgOperand(2), DFSF.DFS.IntptrTy, false)});
29302927
}
29312928

@@ -3213,10 +3210,9 @@ void DFSanVisitor::visitLibAtomicLoad(CallBase &CB) {
32133210
// TODO: Support ClCombinePointerLabelsOnLoad
32143211
// TODO: Support ClEventCallbacks
32153212

3216-
NextIRB.CreateCall(DFSF.DFS.DFSanMemShadowOriginTransferFn,
3217-
{NextIRB.CreatePointerCast(DstPtr, NextIRB.getInt8PtrTy()),
3218-
NextIRB.CreatePointerCast(SrcPtr, NextIRB.getInt8PtrTy()),
3219-
NextIRB.CreateIntCast(Size, DFSF.DFS.IntptrTy, false)});
3213+
NextIRB.CreateCall(
3214+
DFSF.DFS.DFSanMemShadowOriginTransferFn,
3215+
{DstPtr, SrcPtr, NextIRB.CreateIntCast(Size, DFSF.DFS.IntptrTy, false)});
32203216
}
32213217

32223218
Value *DFSanVisitor::makeAddReleaseOrderingTable(IRBuilder<> &IRB) {
@@ -3252,10 +3248,9 @@ void DFSanVisitor::visitLibAtomicStore(CallBase &CB) {
32523248
// TODO: Support ClCombinePointerLabelsOnStore
32533249
// TODO: Support ClEventCallbacks
32543250

3255-
IRB.CreateCall(DFSF.DFS.DFSanMemShadowOriginTransferFn,
3256-
{IRB.CreatePointerCast(DstPtr, IRB.getInt8PtrTy()),
3257-
IRB.CreatePointerCast(SrcPtr, IRB.getInt8PtrTy()),
3258-
IRB.CreateIntCast(Size, DFSF.DFS.IntptrTy, false)});
3251+
IRB.CreateCall(
3252+
DFSF.DFS.DFSanMemShadowOriginTransferFn,
3253+
{DstPtr, SrcPtr, IRB.CreateIntCast(Size, DFSF.DFS.IntptrTy, false)});
32593254
}
32603255

32613256
void DFSanVisitor::visitLibAtomicExchange(CallBase &CB) {
@@ -3273,16 +3268,14 @@ void DFSanVisitor::visitLibAtomicExchange(CallBase &CB) {
32733268
// the additional complexity to address this is not warrented.
32743269

32753270
// Current Target to Dest
3276-
IRB.CreateCall(DFSF.DFS.DFSanMemShadowOriginTransferFn,
3277-
{IRB.CreatePointerCast(DstPtr, IRB.getInt8PtrTy()),
3278-
IRB.CreatePointerCast(TargetPtr, IRB.getInt8PtrTy()),
3279-
IRB.CreateIntCast(Size, DFSF.DFS.IntptrTy, false)});
3271+
IRB.CreateCall(
3272+
DFSF.DFS.DFSanMemShadowOriginTransferFn,
3273+
{DstPtr, TargetPtr, IRB.CreateIntCast(Size, DFSF.DFS.IntptrTy, false)});
32803274

32813275
// Current Src to Target (overriding)
3282-
IRB.CreateCall(DFSF.DFS.DFSanMemShadowOriginTransferFn,
3283-
{IRB.CreatePointerCast(TargetPtr, IRB.getInt8PtrTy()),
3284-
IRB.CreatePointerCast(SrcPtr, IRB.getInt8PtrTy()),
3285-
IRB.CreateIntCast(Size, DFSF.DFS.IntptrTy, false)});
3276+
IRB.CreateCall(
3277+
DFSF.DFS.DFSanMemShadowOriginTransferFn,
3278+
{TargetPtr, SrcPtr, IRB.CreateIntCast(Size, DFSF.DFS.IntptrTy, false)});
32863279
}
32873280

32883281
void DFSanVisitor::visitLibAtomicCompareExchange(CallBase &CB) {
@@ -3305,13 +3298,10 @@ void DFSanVisitor::visitLibAtomicCompareExchange(CallBase &CB) {
33053298

33063299
// If original call returned true, copy Desired to Target.
33073300
// If original call returned false, copy Target to Expected.
3308-
NextIRB.CreateCall(
3309-
DFSF.DFS.DFSanMemShadowOriginConditionalExchangeFn,
3310-
{NextIRB.CreateIntCast(&CB, NextIRB.getInt8Ty(), false),
3311-
NextIRB.CreatePointerCast(TargetPtr, NextIRB.getInt8PtrTy()),
3312-
NextIRB.CreatePointerCast(ExpectedPtr, NextIRB.getInt8PtrTy()),
3313-
NextIRB.CreatePointerCast(DesiredPtr, NextIRB.getInt8PtrTy()),
3314-
NextIRB.CreateIntCast(Size, DFSF.DFS.IntptrTy, false)});
3301+
NextIRB.CreateCall(DFSF.DFS.DFSanMemShadowOriginConditionalExchangeFn,
3302+
{NextIRB.CreateIntCast(&CB, NextIRB.getInt8Ty(), false),
3303+
TargetPtr, ExpectedPtr, DesiredPtr,
3304+
NextIRB.CreateIntCast(Size, DFSF.DFS.IntptrTy, false)});
33153305
}
33163306

33173307
void DFSanVisitor::visitCallBase(CallBase &CB) {

llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1100,7 +1100,7 @@ Function *GCOVProfiler::insertCounterWriteout(
11001100
// Collect the relevant data into a large constant data structure that we can
11011101
// walk to write out everything.
11021102
StructType *StartFileCallArgsTy = StructType::create(
1103-
{Builder.getInt8PtrTy(), Builder.getInt32Ty(), Builder.getInt32Ty()},
1103+
{Builder.getPtrTy(), Builder.getInt32Ty(), Builder.getInt32Ty()},
11041104
"start_file_args_ty");
11051105
StructType *EmitFunctionCallArgsTy = StructType::create(
11061106
{Builder.getInt32Ty(), Builder.getInt32Ty(), Builder.getInt32Ty()},

llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -671,13 +671,13 @@ void InstrProfiling::lowerValueProfileInst(InstrProfValueProfileInst *Ind) {
671671
Ind->getOperandBundlesAsDefs(OpBundles);
672672
if (!IsMemOpSize) {
673673
Value *Args[3] = {Ind->getTargetValue(),
674-
Builder.CreateBitCast(DataVar, Builder.getInt8PtrTy()),
674+
Builder.CreateBitCast(DataVar, Builder.getPtrTy()),
675675
Builder.getInt32(Index)};
676676
Call = Builder.CreateCall(getOrInsertValueProfilingCall(*M, *TLI), Args,
677677
OpBundles);
678678
} else {
679679
Value *Args[3] = {Ind->getTargetValue(),
680-
Builder.CreateBitCast(DataVar, Builder.getInt8PtrTy()),
680+
Builder.CreateBitCast(DataVar, Builder.getPtrTy()),
681681
Builder.getInt32(Index)};
682682
Call = Builder.CreateCall(
683683
getOrInsertValueProfilingCall(*M, *TLI, ValueProfilingCallType::MemOp),

llvm/lib/Transforms/Instrumentation/MemProfiler.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ class MemProfiler {
182182
C = &(M.getContext());
183183
LongSize = M.getDataLayout().getPointerSizeInBits();
184184
IntptrTy = Type::getIntNTy(*C, LongSize);
185+
PtrTy = PointerType::getUnqual(*C);
185186
}
186187

187188
/// If it is an interesting memory access, populate information
@@ -209,6 +210,7 @@ class MemProfiler {
209210
LLVMContext *C;
210211
int LongSize;
211212
Type *IntptrTy;
213+
PointerType *PtrTy;
212214
ShadowMapping Mapping;
213215

214216
// These arrays is indexed by AccessIsWrite
@@ -267,15 +269,13 @@ Value *MemProfiler::memToShadow(Value *Shadow, IRBuilder<> &IRB) {
267269
void MemProfiler::instrumentMemIntrinsic(MemIntrinsic *MI) {
268270
IRBuilder<> IRB(MI);
269271
if (isa<MemTransferInst>(MI)) {
270-
IRB.CreateCall(
271-
isa<MemMoveInst>(MI) ? MemProfMemmove : MemProfMemcpy,
272-
{IRB.CreatePointerCast(MI->getOperand(0), IRB.getInt8PtrTy()),
273-
IRB.CreatePointerCast(MI->getOperand(1), IRB.getInt8PtrTy()),
274-
IRB.CreateIntCast(MI->getOperand(2), IntptrTy, false)});
272+
IRB.CreateCall(isa<MemMoveInst>(MI) ? MemProfMemmove : MemProfMemcpy,
273+
{MI->getOperand(0), MI->getOperand(1),
274+
IRB.CreateIntCast(MI->getOperand(2), IntptrTy, false)});
275275
} else if (isa<MemSetInst>(MI)) {
276276
IRB.CreateCall(
277277
MemProfMemset,
278-
{IRB.CreatePointerCast(MI->getOperand(0), IRB.getInt8PtrTy()),
278+
{MI->getOperand(0),
279279
IRB.CreateIntCast(MI->getOperand(1), IRB.getInt32Ty(), false),
280280
IRB.CreateIntCast(MI->getOperand(2), IntptrTy, false)});
281281
}
@@ -519,14 +519,12 @@ void MemProfiler::initializeCallbacks(Module &M) {
519519
FunctionType::get(IRB.getVoidTy(), Args1, false));
520520
}
521521
MemProfMemmove = M.getOrInsertFunction(
522-
ClMemoryAccessCallbackPrefix + "memmove", IRB.getInt8PtrTy(),
523-
IRB.getInt8PtrTy(), IRB.getInt8PtrTy(), IntptrTy);
522+
ClMemoryAccessCallbackPrefix + "memmove", PtrTy, PtrTy, PtrTy, IntptrTy);
524523
MemProfMemcpy = M.getOrInsertFunction(ClMemoryAccessCallbackPrefix + "memcpy",
525-
IRB.getInt8PtrTy(), IRB.getInt8PtrTy(),
526-
IRB.getInt8PtrTy(), IntptrTy);
527-
MemProfMemset = M.getOrInsertFunction(ClMemoryAccessCallbackPrefix + "memset",
528-
IRB.getInt8PtrTy(), IRB.getInt8PtrTy(),
529-
IRB.getInt32Ty(), IntptrTy);
524+
PtrTy, PtrTy, PtrTy, IntptrTy);
525+
MemProfMemset =
526+
M.getOrInsertFunction(ClMemoryAccessCallbackPrefix + "memset", PtrTy,
527+
PtrTy, IRB.getInt32Ty(), IntptrTy);
530528
}
531529

532530
bool MemProfiler::maybeInsertMemProfInitAtFunctionEntry(Function &F) {

0 commit comments

Comments
 (0)