Skip to content

Commit c641166

Browse files
authored
[clang-offload-wrapper] Do not create .tgtimg section with -emit-reg-funcs=0 (#4577)
With -emit-reg-funcs=0 wrapped images will not be registered at offloading runtime, therefore they also should not be added to the .tgtimg section. Signed-off-by: Sergey Dmitriev <[email protected]>
1 parent c8c5163 commit c641166

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

clang/test/Driver/clang-offload-wrapper.c

+1
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@
191191
// CHECK-IR1: [[DESCTY:%.+]] = type { i16, i16, [[IMAGETY]]*, [[ENTTY]]*, [[ENTTY]]* }
192192
// CHECK-IR1-NOT: @llvm.global_ctors
193193
// CHECK-IR1-NOT: @llvm.global_dtors
194+
// CHECK-IR1-NOT: section ".tgtimg"
194195
// CHECK-IR1: @.sycl_offloading.lalala = constant [[DESCTY]] { i16 {{[0-9]+}}, i16 1, [[IMAGETY]]* getelementptr inbounds ([1 x [[IMAGETY]]], [1 x [[IMAGETY]]]* @.sycl_offloading.device_images, i64 0, i64 0), [[ENTTY]]* null, [[ENTTY]]* null }
195196

196197
// -------

clang/tools/clang-offload-wrapper/ClangOffloadWrapper.cpp

+23-20
Original file line numberDiff line numberDiff line change
@@ -997,26 +997,29 @@ class BinaryWrapper {
997997
ImagesInits.push_back(ConstantStruct::get(
998998
getDeviceImageTy(), Fbin.first, Fbin.second, EntriesB, EntriesE));
999999

1000-
// Create an object that holds <address, size> pair for the device image
1001-
// and put it into a .tgtimg section. This section can be used for finding
1002-
// and extracting all device images from the fat binary after linking.
1003-
Type *IntPtrTy = M.getDataLayout().getIntPtrType(C);
1004-
auto *ImgInfoArr = ConstantArray::get(
1005-
ArrayType::get(IntPtrTy, 2),
1006-
{ConstantExpr::getPointerCast(Fbin.first, IntPtrTy),
1007-
ConstantInt::get(IntPtrTy, Bin->getBufferSize())});
1008-
auto *ImgInfoVar = new GlobalVariable(
1009-
M, ImgInfoArr->getType(), /*isConstant*/ true,
1010-
GlobalVariable::InternalLinkage, ImgInfoArr,
1011-
Twine(OffloadKindTag) + Twine(ImgId) + Twine(".info"));
1012-
ImgInfoVar->setAlignment(
1013-
MaybeAlign(M.getDataLayout().getTypeStoreSize(IntPtrTy) * 2u));
1014-
ImgInfoVar->setUnnamedAddr(GlobalValue::UnnamedAddr::Local);
1015-
ImgInfoVar->setSection(".tgtimg");
1016-
1017-
// Add image info to the used list to force it to be emitted to the
1018-
// object.
1019-
appendToUsed(M, ImgInfoVar);
1000+
if (EmitRegFuncs) {
1001+
// Create an object that holds <address, size> pair for the device image
1002+
// and put it into a .tgtimg section. This section can be used for
1003+
// finding and extracting all device images from the fat binary after
1004+
// linking.
1005+
Type *IntPtrTy = M.getDataLayout().getIntPtrType(C);
1006+
auto *ImgInfoArr = ConstantArray::get(
1007+
ArrayType::get(IntPtrTy, 2),
1008+
{ConstantExpr::getPointerCast(Fbin.first, IntPtrTy),
1009+
ConstantInt::get(IntPtrTy, Bin->getBufferSize())});
1010+
auto *ImgInfoVar = new GlobalVariable(
1011+
M, ImgInfoArr->getType(), /*isConstant*/ true,
1012+
GlobalVariable::InternalLinkage, ImgInfoArr,
1013+
Twine(OffloadKindTag) + Twine(ImgId) + Twine(".info"));
1014+
ImgInfoVar->setAlignment(
1015+
MaybeAlign(M.getDataLayout().getTypeStoreSize(IntPtrTy) * 2u));
1016+
ImgInfoVar->setUnnamedAddr(GlobalValue::UnnamedAddr::Local);
1017+
ImgInfoVar->setSection(".tgtimg");
1018+
1019+
// Add image info to the used list to force it to be emitted to the
1020+
// object.
1021+
appendToUsed(M, ImgInfoVar);
1022+
}
10201023

10211024
ImgId++;
10221025
}

0 commit comments

Comments
 (0)