Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clang-offload-wrapper] Do not create .tgtimg section with -emit-reg-funcs=0 #4577

Merged
merged 1 commit into from
Sep 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clang/test/Driver/clang-offload-wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@
// CHECK-IR1: [[DESCTY:%.+]] = type { i16, i16, [[IMAGETY]]*, [[ENTTY]]*, [[ENTTY]]* }
// CHECK-IR1-NOT: @llvm.global_ctors
// CHECK-IR1-NOT: @llvm.global_dtors
// CHECK-IR1-NOT: section ".tgtimg"
// 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 }

// -------
Expand Down
43 changes: 23 additions & 20 deletions clang/tools/clang-offload-wrapper/ClangOffloadWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -997,26 +997,29 @@ class BinaryWrapper {
ImagesInits.push_back(ConstantStruct::get(
getDeviceImageTy(), Fbin.first, Fbin.second, EntriesB, EntriesE));

// Create an object that holds <address, size> pair for the device image
// and put it into a .tgtimg section. This section can be used for finding
// and extracting all device images from the fat binary after linking.
Type *IntPtrTy = M.getDataLayout().getIntPtrType(C);
auto *ImgInfoArr = ConstantArray::get(
ArrayType::get(IntPtrTy, 2),
{ConstantExpr::getPointerCast(Fbin.first, IntPtrTy),
ConstantInt::get(IntPtrTy, Bin->getBufferSize())});
auto *ImgInfoVar = new GlobalVariable(
M, ImgInfoArr->getType(), /*isConstant*/ true,
GlobalVariable::InternalLinkage, ImgInfoArr,
Twine(OffloadKindTag) + Twine(ImgId) + Twine(".info"));
ImgInfoVar->setAlignment(
MaybeAlign(M.getDataLayout().getTypeStoreSize(IntPtrTy) * 2u));
ImgInfoVar->setUnnamedAddr(GlobalValue::UnnamedAddr::Local);
ImgInfoVar->setSection(".tgtimg");

// Add image info to the used list to force it to be emitted to the
// object.
appendToUsed(M, ImgInfoVar);
if (EmitRegFuncs) {
// Create an object that holds <address, size> pair for the device image
// and put it into a .tgtimg section. This section can be used for
// finding and extracting all device images from the fat binary after
// linking.
Type *IntPtrTy = M.getDataLayout().getIntPtrType(C);
auto *ImgInfoArr = ConstantArray::get(
ArrayType::get(IntPtrTy, 2),
{ConstantExpr::getPointerCast(Fbin.first, IntPtrTy),
ConstantInt::get(IntPtrTy, Bin->getBufferSize())});
auto *ImgInfoVar = new GlobalVariable(
M, ImgInfoArr->getType(), /*isConstant*/ true,
GlobalVariable::InternalLinkage, ImgInfoArr,
Twine(OffloadKindTag) + Twine(ImgId) + Twine(".info"));
ImgInfoVar->setAlignment(
MaybeAlign(M.getDataLayout().getTypeStoreSize(IntPtrTy) * 2u));
ImgInfoVar->setUnnamedAddr(GlobalValue::UnnamedAddr::Local);
ImgInfoVar->setSection(".tgtimg");

// Add image info to the used list to force it to be emitted to the
// object.
appendToUsed(M, ImgInfoVar);
}

ImgId++;
}
Expand Down