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