Skip to content

Commit 4100199

Browse files
committed
Initial support for replace all uses with
1 parent 5d48bd5 commit 4100199

File tree

11 files changed

+50
-1
lines changed

11 files changed

+50
-1
lines changed

src/values/array_value.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ impl ArrayValue {
6565
pub fn set_metadata(&self, metadata: &MetadataValue, kind_id: u32) {
6666
self.array_value.set_metadata(metadata, kind_id)
6767
}
68+
69+
pub fn replace_all_uses_with(&self, other: &ArrayValue) {
70+
self.array_value.replace_all_uses_with(other.as_value_ref())
71+
}
6872
}
6973

7074
impl AsValueRef for ArrayValue {

src/values/float_value.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ impl FloatValue {
166166

167167
IntValue::new(value)
168168
}
169+
170+
pub fn replace_all_uses_with(&self, other: &FloatValue) {
171+
self.float_value.replace_all_uses_with(other.as_value_ref())
172+
}
169173
}
170174

171175
impl AsValueRef for FloatValue {

src/values/fn_value.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,10 @@ impl FunctionValue {
302302
LLVMSetGC(self.as_value_ref(), c_string.as_ptr())
303303
}
304304
}
305+
306+
pub fn replace_all_uses_with(&self, other: &FunctionValue) {
307+
self.fn_value.replace_all_uses_with(other.as_value_ref())
308+
}
305309
}
306310

307311
impl AsValueRef for FunctionValue {

src/values/instruction_value.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,11 @@ impl InstructionValue {
228228
LLVMIsTailCall(self.as_value_ref()) == 1
229229
}
230230
}
231+
232+
pub fn replace_all_uses_with(&self, other: &InstructionValue) {
233+
self.instruction_value.replace_all_uses_with(other.as_value_ref())
234+
}
235+
231236
}
232237

233238
impl Clone for InstructionValue {

src/values/int_value.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,10 @@ impl IntValue {
365365

366366
IntValue::new(value)
367367
}
368+
369+
pub fn replace_all_uses_with(&self, other: &IntValue) {
370+
self.int_value.replace_all_uses_with(other.as_value_ref())
371+
}
368372
}
369373

370374
impl AsValueRef for IntValue {

src/values/metadata_value.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ impl MetadataValue {
125125
pub fn print_to_stderr(&self) {
126126
self.metadata_value.print_to_stderr()
127127
}
128+
129+
pub fn replace_all_uses_with(&self, other: &MetadataValue) {
130+
self.metadata_value.replace_all_uses_with(other.as_value_ref())
131+
}
128132
}
129133

130134
impl AsValueRef for MetadataValue {

src/values/mod.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub use values::traits::{AnyValue, AggregateValue, BasicValue};
2727
pub use values::vec_value::VectorValue;
2828
pub(crate) use values::traits::AsValueRef;
2929

30-
use llvm_sys::core::{LLVMGetValueName, LLVMIsConstant, LLVMIsNull, LLVMIsUndef, LLVMPrintTypeToString, LLVMPrintValueToString, LLVMSetGlobalConstant, LLVMSetValueName, LLVMTypeOf, LLVMDumpValue, LLVMIsAInstruction, LLVMGetMetadata, LLVMHasMetadata, LLVMSetMetadata};
30+
use llvm_sys::core::{LLVMGetValueName, LLVMIsConstant, LLVMIsNull, LLVMIsUndef, LLVMPrintTypeToString, LLVMPrintValueToString, LLVMSetGlobalConstant, LLVMSetValueName, LLVMTypeOf, LLVMDumpValue, LLVMIsAInstruction, LLVMGetMetadata, LLVMHasMetadata, LLVMSetMetadata, LLVMReplaceAllUsesWith};
3131
use llvm_sys::prelude::{LLVMValueRef, LLVMTypeRef};
3232

3333
use std::ffi::{CString, CStr};
@@ -141,6 +141,14 @@ impl Value {
141141
}
142142
}
143143

144+
// REVIEW: I think this is memory safe, though it may result in an IR error
145+
// if used incorrectly, which is OK.
146+
fn replace_all_uses_with(&self, other: LLVMValueRef) {
147+
unsafe {
148+
LLVMReplaceAllUsesWith(self.value, other)
149+
}
150+
}
151+
144152
// REVIEW: Remove?
145153
// fn get_type_kind(&self) -> LLVMTypeKind {
146154
// (*self.get_type()).as_llvm_type_ref().get_kind()

src/values/phi_value.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ impl PhiValue {
7979
pub fn as_instruction(&self) -> Option<InstructionValue> {
8080
self.phi_value.as_instruction()
8181
}
82+
83+
pub fn replace_all_uses_with(&self, other: &PhiValue) {
84+
self.phi_value.replace_all_uses_with(other.as_value_ref())
85+
}
8286
}
8387

8488
impl AsValueRef for PhiValue {

src/values/ptr_value.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ impl PointerValue {
110110

111111
PointerValue::new(value)
112112
}
113+
114+
pub fn replace_all_uses_with(&self, other: &PointerValue) {
115+
self.ptr_value.replace_all_uses_with(other.as_value_ref())
116+
}
113117
}
114118

115119
impl AsValueRef for PointerValue {

src/values/struct_value.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ impl StructValue {
6363
pub fn set_metadata(&self, metadata: &MetadataValue, kind_id: u32) {
6464
self.struct_value.set_metadata(metadata, kind_id)
6565
}
66+
67+
pub fn replace_all_uses_with(&self, other: &StructValue) {
68+
self.struct_value.replace_all_uses_with(other.as_value_ref())
69+
}
6670
}
6771

6872
impl AsValueRef for StructValue {

src/values/vec_value.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ impl VectorValue {
9898
pub fn set_metadata(&self, metadata: &MetadataValue, kind_id: u32) {
9999
self.vec_value.set_metadata(metadata, kind_id)
100100
}
101+
102+
pub fn replace_all_uses_with(&self, other: &VectorValue) {
103+
self.vec_value.replace_all_uses_with(other.as_value_ref())
104+
}
101105
}
102106

103107
impl AsValueRef for VectorValue {

0 commit comments

Comments
 (0)