LLVM  8.0.1
Core.cpp
Go to the documentation of this file.
1 //===-- Core.cpp ----------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the common infrastructure (including the C bindings)
11 // for libLLVMCore.a, which implements the LLVM intermediate representation.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "llvm-c/Core.h"
16 #include "llvm/ADT/StringSwitch.h"
17 #include "llvm/IR/Attributes.h"
18 #include "llvm/IR/Constants.h"
20 #include "llvm/IR/DerivedTypes.h"
21 #include "llvm/IR/DiagnosticInfo.h"
23 #include "llvm/IR/GlobalAlias.h"
24 #include "llvm/IR/GlobalVariable.h"
25 #include "llvm/IR/IRBuilder.h"
26 #include "llvm/IR/InlineAsm.h"
27 #include "llvm/IR/IntrinsicInst.h"
28 #include "llvm/IR/LLVMContext.h"
30 #include "llvm/IR/Module.h"
31 #include "llvm/Support/Debug.h"
36 #include "llvm/Support/Threading.h"
38 #include <cassert>
39 #include <cstdlib>
40 #include <cstring>
41 #include <system_error>
42 
43 using namespace llvm;
44 
45 #define DEBUG_TYPE "ir"
46 
54 }
55 
58 }
59 
60 void LLVMShutdown() {
61  llvm_shutdown();
62 }
63 
64 /*===-- Error handling ----------------------------------------------------===*/
65 
66 char *LLVMCreateMessage(const char *Message) {
67  return strdup(Message);
68 }
69 
70 void LLVMDisposeMessage(char *Message) {
71  free(Message);
72 }
73 
74 
75 /*===-- Operations on contexts --------------------------------------------===*/
76 
78 
80  return wrap(new LLVMContext());
81 }
82 
83 LLVMContextRef LLVMGetGlobalContext() { return wrap(&*GlobalContext); }
84 
86  LLVMDiagnosticHandler Handler,
87  void *DiagnosticContext) {
88  unwrap(C)->setDiagnosticHandlerCallBack(
89  LLVM_EXTENSION reinterpret_cast<DiagnosticHandler::DiagnosticHandlerTy>(
90  Handler),
91  DiagnosticContext);
92 }
93 
95  return LLVM_EXTENSION reinterpret_cast<LLVMDiagnosticHandler>(
96  unwrap(C)->getDiagnosticHandlerCallBack());
97 }
98 
100  return unwrap(C)->getDiagnosticContext();
101 }
102 
104  void *OpaqueHandle) {
105  auto YieldCallback =
106  LLVM_EXTENSION reinterpret_cast<LLVMContext::YieldCallbackTy>(Callback);
107  unwrap(C)->setYieldCallback(YieldCallback, OpaqueHandle);
108 }
109 
111  return unwrap(C)->shouldDiscardValueNames();
112 }
113 
115  unwrap(C)->setDiscardValueNames(Discard);
116 }
117 
119  delete unwrap(C);
120 }
121 
123  unsigned SLen) {
124  return unwrap(C)->getMDKindID(StringRef(Name, SLen));
125 }
126 
127 unsigned LLVMGetMDKindID(const char *Name, unsigned SLen) {
128  return LLVMGetMDKindIDInContext(LLVMGetGlobalContext(), Name, SLen);
129 }
130 
131 #define GET_ATTR_KIND_FROM_NAME
132 #include "AttributesCompatFunc.inc"
133 
134 unsigned LLVMGetEnumAttributeKindForName(const char *Name, size_t SLen) {
135  return getAttrKindFromName(StringRef(Name, SLen));
136 }
137 
139  return Attribute::AttrKind::EndAttrKinds;
140 }
141 
143  uint64_t Val) {
144  return wrap(Attribute::get(*unwrap(C), (Attribute::AttrKind)KindID, Val));
145 }
146 
148  return unwrap(A).getKindAsEnum();
149 }
150 
152  auto Attr = unwrap(A);
153  if (Attr.isEnumAttribute())
154  return 0;
155  return Attr.getValueAsInt();
156 }
157 
159  const char *K, unsigned KLength,
160  const char *V, unsigned VLength) {
161  return wrap(Attribute::get(*unwrap(C), StringRef(K, KLength),
162  StringRef(V, VLength)));
163 }
164 
166  unsigned *Length) {
167  auto S = unwrap(A).getKindAsString();
168  *Length = S.size();
169  return S.data();
170 }
171 
173  unsigned *Length) {
174  auto S = unwrap(A).getValueAsString();
175  *Length = S.size();
176  return S.data();
177 }
178 
180  auto Attr = unwrap(A);
181  return Attr.isEnumAttribute() || Attr.isIntAttribute();
182 }
183 
185  return unwrap(A).isStringAttribute();
186 }
187 
189  std::string MsgStorage;
190  raw_string_ostream Stream(MsgStorage);
191  DiagnosticPrinterRawOStream DP(Stream);
192 
193  unwrap(DI)->print(DP);
194  Stream.flush();
195 
196  return LLVMCreateMessage(MsgStorage.c_str());
197 }
198 
200  LLVMDiagnosticSeverity severity;
201 
202  switch(unwrap(DI)->getSeverity()) {
203  default:
204  severity = LLVMDSError;
205  break;
206  case DS_Warning:
207  severity = LLVMDSWarning;
208  break;
209  case DS_Remark:
210  severity = LLVMDSRemark;
211  break;
212  case DS_Note:
213  severity = LLVMDSNote;
214  break;
215  }
216 
217  return severity;
218 }
219 
220 /*===-- Operations on modules ---------------------------------------------===*/
221 
223  return wrap(new Module(ModuleID, *GlobalContext));
224 }
225 
227  LLVMContextRef C) {
228  return wrap(new Module(ModuleID, *unwrap(C)));
229 }
230 
232  delete unwrap(M);
233 }
234 
235 const char *LLVMGetModuleIdentifier(LLVMModuleRef M, size_t *Len) {
236  auto &Str = unwrap(M)->getModuleIdentifier();
237  *Len = Str.length();
238  return Str.c_str();
239 }
240 
241 void LLVMSetModuleIdentifier(LLVMModuleRef M, const char *Ident, size_t Len) {
242  unwrap(M)->setModuleIdentifier(StringRef(Ident, Len));
243 }
244 
245 const char *LLVMGetSourceFileName(LLVMModuleRef M, size_t *Len) {
246  auto &Str = unwrap(M)->getSourceFileName();
247  *Len = Str.length();
248  return Str.c_str();
249 }
250 
251 void LLVMSetSourceFileName(LLVMModuleRef M, const char *Name, size_t Len) {
252  unwrap(M)->setSourceFileName(StringRef(Name, Len));
253 }
254 
255 /*--.. Data layout .........................................................--*/
257  return unwrap(M)->getDataLayoutStr().c_str();
258 }
259 
261  return LLVMGetDataLayoutStr(M);
262 }
263 
264 void LLVMSetDataLayout(LLVMModuleRef M, const char *DataLayoutStr) {
265  unwrap(M)->setDataLayout(DataLayoutStr);
266 }
267 
268 /*--.. Target triple .......................................................--*/
269 const char * LLVMGetTarget(LLVMModuleRef M) {
270  return unwrap(M)->getTargetTriple().c_str();
271 }
272 
273 void LLVMSetTarget(LLVMModuleRef M, const char *Triple) {
274  unwrap(M)->setTargetTriple(Triple);
275 }
276 
277 /*--.. Module flags ........................................................--*/
280  const char *Key;
281  size_t KeyLen;
283 };
284 
287  switch (Behavior) {
291  return Module::ModFlagBehavior::Warning;
293  return Module::ModFlagBehavior::Require;
295  return Module::ModFlagBehavior::Override;
297  return Module::ModFlagBehavior::Append;
299  return Module::ModFlagBehavior::AppendUnique;
300  }
301  llvm_unreachable("Unknown LLVMModuleFlagBehavior");
302 }
303 
306  switch (Behavior) {
309  case Module::ModFlagBehavior::Warning:
311  case Module::ModFlagBehavior::Require:
313  case Module::ModFlagBehavior::Override:
315  case Module::ModFlagBehavior::Append:
317  case Module::ModFlagBehavior::AppendUnique:
319  default:
320  llvm_unreachable("Unhandled Flag Behavior");
321  }
322 }
323 
326  unwrap(M)->getModuleFlagsMetadata(MFEs);
327 
328  LLVMOpaqueModuleFlagEntry *Result = static_cast<LLVMOpaqueModuleFlagEntry *>(
329  safe_malloc(MFEs.size() * sizeof(LLVMOpaqueModuleFlagEntry)));
330  for (unsigned i = 0; i < MFEs.size(); ++i) {
331  const auto &ModuleFlag = MFEs[i];
332  Result[i].Behavior = map_from_llvmModFlagBehavior(ModuleFlag.Behavior);
333  Result[i].Key = ModuleFlag.Key->getString().data();
334  Result[i].KeyLen = ModuleFlag.Key->getString().size();
335  Result[i].Metadata = wrap(ModuleFlag.Val);
336  }
337  *Len = MFEs.size();
338  return Result;
339 }
340 
342  free(Entries);
343 }
344 
347  unsigned Index) {
349  static_cast<LLVMOpaqueModuleFlagEntry>(Entries[Index]);
350  return MFE.Behavior;
351 }
352 
354  unsigned Index, size_t *Len) {
356  static_cast<LLVMOpaqueModuleFlagEntry>(Entries[Index]);
357  *Len = MFE.KeyLen;
358  return MFE.Key;
359 }
360 
362  unsigned Index) {
364  static_cast<LLVMOpaqueModuleFlagEntry>(Entries[Index]);
365  return MFE.Metadata;
366 }
367 
369  const char *Key, size_t KeyLen) {
370  return wrap(unwrap(M)->getModuleFlag({Key, KeyLen}));
371 }
372 
374  const char *Key, size_t KeyLen,
375  LLVMMetadataRef Val) {
376  unwrap(M)->addModuleFlag(map_to_llvmModFlagBehavior(Behavior),
377  {Key, KeyLen}, unwrap(Val));
378 }
379 
380 /*--.. Printing modules ....................................................--*/
381 
383  unwrap(M)->print(errs(), nullptr,
384  /*ShouldPreserveUseListOrder=*/false, /*IsForDebug=*/true);
385 }
386 
388  char **ErrorMessage) {
389  std::error_code EC;
390  raw_fd_ostream dest(Filename, EC, sys::fs::F_Text);
391  if (EC) {
392  *ErrorMessage = strdup(EC.message().c_str());
393  return true;
394  }
395 
396  unwrap(M)->print(dest, nullptr);
397 
398  dest.close();
399 
400  if (dest.has_error()) {
401  std::string E = "Error printing to file: " + dest.error().message();
402  *ErrorMessage = strdup(E.c_str());
403  return true;
404  }
405 
406  return false;
407 }
408 
410  std::string buf;
411  raw_string_ostream os(buf);
412 
413  unwrap(M)->print(os, nullptr);
414  os.flush();
415 
416  return strdup(buf.c_str());
417 }
418 
419 /*--.. Operations on inline assembler ......................................--*/
420 void LLVMSetModuleInlineAsm2(LLVMModuleRef M, const char *Asm, size_t Len) {
421  unwrap(M)->setModuleInlineAsm(StringRef(Asm, Len));
422 }
423 
425  unwrap(M)->setModuleInlineAsm(StringRef(Asm));
426 }
427 
428 void LLVMAppendModuleInlineAsm(LLVMModuleRef M, const char *Asm, size_t Len) {
429  unwrap(M)->appendModuleInlineAsm(StringRef(Asm, Len));
430 }
431 
432 const char *LLVMGetModuleInlineAsm(LLVMModuleRef M, size_t *Len) {
433  auto &Str = unwrap(M)->getModuleInlineAsm();
434  *Len = Str.length();
435  return Str.c_str();
436 }
437 
439  char *AsmString, size_t AsmStringSize,
440  char *Constraints, size_t ConstraintsSize,
441  LLVMBool HasSideEffects, LLVMBool IsAlignStack,
442  LLVMInlineAsmDialect Dialect) {
444  switch (Dialect) {
446  AD = InlineAsm::AD_ATT;
447  break;
449  AD = InlineAsm::AD_Intel;
450  break;
451  }
452  return wrap(InlineAsm::get(unwrap<FunctionType>(Ty),
453  StringRef(AsmString, AsmStringSize),
454  StringRef(Constraints, ConstraintsSize),
455  HasSideEffects, IsAlignStack, AD));
456 }
457 
458 
459 /*--.. Operations on module contexts ......................................--*/
461  return wrap(&unwrap(M)->getContext());
462 }
463 
464 
465 /*===-- Operations on types -----------------------------------------------===*/
466 
467 /*--.. Operations on all types (mostly) ....................................--*/
468 
470  switch (unwrap(Ty)->getTypeID()) {
471  case Type::VoidTyID:
472  return LLVMVoidTypeKind;
473  case Type::HalfTyID:
474  return LLVMHalfTypeKind;
475  case Type::FloatTyID:
476  return LLVMFloatTypeKind;
477  case Type::DoubleTyID:
478  return LLVMDoubleTypeKind;
479  case Type::X86_FP80TyID:
480  return LLVMX86_FP80TypeKind;
481  case Type::FP128TyID:
482  return LLVMFP128TypeKind;
483  case Type::PPC_FP128TyID:
484  return LLVMPPC_FP128TypeKind;
485  case Type::LabelTyID:
486  return LLVMLabelTypeKind;
487  case Type::MetadataTyID:
488  return LLVMMetadataTypeKind;
489  case Type::IntegerTyID:
490  return LLVMIntegerTypeKind;
491  case Type::FunctionTyID:
492  return LLVMFunctionTypeKind;
493  case Type::StructTyID:
494  return LLVMStructTypeKind;
495  case Type::ArrayTyID:
496  return LLVMArrayTypeKind;
497  case Type::PointerTyID:
498  return LLVMPointerTypeKind;
499  case Type::VectorTyID:
500  return LLVMVectorTypeKind;
501  case Type::X86_MMXTyID:
502  return LLVMX86_MMXTypeKind;
503  case Type::TokenTyID:
504  return LLVMTokenTypeKind;
505  }
506  llvm_unreachable("Unhandled TypeID.");
507 }
508 
510 {
511  return unwrap(Ty)->isSized();
512 }
513 
515  return wrap(&unwrap(Ty)->getContext());
516 }
517 
519  return unwrap(Ty)->print(errs(), /*IsForDebug=*/true);
520 }
521 
523  std::string buf;
524  raw_string_ostream os(buf);
525 
526  if (unwrap(Ty))
527  unwrap(Ty)->print(os);
528  else
529  os << "Printing <null> Type";
530 
531  os.flush();
532 
533  return strdup(buf.c_str());
534 }
535 
536 /*--.. Operations on integer types .........................................--*/
537 
539  return (LLVMTypeRef) Type::getInt1Ty(*unwrap(C));
540 }
542  return (LLVMTypeRef) Type::getInt8Ty(*unwrap(C));
543 }
545  return (LLVMTypeRef) Type::getInt16Ty(*unwrap(C));
546 }
548  return (LLVMTypeRef) Type::getInt32Ty(*unwrap(C));
549 }
551  return (LLVMTypeRef) Type::getInt64Ty(*unwrap(C));
552 }
554  return (LLVMTypeRef) Type::getInt128Ty(*unwrap(C));
555 }
557  return wrap(IntegerType::get(*unwrap(C), NumBits));
558 }
559 
562 }
565 }
568 }
571 }
574 }
577 }
578 LLVMTypeRef LLVMIntType(unsigned NumBits) {
579  return LLVMIntTypeInContext(LLVMGetGlobalContext(), NumBits);
580 }
581 
582 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy) {
583  return unwrap<IntegerType>(IntegerTy)->getBitWidth();
584 }
585 
586 /*--.. Operations on real types ............................................--*/
587 
589  return (LLVMTypeRef) Type::getHalfTy(*unwrap(C));
590 }
592  return (LLVMTypeRef) Type::getFloatTy(*unwrap(C));
593 }
595  return (LLVMTypeRef) Type::getDoubleTy(*unwrap(C));
596 }
598  return (LLVMTypeRef) Type::getX86_FP80Ty(*unwrap(C));
599 }
601  return (LLVMTypeRef) Type::getFP128Ty(*unwrap(C));
602 }
605 }
607  return (LLVMTypeRef) Type::getX86_MMXTy(*unwrap(C));
608 }
609 
612 }
615 }
618 }
621 }
624 }
627 }
630 }
631 
632 /*--.. Operations on function types ........................................--*/
633 
635  LLVMTypeRef *ParamTypes, unsigned ParamCount,
636  LLVMBool IsVarArg) {
637  ArrayRef<Type*> Tys(unwrap(ParamTypes), ParamCount);
638  return wrap(FunctionType::get(unwrap(ReturnType), Tys, IsVarArg != 0));
639 }
640 
642  return unwrap<FunctionType>(FunctionTy)->isVarArg();
643 }
644 
646  return wrap(unwrap<FunctionType>(FunctionTy)->getReturnType());
647 }
648 
649 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy) {
650  return unwrap<FunctionType>(FunctionTy)->getNumParams();
651 }
652 
653 void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest) {
654  FunctionType *Ty = unwrap<FunctionType>(FunctionTy);
656  E = Ty->param_end(); I != E; ++I)
657  *Dest++ = wrap(*I);
658 }
659 
660 /*--.. Operations on struct types ..........................................--*/
661 
663  unsigned ElementCount, LLVMBool Packed) {
664  ArrayRef<Type*> Tys(unwrap(ElementTypes), ElementCount);
665  return wrap(StructType::get(*unwrap(C), Tys, Packed != 0));
666 }
667 
669  unsigned ElementCount, LLVMBool Packed) {
670  return LLVMStructTypeInContext(LLVMGetGlobalContext(), ElementTypes,
671  ElementCount, Packed);
672 }
673 
675 {
676  return wrap(StructType::create(*unwrap(C), Name));
677 }
678 
680 {
681  StructType *Type = unwrap<StructType>(Ty);
682  if (!Type->hasName())
683  return nullptr;
684  return Type->getName().data();
685 }
686 
687 void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
688  unsigned ElementCount, LLVMBool Packed) {
689  ArrayRef<Type*> Tys(unwrap(ElementTypes), ElementCount);
690  unwrap<StructType>(StructTy)->setBody(Tys, Packed != 0);
691 }
692 
694  return unwrap<StructType>(StructTy)->getNumElements();
695 }
696 
698  StructType *Ty = unwrap<StructType>(StructTy);
700  E = Ty->element_end(); I != E; ++I)
701  *Dest++ = wrap(*I);
702 }
703 
705  StructType *Ty = unwrap<StructType>(StructTy);
706  return wrap(Ty->getTypeAtIndex(i));
707 }
708 
710  return unwrap<StructType>(StructTy)->isPacked();
711 }
712 
714  return unwrap<StructType>(StructTy)->isOpaque();
715 }
716 
718  return unwrap<StructType>(StructTy)->isLiteral();
719 }
720 
722  return wrap(unwrap(M)->getTypeByName(Name));
723 }
724 
725 /*--.. Operations on array, pointer, and vector types (sequence types) .....--*/
726 
728  int i = 0;
729  for (auto *T : unwrap(Tp)->subtypes()) {
730  Arr[i] = wrap(T);
731  i++;
732  }
733 }
734 
735 LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount) {
736  return wrap(ArrayType::get(unwrap(ElementType), ElementCount));
737 }
738 
740  return wrap(PointerType::get(unwrap(ElementType), AddressSpace));
741 }
742 
743 LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount) {
744  return wrap(VectorType::get(unwrap(ElementType), ElementCount));
745 }
746 
748  auto *Ty = unwrap<Type>(WrappedTy);
749  if (auto *PTy = dyn_cast<PointerType>(Ty))
750  return wrap(PTy->getElementType());
751  return wrap(cast<SequentialType>(Ty)->getElementType());
752 }
753 
755  return unwrap(Tp)->getNumContainedTypes();
756 }
757 
758 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy) {
759  return unwrap<ArrayType>(ArrayTy)->getNumElements();
760 }
761 
763  return unwrap<PointerType>(PointerTy)->getAddressSpace();
764 }
765 
766 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy) {
767  return unwrap<VectorType>(VectorTy)->getNumElements();
768 }
769 
770 /*--.. Operations on other types ...........................................--*/
771 
773  return wrap(Type::getVoidTy(*unwrap(C)));
774 }
776  return wrap(Type::getLabelTy(*unwrap(C)));
777 }
779  return wrap(Type::getTokenTy(*unwrap(C)));
780 }
782  return wrap(Type::getMetadataTy(*unwrap(C)));
783 }
784 
787 }
790 }
791 
792 /*===-- Operations on values ----------------------------------------------===*/
793 
794 /*--.. Operations on all values ............................................--*/
795 
797  return wrap(unwrap(Val)->getType());
798 }
799 
801  switch(unwrap(Val)->getValueID()) {
802 #define HANDLE_VALUE(Name) \
803  case Value::Name##Val: \
804  return LLVM##Name##ValueKind;
805 #include "llvm/IR/Value.def"
806  default:
808  }
809 }
810 
811 const char *LLVMGetValueName2(LLVMValueRef Val, size_t *Length) {
812  auto *V = unwrap(Val);
813  *Length = V->getName().size();
814  return V->getName().data();
815 }
816 
817 void LLVMSetValueName2(LLVMValueRef Val, const char *Name, size_t NameLen) {
818  unwrap(Val)->setName(StringRef(Name, NameLen));
819 }
820 
821 const char *LLVMGetValueName(LLVMValueRef Val) {
822  return unwrap(Val)->getName().data();
823 }
824 
825 void LLVMSetValueName(LLVMValueRef Val, const char *Name) {
826  unwrap(Val)->setName(Name);
827 }
828 
830  unwrap(Val)->print(errs(), /*IsForDebug=*/true);
831 }
832 
834  std::string buf;
835  raw_string_ostream os(buf);
836 
837  if (unwrap(Val))
838  unwrap(Val)->print(os);
839  else
840  os << "Printing <null> Value";
841 
842  os.flush();
843 
844  return strdup(buf.c_str());
845 }
846 
848  unwrap(OldVal)->replaceAllUsesWith(unwrap(NewVal));
849 }
850 
852  return unwrap<Instruction>(Inst)->hasMetadata();
853 }
854 
855 LLVMValueRef LLVMGetMetadata(LLVMValueRef Inst, unsigned KindID) {
856  auto *I = unwrap<Instruction>(Inst);
857  assert(I && "Expected instruction");
858  if (auto *MD = I->getMetadata(KindID))
859  return wrap(MetadataAsValue::get(I->getContext(), MD));
860  return nullptr;
861 }
862 
863 // MetadataAsValue uses a canonical format which strips the actual MDNode for
864 // MDNode with just a single constant value, storing just a ConstantAsMetadata
865 // This undoes this canonicalization, reconstructing the MDNode.
867  Metadata *MD = MAV->getMetadata();
868  assert((isa<MDNode>(MD) || isa<ConstantAsMetadata>(MD)) &&
869  "Expected a metadata node or a canonicalized constant");
870 
871  if (MDNode *N = dyn_cast<MDNode>(MD))
872  return N;
873 
874  return MDNode::get(MAV->getContext(), MD);
875 }
876 
877 void LLVMSetMetadata(LLVMValueRef Inst, unsigned KindID, LLVMValueRef Val) {
878  MDNode *N = Val ? extractMDNode(unwrap<MetadataAsValue>(Val)) : nullptr;
879 
880  unwrap<Instruction>(Inst)->setMetadata(KindID, N);
881 }
882 
884  unsigned Kind;
886 };
887 
889 static LLVMValueMetadataEntry *
890 llvm_getMetadata(size_t *NumEntries,
891  llvm::function_ref<void(MetadataEntries &)> AccessMD) {
893  AccessMD(MVEs);
894 
896  static_cast<LLVMOpaqueValueMetadataEntry *>(
897  safe_malloc(MVEs.size() * sizeof(LLVMOpaqueValueMetadataEntry)));
898  for (unsigned i = 0; i < MVEs.size(); ++i) {
899  const auto &ModuleFlag = MVEs[i];
900  Result[i].Kind = ModuleFlag.first;
901  Result[i].Metadata = wrap(ModuleFlag.second);
902  }
903  *NumEntries = MVEs.size();
904  return Result;
905 }
906 
909  size_t *NumEntries) {
910  return llvm_getMetadata(NumEntries, [&Value](MetadataEntries &Entries) {
911  unwrap<Instruction>(Value)->getAllMetadata(Entries);
912  });
913 }
914 
915 /*--.. Conversion functions ................................................--*/
916 
917 #define LLVM_DEFINE_VALUE_CAST(name) \
918  LLVMValueRef LLVMIsA##name(LLVMValueRef Val) { \
919  return wrap(static_cast<Value*>(dyn_cast_or_null<name>(unwrap(Val)))); \
920  }
921 
923 
925  if (auto *MD = dyn_cast_or_null<MetadataAsValue>(unwrap(Val)))
926  if (isa<MDNode>(MD->getMetadata()) ||
927  isa<ValueAsMetadata>(MD->getMetadata()))
928  return Val;
929  return nullptr;
930 }
931 
933  if (auto *MD = dyn_cast_or_null<MetadataAsValue>(unwrap(Val)))
934  if (isa<MDString>(MD->getMetadata()))
935  return Val;
936  return nullptr;
937 }
938 
939 /*--.. Operations on Uses ..................................................--*/
941  Value *V = unwrap(Val);
943  if (I == V->use_end())
944  return nullptr;
945  return wrap(&*I);
946 }
947 
949  Use *Next = unwrap(U)->getNext();
950  if (Next)
951  return wrap(Next);
952  return nullptr;
953 }
954 
956  return wrap(unwrap(U)->getUser());
957 }
958 
960  return wrap(unwrap(U)->get());
961 }
962 
963 /*--.. Operations on Users .................................................--*/
964 
966  unsigned Index) {
967  Metadata *Op = N->getOperand(Index);
968  if (!Op)
969  return nullptr;
970  if (auto *C = dyn_cast<ConstantAsMetadata>(Op))
971  return wrap(C->getValue());
972  return wrap(MetadataAsValue::get(Context, Op));
973 }
974 
976  Value *V = unwrap(Val);
977  if (auto *MD = dyn_cast<MetadataAsValue>(V)) {
978  if (auto *L = dyn_cast<ValueAsMetadata>(MD->getMetadata())) {
979  assert(Index == 0 && "Function-local metadata can only have one operand");
980  return wrap(L->getValue());
981  }
982  return getMDNodeOperandImpl(V->getContext(),
983  cast<MDNode>(MD->getMetadata()), Index);
984  }
985 
986  return wrap(cast<User>(V)->getOperand(Index));
987 }
988 
990  Value *V = unwrap(Val);
991  return wrap(&cast<User>(V)->getOperandUse(Index));
992 }
993 
995  unwrap<User>(Val)->setOperand(Index, unwrap(Op));
996 }
997 
999  Value *V = unwrap(Val);
1000  if (isa<MetadataAsValue>(V))
1001  return LLVMGetMDNodeNumOperands(Val);
1002 
1003  return cast<User>(V)->getNumOperands();
1004 }
1005 
1006 /*--.. Operations on constants of any type .................................--*/
1007 
1009  return wrap(Constant::getNullValue(unwrap(Ty)));
1010 }
1011 
1013  return wrap(Constant::getAllOnesValue(unwrap(Ty)));
1014 }
1015 
1017  return wrap(UndefValue::get(unwrap(Ty)));
1018 }
1019 
1021  return isa<Constant>(unwrap(Ty));
1022 }
1023 
1025  if (Constant *C = dyn_cast<Constant>(unwrap(Val)))
1026  return C->isNullValue();
1027  return false;
1028 }
1029 
1031  return isa<UndefValue>(unwrap(Val));
1032 }
1033 
1035  return wrap(ConstantPointerNull::get(unwrap<PointerType>(Ty)));
1036 }
1037 
1038 /*--.. Operations on metadata nodes ........................................--*/
1039 
1041  unsigned SLen) {
1042  LLVMContext &Context = *unwrap(C);
1043  return wrap(MetadataAsValue::get(
1044  Context, MDString::get(Context, StringRef(Str, SLen))));
1045 }
1046 
1047 LLVMValueRef LLVMMDString(const char *Str, unsigned SLen) {
1048  return LLVMMDStringInContext(LLVMGetGlobalContext(), Str, SLen);
1049 }
1050 
1052  unsigned Count) {
1053  LLVMContext &Context = *unwrap(C);
1055  for (auto *OV : makeArrayRef(Vals, Count)) {
1056  Value *V = unwrap(OV);
1057  Metadata *MD;
1058  if (!V)
1059  MD = nullptr;
1060  else if (auto *C = dyn_cast<Constant>(V))
1061  MD = ConstantAsMetadata::get(C);
1062  else if (auto *MDV = dyn_cast<MetadataAsValue>(V)) {
1063  MD = MDV->getMetadata();
1064  assert(!isa<LocalAsMetadata>(MD) && "Unexpected function-local metadata "
1065  "outside of direct argument to call");
1066  } else {
1067  // This is function-local metadata. Pretend to make an MDNode.
1068  assert(Count == 1 &&
1069  "Expected only one operand to function-local metadata");
1070  return wrap(MetadataAsValue::get(Context, LocalAsMetadata::get(V)));
1071  }
1072 
1073  MDs.push_back(MD);
1074  }
1075  return wrap(MetadataAsValue::get(Context, MDNode::get(Context, MDs)));
1076 }
1077 
1078 LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count) {
1079  return LLVMMDNodeInContext(LLVMGetGlobalContext(), Vals, Count);
1080 }
1081 
1083  return wrap(MetadataAsValue::get(*unwrap(C), unwrap(MD)));
1084 }
1085 
1087  auto *V = unwrap(Val);
1088  if (auto *C = dyn_cast<Constant>(V))
1089  return wrap(ConstantAsMetadata::get(C));
1090  if (auto *MAV = dyn_cast<MetadataAsValue>(V))
1091  return wrap(MAV->getMetadata());
1092  return wrap(ValueAsMetadata::get(V));
1093 }
1094 
1095 const char *LLVMGetMDString(LLVMValueRef V, unsigned *Length) {
1096  if (const auto *MD = dyn_cast<MetadataAsValue>(unwrap(V)))
1097  if (const MDString *S = dyn_cast<MDString>(MD->getMetadata())) {
1098  *Length = S->getString().size();
1099  return S->getString().data();
1100  }
1101  *Length = 0;
1102  return nullptr;
1103 }
1104 
1106  auto *MD = cast<MetadataAsValue>(unwrap(V));
1107  if (isa<ValueAsMetadata>(MD->getMetadata()))
1108  return 1;
1109  return cast<MDNode>(MD->getMetadata())->getNumOperands();
1110 }
1111 
1113  Module *Mod = unwrap(M);
1115  if (I == Mod->named_metadata_end())
1116  return nullptr;
1117  return wrap(&*I);
1118 }
1119 
1121  Module *Mod = unwrap(M);
1123  if (I == Mod->named_metadata_begin())
1124  return nullptr;
1125  return wrap(&*--I);
1126 }
1127 
1129  NamedMDNode *NamedNode = unwrap<NamedMDNode>(NMD);
1131  if (++I == NamedNode->getParent()->named_metadata_end())
1132  return nullptr;
1133  return wrap(&*I);
1134 }
1135 
1137  NamedMDNode *NamedNode = unwrap<NamedMDNode>(NMD);
1139  if (I == NamedNode->getParent()->named_metadata_begin())
1140  return nullptr;
1141  return wrap(&*--I);
1142 }
1143 
1145  const char *Name, size_t NameLen) {
1146  return wrap(unwrap(M)->getNamedMetadata(StringRef(Name, NameLen)));
1147 }
1148 
1150  const char *Name, size_t NameLen) {
1151  return wrap(unwrap(M)->getOrInsertNamedMetadata({Name, NameLen}));
1152 }
1153 
1154 const char *LLVMGetNamedMetadataName(LLVMNamedMDNodeRef NMD, size_t *NameLen) {
1155  NamedMDNode *NamedNode = unwrap<NamedMDNode>(NMD);
1156  *NameLen = NamedNode->getName().size();
1157  return NamedNode->getName().data();
1158 }
1159 
1161  auto *MD = cast<MetadataAsValue>(unwrap(V));
1162  if (auto *MDV = dyn_cast<ValueAsMetadata>(MD->getMetadata())) {
1163  *Dest = wrap(MDV->getValue());
1164  return;
1165  }
1166  const auto *N = cast<MDNode>(MD->getMetadata());
1167  const unsigned numOperands = N->getNumOperands();
1168  LLVMContext &Context = unwrap(V)->getContext();
1169  for (unsigned i = 0; i < numOperands; i++)
1170  Dest[i] = getMDNodeOperandImpl(Context, N, i);
1171 }
1172 
1174  if (NamedMDNode *N = unwrap(M)->getNamedMetadata(Name)) {
1175  return N->getNumOperands();
1176  }
1177  return 0;
1178 }
1179 
1181  LLVMValueRef *Dest) {
1182  NamedMDNode *N = unwrap(M)->getNamedMetadata(Name);
1183  if (!N)
1184  return;
1185  LLVMContext &Context = unwrap(M)->getContext();
1186  for (unsigned i=0;i<N->getNumOperands();i++)
1187  Dest[i] = wrap(MetadataAsValue::get(Context, N->getOperand(i)));
1188 }
1189 
1191  LLVMValueRef Val) {
1192  NamedMDNode *N = unwrap(M)->getOrInsertNamedMetadata(Name);
1193  if (!N)
1194  return;
1195  if (!Val)
1196  return;
1197  N->addOperand(extractMDNode(unwrap<MetadataAsValue>(Val)));
1198 }
1199 
1200 const char *LLVMGetDebugLocDirectory(LLVMValueRef Val, unsigned *Length) {
1201  if (!Length) return nullptr;
1202  StringRef S;
1203  if (const auto *I = unwrap<Instruction>(Val)) {
1204  S = I->getDebugLoc()->getDirectory();
1205  } else if (const auto *GV = unwrap<GlobalVariable>(Val)) {
1207  GV->getDebugInfo(GVEs);
1208  if (GVEs.size())
1209  if (const DIGlobalVariable *DGV = GVEs[0]->getVariable())
1210  S = DGV->getDirectory();
1211  } else if (const auto *F = unwrap<Function>(Val)) {
1212  if (const DISubprogram *DSP = F->getSubprogram())
1213  S = DSP->getDirectory();
1214  } else {
1215  assert(0 && "Expected Instruction, GlobalVariable or Function");
1216  return nullptr;
1217  }
1218  *Length = S.size();
1219  return S.data();
1220 }
1221 
1222 const char *LLVMGetDebugLocFilename(LLVMValueRef Val, unsigned *Length) {
1223  if (!Length) return nullptr;
1224  StringRef S;
1225  if (const auto *I = unwrap<Instruction>(Val)) {
1226  S = I->getDebugLoc()->getFilename();
1227  } else if (const auto *GV = unwrap<GlobalVariable>(Val)) {
1229  GV->getDebugInfo(GVEs);
1230  if (GVEs.size())
1231  if (const DIGlobalVariable *DGV = GVEs[0]->getVariable())
1232  S = DGV->getFilename();
1233  } else if (const auto *F = unwrap<Function>(Val)) {
1234  if (const DISubprogram *DSP = F->getSubprogram())
1235  S = DSP->getFilename();
1236  } else {
1237  assert(0 && "Expected Instruction, GlobalVariable or Function");
1238  return nullptr;
1239  }
1240  *Length = S.size();
1241  return S.data();
1242 }
1243 
1245  unsigned L = 0;
1246  if (const auto *I = unwrap<Instruction>(Val)) {
1247  L = I->getDebugLoc()->getLine();
1248  } else if (const auto *GV = unwrap<GlobalVariable>(Val)) {
1250  GV->getDebugInfo(GVEs);
1251  if (GVEs.size())
1252  if (const DIGlobalVariable *DGV = GVEs[0]->getVariable())
1253  L = DGV->getLine();
1254  } else if (const auto *F = unwrap<Function>(Val)) {
1255  if (const DISubprogram *DSP = F->getSubprogram())
1256  L = DSP->getLine();
1257  } else {
1258  assert(0 && "Expected Instruction, GlobalVariable or Function");
1259  return -1;
1260  }
1261  return L;
1262 }
1263 
1265  unsigned C = 0;
1266  if (const auto *I = unwrap<Instruction>(Val))
1267  if (const auto &L = I->getDebugLoc())
1268  C = L->getColumn();
1269  return C;
1270 }
1271 
1272 /*--.. Operations on scalar constants ......................................--*/
1273 
1274 LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
1275  LLVMBool SignExtend) {
1276  return wrap(ConstantInt::get(unwrap<IntegerType>(IntTy), N, SignExtend != 0));
1277 }
1278 
1280  unsigned NumWords,
1281  const uint64_t Words[]) {
1282  IntegerType *Ty = unwrap<IntegerType>(IntTy);
1283  return wrap(ConstantInt::get(Ty->getContext(),
1284  APInt(Ty->getBitWidth(),
1285  makeArrayRef(Words, NumWords))));
1286 }
1287 
1289  uint8_t Radix) {
1290  return wrap(ConstantInt::get(unwrap<IntegerType>(IntTy), StringRef(Str),
1291  Radix));
1292 }
1293 
1295  unsigned SLen, uint8_t Radix) {
1296  return wrap(ConstantInt::get(unwrap<IntegerType>(IntTy), StringRef(Str, SLen),
1297  Radix));
1298 }
1299 
1301  return wrap(ConstantFP::get(unwrap(RealTy), N));
1302 }
1303 
1305  return wrap(ConstantFP::get(unwrap(RealTy), StringRef(Text)));
1306 }
1307 
1309  unsigned SLen) {
1310  return wrap(ConstantFP::get(unwrap(RealTy), StringRef(Str, SLen)));
1311 }
1312 
1313 unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal) {
1314  return unwrap<ConstantInt>(ConstantVal)->getZExtValue();
1315 }
1316 
1317 long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal) {
1318  return unwrap<ConstantInt>(ConstantVal)->getSExtValue();
1319 }
1320 
1321 double LLVMConstRealGetDouble(LLVMValueRef ConstantVal, LLVMBool *LosesInfo) {
1322  ConstantFP *cFP = unwrap<ConstantFP>(ConstantVal) ;
1323  Type *Ty = cFP->getType();
1324 
1325  if (Ty->isFloatTy()) {
1326  *LosesInfo = false;
1327  return cFP->getValueAPF().convertToFloat();
1328  }
1329 
1330  if (Ty->isDoubleTy()) {
1331  *LosesInfo = false;
1332  return cFP->getValueAPF().convertToDouble();
1333  }
1334 
1335  bool APFLosesInfo;
1336  APFloat APF = cFP->getValueAPF();
1338  *LosesInfo = APFLosesInfo;
1339  return APF.convertToDouble();
1340 }
1341 
1342 /*--.. Operations on composite constants ...................................--*/
1343 
1345  unsigned Length,
1346  LLVMBool DontNullTerminate) {
1347  /* Inverted the sense of AddNull because ', 0)' is a
1348  better mnemonic for null termination than ', 1)'. */
1349  return wrap(ConstantDataArray::getString(*unwrap(C), StringRef(Str, Length),
1350  DontNullTerminate == 0));
1351 }
1352 
1353 LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
1354  LLVMBool DontNullTerminate) {
1355  return LLVMConstStringInContext(LLVMGetGlobalContext(), Str, Length,
1356  DontNullTerminate);
1357 }
1358 
1360  return wrap(unwrap<ConstantDataSequential>(C)->getElementAsConstant(idx));
1361 }
1362 
1364  return unwrap<ConstantDataSequential>(C)->isString();
1365 }
1366 
1367 const char *LLVMGetAsString(LLVMValueRef C, size_t *Length) {
1368  StringRef Str = unwrap<ConstantDataSequential>(C)->getAsString();
1369  *Length = Str.size();
1370  return Str.data();
1371 }
1372 
1374  LLVMValueRef *ConstantVals, unsigned Length) {
1375  ArrayRef<Constant*> V(unwrap<Constant>(ConstantVals, Length), Length);
1376  return wrap(ConstantArray::get(ArrayType::get(unwrap(ElementTy), Length), V));
1377 }
1378 
1380  LLVMValueRef *ConstantVals,
1381  unsigned Count, LLVMBool Packed) {
1382  Constant **Elements = unwrap<Constant>(ConstantVals, Count);
1383  return wrap(ConstantStruct::getAnon(*unwrap(C), makeArrayRef(Elements, Count),
1384  Packed != 0));
1385 }
1386 
1387 LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
1388  LLVMBool Packed) {
1389  return LLVMConstStructInContext(LLVMGetGlobalContext(), ConstantVals, Count,
1390  Packed);
1391 }
1392 
1394  LLVMValueRef *ConstantVals,
1395  unsigned Count) {
1396  Constant **Elements = unwrap<Constant>(ConstantVals, Count);
1397  StructType *Ty = cast<StructType>(unwrap(StructTy));
1398 
1399  return wrap(ConstantStruct::get(Ty, makeArrayRef(Elements, Count)));
1400 }
1401 
1402 LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size) {
1404  unwrap<Constant>(ScalarConstantVals, Size), Size)));
1405 }
1406 
1407 /*-- Opcode mapping */
1408 
1409 static LLVMOpcode map_to_llvmopcode(int opcode)
1410 {
1411  switch (opcode) {
1412  default: llvm_unreachable("Unhandled Opcode.");
1413 #define HANDLE_INST(num, opc, clas) case num: return LLVM##opc;
1414 #include "llvm/IR/Instruction.def"
1415 #undef HANDLE_INST
1416  }
1417 }
1418 
1420 {
1421  switch (code) {
1422 #define HANDLE_INST(num, opc, clas) case LLVM##opc: return num;
1423 #include "llvm/IR/Instruction.def"
1424 #undef HANDLE_INST
1425  }
1426  llvm_unreachable("Unhandled Opcode.");
1427 }
1428 
1429 /*--.. Constant expressions ................................................--*/
1430 
1432  return map_to_llvmopcode(unwrap<ConstantExpr>(ConstantVal)->getOpcode());
1433 }
1434 
1436  return wrap(ConstantExpr::getAlignOf(unwrap(Ty)));
1437 }
1438 
1440  return wrap(ConstantExpr::getSizeOf(unwrap(Ty)));
1441 }
1442 
1444  return wrap(ConstantExpr::getNeg(unwrap<Constant>(ConstantVal)));
1445 }
1446 
1448  return wrap(ConstantExpr::getNSWNeg(unwrap<Constant>(ConstantVal)));
1449 }
1450 
1452  return wrap(ConstantExpr::getNUWNeg(unwrap<Constant>(ConstantVal)));
1453 }
1454 
1455 
1457  return wrap(ConstantExpr::getFNeg(unwrap<Constant>(ConstantVal)));
1458 }
1459 
1461  return wrap(ConstantExpr::getNot(unwrap<Constant>(ConstantVal)));
1462 }
1463 
1465  return wrap(ConstantExpr::getAdd(unwrap<Constant>(LHSConstant),
1466  unwrap<Constant>(RHSConstant)));
1467 }
1468 
1470  LLVMValueRef RHSConstant) {
1471  return wrap(ConstantExpr::getNSWAdd(unwrap<Constant>(LHSConstant),
1472  unwrap<Constant>(RHSConstant)));
1473 }
1474 
1476  LLVMValueRef RHSConstant) {
1477  return wrap(ConstantExpr::getNUWAdd(unwrap<Constant>(LHSConstant),
1478  unwrap<Constant>(RHSConstant)));
1479 }
1480 
1482  return wrap(ConstantExpr::getFAdd(unwrap<Constant>(LHSConstant),
1483  unwrap<Constant>(RHSConstant)));
1484 }
1485 
1487  return wrap(ConstantExpr::getSub(unwrap<Constant>(LHSConstant),
1488  unwrap<Constant>(RHSConstant)));
1489 }
1490 
1492  LLVMValueRef RHSConstant) {
1493  return wrap(ConstantExpr::getNSWSub(unwrap<Constant>(LHSConstant),
1494  unwrap<Constant>(RHSConstant)));
1495 }
1496 
1498  LLVMValueRef RHSConstant) {
1499  return wrap(ConstantExpr::getNUWSub(unwrap<Constant>(LHSConstant),
1500  unwrap<Constant>(RHSConstant)));
1501 }
1502 
1504  return wrap(ConstantExpr::getFSub(unwrap<Constant>(LHSConstant),
1505  unwrap<Constant>(RHSConstant)));
1506 }
1507 
1509  return wrap(ConstantExpr::getMul(unwrap<Constant>(LHSConstant),
1510  unwrap<Constant>(RHSConstant)));
1511 }
1512 
1514  LLVMValueRef RHSConstant) {
1515  return wrap(ConstantExpr::getNSWMul(unwrap<Constant>(LHSConstant),
1516  unwrap<Constant>(RHSConstant)));
1517 }
1518 
1520  LLVMValueRef RHSConstant) {
1521  return wrap(ConstantExpr::getNUWMul(unwrap<Constant>(LHSConstant),
1522  unwrap<Constant>(RHSConstant)));
1523 }
1524 
1526  return wrap(ConstantExpr::getFMul(unwrap<Constant>(LHSConstant),
1527  unwrap<Constant>(RHSConstant)));
1528 }
1529 
1531  return wrap(ConstantExpr::getUDiv(unwrap<Constant>(LHSConstant),
1532  unwrap<Constant>(RHSConstant)));
1533 }
1534 
1536  LLVMValueRef RHSConstant) {
1537  return wrap(ConstantExpr::getExactUDiv(unwrap<Constant>(LHSConstant),
1538  unwrap<Constant>(RHSConstant)));
1539 }
1540 
1542  return wrap(ConstantExpr::getSDiv(unwrap<Constant>(LHSConstant),
1543  unwrap<Constant>(RHSConstant)));
1544 }
1545 
1547  LLVMValueRef RHSConstant) {
1548  return wrap(ConstantExpr::getExactSDiv(unwrap<Constant>(LHSConstant),
1549  unwrap<Constant>(RHSConstant)));
1550 }
1551 
1553  return wrap(ConstantExpr::getFDiv(unwrap<Constant>(LHSConstant),
1554  unwrap<Constant>(RHSConstant)));
1555 }
1556 
1558  return wrap(ConstantExpr::getURem(unwrap<Constant>(LHSConstant),
1559  unwrap<Constant>(RHSConstant)));
1560 }
1561 
1563  return wrap(ConstantExpr::getSRem(unwrap<Constant>(LHSConstant),
1564  unwrap<Constant>(RHSConstant)));
1565 }
1566 
1568  return wrap(ConstantExpr::getFRem(unwrap<Constant>(LHSConstant),
1569  unwrap<Constant>(RHSConstant)));
1570 }
1571 
1573  return wrap(ConstantExpr::getAnd(unwrap<Constant>(LHSConstant),
1574  unwrap<Constant>(RHSConstant)));
1575 }
1576 
1578  return wrap(ConstantExpr::getOr(unwrap<Constant>(LHSConstant),
1579  unwrap<Constant>(RHSConstant)));
1580 }
1581 
1583  return wrap(ConstantExpr::getXor(unwrap<Constant>(LHSConstant),
1584  unwrap<Constant>(RHSConstant)));
1585 }
1586 
1588  LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1589  return wrap(ConstantExpr::getICmp(Predicate,
1590  unwrap<Constant>(LHSConstant),
1591  unwrap<Constant>(RHSConstant)));
1592 }
1593 
1595  LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1596  return wrap(ConstantExpr::getFCmp(Predicate,
1597  unwrap<Constant>(LHSConstant),
1598  unwrap<Constant>(RHSConstant)));
1599 }
1600 
1602  return wrap(ConstantExpr::getShl(unwrap<Constant>(LHSConstant),
1603  unwrap<Constant>(RHSConstant)));
1604 }
1605 
1607  return wrap(ConstantExpr::getLShr(unwrap<Constant>(LHSConstant),
1608  unwrap<Constant>(RHSConstant)));
1609 }
1610 
1612  return wrap(ConstantExpr::getAShr(unwrap<Constant>(LHSConstant),
1613  unwrap<Constant>(RHSConstant)));
1614 }
1615 
1617  LLVMValueRef *ConstantIndices, unsigned NumIndices) {
1618  ArrayRef<Constant *> IdxList(unwrap<Constant>(ConstantIndices, NumIndices),
1619  NumIndices);
1620  Constant *Val = unwrap<Constant>(ConstantVal);
1621  Type *Ty =
1622  cast<PointerType>(Val->getType()->getScalarType())->getElementType();
1623  return wrap(ConstantExpr::getGetElementPtr(Ty, Val, IdxList));
1624 }
1625 
1627  LLVMValueRef *ConstantIndices,
1628  unsigned NumIndices) {
1629  ArrayRef<Constant *> IdxList(unwrap<Constant>(ConstantIndices, NumIndices),
1630  NumIndices);
1631  Constant *Val = unwrap<Constant>(ConstantVal);
1632  Type *Ty =
1633  cast<PointerType>(Val->getType()->getScalarType())->getElementType();
1634  return wrap(ConstantExpr::getInBoundsGetElementPtr(Ty, Val, IdxList));
1635 }
1636 
1638  return wrap(ConstantExpr::getTrunc(unwrap<Constant>(ConstantVal),
1639  unwrap(ToType)));
1640 }
1641 
1643  return wrap(ConstantExpr::getSExt(unwrap<Constant>(ConstantVal),
1644  unwrap(ToType)));
1645 }
1646 
1648  return wrap(ConstantExpr::getZExt(unwrap<Constant>(ConstantVal),
1649  unwrap(ToType)));
1650 }
1651 
1653  return wrap(ConstantExpr::getFPTrunc(unwrap<Constant>(ConstantVal),
1654  unwrap(ToType)));
1655 }
1656 
1658  return wrap(ConstantExpr::getFPExtend(unwrap<Constant>(ConstantVal),
1659  unwrap(ToType)));
1660 }
1661 
1663  return wrap(ConstantExpr::getUIToFP(unwrap<Constant>(ConstantVal),
1664  unwrap(ToType)));
1665 }
1666 
1668  return wrap(ConstantExpr::getSIToFP(unwrap<Constant>(ConstantVal),
1669  unwrap(ToType)));
1670 }
1671 
1673  return wrap(ConstantExpr::getFPToUI(unwrap<Constant>(ConstantVal),
1674  unwrap(ToType)));
1675 }
1676 
1678  return wrap(ConstantExpr::getFPToSI(unwrap<Constant>(ConstantVal),
1679  unwrap(ToType)));
1680 }
1681 
1683  return wrap(ConstantExpr::getPtrToInt(unwrap<Constant>(ConstantVal),
1684  unwrap(ToType)));
1685 }
1686 
1688  return wrap(ConstantExpr::getIntToPtr(unwrap<Constant>(ConstantVal),
1689  unwrap(ToType)));
1690 }
1691 
1693  return wrap(ConstantExpr::getBitCast(unwrap<Constant>(ConstantVal),
1694  unwrap(ToType)));
1695 }
1696 
1698  LLVMTypeRef ToType) {
1699  return wrap(ConstantExpr::getAddrSpaceCast(unwrap<Constant>(ConstantVal),
1700  unwrap(ToType)));
1701 }
1702 
1704  LLVMTypeRef ToType) {
1705  return wrap(ConstantExpr::getZExtOrBitCast(unwrap<Constant>(ConstantVal),
1706  unwrap(ToType)));
1707 }
1708 
1710  LLVMTypeRef ToType) {
1711  return wrap(ConstantExpr::getSExtOrBitCast(unwrap<Constant>(ConstantVal),
1712  unwrap(ToType)));
1713 }
1714 
1716  LLVMTypeRef ToType) {
1717  return wrap(ConstantExpr::getTruncOrBitCast(unwrap<Constant>(ConstantVal),
1718  unwrap(ToType)));
1719 }
1720 
1722  LLVMTypeRef ToType) {
1723  return wrap(ConstantExpr::getPointerCast(unwrap<Constant>(ConstantVal),
1724  unwrap(ToType)));
1725 }
1726 
1728  LLVMBool isSigned) {
1729  return wrap(ConstantExpr::getIntegerCast(unwrap<Constant>(ConstantVal),
1730  unwrap(ToType), isSigned));
1731 }
1732 
1734  return wrap(ConstantExpr::getFPCast(unwrap<Constant>(ConstantVal),
1735  unwrap(ToType)));
1736 }
1737 
1739  LLVMValueRef ConstantIfTrue,
1740  LLVMValueRef ConstantIfFalse) {
1741  return wrap(ConstantExpr::getSelect(unwrap<Constant>(ConstantCondition),
1742  unwrap<Constant>(ConstantIfTrue),
1743  unwrap<Constant>(ConstantIfFalse)));
1744 }
1745 
1747  LLVMValueRef IndexConstant) {
1748  return wrap(ConstantExpr::getExtractElement(unwrap<Constant>(VectorConstant),
1749  unwrap<Constant>(IndexConstant)));
1750 }
1751 
1753  LLVMValueRef ElementValueConstant,
1754  LLVMValueRef IndexConstant) {
1755  return wrap(ConstantExpr::getInsertElement(unwrap<Constant>(VectorConstant),
1756  unwrap<Constant>(ElementValueConstant),
1757  unwrap<Constant>(IndexConstant)));
1758 }
1759 
1761  LLVMValueRef VectorBConstant,
1762  LLVMValueRef MaskConstant) {
1763  return wrap(ConstantExpr::getShuffleVector(unwrap<Constant>(VectorAConstant),
1764  unwrap<Constant>(VectorBConstant),
1765  unwrap<Constant>(MaskConstant)));
1766 }
1767 
1768 LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
1769  unsigned NumIdx) {
1770  return wrap(ConstantExpr::getExtractValue(unwrap<Constant>(AggConstant),
1771  makeArrayRef(IdxList, NumIdx)));
1772 }
1773 
1775  LLVMValueRef ElementValueConstant,
1776  unsigned *IdxList, unsigned NumIdx) {
1777  return wrap(ConstantExpr::getInsertValue(unwrap<Constant>(AggConstant),
1778  unwrap<Constant>(ElementValueConstant),
1779  makeArrayRef(IdxList, NumIdx)));
1780 }
1781 
1782 LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty, const char *AsmString,
1783  const char *Constraints,
1784  LLVMBool HasSideEffects,
1785  LLVMBool IsAlignStack) {
1786  return wrap(InlineAsm::get(dyn_cast<FunctionType>(unwrap(Ty)), AsmString,
1787  Constraints, HasSideEffects, IsAlignStack));
1788 }
1789 
1791  return wrap(BlockAddress::get(unwrap<Function>(F), unwrap(BB)));
1792 }
1793 
1794 /*--.. Operations on global variables, functions, and aliases (globals) ....--*/
1795 
1797  return wrap(unwrap<GlobalValue>(Global)->getParent());
1798 }
1799 
1801  return unwrap<GlobalValue>(Global)->isDeclaration();
1802 }
1803 
1805  switch (unwrap<GlobalValue>(Global)->getLinkage()) {
1807  return LLVMExternalLinkage;
1811  return LLVMLinkOnceAnyLinkage;
1813  return LLVMLinkOnceODRLinkage;
1815  return LLVMWeakAnyLinkage;
1817  return LLVMWeakODRLinkage;
1819  return LLVMAppendingLinkage;
1821  return LLVMInternalLinkage;
1823  return LLVMPrivateLinkage;
1825  return LLVMExternalWeakLinkage;
1827  return LLVMCommonLinkage;
1828  }
1829 
1830  llvm_unreachable("Invalid GlobalValue linkage!");
1831 }
1832 
1833 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage) {
1834  GlobalValue *GV = unwrap<GlobalValue>(Global);
1835 
1836  switch (Linkage) {
1837  case LLVMExternalLinkage:
1839  break;
1842  break;
1845  break;
1848  break;
1850  LLVM_DEBUG(
1851  errs() << "LLVMSetLinkage(): LLVMLinkOnceODRAutoHideLinkage is no "
1852  "longer supported.");
1853  break;
1854  case LLVMWeakAnyLinkage:
1856  break;
1857  case LLVMWeakODRLinkage:
1859  break;
1860  case LLVMAppendingLinkage:
1862  break;
1863  case LLVMInternalLinkage:
1865  break;
1866  case LLVMPrivateLinkage:
1868  break;
1871  break;
1874  break;
1875  case LLVMDLLImportLinkage:
1876  LLVM_DEBUG(
1877  errs()
1878  << "LLVMSetLinkage(): LLVMDLLImportLinkage is no longer supported.");
1879  break;
1880  case LLVMDLLExportLinkage:
1881  LLVM_DEBUG(
1882  errs()
1883  << "LLVMSetLinkage(): LLVMDLLExportLinkage is no longer supported.");
1884  break;
1887  break;
1888  case LLVMGhostLinkage:
1889  LLVM_DEBUG(
1890  errs() << "LLVMSetLinkage(): LLVMGhostLinkage is no longer supported.");
1891  break;
1892  case LLVMCommonLinkage:
1894  break;
1895  }
1896 }
1897 
1898 const char *LLVMGetSection(LLVMValueRef Global) {
1899  // Using .data() is safe because of how GlobalObject::setSection is
1900  // implemented.
1901  return unwrap<GlobalValue>(Global)->getSection().data();
1902 }
1903 
1904 void LLVMSetSection(LLVMValueRef Global, const char *Section) {
1905  unwrap<GlobalObject>(Global)->setSection(Section);
1906 }
1907 
1909  return static_cast<LLVMVisibility>(
1910  unwrap<GlobalValue>(Global)->getVisibility());
1911 }
1912 
1914  unwrap<GlobalValue>(Global)
1915  ->setVisibility(static_cast<GlobalValue::VisibilityTypes>(Viz));
1916 }
1917 
1919  return static_cast<LLVMDLLStorageClass>(
1920  unwrap<GlobalValue>(Global)->getDLLStorageClass());
1921 }
1922 
1924  unwrap<GlobalValue>(Global)->setDLLStorageClass(
1925  static_cast<GlobalValue::DLLStorageClassTypes>(Class));
1926 }
1927 
1929  switch (unwrap<GlobalValue>(Global)->getUnnamedAddr()) {
1931  return LLVMNoUnnamedAddr;
1933  return LLVMLocalUnnamedAddr;
1935  return LLVMGlobalUnnamedAddr;
1936  }
1937  llvm_unreachable("Unknown UnnamedAddr kind!");
1938 }
1939 
1941  GlobalValue *GV = unwrap<GlobalValue>(Global);
1942 
1943  switch (UnnamedAddr) {
1944  case LLVMNoUnnamedAddr:
1946  case LLVMLocalUnnamedAddr:
1948  case LLVMGlobalUnnamedAddr:
1950  }
1951 }
1952 
1954  return unwrap<GlobalValue>(Global)->hasGlobalUnnamedAddr();
1955 }
1956 
1957 void LLVMSetUnnamedAddr(LLVMValueRef Global, LLVMBool HasUnnamedAddr) {
1958  unwrap<GlobalValue>(Global)->setUnnamedAddr(
1959  HasUnnamedAddr ? GlobalValue::UnnamedAddr::Global
1961 }
1962 
1964  return wrap(unwrap<GlobalValue>(Global)->getValueType());
1965 }
1966 
1967 /*--.. Operations on global variables, load and store instructions .........--*/
1968 
1970  Value *P = unwrap<Value>(V);
1971  if (GlobalValue *GV = dyn_cast<GlobalValue>(P))
1972  return GV->getAlignment();
1973  if (AllocaInst *AI = dyn_cast<AllocaInst>(P))
1974  return AI->getAlignment();
1975  if (LoadInst *LI = dyn_cast<LoadInst>(P))
1976  return LI->getAlignment();
1977  if (StoreInst *SI = dyn_cast<StoreInst>(P))
1978  return SI->getAlignment();
1979 
1981  "only GlobalValue, AllocaInst, LoadInst and StoreInst have alignment");
1982 }
1983 
1984 void LLVMSetAlignment(LLVMValueRef V, unsigned Bytes) {
1985  Value *P = unwrap<Value>(V);
1986  if (GlobalObject *GV = dyn_cast<GlobalObject>(P))
1987  GV->setAlignment(Bytes);
1988  else if (AllocaInst *AI = dyn_cast<AllocaInst>(P))
1989  AI->setAlignment(Bytes);
1990  else if (LoadInst *LI = dyn_cast<LoadInst>(P))
1991  LI->setAlignment(Bytes);
1992  else if (StoreInst *SI = dyn_cast<StoreInst>(P))
1993  SI->setAlignment(Bytes);
1994  else
1996  "only GlobalValue, AllocaInst, LoadInst and StoreInst have alignment");
1997 }
1998 
2000  size_t *NumEntries) {
2001  return llvm_getMetadata(NumEntries, [&Value](MetadataEntries &Entries) {
2002  if (Instruction *Instr = dyn_cast<Instruction>(unwrap(Value))) {
2003  Instr->getAllMetadata(Entries);
2004  } else {
2005  unwrap<GlobalObject>(Value)->getAllMetadata(Entries);
2006  }
2007  });
2008 }
2009 
2011  unsigned Index) {
2013  static_cast<LLVMOpaqueValueMetadataEntry>(Entries[Index]);
2014  return MVE.Kind;
2015 }
2016 
2019  unsigned Index) {
2021  static_cast<LLVMOpaqueValueMetadataEntry>(Entries[Index]);
2022  return MVE.Metadata;
2023 }
2024 
2026  free(Entries);
2027 }
2028 
2030  LLVMMetadataRef MD) {
2031  unwrap<GlobalObject>(Global)->setMetadata(Kind, unwrap<MDNode>(MD));
2032 }
2033 
2035  unwrap<GlobalObject>(Global)->eraseMetadata(Kind);
2036 }
2037 
2039  unwrap<GlobalObject>(Global)->clearMetadata();
2040 }
2041 
2042 /*--.. Operations on global variables ......................................--*/
2043 
2045  return wrap(new GlobalVariable(*unwrap(M), unwrap(Ty), false,
2046  GlobalValue::ExternalLinkage, nullptr, Name));
2047 }
2048 
2050  const char *Name,
2051  unsigned AddressSpace) {
2052  return wrap(new GlobalVariable(*unwrap(M), unwrap(Ty), false,
2053  GlobalValue::ExternalLinkage, nullptr, Name,
2055  AddressSpace));
2056 }
2057 
2059  return wrap(unwrap(M)->getNamedGlobal(Name));
2060 }
2061 
2063  Module *Mod = unwrap(M);
2065  if (I == Mod->global_end())
2066  return nullptr;
2067  return wrap(&*I);
2068 }
2069 
2071  Module *Mod = unwrap(M);
2073  if (I == Mod->global_begin())
2074  return nullptr;
2075  return wrap(&*--I);
2076 }
2077 
2079  GlobalVariable *GV = unwrap<GlobalVariable>(GlobalVar);
2081  if (++I == GV->getParent()->global_end())
2082  return nullptr;
2083  return wrap(&*I);
2084 }
2085 
2087  GlobalVariable *GV = unwrap<GlobalVariable>(GlobalVar);
2089  if (I == GV->getParent()->global_begin())
2090  return nullptr;
2091  return wrap(&*--I);
2092 }
2093 
2095  unwrap<GlobalVariable>(GlobalVar)->eraseFromParent();
2096 }
2097 
2099  GlobalVariable* GV = unwrap<GlobalVariable>(GlobalVar);
2100  if ( !GV->hasInitializer() )
2101  return nullptr;
2102  return wrap(GV->getInitializer());
2103 }
2104 
2106  unwrap<GlobalVariable>(GlobalVar)
2107  ->setInitializer(unwrap<Constant>(ConstantVal));
2108 }
2109 
2111  return unwrap<GlobalVariable>(GlobalVar)->isThreadLocal();
2112 }
2113 
2115  unwrap<GlobalVariable>(GlobalVar)->setThreadLocal(IsThreadLocal != 0);
2116 }
2117 
2119  return unwrap<GlobalVariable>(GlobalVar)->isConstant();
2120 }
2121 
2123  unwrap<GlobalVariable>(GlobalVar)->setConstant(IsConstant != 0);
2124 }
2125 
2127  switch (unwrap<GlobalVariable>(GlobalVar)->getThreadLocalMode()) {
2129  return LLVMNotThreadLocal;
2133  return LLVMLocalDynamicTLSModel;
2135  return LLVMInitialExecTLSModel;
2137  return LLVMLocalExecTLSModel;
2138  }
2139 
2140  llvm_unreachable("Invalid GlobalVariable thread local mode");
2141 }
2142 
2144  GlobalVariable *GV = unwrap<GlobalVariable>(GlobalVar);
2145 
2146  switch (Mode) {
2147  case LLVMNotThreadLocal:
2149  break;
2152  break;
2155  break;
2158  break;
2159  case LLVMLocalExecTLSModel:
2161  break;
2162  }
2163 }
2164 
2166  return unwrap<GlobalVariable>(GlobalVar)->isExternallyInitialized();
2167 }
2168 
2170  unwrap<GlobalVariable>(GlobalVar)->setExternallyInitialized(IsExtInit);
2171 }
2172 
2173 /*--.. Operations on aliases ......................................--*/
2174 
2176  const char *Name) {
2177  auto *PTy = cast<PointerType>(unwrap(Ty));
2178  return wrap(GlobalAlias::create(PTy->getElementType(), PTy->getAddressSpace(),
2180  unwrap<Constant>(Aliasee), unwrap(M)));
2181 }
2182 
2184  const char *Name, size_t NameLen) {
2185  return wrap(unwrap(M)->getNamedAlias(Name));
2186 }
2187 
2189  Module *Mod = unwrap(M);
2191  if (I == Mod->alias_end())
2192  return nullptr;
2193  return wrap(&*I);
2194 }
2195 
2197  Module *Mod = unwrap(M);
2199  if (I == Mod->alias_begin())
2200  return nullptr;
2201  return wrap(&*--I);
2202 }
2203 
2205  GlobalAlias *Alias = unwrap<GlobalAlias>(GA);
2206  Module::alias_iterator I(Alias);
2207  if (++I == Alias->getParent()->alias_end())
2208  return nullptr;
2209  return wrap(&*I);
2210 }
2211 
2213  GlobalAlias *Alias = unwrap<GlobalAlias>(GA);
2214  Module::alias_iterator I(Alias);
2215  if (I == Alias->getParent()->alias_begin())
2216  return nullptr;
2217  return wrap(&*--I);
2218 }
2219 
2221  return wrap(unwrap<GlobalAlias>(Alias)->getAliasee());
2222 }
2223 
2225  unwrap<GlobalAlias>(Alias)->setAliasee(unwrap<Constant>(Aliasee));
2226 }
2227 
2228 /*--.. Operations on functions .............................................--*/
2229 
2231  LLVMTypeRef FunctionTy) {
2232  return wrap(Function::Create(unwrap<FunctionType>(FunctionTy),
2234 }
2235 
2237  return wrap(unwrap(M)->getFunction(Name));
2238 }
2239 
2241  Module *Mod = unwrap(M);
2242  Module::iterator I = Mod->begin();
2243  if (I == Mod->end())
2244  return nullptr;
2245  return wrap(&*I);
2246 }
2247 
2249  Module *Mod = unwrap(M);
2250  Module::iterator I = Mod->end();
2251  if (I == Mod->begin())
2252  return nullptr;
2253  return wrap(&*--I);
2254 }
2255 
2257  Function *Func = unwrap<Function>(Fn);
2258  Module::iterator I(Func);
2259  if (++I == Func->getParent()->end())
2260  return nullptr;
2261  return wrap(&*I);
2262 }
2263 
2265  Function *Func = unwrap<Function>(Fn);
2266  Module::iterator I(Func);
2267  if (I == Func->getParent()->begin())
2268  return nullptr;
2269  return wrap(&*--I);
2270 }
2271 
2273  unwrap<Function>(Fn)->eraseFromParent();
2274 }
2275 
2277  return unwrap<Function>(Fn)->hasPersonalityFn();
2278 }
2279 
2281  return wrap(unwrap<Function>(Fn)->getPersonalityFn());
2282 }
2283 
2285  unwrap<Function>(Fn)->setPersonalityFn(unwrap<Constant>(PersonalityFn));
2286 }
2287 
2289  if (Function *F = dyn_cast<Function>(unwrap(Fn)))
2290  return F->getIntrinsicID();
2291  return 0;
2292 }
2293 
2295  assert(ID < llvm::Intrinsic::num_intrinsics && "Intrinsic ID out of range");
2296  return llvm::Intrinsic::ID(ID);
2297 }
2298 
2300  unsigned ID,
2301  LLVMTypeRef *ParamTypes,
2302  size_t ParamCount) {
2303  ArrayRef<Type*> Tys(unwrap(ParamTypes), ParamCount);
2304  auto IID = llvm_map_to_intrinsic_id(ID);
2305  return wrap(llvm::Intrinsic::getDeclaration(unwrap(Mod), IID, Tys));
2306 }
2307 
2308 const char *LLVMIntrinsicGetName(unsigned ID, size_t *NameLength) {
2309  auto IID = llvm_map_to_intrinsic_id(ID);
2310  auto Str = llvm::Intrinsic::getName(IID);
2311  *NameLength = Str.size();
2312  return Str.data();
2313 }
2314 
2316  LLVMTypeRef *ParamTypes, size_t ParamCount) {
2317  auto IID = llvm_map_to_intrinsic_id(ID);
2318  ArrayRef<Type*> Tys(unwrap(ParamTypes), ParamCount);
2319  return wrap(llvm::Intrinsic::getType(*unwrap(Ctx), IID, Tys));
2320 }
2321 
2323  LLVMTypeRef *ParamTypes,
2324  size_t ParamCount,
2325  size_t *NameLength) {
2326  auto IID = llvm_map_to_intrinsic_id(ID);
2327  ArrayRef<Type*> Tys(unwrap(ParamTypes), ParamCount);
2328  auto Str = llvm::Intrinsic::getName(IID, Tys);
2329  *NameLength = Str.length();
2330  return strdup(Str.c_str());
2331 }
2332 
2334  auto IID = llvm_map_to_intrinsic_id(ID);
2335  return llvm::Intrinsic::isOverloaded(IID);
2336 }
2337 
2339  return unwrap<Function>(Fn)->getCallingConv();
2340 }
2341 
2342 void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC) {
2343  return unwrap<Function>(Fn)->setCallingConv(
2344  static_cast<CallingConv::ID>(CC));
2345 }
2346 
2347 const char *LLVMGetGC(LLVMValueRef Fn) {
2348  Function *F = unwrap<Function>(Fn);
2349  return F->hasGC()? F->getGC().c_str() : nullptr;
2350 }
2351 
2352 void LLVMSetGC(LLVMValueRef Fn, const char *GC) {
2353  Function *F = unwrap<Function>(Fn);
2354  if (GC)
2355  F->setGC(GC);
2356  else
2357  F->clearGC();
2358 }
2359 
2361  LLVMAttributeRef A) {
2362  unwrap<Function>(F)->addAttribute(Idx, unwrap(A));
2363 }
2364 
2366  auto AS = unwrap<Function>(F)->getAttributes().getAttributes(Idx);
2367  return AS.getNumAttributes();
2368 }
2369 
2372  auto AS = unwrap<Function>(F)->getAttributes().getAttributes(Idx);
2373  for (auto A : AS)
2374  *Attrs++ = wrap(A);
2375 }
2376 
2378  LLVMAttributeIndex Idx,
2379  unsigned KindID) {
2380  return wrap(unwrap<Function>(F)->getAttribute(Idx,
2381  (Attribute::AttrKind)KindID));
2382 }
2383 
2385  LLVMAttributeIndex Idx,
2386  const char *K, unsigned KLen) {
2387  return wrap(unwrap<Function>(F)->getAttribute(Idx, StringRef(K, KLen)));
2388 }
2389 
2391  unsigned KindID) {
2392  unwrap<Function>(F)->removeAttribute(Idx, (Attribute::AttrKind)KindID);
2393 }
2394 
2396  const char *K, unsigned KLen) {
2397  unwrap<Function>(F)->removeAttribute(Idx, StringRef(K, KLen));
2398 }
2399 
2401  const char *V) {
2402  Function *Func = unwrap<Function>(Fn);
2403  Attribute Attr = Attribute::get(Func->getContext(), A, V);
2405 }
2406 
2407 /*--.. Operations on parameters ............................................--*/
2408 
2410  // This function is strictly redundant to
2411  // LLVMCountParamTypes(LLVMGetElementType(LLVMTypeOf(FnRef)))
2412  return unwrap<Function>(FnRef)->arg_size();
2413 }
2414 
2415 void LLVMGetParams(LLVMValueRef FnRef, LLVMValueRef *ParamRefs) {
2416  Function *Fn = unwrap<Function>(FnRef);
2417  for (Function::arg_iterator I = Fn->arg_begin(),
2418  E = Fn->arg_end(); I != E; I++)
2419  *ParamRefs++ = wrap(&*I);
2420 }
2421 
2422 LLVMValueRef LLVMGetParam(LLVMValueRef FnRef, unsigned index) {
2423  Function *Fn = unwrap<Function>(FnRef);
2424  return wrap(&Fn->arg_begin()[index]);
2425 }
2426 
2428  return wrap(unwrap<Argument>(V)->getParent());
2429 }
2430 
2432  Function *Func = unwrap<Function>(Fn);
2434  if (I == Func->arg_end())
2435  return nullptr;
2436  return wrap(&*I);
2437 }
2438 
2440  Function *Func = unwrap<Function>(Fn);
2441  Function::arg_iterator I = Func->arg_end();
2442  if (I == Func->arg_begin())
2443  return nullptr;
2444  return wrap(&*--I);
2445 }
2446 
2448  Argument *A = unwrap<Argument>(Arg);
2449  Function *Fn = A->getParent();
2450  if (A->getArgNo() + 1 >= Fn->arg_size())
2451  return nullptr;
2452  return wrap(&Fn->arg_begin()[A->getArgNo() + 1]);
2453 }
2454 
2456  Argument *A = unwrap<Argument>(Arg);
2457  if (A->getArgNo() == 0)
2458  return nullptr;
2459  return wrap(&A->getParent()->arg_begin()[A->getArgNo() - 1]);
2460 }
2461 
2462 void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align) {
2463  Argument *A = unwrap<Argument>(Arg);
2465 }
2466 
2467 /*--.. Operations on basic blocks ..........................................--*/
2468 
2470  return wrap(static_cast<Value*>(unwrap(BB)));
2471 }
2472 
2474  return isa<BasicBlock>(unwrap(Val));
2475 }
2476 
2478  return wrap(unwrap<BasicBlock>(Val));
2479 }
2480 
2482  return unwrap(BB)->getName().data();
2483 }
2484 
2486  return wrap(unwrap(BB)->getParent());
2487 }
2488 
2490  return wrap(unwrap(BB)->getTerminator());
2491 }
2492 
2494  return unwrap<Function>(FnRef)->size();
2495 }
2496 
2497 void LLVMGetBasicBlocks(LLVMValueRef FnRef, LLVMBasicBlockRef *BasicBlocksRefs){
2498  Function *Fn = unwrap<Function>(FnRef);
2499  for (BasicBlock &BB : *Fn)
2500  *BasicBlocksRefs++ = wrap(&BB);
2501 }
2502 
2504  return wrap(&unwrap<Function>(Fn)->getEntryBlock());
2505 }
2506 
2508  Function *Func = unwrap<Function>(Fn);
2509  Function::iterator I = Func->begin();
2510  if (I == Func->end())
2511  return nullptr;
2512  return wrap(&*I);
2513 }
2514 
2516  Function *Func = unwrap<Function>(Fn);
2517  Function::iterator I = Func->end();
2518  if (I == Func->begin())
2519  return nullptr;
2520  return wrap(&*--I);
2521 }
2522 
2524  BasicBlock *Block = unwrap(BB);
2525  Function::iterator I(Block);
2526  if (++I == Block->getParent()->end())
2527  return nullptr;
2528  return wrap(&*I);
2529 }
2530 
2532  BasicBlock *Block = unwrap(BB);
2533  Function::iterator I(Block);
2534  if (I == Block->getParent()->begin())
2535  return nullptr;
2536  return wrap(&*--I);
2537 }
2538 
2540  const char *Name) {
2541  return wrap(llvm::BasicBlock::Create(*unwrap(C), Name));
2542 }
2543 
2545  LLVMValueRef FnRef,
2546  const char *Name) {
2547  return wrap(BasicBlock::Create(*unwrap(C), Name, unwrap<Function>(FnRef)));
2548 }
2549 
2551  return LLVMAppendBasicBlockInContext(LLVMGetGlobalContext(), FnRef, Name);
2552 }
2553 
2555  LLVMBasicBlockRef BBRef,
2556  const char *Name) {
2557  BasicBlock *BB = unwrap(BBRef);
2558  return wrap(BasicBlock::Create(*unwrap(C), Name, BB->getParent(), BB));
2559 }
2560 
2562  const char *Name) {
2563  return LLVMInsertBasicBlockInContext(LLVMGetGlobalContext(), BBRef, Name);
2564 }
2565 
2567  unwrap(BBRef)->eraseFromParent();
2568 }
2569 
2571  unwrap(BBRef)->removeFromParent();
2572 }
2573 
2575  unwrap(BB)->moveBefore(unwrap(MovePos));
2576 }
2577 
2579  unwrap(BB)->moveAfter(unwrap(MovePos));
2580 }
2581 
2582 /*--.. Operations on instructions ..........................................--*/
2583 
2585  return wrap(unwrap<Instruction>(Inst)->getParent());
2586 }
2587 
2589  BasicBlock *Block = unwrap(BB);
2590  BasicBlock::iterator I = Block->begin();
2591  if (I == Block->end())
2592  return nullptr;
2593  return wrap(&*I);
2594 }
2595 
2597  BasicBlock *Block = unwrap(BB);
2598  BasicBlock::iterator I = Block->end();
2599  if (I == Block->begin())
2600  return nullptr;
2601  return wrap(&*--I);
2602 }
2603 
2605  Instruction *Instr = unwrap<Instruction>(Inst);
2606  BasicBlock::iterator I(Instr);
2607  if (++I == Instr->getParent()->end())
2608  return nullptr;
2609  return wrap(&*I);
2610 }
2611 
2613  Instruction *Instr = unwrap<Instruction>(Inst);
2614  BasicBlock::iterator I(Instr);
2615  if (I == Instr->getParent()->begin())
2616  return nullptr;
2617  return wrap(&*--I);
2618 }
2619 
2621  unwrap<Instruction>(Inst)->removeFromParent();
2622 }
2623 
2625  unwrap<Instruction>(Inst)->eraseFromParent();
2626 }
2627 
2629  if (ICmpInst *I = dyn_cast<ICmpInst>(unwrap(Inst)))
2630  return (LLVMIntPredicate)I->getPredicate();
2631  if (ConstantExpr *CE = dyn_cast<ConstantExpr>(unwrap(Inst)))
2632  if (CE->getOpcode() == Instruction::ICmp)
2633  return (LLVMIntPredicate)CE->getPredicate();
2634  return (LLVMIntPredicate)0;
2635 }
2636 
2638  if (FCmpInst *I = dyn_cast<FCmpInst>(unwrap(Inst)))
2639  return (LLVMRealPredicate)I->getPredicate();
2640  if (ConstantExpr *CE = dyn_cast<ConstantExpr>(unwrap(Inst)))
2641  if (CE->getOpcode() == Instruction::FCmp)
2642  return (LLVMRealPredicate)CE->getPredicate();
2643  return (LLVMRealPredicate)0;
2644 }
2645 
2647  if (Instruction *C = dyn_cast<Instruction>(unwrap(Inst)))
2648  return map_to_llvmopcode(C->getOpcode());
2649  return (LLVMOpcode)0;
2650 }
2651 
2653  if (Instruction *C = dyn_cast<Instruction>(unwrap(Inst)))
2654  return wrap(C->clone());
2655  return nullptr;
2656 }
2657 
2660  return (I && I->isTerminator()) ? wrap(I) : nullptr;
2661 }
2662 
2664  if (FuncletPadInst *FPI = dyn_cast<FuncletPadInst>(unwrap(Instr))) {
2665  return FPI->getNumArgOperands();
2666  }
2667  return unwrap<CallBase>(Instr)->getNumArgOperands();
2668 }
2669 
2670 /*--.. Call and invoke instructions ........................................--*/
2671 
2673  return unwrap<CallBase>(Instr)->getCallingConv();
2674 }
2675 
2676 void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC) {
2677  return unwrap<CallBase>(Instr)->setCallingConv(
2678  static_cast<CallingConv::ID>(CC));
2679 }
2680 
2681 void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
2682  unsigned align) {
2683  auto *Call = unwrap<CallBase>(Instr);
2684  Attribute AlignAttr = Attribute::getWithAlignment(Call->getContext(), align);
2685  Call->addAttribute(index, AlignAttr);
2686 }
2687 
2689  LLVMAttributeRef A) {
2690  unwrap<CallBase>(C)->addAttribute(Idx, unwrap(A));
2691 }
2692 
2694  LLVMAttributeIndex Idx) {
2695  auto *Call = unwrap<CallBase>(C);
2696  auto AS = Call->getAttributes().getAttributes(Idx);
2697  return AS.getNumAttributes();
2698 }
2699 
2702  auto *Call = unwrap<CallBase>(C);
2703  auto AS = Call->getAttributes().getAttributes(Idx);
2704  for (auto A : AS)
2705  *Attrs++ = wrap(A);
2706 }
2707 
2709  LLVMAttributeIndex Idx,
2710  unsigned KindID) {
2711  return wrap(
2712  unwrap<CallBase>(C)->getAttribute(Idx, (Attribute::AttrKind)KindID));
2713 }
2714 
2716  LLVMAttributeIndex Idx,
2717  const char *K, unsigned KLen) {
2718  return wrap(unwrap<CallBase>(C)->getAttribute(Idx, StringRef(K, KLen)));
2719 }
2720 
2722  unsigned KindID) {
2723  unwrap<CallBase>(C)->removeAttribute(Idx, (Attribute::AttrKind)KindID);
2724 }
2725 
2727  const char *K, unsigned KLen) {
2728  unwrap<CallBase>(C)->removeAttribute(Idx, StringRef(K, KLen));
2729 }
2730 
2732  return wrap(unwrap<CallBase>(Instr)->getCalledValue());
2733 }
2734 
2736  return wrap(unwrap<CallBase>(Instr)->getFunctionType());
2737 }
2738 
2739 /*--.. Operations on call instructions (only) ..............................--*/
2740 
2742  return unwrap<CallInst>(Call)->isTailCall();
2743 }
2744 
2745 void LLVMSetTailCall(LLVMValueRef Call, LLVMBool isTailCall) {
2746  unwrap<CallInst>(Call)->setTailCall(isTailCall);
2747 }
2748 
2749 /*--.. Operations on invoke instructions (only) ............................--*/
2750 
2752  return wrap(unwrap<InvokeInst>(Invoke)->getNormalDest());
2753 }
2754 
2756  if (CleanupReturnInst *CRI = dyn_cast<CleanupReturnInst>(unwrap(Invoke))) {
2757  return wrap(CRI->getUnwindDest());
2758  } else if (CatchSwitchInst *CSI = dyn_cast<CatchSwitchInst>(unwrap(Invoke))) {
2759  return wrap(CSI->getUnwindDest());
2760  }
2761  return wrap(unwrap<InvokeInst>(Invoke)->getUnwindDest());
2762 }
2763 
2765  unwrap<InvokeInst>(Invoke)->setNormalDest(unwrap(B));
2766 }
2767 
2769  if (CleanupReturnInst *CRI = dyn_cast<CleanupReturnInst>(unwrap(Invoke))) {
2770  return CRI->setUnwindDest(unwrap(B));
2771  } else if (CatchSwitchInst *CSI = dyn_cast<CatchSwitchInst>(unwrap(Invoke))) {
2772  return CSI->setUnwindDest(unwrap(B));
2773  }
2774  unwrap<InvokeInst>(Invoke)->setUnwindDest(unwrap(B));
2775 }
2776 
2777 /*--.. Operations on terminators ...........................................--*/
2778 
2780  return unwrap<Instruction>(Term)->getNumSuccessors();
2781 }
2782 
2784  return wrap(unwrap<Instruction>(Term)->getSuccessor(i));
2785 }
2786 
2787 void LLVMSetSuccessor(LLVMValueRef Term, unsigned i, LLVMBasicBlockRef block) {
2788  return unwrap<Instruction>(Term)->setSuccessor(i, unwrap(block));
2789 }
2790 
2791 /*--.. Operations on branch instructions (only) ............................--*/
2792 
2794  return unwrap<BranchInst>(Branch)->isConditional();
2795 }
2796 
2798  return wrap(unwrap<BranchInst>(Branch)->getCondition());
2799 }
2800 
2802  return unwrap<BranchInst>(Branch)->setCondition(unwrap(Cond));
2803 }
2804 
2805 /*--.. Operations on switch instructions (only) ............................--*/
2806 
2808  return wrap(unwrap<SwitchInst>(Switch)->getDefaultDest());
2809 }
2810 
2811 /*--.. Operations on alloca instructions (only) ............................--*/
2812 
2814  return wrap(unwrap<AllocaInst>(Alloca)->getAllocatedType());
2815 }
2816 
2817 /*--.. Operations on gep instructions (only) ...............................--*/
2818 
2820  return unwrap<GetElementPtrInst>(GEP)->isInBounds();
2821 }
2822 
2824  return unwrap<GetElementPtrInst>(GEP)->setIsInBounds(InBounds);
2825 }
2826 
2827 /*--.. Operations on phi nodes .............................................--*/
2828 
2829 void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
2830  LLVMBasicBlockRef *IncomingBlocks, unsigned Count) {
2831  PHINode *PhiVal = unwrap<PHINode>(PhiNode);
2832  for (unsigned I = 0; I != Count; ++I)
2833  PhiVal->addIncoming(unwrap(IncomingValues[I]), unwrap(IncomingBlocks[I]));
2834 }
2835 
2836 unsigned LLVMCountIncoming(LLVMValueRef PhiNode) {
2837  return unwrap<PHINode>(PhiNode)->getNumIncomingValues();
2838 }
2839 
2841  return wrap(unwrap<PHINode>(PhiNode)->getIncomingValue(Index));
2842 }
2843 
2845  return wrap(unwrap<PHINode>(PhiNode)->getIncomingBlock(Index));
2846 }
2847 
2848 /*--.. Operations on extractvalue and insertvalue nodes ....................--*/
2849 
2851  auto *I = unwrap(Inst);
2852  if (auto *GEP = dyn_cast<GetElementPtrInst>(I))
2853  return GEP->getNumIndices();
2854  if (auto *EV = dyn_cast<ExtractValueInst>(I))
2855  return EV->getNumIndices();
2856  if (auto *IV = dyn_cast<InsertValueInst>(I))
2857  return IV->getNumIndices();
2858  if (auto *CE = dyn_cast<ConstantExpr>(I))
2859  return CE->getIndices().size();
2861  "LLVMGetNumIndices applies only to extractvalue and insertvalue!");
2862 }
2863 
2864 const unsigned *LLVMGetIndices(LLVMValueRef Inst) {
2865  auto *I = unwrap(Inst);
2866  if (auto *EV = dyn_cast<ExtractValueInst>(I))
2867  return EV->getIndices().data();
2868  if (auto *IV = dyn_cast<InsertValueInst>(I))
2869  return IV->getIndices().data();
2870  if (auto *CE = dyn_cast<ConstantExpr>(I))
2871  return CE->getIndices().data();
2873  "LLVMGetIndices applies only to extractvalue and insertvalue!");
2874 }
2875 
2876 
2877 /*===-- Instruction builders ----------------------------------------------===*/
2878 
2880  return wrap(new IRBuilder<>(*unwrap(C)));
2881 }
2882 
2885 }
2886 
2888  LLVMValueRef Instr) {
2889  BasicBlock *BB = unwrap(Block);
2890  auto I = Instr ? unwrap<Instruction>(Instr)->getIterator() : BB->end();
2891  unwrap(Builder)->SetInsertPoint(BB, I);
2892 }
2893 
2895  Instruction *I = unwrap<Instruction>(Instr);
2896  unwrap(Builder)->SetInsertPoint(I->getParent(), I->getIterator());
2897 }
2898 
2900  BasicBlock *BB = unwrap(Block);
2901  unwrap(Builder)->SetInsertPoint(BB);
2902 }
2903 
2905  return wrap(unwrap(Builder)->GetInsertBlock());
2906 }
2907 
2909  unwrap(Builder)->ClearInsertionPoint();
2910 }
2911 
2913  unwrap(Builder)->Insert(unwrap<Instruction>(Instr));
2914 }
2915 
2917  const char *Name) {
2918  unwrap(Builder)->Insert(unwrap<Instruction>(Instr), Name);
2919 }
2920 
2922  delete unwrap(Builder);
2923 }
2924 
2925 /*--.. Metadata builders ...................................................--*/
2926 
2928  MDNode *Loc =
2929  L ? cast<MDNode>(unwrap<MetadataAsValue>(L)->getMetadata()) : nullptr;
2930  unwrap(Builder)->SetCurrentDebugLocation(DebugLoc(Loc));
2931 }
2932 
2934  LLVMContext &Context = unwrap(Builder)->getContext();
2935  return wrap(MetadataAsValue::get(
2936  Context, unwrap(Builder)->getCurrentDebugLocation().getAsMDNode()));
2937 }
2938 
2940  unwrap(Builder)->SetInstDebugLocation(unwrap<Instruction>(Inst));
2941 }
2942 
2943 
2944 /*--.. Instruction builders ................................................--*/
2945 
2947  return wrap(unwrap(B)->CreateRetVoid());
2948 }
2949 
2951  return wrap(unwrap(B)->CreateRet(unwrap(V)));
2952 }
2953 
2955  unsigned N) {
2956  return wrap(unwrap(B)->CreateAggregateRet(unwrap(RetVals), N));
2957 }
2958 
2960  return wrap(unwrap(B)->CreateBr(unwrap(Dest)));
2961 }
2962 
2965  return wrap(unwrap(B)->CreateCondBr(unwrap(If), unwrap(Then), unwrap(Else)));
2966 }
2967 
2969  LLVMBasicBlockRef Else, unsigned NumCases) {
2970  return wrap(unwrap(B)->CreateSwitch(unwrap(V), unwrap(Else), NumCases));
2971 }
2972 
2974  unsigned NumDests) {
2975  return wrap(unwrap(B)->CreateIndirectBr(unwrap(Addr), NumDests));
2976 }
2977 
2979  LLVMValueRef *Args, unsigned NumArgs,
2981  const char *Name) {
2982  Value *V = unwrap(Fn);
2983  FunctionType *FnT =
2984  cast<FunctionType>(cast<PointerType>(V->getType())->getElementType());
2985 
2986  return wrap(
2987  unwrap(B)->CreateInvoke(FnT, unwrap(Fn), unwrap(Then), unwrap(Catch),
2988  makeArrayRef(unwrap(Args), NumArgs), Name));
2989 }
2990 
2992  LLVMValueRef *Args, unsigned NumArgs,
2994  const char *Name) {
2995  return wrap(unwrap(B)->CreateInvoke(
2996  unwrap<FunctionType>(Ty), unwrap(Fn), unwrap(Then), unwrap(Catch),
2997  makeArrayRef(unwrap(Args), NumArgs), Name));
2998 }
2999 
3001  LLVMValueRef PersFn, unsigned NumClauses,
3002  const char *Name) {
3003  // The personality used to live on the landingpad instruction, but now it
3004  // lives on the parent function. For compatibility, take the provided
3005  // personality and put it on the parent function.
3006  if (PersFn)
3007  unwrap(B)->GetInsertBlock()->getParent()->setPersonalityFn(
3008  cast<Function>(unwrap(PersFn)));
3009  return wrap(unwrap(B)->CreateLandingPad(unwrap(Ty), NumClauses, Name));
3010 }
3011 
3013  LLVMValueRef *Args, unsigned NumArgs,
3014  const char *Name) {
3015  return wrap(unwrap(B)->CreateCatchPad(unwrap(ParentPad),
3016  makeArrayRef(unwrap(Args), NumArgs),
3017  Name));
3018 }
3019 
3021  LLVMValueRef *Args, unsigned NumArgs,
3022  const char *Name) {
3023  if (ParentPad == nullptr) {
3024  Type *Ty = Type::getTokenTy(unwrap(B)->getContext());
3025  ParentPad = wrap(Constant::getNullValue(Ty));
3026  }
3027  return wrap(unwrap(B)->CreateCleanupPad(unwrap(ParentPad),
3028  makeArrayRef(unwrap(Args), NumArgs),
3029  Name));
3030 }
3031 
3033  return wrap(unwrap(B)->CreateResume(unwrap(Exn)));
3034 }
3035 
3037  LLVMBasicBlockRef UnwindBB,
3038  unsigned NumHandlers, const char *Name) {
3039  if (ParentPad == nullptr) {
3040  Type *Ty = Type::getTokenTy(unwrap(B)->getContext());
3041  ParentPad = wrap(Constant::getNullValue(Ty));
3042  }
3043  return wrap(unwrap(B)->CreateCatchSwitch(unwrap(ParentPad), unwrap(UnwindBB),
3044  NumHandlers, Name));
3045 }
3046 
3048  LLVMBasicBlockRef BB) {
3049  return wrap(unwrap(B)->CreateCatchRet(unwrap<CatchPadInst>(CatchPad),
3050  unwrap(BB)));
3051 }
3052 
3054  LLVMBasicBlockRef BB) {
3055  return wrap(unwrap(B)->CreateCleanupRet(unwrap<CleanupPadInst>(CatchPad),
3056  unwrap(BB)));
3057 }
3058 
3060  return wrap(unwrap(B)->CreateUnreachable());
3061 }
3062 
3064  LLVMBasicBlockRef Dest) {
3065  unwrap<SwitchInst>(Switch)->addCase(unwrap<ConstantInt>(OnVal), unwrap(Dest));
3066 }
3067 
3069  unwrap<IndirectBrInst>(IndirectBr)->addDestination(unwrap(Dest));
3070 }
3071 
3072 unsigned LLVMGetNumClauses(LLVMValueRef LandingPad) {
3073  return unwrap<LandingPadInst>(LandingPad)->getNumClauses();
3074 }
3075 
3076 LLVMValueRef LLVMGetClause(LLVMValueRef LandingPad, unsigned Idx) {
3077  return wrap(unwrap<LandingPadInst>(LandingPad)->getClause(Idx));
3078 }
3079 
3080 void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal) {
3081  unwrap<LandingPadInst>(LandingPad)->
3082  addClause(cast<Constant>(unwrap(ClauseVal)));
3083 }
3084 
3086  return unwrap<LandingPadInst>(LandingPad)->isCleanup();
3087 }
3088 
3089 void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val) {
3090  unwrap<LandingPadInst>(LandingPad)->setCleanup(Val);
3091 }
3092 
3094  unwrap<CatchSwitchInst>(CatchSwitch)->addHandler(unwrap(Dest));
3095 }
3096 
3097 unsigned LLVMGetNumHandlers(LLVMValueRef CatchSwitch) {
3098  return unwrap<CatchSwitchInst>(CatchSwitch)->getNumHandlers();
3099 }
3100 
3101 void LLVMGetHandlers(LLVMValueRef CatchSwitch, LLVMBasicBlockRef *Handlers) {
3102  CatchSwitchInst *CSI = unwrap<CatchSwitchInst>(CatchSwitch);
3104  E = CSI->handler_end(); I != E; ++I)
3105  *Handlers++ = wrap(*I);
3106 }
3107 
3109  return wrap(unwrap<CatchPadInst>(CatchPad)->getCatchSwitch());
3110 }
3111 
3113  unwrap<CatchPadInst>(CatchPad)
3114  ->setCatchSwitch(unwrap<CatchSwitchInst>(CatchSwitch));
3115 }
3116 
3117 /*--.. Funclets ...........................................................--*/
3118 
3120  return wrap(unwrap<FuncletPadInst>(Funclet)->getArgOperand(i));
3121 }
3122 
3123 void LLVMSetArgOperand(LLVMValueRef Funclet, unsigned i, LLVMValueRef value) {
3124  unwrap<FuncletPadInst>(Funclet)->setArgOperand(i, unwrap(value));
3125 }
3126 
3127 /*--.. Arithmetic ..........................................................--*/
3128 
3130  const char *Name) {
3131  return wrap(unwrap(B)->CreateAdd(unwrap(LHS), unwrap(RHS), Name));
3132 }
3133 
3135  const char *Name) {
3136  return wrap(unwrap(B)->CreateNSWAdd(unwrap(LHS), unwrap(RHS), Name));
3137 }
3138 
3140  const char *Name) {
3141  return wrap(unwrap(B)->CreateNUWAdd(unwrap(LHS), unwrap(RHS), Name));
3142 }
3143 
3145  const char *Name) {
3146  return wrap(unwrap(B)->CreateFAdd(unwrap(LHS), unwrap(RHS), Name));
3147 }
3148 
3150  const char *Name) {
3151  return wrap(unwrap(B)->CreateSub(unwrap(LHS), unwrap(RHS), Name));
3152 }
3153 
3155  const char *Name) {
3156  return wrap(unwrap(B)->CreateNSWSub(unwrap(LHS), unwrap(RHS), Name));
3157 }
3158 
3160  const char *Name) {
3161  return wrap(unwrap(B)->CreateNUWSub(unwrap(LHS), unwrap(RHS), Name));
3162 }
3163 
3165  const char *Name) {
3166  return wrap(unwrap(B)->CreateFSub(unwrap(LHS), unwrap(RHS), Name));
3167 }
3168 
3170  const char *Name) {
3171  return wrap(unwrap(B)->CreateMul(unwrap(LHS), unwrap(RHS), Name));
3172 }
3173 
3175  const char *Name) {
3176  return wrap(unwrap(B)->CreateNSWMul(unwrap(LHS), unwrap(RHS), Name));
3177 }
3178 
3180  const char *Name) {
3181  return wrap(unwrap(B)->CreateNUWMul(unwrap(LHS), unwrap(RHS), Name));
3182 }
3183 
3185  const char *Name) {
3186  return wrap(unwrap(B)->CreateFMul(unwrap(LHS), unwrap(RHS), Name));
3187 }
3188 
3190  const char *Name) {
3191  return wrap(unwrap(B)->CreateUDiv(unwrap(LHS), unwrap(RHS), Name));
3192 }
3193 
3195  LLVMValueRef RHS, const char *Name) {
3196  return wrap(unwrap(B)->CreateExactUDiv(unwrap(LHS), unwrap(RHS), Name));
3197 }
3198 
3200  const char *Name) {
3201  return wrap(unwrap(B)->CreateSDiv(unwrap(LHS), unwrap(RHS), Name));
3202 }
3203 
3205  LLVMValueRef RHS, const char *Name) {
3206  return wrap(unwrap(B)->CreateExactSDiv(unwrap(LHS), unwrap(RHS), Name));
3207 }
3208 
3210  const char *Name) {
3211  return wrap(unwrap(B)->CreateFDiv(unwrap(LHS), unwrap(RHS), Name));
3212 }
3213 
3215  const char *Name) {
3216  return wrap(unwrap(B)->CreateURem(unwrap(LHS), unwrap(RHS), Name));
3217 }
3218 
3220  const char *Name) {
3221  return wrap(unwrap(B)->CreateSRem(unwrap(LHS), unwrap(RHS), Name));
3222 }
3223 
3225  const char *Name) {
3226  return wrap(unwrap(B)->CreateFRem(unwrap(LHS), unwrap(RHS), Name));
3227 }
3228 
3230  const char *Name) {
3231  return wrap(unwrap(B)->CreateShl(unwrap(LHS), unwrap(RHS), Name));
3232 }
3233 
3235  const char *Name) {
3236  return wrap(unwrap(B)->CreateLShr(unwrap(LHS), unwrap(RHS), Name));
3237 }
3238 
3240  const char *Name) {
3241  return wrap(unwrap(B)->CreateAShr(unwrap(LHS), unwrap(RHS), Name));
3242 }
3243 
3245  const char *Name) {
3246  return wrap(unwrap(B)->CreateAnd(unwrap(LHS), unwrap(RHS), Name));
3247 }
3248 
3250  const char *Name) {
3251  return wrap(unwrap(B)->CreateOr(unwrap(LHS), unwrap(RHS), Name));
3252 }
3253 
3255  const char *Name) {
3256  return wrap(unwrap(B)->CreateXor(unwrap(LHS), unwrap(RHS), Name));
3257 }
3258 
3260  LLVMValueRef LHS, LLVMValueRef RHS,
3261  const char *Name) {
3262  return wrap(unwrap(B)->CreateBinOp(Instruction::BinaryOps(map_from_llvmopcode(Op)), unwrap(LHS),
3263  unwrap(RHS), Name));
3264 }
3265 
3267  return wrap(unwrap(B)->CreateNeg(unwrap(V), Name));
3268 }
3269 
3271  const char *Name) {
3272  return wrap(unwrap(B)->CreateNSWNeg(unwrap(V), Name));
3273 }
3274 
3276  const char *Name) {
3277  return wrap(unwrap(B)->CreateNUWNeg(unwrap(V), Name));
3278 }
3279 
3281  return wrap(unwrap(B)->CreateFNeg(unwrap(V), Name));
3282 }
3283 
3285  return wrap(unwrap(B)->CreateNot(unwrap(V), Name));
3286 }
3287 
3288 /*--.. Memory ..............................................................--*/
3289 
3291  const char *Name) {
3292  Type* ITy = Type::getInt32Ty(unwrap(B)->GetInsertBlock()->getContext());
3293  Constant* AllocSize = ConstantExpr::getSizeOf(unwrap(Ty));
3294  AllocSize = ConstantExpr::getTruncOrBitCast(AllocSize, ITy);
3295  Instruction* Malloc = CallInst::CreateMalloc(unwrap(B)->GetInsertBlock(),
3296  ITy, unwrap(Ty), AllocSize,
3297  nullptr, nullptr, "");
3298  return wrap(unwrap(B)->Insert(Malloc, Twine(Name)));
3299 }
3300 
3302  LLVMValueRef Val, const char *Name) {
3303  Type* ITy = Type::getInt32Ty(unwrap(B)->GetInsertBlock()->getContext());
3304  Constant* AllocSize = ConstantExpr::getSizeOf(unwrap(Ty));
3305  AllocSize = ConstantExpr::getTruncOrBitCast(AllocSize, ITy);
3306  Instruction* Malloc = CallInst::CreateMalloc(unwrap(B)->GetInsertBlock(),
3307  ITy, unwrap(Ty), AllocSize,
3308  unwrap(Val), nullptr, "");
3309  return wrap(unwrap(B)->Insert(Malloc, Twine(Name)));
3310 }
3311 
3313  LLVMValueRef Val, LLVMValueRef Len,
3314  unsigned Align) {
3315  return wrap(unwrap(B)->CreateMemSet(unwrap(Ptr), unwrap(Val), unwrap(Len), Align));
3316 }
3317 
3319  LLVMValueRef Dst, unsigned DstAlign,
3320  LLVMValueRef Src, unsigned SrcAlign,
3321  LLVMValueRef Size) {
3322  return wrap(unwrap(B)->CreateMemCpy(unwrap(Dst), DstAlign,
3323  unwrap(Src), SrcAlign,
3324  unwrap(Size)));
3325 }
3326 
3328  LLVMValueRef Dst, unsigned DstAlign,
3329  LLVMValueRef Src, unsigned SrcAlign,
3330  LLVMValueRef Size) {
3331  return wrap(unwrap(B)->CreateMemMove(unwrap(Dst), DstAlign,
3332  unwrap(Src), SrcAlign,
3333  unwrap(Size)));
3334 }
3335 
3337  const char *Name) {
3338  return wrap(unwrap(B)->CreateAlloca(unwrap(Ty), nullptr, Name));
3339 }
3340 
3342  LLVMValueRef Val, const char *Name) {
3343  return wrap(unwrap(B)->CreateAlloca(unwrap(Ty), unwrap(Val), Name));
3344 }
3345 
3347  return wrap(unwrap(B)->Insert(
3348  CallInst::CreateFree(unwrap(PointerVal), unwrap(B)->GetInsertBlock())));
3349 }
3350 
3352  const char *Name) {
3353  Value *V = unwrap(PointerVal);
3354  PointerType *Ty = cast<PointerType>(V->getType());
3355 
3356  return wrap(unwrap(B)->CreateLoad(Ty->getElementType(), V, Name));
3357 }
3358 
3360  LLVMValueRef PointerVal, const char *Name) {
3361  return wrap(unwrap(B)->CreateLoad(unwrap(Ty), unwrap(PointerVal), Name));
3362 }
3363 
3365  LLVMValueRef PointerVal) {
3366  return wrap(unwrap(B)->CreateStore(unwrap(Val), unwrap(PointerVal)));
3367 }
3368 
3370  switch (Ordering) {
3380  }
3381 
3382  llvm_unreachable("Invalid LLVMAtomicOrdering value!");
3383 }
3384 
3386  switch (Ordering) {
3396  }
3397 
3398  llvm_unreachable("Invalid AtomicOrdering value!");
3399 }
3400 
3401 // TODO: Should this and other atomic instructions support building with
3402 // "syncscope"?
3404  LLVMBool isSingleThread, const char *Name) {
3405  return wrap(
3406  unwrap(B)->CreateFence(mapFromLLVMOrdering(Ordering),
3407  isSingleThread ? SyncScope::SingleThread
3409  Name));
3410 }
3411 
3413  LLVMValueRef *Indices, unsigned NumIndices,
3414  const char *Name) {
3415  ArrayRef<Value *> IdxList(unwrap(Indices), NumIndices);
3416  Value *Val = unwrap(Pointer);
3417  Type *Ty =
3418  cast<PointerType>(Val->getType()->getScalarType())->getElementType();
3419  return wrap(unwrap(B)->CreateGEP(Ty, Val, IdxList, Name));
3420 }
3421 
3423  LLVMValueRef Pointer, LLVMValueRef *Indices,
3424  unsigned NumIndices, const char *Name) {
3425  ArrayRef<Value *> IdxList(unwrap(Indices), NumIndices);
3426  return wrap(unwrap(B)->CreateGEP(unwrap(Ty), unwrap(Pointer), IdxList, Name));
3427 }
3428 
3430  LLVMValueRef *Indices, unsigned NumIndices,
3431  const char *Name) {
3432  ArrayRef<Value *> IdxList(unwrap(Indices), NumIndices);
3433  Value *Val = unwrap(Pointer);
3434  Type *Ty =
3435  cast<PointerType>(Val->getType()->getScalarType())->getElementType();
3436  return wrap(unwrap(B)->CreateInBoundsGEP(Ty, Val, IdxList, Name));
3437 }
3438 
3440  LLVMValueRef Pointer, LLVMValueRef *Indices,
3441  unsigned NumIndices, const char *Name) {
3442  ArrayRef<Value *> IdxList(unwrap(Indices), NumIndices);
3443  return wrap(
3444  unwrap(B)->CreateInBoundsGEP(unwrap(Ty), unwrap(Pointer), IdxList, Name));
3445 }
3446 
3448  unsigned Idx, const char *Name) {
3449  Value *Val = unwrap(Pointer);
3450  Type *Ty =
3451  cast<PointerType>(Val->getType()->getScalarType())->getElementType();
3452  return wrap(unwrap(B)->CreateStructGEP(Ty, Val, Idx, Name));
3453 }
3454 
3456  LLVMValueRef Pointer, unsigned Idx,
3457  const char *Name) {
3458  return wrap(
3459  unwrap(B)->CreateStructGEP(unwrap(Ty), unwrap(Pointer), Idx, Name));
3460 }
3461 
3463  const char *Name) {
3464  return wrap(unwrap(B)->CreateGlobalString(Str, Name));
3465 }
3466 
3468  const char *Name) {
3469  return wrap(unwrap(B)->CreateGlobalStringPtr(Str, Name));
3470 }
3471 
3473  Value *P = unwrap<Value>(MemAccessInst);
3474  if (LoadInst *LI = dyn_cast<LoadInst>(P))
3475  return LI->isVolatile();
3476  return cast<StoreInst>(P)->isVolatile();
3477 }
3478 
3480  Value *P = unwrap<Value>(MemAccessInst);
3481  if (LoadInst *LI = dyn_cast<LoadInst>(P))
3482  return LI->setVolatile(isVolatile);
3483  return cast<StoreInst>(P)->setVolatile(isVolatile);
3484 }
3485 
3487  Value *P = unwrap<Value>(MemAccessInst);
3488  AtomicOrdering O;
3489  if (LoadInst *LI = dyn_cast<LoadInst>(P))
3490  O = LI->getOrdering();
3491  else
3492  O = cast<StoreInst>(P)->getOrdering();
3493  return mapToLLVMOrdering(O);
3494 }
3495 
3496 void LLVMSetOrdering(LLVMValueRef MemAccessInst, LLVMAtomicOrdering Ordering) {
3497  Value *P = unwrap<Value>(MemAccessInst);
3498  AtomicOrdering O = mapFromLLVMOrdering(Ordering);
3499 
3500  if (LoadInst *LI = dyn_cast<LoadInst>(P))
3501  return LI->setOrdering(O);
3502  return cast<StoreInst>(P)->setOrdering(O);
3503 }
3504 
3505 /*--.. Casts ...............................................................--*/
3506 
3508  LLVMTypeRef DestTy, const char *Name) {
3509  return wrap(unwrap(B)->CreateTrunc(unwrap(Val), unwrap(DestTy), Name));
3510 }
3511 
3513  LLVMTypeRef DestTy, const char *Name) {
3514  return wrap(unwrap(B)->CreateZExt(unwrap(Val), unwrap(DestTy), Name));
3515 }
3516 
3518  LLVMTypeRef DestTy, const char *Name) {
3519  return wrap(unwrap(B)->CreateSExt(unwrap(Val), unwrap(DestTy), Name));
3520 }
3521 
3523  LLVMTypeRef DestTy, const char *Name) {
3524  return wrap(unwrap(B)->CreateFPToUI(unwrap(Val), unwrap(DestTy), Name));
3525 }
3526 
3528  LLVMTypeRef DestTy, const char *Name) {
3529  return wrap(unwrap(B)->CreateFPToSI(unwrap(Val), unwrap(DestTy), Name));
3530 }
3531 
3533  LLVMTypeRef DestTy, const char *Name) {
3534  return wrap(unwrap(B)->CreateUIToFP(unwrap(Val), unwrap(DestTy), Name));
3535 }
3536 
3538  LLVMTypeRef DestTy, const char *Name) {
3539  return wrap(unwrap(B)->CreateSIToFP(unwrap(Val), unwrap(DestTy), Name));
3540 }
3541 
3543  LLVMTypeRef DestTy, const char *Name) {
3544  return wrap(unwrap(B)->CreateFPTrunc(unwrap(Val), unwrap(DestTy), Name));
3545 }
3546 
3548  LLVMTypeRef DestTy, const char *Name) {
3549  return wrap(unwrap(B)->CreateFPExt(unwrap(Val), unwrap(DestTy), Name));
3550 }
3551 
3553  LLVMTypeRef DestTy, const char *Name) {
3554  return wrap(unwrap(B)->CreatePtrToInt(unwrap(Val), unwrap(DestTy), Name));
3555 }
3556 
3558  LLVMTypeRef DestTy, const char *Name) {
3559  return wrap(unwrap(B)->CreateIntToPtr(unwrap(Val), unwrap(DestTy), Name));
3560 }
3561 
3563  LLVMTypeRef DestTy, const char *Name) {
3564  return wrap(unwrap(B)->CreateBitCast(unwrap(Val), unwrap(DestTy), Name));
3565 }
3566 
3568  LLVMTypeRef DestTy, const char *Name) {
3569  return wrap(unwrap(B)->CreateAddrSpaceCast(unwrap(Val), unwrap(DestTy), Name));
3570 }
3571 
3573  LLVMTypeRef DestTy, const char *Name) {
3574  return wrap(unwrap(B)->CreateZExtOrBitCast(unwrap(Val), unwrap(DestTy),
3575  Name));
3576 }
3577 
3579  LLVMTypeRef DestTy, const char *Name) {
3580  return wrap(unwrap(B)->CreateSExtOrBitCast(unwrap(Val), unwrap(DestTy),
3581  Name));
3582 }
3583 
3585  LLVMTypeRef DestTy, const char *Name) {
3586  return wrap(unwrap(B)->CreateTruncOrBitCast(unwrap(Val), unwrap(DestTy),
3587  Name));
3588 }
3589 
3591  LLVMTypeRef DestTy, const char *Name) {
3592  return wrap(unwrap(B)->CreateCast(Instruction::CastOps(map_from_llvmopcode(Op)), unwrap(Val),
3593  unwrap(DestTy), Name));
3594 }
3595 
3597  LLVMTypeRef DestTy, const char *Name) {
3598  return wrap(unwrap(B)->CreatePointerCast(unwrap(Val), unwrap(DestTy), Name));
3599 }
3600 
3602  LLVMTypeRef DestTy, LLVMBool IsSigned,
3603  const char *Name) {
3604  return wrap(
3605  unwrap(B)->CreateIntCast(unwrap(Val), unwrap(DestTy), IsSigned, Name));
3606 }
3607 
3609  LLVMTypeRef DestTy, const char *Name) {
3610  return wrap(unwrap(B)->CreateIntCast(unwrap(Val), unwrap(DestTy),
3611  /*isSigned*/true, Name));
3612 }
3613 
3615  LLVMTypeRef DestTy, const char *Name) {
3616  return wrap(unwrap(B)->CreateFPCast(unwrap(Val), unwrap(DestTy), Name));
3617 }
3618 
3619 /*--.. Comparisons .........................................................--*/
3620 
3622  LLVMValueRef LHS, LLVMValueRef RHS,
3623  const char *Name) {
3624  return wrap(unwrap(B)->CreateICmp(static_cast<ICmpInst::Predicate>(Op),
3625  unwrap(LHS), unwrap(RHS), Name));
3626 }
3627 
3629  LLVMValueRef LHS, LLVMValueRef RHS,
3630  const char *Name) {
3631  return wrap(unwrap(B)->CreateFCmp(static_cast<FCmpInst::Predicate>(Op),
3632  unwrap(LHS), unwrap(RHS), Name));
3633 }
3634 
3635 /*--.. Miscellaneous instructions ..........................................--*/
3636 
3638  return wrap(unwrap(B)->CreatePHI(unwrap(Ty), 0, Name));
3639 }
3640 
3642  LLVMValueRef *Args, unsigned NumArgs,
3643  const char *Name) {
3644  Value *V = unwrap(Fn);
3645  FunctionType *FnT =
3646  cast<FunctionType>(cast<PointerType>(V->getType())->getElementType());
3647 
3648  return wrap(unwrap(B)->CreateCall(FnT, unwrap(Fn),
3649  makeArrayRef(unwrap(Args), NumArgs), Name));
3650 }
3651 
3653  LLVMValueRef *Args, unsigned NumArgs,
3654  const char *Name) {
3655  FunctionType *FTy = unwrap<FunctionType>(Ty);
3656  return wrap(unwrap(B)->CreateCall(FTy, unwrap(Fn),
3657  makeArrayRef(unwrap(Args), NumArgs), Name));
3658 }
3659 
3662  const char *Name) {
3663  return wrap(unwrap(B)->CreateSelect(unwrap(If), unwrap(Then), unwrap(Else),
3664  Name));
3665 }
3666 
3668  LLVMTypeRef Ty, const char *Name) {
3669  return wrap(unwrap(B)->CreateVAArg(unwrap(List), unwrap(Ty), Name));
3670 }
3671 
3673  LLVMValueRef Index, const char *Name) {
3674  return wrap(unwrap(B)->CreateExtractElement(unwrap(VecVal), unwrap(Index),
3675  Name));
3676 }
3677 
3680  const char *Name) {
3681  return wrap(unwrap(B)->CreateInsertElement(unwrap(VecVal), unwrap(EltVal),
3682  unwrap(Index), Name));
3683 }
3684 
3687  const char *Name) {
3688  return wrap(unwrap(B)->CreateShuffleVector(unwrap(V1), unwrap(V2),
3689  unwrap(Mask), Name));
3690 }
3691 
3693  unsigned Index, const char *Name) {
3694  return wrap(unwrap(B)->CreateExtractValue(unwrap(AggVal), Index, Name));
3695 }
3696 
3698  LLVMValueRef EltVal, unsigned Index,
3699  const char *Name) {
3700  return wrap(unwrap(B)->CreateInsertValue(unwrap(AggVal), unwrap(EltVal),
3701  Index, Name));
3702 }
3703 
3705  const char *Name) {
3706  return wrap(unwrap(B)->CreateIsNull(unwrap(Val), Name));
3707 }
3708 
3710  const char *Name) {
3711  return wrap(unwrap(B)->CreateIsNotNull(unwrap(Val), Name));
3712 }
3713 
3715  LLVMValueRef RHS, const char *Name) {
3716  return wrap(unwrap(B)->CreatePtrDiff(unwrap(LHS), unwrap(RHS), Name));
3717 }
3718 
3720  LLVMValueRef PTR, LLVMValueRef Val,
3721  LLVMAtomicOrdering ordering,
3722  LLVMBool singleThread) {
3723  AtomicRMWInst::BinOp intop;
3724  switch (op) {
3725  case LLVMAtomicRMWBinOpXchg: intop = AtomicRMWInst::Xchg; break;
3726  case LLVMAtomicRMWBinOpAdd: intop = AtomicRMWInst::Add; break;
3727  case LLVMAtomicRMWBinOpSub: intop = AtomicRMWInst::Sub; break;
3728  case LLVMAtomicRMWBinOpAnd: intop = AtomicRMWInst::And; break;
3729  case LLVMAtomicRMWBinOpNand: intop = AtomicRMWInst::Nand; break;
3730  case LLVMAtomicRMWBinOpOr: intop = AtomicRMWInst::Or; break;
3731  case LLVMAtomicRMWBinOpXor: intop = AtomicRMWInst::Xor; break;
3732  case LLVMAtomicRMWBinOpMax: intop = AtomicRMWInst::Max; break;
3733  case LLVMAtomicRMWBinOpMin: intop = AtomicRMWInst::Min; break;
3734  case LLVMAtomicRMWBinOpUMax: intop = AtomicRMWInst::UMax; break;
3735  case LLVMAtomicRMWBinOpUMin: intop = AtomicRMWInst::UMin; break;
3736  }
3737  return wrap(unwrap(B)->CreateAtomicRMW(intop, unwrap(PTR), unwrap(Val),
3738  mapFromLLVMOrdering(ordering), singleThread ? SyncScope::SingleThread
3739  : SyncScope::System));
3740 }
3741 
3743  LLVMValueRef Cmp, LLVMValueRef New,
3744  LLVMAtomicOrdering SuccessOrdering,
3745  LLVMAtomicOrdering FailureOrdering,
3746  LLVMBool singleThread) {
3747 
3748  return wrap(unwrap(B)->CreateAtomicCmpXchg(unwrap(Ptr), unwrap(Cmp),
3749  unwrap(New), mapFromLLVMOrdering(SuccessOrdering),
3750  mapFromLLVMOrdering(FailureOrdering),
3751  singleThread ? SyncScope::SingleThread : SyncScope::System));
3752 }
3753 
3754 
3756  Value *P = unwrap<Value>(AtomicInst);
3757 
3758  if (AtomicRMWInst *I = dyn_cast<AtomicRMWInst>(P))
3759  return I->getSyncScopeID() == SyncScope::SingleThread;
3760  return cast<AtomicCmpXchgInst>(P)->getSyncScopeID() ==
3762 }
3763 
3765  Value *P = unwrap<Value>(AtomicInst);
3767 
3768  if (AtomicRMWInst *I = dyn_cast<AtomicRMWInst>(P))
3769  return I->setSyncScopeID(SSID);
3770  return cast<AtomicCmpXchgInst>(P)->setSyncScopeID(SSID);
3771 }
3772 
3774  Value *P = unwrap<Value>(CmpXchgInst);
3775  return mapToLLVMOrdering(cast<AtomicCmpXchgInst>(P)->getSuccessOrdering());
3776 }
3777 
3779  LLVMAtomicOrdering Ordering) {
3780  Value *P = unwrap<Value>(CmpXchgInst);
3781  AtomicOrdering O = mapFromLLVMOrdering(Ordering);
3782 
3783  return cast<AtomicCmpXchgInst>(P)->setSuccessOrdering(O);
3784 }
3785 
3787  Value *P = unwrap<Value>(CmpXchgInst);
3788  return mapToLLVMOrdering(cast<AtomicCmpXchgInst>(P)->getFailureOrdering());
3789 }
3790 
3792  LLVMAtomicOrdering Ordering) {
3793  Value *P = unwrap<Value>(CmpXchgInst);
3794  AtomicOrdering O = mapFromLLVMOrdering(Ordering);
3795 
3796  return cast<AtomicCmpXchgInst>(P)->setFailureOrdering(O);
3797 }
3798 
3799 /*===-- Module providers --------------------------------------------------===*/
3800 
3803  return reinterpret_cast<LLVMModuleProviderRef>(M);
3804 }
3805 
3807  delete unwrap(MP);
3808 }
3809 
3810 
3811 /*===-- Memory buffers ----------------------------------------------------===*/
3812 
3814  const char *Path,
3815  LLVMMemoryBufferRef *OutMemBuf,
3816  char **OutMessage) {
3817 
3819  if (std::error_code EC = MBOrErr.getError()) {
3820  *OutMessage = strdup(EC.message().c_str());
3821  return 1;
3822  }
3823  *OutMemBuf = wrap(MBOrErr.get().release());
3824  return 0;
3825 }
3826 
3828  char **OutMessage) {
3830  if (std::error_code EC = MBOrErr.getError()) {
3831  *OutMessage = strdup(EC.message().c_str());
3832  return 1;
3833  }
3834  *OutMemBuf = wrap(MBOrErr.get().release());
3835  return 0;
3836 }
3837 
3839  const char *InputData,
3840  size_t InputDataLength,
3841  const char *BufferName,
3842  LLVMBool RequiresNullTerminator) {
3843 
3844  return wrap(MemoryBuffer::getMemBuffer(StringRef(InputData, InputDataLength),
3845  StringRef(BufferName),
3846  RequiresNullTerminator).release());
3847 }
3848 
3850  const char *InputData,
3851  size_t InputDataLength,
3852  const char *BufferName) {
3853 
3854  return wrap(
3855  MemoryBuffer::getMemBufferCopy(StringRef(InputData, InputDataLength),
3856  StringRef(BufferName)).release());
3857 }
3858 
3860  return unwrap(MemBuf)->getBufferStart();
3861 }
3862 
3864  return unwrap(MemBuf)->getBufferSize();
3865 }
3866 
3868  delete unwrap(MemBuf);
3869 }
3870 
3871 /*===-- Pass Registry -----------------------------------------------------===*/
3872 
3875 }
3876 
3877 /*===-- Pass Manager ------------------------------------------------------===*/
3878 
3880  return wrap(new legacy::PassManager());
3881 }
3882 
3884  return wrap(new legacy::FunctionPassManager(unwrap(M)));
3885 }
3886 
3889  reinterpret_cast<LLVMModuleRef>(P));
3890 }
3891 
3893  return unwrap<legacy::PassManager>(PM)->run(*unwrap(M));
3894 }
3895 
3897  return unwrap<legacy::FunctionPassManager>(FPM)->doInitialization();
3898 }
3899 
3901  return unwrap<legacy::FunctionPassManager>(FPM)->run(*unwrap<Function>(F));
3902 }
3903 
3905  return unwrap<legacy::FunctionPassManager>(FPM)->doFinalization();
3906 }
3907 
3909  delete unwrap(PM);
3910 }
3911 
3912 /*===-- Threading ------------------------------------------------------===*/
3913 
3915  return LLVMIsMultithreaded();
3916 }
3917 
3919 }
3920 
3922  return llvm_is_multithreaded();
3923 }
LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1546
LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty, const char *AsmString, const char *Constraints, LLVMBool HasSideEffects, LLVMBool IsAlignStack)
Deprecated: Use LLVMGetInlineAsm instead.
Definition: Core.cpp:1782
Subtract a value and return the old one.
Definition: Core.h:358
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
const char * LLVMGetBufferStart(LLVMMemoryBufferRef MemBuf)
Definition: Core.cpp:3859
static Constant * getFPTrunc(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:1679
void LLVMDisposeBuilder(LLVMBuilderRef Builder)
Definition: Core.cpp:2921
uint64_t CallInst * C
unsigned LLVMGetMDNodeNumOperands(LLVMValueRef V)
Obtain the number of operands from an MDNode value.
Definition: Core.cpp:1105
X86 MMX.
Definition: Core.h:161
Adds a requirement that another module flag be present and have a specified value after linking is pe...
Definition: Core.h:415
use_iterator use_end()
Definition: Value.h:347
LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy, LLVMValueRef *ConstantVals, unsigned Count)
Create a non-anonymous ConstantStruct from values.
Definition: Core.cpp:1393
7: Labels
Definition: Type.h:64
LLVMValueRef LLVMInstructionClone(LLVMValueRef Inst)
Create a copy of &#39;this&#39; instruction that is identical in all ways except the following: ...
Definition: Core.cpp:2652
LLVMRealPredicate LLVMGetFCmpPredicate(LLVMValueRef Inst)
Obtain the float predicate of an instruction.
Definition: Core.cpp:2637
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C, LLVMBasicBlockRef BBRef, const char *Name)
Insert a basic block in a function before another basic block.
Definition: Core.cpp:2554
Represents either an error or a value T.
Definition: ErrorOr.h:57
void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest)
Get the elements within a structure.
Definition: Core.cpp:697
void LLVMGetParams(LLVMValueRef FnRef, LLVMValueRef *ParamRefs)
Obtain the parameters in a function.
Definition: Core.cpp:2415
LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar)
Definition: Core.cpp:2098
LLVMValueRef LLVMBuildICmp(LLVMBuilderRef B, LLVMIntPredicate Op, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:3621
static Constant * getString(LLVMContext &Context, StringRef Initializer, bool AddNull=true)
This method constructs a CDS and initializes it with a text string.
Definition: Constants.cpp:2567
void LLVMGetHandlers(LLVMValueRef CatchSwitch, LLVMBasicBlockRef *Handlers)
Obtain the basic blocks acting as handlers for a catchswitch instruction.
Definition: Core.cpp:3101
StringRef getKindAsString() const
Return the attribute&#39;s kind as a string.
Definition: Attributes.cpp:188
static bool isConstant(const MachineInstr &MI)
static Type * getDoubleTy(LLVMContext &C)
Definition: Type.cpp:165
void LLVMSetCmpXchgFailureOrdering(LLVMValueRef CmpXchgInst, LLVMAtomicOrdering Ordering)
Definition: Core.cpp:3791
static IntegerType * getInt1Ty(LLVMContext &C)
Definition: Type.cpp:173
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy)
Obtain the address space of a pointer type.
Definition: Core.cpp:762
static Constant * getFAdd(Constant *C1, Constant *C2)
Definition: Constants.cpp:2245
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
Special purpose, only applies to global arrays.
Definition: GlobalValue.h:55
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
LLVMBool LLVMHasPersonalityFn(LLVMValueRef Fn)
Check whether the given function has a personality function.
Definition: Core.cpp:2276
*p = old <signed v ? old : v
Definition: Instructions.h:722
LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef B, LLVMTypeRef Ty, LLVMValueRef Val, const char *Name)
Definition: Core.cpp:3341
LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1582
LLVMValueRef LLVMBuildZExt(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:3512
LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn)
Obtain the basic block that corresponds to the entry point of a function.
Definition: Core.cpp:2503
LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M)
Obtain an iterator to the last Function in a Module.
Definition: Core.cpp:2248
LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType)
Definition: Core.cpp:1692
This class represents an incoming formal argument to a Function.
Definition: Argument.h:30
LLVMContext & Context
Not-And a value and return the old one.
Definition: Core.h:360
LLVMValueRef LLVMBuildAtomicCmpXchg(LLVMBuilderRef B, LLVMValueRef Ptr, LLVMValueRef Cmp, LLVMValueRef New, LLVMAtomicOrdering SuccessOrdering, LLVMAtomicOrdering FailureOrdering, LLVMBool singleThread)
Definition: Core.cpp:3742
static AtomicOrdering mapFromLLVMOrdering(LLVMAtomicOrdering Ordering)
Definition: Core.cpp:3369
LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1530
Externally visible function.
Definition: Core.h:166
SI Whole Quad Mode
LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty)
Whether the type has a known size.
Definition: Core.cpp:509
LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1541
void LLVMSetSection(LLVMValueRef Global, const char *Section)
Definition: Core.cpp:1904
MDNode * getOperand(unsigned i) const
Definition: Metadata.cpp:1081
void LLVMSetValueName2(LLVMValueRef Val, const char *Name, size_t NameLen)
Set the string name of a value.
Definition: Core.cpp:817
unsigned LLVMAttributeIndex
Definition: Core.h:452
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
This class represents lattice values for constants.
Definition: AllocatorList.h:24
struct LLVMOpaqueModule * LLVMModuleRef
The top-level container for all other LLVM Intermediate Representation (IR) objects.
Definition: Types.h:62
LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRangeCopy(const char *InputData, size_t InputDataLength, const char *BufferName)
Definition: Core.cpp:3849
LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count)
Obtain a MDNode value from the global context.
Definition: Core.cpp:1078
provides both an Acquire and a Release barrier (for fences and operations which both read and write m...
Definition: Core.h:341
const char * LLVMGetAsString(LLVMValueRef C, size_t *Length)
Get the given constant data sequential as a string.
Definition: Core.cpp:1367
LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index)
Obtain an incoming value to a PHI node as an LLVMValueRef.
Definition: Core.cpp:2840
LLVMTypeRef LLVMIntrinsicGetType(LLVMContextRef Ctx, unsigned ID, LLVMTypeRef *ParamTypes, size_t ParamCount)
Retrieves the type of an intrinsic.
Definition: Core.cpp:2315
static Constant * getNSWAdd(Constant *C1, Constant *C2)
Definition: Constants.h:977
void initializePrintModulePassWrapperPass(PassRegistry &)
static Attribute getWithAlignment(LLVMContext &Context, uint64_t Align)
Return a uniquified Attribute object that has the specific alignment set.
Definition: Attributes.cpp:125
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:65
struct LLVMOpaqueMemoryBuffer * LLVMMemoryBufferRef
LLVM uses a polymorphic type hierarchy which C cannot represent, therefore parameters must be passed ...
Definition: Types.h:49
static Constant * getGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant *> IdxList, bool InBounds=false, Optional< unsigned > InRangeIndex=None, Type *OnlyIfReducedTy=nullptr)
Getelementptr form.
Definition: Constants.h:1154
static MDNode * extractMDNode(MetadataAsValue *MAV)
Definition: Core.cpp:866
void LLVMSetSuccessor(LLVMValueRef Term, unsigned i, LLVMBasicBlockRef block)
Update the specified successor to point at the provided block.
Definition: Core.cpp:2787
LLVMValueRef LLVMBuildLoad2(LLVMBuilderRef B, LLVMTypeRef Ty, LLVMValueRef PointerVal, const char *Name)
Definition: Core.cpp:3359
LLVMValueRef LLVMBuildAdd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:3129
LLVMBuilderRef LLVMCreateBuilder(void)
Definition: Core.cpp:2883
Obsolete.
Definition: Core.h:179
LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg)
Obtain the next parameter to a function.
Definition: Core.cpp:2447
2: 32-bit floating point type
Definition: Type.h:59
iterator end()
Definition: Function.h:658
Same, but only replaced by something equivalent.
Definition: GlobalValue.h:54
LLVMModuleFlagBehavior Behavior
Definition: Core.cpp:279
LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:3139
static LLVMAtomicOrdering mapToLLVMOrdering(AtomicOrdering Ordering)
Definition: Core.cpp:3385
static MDString * get(LLVMContext &Context, StringRef Str)
Definition: Metadata.cpp:454
LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer, unsigned Idx, const char *Name)
Definition: Core.cpp:3447
LLVMAttributeRef LLVMGetEnumAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx, unsigned KindID)
Definition: Core.cpp:2377
LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name)
Definition: Core.cpp:2058
LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy)
Determine whether a structure is opaque.
Definition: Core.cpp:713
LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRange(const char *InputData, size_t InputDataLength, const char *BufferName, LLVMBool RequiresNullTerminator)
Definition: Core.cpp:3838
LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn)
Obtain the first parameter to a function.
Definition: Core.cpp:2431
void initializeSafepointIRVerifierPass(PassRegistry &)
void(*)(LLVMContext *Context, void *OpaqueHandle) YieldCallbackTy
Defines the type of a yield callback.
Definition: LLVMContext.h:176
LLVMValueRef LLVMGetNextGlobalAlias(LLVMValueRef GA)
Advance a GlobalAlias iterator to the next GlobalAlias.
Definition: Core.cpp:2204
LLVMValueRef LLVMBuildSExt(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:3517
LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee, const char *Name)
Definition: Core.cpp:2175
LLVMAttributeRef LLVMCreateStringAttribute(LLVMContextRef C, const char *K, unsigned KLength, const char *V, unsigned VLength)
Create a string attribute.
Definition: Core.cpp:158
LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty)
Definition: Core.cpp:1435
LLVMBool LLVMHasUnnamedAddr(LLVMValueRef Global)
Deprecated: Use LLVMGetUnnamedAddress instead.
Definition: Core.cpp:1953
Available for inspection, not emission.
Definition: GlobalValue.h:50
void LLVMStopMultithreaded()
Deprecated: Multi-threading can only be enabled/disabled with the compile time define LLVM_ENABLE_THR...
Definition: Core.cpp:3918
LLVMOpcode
External users depend on the following values being stable.
Definition: Core.h:59
void LLVMSetValueName(LLVMValueRef Val, const char *Name)
Deprecated: Use LLVMSetValueName2 instead.
Definition: Core.cpp:825
static Constant * getAddrSpaceCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:1785
const char * LLVMGetNamedMetadataName(LLVMNamedMDNodeRef NMD, size_t *NameLen)
Retrieve the name of a NamedMDNode.
Definition: Core.cpp:1154
Metadata * getMetadata() const
Definition: Metadata.h:191
LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType)
Definition: Core.cpp:1672
Emits an error if two values disagree, otherwise the resulting value is that of the operands...
Definition: Core.h:396
void clearGC()
Definition: Function.cpp:475
const char * LLVMGetGC(LLVMValueRef Fn)
Obtain the name of the garbage collector to use during code generation.
Definition: Core.cpp:2347
LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef P)
Deprecated: Use LLVMCreateFunctionPassManagerForModule instead.
Definition: Core.cpp:3887
LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name)
Definition: Core.cpp:2044
LLVMTypeRef LLVMGetAllocatedType(LLVMValueRef Alloca)
Obtain the type that is being allocated by the alloca instruction.
Definition: Core.cpp:2813
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
Definition: StringRef.h:138
LLVMTypeRef LLVMHalfType(void)
Obtain a floating point type from the global context.
Definition: Core.cpp:610
static std::unique_ptr< MemoryBuffer > getMemBuffer(StringRef InputData, StringRef BufferName="", bool RequiresNullTerminator=true)
Open the specified memory range as a MemoryBuffer.
LLVMValueRef LLVMBuildRet(LLVMBuilderRef B, LLVMValueRef V)
Definition: Core.cpp:2950
LLVMAttributeRef LLVMCreateEnumAttribute(LLVMContextRef C, unsigned KindID, uint64_t Val)
Create an enum attribute.
Definition: Core.cpp:142
LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB)
Advance a basic block iterator.
Definition: Core.cpp:2523
LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path, LLVMMemoryBufferRef *OutMemBuf, char **OutMessage)
Definition: Core.cpp:3813
A global registry used in conjunction with static constructors to make pluggable components (like tar...
Definition: Registry.h:45
char * LLVMCreateMessage(const char *Message)
Definition: Core.cpp:66
LLVMPassManagerRef LLVMCreatePassManager()
Constructs a new whole-module pass pipeline.
Definition: Core.cpp:3879
LLVMInlineAsmDialect
Definition: Core.h:384
void addOperand(MDNode *M)
Definition: Metadata.cpp:1087
LLVMTypeRef LLVMFP128Type(void)
Definition: Core.cpp:622
named_metadata_iterator named_metadata_end()
Definition: Module.h:712
LLVMValueRef LLVMGetClause(LLVMValueRef LandingPad, unsigned Idx)
Definition: Core.cpp:3076
static Constant * getExactSDiv(Constant *C1, Constant *C2)
Definition: Constants.h:1009
void setGC(std::string Str)
Definition: Function.cpp:470
LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:3522
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space...
Definition: Type.cpp:630
#define LLVM_FOR_EACH_VALUE_SUBCLASS(macro)
Definition: Core.h:1514
unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy)
Obtain the number of elements in a vector type.
Definition: Core.cpp:766
LLVMMetadataRef LLVMModuleFlagEntriesGetMetadata(LLVMModuleFlagEntry *Entries, unsigned Index)
Returns the metadata for a module flag entry at a specific index.
Definition: Core.cpp:361
LLVMDiagnosticSeverity LLVMGetDiagInfoSeverity(LLVMDiagnosticInfoRef DI)
Return an enum LLVMDiagnosticSeverity.
Definition: Core.cpp:199
*p = old <unsigned v ? old : v
Definition: Instructions.h:726
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLExtras.h:117
static Constant * getIntToPtr(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:1760
LLVMBool LLVMIsAtomicSingleThread(LLVMValueRef AtomicInst)
Definition: Core.cpp:3755
float convertToFloat() const
Definition: APFloat.h:1098
static Constant * getExtractElement(Constant *Vec, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
Definition: Constants.cpp:2103
const char * LLVMGetDataLayoutStr(LLVMModuleRef M)
Obtain the data layout for a module.
Definition: Core.cpp:256
LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef B, LLVMValueRef If, LLVMBasicBlockRef Then, LLVMBasicBlockRef Else)
Definition: Core.cpp:2963
Like Internal, but omit from symbol table.
Definition: GlobalValue.h:57
LLVMTypeRef LLVMX86MMXType(void)
Definition: Core.cpp:628
*p = old >unsigned v ? old : v
Definition: Instructions.h:724
Externally visible function.
Definition: GlobalValue.h:49
LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef B, LLVMValueRef V, const char *Name)
Definition: Core.cpp:3280
bool isOverloaded(ID id)
Returns true if the intrinsic can be overloaded.
Definition: Function.cpp:997
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:705
bool isTerminator() const
Definition: Instruction.h:129
LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:3584
struct LLVMOpaquePassRegistry * LLVMPassRegistryRef
Definition: Types.h:131
LLVMNamedMDNodeRef LLVMGetLastNamedMetadata(LLVMModuleRef M)
Obtain an iterator to the last NamedMDNode in a Module.
Definition: Core.cpp:1120
unsigned LLVMGetNumArgOperands(LLVMValueRef Instr)
Obtain the argument count for a call instruction.
Definition: Core.cpp:2663
struct LLVMOpaqueBuilder * LLVMBuilderRef
Represents an LLVM basic block builder.
Definition: Types.h:111
LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:3199
arg_iterator arg_end()
Definition: Function.h:680
unsigned LLVMGetLastEnumAttributeKind(void)
Definition: Core.cpp:138
13: Structures
Definition: Type.h:73
LLVMTypeRef LLVMX86FP80Type(void)
Definition: Core.cpp:619
LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val)
Obtain the first use of a value.
Definition: Core.cpp:940
A debug info location.
Definition: DebugLoc.h:34
Metadata node.
Definition: Metadata.h:864
void LLVMClearInsertionPosition(LLVMBuilderRef Builder)
Definition: Core.cpp:2908
LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar)
Definition: Core.cpp:2078
F(f)
4: 80-bit floating point type (X87)
Definition: Type.h:61
LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount)
Create a vector type that contains a defined type and has a specific number of elements.
Definition: Core.cpp:743
LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1572
unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char *Name, unsigned SLen)
Definition: Core.cpp:122
LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void)
Return the global pass registry, for use with initialization functions.
Definition: Core.cpp:3873
const MDOperand & getOperand(unsigned I) const
Definition: Metadata.h:1069
LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:3590
LLVMValueRef LLVMBuildFRem(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:3224
param_iterator param_end() const
Definition: DerivedTypes.h:129
An instruction for reading from memory.
Definition: Instructions.h:168
LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition, LLVMValueRef ConstantIfTrue, LLVMValueRef ConstantIfFalse)
Definition: Core.cpp:1738
1: 16-bit floating point type
Definition: Type.h:58
LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType)
Definition: Core.cpp:1637
LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val)
Determine whether an LLVMValueRef is itself a basic block.
Definition: Core.cpp:2473
static IntegerType * getInt64Ty(LLVMContext &C)
Definition: Type.cpp:177
LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes, unsigned ElementCount, LLVMBool Packed)
Create a new structure type in a context.
Definition: Core.cpp:662
an instruction that atomically reads a memory location, combines it with another value, and then stores the result back.
Definition: Instructions.h:692
Appends the two values, which are required to be metadata nodes.
Definition: Core.h:437
Hexagon Common GEP
LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef BBRef, const char *Name)
Insert a basic block in a function using the global context.
Definition: Core.cpp:2561
int LLVMHasMetadata(LLVMValueRef Inst)
Determine whether an instruction has any metadata attached.
Definition: Core.cpp:851
static Type * getMetadataTy(LLVMContext &C)
Definition: Type.cpp:166
static Constant * getSub(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
Definition: Constants.cpp:2249
const char * LLVMGetSection(LLVMValueRef Global)
Definition: Core.cpp:1898
static Instruction * CreateFree(Value *Source, Instruction *InsertBefore)
Generate the IR for a call to the builtin free function.
LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C)
Definition: Core.cpp:544
LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals, unsigned Count)
Obtain a MDNode value from a context.
Definition: Core.cpp:1051
LLVMTypeRef LLVMTokenTypeInContext(LLVMContextRef C)
Create a token type in a context.
Definition: Core.cpp:778
#define op(i)
LLVMValueRef LLVMBuildFence(LLVMBuilderRef B, LLVMAtomicOrdering Ordering, LLVMBool isSingleThread, const char *Name)
Definition: Core.cpp:3403
15: Pointers
Definition: Type.h:75
void initializeCore(PassRegistry &)
Initialize all passes linked into the TransformUtils library.
Definition: Core.cpp:47
handler_iterator handler_begin()
Returns an iterator that points to the first handler in CatchSwitchInst.
static IntegerType * getInt16Ty(LLVMContext &C)
Definition: Type.cpp:175
LLVMAttributeRef LLVMGetStringAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx, const char *K, unsigned KLen)
Definition: Core.cpp:2384
static Type * getX86_MMXTy(LLVMContext &C)
Definition: Type.cpp:171
LLVMValueRef LLVMGetPreviousGlobalAlias(LLVMValueRef GA)
Decrement a GlobalAlias iterator to the previous GlobalAlias.
Definition: Core.cpp:2212
LLVMAtomicRMWBinOp
Definition: Core.h:355
12: Functions
Definition: Type.h:72
*p = old >signed v ? old : v
Definition: Instructions.h:720
LLVMValueRef LLVMConstAddrSpaceCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType)
Definition: Core.cpp:1697
Lowest level of atomicity, guarantees somewhat sane results, lock free.
Definition: Core.h:330
Appends the two values, which are required to be metadata nodes.
Definition: Core.h:429
std::error_code error() const
Definition: raw_ostream.h:446
Tentative definitions.
Definition: GlobalValue.h:59
static Type * getX86_FP80Ty(LLVMContext &C)
Definition: Type.cpp:168
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition: StringRef.h:128
void LLVMContextDispose(LLVMContextRef C)
Destroy a context instance.
Definition: Core.cpp:118
static Constant * get(ArrayType *T, ArrayRef< Constant *> V)
Definition: Constants.cpp:983
128 bit floating point type (112-bit mantissa)
Definition: Core.h:151
LLVMBool LLVMIntrinsicIsOverloaded(unsigned ID)
Obtain if the intrinsic identified by the given ID is overloaded.
Definition: Core.cpp:2333
void LLVMAddModuleFlag(LLVMModuleRef M, LLVMModuleFlagBehavior Behavior, const char *Key, size_t KeyLen, LLVMMetadataRef Val)
Add a module-level flag to the module-level flags metadata if it doesn&#39;t already exist.
Definition: Core.cpp:373
void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant)
Definition: Core.cpp:2122
void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal)
Definition: Core.cpp:2114
void LLVMSetModuleIdentifier(LLVMModuleRef M, const char *Ident, size_t Len)
Set the identifier of a module to a string Ident with length Len.
Definition: Core.cpp:241
static Constant * getInsertElement(Constant *Vec, Constant *Elt, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
Definition: Constants.cpp:2125
ExternalWeak linkage description.
Definition: Core.h:181
LLVMValueRef LLVMConstNull(LLVMTypeRef Ty)
Obtain a constant value referring to the null instance of a type.
Definition: Core.cpp:1008
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition: Type.h:130
LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N)
Obtain a constant value referring to a double floating point value.
Definition: Core.cpp:1300
LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:3596
static Constant * getNullValue(Type *Ty)
Constructor to create a &#39;0&#39; constant of arbitrary type.
Definition: Constants.cpp:265
LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM)
Initializes all of the function passes scheduled in the function pass manager.
Definition: Core.cpp:3896
void LLVMRemoveCallSiteStringAttribute(LLVMValueRef C, LLVMAttributeIndex Idx, const char *K, unsigned KLen)
Definition: Core.cpp:2726
void LLVMSetOperand(LLVMValueRef Val, unsigned Index, LLVMValueRef Op)
Set an operand at a specific index in a llvm::User value.
Definition: Core.cpp:994
iterator begin()
Instruction iterator methods.
Definition: BasicBlock.h:269
long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal)
Obtain the sign extended value for an integer constant value.
Definition: Core.cpp:1317
static Constant * getAdd(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
Definition: Constants.cpp:2238
unsigned LLVMGetDebugLocLine(LLVMValueRef Val)
Return the line number of the debug location for this value, which must be an llvm::Instruction, llvm::GlobalVariable, or llvm::Function.
Definition: Core.cpp:1244
static Constant * getFMul(Constant *C1, Constant *C2)
Definition: Constants.cpp:2267
void(* LLVMYieldCallback)(LLVMContextRef, void *)
Definition: Core.h:483
void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index, unsigned align)
Definition: Core.cpp:2681
void initializeDominatorTreeWrapperPassPass(PassRegistry &)
LLVMTypeRef LLVMStructGetTypeAtIndex(LLVMTypeRef StructTy, unsigned i)
Get the type of the element at a given index in the structure.
Definition: Core.cpp:704
LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst)
Obtain the code opcode for an individual instruction.
Definition: Core.cpp:2646
LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C)
Obtain a 128-bit floating point type (112-bit mantissa) from a context.
Definition: Core.cpp:600
const char * LLVMGetStructName(LLVMTypeRef Ty)
Obtain the name of a structure.
Definition: Core.cpp:679
LLVMValueRef LLVMBuildCleanupPad(LLVMBuilderRef B, LLVMValueRef ParentPad, LLVMValueRef *Args, unsigned NumArgs, const char *Name)
Definition: Core.cpp:3020
const char * LLVMGetDebugLocDirectory(LLVMValueRef Val, unsigned *Length)
Return the directory of the debug location for this value, which must be an llvm::Instruction, llvm::GlobalVariable, or llvm::Function.
Definition: Core.cpp:1200
LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn)
Obtain the last basic block in a function.
Definition: Core.cpp:2515
Same, but only replaced by something equivalent.
Definition: Core.h:173
void * PointerTy
Definition: GenericValue.h:22
LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB)
Convert a basic block instance to a value type.
Definition: Core.cpp:2469
LLVMValueRef LLVMGetParentCatchSwitch(LLVMValueRef CatchPad)
Get the parent catchswitch instruction of a catchpad instruction.
Definition: Core.cpp:3108
A tuple of MDNodes.
Definition: Metadata.h:1326
static Constant * getIntegerCast(Constant *C, Type *Ty, bool isSigned)
Create a ZExt, Bitcast or Trunc for integer -> integer casts.
Definition: Constants.cpp:1613
amdgpu Simplify well known AMD library false Value Value const Twine & Name
LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C)
Create a label type in a context.
Definition: Core.cpp:775
LLVMMetadataRef LLVMValueAsMetadata(LLVMValueRef Val)
Obtain a Value as a Metadata.
Definition: Core.cpp:1086
LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C)
Obtain a 64-bit floating point type from a context.
Definition: Core.cpp:594
static Type * getTokenTy(LLVMContext &C)
Definition: Type.cpp:167
LLVMValueRef LLVMGetNamedGlobalAlias(LLVMModuleRef M, const char *Name, size_t NameLen)
Obtain a GlobalAlias value from a Module by its name.
Definition: Core.cpp:2183
LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size)
Create a ConstantVector from values.
Definition: Core.cpp:1402
StringRef getName(ID id)
Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
Definition: Function.cpp:626
Set the new value and return the one old.
Definition: Core.h:356
LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:3204
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
bool isStringAttribute() const
Return true if the attribute is a string (target-dependent) attribute.
Definition: Attributes.cpp:170
LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty)
Definition: Core.cpp:1439
struct LLVMOpaqueNamedMDNode * LLVMNamedMDNodeRef
Represents an LLVM Named Metadata Node.
Definition: Types.h:97
LLVMBool LLVMIsNull(LLVMValueRef Val)
Determine whether a value instance is null.
Definition: Core.cpp:1024
Attribute unwrap(LLVMAttributeRef Attr)
Definition: Attributes.h:195
static Type * getFloatTy(LLVMContext &C)
Definition: Type.cpp:164
LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant, LLVMValueRef VectorBConstant, LLVMValueRef MaskConstant)
Definition: Core.cpp:1760
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:451
LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef Switch)
Obtain the default destination basic block of a switch instruction.
Definition: Core.cpp:2807
LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text)
Obtain a constant for a floating point value parsed from a string.
Definition: Core.cpp:1304
LLVMValueRef LLVMBuildGEP2(LLVMBuilderRef B, LLVMTypeRef Ty, LLVMValueRef Pointer, LLVMValueRef *Indices, unsigned NumIndices, const char *Name)
Definition: Core.cpp:3422
const char * Key
Definition: Core.cpp:280
LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef B, LLVMValueRef *RetVals, unsigned N)
Definition: Core.cpp:2954
Class to represent struct types.
Definition: DerivedTypes.h:201
Sets the value if it&#39;s greater than the original using an unsigned comparison and return the old one...
Definition: Core.h:369
A Use represents the edge between a Value definition and its users.
Definition: Use.h:56
static Constant * getLShr(Constant *C1, Constant *C2, bool isExact=false)
Definition: Constants.cpp:2316
static Constant * getNUWNeg(Constant *C)
Definition: Constants.h:975
Address of the GV is globally insignificant.
Definition: Core.h:197
Add a value and return the old one.
Definition: Core.h:357
static Optional< unsigned > getOpcode(ArrayRef< VPValue *> Values)
Returns the opcode of Values or ~0 if they do not all agree.
Definition: VPlanSLP.cpp:197
void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block, LLVMValueRef Instr)
Definition: Core.cpp:2887
LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C)
Definition: Core.cpp:541
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn)
Obtain the calling function of a function.
Definition: Core.cpp:2338
LLVMValueRef LLVMBuildStructGEP2(LLVMBuilderRef B, LLVMTypeRef Ty, LLVMValueRef Pointer, unsigned Idx, const char *Name)
Definition: Core.cpp:3455
LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType, LLVMBool isSigned)
Definition: Core.cpp:1727
LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1475
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:743
void setThreadLocalMode(ThreadLocalMode Val)
Definition: GlobalValue.h:251
void LLVMSetDataLayout(LLVMModuleRef M, const char *DataLayoutStr)
Set the data layout for a module.
Definition: Core.cpp:264
LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1503
unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy)
Definition: Core.cpp:582
This file contains the simple types necessary to represent the attributes associated with functions a...
LLVMBool LLVMIsExternallyInitialized(LLVMValueRef GlobalVar)
Definition: Core.cpp:2165
unsigned LLVMGetDebugLocColumn(LLVMValueRef Val)
Return the column number of the debug location for this value, which must be an llvm::Instruction.
Definition: Core.cpp:1264
Pointers.
Definition: Core.h:158
static Constant * getSExt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:1651
LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1611
LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB)
Obtain the function to which a basic block belongs.
Definition: Core.cpp:2485
void LLVMSetCondition(LLVMValueRef Branch, LLVMValueRef Cond)
Set the condition of a branch instruction.
Definition: Core.cpp:2801
unsigned getNumOperands() const
Definition: Metadata.cpp:1077
LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn)
Obtain the last parameter to a function.
Definition: Core.cpp:2439
LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate, LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1587
LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty)
Obtain a constant value referring to an undefined value of a type.
Definition: Core.cpp:1016
Rename collisions when linking (static functions)
Definition: Core.h:176
uint64_t LLVMGetEnumAttributeValue(LLVMAttributeRef A)
Get the enum attribute&#39;s value.
Definition: Core.cpp:151
void LLVMGlobalSetMetadata(LLVMValueRef Global, unsigned Kind, LLVMMetadataRef MD)
Sets a metadata attachment, erasing the existing metadata attachment if it already exists for the giv...
Definition: Core.cpp:2029
LLVMValueRef LLVMGetInlineAsm(LLVMTypeRef Ty, char *AsmString, size_t AsmStringSize, char *Constraints, size_t ConstraintsSize, LLVMBool HasSideEffects, LLVMBool IsAlignStack, LLVMInlineAsmDialect Dialect)
Create the specified uniqued inline asm string.
Definition: Core.cpp:438
LLVMBool LLVMIsCleanup(LLVMValueRef LandingPad)
Definition: Core.cpp:3085
void LLVMGetSubtypes(LLVMTypeRef Tp, LLVMTypeRef *Arr)
Returns type&#39;s subtypes.
Definition: Core.cpp:727
LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char Str[], unsigned SLen)
Definition: Core.cpp:1308
Arrays.
Definition: Core.h:157
void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz)
Definition: Core.cpp:1913
static Type * getPPC_FP128Ty(LLVMContext &C)
Definition: Type.cpp:170
void LLVMSetNormalDest(LLVMValueRef Invoke, LLVMBasicBlockRef B)
Set the normal destination basic block.
Definition: Core.cpp:2764
LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType)
Definition: Core.cpp:1642
void LLVMContextSetDiagnosticHandler(LLVMContextRef C, LLVMDiagnosticHandler Handler, void *DiagnosticContext)
Set the diagnostic handler for this context.
Definition: Core.cpp:85
LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar)
Definition: Core.cpp:2086
LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:3134
static StructType * get(LLVMContext &Context, ArrayRef< Type *> Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
Definition: Type.cpp:342
LLVMBool LLVMIsStringAttribute(LLVMAttributeRef A)
Definition: Core.cpp:184
LLVMValueRef LLVMGetIntrinsicDeclaration(LLVMModuleRef Mod, unsigned ID, LLVMTypeRef *ParamTypes, size_t ParamCount)
Create or insert the declaration of an intrinsic.
Definition: Core.cpp:2299
Expected< const typename ELFT::Shdr * > getSection(typename ELFT::ShdrRange Sections, uint32_t Index)
Definition: ELF.h:275
SIMD &#39;packed&#39; format, or other vector type.
Definition: Core.h:159
LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB)
Obtain the first instruction in a basic block.
Definition: Core.cpp:2588
LLVMTypeRef LLVMFloatType(void)
Definition: Core.cpp:613
AtomicOrdering
Atomic ordering for LLVM&#39;s memory model.
LLVMUnnamedAddr
Definition: Core.h:194
global_iterator global_begin()
Definition: Module.h:578
void LLVMDisposeMessage(char *Message)
Definition: Core.cpp:70
A load or store which is not atomic.
Definition: Core.h:329
LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType)
Definition: Core.cpp:1733
LLVMValueRef LLVMBuildSRem(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:3219
struct LLVMOpaqueType * LLVMTypeRef
Each value in the LLVM IR has a type, an LLVMTypeRef.
Definition: Types.h:69
AttributeList getAttributes(LLVMContext &C, ID id)
Return the attributes for an intrinsic.
LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst)
Obtain the instruction that occurred before this one.
Definition: Core.cpp:2612
void LLVMContextSetYieldCallback(LLVMContextRef C, LLVMYieldCallback Callback, void *OpaqueHandle)
Set the yield callback function for this context.
Definition: Core.cpp:103
static Constant * getZExt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:1665
Instruction * clone() const
Create a copy of &#39;this&#39; instruction that is identical in all ways except the following: ...
Subprogram description.
Key
PAL metadata keys.
void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos)
Move a basic block to before another one.
Definition: Core.cpp:2574
static Constant * getSizeOf(Type *Ty)
getSizeOf constant expr - computes the (alloc) size of a type (in address-units, not bits) in a targe...
Definition: Constants.cpp:1915
LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant, LLVMValueRef ElementValueConstant, LLVMValueRef IndexConstant)
Definition: Core.cpp:1752
void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest)
Obtain the types of a function&#39;s parameters.
Definition: Core.cpp:653
A constant value that is initialized with an expression using other constant values.
Definition: Constants.h:889
Class to represent function types.
Definition: DerivedTypes.h:103
void LLVMGlobalEraseMetadata(LLVMValueRef Global, unsigned Kind)
Erases a metadata attachment of the given kind if it exists.
Definition: Core.cpp:2034
char * LLVMPrintModuleToString(LLVMModuleRef M)
Return a string representation of the module.
Definition: Core.cpp:409
static Type * getLabelTy(LLVMContext &C)
Definition: Type.cpp:162
LLVMValueRef LLVMMetadataAsValue(LLVMContextRef C, LLVMMetadataRef MD)
Obtain a Metadata as a Value.
Definition: Core.cpp:1082
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:245
void LLVMDisposeModuleFlagsMetadata(LLVMModuleFlagEntry *Entries)
Destroys module flags metadata entries.
Definition: Core.cpp:341
void LLVMDisposeModule(LLVMModuleRef M)
Destroy a module instance.
Definition: Core.cpp:231
LLVMValueRef LLVMBuildCatchSwitch(LLVMBuilderRef B, LLVMValueRef ParentPad, LLVMBasicBlockRef UnwindBB, unsigned NumHandlers, const char *Name)
Definition: Core.cpp:3036
void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst)
Definition: Core.cpp:2939
opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
Definition: APFloat.cpp:4444
LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar)
Definition: Core.cpp:2118
LLVMValueRef LLVMConstStructInContext(LLVMContextRef C, LLVMValueRef *ConstantVals, unsigned Count, LLVMBool Packed)
Create an anonymous ConstantStruct with the specified values.
Definition: Core.cpp:1379
static Constant * getFPCast(Constant *C, Type *Ty)
Create a FPExt, Bitcast or FPTrunc for fp -> fp casts.
Definition: Constants.cpp:1625
LLVMBool LLVMIsTailCall(LLVMValueRef Call)
Obtain whether a call instruction is a tail call.
Definition: Core.cpp:2741
LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB)
Definition: Core.cpp:1790
void llvm_shutdown()
llvm_shutdown - Deallocate and destroy all ManagedStatic variables.
LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType)
Definition: Core.cpp:1703
BinOp
This enumeration lists the possible modifications atomicrmw can make.
Definition: Instructions.h:704
LLVMValueKind
Definition: Core.h:251
LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal, LLVMValueRef *ConstantIndices, unsigned NumIndices)
Definition: Core.cpp:1616
struct LLVMOpaqueUse * LLVMUseRef
Used to get the users and usees of a Value.
Definition: Types.h:137
LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal, LLVMValueRef *ConstantIndices, unsigned NumIndices)
Definition: Core.cpp:1626
Keep one copy of function when linking (inline)
Definition: Core.h:168
static Constant * getAShr(Constant *C1, Constant *C2, bool isExact=false)
Definition: Constants.cpp:2321
LLVMValueRef LLVMBuildOr(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:3249
LLVMValueRef LLVMIsATerminatorInst(LLVMValueRef Inst)
Determine whether an instruction is a terminator.
Definition: Core.cpp:2658
void LLVMDeleteFunction(LLVMValueRef Fn)
Remove a function from its containing module and deletes it.
Definition: Core.cpp:2272
void LLVMRemoveCallSiteEnumAttribute(LLVMValueRef C, LLVMAttributeIndex Idx, unsigned KindID)
Definition: Core.cpp:2721
struct LLVMOpaqueContext * LLVMContextRef
The top-level container for all LLVM global data.
Definition: Types.h:54
LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:3209
LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType)
Definition: Core.cpp:1677
OR a value and return the old one.
Definition: Core.h:361
LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB)
Go backwards in a basic block iterator.
Definition: Core.cpp:2531
This instruction compares its operands according to the predicate given to the constructor.
static Constant * getSelect(Constant *C, Constant *V1, Constant *V2, Type *OnlyIfReducedTy=nullptr)
Select constant expr.
Definition: Constants.cpp:1978
LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M)
Definition: Core.cpp:2062
void LLVMDumpModule(LLVMModuleRef M)
Dump a representation of a module to stderr.
Definition: Core.cpp:382
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
void LLVMDisposeValueMetadataEntries(LLVMValueMetadataEntry *Entries)
Destroys value metadata entries.
Definition: Core.cpp:2025
unsigned LLVMCountIncoming(LLVMValueRef PhiNode)
Obtain the number of incoming basic blocks to a PHI node.
Definition: Core.cpp:2836
LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Deprecated: This cast is always signed.
Definition: Core.cpp:3608
LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C)
Obtain a 32-bit floating point type from a context.
Definition: Core.cpp:591
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
Definition: Instruction.h:126
LLVMMetadataRef Metadata
Definition: Core.cpp:282
unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal)
Obtain the zero extended value for an integer constant value.
Definition: Core.cpp:1313
const std::string & getGC() const
Definition: Function.cpp:465
An instruction for storing to memory.
Definition: Instructions.h:321
void LLVMGetMDNodeOperands(LLVMValueRef V, LLVMValueRef *Dest)
Obtain the given MDNode&#39;s operands.
Definition: Core.cpp:1160
LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1525
LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB)
Obtain the last instruction in a basic block.
Definition: Core.cpp:2596
const char * LLVMModuleFlagEntriesGetKey(LLVMModuleFlagEntry *Entries, unsigned Index, size_t *Len)
Returns the key for a module flag entry at a specific index.
Definition: Core.cpp:353
LLVMValueRef LLVMBuildSub(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:3149
LLVMUseRef LLVMGetNextUse(LLVMUseRef U)
Obtain the next use of a value.
Definition: Core.cpp:948
static const fltSemantics & IEEEdouble() LLVM_READNONE
Definition: APFloat.cpp:123
LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name, LLVMTypeRef FunctionTy)
Add a function to a module under a specified name.
Definition: Core.cpp:2230
LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:3144
static Constant * getUDiv(Constant *C1, Constant *C2, bool isExact=false)
Definition: Constants.cpp:2271
static Constant * getNSWNeg(Constant *C)
Definition: Constants.h:974
Keep one copy of function when linking (weak)
Definition: Core.h:172
unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy)
Obtain the number of parameters this function accepts.
Definition: Core.cpp:649
LLVMIntPredicate
Definition: Core.h:283
static Function * getFunction(Constant *C)
Definition: Evaluator.cpp:221
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:3159
unsigned getBitWidth() const
Get the number of bits in this IntegerType.
Definition: DerivedTypes.h:66
struct LLVMOpaqueAttributeRef * LLVMAttributeRef
Used to represent an attributes.
Definition: Types.h:144
iterator begin()
Definition: Function.h:656
Type::subtype_iterator element_iterator
Definition: DerivedTypes.h:301
static ManagedStatic< LLVMContext > GlobalContext
Definition: Core.cpp:77
static ConstantAsMetadata * get(Constant *C)
Definition: Metadata.h:410
Function * getDeclaration(Module *M, ID id, ArrayRef< Type *> Tys=None)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
Definition: Function.cpp:1020
LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:3552
LLVMDiagnosticSeverity
Definition: Core.h:377
static Constant * getFDiv(Constant *C1, Constant *C2)
Definition: Constants.cpp:2281
LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name)
Create an empty structure in a context having a specified name.
Definition: Core.cpp:674
LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N, LLVMBool SignExtend)
Obtain a constant value for an integer type.
Definition: Core.cpp:1274
static BinaryOperator * CreateAdd(Value *S1, Value *S2, const Twine &Name, Instruction *InsertBefore, Value *FlagsOp)
size_t LLVMGetBufferSize(LLVMMemoryBufferRef MemBuf)
Definition: Core.cpp:3863
LLVMValueRef LLVMBuildAnd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:3244
Class to represent pointers.
Definition: DerivedTypes.h:467
void LLVMSetCmpXchgSuccessOrdering(LLVMValueRef CmpXchgInst, LLVMAtomicOrdering Ordering)
Definition: Core.cpp:3778
void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage)
Definition: Core.cpp:1833
void initializePrintBasicBlockPassPass(PassRegistry &)
unsigned LLVMGetIntrinsicID(LLVMValueRef Fn)
Obtain the ID number from a function instance.
Definition: Core.cpp:2288
void LLVMAddTargetDependentFunctionAttr(LLVMValueRef Fn, const char *A, const char *V)
Add a target-dependent attribute to a function.
Definition: Core.cpp:2400
LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst)
Obtain the basic block to which an instruction belongs.
Definition: Core.cpp:2584
LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C)
Definition: Core.cpp:550
void LLVMSetArgOperand(LLVMValueRef Funclet, unsigned i, LLVMValueRef value)
Definition: Core.cpp:3123
LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M)
Definition: Core.cpp:2070
const char * LLVMGetBasicBlockName(LLVMBasicBlockRef BB)
Obtain the string name of a basic block.
Definition: Core.cpp:2481
LLVMAttributeRef LLVMGetCallSiteStringAttribute(LLVMValueRef C, LLVMAttributeIndex Idx, const char *K, unsigned KLen)
Definition: Core.cpp:2715
LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1464
unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy)
Obtain the length of an array type.
Definition: Core.cpp:758
use_iterator_impl< Use > use_iterator
Definition: Value.h:332
void LLVMDisposePassManager(LLVMPassManagerRef PM)
Frees the memory of a pass pipeline.
Definition: Core.cpp:3908
LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char Str[], unsigned SLen, uint8_t Radix)
Definition: Core.cpp:1294
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return &#39;this&#39;.
Definition: Type.h:304
LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef B, LLVMValueRef Val, const char *Name)
Definition: Core.cpp:3704
void LLVMSetVolatile(LLVMValueRef MemAccessInst, LLVMBool isVolatile)
Definition: Core.cpp:3479
AttributeSet getAttributes(unsigned Index) const
The attributes for the specified index are returned.
LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C)
Create a void type in a context.
Definition: Core.cpp:772
11: Arbitrary bit width integers
Definition: Type.h:71
static MetadataAsValue * get(LLVMContext &Context, Metadata *MD)
Definition: Metadata.cpp:106
PassManager manages ModulePassManagers.
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:1773
static int map_from_llvmopcode(LLVMOpcode code)
Definition: Core.cpp:1419
ExternalWeak linkage description.
Definition: GlobalValue.h:58
void LLVMSetUnnamedAddr(LLVMValueRef Global, LLVMBool HasUnnamedAddr)
Deprecated: Use LLVMSetUnnamedAddress instead.
Definition: Core.cpp:1957
#define LLVM_DEFINE_VALUE_CAST(name)
Definition: Core.cpp:917
LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1469
LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal)
Definition: Core.cpp:1447
void LLVMSetTarget(LLVMModuleRef M, const char *Triple)
Set the target triple for a module.
Definition: Core.cpp:273
static Constant * getInsertValue(Constant *Agg, Constant *Val, ArrayRef< unsigned > Idxs, Type *OnlyIfReducedTy=nullptr)
Definition: Constants.cpp:2171
0: type with no size
Definition: Type.h:57
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata *> MDs)
Definition: Metadata.h:1166
#define P(N)
Same, but only replaced by something equivalent.
Definition: GlobalValue.h:52
static Constant * getFNeg(Constant *C)
Definition: Constants.cpp:2226
LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn)
Obtain the first basic block in a function.
Definition: Core.cpp:2507
LLVMNamedMDNodeRef LLVMGetNamedMetadata(LLVMModuleRef M, const char *Name, size_t NameLen)
Retrieve a NamedMDNode with the given name, returning NULL if no such node exists.
Definition: Core.cpp:1144
LLVMTypeRef LLVMMetadataTypeInContext(LLVMContextRef C)
Create a metadata type in a context.
Definition: Core.cpp:781
LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V, const char *Name)
Definition: Core.cpp:3275
void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L)
Definition: Core.cpp:2927
const unsigned * LLVMGetIndices(LLVMValueRef Inst)
Obtain the indices as an array.
Definition: Core.cpp:2864
static Constant * getFRem(Constant *C1, Constant *C2)
Definition: Constants.cpp:2293
void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block)
Definition: Core.cpp:2899
void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes, unsigned ElementCount, LLVMBool Packed)
Set the contents of a structure type.
Definition: Core.cpp:687
LLVMValueRef LLVMBuildShl(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:3229
static ErrorOr< std::unique_ptr< MemoryBuffer > > getSTDIN()
Read all of stdin into a file buffer, and return it.
static IntegerType * getInt128Ty(LLVMContext &C)
Definition: Type.cpp:178
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
Definition: Function.h:136
Acquire provides a barrier of the sort necessary to acquire a lock to access other memory with normal...
Definition: Core.h:335
void addAttr(Attribute::AttrKind Kind)
Definition: Function.cpp:173
LLVMTypeKind
Definition: Core.h:145
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef B, LLVMValueRef VecVal, LLVMValueRef EltVal, LLVMValueRef Index, const char *Name)
Definition: Core.cpp:3678
static ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
Definition: Constants.cpp:1401
LLVMMetadataRef LLVMGetModuleFlag(LLVMModuleRef M, const char *Key, size_t KeyLen)
Add a module-level flag to the module-level flags metadata if it doesn&#39;t already exist.
Definition: Core.cpp:368
LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef B, LLVMTypeRef Ty, const char *Name)
Definition: Core.cpp:3336
LLVMAtomicOrdering
Definition: Core.h:328
LLVMTypeRef LLVMInt32Type(void)
Definition: Core.cpp:569
alias_iterator alias_end()
Definition: Module.h:619
void LLVMGetAttributesAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx, LLVMAttributeRef *Attrs)
Definition: Core.cpp:2370
LLVMValueRef LLVMBuildPhi(LLVMBuilderRef B, LLVMTypeRef Ty, const char *Name)
Definition: Core.cpp:3637
LLVM Basic Block Representation.
Definition: BasicBlock.h:58
LLVMValueRef LLVMIsAMDString(LLVMValueRef Val)
Definition: Core.cpp:932
Sets the value if it&#39;s greater than the original using an unsigned comparison and return the old one...
Definition: Core.h:372
LLVMValueRef LLVMGetMetadata(LLVMValueRef Inst, unsigned KindID)
Return metadata associated with an instruction value.
Definition: Core.cpp:855
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal)
Definition: Core.cpp:3080
unsigned LLVMCountBasicBlocks(LLVMValueRef FnRef)
Obtain the number of basic blocks in a function.
Definition: Core.cpp:2493
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:69
LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy)
Determine whether a structure is packed.
Definition: Core.cpp:709
void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal)
Replace all uses of a value with another one.
Definition: Core.cpp:847
LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:3527
LLVMBool LLVMStartMultithreaded()
Deprecated: Multi-threading can only be enabled/disabled with the compile time define LLVM_ENABLE_THR...
Definition: Core.cpp:3914
LLVMDiagnosticHandler LLVMContextGetDiagnosticHandler(LLVMContextRef C)
Get the diagnostic handler of this context.
Definition: Core.cpp:94
LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M)
Obtain the context to which this module is associated.
Definition: Core.cpp:460
LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1552
static BlockAddress * get(Function *F, BasicBlock *BB)
Return a BlockAddress for the specified function and basic block.
Definition: Constants.cpp:1434
LLVMValueRef LLVMBuildInvoke2(LLVMBuilderRef B, LLVMTypeRef Ty, LLVMValueRef Fn, LLVMValueRef *Args, unsigned NumArgs, LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch, const char *Name)
Definition: Core.cpp:2991
static LLVMValueMetadataEntry * llvm_getMetadata(size_t *NumEntries, llvm::function_ref< void(MetadataEntries &)> AccessMD)
Definition: Core.cpp:890
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
Definition: Constant.h:42
LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:3154
LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name)
Obtain a Function value from a Module by its name.
Definition: Core.cpp:2236
LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal)
Definition: Core.cpp:1456
This file contains the declarations for the subclasses of Constant, which represent the different fla...
LLVMValueRef LLVMGetLastGlobalAlias(LLVMModuleRef M)
Obtain an iterator to the last GlobalAlias in a Module.
Definition: Core.cpp:2196
unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy)
Get the number of elements defined inside the structure.
Definition: Core.cpp:693
10: Tokens
Definition: Type.h:67
LLVMThreadLocalMode LLVMGetThreadLocalMode(LLVMValueRef GlobalVar)
Definition: Core.cpp:2126
LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:3537
char * LLVMPrintValueToString(LLVMValueRef Val)
Return a string representation of the value.
Definition: Core.cpp:833
LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef B, LLVMValueRef VecVal, LLVMValueRef Index, const char *Name)
Definition: Core.cpp:3672
std::error_code getError() const
Definition: ErrorOr.h:160
LLVMValueRef LLVMBuildFMul(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:3184
static Constant * getAnd(Constant *C1, Constant *C2)
Definition: Constants.cpp:2297
#define LLVM_EXTENSION
LLVM_EXTENSION - Support compilers where we have a keyword to suppress pedantic diagnostics.
Definition: Compiler.h:263
void LLVMSetDLLStorageClass(LLVMValueRef Global, LLVMDLLStorageClass Class)
Definition: Core.cpp:1923
ModFlagBehavior
This enumeration defines the supported behaviors of module flags.
Definition: Module.h:113
ConstantFP - Floating Point Values [float, double].
Definition: Constants.h:264
LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C)
Obtain a 128-bit floating point type (two 64-bits) from a context.
Definition: Core.cpp:603
80 bit floating point type (X87)
Definition: Core.h:150
LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:3714
double convertToDouble() const
Definition: APFloat.h:1097
LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer, LLVMValueRef *Indices, unsigned NumIndices, const char *Name)
Definition: Core.cpp:3429
static Constant * getSExtOrBitCast(Constant *C, Type *Ty)
Definition: Constants.cpp:1575
void LLVMSetUnnamedAddress(LLVMValueRef Global, LLVMUnnamedAddr UnnamedAddr)
Definition: Core.cpp:1940
LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1519
bool llvm_is_multithreaded()
Returns true if LLVM is compiled with support for multi-threading, and false otherwise.
Definition: Threading.cpp:31
unsigned getNumAttributes() const
Return the number of attributes in this set.
Definition: Attributes.cpp:574
element_iterator element_end() const
Definition: DerivedTypes.h:304
LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList, unsigned NumIdx)
Definition: Core.cpp:1768
LLVMValueRef LLVMBuildExactUDiv(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:3194
void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest)
Definition: Core.cpp:3068
LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1577
unsigned LLVMGetNumContainedTypes(LLVMTypeRef Tp)
Return the number of types in the derived type.
Definition: Core.cpp:754
void LLVMInstructionEraseFromParent(LLVMValueRef Inst)
Remove and delete an instruction.
Definition: Core.cpp:2624
static Constant * getShuffleVector(Constant *V1, Constant *V2, Constant *Mask, Type *OnlyIfReducedTy=nullptr)
Definition: Constants.cpp:2148
LLVMModuleFlagBehavior LLVMModuleFlagEntriesGetFlagBehavior(LLVMModuleFlagEntry *Entries, unsigned Index)
Returns the flag behavior for a module flag entry at a specific index.
Definition: Core.cpp:346
LLVMNamedMDNodeRef LLVMGetPreviousNamedMetadata(LLVMNamedMDNodeRef NMD)
Decrement a NamedMDNode iterator to the previous NamedMDNode.
Definition: Core.cpp:1136
param_iterator param_begin() const
Definition: DerivedTypes.h:128
LLVMValueMetadataEntry * LLVMGlobalCopyAllMetadata(LLVMValueRef Value, size_t *NumEntries)
Retrieves an array of metadata entries representing the metadata attached to this value...
Definition: Core.cpp:1999
LLVMUseRef LLVMGetOperandUse(LLVMValueRef Val, unsigned Index)
Obtain the use of an operand at a specific index in a llvm::User value.
Definition: Core.cpp:989
void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos)
Move a basic block to after another one.
Definition: Core.cpp:2578
LLVMValueRef LLVMGetUsedValue(LLVMUseRef U)
Obtain the value this use corresponds to.
Definition: Core.cpp:959
void addAttribute(unsigned i, Attribute::AttrKind Kind)
adds the attribute to the list of attributes.
Definition: Function.cpp:368
static Type * getVoidTy(LLVMContext &C)
Definition: Type.cpp:161
LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount)
Create a fixed size array type that refers to a specific type.
Definition: Core.cpp:735
LLVMValueRef LLVMGetElementAsConstant(LLVMValueRef C, unsigned idx)
Get an element at specified index as a constant.
Definition: Core.cpp:1359
LLVMBool LLVMIsUndef(LLVMValueRef Val)
Determine whether a value instance is undefined.
Definition: Core.cpp:1030
char * LLVMGetDiagInfoDescription(LLVMDiagnosticInfoRef DI)
Return a string representation of the DiagnosticInfo.
Definition: Core.cpp:188
void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align)
Set the alignment for a function parameter.
Definition: Core.cpp:2462
LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str, unsigned SLen)
Obtain a MDString value from a context.
Definition: Core.cpp:1040
LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn)
Definition: Core.cpp:3032
LLVMBool LLVMContextShouldDiscardValueNames(LLVMContextRef C)
Retrieve whether the given context is set to discard all value names.
Definition: Core.cpp:110
LLVMValueRef LLVMConstString(const char *Str, unsigned Length, LLVMBool DontNullTerminate)
Create a ConstantDataSequential with string content in the global context.
Definition: Core.cpp:1353
This instruction compares its operands according to the predicate given to the constructor.
LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits)
Definition: Core.cpp:556
StringRef getName() const
Return the name for this struct type if it has an identity.
Definition: Type.cpp:500
Functions.
Definition: Core.h:155
Attribute::AttrKind getKindAsEnum() const
Return the attribute&#39;s kind as an enum (Attribute::AttrKind).
Definition: Attributes.cpp:174
LLVMBasicBlockRef LLVMGetSuccessor(LLVMValueRef Term, unsigned i)
Return the specified successor.
Definition: Core.cpp:2783
LLVMValueRef LLVMMDString(const char *Str, unsigned SLen)
Obtain a MDString value from the global context.
Definition: Core.cpp:1047
6: 128-bit floating point type (two 64-bits, PowerPC)
Definition: Type.h:63
static FunctionType * get(Type *Result, ArrayRef< Type *> Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
Definition: Type.cpp:297
static Constant * get(StructType *T, ArrayRef< Constant *> V)
Definition: Constants.cpp:1044
LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1562
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
Definition: BasicBlock.h:100
void LLVMContextSetDiscardValueNames(LLVMContextRef C, LLVMBool Discard)
Set whether the given context discards all value names.
Definition: Core.cpp:114
arg_iterator arg_begin()
Definition: Function.h:671
LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef B)
Definition: Core.cpp:3059
static Constant * getICmp(unsigned short pred, Constant *LHS, Constant *RHS, bool OnlyIfReduced=false)
get* - Return some common constants without having to specify the full Instruction::OPCODE identifier...
Definition: Constants.cpp:2053
LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef B, LLVMValueRef Fn, LLVMValueRef *Args, unsigned NumArgs, LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch, const char *Name)
Definition: Core.cpp:2978
self_iterator getIterator()
Definition: ilist_node.h:82
void LLVMShutdown()
Deallocate and destroy all ManagedStatic variables.
Definition: Core.cpp:60
LLVMTypeRef LLVMPPCFP128Type(void)
Definition: Core.cpp:625
LLVMValueRef LLVMBuildInBoundsGEP2(LLVMBuilderRef B, LLVMTypeRef Ty, LLVMValueRef Pointer, LLVMValueRef *Indices, unsigned NumIndices, const char *Name)
Definition: Core.cpp:3439
Class to represent integer types.
Definition: DerivedTypes.h:40
LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType)
Definition: Core.cpp:1687
And a value and return the old one.
Definition: Core.h:359
LLVMBool LLVMIsEnumAttribute(LLVMAttributeRef A)
Check for the different types of attributes.
Definition: Core.cpp:179
LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType)
Definition: Core.cpp:1721
LLVMValueRef LLVMBuildNot(LLVMBuilderRef B, LLVMValueRef V, const char *Name)
Definition: Core.cpp:3284
LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder)
Definition: Core.cpp:2904
const char * LLVMGetTarget(LLVMModuleRef M)
Obtain the target triple for a module.
Definition: Core.cpp:269
const char * LLVMGetValueName2(LLVMValueRef Val, size_t *Length)
Obtain the string name of a value.
Definition: Core.cpp:811
LLVMTypeRef LLVMInt16Type(void)
Definition: Core.cpp:566
Sets the value if it&#39;s greater than the original using a signed comparison and return the old one...
Definition: Core.h:363
Metadata wrapper in the Value hierarchy.
Definition: Metadata.h:174
static Constant * getNot(Constant *C)
Definition: Constants.cpp:2232
unsigned LLVMGetEnumAttributeKind(LLVMAttributeRef A)
Get the unique id corresponding to the enum attribute passed as argument.
Definition: Core.cpp:147
void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr)
Definition: Core.cpp:2894
void LLVMSetPersonalityFn(LLVMValueRef Fn, LLVMValueRef PersonalityFn)
Set the personality function attached to the function.
Definition: Core.cpp:2284
static Constant * getAllOnesValue(Type *Ty)
Definition: Constants.cpp:319
LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name)
Obtain a Type from a module by its registered name.
Definition: Core.cpp:721
LLVMValueRef LLVMGetPersonalityFn(LLVMValueRef Fn)
Obtain the personality function attached to the function.
Definition: Core.cpp:2280
LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char Str[], uint8_t Radix)
Definition: Core.cpp:1288
unsigned LLVMGetNumClauses(LLVMValueRef LandingPad)
Definition: Core.cpp:3072
LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal)
Definition: Core.cpp:1431
static LocalAsMetadata * get(Value *Local)
Definition: Metadata.h:436
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
Definition: Function.cpp:193
unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr)
Obtain the calling convention for a call instruction.
Definition: Core.cpp:2672
void LLVMDumpValue(LLVMValueRef Val)
Dump a representation of a value to stderr.
Definition: Core.cpp:829
LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1486
struct LLVMOpaqueModuleProvider * LLVMModuleProviderRef
Interface used to provide a module to JIT or interpreter.
Definition: Types.h:125
void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char *Name, LLVMValueRef *Dest)
Obtain the named metadata operands for a module.
Definition: Core.cpp:1180
FunctionPassManager manages FunctionPasses and BasicBlockPassManagers.
LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType)
Definition: Core.cpp:1662
int LLVMBool
Definition: Types.h:29
int LLVMGetNumOperands(LLVMValueRef Val)
Obtain the number of operands in a llvm::User value.
Definition: Core.cpp:998
static UndefValue * get(Type *T)
Static factory methods - Return an &#39;undef&#39; object of the specified type.
Definition: Constants.cpp:1415
const char * LLVMIntrinsicGetName(unsigned ID, size_t *NameLength)
Retrieves the name of an intrinsic.
Definition: Core.cpp:2308
void * LLVMContextGetDiagnosticContext(LLVMContextRef C)
Get the diagnostic context of this context.
Definition: Core.cpp:99
unsigned LLVMGetCallSiteAttributeCount(LLVMValueRef C, LLVMAttributeIndex Idx)
Definition: Core.cpp:2693
LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer, LLVMValueRef *Indices, unsigned NumIndices, const char *Name)
Definition: Core.cpp:3412
LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name, unsigned AddressSpace)
Definition: Core.cpp:2049
struct LLVMOpaqueDiagnosticInfo * LLVMDiagnosticInfoRef
Definition: Types.h:149
type with no size
Definition: Core.h:146
size_t size() const
Definition: SmallVector.h:53
LLVMBasicBlockRef LLVMCreateBasicBlockInContext(LLVMContextRef C, const char *Name)
Create a new basic block without inserting it into a function.
Definition: Core.cpp:2539
static wasm::ValType getType(const TargetRegisterClass *RC)
LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:3507
const char * LLVMGetDataLayout(LLVMModuleRef M)
Definition: Core.cpp:260
C setMetadata(LLVMContext::MD_range, MDNode::get(Context, LowAndHigh))
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Like Private, but linker removes.
Definition: Core.h:184
LLVMValueRef LLVMGetParam(LLVMValueRef FnRef, unsigned index)
Obtain the parameter at the specified index.
Definition: Core.cpp:2422
LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str, unsigned Length, LLVMBool DontNullTerminate)
Create a ConstantDataSequential and initialize it with a string.
Definition: Core.cpp:1344
LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1557
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
void LLVMAddHandler(LLVMValueRef CatchSwitch, LLVMBasicBlockRef Dest)
Definition: Core.cpp:3093
LLVMNamedMDNodeRef LLVMGetNextNamedMetadata(LLVMNamedMDNodeRef NMD)
Advance a NamedMDNode iterator to the next NamedMDNode.
Definition: Core.cpp:1128
LLVMTypeRef LLVMVoidType(void)
These are similar to the above functions except they operate on the global context.
Definition: Core.cpp:785
bool has_error() const
Return the value of the flag in this raw_fd_ostream indicating whether an output error has been encou...
Definition: raw_ostream.h:452
LLVMValueRef LLVMBuildCall(LLVMBuilderRef B, LLVMValueRef Fn, LLVMValueRef *Args, unsigned NumArgs, const char *Name)
Definition: Core.cpp:3641
static Type * getFP128Ty(LLVMContext &C)
Definition: Type.cpp:169
LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C, LLVMValueRef FnRef, const char *Name)
Append a basic block to the end of a function.
Definition: Core.cpp:2544
LLVMTypeRef LLVMGetElementType(LLVMTypeRef WrappedTy)
Obtain the type of elements within a sequential type.
Definition: Core.cpp:747
LLVMValueRef LLVMBuildNeg(LLVMBuilderRef B, LLVMValueRef V, const char *Name)
Definition: Core.cpp:3266
void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf)
Definition: Core.cpp:3867
LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:3532
void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC)
Set the calling convention of a function.
Definition: Core.cpp:2342
Like Internal, but omit from symbol table.
Definition: Core.h:178
void LLVMGetBasicBlocks(LLVMValueRef FnRef, LLVMBasicBlockRef *BasicBlocksRefs)
Obtain all of the basic blocks in a function.
Definition: Core.cpp:2497
const APFloat & getValueAPF() const
Definition: Constants.h:303
Sets the value if it&#39;s Smaller than the original using a signed comparison and return the old one...
Definition: Core.h:366
global_iterator global_end()
Definition: Module.h:580
14: Arrays
Definition: Type.h:74
static Constant * getFCmp(unsigned short pred, Constant *LHS, Constant *RHS, bool OnlyIfReduced=false)
Definition: Constants.cpp:2078
LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty)
Obtain the context to which this type instance is associated.
Definition: Core.cpp:514
static Constant * getPointerCast(Constant *C, Type *Ty)
Create a BitCast, AddrSpaceCast, or a PtrToInt cast constant expression.
Definition: Constants.cpp:1587
static Constant * getSIToFP(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:1714
LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index)
Obtain an operand at a specific index in a llvm::User value.
Definition: Core.cpp:975
LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType)
Definition: Core.cpp:1715
static Type * getHalfTy(LLVMContext &C)
Definition: Type.cpp:163
unsigned LLVMCountParams(LLVMValueRef FnRef)
Obtain the number of parameters in a function.
Definition: Core.cpp:2409
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Definition: Type.cpp:240
LLVMModuleProviderRef LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M)
Changes the type of M so it can be passed to FunctionPassManagers and the JIT.
Definition: Core.cpp:3802
void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr)
Definition: Core.cpp:2912
LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:3614
LLVM_ATTRIBUTE_RETURNS_NONNULL void * safe_malloc(size_t Sz)
Definition: MemAlloc.h:26
LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef B)
Definition: Core.cpp:2946
Iterator for intrusive lists based on ilist_node.
LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str, const char *Name)
Definition: Core.cpp:3462
LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty)
Obtain a constant that is a constant pointer pointing to NULL for a specified type.
Definition: Core.cpp:1034
void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal)
Definition: Core.cpp:2105
LLVMThreadLocalMode
Definition: Core.h:320
LLVMVisibility LLVMGetVisibility(LLVMValueRef Global)
Definition: Core.cpp:1908
LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1497
void LLVMInitializeCore(LLVMPassRegistryRef R)
Definition: Core.cpp:56
auto size(R &&Range, typename std::enable_if< std::is_same< typename std::iterator_traits< decltype(Range.begin())>::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr) -> decltype(std::distance(Range.begin(), Range.end()))
Get the size of a range.
Definition: STLExtras.h:1167
LLVMContextRef LLVMContextCreate()
Create a new context.
Definition: Core.cpp:79
Labels.
Definition: Core.h:153
LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty)
Obtain the enumerated type of a Type instance.
Definition: Core.cpp:469
const char * LLVMGetDebugLocFilename(LLVMValueRef Val, unsigned *Length)
Return the filename of the debug location for this value, which must be an llvm::Instruction, llvm::GlobalVariable, or llvm::Function.
Definition: Core.cpp:1222
LLVMTypeRef LLVMTypeOf(LLVMValueRef Val)
Obtain the type of a value.
Definition: Core.cpp:796
LLVMValueRef LLVMGetFirstGlobalAlias(LLVMModuleRef M)
Obtain an iterator to the first GlobalAlias in a Module.
Definition: Core.cpp:2188
LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty)
Obtain a constant value referring to the instance of a type consisting of all ones.
Definition: Core.cpp:1012
16: SIMD &#39;packed&#39; format, or other vector type
Definition: Type.h:76
LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType)
Definition: Core.cpp:1652
static Constant * getSDiv(Constant *C1, Constant *C2, bool isExact=false)
Definition: Constants.cpp:2276
iterator end()
Definition: BasicBlock.h:271
LLVMValueRef LLVMGetCalledValue(LLVMValueRef Instr)
Obtain the pointer to the function invoked by this instruction.
Definition: Core.cpp:2731
const char * LLVMGetSourceFileName(LLVMModuleRef M, size_t *Len)
Obtain the module&#39;s original source file name.
Definition: Core.cpp:245
LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant, LLVMValueRef ElementValueConstant, unsigned *IdxList, unsigned NumIdx)
Definition: Core.cpp:1774
LLVMValueRef LLVMBuildURem(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:3214
static ValueAsMetadata * get(Value *V)
Definition: Metadata.cpp:349
LLVMTypeRef LLVMLabelType(void)
Definition: Core.cpp:788
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:847
Keep one copy of function when linking (inline)
Definition: GlobalValue.h:51
Arbitrary bit width integers.
Definition: Core.h:154
Module.h This file contains the declarations for the Module class.
LLVMValueRef LLVMGetCondition(LLVMValueRef Branch)
Return the condition of a branch instruction.
Definition: Core.cpp:2797
FunctionType * getType(LLVMContext &Context, ID id, ArrayRef< Type *> Tys=None)
Return the function type for an intrinsic.
Definition: Function.cpp:976
static LLVMOpcode map_to_llvmopcode(int opcode)
Definition: Core.cpp:1409
Type::subtype_iterator param_iterator
Definition: DerivedTypes.h:126
AddressSpace
Definition: NVPTXBaseInfo.h:22
LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef B, LLVMRealPredicate Op, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:3628
static Constant * getNUWMul(Constant *C1, Constant *C2)
Definition: Constants.h:997
struct LLVMOpaqueBasicBlock * LLVMBasicBlockRef
Represents a basic block of instructions in LLVM IR.
Definition: Types.h:83
Structures.
Definition: Core.h:156
LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst)
Obtain the instruction that occurs after the one specified.
Definition: Core.cpp:2604
void LLVMDeleteGlobal(LLVMValueRef GlobalVar)
Definition: Core.cpp:2094
void LLVMSetParentCatchSwitch(LLVMValueRef CatchPad, LLVMValueRef CatchSwitch)
Set the parent catchswitch instruction of a catchpad instruction.
Definition: Core.cpp:3112
Xor a value and return the old one.
Definition: Core.h:362
alias_iterator alias_begin()
Definition: Module.h:617
LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType)
Definition: Core.cpp:1709
LLVMValueRef LLVMBuildXor(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:3254
LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:3189
static Constant * getNSWSub(Constant *C1, Constant *C2)
Definition: Constants.h:985
Emits a warning if two values disagree.
Definition: Core.h:403
static Constant * getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:1637
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Definition: Constants.cpp:622
LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy)
Returns whether a function type is variadic.
Definition: Core.cpp:641
LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder)
Definition: Core.cpp:2933
Uses the specified value, regardless of the behavior or value of the other module.
Definition: Core.h:423
LLVMLinkage
Definition: Core.h:165
static Constant * get(Type *Ty, double V)
This returns a ConstantFP, or a vector containing a splat of a ConstantFP, for the specified value in...
Definition: Constants.cpp:685
unsigned LLVMValueMetadataEntriesGetKind(LLVMValueMetadataEntry *Entries, unsigned Index)
Returns the kind of a value metadata entry at a specific index.
Definition: Core.cpp:2010
unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char *Name)
Obtain the number of operands for named metadata in a module.
Definition: Core.cpp:1173
void LLVMSetAtomicSingleThread(LLVMValueRef AtomicInst, LLVMBool NewValue)
Definition: Core.cpp:3764
size_t NameLength
LLVMTypeRef LLVMDoubleType(void)
Definition: Core.cpp:616
32 bit floating point type
Definition: Core.h:148
LLVMValueRef LLVMBuildMemSet(LLVMBuilderRef B, LLVMValueRef Ptr, LLVMValueRef Val, LLVMValueRef Len, unsigned Align)
Creates and inserts a memset to the specified pointer and the specified value.
Definition: Core.cpp:3312
LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef B, LLVMValueRef AggVal, LLVMValueRef EltVal, unsigned Index, const char *Name)
Definition: Core.cpp:3697
LLVMValueRef LLVMGetUser(LLVMUseRef U)
Obtain the user value for a user.
Definition: Core.cpp:955
void setLinkage(LinkageTypes LT)
Definition: GlobalValue.h:445
LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType)
Definition: Core.cpp:1657
LLVMTypeRef LLVMGlobalGetValueType(LLVMValueRef Global)
Returns the "value type" of a global value.
Definition: Core.cpp:1963
8: Metadata
Definition: Type.h:65
The access may modify the value stored in memory.
provides Acquire semantics for loads and Release semantics for stores.
Definition: Core.h:345
static Module::ModFlagBehavior map_to_llvmModFlagBehavior(LLVMModuleFlagBehavior Behavior)
Definition: Core.cpp:286
struct LLVMOpaquePassManager * LLVMPassManagerRef
Definition: Types.h:128
LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount, LLVMBool Packed)
Create a new structure type in the global context.
Definition: Core.cpp:668
LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef B, LLVMValueRef V1, LLVMValueRef V2, LLVMValueRef Mask, const char *Name)
Definition: Core.cpp:3685
void LLVMSetSourceFileName(LLVMModuleRef M, const char *Name, size_t Len)
Set the original source file name of a module to a string Name with length Len.
Definition: Core.cpp:251
double LLVMConstRealGetDouble(LLVMValueRef ConstantVal, LLVMBool *LosesInfo)
Obtain the double value for an floating point constant value.
Definition: Core.cpp:1321
LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str, const char *Name)
Definition: Core.cpp:3467
void LLVMSetExternallyInitialized(LLVMValueRef GlobalVar, LLVMBool IsExtInit)
Definition: Core.cpp:2169
Class for arbitrary precision integers.
Definition: APInt.h:70
LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef B, LLVMTypeRef Ty, const char *Name)
Definition: Core.cpp:3290
static std::unique_ptr< MemoryBuffer > getMemBufferCopy(StringRef InputData, const Twine &BufferName="")
Open the specified memory range as a MemoryBuffer, copying the contents and taking ownership of it...
LLVMValueRef LLVMIsAMDNode(LLVMValueRef Val)
Definition: Core.cpp:924
Same, but only replaced by something equivalent.
Definition: Core.h:169
StringRef getName() const
Definition: Metadata.cpp:1098
LLVMAttributeRef LLVMGetCallSiteEnumAttribute(LLVMValueRef C, LLVMAttributeIndex Idx, unsigned KindID)
Definition: Core.cpp:2708
LLVMValueRef LLVMBuildFree(LLVMBuilderRef B, LLVMValueRef PointerVal)
Definition: Core.cpp:3346
LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType, LLVMTypeRef *ParamTypes, unsigned ParamCount, LLVMBool IsVarArg)
Obtain a function type consisting of a specified signature.
Definition: Core.cpp:634
unsigned getArgNo() const
Return the index of this formal argument in its containing function.
Definition: Argument.h:48
LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:3562
LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar)
Definition: Core.cpp:2110
void LLVMSetModuleInlineAsm2(LLVMModuleRef M, const char *Asm, size_t Len)
Set inline assembly for a module.
Definition: Core.cpp:420
static Constant * getFPToUI(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:1725
LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType)
Definition: Core.cpp:1682
static char getTypeID(Type *Ty)
LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M)
Initializes, executes on the provided module, and finalizes all of the passes scheduled in the pass m...
Definition: Core.cpp:3892
LLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB)
Obtain the terminator instruction for a basic block.
Definition: Core.cpp:2489
Metadata.
Definition: Core.h:160
LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count, LLVMBool Packed)
Create a ConstantStruct in the global Context.
Definition: Core.cpp:1387
static Constant * getZExtOrBitCast(Constant *C, Type *Ty)
Definition: Constants.cpp:1569
LLVMBool LLVMIsConstantString(LLVMValueRef C)
Returns true if the specified constant is an array of i8.
Definition: Core.cpp:1363
element_iterator element_begin() const
Definition: DerivedTypes.h:303
LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate, LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1594
LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C)
Create a X86 MMX type in a context.
Definition: Core.cpp:606
LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1508
LLVMBool LLVMIsDeclaration(LLVMValueRef Global)
Definition: Core.cpp:1800
void LLVMAppendModuleInlineAsm(LLVMModuleRef M, const char *Asm, size_t Len)
Append inline assembly to a module.
Definition: Core.cpp:428
static Instruction * CreateMalloc(Instruction *InsertBefore, Type *IntPtrTy, Type *AllocTy, Value *AllocSize, Value *ArraySize=nullptr, Function *MallocF=nullptr, const Twine &Name="")
Generate the IR for a call to malloc:
amdgpu Simplify well known AMD library false Value Value * Arg
LLVMValueRef LLVMAliasGetAliasee(LLVMValueRef Alias)
Retrieve the target value of an alias.
Definition: Core.cpp:2220
LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:3547
Basic diagnostic printer that uses an underlying raw_ostream.
LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal)
Definition: Core.cpp:1443
void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues, LLVMBasicBlockRef *IncomingBlocks, unsigned Count)
Add an incoming value to the end of a PHI list.
Definition: Core.cpp:2829
static Constant * getFSub(Constant *C1, Constant *C2)
Definition: Constants.cpp:2256
LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef B, LLVMValueRef AggVal, unsigned Index, const char *Name)
Definition: Core.cpp:3692
LLVMValueRef LLVMBuildAShr(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:3239
static Constant * getTruncOrBitCast(Constant *C, Type *Ty)
Definition: Constants.cpp:1581
void LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BBRef)
Remove a basic block from a function.
Definition: Core.cpp:2570
LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1481
static Constant * getNeg(Constant *C, bool HasNUW=false, bool HasNSW=false)
Definition: Constants.cpp:2219
use_iterator use_begin()
Definition: Value.h:339
void(* LLVMDiagnosticHandler)(LLVMDiagnosticInfoRef, void *)
Definition: Core.h:482
LLVMMetadataRef Metadata
Definition: Core.cpp:885
LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1491
LLVMValueRef LLVMBuildMul(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:3169
void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char *Name, LLVMValueRef Val)
Add an operand to named metadata.
Definition: Core.cpp:1190
LLVMBool LLVMIsInBounds(LLVMValueRef GEP)
Check whether the given GEP instruction is inbounds.
Definition: Core.cpp:2819
LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg)
Obtain the previous parameter to a function.
Definition: Core.cpp:2455
LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID)
Create a new, empty module in the global context.
Definition: Core.cpp:222
unsigned LLVMGetNumIndices(LLVMValueRef Inst)
Obtain the number of indices.
Definition: Core.cpp:2850
Obsolete.
Definition: Core.h:182
void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal, LLVMBasicBlockRef Dest)
Definition: Core.cpp:3063
static Constant * getNSWMul(Constant *C1, Constant *C2)
Definition: Constants.h:993
bool hasGC() const
hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm to use during code generatio...
Definition: Function.h:349
LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef B, LLVMTypeRef Ty, LLVMValueRef Val, const char *Name)
Definition: Core.cpp:3301
LLVMAttributeRef wrap(Attribute Attr)
Definition: Attributes.h:190
A raw_ostream that writes to a file descriptor.
Definition: raw_ostream.h:366
char * LLVMPrintTypeToString(LLVMTypeRef Ty)
Return a string representation of the type.
Definition: Core.cpp:522
iterator end()
Definition: Module.h:597
LLVMBool LLVMIsConditional(LLVMValueRef Branch)
Return if a branch is conditional.
Definition: Core.cpp:2793
void LLVMRemoveEnumAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx, unsigned KindID)
Definition: Core.cpp:2390
void setUnnamedAddr(UnnamedAddr Val)
Definition: GlobalValue.h:216
const Function * getParent() const
Definition: Argument.h:42
LLVMValueRef LLVMBuildMemMove(LLVMBuilderRef B, LLVMValueRef Dst, unsigned DstAlign, LLVMValueRef Src, unsigned SrcAlign, LLVMValueRef Size)
Creates and inserts a memmove between the specified pointers.
Definition: Core.cpp:3327
Tentative definitions.
Definition: Core.h:183
LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:3557
static IntegerType * getInt32Ty(LLVMContext &C)
Definition: Type.cpp:176
LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy, unsigned NumWords, const uint64_t Words[])
Obtain a constant value for an integer of arbitrary precision.
Definition: Core.cpp:1279
LLVMTypeRef LLVMInt64Type(void)
Definition: Core.cpp:572
16 bit floating point type
Definition: Core.h:147
LLVMVisibility
Definition: Core.h:188
unsigned LLVMGetEnumAttributeKindForName(const char *Name, size_t SLen)
Return an unique id given the name of a enum attribute, or 0 if no attribute by that name exists...
Definition: Core.cpp:134
LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C)
Obtain a 16-bit floating point type from a context.
Definition: Core.cpp:588
LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef FnRef, const char *Name)
Append a basic block to the end of a function using the global context.
Definition: Core.cpp:2550
const char * LLVMGetStringAttributeValue(LLVMAttributeRef A, unsigned *Length)
Get the string attribute&#39;s value.
Definition: Core.cpp:172
guarantees that if you take all the operations affecting a specific address, a consistent ordering ex...
Definition: Core.h:332
StringRef getValueAsString() const
Return the attribute&#39;s value as a string.
Definition: Attributes.cpp:195
LLVMTypeRef LLVMInt128TypeInContext(LLVMContextRef C)
Definition: Core.cpp:553
LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal)
Definition: Core.cpp:1451
LLVMValueRef LLVMBuildAtomicRMW(LLVMBuilderRef B, LLVMAtomicRMWBinOp op, LLVMValueRef PTR, LLVMValueRef Val, LLVMAtomicOrdering ordering, LLVMBool singleThread)
Definition: Core.cpp:3719
LLVMUnnamedAddr LLVMGetUnnamedAddress(LLVMValueRef Global)
Definition: Core.cpp:1928
void LLVMDeleteBasicBlock(LLVMBasicBlockRef BBRef)
Remove a basic block from a function and delete it.
Definition: Core.cpp:2566
LLVMAtomicOrdering LLVMGetCmpXchgSuccessOrdering(LLVMValueRef CmpXchgInst)
Definition: Core.cpp:3773
LLVMValueRef LLVMBuildLShr(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:3234
unsigned LLVMGetNumSuccessors(LLVMValueRef Term)
Return the number of successors that this terminator has.
Definition: Core.cpp:2779
LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef B, LLVMValueRef Val, const char *Name)
Definition: Core.cpp:3709
unsigned LLVMGetMDKindID(const char *Name, unsigned SLen)
Definition: Core.cpp:127
static Constant * getInBoundsGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant *> IdxList)
Create an "inbounds" getelementptr.
Definition: Constants.h:1181
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:107
const NodeList & List
Definition: RDFGraph.cpp:210
LLVMBool LLVMIsConstant(LLVMValueRef Ty)
Determine whether the specified value instance is constant.
Definition: Core.cpp:1020
static Constant * getPtrToInt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:1747
#define I(x, y, z)
Definition: MD5.cpp:58
#define N
LLVMBasicBlockRef LLVMGetUnwindDest(LLVMValueRef Invoke)
Return the unwind destination basic block.
Definition: Core.cpp:2755
LLVMValueRef LLVMBuildFSub(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:3164
static Constant * getOr(Constant *C1, Constant *C2)
Definition: Constants.cpp:2301
LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index)
Obtain an incoming value to a PHI node as an LLVMBasicBlockRef.
Definition: Core.cpp:2844
void LLVMSetUnwindDest(LLVMValueRef Invoke, LLVMBasicBlockRef B)
Set the unwind destination basic block.
Definition: Core.cpp:2768
LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C)
Obtain an integer type from a context with specified bit width.
Definition: Core.cpp:538
LLVMBool LLVMGetVolatile(LLVMValueRef MemAccessInst)
Definition: Core.cpp:3472
LLVMTypeRef LLVMInt1Type(void)
Obtain an integer type from the global context with a specified bit width.
Definition: Core.cpp:560
LLVMBool LLVMIsLiteralStruct(LLVMTypeRef StructTy)
Determine whether a structure is literal.
Definition: Core.cpp:717
void initializeVerifierLegacyPassPass(PassRegistry &)
void LLVMGetCallSiteAttributes(LLVMValueRef C, LLVMAttributeIndex Idx, LLVMAttributeRef *Attrs)
Definition: Core.cpp:2700
LLVMTypeRef LLVMIntType(unsigned NumBits)
Definition: Core.cpp:578
void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC)
Set the calling convention for a call instruction.
Definition: Core.cpp:2676
iterator begin()
Definition: Module.h:595
LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M)
Constructs a new function-by-function pass pipeline over the module provider.
Definition: Core.cpp:3883
LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID, LLVMContextRef C)
Create a new, empty module in a specific context.
Definition: Core.cpp:226
LLVMMetadataRef LLVMValueMetadataEntriesGetMetadata(LLVMValueMetadataEntry *Entries, unsigned Index)
Returns the underlying metadata node of a value metadata entry at a specific index.
Definition: Core.cpp:2018
LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef B, LLVMValueRef V, LLVMBasicBlockRef Else, unsigned NumCases)
Definition: Core.cpp:2968
LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy, LLVMValueRef *ConstantVals, unsigned Length)
Create a ConstantArray from values.
Definition: Core.cpp:1373
128 bit floating point type (two 64-bits)
Definition: Core.h:152
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
Definition: Type.cpp:581
void LLVMDumpType(LLVMTypeRef Ty)
Dump a representation of a type to stderr.
Definition: Core.cpp:518
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:323
uint32_t Size
Definition: Profile.cpp:47
static Constant * getShl(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
Definition: Constants.cpp:2309
Keep one copy of named function when linking (weak)
Definition: GlobalValue.h:53
static BinaryOperator * CreateNeg(Value *S1, const Twine &Name, Instruction *InsertBefore, Value *FlagsOp)
Rename collisions when linking (static functions).
Definition: GlobalValue.h:56
LLVMTypeRef LLVMInt8Type(void)
Definition: Core.cpp:563
void LLVMAliasSetAliasee(LLVMValueRef Alias, LLVMValueRef Aliasee)
Set the target value of an alias.
Definition: Core.cpp:2224
static Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
Definition: Attributes.cpp:81
Special purpose, only applies to global arrays.
Definition: Core.h:175
static InlineAsm * get(FunctionType *Ty, StringRef AsmString, StringRef Constraints, bool hasSideEffects, bool isAlignStack=false, AsmDialect asmDialect=AD_ATT)
InlineAsm::get - Return the specified uniqued inline asm string.
Definition: InlineAsm.cpp:43
LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType)
Definition: Core.cpp:1667
LLVMValueRef LLVMBuildMemCpy(LLVMBuilderRef B, LLVMValueRef Dst, unsigned DstAlign, LLVMValueRef Src, unsigned SrcAlign, LLVMValueRef Size)
Creates and inserts a memcpy between the specified pointers.
Definition: Core.cpp:3318
LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1606
const char * LLVMGetMDString(LLVMValueRef V, unsigned *Length)
Obtain the underlying string from a MDString value.
Definition: Core.cpp:1095
LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM)
Finalizes all of the function passes scheduled in the function pass manager.
Definition: Core.cpp:3904
void close()
Manually flush the stream and close the file.
LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst)
Obtain the predicate of an instruction.
Definition: Core.cpp:2628
void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val)
Definition: Core.cpp:3089
LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1601
LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:3179
Like LinkerPrivate, but is weak.
Definition: Core.h:185
LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal)
Definition: Core.cpp:1460
LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty, LLVMValueRef PersFn, unsigned NumClauses, const char *Name)
Definition: Core.cpp:3000
LLVMTypeRef LLVMGetCalledFunctionType(LLVMValueRef Instr)
Obtain the function type called by this instruction.
Definition: Core.cpp:2735
unsigned LLVMGetAttributeCountAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx)
Definition: Core.cpp:2365
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, int64_t FileSize=-1, bool RequiresNullTerminator=true, bool IsVolatile=false)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful, otherwise returning null.
static LLVMModuleFlagBehavior map_from_llvmModFlagBehavior(Module::ModFlagBehavior Behavior)
Definition: Core.cpp:305
const unsigned Kind
3: 64-bit floating point type
Definition: Type.h:60
const char * LLVMIntrinsicCopyOverloadedName(unsigned ID, LLVMTypeRef *ParamTypes, size_t ParamCount, size_t *NameLength)
Copies the name of an overloaded intrinsic identified by a given list of parameter types...
Definition: Core.cpp:2322
LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M)
Obtain an iterator to the first Function in a Module.
Definition: Core.cpp:2240
LLVMValueRef LLVMBuildCatchRet(LLVMBuilderRef B, LLVMValueRef CatchPad, LLVMBasicBlockRef BB)
Definition: Core.cpp:3047
static Intrinsic::ID llvm_map_to_intrinsic_id(unsigned ID)
Definition: Core.cpp:2294
LLVMNamedMDNodeRef LLVMGetOrInsertNamedMetadata(LLVMModuleRef M, const char *Name, size_t NameLen)
Retrieve a NamedMDNode with the given name, creating a new node if no such node exists.
Definition: Core.cpp:1149
LLVMValueRef LLVMBuildCall2(LLVMBuilderRef B, LLVMTypeRef Ty, LLVMValueRef Fn, LLVMValueRef *Args, unsigned NumArgs, const char *Name)
Definition: Core.cpp:3652
struct LLVMOpaqueMetadata * LLVMMetadataRef
Represents an LLVM Metadata.
Definition: Types.h:90
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename, char **ErrorMessage)
Print a representation of a module to a file.
Definition: Core.cpp:387
handler_iterator handler_end()
Returns a read-only iterator that points one past the last handler in the CatchSwitchInst.
LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef B, LLVMValueRef List, LLVMTypeRef Ty, const char *Name)
Definition: Core.cpp:3667
void LLVMSetThreadLocalMode(LLVMValueRef GlobalVar, LLVMThreadLocalMode Mode)
Definition: Core.cpp:2143
static Constant * getSRem(Constant *C1, Constant *C2)
Definition: Constants.cpp:2289
Release is similar to Acquire, but with a barrier of the sort necessary to release a lock...
Definition: Core.h:338
LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C)
Definition: Core.cpp:2879
LLVMAtomicOrdering LLVMGetOrdering(LLVMValueRef MemAccessInst)
Definition: Core.cpp:3486
void LLVMSetMetadata(LLVMValueRef Inst, unsigned KindID, LLVMValueRef Val)
Set metadata associated with an instruction value.
Definition: Core.cpp:877
LLVMValueRef LLVMGetParamParent(LLVMValueRef V)
Obtain the function to which this argument belongs.
Definition: Core.cpp:2427
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:483
const char * LLVMGetValueName(LLVMValueRef Val)
Deprecated: Use LLVMGetValueName2 instead.
Definition: Core.cpp:821
Synchronized with respect to signal handlers executing in the same thread.
Definition: LLVMContext.h:56
LLVMValueRef LLVMGetArgOperand(LLVMValueRef Funclet, unsigned i)
Definition: Core.cpp:3119
LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:3578
LLVMValueRef LLVMBuildBr(LLVMBuilderRef B, LLVMBasicBlockRef Dest)
Definition: Core.cpp:2959
void LLVMAddCallSiteAttribute(LLVMValueRef C, LLVMAttributeIndex Idx, LLVMAttributeRef A)
Definition: Core.cpp:2688
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:566
LLVM Value Representation.
Definition: Value.h:73
Address of the GV is locally insignificant.
Definition: Core.h:196
LLVMValueRef LLVMBuildCleanupRet(LLVMBuilderRef B, LLVMValueRef CatchPad, LLVMBasicBlockRef BB)
Definition: Core.cpp:3053
LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:3572
LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf, char **OutMessage)
Definition: Core.cpp:3827
LLVMLinkage LLVMGetLinkage(LLVMValueRef Global)
Definition: Core.cpp:1804
bool hasInitializer() const
Definitions have initializers, declarations don&#39;t.
static Constant * getURem(Constant *C1, Constant *C2)
Definition: Constants.cpp:2285
static VectorType * get(Type *ElementType, unsigned NumElements)
This static method is the primary way to construct an VectorType.
Definition: Type.cpp:606
static StructType * create(LLVMContext &Context, StringRef Name)
This creates an identified struct.
Definition: Type.cpp:437
Synchronized with respect to all concurrently executing threads.
Definition: LLVMContext.h:59
LLVMDLLStorageClass
Definition: Core.h:200
LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val)
Convert an LLVMValueRef to an LLVMBasicBlockRef instance.
Definition: Core.cpp:2477
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E&#39;s largest value.
Definition: BitmaskEnum.h:81
LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn)
Decrement a Function iterator to the previous Function.
Definition: Core.cpp:2264
static const Function * getParent(const Value *V)
void LLVMSetOrdering(LLVMValueRef MemAccessInst, LLVMAtomicOrdering Ordering)
Definition: Core.cpp:3496
LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr, unsigned NumDests)
Definition: Core.cpp:2973
void LLVMSetGC(LLVMValueRef Fn, const char *GC)
Define the garbage collector to use during code generation.
Definition: Core.cpp:2352
LLVMDLLStorageClass LLVMGetDLLStorageClass(LLVMValueRef Global)
Definition: Core.cpp:1918
static Constant * getUIToFP(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:1703
LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V, const char *Name)
Definition: Core.cpp:3270
static Constant * getFPToSI(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:1736
LLVMValueRef LLVMConstExactUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1535
LLVMValueRef LLVMBuildIntCast2(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, LLVMBool IsSigned, const char *Name)
Definition: Core.cpp:3601
Obsolete.
Definition: Core.h:180
static Constant * getAnon(ArrayRef< Constant *> V, bool Packed=false)
Return an anonymous struct that has the specified elements.
Definition: Constants.h:469
LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy)
Obtain the Type this function Type returns.
Definition: Core.cpp:645
LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:3174
LLVMValueRef LLVMBuildStore(LLVMBuilderRef B, LLVMValueRef Val, LLVMValueRef PointerVal)
Definition: Core.cpp:3364
LLVMModuleFlagBehavior
Definition: Core.h:389
LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:3259
LLVMValueMetadataEntry * LLVMInstructionGetAllMetadataOtherThanDebugLoc(LLVMValueRef Value, size_t *NumEntries)
Returns the metadata associated with an instruction value, but filters out all the debug locations...
Definition: Core.cpp:908
const char * LLVMGetModuleIdentifier(LLVMModuleRef M, size_t *Len)
Obtain the identifier of a module.
Definition: Core.cpp:235
static Constant * getExtractValue(Constant *Agg, ArrayRef< unsigned > Idxs, Type *OnlyIfReducedTy=nullptr)
Definition: Constants.cpp:2195
LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType)
Definition: Core.cpp:1647
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
LLVMBool LLVMIsMultithreaded()
Check whether LLVM is executing in thread-safe mode or not.
Definition: Core.cpp:3921
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
Definition: PassRegistry.h:39
A single uniqued string.
Definition: Metadata.h:604
LLVMContextRef LLVMGetGlobalContext()
Obtain the global context instance.
Definition: Core.cpp:83
LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1513
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
Definition: ManagedStatic.h:61
LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C)
Definition: Core.cpp:547
LLVMAtomicOrdering LLVMGetCmpXchgFailureOrdering(LLVMValueRef CmpXchgInst)
Definition: Core.cpp:3786
void initializePrintFunctionPassWrapperPass(PassRegistry &)
static Constant * getExactUDiv(Constant *C1, Constant *C2)
Definition: Constants.h:1013
LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F)
Executes all of the function passes scheduled in the function pass manager on the provided function...
Definition: Core.cpp:3900
static bool isVolatile(Instruction *Inst)
64 bit floating point type
Definition: Core.h:149
9: MMX vectors (64 bits, X86 specific)
Definition: Type.h:66
static Constant * getAlignOf(Type *Ty)
getAlignOf constant expr - computes the alignment of a type in a target independent way (Note: the re...
Definition: Constants.cpp:1925
LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace)
Create a pointer type that points to a defined type.
Definition: Core.cpp:739
static Constant * getMul(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
Definition: Constants.cpp:2260
LLVMValueRef LLVMBuildLoad(LLVMBuilderRef B, LLVMValueRef PointerVal, const char *Name)
Definition: Core.cpp:3351
void LLVMInstructionRemoveFromParent(LLVMValueRef Inst)
Remove and delete an instruction.
Definition: Core.cpp:2620
LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant, LLVMValueRef IndexConstant)
Definition: Core.cpp:1746
void LLVMSetTailCall(LLVMValueRef Call, LLVMBool isTailCall)
Set whether a call instruction is a tail call.
Definition: Core.cpp:2745
static Constant * getNUWSub(Constant *C1, Constant *C2)
Definition: Constants.h:989
static BinaryOperator * CreateMul(Value *S1, Value *S2, const Twine &Name, Instruction *InsertBefore, Value *FlagsOp)
#define LLVM_DEBUG(X)
Definition: Debug.h:123
void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm)
Deprecated: Use LLVMSetModuleInlineAsm2 instead.
Definition: Core.cpp:424
LLVMValueRef LLVMBuildAddrSpaceCast(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:3567
LLVMBasicBlockRef LLVMGetNormalDest(LLVMValueRef Invoke)
Return the normal destination basic block.
Definition: Core.cpp:2751
bool hasName() const
Return true if this is a named struct that has a non-empty name.
Definition: DerivedTypes.h:275
const char * LLVMGetModuleInlineAsm(LLVMModuleRef M, size_t *Len)
Get inline assembly for a module.
Definition: Core.cpp:432
const char * LLVMGetStringAttributeKind(LLVMAttributeRef A, unsigned *Length)
Get the string attribute&#39;s kind.
Definition: Core.cpp:165
static Constant * getFPExtend(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:1691
LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1567
LLVMModuleFlagEntry * LLVMCopyModuleFlagsMetadata(LLVMModuleRef M, size_t *Len)
Returns the module flags as an array of flag-key-value triples.
Definition: Core.cpp:324
static Constant * getNUWAdd(Constant *C1, Constant *C2)
Definition: Constants.h:981
unsigned LLVMGetAlignment(LLVMValueRef V)
Obtain the preferred alignment of the value.
Definition: Core.cpp:1969
Tokens.
Definition: Core.h:162
LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn)
Advance a Function iterator to the next Function.
Definition: Core.cpp:2256
Root of the metadata hierarchy.
Definition: Metadata.h:58
void LLVMAddAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx, LLVMAttributeRef A)
Add an attribute to a function.
Definition: Core.cpp:2360
static IntegerType * getInt8Ty(LLVMContext &C)
Definition: Type.cpp:174
unsigned LLVMGetNumHandlers(LLVMValueRef CatchSwitch)
Definition: Core.cpp:3097
void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP)
Destroys the module M.
Definition: Core.cpp:3806
void LLVMRemoveStringAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx, const char *K, unsigned KLen)
Definition: Core.cpp:2395
LLVMTypeRef LLVMInt128Type(void)
Definition: Core.cpp:575
LLVMValueRef LLVMBuildSelect(LLVMBuilderRef B, LLVMValueRef If, LLVMValueRef Then, LLVMValueRef Else, const char *Name)
Definition: Core.cpp:3660
static GlobalAlias * create(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage, const Twine &Name, Constant *Aliasee, Module *Parent)
If a parent module is specified, the alias is automatically inserted into the end of the specified mo...
Definition: Globals.cpp:423
static Constant * get(ArrayRef< Constant *> V)
Definition: Constants.cpp:1079
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Address of the GV is significant.
Definition: Core.h:195
LLVMRealPredicate
Definition: Core.h:296
LLVMNamedMDNodeRef LLVMGetFirstNamedMetadata(LLVMModuleRef M)
Obtain an iterator to the first NamedMDNode in a Module.
Definition: Core.cpp:1112
LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C)
Obtain a 80-bit floating point type (X87) from a context.
Definition: Core.cpp:597
Type * getElementType() const
Definition: DerivedTypes.h:486
struct LLVMOpaqueValue * LLVMValueRef
Represents an individual value in LLVM IR.
Definition: Types.h:76
reference get()
Definition: ErrorOr.h:157
named_metadata_iterator named_metadata_begin()
Definition: Module.h:707
Module * getParent()
Get the module that holds this named metadata collection.
Definition: Metadata.h:1392
Type * getTypeAtIndex(const Value *V) const
Given an index value into the type, return the type of the element.
Definition: Type.cpp:530
const BasicBlock * getParent() const
Definition: Instruction.h:67
void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr, const char *Name)
Definition: Core.cpp:2916
an instruction to allocate memory on the stack
Definition: Instructions.h:60
static Constant * getXor(Constant *C1, Constant *C2)
Definition: Constants.cpp:2305
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results...
Definition: Attributes.h:70
LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:3542
5: 128-bit floating point type (112-bit mantissa)
Definition: Type.h:62
void LLVMSetIsInBounds(LLVMValueRef GEP, LLVMBool InBounds)
Set the given GEP instruction to be inbounds or not.
Definition: Core.cpp:2823
static LLVMValueRef getMDNodeOperandImpl(LLVMContext &Context, const MDNode *N, unsigned Index)
Definition: Core.cpp:965
void LLVMSetAlignment(LLVMValueRef V, unsigned Bytes)
Set the preferred alignment of the value.
Definition: Core.cpp:1984
LLVMValueKind LLVMGetValueKind(LLVMValueRef Val)
Obtain the enumerated type of a Value instance.
Definition: Core.cpp:800
LLVMValueRef LLVMBuildCatchPad(LLVMBuilderRef B, LLVMValueRef ParentPad, LLVMValueRef *Args, unsigned NumArgs, const char *Name)
Definition: Core.cpp:3012
void LLVMGlobalClearMetadata(LLVMValueRef Global)
Removes all metadata attachments from this value.
Definition: Core.cpp:2038
LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global)
Definition: Core.cpp:1796