Skip to content

Commit

Permalink
Add ImmutableString str
Browse files Browse the repository at this point in the history
The global variable created from ImmutableString must have str name. or
it can not be used  from inlineFunction
  • Loading branch information
jiaolu authored and tsymalla-AMD committed Jun 25, 2024
1 parent ec61062 commit f38c271
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion include/llvm-dialects/Dialect/Dialect.td
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def : AttrLlvmType<AttrI32, I32>;
def : AttrLlvmType<AttrI64, I64>;

def ImmutableStringAttr : Attr<"::llvm::StringRef"> {
let toLlvmValue = [{ $_builder.CreateGlobalString($0) }];
let toLlvmValue = [{ $_builder.CreateGlobalString($0, "str") }];
let fromLlvmValue = [{ ::llvm::cast<::llvm::ConstantDataArray>(::llvm::cast<::llvm::GlobalVariable>($0)->getInitializer())->getAsString() }];
let isImmutable = true;
}
Expand Down
2 changes: 1 addition & 1 deletion test/example/generated/ExampleDialect.cpp.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2064,7 +2064,7 @@ initial


::llvm::SmallVector<::llvm::Value*, 1> args = {
b.CreateGlobalString(val)
b.CreateGlobalString(val, "str")
};

return ::llvm::cast<StringAttrOp>(b.CreateCall(fn, args, instName));
Expand Down
4 changes: 2 additions & 2 deletions test/example/test-builder.test
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
; RUN: llvm-dialects-example - | FileCheck --check-prefixes=CHECK %s

;.
; CHECK: @[[GLOB0:[0-9]+]] = private unnamed_addr constant [13 x i8] c"Hello world!\00", align 1
; CHECK: @[[GLOB0:.*]] = private unnamed_addr constant [13 x i8] c"Hello world!\00", align 1
;.
; CHECK-LABEL: @example(
; CHECK-NEXT: entry:
Expand Down Expand Up @@ -45,6 +45,6 @@
; CHECK-NEXT: [[TWO_VARARGS:%.*]] = call i32 (...) @xd.inst.name.conflict.varargs(ptr [[P1]], i8 [[P2]])
; CHECK-NEXT: [[THREE_VARARGS:%.*]] = call i32 (...) @xd.inst.name.conflict.varargs(ptr [[P1]], i8 [[P2]], i32 3)
; CHECK-NEXT: [[FOUR_VARARGS:%.*]] = call i32 (...) @xd.inst.name.conflict.varargs(ptr [[P1]], i8 [[P2]], i32 3, i32 4)
; CHECK-NEXT: call void @xd.string.attr.op(ptr @[[GLOB0:[0-9]+]])
; CHECK-NEXT: call void @xd.string.attr.op(ptr @[[GLOB0]])
; CHECK-NEXT: ret void
;

0 comments on commit f38c271

Please sign in to comment.