-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[Asan][RISCV] Enhance getTgtMemIntrinsic() to allow Asan instrument t… #135198
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4874,8 +4874,9 @@ Value *AArch64TTIImpl::getOrCreateResultFromMemIntrinsic(IntrinsicInst *Inst, | |
| } | ||
| } | ||
|
|
||
| bool AArch64TTIImpl::getTgtMemIntrinsic(IntrinsicInst *Inst, | ||
| MemIntrinsicInfo &Info) { | ||
| bool AArch64TTIImpl::getTgtMemIntrinsic( | ||
| IntrinsicInst *Inst, MemIntrinsicInfo &Info, | ||
| SmallVectorImpl<InterestingMemoryOperand> *Interesting) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fill the InterestingMemoryOperand as well if available? |
||
| switch (Inst->getIntrinsicID()) { | ||
| default: | ||
| break; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -494,8 +494,9 @@ unsigned GCNTTIImpl::getMaxInterleaveFactor(ElementCount VF) { | |
| return 8; | ||
| } | ||
|
|
||
| bool GCNTTIImpl::getTgtMemIntrinsic(IntrinsicInst *Inst, | ||
| MemIntrinsicInfo &Info) const { | ||
| bool GCNTTIImpl::getTgtMemIntrinsic( | ||
| IntrinsicInst *Inst, MemIntrinsicInfo &Info, | ||
| SmallVectorImpl<InterestingMemoryOperand> *Interesting) const { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fill the InterestingMemoryOperand as well if available?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @arichardson Thank you for the feedback, after few days of thinking. I'd like to rewrite this patch since this |
||
| switch (Inst->getIntrinsicID()) { | ||
| case Intrinsic::amdgcn_ds_ordered_add: | ||
| case Intrinsic::amdgcn_ds_ordered_swap: { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
| #include "llvm/CodeGen/TargetLowering.h" | ||
| #include "llvm/CodeGen/ValueTypes.h" | ||
| #include "llvm/IR/Instructions.h" | ||
| #include "llvm/IR/IntrinsicsRISCV.h" | ||
| #include "llvm/IR/PatternMatch.h" | ||
| #include <cmath> | ||
| #include <optional> | ||
|
|
@@ -43,6 +44,87 @@ static cl::opt<unsigned> | |
| "vectorization while tail-folding."), | ||
| cl::init(5), cl::Hidden); | ||
|
|
||
| bool RISCVTTIImpl::getTgtMemIntrinsic( | ||
| IntrinsicInst *Inst, MemIntrinsicInfo &Info, | ||
| SmallVectorImpl<InterestingMemoryOperand> *Interesting) const { | ||
| const DataLayout &DL = getDataLayout(); | ||
| Intrinsic::ID IID = Inst->getIntrinsicID(); | ||
| LLVMContext &C = Inst->getContext(); | ||
| bool HasMask = false; | ||
| bool HasInteresting = (Interesting == nullptr) ? false : true; | ||
|
|
||
| switch (IID) { | ||
| case Intrinsic::riscv_vle_mask: | ||
| case Intrinsic::riscv_vse_mask: | ||
| HasMask = true; | ||
| [[fallthrough]]; | ||
| case Intrinsic::riscv_vle: | ||
| case Intrinsic::riscv_vse: { | ||
| // Intrinsic interface: | ||
| // riscv_vle(merge, ptr, vl) | ||
| // riscv_vle_mask(merge, ptr, mask, vl, policy) | ||
| // riscv_vse(val, ptr, vl) | ||
| // riscv_vse_mask(val, ptr, mask, vl, policy) | ||
| bool IsWrite = Inst->getType()->isVoidTy(); | ||
| Type *Ty = IsWrite ? Inst->getArgOperand(0)->getType() : Inst->getType(); | ||
| const auto *RVVIInfo = RISCVVIntrinsicsTable::getRISCVVIntrinsicInfo(IID); | ||
| unsigned VLIndex = RVVIInfo->VLOperand; | ||
| unsigned PtrOperandNo = VLIndex - 1 - HasMask; | ||
| MaybeAlign Alignment = | ||
| Inst->getArgOperand(PtrOperandNo)->getPointerAlignment(DL); | ||
| Type *MaskType = Ty->getWithNewType(Type::getInt1Ty(C)); | ||
| Value *Mask = ConstantInt::getTrue(MaskType); | ||
| if (HasMask) | ||
| Mask = Inst->getArgOperand(VLIndex - 1); | ||
| Value *EVL = Inst->getArgOperand(VLIndex); | ||
| if (HasInteresting) | ||
| Interesting->emplace_back(Inst, PtrOperandNo, IsWrite, Ty, Alignment, | ||
| Mask, EVL); | ||
| return true; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Return true means we have fill up |
||
| } | ||
| case Intrinsic::riscv_vlse_mask: | ||
| case Intrinsic::riscv_vsse_mask: | ||
| HasMask = true; | ||
| [[fallthrough]]; | ||
| case Intrinsic::riscv_vlse: | ||
| case Intrinsic::riscv_vsse: { | ||
| // Intrinsic interface: | ||
| // riscv_vlse(merge, ptr, stride, vl) | ||
| // riscv_vlse_mask(merge, ptr, stride, mask, vl, policy) | ||
| // riscv_vsse(val, ptr, stride, vl) | ||
| // riscv_vsse_mask(val, ptr, stride, mask, vl, policy) | ||
| bool IsWrite = Inst->getType()->isVoidTy(); | ||
| Type *Ty = IsWrite ? Inst->getArgOperand(0)->getType() : Inst->getType(); | ||
| const auto *RVVIInfo = RISCVVIntrinsicsTable::getRISCVVIntrinsicInfo(IID); | ||
| unsigned VLIndex = RVVIInfo->VLOperand; | ||
| unsigned PtrOperandNo = VLIndex - 2 - HasMask; | ||
| MaybeAlign Alignment = | ||
| Inst->getArgOperand(PtrOperandNo)->getPointerAlignment(DL); | ||
|
|
||
| Value *Stride = Inst->getArgOperand(PtrOperandNo + 1); | ||
| // Use the pointer alignment as the element alignment if the stride is a | ||
| // multiple of the pointer alignment. Otherwise, the element alignment | ||
| // should be the greatest common divisor of pointer alignment and stride. | ||
| // For simplicity, just consider unalignment for elements. | ||
| unsigned PointerAlign = Alignment.valueOrOne().value(); | ||
| if (!isa<ConstantInt>(Stride) || | ||
| cast<ConstantInt>(Stride)->getZExtValue() % PointerAlign != 0) | ||
| Alignment = Align(1); | ||
|
|
||
| Type *MaskType = Ty->getWithNewType(Type::getInt1Ty(C)); | ||
| Value *Mask = ConstantInt::getTrue(MaskType); | ||
| if (HasMask) | ||
| Mask = Inst->getArgOperand(VLIndex - 1); | ||
| Value *EVL = Inst->getArgOperand(VLIndex); | ||
| if (HasInteresting) | ||
| Interesting->emplace_back(Inst, PtrOperandNo, IsWrite, Ty, Alignment, | ||
| Mask, EVL, Stride); | ||
| return true; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| InstructionCost | ||
| RISCVTTIImpl::getRISCVInstructionCost(ArrayRef<unsigned> OpCodes, MVT VT, | ||
| TTI::TargetCostKind CostKind) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may update the comment to indicate the relationship between return value and
Interesting?