diff options
Diffstat (limited to 'lib/IR/Core.cpp')
-rw-r--r-- | lib/IR/Core.cpp | 158 |
1 files changed, 139 insertions, 19 deletions
diff --git a/lib/IR/Core.cpp b/lib/IR/Core.cpp index 815797f4b7ea..310935b5213a 100644 --- a/lib/IR/Core.cpp +++ b/lib/IR/Core.cpp @@ -1,9 +1,8 @@ //===-- Core.cpp ----------------------------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -1037,6 +1036,16 @@ LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty) { /*--.. Operations on metadata nodes ........................................--*/ +LLVMMetadataRef LLVMMDStringInContext2(LLVMContextRef C, const char *Str, + size_t SLen) { + return wrap(MDString::get(*unwrap(C), StringRef(Str, SLen))); +} + +LLVMMetadataRef LLVMMDNodeInContext2(LLVMContextRef C, LLVMMetadataRef *MDs, + size_t Count) { + return wrap(MDNode::get(*unwrap(C), ArrayRef<Metadata*>(unwrap(MDs), Count))); +} + LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str, unsigned SLen) { LLVMContext &Context = *unwrap(C); @@ -1200,15 +1209,17 @@ void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char *Name, 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)) { + if (const auto *I = dyn_cast<Instruction>(unwrap(Val))) { + if (const auto &DL = I->getDebugLoc()) { + S = DL->getDirectory(); + } + } else if (const auto *GV = dyn_cast<GlobalVariable>(unwrap(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)) { + } else if (const auto *F = dyn_cast<Function>(unwrap(Val))) { if (const DISubprogram *DSP = F->getSubprogram()) S = DSP->getDirectory(); } else { @@ -1222,15 +1233,17 @@ const char *LLVMGetDebugLocDirectory(LLVMValueRef Val, unsigned *Length) { 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)) { + if (const auto *I = dyn_cast<Instruction>(unwrap(Val))) { + if (const auto &DL = I->getDebugLoc()) { + S = DL->getFilename(); + } + } else if (const auto *GV = dyn_cast<GlobalVariable>(unwrap(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)) { + } else if (const auto *F = dyn_cast<Function>(unwrap(Val))) { if (const DISubprogram *DSP = F->getSubprogram()) S = DSP->getFilename(); } else { @@ -1243,15 +1256,17 @@ const char *LLVMGetDebugLocFilename(LLVMValueRef Val, unsigned *Length) { 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)) { + if (const auto *I = dyn_cast<Instruction>(unwrap(Val))) { + if (const auto &DL = I->getDebugLoc()) { + L = DL->getLine(); + } + } else if (const auto *GV = dyn_cast<GlobalVariable>(unwrap(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)) { + } else if (const auto *F = dyn_cast<Function>(unwrap(Val))) { if (const DISubprogram *DSP = F->getSubprogram()) L = DSP->getLine(); } else { @@ -1263,9 +1278,9 @@ unsigned LLVMGetDebugLocLine(LLVMValueRef Val) { unsigned LLVMGetDebugLocColumn(LLVMValueRef Val) { unsigned C = 0; - if (const auto *I = unwrap<Instruction>(Val)) - if (const auto &L = I->getDebugLoc()) - C = L->getColumn(); + if (const auto *I = dyn_cast<Instruction>(unwrap(Val))) + if (const auto &DL = I->getDebugLoc()) + C = DL->getColumn(); return C; } @@ -2330,6 +2345,10 @@ const char *LLVMIntrinsicCopyOverloadedName(unsigned ID, return strdup(Str.c_str()); } +unsigned LLVMLookupIntrinsicID(const char *Name, size_t NameLen) { + return Function::lookupIntrinsicID({Name, NameLen}); +} + LLVMBool LLVMIntrinsicIsOverloaded(unsigned ID) { auto IID = llvm_map_to_intrinsic_id(ID); return llvm::Intrinsic::isOverloaded(IID); @@ -2464,6 +2483,71 @@ void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align) { A->addAttr(Attribute::getWithAlignment(A->getContext(), align)); } +/*--.. Operations on ifuncs ................................................--*/ + +LLVMValueRef LLVMAddGlobalIFunc(LLVMModuleRef M, + const char *Name, size_t NameLen, + LLVMTypeRef Ty, unsigned AddrSpace, + LLVMValueRef Resolver) { + return wrap(GlobalIFunc::create(unwrap(Ty), AddrSpace, + GlobalValue::ExternalLinkage, + StringRef(Name, NameLen), + unwrap<Constant>(Resolver), unwrap(M))); +} + +LLVMValueRef LLVMGetNamedGlobalIFunc(LLVMModuleRef M, + const char *Name, size_t NameLen) { + return wrap(unwrap(M)->getNamedIFunc(StringRef(Name, NameLen))); +} + +LLVMValueRef LLVMGetFirstGlobalIFunc(LLVMModuleRef M) { + Module *Mod = unwrap(M); + Module::ifunc_iterator I = Mod->ifunc_begin(); + if (I == Mod->ifunc_end()) + return nullptr; + return wrap(&*I); +} + +LLVMValueRef LLVMGetLastGlobalIFunc(LLVMModuleRef M) { + Module *Mod = unwrap(M); + Module::ifunc_iterator I = Mod->ifunc_end(); + if (I == Mod->ifunc_begin()) + return nullptr; + return wrap(&*--I); +} + +LLVMValueRef LLVMGetNextGlobalIFunc(LLVMValueRef IFunc) { + GlobalIFunc *GIF = unwrap<GlobalIFunc>(IFunc); + Module::ifunc_iterator I(GIF); + if (++I == GIF->getParent()->ifunc_end()) + return nullptr; + return wrap(&*I); +} + +LLVMValueRef LLVMGetPreviousGlobalIFunc(LLVMValueRef IFunc) { + GlobalIFunc *GIF = unwrap<GlobalIFunc>(IFunc); + Module::ifunc_iterator I(GIF); + if (I == GIF->getParent()->ifunc_begin()) + return nullptr; + return wrap(&*--I); +} + +LLVMValueRef LLVMGetGlobalIFuncResolver(LLVMValueRef IFunc) { + return wrap(unwrap<GlobalIFunc>(IFunc)->getResolver()); +} + +void LLVMSetGlobalIFuncResolver(LLVMValueRef IFunc, LLVMValueRef Resolver) { + unwrap<GlobalIFunc>(IFunc)->setResolver(unwrap<Constant>(Resolver)); +} + +void LLVMEraseGlobalIFunc(LLVMValueRef IFunc) { + unwrap<GlobalIFunc>(IFunc)->eraseFromParent(); +} + +void LLVMRemoveGlobalIFunc(LLVMValueRef IFunc) { + unwrap<GlobalIFunc>(IFunc)->removeFromParent(); +} + /*--.. Operations on basic blocks ..........................................--*/ LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB) { @@ -2541,6 +2625,20 @@ LLVMBasicBlockRef LLVMCreateBasicBlockInContext(LLVMContextRef C, return wrap(llvm::BasicBlock::Create(*unwrap(C), Name)); } +void LLVMInsertExistingBasicBlockAfterInsertBlock(LLVMBuilderRef Builder, + LLVMBasicBlockRef BB) { + BasicBlock *ToInsert = unwrap(BB); + BasicBlock *CurBB = unwrap(Builder)->GetInsertBlock(); + assert(CurBB && "current insertion point is invalid!"); + CurBB->getParent()->getBasicBlockList().insertAfter(CurBB->getIterator(), + ToInsert); +} + +void LLVMAppendExistingBasicBlock(LLVMValueRef Fn, + LLVMBasicBlockRef BB) { + unwrap<Function>(Fn)->getBasicBlockList().push_back(unwrap(BB)); +} + LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C, LLVMValueRef FnRef, const char *Name) { @@ -2924,6 +3022,17 @@ void LLVMDisposeBuilder(LLVMBuilderRef Builder) { /*--.. Metadata builders ...................................................--*/ +LLVMMetadataRef LLVMGetCurrentDebugLocation2(LLVMBuilderRef Builder) { + return wrap(unwrap(Builder)->getCurrentDebugLocation().getAsMDNode()); +} + +void LLVMSetCurrentDebugLocation2(LLVMBuilderRef Builder, LLVMMetadataRef Loc) { + if (Loc) + unwrap(Builder)->SetCurrentDebugLocation(DebugLoc(unwrap<MDNode>(Loc))); + else + unwrap(Builder)->SetCurrentDebugLocation(DebugLoc()); +} + void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L) { MDNode *Loc = L ? cast<MDNode>(unwrap<MetadataAsValue>(L)->getMetadata()) : nullptr; @@ -2940,6 +3049,17 @@ void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst) { unwrap(Builder)->SetInstDebugLocation(unwrap<Instruction>(Inst)); } +void LLVMBuilderSetDefaultFPMathTag(LLVMBuilderRef Builder, + LLVMMetadataRef FPMathTag) { + + unwrap(Builder)->setDefaultFPMathTag(FPMathTag + ? unwrap<MDNode>(FPMathTag) + : nullptr); +} + +LLVMMetadataRef LLVMBuilderGetDefaultFPMathTag(LLVMBuilderRef Builder) { + return wrap(unwrap(Builder)->getDefaultFPMathTag()); +} /*--.. Instruction builders ................................................--*/ |