llvm / clangir

A new (MLIR based) high-level IR for clang.
https://clangir.org
Other
307 stars 84 forks source link

[CIR] Vector constants #700

Closed dkolsen-pgi closed 2 days ago

dkolsen-pgi commented 1 week ago

Implement vector constants in ClangIR.

Resolves issue #498 - Add a cir.const_vec, simlar to cir.const_array and cir.const_struct

Create a new kind of attribute, cir::ConstVectorAttr in the code or #cir.const_vector in the assembly, which represents a compile-time value of a cir::VectorType. The values for the elements within the vector are stored as attributes within an mlir::ArrayAttr.

When doing CodeGen for a prvalue of vector type, try to represent it as cir.const #cir.const_vector first. If that fails, most likely because some of the elements are not compile-time values, fall back to the existing code that uses a cir.vec.create operation.

When lowering directly to LLVM IR, lower cir.const #cir.const_vector as llvm.mlir.constant(dense<[...]> : _type_) : _type_.

When lowering through other MLIR dialects, lower cir.const #cir.const_vector as arith.constant dense<[...]> : _type_.

No new tests were added, but the expected results of the existing tests that use vector constants were updated.

dkolsen-pgi commented 6 days ago

I resolved the code review requests, except for VecCreateOp::fold. Would you like me to do that now, or separately?

bcardosolopes commented 6 days ago

I resolved the code review requests, except for VecCreateOp::fold. Would you like me to do that now, or separately?

That can come next! Good to go after resolving conflicts.

dkolsen-pgi commented 4 days ago

I rebased my branch (with manual work to avoid the deprecated isa/cast/dyn_cast functions). It should now be free of conflicts.