From cb0fa3234daf973c146b25ba8f9a95a40ee189e9 Mon Sep 17 00:00:00 2001 From: Tyker Date: Tue, 31 Mar 2020 19:38:08 +0200 Subject: [PATCH] Fix 7093b92a136b0696cf9cfc3f9822973ed886be5b accidently pushed the wrong version of the patch. --- llvm/include/llvm/IR/KnowledgeRetention.h | 2 +- llvm/lib/IR/KnowledgeRetention.cpp | 53 +++++++++++++++---------------- 2 files changed, 26 insertions(+), 29 deletions(-) diff --git a/llvm/include/llvm/IR/KnowledgeRetention.h b/llvm/include/llvm/IR/KnowledgeRetention.h index 4279aa6..0942d79 100644 --- a/llvm/include/llvm/IR/KnowledgeRetention.h +++ b/llvm/include/llvm/IR/KnowledgeRetention.h @@ -33,7 +33,7 @@ IntrinsicInst *buildAssumeFromInst(Instruction *I); /// Calls BuildAssumeFromInst and if the resulting llvm.assume is valid insert /// if before I. This is usually what need to be done to salvage the knowledge /// contained in the instruction I. -void salvageKnowledge(Instruction* I); +void salvageKnowledge(Instruction *I); /// It is possible to have multiple Value for the argument of an attribute in /// the same llvm.assume on the same llvm::Value. This is rare but need to be diff --git a/llvm/lib/IR/KnowledgeRetention.cpp b/llvm/lib/IR/KnowledgeRetention.cpp index 221bb8c..3de899a 100644 --- a/llvm/lib/IR/KnowledgeRetention.cpp +++ b/llvm/lib/IR/KnowledgeRetention.cpp @@ -174,10 +174,10 @@ struct AssumeBuilderState { FnAssume, ArrayRef({ConstantInt::getTrue(C)}), OpBundle)); } - void addAttr(Attribute::AttrKind Kind, Value *Ptr, unsigned Argument = 0) { + void addAttr(Attribute::AttrKind Kind, Value *Val, unsigned Argument = 0) { AssumedKnowledge AK; AK.Name = Attribute::getNameFromAttrKind(Kind).data(); - AK.WasOn.setPointer(Ptr); + AK.WasOn.setPointer(Val); if (Attribute::doesAttrKindHaveArgument(Kind)) { AK.Argument = ConstantInt::get(Type::getInt64Ty(M->getContext()), Argument); @@ -188,35 +188,32 @@ struct AssumeBuilderState { AssumedKnowledgeSet.insert(AK); }; - void addLoadOrStore(Instruction *I) { - auto Impl = [&](auto *MemInst, Type *T) { - uint64_t DerefSize = - I->getModule()->getDataLayout().getTypeStoreSize(T).getKnownMinSize(); - if (DerefSize != 0) { - addAttr(Attribute::Dereferenceable, MemInst->getPointerOperand(), - DerefSize); - if (!NullPointerIsDefined(MemInst->getFunction(), - MemInst->getPointerOperand() - ->getType() - ->getPointerAddressSpace())) - addAttr(Attribute::NonNull, MemInst->getPointerOperand()); - } - MaybeAlign MA = MemInst->getAlign(); - if (MA.valueOrOne() > 1) - addAttr(Attribute::Alignment, MemInst->getPointerOperand(), - MA.valueOrOne().value()); - }; - if (auto *Load = dyn_cast(I)) - Impl(Load, Load->getType()); - if (auto *Store = dyn_cast(I)) - Impl(Store, Store->getValueOperand()->getType()); + void addAccessedPtr(Instruction *MemInst, Value *Pointer, Type *AccType, + MaybeAlign MA) { + uint64_t DerefSize = MemInst->getModule() + ->getDataLayout() + .getTypeStoreSize(AccType) + .getKnownMinSize(); + if (DerefSize != 0) { + addAttr(Attribute::Dereferenceable, Pointer, DerefSize); + if (!NullPointerIsDefined(MemInst->getFunction(), + Pointer->getType()->getPointerAddressSpace())) + addAttr(Attribute::NonNull, Pointer); + } + if (MA.valueOrOne() > 1) + addAttr(Attribute::Alignment, Pointer, MA.valueOrOne().value()); } void addInstruction(Instruction *I) { if (auto *Call = dyn_cast(I)) return addCall(Call); - if (isa(I) || isa(I)) - return addLoadOrStore(I); + if (auto *Load = dyn_cast(I)) + return addAccessedPtr(I, Load->getPointerOperand(), Load->getType(), + Load->getAlign()); + if (auto *Store = dyn_cast(I)) + return addAccessedPtr(I, Store->getPointerOperand(), + Store->getValueOperand()->getType(), + Store->getAlign()); // TODO: Add support for the other Instructions. // TODO: Maybe we should look around and merge with other llvm.assume. } @@ -232,8 +229,8 @@ IntrinsicInst *llvm::buildAssumeFromInst(Instruction *I) { return Builder.build(); } -void llvm::salvageKnowledge(Instruction* I) { - if (Instruction* Intr = buildAssumeFromInst(I)) +void llvm::salvageKnowledge(Instruction *I) { + if (Instruction *Intr = buildAssumeFromInst(I)) Intr->insertBefore(I); } -- 2.7.4