File tree 3 files changed +28
-1
lines changed
include/clang/CIR/Dialect/IR
3 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -2231,7 +2231,8 @@ def GetGlobalOp : CIR_Op<"get_global",
2231
2231
The `cir.get_global` operation retrieves the address pointing to a
2232
2232
named global variable. If the global variable is marked constant, writing
2233
2233
to the resulting address (such as through a `cir.store` operation) is
2234
- undefined. Resulting type must always be a `!cir.ptr<...>` type.
2234
+ undefined. Resulting type must always be a `!cir.ptr<...>` type with the
2235
+ same address space as the global variable.
2235
2236
2236
2237
Addresses of thread local globals can only be retrieved if this operation
2237
2238
is marked `thread_local`, which indicates the address isn't constant.
@@ -2241,6 +2242,9 @@ def GetGlobalOp : CIR_Op<"get_global",
2241
2242
%x = cir.get_global @foo : !cir.ptr<i32>
2242
2243
...
2243
2244
%y = cir.get_global thread_local @batata : !cir.ptr<i32>
2245
+ ...
2246
+ cir.global external addrspace(offload_global) @gv = #cir.int<0> : !s32i
2247
+ %z = cir.get_global @gv : !cir.ptr<!s32i, addrspace(offload_global)>
2244
2248
```
2245
2249
}];
2246
2250
Original file line number Diff line number Diff line change @@ -2044,8 +2044,10 @@ GetGlobalOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
2044
2044
<< " ' does not reference a valid cir.global or cir.func" ;
2045
2045
2046
2046
mlir::Type symTy;
2047
+ mlir::cir::AddressSpaceAttr symAddrSpace{};
2047
2048
if (auto g = dyn_cast<GlobalOp>(op)) {
2048
2049
symTy = g.getSymType ();
2050
+ symAddrSpace = g.getAddrSpaceAttr ();
2049
2051
// Verify that for thread local global access, the global needs to
2050
2052
// be marked with tls bits.
2051
2053
if (getTls () && !g.getTlsModel ())
@@ -2060,6 +2062,14 @@ GetGlobalOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
2060
2062
return emitOpError (" result type pointee type '" )
2061
2063
<< resultType.getPointee () << " ' does not match type " << symTy
2062
2064
<< " of the global @" << getName ();
2065
+
2066
+ if (symAddrSpace != resultType.getAddrSpace ()) {
2067
+ return emitOpError ()
2068
+ << " result type address space does not match the address "
2069
+ " space of the global @"
2070
+ << getName ();
2071
+ }
2072
+
2063
2073
return success ();
2064
2074
}
2065
2075
Original file line number Diff line number Diff line change @@ -1272,3 +1272,16 @@ module {
1272
1272
}
1273
1273
}
1274
1274
1275
+ // -----
1276
+
1277
+ !s32i = !cir.int<s, 32>
1278
+
1279
+ module {
1280
+ cir.global external addrspace(offload_global) @gv = #cir.int<0> : !s32i
1281
+
1282
+ cir.func @test_get_global() {
1283
+ // expected-error@+1 {{'cir.get_global' op result type address space does not match the address space of the global @gv}}
1284
+ %addr = cir.get_global @gv : !cir.ptr<!s32i>
1285
+ cir.return
1286
+ }
1287
+ }
You can’t perform that action at this time.
0 commit comments