mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-05 12:31:33 +00:00
Add CreateAlignmentAssumption to IRBuilder
Clang CodeGen had a utility function for creating pointer alignment assumptions using the @llvm.assume intrinsic. This functionality will also be needed by the inliner (to preserve function-argument alignment attributes when inlining), so this moves the utility function into IRBuilder where it can be used both by Clang CodeGen and also other LLVM-level code. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@219875 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
fb9d61a8d6
commit
76ce614af7
@ -429,6 +429,10 @@ public:
|
|||||||
/// If the pointer isn't i8* it will be converted.
|
/// If the pointer isn't i8* it will be converted.
|
||||||
CallInst *CreateLifetimeEnd(Value *Ptr, ConstantInt *Size = nullptr);
|
CallInst *CreateLifetimeEnd(Value *Ptr, ConstantInt *Size = nullptr);
|
||||||
|
|
||||||
|
/// \brief Create an assume intrinsic call that allows the optimizer to
|
||||||
|
/// assume that the provided condition will be true.
|
||||||
|
CallInst *CreateAssumption(Value *Cond);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Value *getCastedInt8PtrValue(Value *Ptr);
|
Value *getCastedInt8PtrValue(Value *Ptr);
|
||||||
};
|
};
|
||||||
@ -1524,6 +1528,44 @@ public:
|
|||||||
}
|
}
|
||||||
return V;
|
return V;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// \brief Create an assume intrinsic call that represents an alignment
|
||||||
|
/// assumption on the provided pointer.
|
||||||
|
///
|
||||||
|
/// An optional offset can be provided, and if it is provided, the offset
|
||||||
|
/// must be subtracted from the provided pointer to get the pointer with the
|
||||||
|
/// specified alignment.
|
||||||
|
CallInst *CreateAlignmentAssumption(const DataLayout &DL, Value *PtrValue,
|
||||||
|
unsigned Alignment,
|
||||||
|
Value *OffsetValue = nullptr) {
|
||||||
|
assert(isa<PointerType>(PtrValue->getType()) &&
|
||||||
|
"trying to create an alignment assumption on a non-pointer?");
|
||||||
|
|
||||||
|
PointerType *PtrTy = cast<PointerType>(PtrValue->getType());
|
||||||
|
Type *IntPtrTy = getIntPtrTy(&DL, PtrTy->getAddressSpace());
|
||||||
|
Value *PtrIntValue = CreatePtrToInt(PtrValue, IntPtrTy, "ptrint");
|
||||||
|
|
||||||
|
Value *Mask = ConstantInt::get(IntPtrTy,
|
||||||
|
Alignment > 0 ? Alignment - 1 : 0);
|
||||||
|
if (OffsetValue) {
|
||||||
|
bool IsOffsetZero = false;
|
||||||
|
if (ConstantInt *CI = dyn_cast<ConstantInt>(OffsetValue))
|
||||||
|
IsOffsetZero = CI->isZero();
|
||||||
|
|
||||||
|
if (!IsOffsetZero) {
|
||||||
|
if (OffsetValue->getType() != IntPtrTy)
|
||||||
|
OffsetValue = CreateIntCast(OffsetValue, IntPtrTy, /*isSigned*/ true,
|
||||||
|
"offsetcast");
|
||||||
|
PtrIntValue = CreateSub(PtrIntValue, OffsetValue, "offsetptr");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Value *Zero = ConstantInt::get(IntPtrTy, 0);
|
||||||
|
Value *MaskedPtr = CreateAnd(PtrIntValue, Mask, "maskedptr");
|
||||||
|
Value *InvCond = CreateICmpEQ(MaskedPtr, Zero, "maskcond");
|
||||||
|
|
||||||
|
return CreateAssumption(InvCond);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create wrappers for C Binding types (see CBindingWrapping.h).
|
// Create wrappers for C Binding types (see CBindingWrapping.h).
|
||||||
|
@ -172,3 +172,14 @@ CallInst *IRBuilderBase::CreateLifetimeEnd(Value *Ptr, ConstantInt *Size) {
|
|||||||
Value *TheFn = Intrinsic::getDeclaration(M, Intrinsic::lifetime_end);
|
Value *TheFn = Intrinsic::getDeclaration(M, Intrinsic::lifetime_end);
|
||||||
return createCallHelper(TheFn, Ops, this);
|
return createCallHelper(TheFn, Ops, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CallInst *IRBuilderBase::CreateAssumption(Value *Cond) {
|
||||||
|
assert(Cond->getType() == getInt1Ty() &&
|
||||||
|
"an assumption condition must be of type i1");
|
||||||
|
|
||||||
|
Value *Ops[] = { Cond };
|
||||||
|
Module *M = BB->getParent()->getParent();
|
||||||
|
Value *FnAssume = Intrinsic::getDeclaration(M, Intrinsic::assume);
|
||||||
|
return createCallHelper(FnAssume, Ops, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user