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