LLVM  9.0.0svn
Function.cpp
Go to the documentation of this file.
1 //===- Function.cpp - Implement the Global object classes -----------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the Function class for the IR library.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "llvm/IR/Function.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/Argument.h"
24 #include "llvm/IR/Attributes.h"
25 #include "llvm/IR/BasicBlock.h"
26 #include "llvm/IR/Constant.h"
27 #include "llvm/IR/Constants.h"
28 #include "llvm/IR/DerivedTypes.h"
29 #include "llvm/IR/GlobalValue.h"
30 #include "llvm/IR/InstIterator.h"
31 #include "llvm/IR/Instruction.h"
32 #include "llvm/IR/Instructions.h"
33 #include "llvm/IR/IntrinsicInst.h"
34 #include "llvm/IR/Intrinsics.h"
35 #include "llvm/IR/LLVMContext.h"
36 #include "llvm/IR/MDBuilder.h"
37 #include "llvm/IR/Metadata.h"
38 #include "llvm/IR/Module.h"
40 #include "llvm/IR/Type.h"
41 #include "llvm/IR/Use.h"
42 #include "llvm/IR/User.h"
43 #include "llvm/IR/Value.h"
45 #include "llvm/Support/Casting.h"
46 #include "llvm/Support/Compiler.h"
48 #include <algorithm>
49 #include <cassert>
50 #include <cstddef>
51 #include <cstdint>
52 #include <cstring>
53 #include <string>
54 
55 using namespace llvm;
57 
58 // Explicit instantiations of SymbolTableListTraits since some of the methods
59 // are not in the public header file...
61 
62 //===----------------------------------------------------------------------===//
63 // Argument Implementation
64 //===----------------------------------------------------------------------===//
65 
66 Argument::Argument(Type *Ty, const Twine &Name, Function *Par, unsigned ArgNo)
67  : Value(Ty, Value::ArgumentVal), Parent(Par), ArgNo(ArgNo) {
68  setName(Name);
69 }
70 
71 void Argument::setParent(Function *parent) {
72  Parent = parent;
73 }
74 
76  if (!getType()->isPointerTy()) return false;
77  if (getParent()->hasParamAttribute(getArgNo(), Attribute::NonNull))
78  return true;
79  else if (getDereferenceableBytes() > 0 &&
81  getType()->getPointerAddressSpace()))
82  return true;
83  return false;
84 }
85 
86 bool Argument::hasByValAttr() const {
87  if (!getType()->isPointerTy()) return false;
88  return hasAttribute(Attribute::ByVal);
89 }
90 
92  return getParent()->hasParamAttribute(getArgNo(), Attribute::SwiftSelf);
93 }
94 
96  return getParent()->hasParamAttribute(getArgNo(), Attribute::SwiftError);
97 }
98 
100  if (!getType()->isPointerTy()) return false;
101  return hasAttribute(Attribute::InAlloca);
102 }
103 
105  if (!getType()->isPointerTy()) return false;
107  return Attrs.hasParamAttribute(getArgNo(), Attribute::ByVal) ||
108  Attrs.hasParamAttribute(getArgNo(), Attribute::InAlloca);
109 }
110 
111 unsigned Argument::getParamAlignment() const {
112  assert(getType()->isPointerTy() && "Only pointers have alignments");
113  return getParent()->getParamAlignment(getArgNo());
114 }
115 
117  assert(getType()->isPointerTy() && "Only pointers have byval types");
118  return getParent()->getParamByValType(getArgNo());
119 }
120 
122  assert(getType()->isPointerTy() &&
123  "Only pointers have dereferenceable bytes");
125 }
126 
128  assert(getType()->isPointerTy() &&
129  "Only pointers have dereferenceable bytes");
131 }
132 
133 bool Argument::hasNestAttr() const {
134  if (!getType()->isPointerTy()) return false;
135  return hasAttribute(Attribute::Nest);
136 }
137 
139  if (!getType()->isPointerTy()) return false;
141 }
142 
144  if (!getType()->isPointerTy()) return false;
145  return hasAttribute(Attribute::NoCapture);
146 }
147 
149  if (!getType()->isPointerTy()) return false;
150  return hasAttribute(Attribute::StructRet);
151 }
152 
154  return hasAttribute(Attribute::InReg);
155 }
156 
158  return hasAttribute(Attribute::Returned);
159 }
160 
161 bool Argument::hasZExtAttr() const {
162  return hasAttribute(Attribute::ZExt);
163 }
164 
165 bool Argument::hasSExtAttr() const {
166  return hasAttribute(Attribute::SExt);
167 }
168 
171  return Attrs.hasParamAttribute(getArgNo(), Attribute::ReadOnly) ||
172  Attrs.hasParamAttribute(getArgNo(), Attribute::ReadNone);
173 }
174 
177  AL = AL.addParamAttributes(Parent->getContext(), getArgNo(), B);
178  getParent()->setAttributes(AL);
179 }
180 
182  getParent()->addParamAttr(getArgNo(), Kind);
183 }
184 
186  getParent()->addParamAttr(getArgNo(), Attr);
187 }
188 
190  getParent()->removeParamAttr(getArgNo(), Kind);
191 }
192 
194  return getParent()->hasParamAttribute(getArgNo(), Kind);
195 }
196 
198  return getParent()->getParamAttribute(getArgNo(), Kind);
199 }
200 
201 //===----------------------------------------------------------------------===//
202 // Helper Methods in Function
203 //===----------------------------------------------------------------------===//
204 
206  return getType()->getContext();
207 }
208 
210  unsigned NumInstrs = 0;
211  for (const BasicBlock &BB : BasicBlocks)
212  NumInstrs += std::distance(BB.instructionsWithoutDebug().begin(),
213  BB.instructionsWithoutDebug().end());
214  return NumInstrs;
215 }
216 
218  const Twine &N, Module &M) {
219  return Create(Ty, Linkage, M.getDataLayout().getProgramAddressSpace(), N, &M);
220 }
221 
223  getParent()->getFunctionList().remove(getIterator());
224 }
225 
227  getParent()->getFunctionList().erase(getIterator());
228 }
229 
230 //===----------------------------------------------------------------------===//
231 // Function Implementation
232 //===----------------------------------------------------------------------===//
233 
234 static unsigned computeAddrSpace(unsigned AddrSpace, Module *M) {
235  // If AS == -1 and we are passed a valid module pointer we place the function
236  // in the program address space. Otherwise we default to AS0.
237  if (AddrSpace == static_cast<unsigned>(-1))
238  return M ? M->getDataLayout().getProgramAddressSpace() : 0;
239  return AddrSpace;
240 }
241 
242 Function::Function(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace,
243  const Twine &name, Module *ParentModule)
244  : GlobalObject(Ty, Value::FunctionVal,
245  OperandTraits<Function>::op_begin(this), 0, Linkage, name,
246  computeAddrSpace(AddrSpace, ParentModule)),
247  NumArgs(Ty->getNumParams()) {
248  assert(FunctionType::isValidReturnType(getReturnType()) &&
249  "invalid return type");
250  setGlobalObjectSubClassData(0);
251 
252  // We only need a symbol table for a function if the context keeps value names
253  if (!getContext().shouldDiscardValueNames())
254  SymTab = make_unique<ValueSymbolTable>();
255 
256  // If the function has arguments, mark them as lazily built.
257  if (Ty->getNumParams())
258  setValueSubclassData(1); // Set the "has lazy arguments" bit.
259 
260  if (ParentModule)
261  ParentModule->getFunctionList().push_back(this);
262 
263  HasLLVMReservedName = getName().startswith("llvm.");
264  // Ensure intrinsics have the right parameter attributes.
265  // Note, the IntID field will have been set in Value::setName if this function
266  // name is a valid intrinsic ID.
267  if (IntID)
268  setAttributes(Intrinsic::getAttributes(getContext(), IntID));
269 }
270 
272  dropAllReferences(); // After this it is safe to delete instructions.
273 
274  // Delete all of the method arguments and unlink from symbol table...
275  if (Arguments)
276  clearArguments();
277 
278  // Remove the function from the on-the-side GC table.
279  clearGC();
280 }
281 
282 void Function::BuildLazyArguments() const {
283  // Create the arguments vector, all arguments start out unnamed.
284  auto *FT = getFunctionType();
285  if (NumArgs > 0) {
286  Arguments = std::allocator<Argument>().allocate(NumArgs);
287  for (unsigned i = 0, e = NumArgs; i != e; ++i) {
288  Type *ArgTy = FT->getParamType(i);
289  assert(!ArgTy->isVoidTy() && "Cannot have void typed arguments!");
290  new (Arguments + i) Argument(ArgTy, "", const_cast<Function *>(this), i);
291  }
292  }
293 
294  // Clear the lazy arguments bit.
295  unsigned SDC = getSubclassDataFromValue();
296  const_cast<Function*>(this)->setValueSubclassData(SDC &= ~(1<<0));
297  assert(!hasLazyArguments());
298 }
299 
301  return MutableArrayRef<Argument>(Args, Count);
302 }
303 
304 void Function::clearArguments() {
305  for (Argument &A : makeArgArray(Arguments, NumArgs)) {
306  A.setName("");
307  A.~Argument();
308  }
309  std::allocator<Argument>().deallocate(Arguments, NumArgs);
310  Arguments = nullptr;
311 }
312 
314  assert(isDeclaration() && "Expected no references to current arguments");
315 
316  // Drop the current arguments, if any, and set the lazy argument bit.
317  if (!hasLazyArguments()) {
319  [](const Argument &A) { return A.use_empty(); }) &&
320  "Expected arguments to be unused in declaration");
321  clearArguments();
323  }
324 
325  // Nothing to steal if Src has lazy arguments.
326  if (Src.hasLazyArguments())
327  return;
328 
329  // Steal arguments from Src, and fix the lazy argument bits.
330  assert(arg_size() == Src.arg_size());
331  Arguments = Src.Arguments;
332  Src.Arguments = nullptr;
333  for (Argument &A : makeArgArray(Arguments, NumArgs)) {
334  // FIXME: This does the work of transferNodesFromList inefficiently.
336  if (A.hasName())
337  Name = A.getName();
338  if (!Name.empty())
339  A.setName("");
340  A.setParent(this);
341  if (!Name.empty())
342  A.setName(Name);
343  }
344 
346  assert(!hasLazyArguments());
347  Src.setValueSubclassData(Src.getSubclassDataFromValue() | (1 << 0));
348 }
349 
350 // dropAllReferences() - This function causes all the subinstructions to "let
351 // go" of all references that they are maintaining. This allows one to
352 // 'delete' a whole class at a time, even though there may be circular
353 // references... first all references are dropped, and all use counts go to
354 // zero. Then everything is deleted for real. Note that no operations are
355 // valid on an object that has "dropped all references", except operator
356 // delete.
357 //
359  setIsMaterializable(false);
360 
361  for (BasicBlock &BB : *this)
362  BB.dropAllReferences();
363 
364  // Delete all basic blocks. They are now unused, except possibly by
365  // blockaddresses, but BasicBlock's destructor takes care of those.
366  while (!BasicBlocks.empty())
367  BasicBlocks.begin()->eraseFromParent();
368 
369  // Drop uses of any optional data (real or placeholder).
370  if (getNumOperands()) {
372  setNumHungOffUseOperands(0);
374  }
375 
376  // Metadata is stored in a side-table.
377  clearMetadata();
378 }
379 
382  PAL = PAL.addAttribute(getContext(), i, Kind);
383  setAttributes(PAL);
384 }
385 
386 void Function::addAttribute(unsigned i, Attribute Attr) {
388  PAL = PAL.addAttribute(getContext(), i, Attr);
389  setAttributes(PAL);
390 }
391 
392 void Function::addAttributes(unsigned i, const AttrBuilder &Attrs) {
394  PAL = PAL.addAttributes(getContext(), i, Attrs);
395  setAttributes(PAL);
396 }
397 
400  PAL = PAL.addParamAttribute(getContext(), ArgNo, Kind);
401  setAttributes(PAL);
402 }
403 
404 void Function::addParamAttr(unsigned ArgNo, Attribute Attr) {
406  PAL = PAL.addParamAttribute(getContext(), ArgNo, Attr);
407  setAttributes(PAL);
408 }
409 
410 void Function::addParamAttrs(unsigned ArgNo, const AttrBuilder &Attrs) {
412  PAL = PAL.addParamAttributes(getContext(), ArgNo, Attrs);
413  setAttributes(PAL);
414 }
415 
418  PAL = PAL.removeAttribute(getContext(), i, Kind);
419  setAttributes(PAL);
420 }
421 
424  PAL = PAL.removeAttribute(getContext(), i, Kind);
425  setAttributes(PAL);
426 }
427 
428 void Function::removeAttributes(unsigned i, const AttrBuilder &Attrs) {
430  PAL = PAL.removeAttributes(getContext(), i, Attrs);
431  setAttributes(PAL);
432 }
433 
436  PAL = PAL.removeParamAttribute(getContext(), ArgNo, Kind);
437  setAttributes(PAL);
438 }
439 
440 void Function::removeParamAttr(unsigned ArgNo, StringRef Kind) {
442  PAL = PAL.removeParamAttribute(getContext(), ArgNo, Kind);
443  setAttributes(PAL);
444 }
445 
446 void Function::removeParamAttrs(unsigned ArgNo, const AttrBuilder &Attrs) {
448  PAL = PAL.removeParamAttributes(getContext(), ArgNo, Attrs);
449  setAttributes(PAL);
450 }
451 
452 void Function::addDereferenceableAttr(unsigned i, uint64_t Bytes) {
454  PAL = PAL.addDereferenceableAttr(getContext(), i, Bytes);
455  setAttributes(PAL);
456 }
457 
458 void Function::addDereferenceableParamAttr(unsigned ArgNo, uint64_t Bytes) {
460  PAL = PAL.addDereferenceableParamAttr(getContext(), ArgNo, Bytes);
461  setAttributes(PAL);
462 }
463 
464 void Function::addDereferenceableOrNullAttr(unsigned i, uint64_t Bytes) {
466  PAL = PAL.addDereferenceableOrNullAttr(getContext(), i, Bytes);
467  setAttributes(PAL);
468 }
469 
471  uint64_t Bytes) {
473  PAL = PAL.addDereferenceableOrNullParamAttr(getContext(), ArgNo, Bytes);
474  setAttributes(PAL);
475 }
476 
477 const std::string &Function::getGC() const {
478  assert(hasGC() && "Function has no collector");
479  return getContext().getGC(*this);
480 }
481 
482 void Function::setGC(std::string Str) {
483  setValueSubclassDataBit(14, !Str.empty());
484  getContext().setGC(*this, std::move(Str));
485 }
486 
488  if (!hasGC())
489  return;
490  getContext().deleteGC(*this);
491  setValueSubclassDataBit(14, false);
492 }
493 
494 /// Copy all additional attributes (those not needed to create a Function) from
495 /// the Function Src to this one.
498  setCallingConv(Src->getCallingConv());
499  setAttributes(Src->getAttributes());
500  if (Src->hasGC())
501  setGC(Src->getGC());
502  else
503  clearGC();
504  if (Src->hasPersonalityFn())
505  setPersonalityFn(Src->getPersonalityFn());
506  if (Src->hasPrefixData())
507  setPrefixData(Src->getPrefixData());
508  if (Src->hasPrologueData())
509  setPrologueData(Src->getPrologueData());
510 }
511 
512 /// Table of string intrinsic names indexed by enum value.
513 static const char * const IntrinsicNameTable[] = {
514  "not_intrinsic",
515 #define GET_INTRINSIC_NAME_TABLE
516 #include "llvm/IR/IntrinsicImpl.inc"
517 #undef GET_INTRINSIC_NAME_TABLE
518 };
519 
520 /// Table of per-target intrinsic name tables.
521 #define GET_INTRINSIC_TARGET_DATA
522 #include "llvm/IR/IntrinsicImpl.inc"
523 #undef GET_INTRINSIC_TARGET_DATA
524 
525 /// Find the segment of \c IntrinsicNameTable for intrinsics with the same
526 /// target as \c Name, or the generic table if \c Name is not target specific.
527 ///
528 /// Returns the relevant slice of \c IntrinsicNameTable
530  assert(Name.startswith("llvm."));
531 
532  ArrayRef<IntrinsicTargetInfo> Targets(TargetInfos);
533  // Drop "llvm." and take the first dotted component. That will be the target
534  // if this is target specific.
535  StringRef Target = Name.drop_front(5).split('.').first;
536  auto It = llvm::bsearch(Targets, [=](const IntrinsicTargetInfo &TI) {
537  return Target <= TI.Name;
538  });
539  // We've either found the target or just fall back to the generic set, which
540  // is always first.
541  const auto &TI = It != Targets.end() && It->Name == Target ? *It : Targets[0];
542  return makeArrayRef(&IntrinsicNameTable[1] + TI.Offset, TI.Count);
543 }
544 
545 /// This does the actual lookup of an intrinsic ID which
546 /// matches the given function name.
548  ArrayRef<const char *> NameTable = findTargetSubtable(Name);
549  int Idx = Intrinsic::lookupLLVMIntrinsicByName(NameTable, Name);
550  if (Idx == -1)
552 
553  // Intrinsic IDs correspond to the location in IntrinsicNameTable, but we have
554  // an index into a sub-table.
555  int Adjust = NameTable.data() - IntrinsicNameTable;
556  Intrinsic::ID ID = static_cast<Intrinsic::ID>(Idx + Adjust);
557 
558  // If the intrinsic is not overloaded, require an exact match. If it is
559  // overloaded, require either exact or prefix match.
560  const auto MatchSize = strlen(NameTable[Idx]);
561  assert(Name.size() >= MatchSize && "Expected either exact or prefix match");
562  bool IsExactMatch = Name.size() == MatchSize;
563  return IsExactMatch || isOverloaded(ID) ? ID : Intrinsic::not_intrinsic;
564 }
565 
567  StringRef Name = getName();
568  if (!Name.startswith("llvm.")) {
569  HasLLVMReservedName = false;
570  IntID = Intrinsic::not_intrinsic;
571  return;
572  }
573  HasLLVMReservedName = true;
574  IntID = lookupIntrinsicID(Name);
575 }
576 
577 /// Returns a stable mangling for the type specified for use in the name
578 /// mangling scheme used by 'any' types in intrinsic signatures. The mangling
579 /// of named types is simply their name. Manglings for unnamed types consist
580 /// of a prefix ('p' for pointers, 'a' for arrays, 'f_' for functions)
581 /// combined with the mangling of their component types. A vararg function
582 /// type will have a suffix of 'vararg'. Since function types can contain
583 /// other function types, we close a function type mangling with suffix 'f'
584 /// which can't be confused with it's prefix. This ensures we don't have
585 /// collisions between two unrelated function types. Otherwise, you might
586 /// parse ffXX as f(fXX) or f(fX)X. (X is a placeholder for any other type.)
587 ///
588 static std::string getMangledTypeStr(Type* Ty) {
589  std::string Result;
590  if (PointerType* PTyp = dyn_cast<PointerType>(Ty)) {
591  Result += "p" + utostr(PTyp->getAddressSpace()) +
592  getMangledTypeStr(PTyp->getElementType());
593  } else if (ArrayType* ATyp = dyn_cast<ArrayType>(Ty)) {
594  Result += "a" + utostr(ATyp->getNumElements()) +
595  getMangledTypeStr(ATyp->getElementType());
596  } else if (StructType *STyp = dyn_cast<StructType>(Ty)) {
597  if (!STyp->isLiteral()) {
598  Result += "s_";
599  Result += STyp->getName();
600  } else {
601  Result += "sl_";
602  for (auto Elem : STyp->elements())
603  Result += getMangledTypeStr(Elem);
604  }
605  // Ensure nested structs are distinguishable.
606  Result += "s";
607  } else if (FunctionType *FT = dyn_cast<FunctionType>(Ty)) {
608  Result += "f_" + getMangledTypeStr(FT->getReturnType());
609  for (size_t i = 0; i < FT->getNumParams(); i++)
610  Result += getMangledTypeStr(FT->getParamType(i));
611  if (FT->isVarArg())
612  Result += "vararg";
613  // Ensure nested function types are distinguishable.
614  Result += "f";
615  } else if (isa<VectorType>(Ty)) {
616  Result += "v" + utostr(Ty->getVectorNumElements()) +
618  } else if (Ty) {
619  switch (Ty->getTypeID()) {
620  default: llvm_unreachable("Unhandled type");
621  case Type::VoidTyID: Result += "isVoid"; break;
622  case Type::MetadataTyID: Result += "Metadata"; break;
623  case Type::HalfTyID: Result += "f16"; break;
624  case Type::FloatTyID: Result += "f32"; break;
625  case Type::DoubleTyID: Result += "f64"; break;
626  case Type::X86_FP80TyID: Result += "f80"; break;
627  case Type::FP128TyID: Result += "f128"; break;
628  case Type::PPC_FP128TyID: Result += "ppcf128"; break;
629  case Type::X86_MMXTyID: Result += "x86mmx"; break;
630  case Type::IntegerTyID:
631  Result += "i" + utostr(cast<IntegerType>(Ty)->getBitWidth());
632  break;
633  }
634  }
635  return Result;
636 }
637 
639  assert(id < num_intrinsics && "Invalid intrinsic ID!");
640  assert(!isOverloaded(id) &&
641  "This version of getName does not support overloading");
642  return IntrinsicNameTable[id];
643 }
644 
645 std::string Intrinsic::getName(ID id, ArrayRef<Type*> Tys) {
646  assert(id < num_intrinsics && "Invalid intrinsic ID!");
647  std::string Result(IntrinsicNameTable[id]);
648  for (Type *Ty : Tys) {
649  Result += "." + getMangledTypeStr(Ty);
650  }
651  return Result;
652 }
653 
654 /// IIT_Info - These are enumerators that describe the entries returned by the
655 /// getIntrinsicInfoTableEntries function.
656 ///
657 /// NOTE: This must be kept in synch with the copy in TblGen/IntrinsicEmitter!
658 enum IIT_Info {
659  // Common values should be encoded with 0-15.
660  IIT_Done = 0,
661  IIT_I1 = 1,
662  IIT_I8 = 2,
663  IIT_I16 = 3,
664  IIT_I32 = 4,
665  IIT_I64 = 5,
666  IIT_F16 = 6,
667  IIT_F32 = 7,
668  IIT_F64 = 8,
669  IIT_V2 = 9,
670  IIT_V4 = 10,
671  IIT_V8 = 11,
672  IIT_V16 = 12,
673  IIT_V32 = 13,
674  IIT_PTR = 14,
675  IIT_ARG = 15,
676 
677  // Values from 16+ are only encodable with the inefficient encoding.
678  IIT_V64 = 16,
679  IIT_MMX = 17,
680  IIT_TOKEN = 18,
690  IIT_V1 = 28,
697  IIT_I128 = 35,
698  IIT_V512 = 36,
699  IIT_V1024 = 37,
703  IIT_F128 = 41,
705 };
706 
707 static void DecodeIITType(unsigned &NextElt, ArrayRef<unsigned char> Infos,
709  using namespace Intrinsic;
710 
711  IIT_Info Info = IIT_Info(Infos[NextElt++]);
712  unsigned StructElts = 2;
713 
714  switch (Info) {
715  case IIT_Done:
716  OutputTable.push_back(IITDescriptor::get(IITDescriptor::Void, 0));
717  return;
718  case IIT_VARARG:
719  OutputTable.push_back(IITDescriptor::get(IITDescriptor::VarArg, 0));
720  return;
721  case IIT_MMX:
722  OutputTable.push_back(IITDescriptor::get(IITDescriptor::MMX, 0));
723  return;
724  case IIT_TOKEN:
725  OutputTable.push_back(IITDescriptor::get(IITDescriptor::Token, 0));
726  return;
727  case IIT_METADATA:
728  OutputTable.push_back(IITDescriptor::get(IITDescriptor::Metadata, 0));
729  return;
730  case IIT_F16:
731  OutputTable.push_back(IITDescriptor::get(IITDescriptor::Half, 0));
732  return;
733  case IIT_F32:
734  OutputTable.push_back(IITDescriptor::get(IITDescriptor::Float, 0));
735  return;
736  case IIT_F64:
737  OutputTable.push_back(IITDescriptor::get(IITDescriptor::Double, 0));
738  return;
739  case IIT_F128:
740  OutputTable.push_back(IITDescriptor::get(IITDescriptor::Quad, 0));
741  return;
742  case IIT_I1:
743  OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 1));
744  return;
745  case IIT_I8:
746  OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 8));
747  return;
748  case IIT_I16:
749  OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer,16));
750  return;
751  case IIT_I32:
752  OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 32));
753  return;
754  case IIT_I64:
755  OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 64));
756  return;
757  case IIT_I128:
758  OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 128));
759  return;
760  case IIT_V1:
761  OutputTable.push_back(IITDescriptor::get(IITDescriptor::Vector, 1));
762  DecodeIITType(NextElt, Infos, OutputTable);
763  return;
764  case IIT_V2:
765  OutputTable.push_back(IITDescriptor::get(IITDescriptor::Vector, 2));
766  DecodeIITType(NextElt, Infos, OutputTable);
767  return;
768  case IIT_V4:
769  OutputTable.push_back(IITDescriptor::get(IITDescriptor::Vector, 4));
770  DecodeIITType(NextElt, Infos, OutputTable);
771  return;
772  case IIT_V8:
773  OutputTable.push_back(IITDescriptor::get(IITDescriptor::Vector, 8));
774  DecodeIITType(NextElt, Infos, OutputTable);
775  return;
776  case IIT_V16:
777  OutputTable.push_back(IITDescriptor::get(IITDescriptor::Vector, 16));
778  DecodeIITType(NextElt, Infos, OutputTable);
779  return;
780  case IIT_V32:
781  OutputTable.push_back(IITDescriptor::get(IITDescriptor::Vector, 32));
782  DecodeIITType(NextElt, Infos, OutputTable);
783  return;
784  case IIT_V64:
785  OutputTable.push_back(IITDescriptor::get(IITDescriptor::Vector, 64));
786  DecodeIITType(NextElt, Infos, OutputTable);
787  return;
788  case IIT_V512:
789  OutputTable.push_back(IITDescriptor::get(IITDescriptor::Vector, 512));
790  DecodeIITType(NextElt, Infos, OutputTable);
791  return;
792  case IIT_V1024:
793  OutputTable.push_back(IITDescriptor::get(IITDescriptor::Vector, 1024));
794  DecodeIITType(NextElt, Infos, OutputTable);
795  return;
796  case IIT_PTR:
797  OutputTable.push_back(IITDescriptor::get(IITDescriptor::Pointer, 0));
798  DecodeIITType(NextElt, Infos, OutputTable);
799  return;
800  case IIT_ANYPTR: { // [ANYPTR addrspace, subtype]
801  OutputTable.push_back(IITDescriptor::get(IITDescriptor::Pointer,
802  Infos[NextElt++]));
803  DecodeIITType(NextElt, Infos, OutputTable);
804  return;
805  }
806  case IIT_ARG: {
807  unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
808  OutputTable.push_back(IITDescriptor::get(IITDescriptor::Argument, ArgInfo));
809  return;
810  }
811  case IIT_EXTEND_ARG: {
812  unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
813  OutputTable.push_back(IITDescriptor::get(IITDescriptor::ExtendArgument,
814  ArgInfo));
815  return;
816  }
817  case IIT_TRUNC_ARG: {
818  unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
819  OutputTable.push_back(IITDescriptor::get(IITDescriptor::TruncArgument,
820  ArgInfo));
821  return;
822  }
823  case IIT_HALF_VEC_ARG: {
824  unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
825  OutputTable.push_back(IITDescriptor::get(IITDescriptor::HalfVecArgument,
826  ArgInfo));
827  return;
828  }
829  case IIT_SAME_VEC_WIDTH_ARG: {
830  unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
831  OutputTable.push_back(IITDescriptor::get(IITDescriptor::SameVecWidthArgument,
832  ArgInfo));
833  return;
834  }
835  case IIT_PTR_TO_ARG: {
836  unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
837  OutputTable.push_back(IITDescriptor::get(IITDescriptor::PtrToArgument,
838  ArgInfo));
839  return;
840  }
841  case IIT_PTR_TO_ELT: {
842  unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
843  OutputTable.push_back(IITDescriptor::get(IITDescriptor::PtrToElt, ArgInfo));
844  return;
845  }
847  unsigned short ArgNo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
848  unsigned short RefNo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
849  OutputTable.push_back(
850  IITDescriptor::get(IITDescriptor::VecOfAnyPtrsToElt, ArgNo, RefNo));
851  return;
852  }
853  case IIT_EMPTYSTRUCT:
854  OutputTable.push_back(IITDescriptor::get(IITDescriptor::Struct, 0));
855  return;
856  case IIT_STRUCT8: ++StructElts; LLVM_FALLTHROUGH;
857  case IIT_STRUCT7: ++StructElts; LLVM_FALLTHROUGH;
858  case IIT_STRUCT6: ++StructElts; LLVM_FALLTHROUGH;
859  case IIT_STRUCT5: ++StructElts; LLVM_FALLTHROUGH;
860  case IIT_STRUCT4: ++StructElts; LLVM_FALLTHROUGH;
861  case IIT_STRUCT3: ++StructElts; LLVM_FALLTHROUGH;
862  case IIT_STRUCT2: {
863  OutputTable.push_back(IITDescriptor::get(IITDescriptor::Struct,StructElts));
864 
865  for (unsigned i = 0; i != StructElts; ++i)
866  DecodeIITType(NextElt, Infos, OutputTable);
867  return;
868  }
869  case IIT_VEC_ELEMENT: {
870  unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
871  OutputTable.push_back(IITDescriptor::get(IITDescriptor::VecElementArgument,
872  ArgInfo));
873  return;
874  }
875  }
876  llvm_unreachable("unhandled");
877 }
878 
879 #define GET_INTRINSIC_GENERATOR_GLOBAL
880 #include "llvm/IR/IntrinsicImpl.inc"
881 #undef GET_INTRINSIC_GENERATOR_GLOBAL
882 
885  // Check to see if the intrinsic's type was expressible by the table.
886  unsigned TableVal = IIT_Table[id-1];
887 
888  // Decode the TableVal into an array of IITValues.
890  ArrayRef<unsigned char> IITEntries;
891  unsigned NextElt = 0;
892  if ((TableVal >> 31) != 0) {
893  // This is an offset into the IIT_LongEncodingTable.
894  IITEntries = IIT_LongEncodingTable;
895 
896  // Strip sentinel bit.
897  NextElt = (TableVal << 1) >> 1;
898  } else {
899  // Decode the TableVal into an array of IITValues. If the entry was encoded
900  // into a single word in the table itself, decode it now.
901  do {
902  IITValues.push_back(TableVal & 0xF);
903  TableVal >>= 4;
904  } while (TableVal);
905 
906  IITEntries = IITValues;
907  NextElt = 0;
908  }
909 
910  // Okay, decode the table into the output vector of IITDescriptors.
911  DecodeIITType(NextElt, IITEntries, T);
912  while (NextElt != IITEntries.size() && IITEntries[NextElt] != 0)
913  DecodeIITType(NextElt, IITEntries, T);
914 }
915 
918  using namespace Intrinsic;
919 
920  IITDescriptor D = Infos.front();
921  Infos = Infos.slice(1);
922 
923  switch (D.Kind) {
924  case IITDescriptor::Void: return Type::getVoidTy(Context);
925  case IITDescriptor::VarArg: return Type::getVoidTy(Context);
926  case IITDescriptor::MMX: return Type::getX86_MMXTy(Context);
927  case IITDescriptor::Token: return Type::getTokenTy(Context);
928  case IITDescriptor::Metadata: return Type::getMetadataTy(Context);
929  case IITDescriptor::Half: return Type::getHalfTy(Context);
930  case IITDescriptor::Float: return Type::getFloatTy(Context);
931  case IITDescriptor::Double: return Type::getDoubleTy(Context);
932  case IITDescriptor::Quad: return Type::getFP128Ty(Context);
933 
935  return IntegerType::get(Context, D.Integer_Width);
936  case IITDescriptor::Vector:
937  return VectorType::get(DecodeFixedType(Infos, Tys, Context),D.Vector_Width);
938  case IITDescriptor::Pointer:
939  return PointerType::get(DecodeFixedType(Infos, Tys, Context),
940  D.Pointer_AddressSpace);
941  case IITDescriptor::Struct: {
943  for (unsigned i = 0, e = D.Struct_NumElements; i != e; ++i)
944  Elts.push_back(DecodeFixedType(Infos, Tys, Context));
945  return StructType::get(Context, Elts);
946  }
947  case IITDescriptor::Argument:
948  return Tys[D.getArgumentNumber()];
949  case IITDescriptor::ExtendArgument: {
950  Type *Ty = Tys[D.getArgumentNumber()];
951  if (VectorType *VTy = dyn_cast<VectorType>(Ty))
953 
954  return IntegerType::get(Context, 2 * cast<IntegerType>(Ty)->getBitWidth());
955  }
956  case IITDescriptor::TruncArgument: {
957  Type *Ty = Tys[D.getArgumentNumber()];
958  if (VectorType *VTy = dyn_cast<VectorType>(Ty))
960 
961  IntegerType *ITy = cast<IntegerType>(Ty);
962  assert(ITy->getBitWidth() % 2 == 0);
963  return IntegerType::get(Context, ITy->getBitWidth() / 2);
964  }
965  case IITDescriptor::HalfVecArgument:
966  return VectorType::getHalfElementsVectorType(cast<VectorType>(
967  Tys[D.getArgumentNumber()]));
968  case IITDescriptor::SameVecWidthArgument: {
969  Type *EltTy = DecodeFixedType(Infos, Tys, Context);
970  Type *Ty = Tys[D.getArgumentNumber()];
971  if (auto *VTy = dyn_cast<VectorType>(Ty))
972  return VectorType::get(EltTy, VTy->getNumElements());
973  return EltTy;
974  }
975  case IITDescriptor::PtrToArgument: {
976  Type *Ty = Tys[D.getArgumentNumber()];
977  return PointerType::getUnqual(Ty);
978  }
979  case IITDescriptor::PtrToElt: {
980  Type *Ty = Tys[D.getArgumentNumber()];
981  VectorType *VTy = dyn_cast<VectorType>(Ty);
982  if (!VTy)
983  llvm_unreachable("Expected an argument of Vector Type");
984  Type *EltTy = VTy->getVectorElementType();
985  return PointerType::getUnqual(EltTy);
986  }
987  case IITDescriptor::VecElementArgument: {
988  Type *Ty = Tys[D.getArgumentNumber()];
989  if (VectorType *VTy = dyn_cast<VectorType>(Ty))
990  return VTy->getElementType();
991  llvm_unreachable("Expected an argument of Vector Type");
992  }
993  case IITDescriptor::VecOfAnyPtrsToElt:
994  // Return the overloaded type (which determines the pointers address space)
995  return Tys[D.getOverloadArgNumber()];
996  }
997  llvm_unreachable("unhandled");
998 }
999 
1001  ID id, ArrayRef<Type*> Tys) {
1003  getIntrinsicInfoTableEntries(id, Table);
1004 
1006  Type *ResultTy = DecodeFixedType(TableRef, Tys, Context);
1007 
1008  SmallVector<Type*, 8> ArgTys;
1009  while (!TableRef.empty())
1010  ArgTys.push_back(DecodeFixedType(TableRef, Tys, Context));
1011 
1012  // DecodeFixedType returns Void for IITDescriptor::Void and IITDescriptor::VarArg
1013  // If we see void type as the type of the last argument, it is vararg intrinsic
1014  if (!ArgTys.empty() && ArgTys.back()->isVoidTy()) {
1015  ArgTys.pop_back();
1016  return FunctionType::get(ResultTy, ArgTys, true);
1017  }
1018  return FunctionType::get(ResultTy, ArgTys, false);
1019 }
1020 
1022 #define GET_INTRINSIC_OVERLOAD_TABLE
1023 #include "llvm/IR/IntrinsicImpl.inc"
1024 #undef GET_INTRINSIC_OVERLOAD_TABLE
1025 }
1026 
1028  switch (id) {
1029  default:
1030  return true;
1031 
1032  case Intrinsic::experimental_gc_statepoint:
1033  case Intrinsic::experimental_patchpoint_void:
1034  case Intrinsic::experimental_patchpoint_i64:
1035  return false;
1036  }
1037 }
1038 
1039 /// This defines the "Intrinsic::getAttributes(ID id)" method.
1040 #define GET_INTRINSIC_ATTRIBUTES
1041 #include "llvm/IR/IntrinsicImpl.inc"
1042 #undef GET_INTRINSIC_ATTRIBUTES
1043 
1045  // There can never be multiple globals with the same name of different types,
1046  // because intrinsics must be a specific type.
1047  return cast<Function>(
1048  M->getOrInsertFunction(getName(id, Tys),
1049  getType(M->getContext(), id, Tys))
1050  .getCallee());
1051 }
1052 
1053 // This defines the "Intrinsic::getIntrinsicForGCCBuiltin()" method.
1054 #define GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN
1055 #include "llvm/IR/IntrinsicImpl.inc"
1056 #undef GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN
1057 
1058 // This defines the "Intrinsic::getIntrinsicForMSBuiltin()" method.
1059 #define GET_LLVM_INTRINSIC_FOR_MS_BUILTIN
1060 #include "llvm/IR/IntrinsicImpl.inc"
1061 #undef GET_LLVM_INTRINSIC_FOR_MS_BUILTIN
1062 
1064  std::pair<Type *, ArrayRef<Intrinsic::IITDescriptor>>;
1065 
1068  SmallVectorImpl<Type *> &ArgTys,
1070  bool IsDeferredCheck) {
1071  using namespace Intrinsic;
1072 
1073  // If we ran out of descriptors, there are too many arguments.
1074  if (Infos.empty()) return true;
1075 
1076  // Do this before slicing off the 'front' part
1077  auto InfosRef = Infos;
1078  auto DeferCheck = [&DeferredChecks, &InfosRef](Type *T) {
1079  DeferredChecks.emplace_back(T, InfosRef);
1080  return false;
1081  };
1082 
1083  IITDescriptor D = Infos.front();
1084  Infos = Infos.slice(1);
1085 
1086  switch (D.Kind) {
1087  case IITDescriptor::Void: return !Ty->isVoidTy();
1088  case IITDescriptor::VarArg: return true;
1089  case IITDescriptor::MMX: return !Ty->isX86_MMXTy();
1090  case IITDescriptor::Token: return !Ty->isTokenTy();
1091  case IITDescriptor::Metadata: return !Ty->isMetadataTy();
1092  case IITDescriptor::Half: return !Ty->isHalfTy();
1093  case IITDescriptor::Float: return !Ty->isFloatTy();
1094  case IITDescriptor::Double: return !Ty->isDoubleTy();
1095  case IITDescriptor::Quad: return !Ty->isFP128Ty();
1096  case IITDescriptor::Integer: return !Ty->isIntegerTy(D.Integer_Width);
1097  case IITDescriptor::Vector: {
1098  VectorType *VT = dyn_cast<VectorType>(Ty);
1099  return !VT || VT->getNumElements() != D.Vector_Width ||
1100  matchIntrinsicType(VT->getElementType(), Infos, ArgTys,
1101  DeferredChecks, IsDeferredCheck);
1102  }
1103  case IITDescriptor::Pointer: {
1104  PointerType *PT = dyn_cast<PointerType>(Ty);
1105  return !PT || PT->getAddressSpace() != D.Pointer_AddressSpace ||
1106  matchIntrinsicType(PT->getElementType(), Infos, ArgTys,
1107  DeferredChecks, IsDeferredCheck);
1108  }
1109 
1110  case IITDescriptor::Struct: {
1111  StructType *ST = dyn_cast<StructType>(Ty);
1112  if (!ST || ST->getNumElements() != D.Struct_NumElements)
1113  return true;
1114 
1115  for (unsigned i = 0, e = D.Struct_NumElements; i != e; ++i)
1116  if (matchIntrinsicType(ST->getElementType(i), Infos, ArgTys,
1117  DeferredChecks, IsDeferredCheck))
1118  return true;
1119  return false;
1120  }
1121 
1122  case IITDescriptor::Argument:
1123  // If this is the second occurrence of an argument,
1124  // verify that the later instance matches the previous instance.
1125  if (D.getArgumentNumber() < ArgTys.size())
1126  return Ty != ArgTys[D.getArgumentNumber()];
1127 
1128  if (D.getArgumentNumber() > ArgTys.size() ||
1129  D.getArgumentKind() == IITDescriptor::AK_MatchType)
1130  return IsDeferredCheck || DeferCheck(Ty);
1131 
1132  assert(D.getArgumentNumber() == ArgTys.size() && !IsDeferredCheck &&
1133  "Table consistency error");
1134  ArgTys.push_back(Ty);
1135 
1136  switch (D.getArgumentKind()) {
1137  case IITDescriptor::AK_Any: return false; // Success
1138  case IITDescriptor::AK_AnyInteger: return !Ty->isIntOrIntVectorTy();
1139  case IITDescriptor::AK_AnyFloat: return !Ty->isFPOrFPVectorTy();
1140  case IITDescriptor::AK_AnyVector: return !isa<VectorType>(Ty);
1141  case IITDescriptor::AK_AnyPointer: return !isa<PointerType>(Ty);
1142  default: break;
1143  }
1144  llvm_unreachable("all argument kinds not covered");
1145 
1146  case IITDescriptor::ExtendArgument: {
1147  // If this is a forward reference, defer the check for later.
1148  if (D.getArgumentNumber() >= ArgTys.size())
1149  return IsDeferredCheck || DeferCheck(Ty);
1150 
1151  Type *NewTy = ArgTys[D.getArgumentNumber()];
1152  if (VectorType *VTy = dyn_cast<VectorType>(NewTy))
1154  else if (IntegerType *ITy = dyn_cast<IntegerType>(NewTy))
1155  NewTy = IntegerType::get(ITy->getContext(), 2 * ITy->getBitWidth());
1156  else
1157  return true;
1158 
1159  return Ty != NewTy;
1160  }
1161  case IITDescriptor::TruncArgument: {
1162  // If this is a forward reference, defer the check for later.
1163  if (D.getArgumentNumber() >= ArgTys.size())
1164  return IsDeferredCheck || DeferCheck(Ty);
1165 
1166  Type *NewTy = ArgTys[D.getArgumentNumber()];
1167  if (VectorType *VTy = dyn_cast<VectorType>(NewTy))
1169  else if (IntegerType *ITy = dyn_cast<IntegerType>(NewTy))
1170  NewTy = IntegerType::get(ITy->getContext(), ITy->getBitWidth() / 2);
1171  else
1172  return true;
1173 
1174  return Ty != NewTy;
1175  }
1176  case IITDescriptor::HalfVecArgument:
1177  // If this is a forward reference, defer the check for later.
1178  return D.getArgumentNumber() >= ArgTys.size() ||
1179  !isa<VectorType>(ArgTys[D.getArgumentNumber()]) ||
1181  cast<VectorType>(ArgTys[D.getArgumentNumber()])) != Ty;
1182  case IITDescriptor::SameVecWidthArgument: {
1183  if (D.getArgumentNumber() >= ArgTys.size()) {
1184  // Defer check and subsequent check for the vector element type.
1185  Infos = Infos.slice(1);
1186  return IsDeferredCheck || DeferCheck(Ty);
1187  }
1188  auto *ReferenceType = dyn_cast<VectorType>(ArgTys[D.getArgumentNumber()]);
1189  auto *ThisArgType = dyn_cast<VectorType>(Ty);
1190  // Both must be vectors of the same number of elements or neither.
1191  if ((ReferenceType != nullptr) != (ThisArgType != nullptr))
1192  return true;
1193  Type *EltTy = Ty;
1194  if (ThisArgType) {
1195  if (ReferenceType->getVectorNumElements() !=
1196  ThisArgType->getVectorNumElements())
1197  return true;
1198  EltTy = ThisArgType->getVectorElementType();
1199  }
1200  return matchIntrinsicType(EltTy, Infos, ArgTys, DeferredChecks,
1201  IsDeferredCheck);
1202  }
1203  case IITDescriptor::PtrToArgument: {
1204  if (D.getArgumentNumber() >= ArgTys.size())
1205  return IsDeferredCheck || DeferCheck(Ty);
1206  Type * ReferenceType = ArgTys[D.getArgumentNumber()];
1207  PointerType *ThisArgType = dyn_cast<PointerType>(Ty);
1208  return (!ThisArgType || ThisArgType->getElementType() != ReferenceType);
1209  }
1210  case IITDescriptor::PtrToElt: {
1211  if (D.getArgumentNumber() >= ArgTys.size())
1212  return IsDeferredCheck || DeferCheck(Ty);
1214  dyn_cast<VectorType> (ArgTys[D.getArgumentNumber()]);
1215  PointerType *ThisArgType = dyn_cast<PointerType>(Ty);
1216 
1217  return (!ThisArgType || !ReferenceType ||
1218  ThisArgType->getElementType() != ReferenceType->getElementType());
1219  }
1220  case IITDescriptor::VecOfAnyPtrsToElt: {
1221  unsigned RefArgNumber = D.getRefArgNumber();
1222  if (RefArgNumber >= ArgTys.size()) {
1223  if (IsDeferredCheck)
1224  return true;
1225  // If forward referencing, already add the pointer-vector type and
1226  // defer the checks for later.
1227  ArgTys.push_back(Ty);
1228  return DeferCheck(Ty);
1229  }
1230 
1231  if (!IsDeferredCheck){
1232  assert(D.getOverloadArgNumber() == ArgTys.size() &&
1233  "Table consistency error");
1234  ArgTys.push_back(Ty);
1235  }
1236 
1237  // Verify the overloaded type "matches" the Ref type.
1238  // i.e. Ty is a vector with the same width as Ref.
1239  // Composed of pointers to the same element type as Ref.
1240  VectorType *ReferenceType = dyn_cast<VectorType>(ArgTys[RefArgNumber]);
1241  VectorType *ThisArgVecTy = dyn_cast<VectorType>(Ty);
1242  if (!ThisArgVecTy || !ReferenceType ||
1243  (ReferenceType->getVectorNumElements() !=
1244  ThisArgVecTy->getVectorNumElements()))
1245  return true;
1246  PointerType *ThisArgEltTy =
1247  dyn_cast<PointerType>(ThisArgVecTy->getVectorElementType());
1248  if (!ThisArgEltTy)
1249  return true;
1250  return ThisArgEltTy->getElementType() !=
1251  ReferenceType->getVectorElementType();
1252  }
1253  case IITDescriptor::VecElementArgument: {
1254  if (D.getArgumentNumber() >= ArgTys.size())
1255  return IsDeferredCheck ? true : DeferCheck(Ty);
1256  auto *ReferenceType = dyn_cast<VectorType>(ArgTys[D.getArgumentNumber()]);
1257  return !ReferenceType || Ty != ReferenceType->getElementType();
1258  }
1259  }
1260  llvm_unreachable("unhandled");
1261 }
1262 
1266  SmallVectorImpl<Type *> &ArgTys) {
1268  if (matchIntrinsicType(FTy->getReturnType(), Infos, ArgTys, DeferredChecks,
1269  false))
1271 
1272  unsigned NumDeferredReturnChecks = DeferredChecks.size();
1273 
1274  for (auto Ty : FTy->params())
1275  if (matchIntrinsicType(Ty, Infos, ArgTys, DeferredChecks, false))
1277 
1278  for (unsigned I = 0, E = DeferredChecks.size(); I != E; ++I) {
1279  DeferredIntrinsicMatchPair &Check = DeferredChecks[I];
1280  if (matchIntrinsicType(Check.first, Check.second, ArgTys, DeferredChecks,
1281  true))
1282  return I < NumDeferredReturnChecks ? MatchIntrinsicTypes_NoMatchRet
1284  }
1285 
1287 }
1288 
1289 bool
1292  // If there are no descriptors left, then it can't be a vararg.
1293  if (Infos.empty())
1294  return isVarArg;
1295 
1296  // There should be only one descriptor remaining at this point.
1297  if (Infos.size() != 1)
1298  return true;
1299 
1300  // Check and verify the descriptor.
1301  IITDescriptor D = Infos.front();
1302  Infos = Infos.slice(1);
1303  if (D.Kind == IITDescriptor::VarArg)
1304  return !isVarArg;
1305 
1306  return true;
1307 }
1308 
1311  if (!ID)
1312  return None;
1313 
1314  FunctionType *FTy = F->getFunctionType();
1315  // Accumulate an array of overloaded types for the given intrinsic
1316  SmallVector<Type *, 4> ArgTys;
1317  {
1319  getIntrinsicInfoTableEntries(ID, Table);
1321 
1322  if (Intrinsic::matchIntrinsicSignature(FTy, TableRef, ArgTys))
1323  return None;
1324  if (Intrinsic::matchIntrinsicVarArg(FTy->isVarArg(), TableRef))
1325  return None;
1326  }
1327 
1328  StringRef Name = F->getName();
1329  if (Name == Intrinsic::getName(ID, ArgTys))
1330  return None;
1331 
1332  auto NewDecl = Intrinsic::getDeclaration(F->getParent(), ID, ArgTys);
1333  NewDecl->setCallingConv(F->getCallingConv());
1334  assert(NewDecl->getFunctionType() == FTy && "Shouldn't change the signature");
1335  return NewDecl;
1336 }
1337 
1338 /// hasAddressTaken - returns true if there are any uses of this function
1339 /// other than direct calls or invokes to it.
1340 bool Function::hasAddressTaken(const User* *PutOffender) const {
1341  for (const Use &U : uses()) {
1342  const User *FU = U.getUser();
1343  if (isa<BlockAddress>(FU))
1344  continue;
1345  const auto *Call = dyn_cast<CallBase>(FU);
1346  if (!Call) {
1347  if (PutOffender)
1348  *PutOffender = FU;
1349  return true;
1350  }
1351  if (!Call->isCallee(&U)) {
1352  if (PutOffender)
1353  *PutOffender = FU;
1354  return true;
1355  }
1356  }
1357  return false;
1358 }
1359 
1361  // Check the linkage
1362  if (!hasLinkOnceLinkage() && !hasLocalLinkage() &&
1363  !hasAvailableExternallyLinkage())
1364  return false;
1365 
1366  // Check if the function is used by anything other than a blockaddress.
1367  for (const User *U : users())
1368  if (!isa<BlockAddress>(U))
1369  return false;
1370 
1371  return true;
1372 }
1373 
1374 /// callsFunctionThatReturnsTwice - Return true if the function has a call to
1375 /// setjmp or other function that gcc recognizes as "returning twice".
1377  for (const Instruction &I : instructions(this))
1378  if (const auto *Call = dyn_cast<CallBase>(&I))
1379  if (Call->hasFnAttr(Attribute::ReturnsTwice))
1380  return true;
1381 
1382  return false;
1383 }
1384 
1386  assert(hasPersonalityFn() && getNumOperands());
1387  return cast<Constant>(Op<0>());
1388 }
1389 
1391  setHungoffOperand<0>(Fn);
1392  setValueSubclassDataBit(3, Fn != nullptr);
1393 }
1394 
1396  assert(hasPrefixData() && getNumOperands());
1397  return cast<Constant>(Op<1>());
1398 }
1399 
1401  setHungoffOperand<1>(PrefixData);
1402  setValueSubclassDataBit(1, PrefixData != nullptr);
1403 }
1404 
1406  assert(hasPrologueData() && getNumOperands());
1407  return cast<Constant>(Op<2>());
1408 }
1409 
1411  setHungoffOperand<2>(PrologueData);
1412  setValueSubclassDataBit(2, PrologueData != nullptr);
1413 }
1414 
1415 void Function::allocHungoffUselist() {
1416  // If we've already allocated a uselist, stop here.
1417  if (getNumOperands())
1418  return;
1419 
1420  allocHungoffUses(3, /*IsPhi=*/ false);
1421  setNumHungOffUseOperands(3);
1422 
1423  // Initialize the uselist with placeholder operands to allow traversal.
1425  Op<0>().set(CPN);
1426  Op<1>().set(CPN);
1427  Op<2>().set(CPN);
1428 }
1429 
1430 template <int Idx>
1431 void Function::setHungoffOperand(Constant *C) {
1432  if (C) {
1433  allocHungoffUselist();
1434  Op<Idx>().set(C);
1435  } else if (getNumOperands()) {
1436  Op<Idx>().set(
1438  }
1439 }
1440 
1441 void Function::setValueSubclassDataBit(unsigned Bit, bool On) {
1442  assert(Bit < 16 && "SubclassData contains only 16 bits");
1443  if (On)
1445  else
1447 }
1448 
1450  const DenseSet<GlobalValue::GUID> *S) {
1451  assert(Count.hasValue());
1452 #if !defined(NDEBUG)
1453  auto PrevCount = getEntryCount();
1454  assert(!PrevCount.hasValue() || PrevCount.getType() == Count.getType());
1455 #endif
1456  MDBuilder MDB(getContext());
1457  setMetadata(
1459  MDB.createFunctionEntryCount(Count.getCount(), Count.isSynthetic(), S));
1460 }
1461 
1463  const DenseSet<GlobalValue::GUID> *Imports) {
1464  setEntryCount(ProfileCount(Count, Type), Imports);
1465 }
1466 
1467 ProfileCount Function::getEntryCount(bool AllowSynthetic) const {
1468  MDNode *MD = getMetadata(LLVMContext::MD_prof);
1469  if (MD && MD->getOperand(0))
1470  if (MDString *MDS = dyn_cast<MDString>(MD->getOperand(0))) {
1471  if (MDS->getString().equals("function_entry_count")) {
1472  ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(1));
1473  uint64_t Count = CI->getValue().getZExtValue();
1474  // A value of -1 is used for SamplePGO when there were no samples.
1475  // Treat this the same as unknown.
1476  if (Count == (uint64_t)-1)
1477  return ProfileCount::getInvalid();
1478  return ProfileCount(Count, PCT_Real);
1479  } else if (AllowSynthetic &&
1480  MDS->getString().equals("synthetic_function_entry_count")) {
1481  ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(1));
1482  uint64_t Count = CI->getValue().getZExtValue();
1483  return ProfileCount(Count, PCT_Synthetic);
1484  }
1485  }
1486  return ProfileCount::getInvalid();
1487 }
1488 
1491  if (MDNode *MD = getMetadata(LLVMContext::MD_prof))
1492  if (MDString *MDS = dyn_cast<MDString>(MD->getOperand(0)))
1493  if (MDS->getString().equals("function_entry_count"))
1494  for (unsigned i = 2; i < MD->getNumOperands(); i++)
1495  R.insert(mdconst::extract<ConstantInt>(MD->getOperand(i))
1496  ->getValue()
1497  .getZExtValue());
1498  return R;
1499 }
1500 
1502  MDBuilder MDB(getContext());
1504  MDB.createFunctionSectionPrefix(Prefix));
1505 }
1506 
1508  if (MDNode *MD = getMetadata(LLVMContext::MD_section_prefix)) {
1509  assert(cast<MDString>(MD->getOperand(0))
1510  ->getString()
1511  .equals("function_section_prefix") &&
1512  "Metadata not match");
1513  return cast<MDString>(MD->getOperand(1))->getString();
1514  }
1515  return None;
1516 }
1517 
1519  return getFnAttribute("null-pointer-is-valid")
1520  .getValueAsString()
1521  .equals("true");
1522 }
1523 
1524 bool llvm::NullPointerIsDefined(const Function *F, unsigned AS) {
1525  if (F && F->nullPointerIsDefined())
1526  return true;
1527 
1528  if (AS != 0)
1529  return true;
1530 
1531  return false;
1532 }
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
const T & front() const
front - Get the first element.
Definition: ArrayRef.h:151
bool hasNestAttr() const
Return true if this argument has the nest attribute.
Definition: Function.cpp:133
static bool Check(DecodeStatus &Out, DecodeStatus In)
Type * getVectorElementType() const
Definition: Type.h:371
uint64_t CallInst * C
unsigned short getSubclassDataFromValue() const
Definition: Value.h:665
reference emplace_back(ArgTypes &&... Args)
Definition: SmallVector.h:641
iterator_range< use_iterator > uses()
Definition: Value.h:354
bool hasAttribute(Attribute::AttrKind Kind) const
Check if an argument has a given attribute.
Definition: Function.cpp:193
void removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
removes the attribute from the list of attributes.
Definition: Function.cpp:434
static Type * getDoubleTy(LLVMContext &C)
Definition: Type.cpp:164
uint64_t getZExtValue() const
Get zero extended value.
Definition: APInt.h:1562
This class represents an incoming formal argument to a Function.
Definition: Argument.h:29
LLVMContext & Context
uint64_t getDereferenceableOrNullBytes() const
If this argument has the dereferenceable_or_null attribute, return the number of bytes known to be de...
Definition: Function.cpp:127
void dropAllReferences()
Drop all references to operands.
Definition: User.h:294
uint64_t getParamDereferenceableBytes(unsigned ArgNo) const
Extract the number of dereferenceable bytes for a parameter.
Definition: Function.h:454
bool isMetadataTy() const
Return true if this is &#39;metadata&#39;.
Definition: Type.h:190
This class represents lattice values for constants.
Definition: AllocatorList.h:23
Type * getElementType(unsigned N) const
Definition: DerivedTypes.h:346
void removeAttr(Attribute::AttrKind Kind)
Remove attributes from an argument.
Definition: Function.cpp:189
Argument(Type *Ty, const Twine &Name="", Function *F=nullptr, unsigned ArgNo=0)
Argument constructor.
Definition: Function.cpp:66
void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
adds the attribute to the list of attributes for the given arg.
Definition: Function.cpp:398
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:65
2: 32-bit floating point type
Definition: Type.h:58
const std::string & getGC(const Function &Fn)
Return the GC for a function.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
void addDereferenceableAttr(unsigned i, uint64_t Bytes)
adds the dereferenceable attribute to the list of attributes.
Definition: Function.cpp:452
unsigned getInstructionCount() const
Returns the number of non-debug IR instructions in this function.
Definition: Function.cpp:209
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:256
Implements a dense probed hash-table based set.
Definition: DenseSet.h:249
unsigned getNumElements() const
Random access to the elements.
Definition: DerivedTypes.h:345
void clearGC()
Definition: Function.cpp:487
unsigned getParamAlignment(unsigned ArgNo) const
Extract the alignment for a call or parameter (0=unknown).
Definition: Function.h:435
bool hasByValOrInAllocaAttr() const
Return true if this argument has the byval attribute or inalloca attribute.
Definition: Function.cpp:104
bool isFP128Ty() const
Return true if this is &#39;fp128&#39;.
Definition: Type.h:155
void setGC(const Function &Fn, std::string GCName)
Define the GC for a function.
void setGC(std::string Str)
Definition: Function.cpp:482
This file contains the declarations for metadata subclasses.
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space...
Definition: Type.cpp:628
The two locations do not alias at all.
Definition: AliasAnalysis.h:84
void addAttrs(AttrBuilder &B)
Add attributes to an argument.
Definition: Function.cpp:175
bool isOverloaded(ID id)
Returns true if the intrinsic can be overloaded.
Definition: Function.cpp:1021
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:720
static MutableArrayRef< Argument > makeArgArray(Argument *Args, size_t Count)
Definition: Function.cpp:300
bool hasPrologueData() const
Check whether this function has prologue data.
Definition: Function.h:736
void setSectionPrefix(StringRef Prefix)
Set the section prefix for this function.
Definition: Function.cpp:1501
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:1192
Metadata node.
Definition: Metadata.h:863
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1100
F(f)
4: 80-bit floating point type (X87)
Definition: Type.h:60
This is a type descriptor which explains the type requirements of an intrinsic.
Definition: Intrinsics.h:97
static bool isValidReturnType(Type *RetTy)
Return true if the specified type is valid as a return type.
Definition: Type.cpp:326
const MDOperand & getOperand(unsigned I) const
Definition: Metadata.h:1068
1: 16-bit floating point type
Definition: Type.h:57
static Type * getMetadataTy(LLVMContext &C)
Definition: Type.cpp:165
This defines the Use class.
static VectorType * getTruncatedElementVectorType(VectorType *VTy)
This static method is like getInteger except that the element types are half as wide as the elements ...
Definition: DerivedTypes.h:480
static Type * getX86_MMXTy(LLVMContext &C)
Definition: Type.cpp:170
bool hasByValAttr() const
Return true if this argument has the byval attribute.
Definition: Function.cpp:86
LLVM_NODISCARD AttributeList addDereferenceableParamAttr(LLVMContext &C, unsigned ArgNo, uint64_t Bytes) const
Add the dereferenceable attribute to the attribute set at the given arg index.
Definition: Attributes.h:496
void removeFromParent()
removeFromParent - This method unlinks &#39;this&#39; from the containing module, but does not delete it...
Definition: Function.cpp:222
DenseSet< GlobalValue::GUID > getImportGUIDs() const
Returns the set of GUIDs that needs to be imported to the function for sample PGO, to enable the same inlines as the profiled optimized binary.
Definition: Function.cpp:1489
Constant * getPrologueData() const
Get the prologue data associated with this function.
Definition: Function.cpp:1405
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition: Type.h:129
Type * getParamByValType() const
If this is a byval argument, return its type.
Definition: Function.cpp:116
bool hasPrefixData() const
Check whether this function has prefix data.
Definition: Function.h:727
static Type * getTokenTy(LLVMContext &C)
Definition: Type.cpp:166
StringRef getName(ID id)
Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
Definition: Function.cpp:638
const DataLayout & getDataLayout() const
Get the data layout for the module&#39;s target platform.
Definition: Module.cpp:369
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:80
void setEntryCount(ProfileCount Count, const DenseSet< GlobalValue::GUID > *Imports=nullptr)
Set the entry count for this function.
Definition: Function.cpp:1449
static Type * getFloatTy(LLVMContext &C)
Definition: Type.cpp:163
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:450
TypeID getTypeID() const
Return the type id for the type.
Definition: Type.h:137
LLVM_NODISCARD StringRef drop_front(size_t N=1) const
Return a StringRef equal to &#39;this&#39; but with the first N elements dropped.
Definition: StringRef.h:620
Class to represent struct types.
Definition: DerivedTypes.h:233
LLVMContext & getContext() const
Get the global data context.
Definition: Module.h:244
A Use represents the edge between a Value definition and its users.
Definition: Use.h:55
void deleteGC(const Function &Fn)
Remove the GC for a function.
LLVM_NODISCARD AttributeList removeParamAttributes(LLVMContext &C, unsigned ArgNo, const AttrBuilder &AttrsToRemove) const
Remove the specified attribute at the specified arg index from this attribute list.
Definition: Attributes.h:476
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:41
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition: Type.h:196
This file contains the simple types necessary to represent the attributes associated with functions a...
bool hasParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const
check if an attributes is in the list of attributes.
Definition: Function.h:400
void setName(const Twine &Name)
Change the name of the value.
Definition: Value.cpp:285
uint64_t getNumElements() const
For scalable vectors, this will return the minimum number of elements in the vector.
Definition: DerivedTypes.h:393
static StructType * get(LLVMContext &Context, ArrayRef< Type *> Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
Definition: Type.cpp:341
Constant * getPrefixData() const
Get the prefix data associated with this function.
Definition: Function.cpp:1395
AttributeList getAttributes(LLVMContext &C, ID id)
Return the attributes for an intrinsic.
llvm::Optional< Function * > remangleIntrinsicFunction(Function *F)
Definition: Function.cpp:1309
Class to represent function types.
Definition: DerivedTypes.h:103
IIT_Info
IIT_Info - These are enumerators that describe the entries returned by the getIntrinsicInfoTableEntri...
Definition: Function.cpp:658
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:244
LLVM_NODISCARD AttributeList removeAttributes(LLVMContext &C, unsigned Index, const AttrBuilder &AttrsToRemove) const
Remove the specified attributes at the specified index from this attribute list.
bool onlyReadsMemory() const
Return true if this argument has the readonly or readnone attribute.
Definition: Function.cpp:169
Class to represent array types.
Definition: DerivedTypes.h:403
bool isVarArg() const
Definition: DerivedTypes.h:123
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:32
LLVM_NODISCARD size_t size() const
size - Get the string size.
Definition: StringRef.h:130
const APInt & getValue() const
Return the constant as an APInt value reference.
Definition: Constants.h:137
const std::string & getGC() const
Definition: Function.cpp:477
void addDereferenceableOrNullAttr(unsigned i, uint64_t Bytes)
adds the dereferenceable_or_null attribute to the list of attributes.
Definition: Function.cpp:464
AttributeList getAttributes() const
Return the attribute list for this Function.
Definition: Function.h:223
bool hasPersonalityFn() const
Check whether this function has a personality function.
Definition: Function.h:718
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
Definition: Type.h:202
static Type * DecodeFixedType(ArrayRef< Intrinsic::IITDescriptor > &Infos, ArrayRef< Type *> Tys, LLVMContext &Context)
Definition: Function.cpp:916
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
unsigned getBitWidth() const
Get the number of bits in this IntegerType.
Definition: DerivedTypes.h:66
std::pair< Type *, ArrayRef< Intrinsic::IITDescriptor > > DeferredIntrinsicMatchPair
Definition: Function.cpp:1064
uint64_t getParamDereferenceableOrNullBytes(unsigned ArgNo) const
Extract the number of dereferenceable_or_null bytes for a parameter.
Definition: Function.h:468
Function * getDeclaration(Module *M, ID id, ArrayRef< Type *> Tys=None)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
Definition: Function.cpp:1044
size_t bsearch(size_t Lo, size_t Hi, Predicate P)
Binary search for the first index where a predicate is true.
Definition: STLExtras.h:1336
Analysis containing CSE Info
Definition: CSEInfo.cpp:20
Class to represent pointers.
Definition: DerivedTypes.h:544
bool hasNoAliasAttr() const
Return true if this argument has the noalias attribute.
Definition: Function.cpp:138
11: Arbitrary bit width integers
Definition: Type.h:70
static std::string getMangledTypeStr(Type *Ty)
Returns a stable mangling for the type specified for use in the name mangling scheme used by &#39;any&#39; ty...
Definition: Function.cpp:588
bool isVoidTy() const
Return true if this is &#39;void&#39;.
Definition: Type.h:140
bool isFloatTy() const
Return true if this is &#39;float&#39;, a 32-bit IEEE fp type.
Definition: Type.h:146
0: type with no size
Definition: Type.h:56
void setCallingConv(CallingConv::ID CC)
Definition: Function.h:216
void addParamAttrs(unsigned ArgNo, const AttrBuilder &Attrs)
adds the attributes to the list of attributes for the given arg.
Definition: Function.cpp:410
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
Definition: Function.h:135
void addAttr(Attribute::AttrKind Kind)
Definition: Function.cpp:181
static VectorType * getHalfElementsVectorType(VectorType *VTy)
This static method returns a VectorType with half as many elements as the input type and the same ele...
Definition: DerivedTypes.h:490
void stealArgumentListFrom(Function &Src)
Steal arguments from another function.
Definition: Function.cpp:313
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
LLVM_NODISCARD AttributeList addDereferenceableOrNullAttr(LLVMContext &C, unsigned Index, uint64_t Bytes) const
Add the dereferenceable_or_null attribute to the attribute set at the given index.
static ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
Definition: Constants.cpp:1410
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:290
bool isLeaf(ID id)
Returns true if the intrinsic is a leaf, i.e.
Definition: Function.cpp:1027
static Intrinsic::ID lookupIntrinsicID(StringRef Name)
This does the actual lookup of an intrinsic ID which matches the given function name.
Definition: Function.cpp:547
uint64_t getCount() const
Definition: Function.h:271
const FunctionListType & getFunctionList() const
Get the Module&#39;s list of functions (constant).
Definition: Module.h:533
LLVM Basic Block Representation.
Definition: BasicBlock.h:57
LLVM_NODISCARD AttributeList addParamAttribute(LLVMContext &C, unsigned ArgNo, Attribute::AttrKind Kind) const
Add an argument attribute to the list.
Definition: Attributes.h:412
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:64
bool hasNonNullAttr() const
Return true if this argument has the nonnull attribute.
Definition: Function.cpp:75
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:148
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
Definition: Constant.h:41
bool hasStructRetAttr() const
Return true if this argument has the sret attribute.
Definition: Function.cpp:148
void copyAttributesFrom(const Function *Src)
copyAttributesFrom - copy all additional attributes (those not needed to create a Function) from the ...
Definition: Function.cpp:496
This file contains the declarations for the subclasses of Constant, which represent the different fla...
bool hasSExtAttr() const
Return true if this argument has the sext attribute.
Definition: Function.cpp:165
void removeAttribute(unsigned i, Attribute::AttrKind Kind)
removes the attribute from the list of attributes.
Definition: Function.cpp:416
unsigned getNumParams() const
Return the number of fixed parameters this function type requires.
Definition: DerivedTypes.h:139
AMDGPU Lower Kernel Arguments
ProfileCount getEntryCount(bool AllowSynthetic=false) const
Get the entry count for this function.
Definition: Function.cpp:1467
LLVM_NODISCARD AttributeList addParamAttributes(LLVMContext &C, unsigned ArgNo, const AttrBuilder &B) const
Add an argument attribute to the list.
Definition: Attributes.h:433
ArrayRef< Type * > params() const
Definition: DerivedTypes.h:130
void addAttribute(unsigned i, Attribute::AttrKind Kind)
adds the attribute to the list of attributes.
Definition: Function.cpp:380
static Type * getVoidTy(LLVMContext &C)
Definition: Type.cpp:160
bool isHalfTy() const
Return true if this is &#39;half&#39;, a 16-bit IEEE fp type.
Definition: Type.h:143
6: 128-bit floating point type (two 64-bits, PowerPC)
Definition: Type.h:62
static FunctionType * get(Type *Result, ArrayRef< Type *> Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
Definition: Type.cpp:296
bool hasReturnedAttr() const
Return true if this argument has the returned attribute.
Definition: Function.cpp:157
size_t arg_size() const
Definition: Function.h:714
unsigned getAddressSpace() const
Return the address space of the Pointer type.
Definition: DerivedTypes.h:572
void recalculateIntrinsicID()
Recalculate the ID for this function if it is an Intrinsic defined in llvm/Intrinsics.h.
Definition: Function.cpp:566
Attribute getParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const
gets the specified attribute from the list of attributes.
Definition: Function.h:405
bool isX86_MMXTy() const
Return true if this is X86 MMX.
Definition: Type.h:181
Optional< StringRef > getSectionPrefix() const
Get the section prefix for this function.
Definition: Function.cpp:1507
Class to represent integer types.
Definition: DerivedTypes.h:40
void removeParamAttrs(unsigned ArgNo, const AttrBuilder &Attrs)
removes the attribute from the list of attributes.
Definition: Function.cpp:446
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
Definition: Function.cpp:205
bool hasInAllocaAttr() const
Return true if this argument has the inalloca attribute.
Definition: Function.cpp:99
Class to represent profile counts.
Definition: Function.h:260
size_t size() const
Definition: SmallVector.h:52
static ArrayRef< const char * > findTargetSubtable(StringRef Name)
Find the segment of IntrinsicNameTable for intrinsics with the same target as Name, or the generic table if Name is not target specific.
Definition: Function.cpp:529
C setMetadata(LLVMContext::MD_range, MDNode::get(Context, LowAndHigh))
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
const T * data() const
Definition: ArrayRef.h:145
static Type * getFP128Ty(LLVMContext &C)
Definition: Type.cpp:168
LLVM_NODISCARD AttributeList removeParamAttribute(LLVMContext &C, unsigned ArgNo, Attribute::AttrKind Kind) const
Remove the specified attribute at the specified arg index from this attribute list.
Definition: Attributes.h:461
static Type * getHalfTy(LLVMContext &C)
Definition: Type.cpp:162
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Definition: Type.cpp:239
bool hasParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const
Equivalent to hasAttribute(ArgNo + FirstArgIndex, Kind).
static PointerType * getInt1PtrTy(LLVMContext &C, unsigned AS=0)
Definition: Type.cpp:215
enum llvm::Intrinsic::IITDescriptor::IITDescriptorKind Kind
bool matchIntrinsicVarArg(bool isVarArg, ArrayRef< IITDescriptor > &Infos)
Verify if the intrinsic has variable arguments.
Definition: Function.cpp:1290
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the generic address space (address sp...
Definition: DerivedTypes.h:559
This is the shared class of boolean and integer constants.
Definition: Constants.h:83
void getIntrinsicInfoTableEntries(ID id, SmallVectorImpl< IITDescriptor > &T)
Return the IIT table descriptor for the specified intrinsic into an array of IITDescriptors.
Definition: Function.cpp:883
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Definition: Function.h:212
unsigned getParamAlignment() const
If this is a byval or inalloca argument, return its alignment.
Definition: Function.cpp:111
Module.h This file contains the declarations for the Module class.
FunctionType * getType(LLVMContext &Context, ID id, ArrayRef< Type *> Tys=None)
Return the function type for an intrinsic.
Definition: Function.cpp:1000
LLVM_NODISCARD std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition: StringRef.h:696
bool hasSwiftSelfAttr() const
Return true if this argument has the swiftself attribute.
Definition: Function.cpp:91
MatchIntrinsicTypesResult matchIntrinsicSignature(FunctionType *FTy, ArrayRef< IITDescriptor > &Infos, SmallVectorImpl< Type *> &ArgTys)
Match the specified function type with the type constraints specified by the .td file.
Definition: Function.cpp:1264
Type * getReturnType() const
Definition: DerivedTypes.h:124
void dropAllReferences()
dropAllReferences() - This method causes all the subinstructions to "let go" of all references that t...
Definition: Function.cpp:358
unsigned getProgramAddressSpace() const
Definition: DataLayout.h:282
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static ProfileCount getInvalid()
Definition: Function.h:281
FunctionCallee getOrInsertFunction(StringRef Name, FunctionType *T, AttributeList AttributeList)
Look up the specified function in the module symbol table.
Definition: Module.cpp:143
std::string utostr(uint64_t X, bool isNeg=false)
Definition: StringExtras.h:223
bool NullPointerIsDefined(const Function *F, unsigned AS=0)
Check whether null pointer dereferencing is considered undefined behavior for a given function or an ...
Definition: Function.cpp:1524
void setValueSubclassData(unsigned short D)
Definition: Value.h:666
void setAttributes(AttributeList Attrs)
Set the attribute list for this Function.
Definition: Function.h:226
static VectorType * getExtendedElementVectorType(VectorType *VTy)
This static method is like getInteger except that the element types are twice as wide as the elements...
Definition: DerivedTypes.h:472
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
Definition: Function.h:193
8: Metadata
Definition: Type.h:64
unsigned getVectorNumElements() const
Definition: DerivedTypes.h:535
FunctionType * getFunctionType() const
Returns the FunctionType for me.
Definition: Function.h:163
Class to represent vector types.
Definition: DerivedTypes.h:427
Target - Wrapper for Target specific information.
void push_back(pointer val)
Definition: ilist.h:311
LinkageTypes
An enumeration for the kinds of linkage for global values.
Definition: GlobalValue.h:47
unsigned getArgNo() const
Return the index of this formal argument in its containing function.
Definition: Argument.h:47
iterator_range< user_iterator > users()
Definition: Value.h:399
ArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array...
Definition: ArrayRef.h:178
static void DecodeIITType(unsigned &NextElt, ArrayRef< unsigned char > Infos, SmallVectorImpl< Intrinsic::IITDescriptor > &OutputTable)
Definition: Function.cpp:707
static unsigned computeAddrSpace(unsigned AddrSpace, Module *M)
Definition: Function.cpp:234
Function::ProfileCount ProfileCount
Definition: Function.cpp:56
void removeAttributes(unsigned i, const AttrBuilder &Attrs)
removes the attributes from the list of attributes.
Definition: Function.cpp:428
Type * getParamByValType(unsigned ArgNo) const
Extract the byval type for a parameter.
Definition: Function.h:440
LLVM_NODISCARD AttributeList addAttribute(LLVMContext &C, unsigned Index, Attribute::AttrKind Kind) const
Add an attribute to the attribute set at the given index.
bool hasGC() const
hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm to use during code generatio...
Definition: Function.h:351
bool hasInRegAttr() const
Return true if this argument has the inreg attribute.
Definition: Function.cpp:153
const Function * getParent() const
Definition: Argument.h:41
LLVM_NODISCARD AttributeList addDereferenceableAttr(LLVMContext &C, unsigned Index, uint64_t Bytes) const
Add the dereferenceable attribute to the attribute set at the given index.
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:55
bool isTokenTy() const
Return true if this is &#39;token&#39;.
Definition: Type.h:193
static VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
Definition: Type.cpp:605
StringRef getName() const
Return a constant reference to the value&#39;s name.
Definition: Value.cpp:214
LLVM_NODISCARD AttributeList removeAttribute(LLVMContext &C, unsigned Index, Attribute::AttrKind Kind) const
Remove the specified attribute at the specified index from this attribute list.
#define I(x, y, z)
Definition: MD5.cpp:58
#define N
bool hasSwiftErrorAttr() const
Return true if this argument has the swifterror attribute.
Definition: Function.cpp:95
void setPrologueData(Constant *PrologueData)
Definition: Function.cpp:1410
Compile-time customization of User operands.
Definition: User.h:42
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:332
void eraseFromParent()
eraseFromParent - This method unlinks &#39;this&#39; from the containing module and deletes it...
Definition: Function.cpp:226
LLVM_NODISCARD AttributeList addAttributes(LLVMContext &C, unsigned Index, const AttrBuilder &B) const
Add attributes to the attribute set at the given index.
LLVM_NODISCARD AttributeList addDereferenceableOrNullParamAttr(LLVMContext &C, unsigned ArgNo, uint64_t Bytes) const
Add the dereferenceable_or_null attribute to the attribute set at the given arg index.
Definition: Attributes.h:509
bool callsFunctionThatReturnsTwice() const
callsFunctionThatReturnsTwice - Return true if the function has a call to setjmp or other function th...
Definition: Function.cpp:1376
bool isFPOrFPVectorTy() const
Return true if this is a FP type or a vector of FP.
Definition: Type.h:184
3: 64-bit floating point type
Definition: Type.h:59
bool hasAddressTaken(const User **=nullptr) const
hasAddressTaken - returns true if there are any uses of this function other than direct calls or invo...
Definition: Function.cpp:1340
void addAttributes(unsigned i, const AttrBuilder &Attrs)
adds the attributes to the list of attributes.
Definition: Function.cpp:392
void addDereferenceableOrNullParamAttr(unsigned ArgNo, uint64_t Bytes)
adds the dereferenceable_or_null attribute to the list of attributes for the given arg...
Definition: Function.cpp:470
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static bool matchIntrinsicType(Type *Ty, ArrayRef< Intrinsic::IITDescriptor > &Infos, SmallVectorImpl< Type *> &ArgTys, SmallVectorImpl< DeferredIntrinsicMatchPair > &DeferredChecks, bool IsDeferredCheck)
Definition: Function.cpp:1066
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:575
LLVM Value Representation.
Definition: Value.h:72
Constant * getPersonalityFn() const
Get the personality function associated with this function.
Definition: Function.cpp:1385
static const char * name
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Definition: Compiler.h:250
ProfileCountType getType() const
Definition: Function.h:272
bool hasZExtAttr() const
Return true if this argument has the zext attribute.
Definition: Function.cpp:161
static const char *const IntrinsicNameTable[]
Table of string intrinsic names indexed by enum value.
Definition: Function.cpp:513
Type * getElementType() const
Definition: DerivedTypes.h:394
MDNode * createFunctionSectionPrefix(StringRef Prefix)
Return metadata containing the section prefix for a function.
Definition: MDBuilder.cpp:78
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
inst_range instructions(Function *F)
Definition: InstIterator.h:133
A single uniqued string.
Definition: Metadata.h:603
int lookupLLVMIntrinsicByName(ArrayRef< const char *> NameTable, StringRef Name)
Looks up Name in NameTable via binary search.
void setPersonalityFn(Constant *Fn)
Definition: Function.cpp:1390
bool nullPointerIsDefined() const
Check if null pointer dereferencing is considered undefined behavior for the function.
Definition: Function.cpp:1518
9: MMX vectors (64 bits, X86 specific)
Definition: Type.h:65
bool hasNoCaptureAttr() const
Return true if this argument has the nocapture attribute.
Definition: Function.cpp:143
void addDereferenceableParamAttr(unsigned ArgNo, uint64_t Bytes)
adds the dereferenceable attribute to the list of attributes for the given arg.
Definition: Function.cpp:458
void copyAttributesFrom(const GlobalObject *Src)
Definition: Globals.cpp:126
bool isDoubleTy() const
Return true if this is &#39;double&#39;, a 64-bit IEEE fp type.
Definition: Type.h:149
bool use_empty() const
Definition: Value.h:322
bool isDefTriviallyDead() const
isDefTriviallyDead - Return true if it is trivially safe to remove this function definition from the ...
Definition: Function.cpp:1360
Attribute getAttribute(Attribute::AttrKind Kind) const
Definition: Function.cpp:197
uint64_t getDereferenceableBytes() const
If this argument has the dereferenceable attribute, return the number of bytes known to be dereferenc...
Definition: Function.cpp:121
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
bool hasLazyArguments() const
hasLazyArguments/CheckLazyArguments - The argument list of a function is built on demand...
Definition: Function.h:104
Type * getElementType() const
Definition: DerivedTypes.h:563
void dropAllReferences()
Cause all subinstructions to "let go" of all the references that said subinstructions are maintaining...
Definition: BasicBlock.cpp:226
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:143
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results...
Definition: Attributes.h:69
5: 128-bit floating point type (112-bit mantissa)
Definition: Type.h:61
void setPrefixData(Constant *PrefixData)
Definition: Function.cpp:1400