You can see the toy.print here.I have a question.If I printf F32MemRef, it will output all 0,it doesn’t work well.
llvm.mlir.global internal constant @nl("\0A\00") {addr_space = 0 : i32}
llvm.mlir.global internal constant @frmt_spec("%f \00") {addr_space = 0 : i32}
llvm.func @printf(!llvm.ptr<i8>, ...) -> i32
llvm.func @malloc(i64) -> !llvm.ptr<i8>
You can see that the frmt_spec
,in c language %f can be used to output float(f32), but I don’t know why the output result here is all 0.If anyone can help me, I would appreciate it.Thanks!
If I print F64MemRef,it works well.If I want to print I8MemRef, I just need to change %f to %d, but here I wonder why F32MemRef prints 0.
I have made progress on this issue.
// Here is the code I generated in c
%3 = load float, ptr %2, align 4
%4 = fpext float %3 to double // Lifting float to double
%5 = call i32 (ptr, ...) @printf(ptr noundef @.str, double noundef %4)
Since my dialect is running on spike, I have to use printf for the output.I borrowed toy.print.
my_dialect_name.print %aArray : memref<8x8xf32>
// The generated code then looks like this,
// here the printf argument is still a float type,
// this will make the output 0.
%134 = load float, ptr %133, align 4
%135 = call i32 (ptr, ...) @printf(ptr @frmt_spec, float %134)
// Here is the code after my manual modification,
// This will produce the correct output
%134 = load float, ptr %133, align 4
%tmp = fpext float %134 to double
%135 = call i32 (ptr, ...) @printf(ptr @frmt_spec, double %tmp)
I have two questions to ask.
- Why convert float to double?
- How do I change the c++ code?
Because I want to print F32MemRef.I don’t know what to do to get the directive %134 = load float, ptr %133, align 4 generated
.
If anyone can help me, I would appreciate it.Thanks!
I have solved the problem by use ::mlir::LLVM::FPExtOp
.