diff --git a/IRBindings.cpp b/IRBindings.cpp index be0a466..7b3dd57 100644 --- a/IRBindings.cpp +++ b/IRBindings.cpp @@ -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; @@ -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 +} diff --git a/IRBindings.h b/IRBindings.h index 80552de..160d293 100644 --- a/IRBindings.h +++ b/IRBindings.h @@ -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 diff --git a/ir.go b/ir.go index efb0de1..a77d9e7 100644 --- a/ir.go +++ b/ir.go @@ -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