LLVM 23.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
12#include "llvm/IR/Constants.h"
13
14using namespace llvm;
15
17 switch (BA) {
18#define ATTR(Name, Str) \
19 case BundleAttr::Name: \
20 return #Str;
21#include "llvm/IR/BundleAttributes.def"
23 return "none";
24 }
25 llvm_unreachable("unknonwn bundle attribute");
26}
27
29 switch (ID) {
30#define ATTR(Name, Str) \
31 case LLVMContext::OB_##Name: \
32 return BundleAttr::Name;
33#include "llvm/IR/BundleAttributes.def"
34 default:
35 return BundleAttr::None;
36 }
37}
38
40 assert(OBU.getTagID() == LLVMContext::OB_Align && OBU.Inputs.size() >= 2 &&
41 OBU.Inputs.size() <= 3);
42 AssumeAlignInfo Ret{OBU.Inputs[0], OBU.Inputs[1], nullptr, std::nullopt,
43 std::nullopt};
44 if (auto *Align = dyn_cast<ConstantInt>(OBU.Inputs[1]))
45 Ret.AlignmentVal = Align->getZExtValue();
46 if (OBU.Inputs.size() == 3) {
47 Ret.Offset = &OBU.Inputs[2];
48 if (auto *Offset = dyn_cast<ConstantInt>(OBU.Inputs[2]))
49 Ret.OffsetVal = Offset->getZExtValue();
50 } else {
51 Ret.OffsetVal = 0;
52 }
53 return Ret;
54}
55
57 assert(OBU.getTagID() == LLVMContext::OB_NoUndef && OBU.Inputs.size() == 1);
58 return {OBU.Inputs[0]};
59}
60
63 assert(OBU.getTagID() == LLVMContext::OB_SeparateStorage &&
64 OBU.Inputs.size() == 2);
65 return {OBU.Inputs[0], OBU.Inputs[1]};
66}
67
69 assert(OBU.getTagID() == LLVMContext::OB_NonNull && OBU.Inputs.size() == 1);
70 return {OBU.Inputs[0]};
71}
72
75 assert(OBU.getTagID() == LLVMContext::OB_Dereferenceable &&
76 OBU.Inputs.size() == 2);
77 AssumeDereferenceableInfo Ret{OBU.Inputs[0], OBU.Inputs[1], std::nullopt};
78
79 if (auto *Size = dyn_cast<ConstantInt>(OBU.Inputs[1]))
80 Ret.CountVal = Size->getZExtValue();
81 return Ret;
82}
83
84bool llvm::assumeBundleImpliesNonNull(const Value *Val, const Function *Context,
85 OperandBundleUse OBU) {
86 switch (getBundleAttrFromOBU(OBU)) {
87 case BundleAttr::Align: {
88 auto [Ptr, _, _2, Alignment, Offset] = getAssumeAlignInfo(OBU);
89 return Ptr == Val && Alignment && Offset && isPowerOf2_64(*Alignment) &&
90 *Offset % *Alignment != 0;
91 }
92
93 case BundleAttr::Dereferenceable: {
94 auto [Ptr, _, Count] = getAssumeDereferenceableInfo(OBU);
95 return Ptr == Val && Count && *Count != 0 &&
96 !NullPointerIsDefined(Context,
98 }
99
100 case BundleAttr::NonNull:
101 return getAssumeNonNullInfo(OBU).Ptr == Val;
102
103 default:
104 return false;
105 }
106}
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 _
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
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.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:558
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:284
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 ...
FunctionAddr VTableAddr Count
Definition InstrProf.h:139
LLVM_ABI AssumeNonNullInfo getAssumeNonNullInfo(OperandBundleUse)
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