Switch to the LLVMBuildGEPWithNoWrapFlags API
This API allows us to set the nuw flag as well.
This commit is contained in:
parent
3b022d8cee
commit
5e9d8a7d55
3 changed files with 36 additions and 12 deletions
|
@ -32,7 +32,7 @@ use crate::abi::FnAbiLlvmExt;
|
||||||
use crate::attributes;
|
use crate::attributes;
|
||||||
use crate::common::Funclet;
|
use crate::common::Funclet;
|
||||||
use crate::context::{CodegenCx, SimpleCx};
|
use crate::context::{CodegenCx, SimpleCx};
|
||||||
use crate::llvm::{self, AtomicOrdering, AtomicRmwBinOp, BasicBlock, False, Metadata, True};
|
use crate::llvm::{self, AtomicOrdering, AtomicRmwBinOp, BasicBlock, False, GEPNoWrapFlags, Metadata, True};
|
||||||
use crate::type_::Type;
|
use crate::type_::Type;
|
||||||
use crate::type_of::LayoutLlvmExt;
|
use crate::type_of::LayoutLlvmExt;
|
||||||
use crate::value::Value;
|
use crate::value::Value;
|
||||||
|
@ -908,13 +908,14 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
|
||||||
|
|
||||||
fn gep(&mut self, ty: &'ll Type, ptr: &'ll Value, indices: &[&'ll Value]) -> &'ll Value {
|
fn gep(&mut self, ty: &'ll Type, ptr: &'ll Value, indices: &[&'ll Value]) -> &'ll Value {
|
||||||
unsafe {
|
unsafe {
|
||||||
llvm::LLVMBuildGEP2(
|
llvm::LLVMBuildGEPWithNoWrapFlags(
|
||||||
self.llbuilder,
|
self.llbuilder,
|
||||||
ty,
|
ty,
|
||||||
ptr,
|
ptr,
|
||||||
indices.as_ptr(),
|
indices.as_ptr(),
|
||||||
indices.len() as c_uint,
|
indices.len() as c_uint,
|
||||||
UNNAMED,
|
UNNAMED,
|
||||||
|
GEPNoWrapFlags::default(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -926,13 +927,14 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
|
||||||
indices: &[&'ll Value],
|
indices: &[&'ll Value],
|
||||||
) -> &'ll Value {
|
) -> &'ll Value {
|
||||||
unsafe {
|
unsafe {
|
||||||
llvm::LLVMBuildInBoundsGEP2(
|
llvm::LLVMBuildGEPWithNoWrapFlags(
|
||||||
self.llbuilder,
|
self.llbuilder,
|
||||||
ty,
|
ty,
|
||||||
ptr,
|
ptr,
|
||||||
indices.as_ptr(),
|
indices.as_ptr(),
|
||||||
indices.len() as c_uint,
|
indices.len() as c_uint,
|
||||||
UNNAMED,
|
UNNAMED,
|
||||||
|
GEPNoWrapFlags::InBounds,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -954,6 +954,17 @@ bitflags! {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// These values **must** match with LLVMGEPNoWrapFlags
|
||||||
|
bitflags! {
|
||||||
|
#[repr(transparent)]
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct GEPNoWrapFlags : c_uint {
|
||||||
|
const InBounds = 1 << 0;
|
||||||
|
const NUSW = 1 << 1;
|
||||||
|
const NUW = 1 << 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
unsafe extern "C" {
|
unsafe extern "C" {
|
||||||
pub type ModuleBuffer;
|
pub type ModuleBuffer;
|
||||||
}
|
}
|
||||||
|
@ -1454,21 +1465,14 @@ unsafe extern "C" {
|
||||||
|
|
||||||
pub(crate) fn LLVMBuildStore<'a>(B: &Builder<'a>, Val: &'a Value, Ptr: &'a Value) -> &'a Value;
|
pub(crate) fn LLVMBuildStore<'a>(B: &Builder<'a>, Val: &'a Value, Ptr: &'a Value) -> &'a Value;
|
||||||
|
|
||||||
pub(crate) fn LLVMBuildGEP2<'a>(
|
pub(crate) fn LLVMBuildGEPWithNoWrapFlags<'a>(
|
||||||
B: &Builder<'a>,
|
|
||||||
Ty: &'a Type,
|
|
||||||
Pointer: &'a Value,
|
|
||||||
Indices: *const &'a Value,
|
|
||||||
NumIndices: c_uint,
|
|
||||||
Name: *const c_char,
|
|
||||||
) -> &'a Value;
|
|
||||||
pub(crate) fn LLVMBuildInBoundsGEP2<'a>(
|
|
||||||
B: &Builder<'a>,
|
B: &Builder<'a>,
|
||||||
Ty: &'a Type,
|
Ty: &'a Type,
|
||||||
Pointer: &'a Value,
|
Pointer: &'a Value,
|
||||||
Indices: *const &'a Value,
|
Indices: *const &'a Value,
|
||||||
NumIndices: c_uint,
|
NumIndices: c_uint,
|
||||||
Name: *const c_char,
|
Name: *const c_char,
|
||||||
|
Flags: GEPNoWrapFlags,
|
||||||
) -> &'a Value;
|
) -> &'a Value;
|
||||||
|
|
||||||
// Casts
|
// Casts
|
||||||
|
|
|
@ -1767,6 +1767,24 @@ extern "C" LLVMValueRef LLVMRustBuildMaxNum(LLVMBuilderRef B, LLVMValueRef LHS,
|
||||||
return wrap(unwrap(B)->CreateMaxNum(unwrap(LHS), unwrap(RHS)));
|
return wrap(unwrap(B)->CreateMaxNum(unwrap(LHS), unwrap(RHS)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if LLVM_VERSION_LT(19, 0)
|
||||||
|
enum {
|
||||||
|
LLVMGEPFlagInBounds = (1 << 0),
|
||||||
|
LLVMGEPFlagNUSW = (1 << 1),
|
||||||
|
LLVMGEPFlagNUW = (1 << 2),
|
||||||
|
};
|
||||||
|
extern "C" LLVMValueRef
|
||||||
|
LLVMBuildGEPWithNoWrapFlags(LLVMBuilderRef B, LLVMTypeRef Ty,
|
||||||
|
LLVMValueRef Pointer, LLVMValueRef *Indices,
|
||||||
|
unsigned NumIndices, const char *Name,
|
||||||
|
unsigned NoWrapFlags) {
|
||||||
|
if (NoWrapFlags & LLVMGEPFlagInBounds)
|
||||||
|
return LLVMBuildInBoundsGEP2(B, Ty, Pointer, Indices, NumIndices, Name);
|
||||||
|
else
|
||||||
|
return LLVMBuildGEP2(B, Ty, Pointer, Indices, NumIndices, Name);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Transfers ownership of DiagnosticHandler unique_ptr to the caller.
|
// Transfers ownership of DiagnosticHandler unique_ptr to the caller.
|
||||||
extern "C" DiagnosticHandler *
|
extern "C" DiagnosticHandler *
|
||||||
LLVMRustContextGetDiagnosticHandler(LLVMContextRef C) {
|
LLVMRustContextGetDiagnosticHandler(LLVMContextRef C) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue