forked from OSchip/llvm-project
[Alignment][NFC] CreateMemSet use MaybeAlign
Summary: This is patch is part of a series to introduce an Alignment type. See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html See this patch for the introduction of the type: https://reviews.llvm.org/D64790 Reviewers: courbet Subscribers: arsenm, jvesely, nhaehnle, hiraditya, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D71213
This commit is contained in:
parent
707e970781
commit
1b2842bf90
|
@ -350,7 +350,7 @@ bool AtomicInfo::emitMemSetZeroIfNecessary() const {
|
|||
CGF.Builder.CreateMemSet(
|
||||
addr, llvm::ConstantInt::get(CGF.Int8Ty, 0),
|
||||
CGF.getContext().toCharUnitsFromBits(AtomicSizeInBits).getQuantity(),
|
||||
LVal.getAlignment().getQuantity());
|
||||
LVal.getAlignment().getAsAlign());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -296,7 +296,7 @@ public:
|
|||
llvm::CallInst *CreateMemSet(Address Dest, llvm::Value *Value,
|
||||
llvm::Value *Size, bool IsVolatile = false) {
|
||||
return CreateMemSet(Dest.getPointer(), Value, Size,
|
||||
Dest.getAlignment().getQuantity(), IsVolatile);
|
||||
Dest.getAlignment().getAsAlign(), IsVolatile);
|
||||
}
|
||||
|
||||
using CGBuilderBaseTy::CreatePreserveStructAccessIndex;
|
||||
|
|
|
@ -46,7 +46,8 @@ int64_t clamp(int64_t Value, int64_t Low, int64_t High) {
|
|||
return std::min(High, std::max(Low, Value));
|
||||
}
|
||||
|
||||
static void initializeAlloca(CodeGenFunction &CGF, AllocaInst *AI, Value *Size, unsigned AlignmentInBytes) {
|
||||
static void initializeAlloca(CodeGenFunction &CGF, AllocaInst *AI, Value *Size,
|
||||
Align AlignmentInBytes) {
|
||||
ConstantInt *Byte;
|
||||
switch (CGF.getLangOpts().getTrivialAutoVarInit()) {
|
||||
case LangOptions::TrivialAutoVarInitKind::Uninitialized:
|
||||
|
@ -2359,12 +2360,12 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
|
|||
Value *Size = EmitScalarExpr(E->getArg(0));
|
||||
const TargetInfo &TI = getContext().getTargetInfo();
|
||||
// The alignment of the alloca should correspond to __BIGGEST_ALIGNMENT__.
|
||||
unsigned SuitableAlignmentInBytes =
|
||||
const Align SuitableAlignmentInBytes =
|
||||
CGM.getContext()
|
||||
.toCharUnitsFromBits(TI.getSuitableAlign())
|
||||
.getQuantity();
|
||||
.getAsAlign();
|
||||
AllocaInst *AI = Builder.CreateAlloca(Builder.getInt8Ty(), Size);
|
||||
AI->setAlignment(MaybeAlign(SuitableAlignmentInBytes));
|
||||
AI->setAlignment(SuitableAlignmentInBytes);
|
||||
initializeAlloca(*this, AI, Size, SuitableAlignmentInBytes);
|
||||
return RValue::get(AI);
|
||||
}
|
||||
|
@ -2374,10 +2375,10 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
|
|||
Value *AlignmentInBitsValue = EmitScalarExpr(E->getArg(1));
|
||||
auto *AlignmentInBitsCI = cast<ConstantInt>(AlignmentInBitsValue);
|
||||
unsigned AlignmentInBits = AlignmentInBitsCI->getZExtValue();
|
||||
unsigned AlignmentInBytes =
|
||||
CGM.getContext().toCharUnitsFromBits(AlignmentInBits).getQuantity();
|
||||
const Align AlignmentInBytes =
|
||||
CGM.getContext().toCharUnitsFromBits(AlignmentInBits).getAsAlign();
|
||||
AllocaInst *AI = Builder.CreateAlloca(Builder.getInt8Ty(), Size);
|
||||
AI->setAlignment(MaybeAlign(AlignmentInBytes));
|
||||
AI->setAlignment(AlignmentInBytes);
|
||||
initializeAlloca(*this, AI, Size, AlignmentInBytes);
|
||||
return RValue::get(AI);
|
||||
}
|
||||
|
@ -12335,7 +12336,7 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID,
|
|||
case X86::BI__stosb: {
|
||||
// We treat __stosb as a volatile memset - it may not generate "rep stosb"
|
||||
// instruction, but it will create a memset that won't be optimized away.
|
||||
return Builder.CreateMemSet(Ops[0], Ops[1], Ops[2], 1, true);
|
||||
return Builder.CreateMemSet(Ops[0], Ops[1], Ops[2], Align::None(), true);
|
||||
}
|
||||
case X86::BI__ud2:
|
||||
// llvm.trap makes a ud2a instruction on x86.
|
||||
|
|
|
@ -449,15 +449,15 @@ public:
|
|||
/// If the pointer isn't an i8*, it will be converted. If a TBAA tag is
|
||||
/// specified, it will be added to the instruction. Likewise with alias.scope
|
||||
/// and noalias tags.
|
||||
CallInst *CreateMemSet(Value *Ptr, Value *Val, uint64_t Size, unsigned Align,
|
||||
bool isVolatile = false, MDNode *TBAATag = nullptr,
|
||||
MDNode *ScopeTag = nullptr,
|
||||
CallInst *CreateMemSet(Value *Ptr, Value *Val, uint64_t Size,
|
||||
MaybeAlign Align, bool isVolatile = false,
|
||||
MDNode *TBAATag = nullptr, MDNode *ScopeTag = nullptr,
|
||||
MDNode *NoAliasTag = nullptr) {
|
||||
return CreateMemSet(Ptr, Val, getInt64(Size), Align, isVolatile,
|
||||
TBAATag, ScopeTag, NoAliasTag);
|
||||
}
|
||||
|
||||
CallInst *CreateMemSet(Value *Ptr, Value *Val, Value *Size, unsigned Align,
|
||||
CallInst *CreateMemSet(Value *Ptr, Value *Val, Value *Size, MaybeAlign Align,
|
||||
bool isVolatile = false, MDNode *TBAATag = nullptr,
|
||||
MDNode *ScopeTag = nullptr,
|
||||
MDNode *NoAliasTag = nullptr);
|
||||
|
|
|
@ -3442,7 +3442,8 @@ LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef B, LLVMTypeRef Ty,
|
|||
LLVMValueRef LLVMBuildMemSet(LLVMBuilderRef B, LLVMValueRef Ptr,
|
||||
LLVMValueRef Val, LLVMValueRef Len,
|
||||
unsigned Align) {
|
||||
return wrap(unwrap(B)->CreateMemSet(unwrap(Ptr), unwrap(Val), unwrap(Len), Align));
|
||||
return wrap(unwrap(B)->CreateMemSet(unwrap(Ptr), unwrap(Val), unwrap(Len),
|
||||
MaybeAlign(Align)));
|
||||
}
|
||||
|
||||
LLVMValueRef LLVMBuildMemCpy(LLVMBuilderRef B,
|
||||
|
|
|
@ -96,10 +96,10 @@ static InvokeInst *createInvokeHelper(Function *Invokee, BasicBlock *NormalDest,
|
|||
return II;
|
||||
}
|
||||
|
||||
CallInst *IRBuilderBase::
|
||||
CreateMemSet(Value *Ptr, Value *Val, Value *Size, unsigned Align,
|
||||
bool isVolatile, MDNode *TBAATag, MDNode *ScopeTag,
|
||||
MDNode *NoAliasTag) {
|
||||
CallInst *IRBuilderBase::CreateMemSet(Value *Ptr, Value *Val, Value *Size,
|
||||
MaybeAlign Align, bool isVolatile,
|
||||
MDNode *TBAATag, MDNode *ScopeTag,
|
||||
MDNode *NoAliasTag) {
|
||||
Ptr = getCastedInt8PtrValue(Ptr);
|
||||
Value *Ops[] = {Ptr, Val, Size, getInt1(isVolatile)};
|
||||
Type *Tys[] = { Ptr->getType(), Size->getType() };
|
||||
|
@ -108,8 +108,8 @@ CreateMemSet(Value *Ptr, Value *Val, Value *Size, unsigned Align,
|
|||
|
||||
CallInst *CI = createCallHelper(TheFn, Ops, this);
|
||||
|
||||
if (Align > 0)
|
||||
cast<MemSetInst>(CI)->setDestAlignment(Align);
|
||||
if (Align)
|
||||
cast<MemSetInst>(CI)->setDestAlignment(Align->value());
|
||||
|
||||
// Set the TBAA info if present.
|
||||
if (TBAATag)
|
||||
|
|
|
@ -898,9 +898,9 @@ bool AMDGPUPromoteAlloca::handleAlloca(AllocaInst &I, bool SufficientLDS) {
|
|||
}
|
||||
case Intrinsic::memset: {
|
||||
MemSetInst *MemSet = cast<MemSetInst>(Intr);
|
||||
Builder.CreateMemSet(MemSet->getRawDest(), MemSet->getValue(),
|
||||
MemSet->getLength(), MemSet->getDestAlignment(),
|
||||
MemSet->isVolatile());
|
||||
Builder.CreateMemSet(
|
||||
MemSet->getRawDest(), MemSet->getValue(), MemSet->getLength(),
|
||||
MaybeAlign(MemSet->getDestAlignment()), MemSet->isVolatile());
|
||||
Intr->eraseFromParent();
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -789,7 +789,7 @@ bool HWAddressSanitizer::tagAlloca(IRBuilder<> &IRB, AllocaInst *AI,
|
|||
// llvm.memset right here into either a sequence of stores, or a call to
|
||||
// hwasan_tag_memory.
|
||||
if (ShadowSize)
|
||||
IRB.CreateMemSet(ShadowPtr, JustTag, ShadowSize, /*Align=*/1);
|
||||
IRB.CreateMemSet(ShadowPtr, JustTag, ShadowSize, Align::None());
|
||||
if (Size != AlignedSize) {
|
||||
IRB.CreateStore(
|
||||
ConstantInt::get(Int8Ty, Size % Mapping.getObjectAlignment()),
|
||||
|
|
|
@ -203,8 +203,8 @@ using namespace llvm;
|
|||
#define DEBUG_TYPE "msan"
|
||||
|
||||
static const unsigned kOriginSize = 4;
|
||||
static const unsigned kMinOriginAlignment = 4;
|
||||
static const unsigned kShadowTLSAlignment = 8;
|
||||
static const Align kMinOriginAlignment = Align(4);
|
||||
static const Align kShadowTLSAlignment = Align(8);
|
||||
|
||||
// These constants must be kept in sync with the ones in msan.h.
|
||||
static const unsigned kParamTLSSize = 800;
|
||||
|
@ -1087,15 +1087,15 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
|
|||
|
||||
/// Fill memory range with the given origin value.
|
||||
void paintOrigin(IRBuilder<> &IRB, Value *Origin, Value *OriginPtr,
|
||||
unsigned Size, unsigned Alignment) {
|
||||
unsigned Size, Align Alignment) {
|
||||
const DataLayout &DL = F.getParent()->getDataLayout();
|
||||
unsigned IntptrAlignment = DL.getABITypeAlignment(MS.IntptrTy);
|
||||
const Align IntptrAlignment = Align(DL.getABITypeAlignment(MS.IntptrTy));
|
||||
unsigned IntptrSize = DL.getTypeStoreSize(MS.IntptrTy);
|
||||
assert(IntptrAlignment >= kMinOriginAlignment);
|
||||
assert(IntptrSize >= kOriginSize);
|
||||
|
||||
unsigned Ofs = 0;
|
||||
unsigned CurrentAlignment = Alignment;
|
||||
Align CurrentAlignment = Alignment;
|
||||
if (Alignment >= IntptrAlignment && IntptrSize > kOriginSize) {
|
||||
Value *IntptrOrigin = originToIntptr(IRB, Origin);
|
||||
Value *IntptrOriginPtr =
|
||||
|
@ -1103,7 +1103,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
|
|||
for (unsigned i = 0; i < Size / IntptrSize; ++i) {
|
||||
Value *Ptr = i ? IRB.CreateConstGEP1_32(MS.IntptrTy, IntptrOriginPtr, i)
|
||||
: IntptrOriginPtr;
|
||||
IRB.CreateAlignedStore(IntptrOrigin, Ptr, CurrentAlignment);
|
||||
IRB.CreateAlignedStore(IntptrOrigin, Ptr, CurrentAlignment.value());
|
||||
Ofs += IntptrSize / kOriginSize;
|
||||
CurrentAlignment = IntptrAlignment;
|
||||
}
|
||||
|
@ -1112,15 +1112,15 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
|
|||
for (unsigned i = Ofs; i < (Size + kOriginSize - 1) / kOriginSize; ++i) {
|
||||
Value *GEP =
|
||||
i ? IRB.CreateConstGEP1_32(MS.OriginTy, OriginPtr, i) : OriginPtr;
|
||||
IRB.CreateAlignedStore(Origin, GEP, CurrentAlignment);
|
||||
IRB.CreateAlignedStore(Origin, GEP, CurrentAlignment.value());
|
||||
CurrentAlignment = kMinOriginAlignment;
|
||||
}
|
||||
}
|
||||
|
||||
void storeOrigin(IRBuilder<> &IRB, Value *Addr, Value *Shadow, Value *Origin,
|
||||
Value *OriginPtr, unsigned Alignment, bool AsCall) {
|
||||
Value *OriginPtr, Align Alignment, bool AsCall) {
|
||||
const DataLayout &DL = F.getParent()->getDataLayout();
|
||||
unsigned OriginAlignment = std::max(kMinOriginAlignment, Alignment);
|
||||
const Align OriginAlignment = std::max(kMinOriginAlignment, Alignment);
|
||||
unsigned StoreSize = DL.getTypeStoreSize(Shadow->getType());
|
||||
if (Shadow->getType()->isAggregateType()) {
|
||||
paintOrigin(IRB, updateOrigin(Origin, IRB), OriginPtr, StoreSize,
|
||||
|
@ -1165,12 +1165,13 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
|
|||
Value *Shadow = SI->isAtomic() ? getCleanShadow(Val) : getShadow(Val);
|
||||
Value *ShadowPtr, *OriginPtr;
|
||||
Type *ShadowTy = Shadow->getType();
|
||||
unsigned Alignment = SI->getAlignment();
|
||||
unsigned OriginAlignment = std::max(kMinOriginAlignment, Alignment);
|
||||
const Align Alignment = assumeAligned(SI->getAlignment());
|
||||
const Align OriginAlignment = std::max(kMinOriginAlignment, Alignment);
|
||||
std::tie(ShadowPtr, OriginPtr) =
|
||||
getShadowOriginPtr(Addr, IRB, ShadowTy, Alignment, /*isStore*/ true);
|
||||
|
||||
StoreInst *NewSI = IRB.CreateAlignedStore(Shadow, ShadowPtr, Alignment);
|
||||
StoreInst *NewSI =
|
||||
IRB.CreateAlignedStore(Shadow, ShadowPtr, Alignment.value());
|
||||
LLVM_DEBUG(dbgs() << " STORE: " << *NewSI << "\n");
|
||||
(void)NewSI;
|
||||
|
||||
|
@ -1407,7 +1408,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
|
|||
std::pair<Value *, Value *> getShadowOriginPtrUserspace(Value *Addr,
|
||||
IRBuilder<> &IRB,
|
||||
Type *ShadowTy,
|
||||
unsigned Alignment) {
|
||||
Align Alignment) {
|
||||
Value *ShadowOffset = getShadowPtrOffset(Addr, IRB);
|
||||
Value *ShadowLong = ShadowOffset;
|
||||
uint64_t ShadowBase = MS.MapParams->ShadowBase;
|
||||
|
@ -1426,7 +1427,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
|
|||
OriginLong = IRB.CreateAdd(OriginLong,
|
||||
ConstantInt::get(MS.IntptrTy, OriginBase));
|
||||
if (Alignment < kMinOriginAlignment) {
|
||||
uint64_t Mask = kMinOriginAlignment - 1;
|
||||
uint64_t Mask = kMinOriginAlignment.value() - 1;
|
||||
OriginLong =
|
||||
IRB.CreateAnd(OriginLong, ConstantInt::get(MS.IntptrTy, ~Mask));
|
||||
}
|
||||
|
@ -1436,9 +1437,10 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
|
|||
return std::make_pair(ShadowPtr, OriginPtr);
|
||||
}
|
||||
|
||||
std::pair<Value *, Value *>
|
||||
getShadowOriginPtrKernel(Value *Addr, IRBuilder<> &IRB, Type *ShadowTy,
|
||||
unsigned Alignment, bool isStore) {
|
||||
std::pair<Value *, Value *> getShadowOriginPtrKernel(Value *Addr,
|
||||
IRBuilder<> &IRB,
|
||||
Type *ShadowTy,
|
||||
bool isStore) {
|
||||
Value *ShadowOriginPtrs;
|
||||
const DataLayout &DL = F.getParent()->getDataLayout();
|
||||
int Size = DL.getTypeStoreSize(ShadowTy);
|
||||
|
@ -1463,14 +1465,11 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
|
|||
|
||||
std::pair<Value *, Value *> getShadowOriginPtr(Value *Addr, IRBuilder<> &IRB,
|
||||
Type *ShadowTy,
|
||||
unsigned Alignment,
|
||||
Align Alignment,
|
||||
bool isStore) {
|
||||
std::pair<Value *, Value *> ret;
|
||||
if (MS.CompileKernel)
|
||||
ret = getShadowOriginPtrKernel(Addr, IRB, ShadowTy, Alignment, isStore);
|
||||
else
|
||||
ret = getShadowOriginPtrUserspace(Addr, IRB, ShadowTy, Alignment);
|
||||
return ret;
|
||||
return getShadowOriginPtrKernel(Addr, IRB, ShadowTy, isStore);
|
||||
return getShadowOriginPtrUserspace(Addr, IRB, ShadowTy, Alignment);
|
||||
}
|
||||
|
||||
/// Compute the shadow address for a given function argument.
|
||||
|
@ -1620,11 +1619,9 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
|
|||
// ByVal pointer itself has clean shadow. We copy the actual
|
||||
// argument shadow to the underlying memory.
|
||||
// Figure out maximal valid memcpy alignment.
|
||||
unsigned ArgAlign = FArg.getParamAlignment();
|
||||
if (ArgAlign == 0) {
|
||||
Type *EltType = A->getType()->getPointerElementType();
|
||||
ArgAlign = DL.getABITypeAlignment(EltType);
|
||||
}
|
||||
const Align ArgAlign = DL.getValueOrABITypeAlignment(
|
||||
MaybeAlign(FArg.getParamAlignment()),
|
||||
A->getType()->getPointerElementType());
|
||||
Value *CpShadowPtr =
|
||||
getShadowOriginPtr(V, EntryIRB, EntryIRB.getInt8Ty(), ArgAlign,
|
||||
/*isStore*/ true)
|
||||
|
@ -1636,9 +1633,9 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
|
|||
CpShadowPtr, Constant::getNullValue(EntryIRB.getInt8Ty()),
|
||||
Size, ArgAlign);
|
||||
} else {
|
||||
unsigned CopyAlign = std::min(ArgAlign, kShadowTLSAlignment);
|
||||
Value *Cpy = EntryIRB.CreateMemCpy(CpShadowPtr, CopyAlign, Base,
|
||||
CopyAlign, Size);
|
||||
const Align CopyAlign = std::min(ArgAlign, kShadowTLSAlignment);
|
||||
Value *Cpy = EntryIRB.CreateMemCpy(CpShadowPtr, CopyAlign.value(),
|
||||
Base, CopyAlign.value(), Size);
|
||||
LLVM_DEBUG(dbgs() << " ByValCpy: " << *Cpy << "\n");
|
||||
(void)Cpy;
|
||||
}
|
||||
|
@ -1648,8 +1645,8 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
|
|||
// ParamTLS overflow.
|
||||
*ShadowPtr = getCleanShadow(V);
|
||||
} else {
|
||||
*ShadowPtr = EntryIRB.CreateAlignedLoad(getShadowTy(&FArg), Base,
|
||||
kShadowTLSAlignment);
|
||||
*ShadowPtr = EntryIRB.CreateAlignedLoad(
|
||||
getShadowTy(&FArg), Base, kShadowTLSAlignment.value());
|
||||
}
|
||||
}
|
||||
LLVM_DEBUG(dbgs()
|
||||
|
@ -1784,12 +1781,12 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
|
|||
Type *ShadowTy = getShadowTy(&I);
|
||||
Value *Addr = I.getPointerOperand();
|
||||
Value *ShadowPtr, *OriginPtr;
|
||||
unsigned Alignment = I.getAlignment();
|
||||
const Align Alignment = assumeAligned(I.getAlignment());
|
||||
if (PropagateShadow) {
|
||||
std::tie(ShadowPtr, OriginPtr) =
|
||||
getShadowOriginPtr(Addr, IRB, ShadowTy, Alignment, /*isStore*/ false);
|
||||
setShadow(&I,
|
||||
IRB.CreateAlignedLoad(ShadowTy, ShadowPtr, Alignment, "_msld"));
|
||||
setShadow(&I, IRB.CreateAlignedLoad(ShadowTy, ShadowPtr,
|
||||
Alignment.value(), "_msld"));
|
||||
} else {
|
||||
setShadow(&I, getCleanShadow(&I));
|
||||
}
|
||||
|
@ -1802,9 +1799,9 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
|
|||
|
||||
if (MS.TrackOrigins) {
|
||||
if (PropagateShadow) {
|
||||
unsigned OriginAlignment = std::max(kMinOriginAlignment, Alignment);
|
||||
setOrigin(
|
||||
&I, IRB.CreateAlignedLoad(MS.OriginTy, OriginPtr, OriginAlignment));
|
||||
const Align OriginAlignment = std::max(kMinOriginAlignment, Alignment);
|
||||
setOrigin(&I, IRB.CreateAlignedLoad(MS.OriginTy, OriginPtr,
|
||||
OriginAlignment.value()));
|
||||
} else {
|
||||
setOrigin(&I, getCleanOrigin());
|
||||
}
|
||||
|
@ -1826,8 +1823,8 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
|
|||
|
||||
IRBuilder<> IRB(&I);
|
||||
Value *Addr = I.getOperand(0);
|
||||
Value *ShadowPtr = getShadowOriginPtr(Addr, IRB, I.getType(),
|
||||
/*Alignment*/ 1, /*isStore*/ true)
|
||||
Value *ShadowPtr = getShadowOriginPtr(Addr, IRB, I.getType(), Align::None(),
|
||||
/*isStore*/ true)
|
||||
.first;
|
||||
|
||||
if (ClCheckAccessAddress)
|
||||
|
@ -2459,7 +2456,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
|
|||
// We don't know the pointer alignment (could be unaligned SSE store!).
|
||||
// Have to assume to worst case.
|
||||
std::tie(ShadowPtr, OriginPtr) = getShadowOriginPtr(
|
||||
Addr, IRB, Shadow->getType(), /*Alignment*/ 1, /*isStore*/ true);
|
||||
Addr, IRB, Shadow->getType(), Align::None(), /*isStore*/ true);
|
||||
IRB.CreateAlignedStore(Shadow, ShadowPtr, 1);
|
||||
|
||||
if (ClCheckAccessAddress)
|
||||
|
@ -2483,11 +2480,11 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
|
|||
if (PropagateShadow) {
|
||||
// We don't know the pointer alignment (could be unaligned SSE load!).
|
||||
// Have to assume to worst case.
|
||||
unsigned Alignment = 1;
|
||||
const Align Alignment = Align::None();
|
||||
std::tie(ShadowPtr, OriginPtr) =
|
||||
getShadowOriginPtr(Addr, IRB, ShadowTy, Alignment, /*isStore*/ false);
|
||||
setShadow(&I,
|
||||
IRB.CreateAlignedLoad(ShadowTy, ShadowPtr, Alignment, "_msld"));
|
||||
setShadow(&I, IRB.CreateAlignedLoad(ShadowTy, ShadowPtr,
|
||||
Alignment.value(), "_msld"));
|
||||
} else {
|
||||
setShadow(&I, getCleanShadow(&I));
|
||||
}
|
||||
|
@ -2874,7 +2871,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
|
|||
Value* Addr = I.getArgOperand(0);
|
||||
Type *Ty = IRB.getInt32Ty();
|
||||
Value *ShadowPtr =
|
||||
getShadowOriginPtr(Addr, IRB, Ty, /*Alignment*/ 1, /*isStore*/ true)
|
||||
getShadowOriginPtr(Addr, IRB, Ty, Align::None(), /*isStore*/ true)
|
||||
.first;
|
||||
|
||||
IRB.CreateStore(getCleanShadow(Ty),
|
||||
|
@ -2890,7 +2887,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
|
|||
IRBuilder<> IRB(&I);
|
||||
Value *Addr = I.getArgOperand(0);
|
||||
Type *Ty = IRB.getInt32Ty();
|
||||
unsigned Alignment = 1;
|
||||
const Align Alignment = Align::None();
|
||||
Value *ShadowPtr, *OriginPtr;
|
||||
std::tie(ShadowPtr, OriginPtr) =
|
||||
getShadowOriginPtr(Addr, IRB, Ty, Alignment, /*isStore*/ false);
|
||||
|
@ -2898,7 +2895,8 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
|
|||
if (ClCheckAccessAddress)
|
||||
insertShadowCheck(Addr, &I);
|
||||
|
||||
Value *Shadow = IRB.CreateAlignedLoad(Ty, ShadowPtr, Alignment, "_ldmxcsr");
|
||||
Value *Shadow =
|
||||
IRB.CreateAlignedLoad(Ty, ShadowPtr, Alignment.value(), "_ldmxcsr");
|
||||
Value *Origin = MS.TrackOrigins ? IRB.CreateLoad(MS.OriginTy, OriginPtr)
|
||||
: getCleanOrigin();
|
||||
insertShadowCheck(Shadow, Origin, &I);
|
||||
|
@ -2908,14 +2906,15 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
|
|||
IRBuilder<> IRB(&I);
|
||||
Value *V = I.getArgOperand(0);
|
||||
Value *Addr = I.getArgOperand(1);
|
||||
unsigned Align = cast<ConstantInt>(I.getArgOperand(2))->getZExtValue();
|
||||
const Align Alignment =
|
||||
assumeAligned(cast<ConstantInt>(I.getArgOperand(2))->getZExtValue());
|
||||
Value *Mask = I.getArgOperand(3);
|
||||
Value *Shadow = getShadow(V);
|
||||
|
||||
Value *ShadowPtr;
|
||||
Value *OriginPtr;
|
||||
std::tie(ShadowPtr, OriginPtr) = getShadowOriginPtr(
|
||||
Addr, IRB, Shadow->getType(), Align, /*isStore*/ true);
|
||||
Addr, IRB, Shadow->getType(), Alignment, /*isStore*/ true);
|
||||
|
||||
if (ClCheckAccessAddress) {
|
||||
insertShadowCheck(Addr, &I);
|
||||
|
@ -2924,20 +2923,21 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
|
|||
insertShadowCheck(Mask, &I);
|
||||
}
|
||||
|
||||
IRB.CreateMaskedStore(Shadow, ShadowPtr, Align, Mask);
|
||||
IRB.CreateMaskedStore(Shadow, ShadowPtr, Alignment.value(), Mask);
|
||||
|
||||
if (MS.TrackOrigins) {
|
||||
auto &DL = F.getParent()->getDataLayout();
|
||||
paintOrigin(IRB, getOrigin(V), OriginPtr,
|
||||
DL.getTypeStoreSize(Shadow->getType()),
|
||||
std::max(Align, kMinOriginAlignment));
|
||||
std::max(Alignment, kMinOriginAlignment));
|
||||
}
|
||||
}
|
||||
|
||||
bool handleMaskedLoad(IntrinsicInst &I) {
|
||||
IRBuilder<> IRB(&I);
|
||||
Value *Addr = I.getArgOperand(0);
|
||||
unsigned Align = cast<ConstantInt>(I.getArgOperand(1))->getZExtValue();
|
||||
const Align Alignment =
|
||||
assumeAligned(cast<ConstantInt>(I.getArgOperand(1))->getZExtValue());
|
||||
Value *Mask = I.getArgOperand(2);
|
||||
Value *PassThru = I.getArgOperand(3);
|
||||
|
||||
|
@ -2945,8 +2945,8 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
|
|||
Value *ShadowPtr, *OriginPtr;
|
||||
if (PropagateShadow) {
|
||||
std::tie(ShadowPtr, OriginPtr) =
|
||||
getShadowOriginPtr(Addr, IRB, ShadowTy, Align, /*isStore*/ false);
|
||||
setShadow(&I, IRB.CreateMaskedLoad(ShadowPtr, Align, Mask,
|
||||
getShadowOriginPtr(Addr, IRB, ShadowTy, Alignment, /*isStore*/ false);
|
||||
setShadow(&I, IRB.CreateMaskedLoad(ShadowPtr, Alignment.value(), Mask,
|
||||
getShadow(PassThru), "_msmaskedld"));
|
||||
} else {
|
||||
setShadow(&I, getCleanShadow(&I));
|
||||
|
@ -3316,21 +3316,21 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
|
|||
"ByVal argument is not a pointer!");
|
||||
Size = DL.getTypeAllocSize(A->getType()->getPointerElementType());
|
||||
if (ArgOffset + Size > kParamTLSSize) break;
|
||||
unsigned ParamAlignment = CS.getParamAlignment(i);
|
||||
unsigned Alignment = std::min(ParamAlignment, kShadowTLSAlignment);
|
||||
const Align ParamAlignment = assumeAligned(CS.getParamAlignment(i));
|
||||
const Align Alignment = std::min(ParamAlignment, kShadowTLSAlignment);
|
||||
Value *AShadowPtr =
|
||||
getShadowOriginPtr(A, IRB, IRB.getInt8Ty(), Alignment,
|
||||
/*isStore*/ false)
|
||||
.first;
|
||||
|
||||
Store = IRB.CreateMemCpy(ArgShadowBase, Alignment, AShadowPtr,
|
||||
Alignment, Size);
|
||||
Store = IRB.CreateMemCpy(ArgShadowBase, Alignment.value(), AShadowPtr,
|
||||
Alignment.value(), Size);
|
||||
// TODO(glider): need to copy origins.
|
||||
} else {
|
||||
Size = DL.getTypeAllocSize(A->getType());
|
||||
if (ArgOffset + Size > kParamTLSSize) break;
|
||||
Store = IRB.CreateAlignedStore(ArgShadow, ArgShadowBase,
|
||||
kShadowTLSAlignment);
|
||||
kShadowTLSAlignment.value());
|
||||
Constant *Cst = dyn_cast<Constant>(ArgShadow);
|
||||
if (Cst && Cst->isNullValue()) ArgIsInitialized = true;
|
||||
}
|
||||
|
@ -3356,7 +3356,8 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
|
|||
IRBuilder<> IRBBefore(&I);
|
||||
// Until we have full dynamic coverage, make sure the retval shadow is 0.
|
||||
Value *Base = getShadowPtrForRetval(&I, IRBBefore);
|
||||
IRBBefore.CreateAlignedStore(getCleanShadow(&I), Base, kShadowTLSAlignment);
|
||||
IRBBefore.CreateAlignedStore(getCleanShadow(&I), Base,
|
||||
kShadowTLSAlignment.value());
|
||||
BasicBlock::iterator NextInsn;
|
||||
if (CS.isCall()) {
|
||||
NextInsn = ++I.getIterator();
|
||||
|
@ -3380,7 +3381,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
|
|||
IRBuilder<> IRBAfter(&*NextInsn);
|
||||
Value *RetvalShadow = IRBAfter.CreateAlignedLoad(
|
||||
getShadowTy(&I), getShadowPtrForRetval(&I, IRBAfter),
|
||||
kShadowTLSAlignment, "_msret");
|
||||
kShadowTLSAlignment.value(), "_msret");
|
||||
setShadow(&I, RetvalShadow);
|
||||
if (MS.TrackOrigins)
|
||||
setOrigin(&I, IRBAfter.CreateLoad(MS.OriginTy,
|
||||
|
@ -3407,10 +3408,10 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
|
|||
if (CheckReturnValue) {
|
||||
insertShadowCheck(RetVal, &I);
|
||||
Value *Shadow = getCleanShadow(RetVal);
|
||||
IRB.CreateAlignedStore(Shadow, ShadowPtr, kShadowTLSAlignment);
|
||||
IRB.CreateAlignedStore(Shadow, ShadowPtr, kShadowTLSAlignment.value());
|
||||
} else {
|
||||
Value *Shadow = getShadow(RetVal);
|
||||
IRB.CreateAlignedStore(Shadow, ShadowPtr, kShadowTLSAlignment);
|
||||
IRB.CreateAlignedStore(Shadow, ShadowPtr, kShadowTLSAlignment.value());
|
||||
if (MS.TrackOrigins)
|
||||
IRB.CreateStore(getOrigin(RetVal), getOriginPtrForRetval(IRB));
|
||||
}
|
||||
|
@ -3451,11 +3452,12 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
|
|||
{IRB.CreatePointerCast(&I, IRB.getInt8PtrTy()), Len});
|
||||
} else {
|
||||
Value *ShadowBase, *OriginBase;
|
||||
std::tie(ShadowBase, OriginBase) =
|
||||
getShadowOriginPtr(&I, IRB, IRB.getInt8Ty(), 1, /*isStore*/ true);
|
||||
std::tie(ShadowBase, OriginBase) = getShadowOriginPtr(
|
||||
&I, IRB, IRB.getInt8Ty(), Align::None(), /*isStore*/ true);
|
||||
|
||||
Value *PoisonValue = IRB.getInt8(PoisonStack ? ClPoisonStackPattern : 0);
|
||||
IRB.CreateMemSet(ShadowBase, PoisonValue, Len, I.getAlignment());
|
||||
IRB.CreateMemSet(ShadowBase, PoisonValue, Len,
|
||||
MaybeAlign(I.getAlignment()));
|
||||
}
|
||||
|
||||
if (PoisonStack && MS.TrackOrigins) {
|
||||
|
@ -3819,11 +3821,11 @@ struct VarArgAMD64Helper : public VarArgHelper {
|
|||
MSV.getShadowOriginPtr(A, IRB, IRB.getInt8Ty(), kShadowTLSAlignment,
|
||||
/*isStore*/ false);
|
||||
|
||||
IRB.CreateMemCpy(ShadowBase, kShadowTLSAlignment, ShadowPtr,
|
||||
kShadowTLSAlignment, ArgSize);
|
||||
IRB.CreateMemCpy(ShadowBase, kShadowTLSAlignment.value(), ShadowPtr,
|
||||
kShadowTLSAlignment.value(), ArgSize);
|
||||
if (MS.TrackOrigins)
|
||||
IRB.CreateMemCpy(OriginBase, kShadowTLSAlignment, OriginPtr,
|
||||
kShadowTLSAlignment, ArgSize);
|
||||
IRB.CreateMemCpy(OriginBase, kShadowTLSAlignment.value(), OriginPtr,
|
||||
kShadowTLSAlignment.value(), ArgSize);
|
||||
} else {
|
||||
ArgKind AK = classifyArgument(A);
|
||||
if (AK == AK_GeneralPurpose && GpOffset >= AMD64GpEndOffset)
|
||||
|
@ -3867,7 +3869,7 @@ struct VarArgAMD64Helper : public VarArgHelper {
|
|||
if (!ShadowBase)
|
||||
continue;
|
||||
Value *Shadow = MSV.getShadow(A);
|
||||
IRB.CreateAlignedStore(Shadow, ShadowBase, kShadowTLSAlignment);
|
||||
IRB.CreateAlignedStore(Shadow, ShadowBase, kShadowTLSAlignment.value());
|
||||
if (MS.TrackOrigins) {
|
||||
Value *Origin = MSV.getOrigin(A);
|
||||
unsigned StoreSize = DL.getTypeStoreSize(Shadow->getType());
|
||||
|
@ -3908,7 +3910,7 @@ struct VarArgAMD64Helper : public VarArgHelper {
|
|||
IRBuilder<> IRB(&I);
|
||||
Value *VAListTag = I.getArgOperand(0);
|
||||
Value *ShadowPtr, *OriginPtr;
|
||||
unsigned Alignment = 8;
|
||||
const Align Alignment = Align(8);
|
||||
std::tie(ShadowPtr, OriginPtr) =
|
||||
MSV.getShadowOriginPtr(VAListTag, IRB, IRB.getInt8Ty(), Alignment,
|
||||
/*isStore*/ true);
|
||||
|
@ -3968,15 +3970,16 @@ struct VarArgAMD64Helper : public VarArgHelper {
|
|||
Value *RegSaveAreaPtr =
|
||||
IRB.CreateLoad(RegSaveAreaPtrTy, RegSaveAreaPtrPtr);
|
||||
Value *RegSaveAreaShadowPtr, *RegSaveAreaOriginPtr;
|
||||
unsigned Alignment = 16;
|
||||
const Align Alignment = Align(16);
|
||||
std::tie(RegSaveAreaShadowPtr, RegSaveAreaOriginPtr) =
|
||||
MSV.getShadowOriginPtr(RegSaveAreaPtr, IRB, IRB.getInt8Ty(),
|
||||
Alignment, /*isStore*/ true);
|
||||
IRB.CreateMemCpy(RegSaveAreaShadowPtr, Alignment, VAArgTLSCopy, Alignment,
|
||||
AMD64FpEndOffset);
|
||||
IRB.CreateMemCpy(RegSaveAreaShadowPtr, Alignment.value(), VAArgTLSCopy,
|
||||
Alignment.value(), AMD64FpEndOffset);
|
||||
if (MS.TrackOrigins)
|
||||
IRB.CreateMemCpy(RegSaveAreaOriginPtr, Alignment, VAArgTLSOriginCopy,
|
||||
Alignment, AMD64FpEndOffset);
|
||||
IRB.CreateMemCpy(RegSaveAreaOriginPtr, Alignment.value(),
|
||||
VAArgTLSOriginCopy, Alignment.value(),
|
||||
AMD64FpEndOffset);
|
||||
Type *OverflowArgAreaPtrTy = Type::getInt64PtrTy(*MS.C);
|
||||
Value *OverflowArgAreaPtrPtr = IRB.CreateIntToPtr(
|
||||
IRB.CreateAdd(IRB.CreatePtrToInt(VAListTag, MS.IntptrTy),
|
||||
|
@ -3990,13 +3993,13 @@ struct VarArgAMD64Helper : public VarArgHelper {
|
|||
Alignment, /*isStore*/ true);
|
||||
Value *SrcPtr = IRB.CreateConstGEP1_32(IRB.getInt8Ty(), VAArgTLSCopy,
|
||||
AMD64FpEndOffset);
|
||||
IRB.CreateMemCpy(OverflowArgAreaShadowPtr, Alignment, SrcPtr, Alignment,
|
||||
VAArgOverflowSize);
|
||||
IRB.CreateMemCpy(OverflowArgAreaShadowPtr, Alignment.value(), SrcPtr,
|
||||
Alignment.value(), VAArgOverflowSize);
|
||||
if (MS.TrackOrigins) {
|
||||
SrcPtr = IRB.CreateConstGEP1_32(IRB.getInt8Ty(), VAArgTLSOriginCopy,
|
||||
AMD64FpEndOffset);
|
||||
IRB.CreateMemCpy(OverflowArgAreaOriginPtr, Alignment, SrcPtr, Alignment,
|
||||
VAArgOverflowSize);
|
||||
IRB.CreateMemCpy(OverflowArgAreaOriginPtr, Alignment.value(), SrcPtr,
|
||||
Alignment.value(), VAArgOverflowSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4036,7 +4039,8 @@ struct VarArgMIPS64Helper : public VarArgHelper {
|
|||
VAArgOffset = alignTo(VAArgOffset, 8);
|
||||
if (!Base)
|
||||
continue;
|
||||
IRB.CreateAlignedStore(MSV.getShadow(A), Base, kShadowTLSAlignment);
|
||||
IRB.CreateAlignedStore(MSV.getShadow(A), Base,
|
||||
kShadowTLSAlignment.value());
|
||||
}
|
||||
|
||||
Constant *TotalVAArgSize = ConstantInt::get(IRB.getInt64Ty(), VAArgOffset);
|
||||
|
@ -4062,7 +4066,7 @@ struct VarArgMIPS64Helper : public VarArgHelper {
|
|||
VAStartInstrumentationList.push_back(&I);
|
||||
Value *VAListTag = I.getArgOperand(0);
|
||||
Value *ShadowPtr, *OriginPtr;
|
||||
unsigned Alignment = 8;
|
||||
const Align Alignment = Align(8);
|
||||
std::tie(ShadowPtr, OriginPtr) = MSV.getShadowOriginPtr(
|
||||
VAListTag, IRB, IRB.getInt8Ty(), Alignment, /*isStore*/ true);
|
||||
IRB.CreateMemSet(ShadowPtr, Constant::getNullValue(IRB.getInt8Ty()),
|
||||
|
@ -4074,7 +4078,7 @@ struct VarArgMIPS64Helper : public VarArgHelper {
|
|||
VAStartInstrumentationList.push_back(&I);
|
||||
Value *VAListTag = I.getArgOperand(0);
|
||||
Value *ShadowPtr, *OriginPtr;
|
||||
unsigned Alignment = 8;
|
||||
const Align Alignment = Align(8);
|
||||
std::tie(ShadowPtr, OriginPtr) = MSV.getShadowOriginPtr(
|
||||
VAListTag, IRB, IRB.getInt8Ty(), Alignment, /*isStore*/ true);
|
||||
IRB.CreateMemSet(ShadowPtr, Constant::getNullValue(IRB.getInt8Ty()),
|
||||
|
@ -4109,12 +4113,12 @@ struct VarArgMIPS64Helper : public VarArgHelper {
|
|||
Value *RegSaveAreaPtr =
|
||||
IRB.CreateLoad(RegSaveAreaPtrTy, RegSaveAreaPtrPtr);
|
||||
Value *RegSaveAreaShadowPtr, *RegSaveAreaOriginPtr;
|
||||
unsigned Alignment = 8;
|
||||
const Align Alignment = Align(8);
|
||||
std::tie(RegSaveAreaShadowPtr, RegSaveAreaOriginPtr) =
|
||||
MSV.getShadowOriginPtr(RegSaveAreaPtr, IRB, IRB.getInt8Ty(),
|
||||
Alignment, /*isStore*/ true);
|
||||
IRB.CreateMemCpy(RegSaveAreaShadowPtr, Alignment, VAArgTLSCopy, Alignment,
|
||||
CopySize);
|
||||
IRB.CreateMemCpy(RegSaveAreaShadowPtr, Alignment.value(), VAArgTLSCopy,
|
||||
Alignment.value(), CopySize);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -4207,7 +4211,8 @@ struct VarArgAArch64Helper : public VarArgHelper {
|
|||
continue;
|
||||
if (!Base)
|
||||
continue;
|
||||
IRB.CreateAlignedStore(MSV.getShadow(A), Base, kShadowTLSAlignment);
|
||||
IRB.CreateAlignedStore(MSV.getShadow(A), Base,
|
||||
kShadowTLSAlignment.value());
|
||||
}
|
||||
Constant *OverflowSize =
|
||||
ConstantInt::get(IRB.getInt64Ty(), OverflowOffset - AArch64VAEndOffset);
|
||||
|
@ -4231,7 +4236,7 @@ struct VarArgAArch64Helper : public VarArgHelper {
|
|||
VAStartInstrumentationList.push_back(&I);
|
||||
Value *VAListTag = I.getArgOperand(0);
|
||||
Value *ShadowPtr, *OriginPtr;
|
||||
unsigned Alignment = 8;
|
||||
const Align Alignment = Align(8);
|
||||
std::tie(ShadowPtr, OriginPtr) = MSV.getShadowOriginPtr(
|
||||
VAListTag, IRB, IRB.getInt8Ty(), Alignment, /*isStore*/ true);
|
||||
IRB.CreateMemSet(ShadowPtr, Constant::getNullValue(IRB.getInt8Ty()),
|
||||
|
@ -4243,7 +4248,7 @@ struct VarArgAArch64Helper : public VarArgHelper {
|
|||
VAStartInstrumentationList.push_back(&I);
|
||||
Value *VAListTag = I.getArgOperand(0);
|
||||
Value *ShadowPtr, *OriginPtr;
|
||||
unsigned Alignment = 8;
|
||||
const Align Alignment = Align(8);
|
||||
std::tie(ShadowPtr, OriginPtr) = MSV.getShadowOriginPtr(
|
||||
VAListTag, IRB, IRB.getInt8Ty(), Alignment, /*isStore*/ true);
|
||||
IRB.CreateMemSet(ShadowPtr, Constant::getNullValue(IRB.getInt8Ty()),
|
||||
|
@ -4335,7 +4340,7 @@ struct VarArgAArch64Helper : public VarArgHelper {
|
|||
|
||||
Value *GrRegSaveAreaShadowPtr =
|
||||
MSV.getShadowOriginPtr(GrRegSaveAreaPtr, IRB, IRB.getInt8Ty(),
|
||||
/*Alignment*/ 8, /*isStore*/ true)
|
||||
Align(8), /*isStore*/ true)
|
||||
.first;
|
||||
|
||||
Value *GrSrcPtr = IRB.CreateInBoundsGEP(IRB.getInt8Ty(), VAArgTLSCopy,
|
||||
|
@ -4350,7 +4355,7 @@ struct VarArgAArch64Helper : public VarArgHelper {
|
|||
|
||||
Value *VrRegSaveAreaShadowPtr =
|
||||
MSV.getShadowOriginPtr(VrRegSaveAreaPtr, IRB, IRB.getInt8Ty(),
|
||||
/*Alignment*/ 8, /*isStore*/ true)
|
||||
Align(8), /*isStore*/ true)
|
||||
.first;
|
||||
|
||||
Value *VrSrcPtr = IRB.CreateInBoundsGEP(
|
||||
|
@ -4365,7 +4370,7 @@ struct VarArgAArch64Helper : public VarArgHelper {
|
|||
// And finally for remaining arguments.
|
||||
Value *StackSaveAreaShadowPtr =
|
||||
MSV.getShadowOriginPtr(StackSaveAreaPtr, IRB, IRB.getInt8Ty(),
|
||||
/*Alignment*/ 16, /*isStore*/ true)
|
||||
Align(16), /*isStore*/ true)
|
||||
.first;
|
||||
|
||||
Value *StackSrcPtr =
|
||||
|
@ -4433,8 +4438,8 @@ struct VarArgPowerPC64Helper : public VarArgHelper {
|
|||
MSV.getShadowOriginPtr(A, IRB, IRB.getInt8Ty(),
|
||||
kShadowTLSAlignment, /*isStore*/ false);
|
||||
|
||||
IRB.CreateMemCpy(Base, kShadowTLSAlignment, AShadowPtr,
|
||||
kShadowTLSAlignment, ArgSize);
|
||||
IRB.CreateMemCpy(Base, kShadowTLSAlignment.value(), AShadowPtr,
|
||||
kShadowTLSAlignment.value(), ArgSize);
|
||||
}
|
||||
}
|
||||
VAArgOffset += alignTo(ArgSize, 8);
|
||||
|
@ -4465,7 +4470,8 @@ struct VarArgPowerPC64Helper : public VarArgHelper {
|
|||
Base = getShadowPtrForVAArgument(A->getType(), IRB,
|
||||
VAArgOffset - VAArgBase, ArgSize);
|
||||
if (Base)
|
||||
IRB.CreateAlignedStore(MSV.getShadow(A), Base, kShadowTLSAlignment);
|
||||
IRB.CreateAlignedStore(MSV.getShadow(A), Base,
|
||||
kShadowTLSAlignment.value());
|
||||
}
|
||||
VAArgOffset += ArgSize;
|
||||
VAArgOffset = alignTo(VAArgOffset, 8);
|
||||
|
@ -4498,7 +4504,7 @@ struct VarArgPowerPC64Helper : public VarArgHelper {
|
|||
VAStartInstrumentationList.push_back(&I);
|
||||
Value *VAListTag = I.getArgOperand(0);
|
||||
Value *ShadowPtr, *OriginPtr;
|
||||
unsigned Alignment = 8;
|
||||
const Align Alignment = Align(8);
|
||||
std::tie(ShadowPtr, OriginPtr) = MSV.getShadowOriginPtr(
|
||||
VAListTag, IRB, IRB.getInt8Ty(), Alignment, /*isStore*/ true);
|
||||
IRB.CreateMemSet(ShadowPtr, Constant::getNullValue(IRB.getInt8Ty()),
|
||||
|
@ -4509,7 +4515,7 @@ struct VarArgPowerPC64Helper : public VarArgHelper {
|
|||
IRBuilder<> IRB(&I);
|
||||
Value *VAListTag = I.getArgOperand(0);
|
||||
Value *ShadowPtr, *OriginPtr;
|
||||
unsigned Alignment = 8;
|
||||
const Align Alignment = Align(8);
|
||||
std::tie(ShadowPtr, OriginPtr) = MSV.getShadowOriginPtr(
|
||||
VAListTag, IRB, IRB.getInt8Ty(), Alignment, /*isStore*/ true);
|
||||
// Unpoison the whole __va_list_tag.
|
||||
|
@ -4546,12 +4552,12 @@ struct VarArgPowerPC64Helper : public VarArgHelper {
|
|||
Value *RegSaveAreaPtr =
|
||||
IRB.CreateLoad(RegSaveAreaPtrTy, RegSaveAreaPtrPtr);
|
||||
Value *RegSaveAreaShadowPtr, *RegSaveAreaOriginPtr;
|
||||
unsigned Alignment = 8;
|
||||
const Align Alignment = Align(8);
|
||||
std::tie(RegSaveAreaShadowPtr, RegSaveAreaOriginPtr) =
|
||||
MSV.getShadowOriginPtr(RegSaveAreaPtr, IRB, IRB.getInt8Ty(),
|
||||
Alignment, /*isStore*/ true);
|
||||
IRB.CreateMemCpy(RegSaveAreaShadowPtr, Alignment, VAArgTLSCopy, Alignment,
|
||||
CopySize);
|
||||
IRB.CreateMemCpy(RegSaveAreaShadowPtr, Alignment.value(), VAArgTLSCopy,
|
||||
Alignment.value(), CopySize);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -791,8 +791,8 @@ static bool handleMemIntrinsicPtrUse(MemIntrinsic *MI, Value *OldV,
|
|||
MDNode *NoAliasMD = MI->getMetadata(LLVMContext::MD_noalias);
|
||||
|
||||
if (auto *MSI = dyn_cast<MemSetInst>(MI)) {
|
||||
B.CreateMemSet(NewV, MSI->getValue(),
|
||||
MSI->getLength(), MSI->getDestAlignment(),
|
||||
B.CreateMemSet(NewV, MSI->getValue(), MSI->getLength(),
|
||||
MaybeAlign(MSI->getDestAlignment()),
|
||||
false, // isVolatile
|
||||
TBAA, ScopeMD, NoAliasMD);
|
||||
} else if (auto *MTI = dyn_cast<MemTransferInst>(MI)) {
|
||||
|
|
|
@ -172,7 +172,7 @@ private:
|
|||
bool processLoopMemSet(MemSetInst *MSI, const SCEV *BECount);
|
||||
|
||||
bool processLoopStridedStore(Value *DestPtr, unsigned StoreSize,
|
||||
unsigned StoreAlignment, Value *StoredVal,
|
||||
MaybeAlign StoreAlignment, Value *StoredVal,
|
||||
Instruction *TheStore,
|
||||
SmallPtrSetImpl<Instruction *> &Stores,
|
||||
const SCEVAddRecExpr *Ev, const SCEV *BECount,
|
||||
|
@ -731,7 +731,8 @@ bool LoopIdiomRecognize::processLoopStores(SmallVectorImpl<StoreInst *> &SL,
|
|||
|
||||
bool NegStride = StoreSize == -Stride;
|
||||
|
||||
if (processLoopStridedStore(StorePtr, StoreSize, HeadStore->getAlignment(),
|
||||
if (processLoopStridedStore(StorePtr, StoreSize,
|
||||
MaybeAlign(HeadStore->getAlignment()),
|
||||
StoredVal, HeadStore, AdjacentStores, StoreEv,
|
||||
BECount, NegStride)) {
|
||||
TransformedStores.insert(AdjacentStores.begin(), AdjacentStores.end());
|
||||
|
@ -786,9 +787,9 @@ bool LoopIdiomRecognize::processLoopMemSet(MemSetInst *MSI,
|
|||
SmallPtrSet<Instruction *, 1> MSIs;
|
||||
MSIs.insert(MSI);
|
||||
bool NegStride = SizeInBytes == -Stride;
|
||||
return processLoopStridedStore(Pointer, (unsigned)SizeInBytes,
|
||||
MSI->getDestAlignment(), SplatValue, MSI, MSIs,
|
||||
Ev, BECount, NegStride, /*IsLoopMemset=*/true);
|
||||
return processLoopStridedStore(
|
||||
Pointer, (unsigned)SizeInBytes, MaybeAlign(MSI->getDestAlignment()),
|
||||
SplatValue, MSI, MSIs, Ev, BECount, NegStride, /*IsLoopMemset=*/true);
|
||||
}
|
||||
|
||||
/// mayLoopAccessLocation - Return true if the specified loop might access the
|
||||
|
@ -878,7 +879,7 @@ static const SCEV *getNumBytes(const SCEV *BECount, Type *IntPtr,
|
|||
/// processLoopStridedStore - We see a strided store of some value. If we can
|
||||
/// transform this into a memset or memset_pattern in the loop preheader, do so.
|
||||
bool LoopIdiomRecognize::processLoopStridedStore(
|
||||
Value *DestPtr, unsigned StoreSize, unsigned StoreAlignment,
|
||||
Value *DestPtr, unsigned StoreSize, MaybeAlign StoreAlignment,
|
||||
Value *StoredVal, Instruction *TheStore,
|
||||
SmallPtrSetImpl<Instruction *> &Stores, const SCEVAddRecExpr *Ev,
|
||||
const SCEV *BECount, bool NegStride, bool IsLoopMemset) {
|
||||
|
@ -945,8 +946,8 @@ bool LoopIdiomRecognize::processLoopStridedStore(
|
|||
|
||||
CallInst *NewCall;
|
||||
if (SplatValue) {
|
||||
NewCall =
|
||||
Builder.CreateMemSet(BasePtr, SplatValue, NumBytes, StoreAlignment);
|
||||
NewCall = Builder.CreateMemSet(BasePtr, SplatValue, NumBytes,
|
||||
MaybeAlign(StoreAlignment));
|
||||
} else {
|
||||
// Everything is emitted in default address space
|
||||
Type *Int8PtrTy = DestInt8PtrTy;
|
||||
|
|
|
@ -388,16 +388,12 @@ Instruction *MemCpyOptPass::tryMergingIntoMemset(Instruction *StartInst,
|
|||
StartPtr = Range.StartPtr;
|
||||
|
||||
// Determine alignment
|
||||
unsigned Alignment = Range.Alignment;
|
||||
if (Alignment == 0) {
|
||||
Type *EltType =
|
||||
cast<PointerType>(StartPtr->getType())->getElementType();
|
||||
Alignment = DL.getABITypeAlignment(EltType);
|
||||
}
|
||||
|
||||
AMemSet =
|
||||
Builder.CreateMemSet(StartPtr, ByteVal, Range.End-Range.Start, Alignment);
|
||||
const Align Alignment = DL.getValueOrABITypeAlignment(
|
||||
MaybeAlign(Range.Alignment),
|
||||
cast<PointerType>(StartPtr->getType())->getElementType());
|
||||
|
||||
AMemSet = Builder.CreateMemSet(StartPtr, ByteVal, Range.End - Range.Start,
|
||||
Alignment);
|
||||
LLVM_DEBUG(dbgs() << "Replace stores:\n"; for (Instruction *SI
|
||||
: Range.TheStores) dbgs()
|
||||
<< *SI << '\n';
|
||||
|
@ -683,12 +679,11 @@ bool MemCpyOptPass::processStore(StoreInst *SI, BasicBlock::iterator &BBI) {
|
|||
auto *T = V->getType();
|
||||
if (T->isAggregateType()) {
|
||||
uint64_t Size = DL.getTypeStoreSize(T);
|
||||
unsigned Align = SI->getAlignment();
|
||||
if (!Align)
|
||||
Align = DL.getABITypeAlignment(T);
|
||||
const Align MA =
|
||||
DL.getValueOrABITypeAlignment(MaybeAlign(SI->getAlignment()), T);
|
||||
IRBuilder<> Builder(SI);
|
||||
auto *M =
|
||||
Builder.CreateMemSet(SI->getPointerOperand(), ByteVal, Size, Align);
|
||||
Builder.CreateMemSet(SI->getPointerOperand(), ByteVal, Size, MA);
|
||||
|
||||
LLVM_DEBUG(dbgs() << "Promoting " << *SI << " to " << *M << "\n");
|
||||
|
||||
|
@ -1058,7 +1053,7 @@ bool MemCpyOptPass::processMemSetMemCpyDependence(MemCpyInst *MemCpy,
|
|||
Builder.CreateMemSet(
|
||||
Builder.CreateGEP(Dest->getType()->getPointerElementType(), Dest,
|
||||
SrcSize),
|
||||
MemSet->getOperand(1), MemsetLen, Align);
|
||||
MemSet->getOperand(1), MemsetLen, MaybeAlign(Align));
|
||||
|
||||
MD->removeInstruction(MemSet);
|
||||
MemSet->eraseFromParent();
|
||||
|
@ -1126,8 +1121,8 @@ bool MemCpyOptPass::performMemCpyToMemSetOptzn(MemCpyInst *MemCpy,
|
|||
}
|
||||
|
||||
IRBuilder<> Builder(MemCpy);
|
||||
Builder.CreateMemSet(MemCpy->getRawDest(), MemSet->getOperand(1),
|
||||
CopySize, MemCpy->getDestAlignment());
|
||||
Builder.CreateMemSet(MemCpy->getRawDest(), MemSet->getOperand(1), CopySize,
|
||||
MaybeAlign(MemCpy->getDestAlignment()));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1154,7 +1149,7 @@ bool MemCpyOptPass::processMemCpy(MemCpyInst *M) {
|
|||
M->getModule()->getDataLayout())) {
|
||||
IRBuilder<> Builder(M);
|
||||
Builder.CreateMemSet(M->getRawDest(), ByteVal, M->getLength(),
|
||||
M->getDestAlignment(), false);
|
||||
MaybeAlign(M->getDestAlignment()), false);
|
||||
MD->removeInstruction(M);
|
||||
M->eraseFromParent();
|
||||
++NumCpyToSet;
|
||||
|
|
|
@ -2801,7 +2801,7 @@ private:
|
|||
Constant *Size = ConstantInt::get(SizeTy, NewEndOffset - NewBeginOffset);
|
||||
CallInst *New = IRB.CreateMemSet(
|
||||
getNewAllocaSlicePtr(IRB, OldPtr->getType()), II.getValue(), Size,
|
||||
getSliceAlign(), II.isVolatile());
|
||||
MaybeAlign(getSliceAlign()), II.isVolatile());
|
||||
if (AATags)
|
||||
New->setAAMetadata(AATags);
|
||||
LLVM_DEBUG(dbgs() << " to: " << *New << "\n");
|
||||
|
|
|
@ -624,7 +624,7 @@ Value *LibCallSimplifier::optimizeStrNCpy(CallInst *CI, IRBuilder<> &B) {
|
|||
|
||||
if (SrcLen == 0) {
|
||||
// strncpy(x, "", y) -> memset(align 1 x, '\0', y)
|
||||
CallInst *NewCI = B.CreateMemSet(Dst, B.getInt8('\0'), Size, 1);
|
||||
CallInst *NewCI = B.CreateMemSet(Dst, B.getInt8('\0'), Size, Align::None());
|
||||
AttrBuilder ArgAttrs(CI->getAttributes().getParamAttributes(0));
|
||||
NewCI->setAttributes(NewCI->getAttributes().addParamAttributes(
|
||||
CI->getContext(), 0, ArgAttrs));
|
||||
|
@ -1235,7 +1235,8 @@ Value *LibCallSimplifier::optimizeMemSet(CallInst *CI, IRBuilder<> &B) {
|
|||
|
||||
// memset(p, v, n) -> llvm.memset(align 1 p, v, n)
|
||||
Value *Val = B.CreateIntCast(CI->getArgOperand(1), B.getInt8Ty(), false);
|
||||
CallInst *NewCI = B.CreateMemSet(CI->getArgOperand(0), Val, Size, 1);
|
||||
CallInst *NewCI =
|
||||
B.CreateMemSet(CI->getArgOperand(0), Val, Size, Align::None());
|
||||
NewCI->setAttributes(CI->getAttributes());
|
||||
return CI->getArgOperand(0);
|
||||
}
|
||||
|
@ -3290,8 +3291,8 @@ Value *FortifiedLibCallSimplifier::optimizeMemSetChk(CallInst *CI,
|
|||
|
||||
if (isFortifiedCallFoldable(CI, 3, 2)) {
|
||||
Value *Val = B.CreateIntCast(CI->getArgOperand(1), B.getInt8Ty(), false);
|
||||
CallInst *NewCI =
|
||||
B.CreateMemSet(CI->getArgOperand(0), Val, CI->getArgOperand(2), 1);
|
||||
CallInst *NewCI = B.CreateMemSet(CI->getArgOperand(0), Val,
|
||||
CI->getArgOperand(2), Align::None());
|
||||
NewCI->setAttributes(CI->getAttributes());
|
||||
return CI->getArgOperand(0);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue