[clang] Add test for CWG190 "Layout-compatible POD-struct types" (#121668)
[llvm-project.git] / llvm / lib / IR / Intrinsics.cpp
blobec1184e8d835d6fe1c4a8d80ad54c33691a48c2f
1 //===-- Intrinsics.cpp - Intrinsic Function Handling ------------*- C++ -*-===//
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 functions required for supporting intrinsic functions.
11 //===----------------------------------------------------------------------===//
13 #include "llvm/IR/Intrinsics.h"
14 #include "llvm/ADT/StringExtras.h"
15 #include "llvm/IR/Function.h"
16 #include "llvm/IR/IntrinsicsAArch64.h"
17 #include "llvm/IR/IntrinsicsAMDGPU.h"
18 #include "llvm/IR/IntrinsicsARM.h"
19 #include "llvm/IR/IntrinsicsBPF.h"
20 #include "llvm/IR/IntrinsicsHexagon.h"
21 #include "llvm/IR/IntrinsicsLoongArch.h"
22 #include "llvm/IR/IntrinsicsMips.h"
23 #include "llvm/IR/IntrinsicsNVPTX.h"
24 #include "llvm/IR/IntrinsicsPowerPC.h"
25 #include "llvm/IR/IntrinsicsR600.h"
26 #include "llvm/IR/IntrinsicsRISCV.h"
27 #include "llvm/IR/IntrinsicsS390.h"
28 #include "llvm/IR/IntrinsicsVE.h"
29 #include "llvm/IR/IntrinsicsX86.h"
30 #include "llvm/IR/IntrinsicsXCore.h"
31 #include "llvm/IR/Module.h"
32 #include "llvm/IR/Type.h"
34 using namespace llvm;
36 /// Table of string intrinsic names indexed by enum value.
37 #define GET_INTRINSIC_NAME_TABLE
38 #include "llvm/IR/IntrinsicImpl.inc"
39 #undef GET_INTRINSIC_NAME_TABLE
41 StringRef Intrinsic::getBaseName(ID id) {
42 assert(id < num_intrinsics && "Invalid intrinsic ID!");
43 return IntrinsicNameTable + IntrinsicNameOffsetTable[id];
46 StringRef Intrinsic::getName(ID id) {
47 assert(id < num_intrinsics && "Invalid intrinsic ID!");
48 assert(!Intrinsic::isOverloaded(id) &&
49 "This version of getName does not support overloading");
50 return getBaseName(id);
53 /// Returns a stable mangling for the type specified for use in the name
54 /// mangling scheme used by 'any' types in intrinsic signatures. The mangling
55 /// of named types is simply their name. Manglings for unnamed types consist
56 /// of a prefix ('p' for pointers, 'a' for arrays, 'f_' for functions)
57 /// combined with the mangling of their component types. A vararg function
58 /// type will have a suffix of 'vararg'. Since function types can contain
59 /// other function types, we close a function type mangling with suffix 'f'
60 /// which can't be confused with it's prefix. This ensures we don't have
61 /// collisions between two unrelated function types. Otherwise, you might
62 /// parse ffXX as f(fXX) or f(fX)X. (X is a placeholder for any other type.)
63 /// The HasUnnamedType boolean is set if an unnamed type was encountered,
64 /// indicating that extra care must be taken to ensure a unique name.
65 static std::string getMangledTypeStr(Type *Ty, bool &HasUnnamedType) {
66 std::string Result;
67 if (PointerType *PTyp = dyn_cast<PointerType>(Ty)) {
68 Result += "p" + utostr(PTyp->getAddressSpace());
69 } else if (ArrayType *ATyp = dyn_cast<ArrayType>(Ty)) {
70 Result += "a" + utostr(ATyp->getNumElements()) +
71 getMangledTypeStr(ATyp->getElementType(), HasUnnamedType);
72 } else if (StructType *STyp = dyn_cast<StructType>(Ty)) {
73 if (!STyp->isLiteral()) {
74 Result += "s_";
75 if (STyp->hasName())
76 Result += STyp->getName();
77 else
78 HasUnnamedType = true;
79 } else {
80 Result += "sl_";
81 for (auto *Elem : STyp->elements())
82 Result += getMangledTypeStr(Elem, HasUnnamedType);
84 // Ensure nested structs are distinguishable.
85 Result += "s";
86 } else if (FunctionType *FT = dyn_cast<FunctionType>(Ty)) {
87 Result += "f_" + getMangledTypeStr(FT->getReturnType(), HasUnnamedType);
88 for (size_t i = 0; i < FT->getNumParams(); i++)
89 Result += getMangledTypeStr(FT->getParamType(i), HasUnnamedType);
90 if (FT->isVarArg())
91 Result += "vararg";
92 // Ensure nested function types are distinguishable.
93 Result += "f";
94 } else if (VectorType *VTy = dyn_cast<VectorType>(Ty)) {
95 ElementCount EC = VTy->getElementCount();
96 if (EC.isScalable())
97 Result += "nx";
98 Result += "v" + utostr(EC.getKnownMinValue()) +
99 getMangledTypeStr(VTy->getElementType(), HasUnnamedType);
100 } else if (TargetExtType *TETy = dyn_cast<TargetExtType>(Ty)) {
101 Result += "t";
102 Result += TETy->getName();
103 for (Type *ParamTy : TETy->type_params())
104 Result += "_" + getMangledTypeStr(ParamTy, HasUnnamedType);
105 for (unsigned IntParam : TETy->int_params())
106 Result += "_" + utostr(IntParam);
107 // Ensure nested target extension types are distinguishable.
108 Result += "t";
109 } else if (Ty) {
110 switch (Ty->getTypeID()) {
111 default:
112 llvm_unreachable("Unhandled type");
113 case Type::VoidTyID:
114 Result += "isVoid";
115 break;
116 case Type::MetadataTyID:
117 Result += "Metadata";
118 break;
119 case Type::HalfTyID:
120 Result += "f16";
121 break;
122 case Type::BFloatTyID:
123 Result += "bf16";
124 break;
125 case Type::FloatTyID:
126 Result += "f32";
127 break;
128 case Type::DoubleTyID:
129 Result += "f64";
130 break;
131 case Type::X86_FP80TyID:
132 Result += "f80";
133 break;
134 case Type::FP128TyID:
135 Result += "f128";
136 break;
137 case Type::PPC_FP128TyID:
138 Result += "ppcf128";
139 break;
140 case Type::X86_AMXTyID:
141 Result += "x86amx";
142 break;
143 case Type::IntegerTyID:
144 Result += "i" + utostr(cast<IntegerType>(Ty)->getBitWidth());
145 break;
148 return Result;
151 static std::string getIntrinsicNameImpl(Intrinsic::ID Id, ArrayRef<Type *> Tys,
152 Module *M, FunctionType *FT,
153 bool EarlyModuleCheck) {
155 assert(Id < Intrinsic::num_intrinsics && "Invalid intrinsic ID!");
156 assert((Tys.empty() || Intrinsic::isOverloaded(Id)) &&
157 "This version of getName is for overloaded intrinsics only");
158 (void)EarlyModuleCheck;
159 assert((!EarlyModuleCheck || M ||
160 !any_of(Tys, [](Type *T) { return isa<PointerType>(T); })) &&
161 "Intrinsic overloading on pointer types need to provide a Module");
162 bool HasUnnamedType = false;
163 std::string Result(Intrinsic::getBaseName(Id));
164 for (Type *Ty : Tys)
165 Result += "." + getMangledTypeStr(Ty, HasUnnamedType);
166 if (HasUnnamedType) {
167 assert(M && "unnamed types need a module");
168 if (!FT)
169 FT = Intrinsic::getType(M->getContext(), Id, Tys);
170 else
171 assert((FT == Intrinsic::getType(M->getContext(), Id, Tys)) &&
172 "Provided FunctionType must match arguments");
173 return M->getUniqueIntrinsicName(Result, Id, FT);
175 return Result;
178 std::string Intrinsic::getName(ID Id, ArrayRef<Type *> Tys, Module *M,
179 FunctionType *FT) {
180 assert(M && "We need to have a Module");
181 return getIntrinsicNameImpl(Id, Tys, M, FT, true);
184 std::string Intrinsic::getNameNoUnnamedTypes(ID Id, ArrayRef<Type *> Tys) {
185 return getIntrinsicNameImpl(Id, Tys, nullptr, nullptr, false);
188 /// IIT_Info - These are enumerators that describe the entries returned by the
189 /// getIntrinsicInfoTableEntries function.
191 /// Defined in Intrinsics.td.
192 enum IIT_Info {
193 #define GET_INTRINSIC_IITINFO
194 #include "llvm/IR/IntrinsicImpl.inc"
195 #undef GET_INTRINSIC_IITINFO
198 static void
199 DecodeIITType(unsigned &NextElt, ArrayRef<unsigned char> Infos,
200 IIT_Info LastInfo,
201 SmallVectorImpl<Intrinsic::IITDescriptor> &OutputTable) {
202 using namespace Intrinsic;
204 bool IsScalableVector = (LastInfo == IIT_SCALABLE_VEC);
206 IIT_Info Info = IIT_Info(Infos[NextElt++]);
207 unsigned StructElts = 2;
209 switch (Info) {
210 case IIT_Done:
211 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Void, 0));
212 return;
213 case IIT_VARARG:
214 OutputTable.push_back(IITDescriptor::get(IITDescriptor::VarArg, 0));
215 return;
216 case IIT_MMX:
217 OutputTable.push_back(IITDescriptor::get(IITDescriptor::MMX, 0));
218 return;
219 case IIT_AMX:
220 OutputTable.push_back(IITDescriptor::get(IITDescriptor::AMX, 0));
221 return;
222 case IIT_TOKEN:
223 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Token, 0));
224 return;
225 case IIT_METADATA:
226 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Metadata, 0));
227 return;
228 case IIT_F16:
229 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Half, 0));
230 return;
231 case IIT_BF16:
232 OutputTable.push_back(IITDescriptor::get(IITDescriptor::BFloat, 0));
233 return;
234 case IIT_F32:
235 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Float, 0));
236 return;
237 case IIT_F64:
238 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Double, 0));
239 return;
240 case IIT_F128:
241 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Quad, 0));
242 return;
243 case IIT_PPCF128:
244 OutputTable.push_back(IITDescriptor::get(IITDescriptor::PPCQuad, 0));
245 return;
246 case IIT_I1:
247 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 1));
248 return;
249 case IIT_I2:
250 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 2));
251 return;
252 case IIT_I4:
253 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 4));
254 return;
255 case IIT_AARCH64_SVCOUNT:
256 OutputTable.push_back(IITDescriptor::get(IITDescriptor::AArch64Svcount, 0));
257 return;
258 case IIT_I8:
259 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 8));
260 return;
261 case IIT_I16:
262 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 16));
263 return;
264 case IIT_I32:
265 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 32));
266 return;
267 case IIT_I64:
268 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 64));
269 return;
270 case IIT_I128:
271 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 128));
272 return;
273 case IIT_V1:
274 OutputTable.push_back(IITDescriptor::getVector(1, IsScalableVector));
275 DecodeIITType(NextElt, Infos, Info, OutputTable);
276 return;
277 case IIT_V2:
278 OutputTable.push_back(IITDescriptor::getVector(2, IsScalableVector));
279 DecodeIITType(NextElt, Infos, Info, OutputTable);
280 return;
281 case IIT_V3:
282 OutputTable.push_back(IITDescriptor::getVector(3, IsScalableVector));
283 DecodeIITType(NextElt, Infos, Info, OutputTable);
284 return;
285 case IIT_V4:
286 OutputTable.push_back(IITDescriptor::getVector(4, IsScalableVector));
287 DecodeIITType(NextElt, Infos, Info, OutputTable);
288 return;
289 case IIT_V6:
290 OutputTable.push_back(IITDescriptor::getVector(6, IsScalableVector));
291 DecodeIITType(NextElt, Infos, Info, OutputTable);
292 return;
293 case IIT_V8:
294 OutputTable.push_back(IITDescriptor::getVector(8, IsScalableVector));
295 DecodeIITType(NextElt, Infos, Info, OutputTable);
296 return;
297 case IIT_V10:
298 OutputTable.push_back(IITDescriptor::getVector(10, IsScalableVector));
299 DecodeIITType(NextElt, Infos, Info, OutputTable);
300 return;
301 case IIT_V16:
302 OutputTable.push_back(IITDescriptor::getVector(16, IsScalableVector));
303 DecodeIITType(NextElt, Infos, Info, OutputTable);
304 return;
305 case IIT_V32:
306 OutputTable.push_back(IITDescriptor::getVector(32, IsScalableVector));
307 DecodeIITType(NextElt, Infos, Info, OutputTable);
308 return;
309 case IIT_V64:
310 OutputTable.push_back(IITDescriptor::getVector(64, IsScalableVector));
311 DecodeIITType(NextElt, Infos, Info, OutputTable);
312 return;
313 case IIT_V128:
314 OutputTable.push_back(IITDescriptor::getVector(128, IsScalableVector));
315 DecodeIITType(NextElt, Infos, Info, OutputTable);
316 return;
317 case IIT_V256:
318 OutputTable.push_back(IITDescriptor::getVector(256, IsScalableVector));
319 DecodeIITType(NextElt, Infos, Info, OutputTable);
320 return;
321 case IIT_V512:
322 OutputTable.push_back(IITDescriptor::getVector(512, IsScalableVector));
323 DecodeIITType(NextElt, Infos, Info, OutputTable);
324 return;
325 case IIT_V1024:
326 OutputTable.push_back(IITDescriptor::getVector(1024, IsScalableVector));
327 DecodeIITType(NextElt, Infos, Info, OutputTable);
328 return;
329 case IIT_EXTERNREF:
330 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Pointer, 10));
331 return;
332 case IIT_FUNCREF:
333 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Pointer, 20));
334 return;
335 case IIT_PTR:
336 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Pointer, 0));
337 return;
338 case IIT_ANYPTR: // [ANYPTR addrspace]
339 OutputTable.push_back(
340 IITDescriptor::get(IITDescriptor::Pointer, Infos[NextElt++]));
341 return;
342 case IIT_ARG: {
343 unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
344 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Argument, ArgInfo));
345 return;
347 case IIT_EXTEND_ARG: {
348 unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
349 OutputTable.push_back(
350 IITDescriptor::get(IITDescriptor::ExtendArgument, ArgInfo));
351 return;
353 case IIT_TRUNC_ARG: {
354 unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
355 OutputTable.push_back(
356 IITDescriptor::get(IITDescriptor::TruncArgument, ArgInfo));
357 return;
359 case IIT_HALF_VEC_ARG: {
360 unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
361 OutputTable.push_back(
362 IITDescriptor::get(IITDescriptor::HalfVecArgument, ArgInfo));
363 return;
365 case IIT_SAME_VEC_WIDTH_ARG: {
366 unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
367 OutputTable.push_back(
368 IITDescriptor::get(IITDescriptor::SameVecWidthArgument, ArgInfo));
369 return;
371 case IIT_VEC_OF_ANYPTRS_TO_ELT: {
372 unsigned short ArgNo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
373 unsigned short RefNo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
374 OutputTable.push_back(
375 IITDescriptor::get(IITDescriptor::VecOfAnyPtrsToElt, ArgNo, RefNo));
376 return;
378 case IIT_EMPTYSTRUCT:
379 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Struct, 0));
380 return;
381 case IIT_STRUCT9:
382 ++StructElts;
383 [[fallthrough]];
384 case IIT_STRUCT8:
385 ++StructElts;
386 [[fallthrough]];
387 case IIT_STRUCT7:
388 ++StructElts;
389 [[fallthrough]];
390 case IIT_STRUCT6:
391 ++StructElts;
392 [[fallthrough]];
393 case IIT_STRUCT5:
394 ++StructElts;
395 [[fallthrough]];
396 case IIT_STRUCT4:
397 ++StructElts;
398 [[fallthrough]];
399 case IIT_STRUCT3:
400 ++StructElts;
401 [[fallthrough]];
402 case IIT_STRUCT2: {
403 OutputTable.push_back(
404 IITDescriptor::get(IITDescriptor::Struct, StructElts));
406 for (unsigned i = 0; i != StructElts; ++i)
407 DecodeIITType(NextElt, Infos, Info, OutputTable);
408 return;
410 case IIT_SUBDIVIDE2_ARG: {
411 unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
412 OutputTable.push_back(
413 IITDescriptor::get(IITDescriptor::Subdivide2Argument, ArgInfo));
414 return;
416 case IIT_SUBDIVIDE4_ARG: {
417 unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
418 OutputTable.push_back(
419 IITDescriptor::get(IITDescriptor::Subdivide4Argument, ArgInfo));
420 return;
422 case IIT_VEC_ELEMENT: {
423 unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
424 OutputTable.push_back(
425 IITDescriptor::get(IITDescriptor::VecElementArgument, ArgInfo));
426 return;
428 case IIT_SCALABLE_VEC: {
429 DecodeIITType(NextElt, Infos, Info, OutputTable);
430 return;
432 case IIT_VEC_OF_BITCASTS_TO_INT: {
433 unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
434 OutputTable.push_back(
435 IITDescriptor::get(IITDescriptor::VecOfBitcastsToInt, ArgInfo));
436 return;
439 llvm_unreachable("unhandled");
442 #define GET_INTRINSIC_GENERATOR_GLOBAL
443 #include "llvm/IR/IntrinsicImpl.inc"
444 #undef GET_INTRINSIC_GENERATOR_GLOBAL
446 void Intrinsic::getIntrinsicInfoTableEntries(
447 ID id, SmallVectorImpl<IITDescriptor> &T) {
448 static_assert(sizeof(IIT_Table[0]) == 2,
449 "Expect 16-bit entries in IIT_Table");
450 // Check to see if the intrinsic's type was expressible by the table.
451 uint16_t TableVal = IIT_Table[id - 1];
453 // Decode the TableVal into an array of IITValues.
454 SmallVector<unsigned char> IITValues;
455 ArrayRef<unsigned char> IITEntries;
456 unsigned NextElt = 0;
457 if (TableVal >> 15) {
458 // This is an offset into the IIT_LongEncodingTable.
459 IITEntries = IIT_LongEncodingTable;
461 // Strip sentinel bit.
462 NextElt = TableVal & 0x7fff;
463 } else {
464 // If the entry was encoded into a single word in the table itself, decode
465 // it from an array of nibbles to an array of bytes.
466 do {
467 IITValues.push_back(TableVal & 0xF);
468 TableVal >>= 4;
469 } while (TableVal);
471 IITEntries = IITValues;
472 NextElt = 0;
475 // Okay, decode the table into the output vector of IITDescriptors.
476 DecodeIITType(NextElt, IITEntries, IIT_Done, T);
477 while (NextElt != IITEntries.size() && IITEntries[NextElt] != 0)
478 DecodeIITType(NextElt, IITEntries, IIT_Done, T);
481 static Type *DecodeFixedType(ArrayRef<Intrinsic::IITDescriptor> &Infos,
482 ArrayRef<Type *> Tys, LLVMContext &Context) {
483 using namespace Intrinsic;
485 IITDescriptor D = Infos.front();
486 Infos = Infos.slice(1);
488 switch (D.Kind) {
489 case IITDescriptor::Void:
490 return Type::getVoidTy(Context);
491 case IITDescriptor::VarArg:
492 return Type::getVoidTy(Context);
493 case IITDescriptor::MMX:
494 return llvm::FixedVectorType::get(llvm::IntegerType::get(Context, 64), 1);
495 case IITDescriptor::AMX:
496 return Type::getX86_AMXTy(Context);
497 case IITDescriptor::Token:
498 return Type::getTokenTy(Context);
499 case IITDescriptor::Metadata:
500 return Type::getMetadataTy(Context);
501 case IITDescriptor::Half:
502 return Type::getHalfTy(Context);
503 case IITDescriptor::BFloat:
504 return Type::getBFloatTy(Context);
505 case IITDescriptor::Float:
506 return Type::getFloatTy(Context);
507 case IITDescriptor::Double:
508 return Type::getDoubleTy(Context);
509 case IITDescriptor::Quad:
510 return Type::getFP128Ty(Context);
511 case IITDescriptor::PPCQuad:
512 return Type::getPPC_FP128Ty(Context);
513 case IITDescriptor::AArch64Svcount:
514 return TargetExtType::get(Context, "aarch64.svcount");
516 case IITDescriptor::Integer:
517 return IntegerType::get(Context, D.Integer_Width);
518 case IITDescriptor::Vector:
519 return VectorType::get(DecodeFixedType(Infos, Tys, Context),
520 D.Vector_Width);
521 case IITDescriptor::Pointer:
522 return PointerType::get(Context, D.Pointer_AddressSpace);
523 case IITDescriptor::Struct: {
524 SmallVector<Type *, 8> Elts;
525 for (unsigned i = 0, e = D.Struct_NumElements; i != e; ++i)
526 Elts.push_back(DecodeFixedType(Infos, Tys, Context));
527 return StructType::get(Context, Elts);
529 case IITDescriptor::Argument:
530 return Tys[D.getArgumentNumber()];
531 case IITDescriptor::ExtendArgument: {
532 Type *Ty = Tys[D.getArgumentNumber()];
533 if (VectorType *VTy = dyn_cast<VectorType>(Ty))
534 return VectorType::getExtendedElementVectorType(VTy);
536 return IntegerType::get(Context, 2 * cast<IntegerType>(Ty)->getBitWidth());
538 case IITDescriptor::TruncArgument: {
539 Type *Ty = Tys[D.getArgumentNumber()];
540 if (VectorType *VTy = dyn_cast<VectorType>(Ty))
541 return VectorType::getTruncatedElementVectorType(VTy);
543 IntegerType *ITy = cast<IntegerType>(Ty);
544 assert(ITy->getBitWidth() % 2 == 0);
545 return IntegerType::get(Context, ITy->getBitWidth() / 2);
547 case IITDescriptor::Subdivide2Argument:
548 case IITDescriptor::Subdivide4Argument: {
549 Type *Ty = Tys[D.getArgumentNumber()];
550 VectorType *VTy = dyn_cast<VectorType>(Ty);
551 assert(VTy && "Expected an argument of Vector Type");
552 int SubDivs = D.Kind == IITDescriptor::Subdivide2Argument ? 1 : 2;
553 return VectorType::getSubdividedVectorType(VTy, SubDivs);
555 case IITDescriptor::HalfVecArgument:
556 return VectorType::getHalfElementsVectorType(
557 cast<VectorType>(Tys[D.getArgumentNumber()]));
558 case IITDescriptor::SameVecWidthArgument: {
559 Type *EltTy = DecodeFixedType(Infos, Tys, Context);
560 Type *Ty = Tys[D.getArgumentNumber()];
561 if (auto *VTy = dyn_cast<VectorType>(Ty))
562 return VectorType::get(EltTy, VTy->getElementCount());
563 return EltTy;
565 case IITDescriptor::VecElementArgument: {
566 Type *Ty = Tys[D.getArgumentNumber()];
567 if (VectorType *VTy = dyn_cast<VectorType>(Ty))
568 return VTy->getElementType();
569 llvm_unreachable("Expected an argument of Vector Type");
571 case IITDescriptor::VecOfBitcastsToInt: {
572 Type *Ty = Tys[D.getArgumentNumber()];
573 VectorType *VTy = dyn_cast<VectorType>(Ty);
574 assert(VTy && "Expected an argument of Vector Type");
575 return VectorType::getInteger(VTy);
577 case IITDescriptor::VecOfAnyPtrsToElt:
578 // Return the overloaded type (which determines the pointers address space)
579 return Tys[D.getOverloadArgNumber()];
581 llvm_unreachable("unhandled");
584 FunctionType *Intrinsic::getType(LLVMContext &Context, ID id,
585 ArrayRef<Type *> Tys) {
586 SmallVector<IITDescriptor, 8> Table;
587 getIntrinsicInfoTableEntries(id, Table);
589 ArrayRef<IITDescriptor> TableRef = Table;
590 Type *ResultTy = DecodeFixedType(TableRef, Tys, Context);
592 SmallVector<Type *, 8> ArgTys;
593 while (!TableRef.empty())
594 ArgTys.push_back(DecodeFixedType(TableRef, Tys, Context));
596 // DecodeFixedType returns Void for IITDescriptor::Void and
597 // IITDescriptor::VarArg If we see void type as the type of the last argument,
598 // it is vararg intrinsic
599 if (!ArgTys.empty() && ArgTys.back()->isVoidTy()) {
600 ArgTys.pop_back();
601 return FunctionType::get(ResultTy, ArgTys, true);
603 return FunctionType::get(ResultTy, ArgTys, false);
606 bool Intrinsic::isOverloaded(ID id) {
607 #define GET_INTRINSIC_OVERLOAD_TABLE
608 #include "llvm/IR/IntrinsicImpl.inc"
609 #undef GET_INTRINSIC_OVERLOAD_TABLE
612 /// Table of per-target intrinsic name tables.
613 #define GET_INTRINSIC_TARGET_DATA
614 #include "llvm/IR/IntrinsicImpl.inc"
615 #undef GET_INTRINSIC_TARGET_DATA
617 bool Intrinsic::isTargetIntrinsic(Intrinsic::ID IID) {
618 return IID > TargetInfos[0].Count;
621 /// Looks up Name in NameTable via binary search. NameTable must be sorted
622 /// and all entries must start with "llvm.". If NameTable contains an exact
623 /// match for Name or a prefix of Name followed by a dot, its index in
624 /// NameTable is returned. Otherwise, -1 is returned.
625 static int lookupLLVMIntrinsicByName(ArrayRef<unsigned> NameOffsetTable,
626 StringRef Name, StringRef Target = "") {
627 assert(Name.starts_with("llvm.") && "Unexpected intrinsic prefix");
628 assert(Name.drop_front(5).starts_with(Target) && "Unexpected target");
630 // Do successive binary searches of the dotted name components. For
631 // "llvm.gc.experimental.statepoint.p1i8.p1i32", we will find the range of
632 // intrinsics starting with "llvm.gc", then "llvm.gc.experimental", then
633 // "llvm.gc.experimental.statepoint", and then we will stop as the range is
634 // size 1. During the search, we can skip the prefix that we already know is
635 // identical. By using strncmp we consider names with differing suffixes to
636 // be part of the equal range.
637 size_t CmpEnd = 4; // Skip the "llvm" component.
638 if (!Target.empty())
639 CmpEnd += 1 + Target.size(); // skip the .target component.
641 const unsigned *Low = NameOffsetTable.begin();
642 const unsigned *High = NameOffsetTable.end();
643 const unsigned *LastLow = Low;
644 while (CmpEnd < Name.size() && High - Low > 0) {
645 size_t CmpStart = CmpEnd;
646 CmpEnd = Name.find('.', CmpStart + 1);
647 CmpEnd = CmpEnd == StringRef::npos ? Name.size() : CmpEnd;
648 auto Cmp = [CmpStart, CmpEnd](auto LHS, auto RHS) {
649 // `equal_range` requires the comparison to work with either side being an
650 // offset or the value. Detect which kind each side is to set up the
651 // compared strings.
652 const char *LHSStr;
653 if constexpr (std::is_integral_v<decltype(LHS)>) {
654 LHSStr = &IntrinsicNameTable[LHS];
655 } else {
656 LHSStr = LHS;
658 const char *RHSStr;
659 if constexpr (std::is_integral_v<decltype(RHS)>) {
660 RHSStr = &IntrinsicNameTable[RHS];
661 } else {
662 RHSStr = RHS;
664 return strncmp(LHSStr + CmpStart, RHSStr + CmpStart, CmpEnd - CmpStart) <
667 LastLow = Low;
668 std::tie(Low, High) = std::equal_range(Low, High, Name.data(), Cmp);
670 if (High - Low > 0)
671 LastLow = Low;
673 if (LastLow == NameOffsetTable.end())
674 return -1;
675 StringRef NameFound = &IntrinsicNameTable[*LastLow];
676 if (Name == NameFound ||
677 (Name.starts_with(NameFound) && Name[NameFound.size()] == '.'))
678 return LastLow - NameOffsetTable.begin();
679 return -1;
682 /// Find the segment of \c IntrinsicNameOffsetTable for intrinsics with the same
683 /// target as \c Name, or the generic table if \c Name is not target specific.
685 /// Returns the relevant slice of \c IntrinsicNameOffsetTable and the target
686 /// name.
687 static std::pair<ArrayRef<unsigned>, StringRef>
688 findTargetSubtable(StringRef Name) {
689 assert(Name.starts_with("llvm."));
691 ArrayRef<IntrinsicTargetInfo> Targets(TargetInfos);
692 // Drop "llvm." and take the first dotted component. That will be the target
693 // if this is target specific.
694 StringRef Target = Name.drop_front(5).split('.').first;
695 auto It = partition_point(
696 Targets, [=](const IntrinsicTargetInfo &TI) { return TI.Name < Target; });
697 // We've either found the target or just fall back to the generic set, which
698 // is always first.
699 const auto &TI = It != Targets.end() && It->Name == Target ? *It : Targets[0];
700 return {ArrayRef(&IntrinsicNameOffsetTable[1] + TI.Offset, TI.Count),
701 TI.Name};
704 /// This does the actual lookup of an intrinsic ID which matches the given
705 /// function name.
706 Intrinsic::ID Intrinsic::lookupIntrinsicID(StringRef Name) {
707 auto [NameOffsetTable, Target] = findTargetSubtable(Name);
708 int Idx = lookupLLVMIntrinsicByName(NameOffsetTable, Name, Target);
709 if (Idx == -1)
710 return Intrinsic::not_intrinsic;
712 // Intrinsic IDs correspond to the location in IntrinsicNameTable, but we have
713 // an index into a sub-table.
714 int Adjust = NameOffsetTable.data() - IntrinsicNameOffsetTable;
715 Intrinsic::ID ID = static_cast<Intrinsic::ID>(Idx + Adjust);
717 // If the intrinsic is not overloaded, require an exact match. If it is
718 // overloaded, require either exact or prefix match.
719 const auto MatchSize = strlen(&IntrinsicNameTable[NameOffsetTable[Idx]]);
720 assert(Name.size() >= MatchSize && "Expected either exact or prefix match");
721 bool IsExactMatch = Name.size() == MatchSize;
722 return IsExactMatch || Intrinsic::isOverloaded(ID) ? ID
723 : Intrinsic::not_intrinsic;
726 /// This defines the "Intrinsic::getAttributes(ID id)" method.
727 #define GET_INTRINSIC_ATTRIBUTES
728 #include "llvm/IR/IntrinsicImpl.inc"
729 #undef GET_INTRINSIC_ATTRIBUTES
731 Function *Intrinsic::getOrInsertDeclaration(Module *M, ID id,
732 ArrayRef<Type *> Tys) {
733 // There can never be multiple globals with the same name of different types,
734 // because intrinsics must be a specific type.
735 auto *FT = getType(M->getContext(), id, Tys);
736 return cast<Function>(
737 M->getOrInsertFunction(
738 Tys.empty() ? getName(id) : getName(id, Tys, M, FT), FT)
739 .getCallee());
742 Function *Intrinsic::getDeclarationIfExists(const Module *M, ID id) {
743 return M->getFunction(getName(id));
746 Function *Intrinsic::getDeclarationIfExists(Module *M, ID id,
747 ArrayRef<Type *> Tys,
748 FunctionType *FT) {
749 return M->getFunction(getName(id, Tys, M, FT));
752 // This defines the "Intrinsic::getIntrinsicForClangBuiltin()" method.
753 #define GET_LLVM_INTRINSIC_FOR_CLANG_BUILTIN
754 #include "llvm/IR/IntrinsicImpl.inc"
755 #undef GET_LLVM_INTRINSIC_FOR_CLANG_BUILTIN
757 // This defines the "Intrinsic::getIntrinsicForMSBuiltin()" method.
758 #define GET_LLVM_INTRINSIC_FOR_MS_BUILTIN
759 #include "llvm/IR/IntrinsicImpl.inc"
760 #undef GET_LLVM_INTRINSIC_FOR_MS_BUILTIN
762 bool Intrinsic::isConstrainedFPIntrinsic(ID QID) {
763 switch (QID) {
764 #define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC) \
765 case Intrinsic::INTRINSIC:
766 #include "llvm/IR/ConstrainedOps.def"
767 #undef INSTRUCTION
768 return true;
769 default:
770 return false;
774 bool Intrinsic::hasConstrainedFPRoundingModeOperand(Intrinsic::ID QID) {
775 switch (QID) {
776 #define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC) \
777 case Intrinsic::INTRINSIC: \
778 return ROUND_MODE == 1;
779 #include "llvm/IR/ConstrainedOps.def"
780 #undef INSTRUCTION
781 default:
782 return false;
786 using DeferredIntrinsicMatchPair =
787 std::pair<Type *, ArrayRef<Intrinsic::IITDescriptor>>;
789 static bool
790 matchIntrinsicType(Type *Ty, ArrayRef<Intrinsic::IITDescriptor> &Infos,
791 SmallVectorImpl<Type *> &ArgTys,
792 SmallVectorImpl<DeferredIntrinsicMatchPair> &DeferredChecks,
793 bool IsDeferredCheck) {
794 using namespace Intrinsic;
796 // If we ran out of descriptors, there are too many arguments.
797 if (Infos.empty())
798 return true;
800 // Do this before slicing off the 'front' part
801 auto InfosRef = Infos;
802 auto DeferCheck = [&DeferredChecks, &InfosRef](Type *T) {
803 DeferredChecks.emplace_back(T, InfosRef);
804 return false;
807 IITDescriptor D = Infos.front();
808 Infos = Infos.slice(1);
810 switch (D.Kind) {
811 case IITDescriptor::Void:
812 return !Ty->isVoidTy();
813 case IITDescriptor::VarArg:
814 return true;
815 case IITDescriptor::MMX: {
816 FixedVectorType *VT = dyn_cast<FixedVectorType>(Ty);
817 return !VT || VT->getNumElements() != 1 ||
818 !VT->getElementType()->isIntegerTy(64);
820 case IITDescriptor::AMX:
821 return !Ty->isX86_AMXTy();
822 case IITDescriptor::Token:
823 return !Ty->isTokenTy();
824 case IITDescriptor::Metadata:
825 return !Ty->isMetadataTy();
826 case IITDescriptor::Half:
827 return !Ty->isHalfTy();
828 case IITDescriptor::BFloat:
829 return !Ty->isBFloatTy();
830 case IITDescriptor::Float:
831 return !Ty->isFloatTy();
832 case IITDescriptor::Double:
833 return !Ty->isDoubleTy();
834 case IITDescriptor::Quad:
835 return !Ty->isFP128Ty();
836 case IITDescriptor::PPCQuad:
837 return !Ty->isPPC_FP128Ty();
838 case IITDescriptor::Integer:
839 return !Ty->isIntegerTy(D.Integer_Width);
840 case IITDescriptor::AArch64Svcount:
841 return !isa<TargetExtType>(Ty) ||
842 cast<TargetExtType>(Ty)->getName() != "aarch64.svcount";
843 case IITDescriptor::Vector: {
844 VectorType *VT = dyn_cast<VectorType>(Ty);
845 return !VT || VT->getElementCount() != D.Vector_Width ||
846 matchIntrinsicType(VT->getElementType(), Infos, ArgTys,
847 DeferredChecks, IsDeferredCheck);
849 case IITDescriptor::Pointer: {
850 PointerType *PT = dyn_cast<PointerType>(Ty);
851 return !PT || PT->getAddressSpace() != D.Pointer_AddressSpace;
854 case IITDescriptor::Struct: {
855 StructType *ST = dyn_cast<StructType>(Ty);
856 if (!ST || !ST->isLiteral() || ST->isPacked() ||
857 ST->getNumElements() != D.Struct_NumElements)
858 return true;
860 for (unsigned i = 0, e = D.Struct_NumElements; i != e; ++i)
861 if (matchIntrinsicType(ST->getElementType(i), Infos, ArgTys,
862 DeferredChecks, IsDeferredCheck))
863 return true;
864 return false;
867 case IITDescriptor::Argument:
868 // If this is the second occurrence of an argument,
869 // verify that the later instance matches the previous instance.
870 if (D.getArgumentNumber() < ArgTys.size())
871 return Ty != ArgTys[D.getArgumentNumber()];
873 if (D.getArgumentNumber() > ArgTys.size() ||
874 D.getArgumentKind() == IITDescriptor::AK_MatchType)
875 return IsDeferredCheck || DeferCheck(Ty);
877 assert(D.getArgumentNumber() == ArgTys.size() && !IsDeferredCheck &&
878 "Table consistency error");
879 ArgTys.push_back(Ty);
881 switch (D.getArgumentKind()) {
882 case IITDescriptor::AK_Any:
883 return false; // Success
884 case IITDescriptor::AK_AnyInteger:
885 return !Ty->isIntOrIntVectorTy();
886 case IITDescriptor::AK_AnyFloat:
887 return !Ty->isFPOrFPVectorTy();
888 case IITDescriptor::AK_AnyVector:
889 return !isa<VectorType>(Ty);
890 case IITDescriptor::AK_AnyPointer:
891 return !isa<PointerType>(Ty);
892 default:
893 break;
895 llvm_unreachable("all argument kinds not covered");
897 case IITDescriptor::ExtendArgument: {
898 // If this is a forward reference, defer the check for later.
899 if (D.getArgumentNumber() >= ArgTys.size())
900 return IsDeferredCheck || DeferCheck(Ty);
902 Type *NewTy = ArgTys[D.getArgumentNumber()];
903 if (VectorType *VTy = dyn_cast<VectorType>(NewTy))
904 NewTy = VectorType::getExtendedElementVectorType(VTy);
905 else if (IntegerType *ITy = dyn_cast<IntegerType>(NewTy))
906 NewTy = IntegerType::get(ITy->getContext(), 2 * ITy->getBitWidth());
907 else
908 return true;
910 return Ty != NewTy;
912 case IITDescriptor::TruncArgument: {
913 // If this is a forward reference, defer the check for later.
914 if (D.getArgumentNumber() >= ArgTys.size())
915 return IsDeferredCheck || DeferCheck(Ty);
917 Type *NewTy = ArgTys[D.getArgumentNumber()];
918 if (VectorType *VTy = dyn_cast<VectorType>(NewTy))
919 NewTy = VectorType::getTruncatedElementVectorType(VTy);
920 else if (IntegerType *ITy = dyn_cast<IntegerType>(NewTy))
921 NewTy = IntegerType::get(ITy->getContext(), ITy->getBitWidth() / 2);
922 else
923 return true;
925 return Ty != NewTy;
927 case IITDescriptor::HalfVecArgument:
928 // If this is a forward reference, defer the check for later.
929 if (D.getArgumentNumber() >= ArgTys.size())
930 return IsDeferredCheck || DeferCheck(Ty);
931 return !isa<VectorType>(ArgTys[D.getArgumentNumber()]) ||
932 VectorType::getHalfElementsVectorType(
933 cast<VectorType>(ArgTys[D.getArgumentNumber()])) != Ty;
934 case IITDescriptor::SameVecWidthArgument: {
935 if (D.getArgumentNumber() >= ArgTys.size()) {
936 // Defer check and subsequent check for the vector element type.
937 Infos = Infos.slice(1);
938 return IsDeferredCheck || DeferCheck(Ty);
940 auto *ReferenceType = dyn_cast<VectorType>(ArgTys[D.getArgumentNumber()]);
941 auto *ThisArgType = dyn_cast<VectorType>(Ty);
942 // Both must be vectors of the same number of elements or neither.
943 if ((ReferenceType != nullptr) != (ThisArgType != nullptr))
944 return true;
945 Type *EltTy = Ty;
946 if (ThisArgType) {
947 if (ReferenceType->getElementCount() != ThisArgType->getElementCount())
948 return true;
949 EltTy = ThisArgType->getElementType();
951 return matchIntrinsicType(EltTy, Infos, ArgTys, DeferredChecks,
952 IsDeferredCheck);
954 case IITDescriptor::VecOfAnyPtrsToElt: {
955 unsigned RefArgNumber = D.getRefArgNumber();
956 if (RefArgNumber >= ArgTys.size()) {
957 if (IsDeferredCheck)
958 return true;
959 // If forward referencing, already add the pointer-vector type and
960 // defer the checks for later.
961 ArgTys.push_back(Ty);
962 return DeferCheck(Ty);
965 if (!IsDeferredCheck) {
966 assert(D.getOverloadArgNumber() == ArgTys.size() &&
967 "Table consistency error");
968 ArgTys.push_back(Ty);
971 // Verify the overloaded type "matches" the Ref type.
972 // i.e. Ty is a vector with the same width as Ref.
973 // Composed of pointers to the same element type as Ref.
974 auto *ReferenceType = dyn_cast<VectorType>(ArgTys[RefArgNumber]);
975 auto *ThisArgVecTy = dyn_cast<VectorType>(Ty);
976 if (!ThisArgVecTy || !ReferenceType ||
977 (ReferenceType->getElementCount() != ThisArgVecTy->getElementCount()))
978 return true;
979 return !ThisArgVecTy->getElementType()->isPointerTy();
981 case IITDescriptor::VecElementArgument: {
982 if (D.getArgumentNumber() >= ArgTys.size())
983 return IsDeferredCheck ? true : DeferCheck(Ty);
984 auto *ReferenceType = dyn_cast<VectorType>(ArgTys[D.getArgumentNumber()]);
985 return !ReferenceType || Ty != ReferenceType->getElementType();
987 case IITDescriptor::Subdivide2Argument:
988 case IITDescriptor::Subdivide4Argument: {
989 // If this is a forward reference, defer the check for later.
990 if (D.getArgumentNumber() >= ArgTys.size())
991 return IsDeferredCheck || DeferCheck(Ty);
993 Type *NewTy = ArgTys[D.getArgumentNumber()];
994 if (auto *VTy = dyn_cast<VectorType>(NewTy)) {
995 int SubDivs = D.Kind == IITDescriptor::Subdivide2Argument ? 1 : 2;
996 NewTy = VectorType::getSubdividedVectorType(VTy, SubDivs);
997 return Ty != NewTy;
999 return true;
1001 case IITDescriptor::VecOfBitcastsToInt: {
1002 if (D.getArgumentNumber() >= ArgTys.size())
1003 return IsDeferredCheck || DeferCheck(Ty);
1004 auto *ReferenceType = dyn_cast<VectorType>(ArgTys[D.getArgumentNumber()]);
1005 auto *ThisArgVecTy = dyn_cast<VectorType>(Ty);
1006 if (!ThisArgVecTy || !ReferenceType)
1007 return true;
1008 return ThisArgVecTy != VectorType::getInteger(ReferenceType);
1011 llvm_unreachable("unhandled");
1014 Intrinsic::MatchIntrinsicTypesResult
1015 Intrinsic::matchIntrinsicSignature(FunctionType *FTy,
1016 ArrayRef<Intrinsic::IITDescriptor> &Infos,
1017 SmallVectorImpl<Type *> &ArgTys) {
1018 SmallVector<DeferredIntrinsicMatchPair, 2> DeferredChecks;
1019 if (matchIntrinsicType(FTy->getReturnType(), Infos, ArgTys, DeferredChecks,
1020 false))
1021 return MatchIntrinsicTypes_NoMatchRet;
1023 unsigned NumDeferredReturnChecks = DeferredChecks.size();
1025 for (auto *Ty : FTy->params())
1026 if (matchIntrinsicType(Ty, Infos, ArgTys, DeferredChecks, false))
1027 return MatchIntrinsicTypes_NoMatchArg;
1029 for (unsigned I = 0, E = DeferredChecks.size(); I != E; ++I) {
1030 DeferredIntrinsicMatchPair &Check = DeferredChecks[I];
1031 if (matchIntrinsicType(Check.first, Check.second, ArgTys, DeferredChecks,
1032 true))
1033 return I < NumDeferredReturnChecks ? MatchIntrinsicTypes_NoMatchRet
1034 : MatchIntrinsicTypes_NoMatchArg;
1037 return MatchIntrinsicTypes_Match;
1040 bool Intrinsic::matchIntrinsicVarArg(
1041 bool isVarArg, ArrayRef<Intrinsic::IITDescriptor> &Infos) {
1042 // If there are no descriptors left, then it can't be a vararg.
1043 if (Infos.empty())
1044 return isVarArg;
1046 // There should be only one descriptor remaining at this point.
1047 if (Infos.size() != 1)
1048 return true;
1050 // Check and verify the descriptor.
1051 IITDescriptor D = Infos.front();
1052 Infos = Infos.slice(1);
1053 if (D.Kind == IITDescriptor::VarArg)
1054 return !isVarArg;
1056 return true;
1059 bool Intrinsic::getIntrinsicSignature(Intrinsic::ID ID, FunctionType *FT,
1060 SmallVectorImpl<Type *> &ArgTys) {
1061 if (!ID)
1062 return false;
1064 SmallVector<Intrinsic::IITDescriptor, 8> Table;
1065 getIntrinsicInfoTableEntries(ID, Table);
1066 ArrayRef<Intrinsic::IITDescriptor> TableRef = Table;
1068 if (Intrinsic::matchIntrinsicSignature(FT, TableRef, ArgTys) !=
1069 Intrinsic::MatchIntrinsicTypesResult::MatchIntrinsicTypes_Match) {
1070 return false;
1072 if (Intrinsic::matchIntrinsicVarArg(FT->isVarArg(), TableRef))
1073 return false;
1074 return true;
1077 bool Intrinsic::getIntrinsicSignature(Function *F,
1078 SmallVectorImpl<Type *> &ArgTys) {
1079 return getIntrinsicSignature(F->getIntrinsicID(), F->getFunctionType(),
1080 ArgTys);
1083 std::optional<Function *> Intrinsic::remangleIntrinsicFunction(Function *F) {
1084 SmallVector<Type *, 4> ArgTys;
1085 if (!getIntrinsicSignature(F, ArgTys))
1086 return std::nullopt;
1088 Intrinsic::ID ID = F->getIntrinsicID();
1089 StringRef Name = F->getName();
1090 std::string WantedName =
1091 Intrinsic::getName(ID, ArgTys, F->getParent(), F->getFunctionType());
1092 if (Name == WantedName)
1093 return std::nullopt;
1095 Function *NewDecl = [&] {
1096 if (auto *ExistingGV = F->getParent()->getNamedValue(WantedName)) {
1097 if (auto *ExistingF = dyn_cast<Function>(ExistingGV))
1098 if (ExistingF->getFunctionType() == F->getFunctionType())
1099 return ExistingF;
1101 // The name already exists, but is not a function or has the wrong
1102 // prototype. Make place for the new one by renaming the old version.
1103 // Either this old version will be removed later on or the module is
1104 // invalid and we'll get an error.
1105 ExistingGV->setName(WantedName + ".renamed");
1107 return Intrinsic::getOrInsertDeclaration(F->getParent(), ID, ArgTys);
1108 }();
1110 NewDecl->setCallingConv(F->getCallingConv());
1111 assert(NewDecl->getFunctionType() == F->getFunctionType() &&
1112 "Shouldn't change the signature");
1113 return NewDecl;