LLVM  4.0.0
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"
18 #include "llvm/IR/Attributes.h"
19 #include "AttributeSetNode.h"
20 #include "llvm/IR/CallSite.h"
21 #include "llvm/IR/Constants.h"
22 #include "llvm/IR/DerivedTypes.h"
23 #include "llvm/IR/DiagnosticInfo.h"
25 #include "llvm/IR/GlobalAlias.h"
26 #include "llvm/IR/GlobalVariable.h"
27 #include "llvm/IR/IRBuilder.h"
28 #include "llvm/IR/InlineAsm.h"
29 #include "llvm/IR/IntrinsicInst.h"
30 #include "llvm/IR/LLVMContext.h"
32 #include "llvm/IR/Module.h"
33 #include "llvm/Support/Debug.h"
38 #include "llvm/Support/Threading.h"
40 #include <cassert>
41 #include <cstdlib>
42 #include <cstring>
43 #include <system_error>
44 
45 using namespace llvm;
46 
47 #define DEBUG_TYPE "ir"
48 
55 }
56 
59 }
60 
61 void LLVMShutdown() {
62  llvm_shutdown();
63 }
64 
65 /*===-- Error handling ----------------------------------------------------===*/
66 
67 char *LLVMCreateMessage(const char *Message) {
68  return strdup(Message);
69 }
70 
71 void LLVMDisposeMessage(char *Message) {
72  free(Message);
73 }
74 
75 
76 /*===-- Operations on contexts --------------------------------------------===*/
77 
79 
81  return wrap(new LLVMContext());
82 }
83 
85 
87  LLVMDiagnosticHandler Handler,
88  void *DiagnosticContext) {
89  unwrap(C)->setDiagnosticHandler(
90  LLVM_EXTENSION reinterpret_cast<LLVMContext::DiagnosticHandlerTy>(
91  Handler),
92  DiagnosticContext);
93 }
94 
96  return LLVM_EXTENSION reinterpret_cast<LLVMDiagnosticHandler>(
97  unwrap(C)->getDiagnosticHandler());
98 }
99 
101  return unwrap(C)->getDiagnosticContext();
102 }
103 
105  void *OpaqueHandle) {
106  auto YieldCallback =
107  LLVM_EXTENSION reinterpret_cast<LLVMContext::YieldCallbackTy>(Callback);
108  unwrap(C)->setYieldCallback(YieldCallback, OpaqueHandle);
109 }
110 
112  delete unwrap(C);
113 }
114 
116  unsigned SLen) {
117  return unwrap(C)->getMDKindID(StringRef(Name, SLen));
118 }
119 
120 unsigned LLVMGetMDKindID(const char *Name, unsigned SLen) {
121  return LLVMGetMDKindIDInContext(LLVMGetGlobalContext(), Name, SLen);
122 }
123 
124 #define GET_ATTR_KIND_FROM_NAME
125 #include "AttributesCompatFunc.inc"
126 
127 unsigned LLVMGetEnumAttributeKindForName(const char *Name, size_t SLen) {
128  return getAttrKindFromName(StringRef(Name, SLen));
129 }
130 
132  return Attribute::AttrKind::EndAttrKinds;
133 }
134 
136  uint64_t Val) {
137  return wrap(Attribute::get(*unwrap(C), (Attribute::AttrKind)KindID, Val));
138 }
139 
141  return unwrap(A).getKindAsEnum();
142 }
143 
145  auto Attr = unwrap(A);
146  if (Attr.isEnumAttribute())
147  return 0;
148  return Attr.getValueAsInt();
149 }
150 
152  const char *K, unsigned KLength,
153  const char *V, unsigned VLength) {
154  return wrap(Attribute::get(*unwrap(C), StringRef(K, KLength),
155  StringRef(V, VLength)));
156 }
157 
159  unsigned *Length) {
160  auto S = unwrap(A).getKindAsString();
161  *Length = S.size();
162  return S.data();
163 }
164 
166  unsigned *Length) {
167  auto S = unwrap(A).getValueAsString();
168  *Length = S.size();
169  return S.data();
170 }
171 
173  auto Attr = unwrap(A);
174  return Attr.isEnumAttribute() || Attr.isIntAttribute();
175 }
176 
178  return unwrap(A).isStringAttribute();
179 }
180 
182  std::string MsgStorage;
183  raw_string_ostream Stream(MsgStorage);
184  DiagnosticPrinterRawOStream DP(Stream);
185 
186  unwrap(DI)->print(DP);
187  Stream.flush();
188 
189  return LLVMCreateMessage(MsgStorage.c_str());
190 }
191 
193  LLVMDiagnosticSeverity severity;
194 
195  switch(unwrap(DI)->getSeverity()) {
196  default:
197  severity = LLVMDSError;
198  break;
199  case DS_Warning:
200  severity = LLVMDSWarning;
201  break;
202  case DS_Remark:
203  severity = LLVMDSRemark;
204  break;
205  case DS_Note:
206  severity = LLVMDSNote;
207  break;
208  }
209 
210  return severity;
211 }
212 
213 /*===-- Operations on modules ---------------------------------------------===*/
214 
216  return wrap(new Module(ModuleID, *GlobalContext));
217 }
218 
220  LLVMContextRef C) {
221  return wrap(new Module(ModuleID, *unwrap(C)));
222 }
223 
225  delete unwrap(M);
226 }
227 
228 const char *LLVMGetModuleIdentifier(LLVMModuleRef M, size_t *Len) {
229  auto &Str = unwrap(M)->getModuleIdentifier();
230  *Len = Str.length();
231  return Str.c_str();
232 }
233 
234 void LLVMSetModuleIdentifier(LLVMModuleRef M, const char *Ident, size_t Len) {
235  unwrap(M)->setModuleIdentifier(StringRef(Ident, Len));
236 }
237 
238 
239 /*--.. Data layout .........................................................--*/
241  return unwrap(M)->getDataLayoutStr().c_str();
242 }
243 
245  return LLVMGetDataLayoutStr(M);
246 }
247 
248 void LLVMSetDataLayout(LLVMModuleRef M, const char *DataLayoutStr) {
249  unwrap(M)->setDataLayout(DataLayoutStr);
250 }
251 
252 /*--.. Target triple .......................................................--*/
253 const char * LLVMGetTarget(LLVMModuleRef M) {
254  return unwrap(M)->getTargetTriple().c_str();
255 }
256 
257 void LLVMSetTarget(LLVMModuleRef M, const char *Triple) {
258  unwrap(M)->setTargetTriple(Triple);
259 }
260 
262  unwrap(M)->dump();
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  *ErrorMessage = strdup("Error printing to file");
280  return true;
281  }
282 
283  return false;
284 }
285 
287  std::string buf;
288  raw_string_ostream os(buf);
289 
290  unwrap(M)->print(os, nullptr);
291  os.flush();
292 
293  return strdup(buf.c_str());
294 }
295 
296 /*--.. Operations on inline assembler ......................................--*/
298  unwrap(M)->setModuleInlineAsm(StringRef(Asm));
299 }
300 
301 
302 /*--.. Operations on module contexts ......................................--*/
304  return wrap(&unwrap(M)->getContext());
305 }
306 
307 
308 /*===-- Operations on types -----------------------------------------------===*/
309 
310 /*--.. Operations on all types (mostly) ....................................--*/
311 
313  switch (unwrap(Ty)->getTypeID()) {
314  case Type::VoidTyID:
315  return LLVMVoidTypeKind;
316  case Type::HalfTyID:
317  return LLVMHalfTypeKind;
318  case Type::FloatTyID:
319  return LLVMFloatTypeKind;
320  case Type::DoubleTyID:
321  return LLVMDoubleTypeKind;
322  case Type::X86_FP80TyID:
323  return LLVMX86_FP80TypeKind;
324  case Type::FP128TyID:
325  return LLVMFP128TypeKind;
326  case Type::PPC_FP128TyID:
327  return LLVMPPC_FP128TypeKind;
328  case Type::LabelTyID:
329  return LLVMLabelTypeKind;
330  case Type::MetadataTyID:
331  return LLVMMetadataTypeKind;
332  case Type::IntegerTyID:
333  return LLVMIntegerTypeKind;
334  case Type::FunctionTyID:
335  return LLVMFunctionTypeKind;
336  case Type::StructTyID:
337  return LLVMStructTypeKind;
338  case Type::ArrayTyID:
339  return LLVMArrayTypeKind;
340  case Type::PointerTyID:
341  return LLVMPointerTypeKind;
342  case Type::VectorTyID:
343  return LLVMVectorTypeKind;
344  case Type::X86_MMXTyID:
345  return LLVMX86_MMXTypeKind;
346  case Type::TokenTyID:
347  return LLVMTokenTypeKind;
348  }
349  llvm_unreachable("Unhandled TypeID.");
350 }
351 
353 {
354  return unwrap(Ty)->isSized();
355 }
356 
358  return wrap(&unwrap(Ty)->getContext());
359 }
360 
362  return unwrap(Ty)->dump();
363 }
364 
366  std::string buf;
367  raw_string_ostream os(buf);
368 
369  if (unwrap(Ty))
370  unwrap(Ty)->print(os);
371  else
372  os << "Printing <null> Type";
373 
374  os.flush();
375 
376  return strdup(buf.c_str());
377 }
378 
379 /*--.. Operations on integer types .........................................--*/
380 
382  return (LLVMTypeRef) Type::getInt1Ty(*unwrap(C));
383 }
385  return (LLVMTypeRef) Type::getInt8Ty(*unwrap(C));
386 }
388  return (LLVMTypeRef) Type::getInt16Ty(*unwrap(C));
389 }
391  return (LLVMTypeRef) Type::getInt32Ty(*unwrap(C));
392 }
394  return (LLVMTypeRef) Type::getInt64Ty(*unwrap(C));
395 }
397  return (LLVMTypeRef) Type::getInt128Ty(*unwrap(C));
398 }
400  return wrap(IntegerType::get(*unwrap(C), NumBits));
401 }
402 
405 }
408 }
411 }
414 }
417 }
420 }
421 LLVMTypeRef LLVMIntType(unsigned NumBits) {
422  return LLVMIntTypeInContext(LLVMGetGlobalContext(), NumBits);
423 }
424 
425 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy) {
426  return unwrap<IntegerType>(IntegerTy)->getBitWidth();
427 }
428 
429 /*--.. Operations on real types ............................................--*/
430 
432  return (LLVMTypeRef) Type::getHalfTy(*unwrap(C));
433 }
435  return (LLVMTypeRef) Type::getFloatTy(*unwrap(C));
436 }
438  return (LLVMTypeRef) Type::getDoubleTy(*unwrap(C));
439 }
441  return (LLVMTypeRef) Type::getX86_FP80Ty(*unwrap(C));
442 }
444  return (LLVMTypeRef) Type::getFP128Ty(*unwrap(C));
445 }
448 }
450  return (LLVMTypeRef) Type::getX86_MMXTy(*unwrap(C));
451 }
453  return (LLVMTypeRef) Type::getTokenTy(*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 
569 LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount) {
570  return wrap(ArrayType::get(unwrap(ElementType), ElementCount));
571 }
572 
574  return wrap(PointerType::get(unwrap(ElementType), AddressSpace));
575 }
576 
577 LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount) {
578  return wrap(VectorType::get(unwrap(ElementType), ElementCount));
579 }
580 
582  auto *Ty = unwrap<Type>(WrappedTy);
583  if (auto *PTy = dyn_cast<PointerType>(Ty))
584  return wrap(PTy->getElementType());
585  return wrap(cast<SequentialType>(Ty)->getElementType());
586 }
587 
588 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy) {
589  return unwrap<ArrayType>(ArrayTy)->getNumElements();
590 }
591 
593  return unwrap<PointerType>(PointerTy)->getAddressSpace();
594 }
595 
596 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy) {
597  return unwrap<VectorType>(VectorTy)->getNumElements();
598 }
599 
600 /*--.. Operations on other types ...........................................--*/
601 
603  return wrap(Type::getVoidTy(*unwrap(C)));
604 }
606  return wrap(Type::getLabelTy(*unwrap(C)));
607 }
608 
611 }
614 }
615 
616 /*===-- Operations on values ----------------------------------------------===*/
617 
618 /*--.. Operations on all values ............................................--*/
619 
621  return wrap(unwrap(Val)->getType());
622 }
623 
625  switch(unwrap(Val)->getValueID()) {
626 #define HANDLE_VALUE(Name) \
627  case Value::Name##Val: \
628  return LLVM##Name##ValueKind;
629 #include "llvm/IR/Value.def"
630  default:
632  }
633 }
634 
635 const char *LLVMGetValueName(LLVMValueRef Val) {
636  return unwrap(Val)->getName().data();
637 }
638 
639 void LLVMSetValueName(LLVMValueRef Val, const char *Name) {
640  unwrap(Val)->setName(Name);
641 }
642 
644  unwrap(Val)->dump();
645 }
646 
648  std::string buf;
649  raw_string_ostream os(buf);
650 
651  if (unwrap(Val))
652  unwrap(Val)->print(os);
653  else
654  os << "Printing <null> Value";
655 
656  os.flush();
657 
658  return strdup(buf.c_str());
659 }
660 
662  unwrap(OldVal)->replaceAllUsesWith(unwrap(NewVal));
663 }
664 
666  return unwrap<Instruction>(Inst)->hasMetadata();
667 }
668 
669 LLVMValueRef LLVMGetMetadata(LLVMValueRef Inst, unsigned KindID) {
670  auto *I = unwrap<Instruction>(Inst);
671  assert(I && "Expected instruction");
672  if (auto *MD = I->getMetadata(KindID))
673  return wrap(MetadataAsValue::get(I->getContext(), MD));
674  return nullptr;
675 }
676 
677 // MetadataAsValue uses a canonical format which strips the actual MDNode for
678 // MDNode with just a single constant value, storing just a ConstantAsMetadata
679 // This undoes this canonicalization, reconstructing the MDNode.
681  Metadata *MD = MAV->getMetadata();
682  assert((isa<MDNode>(MD) || isa<ConstantAsMetadata>(MD)) &&
683  "Expected a metadata node or a canonicalized constant");
684 
685  if (MDNode *N = dyn_cast<MDNode>(MD))
686  return N;
687 
688  return MDNode::get(MAV->getContext(), MD);
689 }
690 
691 void LLVMSetMetadata(LLVMValueRef Inst, unsigned KindID, LLVMValueRef Val) {
692  MDNode *N = Val ? extractMDNode(unwrap<MetadataAsValue>(Val)) : nullptr;
693 
694  unwrap<Instruction>(Inst)->setMetadata(KindID, N);
695 }
696 
697 /*--.. Conversion functions ................................................--*/
698 
699 #define LLVM_DEFINE_VALUE_CAST(name) \
700  LLVMValueRef LLVMIsA##name(LLVMValueRef Val) { \
701  return wrap(static_cast<Value*>(dyn_cast_or_null<name>(unwrap(Val)))); \
702  }
703 
705 
707  if (auto *MD = dyn_cast_or_null<MetadataAsValue>(unwrap(Val)))
708  if (isa<MDNode>(MD->getMetadata()) ||
709  isa<ValueAsMetadata>(MD->getMetadata()))
710  return Val;
711  return nullptr;
712 }
713 
715  if (auto *MD = dyn_cast_or_null<MetadataAsValue>(unwrap(Val)))
716  if (isa<MDString>(MD->getMetadata()))
717  return Val;
718  return nullptr;
719 }
720 
721 /*--.. Operations on Uses ..................................................--*/
723  Value *V = unwrap(Val);
725  if (I == V->use_end())
726  return nullptr;
727  return wrap(&*I);
728 }
729 
731  Use *Next = unwrap(U)->getNext();
732  if (Next)
733  return wrap(Next);
734  return nullptr;
735 }
736 
738  return wrap(unwrap(U)->getUser());
739 }
740 
742  return wrap(unwrap(U)->get());
743 }
744 
745 /*--.. Operations on Users .................................................--*/
746 
748  unsigned Index) {
749  Metadata *Op = N->getOperand(Index);
750  if (!Op)
751  return nullptr;
752  if (auto *C = dyn_cast<ConstantAsMetadata>(Op))
753  return wrap(C->getValue());
754  return wrap(MetadataAsValue::get(Context, Op));
755 }
756 
758  Value *V = unwrap(Val);
759  if (auto *MD = dyn_cast<MetadataAsValue>(V)) {
760  if (auto *L = dyn_cast<ValueAsMetadata>(MD->getMetadata())) {
761  assert(Index == 0 && "Function-local metadata can only have one operand");
762  return wrap(L->getValue());
763  }
764  return getMDNodeOperandImpl(V->getContext(),
765  cast<MDNode>(MD->getMetadata()), Index);
766  }
767 
768  return wrap(cast<User>(V)->getOperand(Index));
769 }
770 
772  Value *V = unwrap(Val);
773  return wrap(&cast<User>(V)->getOperandUse(Index));
774 }
775 
776 void LLVMSetOperand(LLVMValueRef Val, unsigned Index, LLVMValueRef Op) {
777  unwrap<User>(Val)->setOperand(Index, unwrap(Op));
778 }
779 
781  Value *V = unwrap(Val);
782  if (isa<MetadataAsValue>(V))
783  return LLVMGetMDNodeNumOperands(Val);
784 
785  return cast<User>(V)->getNumOperands();
786 }
787 
788 /*--.. Operations on constants of any type .................................--*/
789 
791  return wrap(Constant::getNullValue(unwrap(Ty)));
792 }
793 
796 }
797 
799  return wrap(UndefValue::get(unwrap(Ty)));
800 }
801 
803  return isa<Constant>(unwrap(Ty));
804 }
805 
807  if (Constant *C = dyn_cast<Constant>(unwrap(Val)))
808  return C->isNullValue();
809  return false;
810 }
811 
813  return isa<UndefValue>(unwrap(Val));
814 }
815 
817  return wrap(ConstantPointerNull::get(unwrap<PointerType>(Ty)));
818 }
819 
820 /*--.. Operations on metadata nodes ........................................--*/
821 
823  unsigned SLen) {
824  LLVMContext &Context = *unwrap(C);
825  return wrap(MetadataAsValue::get(
826  Context, MDString::get(Context, StringRef(Str, SLen))));
827 }
828 
829 LLVMValueRef LLVMMDString(const char *Str, unsigned SLen) {
830  return LLVMMDStringInContext(LLVMGetGlobalContext(), Str, SLen);
831 }
832 
834  unsigned Count) {
835  LLVMContext &Context = *unwrap(C);
837  for (auto *OV : makeArrayRef(Vals, Count)) {
838  Value *V = unwrap(OV);
839  Metadata *MD;
840  if (!V)
841  MD = nullptr;
842  else if (auto *C = dyn_cast<Constant>(V))
843  MD = ConstantAsMetadata::get(C);
844  else if (auto *MDV = dyn_cast<MetadataAsValue>(V)) {
845  MD = MDV->getMetadata();
846  assert(!isa<LocalAsMetadata>(MD) && "Unexpected function-local metadata "
847  "outside of direct argument to call");
848  } else {
849  // This is function-local metadata. Pretend to make an MDNode.
850  assert(Count == 1 &&
851  "Expected only one operand to function-local metadata");
852  return wrap(MetadataAsValue::get(Context, LocalAsMetadata::get(V)));
853  }
854 
855  MDs.push_back(MD);
856  }
857  return wrap(MetadataAsValue::get(Context, MDNode::get(Context, MDs)));
858 }
859 
861  return LLVMMDNodeInContext(LLVMGetGlobalContext(), Vals, Count);
862 }
863 
864 const char *LLVMGetMDString(LLVMValueRef V, unsigned *Length) {
865  if (const auto *MD = dyn_cast<MetadataAsValue>(unwrap(V)))
866  if (const MDString *S = dyn_cast<MDString>(MD->getMetadata())) {
867  *Length = S->getString().size();
868  return S->getString().data();
869  }
870  *Length = 0;
871  return nullptr;
872 }
873 
875  auto *MD = cast<MetadataAsValue>(unwrap(V));
876  if (isa<ValueAsMetadata>(MD->getMetadata()))
877  return 1;
878  return cast<MDNode>(MD->getMetadata())->getNumOperands();
879 }
880 
882  auto *MD = cast<MetadataAsValue>(unwrap(V));
883  if (auto *MDV = dyn_cast<ValueAsMetadata>(MD->getMetadata())) {
884  *Dest = wrap(MDV->getValue());
885  return;
886  }
887  const auto *N = cast<MDNode>(MD->getMetadata());
888  const unsigned numOperands = N->getNumOperands();
889  LLVMContext &Context = unwrap(V)->getContext();
890  for (unsigned i = 0; i < numOperands; i++)
891  Dest[i] = getMDNodeOperandImpl(Context, N, i);
892 }
893 
895  if (NamedMDNode *N = unwrap(M)->getNamedMetadata(Name)) {
896  return N->getNumOperands();
897  }
898  return 0;
899 }
900 
902  LLVMValueRef *Dest) {
903  NamedMDNode *N = unwrap(M)->getNamedMetadata(Name);
904  if (!N)
905  return;
906  LLVMContext &Context = unwrap(M)->getContext();
907  for (unsigned i=0;i<N->getNumOperands();i++)
908  Dest[i] = wrap(MetadataAsValue::get(Context, N->getOperand(i)));
909 }
910 
912  LLVMValueRef Val) {
913  NamedMDNode *N = unwrap(M)->getOrInsertNamedMetadata(Name);
914  if (!N)
915  return;
916  if (!Val)
917  return;
918  N->addOperand(extractMDNode(unwrap<MetadataAsValue>(Val)));
919 }
920 
921 /*--.. Operations on scalar constants ......................................--*/
922 
923 LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
924  LLVMBool SignExtend) {
925  return wrap(ConstantInt::get(unwrap<IntegerType>(IntTy), N, SignExtend != 0));
926 }
927 
929  unsigned NumWords,
930  const uint64_t Words[]) {
931  IntegerType *Ty = unwrap<IntegerType>(IntTy);
932  return wrap(ConstantInt::get(Ty->getContext(),
933  APInt(Ty->getBitWidth(),
934  makeArrayRef(Words, NumWords))));
935 }
936 
938  uint8_t Radix) {
939  return wrap(ConstantInt::get(unwrap<IntegerType>(IntTy), StringRef(Str),
940  Radix));
941 }
942 
944  unsigned SLen, uint8_t Radix) {
945  return wrap(ConstantInt::get(unwrap<IntegerType>(IntTy), StringRef(Str, SLen),
946  Radix));
947 }
948 
950  return wrap(ConstantFP::get(unwrap(RealTy), N));
951 }
952 
953 LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text) {
954  return wrap(ConstantFP::get(unwrap(RealTy), StringRef(Text)));
955 }
956 
958  unsigned SLen) {
959  return wrap(ConstantFP::get(unwrap(RealTy), StringRef(Str, SLen)));
960 }
961 
962 unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal) {
963  return unwrap<ConstantInt>(ConstantVal)->getZExtValue();
964 }
965 
966 long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal) {
967  return unwrap<ConstantInt>(ConstantVal)->getSExtValue();
968 }
969 
970 double LLVMConstRealGetDouble(LLVMValueRef ConstantVal, LLVMBool *LosesInfo) {
971  ConstantFP *cFP = unwrap<ConstantFP>(ConstantVal) ;
972  Type *Ty = cFP->getType();
973 
974  if (Ty->isFloatTy()) {
975  *LosesInfo = false;
976  return cFP->getValueAPF().convertToFloat();
977  }
978 
979  if (Ty->isDoubleTy()) {
980  *LosesInfo = false;
981  return cFP->getValueAPF().convertToDouble();
982  }
983 
984  bool APFLosesInfo;
985  APFloat APF = cFP->getValueAPF();
987  *LosesInfo = APFLosesInfo;
988  return APF.convertToDouble();
989 }
990 
991 /*--.. Operations on composite constants ...................................--*/
992 
994  unsigned Length,
995  LLVMBool DontNullTerminate) {
996  /* Inverted the sense of AddNull because ', 0)' is a
997  better mnemonic for null termination than ', 1)'. */
998  return wrap(ConstantDataArray::getString(*unwrap(C), StringRef(Str, Length),
999  DontNullTerminate == 0));
1000 }
1001 
1002 LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
1003  LLVMBool DontNullTerminate) {
1004  return LLVMConstStringInContext(LLVMGetGlobalContext(), Str, Length,
1005  DontNullTerminate);
1006 }
1007 
1009  return wrap(unwrap<ConstantDataSequential>(C)->getElementAsConstant(idx));
1010 }
1011 
1013  return unwrap<ConstantDataSequential>(C)->isString();
1014 }
1015 
1016 const char *LLVMGetAsString(LLVMValueRef C, size_t *Length) {
1017  StringRef Str = unwrap<ConstantDataSequential>(C)->getAsString();
1018  *Length = Str.size();
1019  return Str.data();
1020 }
1021 
1023  LLVMValueRef *ConstantVals, unsigned Length) {
1024  ArrayRef<Constant*> V(unwrap<Constant>(ConstantVals, Length), Length);
1025  return wrap(ConstantArray::get(ArrayType::get(unwrap(ElementTy), Length), V));
1026 }
1027 
1029  LLVMValueRef *ConstantVals,
1030  unsigned Count, LLVMBool Packed) {
1031  Constant **Elements = unwrap<Constant>(ConstantVals, Count);
1032  return wrap(ConstantStruct::getAnon(*unwrap(C), makeArrayRef(Elements, Count),
1033  Packed != 0));
1034 }
1035 
1036 LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
1037  LLVMBool Packed) {
1038  return LLVMConstStructInContext(LLVMGetGlobalContext(), ConstantVals, Count,
1039  Packed);
1040 }
1041 
1043  LLVMValueRef *ConstantVals,
1044  unsigned Count) {
1045  Constant **Elements = unwrap<Constant>(ConstantVals, Count);
1046  StructType *Ty = cast<StructType>(unwrap(StructTy));
1047 
1048  return wrap(ConstantStruct::get(Ty, makeArrayRef(Elements, Count)));
1049 }
1050 
1051 LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size) {
1053  unwrap<Constant>(ScalarConstantVals, Size), Size)));
1054 }
1055 
1056 /*-- Opcode mapping */
1057 
1058 static LLVMOpcode map_to_llvmopcode(int opcode)
1059 {
1060  switch (opcode) {
1061  default: llvm_unreachable("Unhandled Opcode.");
1062 #define HANDLE_INST(num, opc, clas) case num: return LLVM##opc;
1063 #include "llvm/IR/Instruction.def"
1064 #undef HANDLE_INST
1065  }
1066 }
1067 
1069 {
1070  switch (code) {
1071 #define HANDLE_INST(num, opc, clas) case LLVM##opc: return num;
1072 #include "llvm/IR/Instruction.def"
1073 #undef HANDLE_INST
1074  }
1075  llvm_unreachable("Unhandled Opcode.");
1076 }
1077 
1078 /*--.. Constant expressions ................................................--*/
1079 
1081  return map_to_llvmopcode(unwrap<ConstantExpr>(ConstantVal)->getOpcode());
1082 }
1083 
1085  return wrap(ConstantExpr::getAlignOf(unwrap(Ty)));
1086 }
1087 
1089  return wrap(ConstantExpr::getSizeOf(unwrap(Ty)));
1090 }
1091 
1093  return wrap(ConstantExpr::getNeg(unwrap<Constant>(ConstantVal)));
1094 }
1095 
1097  return wrap(ConstantExpr::getNSWNeg(unwrap<Constant>(ConstantVal)));
1098 }
1099 
1101  return wrap(ConstantExpr::getNUWNeg(unwrap<Constant>(ConstantVal)));
1102 }
1103 
1104 
1106  return wrap(ConstantExpr::getFNeg(unwrap<Constant>(ConstantVal)));
1107 }
1108 
1110  return wrap(ConstantExpr::getNot(unwrap<Constant>(ConstantVal)));
1111 }
1112 
1114  return wrap(ConstantExpr::getAdd(unwrap<Constant>(LHSConstant),
1115  unwrap<Constant>(RHSConstant)));
1116 }
1117 
1119  LLVMValueRef RHSConstant) {
1120  return wrap(ConstantExpr::getNSWAdd(unwrap<Constant>(LHSConstant),
1121  unwrap<Constant>(RHSConstant)));
1122 }
1123 
1125  LLVMValueRef RHSConstant) {
1126  return wrap(ConstantExpr::getNUWAdd(unwrap<Constant>(LHSConstant),
1127  unwrap<Constant>(RHSConstant)));
1128 }
1129 
1131  return wrap(ConstantExpr::getFAdd(unwrap<Constant>(LHSConstant),
1132  unwrap<Constant>(RHSConstant)));
1133 }
1134 
1136  return wrap(ConstantExpr::getSub(unwrap<Constant>(LHSConstant),
1137  unwrap<Constant>(RHSConstant)));
1138 }
1139 
1141  LLVMValueRef RHSConstant) {
1142  return wrap(ConstantExpr::getNSWSub(unwrap<Constant>(LHSConstant),
1143  unwrap<Constant>(RHSConstant)));
1144 }
1145 
1147  LLVMValueRef RHSConstant) {
1148  return wrap(ConstantExpr::getNUWSub(unwrap<Constant>(LHSConstant),
1149  unwrap<Constant>(RHSConstant)));
1150 }
1151 
1153  return wrap(ConstantExpr::getFSub(unwrap<Constant>(LHSConstant),
1154  unwrap<Constant>(RHSConstant)));
1155 }
1156 
1158  return wrap(ConstantExpr::getMul(unwrap<Constant>(LHSConstant),
1159  unwrap<Constant>(RHSConstant)));
1160 }
1161 
1163  LLVMValueRef RHSConstant) {
1164  return wrap(ConstantExpr::getNSWMul(unwrap<Constant>(LHSConstant),
1165  unwrap<Constant>(RHSConstant)));
1166 }
1167 
1169  LLVMValueRef RHSConstant) {
1170  return wrap(ConstantExpr::getNUWMul(unwrap<Constant>(LHSConstant),
1171  unwrap<Constant>(RHSConstant)));
1172 }
1173 
1175  return wrap(ConstantExpr::getFMul(unwrap<Constant>(LHSConstant),
1176  unwrap<Constant>(RHSConstant)));
1177 }
1178 
1180  return wrap(ConstantExpr::getUDiv(unwrap<Constant>(LHSConstant),
1181  unwrap<Constant>(RHSConstant)));
1182 }
1183 
1185  LLVMValueRef RHSConstant) {
1186  return wrap(ConstantExpr::getExactUDiv(unwrap<Constant>(LHSConstant),
1187  unwrap<Constant>(RHSConstant)));
1188 }
1189 
1191  return wrap(ConstantExpr::getSDiv(unwrap<Constant>(LHSConstant),
1192  unwrap<Constant>(RHSConstant)));
1193 }
1194 
1196  LLVMValueRef RHSConstant) {
1197  return wrap(ConstantExpr::getExactSDiv(unwrap<Constant>(LHSConstant),
1198  unwrap<Constant>(RHSConstant)));
1199 }
1200 
1202  return wrap(ConstantExpr::getFDiv(unwrap<Constant>(LHSConstant),
1203  unwrap<Constant>(RHSConstant)));
1204 }
1205 
1207  return wrap(ConstantExpr::getURem(unwrap<Constant>(LHSConstant),
1208  unwrap<Constant>(RHSConstant)));
1209 }
1210 
1212  return wrap(ConstantExpr::getSRem(unwrap<Constant>(LHSConstant),
1213  unwrap<Constant>(RHSConstant)));
1214 }
1215 
1217  return wrap(ConstantExpr::getFRem(unwrap<Constant>(LHSConstant),
1218  unwrap<Constant>(RHSConstant)));
1219 }
1220 
1222  return wrap(ConstantExpr::getAnd(unwrap<Constant>(LHSConstant),
1223  unwrap<Constant>(RHSConstant)));
1224 }
1225 
1227  return wrap(ConstantExpr::getOr(unwrap<Constant>(LHSConstant),
1228  unwrap<Constant>(RHSConstant)));
1229 }
1230 
1232  return wrap(ConstantExpr::getXor(unwrap<Constant>(LHSConstant),
1233  unwrap<Constant>(RHSConstant)));
1234 }
1235 
1237  LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1238  return wrap(ConstantExpr::getICmp(Predicate,
1239  unwrap<Constant>(LHSConstant),
1240  unwrap<Constant>(RHSConstant)));
1241 }
1242 
1244  LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1245  return wrap(ConstantExpr::getFCmp(Predicate,
1246  unwrap<Constant>(LHSConstant),
1247  unwrap<Constant>(RHSConstant)));
1248 }
1249 
1251  return wrap(ConstantExpr::getShl(unwrap<Constant>(LHSConstant),
1252  unwrap<Constant>(RHSConstant)));
1253 }
1254 
1256  return wrap(ConstantExpr::getLShr(unwrap<Constant>(LHSConstant),
1257  unwrap<Constant>(RHSConstant)));
1258 }
1259 
1261  return wrap(ConstantExpr::getAShr(unwrap<Constant>(LHSConstant),
1262  unwrap<Constant>(RHSConstant)));
1263 }
1264 
1266  LLVMValueRef *ConstantIndices, unsigned NumIndices) {
1267  ArrayRef<Constant *> IdxList(unwrap<Constant>(ConstantIndices, NumIndices),
1268  NumIndices);
1270  nullptr, unwrap<Constant>(ConstantVal), IdxList));
1271 }
1272 
1274  LLVMValueRef *ConstantIndices,
1275  unsigned NumIndices) {
1276  Constant* Val = unwrap<Constant>(ConstantVal);
1277  ArrayRef<Constant *> IdxList(unwrap<Constant>(ConstantIndices, NumIndices),
1278  NumIndices);
1279  return wrap(ConstantExpr::getInBoundsGetElementPtr(nullptr, Val, IdxList));
1280 }
1281 
1283  return wrap(ConstantExpr::getTrunc(unwrap<Constant>(ConstantVal),
1284  unwrap(ToType)));
1285 }
1286 
1288  return wrap(ConstantExpr::getSExt(unwrap<Constant>(ConstantVal),
1289  unwrap(ToType)));
1290 }
1291 
1293  return wrap(ConstantExpr::getZExt(unwrap<Constant>(ConstantVal),
1294  unwrap(ToType)));
1295 }
1296 
1298  return wrap(ConstantExpr::getFPTrunc(unwrap<Constant>(ConstantVal),
1299  unwrap(ToType)));
1300 }
1301 
1303  return wrap(ConstantExpr::getFPExtend(unwrap<Constant>(ConstantVal),
1304  unwrap(ToType)));
1305 }
1306 
1308  return wrap(ConstantExpr::getUIToFP(unwrap<Constant>(ConstantVal),
1309  unwrap(ToType)));
1310 }
1311 
1313  return wrap(ConstantExpr::getSIToFP(unwrap<Constant>(ConstantVal),
1314  unwrap(ToType)));
1315 }
1316 
1318  return wrap(ConstantExpr::getFPToUI(unwrap<Constant>(ConstantVal),
1319  unwrap(ToType)));
1320 }
1321 
1323  return wrap(ConstantExpr::getFPToSI(unwrap<Constant>(ConstantVal),
1324  unwrap(ToType)));
1325 }
1326 
1328  return wrap(ConstantExpr::getPtrToInt(unwrap<Constant>(ConstantVal),
1329  unwrap(ToType)));
1330 }
1331 
1333  return wrap(ConstantExpr::getIntToPtr(unwrap<Constant>(ConstantVal),
1334  unwrap(ToType)));
1335 }
1336 
1338  return wrap(ConstantExpr::getBitCast(unwrap<Constant>(ConstantVal),
1339  unwrap(ToType)));
1340 }
1341 
1343  LLVMTypeRef ToType) {
1344  return wrap(ConstantExpr::getAddrSpaceCast(unwrap<Constant>(ConstantVal),
1345  unwrap(ToType)));
1346 }
1347 
1349  LLVMTypeRef ToType) {
1350  return wrap(ConstantExpr::getZExtOrBitCast(unwrap<Constant>(ConstantVal),
1351  unwrap(ToType)));
1352 }
1353 
1355  LLVMTypeRef ToType) {
1356  return wrap(ConstantExpr::getSExtOrBitCast(unwrap<Constant>(ConstantVal),
1357  unwrap(ToType)));
1358 }
1359 
1361  LLVMTypeRef ToType) {
1362  return wrap(ConstantExpr::getTruncOrBitCast(unwrap<Constant>(ConstantVal),
1363  unwrap(ToType)));
1364 }
1365 
1367  LLVMTypeRef ToType) {
1368  return wrap(ConstantExpr::getPointerCast(unwrap<Constant>(ConstantVal),
1369  unwrap(ToType)));
1370 }
1371 
1373  LLVMBool isSigned) {
1374  return wrap(ConstantExpr::getIntegerCast(unwrap<Constant>(ConstantVal),
1375  unwrap(ToType), isSigned));
1376 }
1377 
1379  return wrap(ConstantExpr::getFPCast(unwrap<Constant>(ConstantVal),
1380  unwrap(ToType)));
1381 }
1382 
1384  LLVMValueRef ConstantIfTrue,
1385  LLVMValueRef ConstantIfFalse) {
1386  return wrap(ConstantExpr::getSelect(unwrap<Constant>(ConstantCondition),
1387  unwrap<Constant>(ConstantIfTrue),
1388  unwrap<Constant>(ConstantIfFalse)));
1389 }
1390 
1392  LLVMValueRef IndexConstant) {
1393  return wrap(ConstantExpr::getExtractElement(unwrap<Constant>(VectorConstant),
1394  unwrap<Constant>(IndexConstant)));
1395 }
1396 
1398  LLVMValueRef ElementValueConstant,
1399  LLVMValueRef IndexConstant) {
1400  return wrap(ConstantExpr::getInsertElement(unwrap<Constant>(VectorConstant),
1401  unwrap<Constant>(ElementValueConstant),
1402  unwrap<Constant>(IndexConstant)));
1403 }
1404 
1406  LLVMValueRef VectorBConstant,
1407  LLVMValueRef MaskConstant) {
1408  return wrap(ConstantExpr::getShuffleVector(unwrap<Constant>(VectorAConstant),
1409  unwrap<Constant>(VectorBConstant),
1410  unwrap<Constant>(MaskConstant)));
1411 }
1412 
1413 LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
1414  unsigned NumIdx) {
1415  return wrap(ConstantExpr::getExtractValue(unwrap<Constant>(AggConstant),
1416  makeArrayRef(IdxList, NumIdx)));
1417 }
1418 
1420  LLVMValueRef ElementValueConstant,
1421  unsigned *IdxList, unsigned NumIdx) {
1422  return wrap(ConstantExpr::getInsertValue(unwrap<Constant>(AggConstant),
1423  unwrap<Constant>(ElementValueConstant),
1424  makeArrayRef(IdxList, NumIdx)));
1425 }
1426 
1427 LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty, const char *AsmString,
1428  const char *Constraints,
1429  LLVMBool HasSideEffects,
1430  LLVMBool IsAlignStack) {
1431  return wrap(InlineAsm::get(dyn_cast<FunctionType>(unwrap(Ty)), AsmString,
1432  Constraints, HasSideEffects, IsAlignStack));
1433 }
1434 
1436  return wrap(BlockAddress::get(unwrap<Function>(F), unwrap(BB)));
1437 }
1438 
1439 /*--.. Operations on global variables, functions, and aliases (globals) ....--*/
1440 
1442  return wrap(unwrap<GlobalValue>(Global)->getParent());
1443 }
1444 
1446  return unwrap<GlobalValue>(Global)->isDeclaration();
1447 }
1448 
1450  switch (unwrap<GlobalValue>(Global)->getLinkage()) {
1452  return LLVMExternalLinkage;
1456  return LLVMLinkOnceAnyLinkage;
1458  return LLVMLinkOnceODRLinkage;
1460  return LLVMWeakAnyLinkage;
1462  return LLVMWeakODRLinkage;
1464  return LLVMAppendingLinkage;
1466  return LLVMInternalLinkage;
1468  return LLVMPrivateLinkage;
1470  return LLVMExternalWeakLinkage;
1472  return LLVMCommonLinkage;
1473  }
1474 
1475  llvm_unreachable("Invalid GlobalValue linkage!");
1476 }
1477 
1478 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage) {
1479  GlobalValue *GV = unwrap<GlobalValue>(Global);
1480 
1481  switch (Linkage) {
1482  case LLVMExternalLinkage:
1484  break;
1487  break;
1490  break;
1493  break;
1495  DEBUG(errs() << "LLVMSetLinkage(): LLVMLinkOnceODRAutoHideLinkage is no "
1496  "longer supported.");
1497  break;
1498  case LLVMWeakAnyLinkage:
1500  break;
1501  case LLVMWeakODRLinkage:
1503  break;
1504  case LLVMAppendingLinkage:
1506  break;
1507  case LLVMInternalLinkage:
1509  break;
1510  case LLVMPrivateLinkage:
1512  break;
1515  break;
1518  break;
1519  case LLVMDLLImportLinkage:
1520  DEBUG(errs()
1521  << "LLVMSetLinkage(): LLVMDLLImportLinkage is no longer supported.");
1522  break;
1523  case LLVMDLLExportLinkage:
1524  DEBUG(errs()
1525  << "LLVMSetLinkage(): LLVMDLLExportLinkage is no longer supported.");
1526  break;
1529  break;
1530  case LLVMGhostLinkage:
1531  DEBUG(errs()
1532  << "LLVMSetLinkage(): LLVMGhostLinkage is no longer supported.");
1533  break;
1534  case LLVMCommonLinkage:
1536  break;
1537  }
1538 }
1539 
1540 const char *LLVMGetSection(LLVMValueRef Global) {
1541  // Using .data() is safe because of how GlobalObject::setSection is
1542  // implemented.
1543  return unwrap<GlobalValue>(Global)->getSection().data();
1544 }
1545 
1546 void LLVMSetSection(LLVMValueRef Global, const char *Section) {
1547  unwrap<GlobalObject>(Global)->setSection(Section);
1548 }
1549 
1551  return static_cast<LLVMVisibility>(
1552  unwrap<GlobalValue>(Global)->getVisibility());
1553 }
1554 
1556  unwrap<GlobalValue>(Global)
1557  ->setVisibility(static_cast<GlobalValue::VisibilityTypes>(Viz));
1558 }
1559 
1561  return static_cast<LLVMDLLStorageClass>(
1562  unwrap<GlobalValue>(Global)->getDLLStorageClass());
1563 }
1564 
1566  unwrap<GlobalValue>(Global)->setDLLStorageClass(
1567  static_cast<GlobalValue::DLLStorageClassTypes>(Class));
1568 }
1569 
1571  return unwrap<GlobalValue>(Global)->hasGlobalUnnamedAddr();
1572 }
1573 
1574 void LLVMSetUnnamedAddr(LLVMValueRef Global, LLVMBool HasUnnamedAddr) {
1575  unwrap<GlobalValue>(Global)->setUnnamedAddr(
1576  HasUnnamedAddr ? GlobalValue::UnnamedAddr::Global
1578 }
1579 
1580 /*--.. Operations on global variables, load and store instructions .........--*/
1581 
1583  Value *P = unwrap<Value>(V);
1584  if (GlobalValue *GV = dyn_cast<GlobalValue>(P))
1585  return GV->getAlignment();
1586  if (AllocaInst *AI = dyn_cast<AllocaInst>(P))
1587  return AI->getAlignment();
1588  if (LoadInst *LI = dyn_cast<LoadInst>(P))
1589  return LI->getAlignment();
1590  if (StoreInst *SI = dyn_cast<StoreInst>(P))
1591  return SI->getAlignment();
1592 
1594  "only GlobalValue, AllocaInst, LoadInst and StoreInst have alignment");
1595 }
1596 
1597 void LLVMSetAlignment(LLVMValueRef V, unsigned Bytes) {
1598  Value *P = unwrap<Value>(V);
1599  if (GlobalObject *GV = dyn_cast<GlobalObject>(P))
1600  GV->setAlignment(Bytes);
1601  else if (AllocaInst *AI = dyn_cast<AllocaInst>(P))
1602  AI->setAlignment(Bytes);
1603  else if (LoadInst *LI = dyn_cast<LoadInst>(P))
1604  LI->setAlignment(Bytes);
1605  else if (StoreInst *SI = dyn_cast<StoreInst>(P))
1606  SI->setAlignment(Bytes);
1607  else
1609  "only GlobalValue, AllocaInst, LoadInst and StoreInst have alignment");
1610 }
1611 
1612 /*--.. Operations on global variables ......................................--*/
1613 
1615  return wrap(new GlobalVariable(*unwrap(M), unwrap(Ty), false,
1616  GlobalValue::ExternalLinkage, nullptr, Name));
1617 }
1618 
1620  const char *Name,
1621  unsigned AddressSpace) {
1622  return wrap(new GlobalVariable(*unwrap(M), unwrap(Ty), false,
1623  GlobalValue::ExternalLinkage, nullptr, Name,
1625  AddressSpace));
1626 }
1627 
1629  return wrap(unwrap(M)->getNamedGlobal(Name));
1630 }
1631 
1633  Module *Mod = unwrap(M);
1635  if (I == Mod->global_end())
1636  return nullptr;
1637  return wrap(&*I);
1638 }
1639 
1641  Module *Mod = unwrap(M);
1643  if (I == Mod->global_begin())
1644  return nullptr;
1645  return wrap(&*--I);
1646 }
1647 
1649  GlobalVariable *GV = unwrap<GlobalVariable>(GlobalVar);
1651  if (++I == GV->getParent()->global_end())
1652  return nullptr;
1653  return wrap(&*I);
1654 }
1655 
1657  GlobalVariable *GV = unwrap<GlobalVariable>(GlobalVar);
1659  if (I == GV->getParent()->global_begin())
1660  return nullptr;
1661  return wrap(&*--I);
1662 }
1663 
1665  unwrap<GlobalVariable>(GlobalVar)->eraseFromParent();
1666 }
1667 
1669  GlobalVariable* GV = unwrap<GlobalVariable>(GlobalVar);
1670  if ( !GV->hasInitializer() )
1671  return nullptr;
1672  return wrap(GV->getInitializer());
1673 }
1674 
1676  unwrap<GlobalVariable>(GlobalVar)
1677  ->setInitializer(unwrap<Constant>(ConstantVal));
1678 }
1679 
1681  return unwrap<GlobalVariable>(GlobalVar)->isThreadLocal();
1682 }
1683 
1685  unwrap<GlobalVariable>(GlobalVar)->setThreadLocal(IsThreadLocal != 0);
1686 }
1687 
1689  return unwrap<GlobalVariable>(GlobalVar)->isConstant();
1690 }
1691 
1693  unwrap<GlobalVariable>(GlobalVar)->setConstant(IsConstant != 0);
1694 }
1695 
1697  switch (unwrap<GlobalVariable>(GlobalVar)->getThreadLocalMode()) {
1699  return LLVMNotThreadLocal;
1703  return LLVMLocalDynamicTLSModel;
1705  return LLVMInitialExecTLSModel;
1707  return LLVMLocalExecTLSModel;
1708  }
1709 
1710  llvm_unreachable("Invalid GlobalVariable thread local mode");
1711 }
1712 
1714  GlobalVariable *GV = unwrap<GlobalVariable>(GlobalVar);
1715 
1716  switch (Mode) {
1717  case LLVMNotThreadLocal:
1719  break;
1722  break;
1725  break;
1728  break;
1729  case LLVMLocalExecTLSModel:
1731  break;
1732  }
1733 }
1734 
1736  return unwrap<GlobalVariable>(GlobalVar)->isExternallyInitialized();
1737 }
1738 
1740  unwrap<GlobalVariable>(GlobalVar)->setExternallyInitialized(IsExtInit);
1741 }
1742 
1743 /*--.. Operations on aliases ......................................--*/
1744 
1746  const char *Name) {
1747  auto *PTy = cast<PointerType>(unwrap(Ty));
1748  return wrap(GlobalAlias::create(PTy->getElementType(), PTy->getAddressSpace(),
1750  unwrap<Constant>(Aliasee), unwrap(M)));
1751 }
1752 
1753 /*--.. Operations on functions .............................................--*/
1754 
1756  LLVMTypeRef FunctionTy) {
1757  return wrap(Function::Create(unwrap<FunctionType>(FunctionTy),
1759 }
1760 
1762  return wrap(unwrap(M)->getFunction(Name));
1763 }
1764 
1766  Module *Mod = unwrap(M);
1767  Module::iterator I = Mod->begin();
1768  if (I == Mod->end())
1769  return nullptr;
1770  return wrap(&*I);
1771 }
1772 
1774  Module *Mod = unwrap(M);
1775  Module::iterator I = Mod->end();
1776  if (I == Mod->begin())
1777  return nullptr;
1778  return wrap(&*--I);
1779 }
1780 
1782  Function *Func = unwrap<Function>(Fn);
1783  Module::iterator I(Func);
1784  if (++I == Func->getParent()->end())
1785  return nullptr;
1786  return wrap(&*I);
1787 }
1788 
1790  Function *Func = unwrap<Function>(Fn);
1791  Module::iterator I(Func);
1792  if (I == Func->getParent()->begin())
1793  return nullptr;
1794  return wrap(&*--I);
1795 }
1796 
1798  unwrap<Function>(Fn)->eraseFromParent();
1799 }
1800 
1802  return unwrap<Function>(Fn)->hasPersonalityFn();
1803 }
1804 
1806  return wrap(unwrap<Function>(Fn)->getPersonalityFn());
1807 }
1808 
1810  unwrap<Function>(Fn)->setPersonalityFn(unwrap<Constant>(PersonalityFn));
1811 }
1812 
1814  if (Function *F = dyn_cast<Function>(unwrap(Fn)))
1815  return F->getIntrinsicID();
1816  return 0;
1817 }
1818 
1820  return unwrap<Function>(Fn)->getCallingConv();
1821 }
1822 
1823 void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC) {
1824  return unwrap<Function>(Fn)->setCallingConv(
1825  static_cast<CallingConv::ID>(CC));
1826 }
1827 
1828 const char *LLVMGetGC(LLVMValueRef Fn) {
1829  Function *F = unwrap<Function>(Fn);
1830  return F->hasGC()? F->getGC().c_str() : nullptr;
1831 }
1832 
1833 void LLVMSetGC(LLVMValueRef Fn, const char *GC) {
1834  Function *F = unwrap<Function>(Fn);
1835  if (GC)
1836  F->setGC(GC);
1837  else
1838  F->clearGC();
1839 }
1840 
1842  LLVMAttributeRef A) {
1843  unwrap<Function>(F)->addAttribute(Idx, unwrap(A));
1844 }
1845 
1847  auto *ASN = AttributeSetNode::get(unwrap<Function>(F)->getAttributes(), Idx);
1848  if (!ASN)
1849  return 0;
1850  return ASN->getNumAttributes();
1851 }
1852 
1854  LLVMAttributeRef *Attrs) {
1855  auto *ASN = AttributeSetNode::get(unwrap<Function>(F)->getAttributes(), Idx);
1856  if (!ASN)
1857  return;
1858  for (auto A: make_range(ASN->begin(), ASN->end()))
1859  *Attrs++ = wrap(A);
1860 }
1861 
1863  LLVMAttributeIndex Idx,
1864  unsigned KindID) {
1865  return wrap(unwrap<Function>(F)->getAttribute(Idx,
1866  (Attribute::AttrKind)KindID));
1867 }
1868 
1870  LLVMAttributeIndex Idx,
1871  const char *K, unsigned KLen) {
1872  return wrap(unwrap<Function>(F)->getAttribute(Idx, StringRef(K, KLen)));
1873 }
1874 
1876  unsigned KindID) {
1877  unwrap<Function>(F)->removeAttribute(Idx, (Attribute::AttrKind)KindID);
1878 }
1879 
1881  const char *K, unsigned KLen) {
1882  unwrap<Function>(F)->removeAttribute(Idx, StringRef(K, KLen));
1883 }
1884 
1886  const char *V) {
1887  Function *Func = unwrap<Function>(Fn);
1890  AttrBuilder B;
1891 
1892  B.addAttribute(A, V);
1893  AttributeSet Set = AttributeSet::get(Func->getContext(), Idx, B);
1894  Func->addAttributes(Idx, Set);
1895 }
1896 
1897 /*--.. Operations on parameters ............................................--*/
1898 
1900  // This function is strictly redundant to
1901  // LLVMCountParamTypes(LLVMGetElementType(LLVMTypeOf(FnRef)))
1902  return unwrap<Function>(FnRef)->arg_size();
1903 }
1904 
1905 void LLVMGetParams(LLVMValueRef FnRef, LLVMValueRef *ParamRefs) {
1906  Function *Fn = unwrap<Function>(FnRef);
1907  for (Function::arg_iterator I = Fn->arg_begin(),
1908  E = Fn->arg_end(); I != E; I++)
1909  *ParamRefs++ = wrap(&*I);
1910 }
1911 
1912 LLVMValueRef LLVMGetParam(LLVMValueRef FnRef, unsigned index) {
1913  Function::arg_iterator AI = unwrap<Function>(FnRef)->arg_begin();
1914  while (index --> 0)
1915  AI++;
1916  return wrap(&*AI);
1917 }
1918 
1920  return wrap(unwrap<Argument>(V)->getParent());
1921 }
1922 
1924  Function *Func = unwrap<Function>(Fn);
1926  if (I == Func->arg_end())
1927  return nullptr;
1928  return wrap(&*I);
1929 }
1930 
1932  Function *Func = unwrap<Function>(Fn);
1933  Function::arg_iterator I = Func->arg_end();
1934  if (I == Func->arg_begin())
1935  return nullptr;
1936  return wrap(&*--I);
1937 }
1938 
1940  Argument *A = unwrap<Argument>(Arg);
1942  if (++I == A->getParent()->arg_end())
1943  return nullptr;
1944  return wrap(&*I);
1945 }
1946 
1948  Argument *A = unwrap<Argument>(Arg);
1950  if (I == A->getParent()->arg_begin())
1951  return nullptr;
1952  return wrap(&*--I);
1953 }
1954 
1955 void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align) {
1956  Argument *A = unwrap<Argument>(Arg);
1957  AttrBuilder B;
1958  B.addAlignmentAttr(align);
1959  A->addAttr(AttributeSet::get(A->getContext(),A->getArgNo() + 1, B));
1960 }
1961 
1962 /*--.. Operations on basic blocks ..........................................--*/
1963 
1965  return wrap(static_cast<Value*>(unwrap(BB)));
1966 }
1967 
1969  return isa<BasicBlock>(unwrap(Val));
1970 }
1971 
1973  return wrap(unwrap<BasicBlock>(Val));
1974 }
1975 
1977  return unwrap(BB)->getName().data();
1978 }
1979 
1981  return wrap(unwrap(BB)->getParent());
1982 }
1983 
1985  return wrap(unwrap(BB)->getTerminator());
1986 }
1987 
1989  return unwrap<Function>(FnRef)->size();
1990 }
1991 
1992 void LLVMGetBasicBlocks(LLVMValueRef FnRef, LLVMBasicBlockRef *BasicBlocksRefs){
1993  Function *Fn = unwrap<Function>(FnRef);
1994  for (BasicBlock &BB : *Fn)
1995  *BasicBlocksRefs++ = wrap(&BB);
1996 }
1997 
1999  return wrap(&unwrap<Function>(Fn)->getEntryBlock());
2000 }
2001 
2003  Function *Func = unwrap<Function>(Fn);
2004  Function::iterator I = Func->begin();
2005  if (I == Func->end())
2006  return nullptr;
2007  return wrap(&*I);
2008 }
2009 
2011  Function *Func = unwrap<Function>(Fn);
2012  Function::iterator I = Func->end();
2013  if (I == Func->begin())
2014  return nullptr;
2015  return wrap(&*--I);
2016 }
2017 
2019  BasicBlock *Block = unwrap(BB);
2020  Function::iterator I(Block);
2021  if (++I == Block->getParent()->end())
2022  return nullptr;
2023  return wrap(&*I);
2024 }
2025 
2027  BasicBlock *Block = unwrap(BB);
2028  Function::iterator I(Block);
2029  if (I == Block->getParent()->begin())
2030  return nullptr;
2031  return wrap(&*--I);
2032 }
2033 
2035  LLVMValueRef FnRef,
2036  const char *Name) {
2037  return wrap(BasicBlock::Create(*unwrap(C), Name, unwrap<Function>(FnRef)));
2038 }
2039 
2041  return LLVMAppendBasicBlockInContext(LLVMGetGlobalContext(), FnRef, Name);
2042 }
2043 
2045  LLVMBasicBlockRef BBRef,
2046  const char *Name) {
2047  BasicBlock *BB = unwrap(BBRef);
2048  return wrap(BasicBlock::Create(*unwrap(C), Name, BB->getParent(), BB));
2049 }
2050 
2052  const char *Name) {
2053  return LLVMInsertBasicBlockInContext(LLVMGetGlobalContext(), BBRef, Name);
2054 }
2055 
2057  unwrap(BBRef)->eraseFromParent();
2058 }
2059 
2061  unwrap(BBRef)->removeFromParent();
2062 }
2063 
2065  unwrap(BB)->moveBefore(unwrap(MovePos));
2066 }
2067 
2069  unwrap(BB)->moveAfter(unwrap(MovePos));
2070 }
2071 
2072 /*--.. Operations on instructions ..........................................--*/
2073 
2075  return wrap(unwrap<Instruction>(Inst)->getParent());
2076 }
2077 
2079  BasicBlock *Block = unwrap(BB);
2080  BasicBlock::iterator I = Block->begin();
2081  if (I == Block->end())
2082  return nullptr;
2083  return wrap(&*I);
2084 }
2085 
2087  BasicBlock *Block = unwrap(BB);
2088  BasicBlock::iterator I = Block->end();
2089  if (I == Block->begin())
2090  return nullptr;
2091  return wrap(&*--I);
2092 }
2093 
2095  Instruction *Instr = unwrap<Instruction>(Inst);
2096  BasicBlock::iterator I(Instr);
2097  if (++I == Instr->getParent()->end())
2098  return nullptr;
2099  return wrap(&*I);
2100 }
2101 
2103  Instruction *Instr = unwrap<Instruction>(Inst);
2104  BasicBlock::iterator I(Instr);
2105  if (I == Instr->getParent()->begin())
2106  return nullptr;
2107  return wrap(&*--I);
2108 }
2109 
2111  unwrap<Instruction>(Inst)->removeFromParent();
2112 }
2113 
2115  unwrap<Instruction>(Inst)->eraseFromParent();
2116 }
2117 
2119  if (ICmpInst *I = dyn_cast<ICmpInst>(unwrap(Inst)))
2120  return (LLVMIntPredicate)I->getPredicate();
2121  if (ConstantExpr *CE = dyn_cast<ConstantExpr>(unwrap(Inst)))
2122  if (CE->getOpcode() == Instruction::ICmp)
2123  return (LLVMIntPredicate)CE->getPredicate();
2124  return (LLVMIntPredicate)0;
2125 }
2126 
2128  if (FCmpInst *I = dyn_cast<FCmpInst>(unwrap(Inst)))
2129  return (LLVMRealPredicate)I->getPredicate();
2130  if (ConstantExpr *CE = dyn_cast<ConstantExpr>(unwrap(Inst)))
2131  if (CE->getOpcode() == Instruction::FCmp)
2132  return (LLVMRealPredicate)CE->getPredicate();
2133  return (LLVMRealPredicate)0;
2134 }
2135 
2137  if (Instruction *C = dyn_cast<Instruction>(unwrap(Inst)))
2138  return map_to_llvmopcode(C->getOpcode());
2139  return (LLVMOpcode)0;
2140 }
2141 
2143  if (Instruction *C = dyn_cast<Instruction>(unwrap(Inst)))
2144  return wrap(C->clone());
2145  return nullptr;
2146 }
2147 
2148 /*--.. Call and invoke instructions ........................................--*/
2149 
2151  return CallSite(unwrap<Instruction>(Instr)).getNumArgOperands();
2152 }
2153 
2155  return CallSite(unwrap<Instruction>(Instr)).getCallingConv();
2156 }
2157 
2158 void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC) {
2159  return CallSite(unwrap<Instruction>(Instr))
2160  .setCallingConv(static_cast<CallingConv::ID>(CC));
2161 }
2162 
2163 void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
2164  unsigned align) {
2165  CallSite Call = CallSite(unwrap<Instruction>(Instr));
2166  AttrBuilder B;
2167  B.addAlignmentAttr(align);
2168  Call.setAttributes(Call.getAttributes()
2169  .addAttributes(Call->getContext(), index,
2170  AttributeSet::get(Call->getContext(),
2171  index, B)));
2172 }
2173 
2175  LLVMAttributeRef A) {
2176  CallSite(unwrap<Instruction>(C)).addAttribute(Idx, unwrap(A));
2177 }
2178 
2180  LLVMAttributeIndex Idx) {
2181  auto CS = CallSite(unwrap<Instruction>(C));
2182  auto *ASN = AttributeSetNode::get(CS.getAttributes(), Idx);
2183  if (!ASN)
2184  return 0;
2185  return ASN->getNumAttributes();
2186 }
2187 
2189  LLVMAttributeRef *Attrs) {
2190  auto CS = CallSite(unwrap<Instruction>(C));
2191  auto *ASN = AttributeSetNode::get(CS.getAttributes(), Idx);
2192  if (!ASN)
2193  return;
2194  for (auto A: make_range(ASN->begin(), ASN->end()))
2195  *Attrs++ = wrap(A);
2196 }
2197 
2199  LLVMAttributeIndex Idx,
2200  unsigned KindID) {
2201  return wrap(CallSite(unwrap<Instruction>(C))
2202  .getAttribute(Idx, (Attribute::AttrKind)KindID));
2203 }
2204 
2206  LLVMAttributeIndex Idx,
2207  const char *K, unsigned KLen) {
2208  return wrap(CallSite(unwrap<Instruction>(C))
2209  .getAttribute(Idx, StringRef(K, KLen)));
2210 }
2211 
2213  unsigned KindID) {
2214  CallSite(unwrap<Instruction>(C))
2215  .removeAttribute(Idx, (Attribute::AttrKind)KindID);
2216 }
2217 
2219  const char *K, unsigned KLen) {
2220  CallSite(unwrap<Instruction>(C)).removeAttribute(Idx, StringRef(K, KLen));
2221 }
2222 
2224  return wrap(CallSite(unwrap<Instruction>(Instr)).getCalledValue());
2225 }
2226 
2227 /*--.. Operations on call instructions (only) ..............................--*/
2228 
2230  return unwrap<CallInst>(Call)->isTailCall();
2231 }
2232 
2234  unwrap<CallInst>(Call)->setTailCall(isTailCall);
2235 }
2236 
2237 /*--.. Operations on invoke instructions (only) ............................--*/
2238 
2240  return wrap(unwrap<InvokeInst>(Invoke)->getNormalDest());
2241 }
2242 
2244  return wrap(unwrap<InvokeInst>(Invoke)->getUnwindDest());
2245 }
2246 
2248  unwrap<InvokeInst>(Invoke)->setNormalDest(unwrap(B));
2249 }
2250 
2252  unwrap<InvokeInst>(Invoke)->setUnwindDest(unwrap(B));
2253 }
2254 
2255 /*--.. Operations on terminators ...........................................--*/
2256 
2258  return unwrap<TerminatorInst>(Term)->getNumSuccessors();
2259 }
2260 
2262  return wrap(unwrap<TerminatorInst>(Term)->getSuccessor(i));
2263 }
2264 
2265 void LLVMSetSuccessor(LLVMValueRef Term, unsigned i, LLVMBasicBlockRef block) {
2266  return unwrap<TerminatorInst>(Term)->setSuccessor(i,unwrap(block));
2267 }
2268 
2269 /*--.. Operations on branch instructions (only) ............................--*/
2270 
2272  return unwrap<BranchInst>(Branch)->isConditional();
2273 }
2274 
2276  return wrap(unwrap<BranchInst>(Branch)->getCondition());
2277 }
2278 
2280  return unwrap<BranchInst>(Branch)->setCondition(unwrap(Cond));
2281 }
2282 
2283 /*--.. Operations on switch instructions (only) ............................--*/
2284 
2286  return wrap(unwrap<SwitchInst>(Switch)->getDefaultDest());
2287 }
2288 
2289 /*--.. Operations on alloca instructions (only) ............................--*/
2290 
2292  return wrap(unwrap<AllocaInst>(Alloca)->getAllocatedType());
2293 }
2294 
2295 /*--.. Operations on gep instructions (only) ...............................--*/
2296 
2298  return unwrap<GetElementPtrInst>(GEP)->isInBounds();
2299 }
2300 
2302  return unwrap<GetElementPtrInst>(GEP)->setIsInBounds(InBounds);
2303 }
2304 
2305 /*--.. Operations on phi nodes .............................................--*/
2306 
2307 void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
2308  LLVMBasicBlockRef *IncomingBlocks, unsigned Count) {
2309  PHINode *PhiVal = unwrap<PHINode>(PhiNode);
2310  for (unsigned I = 0; I != Count; ++I)
2311  PhiVal->addIncoming(unwrap(IncomingValues[I]), unwrap(IncomingBlocks[I]));
2312 }
2313 
2314 unsigned LLVMCountIncoming(LLVMValueRef PhiNode) {
2315  return unwrap<PHINode>(PhiNode)->getNumIncomingValues();
2316 }
2317 
2319  return wrap(unwrap<PHINode>(PhiNode)->getIncomingValue(Index));
2320 }
2321 
2323  return wrap(unwrap<PHINode>(PhiNode)->getIncomingBlock(Index));
2324 }
2325 
2326 /*--.. Operations on extractvalue and insertvalue nodes ....................--*/
2327 
2329  auto *I = unwrap(Inst);
2330  if (auto *GEP = dyn_cast<GetElementPtrInst>(I))
2331  return GEP->getNumIndices();
2332  if (auto *EV = dyn_cast<ExtractValueInst>(I))
2333  return EV->getNumIndices();
2334  if (auto *IV = dyn_cast<InsertValueInst>(I))
2335  return IV->getNumIndices();
2337  "LLVMGetNumIndices applies only to extractvalue and insertvalue!");
2338 }
2339 
2340 const unsigned *LLVMGetIndices(LLVMValueRef Inst) {
2341  auto *I = unwrap(Inst);
2342  if (auto *EV = dyn_cast<ExtractValueInst>(I))
2343  return EV->getIndices().data();
2344  if (auto *IV = dyn_cast<InsertValueInst>(I))
2345  return IV->getIndices().data();
2347  "LLVMGetIndices applies only to extractvalue and insertvalue!");
2348 }
2349 
2350 
2351 /*===-- Instruction builders ----------------------------------------------===*/
2352 
2354  return wrap(new IRBuilder<>(*unwrap(C)));
2355 }
2356 
2359 }
2360 
2362  LLVMValueRef Instr) {
2363  BasicBlock *BB = unwrap(Block);
2364  auto I = Instr ? unwrap<Instruction>(Instr)->getIterator() : BB->end();
2365  unwrap(Builder)->SetInsertPoint(BB, I);
2366 }
2367 
2369  Instruction *I = unwrap<Instruction>(Instr);
2370  unwrap(Builder)->SetInsertPoint(I->getParent(), I->getIterator());
2371 }
2372 
2374  BasicBlock *BB = unwrap(Block);
2375  unwrap(Builder)->SetInsertPoint(BB);
2376 }
2377 
2379  return wrap(unwrap(Builder)->GetInsertBlock());
2380 }
2381 
2383  unwrap(Builder)->ClearInsertionPoint();
2384 }
2385 
2387  unwrap(Builder)->Insert(unwrap<Instruction>(Instr));
2388 }
2389 
2391  const char *Name) {
2392  unwrap(Builder)->Insert(unwrap<Instruction>(Instr), Name);
2393 }
2394 
2396  delete unwrap(Builder);
2397 }
2398 
2399 /*--.. Metadata builders ...................................................--*/
2400 
2402  MDNode *Loc =
2403  L ? cast<MDNode>(unwrap<MetadataAsValue>(L)->getMetadata()) : nullptr;
2404  unwrap(Builder)->SetCurrentDebugLocation(DebugLoc(Loc));
2405 }
2406 
2408  LLVMContext &Context = unwrap(Builder)->getContext();
2409  return wrap(MetadataAsValue::get(
2410  Context, unwrap(Builder)->getCurrentDebugLocation().getAsMDNode()));
2411 }
2412 
2414  unwrap(Builder)->SetInstDebugLocation(unwrap<Instruction>(Inst));
2415 }
2416 
2417 
2418 /*--.. Instruction builders ................................................--*/
2419 
2421  return wrap(unwrap(B)->CreateRetVoid());
2422 }
2423 
2425  return wrap(unwrap(B)->CreateRet(unwrap(V)));
2426 }
2427 
2429  unsigned N) {
2430  return wrap(unwrap(B)->CreateAggregateRet(unwrap(RetVals), N));
2431 }
2432 
2434  return wrap(unwrap(B)->CreateBr(unwrap(Dest)));
2435 }
2436 
2438  LLVMBasicBlockRef Then, LLVMBasicBlockRef Else) {
2439  return wrap(unwrap(B)->CreateCondBr(unwrap(If), unwrap(Then), unwrap(Else)));
2440 }
2441 
2443  LLVMBasicBlockRef Else, unsigned NumCases) {
2444  return wrap(unwrap(B)->CreateSwitch(unwrap(V), unwrap(Else), NumCases));
2445 }
2446 
2448  unsigned NumDests) {
2449  return wrap(unwrap(B)->CreateIndirectBr(unwrap(Addr), NumDests));
2450 }
2451 
2453  LLVMValueRef *Args, unsigned NumArgs,
2455  const char *Name) {
2456  return wrap(unwrap(B)->CreateInvoke(unwrap(Fn), unwrap(Then), unwrap(Catch),
2457  makeArrayRef(unwrap(Args), NumArgs),
2458  Name));
2459 }
2460 
2462  LLVMValueRef PersFn, unsigned NumClauses,
2463  const char *Name) {
2464  // The personality used to live on the landingpad instruction, but now it
2465  // lives on the parent function. For compatibility, take the provided
2466  // personality and put it on the parent function.
2467  if (PersFn)
2468  unwrap(B)->GetInsertBlock()->getParent()->setPersonalityFn(
2469  cast<Function>(unwrap(PersFn)));
2470  return wrap(unwrap(B)->CreateLandingPad(unwrap(Ty), NumClauses, Name));
2471 }
2472 
2474  return wrap(unwrap(B)->CreateResume(unwrap(Exn)));
2475 }
2476 
2478  return wrap(unwrap(B)->CreateUnreachable());
2479 }
2480 
2482  LLVMBasicBlockRef Dest) {
2483  unwrap<SwitchInst>(Switch)->addCase(unwrap<ConstantInt>(OnVal), unwrap(Dest));
2484 }
2485 
2487  unwrap<IndirectBrInst>(IndirectBr)->addDestination(unwrap(Dest));
2488 }
2489 
2490 unsigned LLVMGetNumClauses(LLVMValueRef LandingPad) {
2491  return unwrap<LandingPadInst>(LandingPad)->getNumClauses();
2492 }
2493 
2494 LLVMValueRef LLVMGetClause(LLVMValueRef LandingPad, unsigned Idx) {
2495  return wrap(unwrap<LandingPadInst>(LandingPad)->getClause(Idx));
2496 }
2497 
2498 void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal) {
2499  unwrap<LandingPadInst>(LandingPad)->
2500  addClause(cast<Constant>(unwrap(ClauseVal)));
2501 }
2502 
2504  return unwrap<LandingPadInst>(LandingPad)->isCleanup();
2505 }
2506 
2507 void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val) {
2508  unwrap<LandingPadInst>(LandingPad)->setCleanup(Val);
2509 }
2510 
2511 /*--.. Arithmetic ..........................................................--*/
2512 
2514  const char *Name) {
2515  return wrap(unwrap(B)->CreateAdd(unwrap(LHS), unwrap(RHS), Name));
2516 }
2517 
2519  const char *Name) {
2520  return wrap(unwrap(B)->CreateNSWAdd(unwrap(LHS), unwrap(RHS), Name));
2521 }
2522 
2524  const char *Name) {
2525  return wrap(unwrap(B)->CreateNUWAdd(unwrap(LHS), unwrap(RHS), Name));
2526 }
2527 
2529  const char *Name) {
2530  return wrap(unwrap(B)->CreateFAdd(unwrap(LHS), unwrap(RHS), Name));
2531 }
2532 
2534  const char *Name) {
2535  return wrap(unwrap(B)->CreateSub(unwrap(LHS), unwrap(RHS), Name));
2536 }
2537 
2539  const char *Name) {
2540  return wrap(unwrap(B)->CreateNSWSub(unwrap(LHS), unwrap(RHS), Name));
2541 }
2542 
2544  const char *Name) {
2545  return wrap(unwrap(B)->CreateNUWSub(unwrap(LHS), unwrap(RHS), Name));
2546 }
2547 
2549  const char *Name) {
2550  return wrap(unwrap(B)->CreateFSub(unwrap(LHS), unwrap(RHS), Name));
2551 }
2552 
2554  const char *Name) {
2555  return wrap(unwrap(B)->CreateMul(unwrap(LHS), unwrap(RHS), Name));
2556 }
2557 
2559  const char *Name) {
2560  return wrap(unwrap(B)->CreateNSWMul(unwrap(LHS), unwrap(RHS), Name));
2561 }
2562 
2564  const char *Name) {
2565  return wrap(unwrap(B)->CreateNUWMul(unwrap(LHS), unwrap(RHS), Name));
2566 }
2567 
2569  const char *Name) {
2570  return wrap(unwrap(B)->CreateFMul(unwrap(LHS), unwrap(RHS), Name));
2571 }
2572 
2574  const char *Name) {
2575  return wrap(unwrap(B)->CreateUDiv(unwrap(LHS), unwrap(RHS), Name));
2576 }
2577 
2579  LLVMValueRef RHS, const char *Name) {
2580  return wrap(unwrap(B)->CreateExactUDiv(unwrap(LHS), unwrap(RHS), Name));
2581 }
2582 
2584  const char *Name) {
2585  return wrap(unwrap(B)->CreateSDiv(unwrap(LHS), unwrap(RHS), Name));
2586 }
2587 
2589  LLVMValueRef RHS, const char *Name) {
2590  return wrap(unwrap(B)->CreateExactSDiv(unwrap(LHS), unwrap(RHS), Name));
2591 }
2592 
2594  const char *Name) {
2595  return wrap(unwrap(B)->CreateFDiv(unwrap(LHS), unwrap(RHS), Name));
2596 }
2597 
2599  const char *Name) {
2600  return wrap(unwrap(B)->CreateURem(unwrap(LHS), unwrap(RHS), Name));
2601 }
2602 
2604  const char *Name) {
2605  return wrap(unwrap(B)->CreateSRem(unwrap(LHS), unwrap(RHS), Name));
2606 }
2607 
2609  const char *Name) {
2610  return wrap(unwrap(B)->CreateFRem(unwrap(LHS), unwrap(RHS), Name));
2611 }
2612 
2614  const char *Name) {
2615  return wrap(unwrap(B)->CreateShl(unwrap(LHS), unwrap(RHS), Name));
2616 }
2617 
2619  const char *Name) {
2620  return wrap(unwrap(B)->CreateLShr(unwrap(LHS), unwrap(RHS), Name));
2621 }
2622 
2624  const char *Name) {
2625  return wrap(unwrap(B)->CreateAShr(unwrap(LHS), unwrap(RHS), Name));
2626 }
2627 
2629  const char *Name) {
2630  return wrap(unwrap(B)->CreateAnd(unwrap(LHS), unwrap(RHS), Name));
2631 }
2632 
2634  const char *Name) {
2635  return wrap(unwrap(B)->CreateOr(unwrap(LHS), unwrap(RHS), Name));
2636 }
2637 
2639  const char *Name) {
2640  return wrap(unwrap(B)->CreateXor(unwrap(LHS), unwrap(RHS), Name));
2641 }
2642 
2644  LLVMValueRef LHS, LLVMValueRef RHS,
2645  const char *Name) {
2646  return wrap(unwrap(B)->CreateBinOp(Instruction::BinaryOps(map_from_llvmopcode(Op)), unwrap(LHS),
2647  unwrap(RHS), Name));
2648 }
2649 
2651  return wrap(unwrap(B)->CreateNeg(unwrap(V), Name));
2652 }
2653 
2655  const char *Name) {
2656  return wrap(unwrap(B)->CreateNSWNeg(unwrap(V), Name));
2657 }
2658 
2660  const char *Name) {
2661  return wrap(unwrap(B)->CreateNUWNeg(unwrap(V), Name));
2662 }
2663 
2665  return wrap(unwrap(B)->CreateFNeg(unwrap(V), Name));
2666 }
2667 
2669  return wrap(unwrap(B)->CreateNot(unwrap(V), Name));
2670 }
2671 
2672 /*--.. Memory ..............................................................--*/
2673 
2675  const char *Name) {
2676  Type* ITy = Type::getInt32Ty(unwrap(B)->GetInsertBlock()->getContext());
2677  Constant* AllocSize = ConstantExpr::getSizeOf(unwrap(Ty));
2678  AllocSize = ConstantExpr::getTruncOrBitCast(AllocSize, ITy);
2679  Instruction* Malloc = CallInst::CreateMalloc(unwrap(B)->GetInsertBlock(),
2680  ITy, unwrap(Ty), AllocSize,
2681  nullptr, nullptr, "");
2682  return wrap(unwrap(B)->Insert(Malloc, Twine(Name)));
2683 }
2684 
2686  LLVMValueRef Val, const char *Name) {
2687  Type* ITy = Type::getInt32Ty(unwrap(B)->GetInsertBlock()->getContext());
2688  Constant* AllocSize = ConstantExpr::getSizeOf(unwrap(Ty));
2689  AllocSize = ConstantExpr::getTruncOrBitCast(AllocSize, ITy);
2690  Instruction* Malloc = CallInst::CreateMalloc(unwrap(B)->GetInsertBlock(),
2691  ITy, unwrap(Ty), AllocSize,
2692  unwrap(Val), nullptr, "");
2693  return wrap(unwrap(B)->Insert(Malloc, Twine(Name)));
2694 }
2695 
2697  const char *Name) {
2698  return wrap(unwrap(B)->CreateAlloca(unwrap(Ty), nullptr, Name));
2699 }
2700 
2702  LLVMValueRef Val, const char *Name) {
2703  return wrap(unwrap(B)->CreateAlloca(unwrap(Ty), unwrap(Val), Name));
2704 }
2705 
2707  return wrap(unwrap(B)->Insert(
2708  CallInst::CreateFree(unwrap(PointerVal), unwrap(B)->GetInsertBlock())));
2709 }
2710 
2712  const char *Name) {
2713  return wrap(unwrap(B)->CreateLoad(unwrap(PointerVal), Name));
2714 }
2715 
2717  LLVMValueRef PointerVal) {
2718  return wrap(unwrap(B)->CreateStore(unwrap(Val), unwrap(PointerVal)));
2719 }
2720 
2722  switch (Ordering) {
2732  }
2733 
2734  llvm_unreachable("Invalid LLVMAtomicOrdering value!");
2735 }
2736 
2738  switch (Ordering) {
2748  }
2749 
2750  llvm_unreachable("Invalid AtomicOrdering value!");
2751 }
2752 
2754  LLVMBool isSingleThread, const char *Name) {
2755  return wrap(
2756  unwrap(B)->CreateFence(mapFromLLVMOrdering(Ordering),
2757  isSingleThread ? SingleThread : CrossThread,
2758  Name));
2759 }
2760 
2762  LLVMValueRef *Indices, unsigned NumIndices,
2763  const char *Name) {
2764  ArrayRef<Value *> IdxList(unwrap(Indices), NumIndices);
2765  return wrap(unwrap(B)->CreateGEP(nullptr, unwrap(Pointer), IdxList, Name));
2766 }
2767 
2769  LLVMValueRef *Indices, unsigned NumIndices,
2770  const char *Name) {
2771  ArrayRef<Value *> IdxList(unwrap(Indices), NumIndices);
2772  return wrap(
2773  unwrap(B)->CreateInBoundsGEP(nullptr, unwrap(Pointer), IdxList, Name));
2774 }
2775 
2777  unsigned Idx, const char *Name) {
2778  return wrap(unwrap(B)->CreateStructGEP(nullptr, unwrap(Pointer), Idx, Name));
2779 }
2780 
2782  const char *Name) {
2783  return wrap(unwrap(B)->CreateGlobalString(Str, Name));
2784 }
2785 
2787  const char *Name) {
2788  return wrap(unwrap(B)->CreateGlobalStringPtr(Str, Name));
2789 }
2790 
2792  Value *P = unwrap<Value>(MemAccessInst);
2793  if (LoadInst *LI = dyn_cast<LoadInst>(P))
2794  return LI->isVolatile();
2795  return cast<StoreInst>(P)->isVolatile();
2796 }
2797 
2799  Value *P = unwrap<Value>(MemAccessInst);
2800  if (LoadInst *LI = dyn_cast<LoadInst>(P))
2801  return LI->setVolatile(isVolatile);
2802  return cast<StoreInst>(P)->setVolatile(isVolatile);
2803 }
2804 
2806  Value *P = unwrap<Value>(MemAccessInst);
2807  AtomicOrdering O;
2808  if (LoadInst *LI = dyn_cast<LoadInst>(P))
2809  O = LI->getOrdering();
2810  else
2811  O = cast<StoreInst>(P)->getOrdering();
2812  return mapToLLVMOrdering(O);
2813 }
2814 
2815 void LLVMSetOrdering(LLVMValueRef MemAccessInst, LLVMAtomicOrdering Ordering) {
2816  Value *P = unwrap<Value>(MemAccessInst);
2817  AtomicOrdering O = mapFromLLVMOrdering(Ordering);
2818 
2819  if (LoadInst *LI = dyn_cast<LoadInst>(P))
2820  return LI->setOrdering(O);
2821  return cast<StoreInst>(P)->setOrdering(O);
2822 }
2823 
2824 /*--.. Casts ...............................................................--*/
2825 
2827  LLVMTypeRef DestTy, const char *Name) {
2828  return wrap(unwrap(B)->CreateTrunc(unwrap(Val), unwrap(DestTy), Name));
2829 }
2830 
2832  LLVMTypeRef DestTy, const char *Name) {
2833  return wrap(unwrap(B)->CreateZExt(unwrap(Val), unwrap(DestTy), Name));
2834 }
2835 
2837  LLVMTypeRef DestTy, const char *Name) {
2838  return wrap(unwrap(B)->CreateSExt(unwrap(Val), unwrap(DestTy), Name));
2839 }
2840 
2842  LLVMTypeRef DestTy, const char *Name) {
2843  return wrap(unwrap(B)->CreateFPToUI(unwrap(Val), unwrap(DestTy), Name));
2844 }
2845 
2847  LLVMTypeRef DestTy, const char *Name) {
2848  return wrap(unwrap(B)->CreateFPToSI(unwrap(Val), unwrap(DestTy), Name));
2849 }
2850 
2852  LLVMTypeRef DestTy, const char *Name) {
2853  return wrap(unwrap(B)->CreateUIToFP(unwrap(Val), unwrap(DestTy), Name));
2854 }
2855 
2857  LLVMTypeRef DestTy, const char *Name) {
2858  return wrap(unwrap(B)->CreateSIToFP(unwrap(Val), unwrap(DestTy), Name));
2859 }
2860 
2862  LLVMTypeRef DestTy, const char *Name) {
2863  return wrap(unwrap(B)->CreateFPTrunc(unwrap(Val), unwrap(DestTy), Name));
2864 }
2865 
2867  LLVMTypeRef DestTy, const char *Name) {
2868  return wrap(unwrap(B)->CreateFPExt(unwrap(Val), unwrap(DestTy), Name));
2869 }
2870 
2872  LLVMTypeRef DestTy, const char *Name) {
2873  return wrap(unwrap(B)->CreatePtrToInt(unwrap(Val), unwrap(DestTy), Name));
2874 }
2875 
2877  LLVMTypeRef DestTy, const char *Name) {
2878  return wrap(unwrap(B)->CreateIntToPtr(unwrap(Val), unwrap(DestTy), Name));
2879 }
2880 
2882  LLVMTypeRef DestTy, const char *Name) {
2883  return wrap(unwrap(B)->CreateBitCast(unwrap(Val), unwrap(DestTy), Name));
2884 }
2885 
2887  LLVMTypeRef DestTy, const char *Name) {
2888  return wrap(unwrap(B)->CreateAddrSpaceCast(unwrap(Val), unwrap(DestTy), Name));
2889 }
2890 
2892  LLVMTypeRef DestTy, const char *Name) {
2893  return wrap(unwrap(B)->CreateZExtOrBitCast(unwrap(Val), unwrap(DestTy),
2894  Name));
2895 }
2896 
2898  LLVMTypeRef DestTy, const char *Name) {
2899  return wrap(unwrap(B)->CreateSExtOrBitCast(unwrap(Val), unwrap(DestTy),
2900  Name));
2901 }
2902 
2904  LLVMTypeRef DestTy, const char *Name) {
2905  return wrap(unwrap(B)->CreateTruncOrBitCast(unwrap(Val), unwrap(DestTy),
2906  Name));
2907 }
2908 
2910  LLVMTypeRef DestTy, const char *Name) {
2911  return wrap(unwrap(B)->CreateCast(Instruction::CastOps(map_from_llvmopcode(Op)), unwrap(Val),
2912  unwrap(DestTy), Name));
2913 }
2914 
2916  LLVMTypeRef DestTy, const char *Name) {
2917  return wrap(unwrap(B)->CreatePointerCast(unwrap(Val), unwrap(DestTy), Name));
2918 }
2919 
2921  LLVMTypeRef DestTy, const char *Name) {
2922  return wrap(unwrap(B)->CreateIntCast(unwrap(Val), unwrap(DestTy),
2923  /*isSigned*/true, Name));
2924 }
2925 
2927  LLVMTypeRef DestTy, const char *Name) {
2928  return wrap(unwrap(B)->CreateFPCast(unwrap(Val), unwrap(DestTy), Name));
2929 }
2930 
2931 /*--.. Comparisons .........................................................--*/
2932 
2934  LLVMValueRef LHS, LLVMValueRef RHS,
2935  const char *Name) {
2936  return wrap(unwrap(B)->CreateICmp(static_cast<ICmpInst::Predicate>(Op),
2937  unwrap(LHS), unwrap(RHS), Name));
2938 }
2939 
2941  LLVMValueRef LHS, LLVMValueRef RHS,
2942  const char *Name) {
2943  return wrap(unwrap(B)->CreateFCmp(static_cast<FCmpInst::Predicate>(Op),
2944  unwrap(LHS), unwrap(RHS), Name));
2945 }
2946 
2947 /*--.. Miscellaneous instructions ..........................................--*/
2948 
2950  return wrap(unwrap(B)->CreatePHI(unwrap(Ty), 0, Name));
2951 }
2952 
2954  LLVMValueRef *Args, unsigned NumArgs,
2955  const char *Name) {
2956  return wrap(unwrap(B)->CreateCall(unwrap(Fn),
2957  makeArrayRef(unwrap(Args), NumArgs),
2958  Name));
2959 }
2960 
2962  LLVMValueRef Then, LLVMValueRef Else,
2963  const char *Name) {
2964  return wrap(unwrap(B)->CreateSelect(unwrap(If), unwrap(Then), unwrap(Else),
2965  Name));
2966 }
2967 
2969  LLVMTypeRef Ty, const char *Name) {
2970  return wrap(unwrap(B)->CreateVAArg(unwrap(List), unwrap(Ty), Name));
2971 }
2972 
2974  LLVMValueRef Index, const char *Name) {
2975  return wrap(unwrap(B)->CreateExtractElement(unwrap(VecVal), unwrap(Index),
2976  Name));
2977 }
2978 
2980  LLVMValueRef EltVal, LLVMValueRef Index,
2981  const char *Name) {
2982  return wrap(unwrap(B)->CreateInsertElement(unwrap(VecVal), unwrap(EltVal),
2983  unwrap(Index), Name));
2984 }
2985 
2988  const char *Name) {
2989  return wrap(unwrap(B)->CreateShuffleVector(unwrap(V1), unwrap(V2),
2990  unwrap(Mask), Name));
2991 }
2992 
2994  unsigned Index, const char *Name) {
2995  return wrap(unwrap(B)->CreateExtractValue(unwrap(AggVal), Index, Name));
2996 }
2997 
2999  LLVMValueRef EltVal, unsigned Index,
3000  const char *Name) {
3001  return wrap(unwrap(B)->CreateInsertValue(unwrap(AggVal), unwrap(EltVal),
3002  Index, Name));
3003 }
3004 
3006  const char *Name) {
3007  return wrap(unwrap(B)->CreateIsNull(unwrap(Val), Name));
3008 }
3009 
3011  const char *Name) {
3012  return wrap(unwrap(B)->CreateIsNotNull(unwrap(Val), Name));
3013 }
3014 
3016  LLVMValueRef RHS, const char *Name) {
3017  return wrap(unwrap(B)->CreatePtrDiff(unwrap(LHS), unwrap(RHS), Name));
3018 }
3019 
3021  LLVMValueRef PTR, LLVMValueRef Val,
3022  LLVMAtomicOrdering ordering,
3023  LLVMBool singleThread) {
3024  AtomicRMWInst::BinOp intop;
3025  switch (op) {
3026  case LLVMAtomicRMWBinOpXchg: intop = AtomicRMWInst::Xchg; break;
3027  case LLVMAtomicRMWBinOpAdd: intop = AtomicRMWInst::Add; break;
3028  case LLVMAtomicRMWBinOpSub: intop = AtomicRMWInst::Sub; break;
3029  case LLVMAtomicRMWBinOpAnd: intop = AtomicRMWInst::And; break;
3030  case LLVMAtomicRMWBinOpNand: intop = AtomicRMWInst::Nand; break;
3031  case LLVMAtomicRMWBinOpOr: intop = AtomicRMWInst::Or; break;
3032  case LLVMAtomicRMWBinOpXor: intop = AtomicRMWInst::Xor; break;
3033  case LLVMAtomicRMWBinOpMax: intop = AtomicRMWInst::Max; break;
3034  case LLVMAtomicRMWBinOpMin: intop = AtomicRMWInst::Min; break;
3035  case LLVMAtomicRMWBinOpUMax: intop = AtomicRMWInst::UMax; break;
3036  case LLVMAtomicRMWBinOpUMin: intop = AtomicRMWInst::UMin; break;
3037  }
3038  return wrap(unwrap(B)->CreateAtomicRMW(intop, unwrap(PTR), unwrap(Val),
3039  mapFromLLVMOrdering(ordering), singleThread ? SingleThread : CrossThread));
3040 }
3041 
3043  LLVMValueRef Cmp, LLVMValueRef New,
3044  LLVMAtomicOrdering SuccessOrdering,
3045  LLVMAtomicOrdering FailureOrdering,
3046  LLVMBool singleThread) {
3047 
3048  return wrap(unwrap(B)->CreateAtomicCmpXchg(unwrap(Ptr), unwrap(Cmp),
3049  unwrap(New), mapFromLLVMOrdering(SuccessOrdering),
3050  mapFromLLVMOrdering(FailureOrdering),
3051  singleThread ? SingleThread : CrossThread));
3052 }
3053 
3054 
3056  Value *P = unwrap<Value>(AtomicInst);
3057 
3058  if (AtomicRMWInst *I = dyn_cast<AtomicRMWInst>(P))
3059  return I->getSynchScope() == SingleThread;
3060  return cast<AtomicCmpXchgInst>(P)->getSynchScope() == SingleThread;
3061 }
3062 
3064  Value *P = unwrap<Value>(AtomicInst);
3066 
3067  if (AtomicRMWInst *I = dyn_cast<AtomicRMWInst>(P))
3068  return I->setSynchScope(Sync);
3069  return cast<AtomicCmpXchgInst>(P)->setSynchScope(Sync);
3070 }
3071 
3073  Value *P = unwrap<Value>(CmpXchgInst);
3074  return mapToLLVMOrdering(cast<AtomicCmpXchgInst>(P)->getSuccessOrdering());
3075 }
3076 
3078  LLVMAtomicOrdering Ordering) {
3079  Value *P = unwrap<Value>(CmpXchgInst);
3080  AtomicOrdering O = mapFromLLVMOrdering(Ordering);
3081 
3082  return cast<AtomicCmpXchgInst>(P)->setSuccessOrdering(O);
3083 }
3084 
3086  Value *P = unwrap<Value>(CmpXchgInst);
3087  return mapToLLVMOrdering(cast<AtomicCmpXchgInst>(P)->getFailureOrdering());
3088 }
3089 
3091  LLVMAtomicOrdering Ordering) {
3092  Value *P = unwrap<Value>(CmpXchgInst);
3093  AtomicOrdering O = mapFromLLVMOrdering(Ordering);
3094 
3095  return cast<AtomicCmpXchgInst>(P)->setFailureOrdering(O);
3096 }
3097 
3098 /*===-- Module providers --------------------------------------------------===*/
3099 
3102  return reinterpret_cast<LLVMModuleProviderRef>(M);
3103 }
3104 
3106  delete unwrap(MP);
3107 }
3108 
3109 
3110 /*===-- Memory buffers ----------------------------------------------------===*/
3111 
3113  const char *Path,
3114  LLVMMemoryBufferRef *OutMemBuf,
3115  char **OutMessage) {
3116 
3118  if (std::error_code EC = MBOrErr.getError()) {
3119  *OutMessage = strdup(EC.message().c_str());
3120  return 1;
3121  }
3122  *OutMemBuf = wrap(MBOrErr.get().release());
3123  return 0;
3124 }
3125 
3127  char **OutMessage) {
3129  if (std::error_code EC = MBOrErr.getError()) {
3130  *OutMessage = strdup(EC.message().c_str());
3131  return 1;
3132  }
3133  *OutMemBuf = wrap(MBOrErr.get().release());
3134  return 0;
3135 }
3136 
3138  const char *InputData,
3139  size_t InputDataLength,
3140  const char *BufferName,
3141  LLVMBool RequiresNullTerminator) {
3142 
3143  return wrap(MemoryBuffer::getMemBuffer(StringRef(InputData, InputDataLength),
3144  StringRef(BufferName),
3145  RequiresNullTerminator).release());
3146 }
3147 
3149  const char *InputData,
3150  size_t InputDataLength,
3151  const char *BufferName) {
3152 
3153  return wrap(
3154  MemoryBuffer::getMemBufferCopy(StringRef(InputData, InputDataLength),
3155  StringRef(BufferName)).release());
3156 }
3157 
3159  return unwrap(MemBuf)->getBufferStart();
3160 }
3161 
3163  return unwrap(MemBuf)->getBufferSize();
3164 }
3165 
3167  delete unwrap(MemBuf);
3168 }
3169 
3170 /*===-- Pass Registry -----------------------------------------------------===*/
3171 
3174 }
3175 
3176 /*===-- Pass Manager ------------------------------------------------------===*/
3177 
3179  return wrap(new legacy::PassManager());
3180 }
3181 
3183  return wrap(new legacy::FunctionPassManager(unwrap(M)));
3184 }
3185 
3188  reinterpret_cast<LLVMModuleRef>(P));
3189 }
3190 
3192  return unwrap<legacy::PassManager>(PM)->run(*unwrap(M));
3193 }
3194 
3196  return unwrap<legacy::FunctionPassManager>(FPM)->doInitialization();
3197 }
3198 
3200  return unwrap<legacy::FunctionPassManager>(FPM)->run(*unwrap<Function>(F));
3201 }
3202 
3204  return unwrap<legacy::FunctionPassManager>(FPM)->doFinalization();
3205 }
3206 
3208  delete unwrap(PM);
3209 }
3210 
3211 /*===-- Threading ------------------------------------------------------===*/
3212 
3214  return LLVMIsMultithreaded();
3215 }
3216 
3218 }
3219 
3221  return llvm_is_multithreaded();
3222 }
MachineLoop * L
LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1195
LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty, const char *AsmString, const char *Constraints, LLVMBool HasSideEffects, LLVMBool IsAlignStack)
Definition: Core.cpp:1427
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 (if unknown returns 0).
const char * LLVMGetBufferStart(LLVMMemoryBufferRef MemBuf)
Definition: Core.cpp:3158
static Constant * getFPTrunc(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:1601
void LLVMDisposeBuilder(LLVMBuilderRef Builder)
Definition: Core.cpp:2395
unsigned LLVMGetMDNodeNumOperands(LLVMValueRef V)
Obtain the number of operands from an MDNode value.
Definition: Core.cpp:874
X86 MMX.
Definition: Core.h:156
use_iterator use_end()
Definition: Value.h:318
LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy, LLVMValueRef *ConstantVals, unsigned Count)
Create a non-anonymous ConstantStruct from values.
Definition: Core.cpp:1042
use_iterator_impl< Use > use_iterator
Definition: Value.h:304
7: Labels
Definition: Type.h:63
LLVMValueRef LLVMInstructionClone(LLVMValueRef Inst)
Create a copy of 'this' instruction that is identical in all ways except the following: ...
Definition: Core.cpp:2142
LLVMRealPredicate LLVMGetFCmpPredicate(LLVMValueRef Inst)
Obtain the float predicate of an instruction.
Definition: Core.cpp:2127
std::error_code getError() const
Definition: ErrorOr.h:169
LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C, LLVMBasicBlockRef BBRef, const char *Name)
Insert a basic block in a function before another basic block.
Definition: Core.cpp:2044
Represents either an error or a value T.
Definition: ErrorOr.h:68
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:1905
LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar)
Definition: Core.cpp:1668
LLVMValueRef LLVMBuildICmp(LLVMBuilderRef B, LLVMIntPredicate Op, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:2933
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:2471
static Type * getDoubleTy(LLVMContext &C)
Definition: Type.cpp:158
void LLVMSetCmpXchgFailureOrdering(LLVMValueRef CmpXchgInst, LLVMAtomicOrdering Ordering)
Definition: Core.cpp:3090
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
static IntegerType * getInt1Ty(LLVMContext &C)
Definition: Type.cpp:166
unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy)
Obtain the address space of a pointer type.
Definition: Core.cpp:592
static Constant * getFAdd(Constant *C1, Constant *C2)
Definition: Constants.cpp:2139
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:1801
static MDNode * extractMDNode(MetadataAsValue *MAV)
Definition: Core.cpp:680
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
Definition: Function.cpp:226
*p = old <signed v ? old : v
Definition: Instructions.h:699
LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef B, LLVMTypeRef Ty, LLVMValueRef Val, const char *Name)
Definition: Core.cpp:2701
LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1231
LLVMValueRef LLVMBuildZExt(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:2831
static LLVMValueRef getMDNodeOperandImpl(LLVMContext &Context, const MDNode *N, unsigned Index)
Definition: Core.cpp:747
LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn)
Obtain the basic block that corresponds to the entry point of a function.
Definition: Core.cpp:1998
LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M)
Obtain an iterator to the last Function in a Module.
Definition: Core.cpp:1773
LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType)
Definition: Core.cpp:1337
LLVM Argument representation.
Definition: Argument.h:34
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:3042
LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1179
Externally visible function.
Definition: Core.h:161
SI Whole Quad Mode
LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty)
Whether the type has a known size.
Definition: Core.cpp:352
LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1190
void LLVMSetSection(LLVMValueRef Global, const char *Section)
Definition: Core.cpp:1546
unsigned LLVMAttributeIndex
Definition: Core.h:350
size_t i
struct LLVMOpaqueModule * LLVMModuleRef
The top-level container for all other LLVM Intermediate Representation (IR) objects.
Definition: c/Types.h:62
LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRangeCopy(const char *InputData, size_t InputDataLength, const char *BufferName)
Definition: Core.cpp:3148
LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count)
Obtain a MDNode value from the global context.
Definition: Core.cpp:860
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:1016
LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index)
Obtain an incoming value to a PHI node as an LLVMValueRef.
Definition: Core.cpp:2318
static Constant * getNSWAdd(Constant *C1, Constant *C2)
Definition: Constants.h:961
void initializePrintModulePassWrapperPass(PassRegistry &)
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:52
struct LLVMOpaqueMemoryBuffer * LLVMMemoryBufferRef
LLVM uses a polymorphic type hierarchy which C cannot represent, therefore parameters must be passed ...
Definition: c/Types.h:49
void LLVMSetSuccessor(LLVMValueRef Term, unsigned i, LLVMBasicBlockRef block)
Update the specified successor to point at the provided block.
Definition: Core.cpp:2265
float convertToFloat() const
Definition: APFloat.h:1014
LLVMValueRef LLVMBuildAdd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:2513
LLVMBuilderRef LLVMCreateBuilder(void)
Definition: Core.cpp:2357
Obsolete.
Definition: Core.h:174
LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg)
Obtain the next parameter to a function.
Definition: Core.cpp:1939
2: 32-bit floating point type
Definition: Type.h:58
iterator end()
Definition: Function.h:537
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:2523
static MDString * get(LLVMContext &Context, StringRef Str)
Definition: Metadata.cpp:414
LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer, unsigned Idx, const char *Name)
Definition: Core.cpp:2776
LLVMAttributeRef LLVMGetEnumAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx, unsigned KindID)
Definition: Core.cpp:1862
LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name)
Definition: Core.cpp:1628
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:3137
static Constant * getAnon(ArrayRef< Constant * > V, bool Packed=false)
Return an anonymous struct that has the specified elements.
Definition: Constants.h:459
LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn)
Obtain the first parameter to a function.
Definition: Core.cpp:1923
LLVMValueRef LLVMBuildSExt(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:2836
LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee, const char *Name)
Definition: Core.cpp:1745
LLVMAttributeRef LLVMCreateStringAttribute(LLVMContextRef C, const char *K, unsigned KLength, const char *V, unsigned VLength)
Create a string attribute.
Definition: Core.cpp:151
LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty)
Definition: Core.cpp:1084
LLVMBool LLVMHasUnnamedAddr(LLVMValueRef Global)
Definition: Core.cpp:1570
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:3217
LLVMOpcode
Definition: Core.h:57
LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char Str[], unsigned SLen)
Definition: Core.cpp:957
void LLVMSetValueName(LLVMValueRef Val, const char *Name)
Set the string name of a value.
Definition: Core.cpp:639
static Constant * getAddrSpaceCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:1707
LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType)
Definition: Core.cpp:1317
void clearGC()
Definition: Function.cpp:422
Type::subtype_iterator param_iterator
Definition: DerivedTypes.h:125
const char * LLVMGetGC(LLVMValueRef Fn)
Obtain the name of the garbage collector to use during code generation.
Definition: Core.cpp:1828
LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef P)
Deprecated: Use LLVMCreateFunctionPassManagerForModule instead.
Definition: Core.cpp:3186
LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name)
Definition: Core.cpp:1614
LLVMTypeRef LLVMGetAllocatedType(LLVMValueRef Alloca)
Obtain the type that is being allocated by the alloca instruction.
Definition: Core.cpp:2291
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:2424
LLVMAttributeRef LLVMCreateEnumAttribute(LLVMContextRef C, unsigned KindID, uint64_t Val)
Create an enum attribute.
Definition: Core.cpp:135
LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB)
Advance a basic block iterator.
Definition: Core.cpp:2018
LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path, LLVMMemoryBufferRef *OutMemBuf, char **OutMessage)
Definition: Core.cpp:3112
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:67
LLVMPassManagerRef LLVMCreatePassManager()
Constructs a new whole-module pass pipeline.
Definition: Core.cpp:3178
void addOperand(MDNode *M)
Definition: Metadata.cpp:1048
LLVMTypeRef LLVMFP128Type(void)
Definition: Core.cpp:468
LLVMValueRef LLVMGetClause(LLVMValueRef LandingPad, unsigned Idx)
Definition: Core.cpp:2494
static Constant * getExactSDiv(Constant *C1, Constant *C2)
Definition: Constants.h:993
void setGC(std::string Str)
Definition: Function.cpp:417
void setAttributes(AttributeSet PAL)
Definition: CallSite.h:328
LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:2841
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:655
#define LLVM_FOR_EACH_VALUE_SUBCLASS(macro)
Definition: Core.h:1162
unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy)
Obtain the number of elements in a vector type.
Definition: Core.cpp:596
void(* LLVMDiagnosticHandler)(LLVMDiagnosticInfoRef, void *)
Definition: Core.h:380
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:1126
LLVMDiagnosticSeverity LLVMGetDiagInfoSeverity(LLVMDiagnosticInfoRef DI)
Return an enum LLVMDiagnosticSeverity.
Definition: Core.cpp:192
*p = old <unsigned v ? old : v
Definition: Instructions.h:703
static Constant * getIntToPtr(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:1682
LLVMBool LLVMIsAtomicSingleThread(LLVMValueRef AtomicInst)
Definition: Core.cpp:3055
static Constant * getExtractElement(Constant *Vec, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
Definition: Constants.cpp:1997
const char * LLVMGetDataLayoutStr(LLVMModuleRef M)
Obtain the data layout for a module.
Definition: Core.cpp:240
LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef B, LLVMValueRef If, LLVMBasicBlockRef Then, LLVMBasicBlockRef Else)
Definition: Core.cpp:2437
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:701
Externally visible function.
Definition: GlobalValue.h:49
LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef B, LLVMValueRef V, const char *Name)
Definition: Core.cpp:2664
LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:2903
struct LLVMOpaquePassRegistry * LLVMPassRegistryRef
Definition: c/Types.h:103
unsigned LLVMGetNumArgOperands(LLVMValueRef Instr)
Obtain the argument count for a call instruction.
Definition: Core.cpp:2150
struct LLVMOpaqueBuilder * LLVMBuilderRef
Represents an LLVM basic block builder.
Definition: c/Types.h:90
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:100
LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:2583
arg_iterator arg_end()
Definition: Function.h:559
unsigned LLVMGetLastEnumAttributeKind(void)
Definition: Core.cpp:131
13: Structures
Definition: Type.h:72
LLVMTypeRef LLVMX86FP80Type(void)
Definition: Core.cpp:465
LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val)
Obtain the first use of a value.
Definition: Core.cpp:722
A debug info location.
Definition: DebugLoc.h:34
Metadata node.
Definition: Metadata.h:830
void LLVMClearInsertionPosition(LLVMBuilderRef Builder)
Definition: Core.cpp:2382
LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar)
Definition: Core.cpp:1648
4: 80-bit floating point type (X87)
Definition: Type.h:60
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:577
LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1221
unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char *Name, unsigned SLen)
Definition: Core.cpp:115
LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void)
Return the global pass registry, for use with initialization functions.
Definition: Core.cpp:3172
LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:2909
LLVMValueRef LLVMBuildFRem(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:2608
An instruction for reading from memory.
Definition: Instructions.h:164
LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition, LLVMValueRef ConstantIfTrue, LLVMValueRef ConstantIfFalse)
Definition: Core.cpp:1383
1: 16-bit floating point type
Definition: Type.h:57
LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType)
Definition: Core.cpp:1282
unsigned getBitWidth() const
Get the number of bits in this IntegerType.
Definition: DerivedTypes.h:65
LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val)
Determine whether an LLVMValueRef is itself a basic block.
Definition: Core.cpp:1968
static IntegerType * getInt64Ty(LLVMContext &C)
Definition: Type.cpp:170
FunctionType * getType(LLVMContext &Context, ID id, ArrayRef< Type * > Tys=None)
Return the function type for an intrinsic.
Definition: Function.cpp:905
LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes, unsigned ElementCount, LLVMBool Packed)
Create a new structure type in a context.
Definition: Core.cpp:508
AttrBuilder & addAttribute(Attribute::AttrKind Val)
Add an attribute to the builder.
an instruction that atomically reads a memory location, combines it with another value, and then stores the result back.
Definition: Instructions.h:669
Hexagon Common GEP
LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef BBRef, const char *Name)
Insert a basic block in a function using the global context.
Definition: Core.cpp:2051
int LLVMHasMetadata(LLVMValueRef Inst)
Determine whether an instruction has any metadata attached.
Definition: Core.cpp:665
static Constant * getSub(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
Definition: Constants.cpp:2143
const char * LLVMGetSection(LLVMValueRef Global)
Definition: Core.cpp:1540
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:387
LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals, unsigned Count)
Obtain a MDNode value from a context.
Definition: Core.cpp:833
#define op(i)
LLVMValueRef LLVMBuildFence(LLVMBuilderRef B, LLVMAtomicOrdering Ordering, LLVMBool isSingleThread, const char *Name)
Definition: Core.cpp:2753
15: Pointers
Definition: Type.h:74
void initializeCore(PassRegistry &)
Initialize all passes linked into the TransformUtils library.
Definition: Core.cpp:49
static IntegerType * getInt16Ty(LLVMContext &C)
Definition: Type.cpp:168
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
LLVMAttributeRef LLVMGetStringAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx, const char *K, unsigned KLen)
Definition: Core.cpp:1869
static Type * getX86_MMXTy(LLVMContext &C)
Definition: Type.cpp:164
LLVMAtomicRMWBinOp
Definition: Core.h:309
12: Functions
Definition: Type.h:71
LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char Str[], uint8_t Radix)
Definition: Core.cpp:937
*p = old >signed v ? old : v
Definition: Instructions.h:697
LLVMValueRef LLVMConstAddrSpaceCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType)
Definition: Core.cpp:1342
Lowest level of atomicity, guarantees somewhat sane results, lock free.
Definition: Core.h:284
Tentative definitions.
Definition: GlobalValue.h:59
static Type * getX86_FP80Ty(LLVMContext &C)
Definition: Type.cpp:161
void LLVMContextDispose(LLVMContextRef C)
Destroy a context instance.
Definition: Core.cpp:111
128 bit floating point type (112-bit mantissa)
Definition: Core.h:146
void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant)
Definition: Core.cpp:1692
void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal)
Definition: Core.cpp:1684
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:234
static Constant * getInsertElement(Constant *Vec, Constant *Elt, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
Definition: Constants.cpp:2019
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:790
LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N)
Obtain a constant value referring to a double floating point value.
Definition: Core.cpp:949
LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:2915
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
Definition: Constants.cpp:195
LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM)
Initializes all of the function passes scheduled in the function pass manager.
Definition: Core.cpp:3195
void LLVMRemoveCallSiteStringAttribute(LLVMValueRef C, LLVMAttributeIndex Idx, const char *K, unsigned KLen)
Definition: Core.cpp:2218
void LLVMSetOperand(LLVMValueRef Val, unsigned Index, LLVMValueRef Op)
Set an operand at a specific index in a llvm::User value.
Definition: Core.cpp:776
iterator begin()
Instruction iterator methods.
Definition: BasicBlock.h:228
long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal)
Obtain the sign extended value for an integer constant value.
Definition: Core.cpp:966
static Constant * getAdd(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
Definition: Constants.cpp:2132
static Constant * getFMul(Constant *C1, Constant *C2)
Definition: Constants.cpp:2161
void addAttr(AttributeSet AS)
Add a Attribute to an argument.
Definition: Function.cpp:188
element_iterator element_end() const
Definition: DerivedTypes.h:280
void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index, unsigned align)
Definition: Core.cpp:2163
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:2136
LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C)
Obtain a 128-bit floating point type (112-bit mantissa) from a context.
Definition: Core.cpp:443
const char * LLVMGetStructName(LLVMTypeRef Ty)
Obtain the name of a structure.
Definition: Core.cpp:525
StringRef getKindAsString() const
Return the attribute's kind as a string.
Definition: Attributes.cpp:171
LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn)
Obtain the last basic block in a function.
Definition: Core.cpp:2010
static LLVMAtomicOrdering mapToLLVMOrdering(AtomicOrdering Ordering)
Definition: Core.cpp:2737
Same, but only replaced by something equivalent.
Definition: Core.h:168
LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB)
Convert a basic block instance to a value type.
Definition: Core.cpp:1964
A tuple of MDNodes.
Definition: Metadata.h:1282
static Constant * getIntegerCast(Constant *C, Type *Ty, bool isSigned)
Create a ZExt, Bitcast or Trunc for integer -> integer casts.
Definition: Constants.cpp:1535
LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C)
Create a label type in a context.
Definition: Core.cpp:605
LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C)
Obtain a 64-bit floating point type from a context.
Definition: Core.cpp:437
static Type * getTokenTy(LLVMContext &C)
Definition: Type.cpp:160
static ManagedStatic< LLVMContext > GlobalContext
Definition: Core.cpp:78
LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size)
Create a ConstantVector from values.
Definition: Core.cpp:1051
bool hasGC() const
hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm to use during code generatio...
Definition: Function.h:250
bool has_error() const
Return the value of the flag in this raw_fd_ostream indicating whether an output error has been encou...
Definition: raw_ostream.h:428
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:2588
void(* LLVMYieldCallback)(LLVMContextRef, void *)
Definition: Core.h:381
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
Type::subtype_iterator element_iterator
Definition: DerivedTypes.h:278
LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty)
Definition: Core.cpp:1088
LLVMBool LLVMIsNull(LLVMValueRef Val)
Determine whether a value instance is null.
Definition: Core.cpp:806
Attribute unwrap(LLVMAttributeRef Attr)
Definition: Attributes.h:191
static Type * getFloatTy(LLVMContext &C)
Definition: Type.cpp:157
LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant, LLVMValueRef VectorBConstant, LLVMValueRef MaskConstant)
Definition: Core.cpp:1405
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:440
LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef Switch)
Obtain the default destination basic block of a switch instruction.
Definition: Core.cpp:2285
LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text)
Obtain a constant for a floating point value parsed from a string.
Definition: Core.cpp:953
LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef B, LLVMValueRef *RetVals, unsigned N)
Definition: Core.cpp:2428
Class to represent struct types.
Definition: DerivedTypes.h:199
Sets the value if it'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:2210
param_iterator param_end() const
Definition: DerivedTypes.h:127
static Constant * getNUWNeg(Constant *C)
Definition: Constants.h:959
LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char Str[], unsigned SLen, uint8_t Radix)
Definition: Core.cpp:943
Add a value and return the old one.
Definition: Core.h:311
void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block, LLVMValueRef Instr)
Definition: Core.cpp:2361
LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C)
Definition: Core.cpp:384
unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn)
Obtain the calling function of a function.
Definition: Core.cpp:1819
LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType, LLVMBool isSigned)
Definition: Core.cpp:1372
LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1124
static Constant * get(ArrayRef< Constant * > V)
Definition: Constants.cpp:994
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:588
void setThreadLocalMode(ThreadLocalMode Val)
Definition: GlobalValue.h:236
void LLVMSetDataLayout(LLVMModuleRef M, const char *DataLayoutStr)
Set the data layout for a module.
Definition: Core.cpp:248
LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1152
unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy)
Definition: Core.cpp:425
This file contains the simple types necessary to represent the attributes associated with functions a...
LLVMBool LLVMIsExternallyInitialized(LLVMValueRef GlobalVar)
Definition: Core.cpp:1735
Pointers.
Definition: Core.h:153
static Constant * getSExt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:1573
LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1260
LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB)
Obtain the function to which a basic block belongs.
Definition: Core.cpp:1980
void LLVMSetCondition(LLVMValueRef Branch, LLVMValueRef Cond)
Set the condition of a branch instruction.
Definition: Core.cpp:2279
SynchronizationScope
Definition: Instructions.h:50
LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn)
Obtain the last parameter to a function.
Definition: Core.cpp:1931
LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate, LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1236
element_iterator element_begin() const
Definition: DerivedTypes.h:279
LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty)
Obtain a constant value referring to an undefined value of a type.
Definition: Core.cpp:798
Rename collisions when linking (static functions)
Definition: Core.h:171
void addAttributes(unsigned i, AttributeSet Attrs)
adds the attributes to the list of attributes.
Definition: Function.cpp:376
uint64_t LLVMGetEnumAttributeValue(LLVMAttributeRef A)
Get the enum attribute's value.
Definition: Core.cpp:144
LLVMBool LLVMIsCleanup(LLVMValueRef LandingPad)
Definition: Core.cpp:2503
Arrays.
Definition: Core.h:152
void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz)
Definition: Core.cpp:1555
static Type * getPPC_FP128Ty(LLVMContext &C)
Definition: Type.cpp:163
void LLVMSetNormalDest(LLVMValueRef Invoke, LLVMBasicBlockRef B)
Set the normal destination basic block.
Definition: Core.cpp:2247
LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType)
Definition: Core.cpp:1287
void LLVMContextSetDiagnosticHandler(LLVMContextRef C, LLVMDiagnosticHandler Handler, void *DiagnosticContext)
Set the diagnostic handler for this context.
Definition: Core.cpp:86
LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar)
Definition: Core.cpp:1656
LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:2518
LLVMBool LLVMIsStringAttribute(LLVMAttributeRef A)
Definition: Core.cpp:177
Expected< const typename ELFT::Shdr * > getSection(typename ELFT::ShdrRange Sections, uint32_t Index)
Definition: Object/ELF.h:171
SIMD 'packed' format, or other vector type.
Definition: Core.h:154
LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB)
Obtain the first instruction in a basic block.
Definition: Core.cpp:2078
LLVMTypeRef LLVMFloatType(void)
Definition: Core.cpp:459
AtomicOrdering
Atomic ordering for LLVM's memory model.
global_iterator global_begin()
Definition: Module.h:518
void LLVMDisposeMessage(char *Message)
Definition: Core.cpp:71
A load or store which is not atomic.
Definition: Core.h:283
LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType)
Definition: Core.cpp:1378
LLVMValueRef LLVMBuildSRem(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:2603
struct LLVMOpaqueType * LLVMTypeRef
Each value in the LLVM IR has a type, an LLVMTypeRef.
Definition: c/Types.h:69
LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst)
Obtain the instruction that occurred before this one.
Definition: Core.cpp:2102
void LLVMContextSetYieldCallback(LLVMContextRef C, LLVMYieldCallback Callback, void *OpaqueHandle)
Set the yield callback function for this context.
Definition: Core.cpp:104
static Constant * getZExt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:1587
void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos)
Move a basic block to before another one.
Definition: Core.cpp:2064
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:1808
LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant, LLVMValueRef ElementValueConstant, LLVMValueRef IndexConstant)
Definition: Core.cpp:1397
void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest)
Obtain the types of a function's parameters.
Definition: Core.cpp:499
A constant value that is initialized with an expression using other constant values.
Definition: Constants.h:873
Class to represent function types.
Definition: DerivedTypes.h:102
char * LLVMPrintModuleToString(LLVMModuleRef M)
Return a string representation of the module.
Definition: Core.cpp:286
static Type * getLabelTy(LLVMContext &C)
Definition: Type.cpp:155
#define F(x, y, z)
Definition: MD5.cpp:51
CallingConv::ID getCallingConv() const
getCallingConv/setCallingConv - get or set the calling convention of the call.
Definition: CallSite.h:308
void LLVMDisposeModule(LLVMModuleRef M)
Destroy a module instance.
Definition: Core.cpp:224
void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst)
Definition: Core.cpp:2413
opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
Definition: APFloat.cpp:4139
LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar)
Definition: Core.cpp:1688
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition: Type.h:128
LLVMValueRef LLVMConstStructInContext(LLVMContextRef C, LLVMValueRef *ConstantVals, unsigned Count, LLVMBool Packed)
Create an anonymous ConstantStruct with the specified values.
Definition: Core.cpp:1028
static Constant * getFPCast(Constant *C, Type *Ty)
Create a FPExt, Bitcast or FPTrunc for fp -> fp casts.
Definition: Constants.cpp:1547
LLVMBool LLVMIsTailCall(LLVMValueRef Call)
Obtain whether a call instruction is a tail call.
Definition: Core.cpp:2229
LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB)
Definition: Core.cpp:1435
void llvm_shutdown()
llvm_shutdown - Deallocate and destroy all ManagedStatic variables.
LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType)
Definition: Core.cpp:1348
BinOp
This enumeration lists the possible modifications atomicrmw can make.
Definition: Instructions.h:681
LLVMValueKind
Definition: Core.h:205
LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal, LLVMValueRef *ConstantIndices, unsigned NumIndices)
Definition: Core.cpp:1265
struct LLVMOpaqueUse * LLVMUseRef
Used to get the users and usees of a Value.
Definition: c/Types.h:109
LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal, LLVMValueRef *ConstantIndices, unsigned NumIndices)
Definition: Core.cpp:1273
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:2215
LLVMValueRef LLVMBuildOr(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:2633
void LLVMDeleteFunction(LLVMValueRef Fn)
Remove a function from its containing module and deletes it.
Definition: Core.cpp:1797
void LLVMRemoveCallSiteEnumAttribute(LLVMValueRef C, LLVMAttributeIndex Idx, unsigned KindID)
Definition: Core.cpp:2212
struct LLVMOpaqueContext * LLVMContextRef
The top-level container for all LLVM global data.
Definition: c/Types.h:54
LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:2593
LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType)
Definition: Core.cpp:1322
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:2026
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:1872
LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M)
Definition: Core.cpp:1632
void LLVMDumpModule(LLVMModuleRef M)
Dump a representation of a module to stderr.
Definition: Core.cpp:261
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
Definition: Type.cpp:291
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:2314
LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:2920
LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C)
Obtain a 32-bit floating point type from a context.
Definition: Core.cpp:434
unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal)
Obtain the zero extended value for an integer constant value.
Definition: Core.cpp:962
static int map_from_llvmopcode(LLVMOpcode code)
Definition: Core.cpp:1068
static GCRegistry::Add< OcamlGC > B("ocaml","ocaml 3.10-compatible GC")
An instruction for storing to memory.
Definition: Instructions.h:300
void LLVMGetMDNodeOperands(LLVMValueRef V, LLVMValueRef *Dest)
Obtain the given MDNode's operands.
Definition: Core.cpp:881
LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1174
LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB)
Obtain the last instruction in a basic block.
Definition: Core.cpp:2086
LLVMValueRef LLVMBuildSub(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:2533
#define LLVM_EXTENSION
LLVM_EXTENSION - Support compilers where we have a keyword to suppress pedantic diagnostics.
Definition: Compiler.h:251
LLVMUseRef LLVMGetNextUse(LLVMUseRef U)
Obtain the next use of a value.
Definition: Core.cpp:730
LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name, LLVMTypeRef FunctionTy)
Add a function to a module under a specified name.
Definition: Core.cpp:1755
LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:2528
static Constant * getUDiv(Constant *C1, Constant *C2, bool isExact=false)
Definition: Constants.cpp:2165
static Constant * getNSWNeg(Constant *C)
Definition: Constants.h:958
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
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
Definition: StringRef.h:135
LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:2543
struct LLVMOpaqueAttributeRef * LLVMAttributeRef
Used to represent an attributes.
Definition: c/Types.h:116
iterator begin()
Definition: Function.h:535
static ConstantAsMetadata * get(Constant *C)
Definition: Metadata.h:392
int Switch(int a)
Definition: Switch2Test.cpp:11
LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:2871
LLVMDiagnosticSeverity
Definition: Core.h:331
static Constant * getFDiv(Constant *C1, Constant *C2)
Definition: Constants.cpp:2175
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:923
static BinaryOperator * CreateAdd(Value *S1, Value *S2, const Twine &Name, Instruction *InsertBefore, Value *FlagsOp)
size_t LLVMGetBufferSize(LLVMMemoryBufferRef MemBuf)
Definition: Core.cpp:3162
LLVMValueRef LLVMBuildAnd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:2628
void LLVMSetCmpXchgSuccessOrdering(LLVMValueRef CmpXchgInst, LLVMAtomicOrdering Ordering)
Definition: Core.cpp:3077
void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage)
Definition: Core.cpp:1478
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
void initializePrintBasicBlockPassPass(PassRegistry &)
unsigned LLVMGetIntrinsicID(LLVMValueRef Fn)
Obtain the ID number from a function instance.
Definition: Core.cpp:1813
void LLVMAddTargetDependentFunctionAttr(LLVMValueRef Fn, const char *A, const char *V)
Add a target-dependent attribute to a function.
Definition: Core.cpp:1885
LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst)
Obtain the basic block to which an instruction belongs.
Definition: Core.cpp:2074
LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C)
Definition: Core.cpp:393
LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M)
Definition: Core.cpp:1640
const char * LLVMGetBasicBlockName(LLVMBasicBlockRef BB)
Obtain the string name of a basic block.
Definition: Core.cpp:1976
LLVMAttributeRef LLVMGetCallSiteStringAttribute(LLVMValueRef C, LLVMAttributeIndex Idx, const char *K, unsigned KLen)
Definition: Core.cpp:2205
LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1113
unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy)
Obtain the length of an array type.
Definition: Core.cpp:588
void LLVMDisposePassManager(LLVMPassManagerRef PM)
Frees the memory of a pass pipeline.
Definition: Core.cpp:3207
LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef B, LLVMValueRef Val, const char *Name)
Definition: Core.cpp:3005
void LLVMSetVolatile(LLVMValueRef MemAccessInst, LLVMBool isVolatile)
Definition: Core.cpp:2798
LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C)
Create a void type in a context.
Definition: Core.cpp:602
11: Arbitrary bit width integers
Definition: Type.h:70
static MetadataAsValue * get(LLVMContext &Context, Metadata *MD)
Definition: Metadata.cpp:74
PassManager manages ModulePassManagers.
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:1695
#define LLVM_DEFINE_VALUE_CAST(name)
Definition: Core.cpp:699
ExternalWeak linkage description.
Definition: GlobalValue.h:58
void LLVMSetUnnamedAddr(LLVMValueRef Global, LLVMBool HasUnnamedAddr)
Definition: Core.cpp:1574
LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1118
LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal)
Definition: Core.cpp:1096
void LLVMSetTarget(LLVMModuleRef M, const char *Triple)
Set the target triple for a module.
Definition: Core.cpp:257
static Constant * getInsertValue(Constant *Agg, Constant *Val, ArrayRef< unsigned > Idxs, Type *OnlyIfReducedTy=nullptr)
Definition: Constants.cpp:2065
0: type with no size
Definition: Type.h:56
#define P(N)
Same, but only replaced by something equivalent.
Definition: GlobalValue.h:52
static Constant * getFNeg(Constant *C)
Definition: Constants.cpp:2120
LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn)
Obtain the first basic block in a function.
Definition: Core.cpp:2002
LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V, const char *Name)
Definition: Core.cpp:2659
void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L)
Definition: Core.cpp:2401
const unsigned * LLVMGetIndices(LLVMValueRef Inst)
Obtain the indices as an array.
Definition: Core.cpp:2340
static Constant * getFRem(Constant *C1, Constant *C2)
Definition: Constants.cpp:2187
void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block)
Definition: Core.cpp:2373
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:2613
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:171
Acquire provides a barrier of the sort necessary to acquire a lock to access other memory with normal...
Definition: Core.h:289
static Constant * getInBoundsGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant * > IdxList)
Create an "inbounds" getelementptr.
Definition: Constants.h:1153
LLVMTypeKind
Definition: Core.h:140
LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef B, LLVMValueRef VecVal, LLVMValueRef EltVal, LLVMValueRef Index, const char *Name)
Definition: Core.cpp:2979
static ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
Definition: Constants.cpp:1323
LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef B, LLVMTypeRef Ty, const char *Name)
Definition: Core.cpp:2696
LLVMAtomicOrdering
Definition: Core.h:282
LLVMTypeRef LLVMInt32Type(void)
Definition: Core.cpp:412
void LLVMGetAttributesAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx, LLVMAttributeRef *Attrs)
Definition: Core.cpp:1853
LLVMValueRef LLVMBuildPhi(LLVMBuilderRef B, LLVMTypeRef Ty, const char *Name)
Definition: Core.cpp:2949
LLVM Basic Block Representation.
Definition: BasicBlock.h:51
LLVMValueRef LLVMIsAMDString(LLVMValueRef Val)
Definition: Core.cpp:714
Sets the value if it'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:669
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal)
Definition: Core.cpp:2498
unsigned LLVMCountBasicBlocks(LLVMValueRef FnRef)
Obtain the number of basic blocks in a function.
Definition: Core.cpp:1988
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:48
const Function * getParent() const
Definition: Argument.h:48
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:661
LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:2846
LLVMBool LLVMStartMultithreaded()
Deprecated: Multi-threading can only be enabled/disabled with the compile time define LLVM_ENABLE_THR...
Definition: Core.cpp:3213
LLVMDiagnosticHandler LLVMContextGetDiagnosticHandler(LLVMContextRef C)
Get the diagnostic handler of this context.
Definition: Core.cpp:95
LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M)
Obtain the context to which this module is associated.
Definition: Core.cpp:303
LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1201
static BlockAddress * get(Function *F, BasicBlock *BB)
Return a BlockAddress for the specified function and basic block.
Definition: Constants.cpp:1356
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:2538
LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name)
Obtain a Function value from a Module by its name.
Definition: Core.cpp:1761
LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal)
Definition: Core.cpp:1105
This file contains the declarations for the subclasses of Constant, which represent the different fla...
unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy)
Get the number of elements defined inside the structure.
Definition: Core.cpp:539
param_iterator param_begin() const
Definition: DerivedTypes.h:126
10: Tokens
Definition: Type.h:66
LLVMThreadLocalMode LLVMGetThreadLocalMode(LLVMValueRef GlobalVar)
Definition: Core.cpp:1696
LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:2856
char * LLVMPrintValueToString(LLVMValueRef Val)
Return a string representation of the value.
Definition: Core.cpp:647
LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef B, LLVMValueRef VecVal, LLVMValueRef Index, const char *Name)
Definition: Core.cpp:2973
LLVMValueRef LLVMBuildFMul(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:2568
static Constant * getAnd(Constant *C1, Constant *C2)
Definition: Constants.cpp:2191
void LLVMSetDLLStorageClass(LLVMValueRef Global, LLVMDLLStorageClass Class)
Definition: Core.cpp:1565
static Constant * get(ArrayType *T, ArrayRef< Constant * > V)
Definition: Constants.cpp:888
ConstantFP - Floating Point Values [float, double].
Definition: Constants.h:269
LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C)
Obtain a 128-bit floating point type (two 64-bits) from a context.
Definition: Core.cpp:446
80 bit floating point type (X87)
Definition: Core.h:145
LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:3015
LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer, LLVMValueRef *Indices, unsigned NumIndices, const char *Name)
Definition: Core.cpp:2768
static Constant * getSExtOrBitCast(Constant *C, Type *Ty)
Definition: Constants.cpp:1497
LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1168
bool llvm_is_multithreaded()
Returns true if LLVM is compiled with support for multi-threading, and false otherwise.
Definition: Threading.cpp:25
LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList, unsigned NumIdx)
Definition: Core.cpp:1413
LLVMValueRef LLVMBuildExactUDiv(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:2578
void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest)
Definition: Core.cpp:2486
LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1226
void LLVMInstructionEraseFromParent(LLVMValueRef Inst)
Remove and delete an instruction.
Definition: Core.cpp:2114
static Constant * getShuffleVector(Constant *V1, Constant *V2, Constant *Mask, Type *OnlyIfReducedTy=nullptr)
Definition: Constants.cpp:2042
LLVMUseRef LLVMGetOperandUse(LLVMValueRef Val, unsigned Index)
Obtain the use of an operand at a specific index in a llvm::User value.
Definition: Core.cpp:771
void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos)
Move a basic block to after another one.
Definition: Core.cpp:2068
LLVMValueRef LLVMGetUsedValue(LLVMUseRef U)
Obtain the value this use corresponds to.
Definition: Core.cpp:741
static Type * getVoidTy(LLVMContext &C)
Definition: Type.cpp:154
LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount)
Create a fixed size array type that refers to a specific type.
Definition: Core.cpp:569
LLVMValueRef LLVMGetElementAsConstant(LLVMValueRef C, unsigned idx)
Get an element at specified index as a constant.
Definition: Core.cpp:1008
LLVMBool LLVMIsUndef(LLVMValueRef Val)
Determine whether a value instance is undefined.
Definition: Core.cpp:812
char * LLVMGetDiagInfoDescription(LLVMDiagnosticInfoRef DI)
Return a string representation of the DiagnosticInfo.
Definition: Core.cpp:181
void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align)
Set the alignment for a function parameter.
Definition: Core.cpp:1955
LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str, unsigned SLen)
Obtain a MDString value from a context.
Definition: Core.cpp:822
LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn)
Definition: Core.cpp:2473
LLVMValueRef LLVMConstString(const char *Str, unsigned Length, LLVMBool DontNullTerminate)
Create a ConstantDataSequential with string content in the global context.
Definition: Core.cpp:1002
This instruction compares its operands according to the predicate given to the constructor.
LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits)
Definition: Core.cpp:399
MDNode * getOperand(unsigned i) const
Definition: Metadata.cpp:1042
Functions.
Definition: Core.h:150
void setCallingConv(CallingConv::ID CC)
Definition: CallSite.h:311
LLVMBasicBlockRef LLVMGetSuccessor(LLVMValueRef Term, unsigned i)
Return the specified successor.
Definition: Core.cpp:2261
LLVMValueRef LLVMMDString(const char *Str, unsigned SLen)
Obtain a MDString value from the global context.
Definition: Core.cpp:829
6: 128-bit floating point type (two 64-bits, PowerPC)
Definition: Type.h:62
LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1211
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
Definition: BasicBlock.h:93
arg_iterator arg_begin()
Definition: Function.h:550
LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef B)
Definition: Core.cpp:2477
static Constant * getICmp(unsigned short pred, Constant *LHS, Constant *RHS, bool OnlyIfReduced=false)
get* - Return some common constants without having to specify the full Instruction::OPCODE identifier...
Definition: Constants.cpp:1948
LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef B, LLVMValueRef Fn, LLVMValueRef *Args, unsigned NumArgs, LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch, const char *Name)
Definition: Core.cpp:2452
self_iterator getIterator()
Definition: ilist_node.h:81
void LLVMShutdown()
Deallocate and destroy all ManagedStatic variables.
Definition: Core.cpp:61
LLVMTypeRef LLVMPPCFP128Type(void)
Definition: Core.cpp:471
Class to represent integer types.
Definition: DerivedTypes.h:39
LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType)
Definition: Core.cpp:1332
LLVMTypeRef LLVMTokenTypeInContext(LLVMContextRef C)
Definition: Core.cpp:452
And a value and return the old one.
Definition: Core.h:313
LLVMBool LLVMIsEnumAttribute(LLVMAttributeRef A)
Check for the different types of attributes.
Definition: Core.cpp:172
LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType)
Definition: Core.cpp:1366
LLVMValueRef LLVMBuildNot(LLVMBuilderRef B, LLVMValueRef V, const char *Name)
Definition: Core.cpp:2668
LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder)
Definition: Core.cpp:2378
const char * LLVMGetTarget(LLVMModuleRef M)
Obtain the target triple for a module.
Definition: Core.cpp:253
static Constant * get(StructType *T, ArrayRef< Constant * > V)
Definition: Constants.cpp:949
LLVMTypeRef LLVMInt16Type(void)
Definition: Core.cpp:409
Sets the value if it's greater than the original using a signed comparison and return the old one...
Definition: Core.h:317
Metadata wrapper in the Value hierarchy.
Definition: Metadata.h:161
static Constant * getNot(Constant *C)
Definition: Constants.cpp:2126
unsigned LLVMGetEnumAttributeKind(LLVMAttributeRef A)
Get the unique id corresponding to the enum attribute passed as argument.
Definition: Core.cpp:140
void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr)
Definition: Core.cpp:2368
void LLVMSetPersonalityFn(LLVMValueRef Fn, LLVMValueRef PersonalityFn)
Set the personality function attached to the function.
Definition: Core.cpp:1809
static Constant * getAllOnesValue(Type *Ty)
Get the all ones value.
Definition: Constants.cpp:249
LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name)
Obtain a Type from a module by its registered name.
Definition: Core.cpp:563
LLVMValueRef LLVMGetPersonalityFn(LLVMValueRef Fn)
Obtain the personality function attached to the function.
Definition: Core.cpp:1805
unsigned LLVMGetNumClauses(LLVMValueRef LandingPad)
Definition: Core.cpp:2490
LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal)
Definition: Core.cpp:1080
static LocalAsMetadata * get(Value *Local)
Definition: Metadata.h:418
unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr)
Obtain the calling convention for a call instruction.
Definition: Core.cpp:2154
void LLVMDumpValue(LLVMValueRef Val)
Dump a representation of a value to stderr.
Definition: Core.cpp:643
LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1135
struct LLVMOpaqueModuleProvider * LLVMModuleProviderRef
Interface used to provide a module to JIT or interpreter.
Definition: c/Types.h:97
void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char *Name, LLVMValueRef *Dest)
Obtain the named metadata operands for a module.
Definition: Core.cpp:901
FunctionPassManager manages FunctionPasses and BasicBlockPassManagers.
LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType)
Definition: Core.cpp:1307
int LLVMBool
Definition: c/Types.h:29
int LLVMGetNumOperands(LLVMValueRef Val)
Obtain the number of operands in a llvm::User value.
Definition: Core.cpp:780
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
Definition: Constants.cpp:1337
void * LLVMContextGetDiagnosticContext(LLVMContextRef C)
Get the diagnostic context of this context.
Definition: Core.cpp:100
unsigned LLVMGetCallSiteAttributeCount(LLVMValueRef C, LLVMAttributeIndex Idx)
Definition: Core.cpp:2179
LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer, LLVMValueRef *Indices, unsigned NumIndices, const char *Name)
Definition: Core.cpp:2761
LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name, unsigned AddressSpace)
Definition: Core.cpp:1619
struct LLVMOpaqueDiagnosticInfo * LLVMDiagnosticInfoRef
Definition: c/Types.h:121
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:654
type with no size
Definition: Core.h:141
LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:2826
const char * LLVMGetDataLayout(LLVMModuleRef M)
Definition: Core.cpp:244
C setMetadata(LLVMContext::MD_range, MDNode::get(Context, LowAndHigh))
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Like Private, but linker removes.
Definition: Core.h:179
LLVMValueRef LLVMGetParam(LLVMValueRef FnRef, unsigned index)
Obtain the parameter at the specified index.
Definition: Core.cpp:1912
LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str, unsigned Length, LLVMBool DontNullTerminate)
Create a ConstantDataSequential and initialize it with a string.
Definition: Core.cpp:993
LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1206
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
LLVMTypeRef LLVMVoidType(void)
These are similar to the above functions except they operate on the global context.
Definition: Core.cpp:609
LLVMValueRef LLVMBuildCall(LLVMBuilderRef B, LLVMValueRef Fn, LLVMValueRef *Args, unsigned NumArgs, const char *Name)
Definition: Core.cpp:2953
static Type * getFP128Ty(LLVMContext &C)
Definition: Type.cpp:162
LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C, LLVMValueRef FnRef, const char *Name)
Append a basic block to the end of a function.
Definition: Core.cpp:2034
LLVMTypeRef LLVMGetElementType(LLVMTypeRef WrappedTy)
Obtain the type of elements within a sequential type.
Definition: Core.cpp:581
LLVMValueRef LLVMBuildNeg(LLVMBuilderRef B, LLVMValueRef V, const char *Name)
Definition: Core.cpp:2650
void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf)
Definition: Core.cpp:3166
LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:2851
void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC)
Set the calling convention of a function.
Definition: Core.cpp:1823
Like Internal, but omit from symbol table.
Definition: Core.h:173
void LLVMGetBasicBlocks(LLVMValueRef FnRef, LLVMBasicBlockRef *BasicBlocksRefs)
Obtain all of the basic blocks in a function.
Definition: Core.cpp:1992
Sets the value if it's Smaller than the original using a signed comparison and return the old one...
Definition: Core.h:320
static AtomicOrdering mapFromLLVMOrdering(LLVMAtomicOrdering Ordering)
Definition: Core.cpp:2721
global_iterator global_end()
Definition: Module.h:520
AttributeSet getAttributes() const
getAttributes/setAttributes - get or set the parameter attributes of the call.
Definition: CallSite.h:325
14: Arrays
Definition: Type.h:73
static Constant * getFCmp(unsigned short pred, Constant *LHS, Constant *RHS, bool OnlyIfReduced=false)
Definition: Constants.cpp:1973
LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty)
Obtain the context to which this type instance is associated.
Definition: Core.cpp:357
static Constant * getPointerCast(Constant *C, Type *Ty)
Create a BitCast, AddrSpaceCast, or a PtrToInt cast constant expression.
Definition: Constants.cpp:1509
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
static Constant * getSIToFP(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:1636
LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index)
Obtain an operand at a specific index in a llvm::User value.
Definition: Core.cpp:757
LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType)
Definition: Core.cpp:1360
static Type * getHalfTy(LLVMContext &C)
Definition: Type.cpp:156
unsigned LLVMCountParams(LLVMValueRef FnRef)
Obtain the number of parameters in a function.
Definition: Core.cpp:1899
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Definition: Type.cpp:234
const MDOperand & getOperand(unsigned I) const
Definition: Metadata.h:1034
LLVMModuleProviderRef LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M)
Changes the type of M so it can be passed to FunctionPassManagers and the JIT.
Definition: Core.cpp:3101
void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr)
Definition: Core.cpp:2386
LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:2926
LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef B)
Definition: Core.cpp:2420
uint64_t * Vals
Iterator for intrusive lists based on ilist_node.
LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str, const char *Name)
Definition: Core.cpp:2781
LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty)
Obtain a constant that is a constant pointer pointing to NULL for a specified type.
Definition: Core.cpp:816
void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal)
Definition: Core.cpp:1675
LLVMThreadLocalMode
Definition: Core.h:274
LLVMVisibility LLVMGetVisibility(LLVMValueRef Global)
Definition: Core.cpp:1550
LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1146
Metadata * getMetadata() const
Definition: Metadata.h:176
void LLVMInitializeCore(LLVMPassRegistryRef R)
Definition: Core.cpp:57
LLVMContextRef LLVMContextCreate()
Create a new context.
Definition: Core.cpp:80
Labels.
Definition: Core.h:148
LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty)
Obtain the enumerated type of a Type instance.
Definition: Core.cpp:312
LLVMTypeRef LLVMTypeOf(LLVMValueRef Val)
Obtain the type of a value.
Definition: Core.cpp:620
LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty)
Obtain a constant value referring to the instance of a type consisting of all ones.
Definition: Core.cpp:794
16: SIMD 'packed' format, or other vector type
Definition: Type.h:75
LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType)
Definition: Core.cpp:1297
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:330
static Constant * getSDiv(Constant *C1, Constant *C2, bool isExact=false)
Definition: Constants.cpp:2170
iterator end()
Definition: BasicBlock.h:230
LLVMValueRef LLVMGetCalledValue(LLVMValueRef Instr)
Obtain the pointer to the function invoked by this instruction.
Definition: Core.cpp:2223
LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant, LLVMValueRef ElementValueConstant, unsigned *IdxList, unsigned NumIdx)
Definition: Core.cpp:1419
LLVMValueRef LLVMBuildURem(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:2598
bool hasName() const
Return true if this is a named struct that has a non-empty name.
Definition: DerivedTypes.h:259
LLVMTypeRef LLVMLabelType(void)
Definition: Core.cpp:612
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:843
Keep one copy of function when linking (inline)
Definition: GlobalValue.h:51
Arbitrary bit width integers.
Definition: Core.h:149
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:230
LLVMValueRef LLVMGetCondition(LLVMValueRef Branch)
Return the condition of a branch instruction.
Definition: Core.cpp:2275
Attribute::AttrKind getKindAsEnum() const
Return the attribute's kind as an enum (Attribute::AttrKind).
Definition: Attributes.cpp:157
AddressSpace
Definition: NVPTXBaseInfo.h:22
LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef B, LLVMRealPredicate Op, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:2940
static Constant * getNUWMul(Constant *C1, Constant *C2)
Definition: Constants.h:981
struct LLVMOpaqueBasicBlock * LLVMBasicBlockRef
Represents a basic block of instructions in LLVM IR.
Definition: c/Types.h:83
Structures.
Definition: Core.h:151
LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst)
Obtain the instruction that occurs after the one specified.
Definition: Core.cpp:2094
void LLVMDeleteGlobal(LLVMValueRef GlobalVar)
Definition: Core.cpp:1664
Xor a value and return the old one.
Definition: Core.h:316
LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType)
Definition: Core.cpp:1354
LLVMValueRef LLVMBuildXor(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:2638
LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:2573
static Constant * getNSWSub(Constant *C1, Constant *C2)
Definition: Constants.h:969
static Constant * getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:1559
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Definition: Constants.cpp:558
LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy)
Returns whether a function type is variadic.
Definition: Core.cpp:487
LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder)
Definition: Core.cpp:2407
LLVMLinkage
Definition: Core.h:160
static Constant * get(Type *Ty, double V)
This returns a ConstantFP, or a vector containing a splat of a ConstantFP, for the specified value in...
Definition: Constants.cpp:623
unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char *Name)
Obtain the number of operands for named metadata in a module.
Definition: Core.cpp:894
void LLVMSetAtomicSingleThread(LLVMValueRef AtomicInst, LLVMBool NewValue)
Definition: Core.cpp:3063
LLVMTypeRef LLVMDoubleType(void)
Definition: Core.cpp:462
32 bit floating point type
Definition: Core.h:143
LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef B, LLVMValueRef AggVal, LLVMValueRef EltVal, unsigned Index, const char *Name)
Definition: Core.cpp:2998
LLVMValueRef LLVMGetUser(LLVMUseRef U)
Obtain the user value for a user.
Definition: Core.cpp:737
void setLinkage(LinkageTypes LT)
Definition: GlobalValue.h:424
LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType)
Definition: Core.cpp:1302
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
8: Metadata
Definition: Type.h:64
provides Acquire semantics for loads and Release semantics for stores.
Definition: Core.h:299
unsigned getNumAttributes() const
Return the number of attributes this AttributeSet contains.
static LLVMOpcode map_to_llvmopcode(int opcode)
Definition: Core.cpp:1058
struct LLVMOpaquePassManager * LLVMPassManagerRef
Definition: c/Types.h:100
LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount, LLVMBool Packed)
Create a new structure type in the global context.
Definition: Core.cpp:514
unsigned getNumArgOperands() const
Definition: CallSite.h:288
LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef B, LLVMValueRef V1, LLVMValueRef V2, LLVMValueRef Mask, const char *Name)
Definition: Core.cpp:2986
double LLVMConstRealGetDouble(LLVMValueRef ConstantVal, LLVMBool *LosesInfo)
Obtain the double value for an floating point constant value.
Definition: Core.cpp:970
LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str, const char *Name)
Definition: Core.cpp:2786
void LLVMSetExternallyInitialized(LLVMValueRef GlobalVar, LLVMBool IsExtInit)
Definition: Core.cpp:1739
bool hasInitializer() const
Definitions have initializers, declarations don't.
Class for arbitrary precision integers.
Definition: APInt.h:77
LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef B, LLVMTypeRef Ty, const char *Name)
Definition: Core.cpp:2674
static std::unique_ptr< MemoryBuffer > getMemBufferCopy(StringRef InputData, const Twine &BufferName="")
Open the specified memory range as a MemoryBuffer, copying the contents and taking ownership of it...
LLVMValueRef LLVMIsAMDNode(LLVMValueRef Val)
Definition: Core.cpp:706
Same, but only replaced by something equivalent.
Definition: Core.h:164
LLVMAttributeRef LLVMGetCallSiteEnumAttribute(LLVMValueRef C, LLVMAttributeIndex Idx, unsigned KindID)
Definition: Core.cpp:2198
LLVMValueRef LLVMBuildFree(LLVMBuilderRef B, LLVMValueRef PointerVal)
Definition: Core.cpp:2706
LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType, LLVMTypeRef *ParamTypes, unsigned ParamCount, LLVMBool IsVarArg)
Obtain a function type consisting of a specified signature.
Definition: Core.cpp:480
StringRef getName() const
Return the name for this struct type if it has an identity.
Definition: Type.cpp:510
LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:2881
LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar)
Definition: Core.cpp:1680
Maximum length of the test input If
static Constant * getFPToUI(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:1647
static AttributeSetNode * get(LLVMContext &C, ArrayRef< Attribute > Attrs)
Definition: Attributes.cpp:479
LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType)
Definition: Core.cpp:1327
static char getTypeID(Type *Ty)
LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M)
Initializes, executes on the provided module, and finalizes all of the passes scheduled in the pass m...
Definition: Core.cpp:3191
LLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB)
Obtain the terminator instruction for a basic block.
Definition: Core.cpp:1984
Metadata.
Definition: Core.h:155
The file should be opened in text mode on platforms that make this distinction.
Definition: FileSystem.h:638
LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count, LLVMBool Packed)
Create a ConstantStruct in the global Context.
Definition: Core.cpp:1036
static Constant * getZExtOrBitCast(Constant *C, Type *Ty)
Definition: Constants.cpp:1491
LLVMBool LLVMIsConstantString(LLVMValueRef C)
Returns true if the specified constant is an array of i8.
Definition: Core.cpp:1012
void addAttribute(unsigned i, Attribute::AttrKind Kind)
Definition: CallSite.h:332
LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate, LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1243
LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C)
Create a X86 MMX type in a context.
Definition: Core.cpp:449
LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1157
double convertToDouble() const
Definition: APFloat.h:1013
LLVMBool LLVMIsDeclaration(LLVMValueRef Global)
Definition: Core.cpp:1445
static const fltSemantics & IEEEdouble()
Definition: APFloat.cpp:103
static Instruction * CreateMalloc(Instruction *InsertBefore, Type *IntPtrTy, Type *AllocTy, Value *AllocSize, Value *ArraySize=nullptr, Function *MallocF=nullptr, const Twine &Name="")
Generate the IR for a call to malloc:
LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:2866
Basic diagnostic printer that uses an underlying raw_ostream.
LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal)
Definition: Core.cpp:1092
void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues, LLVMBasicBlockRef *IncomingBlocks, unsigned Count)
Add an incoming value to the end of a PHI list.
Definition: Core.cpp:2307
static Constant * getFSub(Constant *C1, Constant *C2)
Definition: Constants.cpp:2150
LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef B, LLVMValueRef AggVal, unsigned Index, const char *Name)
Definition: Core.cpp:2993
LLVMValueRef LLVMBuildAShr(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:2623
static Constant * getTruncOrBitCast(Constant *C, Type *Ty)
Definition: Constants.cpp:1503
void LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BBRef)
Remove a basic block from a function.
Definition: Core.cpp:2060
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1132
LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1130
static Constant * getNeg(Constant *C, bool HasNUW=false, bool HasNSW=false)
Definition: Constants.cpp:2113
use_iterator use_begin()
Definition: Value.h:310
LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1140
LLVMValueRef LLVMBuildMul(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:2553
void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char *Name, LLVMValueRef Val)
Add an operand to named metadata.
Definition: Core.cpp:911
LLVMBool LLVMIsInBounds(LLVMValueRef GEP)
Check whether the given GEP instruction is inbounds.
Definition: Core.cpp:2297
LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg)
Obtain the previous parameter to a function.
Definition: Core.cpp:1947
LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID)
Create a new, empty module in the global context.
Definition: Core.cpp:215
unsigned LLVMGetNumIndices(LLVMValueRef Inst)
Obtain the number of indices.
Definition: Core.cpp:2328
Obsolete.
Definition: Core.h:177
void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal, LLVMBasicBlockRef Dest)
Definition: Core.cpp:2481
static Constant * getNSWMul(Constant *C1, Constant *C2)
Definition: Constants.h:977
LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef B, LLVMTypeRef Ty, LLVMValueRef Val, const char *Name)
Definition: Core.cpp:2685
LLVMAttributeRef wrap(Attribute Attr)
Definition: Attributes.h:186
A raw_ostream that writes to a file descriptor.
Definition: raw_ostream.h:357
char * LLVMPrintTypeToString(LLVMTypeRef Ty)
Return a string representation of the type.
Definition: Core.cpp:365
iterator end()
Definition: Module.h:537
LLVMBool LLVMIsConditional(LLVMValueRef Branch)
Return if a branch is conditional.
Definition: Core.cpp:2271
void LLVMRemoveEnumAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx, unsigned KindID)
Definition: Core.cpp:1875
Tentative definitions.
Definition: Core.h:178
LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:2876
static IntegerType * getInt32Ty(LLVMContext &C)
Definition: Type.cpp:169
LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy, unsigned NumWords, const uint64_t Words[])
Obtain a constant value for an integer of arbitrary precision.
Definition: Core.cpp:928
LLVMTypeRef LLVMInt64Type(void)
Definition: Core.cpp:415
16 bit floating point type
Definition: Core.h:142
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, int64_t FileSize=-1, bool RequiresNullTerminator=true, bool IsVolatileSize=false)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful, otherwise returning null.
LLVMVisibility
Definition: Core.h:183
unsigned LLVMGetEnumAttributeKindForName(const char *Name, size_t SLen)
Return an unique id given the name of a enum attribute, or 0 if no attribute by that name exists...
Definition: Core.cpp:127
LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C)
Obtain a 16-bit floating point type from a context.
Definition: Core.cpp:431
LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef FnRef, const char *Name)
Append a basic block to the end of a function using the global context.
Definition: Core.cpp:2040
const char * LLVMGetStringAttributeValue(LLVMAttributeRef A, unsigned *Length)
Get the string attribute's value.
Definition: Core.cpp:165
guarantees that if you take all the operations affecting a specific address, a consistent ordering ex...
Definition: Core.h:286
LLVMTypeRef LLVMInt128TypeInContext(LLVMContextRef C)
Definition: Core.cpp:396
LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal)
Definition: Core.cpp:1100
LLVMValueRef LLVMBuildAtomicRMW(LLVMBuilderRef B, LLVMAtomicRMWBinOp op, LLVMValueRef PTR, LLVMValueRef Val, LLVMAtomicOrdering ordering, LLVMBool singleThread)
Definition: Core.cpp:3020
void LLVMDeleteBasicBlock(LLVMBasicBlockRef BBRef)
Remove a basic block from a function and delete it.
Definition: Core.cpp:2056
void * PointerTy
Definition: GenericValue.h:24
LLVMAtomicOrdering LLVMGetCmpXchgSuccessOrdering(LLVMValueRef CmpXchgInst)
Definition: Core.cpp:3072
LLVMValueRef LLVMBuildLShr(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:2618
unsigned LLVMGetNumSuccessors(LLVMValueRef Term)
Return the number of successors that this terminator has.
Definition: Core.cpp:2257
LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef B, LLVMValueRef Val, const char *Name)
Definition: Core.cpp:3010
unsigned LLVMGetMDKindID(const char *Name, unsigned SLen)
Definition: Core.cpp:120
const NodeList & List
Definition: RDFGraph.cpp:205
LLVMBool LLVMIsConstant(LLVMValueRef Ty)
Determine whether the specified value instance is constant.
Definition: Core.cpp:802
const std::string & getGC() const
Definition: Function.cpp:412
static Constant * getPtrToInt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:1669
#define I(x, y, z)
Definition: MD5.cpp:54
#define N
LLVMBasicBlockRef LLVMGetUnwindDest(LLVMValueRef Invoke)
Return the unwind destination basic block.
Definition: Core.cpp:2243
LLVMValueRef LLVMBuildFSub(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:2548
static Constant * getOr(Constant *C1, Constant *C2)
Definition: Constants.cpp:2195
LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index)
Obtain an incoming value to a PHI node as an LLVMBasicBlockRef.
Definition: Core.cpp:2322
void LLVMSetUnwindDest(LLVMValueRef Invoke, LLVMBasicBlockRef B)
Set the unwind destination basic block.
Definition: Core.cpp:2251
LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C)
Obtain an integer type from a context with specified bit width.
Definition: Core.cpp:381
LLVMBool LLVMGetVolatile(LLVMValueRef MemAccessInst)
Definition: Core.cpp:2791
LLVMTypeRef LLVMInt1Type(void)
Obtain an integer type from the global context with a specified bit width.
Definition: Core.cpp:403
void initializeVerifierLegacyPassPass(PassRegistry &)
void LLVMGetCallSiteAttributes(LLVMValueRef C, LLVMAttributeIndex Idx, LLVMAttributeRef *Attrs)
Definition: Core.cpp:2188
LLVMTypeRef LLVMIntType(unsigned NumBits)
Definition: Core.cpp:421
void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC)
Set the calling convention for a call instruction.
Definition: Core.cpp:2158
iterator begin()
Definition: Module.h:535
LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M)
Constructs a new function-by-function pass pipeline over the module provider.
Definition: Core.cpp:3182
LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID, LLVMContextRef C)
Create a new, empty module in a specific context.
Definition: Core.cpp:219
LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef B, LLVMValueRef V, LLVMBasicBlockRef Else, unsigned NumCases)
Definition: Core.cpp:2442
LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy, LLVMValueRef *ConstantVals, unsigned Length)
Create a ConstantArray from values.
Definition: Core.cpp:1022
void removeAttribute(unsigned i, Attribute::AttrKind Kind)
Definition: CallSite.h:340
128 bit floating point type (two 64-bits)
Definition: Core.h:147
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
Definition: Type.cpp:606
void LLVMDumpType(LLVMTypeRef Ty)
Dump a representation of a type to stderr.
Definition: Core.cpp:361
static Constant * getShl(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
Definition: Constants.cpp:2203
Keep one copy of named function when linking (weak)
Definition: GlobalValue.h:53
bool isStringAttribute() const
Return true if the attribute is a string (target-dependent) attribute.
Definition: Attributes.cpp:153
static BinaryOperator * CreateNeg(Value *S1, const Twine &Name, Instruction *InsertBefore, Value *FlagsOp)
Rename collisions when linking (static functions).
Definition: GlobalValue.h:56
LLVMTypeRef LLVMInt8Type(void)
Definition: Core.cpp:406
static Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
Definition: Attributes.cpp:64
Special purpose, only applies to global arrays.
Definition: Core.h:170
static InlineAsm * get(FunctionType *Ty, StringRef AsmString, StringRef Constraints, bool hasSideEffects, bool isAlignStack=false, AsmDialect asmDialect=AD_ATT)
InlineAsm::get - Return the specified uniqued inline asm string.
Definition: InlineAsm.cpp:27
LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType)
Definition: Core.cpp:1312
AttributeSet getAttributes(LLVMContext &C, ID id)
Return the attributes for an intrinsic.
LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1255
const char * LLVMGetMDString(LLVMValueRef V, unsigned *Length)
Obtain the underlying string from a MDString value.
Definition: Core.cpp:864
LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM)
Finalizes all of the function passes scheduled in in the function pass manager.
Definition: Core.cpp:3203
void close()
Manually flush the stream and close the file.
LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst)
Obtain the predicate of an instruction.
Definition: Core.cpp:2118
void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val)
Definition: Core.cpp:2507
LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1250
LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:2563
Like LinkerPrivate, but is weak.
Definition: Core.h:180
LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal)
Definition: Core.cpp:1109
LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty, LLVMValueRef PersFn, unsigned NumClauses, const char *Name)
Definition: Core.cpp:2461
const APFloat & getValueAPF() const
Definition: Constants.h:300
unsigned LLVMGetAttributeCountAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx)
Definition: Core.cpp:1846
3: 64-bit floating point type
Definition: Type.h:59
LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M)
Obtain an iterator to the first Function in a Module.
Definition: Core.cpp:1765
StringRef getValueAsString() const
Return the attribute's value as a string.
Definition: Attributes.cpp:178
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename, char **ErrorMessage)
Print a representation of a module to a file.
Definition: Core.cpp:265
LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef B, LLVMValueRef List, LLVMTypeRef Ty, const char *Name)
Definition: Core.cpp:2968
void LLVMSetThreadLocalMode(LLVMValueRef GlobalVar, LLVMThreadLocalMode Mode)
Definition: Core.cpp:1713
static Constant * getSRem(Constant *C1, Constant *C2)
Definition: Constants.cpp:2183
Release is similar to Acquire, but with a barrier of the sort necessary to release a lock...
Definition: Core.h:292
LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C)
Definition: Core.cpp:2353
LLVMAtomicOrdering LLVMGetOrdering(LLVMValueRef MemAccessInst)
Definition: Core.cpp:2805
void LLVMSetMetadata(LLVMValueRef Inst, unsigned KindID, LLVMValueRef Val)
Set metadata associated with an instruction value.
Definition: Core.cpp:691
LLVMValueRef LLVMGetParamParent(LLVMValueRef V)
Obtain the function to which this argument belongs.
Definition: Core.cpp:1919
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:463
const char * LLVMGetValueName(LLVMValueRef Val)
Obtain the string name of a value.
Definition: Core.cpp:635
LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:2897
LLVMValueRef LLVMBuildBr(LLVMBuilderRef B, LLVMBasicBlockRef Dest)
Definition: Core.cpp:2433
void LLVMAddCallSiteAttribute(LLVMValueRef C, LLVMAttributeIndex Idx, LLVMAttributeRef A)
Definition: Core.cpp:2174
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:537
LLVM Value Representation.
Definition: Value.h:71
LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:2891
LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf, char **OutMessage)
Definition: Core.cpp:3126
LLVMLinkage LLVMGetLinkage(LLVMValueRef Global)
Definition: Core.cpp:1449
static Constant * getURem(Constant *C1, Constant *C2)
Definition: Constants.cpp:2179
unsigned getArgNo() const
Return the index of this formal argument in its containing function.
Definition: Function.cpp:57
static VectorType * get(Type *ElementType, unsigned NumElements)
This static method is the primary way to construct an VectorType.
Definition: Type.cpp:631
static StructType * create(LLVMContext &Context, StringRef Name)
This creates an identified struct.
Definition: Type.cpp:417
LLVMDLLStorageClass
Definition: Core.h:189
LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val)
Convert an LLVMValueRef to an LLVMBasicBlockRef instance.
Definition: Core.cpp:1972
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
Definition: BitmaskEnum.h:81
LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn)
Decrement a Function iterator to the previous Function.
Definition: Core.cpp:1789
static const Function * getParent(const Value *V)
void LLVMSetOrdering(LLVMValueRef MemAccessInst, LLVMAtomicOrdering Ordering)
Definition: Core.cpp:2815
LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr, unsigned NumDests)
Definition: Core.cpp:2447
void LLVMSetGC(LLVMValueRef Fn, const char *GC)
Define the garbage collector to use during code generation.
Definition: Core.cpp:1833
LLVMDLLStorageClass LLVMGetDLLStorageClass(LLVMValueRef Global)
Definition: Core.cpp:1560
static Constant * getUIToFP(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:1625
LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V, const char *Name)
Definition: Core.cpp:2654
static Constant * getFPToSI(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:1658
LLVMValueRef LLVMConstExactUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1184
Obsolete.
Definition: Core.h:175
LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy)
Obtain the Type this function Type returns.
Definition: Core.cpp:491
unsigned getNumOperands() const
Definition: Metadata.cpp:1038
LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:2558
LLVMValueRef LLVMBuildStore(LLVMBuilderRef B, LLVMValueRef Val, LLVMValueRef PointerVal)
Definition: Core.cpp:2716
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:125
#define DEBUG(X)
Definition: Debug.h:100
LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef LHS, LLVMValueRef RHS, const char *Name)
Definition: Core.cpp:2643
void(* YieldCallbackTy)(LLVMContext *Context, void *OpaqueHandle)
Defines the type of a yield callback.
Definition: LLVMContext.h:146
const char * LLVMGetModuleIdentifier(LLVMModuleRef M, size_t *Len)
Obtain the identifier of a module.
Definition: Core.cpp:228
static Constant * getExtractValue(Constant *Agg, ArrayRef< unsigned > Idxs, Type *OnlyIfReducedTy=nullptr)
Definition: Constants.cpp:2089
LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType)
Definition: Core.cpp:1292
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
LLVMBool LLVMIsMultithreaded()
Check whether LLVM is executing in thread-safe mode or not.
Definition: Core.cpp:3220
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
Definition: PassRegistry.h:40
A single uniqued string.
Definition: Metadata.h:586
AttrBuilder & addAlignmentAttr(unsigned Align)
This turns an int alignment (which must be a power of 2) into the form used internally in Attribute...
LLVMContextRef LLVMGetGlobalContext()
Obtain the global context instance.
Definition: Core.cpp:84
LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1162
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
Definition: ManagedStatic.h:63
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, const Twine &N="", Module *M=nullptr)
Definition: Function.h:117
LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C)
Definition: Core.cpp:390
LLVMAtomicOrdering LLVMGetCmpXchgFailureOrdering(LLVMValueRef CmpXchgInst)
Definition: Core.cpp:3085
void initializePrintFunctionPassWrapperPass(PassRegistry &)
static Constant * getExactUDiv(Constant *C1, Constant *C2)
Definition: Constants.h:997
LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F)
Executes all of the function passes scheduled in the function pass manager on the provided function...
Definition: Core.cpp:3199
static bool isVolatile(Instruction *Inst)
int * Ptr
64 bit floating point type
Definition: Core.h:144
9: MMX vectors (64 bits, X86 specific)
Definition: Type.h:65
static Constant * getAlignOf(Type *Ty)
getAlignOf constant expr - computes the alignment of a type in a target independent way (Note: the re...
Definition: Constants.cpp:1818
LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace)
Create a pointer type that points to a defined type.
Definition: Core.cpp:573
static Constant * getMul(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
Definition: Constants.cpp:2154
LLVMValueRef LLVMBuildLoad(LLVMBuilderRef B, LLVMValueRef PointerVal, const char *Name)
Definition: Core.cpp:2711
void LLVMInstructionRemoveFromParent(LLVMValueRef Inst)
Remove and delete an instruction.
Definition: Core.cpp:2110
LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant, LLVMValueRef IndexConstant)
Definition: Core.cpp:1391
void LLVMSetTailCall(LLVMValueRef Call, LLVMBool isTailCall)
Set whether a call instruction is a tail call.
Definition: Core.cpp:2233
static Constant * getNUWSub(Constant *C1, Constant *C2)
Definition: Constants.h:973
static BinaryOperator * CreateMul(Value *S1, Value *S2, const Twine &Name, Instruction *InsertBefore, Value *FlagsOp)
This file defines the node class used internally by AttributeSet.
void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm)
Set inline assembly for a module.
Definition: Core.cpp:297
LLVMValueRef LLVMBuildAddrSpaceCast(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:2886
LLVMBasicBlockRef LLVMGetNormalDest(LLVMValueRef Invoke)
Return the normal destination basic block.
Definition: Core.cpp:2239
AttributeSet addAttributes(LLVMContext &C, unsigned Index, AttributeSet Attrs) const
Add attributes to the attribute set at the given index.
Definition: Attributes.cpp:796
const char * LLVMGetStringAttributeKind(LLVMAttributeRef A, unsigned *Length)
Get the string attribute's kind.
Definition: Core.cpp:158
static Constant * getFPExtend(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:1613
LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
Definition: Core.cpp:1216
static GCRegistry::Add< ErlangGC > A("erlang","erlang-compatible garbage collector")
static Constant * getNUWAdd(Constant *C1, Constant *C2)
Definition: Constants.h:965
unsigned LLVMGetAlignment(LLVMValueRef V)
Obtain the preferred alignment of the value.
Definition: Core.cpp:1582
Tokens.
Definition: Core.h:157
LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn)
Advance a Function iterator to the next Function.
Definition: Core.cpp:1781
Root of the metadata hierarchy.
Definition: Metadata.h:55
void LLVMAddAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx, LLVMAttributeRef A)
Add an attribute to a function.
Definition: Core.cpp:1841
static IntegerType * getInt8Ty(LLVMContext &C)
Definition: Type.cpp:167
void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP)
Destroys the module M.
Definition: Core.cpp:3105
void LLVMRemoveStringAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx, const char *K, unsigned KLen)
Definition: Core.cpp:1880
LLVMTypeRef LLVMInt128Type(void)
Definition: Core.cpp:418
LLVMValueRef LLVMBuildSelect(LLVMBuilderRef B, LLVMValueRef If, LLVMValueRef Then, LLVMValueRef Else, const char *Name)
Definition: Core.cpp:2961
const BasicBlock * getParent() const
Definition: Instruction.h:62
static GlobalAlias * create(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage, const Twine &Name, Constant *Aliasee, Module *Parent)
If a parent module is specified, the alias is automatically inserted into the end of the specified mo...
Definition: Globals.cpp:384
LLVMRealPredicate
Definition: Core.h:250
LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C)
Obtain a 80-bit floating point type (X87) from a context.
Definition: Core.cpp:440
struct LLVMOpaqueValue * LLVMValueRef
Represents an individual value in LLVM IR.
Definition: c/Types.h:76
reference get()
Definition: ErrorOr.h:166
Type * getTypeAtIndex(const Value *V) const
Given an index value into the type, return the type of the element.
Definition: Type.cpp:554
void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr, const char *Name)
Definition: Core.cpp:2390
an instruction to allocate memory on the stack
Definition: Instructions.h:60
static Constant * getXor(Constant *C1, Constant *C2)
Definition: Constants.cpp:2199
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results...
Definition: Attributes.h:67
LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef B, LLVMValueRef Val, LLVMTypeRef DestTy, const char *Name)
Definition: Core.cpp:2861
5: 128-bit floating point type (112-bit mantissa)
Definition: Type.h:61
void LLVMSetIsInBounds(LLVMValueRef GEP, LLVMBool InBounds)
Set the given GEP instruction to be inbounds or not.
Definition: Core.cpp:2301
void LLVMSetAlignment(LLVMValueRef V, unsigned Bytes)
Set the preferred alignment of the value.
Definition: Core.cpp:1597
LLVMValueKind LLVMGetValueKind(LLVMValueRef Val)
Obtain the enumerated type of a Value instance.
Definition: Core.cpp:624
LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global)
Definition: Core.cpp:1441