Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[HLSL] Use hidden visibility for external linkage. #140292

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
Loading
from
Draft
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
8 changes: 0 additions & 8 deletions 8 clang/lib/CodeGen/CGHLSLRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,14 +444,6 @@ void CGHLSLRuntime::emitEntryFunction(const FunctionDecl *FD,
}
}

void CGHLSLRuntime::setHLSLFunctionAttributes(const FunctionDecl *FD,
llvm::Function *Fn) {
if (FD->isInExportDeclContext()) {
const StringRef ExportAttrKindStr = "hlsl.export";
Fn->addFnAttr(ExportAttrKindStr);
}
}

static void gatherFunctions(SmallVectorImpl<Function *> &Fns, llvm::Module &M,
bool CtorOrDtor) {
const auto *GV =
Expand Down
1 change: 0 additions & 1 deletion 1 clang/lib/CodeGen/CGHLSLRuntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ class CGHLSLRuntime {
void setHLSLEntryAttributes(const FunctionDecl *FD, llvm::Function *Fn);

void emitEntryFunction(const FunctionDecl *FD, llvm::Function *Fn);
void setHLSLFunctionAttributes(const FunctionDecl *FD, llvm::Function *Fn);

llvm::Instruction *getConvergenceToken(llvm::BasicBlock &BB);

Expand Down
1 change: 0 additions & 1 deletion 1 clang/lib/CodeGen/CodeGenFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1274,7 +1274,6 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy,
if (FD->hasAttr<HLSLShaderAttr>()) {
CGM.getHLSLRuntime().emitEntryFunction(FD, Fn);
}
CGM.getHLSLRuntime().setHLSLFunctionAttributes(FD, Fn);
}

EmitFunctionProlog(*CurFnInfo, CurFn, Args);
Expand Down
5 changes: 5 additions & 0 deletions 5 clang/lib/CodeGen/CodeGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1655,6 +1655,11 @@ void CodeGenModule::setGlobalVisibility(llvm::GlobalValue *GV,
return;
}

if (Context.getLangOpts().HLSL && !D->isInExportDeclContext()) {
GV->setVisibility(llvm::GlobalValue::HiddenVisibility);
return;
}

if (GV->hasDLLExportStorageClass() || GV->hasDLLImportStorageClass()) {
// Reject incompatible dlllstorage and visibility annotations.
if (!LV.isVisibilityExplicit())
Expand Down
4 changes: 3 additions & 1 deletion 4 llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ static bool finalizeLinkage(Module &M) {
for (Function &EF : M.functions()) {
if (EF.isIntrinsic())
continue;
if (EF.hasFnAttribute("hlsl.shader") || EF.hasFnAttribute("hlsl.export"))
if (EF.hasExternalLinkage() && EF.hasDefaultVisibility())
continue;
if (EF.hasFnAttribute("hlsl.shader"))
continue;
Funcs.push_back(&EF);
}
Expand Down
3 changes: 2 additions & 1 deletion 3 llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,8 @@ bool SPIRVCallLowering::lowerFormalArguments(MachineIRBuilder &MIRBuilder,
.addUse(FuncVReg);
addStringImm(F.getName(), MIB);
} else if (F.getLinkage() != GlobalValue::InternalLinkage &&
F.getLinkage() != GlobalValue::PrivateLinkage) {
F.getLinkage() != GlobalValue::PrivateLinkage &&
F.getVisibility() != GlobalValue::HiddenVisibility) {
SPIRV::LinkageType::LinkageType LnkTy =
F.isDeclaration()
? SPIRV::LinkageType::Import
Expand Down
3 changes: 2 additions & 1 deletion 3 llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3895,7 +3895,8 @@ bool SPIRVInstructionSelector::selectGlobalValue(
if (hasInitializer(GlobalVar) && !Init)
return true;

bool HasLnkTy = !GV->hasInternalLinkage() && !GV->hasPrivateLinkage();
bool HasLnkTy = !GV->hasInternalLinkage() && !GV->hasPrivateLinkage() &&
!GV->hasHiddenVisibility();
SPIRV::LinkageType::LinkageType LnkType =
GV->isDeclarationForLinker()
? SPIRV::LinkageType::Import
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.