LLVM  4.0.0
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"
15 #include "LLVMContextImpl.h"
17 #include "llvm/ADT/STLExtras.h"
18 #include "llvm/ADT/StringExtras.h"
20 #include "llvm/IR/CallSite.h"
21 #include "llvm/IR/Constants.h"
22 #include "llvm/IR/DerivedTypes.h"
23 #include "llvm/IR/InstIterator.h"
24 #include "llvm/IR/IntrinsicInst.h"
25 #include "llvm/IR/LLVMContext.h"
26 #include "llvm/IR/MDBuilder.h"
27 #include "llvm/IR/Metadata.h"
28 #include "llvm/IR/Module.h"
29 using namespace llvm;
30 
31 // Explicit instantiations of SymbolTableListTraits since some of the methods
32 // are not in the public header file...
35 
36 //===----------------------------------------------------------------------===//
37 // Argument Implementation
38 //===----------------------------------------------------------------------===//
39 
40 void Argument::anchor() { }
41 
43  : Value(Ty, Value::ArgumentVal) {
44  Parent = nullptr;
45 
46  if (Par)
47  Par->getArgumentList().push_back(this);
48  setName(Name);
49 }
50 
51 void Argument::setParent(Function *parent) {
52  Parent = parent;
53 }
54 
55 /// getArgNo - Return the index of this formal argument in its containing
56 /// function. For example in "void foo(int a, float b)" a is 0 and b is 1.
57 unsigned Argument::getArgNo() const {
58  const Function *F = getParent();
59  assert(F && "Argument is not in a function");
60 
62  unsigned ArgIdx = 0;
63  for (; &*AI != this; ++AI)
64  ++ArgIdx;
65 
66  return ArgIdx;
67 }
68 
69 /// hasNonNullAttr - Return true if this argument has the nonnull attribute on
70 /// it in its containing function. Also returns true if at least one byte is
71 /// known to be dereferenceable and the pointer is in addrspace(0).
73  if (!getType()->isPointerTy()) return false;
74  if (getParent()->getAttributes().
75  hasAttribute(getArgNo()+1, Attribute::NonNull))
76  return true;
77  else if (getDereferenceableBytes() > 0 &&
78  getType()->getPointerAddressSpace() == 0)
79  return true;
80  return false;
81 }
82 
83 /// hasByValAttr - Return true if this argument has the byval attribute on it
84 /// in its containing function.
85 bool Argument::hasByValAttr() const {
86  if (!getType()->isPointerTy()) return false;
87  return hasAttribute(Attribute::ByVal);
88 }
89 
91  return getParent()->getAttributes().
92  hasAttribute(getArgNo()+1, Attribute::SwiftSelf);
93 }
94 
96  return getParent()->getAttributes().
97  hasAttribute(getArgNo()+1, Attribute::SwiftError);
98 }
99 
100 /// \brief Return true if this argument has the inalloca attribute on it in
101 /// its containing function.
103  if (!getType()->isPointerTy()) return false;
104  return hasAttribute(Attribute::InAlloca);
105 }
106 
108  if (!getType()->isPointerTy()) return false;
109  AttributeSet Attrs = getParent()->getAttributes();
110  return Attrs.hasAttribute(getArgNo() + 1, Attribute::ByVal) ||
111  Attrs.hasAttribute(getArgNo() + 1, Attribute::InAlloca);
112 }
113 
114 unsigned Argument::getParamAlignment() const {
115  assert(getType()->isPointerTy() && "Only pointers have alignments");
116  return getParent()->getParamAlignment(getArgNo()+1);
117 
118 }
119 
121  assert(getType()->isPointerTy() &&
122  "Only pointers have dereferenceable bytes");
124 }
125 
127  assert(getType()->isPointerTy() &&
128  "Only pointers have dereferenceable bytes");
130 }
131 
132 /// hasNestAttr - Return true if this argument has the nest attribute on
133 /// it in its containing function.
134 bool Argument::hasNestAttr() const {
135  if (!getType()->isPointerTy()) return false;
136  return hasAttribute(Attribute::Nest);
137 }
138 
139 /// hasNoAliasAttr - Return true if this argument has the noalias attribute on
140 /// it in its containing function.
142  if (!getType()->isPointerTy()) return false;
144 }
145 
146 /// hasNoCaptureAttr - Return true if this argument has the nocapture attribute
147 /// on it in its containing function.
149  if (!getType()->isPointerTy()) return false;
150  return hasAttribute(Attribute::NoCapture);
151 }
152 
153 /// hasSRetAttr - Return true if this argument has the sret attribute on
154 /// it in its containing function.
156  if (!getType()->isPointerTy()) return false;
157  return hasAttribute(Attribute::StructRet);
158 }
159 
160 /// hasReturnedAttr - Return true if this argument has the returned attribute on
161 /// it in its containing function.
163  return hasAttribute(Attribute::Returned);
164 }
165 
166 /// hasZExtAttr - Return true if this argument has the zext attribute on it in
167 /// its containing function.
168 bool Argument::hasZExtAttr() const {
169  return hasAttribute(Attribute::ZExt);
170 }
171 
172 /// hasSExtAttr Return true if this argument has the sext attribute on it in its
173 /// containing function.
174 bool Argument::hasSExtAttr() const {
175  return hasAttribute(Attribute::SExt);
176 }
177 
178 /// Return true if this argument has the readonly or readnone attribute on it
179 /// in its containing function.
181  return getParent()->getAttributes().
184  hasAttribute(getArgNo()+1, Attribute::ReadNone);
185 }
186 
187 /// addAttr - Add attributes to an argument.
189  assert(AS.getNumSlots() <= 1 &&
190  "Trying to add more than one attribute set to an argument!");
191  AttrBuilder B(AS, AS.getSlotIndex(0));
193  AttributeSet::get(Parent->getContext(),
194  getArgNo() + 1, B));
195 }
196 
197 /// removeAttr - Remove attributes from an argument.
199  assert(AS.getNumSlots() <= 1 &&
200  "Trying to remove more than one attribute set from an argument!");
201  AttrBuilder B(AS, AS.getSlotIndex(0));
203  AttributeSet::get(Parent->getContext(),
204  getArgNo() + 1, B));
205 }
206 
207 /// hasAttribute - Checks if an argument has a given attribute.
209  return getParent()->hasAttribute(getArgNo() + 1, Kind);
210 }
211 
212 //===----------------------------------------------------------------------===//
213 // Helper Methods in Function
214 //===----------------------------------------------------------------------===//
215 
217  return getGlobalObjectSubClassData() & (1 << IsMaterializableBit);
218 }
219 
221  unsigned Mask = 1 << IsMaterializableBit;
223  (V ? Mask : 0u));
224 }
225 
227  return getType()->getContext();
228 }
229 
231  return cast<FunctionType>(getValueType());
232 }
233 
234 bool Function::isVarArg() const {
235  return getFunctionType()->isVarArg();
236 }
237 
239  return getFunctionType()->getReturnType();
240 }
241 
244 }
245 
248 }
249 
250 //===----------------------------------------------------------------------===//
251 // Function Implementation
252 //===----------------------------------------------------------------------===//
253 
254 Function::Function(FunctionType *Ty, LinkageTypes Linkage, const Twine &name,
255  Module *ParentModule)
256  : GlobalObject(Ty, Value::FunctionVal,
257  OperandTraits<Function>::op_begin(this), 0, Linkage, name) {
259  "invalid return type");
261 
262  // We only need a symbol table for a function if the context keeps value names
263  if (!getContext().shouldDiscardValueNames())
264  SymTab = make_unique<ValueSymbolTable>();
265 
266  // If the function has arguments, mark them as lazily built.
267  if (Ty->getNumParams())
268  setValueSubclassData(1); // Set the "has lazy arguments" bit.
269 
270  if (ParentModule)
271  ParentModule->getFunctionList().push_back(this);
272 
274  // Ensure intrinsics have the right parameter attributes.
275  // Note, the IntID field will have been set in Value::setName if this function
276  // name is a valid intrinsic ID.
277  if (IntID)
279 }
280 
282  dropAllReferences(); // After this it is safe to delete instructions.
283 
284  // Delete all of the method arguments and unlink from symbol table...
285  ArgumentList.clear();
286 
287  // Remove the function from the on-the-side GC table.
288  clearGC();
289 }
290 
291 void Function::BuildLazyArguments() const {
292  // Create the arguments vector, all arguments start out unnamed.
294  for (unsigned i = 0, e = FT->getNumParams(); i != e; ++i) {
295  assert(!FT->getParamType(i)->isVoidTy() &&
296  "Cannot have void typed arguments!");
297  ArgumentList.push_back(new Argument(FT->getParamType(i)));
298  }
299 
300  // Clear the lazy arguments bit.
301  unsigned SDC = getSubclassDataFromValue();
302  const_cast<Function*>(this)->setValueSubclassData(SDC &= ~(1<<0));
303 }
304 
306  assert(isDeclaration() && "Expected no references to current arguments");
307 
308  // Drop the current arguments, if any, and set the lazy argument bit.
309  if (!hasLazyArguments()) {
310  assert(llvm::all_of(ArgumentList,
311  [](const Argument &A) { return A.use_empty(); }) &&
312  "Expected arguments to be unused in declaration");
313  ArgumentList.clear();
314  setValueSubclassData(getSubclassDataFromValue() | (1 << 0));
315  }
316 
317  // Nothing to steal if Src has lazy arguments.
318  if (Src.hasLazyArguments())
319  return;
320 
321  // Steal arguments from Src, and fix the lazy argument bits.
322  ArgumentList.splice(ArgumentList.end(), Src.ArgumentList);
323  setValueSubclassData(getSubclassDataFromValue() & ~(1 << 0));
324  Src.setValueSubclassData(Src.getSubclassDataFromValue() | (1 << 0));
325 }
326 
327 size_t Function::arg_size() const {
328  return getFunctionType()->getNumParams();
329 }
330 bool Function::arg_empty() const {
331  return getFunctionType()->getNumParams() == 0;
332 }
333 
334 // dropAllReferences() - This function causes all the subinstructions to "let
335 // go" of all references that they are maintaining. This allows one to
336 // 'delete' a whole class at a time, even though there may be circular
337 // references... first all references are dropped, and all use counts go to
338 // zero. Then everything is deleted for real. Note that no operations are
339 // valid on an object that has "dropped all references", except operator
340 // delete.
341 //
343  setIsMaterializable(false);
344 
345  for (BasicBlock &BB : *this)
346  BB.dropAllReferences();
347 
348  // Delete all basic blocks. They are now unused, except possibly by
349  // blockaddresses, but BasicBlock's destructor takes care of those.
350  while (!BasicBlocks.empty())
351  BasicBlocks.begin()->eraseFromParent();
352 
353  // Drop uses of any optional data (real or placeholder).
354  if (getNumOperands()) {
357  setValueSubclassData(getSubclassDataFromValue() & ~0xe);
358  }
359 
360  // Metadata is stored in a side-table.
361  clearMetadata();
362 }
363 
365  AttributeSet PAL = getAttributes();
366  PAL = PAL.addAttribute(getContext(), i, Kind);
367  setAttributes(PAL);
368 }
369 
370 void Function::addAttribute(unsigned i, Attribute Attr) {
371  AttributeSet PAL = getAttributes();
372  PAL = PAL.addAttribute(getContext(), i, Attr);
373  setAttributes(PAL);
374 }
375 
376 void Function::addAttributes(unsigned i, AttributeSet Attrs) {
377  AttributeSet PAL = getAttributes();
378  PAL = PAL.addAttributes(getContext(), i, Attrs);
379  setAttributes(PAL);
380 }
381 
383  AttributeSet PAL = getAttributes();
384  PAL = PAL.removeAttribute(getContext(), i, Kind);
385  setAttributes(PAL);
386 }
387 
389  AttributeSet PAL = getAttributes();
390  PAL = PAL.removeAttribute(getContext(), i, Kind);
391  setAttributes(PAL);
392 }
393 
395  AttributeSet PAL = getAttributes();
396  PAL = PAL.removeAttributes(getContext(), i, Attrs);
397  setAttributes(PAL);
398 }
399 
400 void Function::addDereferenceableAttr(unsigned i, uint64_t Bytes) {
401  AttributeSet PAL = getAttributes();
402  PAL = PAL.addDereferenceableAttr(getContext(), i, Bytes);
403  setAttributes(PAL);
404 }
405 
406 void Function::addDereferenceableOrNullAttr(unsigned i, uint64_t Bytes) {
407  AttributeSet PAL = getAttributes();
408  PAL = PAL.addDereferenceableOrNullAttr(getContext(), i, Bytes);
409  setAttributes(PAL);
410 }
411 
412 const std::string &Function::getGC() const {
413  assert(hasGC() && "Function has no collector");
414  return getContext().getGC(*this);
415 }
416 
417 void Function::setGC(std::string Str) {
418  setValueSubclassDataBit(14, !Str.empty());
419  getContext().setGC(*this, std::move(Str));
420 }
421 
423  if (!hasGC())
424  return;
425  getContext().deleteGC(*this);
426  setValueSubclassDataBit(14, false);
427 }
428 
429 /// Copy all additional attributes (those not needed to create a Function) from
430 /// the Function Src to this one.
433  const Function *SrcF = dyn_cast<Function>(Src);
434  if (!SrcF)
435  return;
436 
438  setAttributes(SrcF->getAttributes());
439  if (SrcF->hasGC())
440  setGC(SrcF->getGC());
441  else
442  clearGC();
443  if (SrcF->hasPersonalityFn())
445  if (SrcF->hasPrefixData())
446  setPrefixData(SrcF->getPrefixData());
447  if (SrcF->hasPrologueData())
449 }
450 
451 /// Table of string intrinsic names indexed by enum value.
452 static const char * const IntrinsicNameTable[] = {
453  "not_intrinsic",
454 #define GET_INTRINSIC_NAME_TABLE
455 #include "llvm/IR/Intrinsics.gen"
456 #undef GET_INTRINSIC_NAME_TABLE
457 };
458 
459 /// Table of per-target intrinsic name tables.
460 #define GET_INTRINSIC_TARGET_DATA
461 #include "llvm/IR/Intrinsics.gen"
462 #undef GET_INTRINSIC_TARGET_DATA
463 
464 /// Find the segment of \c IntrinsicNameTable for intrinsics with the same
465 /// target as \c Name, or the generic table if \c Name is not target specific.
466 ///
467 /// Returns the relevant slice of \c IntrinsicNameTable
469  assert(Name.startswith("llvm."));
470 
471  ArrayRef<IntrinsicTargetInfo> Targets(TargetInfos);
472  // Drop "llvm." and take the first dotted component. That will be the target
473  // if this is target specific.
474  StringRef Target = Name.drop_front(5).split('.').first;
475  auto It = std::lower_bound(Targets.begin(), Targets.end(), Target,
476  [](const IntrinsicTargetInfo &TI,
477  StringRef Target) { return TI.Name < Target; });
478  // We've either found the target or just fall back to the generic set, which
479  // is always first.
480  const auto &TI = It != Targets.end() && It->Name == Target ? *It : Targets[0];
481  return makeArrayRef(&IntrinsicNameTable[1] + TI.Offset, TI.Count);
482 }
483 
484 /// \brief This does the actual lookup of an intrinsic ID which
485 /// matches the given function name.
487  ArrayRef<const char *> NameTable = findTargetSubtable(Name);
488  int Idx = Intrinsic::lookupLLVMIntrinsicByName(NameTable, Name);
489  if (Idx == -1)
491 
492  // Intrinsic IDs correspond to the location in IntrinsicNameTable, but we have
493  // an index into a sub-table.
494  int Adjust = NameTable.data() - IntrinsicNameTable;
495  Intrinsic::ID ID = static_cast<Intrinsic::ID>(Idx + Adjust);
496 
497  // If the intrinsic is not overloaded, require an exact match. If it is
498  // overloaded, require a prefix match.
499  bool IsPrefixMatch = Name.size() > strlen(NameTable[Idx]);
500  return IsPrefixMatch == isOverloaded(ID) ? ID : Intrinsic::not_intrinsic;
501 }
502 
504  StringRef Name = getName();
505  if (!Name.startswith("llvm.")) {
506  HasLLVMReservedName = false;
508  return;
509  }
510  HasLLVMReservedName = true;
511  IntID = lookupIntrinsicID(Name);
512 }
513 
514 /// Returns a stable mangling for the type specified for use in the name
515 /// mangling scheme used by 'any' types in intrinsic signatures. The mangling
516 /// of named types is simply their name. Manglings for unnamed types consist
517 /// of a prefix ('p' for pointers, 'a' for arrays, 'f_' for functions)
518 /// combined with the mangling of their component types. A vararg function
519 /// type will have a suffix of 'vararg'. Since function types can contain
520 /// other function types, we close a function type mangling with suffix 'f'
521 /// which can't be confused with it's prefix. This ensures we don't have
522 /// collisions between two unrelated function types. Otherwise, you might
523 /// parse ffXX as f(fXX) or f(fX)X. (X is a placeholder for any other type.)
524 /// Manglings of integers, floats, and vectors ('i', 'f', and 'v' prefix in most
525 /// cases) fall back to the MVT codepath, where they could be mangled to
526 /// 'x86mmx', for example; matching on derived types is not sufficient to mangle
527 /// everything.
528 static std::string getMangledTypeStr(Type* Ty) {
529  std::string Result;
530  if (PointerType* PTyp = dyn_cast<PointerType>(Ty)) {
531  Result += "p" + llvm::utostr(PTyp->getAddressSpace()) +
532  getMangledTypeStr(PTyp->getElementType());
533  } else if (ArrayType* ATyp = dyn_cast<ArrayType>(Ty)) {
534  Result += "a" + llvm::utostr(ATyp->getNumElements()) +
535  getMangledTypeStr(ATyp->getElementType());
536  } else if (StructType* STyp = dyn_cast<StructType>(Ty)) {
537  assert(!STyp->isLiteral() && "TODO: implement literal types");
538  Result += STyp->getName();
539  } else if (FunctionType* FT = dyn_cast<FunctionType>(Ty)) {
540  Result += "f_" + getMangledTypeStr(FT->getReturnType());
541  for (size_t i = 0; i < FT->getNumParams(); i++)
542  Result += getMangledTypeStr(FT->getParamType(i));
543  if (FT->isVarArg())
544  Result += "vararg";
545  // Ensure nested function types are distinguishable.
546  Result += "f";
547  } else if (isa<VectorType>(Ty))
548  Result += "v" + utostr(Ty->getVectorNumElements()) +
550  else if (Ty)
551  Result += EVT::getEVT(Ty).getEVTString();
552  return Result;
553 }
554 
556  assert(id < num_intrinsics && "Invalid intrinsic ID!");
557  assert(!isOverloaded(id) &&
558  "This version of getName does not support overloading");
559  return IntrinsicNameTable[id];
560 }
561 
562 std::string Intrinsic::getName(ID id, ArrayRef<Type*> Tys) {
563  assert(id < num_intrinsics && "Invalid intrinsic ID!");
564  std::string Result(IntrinsicNameTable[id]);
565  for (Type *Ty : Tys) {
566  Result += "." + getMangledTypeStr(Ty);
567  }
568  return Result;
569 }
570 
571 
572 /// IIT_Info - These are enumerators that describe the entries returned by the
573 /// getIntrinsicInfoTableEntries function.
574 ///
575 /// NOTE: This must be kept in synch with the copy in TblGen/IntrinsicEmitter!
576 enum IIT_Info {
577  // Common values should be encoded with 0-15.
578  IIT_Done = 0,
579  IIT_I1 = 1,
580  IIT_I8 = 2,
581  IIT_I16 = 3,
582  IIT_I32 = 4,
583  IIT_I64 = 5,
584  IIT_F16 = 6,
585  IIT_F32 = 7,
586  IIT_F64 = 8,
587  IIT_V2 = 9,
588  IIT_V4 = 10,
589  IIT_V8 = 11,
590  IIT_V16 = 12,
591  IIT_V32 = 13,
592  IIT_PTR = 14,
593  IIT_ARG = 15,
594 
595  // Values from 16+ are only encodable with the inefficient encoding.
596  IIT_V64 = 16,
597  IIT_MMX = 17,
598  IIT_TOKEN = 18,
608  IIT_V1 = 28,
615  IIT_I128 = 35,
616  IIT_V512 = 36,
618 };
619 
620 
621 static void DecodeIITType(unsigned &NextElt, ArrayRef<unsigned char> Infos,
623  IIT_Info Info = IIT_Info(Infos[NextElt++]);
624  unsigned StructElts = 2;
625  using namespace Intrinsic;
626 
627  switch (Info) {
628  case IIT_Done:
630  return;
631  case IIT_VARARG:
633  return;
634  case IIT_MMX:
636  return;
637  case IIT_TOKEN:
639  return;
640  case IIT_METADATA:
642  return;
643  case IIT_F16:
645  return;
646  case IIT_F32:
648  return;
649  case IIT_F64:
651  return;
652  case IIT_I1:
654  return;
655  case IIT_I8:
657  return;
658  case IIT_I16:
660  return;
661  case IIT_I32:
663  return;
664  case IIT_I64:
666  return;
667  case IIT_I128:
669  return;
670  case IIT_V1:
672  DecodeIITType(NextElt, Infos, OutputTable);
673  return;
674  case IIT_V2:
676  DecodeIITType(NextElt, Infos, OutputTable);
677  return;
678  case IIT_V4:
680  DecodeIITType(NextElt, Infos, OutputTable);
681  return;
682  case IIT_V8:
684  DecodeIITType(NextElt, Infos, OutputTable);
685  return;
686  case IIT_V16:
688  DecodeIITType(NextElt, Infos, OutputTable);
689  return;
690  case IIT_V32:
692  DecodeIITType(NextElt, Infos, OutputTable);
693  return;
694  case IIT_V64:
696  DecodeIITType(NextElt, Infos, OutputTable);
697  return;
698  case IIT_V512:
700  DecodeIITType(NextElt, Infos, OutputTable);
701  return;
702  case IIT_V1024:
704  DecodeIITType(NextElt, Infos, OutputTable);
705  return;
706  case IIT_PTR:
708  DecodeIITType(NextElt, Infos, OutputTable);
709  return;
710  case IIT_ANYPTR: { // [ANYPTR addrspace, subtype]
712  Infos[NextElt++]));
713  DecodeIITType(NextElt, Infos, OutputTable);
714  return;
715  }
716  case IIT_ARG: {
717  unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
719  return;
720  }
721  case IIT_EXTEND_ARG: {
722  unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
724  ArgInfo));
725  return;
726  }
727  case IIT_TRUNC_ARG: {
728  unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
730  ArgInfo));
731  return;
732  }
733  case IIT_HALF_VEC_ARG: {
734  unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
736  ArgInfo));
737  return;
738  }
739  case IIT_SAME_VEC_WIDTH_ARG: {
740  unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
742  ArgInfo));
743  return;
744  }
745  case IIT_PTR_TO_ARG: {
746  unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
748  ArgInfo));
749  return;
750  }
751  case IIT_PTR_TO_ELT: {
752  unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
754  return;
755  }
756  case IIT_VEC_OF_PTRS_TO_ELT: {
757  unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
759  ArgInfo));
760  return;
761  }
762  case IIT_EMPTYSTRUCT:
764  return;
765  case IIT_STRUCT5: ++StructElts; LLVM_FALLTHROUGH;
766  case IIT_STRUCT4: ++StructElts; LLVM_FALLTHROUGH;
767  case IIT_STRUCT3: ++StructElts; LLVM_FALLTHROUGH;
768  case IIT_STRUCT2: {
769  OutputTable.push_back(IITDescriptor::get(IITDescriptor::Struct,StructElts));
770 
771  for (unsigned i = 0; i != StructElts; ++i)
772  DecodeIITType(NextElt, Infos, OutputTable);
773  return;
774  }
775  }
776  llvm_unreachable("unhandled");
777 }
778 
779 
780 #define GET_INTRINSIC_GENERATOR_GLOBAL
781 #include "llvm/IR/Intrinsics.gen"
782 #undef GET_INTRINSIC_GENERATOR_GLOBAL
783 
786  // Check to see if the intrinsic's type was expressible by the table.
787  unsigned TableVal = IIT_Table[id-1];
788 
789  // Decode the TableVal into an array of IITValues.
791  ArrayRef<unsigned char> IITEntries;
792  unsigned NextElt = 0;
793  if ((TableVal >> 31) != 0) {
794  // This is an offset into the IIT_LongEncodingTable.
795  IITEntries = IIT_LongEncodingTable;
796 
797  // Strip sentinel bit.
798  NextElt = (TableVal << 1) >> 1;
799  } else {
800  // Decode the TableVal into an array of IITValues. If the entry was encoded
801  // into a single word in the table itself, decode it now.
802  do {
803  IITValues.push_back(TableVal & 0xF);
804  TableVal >>= 4;
805  } while (TableVal);
806 
807  IITEntries = IITValues;
808  NextElt = 0;
809  }
810 
811  // Okay, decode the table into the output vector of IITDescriptors.
812  DecodeIITType(NextElt, IITEntries, T);
813  while (NextElt != IITEntries.size() && IITEntries[NextElt] != 0)
814  DecodeIITType(NextElt, IITEntries, T);
815 }
816 
817 
820  using namespace Intrinsic;
821  IITDescriptor D = Infos.front();
822  Infos = Infos.slice(1);
823 
824  switch (D.Kind) {
825  case IITDescriptor::Void: return Type::getVoidTy(Context);
826  case IITDescriptor::VarArg: return Type::getVoidTy(Context);
827  case IITDescriptor::MMX: return Type::getX86_MMXTy(Context);
828  case IITDescriptor::Token: return Type::getTokenTy(Context);
829  case IITDescriptor::Metadata: return Type::getMetadataTy(Context);
830  case IITDescriptor::Half: return Type::getHalfTy(Context);
831  case IITDescriptor::Float: return Type::getFloatTy(Context);
832  case IITDescriptor::Double: return Type::getDoubleTy(Context);
833 
835  return IntegerType::get(Context, D.Integer_Width);
837  return VectorType::get(DecodeFixedType(Infos, Tys, Context),D.Vector_Width);
839  return PointerType::get(DecodeFixedType(Infos, Tys, Context),
840  D.Pointer_AddressSpace);
841  case IITDescriptor::Struct: {
842  Type *Elts[5];
843  assert(D.Struct_NumElements <= 5 && "Can't handle this yet");
844  for (unsigned i = 0, e = D.Struct_NumElements; i != e; ++i)
845  Elts[i] = DecodeFixedType(Infos, Tys, Context);
846  return StructType::get(Context, makeArrayRef(Elts,D.Struct_NumElements));
847  }
848 
850  return Tys[D.getArgumentNumber()];
852  Type *Ty = Tys[D.getArgumentNumber()];
853  if (VectorType *VTy = dyn_cast<VectorType>(Ty))
855 
856  return IntegerType::get(Context, 2 * cast<IntegerType>(Ty)->getBitWidth());
857  }
859  Type *Ty = Tys[D.getArgumentNumber()];
860  if (VectorType *VTy = dyn_cast<VectorType>(Ty))
862 
863  IntegerType *ITy = cast<IntegerType>(Ty);
864  assert(ITy->getBitWidth() % 2 == 0);
865  return IntegerType::get(Context, ITy->getBitWidth() / 2);
866  }
868  return VectorType::getHalfElementsVectorType(cast<VectorType>(
869  Tys[D.getArgumentNumber()]));
871  Type *EltTy = DecodeFixedType(Infos, Tys, Context);
872  Type *Ty = Tys[D.getArgumentNumber()];
873  if (VectorType *VTy = dyn_cast<VectorType>(Ty)) {
874  return VectorType::get(EltTy, VTy->getNumElements());
875  }
876  llvm_unreachable("unhandled");
877  }
879  Type *Ty = Tys[D.getArgumentNumber()];
880  return PointerType::getUnqual(Ty);
881  }
883  Type *Ty = Tys[D.getArgumentNumber()];
884  VectorType *VTy = dyn_cast<VectorType>(Ty);
885  if (!VTy)
886  llvm_unreachable("Expected an argument of Vector Type");
887  Type *EltTy = VTy->getVectorElementType();
888  return PointerType::getUnqual(EltTy);
889  }
891  Type *Ty = Tys[D.getArgumentNumber()];
892  VectorType *VTy = dyn_cast<VectorType>(Ty);
893  if (!VTy)
894  llvm_unreachable("Expected an argument of Vector Type");
895  Type *EltTy = VTy->getVectorElementType();
897  VTy->getNumElements());
898  }
899  }
900  llvm_unreachable("unhandled");
901 }
902 
903 
904 
906  ID id, ArrayRef<Type*> Tys) {
908  getIntrinsicInfoTableEntries(id, Table);
909 
910  ArrayRef<IITDescriptor> TableRef = Table;
911  Type *ResultTy = DecodeFixedType(TableRef, Tys, Context);
912 
913  SmallVector<Type*, 8> ArgTys;
914  while (!TableRef.empty())
915  ArgTys.push_back(DecodeFixedType(TableRef, Tys, Context));
916 
917  // DecodeFixedType returns Void for IITDescriptor::Void and IITDescriptor::VarArg
918  // If we see void type as the type of the last argument, it is vararg intrinsic
919  if (!ArgTys.empty() && ArgTys.back()->isVoidTy()) {
920  ArgTys.pop_back();
921  return FunctionType::get(ResultTy, ArgTys, true);
922  }
923  return FunctionType::get(ResultTy, ArgTys, false);
924 }
925 
927 #define GET_INTRINSIC_OVERLOAD_TABLE
928 #include "llvm/IR/Intrinsics.gen"
929 #undef GET_INTRINSIC_OVERLOAD_TABLE
930 }
931 
933  switch (id) {
934  default:
935  return true;
936 
937  case Intrinsic::experimental_gc_statepoint:
938  case Intrinsic::experimental_patchpoint_void:
939  case Intrinsic::experimental_patchpoint_i64:
940  return false;
941  }
942 }
943 
944 /// This defines the "Intrinsic::getAttributes(ID id)" method.
945 #define GET_INTRINSIC_ATTRIBUTES
946 #include "llvm/IR/Intrinsics.gen"
947 #undef GET_INTRINSIC_ATTRIBUTES
948 
950  // There can never be multiple globals with the same name of different types,
951  // because intrinsics must be a specific type.
952  return
953  cast<Function>(M->getOrInsertFunction(getName(id, Tys),
954  getType(M->getContext(), id, Tys)));
955 }
956 
957 // This defines the "Intrinsic::getIntrinsicForGCCBuiltin()" method.
958 #define GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN
959 #include "llvm/IR/Intrinsics.gen"
960 #undef GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN
961 
962 // This defines the "Intrinsic::getIntrinsicForMSBuiltin()" method.
963 #define GET_LLVM_INTRINSIC_FOR_MS_BUILTIN
964 #include "llvm/IR/Intrinsics.gen"
965 #undef GET_LLVM_INTRINSIC_FOR_MS_BUILTIN
966 
968  SmallVectorImpl<Type*> &ArgTys) {
969  using namespace Intrinsic;
970 
971  // If we ran out of descriptors, there are too many arguments.
972  if (Infos.empty()) return true;
973  IITDescriptor D = Infos.front();
974  Infos = Infos.slice(1);
975 
976  switch (D.Kind) {
977  case IITDescriptor::Void: return !Ty->isVoidTy();
978  case IITDescriptor::VarArg: return true;
979  case IITDescriptor::MMX: return !Ty->isX86_MMXTy();
980  case IITDescriptor::Token: return !Ty->isTokenTy();
981  case IITDescriptor::Metadata: return !Ty->isMetadataTy();
982  case IITDescriptor::Half: return !Ty->isHalfTy();
983  case IITDescriptor::Float: return !Ty->isFloatTy();
984  case IITDescriptor::Double: return !Ty->isDoubleTy();
985  case IITDescriptor::Integer: return !Ty->isIntegerTy(D.Integer_Width);
986  case IITDescriptor::Vector: {
987  VectorType *VT = dyn_cast<VectorType>(Ty);
988  return !VT || VT->getNumElements() != D.Vector_Width ||
989  matchIntrinsicType(VT->getElementType(), Infos, ArgTys);
990  }
991  case IITDescriptor::Pointer: {
992  PointerType *PT = dyn_cast<PointerType>(Ty);
993  return !PT || PT->getAddressSpace() != D.Pointer_AddressSpace ||
994  matchIntrinsicType(PT->getElementType(), Infos, ArgTys);
995  }
996 
997  case IITDescriptor::Struct: {
999  if (!ST || ST->getNumElements() != D.Struct_NumElements)
1000  return true;
1001 
1002  for (unsigned i = 0, e = D.Struct_NumElements; i != e; ++i)
1003  if (matchIntrinsicType(ST->getElementType(i), Infos, ArgTys))
1004  return true;
1005  return false;
1006  }
1007 
1009  // Two cases here - If this is the second occurrence of an argument, verify
1010  // that the later instance matches the previous instance.
1011  if (D.getArgumentNumber() < ArgTys.size())
1012  return Ty != ArgTys[D.getArgumentNumber()];
1013 
1014  // Otherwise, if this is the first instance of an argument, record it and
1015  // verify the "Any" kind.
1016  assert(D.getArgumentNumber() == ArgTys.size() && "Table consistency error");
1017  ArgTys.push_back(Ty);
1018 
1019  switch (D.getArgumentKind()) {
1020  case IITDescriptor::AK_Any: return false; // Success
1022  case IITDescriptor::AK_AnyFloat: return !Ty->isFPOrFPVectorTy();
1023  case IITDescriptor::AK_AnyVector: return !isa<VectorType>(Ty);
1024  case IITDescriptor::AK_AnyPointer: return !isa<PointerType>(Ty);
1025  }
1026  llvm_unreachable("all argument kinds not covered");
1027 
1029  // This may only be used when referring to a previous vector argument.
1030  if (D.getArgumentNumber() >= ArgTys.size())
1031  return true;
1032 
1033  Type *NewTy = ArgTys[D.getArgumentNumber()];
1034  if (VectorType *VTy = dyn_cast<VectorType>(NewTy))
1036  else if (IntegerType *ITy = dyn_cast<IntegerType>(NewTy))
1037  NewTy = IntegerType::get(ITy->getContext(), 2 * ITy->getBitWidth());
1038  else
1039  return true;
1040 
1041  return Ty != NewTy;
1042  }
1044  // This may only be used when referring to a previous vector argument.
1045  if (D.getArgumentNumber() >= ArgTys.size())
1046  return true;
1047 
1048  Type *NewTy = ArgTys[D.getArgumentNumber()];
1049  if (VectorType *VTy = dyn_cast<VectorType>(NewTy))
1051  else if (IntegerType *ITy = dyn_cast<IntegerType>(NewTy))
1052  NewTy = IntegerType::get(ITy->getContext(), ITy->getBitWidth() / 2);
1053  else
1054  return true;
1055 
1056  return Ty != NewTy;
1057  }
1059  // This may only be used when referring to a previous vector argument.
1060  return D.getArgumentNumber() >= ArgTys.size() ||
1061  !isa<VectorType>(ArgTys[D.getArgumentNumber()]) ||
1063  cast<VectorType>(ArgTys[D.getArgumentNumber()])) != Ty;
1065  if (D.getArgumentNumber() >= ArgTys.size())
1066  return true;
1067  VectorType * ReferenceType =
1068  dyn_cast<VectorType>(ArgTys[D.getArgumentNumber()]);
1069  VectorType *ThisArgType = dyn_cast<VectorType>(Ty);
1070  if (!ThisArgType || !ReferenceType ||
1071  (ReferenceType->getVectorNumElements() !=
1072  ThisArgType->getVectorNumElements()))
1073  return true;
1074  return matchIntrinsicType(ThisArgType->getVectorElementType(),
1075  Infos, ArgTys);
1076  }
1078  if (D.getArgumentNumber() >= ArgTys.size())
1079  return true;
1080  Type * ReferenceType = ArgTys[D.getArgumentNumber()];
1081  PointerType *ThisArgType = dyn_cast<PointerType>(Ty);
1082  return (!ThisArgType || ThisArgType->getElementType() != ReferenceType);
1083  }
1084  case IITDescriptor::PtrToElt: {
1085  if (D.getArgumentNumber() >= ArgTys.size())
1086  return true;
1087  VectorType * ReferenceType =
1088  dyn_cast<VectorType> (ArgTys[D.getArgumentNumber()]);
1089  PointerType *ThisArgType = dyn_cast<PointerType>(Ty);
1090 
1091  return (!ThisArgType || !ReferenceType ||
1092  ThisArgType->getElementType() != ReferenceType->getElementType());
1093  }
1095  if (D.getArgumentNumber() >= ArgTys.size())
1096  return true;
1097  VectorType * ReferenceType =
1098  dyn_cast<VectorType> (ArgTys[D.getArgumentNumber()]);
1099  VectorType *ThisArgVecTy = dyn_cast<VectorType>(Ty);
1100  if (!ThisArgVecTy || !ReferenceType ||
1101  (ReferenceType->getVectorNumElements() !=
1102  ThisArgVecTy->getVectorNumElements()))
1103  return true;
1104  PointerType *ThisArgEltTy =
1105  dyn_cast<PointerType>(ThisArgVecTy->getVectorElementType());
1106  if (!ThisArgEltTy)
1107  return true;
1108  return ThisArgEltTy->getElementType() !=
1109  ReferenceType->getVectorElementType();
1110  }
1111  }
1112  llvm_unreachable("unhandled");
1113 }
1114 
1115 bool
1118  // If there are no descriptors left, then it can't be a vararg.
1119  if (Infos.empty())
1120  return isVarArg;
1121 
1122  // There should be only one descriptor remaining at this point.
1123  if (Infos.size() != 1)
1124  return true;
1125 
1126  // Check and verify the descriptor.
1127  IITDescriptor D = Infos.front();
1128  Infos = Infos.slice(1);
1129  if (D.Kind == IITDescriptor::VarArg)
1130  return !isVarArg;
1131 
1132  return true;
1133 }
1134 
1137  if (!ID)
1138  return None;
1139 
1140  FunctionType *FTy = F->getFunctionType();
1141  // Accumulate an array of overloaded types for the given intrinsic
1142  SmallVector<Type *, 4> ArgTys;
1143  {
1145  getIntrinsicInfoTableEntries(ID, Table);
1146  ArrayRef<Intrinsic::IITDescriptor> TableRef = Table;
1147 
1148  // If we encounter any problems matching the signature with the descriptor
1149  // just give up remangling. It's up to verifier to report the discrepancy.
1150  if (Intrinsic::matchIntrinsicType(FTy->getReturnType(), TableRef, ArgTys))
1151  return None;
1152  for (auto Ty : FTy->params())
1153  if (Intrinsic::matchIntrinsicType(Ty, TableRef, ArgTys))
1154  return None;
1155  if (Intrinsic::matchIntrinsicVarArg(FTy->isVarArg(), TableRef))
1156  return None;
1157  }
1158 
1159  StringRef Name = F->getName();
1160  if (Name == Intrinsic::getName(ID, ArgTys))
1161  return None;
1162 
1163  auto NewDecl = Intrinsic::getDeclaration(F->getParent(), ID, ArgTys);
1164  NewDecl->setCallingConv(F->getCallingConv());
1165  assert(NewDecl->getFunctionType() == FTy && "Shouldn't change the signature");
1166  return NewDecl;
1167 }
1168 
1169 /// hasAddressTaken - returns true if there are any uses of this function
1170 /// other than direct calls or invokes to it.
1171 bool Function::hasAddressTaken(const User* *PutOffender) const {
1172  for (const Use &U : uses()) {
1173  const User *FU = U.getUser();
1174  if (isa<BlockAddress>(FU))
1175  continue;
1176  if (!isa<CallInst>(FU) && !isa<InvokeInst>(FU)) {
1177  if (PutOffender)
1178  *PutOffender = FU;
1179  return true;
1180  }
1181  ImmutableCallSite CS(cast<Instruction>(FU));
1182  if (!CS.isCallee(&U)) {
1183  if (PutOffender)
1184  *PutOffender = FU;
1185  return true;
1186  }
1187  }
1188  return false;
1189 }
1190 
1192  // Check the linkage
1193  if (!hasLinkOnceLinkage() && !hasLocalLinkage() &&
1195  return false;
1196 
1197  // Check if the function is used by anything other than a blockaddress.
1198  for (const User *U : users())
1199  if (!isa<BlockAddress>(U))
1200  return false;
1201 
1202  return true;
1203 }
1204 
1205 /// callsFunctionThatReturnsTwice - Return true if the function has a call to
1206 /// setjmp or other function that gcc recognizes as "returning twice".
1208  for (const_inst_iterator
1209  I = inst_begin(this), E = inst_end(this); I != E; ++I) {
1210  ImmutableCallSite CS(&*I);
1211  if (CS && CS.hasFnAttr(Attribute::ReturnsTwice))
1212  return true;
1213  }
1214 
1215  return false;
1216 }
1217 
1220  return cast<Constant>(Op<0>());
1221 }
1222 
1224  setHungoffOperand<0>(Fn);
1225  setValueSubclassDataBit(3, Fn != nullptr);
1226 }
1227 
1230  return cast<Constant>(Op<1>());
1231 }
1232 
1234  setHungoffOperand<1>(PrefixData);
1235  setValueSubclassDataBit(1, PrefixData != nullptr);
1236 }
1237 
1240  return cast<Constant>(Op<2>());
1241 }
1242 
1244  setHungoffOperand<2>(PrologueData);
1245  setValueSubclassDataBit(2, PrologueData != nullptr);
1246 }
1247 
1248 void Function::allocHungoffUselist() {
1249  // If we've already allocated a uselist, stop here.
1250  if (getNumOperands())
1251  return;
1252 
1253  allocHungoffUses(3, /*IsPhi=*/ false);
1255 
1256  // Initialize the uselist with placeholder operands to allow traversal.
1258  Op<0>().set(CPN);
1259  Op<1>().set(CPN);
1260  Op<2>().set(CPN);
1261 }
1262 
1263 template <int Idx>
1264 void Function::setHungoffOperand(Constant *C) {
1265  if (C) {
1266  allocHungoffUselist();
1267  Op<Idx>().set(C);
1268  } else if (getNumOperands()) {
1269  Op<Idx>().set(
1271  }
1272 }
1273 
1274 void Function::setValueSubclassDataBit(unsigned Bit, bool On) {
1275  assert(Bit < 16 && "SubclassData contains only 16 bits");
1276  if (On)
1277  setValueSubclassData(getSubclassDataFromValue() | (1 << Bit));
1278  else
1279  setValueSubclassData(getSubclassDataFromValue() & ~(1 << Bit));
1280 }
1281 
1282 void Function::setEntryCount(uint64_t Count) {
1283  MDBuilder MDB(getContext());
1285 }
1286 
1289  if (MD && MD->getOperand(0))
1290  if (MDString *MDS = dyn_cast<MDString>(MD->getOperand(0)))
1291  if (MDS->getString().equals("function_entry_count")) {
1292  ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(1));
1293  uint64_t Count = CI->getValue().getZExtValue();
1294  if (Count == 0)
1295  return None;
1296  return Count;
1297  }
1298  return None;
1299 }
1300 
1302  MDBuilder MDB(getContext());
1304  MDB.createFunctionSectionPrefix(Prefix));
1305 }
1306 
1309  assert(dyn_cast<MDString>(MD->getOperand(0))
1310  ->getString()
1311  .equals("function_section_prefix") &&
1312  "Metadata not match");
1313  return dyn_cast<MDString>(MD->getOperand(1))->getString();
1314  }
1315  return None;
1316 }
bool hasNoCaptureAttr() const
Return true if this argument has the nocapture attribute on it in its containing function.
Definition: Function.cpp:148
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type (if unknown returns 0).
bool hasNoAliasAttr() const
Return true if this argument has the noalias attribute on it in its containing function.
Definition: Function.cpp:141
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
Definition: StringRef.h:634
bool isDefTriviallyDead() const
isDefTriviallyDead - Return true if it is trivially safe to remove this function definition from the ...
Definition: Function.cpp:1191
const NoneType None
Definition: None.h:23
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:967
bool hasAttribute(unsigned i, Attribute::AttrKind Kind) const
check if an attributes is in the list of attributes.
Definition: Function.h:276
bool hasLazyArguments() const
hasLazyArguments/CheckLazyArguments - The argument list of a function is built on demand...
Definition: Function.h:93
iterator_range< use_iterator > uses()
Definition: Value.h:326
static Type * getDoubleTy(LLVMContext &C)
Definition: Type.cpp:158
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
Definition: Function.cpp:226
LLVM Argument representation.
Definition: Argument.h:34
LLVMContext & Context
Constant * getPrologueData() const
Get the prologue data associated with this function.
Definition: Function.cpp:1238
bool onlyReadsMemory() const
Return true if this argument has the readonly or readnone attribute on it in its containing function...
Definition: Function.cpp:180
uint64_t getZExtValue() const
Get zero extended value.
Definition: APInt.h:1309
void dropAllReferences()
Drop all references to operands.
Definition: User.h:269
iterator erase(iterator where)
Definition: ilist.h:280
size_t i
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:52
unsigned getNumParams() const
Return the number of fixed parameters this function type requires.
Definition: DerivedTypes.h:137
const std::string & getGC(const Function &Fn)
Return the GC for a function.
const T & front() const
front - Get the first element.
Definition: ArrayRef.h:144
void addDereferenceableAttr(unsigned i, uint64_t Bytes)
adds the dereferenceable attribute to the list of attributes.
Definition: Function.cpp:400
bool hasByValOrInAllocaAttr() const
Return true if this argument has the byval attribute or inalloca attribute on it in its containing fu...
Definition: Function.cpp:107
unsigned getNumOperands() const
Definition: User.h:167
void clearGC()
Definition: Function.cpp:422
void setGC(const Function &Fn, std::string GCName)
Define the GC for a function.
Type * getValueType() const
Definition: GlobalValue.h:261
ArrayRef< Type * > params() const
Definition: DerivedTypes.h:128
void setGC(std::string Str)
Definition: Function.cpp:417
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:655
bool hasSwiftSelfAttr() const
Return true if this argument has the swiftself attribute.
Definition: Function.cpp:90
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
Definition: Type.h:148
bool isOverloaded(ID id)
Returns true if the intrinsic can be overloaded.
Definition: Function.cpp:926
bool hasAvailableExternallyLinkage() const
Definition: GlobalValue.h:402
void setSectionPrefix(StringRef Prefix)
Set the section prefix for this function.
Definition: Function.cpp:1301
bool isTokenTy() const
Return true if this is 'token'.
Definition: Type.h:192
Type * getReturnType() const
Returns the type of the ret val.
Definition: Function.cpp:238
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:736
bool hasPrologueData() const
Check whether this function has prologue data.
Definition: Function.h:599
Metadata node.
Definition: Metadata.h:830
The two locations do not alias at all.
Definition: AliasAnalysis.h:79
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:315
unsigned getAddressSpace() const
Return the address space of the Pointer type.
Definition: DerivedTypes.h:471
unsigned getBitWidth() const
Get the number of bits in this IntegerType.
Definition: DerivedTypes.h:65
FunctionType * getType(LLVMContext &Context, ID id, ArrayRef< Type * > Tys=None)
Return the function type for an intrinsic.
Definition: Function.cpp:905
static Type * getMetadataTy(LLVMContext &C)
Definition: Type.cpp:159
Type * getElementType() const
Definition: DerivedTypes.h:462
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:399
bool hasAttribute(unsigned Index, Attribute::AttrKind Kind) const
Return true if the attribute exists at the given index.
Definition: Attributes.cpp:994
static Type * getX86_MMXTy(LLVMContext &C)
Definition: Type.cpp:164
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Definition: Function.h:165
bool isMaterializable() const
Definition: Function.cpp:216
size_t arg_size() const
Definition: Function.cpp:327
uint64_t getDereferenceableBytes(unsigned i) const
Extract the number of dereferenceable bytes for a call or parameter (0=unknown).
Definition: Function.h:302
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:191
void removeAttributes(unsigned i, AttributeSet Attrs)
removes the attributes from the list of attributes.
Definition: Function.cpp:394
unsigned getGlobalObjectSubClassData() const
Definition: Globals.cpp:96
void addAttr(AttributeSet AS)
Add a Attribute to an argument.
Definition: Function.cpp:188
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:171
std::string getEVTString() const
getEVTString - This function returns value type as a string, e.g.
Definition: ValueTypes.cpp:120
static Type * getTokenTy(LLVMContext &C)
Definition: Type.cpp:160
inst_iterator inst_begin(Function *F)
Definition: InstIterator.h:130
bool hasGC() const
hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm to use during code generatio...
Definition: Function.h:250
StringRef getName(ID id)
Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
Definition: Function.cpp:555
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
bool hasSwiftErrorAttr() const
Return true if this argument has the swifterror attribute.
Definition: Function.cpp:95
static Type * getFloatTy(LLVMContext &C)
Definition: Type.cpp:157
const APInt & getValue() const
Return the constant as an APInt value reference.
Definition: Constants.h:143
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:440
Class to represent struct types.
Definition: DerivedTypes.h:199
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:32
static GCRegistry::Add< StatepointGC > D("statepoint-example","an example strategy for statepoint")
Optional< StringRef > getSectionPrefix() const
Get the section prefix for this function.
Definition: Function.cpp:1307
Constant * getPersonalityFn() const
Get the personality function associated with this function.
Definition: Function.cpp:1218
static StringRef getName(Value *V)
AttributeSet addDereferenceableAttr(LLVMContext &C, unsigned Index, uint64_t Bytes) const
Add the dereferenceable attribute to the attribute set at the given index.
Definition: Attributes.cpp:936
void setName(const Twine &Name)
Change the name of the value.
Definition: Value.cpp:257
uint64_t getDereferenceableOrNullBytes() const
If this argument has the dereferenceable_or_null attribute on it in its containing function...
Definition: Function.cpp:126
void addAttributes(unsigned i, AttributeSet Attrs)
adds the attributes to the list of attributes.
Definition: Function.cpp:376
Type * getVectorElementType() const
Definition: Type.h:353
uint64_t getDereferenceableBytes() const
If this argument has the dereferenceable attribute on it in its containing function, return the number of bytes known to be dereferenceable.
Definition: Function.cpp:120
void removeAttr(AttributeSet AS)
Remove a Attribute from an argument.
Definition: Function.cpp:198
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:60
llvm::Optional< Function * > remangleIntrinsicFunction(Function *F)
Definition: Function.cpp:1135
Class to represent function types.
Definition: DerivedTypes.h:102
IIT_Info
IIT_Info - These are enumerators that describe the entries returned by the getIntrinsicInfoTableEntri...
Definition: Function.cpp:576
#define F(x, y, z)
Definition: MD5.cpp:51
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:264
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition: Type.h:128
bool hasStructRetAttr() const
Return true if this argument has the sret attribute on it in its containing function.
Definition: Function.cpp:155
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
Definition: Type.h:142
Class to represent array types.
Definition: DerivedTypes.h:345
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
Definition: Type.cpp:291
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
static std::string utostr(uint64_t X, bool isNeg=false)
Definition: StringExtras.h:79
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:949
void addDereferenceableOrNullAttr(unsigned i, uint64_t Bytes)
adds the dereferenceable_or_null attribute to the list of attributes.
Definition: Function.cpp:406
static GCRegistry::Add< OcamlGC > B("ocaml","ocaml 3.10-compatible GC")
bool hasNestAttr() const
Return true if this argument has the nest attribute on it in its containing function.
Definition: Function.cpp:134
Optional< uint64_t > getEntryCount() const
Get the entry count for this function.
Definition: Function.cpp:1287
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
Definition: StringRef.h:135
Type * getElementType() const
Definition: DerivedTypes.h:336
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:141
Class to represent pointers.
Definition: DerivedTypes.h:443
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
static std::string getMangledTypeStr(Type *Ty)
Returns a stable mangling for the type specified for use in the name mangling scheme used by 'any' ty...
Definition: Function.cpp:528
bool isX86_MMXTy() const
Return true if this is X86 MMX.
Definition: Type.h:180
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
Definition: Type.h:201
void setCallingConv(CallingConv::ID CC)
Definition: Function.h:169
unsigned getNumSlots() const
Return the number of slots used in this attribute list.
Type * getParamType(unsigned i) const
Parameter type accessors.
Definition: DerivedTypes.h:133
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:409
void stealArgumentListFrom(Function &Src)
Steal arguments from another function.
Definition: Function.cpp:305
static ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
Definition: Constants.cpp:1323
bool isLeaf(ID id)
Returns true if the intrinsic is a leaf, i.e.
Definition: Function.cpp:932
static Intrinsic::ID lookupIntrinsicID(StringRef Name)
This does the actual lookup of an intrinsic ID which matches the given function name.
Definition: Function.cpp:486
Constant * getOrInsertFunction(StringRef Name, FunctionType *T, AttributeSet AttributeList)
Look up the specified function in the module symbol table.
Definition: Module.cpp:123
LLVM Basic Block Representation.
Definition: BasicBlock.h:51
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:48
const Function * getParent() const
Definition: Argument.h:48
bool hasAttribute(Attribute::AttrKind Kind) const
Checks if an argument has a given attribute.
Definition: Function.cpp:208
AttributeSet addAttribute(LLVMContext &C, unsigned Index, Attribute::AttrKind Kind) const
Add an attribute to the attribute set at the given index.
Definition: Attributes.cpp:753
Type * getElementType(unsigned N) const
Definition: DerivedTypes.h:290
This is an important base class in LLVM.
Definition: Constant.h:42
bool hasInAllocaAttr() const
Return true if this argument has the inalloca attribute on it in its containing function.
Definition: Function.cpp:102
This file contains the declarations for the subclasses of Constant, which represent the different fla...
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
Definition: Type.h:145
void removeAttribute(unsigned i, Attribute::AttrKind Kind)
removes the attribute from the list of attributes.
Definition: Function.cpp:382
unsigned getParamAlignment() const
If this is a byval or inalloca argument, return its alignment.
Definition: Function.cpp:114
bool hasPersonalityFn() const
Check whether this function has a personality function.
Definition: Function.h:581
void addAttribute(unsigned i, Attribute::AttrKind Kind)
adds the attribute to the list of attributes.
Definition: Function.cpp:364
static Type * getVoidTy(LLVMContext &C)
Definition: Type.cpp:154
void splice(iterator where, iplist_impl &L2)
Definition: ilist.h:342
bool hasSExtAttr() const
Return true if this argument has the sext attribute on it in its containing function.
Definition: Function.cpp:174
uint64_t getNumElements() const
Definition: DerivedTypes.h:335
void copyAttributesFrom(const GlobalValue *Src) override
copyAttributesFrom - copy all additional attributes (those not needed to create a Function) from the ...
Definition: Function.cpp:431
bool hasFnAttr(Attribute::AttrKind Kind) const
Return true if this function has the given attribute.
Definition: CallSite.h:349
static IITDescriptor get(IITDescriptorKind K, unsigned Field)
Definition: Intrinsics.h:137
void recalculateIntrinsicID()
Recalculate the ID for this function if it is an Intrinsic defined in llvm/Intrinsics.h.
Definition: Function.cpp:503
arg_iterator arg_begin()
Definition: Function.h:550
Intrinsic::ID IntID
The intrinsic ID for this subclass (which must be a Function).
Definition: GlobalValue.h:147
Class to represent integer types.
Definition: DerivedTypes.h:39
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:136
MDNode * createFunctionEntryCount(uint64_t Count)
Return metadata containing the entry count for a function.
Definition: MDBuilder.cpp:59
bool isFPOrFPVectorTy() const
Return true if this is a FP type or a vector of FP.
Definition: Type.h:183
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:468
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void setEntryCount(uint64_t Count)
Set the entry count for this function.
Definition: Function.cpp:1282
bool hasByValAttr() const
Return true if this argument has the byval attribute on it in its containing function.
Definition: Function.cpp:85
const FunctionListType & getFunctionList() const
Get the Module's list of functions (constant).
Definition: Module.h:478
static Type * getHalfTy(LLVMContext &C)
Definition: Type.cpp:156
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Definition: Type.cpp:234
const MDOperand & getOperand(unsigned I) const
Definition: Metadata.h:1034
~Function() override
Definition: Function.cpp:281
uint64_t getDereferenceableOrNullBytes(unsigned i) const
Extract the number of dereferenceable_or_null bytes for a call or parameter (0=unknown).
Definition: Function.h:308
Iterator for intrusive lists based on ilist_node.
static PointerType * getInt1PtrTy(LLVMContext &C, unsigned AS=0)
Definition: Type.cpp:209
enum llvm::Intrinsic::IITDescriptor::IITDescriptorKind Kind
bool matchIntrinsicVarArg(bool isVarArg, ArrayRef< IITDescriptor > &Infos)
Verify if the intrinsic has variable arguments.
Definition: Function.cpp:1116
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:458
This is the shared class of boolean and integer constants.
Definition: Constants.h:88
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:330
void getIntrinsicInfoTableEntries(ID id, SmallVectorImpl< IITDescriptor > &T)
Return the IIT table descriptor for the specified intrinsic into an array of IITDescriptors.
Definition: Function.cpp:784
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:230
static const char * Target
void dropAllReferences()
dropAllReferences() - This method causes all the subinstructions to "let go" of all references that t...
Definition: Function.cpp:342
void copyAttributesFrom(const GlobalValue *Src) override
Copy all additional attributes (those not needed to create a GlobalValue) from the GlobalValue Src to...
Definition: Globals.cpp:108
bool hasZExtAttr() const
Return true if this argument has the zext attribute on it in its containing function.
Definition: Function.cpp:168
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:391
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
Definition: Function.h:146
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
AttributeSet getAttributes() const
Return the attribute list for this Function.
Definition: Function.h:176
AttributeSet removeAttributes(LLVMContext &C, unsigned Index, AttributeSet Attrs) const
Remove the specified attributes at the specified index from this attribute list.
Definition: Attributes.cpp:857
bool arg_empty() const
Definition: Function.cpp:330
Class to represent vector types.
Definition: DerivedTypes.h:369
Target - Wrapper for Target specific information.
Argument(Type *Ty, const Twine &Name="", Function *F=nullptr)
Constructor.
Definition: Function.cpp:42
void push_back(pointer val)
Definition: ilist.h:326
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:716
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition: Type.h:195
iterator_range< user_iterator > users()
Definition: Value.h:370
unsigned HasLLVMReservedName
True if the function's name starts with "llvm.".
Definition: GlobalValue.h:104
unsigned getVectorNumElements() const
Definition: DerivedTypes.h:438
bool hasNonNullAttr() const
Return true if this argument has the nonnull attribute on it in its containing function.
Definition: Function.cpp:72
void setIsMaterializable(bool V)
Definition: Function.cpp:220
static void DecodeIITType(unsigned &NextElt, ArrayRef< unsigned char > Infos, SmallVectorImpl< Intrinsic::IITDescriptor > &OutputTable)
Definition: Function.cpp:621
void eraseFromParent() override
eraseFromParent - This method unlinks 'this' from the containing module and deletes it...
Definition: Function.cpp:246
MDNode * getMetadata(unsigned KindID) const
Get the current metadata attachments for the given kind, if any.
Definition: Metadata.cpp:1391
AttributeSet removeAttribute(LLVMContext &C, unsigned Index, Attribute::AttrKind Kind) const
Remove the specified attribute at the specified index from this attribute list.
Definition: Attributes.cpp:845
void setMetadata(unsigned KindID, MDNode *MD)
Set a particular kind of metadata attachment.
Definition: Metadata.cpp:1381
void setAttributes(AttributeSet Attrs)
Set the attribute list for this Function.
Definition: Function.h:179
bool hasLinkOnceLinkage() const
Definition: GlobalValue.h:405
pointer remove(iterator &IT)
Definition: ilist.h:264
PointerType * getType() const
Global values are always pointers.
Definition: GlobalValue.h:259
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:1171
void removeFromParent() override
removeFromParent - This method unlinks 'this' from the containing module, but does not delete it...
Definition: Function.cpp:242
unsigned short getSubclassDataFromValue() const
Definition: Value.h:615
void clear()
Definition: ilist.h:322
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Definition: Globals.cpp:188
unsigned getSlotIndex(unsigned Slot) const
Return the index for the given slot.
AttributeSet addDereferenceableOrNullAttr(LLVMContext &C, unsigned Index, uint64_t Bytes) const
Add the dereferenceable_or_null attribute to the attribute set at the given index.
Definition: Attributes.cpp:943
ImmutableCallSite - establish a view to a call site for examination.
Definition: CallSite.h:665
const std::string & getGC() const
Definition: Function.cpp:412
#define I(x, y, z)
Definition: MD5.cpp:54
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
Definition: SmallVector.h:135
FunctionType * getFunctionType() const
Returns the FunctionType for me.
Definition: Function.cpp:230
bool callsFunctionThatReturnsTwice() const
callsFunctionThatReturnsTwice - Return true if the function has a call to setjmp or other function th...
Definition: Function.cpp:1207
void setPrologueData(Constant *PrologueData)
Definition: Function.cpp:1243
Compile-time customization of User operands.
Definition: User.h:43
bool hasPrefixData() const
Check whether this function has prefix data.
Definition: Function.h:590
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:287
Constant * getPrefixData() const
Get the prefix data associated with this function.
Definition: Function.cpp:1228
static EVT getEVT(Type *Ty, bool HandleUnknown=false)
getEVT - Return the value type corresponding to the specified type.
Definition: ValueTypes.cpp:309
AttributeSet getAttributes(LLVMContext &C, ID id)
Return the attributes for an intrinsic.
bool hasLocalLinkage() const
Definition: GlobalValue.h:415
bool isVarArg() const
Definition: DerivedTypes.h:122
int lookupLLVMIntrinsicByName(ArrayRef< const char * > NameTable, StringRef Name)
Looks up Name in NameTable via binary search.
const unsigned Kind
bool use_empty() const
Definition: Value.h:299
Type * getReturnType() const
Definition: DerivedTypes.h:123
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
unsigned getParamAlignment(unsigned i) const
Extract the alignment for a call or parameter (0=unknown).
Definition: Function.h:296
static Type * DecodeFixedType(ArrayRef< Intrinsic::IITDescriptor > &Infos, ArrayRef< Type * > Tys, LLVMContext &Context)
Definition: Function.cpp:818
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:537
LLVM Value Representation.
Definition: Value.h:71
static const char * name
const ArgumentListType & getArgumentList() const
Get the underlying elements of the Function...
Definition: Function.h:499
unsigned getArgNo() const
Return the index of this formal argument in its containing function.
Definition: Function.cpp:57
static VectorType * get(Type *ElementType, unsigned NumElements)
This static method is the primary way to construct an VectorType.
Definition: Type.cpp:631
void allocHungoffUses(unsigned N, bool IsPhi=false)
Allocate the array of Uses, followed by a pointer (with bottom bit set) to the User.
Definition: User.cpp:43
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Definition: Compiler.h:239
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
Definition: BitmaskEnum.h:81
static const char *const IntrinsicNameTable[]
Table of string intrinsic names indexed by enum value.
Definition: Function.cpp:452
MDNode * createFunctionSectionPrefix(StringRef Prefix)
Return metadata containing the section prefix for a function.
Definition: MDBuilder.cpp:66
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
inst_iterator inst_end(Function *F)
Definition: InstIterator.h:131
A single uniqued string.
Definition: Metadata.h:586
void setPersonalityFn(Constant *Fn)
Definition: Function.cpp:1223
void setNumHungOffUseOperands(unsigned NumOps)
Subclasses with hung off uses need to manage the operand count themselves.
Definition: User.h:191
unsigned getNumElements() const
Random access to the elements.
Definition: DerivedTypes.h:289
AttributeSet addAttributes(LLVMContext &C, unsigned Index, AttributeSet Attrs) const
Add attributes to the attribute set at the given index.
Definition: Attributes.cpp:796
static GCRegistry::Add< ErlangGC > A("erlang","erlang-compatible garbage collector")
const T * data() const
Definition: ArrayRef.h:138
bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
Definition: Function.cpp:234
void setGlobalObjectSubClassData(unsigned Val)
Definition: Globals.cpp:101
bool hasReturnedAttr() const
Return true if this argument has the returned attribute on it in its containing function.
Definition: Function.cpp:162
void dropAllReferences()
Cause all subinstructions to "let go" of all the references that said subinstructions are maintaining...
Definition: BasicBlock.cpp:219
LLVMContext & getContext() const
Get the global data context.
Definition: Module.h:222
bool isCallee(Value::const_user_iterator UI) const
isCallee - Determine whether the passed iterator points to the callee operand's Use.
Definition: CallSite.h:134
bool isVoidTy() const
Return true if this is 'void'.
Definition: Type.h:139
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results...
Definition: Attributes.h:67
bool isMetadataTy() const
Return true if this is 'metadata'.
Definition: Type.h:189
void setPrefixData(Constant *PrefixData)
Definition: Function.cpp:1233