Skip to content
Draft
Show file tree
Hide file tree
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
22 changes: 22 additions & 0 deletions IRBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/ConstantRange.h"

using namespace llvm;

Expand Down Expand Up @@ -85,3 +86,24 @@ LLVMValueRef LLVMGoGetInlineAsm(LLVMTypeRef Ty, char *AsmString,
IsAlignStack,
Dialect, CanThrow);
}

LLVMAttributeRef LLVMGoCreateSmallRangeAttribute(
LLVMContextRef C,
unsigned KindID,
unsigned bits,
uint64_t lower,
uint64_t upper
) {
#if LLVM_VERSION_MAJOR >= 19
return wrap(Attribute::get(
*unwrap(C),
(Attribute::AttrKind)KindID,
ConstantRange(
APInt(bits, lower),
APInt(bits, upper)
)
));
#else
return nullptr;
#endif
}
8 changes: 8 additions & 0 deletions IRBindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ LLVMValueRef LLVMGoGetInlineAsm(LLVMTypeRef Ty, char *AsmString,
LLVMBool IsAlignStack,
LLVMInlineAsmDialect Dialect, LLVMBool CanThrow);

LLVMAttributeRef LLVMGoCreateSmallRangeAttribute(
LLVMContextRef C,
unsigned KindID,
unsigned bits,
uint64_t lower,
uint64_t upper
);

#ifdef __cplusplus
}
#endif
Expand Down
5 changes: 5 additions & 0 deletions ir.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,11 @@ func (c Context) CreateTypeAttribute(kind uint, t Type) (a Attribute) {
return
}

func (c Context) CreateSmallRangeAttribute(kind uint, bits uint, lower, upper uint64) (a Attribute) {
a.C = C.LLVMGoCreateSmallRangeAttribute(c.C, C.unsigned(kind), C.unsigned(bits), C.uint64_t(lower), C.uint64_t(upper))
return
}

func (a Attribute) GetTypeValue() (t Type) {
t.C = C.LLVMGetTypeAttributeValue(a.C)
return
Expand Down
Loading