CallInst *CreateAlignmentAssumption(const DataLayout &DL, Value *PtrValue,
Value *Alignment,
Value *OffsetValue = nullptr);
- /// Create an assume intrinsic call that represents a nonnull
- /// assumption on the provided pointer.
- CallInst *CreateNonNullAssumption(Value *PtrValue);
};
/// This provides a uniform API for creating instructions and inserting
return CreateAlignmentAssumptionHelper(DL, PtrValue, Alignment, OffsetValue);
}
-CallInst *IRBuilderBase::CreateNonNullAssumption(Value *PtrValue) {
- Value *Vals[] = { PtrValue };
- OperandBundleDefT<Value *> NonNullOpB("nonnull", Vals);
- return CreateAssumption(ConstantInt::getTrue(getContext()), {NonNullOpB});
-}
-
IRBuilderDefaultInserter::~IRBuilderDefaultInserter() = default;
IRBuilderCallbackInserter::~IRBuilderCallbackInserter() = default;
IRBuilderFolder::~IRBuilderFolder() = default;
}
}
-static void AddAssumptionsFromCallSiteAttrs(CallBase &CB, InlineFunctionInfo &IFI) {
- if (!IFI.GetAssumptionCache)
- return;
-
- AssumptionCache *AC = &IFI.GetAssumptionCache(*CB.getCaller());
- Function *CalledFunc = CB.getCalledFunction();
- IRBuilder<> Builder(&CB);
-
- for (Argument &Arg : CalledFunc->args()) {
- unsigned ArgNo = Arg.getArgNo();
- if (CB.paramHasAttr(ArgNo, Attribute::NonNull)) {
- CallInst *NewAsmp = Builder.CreateNonNullAssumption(CB.getArgOperand(ArgNo));
- AC->registerAssumption(cast<AssumeInst>(NewAsmp));
- }
- }
-}
-
static void HandleByValArgumentInit(Type *ByValType, Value *Dst, Value *Src,
Module *M, BasicBlock *InsertBlock,
InlineFunctionInfo &IFI,
VMap[&*I] = ActualArg;
}
- AddAssumptionsFromCallSiteAttrs(CB, IFI);
-
// TODO: Remove this when users have been updated to the assume bundles.
// Add alignment assumptions if necessary. We do this before the inlined
// instructions are actually cloned into the caller so that we can easily
define void @f(ptr %p, ptr %q, ptr %z) {
; CHECK-LABEL: define void @f
; CHECK-SAME: (ptr [[P:%.*]], ptr [[Q:%.*]], ptr [[Z:%.*]]) {
-; CHECK-NEXT: call void @llvm.assume(i1 true) [ "nonnull"(ptr [[P]]) ]
-; CHECK-NEXT: call void @llvm.assume(i1 true) [ "nonnull"(ptr [[Z]]) ]
; CHECK-NEXT: call void @h(ptr [[P]], ptr [[Q]], ptr [[Z]])
; CHECK-NEXT: ret void
;
define void @caller(ptr nonnull %arg) {
; CHECK-LABEL: define void @caller
; CHECK-SAME: (ptr nonnull [[ARG:%.*]]) {
-; CHECK-NEXT: call void @llvm.assume(i1 true) [ "nonnull"(ptr [[ARG]]) ]
; CHECK-NEXT: call void @bar()
; CHECK-NEXT: ret void
;
define void @caller3(ptr %arg) {
; CHECK-LABEL: define void @caller3
; CHECK-SAME: (ptr [[ARG:%.*]]) {
-; CHECK-NEXT: call void @llvm.assume(i1 true) [ "nonnull"(ptr [[ARG]]) ]
; CHECK-NEXT: [[CMP_I:%.*]] = icmp eq ptr [[ARG]], null
; CHECK-NEXT: br i1 [[CMP_I]], label [[EXPENSIVE_I:%.*]], label [[DONE_I:%.*]]
; CHECK: expensive.i: