Skip to content

Commit 48f804d

Browse files
authored
Revert "[TTI][ASan][RISCV] Move InterestingMemoryOperand to Analysis and embed in MemIntrinsicInfo" (#159700)
Reverts llvm/llvm-project#157863
1 parent e79f451 commit 48f804d

File tree

8 files changed

+38
-2462
lines changed

8 files changed

+38
-2462
lines changed

llvm/include/llvm/Analysis/InterestingMemoryOperand.h

Lines changed: 0 additions & 55 deletions
This file was deleted.

llvm/include/llvm/Analysis/TargetTransformInfo.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include "llvm/ADT/ArrayRef.h"
2626
#include "llvm/ADT/BitmaskEnum.h"
2727
#include "llvm/Analysis/IVDescriptors.h"
28-
#include "llvm/Analysis/InterestingMemoryOperand.h"
2928
#include "llvm/IR/FMF.h"
3029
#include "llvm/IR/InstrTypes.h"
3130
#include "llvm/IR/PassManager.h"
@@ -89,8 +88,6 @@ struct MemIntrinsicInfo {
8988
bool WriteMem = false;
9089
bool IsVolatile = false;
9190

92-
SmallVector<InterestingMemoryOperand, 1> InterestingOperands;
93-
9491
bool isUnordered() const {
9592
return (Ordering == AtomicOrdering::NotAtomic ||
9693
Ordering == AtomicOrdering::Unordered) &&

llvm/include/llvm/Transforms/Instrumentation/AddressSanitizerCommon.h

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,45 @@
1414
#define LLVM_TRANSFORMS_INSTRUMENTATION_ADDRESSSANITIZERCOMMON_H
1515

1616
#include "llvm/Analysis/CFG.h"
17-
#include "llvm/Analysis/InterestingMemoryOperand.h"
1817
#include "llvm/Analysis/PostDominators.h"
1918
#include "llvm/IR/Dominators.h"
2019
#include "llvm/IR/Instruction.h"
2120
#include "llvm/IR/IntrinsicInst.h"
2221
#include "llvm/IR/Module.h"
2322

2423
namespace llvm {
24+
25+
class InterestingMemoryOperand {
26+
public:
27+
Use *PtrUse;
28+
bool IsWrite;
29+
Type *OpType;
30+
TypeSize TypeStoreSize = TypeSize::getFixed(0);
31+
MaybeAlign Alignment;
32+
// The mask Value, if we're looking at a masked load/store.
33+
Value *MaybeMask;
34+
// The EVL Value, if we're looking at a vp intrinsic.
35+
Value *MaybeEVL;
36+
// The Stride Value, if we're looking at a strided load/store.
37+
Value *MaybeStride;
38+
39+
InterestingMemoryOperand(Instruction *I, unsigned OperandNo, bool IsWrite,
40+
class Type *OpType, MaybeAlign Alignment,
41+
Value *MaybeMask = nullptr,
42+
Value *MaybeEVL = nullptr,
43+
Value *MaybeStride = nullptr)
44+
: IsWrite(IsWrite), OpType(OpType), Alignment(Alignment),
45+
MaybeMask(MaybeMask), MaybeEVL(MaybeEVL), MaybeStride(MaybeStride) {
46+
const DataLayout &DL = I->getDataLayout();
47+
TypeStoreSize = DL.getTypeStoreSizeInBits(OpType);
48+
PtrUse = &I->getOperandUse(OperandNo);
49+
}
50+
51+
Instruction *getInsn() { return cast<Instruction>(PtrUse->getUser()); }
52+
53+
Value *getPtr() { return PtrUse->get(); }
54+
};
55+
2556
// Get AddressSanitizer parameters.
2657
void getAddressSanitizerParams(const Triple &TargetTriple, int LongSize,
2758
bool IsKasan, uint64_t *ShadowBase,

llvm/lib/Analysis/TargetTransformInfo.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "llvm/Analysis/TargetTransformInfo.h"
10-
#include "llvm/ADT/SmallVector.h"
1110
#include "llvm/Analysis/CFG.h"
1211
#include "llvm/Analysis/LoopIterator.h"
1312
#include "llvm/Analysis/TargetLibraryInfo.h"

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include "llvm/CodeGen/TargetLowering.h"
1616
#include "llvm/CodeGen/ValueTypes.h"
1717
#include "llvm/IR/Instructions.h"
18-
#include "llvm/IR/IntrinsicsRISCV.h"
1918
#include "llvm/IR/PatternMatch.h"
2019
#include <cmath>
2120
#include <optional>
@@ -2702,82 +2701,6 @@ void RISCVTTIImpl::getPeelingPreferences(Loop *L, ScalarEvolution &SE,
27022701
BaseT::getPeelingPreferences(L, SE, PP);
27032702
}
27042703

2705-
bool RISCVTTIImpl::getTgtMemIntrinsic(IntrinsicInst *Inst,
2706-
MemIntrinsicInfo &Info) const {
2707-
const DataLayout &DL = getDataLayout();
2708-
Intrinsic::ID IID = Inst->getIntrinsicID();
2709-
LLVMContext &C = Inst->getContext();
2710-
bool HasMask = false;
2711-
switch (IID) {
2712-
case Intrinsic::riscv_vle_mask:
2713-
case Intrinsic::riscv_vse_mask:
2714-
HasMask = true;
2715-
[[fallthrough]];
2716-
case Intrinsic::riscv_vle:
2717-
case Intrinsic::riscv_vse: {
2718-
// Intrinsic interface:
2719-
// riscv_vle(merge, ptr, vl)
2720-
// riscv_vle_mask(merge, ptr, mask, vl, policy)
2721-
// riscv_vse(val, ptr, vl)
2722-
// riscv_vse_mask(val, ptr, mask, vl, policy)
2723-
bool IsWrite = Inst->getType()->isVoidTy();
2724-
Type *Ty = IsWrite ? Inst->getArgOperand(0)->getType() : Inst->getType();
2725-
const auto *RVVIInfo = RISCVVIntrinsicsTable::getRISCVVIntrinsicInfo(IID);
2726-
unsigned VLIndex = RVVIInfo->VLOperand;
2727-
unsigned PtrOperandNo = VLIndex - 1 - HasMask;
2728-
MaybeAlign Alignment =
2729-
Inst->getArgOperand(PtrOperandNo)->getPointerAlignment(DL);
2730-
Type *MaskType = Ty->getWithNewType(Type::getInt1Ty(C));
2731-
Value *Mask = ConstantInt::getTrue(MaskType);
2732-
if (HasMask)
2733-
Mask = Inst->getArgOperand(VLIndex - 1);
2734-
Value *EVL = Inst->getArgOperand(VLIndex);
2735-
Info.InterestingOperands.emplace_back(Inst, PtrOperandNo, IsWrite, Ty,
2736-
Alignment, Mask, EVL);
2737-
return true;
2738-
}
2739-
case Intrinsic::riscv_vlse_mask:
2740-
case Intrinsic::riscv_vsse_mask:
2741-
HasMask = true;
2742-
[[fallthrough]];
2743-
case Intrinsic::riscv_vlse:
2744-
case Intrinsic::riscv_vsse: {
2745-
// Intrinsic interface:
2746-
// riscv_vlse(merge, ptr, stride, vl)
2747-
// riscv_vlse_mask(merge, ptr, stride, mask, vl, policy)
2748-
// riscv_vsse(val, ptr, stride, vl)
2749-
// riscv_vsse_mask(val, ptr, stride, mask, vl, policy)
2750-
bool IsWrite = Inst->getType()->isVoidTy();
2751-
Type *Ty = IsWrite ? Inst->getArgOperand(0)->getType() : Inst->getType();
2752-
const auto *RVVIInfo = RISCVVIntrinsicsTable::getRISCVVIntrinsicInfo(IID);
2753-
unsigned VLIndex = RVVIInfo->VLOperand;
2754-
unsigned PtrOperandNo = VLIndex - 2 - HasMask;
2755-
MaybeAlign Alignment =
2756-
Inst->getArgOperand(PtrOperandNo)->getPointerAlignment(DL);
2757-
2758-
Value *Stride = Inst->getArgOperand(PtrOperandNo + 1);
2759-
// Use the pointer alignment as the element alignment if the stride is a
2760-
// multiple of the pointer alignment. Otherwise, the element alignment
2761-
// should be the greatest common divisor of pointer alignment and stride.
2762-
// For simplicity, just consider unalignment for elements.
2763-
unsigned PointerAlign = Alignment.valueOrOne().value();
2764-
if (!isa<ConstantInt>(Stride) ||
2765-
cast<ConstantInt>(Stride)->getZExtValue() % PointerAlign != 0)
2766-
Alignment = Align(1);
2767-
2768-
Type *MaskType = Ty->getWithNewType(Type::getInt1Ty(C));
2769-
Value *Mask = ConstantInt::getTrue(MaskType);
2770-
if (HasMask)
2771-
Mask = Inst->getArgOperand(VLIndex - 1);
2772-
Value *EVL = Inst->getArgOperand(VLIndex);
2773-
Info.InterestingOperands.emplace_back(Inst, PtrOperandNo, IsWrite, Ty,
2774-
Alignment, Mask, EVL, Stride);
2775-
return true;
2776-
}
2777-
}
2778-
return false;
2779-
}
2780-
27812704
unsigned RISCVTTIImpl::getRegUsageForType(Type *Ty) const {
27822705
if (Ty->isVectorTy()) {
27832706
// f16 with only zvfhmin and bf16 will be promoted to f32

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,6 @@ class RISCVTTIImpl final : public BasicTTIImplBase<RISCVTTIImpl> {
160160
void getPeelingPreferences(Loop *L, ScalarEvolution &SE,
161161
TTI::PeelingPreferences &PP) const override;
162162

163-
bool getTgtMemIntrinsic(IntrinsicInst *Inst,
164-
MemIntrinsicInfo &Info) const override;
165-
166163
unsigned getMinVectorRegisterBitWidth() const override {
167164
return ST->useRVVForFixedLengthVectors() ? 16 : 0;
168165
}

llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#include "llvm/Analysis/MemoryBuiltins.h"
3030
#include "llvm/Analysis/StackSafetyAnalysis.h"
3131
#include "llvm/Analysis/TargetLibraryInfo.h"
32-
#include "llvm/Analysis/TargetTransformInfo.h"
3332
#include "llvm/Analysis/ValueTracking.h"
3433
#include "llvm/BinaryFormat/MachO.h"
3534
#include "llvm/Demangle/Demangle.h"
@@ -804,8 +803,7 @@ struct AddressSanitizer {
804803

805804
bool ignoreAccess(Instruction *Inst, Value *Ptr);
806805
void getInterestingMemoryOperands(
807-
Instruction *I, SmallVectorImpl<InterestingMemoryOperand> &Interesting,
808-
const TargetTransformInfo *TTI);
806+
Instruction *I, SmallVectorImpl<InterestingMemoryOperand> &Interesting);
809807

810808
void instrumentMop(ObjectSizeOffsetVisitor &ObjSizeVis,
811809
InterestingMemoryOperand &O, bool UseCalls,
@@ -845,8 +843,7 @@ struct AddressSanitizer {
845843
void instrumentMemIntrinsic(MemIntrinsic *MI, RuntimeCallInserter &RTCI);
846844
Value *memToShadow(Value *Shadow, IRBuilder<> &IRB);
847845
bool suppressInstrumentationSiteForDebug(int &Instrumented);
848-
bool instrumentFunction(Function &F, const TargetLibraryInfo *TLI,
849-
const TargetTransformInfo *TTI);
846+
bool instrumentFunction(Function &F, const TargetLibraryInfo *TLI);
850847
bool maybeInsertAsanInitAtFunctionEntry(Function &F);
851848
bool maybeInsertDynamicShadowAtFunctionEntry(Function &F);
852849
void markEscapedLocalAllocas(Function &F);
@@ -1317,8 +1314,7 @@ PreservedAnalyses AddressSanitizerPass::run(Module &M,
13171314
Options.MaxInlinePoisoningSize, Options.CompileKernel, Options.Recover,
13181315
Options.UseAfterScope, Options.UseAfterReturn);
13191316
const TargetLibraryInfo &TLI = FAM.getResult<TargetLibraryAnalysis>(F);
1320-
const TargetTransformInfo &TTI = FAM.getResult<TargetIRAnalysis>(F);
1321-
Modified |= FunctionSanitizer.instrumentFunction(F, &TLI, &TTI);
1317+
Modified |= FunctionSanitizer.instrumentFunction(F, &TLI);
13221318
}
13231319
Modified |= ModuleSanitizer.instrumentModule();
13241320
if (!Modified)
@@ -1456,8 +1452,7 @@ bool AddressSanitizer::ignoreAccess(Instruction *Inst, Value *Ptr) {
14561452
}
14571453

14581454
void AddressSanitizer::getInterestingMemoryOperands(
1459-
Instruction *I, SmallVectorImpl<InterestingMemoryOperand> &Interesting,
1460-
const TargetTransformInfo *TTI) {
1455+
Instruction *I, SmallVectorImpl<InterestingMemoryOperand> &Interesting) {
14611456
// Do not instrument the load fetching the dynamic shadow address.
14621457
if (LocalDynamicShadow == I)
14631458
return;
@@ -1575,12 +1570,6 @@ void AddressSanitizer::getInterestingMemoryOperands(
15751570
break;
15761571
}
15771572
default:
1578-
if (auto *II = dyn_cast<IntrinsicInst>(I)) {
1579-
MemIntrinsicInfo IntrInfo;
1580-
if (TTI->getTgtMemIntrinsic(II, IntrInfo))
1581-
Interesting = IntrInfo.InterestingOperands;
1582-
return;
1583-
}
15841573
for (unsigned ArgNo = 0; ArgNo < CI->arg_size(); ArgNo++) {
15851574
if (!ClInstrumentByval || !CI->isByValArgument(ArgNo) ||
15861575
ignoreAccess(I, CI->getArgOperand(ArgNo)))
@@ -2996,8 +2985,7 @@ bool AddressSanitizer::suppressInstrumentationSiteForDebug(int &Instrumented) {
29962985
}
29972986

29982987
bool AddressSanitizer::instrumentFunction(Function &F,
2999-
const TargetLibraryInfo *TLI,
3000-
const TargetTransformInfo *TTI) {
2988+
const TargetLibraryInfo *TLI) {
30012989
bool FunctionModified = false;
30022990

30032991
// Do not apply any instrumentation for naked functions.
@@ -3050,7 +3038,7 @@ bool AddressSanitizer::instrumentFunction(Function &F,
30503038
if (Inst.hasMetadata(LLVMContext::MD_nosanitize))
30513039
continue;
30523040
SmallVector<InterestingMemoryOperand, 1> InterestingOperands;
3053-
getInterestingMemoryOperands(&Inst, InterestingOperands, TTI);
3041+
getInterestingMemoryOperands(&Inst, InterestingOperands);
30543042

30553043
if (!InterestingOperands.empty()) {
30563044
for (auto &Operand : InterestingOperands) {

0 commit comments

Comments
 (0)