diff options
Diffstat (limited to 'lib/IR/Core.cpp')
| -rw-r--r-- | lib/IR/Core.cpp | 442 | 
1 files changed, 405 insertions, 37 deletions
diff --git a/lib/IR/Core.cpp b/lib/IR/Core.cpp index bea4dee15c13c..815797f4b7ea8 100644 --- a/lib/IR/Core.cpp +++ b/lib/IR/Core.cpp @@ -15,8 +15,8 @@  #include "llvm-c/Core.h"  #include "llvm/ADT/StringSwitch.h"  #include "llvm/IR/Attributes.h" -#include "llvm/IR/CallSite.h"  #include "llvm/IR/Constants.h" +#include "llvm/IR/DebugInfoMetadata.h"  #include "llvm/IR/DerivedTypes.h"  #include "llvm/IR/DiagnosticInfo.h"  #include "llvm/IR/DiagnosticPrinter.h" @@ -107,6 +107,14 @@ void LLVMContextSetYieldCallback(LLVMContextRef C, LLVMYieldCallback Callback,    unwrap(C)->setYieldCallback(YieldCallback, OpaqueHandle);  } +LLVMBool LLVMContextShouldDiscardValueNames(LLVMContextRef C) { +  return unwrap(C)->shouldDiscardValueNames(); +} + +void LLVMContextSetDiscardValueNames(LLVMContextRef C, LLVMBool Discard) { +  unwrap(C)->setDiscardValueNames(Discard); +} +  void LLVMContextDispose(LLVMContextRef C) {    delete unwrap(C);  } @@ -706,6 +714,10 @@ LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy) {    return unwrap<StructType>(StructTy)->isOpaque();  } +LLVMBool LLVMIsLiteralStruct(LLVMTypeRef StructTy) { +  return unwrap<StructType>(StructTy)->isLiteral(); +} +  LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name) {    return wrap(unwrap(M)->getTypeByName(Name));  } @@ -868,6 +880,38 @@ void LLVMSetMetadata(LLVMValueRef Inst, unsigned KindID, LLVMValueRef Val) {    unwrap<Instruction>(Inst)->setMetadata(KindID, N);  } +struct LLVMOpaqueValueMetadataEntry { +  unsigned Kind; +  LLVMMetadataRef Metadata; +}; + +using MetadataEntries = SmallVectorImpl<std::pair<unsigned, MDNode *>>; +static LLVMValueMetadataEntry * +llvm_getMetadata(size_t *NumEntries, +                 llvm::function_ref<void(MetadataEntries &)> AccessMD) { +  SmallVector<std::pair<unsigned, MDNode *>, 8> MVEs; +  AccessMD(MVEs); + +  LLVMOpaqueValueMetadataEntry *Result = +  static_cast<LLVMOpaqueValueMetadataEntry *>( +                                              safe_malloc(MVEs.size() * sizeof(LLVMOpaqueValueMetadataEntry))); +  for (unsigned i = 0; i < MVEs.size(); ++i) { +    const auto &ModuleFlag = MVEs[i]; +    Result[i].Kind = ModuleFlag.first; +    Result[i].Metadata = wrap(ModuleFlag.second); +  } +  *NumEntries = MVEs.size(); +  return Result; +} + +LLVMValueMetadataEntry * +LLVMInstructionGetAllMetadataOtherThanDebugLoc(LLVMValueRef Value, +                                               size_t *NumEntries) { +  return llvm_getMetadata(NumEntries, [&Value](MetadataEntries &Entries) { +    unwrap<Instruction>(Value)->getAllMetadata(Entries); +  }); +} +  /*--.. Conversion functions ................................................--*/  #define LLVM_DEFINE_VALUE_CAST(name)                                       \ @@ -1065,6 +1109,54 @@ unsigned LLVMGetMDNodeNumOperands(LLVMValueRef V) {    return cast<MDNode>(MD->getMetadata())->getNumOperands();  } +LLVMNamedMDNodeRef LLVMGetFirstNamedMetadata(LLVMModuleRef M) { +  Module *Mod = unwrap(M); +  Module::named_metadata_iterator I = Mod->named_metadata_begin(); +  if (I == Mod->named_metadata_end()) +    return nullptr; +  return wrap(&*I); +} + +LLVMNamedMDNodeRef LLVMGetLastNamedMetadata(LLVMModuleRef M) { +  Module *Mod = unwrap(M); +  Module::named_metadata_iterator I = Mod->named_metadata_end(); +  if (I == Mod->named_metadata_begin()) +    return nullptr; +  return wrap(&*--I); +} + +LLVMNamedMDNodeRef LLVMGetNextNamedMetadata(LLVMNamedMDNodeRef NMD) { +  NamedMDNode *NamedNode = unwrap<NamedMDNode>(NMD); +  Module::named_metadata_iterator I(NamedNode); +  if (++I == NamedNode->getParent()->named_metadata_end()) +    return nullptr; +  return wrap(&*I); +} + +LLVMNamedMDNodeRef LLVMGetPreviousNamedMetadata(LLVMNamedMDNodeRef NMD) { +  NamedMDNode *NamedNode = unwrap<NamedMDNode>(NMD); +  Module::named_metadata_iterator I(NamedNode); +  if (I == NamedNode->getParent()->named_metadata_begin()) +    return nullptr; +  return wrap(&*--I); +} + +LLVMNamedMDNodeRef LLVMGetNamedMetadata(LLVMModuleRef M, +                                        const char *Name, size_t NameLen) { +  return wrap(unwrap(M)->getNamedMetadata(StringRef(Name, NameLen))); +} + +LLVMNamedMDNodeRef LLVMGetOrInsertNamedMetadata(LLVMModuleRef M, +                                                const char *Name, size_t NameLen) { +  return wrap(unwrap(M)->getOrInsertNamedMetadata({Name, NameLen})); +} + +const char *LLVMGetNamedMetadataName(LLVMNamedMDNodeRef NMD, size_t *NameLen) { +  NamedMDNode *NamedNode = unwrap<NamedMDNode>(NMD); +  *NameLen = NamedNode->getName().size(); +  return NamedNode->getName().data(); +} +  void LLVMGetMDNodeOperands(LLVMValueRef V, LLVMValueRef *Dest) {    auto *MD = cast<MetadataAsValue>(unwrap(V));    if (auto *MDV = dyn_cast<ValueAsMetadata>(MD->getMetadata())) { @@ -1105,6 +1197,78 @@ void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char *Name,    N->addOperand(extractMDNode(unwrap<MetadataAsValue>(Val)));  } +const char *LLVMGetDebugLocDirectory(LLVMValueRef Val, unsigned *Length) { +  if (!Length) return nullptr; +  StringRef S; +  if (const auto *I = unwrap<Instruction>(Val)) { +    S = I->getDebugLoc()->getDirectory(); +  } else if (const auto *GV = unwrap<GlobalVariable>(Val)) { +    SmallVector<DIGlobalVariableExpression *, 1> GVEs; +    GV->getDebugInfo(GVEs); +    if (GVEs.size()) +      if (const DIGlobalVariable *DGV = GVEs[0]->getVariable()) +        S = DGV->getDirectory(); +  } else if (const auto *F = unwrap<Function>(Val)) { +    if (const DISubprogram *DSP = F->getSubprogram()) +      S = DSP->getDirectory(); +  } else { +    assert(0 && "Expected Instruction, GlobalVariable or Function"); +    return nullptr; +  } +  *Length = S.size(); +  return S.data(); +} + +const char *LLVMGetDebugLocFilename(LLVMValueRef Val, unsigned *Length) { +  if (!Length) return nullptr; +  StringRef S; +  if (const auto *I = unwrap<Instruction>(Val)) { +    S = I->getDebugLoc()->getFilename(); +  } else if (const auto *GV = unwrap<GlobalVariable>(Val)) { +    SmallVector<DIGlobalVariableExpression *, 1> GVEs; +    GV->getDebugInfo(GVEs); +    if (GVEs.size()) +      if (const DIGlobalVariable *DGV = GVEs[0]->getVariable()) +        S = DGV->getFilename(); +  } else if (const auto *F = unwrap<Function>(Val)) { +    if (const DISubprogram *DSP = F->getSubprogram()) +      S = DSP->getFilename(); +  } else { +    assert(0 && "Expected Instruction, GlobalVariable or Function"); +    return nullptr; +  } +  *Length = S.size(); +  return S.data(); +} + +unsigned LLVMGetDebugLocLine(LLVMValueRef Val) { +  unsigned L = 0; +  if (const auto *I = unwrap<Instruction>(Val)) { +    L = I->getDebugLoc()->getLine(); +  } else if (const auto *GV = unwrap<GlobalVariable>(Val)) { +    SmallVector<DIGlobalVariableExpression *, 1> GVEs; +    GV->getDebugInfo(GVEs); +    if (GVEs.size()) +      if (const DIGlobalVariable *DGV = GVEs[0]->getVariable()) +        L = DGV->getLine(); +  } else if (const auto *F = unwrap<Function>(Val)) { +    if (const DISubprogram *DSP = F->getSubprogram()) +      L = DSP->getLine(); +  } else { +    assert(0 && "Expected Instruction, GlobalVariable or Function"); +    return -1; +  } +  return L; +} + +unsigned LLVMGetDebugLocColumn(LLVMValueRef Val) { +  unsigned C = 0; +  if (const auto *I = unwrap<Instruction>(Val)) +    if (const auto &L = I->getDebugLoc()) +      C = L->getColumn(); +  return C; +} +  /*--.. Operations on scalar constants ......................................--*/  LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N, @@ -1453,17 +1617,21 @@ LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,                            LLVMValueRef *ConstantIndices, unsigned NumIndices) {    ArrayRef<Constant *> IdxList(unwrap<Constant>(ConstantIndices, NumIndices),                                 NumIndices); -  return wrap(ConstantExpr::getGetElementPtr( -      nullptr, unwrap<Constant>(ConstantVal), IdxList)); +  Constant *Val = unwrap<Constant>(ConstantVal); +  Type *Ty = +      cast<PointerType>(Val->getType()->getScalarType())->getElementType(); +  return wrap(ConstantExpr::getGetElementPtr(Ty, Val, IdxList));  }  LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,                                    LLVMValueRef *ConstantIndices,                                    unsigned NumIndices) { -  Constant* Val = unwrap<Constant>(ConstantVal);    ArrayRef<Constant *> IdxList(unwrap<Constant>(ConstantIndices, NumIndices),                                 NumIndices); -  return wrap(ConstantExpr::getInBoundsGetElementPtr(nullptr, Val, IdxList)); +  Constant *Val = unwrap<Constant>(ConstantVal); +  Type *Ty = +      cast<PointerType>(Val->getType()->getScalarType())->getElementType(); +  return wrap(ConstantExpr::getInBoundsGetElementPtr(Ty, Val, IdxList));  }  LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType) { @@ -1792,6 +1960,10 @@ void LLVMSetUnnamedAddr(LLVMValueRef Global, LLVMBool HasUnnamedAddr) {                       : GlobalValue::UnnamedAddr::None);  } +LLVMTypeRef LLVMGlobalGetValueType(LLVMValueRef Global) { +  return wrap(unwrap<GlobalValue>(Global)->getValueType()); +} +  /*--.. Operations on global variables, load and store instructions .........--*/  unsigned LLVMGetAlignment(LLVMValueRef V) { @@ -1824,6 +1996,49 @@ void LLVMSetAlignment(LLVMValueRef V, unsigned Bytes) {          "only GlobalValue, AllocaInst, LoadInst and StoreInst have alignment");  } +LLVMValueMetadataEntry *LLVMGlobalCopyAllMetadata(LLVMValueRef Value, +                                                  size_t *NumEntries) { +  return llvm_getMetadata(NumEntries, [&Value](MetadataEntries &Entries) { +    if (Instruction *Instr = dyn_cast<Instruction>(unwrap(Value))) { +      Instr->getAllMetadata(Entries); +    } else { +      unwrap<GlobalObject>(Value)->getAllMetadata(Entries); +    } +  }); +} + +unsigned LLVMValueMetadataEntriesGetKind(LLVMValueMetadataEntry *Entries, +                                         unsigned Index) { +  LLVMOpaqueValueMetadataEntry MVE = +      static_cast<LLVMOpaqueValueMetadataEntry>(Entries[Index]); +  return MVE.Kind; +} + +LLVMMetadataRef +LLVMValueMetadataEntriesGetMetadata(LLVMValueMetadataEntry *Entries, +                                    unsigned Index) { +  LLVMOpaqueValueMetadataEntry MVE = +      static_cast<LLVMOpaqueValueMetadataEntry>(Entries[Index]); +  return MVE.Metadata; +} + +void LLVMDisposeValueMetadataEntries(LLVMValueMetadataEntry *Entries) { +  free(Entries); +} + +void LLVMGlobalSetMetadata(LLVMValueRef Global, unsigned Kind, +                           LLVMMetadataRef MD) { +  unwrap<GlobalObject>(Global)->setMetadata(Kind, unwrap<MDNode>(MD)); +} + +void LLVMGlobalEraseMetadata(LLVMValueRef Global, unsigned Kind) { +  unwrap<GlobalObject>(Global)->eraseMetadata(Kind); +} + +void LLVMGlobalClearMetadata(LLVMValueRef Global) { +  unwrap<GlobalObject>(Global)->clearMetadata(); +} +  /*--.. Operations on global variables ......................................--*/  LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name) { @@ -2076,6 +2291,50 @@ unsigned LLVMGetIntrinsicID(LLVMValueRef Fn) {    return 0;  } +static Intrinsic::ID llvm_map_to_intrinsic_id(unsigned ID) { +  assert(ID < llvm::Intrinsic::num_intrinsics && "Intrinsic ID out of range"); +  return llvm::Intrinsic::ID(ID); +} + +LLVMValueRef LLVMGetIntrinsicDeclaration(LLVMModuleRef Mod, +                                         unsigned ID, +                                         LLVMTypeRef *ParamTypes, +                                         size_t ParamCount) { +  ArrayRef<Type*> Tys(unwrap(ParamTypes), ParamCount); +  auto IID = llvm_map_to_intrinsic_id(ID); +  return wrap(llvm::Intrinsic::getDeclaration(unwrap(Mod), IID, Tys)); +} + +const char *LLVMIntrinsicGetName(unsigned ID, size_t *NameLength) { +  auto IID = llvm_map_to_intrinsic_id(ID); +  auto Str = llvm::Intrinsic::getName(IID); +  *NameLength = Str.size(); +  return Str.data(); +} + +LLVMTypeRef LLVMIntrinsicGetType(LLVMContextRef Ctx, unsigned ID, +                                 LLVMTypeRef *ParamTypes, size_t ParamCount) { +  auto IID = llvm_map_to_intrinsic_id(ID); +  ArrayRef<Type*> Tys(unwrap(ParamTypes), ParamCount); +  return wrap(llvm::Intrinsic::getType(*unwrap(Ctx), IID, Tys)); +} + +const char *LLVMIntrinsicCopyOverloadedName(unsigned ID, +                                            LLVMTypeRef *ParamTypes, +                                            size_t ParamCount, +                                            size_t *NameLength) { +  auto IID = llvm_map_to_intrinsic_id(ID); +  ArrayRef<Type*> Tys(unwrap(ParamTypes), ParamCount); +  auto Str = llvm::Intrinsic::getName(IID, Tys); +  *NameLength = Str.length(); +  return strdup(Str.c_str()); +} + +LLVMBool LLVMIntrinsicIsOverloaded(unsigned ID) { +  auto IID = llvm_map_to_intrinsic_id(ID); +  return llvm::Intrinsic::isOverloaded(IID); +} +  unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn) {    return unwrap<Function>(Fn)->getCallingConv();  } @@ -2277,6 +2536,11 @@ LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB) {    return wrap(&*--I);  } +LLVMBasicBlockRef LLVMCreateBasicBlockInContext(LLVMContextRef C, +                                                const char *Name) { +  return wrap(llvm::BasicBlock::Create(*unwrap(C), Name)); +} +  LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,                                                  LLVMValueRef FnRef,                                                  const char *Name) { @@ -2391,47 +2655,52 @@ LLVMValueRef LLVMInstructionClone(LLVMValueRef Inst) {    return nullptr;  } +LLVMValueRef LLVMIsATerminatorInst(LLVMValueRef Inst) { +  Instruction *I = dyn_cast<Instruction>(unwrap(Inst)); +  return (I && I->isTerminator()) ? wrap(I) : nullptr; +} +  unsigned LLVMGetNumArgOperands(LLVMValueRef Instr) {    if (FuncletPadInst *FPI = dyn_cast<FuncletPadInst>(unwrap(Instr))) {      return FPI->getNumArgOperands();    } -  return CallSite(unwrap<Instruction>(Instr)).getNumArgOperands(); +  return unwrap<CallBase>(Instr)->getNumArgOperands();  }  /*--.. Call and invoke instructions ........................................--*/  unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr) { -  return CallSite(unwrap<Instruction>(Instr)).getCallingConv(); +  return unwrap<CallBase>(Instr)->getCallingConv();  }  void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC) { -  return CallSite(unwrap<Instruction>(Instr)) -    .setCallingConv(static_cast<CallingConv::ID>(CC)); +  return unwrap<CallBase>(Instr)->setCallingConv( +      static_cast<CallingConv::ID>(CC));  }  void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,                                  unsigned align) { -  CallSite Call = CallSite(unwrap<Instruction>(Instr)); +  auto *Call = unwrap<CallBase>(Instr);    Attribute AlignAttr = Attribute::getWithAlignment(Call->getContext(), align); -  Call.addAttribute(index, AlignAttr); +  Call->addAttribute(index, AlignAttr);  }  void LLVMAddCallSiteAttribute(LLVMValueRef C, LLVMAttributeIndex Idx,                                LLVMAttributeRef A) { -  CallSite(unwrap<Instruction>(C)).addAttribute(Idx, unwrap(A)); +  unwrap<CallBase>(C)->addAttribute(Idx, unwrap(A));  }  unsigned LLVMGetCallSiteAttributeCount(LLVMValueRef C,                                         LLVMAttributeIndex Idx) { -  auto CS = CallSite(unwrap<Instruction>(C)); -  auto AS = CS.getAttributes().getAttributes(Idx); +  auto *Call = unwrap<CallBase>(C); +  auto AS = Call->getAttributes().getAttributes(Idx);    return AS.getNumAttributes();  }  void LLVMGetCallSiteAttributes(LLVMValueRef C, LLVMAttributeIndex Idx,                                 LLVMAttributeRef *Attrs) { -  auto CS = CallSite(unwrap<Instruction>(C)); -  auto AS = CS.getAttributes().getAttributes(Idx); +  auto *Call = unwrap<CallBase>(C); +  auto AS = Call->getAttributes().getAttributes(Idx);    for (auto A : AS)      *Attrs++ = wrap(A);  } @@ -2439,30 +2708,32 @@ void LLVMGetCallSiteAttributes(LLVMValueRef C, LLVMAttributeIndex Idx,  LLVMAttributeRef LLVMGetCallSiteEnumAttribute(LLVMValueRef C,                                                LLVMAttributeIndex Idx,                                                unsigned KindID) { -  return wrap(CallSite(unwrap<Instruction>(C)) -    .getAttribute(Idx, (Attribute::AttrKind)KindID)); +  return wrap( +      unwrap<CallBase>(C)->getAttribute(Idx, (Attribute::AttrKind)KindID));  }  LLVMAttributeRef LLVMGetCallSiteStringAttribute(LLVMValueRef C,                                                  LLVMAttributeIndex Idx,                                                  const char *K, unsigned KLen) { -  return wrap(CallSite(unwrap<Instruction>(C)) -    .getAttribute(Idx, StringRef(K, KLen))); +  return wrap(unwrap<CallBase>(C)->getAttribute(Idx, StringRef(K, KLen)));  }  void LLVMRemoveCallSiteEnumAttribute(LLVMValueRef C, LLVMAttributeIndex Idx,                                       unsigned KindID) { -  CallSite(unwrap<Instruction>(C)) -    .removeAttribute(Idx, (Attribute::AttrKind)KindID); +  unwrap<CallBase>(C)->removeAttribute(Idx, (Attribute::AttrKind)KindID);  }  void LLVMRemoveCallSiteStringAttribute(LLVMValueRef C, LLVMAttributeIndex Idx,                                         const char *K, unsigned KLen) { -  CallSite(unwrap<Instruction>(C)).removeAttribute(Idx, StringRef(K, KLen)); +  unwrap<CallBase>(C)->removeAttribute(Idx, StringRef(K, KLen));  }  LLVMValueRef LLVMGetCalledValue(LLVMValueRef Instr) { -  return wrap(CallSite(unwrap<Instruction>(Instr)).getCalledValue()); +  return wrap(unwrap<CallBase>(Instr)->getCalledValue()); +} + +LLVMTypeRef LLVMGetCalledFunctionType(LLVMValueRef Instr) { +  return wrap(unwrap<CallBase>(Instr)->getFunctionType());  }  /*--.. Operations on call instructions (only) ..............................--*/ @@ -2506,15 +2777,15 @@ void LLVMSetUnwindDest(LLVMValueRef Invoke, LLVMBasicBlockRef B) {  /*--.. Operations on terminators ...........................................--*/  unsigned LLVMGetNumSuccessors(LLVMValueRef Term) { -  return unwrap<TerminatorInst>(Term)->getNumSuccessors(); +  return unwrap<Instruction>(Term)->getNumSuccessors();  }  LLVMBasicBlockRef LLVMGetSuccessor(LLVMValueRef Term, unsigned i) { -  return wrap(unwrap<TerminatorInst>(Term)->getSuccessor(i)); +  return wrap(unwrap<Instruction>(Term)->getSuccessor(i));  }  void LLVMSetSuccessor(LLVMValueRef Term, unsigned i, LLVMBasicBlockRef block) { -  return unwrap<TerminatorInst>(Term)->setSuccessor(i,unwrap(block)); +  return unwrap<Instruction>(Term)->setSuccessor(i, unwrap(block));  }  /*--.. Operations on branch instructions (only) ............................--*/ @@ -2584,6 +2855,8 @@ unsigned LLVMGetNumIndices(LLVMValueRef Inst) {      return EV->getNumIndices();    if (auto *IV = dyn_cast<InsertValueInst>(I))      return IV->getNumIndices(); +  if (auto *CE = dyn_cast<ConstantExpr>(I)) +    return CE->getIndices().size();    llvm_unreachable(      "LLVMGetNumIndices applies only to extractvalue and insertvalue!");  } @@ -2594,6 +2867,8 @@ const unsigned *LLVMGetIndices(LLVMValueRef Inst) {      return EV->getIndices().data();    if (auto *IV = dyn_cast<InsertValueInst>(I))      return IV->getIndices().data(); +  if (auto *CE = dyn_cast<ConstantExpr>(I)) +    return CE->getIndices().data();    llvm_unreachable(      "LLVMGetIndices applies only to extractvalue and insertvalue!");  } @@ -2704,9 +2979,22 @@ LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef B, LLVMValueRef Fn,                               LLVMValueRef *Args, unsigned NumArgs,                               LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,                               const char *Name) { -  return wrap(unwrap(B)->CreateInvoke(unwrap(Fn), unwrap(Then), unwrap(Catch), -                                      makeArrayRef(unwrap(Args), NumArgs), -                                      Name)); +  Value *V = unwrap(Fn); +  FunctionType *FnT = +      cast<FunctionType>(cast<PointerType>(V->getType())->getElementType()); + +  return wrap( +      unwrap(B)->CreateInvoke(FnT, unwrap(Fn), unwrap(Then), unwrap(Catch), +                              makeArrayRef(unwrap(Args), NumArgs), Name)); +} + +LLVMValueRef LLVMBuildInvoke2(LLVMBuilderRef B, LLVMTypeRef Ty, LLVMValueRef Fn, +                              LLVMValueRef *Args, unsigned NumArgs, +                              LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch, +                              const char *Name) { +  return wrap(unwrap(B)->CreateInvoke( +      unwrap<FunctionType>(Ty), unwrap(Fn), unwrap(Then), unwrap(Catch), +      makeArrayRef(unwrap(Args), NumArgs), Name));  }  LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty, @@ -3021,6 +3309,30 @@ LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef B, LLVMTypeRef Ty,    return wrap(unwrap(B)->Insert(Malloc, Twine(Name)));  } +LLVMValueRef LLVMBuildMemSet(LLVMBuilderRef B, LLVMValueRef Ptr,  +                             LLVMValueRef Val, LLVMValueRef Len, +                             unsigned Align) { +  return wrap(unwrap(B)->CreateMemSet(unwrap(Ptr), unwrap(Val), unwrap(Len), Align)); +} + +LLVMValueRef LLVMBuildMemCpy(LLVMBuilderRef B,  +                             LLVMValueRef Dst, unsigned DstAlign, +                             LLVMValueRef Src, unsigned SrcAlign, +                             LLVMValueRef Size) { +  return wrap(unwrap(B)->CreateMemCpy(unwrap(Dst), DstAlign, +                                      unwrap(Src), SrcAlign, +                                      unwrap(Size))); +} + +LLVMValueRef LLVMBuildMemMove(LLVMBuilderRef B, +                              LLVMValueRef Dst, unsigned DstAlign, +                              LLVMValueRef Src, unsigned SrcAlign, +                              LLVMValueRef Size) { +  return wrap(unwrap(B)->CreateMemMove(unwrap(Dst), DstAlign, +                                       unwrap(Src), SrcAlign, +                                       unwrap(Size))); +} +  LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef B, LLVMTypeRef Ty,                               const char *Name) {    return wrap(unwrap(B)->CreateAlloca(unwrap(Ty), nullptr, Name)); @@ -3038,7 +3350,15 @@ LLVMValueRef LLVMBuildFree(LLVMBuilderRef B, LLVMValueRef PointerVal) {  LLVMValueRef LLVMBuildLoad(LLVMBuilderRef B, LLVMValueRef PointerVal,                             const char *Name) { -  return wrap(unwrap(B)->CreateLoad(unwrap(PointerVal), Name)); +  Value *V = unwrap(PointerVal); +  PointerType *Ty = cast<PointerType>(V->getType()); + +  return wrap(unwrap(B)->CreateLoad(Ty->getElementType(), V, Name)); +} + +LLVMValueRef LLVMBuildLoad2(LLVMBuilderRef B, LLVMTypeRef Ty, +                            LLVMValueRef PointerVal, const char *Name) { +  return wrap(unwrap(B)->CreateLoad(unwrap(Ty), unwrap(PointerVal), Name));  }  LLVMValueRef LLVMBuildStore(LLVMBuilderRef B, LLVMValueRef Val, @@ -3093,20 +3413,50 @@ LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,                            LLVMValueRef *Indices, unsigned NumIndices,                            const char *Name) {    ArrayRef<Value *> IdxList(unwrap(Indices), NumIndices); -  return wrap(unwrap(B)->CreateGEP(nullptr, unwrap(Pointer), IdxList, Name)); +  Value *Val = unwrap(Pointer); +  Type *Ty = +      cast<PointerType>(Val->getType()->getScalarType())->getElementType(); +  return wrap(unwrap(B)->CreateGEP(Ty, Val, IdxList, Name)); +} + +LLVMValueRef LLVMBuildGEP2(LLVMBuilderRef B, LLVMTypeRef Ty, +                           LLVMValueRef Pointer, LLVMValueRef *Indices, +                           unsigned NumIndices, const char *Name) { +  ArrayRef<Value *> IdxList(unwrap(Indices), NumIndices); +  return wrap(unwrap(B)->CreateGEP(unwrap(Ty), unwrap(Pointer), IdxList, Name));  }  LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,                                    LLVMValueRef *Indices, unsigned NumIndices,                                    const char *Name) {    ArrayRef<Value *> IdxList(unwrap(Indices), NumIndices); +  Value *Val = unwrap(Pointer); +  Type *Ty = +      cast<PointerType>(Val->getType()->getScalarType())->getElementType(); +  return wrap(unwrap(B)->CreateInBoundsGEP(Ty, Val, IdxList, Name)); +} + +LLVMValueRef LLVMBuildInBoundsGEP2(LLVMBuilderRef B, LLVMTypeRef Ty, +                                   LLVMValueRef Pointer, LLVMValueRef *Indices, +                                   unsigned NumIndices, const char *Name) { +  ArrayRef<Value *> IdxList(unwrap(Indices), NumIndices);    return wrap( -      unwrap(B)->CreateInBoundsGEP(nullptr, unwrap(Pointer), IdxList, Name)); +      unwrap(B)->CreateInBoundsGEP(unwrap(Ty), unwrap(Pointer), IdxList, Name));  }  LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,                                  unsigned Idx, const char *Name) { -  return wrap(unwrap(B)->CreateStructGEP(nullptr, unwrap(Pointer), Idx, Name)); +  Value *Val = unwrap(Pointer); +  Type *Ty = +      cast<PointerType>(Val->getType()->getScalarType())->getElementType(); +  return wrap(unwrap(B)->CreateStructGEP(Ty, Val, Idx, Name)); +} + +LLVMValueRef LLVMBuildStructGEP2(LLVMBuilderRef B, LLVMTypeRef Ty, +                                 LLVMValueRef Pointer, unsigned Idx, +                                 const char *Name) { +  return wrap( +      unwrap(B)->CreateStructGEP(unwrap(Ty), unwrap(Pointer), Idx, Name));  }  LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str, @@ -3248,6 +3598,13 @@ LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef B, LLVMValueRef Val,    return wrap(unwrap(B)->CreatePointerCast(unwrap(Val), unwrap(DestTy), Name));  } +LLVMValueRef LLVMBuildIntCast2(LLVMBuilderRef B, LLVMValueRef Val, +                               LLVMTypeRef DestTy, LLVMBool IsSigned, +                               const char *Name) { +  return wrap( +      unwrap(B)->CreateIntCast(unwrap(Val), unwrap(DestTy), IsSigned, Name)); +} +  LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef B, LLVMValueRef Val,                                LLVMTypeRef DestTy, const char *Name) {    return wrap(unwrap(B)->CreateIntCast(unwrap(Val), unwrap(DestTy), @@ -3284,9 +3641,20 @@ LLVMValueRef LLVMBuildPhi(LLVMBuilderRef B, LLVMTypeRef Ty, const char *Name) {  LLVMValueRef LLVMBuildCall(LLVMBuilderRef B, LLVMValueRef Fn,                             LLVMValueRef *Args, unsigned NumArgs,                             const char *Name) { -  return wrap(unwrap(B)->CreateCall(unwrap(Fn), -                                    makeArrayRef(unwrap(Args), NumArgs), -                                    Name)); +  Value *V = unwrap(Fn); +  FunctionType *FnT = +      cast<FunctionType>(cast<PointerType>(V->getType())->getElementType()); + +  return wrap(unwrap(B)->CreateCall(FnT, unwrap(Fn), +                                    makeArrayRef(unwrap(Args), NumArgs), Name)); +} + +LLVMValueRef LLVMBuildCall2(LLVMBuilderRef B, LLVMTypeRef Ty, LLVMValueRef Fn, +                            LLVMValueRef *Args, unsigned NumArgs, +                            const char *Name) { +  FunctionType *FTy = unwrap<FunctionType>(Ty); +  return wrap(unwrap(B)->CreateCall(FTy, unwrap(Fn), +                                    makeArrayRef(unwrap(Args), NumArgs), Name));  }  LLVMValueRef LLVMBuildSelect(LLVMBuilderRef B, LLVMValueRef If,  | 
