LLVM  6.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 
238 /*--.. Data layout .........................................................--*/
240  return unwrap(M)->getDataLayoutStr().c_str();
241 }
242 
244  return LLVMGetDataLayoutStr(M);
245 }
246 
247 void LLVMSetDataLayout(LLVMModuleRef M, const char *DataLayoutStr) {
248  unwrap(M)->setDataLayout(DataLayoutStr);
249 }
250 
251 /*--.. Target triple .......................................................--*/
252 const char * LLVMGetTarget(LLVMModuleRef M) {
253  return unwrap(M)->getTargetTriple().c_str();
254 }
255 
256 void LLVMSetTarget(LLVMModuleRef M, const char *Triple) {
257  unwrap(M)->setTargetTriple(Triple);
258 }
259 
261  unwrap(M)->print(errs(), nullptr,
262  /*ShouldPreserveUseListOrder=*/false, /*IsForDebug=*/true);
263 }
264 
266  char **ErrorMessage) {
267  std::error_code EC;
268  raw_fd_ostream dest(Filename, EC, sys::fs::F_Text);
269  if (EC) {
270  *ErrorMessage = strdup(EC.message().c_str());
271  return true;
272  }
273 
274  unwrap(M)->print(dest, nullptr);
275 
276  dest.close();
277 
278  if (dest.has_error()) {
279  std::string E = "Error printing to file: " + dest.error().message();
280  *ErrorMessage = strdup(E.c_str());
281  return true;
282  }
283 
284  return false;
285 }
286 
288  std::string buf;
289  raw_string_ostream os(buf);
290 
291  unwrap(M)->print(os, nullptr);
292  os.flush();
293 
294  return strdup(buf.c_str());
295 }
296 
297 /*--.. Operations on inline assembler ......................................--*/
299  unwrap(M)->setModuleInlineAsm(StringRef(Asm));
300 }
301 
302 
303 /*--.. Operations on module contexts ......................................--*/
305  return wrap(&unwrap(M)->getContext());
306 }
307 
308 
309 /*===-- Operations on types -----------------------------------------------===*/
310 
311 /*--.. Operations on all types (mostly) ....................................--*/
312 
314  switch (unwrap(Ty)->getTypeID()) {
315  case Type::VoidTyID:
316  return LLVMVoidTypeKind;
317  case Type::HalfTyID:
318  return LLVMHalfTypeKind;
319  case Type::FloatTyID:
320  return LLVMFloatTypeKind;
321  case Type::DoubleTyID:
322  return LLVMDoubleTypeKind;
323  case Type::X86_FP80TyID:
324  return LLVMX86_FP80TypeKind;
325  case Type::FP128TyID:
326  return LLVMFP128TypeKind;
327  case Type::PPC_FP128TyID:
328  return LLVMPPC_FP128TypeKind;
329  case Type::LabelTyID:
330  return LLVMLabelTypeKind;
331  case Type::MetadataTyID:
332  return LLVMMetadataTypeKind;
333  case Type::IntegerTyID:
334  return LLVMIntegerTypeKind;
335  case Type::FunctionTyID:
336  return LLVMFunctionTypeKind;
337  case Type::StructTyID:
338  return LLVMStructTypeKind;
339  case Type::ArrayTyID:
340  return LLVMArrayTypeKind;
341  case Type::PointerTyID:
342  return LLVMPointerTypeKind;
343  case Type::VectorTyID:
344  return LLVMVectorTypeKind;
345  case Type::X86_MMXTyID:
346  return LLVMX86_MMXTypeKind;
347  case Type::TokenTyID:
348  return LLVMTokenTypeKind;
349  }
350  llvm_unreachable("Unhandled TypeID.");
351 }
352 
354 {
355  return unwrap(Ty)->isSized();
356 }
357 
359  return wrap(&unwrap(Ty)->getContext());
360 }
361 
362 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
364  return unwrap(Ty)->dump();
365 }
366 #endif
367 
369  std::string buf;
370  raw_string_ostream os(buf);
371 
372  if (unwrap(Ty))
373  unwrap(Ty)->print(os);
374  else
375  os << "Printing <null> Type";
376 
377  os.flush();
378 
379  return strdup(buf.c_str());
380 }
381 
382 /*--.. Operations on integer types .........................................--*/
383 
385  return (LLVMTypeRef) Type::getInt1Ty(*unwrap(C));
386 }
388  return (LLVMTypeRef) Type::getInt8Ty(*unwrap(C));
389 }
391  return (LLVMTypeRef) Type::getInt16Ty(*unwrap(C));
392 }
394  return (LLVMTypeRef) Type::getInt32Ty(*unwrap(C));
395 }
397  return (LLVMTypeRef) Type::getInt64Ty(*unwrap(C));
398 }
400  return (LLVMTypeRef) Type::getInt128Ty(*unwrap(C));
401 }
403  return wrap(IntegerType::get(*unwrap(C), NumBits));
404 }
405 
408 }
411 }
414 }
417 }
420 }
423 }
424 LLVMTypeRef LLVMIntType(unsigned NumBits) {
425  return LLVMIntTypeInContext(LLVMGetGlobalContext(), NumBits);
426 }
427 
428 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy) {
429  return unwrap<IntegerType>(IntegerTy)->getBitWidth();
430 }
431 
432 /*--.. Operations on real types ............................................--*/
433 
435  return (LLVMTypeRef) Type::getHalfTy(*unwrap(C));
436 }
438  return (LLVMTypeRef) Type::getFloatTy(*unwrap(C));
439 }
441  return (LLVMTypeRef) Type::getDoubleTy(*unwrap(C));
442 }
444  return (LLVMTypeRef) Type::getX86_FP80Ty(*unwrap(C));
445 }
447  return (LLVMTypeRef) Type::getFP128Ty(*unwrap(C));
448 }
451 }
453  return (LLVMTypeRef) Type::getX86_MMXTy(*unwrap(C));
454 }
455 
458 }
461 }
464 }
467 }
470 }
473 }
476 }
477 
478 /*--.. Operations on function types ........................................--*/
479 
481  LLVMTypeRef *ParamTypes, unsigned ParamCount,
482  LLVMBool IsVarArg) {
483  ArrayRef<Type*> Tys(unwrap(ParamTypes), ParamCount);
484  return wrap(FunctionType::get(unwrap(ReturnType), Tys, IsVarArg != 0));
485 }
486 
488  return unwrap<FunctionType>(FunctionTy)->isVarArg();
489 }
490 
492  return wrap(unwrap<FunctionType>(FunctionTy)->getReturnType());
493 }
494 
495 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy) {
496  return unwrap<FunctionType>(FunctionTy)->getNumParams();
497 }
498 
499 void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest) {
500  FunctionType *Ty = unwrap<FunctionType>(FunctionTy);
502  E = Ty->param_end(); I != E; ++I)
503  *Dest++ = wrap(*I);
504 }
505 
506 /*--.. Operations on struct types ..........................................--*/
507 
509  unsigned ElementCount, LLVMBool Packed) {
510  ArrayRef<Type*> Tys(unwrap(ElementTypes), ElementCount);
511  return wrap(StructType::get(*unwrap(C), Tys, Packed != 0));
512 }
513 
515  unsigned ElementCount, LLVMBool Packed) {
516  return LLVMStructTypeInContext(LLVMGetGlobalContext(), ElementTypes,
517  ElementCount, Packed);
518 }
519 
521 {
522  return wrap(StructType::create(*unwrap(C), Name));
523 }
524 
526 {
527  StructType *Type = unwrap<StructType>(Ty);
528  if (!Type->hasName())
529  return nullptr;
530  return Type->getName().data();
531 }
532 
533 void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
534  unsigned ElementCount, LLVMBool Packed) {
535  ArrayRef<Type*> Tys(unwrap(ElementTypes), ElementCount);
536  unwrap<StructType>(StructTy)->setBody(Tys, Packed != 0);
537 }
538 
540  return unwrap<StructType>(StructTy)->getNumElements();
541 }
542 
544  StructType *Ty = unwrap<StructType>(StructTy);
546  E = Ty->element_end(); I != E; ++I)
547  *Dest++ = wrap(*I);
548 }
549 
551  StructType *Ty = unwrap<StructType>(StructTy);
552  return wrap(Ty->getTypeAtIndex(i));
553 }
554 
556  return unwrap<StructType>(StructTy)->isPacked();
557 }
558 
560  return unwrap<StructType>(StructTy)->isOpaque();
561 }
562 
564  return wrap(unwrap(M)->getTypeByName(Name));
565 }
566 
567 /*--.. Operations on array, pointer, and vector types (sequence types) .....--*/
568 
570  int i = 0;
571  for (auto *T : unwrap(Tp)->subtypes()) {
572  Arr[i] = wrap(T);
573  i++;
574  }
575 }
576 
577 LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount) {
578  return wrap(ArrayType::get(unwrap(ElementType), ElementCount));
579 }
580 
582  return wrap(PointerType::get(unwrap(ElementType), AddressSpace));
583 }
584 
585 LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount) {
586  return wrap(VectorType::get(unwrap(ElementType), ElementCount));
587 }
588 
590  auto *Ty = unwrap<Type>(WrappedTy);
591  if (auto *PTy = dyn_cast<PointerType>(Ty))
592  return wrap(PTy->getElementType());
593  return wrap(cast<SequentialType>(Ty)->getElementType());
594 }
595 
597  return unwrap(Tp)->getNumContainedTypes();
598 }
599 
600 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy) {
601  return unwrap<ArrayType>(ArrayTy)->getNumElements();
602 }
603 
605  return unwrap<PointerType>(PointerTy)->getAddressSpace();
606 }
607 
608 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy) {
609  return unwrap<VectorType>(VectorTy)->getNumElements();
610 }
611 
612 /*--.. Operations on other types ...........................................--*/
613 
615  return wrap(Type::getVoidTy(*unwrap(C)));
616 }
618  return wrap(Type::getLabelTy(*unwrap(C)));
619 }
621  return wrap(Type::getTokenTy(*unwrap(C)));
622 }
624  return wrap(Type::getMetadataTy(*unwrap(C)));
625 }
626 
629 }
632 }
633 
634 /*===-- Operations on values ----------------------------------------------===*/
635 
636 /*--.. Operations on all values ............................................--*/
637 
639  return wrap(unwrap(Val)->getType());
640 }
641 
643  switch(unwrap(Val)->getValueID()) {
644 #define HANDLE_VALUE(Name) \
645  case Value::Name##Val: \
646  return LLVM##Name##ValueKind;
647 #include "llvm/IR/Value.def"
648  default:
650  }
651 }
652 
653 const char *LLVMGetValueName(LLVMValueRef Val) {
654  return unwrap(Val)->getName().data();
655 }
656 
657 void LLVMSetValueName(LLVMValueRef Val, const char *Name) {
658  unwrap(Val)->setName(Name);
659 }
660 
662  unwrap(Val)->print(errs(), /*IsForDebug=*/true);
663 }
664 
666  std::string buf;
667  raw_string_ostream os(buf);
668 
669  if (unwrap(Val))
670  unwrap(Val)->print(os);
671  else
672  os << "Printing <null> Value";
673 
674  os.flush();
675 
676  return strdup(buf.c_str());
677 }
678 
680  unwrap(OldVal)->replaceAllUsesWith(unwrap(NewVal));
681 }
682 
684  return unwrap<Instruction>(Inst)->hasMetadata();
685 }
686 
687 LLVMValueRef LLVMGetMetadata(LLVMValueRef Inst, unsigned KindID) {
688  auto *I = unwrap<Instruction>(Inst);
689  assert(I && "Expected instruction");
690  if (auto *MD = I->getMetadata(KindID))
691  return wrap(MetadataAsValue::get(I->getContext(), MD));
692  return nullptr;
693 }
694 
695 // MetadataAsValue uses a canonical format which strips the actual MDNode for
696 // MDNode with just a single constant value, storing just a ConstantAsMetadata
697 // This undoes this canonicalization, reconstructing the MDNode.
699  Metadata *MD = MAV->getMetadata();
700  assert((isa<MDNode>(MD) || isa<ConstantAsMetadata>(MD)) &&
701  "Expected a metadata node or a canonicalized constant");
702 
703  if (MDNode *N = dyn_cast<MDNode>(MD))
704  return N;
705 
706  return MDNode::get(MAV->getContext(), MD);
707 }
708 
709 void LLVMSetMetadata(LLVMValueRef Inst, unsigned KindID, LLVMValueRef Val) {
710  MDNode *N = Val ? extractMDNode(unwrap<MetadataAsValue>(Val)) : nullptr;
711 
712  unwrap<Instruction>(Inst)->setMetadata(KindID, N);
713 }
714 
715 /*--.. Conversion functions ................................................--*/
716 
717 #define LLVM_DEFINE_VALUE_CAST(name) \
718  LLVMValueRef LLVMIsA##name(LLVMValueRef Val) { \
719  return wrap(static_cast<Value*>(dyn_cast_or_null<name>(unwrap(Val)))); \
720  }
721 
723 
725  if (auto *MD = dyn_cast_or_null<MetadataAsValue>(unwrap(Val)))
726  if (isa<MDNode>(MD->getMetadata()) ||
727  isa<ValueAsMetadata>(MD->getMetadata()))
728  return Val;
729  return nullptr;
730 }
731 
733  if (auto *MD = dyn_cast_or_null<MetadataAsValue>(unwrap(Val)))
734  if (isa<MDString>(MD->getMetadata()))
735  return Val;
736  return nullptr;
737 }
738 
739 /*--.. Operations on Uses ..................................................--*/
741  Value *V = unwrap(Val);
743  if (I == V->use_end())
744  return nullptr;
745  return wrap(&*I);
746 }
747 
749  Use *Next = unwrap(U)->getNext();
750  if (Next)
751  return wrap(Next);
752  return nullptr;
753 }
754 
756  return wrap(unwrap(U)->getUser());
757 }
758 
760  return wrap(unwrap(U)->get());
761 }
762 
763 /*--.. Operations on Users .................................................--*/
764 
766  unsigned Index) {
767  Metadata *Op = N->getOperand(Index);
768  if (!Op)
769  return nullptr;
770  if (auto *C = dyn_cast<ConstantAsMetadata>(Op))
771  return wrap(C->getValue());
772  return wrap(MetadataAsValue::get(Context, Op));
773 }
774 
776  Value *V = unwrap(Val);
777  if (auto *MD = dyn_cast<MetadataAsValue>(V)) {
778  if (auto *L = dyn_cast<ValueAsMetadata>(MD->getMetadata())) {
779  assert(Index == 0 && "Function-local metadata can only have one operand");
780  return wrap(L->getValue());
781  }
782  return getMDNodeOperandImpl(V->getContext(),
783  cast<MDNode>(MD->getMetadata()), Index);
784  }
785 
786  return wrap(cast<User>(V)->getOperand(Index));
787 }
788 
790  Value *V = unwrap(Val);
791  return wrap(&cast<User>(V)->getOperandUse(Index));
792 }
793 
794 void LLVMSetOperand(LLVMValueRef Val, unsigned Index, LLVMValueRef Op) {
795  unwrap<User>(Val)->setOperand(Index, unwrap(Op));
796 }
797 
799  Value *V = unwrap(Val);
800  if (isa<MetadataAsValue>(V))
801  return LLVMGetMDNodeNumOperands(Val);
802 
803  return cast<User>(V)->getNumOperands();
804 }
805 
806 /*--.. Operations on constants of any type .................................--*/
807 
809  return wrap(Constant::getNullValue(unwrap(Ty)));
810 }
811 
814 }
815 
817  return wrap(UndefValue::get(unwrap(Ty)));
818 }
819 
821  return isa<Constant>(unwrap(Ty));
822 }
823 
825  if (Constant *C = dyn_cast<Constant>(unwrap(Val)))
826  return C->isNullValue();
827  return false;
828 }
829 
831  return isa<UndefValue>(unwrap(Val));
832 }
833 
835  return wrap(ConstantPointerNull::get(unwrap<PointerType>(Ty)));
836 }
837 
838 /*--.. Operations on metadata nodes ........................................--*/
839 
841  unsigned SLen) {
842  LLVMContext &Context = *unwrap(C);
843  return wrap(MetadataAsValue::get(
844  Context, MDString::get(Context, StringRef(Str, SLen))));
845 }
846 
847 LLVMValueRef LLVMMDString(const char *Str, unsigned SLen) {
848  return LLVMMDStringInContext(LLVMGetGlobalContext(), Str, SLen);
849 }
850 
852  unsigned Count) {
853  LLVMContext &Context = *unwrap(C);
855  for (auto *OV : makeArrayRef(Vals, Count)) {
856  Value *V = unwrap(OV);
857  Metadata *MD;
858  if (!V)
859  MD = nullptr;
860  else if (auto *C = dyn_cast<Constant>(V))
861  MD = ConstantAsMetadata::get(C);
862  else if (auto *MDV = dyn_cast<MetadataAsValue>(V)) {
863  MD = MDV->getMetadata();
864  assert(!isa<LocalAsMetadata>(MD) && "Unexpected function-local metadata "
865  "outside of direct argument to call");
866  } else {
867  // This is function-local metadata. Pretend to make an MDNode.
868  assert(Count == 1 &&
869  "Expected only one operand to function-local metadata");
870  return wrap(MetadataAsValue::get(Context, LocalAsMetadata::get(V)));
871  }
872 
873  MDs.push_back(MD);
874  }
875  return wrap(MetadataAsValue::get(Context, MDNode::get(Context, MDs)));
876 }
877 
878 LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count) {
879  return LLVMMDNodeInContext(LLVMGetGlobalContext(), Vals, Count);
880 }
881 
883  return wrap(MetadataAsValue::get(*unwrap(C), unwrap(MD)));
884 }
885 
887  auto *V = unwrap(Val);
888  if (auto *C = dyn_cast<Constant>(V))
889  return wrap(ConstantAsMetadata::get(C));
890  if (auto *MAV = dyn_cast<MetadataAsValue>(V))
891  return wrap(MAV->getMetadata());
892  return wrap(ValueAsMetadata::get(V));
893 }
894 
895 const char *LLVMGetMDString(LLVMValueRef V, unsigned *Length) {
896  if (const auto *MD = dyn_cast<MetadataAsValue>(unwrap(V)))
897  if (const MDString *S = dyn_cast<MDString>(MD->getMetadata())) {
898  *Length = S->getString().size();
899  return S->getString().data();
900  }
901  *Length = 0;
902  return nullptr;
903 }
904 
906  auto *MD = cast<MetadataAsValue>(unwrap(V));
907  if (isa<ValueAsMetadata>(MD->getMetadata()))
908  return 1;
909  return cast<MDNode>(MD->getMetadata())->getNumOperands();
910 }
911 
913  auto *MD = cast<MetadataAsValue>(unwrap(V));
914  if (auto *MDV = dyn_cast<ValueAsMetadata>(MD->getMetadata())) {
915  *Dest = wrap(MDV->getValue());
916  return;
917  }
918  const auto *N = cast<MDNode>(MD->getMetadata());
919  const unsigned numOperands = N->getNumOperands();
920  LLVMContext &Context = unwrap(V)->getContext();
921  for (unsigned i = 0; i < numOperands; i++)
922  Dest[i] = getMDNodeOperandImpl(Context, N, i);
923 }
924 
926  if (NamedMDNode *N = unwrap(M)->getNamedMetadata(Name)) {
927  return N->getNumOperands();
928  }
929  return 0;
930 }
931 
933  LLVMValueRef *Dest) {
934  NamedMDNode *N = unwrap(M)->getNamedMetadata(Name);
935  if (!N)
936  return;
937  LLVMContext &Context = unwrap(M)->getContext();
938  for (unsigned i=0;i<N->getNumOperands();i++)
939  Dest[i] = wrap(MetadataAsValue::get(Context, N->getOperand(i)));
940 }
941 
943  LLVMValueRef Val) {
944  NamedMDNode *N = unwrap(M)->getOrInsertNamedMetadata(Name);
945  if (!N)
946  return;
947  if (!Val)
948  return;
949  N->addOperand(extractMDNode(unwrap<MetadataAsValue>(Val)));
950 }
951 
952 /*--.. Operations on scalar constants ......................................--*/
953 
954 LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
955  LLVMBool SignExtend) {
956  return wrap(ConstantInt::get(unwrap<IntegerType>(IntTy), N, SignExtend != 0));
957 }
958 
960  unsigned NumWords,
961  const uint64_t Words[]) {
962  IntegerType *Ty = unwrap<IntegerType>(IntTy);
963  return wrap(ConstantInt::get(Ty->getContext(),
964  APInt(Ty->getBitWidth(),
965  makeArrayRef(Words, NumWords))));
966 }
967 
969  uint8_t Radix) {
970  return wrap(ConstantInt::get(unwrap<IntegerType>(IntTy), StringRef(Str),
971  Radix));
972 }
973 
975  unsigned SLen, uint8_t Radix) {
976  return wrap(ConstantInt::get(unwrap<IntegerType>(IntTy), StringRef(Str, SLen),
977  Radix));
978 }
979 
981  return wrap(ConstantFP::get(unwrap(RealTy), N));
982 }
983 
984 LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text) {
985  return wrap(ConstantFP::get(unwrap(RealTy), StringRef(Text)));
986 }
987 
989  unsigned SLen) {
990  return wrap(ConstantFP::get(unwrap(RealTy), StringRef(Str, SLen)));
991 }
992 
993 unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal) {
994  return unwrap<ConstantInt>(ConstantVal)->getZExtValue();
995 }
996 
997 long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal) {
998  return unwrap<ConstantInt>(ConstantVal)->getSExtValue();
999 }
1000 
1001 double LLVMConstRealGetDouble(LLVMValueRef ConstantVal, LLVMBool *LosesInfo) {
1002  ConstantFP *cFP = unwrap<ConstantFP>(ConstantVal) ;
1003  Type *Ty = cFP->getType();
1004 
1005  if (Ty->isFloatTy()) {
1006  *LosesInfo = false;
1007  return cFP->getValueAPF().convertToFloat();
1008  }
1009 
1010  if (Ty->isDoubleTy()) {
1011  *LosesInfo = false;
1012  return cFP->getValueAPF().convertToDouble();
1013  }
1014 
1015  bool APFLosesInfo;
1016  APFloat APF = cFP->getValueAPF();
1018  *LosesInfo = APFLosesInfo;
1019  return APF.convertToDouble();
1020 }
1021 
1022 /*--.. Operations on composite constants ...................................--*/
1023 
1025  unsigned Length,
1026  LLVMBool DontNullTerminate) {
1027  /* Inverted the sense of AddNull because ', 0)' is a
1028  better mnemonic for null termination than ', 1)'. */
1029  return wrap(ConstantDataArray::getString(*unwrap(C), StringRef(Str, Length),
1030  DontNullTerminate == 0));
1031 }
1032 
1033 LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
1034  LLVMBool DontNullTerminate) {
1035  return LLVMConstStringInContext(LLVMGetGlobalContext(), Str, Length,
1036  DontNullTerminate);
1037 }
1038 
1040  return wrap(unwrap<ConstantDataSequential>(C)->getElementAsConstant(idx));
1041 }
1042 
1044  return unwrap<ConstantDataSequential>(C)->isString();
1045 }
1046 
1047 const char *LLVMGetAsString(LLVMValueRef C, size_t *Length) {
1048  StringRef Str = unwrap<ConstantDataSequential>(C)->getAsString();
1049  *Length = Str.size();
1050  return Str.data();
1051 }
1052 
1054  LLVMValueRef *ConstantVals, unsigned Length) {
1055  ArrayRef<Constant*> V(unwrap<Constant>(ConstantVals, Length), Length);
1056  return wrap(ConstantArray::get(ArrayType::get(unwrap(ElementTy), Length), V));
1057 }
1058 
1060  LLVMValueRef *ConstantVals,
1061  unsigned Count, LLVMBool Packed) {
1062  Constant **Elements = unwrap<Constant>(ConstantVals, Count);
1063  return wrap(ConstantStruct::getAnon(*unwrap(C), makeArrayRef(Elements, Count),
1064  Packed != 0));
1065 }
1066 
1067 LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
1068  LLVMBool Packed) {
1069  return LLVMConstStructInContext(LLVMGetGlobalContext(), ConstantVals, Count,
1070  Packed);
1071 }
1072 
1074  LLVMValueRef *ConstantVals,
1075  unsigned Count) {
1076  Constant **Elements = unwrap<Constant>(ConstantVals, Count);
1077  StructType *Ty = cast<StructType>(unwrap(StructTy));
1078 
1079  return wrap(ConstantStruct::get(Ty, makeArrayRef(Elements, Count)));
1080 }
1081 
1082 LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size) {
1084  unwrap<Constant>(ScalarConstantVals, Size), Size)));
1085 }
1086 
1087 /*-- Opcode mapping */
1088 
1089 static LLVMOpcode map_to_llvmopcode(int opcode)
1090 {
1091  switch (opcode) {
1092  default: llvm_unreachable("Unhandled Opcode.");
1093 #define HANDLE_INST(num, opc, clas) case num: return LLVM##opc;
1094 #include "llvm/IR/Instruction.def"
1095 #undef HANDLE_INST
1096  }
1097 }
1098 
1100 {
1101  switch (code) {
1102 #define HANDLE_INST(num, opc, clas) case LLVM##opc: return num;
1103 #include "llvm/IR/Instruction.def"
1104 #undef HANDLE_INST
1105  }
1106  llvm_unreachable("Unhandled Opcode.");
1107 }
1108 
1109 /*--.. Constant expressions ................................................--*/
1110 
1112  return map_to_llvmopcode(unwrap<ConstantExpr>(ConstantVal)->getOpcode());
1113 }
1114 
1116  return wrap(ConstantExpr::getAlignOf(unwrap(Ty)));
1117 }
1118 
1120  return wrap(ConstantExpr::getSizeOf(unwrap(Ty)));
1121 }
1122 
1124  return wrap(ConstantExpr::getNeg(unwrap<Constant>(ConstantVal)));
1125 }
1126 
1128  return wrap(ConstantExpr::getNSWNeg(unwrap<Constant>(ConstantVal)));
1129 }
1130 
1132  return wrap(ConstantExpr::getNUWNeg(unwrap<Constant>(ConstantVal)));
1133 }
1134 
1135 
1137  return wrap(ConstantExpr::getFNeg(unwrap<Constant>(ConstantVal)));
1138 }
1139 
1141  return wrap(ConstantExpr::getNot(unwrap<Constant>(ConstantVal)));
1142 }
1143 
1145  return wrap(ConstantExpr::getAdd(unwrap<Constant>(LHSConstant),
1146  unwrap<Constant>(RHSConstant)));
1147 }
1148 
1150  LLVMValueRef RHSConstant) {
1151  return wrap(ConstantExpr::getNSWAdd(unwrap<Constant>(LHSConstant),
1152  unwrap<Constant>(RHSConstant)));
1153 }
1154 
1156  LLVMValueRef RHSConstant) {
1157  return wrap(ConstantExpr::getNUWAdd(unwrap<Constant>(LHSConstant),
1158  unwrap<Constant>(RHSConstant)));
1159 }
1160 
1162  return wrap(ConstantExpr::getFAdd(unwrap<Constant>(LHSConstant),
1163  unwrap<Constant>(RHSConstant)));
1164 }
1165 
1167  return wrap(ConstantExpr::getSub(unwrap<Constant>(LHSConstant),
1168  unwrap<Constant>(RHSConstant)));
1169 }
1170 
1172  LLVMValueRef RHSConstant) {
1173  return wrap(ConstantExpr::getNSWSub(unwrap<Constant>(LHSConstant),
1174  unwrap<Constant>(RHSConstant)));
1175 }
1176 
1178  LLVMValueRef RHSConstant) {
1179  return wrap(ConstantExpr::getNUWSub(unwrap<Constant>(LHSConstant),
1180  unwrap<Constant>(RHSConstant)));
1181 }
1182 
1184  return wrap(ConstantExpr::getFSub(unwrap<Constant>(LHSConstant),
1185  unwrap<Constant>(RHSConstant)));
1186 }
1187 
1189  return wrap(ConstantExpr::getMul(unwrap<Constant>(LHSConstant),
1190  unwrap<Constant>(RHSConstant)));
1191 }
1192 
1194  LLVMValueRef RHSConstant) {
1195  return wrap(ConstantExpr::getNSWMul(unwrap<Constant>(LHSConstant),
1196  unwrap<Constant>(RHSConstant)));
1197 }
1198 
1200  LLVMValueRef RHSConstant) {
1201  return wrap(ConstantExpr::getNUWMul(unwrap<Constant>(LHSConstant),
1202  unwrap<Constant>(RHSConstant)));
1203 }
1204 
1206  return wrap(ConstantExpr::getFMul(unwrap<Constant>(LHSConstant),
1207  unwrap<Constant>(RHSConstant)));
1208 }
1209 
1211  return wrap(ConstantExpr::getUDiv(unwrap<Constant>(LHSConstant),
1212  unwrap<Constant>(RHSConstant)));
1213 }
1214 
1216  LLVMValueRef RHSConstant) {
1217  return wrap(ConstantExpr::getExactUDiv(unwrap<Constant>(LHSConstant),
1218  unwrap<Constant>(RHSConstant)));
1219 }
1220 
1222  return wrap(ConstantExpr::getSDiv(unwrap<Constant>(LHSConstant),
1223  unwrap<Constant>(RHSConstant)));
1224 }
1225 
1227  LLVMValueRef RHSConstant) {
1228  return wrap(ConstantExpr::getExactSDiv(unwrap<Constant>(LHSConstant),
1229  unwrap<Constant>(RHSConstant)));
1230 }
1231 
1233  return wrap(ConstantExpr::getFDiv(unwrap<Constant>(LHSConstant),
1234  unwrap<Constant>(RHSConstant)));
1235 }
1236 
1238  return wrap(ConstantExpr::getURem(unwrap<Constant>(LHSConstant),
1239  unwrap<Constant>(RHSConstant)));
1240 }
1241 
1243  return wrap(ConstantExpr::getSRem(unwrap<Constant>(LHSConstant),
1244  unwrap<Constant>(RHSConstant)));
1245 }
1246 
1248  return wrap(ConstantExpr::getFRem(unwrap<Constant>(LHSConstant),
1249  unwrap<Constant>(RHSConstant)));
1250 }
1251 
1253  return wrap(ConstantExpr::getAnd(unwrap<Constant>(LHSConstant),
1254  unwrap<Constant>(RHSConstant)));
1255 }
1256 
1258  return wrap(ConstantExpr::getOr(unwrap<Constant>(LHSConstant),
1259  unwrap<Constant>(RHSConstant)));
1260 }
1261 
1263  return wrap(ConstantExpr::getXor(unwrap<Constant>(LHSConstant),
1264  unwrap<Constant>(RHSConstant)));
1265 }
1266 
1268  LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1269  return wrap(ConstantExpr::getICmp(Predicate,
1270  unwrap<Constant>(LHSConstant),
1271  unwrap<Constant>(RHSConstant)));
1272 }
1273 
1275  LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1276  return wrap(ConstantExpr::getFCmp(Predicate,
1277  unwrap<Constant>(LHSConstant),
1278  unwrap<Constant>(RHSConstant)));
1279 }
1280 
1282  return wrap(ConstantExpr::getShl(unwrap<Constant>(LHSConstant),
1283  unwrap<Constant>(RHSConstant)));
1284 }
1285 
1287  return wrap(ConstantExpr::getLShr(unwrap<Constant>(LHSConstant),
1288  unwrap<Constant>(RHSConstant)));
1289 }
1290 
1292  return wrap(ConstantExpr::getAShr(unwrap<Constant>(LHSConstant),
1293  unwrap<Constant>(RHSConstant)));
1294 }
1295 
1297  LLVMValueRef *ConstantIndices, unsigned NumIndices) {
1298  ArrayRef<Constant *> IdxList(unwrap<Constant>(ConstantIndices, NumIndices),
1299  NumIndices);
1301  nullptr, unwrap<Constant>(ConstantVal), IdxList));
1302 }
1303 
1305  LLVMValueRef *ConstantIndices,
1306  unsigned NumIndices) {
1307  Constant* Val = unwrap<Constant>(ConstantVal);
1308  ArrayRef<Constant *> IdxList(unwrap<Constant>(ConstantIndices, NumIndices),
1309  NumIndices);
1310  return wrap(ConstantExpr::getInBoundsGetElementPtr(nullptr, Val, IdxList));
1311 }
1312 
1314  return wrap(ConstantExpr::getTrunc(unwrap<Constant>(ConstantVal),
1315  unwrap(ToType)));
1316 }
1317 
1319  return wrap(ConstantExpr::getSExt(unwrap<Constant>(ConstantVal),
1320  unwrap(ToType)));
1321 }
1322 
1324  return wrap(ConstantExpr::getZExt(unwrap<Constant>(ConstantVal),
1325  unwrap(ToType)));
1326 }
1327 
1329  return wrap(ConstantExpr::getFPTrunc(unwrap<Constant>(ConstantVal),
1330  unwrap(ToType)));
1331 }
1332 
1334  return wrap(ConstantExpr::getFPExtend(unwrap<Constant>(ConstantVal),
1335  unwrap(ToType)));
1336 }
1337 
1339  return wrap(ConstantExpr::getUIToFP(unwrap<Constant>(ConstantVal),
1340  unwrap(ToType)));
1341 }
1342 
1344  return wrap(ConstantExpr::getSIToFP(unwrap<Constant>(ConstantVal),
1345  unwrap(ToType)));
1346 }
1347 
1349  return wrap(ConstantExpr::getFPToUI(unwrap<Constant>(ConstantVal),
1350  unwrap(ToType)));
1351 }
1352 
1354  return wrap(ConstantExpr::getFPToSI(unwrap<Constant>(ConstantVal),
1355  unwrap(ToType)));
1356 }
1357 
1359  return wrap(ConstantExpr::getPtrToInt(unwrap<Constant>(ConstantVal),
1360  unwrap(ToType)));
1361 }
1362 
1364  return wrap(ConstantExpr::getIntToPtr(unwrap<Constant>(ConstantVal),
1365  unwrap(ToType)));
1366 }
1367 
1369  return wrap(ConstantExpr::getBitCast(unwrap<Constant>(ConstantVal),
1370  unwrap(ToType)));
1371 }
1372 
1374  LLVMTypeRef ToType) {
1375  return wrap(ConstantExpr::getAddrSpaceCast(unwrap<Constant>(ConstantVal),
1376  unwrap(ToType)));
1377 }
1378 
1380  LLVMTypeRef ToType) {
1381  return wrap(ConstantExpr::getZExtOrBitCast(unwrap<Constant>(ConstantVal),
1382  unwrap(ToType)));
1383 }
1384 
1386  LLVMTypeRef ToType) {
1387  return wrap(ConstantExpr::getSExtOrBitCast(unwrap<Constant>(ConstantVal),
1388  unwrap(ToType)));
1389 }
1390 
1392  LLVMTypeRef ToType) {
1393  return wrap(ConstantExpr::getTruncOrBitCast(unwrap<Constant>(ConstantVal),
1394  unwrap(ToType)));
1395 }
1396 
1398  LLVMTypeRef ToType) {
1399  return wrap(ConstantExpr::getPointerCast(unwrap<Constant>(ConstantVal),
1400  unwrap(ToType)));
1401 }
1402 
1404  LLVMBool isSigned) {
1405  return wrap(ConstantExpr::getIntegerCast(unwrap<Constant>(ConstantVal),
1406  unwrap(ToType), isSigned));
1407 }
1408 
1410  return wrap(ConstantExpr::getFPCast(unwrap<Constant>(ConstantVal),
1411  unwrap(ToType)));
1412 }
1413 
1415  LLVMValueRef ConstantIfTrue,
1416  LLVMValueRef ConstantIfFalse) {
1417  return wrap(ConstantExpr::getSelect(unwrap<Constant>(ConstantCondition),
1418  unwrap<Constant>(ConstantIfTrue),
1419  unwrap<Constant>(ConstantIfFalse)));
1420 }
1421 
1423  LLVMValueRef IndexConstant) {
1424  return wrap(ConstantExpr::getExtractElement(unwrap<Constant>(VectorConstant),
1425  unwrap<Constant>(IndexConstant)));
1426 }
1427 
1429  LLVMValueRef ElementValueConstant,
1430  LLVMValueRef IndexConstant) {
1431  return wrap(ConstantExpr::getInsertElement(unwrap<Constant>(VectorConstant),
1432  unwrap<Constant>(ElementValueConstant),
1433  unwrap<Constant>(IndexConstant)));
1434 }
1435 
1437  LLVMValueRef VectorBConstant,
1438  LLVMValueRef MaskConstant) {
1439  return wrap(ConstantExpr::getShuffleVector(unwrap<Constant>(VectorAConstant),
1440  unwrap<Constant>(VectorBConstant),
1441  unwrap<Constant>(MaskConstant)));
1442 }
1443 
1444 LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
1445  unsigned NumIdx) {
1446  return wrap(ConstantExpr::getExtractValue(unwrap<Constant>(AggConstant),
1447  makeArrayRef(IdxList, NumIdx)));
1448 }
1449 
1451  LLVMValueRef ElementValueConstant,
1452  unsigned *IdxList, unsigned NumIdx) {
1453  return wrap(ConstantExpr::getInsertValue(unwrap<Constant>(AggConstant),
1454  unwrap<Constant>(ElementValueConstant),
1455  makeArrayRef(IdxList, NumIdx)));
1456 }
1457 
1458 LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty, const char *AsmString,
1459  const char *Constraints,
1460  LLVMBool HasSideEffects,
1461  LLVMBool IsAlignStack) {
1462  return wrap(InlineAsm::get(dyn_cast<FunctionType>(unwrap(Ty)), AsmString,
1463  Constraints, HasSideEffects, IsAlignStack));
1464 }
1465 
1467  return wrap(BlockAddress::get(unwrap<Function>(F), unwrap(BB)));
1468 }
1469 
1470 /*--.. Operations on global variables, functions, and aliases (globals) ....--*/
1471 
1473  return wrap(unwrap<GlobalValue>(Global)->getParent());
1474 }
1475 
1477  return unwrap<GlobalValue>(Global)->isDeclaration();
1478 }
1479 
1481  switch (unwrap<GlobalValue>(Global)->getLinkage()) {
1483  return LLVMExternalLinkage;
1487  return LLVMLinkOnceAnyLinkage;
1489  return LLVMLinkOnceODRLinkage;
1491  return LLVMWeakAnyLinkage;
1493  return LLVMWeakODRLinkage;
1495  return LLVMAppendingLinkage;
1497  return LLVMInternalLinkage;
1499  return LLVMPrivateLinkage;
1501  return LLVMExternalWeakLinkage;
1503  return LLVMCommonLinkage;
1504  }
1505 
1506  llvm_unreachable("Invalid GlobalValue linkage!");
1507 }
1508 
1509 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage) {
1510  GlobalValue *GV = unwrap<GlobalValue>(Global);
1511 
1512  switch (Linkage) {
1513  case LLVMExternalLinkage:
1515  break;
1518  break;
1521  break;
1524  break;
1526  DEBUG(errs() << "LLVMSetLinkage(): LLVMLinkOnceODRAutoHideLinkage is no "
1527  "longer supported.");
1528  break;
1529  case LLVMWeakAnyLinkage:
1531  break;
1532  case LLVMWeakODRLinkage:
1534  break;
1535  case LLVMAppendingLinkage:
1537  break;
1538  case LLVMInternalLinkage:
1540  break;
1541  case LLVMPrivateLinkage:
1543  break;
1546  break;
1549  break;
1550  case LLVMDLLImportLinkage:
1551  DEBUG(errs()
1552  << "LLVMSetLinkage(): LLVMDLLImportLinkage is no longer supported.");
1553  break;
1554  case LLVMDLLExportLinkage:
1555  DEBUG(errs()
1556  << "LLVMSetLinkage(): LLVMDLLExportLinkage is no longer supported.");
1557  break;
1560  break;
1561  case LLVMGhostLinkage:
1562  DEBUG(errs()
1563  << "LLVMSetLinkage(): LLVMGhostLinkage is no longer supported.");
1564  break;
1565  case LLVMCommonLinkage:
1567  break;
1568  }
1569 }
1570 
1571 const char *LLVMGetSection(LLVMValueRef Global) {
1572  // Using .data() is safe because of how GlobalObject::setSection is
1573  // implemented.
1574  return unwrap<GlobalValue>(Global)->getSection().data();
1575 }
1576 
1577 void LLVMSetSection(LLVMValueRef Global, const char *Section) {
1578  unwrap<GlobalObject>(Global)->setSection(Section);
1579 }
1580 
1582  return static_cast<LLVMVisibility>(
1583  unwrap<GlobalValue>(Global)->getVisibility());
1584 }
1585 
1587  unwrap<GlobalValue>(Global)
1588  ->setVisibility(static_cast<GlobalValue::VisibilityTypes>(Viz));
1589 }
1590 
1592  return static_cast<LLVMDLLStorageClass>(
1593  unwrap<GlobalValue>(Global)->getDLLStorageClass());
1594 }
1595 
1597  unwrap<GlobalValue>(Global)->setDLLStorageClass(
1598  static_cast<GlobalValue::DLLStorageClassTypes>(Class));
1599 }
1600 
1602  return unwrap<GlobalValue>(Global)->hasGlobalUnnamedAddr();
1603 }
1604 
1605 void LLVMSetUnnamedAddr(LLVMValueRef Global, LLVMBool HasUnnamedAddr) {
1606  unwrap<GlobalValue>(Global)->setUnnamedAddr(
1607  HasUnnamedAddr ? GlobalValue::UnnamedAddr::Global
1609 }
1610 
1611 /*--.. Operations on global variables, load and store instructions .........--*/
1612 
1614  Value *P = unwrap<Value>(V);
1615  if (GlobalValue *GV = dyn_cast<GlobalValue>(P))
1616  return GV->getAlignment();
1617  if (AllocaInst *AI = dyn_cast<AllocaInst>(P))
1618  return AI->getAlignment();
1619  if (LoadInst *LI = dyn_cast<LoadInst>(P))
1620  return LI->getAlignment();
1621  if (StoreInst *SI = dyn_cast<StoreInst>(P))
1622  return SI->getAlignment();
1623 
1625  "only GlobalValue, AllocaInst, LoadInst and StoreInst have alignment");
1626 }
1627 
1628 void LLVMSetAlignment(LLVMValueRef V, unsigned Bytes) {
1629  Value *P = unwrap<Value>(V);
1630  if (GlobalObject *GV = dyn_cast<GlobalObject>(P))
1631  GV->setAlignment(Bytes);
1632  else if (AllocaInst *AI = dyn_cast<AllocaInst>(P))
1633  AI->setAlignment(Bytes);
1634  else if (LoadInst *LI = dyn_cast<LoadInst>(P))
1635  LI->setAlignment(Bytes);
1636  else if (StoreInst *SI = dyn_cast<StoreInst>(P))
1637  SI->setAlignment(Bytes);
1638  else
1640  "only GlobalValue, AllocaInst, LoadInst and StoreInst have alignment");
1641 }
1642 
1643 /*--.. Operations on global variables ......................................--*/
1644 
1646  return wrap(new GlobalVariable(*unwrap(M), unwrap(Ty), false,
1647  GlobalValue::ExternalLinkage, nullptr, Name));
1648 }
1649 
1651  const char *Name,
1652  unsigned AddressSpace) {
1653  return wrap(new GlobalVariable(*unwrap(M), unwrap(Ty), false,
1654  GlobalValue::ExternalLinkage, nullptr, Name,
1656  AddressSpace));
1657 }
1658 
1660  return wrap(unwrap(M)->getNamedGlobal(Name));
1661 }
1662 
1664  Module *Mod = unwrap(M);
1666  if (I == Mod->global_end())
1667  return nullptr;
1668  return wrap(&*I);
1669 }
1670 
1672  Module *Mod = unwrap(M);
1674  if (I == Mod->global_begin())
1675  return nullptr;
1676  return wrap(&*--I);
1677 }
1678 
1680  GlobalVariable *GV = unwrap<GlobalVariable>(GlobalVar);
1682  if (++I == GV->getParent()->global_end())
1683  return nullptr;
1684  return wrap(&*I);
1685 }
1686 
1688  GlobalVariable *GV = unwrap<GlobalVariable>(GlobalVar);
1690  if (I == GV->getParent()->global_begin())
1691  return nullptr;
1692  return wrap(&*--I);
1693 }
1694 
1696  unwrap<GlobalVariable>(GlobalVar)->eraseFromParent();
1697 }
1698 
1700  GlobalVariable* GV = unwrap<GlobalVariable>(GlobalVar);
1701  if ( !GV->hasInitializer() )
1702  return nullptr;
1703  return wrap(GV->getInitializer());
1704 }
1705 
1707  unwrap<GlobalVariable>(GlobalVar)
1708  ->setInitializer(unwrap<Constant>(ConstantVal));
1709 }
1710 
1712  return unwrap<GlobalVariable>(GlobalVar)->isThreadLocal();
1713 }
1714 
1716  unwrap<GlobalVariable>(GlobalVar)->setThreadLocal(IsThreadLocal != 0);
1717 }
1718 
1720  return unwrap<GlobalVariable>(GlobalVar)->isConstant();
1721 }
1722 
1724  unwrap<GlobalVariable>(GlobalVar)->setConstant(IsConstant != 0);
1725 }
1726 
1728  switch (unwrap<GlobalVariable>(GlobalVar)->getThreadLocalMode()) {
1730  return LLVMNotThreadLocal;
1734  return LLVMLocalDynamicTLSModel;
1736  return LLVMInitialExecTLSModel;
1738  return LLVMLocalExecTLSModel;
1739  }
1740 
1741  llvm_unreachable("Invalid GlobalVariable thread local mode");
1742 }
1743 
1745  GlobalVariable *GV = unwrap<GlobalVariable>(GlobalVar);
1746 
1747  switch (Mode) {
1748  case LLVMNotThreadLocal:
1750  break;
1753  break;
1756  break;
1759  break;
1760  case LLVMLocalExecTLSModel:
1762  break;
1763  }
1764 }
1765 
1767  return unwrap<GlobalVariable>(GlobalVar)->isExternallyInitialized();
1768 }
1769 
1771  unwrap<GlobalVariable>(GlobalVar)->setExternallyInitialized(IsExtInit);
1772 }
1773 
1774 /*--.. Operations on aliases ......................................--*/
1775 
1777  const char *Name) {
1778  auto *PTy = cast<PointerType>(unwrap(Ty));
1779  return wrap(GlobalAlias::create(PTy->getElementType(), PTy->getAddressSpace(),
1781  unwrap<Constant>(Aliasee), unwrap(M)));
1782 }
1783 
1784 /*--.. Operations on functions .............................................--*/
1785 
1787  LLVMTypeRef FunctionTy) {
1788  return wrap(Function::Create(unwrap<FunctionType>(FunctionTy),
1790 }
1791 
1793  return wrap(unwrap(M)->getFunction(Name));
1794 }
1795 
1797  Module *Mod = unwrap(M);
1798  Module::iterator I = Mod->begin();
1799  if (I == Mod->end())
1800  return nullptr;
1801  return wrap(&*I);
1802 }
1803 
1805  Module *Mod = unwrap(M);
1806  Module::iterator I = Mod->end();
1807  if (I == Mod->begin())
1808  return nullptr;
1809  return wrap(&*--I);
1810 }
1811 
1813  Function *Func = unwrap<Function>(Fn);
1814  Module::iterator I(Func);
1815  if (++I == Func->getParent()->end())
1816  return nullptr;
1817  return wrap(&*I);
1818 }
1819 
1821  Function *Func = unwrap<Function>(Fn);
1822  Module::iterator I(Func);
1823  if (I == Func->getParent()->begin())
1824  return nullptr;
1825  return wrap(&*--I);
1826 }
1827 
1829  unwrap<Function>(Fn)->eraseFromParent();
1830 }
1831 
1833  return unwrap<Function>(Fn)->hasPersonalityFn();
1834 }
1835 
1837  return wrap(unwrap<Function>(Fn)->getPersonalityFn());
1838 }
1839 
1841  unwrap<Function>(Fn)->setPersonalityFn(unwrap<Constant>(PersonalityFn));
1842 }
1843 
1845  if (Function *F = dyn_cast<Function>(unwrap(Fn)))
1846  return F->getIntrinsicID();
1847  return 0;
1848 }
1849 
1851  return unwrap<Function>(Fn)->getCallingConv();
1852 }
1853 
1854 void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC) {
1855  return unwrap<Function>(Fn)->setCallingConv(
1856  static_cast<CallingConv::ID>(CC));
1857 }
1858 
1859 const char *LLVMGetGC(LLVMValueRef Fn) {
1860  Function *F = unwrap<Function>(Fn);
1861  return F->hasGC()? F->getGC().c_str() : nullptr;
1862 }
1863 
1864 void LLVMSetGC(LLVMValueRef Fn, const char *GC) {
1865  Function *F = unwrap<Function>(Fn);
1866  if (GC)
1867  F->setGC(GC);
1868  else
1869  F->clearGC();
1870 }
1871 
1873  LLVMAttributeRef A) {
1874  unwrap<Function>(F)->addAttribute(Idx, unwrap(A));
1875 }
1876 
1878  auto AS = unwrap<Function>(F)->getAttributes().getAttributes(Idx);
1879  return AS.getNumAttributes();
1880 }
1881 
1884  auto AS = unwrap<Function>(F)->getAttributes().getAttributes(Idx);
1885  for (auto A : AS)
1886  *Attrs++ = wrap(A);
1887 }
1888 
1890  LLVMAttributeIndex Idx,
1891  unsigned KindID) {
1892  return wrap(unwrap<Function>(F)->getAttribute(Idx,
1893  (Attribute::AttrKind)KindID));
1894 }
1895 
1897  LLVMAttributeIndex Idx,
1898  const char *K, unsigned KLen) {
1899  return wrap(unwrap<Function>(F)->getAttribute(Idx, StringRef(K, KLen)));
1900 }
1901 
1903  unsigned KindID) {
1904  unwrap<Function>(F)->removeAttribute(Idx, (Attribute::AttrKind)KindID);
1905 }
1906 
1908  const char *K, unsigned KLen) {
1909  unwrap<Function>(F)->removeAttribute(Idx, StringRef(K, KLen));
1910 }
1911 
1913  const char *V) {
1914  Function *Func = unwrap<Function>(Fn);
1915  Attribute Attr = Attribute::get(Func->getContext(), A, V);
1917 }
1918 
1919 /*--.. Operations on parameters ............................................--*/
1920 
1922  // This function is strictly redundant to
1923  // LLVMCountParamTypes(LLVMGetElementType(LLVMTypeOf(FnRef)))
1924  return unwrap<Function>(FnRef)->arg_size();
1925 }
1926 
1927 void LLVMGetParams(LLVMValueRef FnRef, LLVMValueRef *ParamRefs) {
1928  Function *Fn = unwrap<Function>(FnRef);
1929  for (Function::arg_iterator I = Fn->arg_begin(),
1930  E = Fn->arg_end(); I != E; I++)
1931  *ParamRefs++ = wrap(&*I);
1932 }
1933 
1934 LLVMValueRef LLVMGetParam(LLVMValueRef FnRef, unsigned index) {
1935  Function *Fn = unwrap<Function>(FnRef);
1936  return wrap(&Fn->arg_begin()[index]);
1937 }
1938 
1940  return wrap(unwrap<Argument>(V)->getParent());
1941 }
1942 
1944  Function *Func = unwrap<Function>(Fn);
1946  if (I == Func->arg_end())
1947  return nullptr;
1948  return wrap(&*I);
1949 }
1950 
1952  Function *Func = unwrap<Function>(Fn);
1953  Function::arg_iterator I = Func->arg_end();
1954  if (I == Func->arg_begin())
1955  return nullptr;
1956  return wrap(&*--I);
1957 }
1958 
1960  Argument *A = unwrap<Argument>(Arg);
1961  Function *Fn = A->getParent();
1962  if (A->getArgNo() + 1 >= Fn->arg_size())
1963  return nullptr;
1964  return wrap(&Fn->arg_begin()[A->getArgNo() + 1]);
1965 }
1966 
1968  Argument *A = unwrap<Argument>(Arg);
1969  if (A->getArgNo() == 0)
1970  return nullptr;
1971  return wrap(&A->getParent()->arg_begin()[A->getArgNo() - 1]);
1972 }
1973 
1974 void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align) {
1975  Argument *A = unwrap<Argument>(Arg);
1977 }
1978 
1979 /*--.. Operations on basic blocks ..........................................--*/
1980 
1982  return wrap(static_cast<Value*>(unwrap(BB)));
1983 }
1984 
1986  return isa<BasicBlock>(unwrap(Val));
1987 }
1988 
1990  return wrap(unwrap<BasicBlock>(Val));
1991 }
1992 
1994  return unwrap(BB)->getName().data();
1995 }
1996 
1998  return wrap(unwrap(BB)->getParent());
1999 }
2000 
2002  return wrap(unwrap(BB)->getTerminator());
2003 }
2004 
2006  return unwrap<Function>(FnRef)->size();
2007 }
2008 
2009 void LLVMGetBasicBlocks(LLVMValueRef FnRef, LLVMBasicBlockRef *BasicBlocksRefs){
2010  Function *Fn = unwrap<Function>(FnRef);
2011  for (BasicBlock &BB : *Fn)
2012  *BasicBlocksRefs++ = wrap(&BB);
2013 }
2014 
2016  return wrap(&unwrap<Function>(Fn)->getEntryBlock());
2017 }
2018 
2020  Function *Func = unwrap<Function>(Fn);
2021  Function::iterator I = Func->begin();
2022  if (I == Func->end())
2023  return nullptr;
2024  return wrap(&*I);
2025 }
2026 
2028  Function *Func = unwrap<Function>(Fn);
2029  Function::iterator I = Func->end();
2030  if (I == Func->begin())
2031  return nullptr;
2032  return wrap(&*--I);
2033 }
2034 
2036  BasicBlock *Block = unwrap(BB);
2037  Function::iterator I(Block);
2038  if (++I == Block->getParent()->end())
2039  return nullptr;
2040  return wrap(&*I);
2041 }
2042 
2044  BasicBlock *Block = unwrap(BB);
2045  Function::iterator I(Block);
2046  if (I == Block->getParent()->begin())
2047  return nullptr;
2048  return wrap(&*--I);
2049 }
2050 
2052  LLVMValueRef FnRef,
2053  const char *Name) {
2054  return wrap(BasicBlock::Create(*unwrap(C), Name, unwrap<Function>(FnRef)));
2055 }
2056 
2058  return LLVMAppendBasicBlockInContext(LLVMGetGlobalContext(), FnRef, Name);
2059 }
2060 
2062  LLVMBasicBlockRef BBRef,
2063  const char *Name) {
2064  BasicBlock *BB = unwrap(BBRef);
2065  return wrap(BasicBlock::Create(*unwrap(C), Name, BB->getParent(), BB));
2066 }
2067 
2069  const char *Name) {
2070  return LLVMInsertBasicBlockInContext(LLVMGetGlobalContext(), BBRef, Name);
2071 }
2072 
2074  unwrap(BBRef)->eraseFromParent();
2075 }
2076 
2078  unwrap(BBRef)->removeFromParent();
2079 }
2080 
2082  unwrap(BB)->moveBefore(unwrap(MovePos));
2083 }
2084 
2086  unwrap(BB)->moveAfter(unwrap(MovePos));
2087 }
2088 
2089 /*--.. Operations on instructions ..........................................--*/
2090 
2092  return wrap(unwrap<Instruction>(Inst)->getParent());
2093 }
2094 
2096  BasicBlock *Block = unwrap(BB);
2097  BasicBlock::iterator I = Block->begin();
2098  if (I == Block->end())
2099  return nullptr;
2100  return wrap(&*I);
2101 }
2102 
2104  BasicBlock *Block = unwrap(BB);
2105  BasicBlock::iterator I = Block->end();
2106  if (I == Block->begin())
2107  return nullptr;
2108  return wrap(&*--I);
2109 }
2110 
2112  Instruction *Instr = unwrap<Instruction>(Inst);
2113  BasicBlock::iterator I(Instr);
2114  if (++I == Instr->getParent()->end())
2115  return nullptr;
2116  return wrap(&*I);
2117 }
2118 
2120  Instruction *Instr = unwrap<Instruction>(Inst);
2121  BasicBlock::iterator I(Instr);
2122  if (I == Instr->getParent()->begin())
2123  return nullptr;
2124  return wrap(&*--I);
2125 }
2126 
2128  unwrap<Instruction>(Inst)->removeFromParent();
2129 }
2130 
2132  unwrap<Instruction>(Inst)->eraseFromParent();
2133 }
2134 
2136  if (ICmpInst *I = dyn_cast<ICmpInst>(unwrap(Inst)))
2137  return (LLVMIntPredicate)I->getPredicate();
2138  if (ConstantExpr *CE = dyn_cast<ConstantExpr>(unwrap(Inst)))
2139  if (CE->getOpcode() == Instruction::ICmp)
2140  return (LLVMIntPredicate)CE->getPredicate();
2141  return (LLVMIntPredicate)0;
2142 }
2143 
2145  if (FCmpInst *I = dyn_cast<FCmpInst>(unwrap(Inst)))
2146  return (LLVMRealPredicate)I->getPredicate();
2147  if (ConstantExpr *CE = dyn_cast<ConstantExpr>(unwrap(Inst)))
2148  if (CE->getOpcode() == Instruction::FCmp)
2149  return (LLVMRealPredicate)CE->getPredicate();
2150  return (LLVMRealPredicate)0;
2151 }
2152 
2154  if (Instruction *C = dyn_cast<Instruction>(unwrap(Inst)))
2155  return map_to_llvmopcode(C->getOpcode());
2156  return (LLVMOpcode)0;
2157 }
2158 
2160  if (Instruction *C = dyn_cast<Instruction>(unwrap(Inst)))
2161  return wrap(C->clone());
2162  return nullptr;
2163 }
2164 
2165 /*--.. Call and invoke instructions ........................................--*/
2166 
2168  return CallSite(unwrap<Instruction>(Instr)).getNumArgOperands();
2169 }
2170 
2172  return CallSite(unwrap<Instruction>(Instr)).getCallingConv();
2173 }
2174 
2175 void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC) {
2176  return CallSite(unwrap<Instruction>(Instr))
2177  .setCallingConv(static_cast<CallingConv::ID>(CC));
2178 }
2179 
2180 void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
2181  unsigned align) {
2182  CallSite Call = CallSite(unwrap<Instruction>(Instr));
2183  Attribute AlignAttr = Attribute::getWithAlignment(Call->getContext(), align);
2184  Call.addAttribute(index, AlignAttr);
2185 }
2186 
2188  LLVMAttributeRef A) {
2189  CallSite(unwrap<Instruction>(C)).addAttribute(Idx, unwrap(A));
2190 }
2191 
2193  LLVMAttributeIndex Idx) {
2194  auto CS = CallSite(unwrap<Instruction>(C));
2195  auto AS = CS.getAttributes().getAttributes(Idx);
2196  return AS.getNumAttributes();
2197 }
2198 
2201  auto CS = CallSite(unwrap<Instruction>(C));
2202  auto AS = CS.getAttributes().getAttributes(Idx);
2203  for (auto A : AS)
2204  *Attrs++ = wrap(A);
2205 }
2206 
2208  LLVMAttributeIndex Idx,
2209  unsigned KindID) {
2210  return wrap(CallSite(unwrap<Instruction>(C))
2211  .getAttribute(Idx, (Attribute::AttrKind)KindID));
2212 }
2213 
2215  LLVMAttributeIndex Idx,
2216  const char *K, unsigned KLen) {
2217  return wrap(CallSite(unwrap<Instruction>(C))
2218  .getAttribute(Idx, StringRef(K, KLen)));
2219 }
2220 
2222  unsigned KindID) {
2223  CallSite(unwrap<Instruction>(C))
2224  .removeAttribute(Idx, (Attribute::AttrKind)KindID);
2225 }
2226 
2228  const char *K, unsigned KLen) {
2229  CallSite(unwrap<Instruction>(C)).removeAttribute(Idx, StringRef(K, KLen));
2230 }
2231 
2233  return wrap(CallSite(unwrap<Instruction>(Instr)).getCalledValue());
2234 }
2235 
2236 /*--.. Operations on call instructions (only) ..............................--*/
2237 
2239  return unwrap<CallInst>(Call)->isTailCall();
2240 }
2241 
2242 void LLVMSetTailCall(LLVMValueRef Call, LLVMBool isTailCall) {
2243  unwrap<CallInst>(Call)->setTailCall(isTailCall);
2244 }
2245 
2246 /*--.. Operations on invoke instructions (only) ............................--*/
2247 
2249  return wrap(unwrap<InvokeInst>(Invoke)->getNormalDest());
2250 }
2251 
2253  return wrap(unwrap<InvokeInst>(Invoke)->getUnwindDest());
2254 }
2255 
2257  unwrap<InvokeInst>(Invoke)->setNormalDest(unwrap(B));
2258 }
2259 
2261  unwrap<InvokeInst>(Invoke)->setUnwindDest(unwrap(B));
2262 }
2263 
2264 /*--.. Operations on terminators ...........................................--*/
2265 
2267  return unwrap<TerminatorInst>(Term)->getNumSuccessors();
2268 }
2269 
2271  return wrap(unwrap<TerminatorInst>(Term)->getSuccessor(i));
2272 }
2273 
2274 void LLVMSetSuccessor(LLVMValueRef Term, unsigned i, LLVMBasicBlockRef block) {
2275  return unwrap<TerminatorInst>(Term)->setSuccessor(i,unwrap(block));
2276 }
2277 
2278 /*--.. Operations on branch instructions (only) ............................--*/
2279 
2281  return unwrap<BranchInst>(Branch)->isConditional();
2282 }
2283 
2285  return wrap(unwrap<BranchInst>(Branch)->getCondition());
2286 }
2287 
2289  return unwrap<BranchInst>(Branch)->setCondition(unwrap(Cond));
2290 }
2291 
2292 /*--.. Operations on switch instructions (only) ............................--*/
2293 
2295  return wrap(unwrap<SwitchInst>(Switch)->getDefaultDest());
2296 }
2297 
2298 /*--.. Operations on alloca instructions (only) ............................--*/
2299 
2301  return wrap(unwrap<AllocaInst>(Alloca)->getAllocatedType());
2302 }
2303 
2304 /*--.. Operations on gep instructions (only) ...............................--*/
2305 
2307  return unwrap<GetElementPtrInst>(GEP)->isInBounds();
2308 }
2309 
2311  return unwrap<GetElementPtrInst>(GEP)->setIsInBounds(InBounds);
2312 }
2313 
2314 /*--.. Operations on phi nodes .............................................--*/
2315 
2316 void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
2317  LLVMBasicBlockRef *IncomingBlocks, unsigned Count) {
2318  PHINode *PhiVal = unwrap<PHINode>(PhiNode);
2319  for (unsigned I = 0; I != Count; ++I)
2320  PhiVal->addIncoming(unwrap(IncomingValues[I]), unwrap(IncomingBlocks[I]));
2321 }
2322 
2323 unsigned LLVMCountIncoming(LLVMValueRef PhiNode) {
2324  return unwrap<PHINode>(PhiNode)->getNumIncomingValues();
2325 }
2326 
2328  return wrap(unwrap<PHINode>(PhiNode)->getIncomingValue(Index));
2329 }
2330 
2332  return wrap(unwrap<PHINode>(PhiNode)->getIncomingBlock(Index));
2333 }
2334 
2335 /*--.. Operations on extractvalue and insertvalue nodes ....................--*/
2336 
2338  auto *I = unwrap(Inst);
2339  if (auto *GEP = dyn_cast<GetElementPtrInst>(I))
2340  return GEP->getNumIndices();
2341  if (auto *EV = dyn_cast<ExtractValueInst>(I))
2342  return EV->getNumIndices();
2343  if (auto *IV = dyn_cast<InsertValueInst>(I))
2344  return IV->getNumIndices();
2346  "LLVMGetNumIndices applies only to extractvalue and insertvalue!");
2347 }
2348 
2349 const unsigned *LLVMGetIndices(LLVMValueRef Inst) {
2350  auto *I = unwrap(Inst);
2351  if (auto *EV = dyn_cast<ExtractValueInst>(I))
2352  return EV->getIndices().data();
2353  if (auto *IV = dyn_cast<InsertValueInst>(I))
2354  return IV->getIndices().data();
2356  "LLVMGetIndices applies only to extractvalue and insertvalue!");
2357 }
2358 
2359 
2360 /*===-- Instruction builders ----------------------------------------------===*/
2361 
2363  return wrap(new IRBuilder<>(*unwrap(C)));
2364 }
2365 
2368 }
2369 
2371  LLVMValueRef Instr) {
2372  BasicBlock *BB = unwrap(Block);
2373  auto I = Instr ? unwrap<Instruction>(Instr)->getIterator() : BB->end();
2374  unwrap(Builder)->SetInsertPoint(BB, I);
2375 }
2376 
2378  Instruction *I = unwrap<Instruction>(Instr);
2379  unwrap(Builder)->SetInsertPoint(I->getParent(), I->getIterator());
2380 }
2381 
2383  BasicBlock *BB = unwrap(Block);
2384  unwrap(Builder)->SetInsertPoint(BB);
2385 }
2386 
2388  return wrap(unwrap(Builder)->GetInsertBlock());
2389 }
2390 
2392  unwrap(Builder)->ClearInsertionPoint();
2393 }
2394 
2396  unwrap(Builder)->Insert(unwrap<Instruction>(Instr));
2397 }
2398 
2400  const char *Name) {
2401  unwrap(Builder)->Insert(unwrap<Instruction>(Instr), Name);
2402 }
2403 
2405  delete unwrap(Builder);
2406 }
2407 
2408 /*--.. Metadata builders ...................................................--*/
2409 
2411  MDNode *Loc =
2412  L ? cast<MDNode>(unwrap<MetadataAsValue>(L)->getMetadata()) : nullptr;
2413  unwrap(Builder)->SetCurrentDebugLocation(DebugLoc(Loc));
2414 }
2415 
2417  LLVMContext &Context = unwrap(Builder)->getContext();
2418  return wrap(MetadataAsValue::get(
2419  Context, unwrap(Builder)->getCurrentDebugLocation().getAsMDNode()));
2420 }
2421 
2423  unwrap(Builder)->SetInstDebugLocation(unwrap<Instruction>(Inst));
2424 }
2425 
2426 
2427 /*--.. Instruction builders ................................................--*/
2428 
2430  return wrap(unwrap(B)->CreateRetVoid());
2431 }
2432 
2434  return wrap(unwrap(B)->CreateRet(unwrap(V)));
2435 }
2436 
2438  unsigned N) {
2439  return wrap(unwrap(B)->CreateAggregateRet(unwrap(RetVals), N));
2440 }
2441 
2443  return wrap(unwrap(B)->CreateBr(unwrap(Dest)));
2444 }
2445 
2447  LLVMBasicBlockRef Then, LLVMBasicBlockRef Else) {
2448  return wrap(unwrap(B)->CreateCondBr(unwrap(If), unwrap(Then), unwrap(Else)));
2449 }
2450 
2452  LLVMBasicBlockRef Else, unsigned NumCases) {
2453  return wrap(unwrap(B)->CreateSwitch(unwrap(V), unwrap(Else), NumCases));
2454 }
2455 
2457  unsigned NumDests) {
2458  return wrap(unwrap(B)->CreateIndirectBr(unwrap(Addr), NumDests));
2459 }
2460 
2462  LLVMValueRef *Args, unsigned NumArgs,
2464  const char *Name) {
2465  return wrap(unwrap(B)->CreateInvoke(unwrap(Fn), unwrap(Then), unwrap(Catch),
2466  makeArrayRef(unwrap(Args), NumArgs),
2467  Name));
2468 }
2469 
2471  LLVMValueRef PersFn, unsigned NumClauses,
2472  const char *Name) {
2473  // The personality used to live on the landingpad instruction, but now it
2474  // lives on the parent function. For compatibility, take the provided
2475  // personality and put it on the parent function.
2476  if (PersFn)
2477  unwrap(B)->GetInsertBlock()->getParent()->setPersonalityFn(
2478  cast<Function>(unwrap(PersFn)));
2479  return wrap(unwrap(B)->CreateLandingPad(unwrap(Ty), NumClauses, Name));
2480 }
2481 
2483  return wrap(unwrap(B)->CreateResume(unwrap(Exn)));
2484 }
2485 
2487  return wrap(unwrap(B)->CreateUnreachable());
2488 }
2489 
2491  LLVMBasicBlockRef Dest) {
2492  unwrap<SwitchInst>(Switch)->addCase(unwrap<ConstantInt>(OnVal), unwrap(Dest));
2493 }
2494 
2496  unwrap<IndirectBrInst>(IndirectBr)->addDestination(unwrap(Dest));
2497 }
2498 
2499 unsigned LLVMGetNumClauses(LLVMValueRef LandingPad) {
2500  return unwrap<LandingPadInst>(LandingPad)->getNumClauses();
2501 }
2502 
2503 LLVMValueRef LLVMGetClause(LLVMValueRef LandingPad, unsigned Idx) {
2504  return wrap(unwrap<LandingPadInst>(LandingPad)->getClause(Idx));
2505 }
2506 
2507 void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal) {
2508  unwrap<LandingPadInst>(LandingPad)->
2509  addClause(cast<Constant>(unwrap(ClauseVal)));
2510 }
2511 
2513  return unwrap<LandingPadInst>(LandingPad)->isCleanup();
2514 }
2515 
2516 void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val) {
2517  unwrap<LandingPadInst>(LandingPad)->setCleanup(Val);
2518 }
2519 
2520 /*--.. Arithmetic ..........................................................--*/
2521 
2523  const char *Name) {
2524  return wrap(unwrap(B)->CreateAdd(unwrap(LHS), unwrap(RHS), Name));
2525 }
2526 
2528  const char *Name) {
2529  return wrap(unwrap(B)->CreateNSWAdd(unwrap(LHS), unwrap(RHS), Name));
2530 }
2531 
2533  const char *Name) {
2534  return wrap(unwrap(B)->CreateNUWAdd(unwrap(LHS), unwrap(RHS), Name));
2535 }
2536 
2538  const char *Name) {
2539  return wrap(unwrap(B)->CreateFAdd(unwrap(LHS), unwrap(RHS), Name));
2540 }
2541 
2543  const char *Name) {
2544  return wrap(unwrap(B)->CreateSub(unwrap(LHS), unwrap(RHS), Name));
2545 }
2546 
2548  const char *Name) {
2549  return wrap(unwrap(B)->CreateNSWSub(unwrap(LHS), unwrap(RHS), Name));
2550 }
2551 
2553  const char *Name) {
2554  return wrap(unwrap(B)->CreateNUWSub(unwrap(LHS), unwrap(RHS), Name));
2555 }
2556 
2558  const char *Name) {
2559  return wrap(unwrap(B)->CreateFSub(unwrap(LHS), unwrap(RHS), Name));
2560 }
2561 
2563  const char *Name) {
2564  return wrap(unwrap(B)->CreateMul(unwrap(LHS), unwrap(RHS), Name));
2565 }
2566 
2568  const char *Name) {
2569  return wrap(unwrap(B)->CreateNSWMul(unwrap(LHS), unwrap(RHS), Name));
2570 }
2571 
2573  const char *Name) {
2574  return wrap(unwrap(B)->CreateNUWMul(unwrap(LHS), unwrap(RHS), Name));
2575 }
2576 
2578  const char *Name) {
2579  return wrap(unwrap(B)->CreateFMul(unwrap(LHS), unwrap(RHS), Name));
2580 }
2581 
2583  const char *Name) {
2584  return wrap(unwrap(B)->CreateUDiv(unwrap(LHS), unwrap(RHS), Name));
2585 }
2586 
2588  LLVMValueRef RHS, const char *Name) {
2589  return wrap(unwrap(B)->CreateExactUDiv(unwrap(LHS), unwrap(RHS), Name));
2590 }
2591 
2593  const char *Name) {
2594  return wrap(unwrap(B)->CreateSDiv(unwrap(LHS), unwrap(RHS), Name));
2595 }
2596 
2598  LLVMValueRef RHS, const char *Name) {
2599  return wrap(unwrap(B)->CreateExactSDiv(unwrap(LHS), unwrap(RHS), Name));
2600 }
2601 
2603  const char *Name) {
2604  return wrap(unwrap(B)->CreateFDiv(unwrap(LHS), unwrap(RHS), Name));
2605 }
2606 
2608  const char *Name) {
2609  return wrap(unwrap(B)->CreateURem(unwrap(LHS), unwrap(RHS), Name));
2610 }
2611 
2613  const char *Name) {
2614  return wrap(unwrap(B)->CreateSRem(unwrap(LHS), unwrap(RHS), Name));
2615 }
2616 
2618  const char *Name) {
2619  return wrap(unwrap(B)->CreateFRem(unwrap(LHS), unwrap(RHS), Name));
2620 }
2621 
2623  const char *Name) {
2624  return wrap(unwrap(B)->CreateShl(unwrap(LHS), unwrap(RHS), Name));
2625 }
2626 
2628  const char *Name) {
2629  return wrap(unwrap(B)->CreateLShr(unwrap(LHS), unwrap(RHS), Name));
2630 }
2631 
2633  const char *Name) {
2634  return wrap(unwrap(B)->CreateAShr(unwrap(LHS), unwrap(RHS), Name));
2635 }
2636 
2638  const char *Name) {
2639  return wrap(unwrap(B)->CreateAnd(unwrap(LHS), unwrap(RHS), Name));
2640 }
2641 
2643  const char *Name) {
2644  return wrap(unwrap(B)->CreateOr(unwrap(LHS), unwrap(RHS), Name));
2645 }
2646 
2648  const char *Name) {
2649  return wrap(unwrap(B)->CreateXor(unwrap(LHS), unwrap(RHS), Name));
2650 }
2651 
2653  LLVMValueRef LHS, LLVMValueRef RHS,
2654  const char *Name) {
2655  return wrap(unwrap(B)->CreateBinOp(Instruction::BinaryOps(map_from_llvmopcode(Op)), unwrap(LHS),
2656  unwrap(RHS), Name));
2657 }
2658 
2660  return wrap(unwrap(B)->CreateNeg(unwrap(V), Name));
2661 }
2662 
2664  const char *Name) {
2665  return wrap(unwrap(B)->CreateNSWNeg(unwrap(V), Name));
2666 }
2667 
2669  const char *Name) {
2670  return wrap(unwrap(B)->CreateNUWNeg(unwrap(V), Name));
2671 }
2672 
2674  return wrap(unwrap(B)->CreateFNeg(unwrap(V), Name));
2675 }
2676 
2678  return wrap(unwrap(B)->CreateNot(unwrap(V), Name));
2679 }
2680 
2681 /*--.. Memory ..............................................................--*/
2682 
2684  const char *Name) {
2685  Type* ITy = Type::getInt32Ty(unwrap(B)->GetInsertBlock()->getContext());
2686  Constant* AllocSize = ConstantExpr::getSizeOf(unwrap(Ty));
2687  AllocSize = ConstantExpr::getTruncOrBitCast(AllocSize, ITy);
2688  Instruction* Malloc = CallInst::CreateMalloc(unwrap(B)->GetInsertBlock(),
2689  ITy, unwrap(Ty), AllocSize,
2690  nullptr, nullptr, "");
2691  return wrap(unwrap(B)->Insert(Malloc, Twine(Name)));
2692 }
2693 
2695  LLVMValueRef Val, const char *Name) {
2696  Type* ITy = Type::getInt32Ty(unwrap(B)->GetInsertBlock()->getContext());
2697  Constant* AllocSize = ConstantExpr::getSizeOf(unwrap(Ty));
2698  AllocSize = ConstantExpr::getTruncOrBitCast(AllocSize, ITy);
2699  Instruction* Malloc = CallInst::CreateMalloc(unwrap(B)->GetInsertBlock(),
2700  ITy, unwrap(Ty), AllocSize,
2701  unwrap(Val), nullptr, "");
2702  return wrap(unwrap(B)->Insert(Malloc, Twine(Name)));
2703 }
2704 
2706  const char *Name) {
2707  return wrap(unwrap(B)->CreateAlloca(unwrap(Ty), nullptr, Name));
2708 }
2709 
2711  LLVMValueRef Val, const char *Name) {
2712  return wrap(unwrap(B)->CreateAlloca(unwrap(Ty), unwrap(Val), Name));
2713 }
2714 
2716  return wrap(unwrap(B)->Insert(
2717  CallInst::CreateFree(unwrap(PointerVal), unwrap(B)->GetInsertBlock())));
2718 }
2719 
2721  const char *Name) {
2722  return wrap(unwrap(B)->CreateLoad(unwrap(PointerVal), Name));
2723 }
2724 
2726  LLVMValueRef PointerVal) {
2727  return wrap(unwrap(B)->CreateStore(unwrap(Val), unwrap(PointerVal)));
2728 }
2729 
2731  switch (Ordering) {
2741  }
2742 
2743  llvm_unreachable("Invalid LLVMAtomicOrdering value!");
2744 }
2745 
2747  switch (Ordering) {
2757  }
2758 
2759  llvm_unreachable("Invalid AtomicOrdering value!");
2760 }
2761 
2762 // TODO: Should this and other atomic instructions support building with
2763 // "syncscope"?
2765  LLVMBool isSingleThread, const char *Name) {
2766  return wrap(
2767  unwrap(B)->CreateFence(mapFromLLVMOrdering(Ordering),
2768  isSingleThread ? SyncScope::SingleThread
2770  Name));
2771 }
2772 
2774  LLVMValueRef *Indices, unsigned NumIndices,
2775  const char *Name) {
2776  ArrayRef<Value *> IdxList(unwrap(Indices), NumIndices);
2777  return wrap(unwrap(B)->CreateGEP(nullptr, unwrap(Pointer), IdxList, Name));
2778 }
2779 
2781  LLVMValueRef *Indices, unsigned NumIndices,
2782  const char *Name) {
2783  ArrayRef<Value *> IdxList(unwrap(Indices), NumIndices);
2784  return wrap(
2785  unwrap(B)->CreateInBoundsGEP(nullptr, unwrap(Pointer), IdxList, Name));
2786 }
2787 
2789  unsigned Idx, const char *Name) {
2790  return wrap(unwrap(B)->CreateStructGEP(nullptr, unwrap(Pointer), Idx, Name));
2791 }
2792 
2794  const char *Name) {
2795  return wrap(unwrap(B)->CreateGlobalString(Str, Name));
2796 }
2797 
2799  const char *Name) {
2800  return wrap(unwrap(B)->CreateGlobalStringPtr(Str, Name));
2801 }
2802 
2804  Value *P = unwrap<Value>(MemAccessInst);
2805  if (LoadInst *LI = dyn_cast<LoadInst>(P))
2806  return LI->isVolatile();
2807  return cast<StoreInst>(P)->isVolatile();
2808 }
2809 
2811  Value *P = unwrap<Value>(MemAccessInst);
2812  if (LoadInst *LI = dyn_cast<LoadInst>(P))
2813  return LI->setVolatile(isVolatile);
2814  return cast<StoreInst>(P)->setVolatile(isVolatile);
2815 }
2816 
2818  Value *P = unwrap<Value>(MemAccessInst);
2819  AtomicOrdering O;
2820  if (LoadInst *LI = dyn_cast<LoadInst>(P))
2821  O = LI->getOrdering();
2822  else
2823  O = cast<StoreInst>(P)->getOrdering();
2824  return mapToLLVMOrdering(O);
2825 }
2826 
2827 void LLVMSetOrdering(LLVMValueRef MemAccessInst, LLVMAtomicOrdering Ordering) {
2828  Value *P = unwrap<Value>(MemAccessInst);
2829  AtomicOrdering O = mapFromLLVMOrdering(Ordering);
2830 
2831  if (LoadInst *LI = dyn_cast<LoadInst>(P))
2832  return LI->setOrdering(O);
2833  return cast<StoreInst>(P)->setOrdering(O);
2834 }
2835 
2836 /*--.. Casts ...............................................................--*/
2837 
2839  LLVMTypeRef DestTy, const char *Name) {
2840  return wrap(unwrap(B)->CreateTrunc(unwrap(Val), unwrap(DestTy), Name));
2841 }
2842 
2844  LLVMTypeRef DestTy, const char *Name) {
2845  return wrap(unwrap(B)->CreateZExt(unwrap(Val), unwrap(DestTy), Name));
2846 }
2847 
2849  LLVMTypeRef DestTy, const char *Name) {
2850  return wrap(unwrap(B)->CreateSExt(unwrap(Val), unwrap(DestTy), Name));
2851 }
2852 
2854  LLVMTypeRef DestTy, const char *Name) {
2855  return wrap(unwrap(B)->CreateFPToUI(unwrap(Val), unwrap(DestTy), Name));
2856 }
2857 
2859  LLVMTypeRef DestTy, const char *Name) {
2860  return wrap(unwrap(B)->CreateFPToSI(unwrap(Val), unwrap(DestTy), Name));
2861 }
2862 
2864  LLVMTypeRef DestTy, const char *Name) {
2865  return wrap(unwrap(B)->CreateUIToFP(unwrap(Val), unwrap(DestTy), Name));
2866 }
2867 
2869  LLVMTypeRef DestTy, const char *Name) {
2870  return wrap(unwrap(B)->CreateSIToFP(unwrap(Val), unwrap(DestTy), Name));
2871 }
2872 
2874  LLVMTypeRef DestTy, const char *Name) {
2875  return wrap(unwrap(B)->CreateFPTrunc(unwrap(Val), unwrap(DestTy), Name));
2876 }
2877 
2879  LLVMTypeRef DestTy, const char *Name) {
2880  return wrap(unwrap(B)->CreateFPExt(unwrap(Val), unwrap(DestTy), Name));
2881 }
2882 
2884  LLVMTypeRef DestTy, const char *Name) {
2885  return wrap(unwrap(B)->CreatePtrToInt(unwrap(Val), unwrap(DestTy), Name));
2886 }
2887 
2889  LLVMTypeRef DestTy, const char *Name) {
2890  return wrap(unwrap(B)->CreateIntToPtr(unwrap(Val), unwrap(DestTy), Name));
2891 }
2892 
2894  LLVMTypeRef DestTy, const char *Name) {
2895  return wrap(unwrap(B)->CreateBitCast(unwrap(Val), unwrap(DestTy), Name));
2896 }
2897 
2899  LLVMTypeRef DestTy, const char *Name) {
2900  return wrap(unwrap(B)->CreateAddrSpaceCast(unwrap(Val), unwrap(DestTy), Name));
2901 }
2902 
2904  LLVMTypeRef DestTy, const char *Name) {
2905  return wrap(unwrap(B)->CreateZExtOrBitCast(unwrap(Val), unwrap(DestTy),
2906  Name));
2907 }
2908 
2910  LLVMTypeRef DestTy, const char *Name) {
2911  return wrap(unwrap(B)->CreateSExtOrBitCast(unwrap(Val), unwrap(DestTy),
2912  Name));
2913 }
2914 
2916  LLVMTypeRef DestTy, const char *Name) {
2917  return wrap(unwrap(B)->CreateTruncOrBitCast(unwrap(Val), unwrap(DestTy),
2918  Name));
2919 }
2920 
2922  LLVMTypeRef DestTy, const char *Name) {
2923  return wrap(unwrap(B)->CreateCast(Instruction::CastOps(map_from_llvmopcode(Op)), unwrap(Val),
2924  unwrap(DestTy), Name));
2925 }
2926 
2928  LLVMTypeRef DestTy, const char *Name) {
2929  return wrap(unwrap(B)->CreatePointerCast(unwrap(Val), unwrap(DestTy), Name));
2930 }
2931 
2933  LLVMTypeRef DestTy, const char *Name) {
2934  return wrap(unwrap(B)->CreateIntCast(unwrap(Val), unwrap(DestTy),
2935  /*isSigned*/true, Name));
2936 }
2937 
2939  LLVMTypeRef DestTy, const char *Name) {
2940  return wrap(unwrap(B)->CreateFPCast(unwrap(Val), unwrap(DestTy), Name));
2941 }
2942 
2943 /*--.. Comparisons .........................................................--*/
2944 
2946  LLVMValueRef LHS, LLVMValueRef RHS,
2947  const char *Name) {
2948  return wrap(unwrap(B)->CreateICmp(static_cast<ICmpInst::Predicate>(Op),
2949  unwrap(LHS), unwrap(RHS), Name));
2950 }
2951 
2953  LLVMValueRef LHS, LLVMValueRef RHS,
2954  const char *Name) {
2955  return wrap(unwrap(B)->CreateFCmp(static_cast<FCmpInst::Predicate>(Op),
2956  unwrap(LHS), unwrap(RHS), Name));
2957 }
2958 
2959 /*--.. Miscellaneous instructions ..........................................--*/
2960 
2962  return wrap(unwrap(B)->CreatePHI(unwrap(Ty), 0, Name));
2963 }
2964 
2966  LLVMValueRef *Args, unsigned NumArgs,
2967  const char *Name) {
2968  return wrap(unwrap(B)->CreateCall(unwrap(Fn),
2969  makeArrayRef(unwrap(Args), NumArgs),
2970  Name));
2971 }
2972 
2974  LLVMValueRef Then, LLVMValueRef Else,
2975  const char *Name) {
2976  return wrap(unwrap(B)->CreateSelect(unwrap(If), unwrap(Then), unwrap(Else),
2977  Name));
2978 }
2979 
2981  LLVMTypeRef Ty, const char *Name) {
2982  return wrap(unwrap(B)->CreateVAArg(unwrap(List), unwrap(Ty), Name));
2983 }
2984 
2986  LLVMValueRef Index, const char *Name) {
2987  return wrap(unwrap(B)->CreateExtractElement(unwrap(VecVal), unwrap(Index),
2988  Name));
2989 }
2990 
2992  LLVMValueRef EltVal, LLVMValueRef Index,
2993  const char *Name) {
2994  return wrap(unwrap(B)->CreateInsertElement(unwrap(VecVal), unwrap(EltVal),
2995  unwrap(Index), Name));
2996 }
2997 
3000  const char *Name) {
3001  return wrap(unwrap(B)->CreateShuffleVector(unwrap(V1), unwrap(V2),
3002  unwrap(Mask), Name));
3003 }
3004 
3006  unsigned Index, const char *Name) {
3007  return wrap(unwrap(B)->CreateExtractValue(unwrap(AggVal), Index, Name));
3008 }
3009 
3011  LLVMValueRef EltVal, unsigned Index,
3012  const char *Name) {
3013  return wrap(unwrap(B)->CreateInsertValue(unwrap(AggVal), unwrap(EltVal),
3014  Index, Name));
3015 }
3016 
3018  const char *Name) {
3019  return wrap(unwrap(B)->CreateIsNull(unwrap(Val), Name));
3020 }
3021 
3023  const char *Name) {
3024  return wrap(unwrap(B)->CreateIsNotNull(unwrap(Val), Name));
3025 }
3026 
3028  LLVMValueRef RHS, const char *Name) {
3029  return wrap(unwrap(B)->CreatePtrDiff(unwrap(LHS), unwrap(RHS), Name));
3030 }
3031 
3033  LLVMValueRef PTR, LLVMValueRef Val,
3034  LLVMAtomicOrdering ordering,
3035  LLVMBool singleThread) {
3036  AtomicRMWInst::BinOp intop;
3037  switch (op) {
3038  case LLVMAtomicRMWBinOpXchg: intop = AtomicRMWInst::Xchg; break;
3039  case LLVMAtomicRMWBinOpAdd: intop = AtomicRMWInst::Add; break;
3040  case LLVMAtomicRMWBinOpSub: intop = AtomicRMWInst::Sub; break;
3041  case LLVMAtomicRMWBinOpAnd: intop = AtomicRMWInst::And; break;
3042  case LLVMAtomicRMWBinOpNand: intop = AtomicRMWInst::Nand; break;
3043  case LLVMAtomicRMWBinOpOr: intop = AtomicRMWInst::Or; break;
3044  case LLVMAtomicRMWBinOpXor: intop = AtomicRMWInst::Xor; break;
3045  case LLVMAtomicRMWBinOpMax: intop = AtomicRMWInst::Max; break;
3046  case LLVMAtomicRMWBinOpMin: intop = AtomicRMWInst::Min; break;
3047  case LLVMAtomicRMWBinOpUMax: intop = AtomicRMWInst::UMax; break;
3048  case LLVMAtomicRMWBinOpUMin: intop = AtomicRMWInst::UMin; break;
3049  }
3050  return wrap(unwrap(B)->CreateAtomicRMW(intop, unwrap(PTR), unwrap(Val),
3051  mapFromLLVMOrdering(ordering), singleThread ? SyncScope::SingleThread
3052  : SyncScope::System));
3053 }
3054 
3056  LLVMValueRef Cmp, LLVMValueRef New,
3057  LLVMAtomicOrdering SuccessOrdering,
3058  LLVMAtomicOrdering FailureOrdering,
3059  LLVMBool singleThread) {
3060 
3061  return wrap(unwrap(B)->CreateAtomicCmpXchg(unwrap(Ptr), unwrap(Cmp),
3062  unwrap(New), mapFromLLVMOrdering(SuccessOrdering),
3063  mapFromLLVMOrdering(FailureOrdering),
3064  singleThread ? SyncScope::SingleThread : SyncScope::System));
3065 }
3066 
3067 
3069  Value *P = unwrap<Value>(AtomicInst);
3070 
3071  if (AtomicRMWInst *I = dyn_cast<AtomicRMWInst>(P))
3072  return I->getSyncScopeID() == SyncScope::SingleThread;
3073  return cast<AtomicCmpXchgInst>(P)->getSyncScopeID() ==
3075 }
3076 
3078  Value *P = unwrap<Value>(AtomicInst);
3080 
3081  if (AtomicRMWInst *I = dyn_cast<AtomicRMWInst>(P))
3082  return I->setSyncScopeID(SSID);
3083  return cast<AtomicCmpXchgInst>(P)->setSyncScopeID(SSID);
3084 }
3085 
3087  Value *P = unwrap<Value>(CmpXchgInst);
3088  return mapToLLVMOrdering(cast<AtomicCmpXchgInst>(P)->getSuccessOrdering());
3089 }
3090 
3092  LLVMAtomicOrdering Ordering) {
3093  Value *P = unwrap<Value>(CmpXchgInst);
3094  AtomicOrdering O = mapFromLLVMOrdering(Ordering);
3095 
3096  return cast<AtomicCmpXchgInst>(P)->setSuccessOrdering(O);
3097 }
3098 
3100  Value *P = unwrap<Value>(CmpXchgInst);
3101  return mapToLLVMOrdering(cast<AtomicCmpXchgInst>(P)->getFailureOrdering());
3102 }
3103 
3105  LLVMAtomicOrdering Ordering) {
3106  Value *P = unwrap<Value>(CmpXchgInst);
3107  AtomicOrdering O = mapFromLLVMOrdering(Ordering);
3108 
3109  return cast<AtomicCmpXchgInst>(P)->setFailureOrdering(O);
3110 }
3111 
3112 /*===-- Module providers --------------------------------------------------===*/
3113 
3116  return reinterpret_cast<LLVMModuleProviderRef>(M);
3117 }
3118 
3120  delete unwrap(MP);
3121 }
3122 
3123 
3124 /*===-- Memory buffers ----------------------------------------------------===*/
3125 
3127  const char *Path,
3128  LLVMMemoryBufferRef *OutMemBuf,
3129  char **OutMessage) {
3130 
3132  if (std::error_code EC = MBOrErr.getError()) {
3133  *OutMessage = strdup(EC.message().c_str());
3134  return 1;
3135  }
3136  *OutMemBuf = wrap(MBOrErr.get().release());
3137  return 0;
3138 }
3139 
3141  char **OutMessage) {
3143  if (std::error_code EC = MBOrErr.getError()) {
3144  *OutMessage = strdup(EC.message().c_str());
3145  return 1;
3146  }
3147  *OutMemBuf = wrap(MBOrErr.get().release());
3148  return 0;
3149 }
3150 
3152  const char *InputData,
3153  size_t InputDataLength,
3154  const char *BufferName,
3155  LLVMBool RequiresNullTerminator) {
3156 
3157  return wrap(MemoryBuffer::getMemBuffer(StringRef(InputData, InputDataLength),
3158  StringRef(BufferName),
3159  RequiresNullTerminator).release());
3160 }
3161 
3163  const char *InputData,
3164  size_t InputDataLength,
3165  const char *BufferName) {
3166 
3167  return wrap(
3168  MemoryBuffer::getMemBufferCopy(StringRef(InputData, InputDataLength),
3169  StringRef(BufferName)).release());
3170 }
3171 
3173  return unwrap(MemBuf)->getBufferStart();
3174 }
3175 
3177  return unwrap(MemBuf)->getBufferSize();
3178 }
3179 
3181  delete unwrap(MemBuf);
3182 }
3183 
3184 /*===-- Pass Registry -----------------------------------------------------===*/
3185 
3188 }
3189 
3190 /*===-- Pass Manager ------------------------------------------------------===*/
3191 
3193  return wrap(new legacy::PassManager());
3194 }
3195 
3197  return wrap(new legacy::FunctionPassManager(unwrap(M)));
3198 }
3199 
3202  reinterpret_cast<LLVMModuleRef>(P));
3203 }
3204 
3206  return unwrap<legacy::PassManager>(PM)->run(*unwrap(M));
3207 }
3208 
3210  return unwrap<legacy::FunctionPassManager>(FPM)->doInitialization();
3211 }
3212 
3214  return unwrap<legacy::FunctionPassManager>(FPM)->run(*unwrap<Function>(F));
3215 }
3216 
3218  return unwrap<legacy::FunctionPassManager>(FPM)->doFinalization();
3219 }
3220 
3222  delete unwrap(PM);
3223 }
3224 
3225 /*===-- Threading ------------------------------------------------------===*/
3226 
3228  return LLVMIsMultithreaded();
3229 }
3230 
3232 }
3233 
3235  return llvm_is_multithreaded();
3236 }
LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1226
LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty, const char *AsmString, const char *Constraints, LLVMBool HasSideEffects, LLVMBool IsAlignStack)
Definition: Core.cpp:1458
Subtract a value and return the old one.
Definition: Core.h:312
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:3172
static Constant * getFPTrunc(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:1584
void LLVMDisposeBuilder(LLVMBuilderRef Builder)
Definition: Core.cpp:2404
uint64_t CallInst * C
unsigned LLVMGetMDNodeNumOperands(LLVMValueRef V)
Obtain the number of operands from an MDNode value.
Definition: Core.cpp:905
X86 MMX.
Definition: Core.h:156
use_iterator use_end()
Definition: Value.h:348
LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy, LLVMValueRef *ConstantVals, unsigned Count)
Create a non-anonymous ConstantStruct from values.
Definition: Core.cpp:1073
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:2159
LLVMRealPredicate LLVMGetFCmpPredicate(LLVMValueRef Inst)
Obtain the float predicate of an instruction.
Definition: Core.cpp:2144
LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C, LLVMBasicBlockRef BBRef, const char *Name)
Insert a basic block in a function before another basic block.
Definition: Core.cpp:2061
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:543
void LLVMGetParams(LLVMValueRef FnRef, LLVMValueRef *ParamRefs)
Obtain the parameters in a function.
Definition: Core.cpp:1927
LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar)
Definition: Core.cpp:1699
LLVMValueRef LLVMBuildICmp(LLVMBuilderRef B, LLVMIntPredicate Op, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:2945
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:2451
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:3104
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:604
static Constant * getFAdd(Constant *C1, Constant *C2)
Definition: Constants.cpp:2122
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:1832
static MDNode * extractMDNode(MetadataAsValue *MAV)
Definition: Core.cpp:698
*p = old <signed v ? old : v
Definition: Instructions.h:707
LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef B, LLVMTypeRef Ty, LLVMValueRef Val, const char *Name)
Definition: Core.cpp:2710
LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1262
LLVMValueRef LLVMBuildZExt(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:2843
static LLVMValueRef getMDNodeOperandImpl(LLVMContext &Context, const MDNode *N, unsigned Index)
Definition: Core.cpp:765
LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn)
Obtain the basic block that corresponds to the entry point of a function.
Definition: Core.cpp:2015
LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M)
Obtain an iterator to the last Function in a Module.
Definition: Core.cpp:1804
LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType)
Definition: Core.cpp:1368
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:314
LLVMValueRef LLVMBuildAtomicCmpXchg(LLVMBuilderRef B, LLVMValueRef Ptr, LLVMValueRef Cmp, LLVMValueRef New, LLVMAtomicOrdering SuccessOrdering, LLVMAtomicOrdering FailureOrdering, LLVMBool singleThread)
Definition: Core.cpp:3055
LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1210
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:353
LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1221
void LLVMSetSection(LLVMValueRef Global, const char *Section)
Definition: Core.cpp:1577
MDNode * getOperand(unsigned i) const
Definition: Metadata.cpp:1073
unsigned LLVMAttributeIndex
Definition: Core.h:350
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:3162
LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count)
Obtain a MDNode value from the global context.
Definition: Core.cpp:878
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
Definition: Compiler.h:449
provides both an Acquire and a Release barrier (for fences and operations which both read and write m...
Definition: Core.h:295
const char * LLVMGetAsString(LLVMValueRef C, size_t *Length)
Get the given constant data sequential as a string.
Definition: Core.cpp:1047
LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index)
Obtain an incoming value to a PHI node as an LLVMValueRef.
Definition: Core.cpp:2327
static Constant * getNSWAdd(Constant *C1, Constant *C2)
Definition: Constants.h:950
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:1115
void LLVMSetSuccessor(LLVMValueRef Term, unsigned i, LLVMBasicBlockRef block)
Update the specified successor to point at the provided block.
Definition: Core.cpp:2274
LLVMValueRef LLVMBuildAdd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:2522
LLVMBuilderRef LLVMCreateBuilder(void)
Definition: Core.cpp:2366
Obsolete.
Definition: Core.h:174
LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg)
Obtain the next parameter to a function.
Definition: Core.cpp:1959
2: 32-bit floating point type
Definition: Type.h:59
iterator end()
Definition: Function.h:590
Same, but only replaced by something equivalent.
Definition: GlobalValue.h:54
LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:2532
static MDString * get(LLVMContext &Context, StringRef Str)
Definition: Metadata.cpp:446
LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer, unsigned Idx, const char *Name)
Definition: Core.cpp:2788
LLVMAttributeRef LLVMGetEnumAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx, unsigned KindID)
Definition: Core.cpp:1889
LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name)
Definition: Core.cpp:1659
LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy)
Determine whether a structure is opaque.
Definition: Core.cpp:559
LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRange(const char *InputData, size_t InputDataLength, const char *BufferName, LLVMBool RequiresNullTerminator)
Definition: Core.cpp:3151
LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn)
Obtain the first parameter to a function.
Definition: Core.cpp:1943
void initializeSafepointIRVerifierPass(PassRegistry &)
void(*)(LLVMContext *Context, void *OpaqueHandle) YieldCallbackTy
Defines the type of a yield callback.
Definition: LLVMContext.h:175
LLVMValueRef LLVMBuildSExt(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:2848
LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee, const char *Name)
Definition: Core.cpp:1776
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:1115
LLVMBool LLVMHasUnnamedAddr(LLVMValueRef Global)
Definition: Core.cpp:1601
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:3231
LLVMOpcode
Definition: Core.h:57
LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char Str[], unsigned SLen)
Definition: Core.cpp:988
void LLVMSetValueName(LLVMValueRef Val, const char *Name)
Set the string name of a value.
Definition: Core.cpp:657
static Constant * getAddrSpaceCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:1690
Metadata * getMetadata() const
Definition: Metadata.h:189
LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType)
Definition: Core.cpp:1348
void clearGC()
Definition: Function.cpp:454
const char * LLVMGetGC(LLVMValueRef Fn)
Obtain the name of the garbage collector to use during code generation.
Definition: Core.cpp:1859
LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef P)
Deprecated: Use LLVMCreateFunctionPassManagerForModule instead.
Definition: Core.cpp:3200
LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name)
Definition: Core.cpp:1645
LLVMTypeRef LLVMGetAllocatedType(LLVMValueRef Alloca)
Obtain the type that is being allocated by the alloca instruction.
Definition: Core.cpp:2300
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:456
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:2433
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:2035
LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path, LLVMMemoryBufferRef *OutMemBuf, char **OutMessage)
Definition: Core.cpp:3126
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:3192
void addOperand(MDNode *M)
Definition: Metadata.cpp:1079
LLVMTypeRef LLVMFP128Type(void)
Definition: Core.cpp:468
LLVMValueRef LLVMGetClause(LLVMValueRef LandingPad, unsigned Idx)
Definition: Core.cpp:2503
static Constant * getExactSDiv(Constant *C1, Constant *C2)
Definition: Constants.h:982
void setGC(std::string Str)
Definition: Function.cpp:449
LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:2853
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:1186
unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy)
Obtain the number of elements in a vector type.
Definition: Core.cpp:608
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:1665
LLVMBool LLVMIsAtomicSingleThread(LLVMValueRef AtomicInst)
Definition: Core.cpp:3068
float convertToFloat() const
Definition: APFloat.h:1098
static Constant * getExtractElement(Constant *Vec, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
Definition: Constants.cpp:1980
const char * LLVMGetDataLayoutStr(LLVMModuleRef M)
Obtain the data layout for a module.
Definition: Core.cpp:239
LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef B, LLVMValueRef If, LLVMBasicBlockRef Then, LLVMBasicBlockRef Else)
Definition: Core.cpp:2446
Like Internal, but omit from symbol table.
Definition: GlobalValue.h:57
LLVMTypeRef LLVMX86MMXType(void)
Definition: Core.cpp:474
*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:2673
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:728
LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:2915
struct LLVMOpaquePassRegistry * LLVMPassRegistryRef
Definition: Types.h:117
unsigned LLVMGetNumArgOperands(LLVMValueRef Instr)
Obtain the argument count for a call instruction.
Definition: Core.cpp:2167
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:2592
arg_iterator arg_end()
Definition: Function.h:612
unsigned LLVMGetLastEnumAttributeKind(void)
Definition: Core.cpp:130
13: Structures
Definition: Type.h:73
LLVMTypeRef LLVMX86FP80Type(void)
Definition: Core.cpp:465
LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val)
Obtain the first use of a value.
Definition: Core.cpp:740
A debug info location.
Definition: DebugLoc.h:34
Metadata node.
Definition: Metadata.h:862
void LLVMClearInsertionPosition(LLVMBuilderRef Builder)
Definition: Core.cpp:2391
LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar)
Definition: Core.cpp:1679
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:585
LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1252
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:3186
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:2921
LLVMValueRef LLVMBuildFRem(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:2617
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:1414
1: 16-bit floating point type
Definition: Type.h:58
LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType)
Definition: Core.cpp:1313
LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val)
Determine whether an LLVMValueRef is itself a basic block.
Definition: Core.cpp:1985
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:508
an instruction that atomically reads a memory location, combines it with another value, and then stores the result back.
Definition: Instructions.h:677
Hexagon Common GEP
LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef BBRef, const char *Name)
Insert a basic block in a function using the global context.
Definition: Core.cpp:2068
int LLVMHasMetadata(LLVMValueRef Inst)
Determine whether an instruction has any metadata attached.
Definition: Core.cpp:683
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:2126
const char * LLVMGetSection(LLVMValueRef Global)
Definition: Core.cpp:1571
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:390
LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals, unsigned Count)
Obtain a MDNode value from a context.
Definition: Core.cpp:851
LLVMTypeRef LLVMTokenTypeInContext(LLVMContextRef C)
Create a token type in a context.
Definition: Core.cpp:620
#define op(i)
LLVMValueRef LLVMBuildFence(LLVMBuilderRef B, LLVMAtomicOrdering Ordering, LLVMBool isSingleThread, const char *Name)
Definition: Core.cpp:2764
15: Pointers
Definition: Type.h:75
void initializeCore(PassRegistry &)
Initialize all passes linked into the TransformUtils library.
Definition: Core.cpp:47
static IntegerType * getInt16Ty(LLVMContext &C)
Definition: Type.cpp:175
LLVMAttributeRef LLVMGetStringAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx, const char *K, unsigned KLen)
Definition: Core.cpp:1896
static Type * getX86_MMXTy(LLVMContext &C)
Definition: Type.cpp:171
LLVMAtomicRMWBinOp
Definition: Core.h:309
12: Functions
Definition: Type.h:72
LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char Str[], uint8_t Radix)
Definition: Core.cpp:968
*p = old >signed v ? old : v
Definition: Instructions.h:705
LLVMValueRef LLVMConstAddrSpaceCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType)
Definition: Core.cpp:1373
Lowest level of atomicity, guarantees somewhat sane results, lock free.
Definition: Core.h:284
std::error_code error() const
Definition: raw_ostream.h:425
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:888
128 bit floating point type (112-bit mantissa)
Definition: Core.h:146
void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant)
Definition: Core.cpp:1723
void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal)
Definition: Core.cpp:1715
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:2002
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:808
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:980
LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:2927
static Constant * getNullValue(Type *Ty)
Constructor to create a &#39;0&#39; constant of arbitrary type.
Definition: Constants.cpp:207
LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM)
Initializes all of the function passes scheduled in the function pass manager.
Definition: Core.cpp:3209
void LLVMRemoveCallSiteStringAttribute(LLVMValueRef C, LLVMAttributeIndex Idx, const char *K, unsigned KLen)
Definition: Core.cpp:2227
void LLVMSetOperand(LLVMValueRef Val, unsigned Index, LLVMValueRef Op)
Set an operand at a specific index in a llvm::User value.
Definition: Core.cpp:794
iterator begin()
Instruction iterator methods.
Definition: BasicBlock.h:252
long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal)
Obtain the sign extended value for an integer constant value.
Definition: Core.cpp:997
static Constant * getAdd(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
Definition: Constants.cpp:2115
static Constant * getFMul(Constant *C1, Constant *C2)
Definition: Constants.cpp:2144
void(* LLVMYieldCallback)(LLVMContextRef, void *)
Definition: Core.h:381
void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index, unsigned align)
Definition: Core.cpp:2180
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:550
LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst)
Obtain the code opcode for an individual instruction.
Definition: Core.cpp:2153
LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C)
Obtain a 128-bit floating point type (112-bit mantissa) from a context.
Definition: Core.cpp:446
const char * LLVMGetStructName(LLVMTypeRef Ty)
Obtain the name of a structure.
Definition: Core.cpp:525
LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn)
Obtain the last basic block in a function.
Definition: Core.cpp:2027
static LLVMAtomicOrdering mapToLLVMOrdering(AtomicOrdering Ordering)
Definition: Core.cpp:2746
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:1981
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:1518
LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C)
Create a label type in a context.
Definition: Core.cpp:617
LLVMMetadataRef LLVMValueAsMetadata(LLVMValueRef Val)
Obtain a Value as a Metadata.
Definition: Core.cpp:886
LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C)
Obtain a 64-bit floating point type from a context.
Definition: Core.cpp:440
static Type * getTokenTy(LLVMContext &C)
Definition: Type.cpp:167
static ManagedStatic< LLVMContext > GlobalContext
Definition: Core.cpp:77
LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size)
Create a ConstantVector from values.
Definition: Core.cpp:1082
Set the new value and return the one old.
Definition: Core.h:310
LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:2597
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:1119
LLVMBool LLVMIsNull(LLVMValueRef Val)
Determine whether a value instance is null.
Definition: Core.cpp:824
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:1436
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:2294
LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text)
Obtain a constant for a floating point value parsed from a string.
Definition: Core.cpp:984
LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef B, LLVMValueRef *RetVals, unsigned N)
Definition: Core.cpp:2437
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:323
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:2193
static Constant * getNUWNeg(Constant *C)
Definition: Constants.h:948
LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char Str[], unsigned SLen, uint8_t Radix)
Definition: Core.cpp:974
Add a value and return the old one.
Definition: Core.h:311
void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block, LLVMValueRef Instr)
Definition: Core.cpp:2370
LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C)
Definition: Core.cpp:387
unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn)
Obtain the calling function of a function.
Definition: Core.cpp:1850
LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType, LLVMBool isSigned)
Definition: Core.cpp:1403
LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1155
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:668
void setThreadLocalMode(ThreadLocalMode Val)
Definition: GlobalValue.h:242
void LLVMSetDataLayout(LLVMModuleRef M, const char *DataLayoutStr)
Set the data layout for a module.
Definition: Core.cpp:247
LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1183
unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy)
Definition: Core.cpp:428
This file contains the simple types necessary to represent the attributes associated with functions a...
LLVMBool LLVMIsExternallyInitialized(LLVMValueRef GlobalVar)
Definition: Core.cpp:1766
Pointers.
Definition: Core.h:153
static Constant * getSExt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:1556
LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1291
LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB)
Obtain the function to which a basic block belongs.
Definition: Core.cpp:1997
void LLVMSetCondition(LLVMValueRef Branch, LLVMValueRef Cond)
Set the condition of a branch instruction.
Definition: Core.cpp:2288
unsigned getNumOperands() const
Definition: Metadata.cpp:1069
LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn)
Obtain the last parameter to a function.
Definition: Core.cpp:1951
LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate, LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1267
LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty)
Obtain a constant value referring to an undefined value of a type.
Definition: Core.cpp:816
Rename collisions when linking (static functions)
Definition: Core.h:171
uint64_t LLVMGetEnumAttributeValue(LLVMAttributeRef A)
Get the enum attribute&#39;s value.
Definition: Core.cpp:143
LLVMBool LLVMIsCleanup(LLVMValueRef LandingPad)
Definition: Core.cpp:2512
void LLVMGetSubtypes(LLVMTypeRef Tp, LLVMTypeRef *Arr)
Returns type&#39;s subtypes.
Definition: Core.cpp:569
Arrays.
Definition: Core.h:152
void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz)
Definition: Core.cpp:1586
static Type * getPPC_FP128Ty(LLVMContext &C)
Definition: Type.cpp:170
void LLVMSetNormalDest(LLVMValueRef Invoke, LLVMBasicBlockRef B)
Set the normal destination basic block.
Definition: Core.cpp:2256
LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType)
Definition: Core.cpp:1318
void LLVMContextSetDiagnosticHandler(LLVMContextRef C, LLVMDiagnosticHandler Handler, void *DiagnosticContext)
Set the diagnostic handler for this context.
Definition: Core.cpp:85
LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar)
Definition: Core.cpp:1687
LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:2527
static StructType * get(LLVMContext &Context, ArrayRef< Type *> Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
Definition: Type.cpp:336
LLVMBool LLVMIsStringAttribute(LLVMAttributeRef A)
Definition: Core.cpp:176
Expected< const typename ELFT::Shdr * > getSection(typename ELFT::ShdrRange Sections, uint32_t Index)
Definition: ELF.h:187
SIMD &#39;packed&#39; format, or other vector type.
Definition: Core.h:154
LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB)
Obtain the first instruction in a basic block.
Definition: Core.cpp:2095
LLVMTypeRef LLVMFloatType(void)
Definition: Core.cpp:459
AtomicOrdering
Atomic ordering for LLVM&#39;s memory model.
global_iterator global_begin()
Definition: Module.h:555
void LLVMDisposeMessage(char *Message)
Definition: Core.cpp:70
A load or store which is not atomic.
Definition: Core.h:283
LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType)
Definition: Core.cpp:1409
LLVMValueRef LLVMBuildSRem(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:2612
struct LLVMOpaqueType * LLVMTypeRef
Each value in the LLVM IR has a type, an LLVMTypeRef.
Definition: Types.h:69
AttributeList getAttributes(LLVMContext &C, ID id)
Return the attributes for an intrinsic.
LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst)
Obtain the instruction that occurred before this one.
Definition: Core.cpp:2119
void LLVMContextSetYieldCallback(LLVMContextRef C, LLVMYieldCallback Callback, void *OpaqueHandle)
Set the yield callback function for this context.
Definition: Core.cpp:103
static Constant * getZExt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:1570
Instruction * clone() const
Create a copy of &#39;this&#39; instruction that is identical in all ways except the following: ...
void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos)
Move a basic block to before another one.
Definition: Core.cpp:2081
static Constant * getSizeOf(Type *Ty)
getSizeOf constant expr - computes the (alloc) size of a type (in address-units, not bits) in a targe...
Definition: Constants.cpp:1791
LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant, LLVMValueRef ElementValueConstant, LLVMValueRef IndexConstant)
Definition: Core.cpp:1428
void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest)
Obtain the types of a function&#39;s parameters.
Definition: Core.cpp:499
A constant value that is initialized with an expression using other constant values.
Definition: Constants.h:862
Class to represent function types.
Definition: DerivedTypes.h:103
char * LLVMPrintModuleToString(LLVMModuleRef M)
Return a string representation of the module.
Definition: Core.cpp:287
static Type * getLabelTy(LLVMContext &C)
Definition: Type.cpp:162
LLVMValueRef LLVMMetadataAsValue(LLVMContextRef C, LLVMMetadataRef MD)
Obtain a Metadata as a Value.
Definition: Core.cpp:882
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:245
void LLVMDisposeModule(LLVMModuleRef M)
Destroy a module instance.
Definition: Core.cpp:223
void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst)
Definition: Core.cpp:2422
opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
Definition: APFloat.cpp:4441
LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar)
Definition: Core.cpp:1719
LLVMValueRef LLVMConstStructInContext(LLVMContextRef C, LLVMValueRef *ConstantVals, unsigned Count, LLVMBool Packed)
Create an anonymous ConstantStruct with the specified values.
Definition: Core.cpp:1059
static Constant * getFPCast(Constant *C, Type *Ty)
Create a FPExt, Bitcast or FPTrunc for fp -> fp casts.
Definition: Constants.cpp:1530
LLVMBool LLVMIsTailCall(LLVMValueRef Call)
Obtain whether a call instruction is a tail call.
Definition: Core.cpp:2238
LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB)
Definition: Core.cpp:1466
void llvm_shutdown()
llvm_shutdown - Deallocate and destroy all ManagedStatic variables.
LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType)
Definition: Core.cpp:1379
BinOp
This enumeration lists the possible modifications atomicrmw can make.
Definition: Instructions.h:689
LLVMValueKind
Definition: Core.h:205
LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal, LLVMValueRef *ConstantIndices, unsigned NumIndices)
Definition: Core.cpp:1296
struct LLVMOpaqueUse * LLVMUseRef
Used to get the users and usees of a Value.
Definition: Types.h:123
LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal, LLVMValueRef *ConstantIndices, unsigned NumIndices)
Definition: Core.cpp:1304
Keep one copy of function when linking (inline)
Definition: Core.h:163
static Constant * getAShr(Constant *C1, Constant *C2, bool isExact=false)
Definition: Constants.cpp:2198
LLVMValueRef LLVMBuildOr(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:2642
void LLVMDeleteFunction(LLVMValueRef Fn)
Remove a function from its containing module and deletes it.
Definition: Core.cpp:1828
void LLVMRemoveCallSiteEnumAttribute(LLVMValueRef C, LLVMAttributeIndex Idx, unsigned KindID)
Definition: Core.cpp:2221
struct LLVMOpaqueContext * LLVMContextRef
The top-level container for all LLVM global data.
Definition: Types.h:54
LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:2602
LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType)
Definition: Core.cpp:1353
OR a value and return the old one.
Definition: Core.h:315
LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB)
Go backwards in a basic block iterator.
Definition: Core.cpp:2043
This instruction compares its operands according to the predicate given to the constructor.
static Constant * getSelect(Constant *C, Constant *V1, Constant *V2, Type *OnlyIfReducedTy=nullptr)
Select constant expr.
Definition: Constants.cpp:1854
LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M)
Definition: Core.cpp:1663
void LLVMDumpModule(LLVMModuleRef M)
Dump a representation of a module to stderr.
Definition: Core.cpp:260
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
unsigned LLVMCountIncoming(LLVMValueRef PhiNode)
Obtain the number of incoming basic blocks to a PHI node.
Definition: Core.cpp:2323
LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:2932
LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C)
Obtain a 32-bit floating point type from a context.
Definition: Core.cpp:437
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
Definition: Instruction.h:125
unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal)
Obtain the zero extended value for an integer constant value.
Definition: Core.cpp:993
static int map_from_llvmopcode(LLVMOpcode code)
Definition: Core.cpp:1099
const std::string & getGC() const
Definition: Function.cpp:444
An instruction for storing to memory.
Definition: Instructions.h:306
void LLVMGetMDNodeOperands(LLVMValueRef V, LLVMValueRef *Dest)
Obtain the given MDNode&#39;s operands.
Definition: Core.cpp:912
LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1205
LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB)
Obtain the last instruction in a basic block.
Definition: Core.cpp:2103
LLVMValueRef LLVMBuildSub(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:2542
#define LLVM_EXTENSION
LLVM_EXTENSION - Support compilers where we have a keyword to suppress pedantic diagnostics.
Definition: Compiler.h:247
LLVMUseRef LLVMGetNextUse(LLVMUseRef U)
Obtain the next use of a value.
Definition: Core.cpp:748
static const fltSemantics & IEEEdouble() LLVM_READNONE
Definition: APFloat.cpp:122
LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name, LLVMTypeRef FunctionTy)
Add a function to a module under a specified name.
Definition: Core.cpp:1786
LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:2537
static Constant * getUDiv(Constant *C1, Constant *C2, bool isExact=false)
Definition: Constants.cpp:2148
static Constant * getNSWNeg(Constant *C)
Definition: Constants.h:947
Keep one copy of function when linking (weak)
Definition: Core.h:167
unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy)
Obtain the number of parameters this function accepts.
Definition: Core.cpp:495
LLVMIntPredicate
Definition: Core.h:237
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:2552
unsigned getBitWidth() const
Get the number of bits in this IntegerType.
Definition: DerivedTypes.h:66
struct LLVMOpaqueAttributeRef * LLVMAttributeRef
Used to represent an attributes.
Definition: Types.h:130
iterator begin()
Definition: Function.h:588
Type::subtype_iterator element_iterator
Definition: DerivedTypes.h:301
static ConstantAsMetadata * get(Constant *C)
Definition: Metadata.h:408
LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:2883
LLVMDiagnosticSeverity
Definition: Core.h:331
static Constant * getFDiv(Constant *C1, Constant *C2)
Definition: Constants.cpp:2158
LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name)
Create an empty structure in a context having a specified name.
Definition: Core.cpp:520
LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N, LLVMBool SignExtend)
Obtain a constant value for an integer type.
Definition: Core.cpp:954
static BinaryOperator * CreateAdd(Value *S1, Value *S2, const Twine &Name, Instruction *InsertBefore, Value *FlagsOp)
size_t LLVMGetBufferSize(LLVMMemoryBufferRef MemBuf)
Definition: Core.cpp:3176
LLVMValueRef LLVMBuildAnd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:2637
void LLVMSetCmpXchgSuccessOrdering(LLVMValueRef CmpXchgInst, LLVMAtomicOrdering Ordering)
Definition: Core.cpp:3091
void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage)
Definition: Core.cpp:1509
void initializePrintBasicBlockPassPass(PassRegistry &)
unsigned LLVMGetIntrinsicID(LLVMValueRef Fn)
Obtain the ID number from a function instance.
Definition: Core.cpp:1844
void LLVMAddTargetDependentFunctionAttr(LLVMValueRef Fn, const char *A, const char *V)
Add a target-dependent attribute to a function.
Definition: Core.cpp:1912
LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst)
Obtain the basic block to which an instruction belongs.
Definition: Core.cpp:2091
LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C)
Definition: Core.cpp:396
LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M)
Definition: Core.cpp:1671
const char * LLVMGetBasicBlockName(LLVMBasicBlockRef BB)
Obtain the string name of a basic block.
Definition: Core.cpp:1993
LLVMAttributeRef LLVMGetCallSiteStringAttribute(LLVMValueRef C, LLVMAttributeIndex Idx, const char *K, unsigned KLen)
Definition: Core.cpp:2214
LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1144
unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy)
Obtain the length of an array type.
Definition: Core.cpp:600
use_iterator_impl< Use > use_iterator
Definition: Value.h:333
void LLVMDisposePassManager(LLVMPassManagerRef PM)
Frees the memory of a pass pipeline.
Definition: Core.cpp:3221
LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef B, LLVMValueRef Val, const char *Name)
Definition: Core.cpp:3017
void LLVMSetVolatile(LLVMValueRef MemAccessInst, LLVMBool isVolatile)
Definition: Core.cpp:2810
AttributeSet getAttributes(unsigned Index) const
The attributes for the specified index are returned.
LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C)
Create a void type in a context.
Definition: Core.cpp:614
11: Arbitrary bit width integers
Definition: Type.h:71
static MetadataAsValue * get(LLVMContext &Context, Metadata *MD)
Definition: Metadata.cpp:106
PassManager manages ModulePassManagers.
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:1678
#define LLVM_DEFINE_VALUE_CAST(name)
Definition: Core.cpp:717
ExternalWeak linkage description.
Definition: GlobalValue.h:58
void LLVMSetUnnamedAddr(LLVMValueRef Global, LLVMBool HasUnnamedAddr)
Definition: Core.cpp:1605
LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1149
LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal)
Definition: Core.cpp:1127
void LLVMSetTarget(LLVMModuleRef M, const char *Triple)
Set the target triple for a module.
Definition: Core.cpp:256
static Constant * getInsertValue(Constant *Agg, Constant *Val, ArrayRef< unsigned > Idxs, Type *OnlyIfReducedTy=nullptr)
Definition: Constants.cpp:2048
0: type with no size
Definition: Type.h:57
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata *> MDs)
Definition: Metadata.h:1164
#define P(N)
Same, but only replaced by something equivalent.
Definition: GlobalValue.h:52
static Constant * getFNeg(Constant *C)
Definition: Constants.cpp:2103
LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn)
Obtain the first basic block in a function.
Definition: Core.cpp:2019
LLVMTypeRef LLVMMetadataTypeInContext(LLVMContextRef C)
Create a metadata type in a context.
Definition: Core.cpp:623
LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V, const char *Name)
Definition: Core.cpp:2668
void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L)
Definition: Core.cpp:2410
const unsigned * LLVMGetIndices(LLVMValueRef Inst)
Obtain the indices as an array.
Definition: Core.cpp:2349
static Constant * getFRem(Constant *C1, Constant *C2)
Definition: Constants.cpp:2170
void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block)
Definition: Core.cpp:2382
void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes, unsigned ElementCount, LLVMBool Packed)
Set the contents of a structure type.
Definition: Core.cpp:533
LLVMValueRef LLVMBuildShl(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:2622
static ErrorOr< std::unique_ptr< MemoryBuffer > > getSTDIN()
Read all of stdin into a file buffer, and return it.
static IntegerType * getInt128Ty(LLVMContext &C)
Definition: Type.cpp:178
Acquire provides a barrier of the sort necessary to acquire a lock to access other memory with normal...
Definition: Core.h:289
void addAttr(Attribute::AttrKind Kind)
Definition: Function.cpp:174
LLVMTypeKind
Definition: Core.h:140
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef B, LLVMValueRef VecVal, LLVMValueRef EltVal, LLVMValueRef Index, const char *Name)
Definition: Core.cpp:2991
static ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
Definition: Constants.cpp:1306
LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef B, LLVMTypeRef Ty, const char *Name)
Definition: Core.cpp:2705
LLVMAtomicOrdering
Definition: Core.h:282
LLVMTypeRef LLVMInt32Type(void)
Definition: Core.cpp:415
void LLVMGetAttributesAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx, LLVMAttributeRef *Attrs)
Definition: Core.cpp:1882
LLVMValueRef LLVMBuildPhi(LLVMBuilderRef B, LLVMTypeRef Ty, const char *Name)
Definition: Core.cpp:2961
LLVM Basic Block Representation.
Definition: BasicBlock.h:59
LLVMValueRef LLVMIsAMDString(LLVMValueRef Val)
Definition: Core.cpp:732
Sets the value if it&#39;s greater than the original using an unsigned comparison and return the old one...
Definition: Core.h:326
LLVMValueRef LLVMGetMetadata(LLVMValueRef Inst, unsigned KindID)
Return metadata associated with an instruction value.
Definition: Core.cpp:687
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal)
Definition: Core.cpp:2507
unsigned LLVMCountBasicBlocks(LLVMValueRef FnRef)
Obtain the number of basic blocks in a function.
Definition: Core.cpp:2005
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:69
LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy)
Determine whether a structure is packed.
Definition: Core.cpp:555
void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal)
Replace all uses of a value with another one.
Definition: Core.cpp:679
LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:2858
LLVMBool LLVMStartMultithreaded()
Deprecated: Multi-threading can only be enabled/disabled with the compile time define LLVM_ENABLE_THR...
Definition: Core.cpp:3227
LLVMDiagnosticHandler LLVMContextGetDiagnosticHandler(LLVMContextRef C)
Get the diagnostic handler of this context.
Definition: Core.cpp:94
LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M)
Obtain the context to which this module is associated.
Definition: Core.cpp:304
LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1232
static BlockAddress * get(Function *F, BasicBlock *BB)
Return a BlockAddress for the specified function and basic block.
Definition: Constants.cpp:1339
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
Definition: Constant.h:42
LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:2547
LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name)
Obtain a Function value from a Module by its name.
Definition: Core.cpp:1792
LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal)
Definition: Core.cpp:1136