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
62 assert(OBU.getTagID() == LLVMContext::OB_SeparateStorage &&
63 OBU.Inputs.size() == 2);
64 return {OBU.Inputs[0], OBU.Inputs[1]};
65}
66
68 assert(OBU.getTagID() == LLVMContext::OB_NonNull && OBU.Inputs.size() == 1);
69 return {OBU.Inputs[0]};
70}
71
74 assert(OBU.getTagID() == LLVMContext::OB_Dereferenceable &&
75 OBU.Inputs.size() == 2);
76 AssumeDereferenceableInfo Ret{OBU.Inputs[0], OBU.Inputs[1], std::nullopt};
77
78 if (auto *Size = dyn_cast<ConstantInt>(OBU.Inputs[1]))
79 Ret.CountVal = Size->getZExtValue();
80 return Ret;
81}
82
83bool llvm::assumeBundleImpliesNonNull(const Value *Val, const Function *Context,
84 OperandBundleUse OBU) {
85 switch (getBundleAttrFromOBU(OBU)) {
86 case BundleAttr::Align: {
87 auto [Ptr, _, _2, Alignment, Offset] = getAssumeAlignInfo(OBU);
88 return Ptr == Val && Alignment && Offset && isPowerOf2_64(*Alignment) &&
89 *Offset % *Alignment != 0;
90 }
91
92 case BundleAttr::Dereferenceable: {
93 auto [Ptr, _, Count] = getAssumeDereferenceableInfo(OBU);
94 return Ptr == Val && Count && *Count != 0 &&
95 !NullPointerIsDefined(Context,
97 }
98
99 case BundleAttr::NonNull:
100 return getAssumeNonNullInfo(OBU).Ptr == Val;
101
102 default:
103 return false;
104 }
105}
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 _
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:255
#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:578
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 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