1 /*===-- llvm-c/Core.h - Core Library C Interface ------------------*- C -*-===*\ 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 header declares the C interface to libLLVMCore.a, which implements *| 11 |* the LLVM intermediate representation. *| 12 |* *| 13 |* LLVM uses a polymorphic type hierarchy which C cannot represent, therefore *| 14 |* parameters must be passed as base types. Despite the declared types, most *| 15 |* of the functions provided operate only on branches of the type hierarchy. *| 16 |* The declared parameter names are descriptive and specify which type is *| 17 |* required. Additionally, each type hierarchy is documented along with the *| 18 |* functions that operate upon it. For more detail, refer to LLVM's C++ code. *| 19 |* If in doubt, refer to Core.cpp, which performs paramter downcasts in the *| 20 |* form unwrap<RequiredType>(Param). *| 21 |* *| 22 |* Many exotic languages can interoperate with C code but have a harder time *| 23 |* with C++ due to name mangling. So in addition to C, this interface enables *| 24 |* tools written in such languages. *| 25 |* *| 26 |* When included into a C++ source file, also declares 'wrap' and 'unwrap' *| 27 |* helpers to perform opaque reference<-->pointer conversions. These helpers *| 28 |* are shorter and more tightly typed than writing the casts by hand when *| 29 |* authoring bindings. In assert builds, they will do runtime type checking. *| 30 |* *| 31 \*===----------------------------------------------------------------------===*/ 32 33 #ifndef LLVM_C_CORE_H 34 #define LLVM_C_CORE_H 35 36 #include "llvm/Support/DataTypes.h" 37 38 #ifdef __cplusplus 39 40 /* Need these includes to support the LLVM 'cast' template for the C++ 'wrap' 41 and 'unwrap' conversion functions. */ 42 #include "llvm/Module.h" 43 #include "llvm/PassRegistry.h" 44 #include "llvm/Support/IRBuilder.h" 45 46 extern "C" { 47 #endif 48 49 50 typedef int LLVMBool; 51 52 /* Opaque types. */ 53 54 /** 55 * The top-level container for all LLVM global data. See the LLVMContext class. 56 */ 57 typedef struct LLVMOpaqueContext *LLVMContextRef; 58 59 /** 60 * The top-level container for all other LLVM Intermediate Representation (IR) 61 * objects. See the llvm::Module class. 62 */ 63 typedef struct LLVMOpaqueModule *LLVMModuleRef; 64 65 /** 66 * Each value in the LLVM IR has a type, an LLVMTypeRef. See the llvm::Type 67 * class. 68 */ 69 typedef struct LLVMOpaqueType *LLVMTypeRef; 70 71 typedef struct LLVMOpaqueValue *LLVMValueRef; 72 typedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef; 73 typedef struct LLVMOpaqueBuilder *LLVMBuilderRef; 74 75 /* Interface used to provide a module to JIT or interpreter. This is now just a 76 * synonym for llvm::Module, but we have to keep using the different type to 77 * keep binary compatibility. 78 */ 79 typedef struct LLVMOpaqueModuleProvider *LLVMModuleProviderRef; 80 81 /* Used to provide a module to JIT or interpreter. 82 * See the llvm::MemoryBuffer class. 83 */ 84 typedef struct LLVMOpaqueMemoryBuffer *LLVMMemoryBufferRef; 85 86 /** See the llvm::PassManagerBase class. */ 87 typedef struct LLVMOpaquePassManager *LLVMPassManagerRef; 88 89 /** See the llvm::PassRegistry class. */ 90 typedef struct LLVMOpaquePassRegistry *LLVMPassRegistryRef; 91 92 /** Used to get the users and usees of a Value. See the llvm::Use class. */ 93 typedef struct LLVMOpaqueUse *LLVMUseRef; 94 95 typedef enum { 96 LLVMZExtAttribute = 1<<0, 97 LLVMSExtAttribute = 1<<1, 98 LLVMNoReturnAttribute = 1<<2, 99 LLVMInRegAttribute = 1<<3, 100 LLVMStructRetAttribute = 1<<4, 101 LLVMNoUnwindAttribute = 1<<5, 102 LLVMNoAliasAttribute = 1<<6, 103 LLVMByValAttribute = 1<<7, 104 LLVMNestAttribute = 1<<8, 105 LLVMReadNoneAttribute = 1<<9, 106 LLVMReadOnlyAttribute = 1<<10, 107 LLVMNoInlineAttribute = 1<<11, 108 LLVMAlwaysInlineAttribute = 1<<12, 109 LLVMOptimizeForSizeAttribute = 1<<13, 110 LLVMStackProtectAttribute = 1<<14, 111 LLVMStackProtectReqAttribute = 1<<15, 112 LLVMAlignment = 31<<16, 113 LLVMNoCaptureAttribute = 1<<21, 114 LLVMNoRedZoneAttribute = 1<<22, 115 LLVMNoImplicitFloatAttribute = 1<<23, 116 LLVMNakedAttribute = 1<<24, 117 LLVMInlineHintAttribute = 1<<25, 118 LLVMStackAlignment = 7<<26 119 } LLVMAttribute; 120 121 typedef enum { 122 /* Terminator Instructions */ 123 LLVMRet = 1, 124 LLVMBr = 2, 125 LLVMSwitch = 3, 126 LLVMIndirectBr = 4, 127 LLVMInvoke = 5, 128 LLVMUnwind = 6, 129 LLVMUnreachable = 7, 130 131 /* Standard Binary Operators */ 132 LLVMAdd = 8, 133 LLVMFAdd = 9, 134 LLVMSub = 10, 135 LLVMFSub = 11, 136 LLVMMul = 12, 137 LLVMFMul = 13, 138 LLVMUDiv = 14, 139 LLVMSDiv = 15, 140 LLVMFDiv = 16, 141 LLVMURem = 17, 142 LLVMSRem = 18, 143 LLVMFRem = 19, 144 145 /* Logical Operators */ 146 LLVMShl = 20, 147 LLVMLShr = 21, 148 LLVMAShr = 22, 149 LLVMAnd = 23, 150 LLVMOr = 24, 151 LLVMXor = 25, 152 153 /* Memory Operators */ 154 LLVMAlloca = 26, 155 LLVMLoad = 27, 156 LLVMStore = 28, 157 LLVMGetElementPtr = 29, 158 159 /* Cast Operators */ 160 LLVMTrunc = 30, 161 LLVMZExt = 31, 162 LLVMSExt = 32, 163 LLVMFPToUI = 33, 164 LLVMFPToSI = 34, 165 LLVMUIToFP = 35, 166 LLVMSIToFP = 36, 167 LLVMFPTrunc = 37, 168 LLVMFPExt = 38, 169 LLVMPtrToInt = 39, 170 LLVMIntToPtr = 40, 171 LLVMBitCast = 41, 172 173 /* Other Operators */ 174 LLVMICmp = 42, 175 LLVMFCmp = 43, 176 LLVMPHI = 44, 177 LLVMCall = 45, 178 LLVMSelect = 46, 179 /* UserOp1 */ 180 /* UserOp2 */ 181 LLVMVAArg = 49, 182 LLVMExtractElement = 50, 183 LLVMInsertElement = 51, 184 LLVMShuffleVector = 52, 185 LLVMExtractValue = 53, 186 LLVMInsertValue = 54 187 } LLVMOpcode; 188 189 typedef enum { 190 LLVMVoidTypeKind, /**< type with no size */ 191 LLVMFloatTypeKind, /**< 32 bit floating point type */ 192 LLVMDoubleTypeKind, /**< 64 bit floating point type */ 193 LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */ 194 LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/ 195 LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */ 196 LLVMLabelTypeKind, /**< Labels */ 197 LLVMIntegerTypeKind, /**< Arbitrary bit width integers */ 198 LLVMFunctionTypeKind, /**< Functions */ 199 LLVMStructTypeKind, /**< Structures */ 200 LLVMArrayTypeKind, /**< Arrays */ 201 LLVMPointerTypeKind, /**< Pointers */ 202 LLVMVectorTypeKind, /**< SIMD 'packed' format, or other vector type */ 203 LLVMMetadataTypeKind, /**< Metadata */ 204 LLVMX86_MMXTypeKind /**< X86 MMX */ 205 } LLVMTypeKind; 206 207 typedef enum { 208 LLVMExternalLinkage, /**< Externally visible function */ 209 LLVMAvailableExternallyLinkage, 210 LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/ 211 LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something 212 equivalent. */ 213 LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */ 214 LLVMWeakODRLinkage, /**< Same, but only replaced by something 215 equivalent. */ 216 LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */ 217 LLVMInternalLinkage, /**< Rename collisions when linking (static 218 functions) */ 219 LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */ 220 LLVMDLLImportLinkage, /**< Function to be imported from DLL */ 221 LLVMDLLExportLinkage, /**< Function to be accessible from DLL */ 222 LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */ 223 LLVMGhostLinkage, /**< Obsolete */ 224 LLVMCommonLinkage, /**< Tentative definitions */ 225 LLVMLinkerPrivateLinkage, /**< Like Private, but linker removes. */ 226 LLVMLinkerPrivateWeakLinkage, /**< Like LinkerPrivate, but is weak. */ 227 LLVMLinkerPrivateWeakDefAutoLinkage /**< Like LinkerPrivateWeak, but possibly 228 hidden. */ 229 } LLVMLinkage; 230 231 typedef enum { 232 LLVMDefaultVisibility, /**< The GV is visible */ 233 LLVMHiddenVisibility, /**< The GV is hidden */ 234 LLVMProtectedVisibility /**< The GV is protected */ 235 } LLVMVisibility; 236 237 typedef enum { 238 LLVMCCallConv = 0, 239 LLVMFastCallConv = 8, 240 LLVMColdCallConv = 9, 241 LLVMX86StdcallCallConv = 64, 242 LLVMX86FastcallCallConv = 65 243 } LLVMCallConv; 244 245 typedef enum { 246 LLVMIntEQ = 32, /**< equal */ 247 LLVMIntNE, /**< not equal */ 248 LLVMIntUGT, /**< unsigned greater than */ 249 LLVMIntUGE, /**< unsigned greater or equal */ 250 LLVMIntULT, /**< unsigned less than */ 251 LLVMIntULE, /**< unsigned less or equal */ 252 LLVMIntSGT, /**< signed greater than */ 253 LLVMIntSGE, /**< signed greater or equal */ 254 LLVMIntSLT, /**< signed less than */ 255 LLVMIntSLE /**< signed less or equal */ 256 } LLVMIntPredicate; 257 258 typedef enum { 259 LLVMRealPredicateFalse, /**< Always false (always folded) */ 260 LLVMRealOEQ, /**< True if ordered and equal */ 261 LLVMRealOGT, /**< True if ordered and greater than */ 262 LLVMRealOGE, /**< True if ordered and greater than or equal */ 263 LLVMRealOLT, /**< True if ordered and less than */ 264 LLVMRealOLE, /**< True if ordered and less than or equal */ 265 LLVMRealONE, /**< True if ordered and operands are unequal */ 266 LLVMRealORD, /**< True if ordered (no nans) */ 267 LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */ 268 LLVMRealUEQ, /**< True if unordered or equal */ 269 LLVMRealUGT, /**< True if unordered or greater than */ 270 LLVMRealUGE, /**< True if unordered, greater than, or equal */ 271 LLVMRealULT, /**< True if unordered or less than */ 272 LLVMRealULE, /**< True if unordered, less than, or equal */ 273 LLVMRealUNE, /**< True if unordered or not equal */ 274 LLVMRealPredicateTrue /**< Always true (always folded) */ 275 } LLVMRealPredicate; 276 277 void LLVMInitializeCore(LLVMPassRegistryRef R); 278 279 280 /*===-- Error handling ----------------------------------------------------===*/ 281 282 void LLVMDisposeMessage(char *Message); 283 284 285 /*===-- Contexts ----------------------------------------------------------===*/ 286 287 /* Create and destroy contexts. */ 288 LLVMContextRef LLVMContextCreate(void); 289 LLVMContextRef LLVMGetGlobalContext(void); 290 void LLVMContextDispose(LLVMContextRef C); 291 292 unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char* Name, 293 unsigned SLen); 294 unsigned LLVMGetMDKindID(const char* Name, unsigned SLen); 295 296 /*===-- Modules -----------------------------------------------------------===*/ 297 298 /* Create and destroy modules. */ 299 /** See llvm::Module::Module. */ 300 LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID); 301 LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID, 302 LLVMContextRef C); 303 304 /** See llvm::Module::~Module. */ 305 void LLVMDisposeModule(LLVMModuleRef M); 306 307 /** Data layout. See Module::getDataLayout. */ 308 const char *LLVMGetDataLayout(LLVMModuleRef M); 309 void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple); 310 311 /** Target triple. See Module::getTargetTriple. */ 312 const char *LLVMGetTarget(LLVMModuleRef M); 313 void LLVMSetTarget(LLVMModuleRef M, const char *Triple); 314 315 /** See Module::dump. */ 316 void LLVMDumpModule(LLVMModuleRef M); 317 318 /** See Module::setModuleInlineAsm. */ 319 void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm); 320 321 /** See Module::getContext. */ 322 LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M); 323 324 /*===-- Types -------------------------------------------------------------===*/ 325 326 /* LLVM types conform to the following hierarchy: 327 * 328 * types: 329 * integer type 330 * real type 331 * function type 332 * sequence types: 333 * array type 334 * pointer type 335 * vector type 336 * void type 337 * label type 338 * opaque type 339 */ 340 341 /** See llvm::LLVMTypeKind::getTypeID. */ 342 LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty); 343 344 /** See llvm::LLVMType::getContext. */ 345 LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty); 346 347 /* Operations on integer types */ 348 LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C); 349 LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C); 350 LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C); 351 LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C); 352 LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C); 353 LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits); 354 355 LLVMTypeRef LLVMInt1Type(void); 356 LLVMTypeRef LLVMInt8Type(void); 357 LLVMTypeRef LLVMInt16Type(void); 358 LLVMTypeRef LLVMInt32Type(void); 359 LLVMTypeRef LLVMInt64Type(void); 360 LLVMTypeRef LLVMIntType(unsigned NumBits); 361 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy); 362 363 /* Operations on real types */ 364 LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C); 365 LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C); 366 LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C); 367 LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C); 368 LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C); 369 370 LLVMTypeRef LLVMFloatType(void); 371 LLVMTypeRef LLVMDoubleType(void); 372 LLVMTypeRef LLVMX86FP80Type(void); 373 LLVMTypeRef LLVMFP128Type(void); 374 LLVMTypeRef LLVMPPCFP128Type(void); 375 376 /* Operations on function types */ 377 LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType, 378 LLVMTypeRef *ParamTypes, unsigned ParamCount, 379 LLVMBool IsVarArg); 380 LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy); 381 LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy); 382 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy); 383 void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest); 384 385 /* Operations on struct types */ 386 LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes, 387 unsigned ElementCount, LLVMBool Packed); 388 LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount, 389 LLVMBool Packed); 390 LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name); 391 void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes, 392 unsigned ElementCount, LLVMBool Packed); 393 394 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy); 395 void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest); 396 LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy); 397 LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy); 398 399 LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name); 400 401 /* Operations on array, pointer, and vector types (sequence types) */ 402 LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount); 403 LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace); 404 LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount); 405 406 LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty); 407 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy); 408 unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy); 409 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy); 410 411 /* Operations on other types */ 412 LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C); 413 LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C); 414 LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C); 415 416 LLVMTypeRef LLVMVoidType(void); 417 LLVMTypeRef LLVMLabelType(void); 418 LLVMTypeRef LLVMX86MMXType(void); 419 420 /*===-- Values ------------------------------------------------------------===*/ 421 422 /* The bulk of LLVM's object model consists of values, which comprise a very 423 * rich type hierarchy. 424 */ 425 426 #define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \ 427 macro(Argument) \ 428 macro(BasicBlock) \ 429 macro(InlineAsm) \ 430 macro(User) \ 431 macro(Constant) \ 432 macro(ConstantAggregateZero) \ 433 macro(ConstantArray) \ 434 macro(ConstantExpr) \ 435 macro(ConstantFP) \ 436 macro(ConstantInt) \ 437 macro(ConstantPointerNull) \ 438 macro(ConstantStruct) \ 439 macro(ConstantVector) \ 440 macro(GlobalValue) \ 441 macro(Function) \ 442 macro(GlobalAlias) \ 443 macro(GlobalVariable) \ 444 macro(UndefValue) \ 445 macro(Instruction) \ 446 macro(BinaryOperator) \ 447 macro(CallInst) \ 448 macro(IntrinsicInst) \ 449 macro(DbgInfoIntrinsic) \ 450 macro(DbgDeclareInst) \ 451 macro(EHSelectorInst) \ 452 macro(MemIntrinsic) \ 453 macro(MemCpyInst) \ 454 macro(MemMoveInst) \ 455 macro(MemSetInst) \ 456 macro(CmpInst) \ 457 macro(FCmpInst) \ 458 macro(ICmpInst) \ 459 macro(ExtractElementInst) \ 460 macro(GetElementPtrInst) \ 461 macro(InsertElementInst) \ 462 macro(InsertValueInst) \ 463 macro(PHINode) \ 464 macro(SelectInst) \ 465 macro(ShuffleVectorInst) \ 466 macro(StoreInst) \ 467 macro(TerminatorInst) \ 468 macro(BranchInst) \ 469 macro(InvokeInst) \ 470 macro(ReturnInst) \ 471 macro(SwitchInst) \ 472 macro(UnreachableInst) \ 473 macro(UnwindInst) \ 474 macro(UnaryInstruction) \ 475 macro(AllocaInst) \ 476 macro(CastInst) \ 477 macro(BitCastInst) \ 478 macro(FPExtInst) \ 479 macro(FPToSIInst) \ 480 macro(FPToUIInst) \ 481 macro(FPTruncInst) \ 482 macro(IntToPtrInst) \ 483 macro(PtrToIntInst) \ 484 macro(SExtInst) \ 485 macro(SIToFPInst) \ 486 macro(TruncInst) \ 487 macro(UIToFPInst) \ 488 macro(ZExtInst) \ 489 macro(ExtractValueInst) \ 490 macro(LoadInst) \ 491 macro(VAArgInst) 492 493 /* Operations on all values */ 494 LLVMTypeRef LLVMTypeOf(LLVMValueRef Val); 495 const char *LLVMGetValueName(LLVMValueRef Val); 496 void LLVMSetValueName(LLVMValueRef Val, const char *Name); 497 void LLVMDumpValue(LLVMValueRef Val); 498 void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal); 499 int LLVMHasMetadata(LLVMValueRef Val); 500 LLVMValueRef LLVMGetMetadata(LLVMValueRef Val, unsigned KindID); 501 void LLVMSetMetadata(LLVMValueRef Val, unsigned KindID, LLVMValueRef Node); 502 503 /* Conversion functions. Return the input value if it is an instance of the 504 specified class, otherwise NULL. See llvm::dyn_cast_or_null<>. */ 505 #define LLVM_DECLARE_VALUE_CAST(name) \ 506 LLVMValueRef LLVMIsA##name(LLVMValueRef Val); 507 LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST) 508 509 /* Operations on Uses */ 510 LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val); 511 LLVMUseRef LLVMGetNextUse(LLVMUseRef U); 512 LLVMValueRef LLVMGetUser(LLVMUseRef U); 513 LLVMValueRef LLVMGetUsedValue(LLVMUseRef U); 514 515 /* Operations on Users */ 516 LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index); 517 void LLVMSetOperand(LLVMValueRef User, unsigned Index, LLVMValueRef Val); 518 int LLVMGetNumOperands(LLVMValueRef Val); 519 520 /* Operations on constants of any type */ 521 LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */ 522 LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); /* only for int/vector */ 523 LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty); 524 LLVMBool LLVMIsConstant(LLVMValueRef Val); 525 LLVMBool LLVMIsNull(LLVMValueRef Val); 526 LLVMBool LLVMIsUndef(LLVMValueRef Val); 527 LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty); 528 529 /* Operations on metadata */ 530 LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str, 531 unsigned SLen); 532 LLVMValueRef LLVMMDString(const char *Str, unsigned SLen); 533 LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals, 534 unsigned Count); 535 LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count); 536 537 /* Operations on scalar constants */ 538 LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N, 539 LLVMBool SignExtend); 540 LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy, 541 unsigned NumWords, 542 const uint64_t Words[]); 543 LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text, 544 uint8_t Radix); 545 LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text, 546 unsigned SLen, uint8_t Radix); 547 LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N); 548 LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text); 549 LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text, 550 unsigned SLen); 551 unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal); 552 long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal); 553 554 555 /* Operations on composite constants */ 556 LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str, 557 unsigned Length, LLVMBool DontNullTerminate); 558 LLVMValueRef LLVMConstStructInContext(LLVMContextRef C, 559 LLVMValueRef *ConstantVals, 560 unsigned Count, LLVMBool Packed); 561 562 LLVMValueRef LLVMConstString(const char *Str, unsigned Length, 563 LLVMBool DontNullTerminate); 564 LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy, 565 LLVMValueRef *ConstantVals, unsigned Length); 566 LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count, 567 LLVMBool Packed); 568 LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy, 569 LLVMValueRef *ConstantVals, 570 unsigned Count); 571 LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size); 572 573 /* Constant expressions */ 574 LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal); 575 LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty); 576 LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty); 577 LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal); 578 LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal); 579 LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal); 580 LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal); 581 LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal); 582 LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 583 LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 584 LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 585 LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 586 LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 587 LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 588 LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 589 LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 590 LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 591 LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 592 LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 593 LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 594 LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 595 LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 596 LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 597 LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 598 LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 599 LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 600 LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 601 LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 602 LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 603 LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 604 LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate, 605 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 606 LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate, 607 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 608 LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 609 LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 610 LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); 611 LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal, 612 LLVMValueRef *ConstantIndices, unsigned NumIndices); 613 LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal, 614 LLVMValueRef *ConstantIndices, 615 unsigned NumIndices); 616 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 617 LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 618 LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 619 LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 620 LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 621 LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 622 LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 623 LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 624 LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 625 LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 626 LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 627 LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 628 LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal, 629 LLVMTypeRef ToType); 630 LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal, 631 LLVMTypeRef ToType); 632 LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal, 633 LLVMTypeRef ToType); 634 LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal, 635 LLVMTypeRef ToType); 636 LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType, 637 LLVMBool isSigned); 638 LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType); 639 LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition, 640 LLVMValueRef ConstantIfTrue, 641 LLVMValueRef ConstantIfFalse); 642 LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant, 643 LLVMValueRef IndexConstant); 644 LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant, 645 LLVMValueRef ElementValueConstant, 646 LLVMValueRef IndexConstant); 647 LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant, 648 LLVMValueRef VectorBConstant, 649 LLVMValueRef MaskConstant); 650 LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList, 651 unsigned NumIdx); 652 LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant, 653 LLVMValueRef ElementValueConstant, 654 unsigned *IdxList, unsigned NumIdx); 655 LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty, 656 const char *AsmString, const char *Constraints, 657 LLVMBool HasSideEffects, LLVMBool IsAlignStack); 658 LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB); 659 660 /* Operations on global variables, functions, and aliases (globals) */ 661 LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global); 662 LLVMBool LLVMIsDeclaration(LLVMValueRef Global); 663 LLVMLinkage LLVMGetLinkage(LLVMValueRef Global); 664 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage); 665 const char *LLVMGetSection(LLVMValueRef Global); 666 void LLVMSetSection(LLVMValueRef Global, const char *Section); 667 LLVMVisibility LLVMGetVisibility(LLVMValueRef Global); 668 void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz); 669 unsigned LLVMGetAlignment(LLVMValueRef Global); 670 void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes); 671 672 /* Operations on global variables */ 673 LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name); 674 LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty, 675 const char *Name, 676 unsigned AddressSpace); 677 LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name); 678 LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M); 679 LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M); 680 LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar); 681 LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar); 682 void LLVMDeleteGlobal(LLVMValueRef GlobalVar); 683 LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar); 684 void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal); 685 LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar); 686 void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal); 687 LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar); 688 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant); 689 690 /* Operations on aliases */ 691 LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee, 692 const char *Name); 693 694 /* Operations on functions */ 695 LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name, 696 LLVMTypeRef FunctionTy); 697 LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name); 698 LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M); 699 LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M); 700 LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn); 701 LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn); 702 void LLVMDeleteFunction(LLVMValueRef Fn); 703 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn); 704 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn); 705 void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC); 706 const char *LLVMGetGC(LLVMValueRef Fn); 707 void LLVMSetGC(LLVMValueRef Fn, const char *Name); 708 void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA); 709 LLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn); 710 void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA); 711 712 /* Operations on parameters */ 713 unsigned LLVMCountParams(LLVMValueRef Fn); 714 void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params); 715 LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index); 716 LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst); 717 LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn); 718 LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn); 719 LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg); 720 LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg); 721 void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA); 722 void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA); 723 LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg); 724 void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align); 725 726 /* Operations on basic blocks */ 727 LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB); 728 LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val); 729 LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val); 730 LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB); 731 unsigned LLVMCountBasicBlocks(LLVMValueRef Fn); 732 void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks); 733 LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn); 734 LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn); 735 LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB); 736 LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB); 737 LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn); 738 739 LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C, 740 LLVMValueRef Fn, 741 const char *Name); 742 LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C, 743 LLVMBasicBlockRef BB, 744 const char *Name); 745 746 LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name); 747 LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB, 748 const char *Name); 749 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB); 750 751 void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos); 752 void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos); 753 754 /* Operations on instructions */ 755 LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst); 756 LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB); 757 LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB); 758 LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst); 759 LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst); 760 761 /* Operations on call sites */ 762 void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC); 763 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr); 764 void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute); 765 void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index, 766 LLVMAttribute); 767 void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index, 768 unsigned align); 769 770 /* Operations on call instructions (only) */ 771 LLVMBool LLVMIsTailCall(LLVMValueRef CallInst); 772 void LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall); 773 774 /* Operations on phi nodes */ 775 void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues, 776 LLVMBasicBlockRef *IncomingBlocks, unsigned Count); 777 unsigned LLVMCountIncoming(LLVMValueRef PhiNode); 778 LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index); 779 LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index); 780 781 /*===-- Instruction builders ----------------------------------------------===*/ 782 783 /* An instruction builder represents a point within a basic block, and is the 784 * exclusive means of building instructions using the C interface. 785 */ 786 787 LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C); 788 LLVMBuilderRef LLVMCreateBuilder(void); 789 void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block, 790 LLVMValueRef Instr); 791 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr); 792 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block); 793 LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder); 794 void LLVMClearInsertionPosition(LLVMBuilderRef Builder); 795 void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr); 796 void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr, 797 const char *Name); 798 void LLVMDisposeBuilder(LLVMBuilderRef Builder); 799 800 /* Metadata */ 801 void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L); 802 LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder); 803 void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst); 804 805 /* Terminators */ 806 LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef); 807 LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V); 808 LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef *RetVals, 809 unsigned N); 810 LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest); 811 LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If, 812 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else); 813 LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V, 814 LLVMBasicBlockRef Else, unsigned NumCases); 815 LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr, 816 unsigned NumDests); 817 LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn, 818 LLVMValueRef *Args, unsigned NumArgs, 819 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch, 820 const char *Name); 821 LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef); 822 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef); 823 824 /* Add a case to the switch instruction */ 825 void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal, 826 LLVMBasicBlockRef Dest); 827 828 /* Add a destination to the indirectbr instruction */ 829 void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest); 830 831 /* Arithmetic */ 832 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 833 const char *Name); 834 LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 835 const char *Name); 836 LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 837 const char *Name); 838 LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 839 const char *Name); 840 LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 841 const char *Name); 842 LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 843 const char *Name); 844 LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 845 const char *Name); 846 LLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 847 const char *Name); 848 LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 849 const char *Name); 850 LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 851 const char *Name); 852 LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 853 const char *Name); 854 LLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 855 const char *Name); 856 LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 857 const char *Name); 858 LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 859 const char *Name); 860 LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 861 const char *Name); 862 LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 863 const char *Name); 864 LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 865 const char *Name); 866 LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 867 const char *Name); 868 LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 869 const char *Name); 870 LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 871 const char *Name); 872 LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 873 const char *Name); 874 LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 875 const char *Name); 876 LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 877 const char *Name); 878 LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 879 const char *Name); 880 LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS, 881 const char *Name); 882 LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op, 883 LLVMValueRef LHS, LLVMValueRef RHS, 884 const char *Name); 885 LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name); 886 LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V, 887 const char *Name); 888 LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V, 889 const char *Name); 890 LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name); 891 LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name); 892 893 /* Memory */ 894 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name); 895 LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty, 896 LLVMValueRef Val, const char *Name); 897 LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name); 898 LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty, 899 LLVMValueRef Val, const char *Name); 900 LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal); 901 LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal, 902 const char *Name); 903 LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr); 904 LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer, 905 LLVMValueRef *Indices, unsigned NumIndices, 906 const char *Name); 907 LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer, 908 LLVMValueRef *Indices, unsigned NumIndices, 909 const char *Name); 910 LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer, 911 unsigned Idx, const char *Name); 912 LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str, 913 const char *Name); 914 LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str, 915 const char *Name); 916 917 /* Casts */ 918 LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val, 919 LLVMTypeRef DestTy, const char *Name); 920 LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val, 921 LLVMTypeRef DestTy, const char *Name); 922 LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val, 923 LLVMTypeRef DestTy, const char *Name); 924 LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val, 925 LLVMTypeRef DestTy, const char *Name); 926 LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val, 927 LLVMTypeRef DestTy, const char *Name); 928 LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val, 929 LLVMTypeRef DestTy, const char *Name); 930 LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val, 931 LLVMTypeRef DestTy, const char *Name); 932 LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val, 933 LLVMTypeRef DestTy, const char *Name); 934 LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val, 935 LLVMTypeRef DestTy, const char *Name); 936 LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val, 937 LLVMTypeRef DestTy, const char *Name); 938 LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val, 939 LLVMTypeRef DestTy, const char *Name); 940 LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val, 941 LLVMTypeRef DestTy, const char *Name); 942 LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val, 943 LLVMTypeRef DestTy, const char *Name); 944 LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val, 945 LLVMTypeRef DestTy, const char *Name); 946 LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val, 947 LLVMTypeRef DestTy, const char *Name); 948 LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val, 949 LLVMTypeRef DestTy, const char *Name); 950 LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val, 951 LLVMTypeRef DestTy, const char *Name); 952 LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val, /*Signed cast!*/ 953 LLVMTypeRef DestTy, const char *Name); 954 LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val, 955 LLVMTypeRef DestTy, const char *Name); 956 957 /* Comparisons */ 958 LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op, 959 LLVMValueRef LHS, LLVMValueRef RHS, 960 const char *Name); 961 LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op, 962 LLVMValueRef LHS, LLVMValueRef RHS, 963 const char *Name); 964 965 /* Miscellaneous instructions */ 966 LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name); 967 LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn, 968 LLVMValueRef *Args, unsigned NumArgs, 969 const char *Name); 970 LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If, 971 LLVMValueRef Then, LLVMValueRef Else, 972 const char *Name); 973 LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty, 974 const char *Name); 975 LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal, 976 LLVMValueRef Index, const char *Name); 977 LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal, 978 LLVMValueRef EltVal, LLVMValueRef Index, 979 const char *Name); 980 LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1, 981 LLVMValueRef V2, LLVMValueRef Mask, 982 const char *Name); 983 LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal, 984 unsigned Index, const char *Name); 985 LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal, 986 LLVMValueRef EltVal, unsigned Index, 987 const char *Name); 988 989 LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val, 990 const char *Name); 991 LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val, 992 const char *Name); 993 LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS, 994 LLVMValueRef RHS, const char *Name); 995 996 997 /*===-- Module providers --------------------------------------------------===*/ 998 999 /* Changes the type of M so it can be passed to FunctionPassManagers and the 1000 * JIT. They take ModuleProviders for historical reasons. 1001 */ 1002 LLVMModuleProviderRef 1003 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M); 1004 1005 /* Destroys the module M. 1006 */ 1007 void LLVMDisposeModuleProvider(LLVMModuleProviderRef M); 1008 1009 1010 /*===-- Memory buffers ----------------------------------------------------===*/ 1011 1012 LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path, 1013 LLVMMemoryBufferRef *OutMemBuf, 1014 char **OutMessage); 1015 LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf, 1016 char **OutMessage); 1017 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf); 1018 1019 /*===-- Pass Registry -----------------------------------------------------===*/ 1020 1021 /** Return the global pass registry, for use with initialization functions. 1022 See llvm::PassRegistry::getPassRegistry. */ 1023 LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void); 1024 1025 /*===-- Pass Managers -----------------------------------------------------===*/ 1026 1027 /** Constructs a new whole-module pass pipeline. This type of pipeline is 1028 suitable for link-time optimization and whole-module transformations. 1029 See llvm::PassManager::PassManager. */ 1030 LLVMPassManagerRef LLVMCreatePassManager(void); 1031 1032 /** Constructs a new function-by-function pass pipeline over the module 1033 provider. It does not take ownership of the module provider. This type of 1034 pipeline is suitable for code generation and JIT compilation tasks. 1035 See llvm::FunctionPassManager::FunctionPassManager. */ 1036 LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M); 1037 1038 /** Deprecated: Use LLVMCreateFunctionPassManagerForModule instead. */ 1039 LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP); 1040 1041 /** Initializes, executes on the provided module, and finalizes all of the 1042 passes scheduled in the pass manager. Returns 1 if any of the passes 1043 modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */ 1044 LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M); 1045 1046 /** Initializes all of the function passes scheduled in the function pass 1047 manager. Returns 1 if any of the passes modified the module, 0 otherwise. 1048 See llvm::FunctionPassManager::doInitialization. */ 1049 LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM); 1050 1051 /** Executes all of the function passes scheduled in the function pass manager 1052 on the provided function. Returns 1 if any of the passes modified the 1053 function, false otherwise. 1054 See llvm::FunctionPassManager::run(Function&). */ 1055 LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F); 1056 1057 /** Finalizes all of the function passes scheduled in in the function pass 1058 manager. Returns 1 if any of the passes modified the module, 0 otherwise. 1059 See llvm::FunctionPassManager::doFinalization. */ 1060 LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM); 1061 1062 /** Frees the memory of a pass pipeline. For function pipelines, does not free 1063 the module provider. 1064 See llvm::PassManagerBase::~PassManagerBase. */ 1065 void LLVMDisposePassManager(LLVMPassManagerRef PM); 1066 1067 1068 #ifdef __cplusplus 1069 } 1070 1071 namespace llvm { 1072 class MemoryBuffer; 1073 class PassManagerBase; 1074 1075 #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \ 1076 inline ty *unwrap(ref P) { \ 1077 return reinterpret_cast<ty*>(P); \ 1078 } \ 1079 \ 1080 inline ref wrap(const ty *P) { \ 1081 return reinterpret_cast<ref>(const_cast<ty*>(P)); \ 1082 } 1083 1084 #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref) \ 1085 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \ 1086 \ 1087 template<typename T> \ 1088 inline T *unwrap(ref P) { \ 1089 return cast<T>(unwrap(P)); \ 1090 } 1091 1092 #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \ 1093 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \ 1094 \ 1095 template<typename T> \ 1096 inline T *unwrap(ref P) { \ 1097 T *Q = (T*)unwrap(P); \ 1098 assert(Q && "Invalid cast!"); \ 1099 return Q; \ 1100 } 1101 1102 DEFINE_ISA_CONVERSION_FUNCTIONS (Type, LLVMTypeRef ) 1103 DEFINE_ISA_CONVERSION_FUNCTIONS (Value, LLVMValueRef ) 1104 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef ) 1105 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef ) 1106 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef ) 1107 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef ) 1108 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext, LLVMContextRef ) 1109 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Use, LLVMUseRef ) 1110 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase, LLVMPassManagerRef ) 1111 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassRegistry, LLVMPassRegistryRef ) 1112 /* LLVMModuleProviderRef exists for historical reasons, but now just holds a 1113 * Module. 1114 */ 1115 inline Module *unwrap(LLVMModuleProviderRef MP) { 1116 return reinterpret_cast<Module*>(MP); 1117 } 1118 1119 #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS 1120 #undef DEFINE_ISA_CONVERSION_FUNCTIONS 1121 #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS 1122 1123 /* Specialized opaque context conversions. 1124 */ 1125 inline LLVMContext **unwrap(LLVMContextRef* Tys) { 1126 return reinterpret_cast<LLVMContext**>(Tys); 1127 } 1128 1129 inline LLVMContextRef *wrap(const LLVMContext **Tys) { 1130 return reinterpret_cast<LLVMContextRef*>(const_cast<LLVMContext**>(Tys)); 1131 } 1132 1133 /* Specialized opaque type conversions. 1134 */ 1135 inline Type **unwrap(LLVMTypeRef* Tys) { 1136 return reinterpret_cast<Type**>(Tys); 1137 } 1138 1139 inline LLVMTypeRef *wrap(Type **Tys) { 1140 return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys)); 1141 } 1142 1143 /* Specialized opaque value conversions. 1144 */ 1145 inline Value **unwrap(LLVMValueRef *Vals) { 1146 return reinterpret_cast<Value**>(Vals); 1147 } 1148 1149 template<typename T> 1150 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) { 1151 #if DEBUG 1152 for (LLVMValueRef *I = Vals, *E = Vals + Length; I != E; ++I) 1153 cast<T>(*I); 1154 #endif 1155 (void)Length; 1156 return reinterpret_cast<T**>(Vals); 1157 } 1158 1159 inline LLVMValueRef *wrap(const Value **Vals) { 1160 return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals)); 1161 } 1162 } 1163 1164 #endif /* !defined(__cplusplus) */ 1165 1166 #endif /* !defined(LLVM_C_CORE_H) */ 1167