File tree Expand file tree Collapse file tree 2 files changed +20
-10
lines changed
Optimizer/OpenCLPasses/ProgramScopeConstants Expand file tree Collapse file tree 2 files changed +20
-10
lines changed Original file line number Diff line number Diff line change @@ -4632,18 +4632,26 @@ namespace IGC
4632
4632
for (auto global : modMD->inlineProgramScopeOffsets )
4633
4633
{
4634
4634
GlobalVariable* pGlobal = global.first ;
4635
- bool needRelocation = false ;
4636
- for (auto ui = pGlobal->user_begin (), ue = pGlobal->user_end (); ui != ue; ui++)
4635
+
4636
+ // Create symbol for external globals
4637
+ bool needSymbol = (pGlobal->getLinkage () == GlobalValue::ExternalLinkage) || (pGlobal->getLinkage () == GlobalValue::CommonLinkage);
4638
+ if (!needSymbol)
4637
4639
{
4638
- // Check if need relocation
4639
- Instruction* inst = dyn_cast<Instruction>(*ui);
4640
- if (inst && inst-> getParent ()-> getParent ()-> hasFnAttribute ( " EnableGlobalRelocation " ) )
4640
+ pGlobal-> removeDeadConstantUsers ();
4641
+ // Also need to create symbol if it requires relocation
4642
+ for ( auto ui = pGlobal-> user_begin (), ue = pGlobal-> user_end (); ui != ue; ui++ )
4641
4643
{
4642
- needRelocation = true ;
4643
- break ;
4644
+ // Check if need relocation
4645
+ Instruction* inst = dyn_cast<Instruction>(*ui);
4646
+ if (inst && inst->getParent ()->getParent ()->hasFnAttribute (" EnableGlobalRelocation" ))
4647
+ {
4648
+ needSymbol = true ;
4649
+ break ;
4650
+ }
4644
4651
}
4645
4652
}
4646
- if (needRelocation)
4653
+
4654
+ if (needSymbol)
4647
4655
{
4648
4656
StringRef name = pGlobal->getName ();
4649
4657
unsigned addrSpace = pGlobal->getType ()->getAddressSpace ();
Original file line number Diff line number Diff line change @@ -110,8 +110,10 @@ bool ProgramScopeConstantAnalysis::runOnModule(Module& M)
110
110
continue ;
111
111
}
112
112
113
- // If this variable isn't used, don't add it to the buffer.
114
- if (globalVar->use_empty ())
113
+ // If this variable isn't used and not exposed externally, don't add it to the buffer.
114
+ if (globalVar->use_empty () &&
115
+ globalVar->getLinkage () != GlobalValue::CommonLinkage &&
116
+ globalVar->getLinkage () != GlobalValue::ExternalLinkage)
115
117
{
116
118
continue ;
117
119
}
You can’t perform that action at this time.
0 commit comments