Skip to content

Commit 800c8c0

Browse files
vmaksimobader
authored andcommitted
[SYCL][FPGA] Fix address space in generation of global Intel FPGA annotation (#578)
* [SYCL][FPGA] Fix address space in generation of global Intel FPGA annotation Invalid bitcast with different address spaces was emmitted as a first argument of Annotations element. This problem caused assertion fail. * [SYCL] Fix address space in generation of annotate attribute for static vars Invalid bitcast with different address spaces was emmitted as a first field of ConstantStruct. This problem caused assertion fail. Signed-off-by: Viktoria Maksimova <[email protected]>
1 parent f58e2eb commit 800c8c0

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2231,13 +2231,15 @@ llvm::Constant *CodeGenModule::EmitAnnotateAttr(llvm::GlobalValue *GV,
22312231
*UnitGV = EmitAnnotationUnit(L),
22322232
*LineNoCst = EmitAnnotationLineNo(L);
22332233

2234+
llvm::Type *ResType = llvm::PointerType::getInt8PtrTy(
2235+
this->getLLVMContext(), GV->getType()->getPointerAddressSpace());
2236+
22342237
// Create the ConstantStruct for the global annotation.
22352238
llvm::Constant *Fields[4] = {
2236-
llvm::ConstantExpr::getBitCast(GV, Int8PtrTy),
2237-
llvm::ConstantExpr::getBitCast(AnnoGV, Int8PtrTy),
2238-
llvm::ConstantExpr::getBitCast(UnitGV, Int8PtrTy),
2239-
LineNoCst
2240-
};
2239+
llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast(GV, ResType),
2240+
llvm::ConstantExpr::getBitCast(AnnoGV, Int8PtrTy),
2241+
llvm::ConstantExpr::getBitCast(UnitGV, Int8PtrTy),
2242+
LineNoCst};
22412243
return llvm::ConstantStruct::getAnon(Fields);
22422244
}
22432245

@@ -3867,8 +3869,11 @@ void CodeGenModule::addGlobalIntelFPGAAnnotation(const VarDecl *VD,
38673869
*UnitGV = EmitAnnotationUnit(VD->getLocation()),
38683870
*LineNoCst = EmitAnnotationLineNo(VD->getLocation());
38693871

3872+
llvm::Type *ResType = llvm::PointerType::getInt8PtrTy(
3873+
this->getLLVMContext(), GV->getType()->getPointerAddressSpace());
38703874
llvm::Constant *C =
3871-
llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast(GV, Int8PtrTy);
3875+
llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast(GV, ResType);
3876+
38723877
// Create the ConstantStruct for the global annotation.
38733878
llvm::Constant *Fields[4] = {
38743879
C, llvm::ConstantExpr::getBitCast(AnnoGV, Int8PtrTy),

clang/test/CodeGenSYCL/intel-fpga-local.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@
1515
//CHECK: [[ANN7:@.str[\.]*[0-9]*]] = {{.*}}{memory:MLAB}
1616
//CHECK: [[ANN8:@.str[\.]*[0-9]*]] = {{.*}}{memory:DEFAULT}{bankwidth:8}
1717
//CHECK: [[ANN9:@.str[\.]*[0-9]*]] = {{.*}}{memory:DEFAULT}{max_private_copies:4}
18+
//CHECK: [[ANN16:@.str.[0-9]*]] = {{.*}}foobar
1819

1920
//CHECK: @llvm.global.annotations
20-
//CHECK-SAME: a_one{{.*}}[[ANN1]]{{.*}}i32 148
21+
//CHECK-SAME: { i8 addrspace(1)* bitcast (i32 addrspace(1)* @_ZZ3quxiE5a_one to i8 addrspace(1)*)
22+
//CHECK-SAME: [[ANN1]]{{.*}}i32 152
23+
//CHECK-SAME: { i8 addrspace(1)* bitcast (i32 addrspace(1)* @_ZZ3quxiE5b_two to i8 addrspace(1)*)
24+
//CHECK-SAME: [[ANN16]]{{.*}}i32 156
2125

2226
void foo() {
2327
//CHECK: %[[VAR_ONE:[0-9]+]] = bitcast{{.*}}var_one
@@ -145,10 +149,14 @@ void baz() {
145149
}
146150

147151
void qux(int a) {
148-
static int a_one [[intelfpga::numbanks(2)]];
152+
static int a_one [[intelfpga::numbanks(4)]];
149153
//CHECK: load{{.*}}a_one
150154
//CHECK: store{{.*}}a_one
151155
a_one = a_one + a;
156+
static int b_two [[clang::annotate("foobar")]];
157+
//CHECK: load{{.*}}b_two
158+
//CHECK: store{{.*}}b_two
159+
b_two = b_two + a;
152160
}
153161

154162
void field_addrspace_cast() {

0 commit comments

Comments
 (0)