LLVM  7.0.0svn
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/CallSite.h"
19 #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  delete unwrap(C);
112 }
113 
115  unsigned SLen) {
116  return unwrap(C)->getMDKindID(StringRef(Name, SLen));
117 }
118 
119 unsigned LLVMGetMDKindID(const char *Name, unsigned SLen) {
120  return LLVMGetMDKindIDInContext(LLVMGetGlobalContext(), Name, SLen);
121 }
122 
123 #define GET_ATTR_KIND_FROM_NAME
124 #include "AttributesCompatFunc.inc"
125 
126 unsigned LLVMGetEnumAttributeKindForName(const char *Name, size_t SLen) {
127  return getAttrKindFromName(StringRef(Name, SLen));
128 }
129 
131  return Attribute::AttrKind::EndAttrKinds;
132 }
133 
135  uint64_t Val) {
136  return wrap(Attribute::get(*unwrap(C), (Attribute::AttrKind)KindID, Val));
137 }
138 
140  return unwrap(A).getKindAsEnum();
141 }
142 
144  auto Attr = unwrap(A);
145  if (Attr.isEnumAttribute())
146  return 0;
147  return Attr.getValueAsInt();
148 }
149 
151  const char *K, unsigned KLength,
152  const char *V, unsigned VLength) {
153  return wrap(Attribute::get(*unwrap(C), StringRef(K, KLength),
154  StringRef(V, VLength)));
155 }
156 
158  unsigned *Length) {
159  auto S = unwrap(A).getKindAsString();
160  *Length = S.size();
161  return S.data();
162 }
163 
165  unsigned *Length) {
166  auto S = unwrap(A).getValueAsString();
167  *Length = S.size();
168  return S.data();
169 }
170 
172  auto Attr = unwrap(A);
173  return Attr.isEnumAttribute() || Attr.isIntAttribute();
174 }
175 
177  return unwrap(A).isStringAttribute();
178 }
179 
181  std::string MsgStorage;
182  raw_string_ostream Stream(MsgStorage);
183  DiagnosticPrinterRawOStream DP(Stream);
184 
185  unwrap(DI)->print(DP);
186  Stream.flush();
187 
188  return LLVMCreateMessage(MsgStorage.c_str());
189 }
190 
192  LLVMDiagnosticSeverity severity;
193 
194  switch(unwrap(DI)->getSeverity()) {
195  default:
196  severity = LLVMDSError;
197  break;
198  case DS_Warning:
199  severity = LLVMDSWarning;
200  break;
201  case DS_Remark:
202  severity = LLVMDSRemark;
203  break;
204  case DS_Note:
205  severity = LLVMDSNote;
206  break;
207  }
208 
209  return severity;
210 }
211 
212 /*===-- Operations on modules ---------------------------------------------===*/
213 
215  return wrap(new Module(ModuleID, *GlobalContext));
216 }
217 
219  LLVMContextRef C) {
220  return wrap(new Module(ModuleID, *unwrap(C)));
221 }
222 
224  delete unwrap(M);
225 }
226 
227 const char *LLVMGetModuleIdentifier(LLVMModuleRef M, size_t *Len) {
228  auto &Str = unwrap(M)->getModuleIdentifier();
229  *Len = Str.length();
230  return Str.c_str();
231 }
232 
233 void LLVMSetModuleIdentifier(LLVMModuleRef M, const char *Ident, size_t Len) {
234  unwrap(M)->setModuleIdentifier(StringRef(Ident, Len));
235 }
236 
237 const char *LLVMGetSourceFileName(LLVMModuleRef M, size_t *Len) {
238  auto &Str = unwrap(M)->getSourceFileName();
239  *Len = Str.length();
240  return Str.c_str();
241 }
242 
243 void LLVMSetSourceFileName(LLVMModuleRef M, const char *Name, size_t Len) {
244  unwrap(M)->setSourceFileName(StringRef(Name, Len));
245 }
246 
247 /*--.. Data layout .........................................................--*/
249  return unwrap(M)->getDataLayoutStr().c_str();
250 }
251 
253  return LLVMGetDataLayoutStr(M);
254 }
255 
256 void LLVMSetDataLayout(LLVMModuleRef M, const char *DataLayoutStr) {
257  unwrap(M)->setDataLayout(DataLayoutStr);
258 }
259 
260 /*--.. Target triple .......................................................--*/
261 const char * LLVMGetTarget(LLVMModuleRef M) {
262  return unwrap(M)->getTargetTriple().c_str();
263 }
264 
265 void LLVMSetTarget(LLVMModuleRef M, const char *Triple) {
266  unwrap(M)->setTargetTriple(Triple);
267 }
268 
269 /*--.. Module flags ........................................................--*/
272  const char *Key;
273  size_t KeyLen;
275 };
276 
279  switch (Behavior) {
283  return Module::ModFlagBehavior::Warning;
285  return Module::ModFlagBehavior::Require;
287  return Module::ModFlagBehavior::Override;
289  return Module::ModFlagBehavior::Append;
291  return Module::ModFlagBehavior::AppendUnique;
292  }
293  llvm_unreachable("Unknown LLVMModuleFlagBehavior");
294 }
295 
298  switch (Behavior) {
301  case Module::ModFlagBehavior::Warning:
303  case Module::ModFlagBehavior::Require:
305  case Module::ModFlagBehavior::Override:
307  case Module::ModFlagBehavior::Append:
309  case Module::ModFlagBehavior::AppendUnique:
311  default:
312  llvm_unreachable("Unhandled Flag Behavior");
313  }
314 }
315 
318  unwrap(M)->getModuleFlagsMetadata(MFEs);
319 
320  LLVMOpaqueModuleFlagEntry *Result = static_cast<LLVMOpaqueModuleFlagEntry *>(
321  safe_malloc(MFEs.size() * sizeof(LLVMOpaqueModuleFlagEntry)));
322  for (unsigned i = 0; i < MFEs.size(); ++i) {
323  const auto &ModuleFlag = MFEs[i];
324  Result[i].Behavior = map_from_llvmModFlagBehavior(ModuleFlag.Behavior);
325  Result[i].Key = ModuleFlag.Key->getString().data();
326  Result[i].KeyLen = ModuleFlag.Key->getString().size();
327  Result[i].Metadata = wrap(ModuleFlag.Val);
328  }
329  *Len = MFEs.size();
330  return Result;
331 }
332 
334  free(Entries);
335 }
336 
339  unsigned Index) {
341  static_cast<LLVMOpaqueModuleFlagEntry>(Entries[Index]);
342  return MFE.Behavior;
343 }
344 
346  unsigned Index, size_t *Len) {
348  static_cast<LLVMOpaqueModuleFlagEntry>(Entries[Index]);
349  *Len = MFE.KeyLen;
350  return MFE.Key;
351 }
352 
354  unsigned Index) {
356  static_cast<LLVMOpaqueModuleFlagEntry>(Entries[Index]);
357  return MFE.Metadata;
358 }
359 
361  const char *Key, size_t KeyLen) {
362  return wrap(unwrap(M)->getModuleFlag({Key, KeyLen}));
363 }
364 
366  const char *Key, size_t KeyLen,
367  LLVMMetadataRef Val) {
368  unwrap(M)->addModuleFlag(map_to_llvmModFlagBehavior(Behavior),
369  {Key, KeyLen}, unwrap(Val));
370 }
371 
372 /*--.. Printing modules ....................................................--*/
373 
375  unwrap(M)->print(errs(), nullptr,
376  /*ShouldPreserveUseListOrder=*/false, /*IsForDebug=*/true);
377 }
378 
380  char **ErrorMessage) {
381  std::error_code EC;
382  raw_fd_ostream dest(Filename, EC, sys::fs::F_Text);
383  if (EC) {
384  *ErrorMessage = strdup(EC.message().c_str());
385  return true;
386  }
387 
388  unwrap(M)->print(dest, nullptr);
389 
390  dest.close();
391 
392  if (dest.has_error()) {
393  std::string E = "Error printing to file: " + dest.error().message();
394  *ErrorMessage = strdup(E.c_str());
395  return true;
396  }
397 
398  return false;
399 }
400 
402  std::string buf;
403  raw_string_ostream os(buf);
404 
405  unwrap(M)->print(os, nullptr);
406  os.flush();
407 
408  return strdup(buf.c_str());
409 }
410 
411 /*--.. Operations on inline assembler ......................................--*/
412 void LLVMSetModuleInlineAsm2(LLVMModuleRef M, const char *Asm, size_t Len) {
413  unwrap(M)->setModuleInlineAsm(StringRef(Asm, Len));
414 }
415 
417  unwrap(M)->setModuleInlineAsm(StringRef(Asm));
418 }
419 
420 void LLVMAppendModuleInlineAsm(LLVMModuleRef M, const char *Asm, size_t Len) {
421  unwrap(M)->appendModuleInlineAsm(StringRef(Asm, Len));
422 }
423 
424 const char *LLVMGetModuleInlineAsm(LLVMModuleRef M, size_t *Len) {
425  auto &Str = unwrap(M)->getModuleInlineAsm();
426  *Len = Str.length();
427  return Str.c_str();
428 }
429 
431  char *AsmString, size_t AsmStringSize,
432  char *Constraints, size_t ConstraintsSize,
433  LLVMBool HasSideEffects, LLVMBool IsAlignStack,
434  LLVMInlineAsmDialect Dialect) {
436  switch (Dialect) {
438  AD = InlineAsm::AD_ATT;
439  break;
441  AD = InlineAsm::AD_Intel;
442  break;
443  }
444  return wrap(InlineAsm::get(unwrap<FunctionType>(Ty),
445  StringRef(AsmString, AsmStringSize),
446  StringRef(Constraints, ConstraintsSize),
447  HasSideEffects, IsAlignStack, AD));
448 }
449 
450 
451 /*--.. Operations on module contexts ......................................--*/
453  return wrap(&unwrap(M)->getContext());
454 }
455 
456 
457 /*===-- Operations on types -----------------------------------------------===*/
458 
459 /*--.. Operations on all types (mostly) ....................................--*/
460 
462  switch (unwrap(Ty)->getTypeID()) {
463  case Type::VoidTyID:
464  return LLVMVoidTypeKind;
465  case Type::HalfTyID:
466  return LLVMHalfTypeKind;
467  case Type::FloatTyID:
468  return LLVMFloatTypeKind;
469  case Type::DoubleTyID:
470  return LLVMDoubleTypeKind;
471  case Type::X86_FP80TyID:
472  return LLVMX86_FP80TypeKind;
473  case Type::FP128TyID:
474  return LLVMFP128TypeKind;
475  case Type::PPC_FP128TyID:
476  return LLVMPPC_FP128TypeKind;
477  case Type::LabelTyID:
478  return LLVMLabelTypeKind;
479  case Type::MetadataTyID:
480  return LLVMMetadataTypeKind;
481  case Type::IntegerTyID:
482  return LLVMIntegerTypeKind;
483  case Type::FunctionTyID:
484  return LLVMFunctionTypeKind;
485  case Type::StructTyID:
486  return LLVMStructTypeKind;
487  case Type::ArrayTyID:
488  return LLVMArrayTypeKind;
489  case Type::PointerTyID:
490  return LLVMPointerTypeKind;
491  case Type::VectorTyID:
492  return LLVMVectorTypeKind;
493  case Type::X86_MMXTyID:
494  return LLVMX86_MMXTypeKind;
495  case Type::TokenTyID:
496  return LLVMTokenTypeKind;
497  }
498  llvm_unreachable("Unhandled TypeID.");
499 }
500 
502 {
503  return unwrap(Ty)->isSized();
504 }
505 
507  return wrap(&unwrap(Ty)->getContext());
508 }
509 
511  return unwrap(Ty)->print(errs(), /*IsForDebug=*/true);
512 }
513 
515  std::string buf;
516  raw_string_ostream os(buf);
517 
518  if (unwrap(Ty))
519  unwrap(Ty)->print(os);
520  else
521  os << "Printing <null> Type";
522 
523  os.flush();
524 
525  return strdup(buf.c_str());
526 }
527 
528 /*--.. Operations on integer types .........................................--*/
529 
531  return (LLVMTypeRef) Type::getInt1Ty(*unwrap(C));
532 }
534  return (LLVMTypeRef) Type::getInt8Ty(*unwrap(C));
535 }
537  return (LLVMTypeRef) Type::getInt16Ty(*unwrap(C));
538 }
540  return (LLVMTypeRef) Type::getInt32Ty(*unwrap(C));
541 }
543  return (LLVMTypeRef) Type::getInt64Ty(*unwrap(C));
544 }
546  return (LLVMTypeRef) Type::getInt128Ty(*unwrap(C));
547 }
549  return wrap(IntegerType::get(*unwrap(C), NumBits));
550 }
551 
554 }
557 }
560 }
563 }
566 }
569 }
570 LLVMTypeRef LLVMIntType(unsigned NumBits) {
571  return LLVMIntTypeInContext(LLVMGetGlobalContext(), NumBits);
572 }
573 
574 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy) {
575  return unwrap<IntegerType>(IntegerTy)->getBitWidth();
576 }
577 
578 /*--.. Operations on real types ............................................--*/
579 
581  return (LLVMTypeRef) Type::getHalfTy(*unwrap(C));
582 }
584  return (LLVMTypeRef) Type::getFloatTy(*unwrap(C));
585 }
587  return (LLVMTypeRef) Type::getDoubleTy(*unwrap(C));
588 }
590  return (LLVMTypeRef) Type::getX86_FP80Ty(*unwrap(C));
591 }
593  return (LLVMTypeRef) Type::getFP128Ty(*unwrap(C));
594 }
597 }
599  return (LLVMTypeRef) Type::getX86_MMXTy(*unwrap(C));
600 }
601 
604 }
607 }
610 }
613 }
616 }
619 }
622 }
623 
624 /*--.. Operations on function types ........................................--*/
625 
627  LLVMTypeRef *ParamTypes, unsigned ParamCount,
628  LLVMBool IsVarArg) {
629  ArrayRef<Type*> Tys(unwrap(ParamTypes), ParamCount);
630  return wrap(FunctionType::get(unwrap(ReturnType), Tys, IsVarArg != 0));
631 }
632 
634  return unwrap<FunctionType>(FunctionTy)->isVarArg();
635 }
636 
638  return wrap(unwrap<FunctionType>(FunctionTy)->getReturnType());
639 }
640 
641 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy) {
642  return unwrap<FunctionType>(FunctionTy)->getNumParams();
643 }
644 
645 void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest) {
646  FunctionType *Ty = unwrap<FunctionType>(FunctionTy);
648  E = Ty->param_end(); I != E; ++I)
649  *Dest++ = wrap(*I);
650 }
651 
652 /*--.. Operations on struct types ..........................................--*/
653 
655  unsigned ElementCount, LLVMBool Packed) {
656  ArrayRef<Type*> Tys(unwrap(ElementTypes), ElementCount);
657  return wrap(StructType::get(*unwrap(C), Tys, Packed != 0));
658 }
659 
661  unsigned ElementCount, LLVMBool Packed) {
662  return LLVMStructTypeInContext(LLVMGetGlobalContext(), ElementTypes,
663  ElementCount, Packed);
664 }
665 
667 {
668  return wrap(StructType::create(*unwrap(C), Name));
669 }
670 
672 {
673  StructType *Type = unwrap<StructType>(Ty);
674  if (!Type->hasName())
675  return nullptr;
676  return Type->getName().data();
677 }
678 
679 void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
680  unsigned ElementCount, LLVMBool Packed) {
681  ArrayRef<Type*> Tys(unwrap(ElementTypes), ElementCount);
682  unwrap<StructType>(StructTy)->setBody(Tys, Packed != 0);
683 }
684 
686  return unwrap<StructType>(StructTy)->getNumElements();
687 }
688 
690  StructType *Ty = unwrap<StructType>(StructTy);
692  E = Ty->element_end(); I != E; ++I)
693  *Dest++ = wrap(*I);
694 }
695 
697  StructType *Ty = unwrap<StructType>(StructTy);
698  return wrap(Ty->getTypeAtIndex(i));
699 }
700 
702  return unwrap<StructType>(StructTy)->isPacked();
703 }
704 
706  return unwrap<StructType>(StructTy)->isOpaque();
707 }
708 
710  return wrap(unwrap(M)->getTypeByName(Name));
711 }
712 
713 /*--.. Operations on array, pointer, and vector types (sequence types) .....--*/
714 
716  int i = 0;
717  for (auto *T : unwrap(Tp)->subtypes()) {
718  Arr[i] = wrap(T);
719  i++;
720  }
721 }
722 
723 LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount) {
724  return wrap(ArrayType::get(unwrap(ElementType), ElementCount));
725 }
726 
728  return wrap(PointerType::get(unwrap(ElementType), AddressSpace));
729 }
730 
731 LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount) {
732  return wrap(VectorType::get(unwrap(ElementType), ElementCount));
733 }
734 
736  auto *Ty = unwrap<Type>(WrappedTy);
737  if (auto *PTy = dyn_cast<PointerType>(Ty))
738  return wrap(PTy->getElementType());
739  return wrap(cast<SequentialType>(Ty)->getElementType());
740 }
741 
743  return unwrap(Tp)->getNumContainedTypes();
744 }
745 
746 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy) {
747  return unwrap<ArrayType>(ArrayTy)->getNumElements();
748 }
749 
751  return unwrap<PointerType>(PointerTy)->getAddressSpace();
752 }
753 
754 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy) {
755  return unwrap<VectorType>(VectorTy)->getNumElements();
756 }
757 
758 /*--.. Operations on other types ...........................................--*/
759 
761  return wrap(Type::getVoidTy(*unwrap(C)));
762 }
764  return wrap(Type::getLabelTy(*unwrap(C)));
765 }
767  return wrap(Type::getTokenTy(*unwrap(C)));
768 }
770  return wrap(Type::getMetadataTy(*unwrap(C)));
771 }
772 
775 }
778 }
779 
780 /*===-- Operations on values ----------------------------------------------===*/
781 
782 /*--.. Operations on all values ............................................--*/
783 
785  return wrap(unwrap(Val)->getType());
786 }
787 
789  switch(unwrap(Val)->getValueID()) {
790 #define HANDLE_VALUE(Name) \
791  case Value::Name##Val: \
792  return LLVM##Name##ValueKind;
793 #include "llvm/IR/Value.def"
794  default:
796  }
797 }
798 
799 const char *LLVMGetValueName2(LLVMValueRef Val, size_t *Length) {
800  auto *V = unwrap(Val);
801  *Length = V->getName().size();
802  return V->getName().data();
803 }
804 
805 void LLVMSetValueName2(LLVMValueRef Val, const char *Name, size_t NameLen) {
806  unwrap(Val)->setName(StringRef(Name, NameLen));
807 }
808 
809 const char *LLVMGetValueName(LLVMValueRef Val) {
810  return unwrap(Val)->getName().data();
811 }
812 
813 void LLVMSetValueName(LLVMValueRef Val, const char *Name) {
814  unwrap(Val)->setName(Name);
815 }
816 
818  unwrap(Val)->print(errs(), /*IsForDebug=*/true);
819 }
820 
822  std::string buf;
823  raw_string_ostream os(buf);
824 
825  if (unwrap(Val))
826  unwrap(Val)->print(os);
827  else
828  os << "Printing <null> Value";
829 
830  os.flush();
831 
832  return strdup(buf.c_str());
833 }
834 
836  unwrap(OldVal)->replaceAllUsesWith(unwrap(NewVal));
837 }
838 
840  return unwrap<Instruction>(Inst)->hasMetadata();
841 }
842 
843 LLVMValueRef LLVMGetMetadata(LLVMValueRef Inst, unsigned KindID) {
844  auto *I = unwrap<Instruction>(Inst);
845  assert(I && "Expected instruction");
846  if (auto *MD = I->getMetadata(KindID))
847  return wrap(MetadataAsValue::get(I->getContext(), MD));
848  return nullptr;
849 }
850 
851 // MetadataAsValue uses a canonical format which strips the actual MDNode for
852 // MDNode with just a single constant value, storing just a ConstantAsMetadata
853 // This undoes this canonicalization, reconstructing the MDNode.
855  Metadata *MD = MAV->getMetadata();
856  assert((isa<MDNode>(MD) || isa<ConstantAsMetadata>(MD)) &&
857  "Expected a metadata node or a canonicalized constant");
858 
859  if (MDNode *N = dyn_cast<MDNode>(MD))
860  return N;
861 
862  return MDNode::get(MAV->getContext(), MD);
863 }
864 
865 void LLVMSetMetadata(LLVMValueRef Inst, unsigned KindID, LLVMValueRef Val) {
866  MDNode *N = Val ? extractMDNode(unwrap<MetadataAsValue>(Val)) : nullptr;
867 
868  unwrap<Instruction>(Inst)->setMetadata(KindID, N);
869 }
870 
871 /*--.. Conversion functions ................................................--*/
872 
873 #define LLVM_DEFINE_VALUE_CAST(name) \
874  LLVMValueRef LLVMIsA##name(LLVMValueRef Val) { \
875  return wrap(static_cast<Value*>(dyn_cast_or_null<name>(unwrap(Val)))); \
876  }
877 
879 
881  if (auto *MD = dyn_cast_or_null<MetadataAsValue>(unwrap(Val)))
882  if (isa<MDNode>(MD->getMetadata()) ||
883  isa<ValueAsMetadata>(MD->getMetadata()))
884  return Val;
885  return nullptr;
886 }
887 
889  if (auto *MD = dyn_cast_or_null<MetadataAsValue>(unwrap(Val)))
890  if (isa<MDString>(MD->getMetadata()))
891  return Val;
892  return nullptr;
893 }
894 
895 /*--.. Operations on Uses ..................................................--*/
897  Value *V = unwrap(Val);
899  if (I == V->use_end())
900  return nullptr;
901  return wrap(&*I);
902 }
903 
905  Use *Next = unwrap(U)->getNext();
906  if (Next)
907  return wrap(Next);
908  return nullptr;
909 }
910 
912  return wrap(unwrap(U)->getUser());
913 }
914 
916  return wrap(unwrap(U)->get());
917 }
918 
919 /*--.. Operations on Users .................................................--*/
920 
922  unsigned Index) {
923  Metadata *Op = N->getOperand(Index);
924  if (!Op)
925  return nullptr;
926  if (auto *C = dyn_cast<ConstantAsMetadata>(Op))
927  return wrap(C->getValue());
928  return wrap(MetadataAsValue::get(Context, Op));
929 }
930 
932  Value *V = unwrap(Val);
933  if (auto *MD = dyn_cast<MetadataAsValue>(V)) {
934  if (auto *L = dyn_cast<ValueAsMetadata>(MD->getMetadata())) {
935  assert(Index == 0 && "Function-local metadata can only have one operand");
936  return wrap(L->getValue());
937  }
938  return getMDNodeOperandImpl(V->getContext(),
939  cast<MDNode>(MD->getMetadata()), Index);
940  }
941 
942  return wrap(cast<User>(V)->getOperand(Index));
943 }
944 
946  Value *V = unwrap(Val);
947  return wrap(&cast<User>(V)->getOperandUse(Index));
948 }
949 
951  unwrap<User>(Val)->setOperand(Index, unwrap(Op));
952 }
953 
955  Value *V = unwrap(Val);
956  if (isa<MetadataAsValue>(V))
957  return LLVMGetMDNodeNumOperands(Val);
958 
959  return cast<User>(V)->getNumOperands();
960 }
961 
962 /*--.. Operations on constants of any type .................................--*/
963 
965  return wrap(Constant::getNullValue(unwrap(Ty)));
966 }
967 
970 }
971 
973  return wrap(UndefValue::get(unwrap(Ty)));
974 }
975 
977  return isa<Constant>(unwrap(Ty));
978 }
979 
981  if (Constant *C = dyn_cast<Constant>(unwrap(Val)))
982  return C->isNullValue();
983  return false;
984 }
985 
987  return isa<UndefValue>(unwrap(Val));
988 }
989 
991  return wrap(ConstantPointerNull::get(unwrap<PointerType>(Ty)));
992 }
993 
994 /*--.. Operations on metadata nodes ........................................--*/
995 
997  unsigned SLen) {
998  LLVMContext &Context = *unwrap(C);
999  return wrap(MetadataAsValue::get(
1000  Context, MDString::get(Context, StringRef(Str, SLen))));
1001 }
1002 
1003 LLVMValueRef LLVMMDString(const char *Str, unsigned SLen) {
1004  return LLVMMDStringInContext(LLVMGetGlobalContext(), Str, SLen);
1005 }
1006 
1008  unsigned Count) {
1009  LLVMContext &Context = *unwrap(C);
1011  for (auto *OV : makeArrayRef(Vals, Count)) {
1012  Value *V = unwrap(OV);
1013  Metadata *MD;
1014  if (!V)
1015  MD = nullptr;
1016  else if (auto *C = dyn_cast<Constant>(V))
1017  MD = ConstantAsMetadata::get(C);
1018  else if (auto *MDV = dyn_cast<MetadataAsValue>(V)) {
1019  MD = MDV->getMetadata();
1020  assert(!isa<LocalAsMetadata>(MD) && "Unexpected function-local metadata "
1021  "outside of direct argument to call");
1022  } else {
1023  // This is function-local metadata. Pretend to make an MDNode.
1024  assert(Count == 1 &&
1025  "Expected only one operand to function-local metadata");
1026  return wrap(MetadataAsValue::get(Context, LocalAsMetadata::get(V)));
1027  }
1028 
1029  MDs.push_back(MD);
1030  }
1031  return wrap(MetadataAsValue::get(Context, MDNode::get(Context, MDs)));
1032 }
1033 
1034 LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count) {
1035  return LLVMMDNodeInContext(LLVMGetGlobalContext(), Vals, Count);
1036 }
1037 
1039  return wrap(MetadataAsValue::get(*unwrap(C), unwrap(MD)));
1040 }
1041 
1043  auto *V = unwrap(Val);
1044  if (auto *C = dyn_cast<Constant>(V))
1045  return wrap(ConstantAsMetadata::get(C));
1046  if (auto *MAV = dyn_cast<MetadataAsValue>(V))
1047  return wrap(MAV->getMetadata());
1048  return wrap(ValueAsMetadata::get(V));
1049 }
1050 
1051 const char *LLVMGetMDString(LLVMValueRef V, unsigned *Length) {
1052  if (const auto *MD = dyn_cast<MetadataAsValue>(unwrap(V)))
1053  if (const MDString *S = dyn_cast<MDString>(MD->getMetadata())) {
1054  *Length = S->getString().size();
1055  return S->getString().data();
1056  }
1057  *Length = 0;
1058  return nullptr;
1059 }
1060 
1062  auto *MD = cast<MetadataAsValue>(unwrap(V));
1063  if (isa<ValueAsMetadata>(MD->getMetadata()))
1064  return 1;
1065  return cast<MDNode>(MD->getMetadata())->getNumOperands();
1066 }
1067 
1069  auto *MD = cast<MetadataAsValue>(unwrap(V));
1070  if (auto *MDV = dyn_cast<ValueAsMetadata>(MD->getMetadata())) {
1071  *Dest = wrap(MDV->getValue());
1072  return;
1073  }
1074  const auto *N = cast<MDNode>(MD->getMetadata());
1075  const unsigned numOperands = N->getNumOperands();
1076  LLVMContext &Context = unwrap(V)->getContext();
1077  for (unsigned i = 0; i < numOperands; i++)
1078  Dest[i] = getMDNodeOperandImpl(Context, N, i);
1079 }
1080 
1082  if (NamedMDNode *N = unwrap(M)->getNamedMetadata(Name)) {
1083  return N->getNumOperands();
1084  }
1085  return 0;
1086 }
1087 
1089  LLVMValueRef *Dest) {
1090  NamedMDNode *N = unwrap(M)->getNamedMetadata(Name);
1091  if (!N)
1092  return;
1093  LLVMContext &Context = unwrap(M)->getContext();
1094  for (unsigned i=0;i<N->getNumOperands();i++)
1095  Dest[i] = wrap(MetadataAsValue::get(Context, N->getOperand(i)));
1096 }
1097 
1099  LLVMValueRef Val) {
1100  NamedMDNode *N = unwrap(M)->getOrInsertNamedMetadata(Name);
1101  if (!N)
1102  return;
1103  if (!Val)
1104  return;
1105  N->addOperand(extractMDNode(unwrap<MetadataAsValue>(Val)));
1106 }
1107 
1108 /*--.. Operations on scalar constants ......................................--*/
1109 
1110 LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
1111  LLVMBool SignExtend) {
1112  return wrap(ConstantInt::get(unwrap<IntegerType>(IntTy), N, SignExtend != 0));
1113 }
1114 
1116  unsigned NumWords,
1117  const uint64_t Words[]) {
1118  IntegerType *Ty = unwrap<IntegerType>(IntTy);
1119  return wrap(ConstantInt::get(Ty->getContext(),
1120  APInt(Ty->getBitWidth(),
1121  makeArrayRef(Words, NumWords))));
1122 }
1123 
1125  uint8_t Radix) {
1126  return wrap(ConstantInt::get(unwrap<IntegerType>(IntTy), StringRef(Str),
1127  Radix));
1128 }
1129 
1131  unsigned SLen, uint8_t Radix) {
1132  return wrap(ConstantInt::get(unwrap<IntegerType>(IntTy), StringRef(Str, SLen),
1133  Radix));
1134 }
1135 
1137  return wrap(ConstantFP::get(unwrap(RealTy), N));
1138 }
1139 
1141  return wrap(ConstantFP::get(unwrap(RealTy), StringRef(Text)));
1142 }
1143 
1145  unsigned SLen) {
1146  return wrap(ConstantFP::get(unwrap(RealTy), StringRef(Str, SLen)));
1147 }
1148 
1149 unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal) {
1150  return unwrap<ConstantInt>(ConstantVal)->getZExtValue();
1151 }
1152 
1153 long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal) {
1154  return unwrap<ConstantInt>(ConstantVal)->getSExtValue();
1155 }
1156 
1157 double LLVMConstRealGetDouble(LLVMValueRef ConstantVal, LLVMBool *LosesInfo) {
1158  ConstantFP *cFP = unwrap<ConstantFP>(ConstantVal) ;
1159  Type *Ty = cFP->getType();
1160 
1161  if (Ty->isFloatTy()) {
1162  *LosesInfo = false;
1163  return cFP->getValueAPF().convertToFloat();
1164  }
1165 
1166  if (Ty->isDoubleTy()) {
1167  *LosesInfo = false;
1168  return cFP->getValueAPF().convertToDouble();
1169  }
1170 
1171  bool APFLosesInfo;
1172  APFloat APF = cFP->getValueAPF();
1174  *LosesInfo = APFLosesInfo;
1175  return APF.convertToDouble();
1176 }
1177 
1178 /*--.. Operations on composite constants ...................................--*/
1179 
1181  unsigned Length,
1182  LLVMBool DontNullTerminate) {
1183  /* Inverted the sense of AddNull because ', 0)' is a
1184  better mnemonic for null termination than ', 1)'. */
1185  return wrap(ConstantDataArray::getString(*unwrap(C), StringRef(Str, Length),
1186  DontNullTerminate == 0));
1187 }
1188 
1189 LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
1190  LLVMBool DontNullTerminate) {
1191  return LLVMConstStringInContext(LLVMGetGlobalContext(), Str, Length,
1192  DontNullTerminate);
1193 }
1194 
1196  return wrap(unwrap<ConstantDataSequential>(C)->getElementAsConstant(idx));
1197 }
1198 
1200  return unwrap<ConstantDataSequential>(C)->isString();
1201 }
1202 
1203 const char *LLVMGetAsString(LLVMValueRef C, size_t *Length) {
1204  StringRef Str = unwrap<ConstantDataSequential>(C)->getAsString();
1205  *Length = Str.size();
1206  return Str.data();
1207 }
1208 
1210  LLVMValueRef *ConstantVals, unsigned Length) {
1211  ArrayRef<Constant*> V(unwrap<Constant>(ConstantVals, Length), Length);
1212  return wrap(ConstantArray::get(ArrayType::get(unwrap(ElementTy), Length), V));
1213 }
1214 
1216  LLVMValueRef *ConstantVals,
1217  unsigned Count, LLVMBool Packed) {
1218  Constant **Elements = unwrap<Constant>(ConstantVals, Count);
1219  return wrap(ConstantStruct::getAnon(*unwrap(C), makeArrayRef(Elements, Count),
1220  Packed != 0));
1221 }
1222 
1223 LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
1224  LLVMBool Packed) {
1225  return LLVMConstStructInContext(LLVMGetGlobalContext(), ConstantVals, Count,
1226  Packed);
1227 }
1228 
1230  LLVMValueRef *ConstantVals,
1231  unsigned Count) {
1232  Constant **Elements = unwrap<Constant>(ConstantVals, Count);
1233  StructType *Ty = cast<StructType>(unwrap(StructTy));
1234 
1235  return wrap(ConstantStruct::get(Ty, makeArrayRef(Elements, Count)));
1236 }
1237 
1238 LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size) {
1240  unwrap<Constant>(ScalarConstantVals, Size), Size)));
1241 }
1242 
1243 /*-- Opcode mapping */
1244 
1245 static LLVMOpcode map_to_llvmopcode(int opcode)
1246 {
1247  switch (opcode) {
1248  default: llvm_unreachable("Unhandled Opcode.");
1249 #define HANDLE_INST(num, opc, clas) case num: return LLVM##opc;
1250 #include "llvm/IR/Instruction.def"
1251 #undef HANDLE_INST
1252  }
1253 }
1254 
1256 {
1257  switch (code) {
1258 #define HANDLE_INST(num, opc, clas) case LLVM##opc: return num;
1259 #include "llvm/IR/Instruction.def"
1260 #undef HANDLE_INST
1261  }
1262  llvm_unreachable("Unhandled Opcode.");
1263 }
1264 
1265 /*--.. Constant expressions ................................................--*/
1266 
1268  return map_to_llvmopcode(unwrap<ConstantExpr>(ConstantVal)->getOpcode());
1269 }
1270 
1272  return wrap(ConstantExpr::getAlignOf(unwrap(Ty)));
1273 }
1274 
1276  return wrap(ConstantExpr::getSizeOf(unwrap(Ty)));
1277 }
1278 
1280  return wrap(ConstantExpr::getNeg(unwrap<Constant>(ConstantVal)));
1281 }
1282 
1284  return wrap(ConstantExpr::getNSWNeg(unwrap<Constant>(ConstantVal)));
1285 }
1286 
1288  return wrap(ConstantExpr::getNUWNeg(unwrap<Constant>(ConstantVal)));
1289 }
1290 
1291 
1293  return wrap(ConstantExpr::getFNeg(unwrap<Constant>(ConstantVal)));
1294 }
1295 
1297  return wrap(ConstantExpr::getNot(unwrap<Constant>(ConstantVal)));
1298 }
1299 
1301  return wrap(ConstantExpr::getAdd(unwrap<Constant>(LHSConstant),
1302  unwrap<Constant>(RHSConstant)));
1303 }
1304 
1306  LLVMValueRef RHSConstant) {
1307  return wrap(ConstantExpr::getNSWAdd(unwrap<Constant>(LHSConstant),
1308  unwrap<Constant>(RHSConstant)));
1309 }
1310 
1312  LLVMValueRef RHSConstant) {
1313  return wrap(ConstantExpr::getNUWAdd(unwrap<Constant>(LHSConstant),
1314  unwrap<Constant>(RHSConstant)));
1315 }
1316 
1318  return wrap(ConstantExpr::getFAdd(unwrap<Constant>(LHSConstant),
1319  unwrap<Constant>(RHSConstant)));
1320 }
1321 
1323  return wrap(ConstantExpr::getSub(unwrap<Constant>(LHSConstant),
1324  unwrap<Constant>(RHSConstant)));
1325 }
1326 
1328  LLVMValueRef RHSConstant) {
1329  return wrap(ConstantExpr::getNSWSub(unwrap<Constant>(LHSConstant),
1330  unwrap<Constant>(RHSConstant)));
1331 }
1332 
1334  LLVMValueRef RHSConstant) {
1335  return wrap(ConstantExpr::getNUWSub(unwrap<Constant>(LHSConstant),
1336  unwrap<Constant>(RHSConstant)));
1337 }
1338 
1340  return wrap(ConstantExpr::getFSub(unwrap<Constant>(LHSConstant),
1341  unwrap<Constant>(RHSConstant)));
1342 }
1343 
1345  return wrap(ConstantExpr::getMul(unwrap<Constant>(LHSConstant),
1346  unwrap<Constant>(RHSConstant)));
1347 }
1348 
1350  LLVMValueRef RHSConstant) {
1351  return wrap(ConstantExpr::getNSWMul(unwrap<Constant>(LHSConstant),
1352  unwrap<Constant>(RHSConstant)));
1353 }
1354 
1356  LLVMValueRef RHSConstant) {
1357  return wrap(ConstantExpr::getNUWMul(unwrap<Constant>(LHSConstant),
1358  unwrap<Constant>(RHSConstant)));
1359 }
1360 
1362  return wrap(ConstantExpr::getFMul(unwrap<Constant>(LHSConstant),
1363  unwrap<Constant>(RHSConstant)));
1364 }
1365 
1367  return wrap(ConstantExpr::getUDiv(unwrap<Constant>(LHSConstant),
1368  unwrap<Constant>(RHSConstant)));
1369 }
1370 
1372  LLVMValueRef RHSConstant) {
1373  return wrap(ConstantExpr::getExactUDiv(unwrap<Constant>(LHSConstant),
1374  unwrap<Constant>(RHSConstant)));
1375 }
1376 
1378  return wrap(ConstantExpr::getSDiv(unwrap<Constant>(LHSConstant),
1379  unwrap<Constant>(RHSConstant)));
1380 }
1381 
1383  LLVMValueRef RHSConstant) {
1384  return wrap(ConstantExpr::getExactSDiv(unwrap<Constant>(LHSConstant),
1385  unwrap<Constant>(RHSConstant)));
1386 }
1387 
1389  return wrap(ConstantExpr::getFDiv(unwrap<Constant>(LHSConstant),
1390  unwrap<Constant>(RHSConstant)));
1391 }
1392 
1394  return wrap(ConstantExpr::getURem(unwrap<Constant>(LHSConstant),
1395  unwrap<Constant>(RHSConstant)));
1396 }
1397 
1399  return wrap(ConstantExpr::getSRem(unwrap<Constant>(LHSConstant),
1400  unwrap<Constant>(RHSConstant)));
1401 }
1402 
1404  return wrap(ConstantExpr::getFRem(unwrap<Constant>(LHSConstant),
1405  unwrap<Constant>(RHSConstant)));
1406 }
1407 
1409  return wrap(ConstantExpr::getAnd(unwrap<Constant>(LHSConstant),
1410  unwrap<Constant>(RHSConstant)));
1411 }
1412 
1414  return wrap(ConstantExpr::getOr(unwrap<Constant>(LHSConstant),
1415  unwrap<Constant>(RHSConstant)));
1416 }
1417 
1419  return wrap(ConstantExpr::getXor(unwrap<Constant>(LHSConstant),
1420  unwrap<Constant>(RHSConstant)));
1421 }
1422 
1424  LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1425  return wrap(ConstantExpr::getICmp(Predicate,
1426  unwrap<Constant>(LHSConstant),
1427  unwrap<Constant>(RHSConstant)));
1428 }
1429 
1431  LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1432  return wrap(ConstantExpr::getFCmp(Predicate,
1433  unwrap<Constant>(LHSConstant),
1434  unwrap<Constant>(RHSConstant)));
1435 }
1436 
1438  return wrap(ConstantExpr::getShl(unwrap<Constant>(LHSConstant),
1439  unwrap<Constant>(RHSConstant)));
1440 }
1441 
1443  return wrap(ConstantExpr::getLShr(unwrap<Constant>(LHSConstant),
1444  unwrap<Constant>(RHSConstant)));
1445 }
1446 
1448  return wrap(ConstantExpr::getAShr(unwrap<Constant>(LHSConstant),
1449  unwrap<Constant>(RHSConstant)));
1450 }
1451 
1453  LLVMValueRef *ConstantIndices, unsigned NumIndices) {
1454  ArrayRef<Constant *> IdxList(unwrap<Constant>(ConstantIndices, NumIndices),
1455  NumIndices);
1457  nullptr, unwrap<Constant>(ConstantVal), IdxList));
1458 }
1459 
1461  LLVMValueRef *ConstantIndices,
1462  unsigned NumIndices) {
1463  Constant* Val = unwrap<Constant>(ConstantVal);
1464  ArrayRef<Constant *> IdxList(unwrap<Constant>(ConstantIndices, NumIndices),
1465  NumIndices);
1466  return wrap(ConstantExpr::getInBoundsGetElementPtr(nullptr, Val, IdxList));
1467 }
1468 
1470  return wrap(ConstantExpr::getTrunc(unwrap<Constant>(ConstantVal),
1471  unwrap(ToType)));
1472 }
1473 
1475  return wrap(ConstantExpr::getSExt(unwrap<Constant>(ConstantVal),
1476  unwrap(ToType)));
1477 }
1478 
1480  return wrap(ConstantExpr::getZExt(unwrap<Constant>(ConstantVal),
1481  unwrap(ToType)));
1482 }
1483 
1485  return wrap(ConstantExpr::getFPTrunc(unwrap<Constant>(ConstantVal),
1486  unwrap(ToType)));
1487 }
1488 
1490  return wrap(ConstantExpr::getFPExtend(unwrap<Constant>(ConstantVal),
1491  unwrap(ToType)));
1492 }
1493 
1495  return wrap(ConstantExpr::getUIToFP(unwrap<Constant>(ConstantVal),
1496  unwrap(ToType)));
1497 }
1498 
1500  return wrap(ConstantExpr::getSIToFP(unwrap<Constant>(ConstantVal),
1501  unwrap(ToType)));
1502 }
1503 
1505  return wrap(ConstantExpr::getFPToUI(unwrap<Constant>(ConstantVal),
1506  unwrap(ToType)));
1507 }
1508 
1510  return wrap(ConstantExpr::getFPToSI(unwrap<Constant>(ConstantVal),
1511  unwrap(ToType)));
1512 }
1513 
1515  return wrap(ConstantExpr::getPtrToInt(unwrap<Constant>(ConstantVal),
1516  unwrap(ToType)));
1517 }
1518 
1520  return wrap(ConstantExpr::getIntToPtr(unwrap<Constant>(ConstantVal),
1521  unwrap(ToType)));
1522 }
1523 
1525  return wrap(ConstantExpr::getBitCast(unwrap<Constant>(ConstantVal),
1526  unwrap(ToType)));
1527 }
1528 
1530  LLVMTypeRef ToType) {
1531  return wrap(ConstantExpr::getAddrSpaceCast(unwrap<Constant>(ConstantVal),
1532  unwrap(ToType)));
1533 }
1534 
1536  LLVMTypeRef ToType) {
1537  return wrap(ConstantExpr::getZExtOrBitCast(unwrap<Constant>(ConstantVal),
1538  unwrap(ToType)));
1539 }
1540 
1542  LLVMTypeRef ToType) {
1543  return wrap(ConstantExpr::getSExtOrBitCast(unwrap<Constant>(ConstantVal),
1544  unwrap(ToType)));
1545 }
1546 
1548  LLVMTypeRef ToType) {
1549  return wrap(ConstantExpr::getTruncOrBitCast(unwrap<Constant>(ConstantVal),
1550  unwrap(ToType)));
1551 }
1552 
1554  LLVMTypeRef ToType) {
1555  return wrap(ConstantExpr::getPointerCast(unwrap<Constant>(ConstantVal),
1556  unwrap(ToType)));
1557 }
1558 
1560  LLVMBool isSigned) {
1561  return wrap(ConstantExpr::getIntegerCast(unwrap<Constant>(ConstantVal),
1562  unwrap(ToType), isSigned));
1563 }
1564 
1566  return wrap(ConstantExpr::getFPCast(unwrap<Constant>(ConstantVal),
1567  unwrap(ToType)));
1568 }
1569 
1571  LLVMValueRef ConstantIfTrue,
1572  LLVMValueRef ConstantIfFalse) {
1573  return wrap(ConstantExpr::getSelect(unwrap<Constant>(ConstantCondition),
1574  unwrap<Constant>(ConstantIfTrue),
1575  unwrap<Constant>(ConstantIfFalse)));
1576 }
1577 
1579  LLVMValueRef IndexConstant) {
1580  return wrap(ConstantExpr::getExtractElement(unwrap<Constant>(VectorConstant),
1581  unwrap<Constant>(IndexConstant)));
1582 }
1583 
1585  LLVMValueRef ElementValueConstant,
1586  LLVMValueRef IndexConstant) {
1587  return wrap(ConstantExpr::getInsertElement(unwrap<Constant>(VectorConstant),
1588  unwrap<Constant>(ElementValueConstant),
1589  unwrap<Constant>(IndexConstant)));
1590 }
1591 
1593  LLVMValueRef VectorBConstant,
1594  LLVMValueRef MaskConstant) {
1595  return wrap(ConstantExpr::getShuffleVector(unwrap<Constant>(VectorAConstant),
1596  unwrap<Constant>(VectorBConstant),
1597  unwrap<Constant>(MaskConstant)));
1598 }
1599 
1600 LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
1601  unsigned NumIdx) {
1602  return wrap(ConstantExpr::getExtractValue(unwrap<Constant>(AggConstant),
1603  makeArrayRef(IdxList, NumIdx)));
1604 }
1605 
1607  LLVMValueRef ElementValueConstant,
1608  unsigned *IdxList, unsigned NumIdx) {
1609  return wrap(ConstantExpr::getInsertValue(unwrap<Constant>(AggConstant),
1610  unwrap<Constant>(ElementValueConstant),
1611  makeArrayRef(IdxList, NumIdx)));
1612 }
1613 
1614 LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty, const char *AsmString,
1615  const char *Constraints,
1616  LLVMBool HasSideEffects,
1617  LLVMBool IsAlignStack) {
1618  return wrap(InlineAsm::get(dyn_cast<FunctionType>(unwrap(Ty)), AsmString,
1619  Constraints, HasSideEffects, IsAlignStack));
1620 }
1621 
1623  return wrap(BlockAddress::get(unwrap<Function>(F), unwrap(BB)));
1624 }
1625 
1626 /*--.. Operations on global variables, functions, and aliases (globals) ....--*/
1627 
1629  return wrap(unwrap<GlobalValue>(Global)->getParent());
1630 }
1631 
1633  return unwrap<GlobalValue>(Global)->isDeclaration();
1634 }
1635 
1637  switch (unwrap<GlobalValue>(Global)->getLinkage()) {
1639  return LLVMExternalLinkage;
1643  return LLVMLinkOnceAnyLinkage;
1645  return LLVMLinkOnceODRLinkage;
1647  return LLVMWeakAnyLinkage;
1649  return LLVMWeakODRLinkage;
1651  return LLVMAppendingLinkage;
1653  return LLVMInternalLinkage;
1655  return LLVMPrivateLinkage;
1657  return LLVMExternalWeakLinkage;
1659  return LLVMCommonLinkage;
1660  }
1661 
1662  llvm_unreachable("Invalid GlobalValue linkage!");
1663 }
1664 
1665 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage) {
1666  GlobalValue *GV = unwrap<GlobalValue>(Global);
1667 
1668  switch (Linkage) {
1669  case LLVMExternalLinkage:
1671  break;
1674  break;
1677  break;
1680  break;
1682  LLVM_DEBUG(
1683  errs() << "LLVMSetLinkage(): LLVMLinkOnceODRAutoHideLinkage is no "
1684  "longer supported.");
1685  break;
1686  case LLVMWeakAnyLinkage:
1688  break;
1689  case LLVMWeakODRLinkage:
1691  break;
1692  case LLVMAppendingLinkage:
1694  break;
1695  case LLVMInternalLinkage:
1697  break;
1698  case LLVMPrivateLinkage:
1700  break;
1703  break;
1706  break;
1707  case LLVMDLLImportLinkage:
1708  LLVM_DEBUG(
1709  errs()
1710  << "LLVMSetLinkage(): LLVMDLLImportLinkage is no longer supported.");
1711  break;
1712  case LLVMDLLExportLinkage:
1713  LLVM_DEBUG(
1714  errs()
1715  << "LLVMSetLinkage(): LLVMDLLExportLinkage is no longer supported.");
1716  break;
1719  break;
1720  case LLVMGhostLinkage:
1721  LLVM_DEBUG(
1722  errs() << "LLVMSetLinkage(): LLVMGhostLinkage is no longer supported.");
1723  break;
1724  case LLVMCommonLinkage:
1726  break;
1727  }
1728 }
1729 
1730 const char *LLVMGetSection(LLVMValueRef Global) {
1731  // Using .data() is safe because of how GlobalObject::setSection is
1732  // implemented.
1733  return unwrap<GlobalValue>(Global)->getSection().data();
1734 }
1735 
1736 void LLVMSetSection(LLVMValueRef Global, const char *Section) {
1737  unwrap<GlobalObject>(Global)->setSection(Section);
1738 }
1739 
1741  return static_cast<LLVMVisibility>(
1742  unwrap<GlobalValue>(Global)->getVisibility());
1743 }
1744 
1746  unwrap<GlobalValue>(Global)
1747  ->setVisibility(static_cast<GlobalValue::VisibilityTypes>(Viz));
1748 }
1749 
1751  return static_cast<LLVMDLLStorageClass>(
1752  unwrap<GlobalValue>(Global)->getDLLStorageClass());
1753 }
1754 
1756  unwrap<GlobalValue>(Global)->setDLLStorageClass(
1757  static_cast<GlobalValue::DLLStorageClassTypes>(Class));
1758 }
1759 
1761  switch (unwrap<GlobalValue>(Global)->getUnnamedAddr()) {
1763  return LLVMNoUnnamedAddr;
1765  return LLVMLocalUnnamedAddr;
1767  return LLVMGlobalUnnamedAddr;
1768  }
1769  llvm_unreachable("Unknown UnnamedAddr kind!");
1770 }
1771 
1773  GlobalValue *GV = unwrap<GlobalValue>(Global);
1774 
1775  switch (UnnamedAddr) {
1776  case LLVMNoUnnamedAddr:
1778  case LLVMLocalUnnamedAddr:
1780  case LLVMGlobalUnnamedAddr:
1782  }
1783 }
1784 
1786  return unwrap<GlobalValue>(Global)->hasGlobalUnnamedAddr();
1787 }
1788 
1789 void LLVMSetUnnamedAddr(LLVMValueRef Global, LLVMBool HasUnnamedAddr) {
1790  unwrap<GlobalValue>(Global)->setUnnamedAddr(
1791  HasUnnamedAddr ? GlobalValue::UnnamedAddr::Global
1793 }
1794 
1795 /*--.. Operations on global variables, load and store instructions .........--*/
1796 
1798  Value *P = unwrap<Value>(V);
1799  if (GlobalValue *GV = dyn_cast<GlobalValue>(P))
1800  return GV->getAlignment();
1801  if (AllocaInst *AI = dyn_cast<AllocaInst>(P))
1802  return AI->getAlignment();
1803  if (LoadInst *LI = dyn_cast<LoadInst>(P))
1804  return LI->getAlignment();
1805  if (StoreInst *SI = dyn_cast<StoreInst>(P))
1806  return SI->getAlignment();
1807 
1809  "only GlobalValue, AllocaInst, LoadInst and StoreInst have alignment");
1810 }
1811 
1812 void LLVMSetAlignment(LLVMValueRef V, unsigned Bytes) {
1813  Value *P = unwrap<Value>(V);
1814  if (GlobalObject *GV = dyn_cast<GlobalObject>(P))
1815  GV->setAlignment(Bytes);
1816  else if (AllocaInst *AI = dyn_cast<AllocaInst>(P))
1817  AI->setAlignment(Bytes);
1818  else if (LoadInst *LI = dyn_cast<LoadInst>(P))
1819  LI->setAlignment(Bytes);
1820  else if (StoreInst *SI = dyn_cast<StoreInst>(P))
1821  SI->setAlignment(Bytes);
1822  else
1824  "only GlobalValue, AllocaInst, LoadInst and StoreInst have alignment");
1825 }
1826 
1827 /*--.. Operations on global variables ......................................--*/
1828 
1830  return wrap(new GlobalVariable(*unwrap(M), unwrap(Ty), false,
1831  GlobalValue::ExternalLinkage, nullptr, Name));
1832 }
1833 
1835  const char *Name,
1836  unsigned AddressSpace) {
1837  return wrap(new GlobalVariable(*unwrap(M), unwrap(Ty), false,
1838  GlobalValue::ExternalLinkage, nullptr, Name,
1840  AddressSpace));
1841 }
1842 
1844  return wrap(unwrap(M)->getNamedGlobal(Name));
1845 }
1846 
1848  Module *Mod = unwrap(M);
1850  if (I == Mod->global_end())
1851  return nullptr;
1852  return wrap(&*I);
1853 }
1854 
1856  Module *Mod = unwrap(M);
1858  if (I == Mod->global_begin())
1859  return nullptr;
1860  return wrap(&*--I);
1861 }
1862 
1864  GlobalVariable *GV = unwrap<GlobalVariable>(GlobalVar);
1866  if (++I == GV->getParent()->global_end())
1867  return nullptr;
1868  return wrap(&*I);
1869 }
1870 
1872  GlobalVariable *GV = unwrap<GlobalVariable>(GlobalVar);
1874  if (I == GV->getParent()->global_begin())
1875  return nullptr;
1876  return wrap(&*--I);
1877 }
1878 
1880  unwrap<GlobalVariable>(GlobalVar)->eraseFromParent();
1881 }
1882 
1884  GlobalVariable* GV = unwrap<GlobalVariable>(GlobalVar);
1885  if ( !GV->hasInitializer() )
1886  return nullptr;
1887  return wrap(GV->getInitializer());
1888 }
1889 
1891  unwrap<GlobalVariable>(GlobalVar)
1892  ->setInitializer(unwrap<Constant>(ConstantVal));
1893 }
1894 
1896  return unwrap<GlobalVariable>(GlobalVar)->isThreadLocal();
1897 }
1898 
1900  unwrap<GlobalVariable>(GlobalVar)->setThreadLocal(IsThreadLocal != 0);
1901 }
1902 
1904  return unwrap<GlobalVariable>(GlobalVar)->isConstant();
1905 }
1906 
1908  unwrap<GlobalVariable>(GlobalVar)->setConstant(IsConstant != 0);
1909 }
1910 
1912  switch (unwrap<GlobalVariable>(GlobalVar)->getThreadLocalMode()) {
1914  return LLVMNotThreadLocal;
1918  return LLVMLocalDynamicTLSModel;
1920  return LLVMInitialExecTLSModel;
1922  return LLVMLocalExecTLSModel;
1923  }
1924 
1925  llvm_unreachable("Invalid GlobalVariable thread local mode");
1926 }
1927 
1929  GlobalVariable *GV = unwrap<GlobalVariable>(GlobalVar);
1930 
1931  switch (Mode) {
1932  case LLVMNotThreadLocal:
1934  break;
1937  break;
1940  break;
1943  break;
1944  case LLVMLocalExecTLSModel:
1946  break;
1947  }
1948 }
1949 
1951  return unwrap<GlobalVariable>(GlobalVar)->isExternallyInitialized();
1952 }
1953 
1955  unwrap<GlobalVariable>(GlobalVar)->setExternallyInitialized(IsExtInit);
1956 }
1957 
1958 /*--.. Operations on aliases ......................................--*/
1959 
1961  const char *Name) {
1962  auto *PTy = cast<PointerType>(unwrap(Ty));
1963  return wrap(GlobalAlias::create(PTy->getElementType(), PTy->getAddressSpace(),
1965  unwrap<Constant>(Aliasee), unwrap(M)));
1966 }
1967 
1969  const char *Name, size_t NameLen) {
1970  return wrap(unwrap(M)->getNamedAlias(Name));
1971 }
1972 
1974  Module *Mod = unwrap(M);
1976  if (I == Mod->alias_end())
1977  return nullptr;
1978  return wrap(&*I);
1979 }
1980 
1982  Module *Mod = unwrap(M);
1984  if (I == Mod->alias_begin())
1985  return nullptr;
1986  return wrap(&*--I);
1987 }
1988 
1990  GlobalAlias *Alias = unwrap<GlobalAlias>(GA);
1991  Module::alias_iterator I(Alias);
1992  if (++I == Alias->getParent()->alias_end())
1993  return nullptr;
1994  return wrap(&*I);
1995 }
1996 
1998  GlobalAlias *Alias = unwrap<GlobalAlias>(GA);
1999  Module::alias_iterator I(Alias);
2000  if (I == Alias->getParent()->alias_begin())
2001  return nullptr;
2002  return wrap(&*--I);
2003 }
2004 
2006  return wrap(unwrap<GlobalAlias>(Alias)->getAliasee());
2007 }
2008 
2010  unwrap<GlobalAlias>(Alias)->setAliasee(unwrap<Constant>(Aliasee));
2011 }
2012 
2013 /*--.. Operations on functions .............................................--*/
2014 
2016  LLVMTypeRef FunctionTy) {
2017  return wrap(Function::Create(unwrap<FunctionType>(FunctionTy),
2019 }
2020 
2022  return wrap(unwrap(M)->getFunction(Name));
2023 }
2024 
2026  Module *Mod = unwrap(M);
2027  Module::iterator I = Mod->begin();
2028  if (I == Mod->end())
2029  return nullptr;
2030  return wrap(&*I);
2031 }
2032 
2034  Module *Mod = unwrap(M);
2035  Module::iterator I = Mod->end();
2036  if (I == Mod->begin())
2037  return nullptr;
2038  return wrap(&*--I);
2039 }
2040 
2042  Function *Func = unwrap<Function>(Fn);
2043  Module::iterator I(Func);
2044  if (++I == Func->getParent()->end())
2045  return nullptr;
2046  return wrap(&*I);
2047 }
2048 
2050  Function *Func = unwrap<Function>(Fn);
2051  Module::iterator I(Func);
2052  if (I == Func->getParent()->begin())
2053  return nullptr;
2054  return wrap(&*--I);
2055 }
2056 
2058  unwrap<Function>(Fn)->eraseFromParent();
2059 }
2060 
2062  return unwrap<Function>(Fn)->hasPersonalityFn();
2063 }
2064 
2066  return wrap(unwrap<Function>(Fn)->getPersonalityFn());
2067 }
2068 
2070  unwrap<Function>(Fn)->setPersonalityFn(unwrap<Constant>(PersonalityFn));
2071 }
2072 
2074  if (Function *F = dyn_cast<Function>(unwrap(Fn)))
2075  return F->getIntrinsicID();
2076  return 0;
2077 }
2078 
2080  return unwrap<Function>(Fn)->getCallingConv();
2081 }
2082 
2083 void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC) {
2084  return unwrap<Function>(Fn)->setCallingConv(
2085  static_cast<CallingConv::ID>(CC));
2086 }
2087 
2088 const char *LLVMGetGC(LLVMValueRef Fn) {
2089  Function *F = unwrap<Function>(Fn);
2090  return F->hasGC()? F->getGC().c_str() : nullptr;
2091 }
2092 
2093 void LLVMSetGC(LLVMValueRef Fn, const char *GC) {
2094  Function *F = unwrap<Function>(Fn);
2095  if (GC)
2096  F->setGC(GC);
2097  else
2098  F->clearGC();
2099 }
2100 
2102  LLVMAttributeRef A) {
2103  unwrap<Function>(F)->addAttribute(Idx, unwrap(A));
2104 }
2105 
2107  auto AS = unwrap<Function>(F)->getAttributes().getAttributes(Idx);
2108  return AS.getNumAttributes();
2109 }
2110 
2113  auto AS = unwrap<Function>(F)->getAttributes().getAttributes(Idx);
2114  for (auto A : AS)
2115  *Attrs++ = wrap(A);
2116 }
2117 
2119  LLVMAttributeIndex Idx,
2120  unsigned KindID) {
2121  return wrap(unwrap<Function>(F)->getAttribute(Idx,
2122  (Attribute::AttrKind)KindID));
2123 }
2124 
2126  LLVMAttributeIndex Idx,
2127  const char *K, unsigned KLen) {
2128  return wrap(unwrap<Function>(F)->getAttribute(Idx, StringRef(K, KLen)));
2129 }
2130 
2132  unsigned KindID) {
2133  unwrap<Function>(F)->removeAttribute(Idx, (Attribute::AttrKind)KindID);
2134 }
2135 
2137  const char *K, unsigned KLen) {
2138  unwrap<Function>(F)->removeAttribute(Idx, StringRef(K, KLen));
2139 }
2140 
2142  const char *V) {
2143  Function *Func = unwrap<Function>(Fn);
2144  Attribute Attr = Attribute::get(Func->getContext(), A, V);
2146 }
2147 
2148 /*--.. Operations on parameters ............................................--*/
2149 
2151  // This function is strictly redundant to
2152  // LLVMCountParamTypes(LLVMGetElementType(LLVMTypeOf(FnRef)))
2153  return unwrap<Function>(FnRef)->arg_size();
2154 }
2155 
2156 void LLVMGetParams(LLVMValueRef FnRef, LLVMValueRef *ParamRefs) {
2157  Function *Fn = unwrap<Function>(FnRef);
2158  for (Function::arg_iterator I = Fn->arg_begin(),
2159  E = Fn->arg_end(); I != E; I++)
2160  *ParamRefs++ = wrap(&*I);
2161 }
2162 
2163 LLVMValueRef LLVMGetParam(LLVMValueRef FnRef, unsigned index) {
2164  Function *Fn = unwrap<Function>(FnRef);
2165  return wrap(&Fn->arg_begin()[index]);
2166 }
2167 
2169  return wrap(unwrap<Argument>(V)->getParent());
2170 }
2171 
2173  Function *Func = unwrap<Function>(Fn);
2175  if (I == Func->arg_end())
2176  return nullptr;
2177  return wrap(&*I);
2178 }
2179 
2181  Function *Func = unwrap<Function>(Fn);
2182  Function::arg_iterator I = Func->arg_end();
2183  if (I == Func->arg_begin())
2184  return nullptr;
2185  return wrap(&*--I);
2186 }
2187 
2189  Argument *A = unwrap<Argument>(Arg);
2190  Function *Fn = A->getParent();
2191  if (A->getArgNo() + 1 >= Fn->arg_size())
2192  return nullptr;
2193  return wrap(&Fn->arg_begin()[A->getArgNo() + 1]);
2194 }
2195 
2197  Argument *A = unwrap<Argument>(Arg);
2198  if (A->getArgNo() == 0)
2199  return nullptr;
2200  return wrap(&A->getParent()->arg_begin()[A->getArgNo() - 1]);
2201 }
2202 
2203 void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align) {
2204  Argument *A = unwrap<Argument>(Arg);
2206 }
2207 
2208 /*--.. Operations on basic blocks ..........................................--*/
2209 
2211  return wrap(static_cast<Value*>(unwrap(BB)));
2212 }
2213 
2215  return isa<BasicBlock>(unwrap(Val));
2216 }
2217 
2219  return wrap(unwrap<BasicBlock>(Val));
2220 }
2221 
2223  return unwrap(BB)->getName().data();
2224 }
2225 
2227  return wrap(unwrap(BB)->getParent());
2228 }
2229 
2231  return wrap(unwrap(BB)->getTerminator());
2232 }
2233 
2235  return unwrap<Function>(FnRef)->size();
2236 }
2237 
2238 void LLVMGetBasicBlocks(LLVMValueRef FnRef, LLVMBasicBlockRef *BasicBlocksRefs){
2239  Function *Fn = unwrap<Function>(FnRef);
2240  for (BasicBlock &BB : *Fn)
2241  *BasicBlocksRefs++ = wrap(&BB);
2242 }
2243 
2245  return wrap(&unwrap<Function>(Fn)->getEntryBlock());
2246 }
2247 
2249  Function *Func = unwrap<Function>(Fn);
2250  Function::iterator I = Func->begin();
2251  if (I == Func->end())
2252  return nullptr;
2253  return wrap(&*I);
2254 }
2255 
2257  Function *Func = unwrap<Function>(Fn);
2258  Function::iterator I = Func->end();
2259  if (I == Func->begin())
2260  return nullptr;
2261  return wrap(&*--I);
2262 }
2263 
2265  BasicBlock *Block = unwrap(BB);
2266  Function::iterator I(Block);
2267  if (++I == Block->getParent()->end())
2268  return nullptr;
2269  return wrap(&*I);
2270 }
2271 
2273  BasicBlock *Block = unwrap(BB);
2274  Function::iterator I(Block);
2275  if (I == Block->getParent()->begin())
2276  return nullptr;
2277  return wrap(&*--I);
2278 }
2279 
2281  LLVMValueRef FnRef,
2282  const char *Name) {
2283  return wrap(BasicBlock::Create(*unwrap(C), Name, unwrap<Function>(FnRef)));
2284 }
2285 
2287  return LLVMAppendBasicBlockInContext(LLVMGetGlobalContext(), FnRef, Name);
2288 }
2289 
2291  LLVMBasicBlockRef BBRef,
2292  const char *Name) {
2293  BasicBlock *BB = unwrap(BBRef);
2294  return wrap(BasicBlock::Create(*unwrap(C), Name, BB->getParent(), BB));
2295 }
2296 
2298  const char *Name) {
2299  return LLVMInsertBasicBlockInContext(LLVMGetGlobalContext(), BBRef, Name);
2300 }
2301 
2303  unwrap(BBRef)->eraseFromParent();
2304 }
2305 
2307  unwrap(BBRef)->removeFromParent();
2308 }
2309 
2311  unwrap(BB)->moveBefore(unwrap(MovePos));
2312 }
2313 
2315  unwrap(BB)->moveAfter(unwrap(MovePos));
2316 }
2317 
2318 /*--.. Operations on instructions ..........................................--*/
2319 
2321  return wrap(unwrap<Instruction>(Inst)->getParent());
2322 }
2323 
2325  BasicBlock *Block = unwrap(BB);
2326  BasicBlock::iterator I = Block->begin();
2327  if (I == Block->end())
2328  return nullptr;
2329  return wrap(&*I);
2330 }
2331 
2333  BasicBlock *Block = unwrap(BB);
2334  BasicBlock::iterator I = Block->end();
2335  if (I == Block->begin())
2336  return nullptr;
2337  return wrap(&*--I);
2338 }
2339 
2341  Instruction *Instr = unwrap<Instruction>(Inst);
2342  BasicBlock::iterator I(Instr);
2343  if (++I == Instr->getParent()->end())
2344  return nullptr;
2345  return wrap(&*I);
2346 }
2347 
2349  Instruction *Instr = unwrap<Instruction>(Inst);
2350  BasicBlock::iterator I(Instr);
2351  if (I == Instr->getParent()->begin())
2352  return nullptr;
2353  return wrap(&*--I);
2354 }
2355 
2357  unwrap<Instruction>(Inst)->removeFromParent();
2358 }
2359 
2361  unwrap<Instruction>(Inst)->eraseFromParent();
2362 }
2363 
2365  if (ICmpInst *I = dyn_cast<ICmpInst>(unwrap(Inst)))
2366  return (LLVMIntPredicate)I->getPredicate();
2367  if (ConstantExpr *CE = dyn_cast<ConstantExpr>(unwrap(Inst)))
2368  if (CE->getOpcode() == Instruction::ICmp)
2369  return (LLVMIntPredicate)CE->getPredicate();
2370  return (LLVMIntPredicate)0;
2371 }
2372 
2374  if (FCmpInst *I = dyn_cast<FCmpInst>(unwrap(Inst)))
2375  return (LLVMRealPredicate)I->getPredicate();
2376  if (ConstantExpr *CE = dyn_cast<ConstantExpr>(unwrap(Inst)))
2377  if (CE->getOpcode() == Instruction::FCmp)
2378  return (LLVMRealPredicate)CE->getPredicate();
2379  return (LLVMRealPredicate)0;
2380 }
2381 
2383  if (Instruction *C = dyn_cast<Instruction>(unwrap(Inst)))
2384  return map_to_llvmopcode(C->getOpcode());
2385  return (LLVMOpcode)0;
2386 }
2387 
2389  if (Instruction *C = dyn_cast<Instruction>(unwrap(Inst)))
2390  return wrap(C->clone());
2391  return nullptr;
2392 }
2393 
2395  if (FuncletPadInst *FPI = dyn_cast<FuncletPadInst>(unwrap(Instr))) {
2396  return FPI->getNumArgOperands();
2397  }
2398  return CallSite(unwrap<Instruction>(Instr)).getNumArgOperands();
2399 }
2400 
2401 /*--.. Call and invoke instructions ........................................--*/
2402 
2404  return CallSite(unwrap<Instruction>(Instr)).getCallingConv();
2405 }
2406 
2407 void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC) {
2408  return CallSite(unwrap<Instruction>(Instr))
2409  .setCallingConv(static_cast<CallingConv::ID>(CC));
2410 }
2411 
2412 void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
2413  unsigned align) {
2414  CallSite Call = CallSite(unwrap<Instruction>(Instr));
2415  Attribute AlignAttr = Attribute::getWithAlignment(Call->getContext(), align);
2416  Call.addAttribute(index, AlignAttr);
2417 }
2418 
2420  LLVMAttributeRef A) {
2421  CallSite(unwrap<Instruction>(C)).addAttribute(Idx, unwrap(A));
2422 }
2423 
2425  LLVMAttributeIndex Idx) {
2426  auto CS = CallSite(unwrap<Instruction>(C));
2427  auto AS = CS.getAttributes().getAttributes(Idx);
2428  return AS.getNumAttributes();
2429 }
2430 
2433  auto CS = CallSite(unwrap<Instruction>(C));
2434  auto AS = CS.getAttributes().getAttributes(Idx);
2435  for (auto A : AS)
2436  *Attrs++ = wrap(A);
2437 }
2438 
2440  LLVMAttributeIndex Idx,
2441  unsigned KindID) {
2442  return wrap(CallSite(unwrap<Instruction>(C))
2443  .getAttribute(Idx, (Attribute::AttrKind)KindID));
2444 }
2445 
2447  LLVMAttributeIndex Idx,
2448  const char *K, unsigned KLen) {
2449  return wrap(CallSite(unwrap<Instruction>(C))
2450  .getAttribute(Idx, StringRef(K, KLen)));
2451 }
2452 
2454  unsigned KindID) {
2455  CallSite(unwrap<Instruction>(C))
2456  .removeAttribute(Idx, (Attribute::AttrKind)KindID);
2457 }
2458 
2460  const char *K, unsigned KLen) {
2461  CallSite(unwrap<Instruction>(C)).removeAttribute(Idx, StringRef(K, KLen));
2462 }
2463 
2465  return wrap(CallSite(unwrap<Instruction>(Instr)).getCalledValue());
2466 }
2467 
2468 /*--.. Operations on call instructions (only) ..............................--*/
2469 
2471  return unwrap<CallInst>(Call)->isTailCall();
2472 }
2473 
2474 void LLVMSetTailCall(LLVMValueRef Call, LLVMBool isTailCall) {
2475  unwrap<CallInst>(Call)->setTailCall(isTailCall);
2476 }
2477 
2478 /*--.. Operations on invoke instructions (only) ............................--*/
2479 
2481  return wrap(unwrap<InvokeInst>(Invoke)->getNormalDest());
2482 }
2483 
2485  if (CleanupReturnInst *CRI = dyn_cast<CleanupReturnInst>(unwrap(Invoke))) {
2486  return wrap(CRI->getUnwindDest());
2487  } else if (CatchSwitchInst *CSI = dyn_cast<CatchSwitchInst>(unwrap(Invoke))) {
2488  return wrap(CSI->getUnwindDest());
2489  }
2490  return wrap(unwrap<InvokeInst>(Invoke)->getUnwindDest());
2491 }
2492 
2494  unwrap<InvokeInst>(Invoke)->setNormalDest(unwrap(B));
2495 }
2496 
2498  if (CleanupReturnInst *CRI = dyn_cast<CleanupReturnInst>(unwrap(Invoke))) {
2499  return CRI->setUnwindDest(unwrap(B));
2500  } else if (CatchSwitchInst *CSI = dyn_cast<CatchSwitchInst>(unwrap(Invoke))) {
2501  return CSI->setUnwindDest(unwrap(B));
2502  }
2503  unwrap<InvokeInst>(Invoke)->setUnwindDest(unwrap(B));
2504 }
2505 
2506 /*--.. Operations on terminators ...........................................--*/
2507 
2509  return unwrap<TerminatorInst>(Term)->getNumSuccessors();
2510 }
2511 
2513  return wrap(unwrap<TerminatorInst>(Term)->getSuccessor(i));
2514 }
2515 
2516 void LLVMSetSuccessor(LLVMValueRef Term, unsigned i, LLVMBasicBlockRef block) {
2517  return unwrap<TerminatorInst>(Term)->setSuccessor(i,unwrap(block));
2518 }
2519 
2520 /*--.. Operations on branch instructions (only) ............................--*/
2521 
2523  return unwrap<BranchInst>(Branch)->isConditional();
2524 }
2525 
2527  return wrap(unwrap<BranchInst>(Branch)->getCondition());
2528 }
2529 
2531  return unwrap<BranchInst>(Branch)->setCondition(unwrap(Cond));
2532 }
2533 
2534 /*--.. Operations on switch instructions (only) ............................--*/
2535 
2537  return wrap(unwrap<SwitchInst>(Switch)->getDefaultDest());
2538 }
2539 
2540 /*--.. Operations on alloca instructions (only) ............................--*/
2541 
2543  return wrap(unwrap<AllocaInst>(Alloca)->getAllocatedType());
2544 }
2545 
2546 /*--.. Operations on gep instructions (only) ...............................--*/
2547 
2549  return unwrap<GetElementPtrInst>(GEP)->isInBounds();
2550 }
2551 
2553  return unwrap<GetElementPtrInst>(GEP)->setIsInBounds(InBounds);
2554 }
2555 
2556 /*--.. Operations on phi nodes .............................................--*/
2557 
2558 void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
2559  LLVMBasicBlockRef *IncomingBlocks, unsigned Count) {
2560  PHINode *PhiVal = unwrap<PHINode>(PhiNode);
2561  for (unsigned I = 0; I != Count; ++I)
2562  PhiVal->addIncoming(unwrap(IncomingValues[I]), unwrap(IncomingBlocks[I]));
2563 }
2564 
2565 unsigned LLVMCountIncoming(LLVMValueRef PhiNode) {
2566  return unwrap<PHINode>(PhiNode)->getNumIncomingValues();
2567 }
2568 
2570  return wrap(unwrap<PHINode>(PhiNode)->getIncomingValue(Index));
2571 }
2572 
2574  return wrap(unwrap<PHINode>(PhiNode)->getIncomingBlock(Index));
2575 }
2576 
2577 /*--.. Operations on extractvalue and insertvalue nodes ....................--*/
2578 
2580  auto *I = unwrap(Inst);
2581  if (auto *GEP = dyn_cast<GetElementPtrInst>(I))
2582  return GEP->getNumIndices();
2583  if (auto *EV = dyn_cast<ExtractValueInst>(I))
2584  return EV->getNumIndices();
2585  if (auto *IV = dyn_cast<InsertValueInst>(I))
2586  return IV->getNumIndices();
2588  "LLVMGetNumIndices applies only to extractvalue and insertvalue!");
2589 }
2590 
2591 const unsigned *LLVMGetIndices(LLVMValueRef Inst) {
2592  auto *I = unwrap(Inst);
2593  if (auto *EV = dyn_cast<ExtractValueInst>(I))
2594  return EV->getIndices().data();
2595  if (auto *IV = dyn_cast<InsertValueInst>(I))
2596  return IV->getIndices().data();
2598  "LLVMGetIndices applies only to extractvalue and insertvalue!");
2599 }
2600 
2601 
2602 /*===-- Instruction builders ----------------------------------------------===*/
2603 
2605  return wrap(new IRBuilder<>(*unwrap(C)));
2606 }
2607 
2610 }
2611 
2613  LLVMValueRef Instr) {
2614  BasicBlock *BB = unwrap(Block);
2615  auto I = Instr ? unwrap<Instruction>(Instr)->getIterator() : BB->end();
2616  unwrap(Builder)->SetInsertPoint(BB, I);
2617 }
2618 
2620  Instruction *I = unwrap<Instruction>(Instr);
2621  unwrap(Builder)->SetInsertPoint(I->getParent(), I->getIterator());
2622 }
2623 
2625  BasicBlock *BB = unwrap(Block);
2626  unwrap(Builder)->SetInsertPoint(BB);
2627 }
2628 
2630  return wrap(unwrap(Builder)->GetInsertBlock());
2631 }
2632 
2634  unwrap(Builder)->ClearInsertionPoint();
2635 }
2636 
2638  unwrap(Builder)->Insert(unwrap<Instruction>(Instr));
2639 }
2640 
2642  const char *Name) {
2643  unwrap(Builder)->Insert(unwrap<Instruction>(Instr), Name);
2644 }
2645 
2647  delete unwrap(Builder);
2648 }
2649 
2650 /*--.. Metadata builders ...................................................--*/
2651 
2653  MDNode *Loc =
2654  L ? cast<MDNode>(unwrap<MetadataAsValue>(L)->getMetadata()) : nullptr;
2655  unwrap(Builder)->SetCurrentDebugLocation(DebugLoc(Loc));
2656 }
2657 
2659  LLVMContext &Context = unwrap(Builder)->getContext();
2660  return wrap(MetadataAsValue::get(
2661  Context, unwrap(Builder)->getCurrentDebugLocation().getAsMDNode()));
2662 }
2663 
2665  unwrap(Builder)->SetInstDebugLocation(unwrap<Instruction>(Inst));
2666 }
2667 
2668 
2669 /*--.. Instruction builders ................................................--*/
2670 
2672  return wrap(unwrap(B)->CreateRetVoid());
2673 }
2674 
2676  return wrap(unwrap(B)->CreateRet(unwrap(V)));
2677 }
2678 
2680  unsigned N) {
2681  return wrap(unwrap(B)->CreateAggregateRet(unwrap(RetVals), N));
2682 }
2683 
2685  return wrap(unwrap(B)->CreateBr(unwrap(Dest)));
2686 }
2687 
2689  LLVMBasicBlockRef Then, LLVMBasicBlockRef Else) {
2690  return wrap(unwrap(B)->CreateCondBr(unwrap(If), unwrap(Then), unwrap(Else)));
2691 }
2692 
2694  LLVMBasicBlockRef Else, unsigned NumCases) {
2695  return wrap(unwrap(B)->CreateSwitch(unwrap(V), unwrap(Else), NumCases));
2696 }
2697 
2699  unsigned NumDests) {
2700  return wrap(unwrap(B)->CreateIndirectBr(unwrap(Addr), NumDests));
2701 }
2702 
2704  LLVMValueRef *Args, unsigned NumArgs,
2706  const char *Name) {
2707  return wrap(unwrap(B)->CreateInvoke(unwrap(Fn), unwrap(Then), unwrap(Catch),
2708  makeArrayRef(unwrap(Args), NumArgs),
2709  Name));
2710 }
2711 
2713  LLVMValueRef PersFn, unsigned NumClauses,
2714  const char *Name) {
2715  // The personality used to live on the landingpad instruction, but now it
2716  // lives on the parent function. For compatibility, take the provided
2717  // personality and put it on the parent function.
2718  if (PersFn)
2719  unwrap(B)->GetInsertBlock()->getParent()->setPersonalityFn(
2720  cast<Function>(unwrap(PersFn)));
2721  return wrap(unwrap(B)->CreateLandingPad(unwrap(Ty), NumClauses, Name));
2722 }
2723 
2725  LLVMValueRef *Args, unsigned NumArgs,
2726  const char *Name) {
2727  return wrap(unwrap(B)->CreateCatchPad(unwrap(ParentPad),
2728  makeArrayRef(unwrap(Args), NumArgs),
2729  Name));
2730 }
2731 
2733  LLVMValueRef *Args, unsigned NumArgs,
2734  const char *Name) {
2735  if (ParentPad == nullptr) {
2736  Type *Ty = Type::getTokenTy(unwrap(B)->getContext());
2737  ParentPad = wrap(Constant::getNullValue(Ty));
2738  }
2739  return wrap(unwrap(B)->CreateCleanupPad(unwrap(ParentPad),
2740  makeArrayRef(unwrap(Args), NumArgs),
2741  Name));
2742 }
2743 
2745  return wrap(unwrap(B)->CreateResume(unwrap(Exn)));
2746 }
2747 
2749  LLVMBasicBlockRef UnwindBB,
2750  unsigned NumHandlers, const char *Name) {
2751  if (ParentPad == nullptr) {
2752  Type *Ty = Type::getTokenTy(unwrap(B)->getContext());
2753  ParentPad = wrap(Constant::getNullValue(Ty));
2754  }
2755  return wrap(unwrap(B)->CreateCatchSwitch(unwrap(ParentPad), unwrap(UnwindBB),
2756  NumHandlers, Name));
2757 }
2758 
2760  LLVMBasicBlockRef BB) {
2761  return wrap(unwrap(B)->CreateCatchRet(unwrap<CatchPadInst>(CatchPad),
2762  unwrap(BB)));
2763 }
2764 
2766  LLVMBasicBlockRef BB) {
2767  return wrap(unwrap(B)->CreateCleanupRet(unwrap<CleanupPadInst>(CatchPad),
2768  unwrap(BB)));
2769 }
2770 
2772  return wrap(unwrap(B)->CreateUnreachable());
2773 }
2774 
2776  LLVMBasicBlockRef Dest) {
2777  unwrap<SwitchInst>(Switch)->addCase(unwrap<ConstantInt>(OnVal), unwrap(Dest));
2778 }
2779 
2781  unwrap<IndirectBrInst>(IndirectBr)->addDestination(unwrap(Dest));
2782 }
2783 
2784 unsigned LLVMGetNumClauses(LLVMValueRef LandingPad) {
2785  return unwrap<LandingPadInst>(LandingPad)->getNumClauses();
2786 }
2787 
2788 LLVMValueRef LLVMGetClause(LLVMValueRef LandingPad, unsigned Idx) {
2789  return wrap(unwrap<LandingPadInst>(LandingPad)->getClause(Idx));
2790 }
2791 
2792 void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal) {
2793  unwrap<LandingPadInst>(LandingPad)->
2794  addClause(cast<Constant>(unwrap(ClauseVal)));
2795 }
2796 
2798  return unwrap<LandingPadInst>(LandingPad)->isCleanup();
2799 }
2800 
2801 void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val) {
2802  unwrap<LandingPadInst>(LandingPad)->setCleanup(Val);
2803 }
2804 
2806  unwrap<CatchSwitchInst>(CatchSwitch)->addHandler(unwrap(Dest));
2807 }
2808 
2809 unsigned LLVMGetNumHandlers(LLVMValueRef CatchSwitch) {
2810  return unwrap<CatchSwitchInst>(CatchSwitch)->getNumHandlers();
2811 }
2812 
2813 void LLVMGetHandlers(LLVMValueRef CatchSwitch, LLVMBasicBlockRef *Handlers) {
2814  CatchSwitchInst *CSI = unwrap<CatchSwitchInst>(CatchSwitch);
2816  E = CSI->handler_end(); I != E; ++I)
2817  *Handlers++ = wrap(*I);
2818 }
2819 
2821  return wrap(unwrap<CatchPadInst>(CatchPad)->getCatchSwitch());
2822 }
2823 
2825  unwrap<CatchPadInst>(CatchPad)
2826  ->setCatchSwitch(unwrap<CatchSwitchInst>(CatchSwitch));
2827 }
2828 
2829 /*--.. Funclets ...........................................................--*/
2830 
2832  return wrap(unwrap<FuncletPadInst>(Funclet)->getArgOperand(i));
2833 }
2834 
2835 void LLVMSetArgOperand(LLVMValueRef Funclet, unsigned i, LLVMValueRef value) {
2836  unwrap<FuncletPadInst>(Funclet)->setArgOperand(i, unwrap(value));
2837 }
2838 
2839 /*--.. Arithmetic ..........................................................--*/
2840 
2842  const char *Name) {
2843  return wrap(unwrap(B)->CreateAdd(unwrap(LHS), unwrap(RHS), Name));
2844 }
2845 
2847  const char *Name) {
2848  return wrap(unwrap(B)->CreateNSWAdd(unwrap(LHS), unwrap(RHS), Name));
2849 }
2850 
2852  const char *Name) {
2853  return wrap(unwrap(B)->CreateNUWAdd(unwrap(LHS), unwrap(RHS), Name));
2854 }
2855 
2857  const char *Name) {
2858  return wrap(unwrap(B)->CreateFAdd(unwrap(LHS), unwrap(RHS), Name));
2859 }
2860 
2862  const char *Name) {
2863  return wrap(unwrap(B)->CreateSub(unwrap(LHS), unwrap(RHS), Name));
2864 }
2865 
2867  const char *Name) {
2868  return wrap(unwrap(B)->CreateNSWSub(unwrap(LHS), unwrap(RHS), Name));
2869 }
2870 
2872  const char *Name) {
2873  return wrap(unwrap(B)->CreateNUWSub(unwrap(LHS), unwrap(RHS), Name));
2874 }
2875 
2877  const char *Name) {
2878  return wrap(unwrap(B)->CreateFSub(unwrap(LHS), unwrap(RHS), Name));
2879 }
2880 
2882  const char *Name) {
2883  return wrap(unwrap(B)->CreateMul(unwrap(LHS), unwrap(RHS), Name));
2884 }
2885 
2887  const char *Name) {
2888  return wrap(unwrap(B)->CreateNSWMul(unwrap(LHS), unwrap(RHS), Name));
2889 }
2890 
2892  const char *Name) {
2893  return wrap(unwrap(B)->CreateNUWMul(unwrap(LHS), unwrap(RHS), Name));
2894 }
2895 
2897  const char *Name) {
2898  return wrap(unwrap(B)->CreateFMul(unwrap(LHS), unwrap(RHS), Name));
2899 }
2900 
2902  const char *Name) {
2903  return wrap(unwrap(B)->CreateUDiv(unwrap(LHS), unwrap(RHS), Name));
2904 }
2905 
2907  LLVMValueRef RHS, const char *Name) {
2908  return wrap(unwrap(B)->CreateExactUDiv(unwrap(LHS), unwrap(RHS), Name));
2909 }
2910 
2912  const char *Name) {
2913  return wrap(unwrap(B)->CreateSDiv(unwrap(LHS), unwrap(RHS), Name));
2914 }
2915 
2917  LLVMValueRef RHS, const char *Name) {
2918  return wrap(unwrap(B)->CreateExactSDiv(unwrap(LHS), unwrap(RHS), Name));
2919 }
2920 
2922  const char *Name) {
2923  return wrap(unwrap(B)->CreateFDiv(unwrap(LHS), unwrap(RHS), Name));
2924 }
2925 
2927  const char *Name) {
2928  return wrap(unwrap(B)->CreateURem(unwrap(LHS), unwrap(RHS), Name));
2929 }
2930 
2932  const char *Name) {
2933  return wrap(unwrap(B)->CreateSRem(unwrap(LHS), unwrap(RHS), Name));
2934 }
2935 
2937  const char *Name) {
2938  return wrap(unwrap(B)->CreateFRem(unwrap(LHS), unwrap(RHS), Name));
2939 }
2940 
2942  const char *Name) {
2943  return wrap(unwrap(B)->CreateShl(unwrap(LHS), unwrap(RHS), Name));
2944 }
2945 
2947  const char *Name) {
2948  return wrap(unwrap(B)->CreateLShr(unwrap(LHS), unwrap(RHS), Name));
2949 }
2950 
2952  const char *Name) {
2953  return wrap(unwrap(B)->CreateAShr(unwrap(LHS), unwrap(RHS), Name));
2954 }
2955 
2957  const char *Name) {
2958  return wrap(unwrap(B)->CreateAnd(unwrap(LHS), unwrap(RHS), Name));
2959 }
2960 
2962  const char *Name) {
2963  return wrap(unwrap(B)->CreateOr(unwrap(LHS), unwrap(RHS), Name));
2964 }
2965 
2967  const char *Name) {
2968  return wrap(unwrap(B)->CreateXor(unwrap(LHS), unwrap(RHS), Name));
2969 }
2970 
2972  LLVMValueRef LHS, LLVMValueRef RHS,
2973  const char *Name) {
2974  return wrap(unwrap(B)->CreateBinOp(Instruction::BinaryOps(map_from_llvmopcode(Op)), unwrap(LHS),
2975  unwrap(RHS), Name));
2976 }
2977 
2979  return wrap(unwrap(B)->CreateNeg(unwrap(V), Name));
2980 }
2981 
2983  const char *Name) {
2984  return wrap(unwrap(B)->CreateNSWNeg(unwrap(V), Name));
2985 }
2986 
2988  const char *Name) {
2989  return wrap(unwrap(B)->CreateNUWNeg(unwrap(V), Name));
2990 }
2991 
2993  return wrap(unwrap(B)->CreateFNeg(unwrap(V), Name));
2994 }
2995 
2997  return wrap(unwrap(B)->CreateNot(unwrap(V), Name));
2998 }
2999 
3000 /*--.. Memory ..............................................................--*/
3001 
3003  const char *Name) {
3004  Type* ITy = Type::getInt32Ty(unwrap(B)->GetInsertBlock()->getContext());
3005  Constant* AllocSize = ConstantExpr::getSizeOf(unwrap(Ty));
3006  AllocSize = ConstantExpr::getTruncOrBitCast(AllocSize, ITy);
3007  Instruction* Malloc = CallInst::CreateMalloc(unwrap(B)->GetInsertBlock(),
3008  ITy, unwrap(Ty), AllocSize,
3009  nullptr, nullptr, "");
3010  return wrap(unwrap(B)->Insert(Malloc, Twine(Name)));
3011 }
3012 
3014  LLVMValueRef Val, const char *Name) {
3015  Type* ITy = Type::getInt32Ty(unwrap(B)->GetInsertBlock()->getContext());
3016  Constant* AllocSize = ConstantExpr::getSizeOf(unwrap(Ty));
3017  AllocSize = ConstantExpr::getTruncOrBitCast(AllocSize, ITy);
3018  Instruction* Malloc = CallInst::CreateMalloc(unwrap(B)->GetInsertBlock(),
3019  ITy, unwrap(Ty), AllocSize,
3020  unwrap(Val), nullptr, "");
3021  return wrap(unwrap(B)->Insert(Malloc, Twine(Name)));
3022 }
3023 
3025  const char *Name) {
3026  return wrap(unwrap(B)->CreateAlloca(unwrap(Ty), nullptr, Name));
3027 }
3028 
3030  LLVMValueRef Val, const char *Name) {
3031  return wrap(unwrap(B)->CreateAlloca(unwrap(Ty), unwrap(Val), Name));
3032 }
3033 
3035  return wrap(unwrap(B)->Insert(
3036  CallInst::CreateFree(unwrap(PointerVal), unwrap(B)->GetInsertBlock())));
3037 }
3038 
3040  const char *Name) {
3041  return wrap(unwrap(B)->CreateLoad(unwrap(PointerVal), Name));
3042 }
3043 
3045  LLVMValueRef PointerVal) {
3046  return wrap(unwrap(B)->CreateStore(unwrap(Val), unwrap(PointerVal)));
3047 }
3048 
3050  switch (Ordering) {
3060  }
3061 
3062  llvm_unreachable("Invalid LLVMAtomicOrdering value!");
3063 }
3064 
3066  switch (Ordering) {
3076  }
3077 
3078  llvm_unreachable("Invalid AtomicOrdering value!");
3079 }
3080 
3081 // TODO: Should this and other atomic instructions support building with
3082 // "syncscope"?
3084  LLVMBool isSingleThread, const char *Name) {
3085  return wrap(
3086  unwrap(B)->CreateFence(mapFromLLVMOrdering(Ordering),
3087  isSingleThread ? SyncScope::SingleThread
3089  Name));
3090 }
3091 
3093  LLVMValueRef *Indices, unsigned NumIndices,
3094  const char *Name) {
3095  ArrayRef<Value *> IdxList(unwrap(Indices), NumIndices);
3096  return wrap(unwrap(B)->CreateGEP(nullptr, unwrap(Pointer), IdxList, Name));
3097 }
3098 
3100  LLVMValueRef *Indices, unsigned NumIndices,
3101  const char *Name) {
3102  ArrayRef<Value *> IdxList(unwrap(Indices), NumIndices);
3103  return wrap(
3104  unwrap(B)->CreateInBoundsGEP(nullptr, unwrap(Pointer), IdxList, Name));
3105 }
3106 
3108  unsigned Idx, const char *Name) {
3109  return wrap(unwrap(B)->CreateStructGEP(nullptr, unwrap(Pointer), Idx, Name));
3110 }
3111 
3113  const char *Name) {
3114  return wrap(unwrap(B)->CreateGlobalString(Str, Name));
3115 }
3116 
3118  const char *Name) {
3119  return wrap(unwrap(B)->CreateGlobalStringPtr(Str, Name));
3120 }
3121 
3123  Value *P = unwrap<Value>(MemAccessInst);
3124  if (LoadInst *LI = dyn_cast<LoadInst>(P))
3125  return LI->isVolatile();
3126  return cast<StoreInst>(P)->isVolatile();
3127 }
3128 
3130  Value *P = unwrap<Value>(MemAccessInst);
3131  if (LoadInst *LI = dyn_cast<LoadInst>(P))
3132  return LI->setVolatile(isVolatile);
3133  return cast<StoreInst>(P)->setVolatile(isVolatile);
3134 }
3135 
3137  Value *P = unwrap<Value>(MemAccessInst);
3138  AtomicOrdering O;
3139  if (LoadInst *LI = dyn_cast<LoadInst>(P))
3140  O = LI->getOrdering();
3141  else
3142  O = cast<StoreInst>(P)->getOrdering();
3143  return mapToLLVMOrdering(O);
3144 }
3145 
3146 void LLVMSetOrdering(LLVMValueRef MemAccessInst, LLVMAtomicOrdering Ordering) {
3147  Value *P = unwrap<Value>(MemAccessInst);
3148  AtomicOrdering O = mapFromLLVMOrdering(Ordering);
3149 
3150  if (LoadInst *LI = dyn_cast<LoadInst>(P))
3151  return LI->setOrdering(O);
3152  return cast<StoreInst>(P)->setOrdering(O);
3153 }
3154 
3155 /*--.. Casts ...............................................................--*/
3156 
3158  LLVMTypeRef DestTy, const char *Name) {
3159  return wrap(unwrap(B)->CreateTrunc(unwrap(Val), unwrap(DestTy), Name));
3160 }
3161 
3163  LLVMTypeRef DestTy, const char *Name) {
3164  return wrap(unwrap(B)->CreateZExt(unwrap(Val), unwrap(DestTy), Name));
3165 }
3166 
3168  LLVMTypeRef DestTy, const char *Name) {
3169  return wrap(unwrap(B)->CreateSExt(unwrap(Val), unwrap(DestTy), Name));
3170 }
3171 
3173  LLVMTypeRef DestTy, const char *Name) {
3174  return wrap(unwrap(B)->CreateFPToUI(unwrap(Val), unwrap(DestTy), Name));
3175 }
3176 
3178  LLVMTypeRef DestTy, const char *Name) {
3179  return wrap(unwrap(B)->CreateFPToSI(unwrap(Val), unwrap(DestTy), Name));
3180 }
3181 
3183  LLVMTypeRef DestTy, const char *Name) {
3184  return wrap(unwrap(B)->CreateUIToFP(unwrap(Val), unwrap(DestTy), Name));
3185 }
3186 
3188  LLVMTypeRef DestTy, const char *Name) {
3189  return wrap(unwrap(B)->CreateSIToFP(unwrap(Val), unwrap(DestTy), Name));
3190 }
3191 
3193  LLVMTypeRef DestTy, const char *Name) {
3194  return wrap(unwrap(B)->CreateFPTrunc(unwrap(Val), unwrap(DestTy), Name));
3195 }
3196 
3198  LLVMTypeRef DestTy, const char *Name) {
3199  return wrap(unwrap(B)->CreateFPExt(unwrap(Val), unwrap(DestTy), Name));
3200 }
3201 
3203  LLVMTypeRef DestTy, const char *Name) {
3204  return wrap(unwrap(B)->CreatePtrToInt(unwrap(Val), unwrap(DestTy), Name));
3205 }
3206 
3208  LLVMTypeRef DestTy, const char *Name) {
3209  return wrap(unwrap(B)->CreateIntToPtr(unwrap(Val), unwrap(DestTy), Name));
3210 }
3211 
3213  LLVMTypeRef DestTy, const char *Name) {
3214  return wrap(unwrap(B)->CreateBitCast(unwrap(Val), unwrap(DestTy), Name));
3215 }
3216 
3218  LLVMTypeRef DestTy, const char *Name) {
3219  return wrap(unwrap(B)->CreateAddrSpaceCast(unwrap(Val), unwrap(DestTy), Name));
3220 }
3221 
3223  LLVMTypeRef DestTy, const char *Name) {
3224  return wrap(unwrap(B)->CreateZExtOrBitCast(unwrap(Val), unwrap(DestTy),
3225  Name));
3226 }
3227 
3229  LLVMTypeRef DestTy, const char *Name) {
3230  return wrap(unwrap(B)->CreateSExtOrBitCast(unwrap(Val), unwrap(DestTy),
3231  Name));
3232 }
3233 
3235  LLVMTypeRef DestTy, const char *Name) {
3236  return wrap(unwrap(B)->CreateTruncOrBitCast(unwrap(Val), unwrap(DestTy),
3237  Name));
3238 }
3239 
3241  LLVMTypeRef DestTy, const char *Name) {
3242  return wrap(unwrap(B)->CreateCast(Instruction::CastOps(map_from_llvmopcode(Op)), unwrap(Val),
3243  unwrap(DestTy), Name));
3244 }
3245 
3247  LLVMTypeRef DestTy, const char *Name) {
3248  return wrap(unwrap(B)->CreatePointerCast(unwrap(Val), unwrap(DestTy), Name));
3249 }
3250 
3252  LLVMTypeRef DestTy, const char *Name) {
3253  return wrap(unwrap(B)->CreateIntCast(unwrap(Val), unwrap(DestTy),
3254  /*isSigned*/true, Name));
3255 }
3256 
3258  LLVMTypeRef DestTy, const char *Name) {
3259  return wrap(unwrap(B)->CreateFPCast(unwrap(Val), unwrap(DestTy), Name));
3260 }
3261 
3262 /*--.. Comparisons .........................................................--*/
3263 
3265  LLVMValueRef LHS, LLVMValueRef RHS,
3266  const char *Name) {
3267  return wrap(unwrap(B)->CreateICmp(static_cast<ICmpInst::Predicate>(Op),
3268  unwrap(LHS), unwrap(RHS), Name));
3269 }
3270 
3272  LLVMValueRef LHS, LLVMValueRef RHS,
3273  const char *Name) {
3274  return wrap(unwrap(B)->CreateFCmp(static_cast<FCmpInst::Predicate>(Op),
3275  unwrap(LHS), unwrap(RHS), Name));
3276 }
3277 
3278 /*--.. Miscellaneous instructions ..........................................--*/
3279 
3281  return wrap(unwrap(B)->CreatePHI(unwrap(Ty), 0, Name));
3282 }
3283 
3285  LLVMValueRef *Args, unsigned NumArgs,
3286  const char *Name) {
3287  return wrap(unwrap(B)->CreateCall(unwrap(Fn),
3288  makeArrayRef(unwrap(Args), NumArgs),
3289  Name));
3290 }
3291 
3293  LLVMValueRef Then, LLVMValueRef Else,
3294  const char *Name) {
3295  return wrap(unwrap(B)->CreateSelect(unwrap(If), unwrap(Then), unwrap(Else),
3296  Name));
3297 }
3298 
3300  LLVMTypeRef Ty, const char *Name) {
3301  return wrap(unwrap(B)->CreateVAArg(unwrap(List), unwrap(Ty), Name));
3302 }
3303 
3305  LLVMValueRef Index, const char *Name) {
3306  return wrap(unwrap(B)->CreateExtractElement(unwrap(VecVal), unwrap(Index),
3307  Name));
3308 }
3309 
3312  const char *Name) {
3313  return wrap(unwrap(B)->CreateInsertElement(unwrap(VecVal), unwrap(EltVal),
3314  unwrap(Index), Name));
3315 }
3316 
3319  const char *Name) {
3320  return wrap(unwrap(B)->CreateShuffleVector(unwrap(V1), unwrap(V2),
3321  unwrap(Mask), Name));
3322 }
3323 
3325  unsigned Index, const char *Name) {
3326  return wrap(unwrap(B)->CreateExtractValue(unwrap(AggVal), Index, Name));
3327 }
3328 
3330  LLVMValueRef EltVal, unsigned Index,
3331  const char *Name) {
3332  return wrap(unwrap(B)->CreateInsertValue(unwrap(AggVal), unwrap(EltVal),
3333  Index, Name));
3334 }
3335 
3337  const char *Name) {
3338  return wrap(unwrap(B)->CreateIsNull(unwrap(Val), Name));
3339 }
3340 
3342  const char *Name) {
3343  return wrap(unwrap(B)->CreateIsNotNull(unwrap(Val), Name));
3344 }
3345 
3347  LLVMValueRef RHS, const char *Name) {
3348  return wrap(unwrap(B)->CreatePtrDiff(unwrap(LHS), unwrap(RHS), Name));
3349 }
3350 
3352  LLVMValueRef PTR, LLVMValueRef Val,
3353  LLVMAtomicOrdering ordering,
3354  LLVMBool singleThread) {
3355  AtomicRMWInst::BinOp intop;
3356  switch (op) {
3357  case LLVMAtomicRMWBinOpXchg: intop = AtomicRMWInst::Xchg; break;
3358  case LLVMAtomicRMWBinOpAdd: intop = AtomicRMWInst::Add; break;
3359  case LLVMAtomicRMWBinOpSub: intop = AtomicRMWInst::Sub; break;
3360  case LLVMAtomicRMWBinOpAnd: intop = AtomicRMWInst::And; break;
3361  case LLVMAtomicRMWBinOpNand: intop = AtomicRMWInst::Nand; break;
3362  case LLVMAtomicRMWBinOpOr: intop = AtomicRMWInst::Or; break;
3363  case LLVMAtomicRMWBinOpXor: intop = AtomicRMWInst::Xor; break;
3364  case LLVMAtomicRMWBinOpMax: intop = AtomicRMWInst::Max; break;
3365  case LLVMAtomicRMWBinOpMin: intop = AtomicRMWInst::Min; break;
3366  case LLVMAtomicRMWBinOpUMax: intop = AtomicRMWInst::UMax; break;
3367  case LLVMAtomicRMWBinOpUMin: intop = AtomicRMWInst::UMin; break;
3368  }
3369  return wrap(unwrap(B)->CreateAtomicRMW(intop, unwrap(PTR), unwrap(Val),
3370  mapFromLLVMOrdering(ordering), singleThread ? SyncScope::SingleThread
3371  : SyncScope::System));
3372 }
3373 
3375  LLVMValueRef Cmp, LLVMValueRef New,
3376  LLVMAtomicOrdering SuccessOrdering,
3377  LLVMAtomicOrdering FailureOrdering,
3378  LLVMBool singleThread) {
3379 
3380  return wrap(unwrap(B)->CreateAtomicCmpXchg(unwrap(Ptr), unwrap(Cmp),
3381  unwrap(New), mapFromLLVMOrdering(SuccessOrdering),
3382  mapFromLLVMOrdering(FailureOrdering),
3383  singleThread ? SyncScope::SingleThread : SyncScope::System));
3384 }
3385 
3386 
3388  Value *P = unwrap<Value>(AtomicInst);
3389 
3390  if (AtomicRMWInst *I = dyn_cast<AtomicRMWInst>(P))
3391  return I->getSyncScopeID() == SyncScope::SingleThread;
3392  return cast<AtomicCmpXchgInst>(P)->getSyncScopeID() ==
3394 }
3395 
3397  Value *P = unwrap<Value>(AtomicInst);
3399 
3400  if (AtomicRMWInst *I = dyn_cast<AtomicRMWInst>(P))
3401  return I->setSyncScopeID(SSID);
3402  return cast<AtomicCmpXchgInst>(P)->setSyncScopeID(SSID);
3403 }
3404 
3406  Value *P = unwrap<Value>(CmpXchgInst);
3407  return mapToLLVMOrdering(cast<AtomicCmpXchgInst>(P)->getSuccessOrdering());
3408 }
3409 
3411  LLVMAtomicOrdering Ordering) {
3412  Value *P = unwrap<Value>(CmpXchgInst);
3413  AtomicOrdering O = mapFromLLVMOrdering(Ordering);
3414 
3415  return cast<AtomicCmpXchgInst>(P)->setSuccessOrdering(O);
3416 }
3417 
3419  Value *P = unwrap<Value>(CmpXchgInst);
3420  return mapToLLVMOrdering(cast<AtomicCmpXchgInst>(P)->getFailureOrdering());
3421 }
3422 
3424  LLVMAtomicOrdering Ordering) {
3425  Value *P = unwrap<Value>(CmpXchgInst);
3426  AtomicOrdering O = mapFromLLVMOrdering(Ordering);
3427 
3428  return cast<AtomicCmpXchgInst>(P)->setFailureOrdering(O);
3429 }
3430 
3431 /*===-- Module providers --------------------------------------------------===*/
3432 
3435  return reinterpret_cast<LLVMModuleProviderRef>(M);
3436 }
3437 
3439  delete unwrap(MP);
3440 }
3441 
3442 
3443 /*===-- Memory buffers ----------------------------------------------------===*/
3444 
3446  const char *Path,
3447  LLVMMemoryBufferRef *OutMemBuf,
3448  char **OutMessage) {
3449 
3451  if (std::error_code EC = MBOrErr.getError()) {
3452  *OutMessage = strdup(EC.message().c_str());
3453  return 1;
3454  }
3455  *OutMemBuf = wrap(MBOrErr.get().release());
3456  return 0;
3457 }
3458 
3460  char **OutMessage) {
3462  if (std::error_code EC = MBOrErr.getError()) {
3463  *OutMessage = strdup(EC.message().c_str());
3464  return 1;
3465  }
3466  *OutMemBuf = wrap(MBOrErr.get().release());
3467  return 0;
3468 }
3469 
3471  const char *InputData,
3472  size_t InputDataLength,
3473  const char *BufferName,
3474  LLVMBool RequiresNullTerminator) {
3475 
3476  return wrap(MemoryBuffer::getMemBuffer(StringRef(InputData, InputDataLength),
3477  StringRef(BufferName),
3478  RequiresNullTerminator).release());
3479 }
3480 
3482  const char *InputData,
3483  size_t InputDataLength,
3484  const char *BufferName) {
3485 
3486  return wrap(
3487  MemoryBuffer::getMemBufferCopy(StringRef(InputData, InputDataLength),
3488  StringRef(BufferName)).release());
3489 }
3490 
3492  return unwrap(MemBuf)->getBufferStart();
3493 }
3494 
3496  return unwrap(MemBuf)->getBufferSize();
3497 }
3498 
3500  delete unwrap(MemBuf);
3501 }
3502 
3503 /*===-- Pass Registry -----------------------------------------------------===*/
3504 
3507 }
3508 
3509 /*===-- Pass Manager ------------------------------------------------------===*/
3510 
3512  return wrap(new legacy::PassManager());
3513 }
3514 
3516  return wrap(new legacy::FunctionPassManager(unwrap(M)));
3517 }
3518 
3521  reinterpret_cast<LLVMModuleRef>(P));
3522 }
3523 
3525  return unwrap<legacy::PassManager>(PM)->run(*unwrap(M));
3526 }
3527 
3529  return unwrap<legacy::FunctionPassManager>(FPM)->doInitialization();
3530 }
3531 
3533  return unwrap<legacy::FunctionPassManager>(FPM)->run(*unwrap<Function>(F));
3534 }
3535 
3537  return unwrap<legacy::FunctionPassManager>(FPM)->doFinalization();
3538 }
3539 
3541  delete unwrap(PM);
3542 }
3543 
3544 /*===-- Threading ------------------------------------------------------===*/
3545 
3547  return LLVMIsMultithreaded();
3548 }
3549 
3551 }
3552 
3554  return llvm_is_multithreaded();
3555 }
LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1382
LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty, const char *AsmString, const char *Constraints, LLVMBool HasSideEffects, LLVMBool IsAlignStack)
Deprecated: Use LLVMGetInlineAsm instead.
Definition: Core.cpp:1614
Subtract a value and return the old one.
Definition: Core.h:353
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:3491
static Constant * getFPTrunc(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:1646
void LLVMDisposeBuilder(LLVMBuilderRef Builder)
Definition: Core.cpp:2646
uint64_t CallInst * C
unsigned LLVMGetMDNodeNumOperands(LLVMValueRef V)
Obtain the number of operands from an MDNode value.
Definition: Core.cpp:1061
X86 MMX.
Definition: Core.h:156
Adds a requirement that another module flag be present and have a specified value after linking is pe...
Definition: Core.h:410
use_iterator use_end()
Definition: Value.h:346
LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy, LLVMValueRef *ConstantVals, unsigned Count)
Create a non-anonymous ConstantStruct from values.
Definition: Core.cpp:1229
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:2388
LLVMRealPredicate LLVMGetFCmpPredicate(LLVMValueRef Inst)
Obtain the float predicate of an instruction.
Definition: Core.cpp:2373
LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C, LLVMBasicBlockRef BBRef, const char *Name)
Insert a basic block in a function before another basic block.
Definition: Core.cpp:2290
Represents either an error or a value T.
Definition: ErrorOr.h:69
void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest)
Get the elements within a structure.
Definition: Core.cpp:689
void LLVMGetParams(LLVMValueRef FnRef, LLVMValueRef *ParamRefs)
Obtain the parameters in a function.
Definition: Core.cpp:2156
LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar)
Definition: Core.cpp:1883
LLVMValueRef LLVMBuildICmp(LLVMBuilderRef B, LLVMIntPredicate Op, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:3264
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:2478
void LLVMGetHandlers(LLVMValueRef CatchSwitch, LLVMBasicBlockRef *Handlers)
Obtain the basic blocks acting as handlers for a catchswitch instruction.
Definition: Core.cpp:2813
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:3423
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:750
static Constant * getFAdd(Constant *C1, Constant *C2)
Definition: Constants.cpp:2183
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:2061
*p = old <signed v ? old : v
Definition: Instructions.h:707
LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef B, LLVMTypeRef Ty, LLVMValueRef Val, const char *Name)
Definition: Core.cpp:3029
LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1418
LLVMValueRef LLVMBuildZExt(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:3162
LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn)
Obtain the basic block that corresponds to the entry point of a function.
Definition: Core.cpp:2244
LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M)
Obtain an iterator to the last Function in a Module.
Definition: Core.cpp:2033
LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType)
Definition: Core.cpp:1524
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:355
LLVMValueRef LLVMBuildAtomicCmpXchg(LLVMBuilderRef B, LLVMValueRef Ptr, LLVMValueRef Cmp, LLVMValueRef New, LLVMAtomicOrdering SuccessOrdering, LLVMAtomicOrdering FailureOrdering, LLVMBool singleThread)
Definition: Core.cpp:3374
static AtomicOrdering mapFromLLVMOrdering(LLVMAtomicOrdering Ordering)
Definition: Core.cpp:3049
LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1366
Externally visible function.
Definition: Core.h:161
CallingConv::ID getCallingConv() const
Get the calling convention of the call.
Definition: CallSite.h:312
SI Whole Quad Mode
LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty)
Whether the type has a known size.
Definition: Core.cpp:501
LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1377
void LLVMSetSection(LLVMValueRef Global, const char *Section)
Definition: Core.cpp:1736
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:805
unsigned LLVMAttributeIndex
Definition: Core.h:447
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
Compute iterated dominance frontiers using a linear time algorithm.
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:3481
LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count)
Obtain a MDNode value from the global context.
Definition: Core.cpp:1034
provides both an Acquire and a Release barrier (for fences and operations which both read and write m...
Definition: Core.h:336
const char * LLVMGetAsString(LLVMValueRef C, size_t *Length)
Get the given constant data sequential as a string.
Definition: Core.cpp:1203
LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index)
Obtain an incoming value to a PHI node as an LLVMValueRef.
Definition: Core.cpp:2569
static Constant * getNSWAdd(Constant *C1, Constant *C2)
Definition: Constants.h:973
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:63
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:1138
static MDNode * extractMDNode(MetadataAsValue *MAV)
Definition: Core.cpp:854
void LLVMSetSuccessor(LLVMValueRef Term, unsigned i, LLVMBasicBlockRef block)
Update the specified successor to point at the provided block.
Definition: Core.cpp:2516
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
Definition: SmallVector.h:137
LLVMValueRef LLVMBuildAdd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:2841
LLVMBuilderRef LLVMCreateBuilder(void)
Definition: Core.cpp:2608
Obsolete.
Definition: Core.h:174
LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg)
Obtain the next parameter to a function.
Definition: Core.cpp:2188
2: 32-bit floating point type
Definition: Type.h:59
iterator end()
Definition: Function.h:644
Same, but only replaced by something equivalent.
Definition: GlobalValue.h:54
LLVMModuleFlagBehavior Behavior
Definition: Core.cpp:271
LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:2851
static LLVMAtomicOrdering mapToLLVMOrdering(AtomicOrdering Ordering)
Definition: Core.cpp:3065
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:3107
LLVMAttributeRef LLVMGetEnumAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx, unsigned KindID)
Definition: Core.cpp:2118
LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name)
Definition: Core.cpp:1843
LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy)
Determine whether a structure is opaque.
Definition: Core.cpp:705
LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRange(const char *InputData, size_t InputDataLength, const char *BufferName, LLVMBool RequiresNullTerminator)
Definition: Core.cpp:3470
LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn)
Obtain the first parameter to a function.
Definition: Core.cpp:2172
void initializeSafepointIRVerifierPass(PassRegistry &)
void(*)(LLVMContext *Context, void *OpaqueHandle) YieldCallbackTy
Defines the type of a yield callback.
Definition: LLVMContext.h:175
LLVMValueRef LLVMGetNextGlobalAlias(LLVMValueRef GA)
Advance a GlobalAlias iterator to the next GlobalAlias.
Definition: Core.cpp:1989
LLVMValueRef LLVMBuildSExt(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:3167
LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee, const char *Name)
Definition: Core.cpp:1960
LLVMAttributeRef LLVMCreateStringAttribute(LLVMContextRef C, const char *K, unsigned KLength, const char *V, unsigned VLength)
Create a string attribute.
Definition: Core.cpp:150
LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty)
Definition: Core.cpp:1271
LLVMBool LLVMHasUnnamedAddr(LLVMValueRef Global)
Deprecated: Use LLVMGetUnnamedAddress instead.
Definition: Core.cpp:1785
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:3550
LLVMOpcode
Definition: Core.h:57
void LLVMSetValueName(LLVMValueRef Val, const char *Name)
Deprecated: Use LLVMSetValueName2 instead.
Definition: Core.cpp:813
static Constant * getAddrSpaceCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:1752
Metadata * getMetadata() const
Definition: Metadata.h:189
LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType)
Definition: Core.cpp:1504
Emits an error if two values disagree, otherwise the resulting value is that of the operands...
Definition: Core.h:391
void clearGC()
Definition: Function.cpp:461
const char * LLVMGetGC(LLVMValueRef Fn)
Obtain the name of the garbage collector to use during code generation.
Definition: Core.cpp:2088
LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef P)
Deprecated: Use LLVMCreateFunctionPassManagerForModule instead.
Definition: Core.cpp:3519
LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name)
Definition: Core.cpp:1829
LLVMTypeRef LLVMGetAllocatedType(LLVMValueRef Alloca)
Obtain the type that is being allocated by the alloca instruction.
Definition: Core.cpp:2542
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:602
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:2675
LLVMAttributeRef LLVMCreateEnumAttribute(LLVMContextRef C, unsigned KindID, uint64_t Val)
Create an enum attribute.
Definition: Core.cpp:134
LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB)
Advance a basic block iterator.
Definition: Core.cpp:2264
LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path, LLVMMemoryBufferRef *OutMemBuf, char **OutMessage)
Definition: Core.cpp:3445
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:3511
LLVMInlineAsmDialect
Definition: Core.h:379
void addOperand(MDNode *M)
Definition: Metadata.cpp:1087
LLVMTypeRef LLVMFP128Type(void)
Definition: Core.cpp:614
LLVMValueRef LLVMGetClause(LLVMValueRef LandingPad, unsigned Idx)
Definition: Core.cpp:2788
static Constant * getExactSDiv(Constant *C1, Constant *C2)
Definition: Constants.h:1005
void setGC(std::string Str)
Definition: Function.cpp:456
LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:3172
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:617
#define LLVM_FOR_EACH_VALUE_SUBCLASS(macro)
Definition: Core.h:1390
unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy)
Obtain the number of elements in a vector type.
Definition: Core.cpp:754
LLVMMetadataRef LLVMModuleFlagEntriesGetMetadata(LLVMModuleFlagEntry *Entries, unsigned Index)
Returns the metadata for a module flag entry at a specific index.
Definition: Core.cpp:353
LLVMDiagnosticSeverity LLVMGetDiagInfoSeverity(LLVMDiagnosticInfoRef DI)
Return an enum LLVMDiagnosticSeverity.
Definition: Core.cpp:191
*p = old <unsigned v ? old : v
Definition: Instructions.h:711
static Constant * getIntToPtr(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:1727
LLVMBool LLVMIsAtomicSingleThread(LLVMValueRef AtomicInst)
Definition: Core.cpp:3387
float convertToFloat() const
Definition: APFloat.h:1098
static Constant * getExtractElement(Constant *Vec, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
Definition: Constants.cpp:2041
const char * LLVMGetDataLayoutStr(LLVMModuleRef M)
Obtain the data layout for a module.
Definition: Core.cpp:248
LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef B, LLVMValueRef If, LLVMBasicBlockRef Then, LLVMBasicBlockRef Else)
Definition: Core.cpp:2688
Like Internal, but omit from symbol table.
Definition: GlobalValue.h:57
LLVMTypeRef LLVMX86MMXType(void)
Definition: Core.cpp:620
*p = old >unsigned v ? old : v
Definition: Instructions.h:709
Externally visible function.
Definition: GlobalValue.h:49
LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef B, LLVMValueRef V, const char *Name)
Definition: Core.cpp:2992
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:713
LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:3234
struct LLVMOpaquePassRegistry * LLVMPassRegistryRef
Definition: Types.h:117
unsigned LLVMGetNumArgOperands(LLVMValueRef Instr)
Obtain the argument count for a call instruction.
Definition: Core.cpp:2394
struct LLVMOpaqueBuilder * LLVMBuilderRef
Represents an LLVM basic block builder.
Definition: Types.h:97
LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:2911
arg_iterator arg_end()
Definition: Function.h:666
unsigned LLVMGetLastEnumAttributeKind(void)
Definition: Core.cpp:130
13: Structures
Definition: Type.h:73
LLVMTypeRef LLVMX86FP80Type(void)
Definition: Core.cpp:611
LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val)
Obtain the first use of a value.
Definition: Core.cpp:896
A debug info location.
Definition: DebugLoc.h:34
Metadata node.
Definition: Metadata.h:862
void LLVMClearInsertionPosition(LLVMBuilderRef Builder)
Definition: Core.cpp:2633
LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar)
Definition: Core.cpp:1863
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:731
LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1408
unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char *Name, unsigned SLen)
Definition: Core.cpp:114
LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void)
Return the global pass registry, for use with initialization functions.
Definition: Core.cpp:3505
const MDOperand & getOperand(unsigned I) const
Definition: Metadata.h:1067
LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:3240
LLVMValueRef LLVMBuildFRem(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:2936
param_iterator param_end() const
Definition: DerivedTypes.h:129
An instruction for reading from memory.
Definition: Instructions.h:164
LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition, LLVMValueRef ConstantIfTrue, LLVMValueRef ConstantIfFalse)
Definition: Core.cpp:1570
1: 16-bit floating point type
Definition: Type.h:58
LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType)
Definition: Core.cpp:1469
LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val)
Determine whether an LLVMValueRef is itself a basic block.
Definition: Core.cpp:2214
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:654
an instruction that atomically reads a memory location, combines it with another value, and then stores the result back.
Definition: Instructions.h:677
Appends the two values, which are required to be metadata nodes.
Definition: Core.h:432
Hexagon Common GEP
LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef BBRef, const char *Name)
Insert a basic block in a function using the global context.
Definition: Core.cpp:2297
int LLVMHasMetadata(LLVMValueRef Inst)
Determine whether an instruction has any metadata attached.
Definition: Core.cpp:839
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:2187
const char * LLVMGetSection(LLVMValueRef Global)
Definition: Core.cpp:1730
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:536
LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals, unsigned Count)
Obtain a MDNode value from a context.
Definition: Core.cpp:1007
LLVMTypeRef LLVMTokenTypeInContext(LLVMContextRef C)
Create a token type in a context.
Definition: Core.cpp:766
#define op(i)
LLVMValueRef LLVMBuildFence(LLVMBuilderRef B, LLVMAtomicOrdering Ordering, LLVMBool isSingleThread, const char *Name)
Definition: Core.cpp:3083
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:2125
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:1997
LLVMAtomicRMWBinOp
Definition: Core.h:350
12: Functions
Definition: Type.h:72
*p = old >signed v ? old : v
Definition: Instructions.h:705
LLVMValueRef LLVMConstAddrSpaceCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType)
Definition: Core.cpp:1529
Lowest level of atomicity, guarantees somewhat sane results, lock free.
Definition: Core.h:325
Appends the two values, which are required to be metadata nodes.
Definition: Core.h:424
std::error_code error() const
Definition: raw_ostream.h:440
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:110
static Constant * get(ArrayType *T, ArrayRef< Constant *> V)
Definition: Constants.cpp:950
128 bit floating point type (112-bit mantissa)
Definition: Core.h:146
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:365
void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant)
Definition: Core.cpp:1907
void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal)
Definition: Core.cpp:1899
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:233
static Constant * getInsertElement(Constant *Vec, Constant *Elt, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
Definition: Constants.cpp:2063
ExternalWeak linkage description.
Definition: Core.h:176
LLVMValueRef LLVMConstNull(LLVMTypeRef Ty)
Obtain a constant value referring to the null instance of a type.
Definition: Core.cpp:964
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:1136
LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:3246
static Constant * getNullValue(Type *Ty)
Constructor to create a &#39;0&#39; constant of arbitrary type.
Definition: Constants.cpp:258
LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM)
Initializes all of the function passes scheduled in the function pass manager.
Definition: Core.cpp:3528
void LLVMRemoveCallSiteStringAttribute(LLVMValueRef C, LLVMAttributeIndex Idx, const char *K, unsigned KLen)
Definition: Core.cpp:2459
void LLVMSetOperand(LLVMValueRef Val, unsigned Index, LLVMValueRef Op)
Set an operand at a specific index in a llvm::User value.
Definition: Core.cpp:950
iterator begin()
Instruction iterator methods.
Definition: BasicBlock.h:264
long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal)
Obtain the sign extended value for an integer constant value.
Definition: Core.cpp:1153
static Constant * getAdd(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
Definition: Constants.cpp:2176
static Constant * getFMul(Constant *C1, Constant *C2)
Definition: Constants.cpp:2205
void(* LLVMYieldCallback)(LLVMContextRef, void *)
Definition: Core.h:478
void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index, unsigned align)
Definition: Core.cpp:2412
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:696
LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst)
Obtain the code opcode for an individual instruction.
Definition: Core.cpp:2382
LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C)
Obtain a 128-bit floating point type (112-bit mantissa) from a context.
Definition: Core.cpp:592
const char * LLVMGetStructName(LLVMTypeRef Ty)
Obtain the name of a structure.
Definition: Core.cpp:671
LLVMValueRef LLVMBuildCleanupPad(LLVMBuilderRef B, LLVMValueRef ParentPad, LLVMValueRef *Args, unsigned NumArgs, const char *Name)
Definition: Core.cpp:2732
LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn)
Obtain the last basic block in a function.
Definition: Core.cpp:2256
Same, but only replaced by something equivalent.
Definition: Core.h:168
void * PointerTy
Definition: GenericValue.h:22
LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB)
Convert a basic block instance to a value type.
Definition: Core.cpp:2210
LLVMValueRef LLVMGetParentCatchSwitch(LLVMValueRef CatchPad)
Get the parent catchswitch instruction of a catchpad instruction.
Definition: Core.cpp:2820
A tuple of MDNodes.
Definition: Metadata.h:1323
static Constant * getIntegerCast(Constant *C, Type *Ty, bool isSigned)
Create a ZExt, Bitcast or Trunc for integer -> integer casts.
Definition: Constants.cpp:1580
LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C)
Create a label type in a context.
Definition: Core.cpp:763
LLVMMetadataRef LLVMValueAsMetadata(LLVMValueRef Val)
Obtain a Value as a Metadata.
Definition: Core.cpp:1042
LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C)
Obtain a 64-bit floating point type from a context.
Definition: Core.cpp:586
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:1968
LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size)
Create a ConstantVector from values.
Definition: Core.cpp:1238
Set the new value and return the one old.
Definition: Core.h:351
LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:2916
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:1275
LLVMBool LLVMIsNull(LLVMValueRef Val)
Determine whether a value instance is null.
Definition: Core.cpp:980
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:1592
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:2536
Synchronized with respect to signal handlers executing in the same thread.
Definition: LLVMContext.h:56
LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text)
Obtain a constant for a floating point value parsed from a string.
Definition: Core.cpp:1140
const char * Key
Definition: Core.cpp:272
LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef B, LLVMValueRef *RetVals, unsigned N)
Definition: Core.cpp:2679
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:364
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:2254
static Constant * getNUWNeg(Constant *C)
Definition: Constants.h:971
Address of the GV is globally insignificant.
Definition: Core.h:192
Add a value and return the old one.
Definition: Core.h:352
void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block, LLVMValueRef Instr)
Definition: Core.cpp:2612
LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C)
Definition: Core.cpp:533
unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn)
Obtain the calling function of a function.
Definition: Core.cpp:2079
LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType, LLVMBool isSigned)
Definition: Core.cpp:1559
LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1311
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:731
void setThreadLocalMode(ThreadLocalMode Val)
Definition: GlobalValue.h:250
void LLVMSetDataLayout(LLVMModuleRef M, const char *DataLayoutStr)
Set the data layout for a module.
Definition: Core.cpp:256
LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1339
unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy)
Definition: Core.cpp:574
This file contains the simple types necessary to represent the attributes associated with functions a...
LLVMBool LLVMIsExternallyInitialized(LLVMValueRef GlobalVar)
Definition: Core.cpp:1950
Pointers.
Definition: Core.h:153
static Constant * getSExt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:1618
LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1447
LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB)
Obtain the function to which a basic block belongs.
Definition: Core.cpp:2226
void LLVMSetCondition(LLVMValueRef Branch, LLVMValueRef Cond)
Set the condition of a branch instruction.
Definition: Core.cpp:2530