Skip to content

Commit 9c870b3

Browse files
committed
auto merge of #14306 : luqmana/rust/up-llvm, r=alexcrichton
We can now mark arguments and returns as `nonnull` in LLVM. It's still somewhat limited by the fact that LLVM loses this information after inlining but it might help in certain cases.
2 parents 12e80f1 + 3cae434 commit 9c870b3

File tree

14 files changed

+279
-281
lines changed

14 files changed

+279
-281
lines changed

src/librustc/lib/llvm.rs

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use std::c_str::ToCStr;
1616
use std::cell::RefCell;
1717
use collections::HashMap;
18-
use libc::{c_uint, c_ushort, c_void, free};
18+
use libc::{c_uint, c_ushort, c_void, free, uint64_t};
1919
use std::str::raw::from_c_str;
2020

2121
use middle::trans::type_::Type;
@@ -92,6 +92,33 @@ pub enum Attribute {
9292
NonLazyBindAttribute = 1 << 31,
9393
}
9494

95+
#[repr(u64)]
96+
pub enum OtherAttribute {
97+
// The following are not really exposed in
98+
// the LLVM c api so instead to add these
99+
// we call a wrapper function in RustWrapper
100+
// that uses the C++ api.
101+
SanitizeAddressAttribute = 1 << 32,
102+
MinSizeAttribute = 1 << 33,
103+
NoDuplicateAttribute = 1 << 34,
104+
StackProtectStrongAttribute = 1 << 35,
105+
SanitizeThreadAttribute = 1 << 36,
106+
SanitizeMemoryAttribute = 1 << 37,
107+
NoBuiltinAttribute = 1 << 38,
108+
ReturnedAttribute = 1 << 39,
109+
ColdAttribute = 1 << 40,
110+
BuiltinAttribute = 1 << 41,
111+
OptimizeNoneAttribute = 1 << 42,
112+
InAllocaAttribute = 1 << 43,
113+
NonNullAttribute = 1 << 44,
114+
}
115+
116+
#[repr(C)]
117+
pub enum AttributeSet {
118+
ReturnIndex = 0,
119+
FunctionIndex = !0
120+
}
121+
95122
// enum for the LLVM IntPredicate type
96123
pub enum IntPredicate {
97124
IntEQ = 32,
@@ -308,7 +335,7 @@ pub mod llvm {
308335
use super::{CodeGenModel, RelocMode, CodeGenOptLevel};
309336
use super::debuginfo::*;
310337
use libc::{c_char, c_int, c_longlong, c_ushort, c_uint, c_ulonglong,
311-
size_t};
338+
size_t, uint64_t};
312339

313340
// Link to our native llvm bindings (things that we need to use the C++ api
314341
// for) and because llvm is written in C++ we need to link against libstdc++
@@ -706,20 +733,11 @@ pub mod llvm {
706733
pub fn LLVMSetFunctionCallConv(Fn: ValueRef, CC: c_uint);
707734
pub fn LLVMGetGC(Fn: ValueRef) -> *c_char;
708735
pub fn LLVMSetGC(Fn: ValueRef, Name: *c_char);
709-
pub fn LLVMAddFunctionAttr(Fn: ValueRef, PA: c_uint);
710-
pub fn LLVMAddFunctionAttrString(Fn: ValueRef, Name: *c_char);
711-
pub fn LLVMRemoveFunctionAttrString(Fn: ValueRef, Name: *c_char);
736+
pub fn LLVMAddFunctionAttribute(Fn: ValueRef, index: c_uint, PA: uint64_t);
737+
pub fn LLVMAddFunctionAttrString(Fn: ValueRef, index: c_uint, Name: *c_char);
738+
pub fn LLVMRemoveFunctionAttrString(Fn: ValueRef, index: c_uint, Name: *c_char);
712739
pub fn LLVMGetFunctionAttr(Fn: ValueRef) -> c_ulonglong;
713740

714-
pub fn LLVMAddReturnAttribute(Fn: ValueRef, PA: c_uint);
715-
pub fn LLVMRemoveReturnAttribute(Fn: ValueRef, PA: c_uint);
716-
717-
pub fn LLVMAddColdAttribute(Fn: ValueRef);
718-
719-
pub fn LLVMRemoveFunctionAttr(Fn: ValueRef,
720-
PA: c_ulonglong,
721-
HighPA: c_ulonglong);
722-
723741
/* Operations on parameters */
724742
pub fn LLVMCountParams(Fn: ValueRef) -> c_uint;
725743
pub fn LLVMGetParams(Fn: ValueRef, Params: *ValueRef);
@@ -783,6 +801,9 @@ pub mod llvm {
783801
pub fn LLVMSetInstrParamAlignment(Instr: ValueRef,
784802
index: c_uint,
785803
align: c_uint);
804+
pub fn LLVMAddCallSiteAttribute(Instr: ValueRef,
805+
index: c_uint,
806+
Val: uint64_t);
786807

787808
/* Operations on call instructions (only) */
788809
pub fn LLVMIsTailCall(CallInst: ValueRef) -> Bool;
@@ -1835,7 +1856,7 @@ pub fn ConstFCmp(pred: RealPredicate, v1: ValueRef, v2: ValueRef) -> ValueRef {
18351856

18361857
pub fn SetFunctionAttribute(fn_: ValueRef, attr: Attribute) {
18371858
unsafe {
1838-
llvm::LLVMAddFunctionAttr(fn_, attr as c_uint)
1859+
llvm::LLVMAddFunctionAttribute(fn_, FunctionIndex as c_uint, attr as uint64_t)
18391860
}
18401861
}
18411862
/* Memory-managed object interface to type handles. */

0 commit comments

Comments
 (0)