Skip to content

Commit a359647

Browse files
committed
add range attribute to bindings
1 parent 00fb430 commit a359647

3 files changed

Lines changed: 31 additions & 0 deletions

File tree

IRBindings.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "llvm/IR/IRBuilder.h"
1919
#include "llvm/IR/LLVMContext.h"
2020
#include "llvm/IR/Module.h"
21+
#include "llvm/IR/ConstantRange.h"
2122

2223
using namespace llvm;
2324

@@ -85,3 +86,20 @@ LLVMValueRef LLVMGoGetInlineAsm(LLVMTypeRef Ty, char *AsmString,
8586
IsAlignStack,
8687
Dialect, CanThrow);
8788
}
89+
90+
LLVMAttributeRef LLVMGoCreateSmallRangeAttribute(
91+
LLVMContextRef C,
92+
unsigned KindID,
93+
unsigned bits,
94+
uint64_t lower,
95+
uint64_t upper
96+
) {
97+
return wrap(Attribute::get(
98+
*unwrap(C),
99+
(Attribute::AttrKind)KindID,
100+
ConstantRange(
101+
APInt(bits, lower),
102+
APInt(bits, upper)
103+
)
104+
));
105+
}

IRBindings.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ LLVMValueRef LLVMGoGetInlineAsm(LLVMTypeRef Ty, char *AsmString,
5555
LLVMBool IsAlignStack,
5656
LLVMInlineAsmDialect Dialect, LLVMBool CanThrow);
5757

58+
LLVMAttributeRef LLVMGoCreateSmallRangeAttribute(
59+
LLVMContextRef C,
60+
unsigned KindID,
61+
unsigned bits,
62+
uint64_t lower,
63+
uint64_t upper
64+
);
65+
5866
#ifdef __cplusplus
5967
}
6068
#endif

ir.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,11 @@ func (c Context) CreateTypeAttribute(kind uint, t Type) (a Attribute) {
395395
return
396396
}
397397

398+
func (c Context) CreateSmallRangeAttribute(kind uint, bits uint, lower, upper uint64) (a Attribute) {
399+
a.C = C.LLVMGoCreateSmallRangeAttribute(c.C, C.unsigned(kind), C.unsigned(bits), C.uint64_t(lower), C.uint64_t(upper))
400+
return
401+
}
402+
398403
func (a Attribute) GetTypeValue() (t Type) {
399404
t.C = C.LLVMGetTypeAttributeValue(a.C)
400405
return

0 commit comments

Comments
 (0)