LLVM 24.0.0git
BundleAttributes.cpp
Go to the documentation of this file.
1//===- llvm/BundleAttributes.cpp - LLVM Bundle Attributes -------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10
11#include "llvm/IR/Constants.h"
12
13using namespace llvm;
14
16 switch (BA) {
17#define ATTR(Name, Str) \
18 case BundleAttr::Name: \
19 return #Str;
20#include "llvm/IR/BundleAttributes.def"
22 return "none";
23 }
24 llvm_unreachable("unknonwn bundle attribute");
25}
26
28 switch (ID) {
29#define ATTR(Name, Str) \
30 case LLVMContext::OB_##Name: \
31 return BundleAttr::Name;
32#include "llvm/IR/BundleAttributes.def"
33 default:
34 return BundleAttr::None;
35 }
36}
37
39 assert(OBU.getTagID() == LLVMContext::OB_Align && OBU.Inputs.size() >= 2 &&
40 OBU.Inputs.size() <= 3);
41 AssumeAlignInfo Ret{OBU.Inputs[0], OBU.Inputs[1], nullptr, std::nullopt,
42 std::nullopt};
43 if (auto *Align = dyn_cast<ConstantInt>(OBU.Inputs[1]))
44 Ret.AlignmentVal = Align->getZExtValue();
45 if (OBU.Inputs.size() == 3) {
46 Ret.Offset = &OBU.Inputs[2];
47 if (auto *Offset = dyn_cast<ConstantInt>(OBU.Inputs[2]))
48 Ret.OffsetVal = Offset->getZExtValue();
49 } else {
50 Ret.OffsetVal = 0;
51 }
52 return Ret;
53}
54
56 assert(OBU.getTagID() == LLVMContext::OB_NoUndef && OBU.Inputs.size() == 1);
57 return {OBU.Inputs[0]};
58}
59
61 assert(OBU.getTagID() == LLVMContext::OB_Range && OBU.Inputs.size() == 3);
62 return {OBU.Inputs[0],
63 ConstantRange(cast<ConstantInt>(OBU.Inputs[1])->getValue(),
64 cast<ConstantInt>(OBU.Inputs[2])->getValue())};
65}
66
69 assert(OBU.getTagID() == LLVMContext::OB_SeparateStorage &&
70 OBU.Inputs.size() == 2);
71 return {OBU.Inputs[0], OBU.Inputs[1]};
72}
73
75 assert(OBU.getTagID() == LLVMContext::OB_NonNull && OBU.Inputs.size() == 1);
76 return {OBU.Inputs[0]};
77}
78
81 assert(OBU.getTagID() == LLVMContext::OB_Dereferenceable &&
82 OBU.Inputs.size() == 2);
83 AssumeDereferenceableInfo Ret{OBU.Inputs[0], OBU.Inputs[1], std::nullopt};
84
85 if (auto *Size = dyn_cast<ConstantInt>(OBU.Inputs[1]))
86 Ret.CountVal = Size->getZExtValue();
87 return Ret;
88}
89
90bool llvm::assumeBundleImpliesNonNull(const Value *Val, const Function *Context,
91 OperandBundleUse OBU) {
92 switch (getBundleAttrFromOBU(OBU)) {
93 case BundleAttr::Align: {
94 auto [Ptr, _, _2, Alignment, Offset] = getAssumeAlignInfo(OBU);
95 return Ptr == Val && Alignment && Offset && isPowerOf2_64(*Alignment) &&
96 *Offset % *Alignment != 0;
97 }
98
99 case BundleAttr::Dereferenceable: {
100 auto [Ptr, _, Count] = getAssumeDereferenceableInfo(OBU);
101 return Ptr == Val && Count && *Count != 0 &&
102 !NullPointerIsDefined(Context,
104 }
105
106 case BundleAttr::NonNull:
107 return getAssumeNonNullInfo(OBU).Ptr == Val;
108
109 case BundleAttr::Range: {
110 auto [V, Range] = getAssumeRangeInfo(OBU);
111 return V == Val && !Range.contains(APInt::getZero(Range.getBitWidth()));
112 }
113
114 default:
115 return false;
116 }
117}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
#define _
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
static APInt getZero(unsigned numBits)
Get the '0' value for the specified bit-width.
Definition APInt.h:196
This class represents a range of values.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
LLVM_ABI unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:257
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
BundleAttr getBundleAttrFromOBU(OperandBundleUse OBU)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
LLVM_ABI AssumeSeparateStorageInfo getAssumeSeparateStorageInfo(OperandBundleUse)
LLVM_ABI bool assumeBundleImpliesNonNull(const Value *Val, const Function *Context, OperandBundleUse OBU)
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
Definition MathExtras.h:285
LLVM_ABI bool NullPointerIsDefined(const Function *F, unsigned AS=0)
Check whether null pointer dereferencing is considered undefined behavior for a given function or an ...
LLVM_ABI AssumeNonNullInfo getAssumeNonNullInfo(OperandBundleUse)
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
Definition InstrProf.h:145
LLVM_ABI StringRef getNameFromBundleAttr(BundleAttr)
LLVM_ABI AssumeRangeInfo getAssumeRangeInfo(OperandBundleUse)
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
LLVM_ABI AssumeAlignInfo getAssumeAlignInfo(OperandBundleUse)
LLVM_ABI BundleAttr getBundleAttrFromID(uint32_t)
LLVM_ABI AssumeDereferenceableInfo getAssumeDereferenceableInfo(OperandBundleUse)
LLVM_ABI AssumeNoUndefInfo getAssumeNoUndefInfo(OperandBundleUse)
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
std::optional< uint64_t > AlignmentVal
std::optional< uint64_t > OffsetVal
std::optional< uint64_t > CountVal
A lightweight accessor for an operand bundle meant to be passed around by value.
uint32_t getTagID() const
Return the tag of this operand bundle as an integer.
ArrayRef< Use > Inputs