Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LLVM intrinsic funtions #43

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions ir.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ type (
FloatPredicate C.LLVMRealPredicate
LandingPadClause C.LLVMLandingPadClauseTy
InlineAsmDialect C.LLVMInlineAsmDialect
Intrinsic C.unsigned
)

func (c Context) IsNil() bool { return c.C == nil }
Expand Down Expand Up @@ -2026,3 +2027,65 @@ func (pm PassManager) FinalizeFunc() bool { return C.LLVMFinalizeFunctionPassMan
// the module provider.
// See llvm::PassManagerBase::~PassManagerBase.
func (pm PassManager) Dispose() { C.LLVMDisposePassManager(pm.C) }

//-------------------------------------------------------------------------
// llvm.Intrinsic
//-------------------------------------------------------------------------

// Obtain the intrinsic ID number which matches the given function name.
// See llvm::Function::lookupIntrinsicID.
func IntrinsicID(name string) (in Intrinsic) {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
in = Intrinsic(C.LLVMLookupIntrinsicID(cname, C.size_t(len(name))))
return
}

// Obtain if the intrinsic identified by the given ID is overloaded.
// See llvm::Intrinsic::isOverloaded
func (in Intrinsic) IsOverloaded() bool {
return C.LLVMIntrinsicIsOverloaded(C.unsigned(in)) != 0
}

// Retrieves the name of an intrinsic.
// See llvm::Intrinsic::getName
func (in Intrinsic) GetName() string {
length := C.size_t(0)
cname := C.LLVMIntrinsicGetName(C.unsigned(in), &length)
return C.GoStringN(cname, C.int(length))
}

// Retrieves the type of an intrinsic. For overloaded intrinsics, parameter types must be provided to uniquely identify an overload.
// See llvm::Intrinsic::getType
func (c Context) GetIntrinsicType(in Intrinsic, paramTypes []Type) (t Type) {
var pt *C.LLVMTypeRef
if paramTypes != nil {
pt = llvmTypeRefPtr(&paramTypes[0])
}
t.C = C.LLVMIntrinsicGetType(c.C, C.unsigned(in), pt, C.size_t(len(paramTypes)))
return
}

// Create or insert the declaration of an intrinsic. For overloaded intrinsics, parameter types must be provided to uniquely identify an overload.
// See llvm::Intrinsic::getDeclaration
func (m Module) GetIntrinsic(in Intrinsic, paramTypes []Type) (v Value) {
var pt *C.LLVMTypeRef
if paramTypes != nil {
pt = llvmTypeRefPtr(&paramTypes[0])
}
v.C = C.LLVMGetIntrinsicDeclaration(m.C, C.unsigned(in), pt, C.size_t(len(paramTypes)))
return
}

// Copies the name of an overloaded intrinsic identified by a given list of parameter types.
// See llvm::Intrinsic::getName
func (m Module) CopyOverloadedName(in Intrinsic, paramTypes []Type) string {
var pt *C.LLVMTypeRef
if paramTypes != nil {
pt = llvmTypeRefPtr(&paramTypes[0])
}
lenght := C.size_t(0)
cname := C.LLVMIntrinsicCopyOverloadedName2(m.C, C.unsigned(in), pt, C.size_t(len(paramTypes)), &lenght)
defer C.free(unsafe.Pointer(cname))
return C.GoStringN(cname, C.int(lenght))
}