MCPcopy Create free account
hub / github.com/Rust-GPU/rust-cuda / codegen_llvm_inline_asm

Method codegen_llvm_inline_asm

crates/rustc_codegen_nvvm/src/asm.rs:26–113  ·  view source on GitHub ↗

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,
    )

Source from the content-addressed store, hash-verified

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,

Callers

nothing calls this directly

Calls 11

inline_asm_callFunction · 0.85
iterMethod · 0.80
load_operandMethod · 0.80
type_voidMethod · 0.80
type_structMethod · 0.80
extract_valueMethod · 0.80
pushMethod · 0.45
llvm_typeMethod · 0.45
is_emptyMethod · 0.45
lenMethod · 0.45
storeMethod · 0.45

Tested by

no test coverage detected