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