[mlir][VectorOps] Support string literals in vector.print (#68695)
Printing strings within integration tests is currently quite annoyingly
verbose, and can't be tucked into shared helpers as the types depend on
the length of the string:
```
llvm.mlir.global internal constant @hello_world("Hello, World!\0")
func.func @entry() {
%0 = llvm.mlir.addressof @hello_world : !llvm.ptr<array<14 x i8>>
%1 = llvm.mlir.constant(0 : index) : i64
%2 = llvm.getelementptr %0[%1, %1]
: (!llvm.ptr<array<14 x i8>>, i64, i64) -> !llvm.ptr<i8>
llvm.call @printCString(%2) : (!llvm.ptr<i8>) -> ()
return
}
```
So this patch adds a simple extension to `vector.print` to simplify
this:
```
func.func @entry() {
// Print a vector of characters ;)
vector.print str "Hello, World!"
return
}
```
Most of the logic for this is now shared with `cf.assert` which already
does something similar.
Depends on #68694
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include "mlir/Conversion/VectorToLLVM/ConvertVectorToLLVM.h"
|
||||
|
||||
#include "mlir/Conversion/ArithCommon/AttrToLLVMConverter.h"
|
||||
#include "mlir/Conversion/LLVMCommon/PrintCallHelper.h"
|
||||
#include "mlir/Conversion/LLVMCommon/TypeConverter.h"
|
||||
#include "mlir/Conversion/LLVMCommon/VectorPattern.h"
|
||||
#include "mlir/Dialect/Arith/IR/Arith.h"
|
||||
@@ -1548,7 +1549,10 @@ public:
|
||||
}
|
||||
|
||||
auto punct = printOp.getPunctuation();
|
||||
if (punct != PrintPunctuation::NoPunctuation) {
|
||||
if (auto stringLiteral = printOp.getStringLiteral()) {
|
||||
LLVM::createPrintStrCall(rewriter, loc, parent, "vector_print_str",
|
||||
*stringLiteral, *getTypeConverter());
|
||||
} else if (punct != PrintPunctuation::NoPunctuation) {
|
||||
emitCall(rewriter, printOp->getLoc(), [&] {
|
||||
switch (punct) {
|
||||
case PrintPunctuation::Close:
|
||||
|
||||
Reference in New Issue
Block a user