inline llvm ir is allowed, but the user needs to make sure it doesnt violate nvvm ir constraints
(
&mut self,
ia: &LlvmInlineAsmInner,
outputs: Vec<PlaceRef<'tcx, &'ll Value>>,
mut inputs: Vec<&'ll Value>,
span: Span,
)
| 24 | // inline llvm ir is allowed, but the user needs to make sure it doesnt violate |
| 25 | // nvvm ir constraints |
| 26 | fn codegen_llvm_inline_asm( |
| 27 | &mut self, |
| 28 | ia: &LlvmInlineAsmInner, |
| 29 | outputs: Vec<PlaceRef<'tcx, &'ll Value>>, |
| 30 | mut inputs: Vec<&'ll Value>, |
| 31 | span: Span, |
| 32 | ) -> bool { |
| 33 | let mut ext_constraints = vec![]; |
| 34 | let mut output_types = vec![]; |
| 35 | |
| 36 | // Prepare the output operands |
| 37 | let mut indirect_outputs = vec![]; |
| 38 | for (i, (out, &place)) in ia.outputs.iter().zip(&outputs).enumerate() { |
| 39 | if out.is_rw { |
| 40 | let operand = self.load_operand(place); |
| 41 | if let OperandValue::Immediate(_) = operand.val { |
| 42 | inputs.push(operand.immediate()); |
| 43 | } |
| 44 | ext_constraints.push(i.to_string()); |
| 45 | } |
| 46 | if out.is_indirect { |
| 47 | let operand = self.load_operand(place); |
| 48 | if let OperandValue::Immediate(_) = operand.val { |
| 49 | indirect_outputs.push(operand.immediate()); |
| 50 | } |
| 51 | } else { |
| 52 | output_types.push(place.layout.llvm_type(self.cx)); |
| 53 | } |
| 54 | } |
| 55 | if !indirect_outputs.is_empty() { |
| 56 | indirect_outputs.extend_from_slice(&inputs); |
| 57 | inputs = indirect_outputs; |
| 58 | } |
| 59 | |
| 60 | let clobbers = ia.clobbers.iter().map(|s| format!("~{{{}}}", &s)); |
| 61 | |
| 62 | let all_constraints = ia |
| 63 | .outputs |
| 64 | .iter() |
| 65 | .map(|out| out.constraint.to_string()) |
| 66 | .chain(ia.inputs.iter().map(|s| s.to_string())) |
| 67 | .chain(ext_constraints) |
| 68 | .chain(clobbers) |
| 69 | .collect::<Vec<String>>() |
| 70 | .join(","); |
| 71 | |
| 72 | // Depending on how many outputs we have, the return type is different |
| 73 | let num_outputs = output_types.len(); |
| 74 | let output_type = match num_outputs { |
| 75 | 0 => self.type_void(), |
| 76 | 1 => output_types[0], |
| 77 | _ => self.type_struct(&output_types, false), |
| 78 | }; |
| 79 | |
| 80 | let asm = ia.asm.as_str(); |
| 81 | let r = inline_asm_call( |
| 82 | self, |
| 83 | &asm, |
nothing calls this directly
no test coverage detected