clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name Function.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 1 -fhalf-no-semantic-interposition -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/gnu/usr.bin/clang/libLLVM/obj -resource-dir /usr/local/lib/clang/13.0.0 -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Analysis -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/ASMParser -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/BinaryFormat -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Bitcode -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Bitcode -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Bitstream -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /include/llvm/CodeGen -I /include/llvm/CodeGen/PBQP -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/IR -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/IR -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms/Coroutines -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/ProfileData/Coverage -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/DebugInfo/CodeView -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/DebugInfo/DWARF -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/DebugInfo -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/DebugInfo/MSF -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/DebugInfo/PDB -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Demangle -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/ExecutionEngine -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/ExecutionEngine/JITLink -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/ExecutionEngine/Orc -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Frontend -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Frontend/OpenACC -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Frontend -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Frontend/OpenMP -I /include/llvm/CodeGen/GlobalISel -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/IRReader -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms/InstCombine -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/Transforms/InstCombine -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/LTO -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Linker -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/MC -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/MC/MCParser -I /include/llvm/CodeGen/MIRParser -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Object -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Option -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Passes -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/ -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/ProfileData -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms/Scalar -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/ADT -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Support -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/DebugInfo/Symbolize -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Target -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms/Utils -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms/Vectorize -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms/IPO -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include -I /usr/src/gnu/usr.bin/clang/libLLVM/../include -I /usr/src/gnu/usr.bin/clang/libLLVM/obj -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include -D NDEBUG -D __STDC_LIMIT_MACROS -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D LLVM_PREFIX="/usr" -D PIC -internal-isystem /usr/include/c++/v1 -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-comment -std=c++14 -fdeprecated-macro -fdebug-compilation-dir=/usr/src/gnu/usr.bin/clang/libLLVM/obj -ferror-limit 19 -fvisibility-inlines-hidden -fwrapv -D_RET_PROTECTOR -ret-protector -fno-rtti -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/ben/Projects/vmm/scan-build/2022-01-12-194120-40624-1 -x c++ /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/IR/Function.cpp
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | #include "llvm/IR/Function.h" |
| 14 | #include "SymbolTableListTraitsImpl.h" |
| 15 | #include "llvm/ADT/ArrayRef.h" |
| 16 | #include "llvm/ADT/DenseSet.h" |
| 17 | #include "llvm/ADT/None.h" |
| 18 | #include "llvm/ADT/STLExtras.h" |
| 19 | #include "llvm/ADT/SmallString.h" |
| 20 | #include "llvm/ADT/SmallVector.h" |
| 21 | #include "llvm/ADT/StringExtras.h" |
| 22 | #include "llvm/ADT/StringRef.h" |
| 23 | #include "llvm/IR/AbstractCallSite.h" |
| 24 | #include "llvm/IR/Argument.h" |
| 25 | #include "llvm/IR/Attributes.h" |
| 26 | #include "llvm/IR/BasicBlock.h" |
| 27 | #include "llvm/IR/Constant.h" |
| 28 | #include "llvm/IR/Constants.h" |
| 29 | #include "llvm/IR/DerivedTypes.h" |
| 30 | #include "llvm/IR/GlobalValue.h" |
| 31 | #include "llvm/IR/InstIterator.h" |
| 32 | #include "llvm/IR/Instruction.h" |
| 33 | #include "llvm/IR/Instructions.h" |
| 34 | #include "llvm/IR/IntrinsicInst.h" |
| 35 | #include "llvm/IR/Intrinsics.h" |
| 36 | #include "llvm/IR/IntrinsicsAArch64.h" |
| 37 | #include "llvm/IR/IntrinsicsAMDGPU.h" |
| 38 | #include "llvm/IR/IntrinsicsARM.h" |
| 39 | #include "llvm/IR/IntrinsicsBPF.h" |
| 40 | #include "llvm/IR/IntrinsicsHexagon.h" |
| 41 | #include "llvm/IR/IntrinsicsMips.h" |
| 42 | #include "llvm/IR/IntrinsicsNVPTX.h" |
| 43 | #include "llvm/IR/IntrinsicsPowerPC.h" |
| 44 | #include "llvm/IR/IntrinsicsR600.h" |
| 45 | #include "llvm/IR/IntrinsicsRISCV.h" |
| 46 | #include "llvm/IR/IntrinsicsS390.h" |
| 47 | #include "llvm/IR/IntrinsicsVE.h" |
| 48 | #include "llvm/IR/IntrinsicsWebAssembly.h" |
| 49 | #include "llvm/IR/IntrinsicsX86.h" |
| 50 | #include "llvm/IR/IntrinsicsXCore.h" |
| 51 | #include "llvm/IR/LLVMContext.h" |
| 52 | #include "llvm/IR/MDBuilder.h" |
| 53 | #include "llvm/IR/Metadata.h" |
| 54 | #include "llvm/IR/Module.h" |
| 55 | #include "llvm/IR/Operator.h" |
| 56 | #include "llvm/IR/SymbolTableListTraits.h" |
| 57 | #include "llvm/IR/Type.h" |
| 58 | #include "llvm/IR/Use.h" |
| 59 | #include "llvm/IR/User.h" |
| 60 | #include "llvm/IR/Value.h" |
| 61 | #include "llvm/IR/ValueSymbolTable.h" |
| 62 | #include "llvm/Support/Casting.h" |
| 63 | #include "llvm/Support/CommandLine.h" |
| 64 | #include "llvm/Support/Compiler.h" |
| 65 | #include "llvm/Support/ErrorHandling.h" |
| 66 | #include <algorithm> |
| 67 | #include <cassert> |
| 68 | #include <cstddef> |
| 69 | #include <cstdint> |
| 70 | #include <cstring> |
| 71 | #include <string> |
| 72 | |
| 73 | using namespace llvm; |
| 74 | using ProfileCount = Function::ProfileCount; |
| 75 | |
| 76 | |
| 77 | |
| 78 | template class llvm::SymbolTableListTraits<BasicBlock>; |
| 79 | |
| 80 | static cl::opt<unsigned> NonGlobalValueMaxNameSize( |
| 81 | "non-global-value-max-name-size", cl::Hidden, cl::init(1024), |
| 82 | cl::desc("Maximum size for the name of non-global values.")); |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | Argument::Argument(Type *Ty, const Twine &Name, Function *Par, unsigned ArgNo) |
| 89 | : Value(Ty, Value::ArgumentVal), Parent(Par), ArgNo(ArgNo) { |
| 90 | setName(Name); |
| 91 | } |
| 92 | |
| 93 | void Argument::setParent(Function *parent) { |
| 94 | Parent = parent; |
| 95 | } |
| 96 | |
| 97 | bool Argument::hasNonNullAttr(bool AllowUndefOrPoison) const { |
| 98 | if (!getType()->isPointerTy()) return false; |
| 99 | if (getParent()->hasParamAttribute(getArgNo(), Attribute::NonNull) && |
| 100 | (AllowUndefOrPoison || |
| 101 | getParent()->hasParamAttribute(getArgNo(), Attribute::NoUndef))) |
| 102 | return true; |
| 103 | else if (getDereferenceableBytes() > 0 && |
| 104 | !NullPointerIsDefined(getParent(), |
| 105 | getType()->getPointerAddressSpace())) |
| 106 | return true; |
| 107 | return false; |
| 108 | } |
| 109 | |
| 110 | bool Argument::hasByValAttr() const { |
| 111 | if (!getType()->isPointerTy()) return false; |
| 112 | return hasAttribute(Attribute::ByVal); |
| 113 | } |
| 114 | |
| 115 | bool Argument::hasByRefAttr() const { |
| 116 | if (!getType()->isPointerTy()) |
| 117 | return false; |
| 118 | return hasAttribute(Attribute::ByRef); |
| 119 | } |
| 120 | |
| 121 | bool Argument::hasSwiftSelfAttr() const { |
| 122 | return getParent()->hasParamAttribute(getArgNo(), Attribute::SwiftSelf); |
| 123 | } |
| 124 | |
| 125 | bool Argument::hasSwiftErrorAttr() const { |
| 126 | return getParent()->hasParamAttribute(getArgNo(), Attribute::SwiftError); |
| 127 | } |
| 128 | |
| 129 | bool Argument::hasInAllocaAttr() const { |
| 130 | if (!getType()->isPointerTy()) return false; |
| 131 | return hasAttribute(Attribute::InAlloca); |
| 132 | } |
| 133 | |
| 134 | bool Argument::hasPreallocatedAttr() const { |
| 135 | if (!getType()->isPointerTy()) |
| 136 | return false; |
| 137 | return hasAttribute(Attribute::Preallocated); |
| 138 | } |
| 139 | |
| 140 | bool Argument::hasPassPointeeByValueCopyAttr() const { |
| 141 | if (!getType()->isPointerTy()) return false; |
| 142 | AttributeList Attrs = getParent()->getAttributes(); |
| 143 | return Attrs.hasParamAttribute(getArgNo(), Attribute::ByVal) || |
| 144 | Attrs.hasParamAttribute(getArgNo(), Attribute::InAlloca) || |
| 145 | Attrs.hasParamAttribute(getArgNo(), Attribute::Preallocated); |
| 146 | } |
| 147 | |
| 148 | bool Argument::hasPointeeInMemoryValueAttr() const { |
| 149 | if (!getType()->isPointerTy()) |
| 150 | return false; |
| 151 | AttributeList Attrs = getParent()->getAttributes(); |
| 152 | return Attrs.hasParamAttribute(getArgNo(), Attribute::ByVal) || |
| 153 | Attrs.hasParamAttribute(getArgNo(), Attribute::StructRet) || |
| 154 | Attrs.hasParamAttribute(getArgNo(), Attribute::InAlloca) || |
| 155 | Attrs.hasParamAttribute(getArgNo(), Attribute::Preallocated) || |
| 156 | Attrs.hasParamAttribute(getArgNo(), Attribute::ByRef); |
| 157 | } |
| 158 | |
| 159 | |
| 160 | |
| 161 | static Type *getMemoryParamAllocType(AttributeSet ParamAttrs, Type *ArgTy) { |
| 162 | |
| 163 | |
| 164 | if (Type *ByValTy = ParamAttrs.getByValType()) |
| 165 | return ByValTy; |
| 166 | if (Type *ByRefTy = ParamAttrs.getByRefType()) |
| 167 | return ByRefTy; |
| 168 | if (Type *PreAllocTy = ParamAttrs.getPreallocatedType()) |
| 169 | return PreAllocTy; |
| 170 | if (Type *InAllocaTy = ParamAttrs.getInAllocaType()) |
| 171 | return InAllocaTy; |
| 172 | if (Type *SRetTy = ParamAttrs.getStructRetType()) |
| 173 | return SRetTy; |
| 174 | |
| 175 | return nullptr; |
| 176 | } |
| 177 | |
| 178 | uint64_t Argument::getPassPointeeByValueCopySize(const DataLayout &DL) const { |
| 179 | AttributeSet ParamAttrs = |
| 180 | getParent()->getAttributes().getParamAttributes(getArgNo()); |
| 181 | if (Type *MemTy = getMemoryParamAllocType(ParamAttrs, getType())) |
| 182 | return DL.getTypeAllocSize(MemTy); |
| 183 | return 0; |
| 184 | } |
| 185 | |
| 186 | Type *Argument::getPointeeInMemoryValueType() const { |
| 187 | AttributeSet ParamAttrs = |
| 188 | getParent()->getAttributes().getParamAttributes(getArgNo()); |
| 189 | return getMemoryParamAllocType(ParamAttrs, getType()); |
| 190 | } |
| 191 | |
| 192 | unsigned Argument::getParamAlignment() const { |
| 193 | assert(getType()->isPointerTy() && "Only pointers have alignments"); |
| 194 | return getParent()->getParamAlignment(getArgNo()); |
| 195 | } |
| 196 | |
| 197 | MaybeAlign Argument::getParamAlign() const { |
| 198 | assert(getType()->isPointerTy() && "Only pointers have alignments"); |
| 199 | return getParent()->getParamAlign(getArgNo()); |
| 200 | } |
| 201 | |
| 202 | MaybeAlign Argument::getParamStackAlign() const { |
| 203 | return getParent()->getParamStackAlign(getArgNo()); |
| 204 | } |
| 205 | |
| 206 | Type *Argument::getParamByValType() const { |
| 207 | assert(getType()->isPointerTy() && "Only pointers have byval types"); |
| 208 | return getParent()->getParamByValType(getArgNo()); |
| 209 | } |
| 210 | |
| 211 | Type *Argument::getParamStructRetType() const { |
| 212 | assert(getType()->isPointerTy() && "Only pointers have sret types"); |
| 213 | return getParent()->getParamStructRetType(getArgNo()); |
| 214 | } |
| 215 | |
| 216 | Type *Argument::getParamByRefType() const { |
| 217 | assert(getType()->isPointerTy() && "Only pointers have byref types"); |
| 218 | return getParent()->getParamByRefType(getArgNo()); |
| 219 | } |
| 220 | |
| 221 | Type *Argument::getParamInAllocaType() const { |
| 222 | assert(getType()->isPointerTy() && "Only pointers have inalloca types"); |
| 223 | return getParent()->getParamInAllocaType(getArgNo()); |
| 224 | } |
| 225 | |
| 226 | uint64_t Argument::getDereferenceableBytes() const { |
| 227 | assert(getType()->isPointerTy() && |
| 228 | "Only pointers have dereferenceable bytes"); |
| 229 | return getParent()->getParamDereferenceableBytes(getArgNo()); |
| 230 | } |
| 231 | |
| 232 | uint64_t Argument::getDereferenceableOrNullBytes() const { |
| 233 | assert(getType()->isPointerTy() && |
| 234 | "Only pointers have dereferenceable bytes"); |
| 235 | return getParent()->getParamDereferenceableOrNullBytes(getArgNo()); |
| 236 | } |
| 237 | |
| 238 | bool Argument::hasNestAttr() const { |
| 239 | if (!getType()->isPointerTy()) return false; |
| 240 | return hasAttribute(Attribute::Nest); |
| 241 | } |
| 242 | |
| 243 | bool Argument::hasNoAliasAttr() const { |
| 244 | if (!getType()->isPointerTy()) return false; |
| 245 | return hasAttribute(Attribute::NoAlias); |
| 246 | } |
| 247 | |
| 248 | bool Argument::hasNoCaptureAttr() const { |
| 249 | if (!getType()->isPointerTy()) return false; |
| 250 | return hasAttribute(Attribute::NoCapture); |
| 251 | } |
| 252 | |
| 253 | bool Argument::hasNoFreeAttr() const { |
| 254 | if (!getType()->isPointerTy()) return false; |
| 255 | return hasAttribute(Attribute::NoFree); |
| 256 | } |
| 257 | |
| 258 | bool Argument::hasStructRetAttr() const { |
| 259 | if (!getType()->isPointerTy()) return false; |
| 260 | return hasAttribute(Attribute::StructRet); |
| 261 | } |
| 262 | |
| 263 | bool Argument::hasInRegAttr() const { |
| 264 | return hasAttribute(Attribute::InReg); |
| 265 | } |
| 266 | |
| 267 | bool Argument::hasReturnedAttr() const { |
| 268 | return hasAttribute(Attribute::Returned); |
| 269 | } |
| 270 | |
| 271 | bool Argument::hasZExtAttr() const { |
| 272 | return hasAttribute(Attribute::ZExt); |
| 273 | } |
| 274 | |
| 275 | bool Argument::hasSExtAttr() const { |
| 276 | return hasAttribute(Attribute::SExt); |
| 277 | } |
| 278 | |
| 279 | bool Argument::onlyReadsMemory() const { |
| 280 | AttributeList Attrs = getParent()->getAttributes(); |
| 281 | return Attrs.hasParamAttribute(getArgNo(), Attribute::ReadOnly) || |
| 282 | Attrs.hasParamAttribute(getArgNo(), Attribute::ReadNone); |
| 283 | } |
| 284 | |
| 285 | void Argument::addAttrs(AttrBuilder &B) { |
| 286 | AttributeList AL = getParent()->getAttributes(); |
| 287 | AL = AL.addParamAttributes(Parent->getContext(), getArgNo(), B); |
| 288 | getParent()->setAttributes(AL); |
| 289 | } |
| 290 | |
| 291 | void Argument::addAttr(Attribute::AttrKind Kind) { |
| 292 | getParent()->addParamAttr(getArgNo(), Kind); |
| 293 | } |
| 294 | |
| 295 | void Argument::addAttr(Attribute Attr) { |
| 296 | getParent()->addParamAttr(getArgNo(), Attr); |
| 297 | } |
| 298 | |
| 299 | void Argument::removeAttr(Attribute::AttrKind Kind) { |
| 300 | getParent()->removeParamAttr(getArgNo(), Kind); |
| 301 | } |
| 302 | |
| 303 | void Argument::removeAttrs(const AttrBuilder &B) { |
| 304 | AttributeList AL = getParent()->getAttributes(); |
| 305 | AL = AL.removeParamAttributes(Parent->getContext(), getArgNo(), B); |
| 306 | getParent()->setAttributes(AL); |
| 307 | } |
| 308 | |
| 309 | bool Argument::hasAttribute(Attribute::AttrKind Kind) const { |
| 310 | return getParent()->hasParamAttribute(getArgNo(), Kind); |
| 311 | } |
| 312 | |
| 313 | Attribute Argument::getAttribute(Attribute::AttrKind Kind) const { |
| 314 | return getParent()->getParamAttribute(getArgNo(), Kind); |
| 315 | } |
| 316 | |
| 317 | |
| 318 | |
| 319 | |
| 320 | |
| 321 | LLVMContext &Function::getContext() const { |
| 322 | return getType()->getContext(); |
| 323 | } |
| 324 | |
| 325 | unsigned Function::getInstructionCount() const { |
| 326 | unsigned NumInstrs = 0; |
| 327 | for (const BasicBlock &BB : BasicBlocks) |
| 328 | NumInstrs += std::distance(BB.instructionsWithoutDebug().begin(), |
| 329 | BB.instructionsWithoutDebug().end()); |
| 330 | return NumInstrs; |
| 331 | } |
| 332 | |
| 333 | Function *Function::Create(FunctionType *Ty, LinkageTypes Linkage, |
| 334 | const Twine &N, Module &M) { |
| 335 | return Create(Ty, Linkage, M.getDataLayout().getProgramAddressSpace(), N, &M); |
| 336 | } |
| 337 | |
| 338 | Function *Function::createWithDefaultAttr(FunctionType *Ty, |
| 339 | LinkageTypes Linkage, |
| 340 | unsigned AddrSpace, const Twine &N, |
| 341 | Module *M) { |
| 342 | auto *F = new Function(Ty, Linkage, AddrSpace, N, M); |
| 343 | AttrBuilder B; |
| 344 | if (M->getUwtable()) |
| 345 | B.addAttribute(Attribute::UWTable); |
| 346 | switch (M->getFramePointer()) { |
| 347 | case FramePointerKind::None: |
| 348 | |
| 349 | break; |
| 350 | case FramePointerKind::NonLeaf: |
| 351 | B.addAttribute("frame-pointer", "non-leaf"); |
| 352 | break; |
| 353 | case FramePointerKind::All: |
| 354 | B.addAttribute("frame-pointer", "all"); |
| 355 | break; |
| 356 | } |
| 357 | F->addAttributes(AttributeList::FunctionIndex, B); |
| 358 | return F; |
| 359 | } |
| 360 | |
| 361 | void Function::removeFromParent() { |
| 362 | getParent()->getFunctionList().remove(getIterator()); |
| 363 | } |
| 364 | |
| 365 | void Function::eraseFromParent() { |
| 366 | getParent()->getFunctionList().erase(getIterator()); |
| 367 | } |
| 368 | |
| 369 | |
| 370 | |
| 371 | |
| 372 | |
| 373 | static unsigned computeAddrSpace(unsigned AddrSpace, Module *M) { |
| 374 | |
| 375 | |
| 376 | if (AddrSpace == static_cast<unsigned>(-1)) |
| 377 | return M ? M->getDataLayout().getProgramAddressSpace() : 0; |
| 378 | return AddrSpace; |
| 379 | } |
| 380 | |
| 381 | Function::Function(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, |
| 382 | const Twine &name, Module *ParentModule) |
| 383 | : GlobalObject(Ty, Value::FunctionVal, |
| 384 | OperandTraits<Function>::op_begin(this), 0, Linkage, name, |
| 385 | computeAddrSpace(AddrSpace, ParentModule)), |
| 386 | NumArgs(Ty->getNumParams()) { |
| 387 | assert(FunctionType::isValidReturnType(getReturnType()) && |
| 388 | "invalid return type"); |
| 389 | setGlobalObjectSubClassData(0); |
| 390 | |
| 391 | |
| 392 | if (!getContext().shouldDiscardValueNames()) |
| 393 | SymTab = std::make_unique<ValueSymbolTable>(NonGlobalValueMaxNameSize); |
| 394 | |
| 395 | |
| 396 | if (Ty->getNumParams()) |
| 397 | setValueSubclassData(1); |
| 398 | |
| 399 | if (ParentModule) |
| 400 | ParentModule->getFunctionList().push_back(this); |
| 401 | |
| 402 | HasLLVMReservedName = getName().startswith("llvm."); |
| 403 | |
| 404 | |
| 405 | |
| 406 | if (IntID) |
| 407 | setAttributes(Intrinsic::getAttributes(getContext(), IntID)); |
| 408 | } |
| 409 | |
| 410 | Function::~Function() { |
| 411 | dropAllReferences(); |
| 412 | |
| 413 | |
| 414 | if (Arguments) |
| 415 | clearArguments(); |
| 416 | |
| 417 | |
| 418 | clearGC(); |
| 419 | } |
| 420 | |
| 421 | void Function::BuildLazyArguments() const { |
| 422 | |
| 423 | auto *FT = getFunctionType(); |
| 424 | if (NumArgs > 0) { |
| 425 | Arguments = std::allocator<Argument>().allocate(NumArgs); |
| 426 | for (unsigned i = 0, e = NumArgs; i != e; ++i) { |
| 427 | Type *ArgTy = FT->getParamType(i); |
| 428 | assert(!ArgTy->isVoidTy() && "Cannot have void typed arguments!"); |
| 429 | new (Arguments + i) Argument(ArgTy, "", const_cast<Function *>(this), i); |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | |
| 434 | unsigned SDC = getSubclassDataFromValue(); |
| 435 | SDC &= ~(1 << 0); |
| 436 | const_cast<Function*>(this)->setValueSubclassData(SDC); |
| 437 | assert(!hasLazyArguments()); |
| 438 | } |
| 439 | |
| 440 | static MutableArrayRef<Argument> makeArgArray(Argument *Args, size_t Count) { |
| 441 | return MutableArrayRef<Argument>(Args, Count); |
| 442 | } |
| 443 | |
| 444 | bool Function::isConstrainedFPIntrinsic() const { |
| 445 | switch (getIntrinsicID()) { |
| 446 | #define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC) \ |
| 447 | case Intrinsic::INTRINSIC: |
| 448 | #include "llvm/IR/ConstrainedOps.def" |
| 449 | return true; |
| 450 | #undef INSTRUCTION |
| 451 | default: |
| 452 | return false; |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | void Function::clearArguments() { |
| 457 | for (Argument &A : makeArgArray(Arguments, NumArgs)) { |
| 458 | A.setName(""); |
| 459 | A.~Argument(); |
| 460 | } |
| 461 | std::allocator<Argument>().deallocate(Arguments, NumArgs); |
| 462 | Arguments = nullptr; |
| 463 | } |
| 464 | |
| 465 | void Function::stealArgumentListFrom(Function &Src) { |
| 466 | assert(isDeclaration() && "Expected no references to current arguments"); |
| 467 | |
| 468 | |
| 469 | if (!hasLazyArguments()) { |
| 470 | assert(llvm::all_of(makeArgArray(Arguments, NumArgs), |
| 471 | [](const Argument &A) { return A.use_empty(); }) && |
| 472 | "Expected arguments to be unused in declaration"); |
| 473 | clearArguments(); |
| 474 | setValueSubclassData(getSubclassDataFromValue() | (1 << 0)); |
| 475 | } |
| 476 | |
| 477 | |
| 478 | if (Src.hasLazyArguments()) |
| 479 | return; |
| 480 | |
| 481 | |
| 482 | assert(arg_size() == Src.arg_size()); |
| 483 | Arguments = Src.Arguments; |
| 484 | Src.Arguments = nullptr; |
| 485 | for (Argument &A : makeArgArray(Arguments, NumArgs)) { |
| 486 | |
| 487 | SmallString<128> Name; |
| 488 | if (A.hasName()) |
| 489 | Name = A.getName(); |
| 490 | if (!Name.empty()) |
| 491 | A.setName(""); |
| 492 | A.setParent(this); |
| 493 | if (!Name.empty()) |
| 494 | A.setName(Name); |
| 495 | } |
| 496 | |
| 497 | setValueSubclassData(getSubclassDataFromValue() & ~(1 << 0)); |
| 498 | assert(!hasLazyArguments()); |
| 499 | Src.setValueSubclassData(Src.getSubclassDataFromValue() | (1 << 0)); |
| 500 | } |
| 501 | |
| 502 | |
| 503 | |
| 504 | |
| 505 | |
| 506 | |
| 507 | |
| 508 | |
| 509 | |
| 510 | void Function::dropAllReferences() { |
| 511 | setIsMaterializable(false); |
| 512 | |
| 513 | for (BasicBlock &BB : *this) |
| 514 | BB.dropAllReferences(); |
| 515 | |
| 516 | |
| 517 | |
| 518 | while (!BasicBlocks.empty()) |
| 519 | BasicBlocks.begin()->eraseFromParent(); |
| 520 | |
| 521 | |
| 522 | if (getNumOperands()) { |
| 523 | User::dropAllReferences(); |
| 524 | setNumHungOffUseOperands(0); |
| 525 | setValueSubclassData(getSubclassDataFromValue() & ~0xe); |
| 526 | } |
| 527 | |
| 528 | |
| 529 | clearMetadata(); |
| 530 | } |
| 531 | |
| 532 | void Function::addAttribute(unsigned i, Attribute::AttrKind Kind) { |
| 533 | AttributeList PAL = getAttributes(); |
| 534 | PAL = PAL.addAttribute(getContext(), i, Kind); |
| 535 | setAttributes(PAL); |
| 536 | } |
| 537 | |
| 538 | void Function::addAttribute(unsigned i, Attribute Attr) { |
| 539 | AttributeList PAL = getAttributes(); |
| 540 | PAL = PAL.addAttribute(getContext(), i, Attr); |
| 541 | setAttributes(PAL); |
| 542 | } |
| 543 | |
| 544 | void Function::addAttributes(unsigned i, const AttrBuilder &Attrs) { |
| 545 | AttributeList PAL = getAttributes(); |
| 546 | PAL = PAL.addAttributes(getContext(), i, Attrs); |
| 547 | setAttributes(PAL); |
| 548 | } |
| 549 | |
| 550 | void Function::addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) { |
| 551 | AttributeList PAL = getAttributes(); |
| 552 | PAL = PAL.addParamAttribute(getContext(), ArgNo, Kind); |
| 553 | setAttributes(PAL); |
| 554 | } |
| 555 | |
| 556 | void Function::addParamAttr(unsigned ArgNo, Attribute Attr) { |
| 557 | AttributeList PAL = getAttributes(); |
| 558 | PAL = PAL.addParamAttribute(getContext(), ArgNo, Attr); |
| 559 | setAttributes(PAL); |
| 560 | } |
| 561 | |
| 562 | void Function::addParamAttrs(unsigned ArgNo, const AttrBuilder &Attrs) { |
| 563 | AttributeList PAL = getAttributes(); |
| 564 | PAL = PAL.addParamAttributes(getContext(), ArgNo, Attrs); |
| 565 | setAttributes(PAL); |
| 566 | } |
| 567 | |
| 568 | void Function::removeAttribute(unsigned i, Attribute::AttrKind Kind) { |
| 569 | AttributeList PAL = getAttributes(); |
| 570 | PAL = PAL.removeAttribute(getContext(), i, Kind); |
| 571 | setAttributes(PAL); |
| 572 | } |
| 573 | |
| 574 | void Function::removeAttribute(unsigned i, StringRef Kind) { |
| 575 | AttributeList PAL = getAttributes(); |
| 576 | PAL = PAL.removeAttribute(getContext(), i, Kind); |
| 577 | setAttributes(PAL); |
| 578 | } |
| 579 | |
| 580 | void Function::removeAttributes(unsigned i, const AttrBuilder &Attrs) { |
| 581 | AttributeList PAL = getAttributes(); |
| 582 | PAL = PAL.removeAttributes(getContext(), i, Attrs); |
| 583 | setAttributes(PAL); |
| 584 | } |
| 585 | |
| 586 | void Function::removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) { |
| 587 | AttributeList PAL = getAttributes(); |
| 588 | PAL = PAL.removeParamAttribute(getContext(), ArgNo, Kind); |
| 589 | setAttributes(PAL); |
| 590 | } |
| 591 | |
| 592 | void Function::removeParamAttr(unsigned ArgNo, StringRef Kind) { |
| 593 | AttributeList PAL = getAttributes(); |
| 594 | PAL = PAL.removeParamAttribute(getContext(), ArgNo, Kind); |
| 595 | setAttributes(PAL); |
| 596 | } |
| 597 | |
| 598 | void Function::removeParamAttrs(unsigned ArgNo, const AttrBuilder &Attrs) { |
| 599 | AttributeList PAL = getAttributes(); |
| 600 | PAL = PAL.removeParamAttributes(getContext(), ArgNo, Attrs); |
| 601 | setAttributes(PAL); |
| 602 | } |
| 603 | |
| 604 | void Function::addDereferenceableAttr(unsigned i, uint64_t Bytes) { |
| 605 | AttributeList PAL = getAttributes(); |
| 606 | PAL = PAL.addDereferenceableAttr(getContext(), i, Bytes); |
| 607 | setAttributes(PAL); |
| 608 | } |
| 609 | |
| 610 | void Function::addDereferenceableParamAttr(unsigned ArgNo, uint64_t Bytes) { |
| 611 | AttributeList PAL = getAttributes(); |
| 612 | PAL = PAL.addDereferenceableParamAttr(getContext(), ArgNo, Bytes); |
| 613 | setAttributes(PAL); |
| 614 | } |
| 615 | |
| 616 | void Function::addDereferenceableOrNullAttr(unsigned i, uint64_t Bytes) { |
| 617 | AttributeList PAL = getAttributes(); |
| 618 | PAL = PAL.addDereferenceableOrNullAttr(getContext(), i, Bytes); |
| 619 | setAttributes(PAL); |
| 620 | } |
| 621 | |
| 622 | void Function::addDereferenceableOrNullParamAttr(unsigned ArgNo, |
| 623 | uint64_t Bytes) { |
| 624 | AttributeList PAL = getAttributes(); |
| 625 | PAL = PAL.addDereferenceableOrNullParamAttr(getContext(), ArgNo, Bytes); |
| 626 | setAttributes(PAL); |
| 627 | } |
| 628 | |
| 629 | DenormalMode Function::getDenormalMode(const fltSemantics &FPType) const { |
| 630 | if (&FPType == &APFloat::IEEEsingle()) { |
| 631 | Attribute Attr = getFnAttribute("denormal-fp-math-f32"); |
| 632 | StringRef Val = Attr.getValueAsString(); |
| 633 | if (!Val.empty()) |
| 634 | return parseDenormalFPAttribute(Val); |
| 635 | |
| 636 | |
| 637 | |
| 638 | } |
| 639 | |
| 640 | Attribute Attr = getFnAttribute("denormal-fp-math"); |
| 641 | return parseDenormalFPAttribute(Attr.getValueAsString()); |
| 642 | } |
| 643 | |
| 644 | const std::string &Function::getGC() const { |
| 645 | assert(hasGC() && "Function has no collector"); |
| 646 | return getContext().getGC(*this); |
| 647 | } |
| 648 | |
| 649 | void Function::setGC(std::string Str) { |
| 650 | setValueSubclassDataBit(14, !Str.empty()); |
| 651 | getContext().setGC(*this, std::move(Str)); |
| 652 | } |
| 653 | |
| 654 | void Function::clearGC() { |
| 655 | if (!hasGC()) |
| 656 | return; |
| 657 | getContext().deleteGC(*this); |
| 658 | setValueSubclassDataBit(14, false); |
| 659 | } |
| 660 | |
| 661 | bool Function::hasStackProtectorFnAttr() const { |
| 662 | return hasFnAttribute(Attribute::StackProtect) || |
| 663 | hasFnAttribute(Attribute::StackProtectStrong) || |
| 664 | hasFnAttribute(Attribute::StackProtectReq); |
| 665 | } |
| 666 | |
| 667 | |
| 668 | |
| 669 | void Function::copyAttributesFrom(const Function *Src) { |
| 670 | GlobalObject::copyAttributesFrom(Src); |
| 671 | setCallingConv(Src->getCallingConv()); |
| 672 | setAttributes(Src->getAttributes()); |
| 673 | if (Src->hasGC()) |
| 674 | setGC(Src->getGC()); |
| 675 | else |
| 676 | clearGC(); |
| 677 | if (Src->hasPersonalityFn()) |
| 678 | setPersonalityFn(Src->getPersonalityFn()); |
| 679 | if (Src->hasPrefixData()) |
| 680 | setPrefixData(Src->getPrefixData()); |
| 681 | if (Src->hasPrologueData()) |
| 682 | setPrologueData(Src->getPrologueData()); |
| 683 | } |
| 684 | |
| 685 | |
| 686 | static const char * const IntrinsicNameTable[] = { |
| 687 | "not_intrinsic", |
| 688 | #define GET_INTRINSIC_NAME_TABLE |
| 689 | #include "llvm/IR/IntrinsicImpl.inc" |
| 690 | #undef GET_INTRINSIC_NAME_TABLE |
| 691 | }; |
| 692 | |
| 693 | |
| 694 | #define GET_INTRINSIC_TARGET_DATA |
| 695 | #include "llvm/IR/IntrinsicImpl.inc" |
| 696 | #undef GET_INTRINSIC_TARGET_DATA |
| 697 | |
| 698 | bool Function::isTargetIntrinsic(Intrinsic::ID IID) { |
| 699 | return IID > TargetInfos[0].Count; |
| 700 | } |
| 701 | |
| 702 | bool Function::isTargetIntrinsic() const { |
| 703 | return isTargetIntrinsic(IntID); |
| 704 | } |
| 705 | |
| 706 | |
| 707 | |
| 708 | |
| 709 | |
| 710 | static ArrayRef<const char *> findTargetSubtable(StringRef Name) { |
| 711 | assert(Name.startswith("llvm.")); |
| 712 | |
| 713 | ArrayRef<IntrinsicTargetInfo> Targets(TargetInfos); |
| 714 | |
| 715 | |
| 716 | StringRef Target = Name.drop_front(5).split('.').first; |
| 717 | auto It = partition_point( |
| 718 | Targets, [=](const IntrinsicTargetInfo &TI) { return TI.Name < Target; }); |
| 719 | |
| 720 | |
| 721 | const auto &TI = It != Targets.end() && It->Name == Target ? *It : Targets[0]; |
| 722 | return makeArrayRef(&IntrinsicNameTable[1] + TI.Offset, TI.Count); |
| 723 | } |
| 724 | |
| 725 | |
| 726 | |
| 727 | Intrinsic::ID Function::lookupIntrinsicID(StringRef Name) { |
| 728 | ArrayRef<const char *> NameTable = findTargetSubtable(Name); |
| 729 | int Idx = Intrinsic::lookupLLVMIntrinsicByName(NameTable, Name); |
| 730 | if (Idx == -1) |
| 731 | return Intrinsic::not_intrinsic; |
| 732 | |
| 733 | |
| 734 | |
| 735 | int Adjust = NameTable.data() - IntrinsicNameTable; |
| 736 | Intrinsic::ID ID = static_cast<Intrinsic::ID>(Idx + Adjust); |
| 737 | |
| 738 | |
| 739 | |
| 740 | const auto MatchSize = strlen(NameTable[Idx]); |
| 741 | assert(Name.size() >= MatchSize && "Expected either exact or prefix match"); |
| 742 | bool IsExactMatch = Name.size() == MatchSize; |
| 743 | return IsExactMatch || Intrinsic::isOverloaded(ID) ? ID |
| 744 | : Intrinsic::not_intrinsic; |
| 745 | } |
| 746 | |
| 747 | void Function::recalculateIntrinsicID() { |
| 748 | StringRef Name = getName(); |
| 749 | if (!Name.startswith("llvm.")) { |
| 750 | HasLLVMReservedName = false; |
| 751 | IntID = Intrinsic::not_intrinsic; |
| 752 | return; |
| 753 | } |
| 754 | HasLLVMReservedName = true; |
| 755 | IntID = lookupIntrinsicID(Name); |
| 756 | } |
| 757 | |
| 758 | |
| 759 | |
| 760 | |
| 761 | |
| 762 | |
| 763 | |
| 764 | |
| 765 | |
| 766 | |
| 767 | |
| 768 | |
| 769 | |
| 770 | static std::string getMangledTypeStr(Type *Ty, bool &HasUnnamedType) { |
| 771 | std::string Result; |
| 772 | if (PointerType *PTyp = dyn_cast<PointerType>(Ty)) { |
| 773 | Result += "p" + utostr(PTyp->getAddressSpace()); |
| 774 | |
| 775 | |
| 776 | if (!PTyp->isOpaque()) |
| 777 | Result += getMangledTypeStr(PTyp->getElementType(), HasUnnamedType); |
| 778 | } else if (ArrayType *ATyp = dyn_cast<ArrayType>(Ty)) { |
| 779 | Result += "a" + utostr(ATyp->getNumElements()) + |
| 780 | getMangledTypeStr(ATyp->getElementType(), HasUnnamedType); |
| 781 | } else if (StructType *STyp = dyn_cast<StructType>(Ty)) { |
| 782 | if (!STyp->isLiteral()) { |
| 783 | Result += "s_"; |
| 784 | if (STyp->hasName()) |
| 785 | Result += STyp->getName(); |
| 786 | else |
| 787 | HasUnnamedType = true; |
| 788 | } else { |
| 789 | Result += "sl_"; |
| 790 | for (auto Elem : STyp->elements()) |
| 791 | Result += getMangledTypeStr(Elem, HasUnnamedType); |
| 792 | } |
| 793 | |
| 794 | Result += "s"; |
| 795 | } else if (FunctionType *FT = dyn_cast<FunctionType>(Ty)) { |
| 796 | Result += "f_" + getMangledTypeStr(FT->getReturnType(), HasUnnamedType); |
| 797 | for (size_t i = 0; i < FT->getNumParams(); i++) |
| 798 | Result += getMangledTypeStr(FT->getParamType(i), HasUnnamedType); |
| 799 | if (FT->isVarArg()) |
| 800 | Result += "vararg"; |
| 801 | |
| 802 | Result += "f"; |
| 803 | } else if (VectorType *VTy = dyn_cast<VectorType>(Ty)) { |
| 804 | ElementCount EC = VTy->getElementCount(); |
| 805 | if (EC.isScalable()) |
| 806 | Result += "nx"; |
| 807 | Result += "v" + utostr(EC.getKnownMinValue()) + |
| 808 | getMangledTypeStr(VTy->getElementType(), HasUnnamedType); |
| 809 | } else if (Ty) { |
| 810 | switch (Ty->getTypeID()) { |
| 811 | default: llvm_unreachable("Unhandled type"); |
| 812 | case Type::VoidTyID: Result += "isVoid"; break; |
| 813 | case Type::MetadataTyID: Result += "Metadata"; break; |
| 814 | case Type::HalfTyID: Result += "f16"; break; |
| 815 | case Type::BFloatTyID: Result += "bf16"; break; |
| 816 | case Type::FloatTyID: Result += "f32"; break; |
| 817 | case Type::DoubleTyID: Result += "f64"; break; |
| 818 | case Type::X86_FP80TyID: Result += "f80"; break; |
| 819 | case Type::FP128TyID: Result += "f128"; break; |
| 820 | case Type::PPC_FP128TyID: Result += "ppcf128"; break; |
| 821 | case Type::X86_MMXTyID: Result += "x86mmx"; break; |
| 822 | case Type::X86_AMXTyID: Result += "x86amx"; break; |
| 823 | case Type::IntegerTyID: |
| 824 | Result += "i" + utostr(cast<IntegerType>(Ty)->getBitWidth()); |
| 825 | break; |
| 826 | } |
| 827 | } |
| 828 | return Result; |
| 829 | } |
| 830 | |
| 831 | StringRef Intrinsic::getBaseName(ID id) { |
| 832 | assert(id < num_intrinsics && "Invalid intrinsic ID!"); |
| 833 | return IntrinsicNameTable[id]; |
| 834 | } |
| 835 | |
| 836 | StringRef Intrinsic::getName(ID id) { |
| 837 | assert(id < num_intrinsics && "Invalid intrinsic ID!"); |
| 838 | assert(!Intrinsic::isOverloaded(id) && |
| 839 | "This version of getName does not support overloading"); |
| 840 | return getBaseName(id); |
| 841 | } |
| 842 | |
| 843 | static std::string getIntrinsicNameImpl(Intrinsic::ID Id, ArrayRef<Type *> Tys, |
| 844 | Module *M, FunctionType *FT, |
| 845 | bool EarlyModuleCheck) { |
| 846 | |
| 847 | assert(Id < Intrinsic::num_intrinsics && "Invalid intrinsic ID!"); |
| 848 | assert((Tys.empty() || Intrinsic::isOverloaded(Id)) && |
| 849 | "This version of getName is for overloaded intrinsics only"); |
| 850 | (void)EarlyModuleCheck; |
| 851 | assert((!EarlyModuleCheck || M || |
| 852 | !any_of(Tys, [](Type *T) { return isa<PointerType>(T); })) && |
| 853 | "Intrinsic overloading on pointer types need to provide a Module"); |
| 854 | bool HasUnnamedType = false; |
| 855 | std::string Result(Intrinsic::getBaseName(Id)); |
| 856 | for (Type *Ty : Tys) |
| 4 | | Assuming '__begin1' is not equal to '__end1' | |
|
| 857 | Result += "." + getMangledTypeStr(Ty, HasUnnamedType); |
| 858 | if (HasUnnamedType) { |
| 5 | | Assuming 'HasUnnamedType' is true | |
|
| |
| 859 | assert(M && "unnamed types need a module"); |
| 860 | if (!FT) |
| |
| |
| 861 | FT = Intrinsic::getType(M->getContext(), Id, Tys); |
| |
| 862 | else |
| 863 | assert((FT == Intrinsic::getType(M->getContext(), Id, Tys)) && |
| 864 | "Provided FunctionType must match arguments"); |
| 865 | return M->getUniqueIntrinsicName(Result, Id, FT); |
| 866 | } |
| 867 | return Result; |
| 868 | } |
| 869 | |
| 870 | std::string Intrinsic::getName(ID Id, ArrayRef<Type *> Tys, Module *M, |
| 871 | FunctionType *FT) { |
| 872 | assert(M && "We need to have a Module"); |
| 873 | return getIntrinsicNameImpl(Id, Tys, M, FT, true); |
| 3 | | Calling 'getIntrinsicNameImpl' | |
|
| 874 | } |
| 875 | |
| 876 | std::string Intrinsic::getNameNoUnnamedTypes(ID Id, ArrayRef<Type *> Tys) { |
| 877 | return getIntrinsicNameImpl(Id, Tys, nullptr, nullptr, false); |
| 878 | } |
| 879 | |
| 880 | |
| 881 | |
| 882 | |
| 883 | |
| 884 | enum IIT_Info { |
| 885 | |
| 886 | IIT_Done = 0, |
| 887 | IIT_I1 = 1, |
| 888 | IIT_I8 = 2, |
| 889 | IIT_I16 = 3, |
| 890 | IIT_I32 = 4, |
| 891 | IIT_I64 = 5, |
| 892 | IIT_F16 = 6, |
| 893 | IIT_F32 = 7, |
| 894 | IIT_F64 = 8, |
| 895 | IIT_V2 = 9, |
| 896 | IIT_V4 = 10, |
| 897 | IIT_V8 = 11, |
| 898 | IIT_V16 = 12, |
| 899 | IIT_V32 = 13, |
| 900 | IIT_PTR = 14, |
| 901 | IIT_ARG = 15, |
| 902 | |
| 903 | |
| 904 | IIT_V64 = 16, |
| 905 | IIT_MMX = 17, |
| 906 | IIT_TOKEN = 18, |
| 907 | IIT_METADATA = 19, |
| 908 | IIT_EMPTYSTRUCT = 20, |
| 909 | IIT_STRUCT2 = 21, |
| 910 | IIT_STRUCT3 = 22, |
| 911 | IIT_STRUCT4 = 23, |
| 912 | IIT_STRUCT5 = 24, |
| 913 | IIT_EXTEND_ARG = 25, |
| 914 | IIT_TRUNC_ARG = 26, |
| 915 | IIT_ANYPTR = 27, |
| 916 | IIT_V1 = 28, |
| 917 | IIT_VARARG = 29, |
| 918 | IIT_HALF_VEC_ARG = 30, |
| 919 | IIT_SAME_VEC_WIDTH_ARG = 31, |
| 920 | IIT_PTR_TO_ARG = 32, |
| 921 | IIT_PTR_TO_ELT = 33, |
| 922 | IIT_VEC_OF_ANYPTRS_TO_ELT = 34, |
| 923 | IIT_I128 = 35, |
| 924 | IIT_V512 = 36, |
| 925 | IIT_V1024 = 37, |
| 926 | IIT_STRUCT6 = 38, |
| 927 | IIT_STRUCT7 = 39, |
| 928 | IIT_STRUCT8 = 40, |
| 929 | IIT_F128 = 41, |
| 930 | IIT_VEC_ELEMENT = 42, |
| 931 | IIT_SCALABLE_VEC = 43, |
| 932 | IIT_SUBDIVIDE2_ARG = 44, |
| 933 | IIT_SUBDIVIDE4_ARG = 45, |
| 934 | IIT_VEC_OF_BITCASTS_TO_INT = 46, |
| 935 | IIT_V128 = 47, |
| 936 | IIT_BF16 = 48, |
| 937 | IIT_STRUCT9 = 49, |
| 938 | IIT_V256 = 50, |
| 939 | IIT_AMX = 51 |
| 940 | }; |
| 941 | |
| 942 | static void DecodeIITType(unsigned &NextElt, ArrayRef<unsigned char> Infos, |
| 943 | IIT_Info LastInfo, |
| 944 | SmallVectorImpl<Intrinsic::IITDescriptor> &OutputTable) { |
| 945 | using namespace Intrinsic; |
| 946 | |
| 947 | bool IsScalableVector = (LastInfo == IIT_SCALABLE_VEC); |
| 948 | |
| 949 | IIT_Info Info = IIT_Info(Infos[NextElt++]); |
| 950 | unsigned StructElts = 2; |
| 951 | |
| 952 | switch (Info) { |
| 953 | case IIT_Done: |
| 954 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::Void, 0)); |
| 955 | return; |
| 956 | case IIT_VARARG: |
| 957 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::VarArg, 0)); |
| 958 | return; |
| 959 | case IIT_MMX: |
| 960 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::MMX, 0)); |
| 961 | return; |
| 962 | case IIT_AMX: |
| 963 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::AMX, 0)); |
| 964 | return; |
| 965 | case IIT_TOKEN: |
| 966 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::Token, 0)); |
| 967 | return; |
| 968 | case IIT_METADATA: |
| 969 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::Metadata, 0)); |
| 970 | return; |
| 971 | case IIT_F16: |
| 972 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::Half, 0)); |
| 973 | return; |
| 974 | case IIT_BF16: |
| 975 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::BFloat, 0)); |
| 976 | return; |
| 977 | case IIT_F32: |
| 978 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::Float, 0)); |
| 979 | return; |
| 980 | case IIT_F64: |
| 981 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::Double, 0)); |
| 982 | return; |
| 983 | case IIT_F128: |
| 984 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::Quad, 0)); |
| 985 | return; |
| 986 | case IIT_I1: |
| 987 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 1)); |
| 988 | return; |
| 989 | case IIT_I8: |
| 990 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 8)); |
| 991 | return; |
| 992 | case IIT_I16: |
| 993 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer,16)); |
| 994 | return; |
| 995 | case IIT_I32: |
| 996 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 32)); |
| 997 | return; |
| 998 | case IIT_I64: |
| 999 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 64)); |
| 1000 | return; |
| 1001 | case IIT_I128: |
| 1002 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 128)); |
| 1003 | return; |
| 1004 | case IIT_V1: |
| 1005 | OutputTable.push_back(IITDescriptor::getVector(1, IsScalableVector)); |
| 1006 | DecodeIITType(NextElt, Infos, Info, OutputTable); |
| 1007 | return; |
| 1008 | case IIT_V2: |
| 1009 | OutputTable.push_back(IITDescriptor::getVector(2, IsScalableVector)); |
| 1010 | DecodeIITType(NextElt, Infos, Info, OutputTable); |
| 1011 | return; |
| 1012 | case IIT_V4: |
| 1013 | OutputTable.push_back(IITDescriptor::getVector(4, IsScalableVector)); |
| 1014 | DecodeIITType(NextElt, Infos, Info, OutputTable); |
| 1015 | return; |
| 1016 | case IIT_V8: |
| 1017 | OutputTable.push_back(IITDescriptor::getVector(8, IsScalableVector)); |
| 1018 | DecodeIITType(NextElt, Infos, Info, OutputTable); |
| 1019 | return; |
| 1020 | case IIT_V16: |
| 1021 | OutputTable.push_back(IITDescriptor::getVector(16, IsScalableVector)); |
| 1022 | DecodeIITType(NextElt, Infos, Info, OutputTable); |
| 1023 | return; |
| 1024 | case IIT_V32: |
| 1025 | OutputTable.push_back(IITDescriptor::getVector(32, IsScalableVector)); |
| 1026 | DecodeIITType(NextElt, Infos, Info, OutputTable); |
| 1027 | return; |
| 1028 | case IIT_V64: |
| 1029 | OutputTable.push_back(IITDescriptor::getVector(64, IsScalableVector)); |
| 1030 | DecodeIITType(NextElt, Infos, Info, OutputTable); |
| 1031 | return; |
| 1032 | case IIT_V128: |
| 1033 | OutputTable.push_back(IITDescriptor::getVector(128, IsScalableVector)); |
| 1034 | DecodeIITType(NextElt, Infos, Info, OutputTable); |
| 1035 | return; |
| 1036 | case IIT_V256: |
| 1037 | OutputTable.push_back(IITDescriptor::getVector(256, IsScalableVector)); |
| 1038 | DecodeIITType(NextElt, Infos, Info, OutputTable); |
| 1039 | return; |
| 1040 | case IIT_V512: |
| 1041 | OutputTable.push_back(IITDescriptor::getVector(512, IsScalableVector)); |
| 1042 | DecodeIITType(NextElt, Infos, Info, OutputTable); |
| 1043 | return; |
| 1044 | case IIT_V1024: |
| 1045 | OutputTable.push_back(IITDescriptor::getVector(1024, IsScalableVector)); |
| 1046 | DecodeIITType(NextElt, Infos, Info, OutputTable); |
| 1047 | return; |
| 1048 | case IIT_PTR: |
| 1049 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::Pointer, 0)); |
| 1050 | DecodeIITType(NextElt, Infos, Info, OutputTable); |
| 1051 | return; |
| 1052 | case IIT_ANYPTR: { |
| 1053 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::Pointer, |
| 1054 | Infos[NextElt++])); |
| 1055 | DecodeIITType(NextElt, Infos, Info, OutputTable); |
| 1056 | return; |
| 1057 | } |
| 1058 | case IIT_ARG: { |
| 1059 | unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]); |
| 1060 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::Argument, ArgInfo)); |
| 1061 | return; |
| 1062 | } |
| 1063 | case IIT_EXTEND_ARG: { |
| 1064 | unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]); |
| 1065 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::ExtendArgument, |
| 1066 | ArgInfo)); |
| 1067 | return; |
| 1068 | } |
| 1069 | case IIT_TRUNC_ARG: { |
| 1070 | unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]); |
| 1071 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::TruncArgument, |
| 1072 | ArgInfo)); |
| 1073 | return; |
| 1074 | } |
| 1075 | case IIT_HALF_VEC_ARG: { |
| 1076 | unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]); |
| 1077 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::HalfVecArgument, |
| 1078 | ArgInfo)); |
| 1079 | return; |
| 1080 | } |
| 1081 | case IIT_SAME_VEC_WIDTH_ARG: { |
| 1082 | unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]); |
| 1083 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::SameVecWidthArgument, |
| 1084 | ArgInfo)); |
| 1085 | return; |
| 1086 | } |
| 1087 | case IIT_PTR_TO_ARG: { |
| 1088 | unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]); |
| 1089 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::PtrToArgument, |
| 1090 | ArgInfo)); |
| 1091 | return; |
| 1092 | } |
| 1093 | case IIT_PTR_TO_ELT: { |
| 1094 | unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]); |
| 1095 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::PtrToElt, ArgInfo)); |
| 1096 | return; |
| 1097 | } |
| 1098 | case IIT_VEC_OF_ANYPTRS_TO_ELT: { |
| 1099 | unsigned short ArgNo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]); |
| 1100 | unsigned short RefNo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]); |
| 1101 | OutputTable.push_back( |
| 1102 | IITDescriptor::get(IITDescriptor::VecOfAnyPtrsToElt, ArgNo, RefNo)); |
| 1103 | return; |
| 1104 | } |
| 1105 | case IIT_EMPTYSTRUCT: |
| 1106 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::Struct, 0)); |
| 1107 | return; |
| 1108 | case IIT_STRUCT9: ++StructElts; LLVM_FALLTHROUGH; |
| 1109 | case IIT_STRUCT8: ++StructElts; LLVM_FALLTHROUGH; |
| 1110 | case IIT_STRUCT7: ++StructElts; LLVM_FALLTHROUGH; |
| 1111 | case IIT_STRUCT6: ++StructElts; LLVM_FALLTHROUGH; |
| 1112 | case IIT_STRUCT5: ++StructElts; LLVM_FALLTHROUGH; |
| 1113 | case IIT_STRUCT4: ++StructElts; LLVM_FALLTHROUGH; |
| 1114 | case IIT_STRUCT3: ++StructElts; LLVM_FALLTHROUGH; |
| 1115 | case IIT_STRUCT2: { |
| 1116 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::Struct,StructElts)); |
| 1117 | |
| 1118 | for (unsigned i = 0; i != StructElts; ++i) |
| 1119 | DecodeIITType(NextElt, Infos, Info, OutputTable); |
| 1120 | return; |
| 1121 | } |
| 1122 | case IIT_SUBDIVIDE2_ARG: { |
| 1123 | unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]); |
| 1124 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::Subdivide2Argument, |
| 1125 | ArgInfo)); |
| 1126 | return; |
| 1127 | } |
| 1128 | case IIT_SUBDIVIDE4_ARG: { |
| 1129 | unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]); |
| 1130 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::Subdivide4Argument, |
| 1131 | ArgInfo)); |
| 1132 | return; |
| 1133 | } |
| 1134 | case IIT_VEC_ELEMENT: { |
| 1135 | unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]); |
| 1136 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::VecElementArgument, |
| 1137 | ArgInfo)); |
| 1138 | return; |
| 1139 | } |
| 1140 | case IIT_SCALABLE_VEC: { |
| 1141 | DecodeIITType(NextElt, Infos, Info, OutputTable); |
| 1142 | return; |
| 1143 | } |
| 1144 | case IIT_VEC_OF_BITCASTS_TO_INT: { |
| 1145 | unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]); |
| 1146 | OutputTable.push_back(IITDescriptor::get(IITDescriptor::VecOfBitcastsToInt, |
| 1147 | ArgInfo)); |
| 1148 | return; |
| 1149 | } |
| 1150 | } |
| 1151 | llvm_unreachable("unhandled"); |
| 1152 | } |
| 1153 | |
| 1154 | #define GET_INTRINSIC_GENERATOR_GLOBAL |
| 1155 | #include "llvm/IR/IntrinsicImpl.inc" |
| 1156 | #undef GET_INTRINSIC_GENERATOR_GLOBAL |
| 1157 | |
| 1158 | void Intrinsic::getIntrinsicInfoTableEntries(ID id, |
| 1159 | SmallVectorImpl<IITDescriptor> &T){ |
| 1160 | |
| 1161 | unsigned TableVal = IIT_Table[id-1]; |
| 1162 | |
| 1163 | |
| 1164 | SmallVector<unsigned char, 8> IITValues; |
| 1165 | ArrayRef<unsigned char> IITEntries; |
| 1166 | unsigned NextElt = 0; |
| 1167 | if ((TableVal >> 31) != 0) { |
| 1168 | |
| 1169 | IITEntries = IIT_LongEncodingTable; |
| 1170 | |
| 1171 | |
| 1172 | NextElt = (TableVal << 1) >> 1; |
| 1173 | } else { |
| 1174 | |
| 1175 | |
| 1176 | do { |
| 1177 | IITValues.push_back(TableVal & 0xF); |
| 1178 | TableVal >>= 4; |
| 1179 | } while (TableVal); |
| 1180 | |
| 1181 | IITEntries = IITValues; |
| 1182 | NextElt = 0; |
| 1183 | } |
| 1184 | |
| 1185 | |
| 1186 | DecodeIITType(NextElt, IITEntries, IIT_Done, T); |
| 1187 | while (NextElt != IITEntries.size() && IITEntries[NextElt] != 0) |
| 1188 | DecodeIITType(NextElt, IITEntries, IIT_Done, T); |
| 1189 | } |
| 1190 | |
| 1191 | static Type *DecodeFixedType(ArrayRef<Intrinsic::IITDescriptor> &Infos, |
| 1192 | ArrayRef<Type*> Tys, LLVMContext &Context) { |
| 1193 | using namespace Intrinsic; |
| 1194 | |
| 1195 | IITDescriptor D = Infos.front(); |
| 1196 | Infos = Infos.slice(1); |
| 1197 | |
| 1198 | switch (D.Kind) { |
| 11 | | Control jumps to 'case Subdivide4Argument:' at line 1244 | |
|
| 1199 | case IITDescriptor::Void: return Type::getVoidTy(Context); |
| 1200 | case IITDescriptor::VarArg: return Type::getVoidTy(Context); |
| 1201 | case IITDescriptor::MMX: return Type::getX86_MMXTy(Context); |
| 1202 | case IITDescriptor::AMX: return Type::getX86_AMXTy(Context); |
| 1203 | case IITDescriptor::Token: return Type::getTokenTy(Context); |
| 1204 | case IITDescriptor::Metadata: return Type::getMetadataTy(Context); |
| 1205 | case IITDescriptor::Half: return Type::getHalfTy(Context); |
| 1206 | case IITDescriptor::BFloat: return Type::getBFloatTy(Context); |
| 1207 | case IITDescriptor::Float: return Type::getFloatTy(Context); |
| 1208 | case IITDescriptor::Double: return Type::getDoubleTy(Context); |
| 1209 | case IITDescriptor::Quad: return Type::getFP128Ty(Context); |
| 1210 | |
| 1211 | case IITDescriptor::Integer: |
| 1212 | return IntegerType::get(Context, D.Integer_Width); |
| 1213 | case IITDescriptor::Vector: |
| 1214 | return VectorType::get(DecodeFixedType(Infos, Tys, Context), |
| 1215 | D.Vector_Width); |
| 1216 | case IITDescriptor::Pointer: |
| 1217 | return PointerType::get(DecodeFixedType(Infos, Tys, Context), |
| 1218 | D.Pointer_AddressSpace); |
| 1219 | case IITDescriptor::Struct: { |
| 1220 | SmallVector<Type *, 8> Elts; |
| 1221 | for (unsigned i = 0, e = D.Struct_NumElements; i != e; ++i) |
| 1222 | Elts.push_back(DecodeFixedType(Infos, Tys, Context)); |
| 1223 | return StructType::get(Context, Elts); |
| 1224 | } |
| 1225 | case IITDescriptor::Argument: |
| 1226 | return Tys[D.getArgumentNumber()]; |
| 1227 | case IITDescriptor::ExtendArgument: { |
| 1228 | Type *Ty = Tys[D.getArgumentNumber()]; |
| 1229 | if (VectorType *VTy = dyn_cast<VectorType>(Ty)) |
| 1230 | return VectorType::getExtendedElementVectorType(VTy); |
| 1231 | |
| 1232 | return IntegerType::get(Context, 2 * cast<IntegerType>(Ty)->getBitWidth()); |
| 1233 | } |
| 1234 | case IITDescriptor::TruncArgument: { |
| 1235 | Type *Ty = Tys[D.getArgumentNumber()]; |
| 1236 | if (VectorType *VTy = dyn_cast<VectorType>(Ty)) |
| 1237 | return VectorType::getTruncatedElementVectorType(VTy); |
| 1238 | |
| 1239 | IntegerType *ITy = cast<IntegerType>(Ty); |
| 1240 | assert(ITy->getBitWidth() % 2 == 0); |
| 1241 | return IntegerType::get(Context, ITy->getBitWidth() / 2); |
| 1242 | } |
| 1243 | case IITDescriptor::Subdivide2Argument: |
| 1244 | case IITDescriptor::Subdivide4Argument: { |
| 1245 | Type *Ty = Tys[D.getArgumentNumber()]; |
| 1246 | VectorType *VTy = dyn_cast<VectorType>(Ty); |
| 12 | | Assuming 'Ty' is not a 'VectorType' | |
|
| 13 | | 'VTy' initialized to a null pointer value | |
|
| 1247 | assert(VTy && "Expected an argument of Vector Type"); |
| 1248 | int SubDivs = D.Kind == IITDescriptor::Subdivide2Argument ? 1 : 2; |
| 14 | | Assuming field 'Kind' is not equal to Subdivide2Argument | |
|
| |
| 1249 | return VectorType::getSubdividedVectorType(VTy, SubDivs); |
| 16 | | Passing null pointer value via 1st parameter 'VTy' | |
|
| 17 | | Calling 'VectorType::getSubdividedVectorType' | |
|
| 1250 | } |
| 1251 | case IITDescriptor::HalfVecArgument: |
| 1252 | return VectorType::getHalfElementsVectorType(cast<VectorType>( |
| 1253 | Tys[D.getArgumentNumber()])); |
| 1254 | case IITDescriptor::SameVecWidthArgument: { |
| 1255 | Type *EltTy = DecodeFixedType(Infos, Tys, Context); |
| 1256 | Type *Ty = Tys[D.getArgumentNumber()]; |
| 1257 | if (auto *VTy = dyn_cast<VectorType>(Ty)) |
| 1258 | return VectorType::get(EltTy, VTy->getElementCount()); |
| 1259 | return EltTy; |
| 1260 | } |
| 1261 | case IITDescriptor::PtrToArgument: { |
| 1262 | Type *Ty = Tys[D.getArgumentNumber()]; |
| 1263 | return PointerType::getUnqual(Ty); |
| 1264 | } |
| 1265 | case IITDescriptor::PtrToElt: { |
| 1266 | Type *Ty = Tys[D.getArgumentNumber()]; |
| 1267 | VectorType *VTy = dyn_cast<VectorType>(Ty); |
| 1268 | if (!VTy) |
| 1269 | llvm_unreachable("Expected an argument of Vector Type"); |
| 1270 | Type *EltTy = VTy->getElementType(); |
| 1271 | return PointerType::getUnqual(EltTy); |
| 1272 | } |
| 1273 | case IITDescriptor::VecElementArgument: { |
| 1274 | Type *Ty = Tys[D.getArgumentNumber()]; |
| 1275 | if (VectorType *VTy = dyn_cast<VectorType>(Ty)) |
| 1276 | return VTy->getElementType(); |
| 1277 | llvm_unreachable("Expected an argument of Vector Type"); |
| 1278 | } |
| 1279 | case IITDescriptor::VecOfBitcastsToInt: { |
| 1280 | Type *Ty = Tys[D.getArgumentNumber()]; |
| 1281 | VectorType *VTy = dyn_cast<VectorType>(Ty); |
| 1282 | assert(VTy && "Expected an argument of Vector Type"); |
| 1283 | return VectorType::getInteger(VTy); |
| 1284 | } |
| 1285 | case IITDescriptor::VecOfAnyPtrsToElt: |
| 1286 | |
| 1287 | return Tys[D.getOverloadArgNumber()]; |
| 1288 | } |
| 1289 | llvm_unreachable("unhandled"); |
| 1290 | } |
| 1291 | |
| 1292 | FunctionType *Intrinsic::getType(LLVMContext &Context, |
| 1293 | ID id, ArrayRef<Type*> Tys) { |
| 1294 | SmallVector<IITDescriptor, 8> Table; |
| 1295 | getIntrinsicInfoTableEntries(id, Table); |
| 1296 | |
| 1297 | ArrayRef<IITDescriptor> TableRef = Table; |
| 1298 | Type *ResultTy = DecodeFixedType(TableRef, Tys, Context); |
| 10 | | Calling 'DecodeFixedType' | |
|
| 1299 | |
| 1300 | SmallVector<Type*, 8> ArgTys; |
| 1301 | while (!TableRef.empty()) |
| 1302 | ArgTys.push_back(DecodeFixedType(TableRef, Tys, Context)); |
| 1303 | |
| 1304 | |
| 1305 | |
| 1306 | if (!ArgTys.empty() && ArgTys.back()->isVoidTy()) { |
| 1307 | ArgTys.pop_back(); |
| 1308 | return FunctionType::get(ResultTy, ArgTys, true); |
| 1309 | } |
| 1310 | return FunctionType::get(ResultTy, ArgTys, false); |
| 1311 | } |
| 1312 | |
| 1313 | bool Intrinsic::isOverloaded(ID id) { |
| 1314 | #define GET_INTRINSIC_OVERLOAD_TABLE |
| 1315 | #include "llvm/IR/IntrinsicImpl.inc" |
| 1316 | #undef GET_INTRINSIC_OVERLOAD_TABLE |
| 1317 | } |
| 1318 | |
| 1319 | bool Intrinsic::isLeaf(ID id) { |
| 1320 | switch (id) { |
| 1321 | default: |
| 1322 | return true; |
| 1323 | |
| 1324 | case Intrinsic::experimental_gc_statepoint: |
| 1325 | case Intrinsic::experimental_patchpoint_void: |
| 1326 | case Intrinsic::experimental_patchpoint_i64: |
| 1327 | return false; |
| 1328 | } |
| 1329 | } |
| 1330 | |
| 1331 | |
| 1332 | #define GET_INTRINSIC_ATTRIBUTES |
| 1333 | #include "llvm/IR/IntrinsicImpl.inc" |
| 1334 | #undef GET_INTRINSIC_ATTRIBUTES |
| 1335 | |
| 1336 | Function *Intrinsic::getDeclaration(Module *M, ID id, ArrayRef<Type*> Tys) { |
| 1337 | |
| 1338 | |
| 1339 | auto *FT = getType(M->getContext(), id, Tys); |
| 1340 | return cast<Function>( |
| 1341 | M->getOrInsertFunction(Tys.empty() ? getName(id) |
| 1342 | : getName(id, Tys, M, FT), |
| 1343 | getType(M->getContext(), id, Tys)) |
| 1344 | .getCallee()); |
| 1345 | } |
| 1346 | |
| 1347 | |
| 1348 | #define GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN |
| 1349 | #include "llvm/IR/IntrinsicImpl.inc" |
| 1350 | #undef GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN |
| 1351 | |
| 1352 | |
| 1353 | #define GET_LLVM_INTRINSIC_FOR_MS_BUILTIN |
| 1354 | #include "llvm/IR/IntrinsicImpl.inc" |
| 1355 | #undef GET_LLVM_INTRINSIC_FOR_MS_BUILTIN |
| 1356 | |
| 1357 | using DeferredIntrinsicMatchPair = |
| 1358 | std::pair<Type *, ArrayRef<Intrinsic::IITDescriptor>>; |
| 1359 | |
| 1360 | static bool matchIntrinsicType( |
| 1361 | Type *Ty, ArrayRef<Intrinsic::IITDescriptor> &Infos, |
| 1362 | SmallVectorImpl<Type *> &ArgTys, |
| 1363 | SmallVectorImpl<DeferredIntrinsicMatchPair> &DeferredChecks, |
| 1364 | bool IsDeferredCheck) { |
| 1365 | using namespace Intrinsic; |
| 1366 | |
| 1367 | |
| 1368 | if (Infos.empty()) return true; |
| 1369 | |
| 1370 | |
| 1371 | auto InfosRef = Infos; |
| 1372 | auto DeferCheck = [&DeferredChecks, &InfosRef](Type *T) { |
| 1373 | DeferredChecks.emplace_back(T, InfosRef); |
| 1374 | return false; |
| 1375 | }; |
| 1376 | |
| 1377 | IITDescriptor D = Infos.front(); |
| 1378 | Infos = Infos.slice(1); |
| 1379 | |
| 1380 | switch (D.Kind) { |
| 1381 | case IITDescriptor::Void: return !Ty->isVoidTy(); |
| 1382 | case IITDescriptor::VarArg: return true; |
| 1383 | case IITDescriptor::MMX: return !Ty->isX86_MMXTy(); |
| 1384 | case IITDescriptor::AMX: return !Ty->isX86_AMXTy(); |
| 1385 | case IITDescriptor::Token: return !Ty->isTokenTy(); |
| 1386 | case IITDescriptor::Metadata: return !Ty->isMetadataTy(); |
| 1387 | case IITDescriptor::Half: return !Ty->isHalfTy(); |
| 1388 | case IITDescriptor::BFloat: return !Ty->isBFloatTy(); |
| 1389 | case IITDescriptor::Float: return !Ty->isFloatTy(); |
| 1390 | case IITDescriptor::Double: return !Ty->isDoubleTy(); |
| 1391 | case IITDescriptor::Quad: return !Ty->isFP128Ty(); |
| 1392 | case IITDescriptor::Integer: return !Ty->isIntegerTy(D.Integer_Width); |
| 1393 | case IITDescriptor::Vector: { |
| 1394 | VectorType *VT = dyn_cast<VectorType>(Ty); |
| 1395 | return !VT || VT->getElementCount() != D.Vector_Width || |
| 1396 | matchIntrinsicType(VT->getElementType(), Infos, ArgTys, |
| 1397 | DeferredChecks, IsDeferredCheck); |
| 1398 | } |
| 1399 | case IITDescriptor::Pointer: { |
| 1400 | PointerType *PT = dyn_cast<PointerType>(Ty); |
| 1401 | if (!PT || PT->getAddressSpace() != D.Pointer_AddressSpace) |
| 1402 | return true; |
| 1403 | if (!PT->isOpaque()) |
| 1404 | return matchIntrinsicType(PT->getElementType(), Infos, ArgTys, |
| 1405 | DeferredChecks, IsDeferredCheck); |
| 1406 | |
| 1407 | |
| 1408 | |
| 1409 | if (Ty->getContext().supportsTypedPointers()) |
| 1410 | return true; |
| 1411 | |
| 1412 | while (Infos.front().Kind == IITDescriptor::Pointer) |
| 1413 | Infos = Infos.slice(1); |
| 1414 | Infos = Infos.slice(1); |
| 1415 | return false; |
| 1416 | } |
| 1417 | |
| 1418 | case IITDescriptor::Struct: { |
| 1419 | StructType *ST = dyn_cast<StructType>(Ty); |
| 1420 | if (!ST || ST->getNumElements() != D.Struct_NumElements) |
| 1421 | return true; |
| 1422 | |
| 1423 | for (unsigned i = 0, e = D.Struct_NumElements; i != e; ++i) |
| 1424 | if (matchIntrinsicType(ST->getElementType(i), Infos, ArgTys, |
| 1425 | DeferredChecks, IsDeferredCheck)) |
| 1426 | return true; |
| 1427 | return false; |
| 1428 | } |
| 1429 | |
| 1430 | case IITDescriptor::Argument: |
| 1431 | |
| 1432 | |
| 1433 | if (D.getArgumentNumber() < ArgTys.size()) |
| 1434 | return Ty != ArgTys[D.getArgumentNumber()]; |
| 1435 | |
| 1436 | if (D.getArgumentNumber() > ArgTys.size() || |
| 1437 | D.getArgumentKind() == IITDescriptor::AK_MatchType) |
| 1438 | return IsDeferredCheck || DeferCheck(Ty); |
| 1439 | |
| 1440 | assert(D.getArgumentNumber() == ArgTys.size() && !IsDeferredCheck && |
| 1441 | "Table consistency error"); |
| 1442 | ArgTys.push_back(Ty); |
| 1443 | |
| 1444 | switch (D.getArgumentKind()) { |
| 1445 | case IITDescriptor::AK_Any: return false; |
| 1446 | case IITDescriptor::AK_AnyInteger: return !Ty->isIntOrIntVectorTy(); |
| 1447 | case IITDescriptor::AK_AnyFloat: return !Ty->isFPOrFPVectorTy(); |
| 1448 | case IITDescriptor::AK_AnyVector: return !isa<VectorType>(Ty); |
| 1449 | case IITDescriptor::AK_AnyPointer: return !isa<PointerType>(Ty); |
| 1450 | default: break; |
| 1451 | } |
| 1452 | llvm_unreachable("all argument kinds not covered"); |
| 1453 | |
| 1454 | case IITDescriptor::ExtendArgument: { |
| 1455 | |
| 1456 | if (D.getArgumentNumber() >= ArgTys.size()) |
| 1457 | return IsDeferredCheck || DeferCheck(Ty); |
| 1458 | |
| 1459 | Type *NewTy = ArgTys[D.getArgumentNumber()]; |
| 1460 | if (VectorType *VTy = dyn_cast<VectorType>(NewTy)) |
| 1461 | NewTy = VectorType::getExtendedElementVectorType(VTy); |
| 1462 | else if (IntegerType *ITy = dyn_cast<IntegerType>(NewTy)) |
| 1463 | NewTy = IntegerType::get(ITy->getContext(), 2 * ITy->getBitWidth()); |
| 1464 | else |
| 1465 | return true; |
| 1466 | |
| 1467 | return Ty != NewTy; |
| 1468 | } |
| 1469 | case IITDescriptor::TruncArgument: { |
| 1470 | |
| 1471 | if (D.getArgumentNumber() >= ArgTys.size()) |
| 1472 | return IsDeferredCheck || DeferCheck(Ty); |
| 1473 | |
| 1474 | Type *NewTy = ArgTys[D.getArgumentNumber()]; |
| 1475 | if (VectorType *VTy = dyn_cast<VectorType>(NewTy)) |
| 1476 | NewTy = VectorType::getTruncatedElementVectorType(VTy); |
| 1477 | else if (IntegerType *ITy = dyn_cast<IntegerType>(NewTy)) |
| 1478 | NewTy = IntegerType::get(ITy->getContext(), ITy->getBitWidth() / 2); |
| 1479 | else |
| 1480 | return true; |
| 1481 | |
| 1482 | return Ty != NewTy; |
| 1483 | } |
| 1484 | case IITDescriptor::HalfVecArgument: |
| 1485 | |
| 1486 | if (D.getArgumentNumber() >= ArgTys.size()) |
| 1487 | return IsDeferredCheck || DeferCheck(Ty); |
| 1488 | return !isa<VectorType>(ArgTys[D.getArgumentNumber()]) || |
| 1489 | VectorType::getHalfElementsVectorType( |
| 1490 | cast<VectorType>(ArgTys[D.getArgumentNumber()])) != Ty; |
| 1491 | case IITDescriptor::SameVecWidthArgument: { |
| 1492 | if (D.getArgumentNumber() >= ArgTys.size()) { |
| 1493 | |
| 1494 | Infos = Infos.slice(1); |
| 1495 | return IsDeferredCheck || DeferCheck(Ty); |
| 1496 | } |
| 1497 | auto *ReferenceType = dyn_cast<VectorType>(ArgTys[D.getArgumentNumber()]); |
| 1498 | auto *ThisArgType = dyn_cast<VectorType>(Ty); |
| 1499 | |
| 1500 | if ((ReferenceType != nullptr) != (ThisArgType != nullptr)) |
| 1501 | return true; |
| 1502 | Type *EltTy = Ty; |
| 1503 | if (ThisArgType) { |
| 1504 | if (ReferenceType->getElementCount() != |
| 1505 | ThisArgType->getElementCount()) |
| 1506 | return true; |
| 1507 | EltTy = ThisArgType->getElementType(); |
| 1508 | } |
| 1509 | return matchIntrinsicType(EltTy, Infos, ArgTys, DeferredChecks, |
| 1510 | IsDeferredCheck); |
| 1511 | } |
| 1512 | case IITDescriptor::PtrToArgument: { |
| 1513 | if (D.getArgumentNumber() >= ArgTys.size()) |
| 1514 | return IsDeferredCheck || DeferCheck(Ty); |
| 1515 | Type * ReferenceType = ArgTys[D.getArgumentNumber()]; |
| 1516 | PointerType *ThisArgType = dyn_cast<PointerType>(Ty); |
| 1517 | return (!ThisArgType || ThisArgType->getElementType() != ReferenceType); |
| 1518 | } |
| 1519 | case IITDescriptor::PtrToElt: { |
| 1520 | if (D.getArgumentNumber() >= ArgTys.size()) |
| 1521 | return IsDeferredCheck || DeferCheck(Ty); |
| 1522 | VectorType * ReferenceType = |
| 1523 | dyn_cast<VectorType> (ArgTys[D.getArgumentNumber()]); |
| 1524 | PointerType *ThisArgType = dyn_cast<PointerType>(Ty); |
| 1525 | |
| 1526 | if (!ThisArgType || !ReferenceType) |
| 1527 | return true; |
| 1528 | if (!ThisArgType->isOpaque()) |
| 1529 | return ThisArgType->getElementType() != ReferenceType->getElementType(); |
| 1530 | |
| 1531 | |
| 1532 | return Ty->getContext().supportsTypedPointers(); |
| 1533 | } |
| 1534 | case IITDescriptor::VecOfAnyPtrsToElt: { |
| 1535 | unsigned RefArgNumber = D.getRefArgNumber(); |
| 1536 | if (RefArgNumber >= ArgTys.size()) { |
| 1537 | if (IsDeferredCheck) |
| 1538 | return true; |
| 1539 | |
| 1540 | |
| 1541 | ArgTys.push_back(Ty); |
| 1542 | return DeferCheck(Ty); |
| 1543 | } |
| 1544 | |
| 1545 | if (!IsDeferredCheck){ |
| 1546 | assert(D.getOverloadArgNumber() == ArgTys.size() && |
| 1547 | "Table consistency error"); |
| 1548 | ArgTys.push_back(Ty); |
| 1549 | } |
| 1550 | |
| 1551 | |
| 1552 | |
| 1553 | |
| 1554 | auto *ReferenceType = dyn_cast<VectorType>(ArgTys[RefArgNumber]); |
| 1555 | auto *ThisArgVecTy = dyn_cast<VectorType>(Ty); |
| 1556 | if (!ThisArgVecTy || !ReferenceType || |
| 1557 | (ReferenceType->getElementCount() != ThisArgVecTy->getElementCount())) |
| 1558 | return true; |
| 1559 | PointerType *ThisArgEltTy = |
| 1560 | dyn_cast<PointerType>(ThisArgVecTy->getElementType()); |
| 1561 | if (!ThisArgEltTy) |
| 1562 | return true; |
| 1563 | return !ThisArgEltTy->isOpaqueOrPointeeTypeMatches( |
| 1564 | ReferenceType->getElementType()); |
| 1565 | } |
| 1566 | case IITDescriptor::VecElementArgument: { |
| 1567 | if (D.getArgumentNumber() >= ArgTys.size()) |
| 1568 | return IsDeferredCheck ? true : DeferCheck(Ty); |
| 1569 | auto *ReferenceType = dyn_cast<VectorType>(ArgTys[D.getArgumentNumber()]); |
| 1570 | return !ReferenceType || Ty != ReferenceType->getElementType(); |
| 1571 | } |
| 1572 | case IITDescriptor::Subdivide2Argument: |
| 1573 | case IITDescriptor::Subdivide4Argument: { |
| 1574 | |
| 1575 | if (D.getArgumentNumber() >= ArgTys.size()) |
| 1576 | return IsDeferredCheck || DeferCheck(Ty); |
| 1577 | |
| 1578 | Type *NewTy = ArgTys[D.getArgumentNumber()]; |
| 1579 | if (auto *VTy = dyn_cast<VectorType>(NewTy)) { |
| 1580 | int SubDivs = D.Kind == IITDescriptor::Subdivide2Argument ? 1 : 2; |
| 1581 | NewTy = VectorType::getSubdividedVectorType(VTy, SubDivs); |
| 1582 | return Ty != NewTy; |
| 1583 | } |
| 1584 | return true; |
| 1585 | } |
| 1586 | case IITDescriptor::VecOfBitcastsToInt: { |
| 1587 | if (D.getArgumentNumber() >= ArgTys.size()) |
| 1588 | return IsDeferredCheck || DeferCheck(Ty); |
| 1589 | auto *ReferenceType = dyn_cast<VectorType>(ArgTys[D.getArgumentNumber()]); |
| 1590 | auto *ThisArgVecTy = dyn_cast<VectorType>(Ty); |
| 1591 | if (!ThisArgVecTy || !ReferenceType) |
| 1592 | return true; |
| 1593 | return ThisArgVecTy != VectorType::getInteger(ReferenceType); |
| 1594 | } |
| 1595 | } |
| 1596 | llvm_unreachable("unhandled"); |
| 1597 | } |
| 1598 | |
| 1599 | Intrinsic::MatchIntrinsicTypesResult |
| 1600 | Intrinsic::matchIntrinsicSignature(FunctionType *FTy, |
| 1601 | ArrayRef<Intrinsic::IITDescriptor> &Infos, |
| 1602 | SmallVectorImpl<Type *> &ArgTys) { |
| 1603 | SmallVector<DeferredIntrinsicMatchPair, 2> DeferredChecks; |
| 1604 | if (matchIntrinsicType(FTy->getReturnType(), Infos, ArgTys, DeferredChecks, |
| 1605 | false)) |
| 1606 | return MatchIntrinsicTypes_NoMatchRet; |
| 1607 | |
| 1608 | unsigned NumDeferredReturnChecks = DeferredChecks.size(); |
| 1609 | |
| 1610 | for (auto Ty : FTy->params()) |
| 1611 | if (matchIntrinsicType(Ty, Infos, ArgTys, DeferredChecks, false)) |
| 1612 | return MatchIntrinsicTypes_NoMatchArg; |
| 1613 | |
| 1614 | for (unsigned I = 0, E = DeferredChecks.size(); I != E; ++I) { |
| 1615 | DeferredIntrinsicMatchPair &Check = DeferredChecks[I]; |
| 1616 | if (matchIntrinsicType(Check.first, Check.second, ArgTys, DeferredChecks, |
| 1617 | true)) |
| 1618 | return I < NumDeferredReturnChecks ? MatchIntrinsicTypes_NoMatchRet |
| 1619 | : MatchIntrinsicTypes_NoMatchArg; |
| 1620 | } |
| 1621 | |
| 1622 | return MatchIntrinsicTypes_Match; |
| 1623 | } |
| 1624 | |
| 1625 | bool |
| 1626 | Intrinsic::matchIntrinsicVarArg(bool isVarArg, |
| 1627 | ArrayRef<Intrinsic::IITDescriptor> &Infos) { |
| 1628 | |
| 1629 | if (Infos.empty()) |
| 1630 | return isVarArg; |
| 1631 | |
| 1632 | |
| 1633 | if (Infos.size() != 1) |
| 1634 | return true; |
| 1635 | |
| 1636 | |
| 1637 | IITDescriptor D = Infos.front(); |
| 1638 | Infos = Infos.slice(1); |
| 1639 | if (D.Kind == IITDescriptor::VarArg) |
| 1640 | return !isVarArg; |
| 1641 | |
| 1642 | return true; |
| 1643 | } |
| 1644 | |
| 1645 | bool Intrinsic::getIntrinsicSignature(Function *F, |
| 1646 | SmallVectorImpl<Type *> &ArgTys) { |
| 1647 | Intrinsic::ID ID = F->getIntrinsicID(); |
| 1648 | if (!ID) |
| 1649 | return false; |
| 1650 | |
| 1651 | SmallVector<Intrinsic::IITDescriptor, 8> Table; |
| 1652 | getIntrinsicInfoTableEntries(ID, Table); |
| 1653 | ArrayRef<Intrinsic::IITDescriptor> TableRef = Table; |
| 1654 | |
| 1655 | if (Intrinsic::matchIntrinsicSignature(F->getFunctionType(), TableRef, |
| 1656 | ArgTys) != |
| 1657 | Intrinsic::MatchIntrinsicTypesResult::MatchIntrinsicTypes_Match) { |
| 1658 | return false; |
| 1659 | } |
| 1660 | if (Intrinsic::matchIntrinsicVarArg(F->getFunctionType()->isVarArg(), |
| 1661 | TableRef)) |
| 1662 | return false; |
| 1663 | return true; |
| 1664 | } |
| 1665 | |
| 1666 | Optional<Function *> Intrinsic::remangleIntrinsicFunction(Function *F) { |
| 1667 | SmallVector<Type *, 4> ArgTys; |
| 1668 | if (!getIntrinsicSignature(F, ArgTys)) |
| |
| 1669 | return None; |
| 1670 | |
| 1671 | Intrinsic::ID ID = F->getIntrinsicID(); |
| 1672 | StringRef Name = F->getName(); |
| 1673 | std::string WantedName = |
| 1674 | Intrinsic::getName(ID, ArgTys, F->getParent(), F->getFunctionType()); |
| |
| 1675 | if (Name == WantedName) |
| 1676 | return None; |
| 1677 | |
| 1678 | Function *NewDecl = [&] { |
| 1679 | if (auto *ExistingGV = F->getParent()->getNamedValue(WantedName)) { |
| 1680 | if (auto *ExistingF = dyn_cast<Function>(ExistingGV)) |
| 1681 | if (ExistingF->getFunctionType() == F->getFunctionType()) |
| 1682 | return ExistingF; |
| 1683 | |
| 1684 | |
| 1685 | |
| 1686 | |
| 1687 | |
| 1688 | ExistingGV->setName(WantedName + ".renamed"); |
| 1689 | } |
| 1690 | return Intrinsic::getDeclaration(F->getParent(), ID, ArgTys); |
| 1691 | }(); |
| 1692 | |
| 1693 | NewDecl->setCallingConv(F->getCallingConv()); |
| 1694 | assert(NewDecl->getFunctionType() == F->getFunctionType() && |
| 1695 | "Shouldn't change the signature"); |
| 1696 | return NewDecl; |
| 1697 | } |
| 1698 | |
| 1699 | |
| 1700 | |
| 1701 | |
| 1702 | |
| 1703 | bool Function::hasAddressTaken(const User **PutOffender, |
| 1704 | bool IgnoreCallbackUses, |
| 1705 | bool IgnoreAssumeLikeCalls, |
| 1706 | bool IgnoreLLVMUsed) const { |
| 1707 | for (const Use &U : uses()) { |
| 1708 | const User *FU = U.getUser(); |
| 1709 | if (isa<BlockAddress>(FU)) |
| 1710 | continue; |
| 1711 | |
| 1712 | if (IgnoreCallbackUses) { |
| 1713 | AbstractCallSite ACS(&U); |
| 1714 | if (ACS && ACS.isCallbackCall()) |
| 1715 | continue; |
| 1716 | } |
| 1717 | |
| 1718 | const auto *Call = dyn_cast<CallBase>(FU); |
| 1719 | if (!Call) { |
| 1720 | if (IgnoreAssumeLikeCalls) { |
| 1721 | if (const auto *FI = dyn_cast<Instruction>(FU)) { |
| 1722 | if (FI->isCast() && !FI->user_empty() && |
| 1723 | llvm::all_of(FU->users(), [](const User *U) { |
| 1724 | if (const auto *I = dyn_cast<IntrinsicInst>(U)) |
| 1725 | return I->isAssumeLikeIntrinsic(); |
| 1726 | return false; |
| 1727 | })) |
| 1728 | continue; |
| 1729 | } |
| 1730 | } |
| 1731 | if (IgnoreLLVMUsed && !FU->user_empty()) { |
| 1732 | const User *FUU = FU; |
| 1733 | if (isa<BitCastOperator>(FU) && FU->hasOneUse() && |
| 1734 | !FU->user_begin()->user_empty()) |
| 1735 | FUU = *FU->user_begin(); |
| 1736 | if (llvm::all_of(FUU->users(), [](const User *U) { |
| 1737 | if (const auto *GV = dyn_cast<GlobalVariable>(U)) |
| 1738 | return GV->hasName() && |
| 1739 | (GV->getName().equals("llvm.compiler.used") || |
| 1740 | GV->getName().equals("llvm.used")); |
| 1741 | return false; |
| 1742 | })) |
| 1743 | continue; |
| 1744 | } |
| 1745 | if (PutOffender) |
| 1746 | *PutOffender = FU; |
| 1747 | return true; |
| 1748 | } |
| 1749 | if (!Call->isCallee(&U)) { |
| 1750 | if (PutOffender) |
| 1751 | *PutOffender = FU; |
| 1752 | return true; |
| 1753 | } |
| 1754 | } |
| 1755 | return false; |
| 1756 | } |
| 1757 | |
| 1758 | bool Function::isDefTriviallyDead() const { |
| 1759 | |
| 1760 | if (!hasLinkOnceLinkage() && !hasLocalLinkage() && |
| 1761 | !hasAvailableExternallyLinkage()) |
| 1762 | return false; |
| 1763 | |
| 1764 | |
| 1765 | for (const User *U : users()) |
| 1766 | if (!isa<BlockAddress>(U)) |
| 1767 | return false; |
| 1768 | |
| 1769 | return true; |
| 1770 | } |
| 1771 | |
| 1772 | |
| 1773 | |
| 1774 | bool Function::callsFunctionThatReturnsTwice() const { |
| 1775 | for (const Instruction &I : instructions(this)) |
| 1776 | if (const auto *Call = dyn_cast<CallBase>(&I)) |
| 1777 | if (Call->hasFnAttr(Attribute::ReturnsTwice)) |
| 1778 | return true; |
| 1779 | |
| 1780 | return false; |
| 1781 | } |
| 1782 | |
| 1783 | Constant *Function::getPersonalityFn() const { |
| 1784 | assert(hasPersonalityFn() && getNumOperands()); |
| 1785 | return cast<Constant>(Op<0>()); |
| 1786 | } |
| 1787 | |
| 1788 | void Function::setPersonalityFn(Constant *Fn) { |
| 1789 | setHungoffOperand<0>(Fn); |
| 1790 | setValueSubclassDataBit(3, Fn != nullptr); |
| 1791 | } |
| 1792 | |
| 1793 | Constant *Function::getPrefixData() const { |
| 1794 | assert(hasPrefixData() && getNumOperands()); |
| 1795 | return cast<Constant>(Op<1>()); |
| 1796 | } |
| 1797 | |
| 1798 | void Function::setPrefixData(Constant *PrefixData) { |
| 1799 | setHungoffOperand<1>(PrefixData); |
| 1800 | setValueSubclassDataBit(1, PrefixData != nullptr); |
| 1801 | } |
| 1802 | |
| 1803 | Constant *Function::getPrologueData() const { |
| 1804 | assert(hasPrologueData() && getNumOperands()); |
| 1805 | return cast<Constant>(Op<2>()); |
| 1806 | } |
| 1807 | |
| 1808 | void Function::setPrologueData(Constant *PrologueData) { |
| 1809 | setHungoffOperand<2>(PrologueData); |
| 1810 | setValueSubclassDataBit(2, PrologueData != nullptr); |
| 1811 | } |
| 1812 | |
| 1813 | void Function::allocHungoffUselist() { |
| 1814 | |
| 1815 | if (getNumOperands()) |
| 1816 | return; |
| 1817 | |
| 1818 | allocHungoffUses(3, false); |
| 1819 | setNumHungOffUseOperands(3); |
| 1820 | |
| 1821 | |
| 1822 | auto *CPN = ConstantPointerNull::get(Type::getInt1PtrTy(getContext(), 0)); |
| 1823 | Op<0>().set(CPN); |
| 1824 | Op<1>().set(CPN); |
| 1825 | Op<2>().set(CPN); |
| 1826 | } |
| 1827 | |
| 1828 | template <int Idx> |
| 1829 | void Function::setHungoffOperand(Constant *C) { |
| 1830 | if (C) { |
| 1831 | allocHungoffUselist(); |
| 1832 | Op<Idx>().set(C); |
| 1833 | } else if (getNumOperands()) { |
| 1834 | Op<Idx>().set( |
| 1835 | ConstantPointerNull::get(Type::getInt1PtrTy(getContext(), 0))); |
| 1836 | } |
| 1837 | } |
| 1838 | |
| 1839 | void Function::setValueSubclassDataBit(unsigned Bit, bool On) { |
| 1840 | assert(Bit < 16 && "SubclassData contains only 16 bits"); |
| 1841 | if (On) |
| 1842 | setValueSubclassData(getSubclassDataFromValue() | (1 << Bit)); |
| 1843 | else |
| 1844 | setValueSubclassData(getSubclassDataFromValue() & ~(1 << Bit)); |
| 1845 | } |
| 1846 | |
| 1847 | void Function::setEntryCount(ProfileCount Count, |
| 1848 | const DenseSet<GlobalValue::GUID> *S) { |
| 1849 | assert(Count.hasValue()); |
| 1850 | #if !defined(NDEBUG) |
| 1851 | auto PrevCount = getEntryCount(); |
| 1852 | assert(!PrevCount.hasValue() || PrevCount.getType() == Count.getType()); |
| 1853 | #endif |
| 1854 | |
| 1855 | auto ImportGUIDs = getImportGUIDs(); |
| 1856 | if (S == nullptr && ImportGUIDs.size()) |
| 1857 | S = &ImportGUIDs; |
| 1858 | |
| 1859 | MDBuilder MDB(getContext()); |
| 1860 | setMetadata( |
| 1861 | LLVMContext::MD_prof, |
| 1862 | MDB.createFunctionEntryCount(Count.getCount(), Count.isSynthetic(), S)); |
| 1863 | } |
| 1864 | |
| 1865 | void Function::setEntryCount(uint64_t Count, Function::ProfileCountType Type, |
| 1866 | const DenseSet<GlobalValue::GUID> *Imports) { |
| 1867 | setEntryCount(ProfileCount(Count, Type), Imports); |
| 1868 | } |
| 1869 | |
| 1870 | ProfileCount Function::getEntryCount(bool AllowSynthetic) const { |
| 1871 | MDNode *MD = getMetadata(LLVMContext::MD_prof); |
| 1872 | if (MD && MD->getOperand(0)) |
| 1873 | if (MDString *MDS = dyn_cast<MDString>(MD->getOperand(0))) { |
| 1874 | if (MDS->getString().equals("function_entry_count")) { |
| 1875 | ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(1)); |
| 1876 | uint64_t Count = CI->getValue().getZExtValue(); |
| 1877 | |
| 1878 | |
| 1879 | if (Count == (uint64_t)-1) |
| 1880 | return ProfileCount::getInvalid(); |
| 1881 | return ProfileCount(Count, PCT_Real); |
| 1882 | } else if (AllowSynthetic && |
| 1883 | MDS->getString().equals("synthetic_function_entry_count")) { |
| 1884 | ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(1)); |
| 1885 | uint64_t Count = CI->getValue().getZExtValue(); |
| 1886 | return ProfileCount(Count, PCT_Synthetic); |
| 1887 | } |
| 1888 | } |
| 1889 | return ProfileCount::getInvalid(); |
| 1890 | } |
| 1891 | |
| 1892 | DenseSet<GlobalValue::GUID> Function::getImportGUIDs() const { |
| 1893 | DenseSet<GlobalValue::GUID> R; |
| 1894 | if (MDNode *MD = getMetadata(LLVMContext::MD_prof)) |
| 1895 | if (MDString *MDS = dyn_cast<MDString>(MD->getOperand(0))) |
| 1896 | if (MDS->getString().equals("function_entry_count")) |
| 1897 | for (unsigned i = 2; i < MD->getNumOperands(); i++) |
| 1898 | R.insert(mdconst::extract<ConstantInt>(MD->getOperand(i)) |
| 1899 | ->getValue() |
| 1900 | .getZExtValue()); |
| 1901 | return R; |
| 1902 | } |
| 1903 | |
| 1904 | void Function::setSectionPrefix(StringRef Prefix) { |
| 1905 | MDBuilder MDB(getContext()); |
| 1906 | setMetadata(LLVMContext::MD_section_prefix, |
| 1907 | MDB.createFunctionSectionPrefix(Prefix)); |
| 1908 | } |
| 1909 | |
| 1910 | Optional<StringRef> Function::getSectionPrefix() const { |
| 1911 | if (MDNode *MD = getMetadata(LLVMContext::MD_section_prefix)) { |
| 1912 | assert(cast<MDString>(MD->getOperand(0)) |
| 1913 | ->getString() |
| 1914 | .equals("function_section_prefix") && |
| 1915 | "Metadata not match"); |
| 1916 | return cast<MDString>(MD->getOperand(1))->getString(); |
| 1917 | } |
| 1918 | return None; |
| 1919 | } |
| 1920 | |
| 1921 | bool Function::nullPointerIsDefined() const { |
| 1922 | return hasFnAttribute(Attribute::NullPointerIsValid); |
| 1923 | } |
| 1924 | |
| 1925 | bool llvm::NullPointerIsDefined(const Function *F, unsigned AS) { |
| 1926 | if (F && F->nullPointerIsDefined()) |
| 1927 | return true; |
| 1928 | |
| 1929 | if (AS != 0) |
| 1930 | return true; |
| 1931 | |
| 1932 | return false; |
| 1933 | } |
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | #ifndef LLVM_IR_DERIVEDTYPES_H |
| 18 | #define LLVM_IR_DERIVEDTYPES_H |
| 19 | |
| 20 | #include "llvm/ADT/ArrayRef.h" |
| 21 | #include "llvm/ADT/STLExtras.h" |
| 22 | #include "llvm/ADT/StringRef.h" |
| 23 | #include "llvm/IR/Type.h" |
| 24 | #include "llvm/Support/Casting.h" |
| 25 | #include "llvm/Support/Compiler.h" |
| 26 | #include "llvm/Support/TypeSize.h" |
| 27 | #include <cassert> |
| 28 | #include <cstdint> |
| 29 | |
| 30 | namespace llvm { |
| 31 | |
| 32 | class Value; |
| 33 | class APInt; |
| 34 | class LLVMContext; |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | class IntegerType : public Type { |
| 41 | friend class LLVMContextImpl; |
| 42 | |
| 43 | protected: |
| 44 | explicit IntegerType(LLVMContext &C, unsigned NumBits) : Type(C, IntegerTyID){ |
| 45 | setSubclassData(NumBits); |
| 46 | } |
| 47 | |
| 48 | public: |
| 49 | |
| 50 | enum { |
| 51 | MIN_INT_BITS = 1, |
| 52 | MAX_INT_BITS = (1<<24)-1 |
| 53 | |
| 54 | |
| 55 | |
| 56 | }; |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | static IntegerType *get(LLVMContext &C, unsigned NumBits); |
| 64 | |
| 65 | |
| 66 | IntegerType *getExtendedType() const { |
| 67 | return Type::getIntNTy(getContext(), 2 * getScalarSizeInBits()); |
| 68 | } |
| 69 | |
| 70 | |
| 71 | unsigned getBitWidth() const { return getSubclassData(); } |
| 72 | |
| 73 | |
| 74 | |
| 75 | uint64_t getBitMask() const { |
| 76 | return ~uint64_t(0UL) >> (64-getBitWidth()); |
| 77 | } |
| 78 | |
| 79 | |
| 80 | |
| 81 | uint64_t getSignBit() const { |
| 82 | return 1ULL << (getBitWidth()-1); |
| 83 | } |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | APInt getMask() const; |
| 89 | |
| 90 | |
| 91 | static bool classof(const Type *T) { |
| 92 | return T->getTypeID() == IntegerTyID; |
| 93 | } |
| 94 | }; |
| 95 | |
| 96 | unsigned Type::getIntegerBitWidth() const { |
| 97 | return cast<IntegerType>(this)->getBitWidth(); |
| 98 | } |
| 99 | |
| 100 | |
| 101 | |
| 102 | class FunctionType : public Type { |
| 103 | FunctionType(Type *Result, ArrayRef<Type*> Params, bool IsVarArgs); |
| 104 | |
| 105 | public: |
| 106 | FunctionType(const FunctionType &) = delete; |
| 107 | FunctionType &operator=(const FunctionType &) = delete; |
| 108 | |
| 109 | |
| 110 | static FunctionType *get(Type *Result, |
| 111 | ArrayRef<Type*> Params, bool isVarArg); |
| 112 | |
| 113 | |
| 114 | static FunctionType *get(Type *Result, bool isVarArg); |
| 115 | |
| 116 | |
| 117 | static bool isValidReturnType(Type *RetTy); |
| 118 | |
| 119 | |
| 120 | static bool isValidArgumentType(Type *ArgTy); |
| 121 | |
| 122 | bool isVarArg() const { return getSubclassData()!=0; } |
| 123 | Type *getReturnType() const { return ContainedTys[0]; } |
| 124 | |
| 125 | using param_iterator = Type::subtype_iterator; |
| 126 | |
| 127 | param_iterator param_begin() const { return ContainedTys + 1; } |
| 128 | param_iterator param_end() const { return &ContainedTys[NumContainedTys]; } |
| 129 | ArrayRef<Type *> params() const { |
| 130 | return makeArrayRef(param_begin(), param_end()); |
| 131 | } |
| 132 | |
| 133 | |
| 134 | Type *getParamType(unsigned i) const { return ContainedTys[i+1]; } |
| 135 | |
| 136 | |
| 137 | |
| 138 | unsigned getNumParams() const { return NumContainedTys - 1; } |
| 139 | |
| 140 | |
| 141 | static bool classof(const Type *T) { |
| 142 | return T->getTypeID() == FunctionTyID; |
| 143 | } |
| 144 | }; |
| 145 | static_assert(alignof(FunctionType) >= alignof(Type *), |
| 146 | "Alignment sufficient for objects appended to FunctionType"); |
| 147 | |
| 148 | bool Type::isFunctionVarArg() const { |
| 149 | return cast<FunctionType>(this)->isVarArg(); |
| 150 | } |
| 151 | |
| 152 | Type *Type::getFunctionParamType(unsigned i) const { |
| 153 | return cast<FunctionType>(this)->getParamType(i); |
| 154 | } |
| 155 | |
| 156 | unsigned Type::getFunctionNumParams() const { |
| 157 | return cast<FunctionType>(this)->getNumParams(); |
| 158 | } |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | class FunctionCallee { |
| 165 | public: |
| 166 | |
| 167 | |
| 168 | template <typename T, typename U = decltype(&T::getFunctionType)> |
| 169 | FunctionCallee(T *Fn) |
| 170 | : FnTy(Fn ? Fn->getFunctionType() : nullptr), Callee(Fn) {} |
| 171 | |
| 172 | FunctionCallee(FunctionType *FnTy, Value *Callee) |
| 173 | : FnTy(FnTy), Callee(Callee) { |
| 174 | assert((FnTy == nullptr) == (Callee == nullptr)); |
| 175 | } |
| 176 | |
| 177 | FunctionCallee(std::nullptr_t) {} |
| 178 | |
| 179 | FunctionCallee() = default; |
| 180 | |
| 181 | FunctionType *getFunctionType() { return FnTy; } |
| 182 | |
| 183 | Value *getCallee() { return Callee; } |
| 184 | |
| 185 | explicit operator bool() { return Callee; } |
| 186 | |
| 187 | private: |
| 188 | FunctionType *FnTy = nullptr; |
| 189 | Value *Callee = nullptr; |
| 190 | }; |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | class StructType : public Type { |
| 213 | StructType(LLVMContext &C) : Type(C, StructTyID) {} |
| 214 | |
| 215 | enum { |
| 216 | |
| 217 | SCDB_HasBody = 1, |
| 218 | SCDB_Packed = 2, |
| 219 | SCDB_IsLiteral = 4, |
| 220 | SCDB_IsSized = 8 |
| 221 | }; |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | |
| 227 | void *SymbolTableEntry = nullptr; |
| 228 | |
| 229 | public: |
| 230 | StructType(const StructType &) = delete; |
| 231 | StructType &operator=(const StructType &) = delete; |
| 232 | |
| 233 | |
| 234 | static StructType *create(LLVMContext &Context, StringRef Name); |
| 235 | static StructType *create(LLVMContext &Context); |
| 236 | |
| 237 | static StructType *create(ArrayRef<Type *> Elements, StringRef Name, |
| 238 | bool isPacked = false); |
| 239 | static StructType *create(ArrayRef<Type *> Elements); |
| 240 | static StructType *create(LLVMContext &Context, ArrayRef<Type *> Elements, |
| 241 | StringRef Name, bool isPacked = false); |
| 242 | static StructType *create(LLVMContext &Context, ArrayRef<Type *> Elements); |
| 243 | template <class... Tys> |
| 244 | static std::enable_if_t<are_base_of<Type, Tys...>::value, StructType *> |
| 245 | create(StringRef Name, Type *elt1, Tys *... elts) { |
| 246 | assert(elt1 && "Cannot create a struct type with no elements with this"); |
| 247 | return create(ArrayRef<Type *>({elt1, elts...}), Name); |
| 248 | } |
| 249 | |
| 250 | |
| 251 | static StructType *get(LLVMContext &Context, ArrayRef<Type*> Elements, |
| 252 | bool isPacked = false); |
| 253 | |
| 254 | |
| 255 | static StructType *get(LLVMContext &Context, bool isPacked = false); |
| 256 | |
| 257 | |
| 258 | |
| 259 | |
| 260 | template <class... Tys> |
| 261 | static std::enable_if_t<are_base_of<Type, Tys...>::value, StructType *> |
| 262 | get(Type *elt1, Tys *... elts) { |
| 263 | assert(elt1 && "Cannot create a struct type with no elements with this"); |
| 264 | LLVMContext &Ctx = elt1->getContext(); |
| 265 | return StructType::get(Ctx, ArrayRef<Type *>({elt1, elts...})); |
| 266 | } |
| 267 | |
| 268 | |
| 269 | |
| 270 | static StructType *getTypeByName(LLVMContext &C, StringRef Name); |
| 271 | |
| 272 | bool isPacked() const { return (getSubclassData() & SCDB_Packed) != 0; } |
| 273 | |
| 274 | |
| 275 | |
| 276 | bool isLiteral() const { return (getSubclassData() & SCDB_IsLiteral) != 0; } |
| 277 | |
| 278 | |
| 279 | |
| 280 | bool isOpaque() const { return (getSubclassData() & SCDB_HasBody) == 0; } |
| 281 | |
| 282 | |
| 283 | bool isSized(SmallPtrSetImpl<Type *> *Visited = nullptr) const; |
| 284 | |
| 285 | |
| 286 | bool containsScalableVectorType() const; |
| 287 | |
| 288 | |
| 289 | bool hasName() const { return SymbolTableEntry != nullptr; } |
| 290 | |
| 291 | |
| 292 | |
| 293 | |
| 294 | StringRef getName() const; |
| 295 | |
| 296 | |
| 297 | |
| 298 | void setName(StringRef Name); |
| 299 | |
| 300 | |
| 301 | void setBody(ArrayRef<Type*> Elements, bool isPacked = false); |
| 302 | |
| 303 | template <typename... Tys> |
| 304 | std::enable_if_t<are_base_of<Type, Tys...>::value, void> |
| 305 | setBody(Type *elt1, Tys *... elts) { |
| 306 | assert(elt1 && "Cannot create a struct type with no elements with this"); |
| 307 | setBody(ArrayRef<Type *>({elt1, elts...})); |
| 308 | } |
| 309 | |
| 310 | |
| 311 | static bool isValidElementType(Type *ElemTy); |
| 312 | |
| 313 | |
| 314 | using element_iterator = Type::subtype_iterator; |
| 315 | |
| 316 | element_iterator element_begin() const { return ContainedTys; } |
| 317 | element_iterator element_end() const { return &ContainedTys[NumContainedTys];} |
| 318 | ArrayRef<Type *> elements() const { |
| 319 | return makeArrayRef(element_begin(), element_end()); |
| 320 | } |
| 321 | |
| 322 | |
| 323 | bool isLayoutIdentical(StructType *Other) const; |
| 324 | |
| 325 | |
| 326 | unsigned getNumElements() const { return NumContainedTys; } |
| 327 | Type *getElementType(unsigned N) const { |
| 328 | assert(N < NumContainedTys && "Element number out of range!"); |
| 329 | return ContainedTys[N]; |
| 330 | } |
| 331 | |
| 332 | Type *getTypeAtIndex(const Value *V) const; |
| 333 | Type *getTypeAtIndex(unsigned N) const { return getElementType(N); } |
| 334 | bool indexValid(const Value *V) const; |
| 335 | bool indexValid(unsigned Idx) const { return Idx < getNumElements(); } |
| 336 | |
| 337 | |
| 338 | static bool classof(const Type *T) { |
| 339 | return T->getTypeID() == StructTyID; |
| 340 | } |
| 341 | }; |
| 342 | |
| 343 | StringRef Type::getStructName() const { |
| 344 | return cast<StructType>(this)->getName(); |
| 345 | } |
| 346 | |
| 347 | unsigned Type::getStructNumElements() const { |
| 348 | return cast<StructType>(this)->getNumElements(); |
| 349 | } |
| 350 | |
| 351 | Type *Type::getStructElementType(unsigned N) const { |
| 352 | return cast<StructType>(this)->getElementType(N); |
| 353 | } |
| 354 | |
| 355 | |
| 356 | class ArrayType : public Type { |
| 357 | |
| 358 | Type *ContainedType; |
| 359 | |
| 360 | uint64_t NumElements; |
| 361 | |
| 362 | ArrayType(Type *ElType, uint64_t NumEl); |
| 363 | |
| 364 | public: |
| 365 | ArrayType(const ArrayType &) = delete; |
| 366 | ArrayType &operator=(const ArrayType &) = delete; |
| 367 | |
| 368 | uint64_t getNumElements() const { return NumElements; } |
| 369 | Type *getElementType() const { return ContainedType; } |
| 370 | |
| 371 | |
| 372 | static ArrayType *get(Type *ElementType, uint64_t NumElements); |
| 373 | |
| 374 | |
| 375 | static bool isValidElementType(Type *ElemTy); |
| 376 | |
| 377 | |
| 378 | static bool classof(const Type *T) { |
| 379 | return T->getTypeID() == ArrayTyID; |
| 380 | } |
| 381 | }; |
| 382 | |
| 383 | uint64_t Type::getArrayNumElements() const { |
| 384 | return cast<ArrayType>(this)->getNumElements(); |
| 385 | } |
| 386 | |
| 387 | |
| 388 | class VectorType : public Type { |
| 389 | |
| 390 | |
| 391 | |
| 392 | |
| 393 | |
| 394 | |
| 395 | |
| 396 | |
| 397 | |
| 398 | |
| 399 | |
| 400 | |
| 401 | |
| 402 | |
| 403 | Type *ContainedType; |
| 404 | |
| 405 | protected: |
| 406 | |
| 407 | |
| 408 | |
| 409 | |
| 410 | |
| 411 | |
| 412 | |
| 413 | const unsigned ElementQuantity; |
| 414 | |
| 415 | VectorType(Type *ElType, unsigned EQ, Type::TypeID TID); |
| 416 | |
| 417 | public: |
| 418 | VectorType(const VectorType &) = delete; |
| 419 | VectorType &operator=(const VectorType &) = delete; |
| 420 | |
| 421 | Type *getElementType() const { return ContainedType; } |
| 422 | |
| 423 | |
| 424 | static VectorType *get(Type *ElementType, ElementCount EC); |
| 425 | |
| 426 | static VectorType *get(Type *ElementType, unsigned NumElements, |
| 427 | bool Scalable) { |
| 428 | return VectorType::get(ElementType, |
| 429 | ElementCount::get(NumElements, Scalable)); |
| 430 | } |
| 431 | |
| 432 | static VectorType *get(Type *ElementType, const VectorType *Other) { |
| 433 | return VectorType::get(ElementType, Other->getElementCount()); |
| 434 | } |
| 435 | |
| 436 | |
| 437 | |
| 438 | |
| 439 | static VectorType *getInteger(VectorType *VTy) { |
| 440 | unsigned EltBits = VTy->getElementType()->getPrimitiveSizeInBits(); |
| 441 | assert(EltBits && "Element size must be of a non-zero size"); |
| 442 | Type *EltTy = IntegerType::get(VTy->getContext(), EltBits); |
| 443 | return VectorType::get(EltTy, VTy->getElementCount()); |
| 444 | } |
| 445 | |
| 446 | |
| 447 | |
| 448 | static VectorType *getExtendedElementVectorType(VectorType *VTy) { |
| 449 | assert(VTy->isIntOrIntVectorTy() && "VTy expected to be a vector of ints."); |
| 450 | auto *EltTy = cast<IntegerType>(VTy->getElementType()); |
| 451 | return VectorType::get(EltTy->getExtendedType(), VTy->getElementCount()); |
| 452 | } |
| 453 | |
| 454 | |
| 455 | |
| 456 | |
| 457 | static VectorType *getTruncatedElementVectorType(VectorType *VTy) { |
| 458 | Type *EltTy; |
| 459 | if (VTy->getElementType()->isFloatingPointTy()) { |
| 460 | switch(VTy->getElementType()->getTypeID()) { |
| 461 | case DoubleTyID: |
| 462 | EltTy = Type::getFloatTy(VTy->getContext()); |
| 463 | break; |
| 464 | case FloatTyID: |
| 465 | EltTy = Type::getHalfTy(VTy->getContext()); |
| 466 | break; |
| 467 | default: |
| 468 | llvm_unreachable("Cannot create narrower fp vector element type"); |
| 469 | } |
| 470 | } else { |
| 471 | unsigned EltBits = VTy->getElementType()->getPrimitiveSizeInBits(); |
| 472 | assert((EltBits & 1) == 0 && |
| 473 | "Cannot truncate vector element with odd bit-width"); |
| 474 | EltTy = IntegerType::get(VTy->getContext(), EltBits / 2); |
| 475 | } |
| 476 | return VectorType::get(EltTy, VTy->getElementCount()); |
| 477 | } |
| 478 | |
| 479 | |
| 480 | |
| 481 | |
| 482 | static VectorType *getSubdividedVectorType(VectorType *VTy, int NumSubdivs) { |
| 483 | for (int i = 0; i < NumSubdivs; ++i) { |
| 18 | | Loop condition is true. Entering loop body | |
|
| 484 | VTy = VectorType::getDoubleElementsVectorType(VTy); |
| 19 | | Passing null pointer value via 1st parameter 'VTy' | |
|
| 20 | | Calling 'VectorType::getDoubleElementsVectorType' | |
|
| 485 | VTy = VectorType::getTruncatedElementVectorType(VTy); |
| 486 | } |
| 487 | return VTy; |
| 488 | } |
| 489 | |
| 490 | |
| 491 | |
| 492 | static VectorType *getHalfElementsVectorType(VectorType *VTy) { |
| 493 | auto EltCnt = VTy->getElementCount(); |
| 494 | assert(EltCnt.isKnownEven() && |
| 495 | "Cannot halve vector with odd number of elements."); |
| 496 | return VectorType::get(VTy->getElementType(), |
| 497 | EltCnt.divideCoefficientBy(2)); |
| 498 | } |
| 499 | |
| 500 | |
| 501 | |
| 502 | static VectorType *getDoubleElementsVectorType(VectorType *VTy) { |
| 503 | auto EltCnt = VTy->getElementCount(); |
| 21 | | Called C++ object pointer is null |
|
| 504 | assert((EltCnt.getKnownMinValue() * 2ull) <= UINT_MAX && |
| 505 | "Too many elements in vector"); |
| 506 | return VectorType::get(VTy->getElementType(), EltCnt * 2); |
| 507 | } |
| 508 | |
| 509 | |
| 510 | static bool isValidElementType(Type *ElemTy); |
| 511 | |
| 512 | |
| 513 | |
| 514 | inline ElementCount getElementCount() const; |
| 515 | |
| 516 | |
| 517 | static bool classof(const Type *T) { |
| 518 | return T->getTypeID() == FixedVectorTyID || |
| 519 | T->getTypeID() == ScalableVectorTyID; |
| 520 | } |
| 521 | }; |
| 522 | |
| 523 | |
| 524 | class FixedVectorType : public VectorType { |
| 525 | protected: |
| 526 | FixedVectorType(Type *ElTy, unsigned NumElts) |
| 527 | : VectorType(ElTy, NumElts, FixedVectorTyID) {} |
| 528 | |
| 529 | public: |
| 530 | static FixedVectorType *get(Type *ElementType, unsigned NumElts); |
| 531 | |
| 532 | static FixedVectorType *get(Type *ElementType, const FixedVectorType *FVTy) { |
| 533 | return get(ElementType, FVTy->getNumElements()); |
| 534 | } |
| 535 | |
| 536 | static FixedVectorType *getInteger(FixedVectorType *VTy) { |
| 537 | return cast<FixedVectorType>(VectorType::getInteger(VTy)); |
| 538 | } |
| 539 | |
| 540 | static FixedVectorType *getExtendedElementVectorType(FixedVectorType *VTy) { |
| 541 | return cast<FixedVectorType>(VectorType::getExtendedElementVectorType(VTy)); |
| 542 | } |
| 543 | |
| 544 | static FixedVectorType *getTruncatedElementVectorType(FixedVectorType *VTy) { |
| 545 | return cast<FixedVectorType>( |
| 546 | VectorType::getTruncatedElementVectorType(VTy)); |
| 547 | } |
| 548 | |
| 549 | static FixedVectorType *getSubdividedVectorType(FixedVectorType *VTy, |
| 550 | int NumSubdivs) { |
| 551 | return cast<FixedVectorType>( |
| 552 | VectorType::getSubdividedVectorType(VTy, NumSubdivs)); |
| 553 | } |
| 554 | |
| 555 | static FixedVectorType *getHalfElementsVectorType(FixedVectorType *VTy) { |
| 556 | return cast<FixedVectorType>(VectorType::getHalfElementsVectorType(VTy)); |
| 557 | } |
| 558 | |
| 559 | static FixedVectorType *getDoubleElementsVectorType(FixedVectorType *VTy) { |
| 560 | return cast<FixedVectorType>(VectorType::getDoubleElementsVectorType(VTy)); |
| 561 | } |
| 562 | |
| 563 | static bool classof(const Type *T) { |
| 564 | return T->getTypeID() == FixedVectorTyID; |
| 565 | } |
| 566 | |
| 567 | unsigned getNumElements() const { return ElementQuantity; } |
| 568 | }; |
| 569 | |
| 570 | |
| 571 | class ScalableVectorType : public VectorType { |
| 572 | protected: |
| 573 | ScalableVectorType(Type *ElTy, unsigned MinNumElts) |
| 574 | : VectorType(ElTy, MinNumElts, ScalableVectorTyID) {} |
| 575 | |
| 576 | public: |
| 577 | static ScalableVectorType *get(Type *ElementType, unsigned MinNumElts); |
| 578 | |
| 579 | static ScalableVectorType *get(Type *ElementType, |
| 580 | const ScalableVectorType *SVTy) { |
| 581 | return get(ElementType, SVTy->getMinNumElements()); |
| 582 | } |
| 583 | |
| 584 | static ScalableVectorType *getInteger(ScalableVectorType *VTy) { |
| 585 | return cast<ScalableVectorType>(VectorType::getInteger(VTy)); |
| 586 | } |
| 587 | |
| 588 | static ScalableVectorType * |
| 589 | getExtendedElementVectorType(ScalableVectorType *VTy) { |
| 590 | return cast<ScalableVectorType>( |
| 591 | VectorType::getExtendedElementVectorType(VTy)); |
| 592 | } |
| 593 | |
| 594 | static ScalableVectorType * |
| 595 | getTruncatedElementVectorType(ScalableVectorType *VTy) { |
| 596 | return cast<ScalableVectorType>( |
| 597 | VectorType::getTruncatedElementVectorType(VTy)); |
| 598 | } |
| 599 | |
| 600 | static ScalableVectorType *getSubdividedVectorType(ScalableVectorType *VTy, |
| 601 | int NumSubdivs) { |
| 602 | return cast<ScalableVectorType>( |
| 603 | VectorType::getSubdividedVectorType(VTy, NumSubdivs)); |
| 604 | } |
| 605 | |
| 606 | static ScalableVectorType * |
| 607 | getHalfElementsVectorType(ScalableVectorType *VTy) { |
| 608 | return cast<ScalableVectorType>(VectorType::getHalfElementsVectorType(VTy)); |
| 609 | } |
| 610 | |
| 611 | static ScalableVectorType * |
| 612 | getDoubleElementsVectorType(ScalableVectorType *VTy) { |
| 613 | return cast<ScalableVectorType>( |
| 614 | VectorType::getDoubleElementsVectorType(VTy)); |
| 615 | } |
| 616 | |
| 617 | |
| 618 | |
| 619 | uint64_t getMinNumElements() const { return ElementQuantity; } |
| 620 | |
| 621 | static bool classof(const Type *T) { |
| 622 | return T->getTypeID() == ScalableVectorTyID; |
| 623 | } |
| 624 | }; |
| 625 | |
| 626 | inline ElementCount VectorType::getElementCount() const { |
| 627 | return ElementCount::get(ElementQuantity, isa<ScalableVectorType>(this)); |
| 628 | } |
| 629 | |
| 630 | |
| 631 | class PointerType : public Type { |
| 632 | explicit PointerType(Type *ElType, unsigned AddrSpace); |
| 633 | explicit PointerType(LLVMContext &C, unsigned AddrSpace); |
| 634 | |
| 635 | Type *PointeeTy; |
| 636 | |
| 637 | public: |
| 638 | PointerType(const PointerType &) = delete; |
| 639 | PointerType &operator=(const PointerType &) = delete; |
| 640 | |
| 641 | |
| 642 | |
| 643 | static PointerType *get(Type *ElementType, unsigned AddressSpace); |
| 644 | |
| 645 | |
| 646 | static PointerType *get(LLVMContext &C, unsigned AddressSpace); |
| 647 | |
| 648 | |
| 649 | |
| 650 | static PointerType *getUnqual(Type *ElementType) { |
| 651 | return PointerType::get(ElementType, 0); |
| 652 | } |
| 653 | |
| 654 | |
| 655 | |
| 656 | static PointerType *getUnqual(LLVMContext &C) { |
| 657 | return PointerType::get(C, 0); |
| 658 | } |
| 659 | |
| 660 | |
| 661 | |
| 662 | |
| 663 | |
| 664 | |
| 665 | static PointerType *getWithSamePointeeType(PointerType *PT, |
| 666 | unsigned AddressSpace) { |
| 667 | if (PT->isOpaque()) |
| 668 | return get(PT->getContext(), AddressSpace); |
| 669 | return get(PT->getElementType(), AddressSpace); |
| 670 | } |
| 671 | |
| 672 | Type *getElementType() const { |
| 673 | assert(!isOpaque() && "Attempting to get element type of opaque pointer"); |
| 674 | return PointeeTy; |
| 675 | } |
| 676 | |
| 677 | bool isOpaque() const { return !PointeeTy; } |
| 678 | |
| 679 | |
| 680 | static bool isValidElementType(Type *ElemTy); |
| 681 | |
| 682 | |
| 683 | static bool isLoadableOrStorableType(Type *ElemTy); |
| 684 | |
| 685 | |
| 686 | inline unsigned getAddressSpace() const { return getSubclassData(); } |
| 687 | |
| 688 | |
| 689 | |
| 690 | |
| 691 | |
| 692 | bool isOpaqueOrPointeeTypeMatches(Type *Ty) { |
| 693 | return isOpaque() || PointeeTy == Ty; |
| 694 | } |
| 695 | |
| 696 | |
| 697 | |
| 698 | |
| 699 | |
| 700 | bool hasSameElementTypeAs(PointerType *Other) { |
| 701 | return PointeeTy == Other->PointeeTy; |
| 702 | } |
| 703 | |
| 704 | |
| 705 | static bool classof(const Type *T) { |
| 706 | return T->getTypeID() == PointerTyID; |
| 707 | } |
| 708 | }; |
| 709 | |
| 710 | Type *Type::getExtendedType() const { |
| 711 | assert( |
| 712 | isIntOrIntVectorTy() && |
| 713 | "Original type expected to be a vector of integers or a scalar integer."); |
| 714 | if (auto *VTy = dyn_cast<VectorType>(this)) |
| 715 | return VectorType::getExtendedElementVectorType( |
| 716 | const_cast<VectorType *>(VTy)); |
| 717 | return cast<IntegerType>(this)->getExtendedType(); |
| 718 | } |
| 719 | |
| 720 | Type *Type::getWithNewType(Type *EltTy) const { |
| 721 | if (auto *VTy = dyn_cast<VectorType>(this)) |
| 722 | return VectorType::get(EltTy, VTy->getElementCount()); |
| 723 | return EltTy; |
| 724 | } |
| 725 | |
| 726 | Type *Type::getWithNewBitWidth(unsigned NewBitWidth) const { |
| 727 | assert( |
| 728 | isIntOrIntVectorTy() && |
| 729 | "Original type expected to be a vector of integers or a scalar integer."); |
| 730 | return getWithNewType(getIntNTy(getContext(), NewBitWidth)); |
| 731 | } |
| 732 | |
| 733 | unsigned Type::getPointerAddressSpace() const { |
| 734 | return cast<PointerType>(getScalarType())->getAddressSpace(); |
| 735 | } |
| 736 | |
| 737 | } |
| 738 | |
| 739 | #endif // LLVM_IR_DERIVEDTYPES_H |