1 //===-- Core.cpp ----------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the common infrastructure (including the C bindings)
11 // for libLLVMCore.a, which implements the LLVM intermediate representation.
13 //===----------------------------------------------------------------------===//
15 #include "llvm-c/Core.h"
16 #include "llvm/Bitcode/ReaderWriter.h"
17 #include "llvm/Constants.h"
18 #include "llvm/DerivedTypes.h"
19 #include "llvm/GlobalVariable.h"
20 #include "llvm/GlobalAlias.h"
21 #include "llvm/LLVMContext.h"
22 #include "llvm/InlineAsm.h"
23 #include "llvm/IntrinsicInst.h"
24 #include "llvm/PassManager.h"
25 #include "llvm/Support/CallSite.h"
26 #include "llvm/Support/Debug.h"
27 #include "llvm/Support/ErrorHandling.h"
28 #include "llvm/Support/MemoryBuffer.h"
29 #include "llvm/Support/raw_ostream.h"
30 #include "llvm/Support/system_error.h"
37 void llvm::initializeCore(PassRegistry
&Registry
) {
38 initializeDominatorTreePass(Registry
);
39 initializePrintModulePassPass(Registry
);
40 initializePrintFunctionPassPass(Registry
);
41 initializeVerifierPass(Registry
);
42 initializePreVerifierPass(Registry
);
45 void LLVMInitializeCore(LLVMPassRegistryRef R
) {
46 initializeCore(*unwrap(R
));
49 /*===-- Error handling ----------------------------------------------------===*/
51 void LLVMDisposeMessage(char *Message
) {
56 /*===-- Operations on contexts --------------------------------------------===*/
58 LLVMContextRef
LLVMContextCreate() {
59 return wrap(new LLVMContext());
62 LLVMContextRef
LLVMGetGlobalContext() {
63 return wrap(&getGlobalContext());
66 void LLVMContextDispose(LLVMContextRef C
) {
70 unsigned LLVMGetMDKindIDInContext(LLVMContextRef C
, const char* Name
,
72 return unwrap(C
)->getMDKindID(StringRef(Name
, SLen
));
75 unsigned LLVMGetMDKindID(const char* Name
, unsigned SLen
) {
76 return LLVMGetMDKindIDInContext(LLVMGetGlobalContext(), Name
, SLen
);
80 /*===-- Operations on modules ---------------------------------------------===*/
82 LLVMModuleRef
LLVMModuleCreateWithName(const char *ModuleID
) {
83 return wrap(new Module(ModuleID
, getGlobalContext()));
86 LLVMModuleRef
LLVMModuleCreateWithNameInContext(const char *ModuleID
,
88 return wrap(new Module(ModuleID
, *unwrap(C
)));
91 void LLVMDisposeModule(LLVMModuleRef M
) {
95 /*--.. Data layout .........................................................--*/
96 const char * LLVMGetDataLayout(LLVMModuleRef M
) {
97 return unwrap(M
)->getDataLayout().c_str();
100 void LLVMSetDataLayout(LLVMModuleRef M
, const char *Triple
) {
101 unwrap(M
)->setDataLayout(Triple
);
104 /*--.. Target triple .......................................................--*/
105 const char * LLVMGetTarget(LLVMModuleRef M
) {
106 return unwrap(M
)->getTargetTriple().c_str();
109 void LLVMSetTarget(LLVMModuleRef M
, const char *Triple
) {
110 unwrap(M
)->setTargetTriple(Triple
);
113 void LLVMDumpModule(LLVMModuleRef M
) {
117 /*--.. Operations on inline assembler ......................................--*/
118 void LLVMSetModuleInlineAsm(LLVMModuleRef M
, const char *Asm
) {
119 unwrap(M
)->setModuleInlineAsm(StringRef(Asm
));
123 /*--.. Operations on module contexts ......................................--*/
124 LLVMContextRef
LLVMGetModuleContext(LLVMModuleRef M
) {
125 return wrap(&unwrap(M
)->getContext());
129 /*===-- Operations on types -----------------------------------------------===*/
131 /*--.. Operations on all types (mostly) ....................................--*/
133 LLVMTypeKind
LLVMGetTypeKind(LLVMTypeRef Ty
) {
134 switch (unwrap(Ty
)->getTypeID()) {
136 assert(false && "Unhandled TypeID.");
138 return LLVMVoidTypeKind
;
139 case Type::FloatTyID
:
140 return LLVMFloatTypeKind
;
141 case Type::DoubleTyID
:
142 return LLVMDoubleTypeKind
;
143 case Type::X86_FP80TyID
:
144 return LLVMX86_FP80TypeKind
;
145 case Type::FP128TyID
:
146 return LLVMFP128TypeKind
;
147 case Type::PPC_FP128TyID
:
148 return LLVMPPC_FP128TypeKind
;
149 case Type::LabelTyID
:
150 return LLVMLabelTypeKind
;
151 case Type::MetadataTyID
:
152 return LLVMMetadataTypeKind
;
153 case Type::IntegerTyID
:
154 return LLVMIntegerTypeKind
;
155 case Type::FunctionTyID
:
156 return LLVMFunctionTypeKind
;
157 case Type::StructTyID
:
158 return LLVMStructTypeKind
;
159 case Type::ArrayTyID
:
160 return LLVMArrayTypeKind
;
161 case Type::PointerTyID
:
162 return LLVMPointerTypeKind
;
163 case Type::VectorTyID
:
164 return LLVMVectorTypeKind
;
165 case Type::X86_MMXTyID
:
166 return LLVMX86_MMXTypeKind
;
170 LLVMContextRef
LLVMGetTypeContext(LLVMTypeRef Ty
) {
171 return wrap(&unwrap(Ty
)->getContext());
174 /*--.. Operations on integer types .........................................--*/
176 LLVMTypeRef
LLVMInt1TypeInContext(LLVMContextRef C
) {
177 return (LLVMTypeRef
) Type::getInt1Ty(*unwrap(C
));
179 LLVMTypeRef
LLVMInt8TypeInContext(LLVMContextRef C
) {
180 return (LLVMTypeRef
) Type::getInt8Ty(*unwrap(C
));
182 LLVMTypeRef
LLVMInt16TypeInContext(LLVMContextRef C
) {
183 return (LLVMTypeRef
) Type::getInt16Ty(*unwrap(C
));
185 LLVMTypeRef
LLVMInt32TypeInContext(LLVMContextRef C
) {
186 return (LLVMTypeRef
) Type::getInt32Ty(*unwrap(C
));
188 LLVMTypeRef
LLVMInt64TypeInContext(LLVMContextRef C
) {
189 return (LLVMTypeRef
) Type::getInt64Ty(*unwrap(C
));
191 LLVMTypeRef
LLVMIntTypeInContext(LLVMContextRef C
, unsigned NumBits
) {
192 return wrap(IntegerType::get(*unwrap(C
), NumBits
));
195 LLVMTypeRef
LLVMInt1Type(void) {
196 return LLVMInt1TypeInContext(LLVMGetGlobalContext());
198 LLVMTypeRef
LLVMInt8Type(void) {
199 return LLVMInt8TypeInContext(LLVMGetGlobalContext());
201 LLVMTypeRef
LLVMInt16Type(void) {
202 return LLVMInt16TypeInContext(LLVMGetGlobalContext());
204 LLVMTypeRef
LLVMInt32Type(void) {
205 return LLVMInt32TypeInContext(LLVMGetGlobalContext());
207 LLVMTypeRef
LLVMInt64Type(void) {
208 return LLVMInt64TypeInContext(LLVMGetGlobalContext());
210 LLVMTypeRef
LLVMIntType(unsigned NumBits
) {
211 return LLVMIntTypeInContext(LLVMGetGlobalContext(), NumBits
);
214 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy
) {
215 return unwrap
<IntegerType
>(IntegerTy
)->getBitWidth();
218 /*--.. Operations on real types ............................................--*/
220 LLVMTypeRef
LLVMFloatTypeInContext(LLVMContextRef C
) {
221 return (LLVMTypeRef
) Type::getFloatTy(*unwrap(C
));
223 LLVMTypeRef
LLVMDoubleTypeInContext(LLVMContextRef C
) {
224 return (LLVMTypeRef
) Type::getDoubleTy(*unwrap(C
));
226 LLVMTypeRef
LLVMX86FP80TypeInContext(LLVMContextRef C
) {
227 return (LLVMTypeRef
) Type::getX86_FP80Ty(*unwrap(C
));
229 LLVMTypeRef
LLVMFP128TypeInContext(LLVMContextRef C
) {
230 return (LLVMTypeRef
) Type::getFP128Ty(*unwrap(C
));
232 LLVMTypeRef
LLVMPPCFP128TypeInContext(LLVMContextRef C
) {
233 return (LLVMTypeRef
) Type::getPPC_FP128Ty(*unwrap(C
));
235 LLVMTypeRef
LLVMX86MMXTypeInContext(LLVMContextRef C
) {
236 return (LLVMTypeRef
) Type::getX86_MMXTy(*unwrap(C
));
239 LLVMTypeRef
LLVMFloatType(void) {
240 return LLVMFloatTypeInContext(LLVMGetGlobalContext());
242 LLVMTypeRef
LLVMDoubleType(void) {
243 return LLVMDoubleTypeInContext(LLVMGetGlobalContext());
245 LLVMTypeRef
LLVMX86FP80Type(void) {
246 return LLVMX86FP80TypeInContext(LLVMGetGlobalContext());
248 LLVMTypeRef
LLVMFP128Type(void) {
249 return LLVMFP128TypeInContext(LLVMGetGlobalContext());
251 LLVMTypeRef
LLVMPPCFP128Type(void) {
252 return LLVMPPCFP128TypeInContext(LLVMGetGlobalContext());
254 LLVMTypeRef
LLVMX86MMXType(void) {
255 return LLVMX86MMXTypeInContext(LLVMGetGlobalContext());
258 /*--.. Operations on function types ........................................--*/
260 LLVMTypeRef
LLVMFunctionType(LLVMTypeRef ReturnType
,
261 LLVMTypeRef
*ParamTypes
, unsigned ParamCount
,
263 std::vector
<const Type
*> Tys
;
264 for (LLVMTypeRef
*I
= ParamTypes
, *E
= ParamTypes
+ ParamCount
; I
!= E
; ++I
)
265 Tys
.push_back(unwrap(*I
));
267 return wrap(FunctionType::get(unwrap(ReturnType
), Tys
, IsVarArg
!= 0));
270 LLVMBool
LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy
) {
271 return unwrap
<FunctionType
>(FunctionTy
)->isVarArg();
274 LLVMTypeRef
LLVMGetReturnType(LLVMTypeRef FunctionTy
) {
275 return wrap(unwrap
<FunctionType
>(FunctionTy
)->getReturnType());
278 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy
) {
279 return unwrap
<FunctionType
>(FunctionTy
)->getNumParams();
282 void LLVMGetParamTypes(LLVMTypeRef FunctionTy
, LLVMTypeRef
*Dest
) {
283 FunctionType
*Ty
= unwrap
<FunctionType
>(FunctionTy
);
284 for (FunctionType::param_iterator I
= Ty
->param_begin(),
285 E
= Ty
->param_end(); I
!= E
; ++I
)
289 /*--.. Operations on struct types ..........................................--*/
291 LLVMTypeRef
LLVMStructTypeInContext(LLVMContextRef C
, LLVMTypeRef
*ElementTypes
,
292 unsigned ElementCount
, LLVMBool Packed
) {
293 std::vector
<const Type
*> Tys
;
294 for (LLVMTypeRef
*I
= ElementTypes
,
295 *E
= ElementTypes
+ ElementCount
; I
!= E
; ++I
)
296 Tys
.push_back(unwrap(*I
));
298 return wrap(StructType::get(*unwrap(C
), Tys
, Packed
!= 0));
301 LLVMTypeRef
LLVMStructType(LLVMTypeRef
*ElementTypes
,
302 unsigned ElementCount
, LLVMBool Packed
) {
303 return LLVMStructTypeInContext(LLVMGetGlobalContext(), ElementTypes
,
304 ElementCount
, Packed
);
308 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy
) {
309 return unwrap
<StructType
>(StructTy
)->getNumElements();
312 void LLVMGetStructElementTypes(LLVMTypeRef StructTy
, LLVMTypeRef
*Dest
) {
313 StructType
*Ty
= unwrap
<StructType
>(StructTy
);
314 for (StructType::element_iterator I
= Ty
->element_begin(),
315 E
= Ty
->element_end(); I
!= E
; ++I
)
319 LLVMBool
LLVMIsPackedStruct(LLVMTypeRef StructTy
) {
320 return unwrap
<StructType
>(StructTy
)->isPacked();
323 /*--.. Operations on array, pointer, and vector types (sequence types) .....--*/
325 LLVMTypeRef
LLVMArrayType(LLVMTypeRef ElementType
, unsigned ElementCount
) {
326 return wrap(ArrayType::get(unwrap(ElementType
), ElementCount
));
329 LLVMTypeRef
LLVMPointerType(LLVMTypeRef ElementType
, unsigned AddressSpace
) {
330 return wrap(PointerType::get(unwrap(ElementType
), AddressSpace
));
333 LLVMTypeRef
LLVMVectorType(LLVMTypeRef ElementType
, unsigned ElementCount
) {
334 return wrap(VectorType::get(unwrap(ElementType
), ElementCount
));
337 LLVMTypeRef
LLVMGetElementType(LLVMTypeRef Ty
) {
338 return wrap(unwrap
<SequentialType
>(Ty
)->getElementType());
341 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy
) {
342 return unwrap
<ArrayType
>(ArrayTy
)->getNumElements();
345 unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy
) {
346 return unwrap
<PointerType
>(PointerTy
)->getAddressSpace();
349 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy
) {
350 return unwrap
<VectorType
>(VectorTy
)->getNumElements();
353 /*--.. Operations on other types ...........................................--*/
355 LLVMTypeRef
LLVMVoidTypeInContext(LLVMContextRef C
) {
356 return wrap(Type::getVoidTy(*unwrap(C
)));
358 LLVMTypeRef
LLVMLabelTypeInContext(LLVMContextRef C
) {
359 return wrap(Type::getLabelTy(*unwrap(C
)));
362 LLVMTypeRef
LLVMVoidType(void) {
363 return LLVMVoidTypeInContext(LLVMGetGlobalContext());
365 LLVMTypeRef
LLVMLabelType(void) {
366 return LLVMLabelTypeInContext(LLVMGetGlobalContext());
369 /*===-- Operations on values ----------------------------------------------===*/
371 /*--.. Operations on all values ............................................--*/
373 LLVMTypeRef
LLVMTypeOf(LLVMValueRef Val
) {
374 return wrap(unwrap(Val
)->getType());
377 const char *LLVMGetValueName(LLVMValueRef Val
) {
378 return unwrap(Val
)->getName().data();
381 void LLVMSetValueName(LLVMValueRef Val
, const char *Name
) {
382 unwrap(Val
)->setName(Name
);
385 void LLVMDumpValue(LLVMValueRef Val
) {
389 void LLVMReplaceAllUsesWith(LLVMValueRef OldVal
, LLVMValueRef NewVal
) {
390 unwrap(OldVal
)->replaceAllUsesWith(unwrap(NewVal
));
393 int LLVMHasMetadata(LLVMValueRef Inst
) {
394 return unwrap
<Instruction
>(Inst
)->hasMetadata();
397 LLVMValueRef
LLVMGetMetadata(LLVMValueRef Inst
, unsigned KindID
) {
398 return wrap(unwrap
<Instruction
>(Inst
)->getMetadata(KindID
));
401 void LLVMSetMetadata(LLVMValueRef Inst
, unsigned KindID
, LLVMValueRef MD
) {
402 unwrap
<Instruction
>(Inst
)->setMetadata(KindID
, MD
? unwrap
<MDNode
>(MD
) : NULL
);
405 /*--.. Conversion functions ................................................--*/
407 #define LLVM_DEFINE_VALUE_CAST(name) \
408 LLVMValueRef LLVMIsA##name(LLVMValueRef Val) { \
409 return wrap(static_cast<Value*>(dyn_cast_or_null<name>(unwrap(Val)))); \
412 LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DEFINE_VALUE_CAST
)
414 /*--.. Operations on Uses ..................................................--*/
415 LLVMUseRef
LLVMGetFirstUse(LLVMValueRef Val
) {
416 Value
*V
= unwrap(Val
);
417 Value::use_iterator I
= V
->use_begin();
418 if (I
== V
->use_end())
420 return wrap(&(I
.getUse()));
423 LLVMUseRef
LLVMGetNextUse(LLVMUseRef U
) {
424 Use
*Next
= unwrap(U
)->getNext();
430 LLVMValueRef
LLVMGetUser(LLVMUseRef U
) {
431 return wrap(unwrap(U
)->getUser());
434 LLVMValueRef
LLVMGetUsedValue(LLVMUseRef U
) {
435 return wrap(unwrap(U
)->get());
438 /*--.. Operations on Users .................................................--*/
439 LLVMValueRef
LLVMGetOperand(LLVMValueRef Val
, unsigned Index
) {
440 return wrap(unwrap
<User
>(Val
)->getOperand(Index
));
443 void LLVMSetOperand(LLVMValueRef Val
, unsigned Index
, LLVMValueRef Op
) {
444 unwrap
<User
>(Val
)->setOperand(Index
, unwrap(Op
));
447 int LLVMGetNumOperands(LLVMValueRef Val
) {
448 return unwrap
<User
>(Val
)->getNumOperands();
451 /*--.. Operations on constants of any type .................................--*/
453 LLVMValueRef
LLVMConstNull(LLVMTypeRef Ty
) {
454 return wrap(Constant::getNullValue(unwrap(Ty
)));
457 LLVMValueRef
LLVMConstAllOnes(LLVMTypeRef Ty
) {
458 return wrap(Constant::getAllOnesValue(unwrap(Ty
)));
461 LLVMValueRef
LLVMGetUndef(LLVMTypeRef Ty
) {
462 return wrap(UndefValue::get(unwrap(Ty
)));
465 LLVMBool
LLVMIsConstant(LLVMValueRef Ty
) {
466 return isa
<Constant
>(unwrap(Ty
));
469 LLVMBool
LLVMIsNull(LLVMValueRef Val
) {
470 if (Constant
*C
= dyn_cast
<Constant
>(unwrap(Val
)))
471 return C
->isNullValue();
475 LLVMBool
LLVMIsUndef(LLVMValueRef Val
) {
476 return isa
<UndefValue
>(unwrap(Val
));
479 LLVMValueRef
LLVMConstPointerNull(LLVMTypeRef Ty
) {
481 wrap(ConstantPointerNull::get(unwrap
<PointerType
>(Ty
)));
484 /*--.. Operations on metadata nodes ........................................--*/
486 LLVMValueRef
LLVMMDStringInContext(LLVMContextRef C
, const char *Str
,
488 return wrap(MDString::get(*unwrap(C
), StringRef(Str
, SLen
)));
491 LLVMValueRef
LLVMMDString(const char *Str
, unsigned SLen
) {
492 return LLVMMDStringInContext(LLVMGetGlobalContext(), Str
, SLen
);
495 LLVMValueRef
LLVMMDNodeInContext(LLVMContextRef C
, LLVMValueRef
*Vals
,
497 return wrap(MDNode::get(*unwrap(C
),
498 ArrayRef
<Value
*>(unwrap
<Value
>(Vals
, Count
), Count
)));
501 LLVMValueRef
LLVMMDNode(LLVMValueRef
*Vals
, unsigned Count
) {
502 return LLVMMDNodeInContext(LLVMGetGlobalContext(), Vals
, Count
);
505 /*--.. Operations on scalar constants ......................................--*/
507 LLVMValueRef
LLVMConstInt(LLVMTypeRef IntTy
, unsigned long long N
,
508 LLVMBool SignExtend
) {
509 return wrap(ConstantInt::get(unwrap
<IntegerType
>(IntTy
), N
, SignExtend
!= 0));
512 LLVMValueRef
LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy
,
514 const uint64_t Words
[]) {
515 IntegerType
*Ty
= unwrap
<IntegerType
>(IntTy
);
516 return wrap(ConstantInt::get(Ty
->getContext(),
517 APInt(Ty
->getBitWidth(), NumWords
, Words
)));
520 LLVMValueRef
LLVMConstIntOfString(LLVMTypeRef IntTy
, const char Str
[],
522 return wrap(ConstantInt::get(unwrap
<IntegerType
>(IntTy
), StringRef(Str
),
526 LLVMValueRef
LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy
, const char Str
[],
527 unsigned SLen
, uint8_t Radix
) {
528 return wrap(ConstantInt::get(unwrap
<IntegerType
>(IntTy
), StringRef(Str
, SLen
),
532 LLVMValueRef
LLVMConstReal(LLVMTypeRef RealTy
, double N
) {
533 return wrap(ConstantFP::get(unwrap(RealTy
), N
));
536 LLVMValueRef
LLVMConstRealOfString(LLVMTypeRef RealTy
, const char *Text
) {
537 return wrap(ConstantFP::get(unwrap(RealTy
), StringRef(Text
)));
540 LLVMValueRef
LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy
, const char Str
[],
542 return wrap(ConstantFP::get(unwrap(RealTy
), StringRef(Str
, SLen
)));
545 unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal
) {
546 return unwrap
<ConstantInt
>(ConstantVal
)->getZExtValue();
549 long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal
) {
550 return unwrap
<ConstantInt
>(ConstantVal
)->getSExtValue();
553 /*--.. Operations on composite constants ...................................--*/
555 LLVMValueRef
LLVMConstStringInContext(LLVMContextRef C
, const char *Str
,
557 LLVMBool DontNullTerminate
) {
558 /* Inverted the sense of AddNull because ', 0)' is a
559 better mnemonic for null termination than ', 1)'. */
560 return wrap(ConstantArray::get(*unwrap(C
), StringRef(Str
, Length
),
561 DontNullTerminate
== 0));
563 LLVMValueRef
LLVMConstStructInContext(LLVMContextRef C
,
564 LLVMValueRef
*ConstantVals
,
565 unsigned Count
, LLVMBool Packed
) {
566 Constant
**Elements
= unwrap
<Constant
>(ConstantVals
, Count
);
567 return wrap(ConstantStruct::getAnon(*unwrap(C
),
568 ArrayRef
<Constant
*>(Elements
, Count
),
572 LLVMValueRef
LLVMConstString(const char *Str
, unsigned Length
,
573 LLVMBool DontNullTerminate
) {
574 return LLVMConstStringInContext(LLVMGetGlobalContext(), Str
, Length
,
577 LLVMValueRef
LLVMConstArray(LLVMTypeRef ElementTy
,
578 LLVMValueRef
*ConstantVals
, unsigned Length
) {
579 ArrayRef
<Constant
*> V(unwrap
<Constant
>(ConstantVals
, Length
), Length
);
580 return wrap(ConstantArray::get(ArrayType::get(unwrap(ElementTy
), Length
), V
));
582 LLVMValueRef
LLVMConstStruct(LLVMValueRef
*ConstantVals
, unsigned Count
,
584 return LLVMConstStructInContext(LLVMGetGlobalContext(), ConstantVals
, Count
,
587 LLVMValueRef
LLVMConstVector(LLVMValueRef
*ScalarConstantVals
, unsigned Size
) {
588 return wrap(ConstantVector::get(ArrayRef
<Constant
*>(
589 unwrap
<Constant
>(ScalarConstantVals
, Size
), Size
)));
591 /*--.. Constant expressions ................................................--*/
593 LLVMOpcode
LLVMGetConstOpcode(LLVMValueRef ConstantVal
) {
594 return (LLVMOpcode
)unwrap
<ConstantExpr
>(ConstantVal
)->getOpcode();
597 LLVMValueRef
LLVMAlignOf(LLVMTypeRef Ty
) {
598 return wrap(ConstantExpr::getAlignOf(unwrap(Ty
)));
601 LLVMValueRef
LLVMSizeOf(LLVMTypeRef Ty
) {
602 return wrap(ConstantExpr::getSizeOf(unwrap(Ty
)));
605 LLVMValueRef
LLVMConstNeg(LLVMValueRef ConstantVal
) {
606 return wrap(ConstantExpr::getNeg(unwrap
<Constant
>(ConstantVal
)));
609 LLVMValueRef
LLVMConstNSWNeg(LLVMValueRef ConstantVal
) {
610 return wrap(ConstantExpr::getNSWNeg(unwrap
<Constant
>(ConstantVal
)));
613 LLVMValueRef
LLVMConstNUWNeg(LLVMValueRef ConstantVal
) {
614 return wrap(ConstantExpr::getNUWNeg(unwrap
<Constant
>(ConstantVal
)));
618 LLVMValueRef
LLVMConstFNeg(LLVMValueRef ConstantVal
) {
619 return wrap(ConstantExpr::getFNeg(unwrap
<Constant
>(ConstantVal
)));
622 LLVMValueRef
LLVMConstNot(LLVMValueRef ConstantVal
) {
623 return wrap(ConstantExpr::getNot(unwrap
<Constant
>(ConstantVal
)));
626 LLVMValueRef
LLVMConstAdd(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
) {
627 return wrap(ConstantExpr::getAdd(unwrap
<Constant
>(LHSConstant
),
628 unwrap
<Constant
>(RHSConstant
)));
631 LLVMValueRef
LLVMConstNSWAdd(LLVMValueRef LHSConstant
,
632 LLVMValueRef RHSConstant
) {
633 return wrap(ConstantExpr::getNSWAdd(unwrap
<Constant
>(LHSConstant
),
634 unwrap
<Constant
>(RHSConstant
)));
637 LLVMValueRef
LLVMConstNUWAdd(LLVMValueRef LHSConstant
,
638 LLVMValueRef RHSConstant
) {
639 return wrap(ConstantExpr::getNUWAdd(unwrap
<Constant
>(LHSConstant
),
640 unwrap
<Constant
>(RHSConstant
)));
643 LLVMValueRef
LLVMConstFAdd(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
) {
644 return wrap(ConstantExpr::getFAdd(unwrap
<Constant
>(LHSConstant
),
645 unwrap
<Constant
>(RHSConstant
)));
648 LLVMValueRef
LLVMConstSub(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
) {
649 return wrap(ConstantExpr::getSub(unwrap
<Constant
>(LHSConstant
),
650 unwrap
<Constant
>(RHSConstant
)));
653 LLVMValueRef
LLVMConstNSWSub(LLVMValueRef LHSConstant
,
654 LLVMValueRef RHSConstant
) {
655 return wrap(ConstantExpr::getNSWSub(unwrap
<Constant
>(LHSConstant
),
656 unwrap
<Constant
>(RHSConstant
)));
659 LLVMValueRef
LLVMConstNUWSub(LLVMValueRef LHSConstant
,
660 LLVMValueRef RHSConstant
) {
661 return wrap(ConstantExpr::getNUWSub(unwrap
<Constant
>(LHSConstant
),
662 unwrap
<Constant
>(RHSConstant
)));
665 LLVMValueRef
LLVMConstFSub(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
) {
666 return wrap(ConstantExpr::getFSub(unwrap
<Constant
>(LHSConstant
),
667 unwrap
<Constant
>(RHSConstant
)));
670 LLVMValueRef
LLVMConstMul(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
) {
671 return wrap(ConstantExpr::getMul(unwrap
<Constant
>(LHSConstant
),
672 unwrap
<Constant
>(RHSConstant
)));
675 LLVMValueRef
LLVMConstNSWMul(LLVMValueRef LHSConstant
,
676 LLVMValueRef RHSConstant
) {
677 return wrap(ConstantExpr::getNSWMul(unwrap
<Constant
>(LHSConstant
),
678 unwrap
<Constant
>(RHSConstant
)));
681 LLVMValueRef
LLVMConstNUWMul(LLVMValueRef LHSConstant
,
682 LLVMValueRef RHSConstant
) {
683 return wrap(ConstantExpr::getNUWMul(unwrap
<Constant
>(LHSConstant
),
684 unwrap
<Constant
>(RHSConstant
)));
687 LLVMValueRef
LLVMConstFMul(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
) {
688 return wrap(ConstantExpr::getFMul(unwrap
<Constant
>(LHSConstant
),
689 unwrap
<Constant
>(RHSConstant
)));
692 LLVMValueRef
LLVMConstUDiv(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
) {
693 return wrap(ConstantExpr::getUDiv(unwrap
<Constant
>(LHSConstant
),
694 unwrap
<Constant
>(RHSConstant
)));
697 LLVMValueRef
LLVMConstSDiv(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
) {
698 return wrap(ConstantExpr::getSDiv(unwrap
<Constant
>(LHSConstant
),
699 unwrap
<Constant
>(RHSConstant
)));
702 LLVMValueRef
LLVMConstExactSDiv(LLVMValueRef LHSConstant
,
703 LLVMValueRef RHSConstant
) {
704 return wrap(ConstantExpr::getExactSDiv(unwrap
<Constant
>(LHSConstant
),
705 unwrap
<Constant
>(RHSConstant
)));
708 LLVMValueRef
LLVMConstFDiv(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
) {
709 return wrap(ConstantExpr::getFDiv(unwrap
<Constant
>(LHSConstant
),
710 unwrap
<Constant
>(RHSConstant
)));
713 LLVMValueRef
LLVMConstURem(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
) {
714 return wrap(ConstantExpr::getURem(unwrap
<Constant
>(LHSConstant
),
715 unwrap
<Constant
>(RHSConstant
)));
718 LLVMValueRef
LLVMConstSRem(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
) {
719 return wrap(ConstantExpr::getSRem(unwrap
<Constant
>(LHSConstant
),
720 unwrap
<Constant
>(RHSConstant
)));
723 LLVMValueRef
LLVMConstFRem(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
) {
724 return wrap(ConstantExpr::getFRem(unwrap
<Constant
>(LHSConstant
),
725 unwrap
<Constant
>(RHSConstant
)));
728 LLVMValueRef
LLVMConstAnd(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
) {
729 return wrap(ConstantExpr::getAnd(unwrap
<Constant
>(LHSConstant
),
730 unwrap
<Constant
>(RHSConstant
)));
733 LLVMValueRef
LLVMConstOr(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
) {
734 return wrap(ConstantExpr::getOr(unwrap
<Constant
>(LHSConstant
),
735 unwrap
<Constant
>(RHSConstant
)));
738 LLVMValueRef
LLVMConstXor(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
) {
739 return wrap(ConstantExpr::getXor(unwrap
<Constant
>(LHSConstant
),
740 unwrap
<Constant
>(RHSConstant
)));
743 LLVMValueRef
LLVMConstICmp(LLVMIntPredicate Predicate
,
744 LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
) {
745 return wrap(ConstantExpr::getICmp(Predicate
,
746 unwrap
<Constant
>(LHSConstant
),
747 unwrap
<Constant
>(RHSConstant
)));
750 LLVMValueRef
LLVMConstFCmp(LLVMRealPredicate Predicate
,
751 LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
) {
752 return wrap(ConstantExpr::getFCmp(Predicate
,
753 unwrap
<Constant
>(LHSConstant
),
754 unwrap
<Constant
>(RHSConstant
)));
757 LLVMValueRef
LLVMConstShl(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
) {
758 return wrap(ConstantExpr::getShl(unwrap
<Constant
>(LHSConstant
),
759 unwrap
<Constant
>(RHSConstant
)));
762 LLVMValueRef
LLVMConstLShr(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
) {
763 return wrap(ConstantExpr::getLShr(unwrap
<Constant
>(LHSConstant
),
764 unwrap
<Constant
>(RHSConstant
)));
767 LLVMValueRef
LLVMConstAShr(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
) {
768 return wrap(ConstantExpr::getAShr(unwrap
<Constant
>(LHSConstant
),
769 unwrap
<Constant
>(RHSConstant
)));
772 LLVMValueRef
LLVMConstGEP(LLVMValueRef ConstantVal
,
773 LLVMValueRef
*ConstantIndices
, unsigned NumIndices
) {
774 return wrap(ConstantExpr::getGetElementPtr(unwrap
<Constant
>(ConstantVal
),
775 unwrap
<Constant
>(ConstantIndices
,
780 LLVMValueRef
LLVMConstInBoundsGEP(LLVMValueRef ConstantVal
,
781 LLVMValueRef
*ConstantIndices
,
782 unsigned NumIndices
) {
783 Constant
* Val
= unwrap
<Constant
>(ConstantVal
);
784 Constant
** Idxs
= unwrap
<Constant
>(ConstantIndices
, NumIndices
);
785 return wrap(ConstantExpr::getInBoundsGetElementPtr(Val
, Idxs
, NumIndices
));
788 LLVMValueRef
LLVMConstTrunc(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
) {
789 return wrap(ConstantExpr::getTrunc(unwrap
<Constant
>(ConstantVal
),
793 LLVMValueRef
LLVMConstSExt(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
) {
794 return wrap(ConstantExpr::getSExt(unwrap
<Constant
>(ConstantVal
),
798 LLVMValueRef
LLVMConstZExt(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
) {
799 return wrap(ConstantExpr::getZExt(unwrap
<Constant
>(ConstantVal
),
803 LLVMValueRef
LLVMConstFPTrunc(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
) {
804 return wrap(ConstantExpr::getFPTrunc(unwrap
<Constant
>(ConstantVal
),
808 LLVMValueRef
LLVMConstFPExt(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
) {
809 return wrap(ConstantExpr::getFPExtend(unwrap
<Constant
>(ConstantVal
),
813 LLVMValueRef
LLVMConstUIToFP(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
) {
814 return wrap(ConstantExpr::getUIToFP(unwrap
<Constant
>(ConstantVal
),
818 LLVMValueRef
LLVMConstSIToFP(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
) {
819 return wrap(ConstantExpr::getSIToFP(unwrap
<Constant
>(ConstantVal
),
823 LLVMValueRef
LLVMConstFPToUI(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
) {
824 return wrap(ConstantExpr::getFPToUI(unwrap
<Constant
>(ConstantVal
),
828 LLVMValueRef
LLVMConstFPToSI(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
) {
829 return wrap(ConstantExpr::getFPToSI(unwrap
<Constant
>(ConstantVal
),
833 LLVMValueRef
LLVMConstPtrToInt(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
) {
834 return wrap(ConstantExpr::getPtrToInt(unwrap
<Constant
>(ConstantVal
),
838 LLVMValueRef
LLVMConstIntToPtr(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
) {
839 return wrap(ConstantExpr::getIntToPtr(unwrap
<Constant
>(ConstantVal
),
843 LLVMValueRef
LLVMConstBitCast(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
) {
844 return wrap(ConstantExpr::getBitCast(unwrap
<Constant
>(ConstantVal
),
848 LLVMValueRef
LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal
,
849 LLVMTypeRef ToType
) {
850 return wrap(ConstantExpr::getZExtOrBitCast(unwrap
<Constant
>(ConstantVal
),
854 LLVMValueRef
LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal
,
855 LLVMTypeRef ToType
) {
856 return wrap(ConstantExpr::getSExtOrBitCast(unwrap
<Constant
>(ConstantVal
),
860 LLVMValueRef
LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal
,
861 LLVMTypeRef ToType
) {
862 return wrap(ConstantExpr::getTruncOrBitCast(unwrap
<Constant
>(ConstantVal
),
866 LLVMValueRef
LLVMConstPointerCast(LLVMValueRef ConstantVal
,
867 LLVMTypeRef ToType
) {
868 return wrap(ConstantExpr::getPointerCast(unwrap
<Constant
>(ConstantVal
),
872 LLVMValueRef
LLVMConstIntCast(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
,
874 return wrap(ConstantExpr::getIntegerCast(unwrap
<Constant
>(ConstantVal
),
875 unwrap(ToType
), isSigned
));
878 LLVMValueRef
LLVMConstFPCast(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
) {
879 return wrap(ConstantExpr::getFPCast(unwrap
<Constant
>(ConstantVal
),
883 LLVMValueRef
LLVMConstSelect(LLVMValueRef ConstantCondition
,
884 LLVMValueRef ConstantIfTrue
,
885 LLVMValueRef ConstantIfFalse
) {
886 return wrap(ConstantExpr::getSelect(unwrap
<Constant
>(ConstantCondition
),
887 unwrap
<Constant
>(ConstantIfTrue
),
888 unwrap
<Constant
>(ConstantIfFalse
)));
891 LLVMValueRef
LLVMConstExtractElement(LLVMValueRef VectorConstant
,
892 LLVMValueRef IndexConstant
) {
893 return wrap(ConstantExpr::getExtractElement(unwrap
<Constant
>(VectorConstant
),
894 unwrap
<Constant
>(IndexConstant
)));
897 LLVMValueRef
LLVMConstInsertElement(LLVMValueRef VectorConstant
,
898 LLVMValueRef ElementValueConstant
,
899 LLVMValueRef IndexConstant
) {
900 return wrap(ConstantExpr::getInsertElement(unwrap
<Constant
>(VectorConstant
),
901 unwrap
<Constant
>(ElementValueConstant
),
902 unwrap
<Constant
>(IndexConstant
)));
905 LLVMValueRef
LLVMConstShuffleVector(LLVMValueRef VectorAConstant
,
906 LLVMValueRef VectorBConstant
,
907 LLVMValueRef MaskConstant
) {
908 return wrap(ConstantExpr::getShuffleVector(unwrap
<Constant
>(VectorAConstant
),
909 unwrap
<Constant
>(VectorBConstant
),
910 unwrap
<Constant
>(MaskConstant
)));
913 LLVMValueRef
LLVMConstExtractValue(LLVMValueRef AggConstant
, unsigned *IdxList
,
915 return wrap(ConstantExpr::getExtractValue(unwrap
<Constant
>(AggConstant
),
919 LLVMValueRef
LLVMConstInsertValue(LLVMValueRef AggConstant
,
920 LLVMValueRef ElementValueConstant
,
921 unsigned *IdxList
, unsigned NumIdx
) {
922 return wrap(ConstantExpr::getInsertValue(unwrap
<Constant
>(AggConstant
),
923 unwrap
<Constant
>(ElementValueConstant
),
927 LLVMValueRef
LLVMConstInlineAsm(LLVMTypeRef Ty
, const char *AsmString
,
928 const char *Constraints
,
929 LLVMBool HasSideEffects
,
930 LLVMBool IsAlignStack
) {
931 return wrap(InlineAsm::get(dyn_cast
<FunctionType
>(unwrap(Ty
)), AsmString
,
932 Constraints
, HasSideEffects
, IsAlignStack
));
935 LLVMValueRef
LLVMBlockAddress(LLVMValueRef F
, LLVMBasicBlockRef BB
) {
936 return wrap(BlockAddress::get(unwrap
<Function
>(F
), unwrap(BB
)));
939 /*--.. Operations on global variables, functions, and aliases (globals) ....--*/
941 LLVMModuleRef
LLVMGetGlobalParent(LLVMValueRef Global
) {
942 return wrap(unwrap
<GlobalValue
>(Global
)->getParent());
945 LLVMBool
LLVMIsDeclaration(LLVMValueRef Global
) {
946 return unwrap
<GlobalValue
>(Global
)->isDeclaration();
949 LLVMLinkage
LLVMGetLinkage(LLVMValueRef Global
) {
950 switch (unwrap
<GlobalValue
>(Global
)->getLinkage()) {
952 assert(false && "Unhandled Linkage Type.");
953 case GlobalValue::ExternalLinkage
:
954 return LLVMExternalLinkage
;
955 case GlobalValue::AvailableExternallyLinkage
:
956 return LLVMAvailableExternallyLinkage
;
957 case GlobalValue::LinkOnceAnyLinkage
:
958 return LLVMLinkOnceAnyLinkage
;
959 case GlobalValue::LinkOnceODRLinkage
:
960 return LLVMLinkOnceODRLinkage
;
961 case GlobalValue::WeakAnyLinkage
:
962 return LLVMWeakAnyLinkage
;
963 case GlobalValue::WeakODRLinkage
:
964 return LLVMWeakODRLinkage
;
965 case GlobalValue::AppendingLinkage
:
966 return LLVMAppendingLinkage
;
967 case GlobalValue::InternalLinkage
:
968 return LLVMInternalLinkage
;
969 case GlobalValue::PrivateLinkage
:
970 return LLVMPrivateLinkage
;
971 case GlobalValue::LinkerPrivateLinkage
:
972 return LLVMLinkerPrivateLinkage
;
973 case GlobalValue::LinkerPrivateWeakLinkage
:
974 return LLVMLinkerPrivateWeakLinkage
;
975 case GlobalValue::LinkerPrivateWeakDefAutoLinkage
:
976 return LLVMLinkerPrivateWeakDefAutoLinkage
;
977 case GlobalValue::DLLImportLinkage
:
978 return LLVMDLLImportLinkage
;
979 case GlobalValue::DLLExportLinkage
:
980 return LLVMDLLExportLinkage
;
981 case GlobalValue::ExternalWeakLinkage
:
982 return LLVMExternalWeakLinkage
;
983 case GlobalValue::CommonLinkage
:
984 return LLVMCommonLinkage
;
987 // Should never get here.
988 return static_cast<LLVMLinkage
>(0);
991 void LLVMSetLinkage(LLVMValueRef Global
, LLVMLinkage Linkage
) {
992 GlobalValue
*GV
= unwrap
<GlobalValue
>(Global
);
996 assert(false && "Unhandled Linkage Type.");
997 case LLVMExternalLinkage
:
998 GV
->setLinkage(GlobalValue::ExternalLinkage
);
1000 case LLVMAvailableExternallyLinkage
:
1001 GV
->setLinkage(GlobalValue::AvailableExternallyLinkage
);
1003 case LLVMLinkOnceAnyLinkage
:
1004 GV
->setLinkage(GlobalValue::LinkOnceAnyLinkage
);
1006 case LLVMLinkOnceODRLinkage
:
1007 GV
->setLinkage(GlobalValue::LinkOnceODRLinkage
);
1009 case LLVMWeakAnyLinkage
:
1010 GV
->setLinkage(GlobalValue::WeakAnyLinkage
);
1012 case LLVMWeakODRLinkage
:
1013 GV
->setLinkage(GlobalValue::WeakODRLinkage
);
1015 case LLVMAppendingLinkage
:
1016 GV
->setLinkage(GlobalValue::AppendingLinkage
);
1018 case LLVMInternalLinkage
:
1019 GV
->setLinkage(GlobalValue::InternalLinkage
);
1021 case LLVMPrivateLinkage
:
1022 GV
->setLinkage(GlobalValue::PrivateLinkage
);
1024 case LLVMLinkerPrivateLinkage
:
1025 GV
->setLinkage(GlobalValue::LinkerPrivateLinkage
);
1027 case LLVMLinkerPrivateWeakLinkage
:
1028 GV
->setLinkage(GlobalValue::LinkerPrivateWeakLinkage
);
1030 case LLVMLinkerPrivateWeakDefAutoLinkage
:
1031 GV
->setLinkage(GlobalValue::LinkerPrivateWeakDefAutoLinkage
);
1033 case LLVMDLLImportLinkage
:
1034 GV
->setLinkage(GlobalValue::DLLImportLinkage
);
1036 case LLVMDLLExportLinkage
:
1037 GV
->setLinkage(GlobalValue::DLLExportLinkage
);
1039 case LLVMExternalWeakLinkage
:
1040 GV
->setLinkage(GlobalValue::ExternalWeakLinkage
);
1042 case LLVMGhostLinkage
:
1044 << "LLVMSetLinkage(): LLVMGhostLinkage is no longer supported.");
1046 case LLVMCommonLinkage
:
1047 GV
->setLinkage(GlobalValue::CommonLinkage
);
1052 const char *LLVMGetSection(LLVMValueRef Global
) {
1053 return unwrap
<GlobalValue
>(Global
)->getSection().c_str();
1056 void LLVMSetSection(LLVMValueRef Global
, const char *Section
) {
1057 unwrap
<GlobalValue
>(Global
)->setSection(Section
);
1060 LLVMVisibility
LLVMGetVisibility(LLVMValueRef Global
) {
1061 return static_cast<LLVMVisibility
>(
1062 unwrap
<GlobalValue
>(Global
)->getVisibility());
1065 void LLVMSetVisibility(LLVMValueRef Global
, LLVMVisibility Viz
) {
1066 unwrap
<GlobalValue
>(Global
)
1067 ->setVisibility(static_cast<GlobalValue::VisibilityTypes
>(Viz
));
1070 unsigned LLVMGetAlignment(LLVMValueRef Global
) {
1071 return unwrap
<GlobalValue
>(Global
)->getAlignment();
1074 void LLVMSetAlignment(LLVMValueRef Global
, unsigned Bytes
) {
1075 unwrap
<GlobalValue
>(Global
)->setAlignment(Bytes
);
1078 /*--.. Operations on global variables ......................................--*/
1080 LLVMValueRef
LLVMAddGlobal(LLVMModuleRef M
, LLVMTypeRef Ty
, const char *Name
) {
1081 return wrap(new GlobalVariable(*unwrap(M
), unwrap(Ty
), false,
1082 GlobalValue::ExternalLinkage
, 0, Name
));
1085 LLVMValueRef
LLVMAddGlobalInAddressSpace(LLVMModuleRef M
, LLVMTypeRef Ty
,
1087 unsigned AddressSpace
) {
1088 return wrap(new GlobalVariable(*unwrap(M
), unwrap(Ty
), false,
1089 GlobalValue::ExternalLinkage
, 0, Name
, 0,
1090 false, AddressSpace
));
1093 LLVMValueRef
LLVMGetNamedGlobal(LLVMModuleRef M
, const char *Name
) {
1094 return wrap(unwrap(M
)->getNamedGlobal(Name
));
1097 LLVMValueRef
LLVMGetFirstGlobal(LLVMModuleRef M
) {
1098 Module
*Mod
= unwrap(M
);
1099 Module::global_iterator I
= Mod
->global_begin();
1100 if (I
== Mod
->global_end())
1105 LLVMValueRef
LLVMGetLastGlobal(LLVMModuleRef M
) {
1106 Module
*Mod
= unwrap(M
);
1107 Module::global_iterator I
= Mod
->global_end();
1108 if (I
== Mod
->global_begin())
1113 LLVMValueRef
LLVMGetNextGlobal(LLVMValueRef GlobalVar
) {
1114 GlobalVariable
*GV
= unwrap
<GlobalVariable
>(GlobalVar
);
1115 Module::global_iterator I
= GV
;
1116 if (++I
== GV
->getParent()->global_end())
1121 LLVMValueRef
LLVMGetPreviousGlobal(LLVMValueRef GlobalVar
) {
1122 GlobalVariable
*GV
= unwrap
<GlobalVariable
>(GlobalVar
);
1123 Module::global_iterator I
= GV
;
1124 if (I
== GV
->getParent()->global_begin())
1129 void LLVMDeleteGlobal(LLVMValueRef GlobalVar
) {
1130 unwrap
<GlobalVariable
>(GlobalVar
)->eraseFromParent();
1133 LLVMValueRef
LLVMGetInitializer(LLVMValueRef GlobalVar
) {
1134 GlobalVariable
* GV
= unwrap
<GlobalVariable
>(GlobalVar
);
1135 if ( !GV
->hasInitializer() )
1137 return wrap(GV
->getInitializer());
1140 void LLVMSetInitializer(LLVMValueRef GlobalVar
, LLVMValueRef ConstantVal
) {
1141 unwrap
<GlobalVariable
>(GlobalVar
)
1142 ->setInitializer(unwrap
<Constant
>(ConstantVal
));
1145 LLVMBool
LLVMIsThreadLocal(LLVMValueRef GlobalVar
) {
1146 return unwrap
<GlobalVariable
>(GlobalVar
)->isThreadLocal();
1149 void LLVMSetThreadLocal(LLVMValueRef GlobalVar
, LLVMBool IsThreadLocal
) {
1150 unwrap
<GlobalVariable
>(GlobalVar
)->setThreadLocal(IsThreadLocal
!= 0);
1153 LLVMBool
LLVMIsGlobalConstant(LLVMValueRef GlobalVar
) {
1154 return unwrap
<GlobalVariable
>(GlobalVar
)->isConstant();
1157 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar
, LLVMBool IsConstant
) {
1158 unwrap
<GlobalVariable
>(GlobalVar
)->setConstant(IsConstant
!= 0);
1161 /*--.. Operations on aliases ......................................--*/
1163 LLVMValueRef
LLVMAddAlias(LLVMModuleRef M
, LLVMTypeRef Ty
, LLVMValueRef Aliasee
,
1165 return wrap(new GlobalAlias(unwrap(Ty
), GlobalValue::ExternalLinkage
, Name
,
1166 unwrap
<Constant
>(Aliasee
), unwrap (M
)));
1169 /*--.. Operations on functions .............................................--*/
1171 LLVMValueRef
LLVMAddFunction(LLVMModuleRef M
, const char *Name
,
1172 LLVMTypeRef FunctionTy
) {
1173 return wrap(Function::Create(unwrap
<FunctionType
>(FunctionTy
),
1174 GlobalValue::ExternalLinkage
, Name
, unwrap(M
)));
1177 LLVMValueRef
LLVMGetNamedFunction(LLVMModuleRef M
, const char *Name
) {
1178 return wrap(unwrap(M
)->getFunction(Name
));
1181 LLVMValueRef
LLVMGetFirstFunction(LLVMModuleRef M
) {
1182 Module
*Mod
= unwrap(M
);
1183 Module::iterator I
= Mod
->begin();
1184 if (I
== Mod
->end())
1189 LLVMValueRef
LLVMGetLastFunction(LLVMModuleRef M
) {
1190 Module
*Mod
= unwrap(M
);
1191 Module::iterator I
= Mod
->end();
1192 if (I
== Mod
->begin())
1197 LLVMValueRef
LLVMGetNextFunction(LLVMValueRef Fn
) {
1198 Function
*Func
= unwrap
<Function
>(Fn
);
1199 Module::iterator I
= Func
;
1200 if (++I
== Func
->getParent()->end())
1205 LLVMValueRef
LLVMGetPreviousFunction(LLVMValueRef Fn
) {
1206 Function
*Func
= unwrap
<Function
>(Fn
);
1207 Module::iterator I
= Func
;
1208 if (I
== Func
->getParent()->begin())
1213 void LLVMDeleteFunction(LLVMValueRef Fn
) {
1214 unwrap
<Function
>(Fn
)->eraseFromParent();
1217 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn
) {
1218 if (Function
*F
= dyn_cast
<Function
>(unwrap(Fn
)))
1219 return F
->getIntrinsicID();
1223 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn
) {
1224 return unwrap
<Function
>(Fn
)->getCallingConv();
1227 void LLVMSetFunctionCallConv(LLVMValueRef Fn
, unsigned CC
) {
1228 return unwrap
<Function
>(Fn
)->setCallingConv(
1229 static_cast<CallingConv::ID
>(CC
));
1232 const char *LLVMGetGC(LLVMValueRef Fn
) {
1233 Function
*F
= unwrap
<Function
>(Fn
);
1234 return F
->hasGC()? F
->getGC() : 0;
1237 void LLVMSetGC(LLVMValueRef Fn
, const char *GC
) {
1238 Function
*F
= unwrap
<Function
>(Fn
);
1245 void LLVMAddFunctionAttr(LLVMValueRef Fn
, LLVMAttribute PA
) {
1246 Function
*Func
= unwrap
<Function
>(Fn
);
1247 const AttrListPtr PAL
= Func
->getAttributes();
1248 const AttrListPtr PALnew
= PAL
.addAttr(~0U, PA
);
1249 Func
->setAttributes(PALnew
);
1252 void LLVMRemoveFunctionAttr(LLVMValueRef Fn
, LLVMAttribute PA
) {
1253 Function
*Func
= unwrap
<Function
>(Fn
);
1254 const AttrListPtr PAL
= Func
->getAttributes();
1255 const AttrListPtr PALnew
= PAL
.removeAttr(~0U, PA
);
1256 Func
->setAttributes(PALnew
);
1259 LLVMAttribute
LLVMGetFunctionAttr(LLVMValueRef Fn
) {
1260 Function
*Func
= unwrap
<Function
>(Fn
);
1261 const AttrListPtr PAL
= Func
->getAttributes();
1262 Attributes attr
= PAL
.getFnAttributes();
1263 return (LLVMAttribute
)attr
;
1266 /*--.. Operations on parameters ............................................--*/
1268 unsigned LLVMCountParams(LLVMValueRef FnRef
) {
1269 // This function is strictly redundant to
1270 // LLVMCountParamTypes(LLVMGetElementType(LLVMTypeOf(FnRef)))
1271 return unwrap
<Function
>(FnRef
)->arg_size();
1274 void LLVMGetParams(LLVMValueRef FnRef
, LLVMValueRef
*ParamRefs
) {
1275 Function
*Fn
= unwrap
<Function
>(FnRef
);
1276 for (Function::arg_iterator I
= Fn
->arg_begin(),
1277 E
= Fn
->arg_end(); I
!= E
; I
++)
1278 *ParamRefs
++ = wrap(I
);
1281 LLVMValueRef
LLVMGetParam(LLVMValueRef FnRef
, unsigned index
) {
1282 Function::arg_iterator AI
= unwrap
<Function
>(FnRef
)->arg_begin();
1288 LLVMValueRef
LLVMGetParamParent(LLVMValueRef V
) {
1289 return wrap(unwrap
<Argument
>(V
)->getParent());
1292 LLVMValueRef
LLVMGetFirstParam(LLVMValueRef Fn
) {
1293 Function
*Func
= unwrap
<Function
>(Fn
);
1294 Function::arg_iterator I
= Func
->arg_begin();
1295 if (I
== Func
->arg_end())
1300 LLVMValueRef
LLVMGetLastParam(LLVMValueRef Fn
) {
1301 Function
*Func
= unwrap
<Function
>(Fn
);
1302 Function::arg_iterator I
= Func
->arg_end();
1303 if (I
== Func
->arg_begin())
1308 LLVMValueRef
LLVMGetNextParam(LLVMValueRef Arg
) {
1309 Argument
*A
= unwrap
<Argument
>(Arg
);
1310 Function::arg_iterator I
= A
;
1311 if (++I
== A
->getParent()->arg_end())
1316 LLVMValueRef
LLVMGetPreviousParam(LLVMValueRef Arg
) {
1317 Argument
*A
= unwrap
<Argument
>(Arg
);
1318 Function::arg_iterator I
= A
;
1319 if (I
== A
->getParent()->arg_begin())
1324 void LLVMAddAttribute(LLVMValueRef Arg
, LLVMAttribute PA
) {
1325 unwrap
<Argument
>(Arg
)->addAttr(PA
);
1328 void LLVMRemoveAttribute(LLVMValueRef Arg
, LLVMAttribute PA
) {
1329 unwrap
<Argument
>(Arg
)->removeAttr(PA
);
1332 LLVMAttribute
LLVMGetAttribute(LLVMValueRef Arg
) {
1333 Argument
*A
= unwrap
<Argument
>(Arg
);
1334 Attributes attr
= A
->getParent()->getAttributes().getParamAttributes(
1336 return (LLVMAttribute
)attr
;
1340 void LLVMSetParamAlignment(LLVMValueRef Arg
, unsigned align
) {
1341 unwrap
<Argument
>(Arg
)->addAttr(
1342 Attribute::constructAlignmentFromInt(align
));
1345 /*--.. Operations on basic blocks ..........................................--*/
1347 LLVMValueRef
LLVMBasicBlockAsValue(LLVMBasicBlockRef BB
) {
1348 return wrap(static_cast<Value
*>(unwrap(BB
)));
1351 LLVMBool
LLVMValueIsBasicBlock(LLVMValueRef Val
) {
1352 return isa
<BasicBlock
>(unwrap(Val
));
1355 LLVMBasicBlockRef
LLVMValueAsBasicBlock(LLVMValueRef Val
) {
1356 return wrap(unwrap
<BasicBlock
>(Val
));
1359 LLVMValueRef
LLVMGetBasicBlockParent(LLVMBasicBlockRef BB
) {
1360 return wrap(unwrap(BB
)->getParent());
1363 unsigned LLVMCountBasicBlocks(LLVMValueRef FnRef
) {
1364 return unwrap
<Function
>(FnRef
)->size();
1367 void LLVMGetBasicBlocks(LLVMValueRef FnRef
, LLVMBasicBlockRef
*BasicBlocksRefs
){
1368 Function
*Fn
= unwrap
<Function
>(FnRef
);
1369 for (Function::iterator I
= Fn
->begin(), E
= Fn
->end(); I
!= E
; I
++)
1370 *BasicBlocksRefs
++ = wrap(I
);
1373 LLVMBasicBlockRef
LLVMGetEntryBasicBlock(LLVMValueRef Fn
) {
1374 return wrap(&unwrap
<Function
>(Fn
)->getEntryBlock());
1377 LLVMBasicBlockRef
LLVMGetFirstBasicBlock(LLVMValueRef Fn
) {
1378 Function
*Func
= unwrap
<Function
>(Fn
);
1379 Function::iterator I
= Func
->begin();
1380 if (I
== Func
->end())
1385 LLVMBasicBlockRef
LLVMGetLastBasicBlock(LLVMValueRef Fn
) {
1386 Function
*Func
= unwrap
<Function
>(Fn
);
1387 Function::iterator I
= Func
->end();
1388 if (I
== Func
->begin())
1393 LLVMBasicBlockRef
LLVMGetNextBasicBlock(LLVMBasicBlockRef BB
) {
1394 BasicBlock
*Block
= unwrap(BB
);
1395 Function::iterator I
= Block
;
1396 if (++I
== Block
->getParent()->end())
1401 LLVMBasicBlockRef
LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB
) {
1402 BasicBlock
*Block
= unwrap(BB
);
1403 Function::iterator I
= Block
;
1404 if (I
== Block
->getParent()->begin())
1409 LLVMBasicBlockRef
LLVMAppendBasicBlockInContext(LLVMContextRef C
,
1412 return wrap(BasicBlock::Create(*unwrap(C
), Name
, unwrap
<Function
>(FnRef
)));
1415 LLVMBasicBlockRef
LLVMAppendBasicBlock(LLVMValueRef FnRef
, const char *Name
) {
1416 return LLVMAppendBasicBlockInContext(LLVMGetGlobalContext(), FnRef
, Name
);
1419 LLVMBasicBlockRef
LLVMInsertBasicBlockInContext(LLVMContextRef C
,
1420 LLVMBasicBlockRef BBRef
,
1422 BasicBlock
*BB
= unwrap(BBRef
);
1423 return wrap(BasicBlock::Create(*unwrap(C
), Name
, BB
->getParent(), BB
));
1426 LLVMBasicBlockRef
LLVMInsertBasicBlock(LLVMBasicBlockRef BBRef
,
1428 return LLVMInsertBasicBlockInContext(LLVMGetGlobalContext(), BBRef
, Name
);
1431 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BBRef
) {
1432 unwrap(BBRef
)->eraseFromParent();
1435 void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB
, LLVMBasicBlockRef MovePos
) {
1436 unwrap(BB
)->moveBefore(unwrap(MovePos
));
1439 void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB
, LLVMBasicBlockRef MovePos
) {
1440 unwrap(BB
)->moveAfter(unwrap(MovePos
));
1443 /*--.. Operations on instructions ..........................................--*/
1445 LLVMBasicBlockRef
LLVMGetInstructionParent(LLVMValueRef Inst
) {
1446 return wrap(unwrap
<Instruction
>(Inst
)->getParent());
1449 LLVMValueRef
LLVMGetFirstInstruction(LLVMBasicBlockRef BB
) {
1450 BasicBlock
*Block
= unwrap(BB
);
1451 BasicBlock::iterator I
= Block
->begin();
1452 if (I
== Block
->end())
1457 LLVMValueRef
LLVMGetLastInstruction(LLVMBasicBlockRef BB
) {
1458 BasicBlock
*Block
= unwrap(BB
);
1459 BasicBlock::iterator I
= Block
->end();
1460 if (I
== Block
->begin())
1465 LLVMValueRef
LLVMGetNextInstruction(LLVMValueRef Inst
) {
1466 Instruction
*Instr
= unwrap
<Instruction
>(Inst
);
1467 BasicBlock::iterator I
= Instr
;
1468 if (++I
== Instr
->getParent()->end())
1473 LLVMValueRef
LLVMGetPreviousInstruction(LLVMValueRef Inst
) {
1474 Instruction
*Instr
= unwrap
<Instruction
>(Inst
);
1475 BasicBlock::iterator I
= Instr
;
1476 if (I
== Instr
->getParent()->begin())
1481 /*--.. Call and invoke instructions ........................................--*/
1483 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr
) {
1484 Value
*V
= unwrap(Instr
);
1485 if (CallInst
*CI
= dyn_cast
<CallInst
>(V
))
1486 return CI
->getCallingConv();
1487 else if (InvokeInst
*II
= dyn_cast
<InvokeInst
>(V
))
1488 return II
->getCallingConv();
1489 llvm_unreachable("LLVMGetInstructionCallConv applies only to call and invoke!");
1493 void LLVMSetInstructionCallConv(LLVMValueRef Instr
, unsigned CC
) {
1494 Value
*V
= unwrap(Instr
);
1495 if (CallInst
*CI
= dyn_cast
<CallInst
>(V
))
1496 return CI
->setCallingConv(static_cast<CallingConv::ID
>(CC
));
1497 else if (InvokeInst
*II
= dyn_cast
<InvokeInst
>(V
))
1498 return II
->setCallingConv(static_cast<CallingConv::ID
>(CC
));
1499 llvm_unreachable("LLVMSetInstructionCallConv applies only to call and invoke!");
1502 void LLVMAddInstrAttribute(LLVMValueRef Instr
, unsigned index
,
1504 CallSite Call
= CallSite(unwrap
<Instruction
>(Instr
));
1506 Call
.getAttributes().addAttr(index
, PA
));
1509 void LLVMRemoveInstrAttribute(LLVMValueRef Instr
, unsigned index
,
1511 CallSite Call
= CallSite(unwrap
<Instruction
>(Instr
));
1513 Call
.getAttributes().removeAttr(index
, PA
));
1516 void LLVMSetInstrParamAlignment(LLVMValueRef Instr
, unsigned index
,
1518 CallSite Call
= CallSite(unwrap
<Instruction
>(Instr
));
1520 Call
.getAttributes().addAttr(index
,
1521 Attribute::constructAlignmentFromInt(align
)));
1524 /*--.. Operations on call instructions (only) ..............................--*/
1526 LLVMBool
LLVMIsTailCall(LLVMValueRef Call
) {
1527 return unwrap
<CallInst
>(Call
)->isTailCall();
1530 void LLVMSetTailCall(LLVMValueRef Call
, LLVMBool isTailCall
) {
1531 unwrap
<CallInst
>(Call
)->setTailCall(isTailCall
);
1534 /*--.. Operations on phi nodes .............................................--*/
1536 void LLVMAddIncoming(LLVMValueRef PhiNode
, LLVMValueRef
*IncomingValues
,
1537 LLVMBasicBlockRef
*IncomingBlocks
, unsigned Count
) {
1538 PHINode
*PhiVal
= unwrap
<PHINode
>(PhiNode
);
1539 for (unsigned I
= 0; I
!= Count
; ++I
)
1540 PhiVal
->addIncoming(unwrap(IncomingValues
[I
]), unwrap(IncomingBlocks
[I
]));
1543 unsigned LLVMCountIncoming(LLVMValueRef PhiNode
) {
1544 return unwrap
<PHINode
>(PhiNode
)->getNumIncomingValues();
1547 LLVMValueRef
LLVMGetIncomingValue(LLVMValueRef PhiNode
, unsigned Index
) {
1548 return wrap(unwrap
<PHINode
>(PhiNode
)->getIncomingValue(Index
));
1551 LLVMBasicBlockRef
LLVMGetIncomingBlock(LLVMValueRef PhiNode
, unsigned Index
) {
1552 return wrap(unwrap
<PHINode
>(PhiNode
)->getIncomingBlock(Index
));
1556 /*===-- Instruction builders ----------------------------------------------===*/
1558 LLVMBuilderRef
LLVMCreateBuilderInContext(LLVMContextRef C
) {
1559 return wrap(new IRBuilder
<>(*unwrap(C
)));
1562 LLVMBuilderRef
LLVMCreateBuilder(void) {
1563 return LLVMCreateBuilderInContext(LLVMGetGlobalContext());
1566 void LLVMPositionBuilder(LLVMBuilderRef Builder
, LLVMBasicBlockRef Block
,
1567 LLVMValueRef Instr
) {
1568 BasicBlock
*BB
= unwrap(Block
);
1569 Instruction
*I
= Instr
? unwrap
<Instruction
>(Instr
) : (Instruction
*) BB
->end();
1570 unwrap(Builder
)->SetInsertPoint(BB
, I
);
1573 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder
, LLVMValueRef Instr
) {
1574 Instruction
*I
= unwrap
<Instruction
>(Instr
);
1575 unwrap(Builder
)->SetInsertPoint(I
->getParent(), I
);
1578 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder
, LLVMBasicBlockRef Block
) {
1579 BasicBlock
*BB
= unwrap(Block
);
1580 unwrap(Builder
)->SetInsertPoint(BB
);
1583 LLVMBasicBlockRef
LLVMGetInsertBlock(LLVMBuilderRef Builder
) {
1584 return wrap(unwrap(Builder
)->GetInsertBlock());
1587 void LLVMClearInsertionPosition(LLVMBuilderRef Builder
) {
1588 unwrap(Builder
)->ClearInsertionPoint();
1591 void LLVMInsertIntoBuilder(LLVMBuilderRef Builder
, LLVMValueRef Instr
) {
1592 unwrap(Builder
)->Insert(unwrap
<Instruction
>(Instr
));
1595 void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder
, LLVMValueRef Instr
,
1597 unwrap(Builder
)->Insert(unwrap
<Instruction
>(Instr
), Name
);
1600 void LLVMDisposeBuilder(LLVMBuilderRef Builder
) {
1601 delete unwrap(Builder
);
1604 /*--.. Metadata builders ...................................................--*/
1606 void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder
, LLVMValueRef L
) {
1607 MDNode
*Loc
= L
? unwrap
<MDNode
>(L
) : NULL
;
1608 unwrap(Builder
)->SetCurrentDebugLocation(DebugLoc::getFromDILocation(Loc
));
1611 LLVMValueRef
LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder
) {
1612 return wrap(unwrap(Builder
)->getCurrentDebugLocation()
1613 .getAsMDNode(unwrap(Builder
)->getContext()));
1616 void LLVMSetInstDebugLocation(LLVMBuilderRef Builder
, LLVMValueRef Inst
) {
1617 unwrap(Builder
)->SetInstDebugLocation(unwrap
<Instruction
>(Inst
));
1621 /*--.. Instruction builders ................................................--*/
1623 LLVMValueRef
LLVMBuildRetVoid(LLVMBuilderRef B
) {
1624 return wrap(unwrap(B
)->CreateRetVoid());
1627 LLVMValueRef
LLVMBuildRet(LLVMBuilderRef B
, LLVMValueRef V
) {
1628 return wrap(unwrap(B
)->CreateRet(unwrap(V
)));
1631 LLVMValueRef
LLVMBuildAggregateRet(LLVMBuilderRef B
, LLVMValueRef
*RetVals
,
1633 return wrap(unwrap(B
)->CreateAggregateRet(unwrap(RetVals
), N
));
1636 LLVMValueRef
LLVMBuildBr(LLVMBuilderRef B
, LLVMBasicBlockRef Dest
) {
1637 return wrap(unwrap(B
)->CreateBr(unwrap(Dest
)));
1640 LLVMValueRef
LLVMBuildCondBr(LLVMBuilderRef B
, LLVMValueRef If
,
1641 LLVMBasicBlockRef Then
, LLVMBasicBlockRef Else
) {
1642 return wrap(unwrap(B
)->CreateCondBr(unwrap(If
), unwrap(Then
), unwrap(Else
)));
1645 LLVMValueRef
LLVMBuildSwitch(LLVMBuilderRef B
, LLVMValueRef V
,
1646 LLVMBasicBlockRef Else
, unsigned NumCases
) {
1647 return wrap(unwrap(B
)->CreateSwitch(unwrap(V
), unwrap(Else
), NumCases
));
1650 LLVMValueRef
LLVMBuildIndirectBr(LLVMBuilderRef B
, LLVMValueRef Addr
,
1651 unsigned NumDests
) {
1652 return wrap(unwrap(B
)->CreateIndirectBr(unwrap(Addr
), NumDests
));
1655 LLVMValueRef
LLVMBuildInvoke(LLVMBuilderRef B
, LLVMValueRef Fn
,
1656 LLVMValueRef
*Args
, unsigned NumArgs
,
1657 LLVMBasicBlockRef Then
, LLVMBasicBlockRef Catch
,
1659 return wrap(unwrap(B
)->CreateInvoke(unwrap(Fn
), unwrap(Then
), unwrap(Catch
),
1660 unwrap(Args
), unwrap(Args
) + NumArgs
,
1664 LLVMValueRef
LLVMBuildUnwind(LLVMBuilderRef B
) {
1665 return wrap(unwrap(B
)->CreateUnwind());
1668 LLVMValueRef
LLVMBuildUnreachable(LLVMBuilderRef B
) {
1669 return wrap(unwrap(B
)->CreateUnreachable());
1672 void LLVMAddCase(LLVMValueRef Switch
, LLVMValueRef OnVal
,
1673 LLVMBasicBlockRef Dest
) {
1674 unwrap
<SwitchInst
>(Switch
)->addCase(unwrap
<ConstantInt
>(OnVal
), unwrap(Dest
));
1677 void LLVMAddDestination(LLVMValueRef IndirectBr
, LLVMBasicBlockRef Dest
) {
1678 unwrap
<IndirectBrInst
>(IndirectBr
)->addDestination(unwrap(Dest
));
1681 /*--.. Arithmetic ..........................................................--*/
1683 LLVMValueRef
LLVMBuildAdd(LLVMBuilderRef B
, LLVMValueRef LHS
, LLVMValueRef RHS
,
1685 return wrap(unwrap(B
)->CreateAdd(unwrap(LHS
), unwrap(RHS
), Name
));
1688 LLVMValueRef
LLVMBuildNSWAdd(LLVMBuilderRef B
, LLVMValueRef LHS
, LLVMValueRef RHS
,
1690 return wrap(unwrap(B
)->CreateNSWAdd(unwrap(LHS
), unwrap(RHS
), Name
));
1693 LLVMValueRef
LLVMBuildNUWAdd(LLVMBuilderRef B
, LLVMValueRef LHS
, LLVMValueRef RHS
,
1695 return wrap(unwrap(B
)->CreateNUWAdd(unwrap(LHS
), unwrap(RHS
), Name
));
1698 LLVMValueRef
LLVMBuildFAdd(LLVMBuilderRef B
, LLVMValueRef LHS
, LLVMValueRef RHS
,
1700 return wrap(unwrap(B
)->CreateFAdd(unwrap(LHS
), unwrap(RHS
), Name
));
1703 LLVMValueRef
LLVMBuildSub(LLVMBuilderRef B
, LLVMValueRef LHS
, LLVMValueRef RHS
,
1705 return wrap(unwrap(B
)->CreateSub(unwrap(LHS
), unwrap(RHS
), Name
));
1708 LLVMValueRef
LLVMBuildNSWSub(LLVMBuilderRef B
, LLVMValueRef LHS
, LLVMValueRef RHS
,
1710 return wrap(unwrap(B
)->CreateNSWSub(unwrap(LHS
), unwrap(RHS
), Name
));
1713 LLVMValueRef
LLVMBuildNUWSub(LLVMBuilderRef B
, LLVMValueRef LHS
, LLVMValueRef RHS
,
1715 return wrap(unwrap(B
)->CreateNUWSub(unwrap(LHS
), unwrap(RHS
), Name
));
1718 LLVMValueRef
LLVMBuildFSub(LLVMBuilderRef B
, LLVMValueRef LHS
, LLVMValueRef RHS
,
1720 return wrap(unwrap(B
)->CreateFSub(unwrap(LHS
), unwrap(RHS
), Name
));
1723 LLVMValueRef
LLVMBuildMul(LLVMBuilderRef B
, LLVMValueRef LHS
, LLVMValueRef RHS
,
1725 return wrap(unwrap(B
)->CreateMul(unwrap(LHS
), unwrap(RHS
), Name
));
1728 LLVMValueRef
LLVMBuildNSWMul(LLVMBuilderRef B
, LLVMValueRef LHS
, LLVMValueRef RHS
,
1730 return wrap(unwrap(B
)->CreateNSWMul(unwrap(LHS
), unwrap(RHS
), Name
));
1733 LLVMValueRef
LLVMBuildNUWMul(LLVMBuilderRef B
, LLVMValueRef LHS
, LLVMValueRef RHS
,
1735 return wrap(unwrap(B
)->CreateNUWMul(unwrap(LHS
), unwrap(RHS
), Name
));
1738 LLVMValueRef
LLVMBuildFMul(LLVMBuilderRef B
, LLVMValueRef LHS
, LLVMValueRef RHS
,
1740 return wrap(unwrap(B
)->CreateFMul(unwrap(LHS
), unwrap(RHS
), Name
));
1743 LLVMValueRef
LLVMBuildUDiv(LLVMBuilderRef B
, LLVMValueRef LHS
, LLVMValueRef RHS
,
1745 return wrap(unwrap(B
)->CreateUDiv(unwrap(LHS
), unwrap(RHS
), Name
));
1748 LLVMValueRef
LLVMBuildSDiv(LLVMBuilderRef B
, LLVMValueRef LHS
, LLVMValueRef RHS
,
1750 return wrap(unwrap(B
)->CreateSDiv(unwrap(LHS
), unwrap(RHS
), Name
));
1753 LLVMValueRef
LLVMBuildExactSDiv(LLVMBuilderRef B
, LLVMValueRef LHS
,
1754 LLVMValueRef RHS
, const char *Name
) {
1755 return wrap(unwrap(B
)->CreateExactSDiv(unwrap(LHS
), unwrap(RHS
), Name
));
1758 LLVMValueRef
LLVMBuildFDiv(LLVMBuilderRef B
, LLVMValueRef LHS
, LLVMValueRef RHS
,
1760 return wrap(unwrap(B
)->CreateFDiv(unwrap(LHS
), unwrap(RHS
), Name
));
1763 LLVMValueRef
LLVMBuildURem(LLVMBuilderRef B
, LLVMValueRef LHS
, LLVMValueRef RHS
,
1765 return wrap(unwrap(B
)->CreateURem(unwrap(LHS
), unwrap(RHS
), Name
));
1768 LLVMValueRef
LLVMBuildSRem(LLVMBuilderRef B
, LLVMValueRef LHS
, LLVMValueRef RHS
,
1770 return wrap(unwrap(B
)->CreateSRem(unwrap(LHS
), unwrap(RHS
), Name
));
1773 LLVMValueRef
LLVMBuildFRem(LLVMBuilderRef B
, LLVMValueRef LHS
, LLVMValueRef RHS
,
1775 return wrap(unwrap(B
)->CreateFRem(unwrap(LHS
), unwrap(RHS
), Name
));
1778 LLVMValueRef
LLVMBuildShl(LLVMBuilderRef B
, LLVMValueRef LHS
, LLVMValueRef RHS
,
1780 return wrap(unwrap(B
)->CreateShl(unwrap(LHS
), unwrap(RHS
), Name
));
1783 LLVMValueRef
LLVMBuildLShr(LLVMBuilderRef B
, LLVMValueRef LHS
, LLVMValueRef RHS
,
1785 return wrap(unwrap(B
)->CreateLShr(unwrap(LHS
), unwrap(RHS
), Name
));
1788 LLVMValueRef
LLVMBuildAShr(LLVMBuilderRef B
, LLVMValueRef LHS
, LLVMValueRef RHS
,
1790 return wrap(unwrap(B
)->CreateAShr(unwrap(LHS
), unwrap(RHS
), Name
));
1793 LLVMValueRef
LLVMBuildAnd(LLVMBuilderRef B
, LLVMValueRef LHS
, LLVMValueRef RHS
,
1795 return wrap(unwrap(B
)->CreateAnd(unwrap(LHS
), unwrap(RHS
), Name
));
1798 LLVMValueRef
LLVMBuildOr(LLVMBuilderRef B
, LLVMValueRef LHS
, LLVMValueRef RHS
,
1800 return wrap(unwrap(B
)->CreateOr(unwrap(LHS
), unwrap(RHS
), Name
));
1803 LLVMValueRef
LLVMBuildXor(LLVMBuilderRef B
, LLVMValueRef LHS
, LLVMValueRef RHS
,
1805 return wrap(unwrap(B
)->CreateXor(unwrap(LHS
), unwrap(RHS
), Name
));
1808 LLVMValueRef
LLVMBuildBinOp(LLVMBuilderRef B
, LLVMOpcode Op
,
1809 LLVMValueRef LHS
, LLVMValueRef RHS
,
1811 return wrap(unwrap(B
)->CreateBinOp(Instruction::BinaryOps(Op
), unwrap(LHS
),
1812 unwrap(RHS
), Name
));
1815 LLVMValueRef
LLVMBuildNeg(LLVMBuilderRef B
, LLVMValueRef V
, const char *Name
) {
1816 return wrap(unwrap(B
)->CreateNeg(unwrap(V
), Name
));
1819 LLVMValueRef
LLVMBuildNSWNeg(LLVMBuilderRef B
, LLVMValueRef V
,
1821 return wrap(unwrap(B
)->CreateNSWNeg(unwrap(V
), Name
));
1824 LLVMValueRef
LLVMBuildNUWNeg(LLVMBuilderRef B
, LLVMValueRef V
,
1826 return wrap(unwrap(B
)->CreateNUWNeg(unwrap(V
), Name
));
1829 LLVMValueRef
LLVMBuildFNeg(LLVMBuilderRef B
, LLVMValueRef V
, const char *Name
) {
1830 return wrap(unwrap(B
)->CreateFNeg(unwrap(V
), Name
));
1833 LLVMValueRef
LLVMBuildNot(LLVMBuilderRef B
, LLVMValueRef V
, const char *Name
) {
1834 return wrap(unwrap(B
)->CreateNot(unwrap(V
), Name
));
1837 /*--.. Memory ..............................................................--*/
1839 LLVMValueRef
LLVMBuildMalloc(LLVMBuilderRef B
, LLVMTypeRef Ty
,
1841 const Type
* ITy
= Type::getInt32Ty(unwrap(B
)->GetInsertBlock()->getContext());
1842 Constant
* AllocSize
= ConstantExpr::getSizeOf(unwrap(Ty
));
1843 AllocSize
= ConstantExpr::getTruncOrBitCast(AllocSize
, ITy
);
1844 Instruction
* Malloc
= CallInst::CreateMalloc(unwrap(B
)->GetInsertBlock(),
1845 ITy
, unwrap(Ty
), AllocSize
,
1847 return wrap(unwrap(B
)->Insert(Malloc
, Twine(Name
)));
1850 LLVMValueRef
LLVMBuildArrayMalloc(LLVMBuilderRef B
, LLVMTypeRef Ty
,
1851 LLVMValueRef Val
, const char *Name
) {
1852 const Type
* ITy
= Type::getInt32Ty(unwrap(B
)->GetInsertBlock()->getContext());
1853 Constant
* AllocSize
= ConstantExpr::getSizeOf(unwrap(Ty
));
1854 AllocSize
= ConstantExpr::getTruncOrBitCast(AllocSize
, ITy
);
1855 Instruction
* Malloc
= CallInst::CreateMalloc(unwrap(B
)->GetInsertBlock(),
1856 ITy
, unwrap(Ty
), AllocSize
,
1857 unwrap(Val
), 0, "");
1858 return wrap(unwrap(B
)->Insert(Malloc
, Twine(Name
)));
1861 LLVMValueRef
LLVMBuildAlloca(LLVMBuilderRef B
, LLVMTypeRef Ty
,
1863 return wrap(unwrap(B
)->CreateAlloca(unwrap(Ty
), 0, Name
));
1866 LLVMValueRef
LLVMBuildArrayAlloca(LLVMBuilderRef B
, LLVMTypeRef Ty
,
1867 LLVMValueRef Val
, const char *Name
) {
1868 return wrap(unwrap(B
)->CreateAlloca(unwrap(Ty
), unwrap(Val
), Name
));
1871 LLVMValueRef
LLVMBuildFree(LLVMBuilderRef B
, LLVMValueRef PointerVal
) {
1872 return wrap(unwrap(B
)->Insert(
1873 CallInst::CreateFree(unwrap(PointerVal
), unwrap(B
)->GetInsertBlock())));
1877 LLVMValueRef
LLVMBuildLoad(LLVMBuilderRef B
, LLVMValueRef PointerVal
,
1879 return wrap(unwrap(B
)->CreateLoad(unwrap(PointerVal
), Name
));
1882 LLVMValueRef
LLVMBuildStore(LLVMBuilderRef B
, LLVMValueRef Val
,
1883 LLVMValueRef PointerVal
) {
1884 return wrap(unwrap(B
)->CreateStore(unwrap(Val
), unwrap(PointerVal
)));
1887 LLVMValueRef
LLVMBuildGEP(LLVMBuilderRef B
, LLVMValueRef Pointer
,
1888 LLVMValueRef
*Indices
, unsigned NumIndices
,
1890 return wrap(unwrap(B
)->CreateGEP(unwrap(Pointer
), unwrap(Indices
),
1891 unwrap(Indices
) + NumIndices
, Name
));
1894 LLVMValueRef
LLVMBuildInBoundsGEP(LLVMBuilderRef B
, LLVMValueRef Pointer
,
1895 LLVMValueRef
*Indices
, unsigned NumIndices
,
1897 return wrap(unwrap(B
)->CreateInBoundsGEP(unwrap(Pointer
), unwrap(Indices
),
1898 unwrap(Indices
) + NumIndices
, Name
));
1901 LLVMValueRef
LLVMBuildStructGEP(LLVMBuilderRef B
, LLVMValueRef Pointer
,
1902 unsigned Idx
, const char *Name
) {
1903 return wrap(unwrap(B
)->CreateStructGEP(unwrap(Pointer
), Idx
, Name
));
1906 LLVMValueRef
LLVMBuildGlobalString(LLVMBuilderRef B
, const char *Str
,
1908 return wrap(unwrap(B
)->CreateGlobalString(Str
, Name
));
1911 LLVMValueRef
LLVMBuildGlobalStringPtr(LLVMBuilderRef B
, const char *Str
,
1913 return wrap(unwrap(B
)->CreateGlobalStringPtr(Str
, Name
));
1916 /*--.. Casts ...............................................................--*/
1918 LLVMValueRef
LLVMBuildTrunc(LLVMBuilderRef B
, LLVMValueRef Val
,
1919 LLVMTypeRef DestTy
, const char *Name
) {
1920 return wrap(unwrap(B
)->CreateTrunc(unwrap(Val
), unwrap(DestTy
), Name
));
1923 LLVMValueRef
LLVMBuildZExt(LLVMBuilderRef B
, LLVMValueRef Val
,
1924 LLVMTypeRef DestTy
, const char *Name
) {
1925 return wrap(unwrap(B
)->CreateZExt(unwrap(Val
), unwrap(DestTy
), Name
));
1928 LLVMValueRef
LLVMBuildSExt(LLVMBuilderRef B
, LLVMValueRef Val
,
1929 LLVMTypeRef DestTy
, const char *Name
) {
1930 return wrap(unwrap(B
)->CreateSExt(unwrap(Val
), unwrap(DestTy
), Name
));
1933 LLVMValueRef
LLVMBuildFPToUI(LLVMBuilderRef B
, LLVMValueRef Val
,
1934 LLVMTypeRef DestTy
, const char *Name
) {
1935 return wrap(unwrap(B
)->CreateFPToUI(unwrap(Val
), unwrap(DestTy
), Name
));
1938 LLVMValueRef
LLVMBuildFPToSI(LLVMBuilderRef B
, LLVMValueRef Val
,
1939 LLVMTypeRef DestTy
, const char *Name
) {
1940 return wrap(unwrap(B
)->CreateFPToSI(unwrap(Val
), unwrap(DestTy
), Name
));
1943 LLVMValueRef
LLVMBuildUIToFP(LLVMBuilderRef B
, LLVMValueRef Val
,
1944 LLVMTypeRef DestTy
, const char *Name
) {
1945 return wrap(unwrap(B
)->CreateUIToFP(unwrap(Val
), unwrap(DestTy
), Name
));
1948 LLVMValueRef
LLVMBuildSIToFP(LLVMBuilderRef B
, LLVMValueRef Val
,
1949 LLVMTypeRef DestTy
, const char *Name
) {
1950 return wrap(unwrap(B
)->CreateSIToFP(unwrap(Val
), unwrap(DestTy
), Name
));
1953 LLVMValueRef
LLVMBuildFPTrunc(LLVMBuilderRef B
, LLVMValueRef Val
,
1954 LLVMTypeRef DestTy
, const char *Name
) {
1955 return wrap(unwrap(B
)->CreateFPTrunc(unwrap(Val
), unwrap(DestTy
), Name
));
1958 LLVMValueRef
LLVMBuildFPExt(LLVMBuilderRef B
, LLVMValueRef Val
,
1959 LLVMTypeRef DestTy
, const char *Name
) {
1960 return wrap(unwrap(B
)->CreateFPExt(unwrap(Val
), unwrap(DestTy
), Name
));
1963 LLVMValueRef
LLVMBuildPtrToInt(LLVMBuilderRef B
, LLVMValueRef Val
,
1964 LLVMTypeRef DestTy
, const char *Name
) {
1965 return wrap(unwrap(B
)->CreatePtrToInt(unwrap(Val
), unwrap(DestTy
), Name
));
1968 LLVMValueRef
LLVMBuildIntToPtr(LLVMBuilderRef B
, LLVMValueRef Val
,
1969 LLVMTypeRef DestTy
, const char *Name
) {
1970 return wrap(unwrap(B
)->CreateIntToPtr(unwrap(Val
), unwrap(DestTy
), Name
));
1973 LLVMValueRef
LLVMBuildBitCast(LLVMBuilderRef B
, LLVMValueRef Val
,
1974 LLVMTypeRef DestTy
, const char *Name
) {
1975 return wrap(unwrap(B
)->CreateBitCast(unwrap(Val
), unwrap(DestTy
), Name
));
1978 LLVMValueRef
LLVMBuildZExtOrBitCast(LLVMBuilderRef B
, LLVMValueRef Val
,
1979 LLVMTypeRef DestTy
, const char *Name
) {
1980 return wrap(unwrap(B
)->CreateZExtOrBitCast(unwrap(Val
), unwrap(DestTy
),
1984 LLVMValueRef
LLVMBuildSExtOrBitCast(LLVMBuilderRef B
, LLVMValueRef Val
,
1985 LLVMTypeRef DestTy
, const char *Name
) {
1986 return wrap(unwrap(B
)->CreateSExtOrBitCast(unwrap(Val
), unwrap(DestTy
),
1990 LLVMValueRef
LLVMBuildTruncOrBitCast(LLVMBuilderRef B
, LLVMValueRef Val
,
1991 LLVMTypeRef DestTy
, const char *Name
) {
1992 return wrap(unwrap(B
)->CreateTruncOrBitCast(unwrap(Val
), unwrap(DestTy
),
1996 LLVMValueRef
LLVMBuildCast(LLVMBuilderRef B
, LLVMOpcode Op
, LLVMValueRef Val
,
1997 LLVMTypeRef DestTy
, const char *Name
) {
1998 return wrap(unwrap(B
)->CreateCast(Instruction::CastOps(Op
), unwrap(Val
),
1999 unwrap(DestTy
), Name
));
2002 LLVMValueRef
LLVMBuildPointerCast(LLVMBuilderRef B
, LLVMValueRef Val
,
2003 LLVMTypeRef DestTy
, const char *Name
) {
2004 return wrap(unwrap(B
)->CreatePointerCast(unwrap(Val
), unwrap(DestTy
), Name
));
2007 LLVMValueRef
LLVMBuildIntCast(LLVMBuilderRef B
, LLVMValueRef Val
,
2008 LLVMTypeRef DestTy
, const char *Name
) {
2009 return wrap(unwrap(B
)->CreateIntCast(unwrap(Val
), unwrap(DestTy
),
2010 /*isSigned*/true, Name
));
2013 LLVMValueRef
LLVMBuildFPCast(LLVMBuilderRef B
, LLVMValueRef Val
,
2014 LLVMTypeRef DestTy
, const char *Name
) {
2015 return wrap(unwrap(B
)->CreateFPCast(unwrap(Val
), unwrap(DestTy
), Name
));
2018 /*--.. Comparisons .........................................................--*/
2020 LLVMValueRef
LLVMBuildICmp(LLVMBuilderRef B
, LLVMIntPredicate Op
,
2021 LLVMValueRef LHS
, LLVMValueRef RHS
,
2023 return wrap(unwrap(B
)->CreateICmp(static_cast<ICmpInst::Predicate
>(Op
),
2024 unwrap(LHS
), unwrap(RHS
), Name
));
2027 LLVMValueRef
LLVMBuildFCmp(LLVMBuilderRef B
, LLVMRealPredicate Op
,
2028 LLVMValueRef LHS
, LLVMValueRef RHS
,
2030 return wrap(unwrap(B
)->CreateFCmp(static_cast<FCmpInst::Predicate
>(Op
),
2031 unwrap(LHS
), unwrap(RHS
), Name
));
2034 /*--.. Miscellaneous instructions ..........................................--*/
2036 LLVMValueRef
LLVMBuildPhi(LLVMBuilderRef B
, LLVMTypeRef Ty
, const char *Name
) {
2037 return wrap(unwrap(B
)->CreatePHI(unwrap(Ty
), 0, Name
));
2040 LLVMValueRef
LLVMBuildCall(LLVMBuilderRef B
, LLVMValueRef Fn
,
2041 LLVMValueRef
*Args
, unsigned NumArgs
,
2043 return wrap(unwrap(B
)->CreateCall(unwrap(Fn
), unwrap(Args
),
2044 unwrap(Args
) + NumArgs
, Name
));
2047 LLVMValueRef
LLVMBuildSelect(LLVMBuilderRef B
, LLVMValueRef If
,
2048 LLVMValueRef Then
, LLVMValueRef Else
,
2050 return wrap(unwrap(B
)->CreateSelect(unwrap(If
), unwrap(Then
), unwrap(Else
),
2054 LLVMValueRef
LLVMBuildVAArg(LLVMBuilderRef B
, LLVMValueRef List
,
2055 LLVMTypeRef Ty
, const char *Name
) {
2056 return wrap(unwrap(B
)->CreateVAArg(unwrap(List
), unwrap(Ty
), Name
));
2059 LLVMValueRef
LLVMBuildExtractElement(LLVMBuilderRef B
, LLVMValueRef VecVal
,
2060 LLVMValueRef Index
, const char *Name
) {
2061 return wrap(unwrap(B
)->CreateExtractElement(unwrap(VecVal
), unwrap(Index
),
2065 LLVMValueRef
LLVMBuildInsertElement(LLVMBuilderRef B
, LLVMValueRef VecVal
,
2066 LLVMValueRef EltVal
, LLVMValueRef Index
,
2068 return wrap(unwrap(B
)->CreateInsertElement(unwrap(VecVal
), unwrap(EltVal
),
2069 unwrap(Index
), Name
));
2072 LLVMValueRef
LLVMBuildShuffleVector(LLVMBuilderRef B
, LLVMValueRef V1
,
2073 LLVMValueRef V2
, LLVMValueRef Mask
,
2075 return wrap(unwrap(B
)->CreateShuffleVector(unwrap(V1
), unwrap(V2
),
2076 unwrap(Mask
), Name
));
2079 LLVMValueRef
LLVMBuildExtractValue(LLVMBuilderRef B
, LLVMValueRef AggVal
,
2080 unsigned Index
, const char *Name
) {
2081 return wrap(unwrap(B
)->CreateExtractValue(unwrap(AggVal
), Index
, Name
));
2084 LLVMValueRef
LLVMBuildInsertValue(LLVMBuilderRef B
, LLVMValueRef AggVal
,
2085 LLVMValueRef EltVal
, unsigned Index
,
2087 return wrap(unwrap(B
)->CreateInsertValue(unwrap(AggVal
), unwrap(EltVal
),
2091 LLVMValueRef
LLVMBuildIsNull(LLVMBuilderRef B
, LLVMValueRef Val
,
2093 return wrap(unwrap(B
)->CreateIsNull(unwrap(Val
), Name
));
2096 LLVMValueRef
LLVMBuildIsNotNull(LLVMBuilderRef B
, LLVMValueRef Val
,
2098 return wrap(unwrap(B
)->CreateIsNotNull(unwrap(Val
), Name
));
2101 LLVMValueRef
LLVMBuildPtrDiff(LLVMBuilderRef B
, LLVMValueRef LHS
,
2102 LLVMValueRef RHS
, const char *Name
) {
2103 return wrap(unwrap(B
)->CreatePtrDiff(unwrap(LHS
), unwrap(RHS
), Name
));
2107 /*===-- Module providers --------------------------------------------------===*/
2109 LLVMModuleProviderRef
2110 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M
) {
2111 return reinterpret_cast<LLVMModuleProviderRef
>(M
);
2114 void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP
) {
2119 /*===-- Memory buffers ----------------------------------------------------===*/
2121 LLVMBool
LLVMCreateMemoryBufferWithContentsOfFile(
2123 LLVMMemoryBufferRef
*OutMemBuf
,
2124 char **OutMessage
) {
2126 OwningPtr
<MemoryBuffer
> MB
;
2128 if (!(ec
= MemoryBuffer::getFile(Path
, MB
))) {
2129 *OutMemBuf
= wrap(MB
.take());
2133 *OutMessage
= strdup(ec
.message().c_str());
2137 LLVMBool
LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef
*OutMemBuf
,
2138 char **OutMessage
) {
2139 OwningPtr
<MemoryBuffer
> MB
;
2141 if (!(ec
= MemoryBuffer::getSTDIN(MB
))) {
2142 *OutMemBuf
= wrap(MB
.take());
2146 *OutMessage
= strdup(ec
.message().c_str());
2150 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf
) {
2151 delete unwrap(MemBuf
);
2154 /*===-- Pass Registry -----------------------------------------------------===*/
2156 LLVMPassRegistryRef
LLVMGetGlobalPassRegistry(void) {
2157 return wrap(PassRegistry::getPassRegistry());
2160 /*===-- Pass Manager ------------------------------------------------------===*/
2162 LLVMPassManagerRef
LLVMCreatePassManager() {
2163 return wrap(new PassManager());
2166 LLVMPassManagerRef
LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M
) {
2167 return wrap(new FunctionPassManager(unwrap(M
)));
2170 LLVMPassManagerRef
LLVMCreateFunctionPassManager(LLVMModuleProviderRef P
) {
2171 return LLVMCreateFunctionPassManagerForModule(
2172 reinterpret_cast<LLVMModuleRef
>(P
));
2175 LLVMBool
LLVMRunPassManager(LLVMPassManagerRef PM
, LLVMModuleRef M
) {
2176 return unwrap
<PassManager
>(PM
)->run(*unwrap(M
));
2179 LLVMBool
LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM
) {
2180 return unwrap
<FunctionPassManager
>(FPM
)->doInitialization();
2183 LLVMBool
LLVMRunFunctionPassManager(LLVMPassManagerRef FPM
, LLVMValueRef F
) {
2184 return unwrap
<FunctionPassManager
>(FPM
)->run(*unwrap
<Function
>(F
));
2187 LLVMBool
LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM
) {
2188 return unwrap
<FunctionPassManager
>(FPM
)->doFinalization();
2191 void LLVMDisposePassManager(LLVMPassManagerRef PM
) {