Skip to content

Commit 2370907

Browse files
committed
feat: added mod operator in LLVM bridge
1 parent fcf5366 commit 2370907

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

compiler/llvm_ir_bridge/src/insts.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,24 @@ pub fn bridge_llvm_instruction(instruction: MIRBlockHeldInstruction, func: usize
8686
Some(res.into())
8787
},
8888

89+
MIRInstruction::IntegerMod { signed, left, right } => {
90+
let left: BaseMIRValue = MIRIntValue::into(left);
91+
let right: BaseMIRValue = MIRIntValue::into(right);
92+
93+
let l = bridge.values[&left.get_ssa_index()].clone();
94+
let r = bridge.values[&right.get_ssa_index()].clone();
95+
96+
let res: IntValue<'static>;
97+
98+
if signed {
99+
res = llvm_to_base!(bridge.builder.build_int_signed_rem(l.into_int_value(), r.into_int_value(), ""))
100+
} else {
101+
res = llvm_to_base!(bridge.builder.build_int_unsigned_rem(l.into_int_value(), r.into_int_value(), ""))
102+
}
103+
104+
Some(res.into())
105+
}
106+
89107
MIRInstruction::FloatAdd { signed: _, left, right } => {
90108
let left: BaseMIRValue = MIRFloatValue::into(left);
91109
let right: BaseMIRValue = MIRFloatValue::into(right);
@@ -134,6 +152,18 @@ pub fn bridge_llvm_instruction(instruction: MIRBlockHeldInstruction, func: usize
134152
Some(res.into())
135153
},
136154

155+
MIRInstruction::FloatMod { signed: _, left, right } => {
156+
let left: BaseMIRValue = MIRFloatValue::into(left);
157+
let right: BaseMIRValue = MIRFloatValue::into(right);
158+
159+
let l = bridge.values[&left.get_ssa_index()].clone();
160+
let r = bridge.values[&right.get_ssa_index()].clone();
161+
162+
let res: FloatValue<'static> = llvm_to_base!(bridge.builder.build_float_rem(l.into_float_value(), r.into_float_value(), ""));
163+
164+
Some(res.into())
165+
}
166+
137167
MIRInstruction::BitwiseAnd { a, b } => {
138168
let left: BaseMIRValue = MIRIntValue::into(a);
139169
let right: BaseMIRValue = MIRIntValue::into(b);

0 commit comments

Comments
 (0)