Skip to content

Commit b8c2807

Browse files
mbelickiigcbot
authored andcommitted
Revert ef7544a: "Enabling uninitialized external global variables."
This reverts commit ef7544a967bb61d1770eabd92c48aa8e9e9438f4. This change enables external global varibles for compute workloads, including variables without initializers. External variables without initializers will be emitted as UNDEF symbols in zebin ELF binary.
1 parent 902743b commit b8c2807

File tree

6 files changed

+32
-36
lines changed

6 files changed

+32
-36
lines changed

IGC/AdaptorOCL/OCL/sp/zebin_builder.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,8 @@ void ZEBinaryBuilder::addProgramSymbols(const IGC::SOpenCLProgramInfo& annotatio
396396
for (auto sym : symbols.globalStringConst)
397397
addSymbol(sym, llvm::ELF::STB_GLOBAL, mConstStringSectID);
398398

399-
// add symbols defined in global section, mGlobalSectID may be unallocated
400-
// at this point if symbols are undef
399+
// add symbols defined in global section
400+
IGC_ASSERT(symbols.global.empty() || mGlobalSectID != -1);
401401
for (auto sym : symbols.global)
402402
addSymbol(sym, llvm::ELF::STB_GLOBAL, mGlobalSectID);
403403

IGC/BiFModule/Implementation/tileid.cl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ SPDX-License-Identifier: MIT
66
77
============================= end_copyright_notice ===========================*/
88

9-
extern int *__SubDeviceID;
9+
__constant int *__SubDeviceID;
1010
__constant int __MaxHWThreadIDPerSubDevice = 1;
1111

1212

IGC/Compiler/CISACodeGen/OpenCLKernelCodeGen.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2208,14 +2208,9 @@ namespace IGC
22082208

22092209
CVariable* COpenCLKernel::GetGlobalMapping(llvm::Value* c)
22102210
{
2211-
GlobalVariable* globalVar = cast<GlobalVariable>(c);
2212-
VISA_Type type = GetType(c->getType());
2213-
2214-
if (!globalVar->hasInitializer()) {
2215-
return GetUndef(type);
2216-
}
2217-
22182211
unsigned int val = GetGlobalMappingValue(c);
2212+
2213+
VISA_Type type = GetType(c->getType());
22192214
return ImmToVariable(val, type);
22202215
}
22212216

IGC/Compiler/Optimizer/OpenCLPasses/ProgramScopeConstants/ProgramScopeConstantAnalysis.cpp

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,6 @@ bool ProgramScopeConstantAnalysis::runOnModule(Module& M)
5757

5858
SmallVector<GlobalVariable*, 32> zeroInitializedGlobals;
5959

60-
auto getOrAllocateGlobalBuffer = [&]{
61-
if (!hasInlineGlobalBuffer)
62-
{
63-
InlineProgramScopeBuffer ilpsb;
64-
ilpsb.alignment = 0;
65-
ilpsb.allocSize = 0;
66-
m_pModuleMd->inlineGlobalBuffers.push_back(ilpsb);
67-
hasInlineGlobalBuffer = true;
68-
}
69-
return &m_pModuleMd->inlineGlobalBuffers.back().Buffer;
70-
};
71-
7260
for (Module::global_iterator I = M.global_begin(), E = M.global_end(); I != E; ++I)
7361
{
7462
GlobalVariable* globalVar = &(*I);
@@ -101,19 +89,25 @@ bool ProgramScopeConstantAnalysis::runOnModule(Module& M)
10189
continue;
10290
}
10391

104-
// Handle external symbols without initializers.
10592
if (!globalVar->hasInitializer())
10693
{
107-
// Include the variable in 'inlineProgramScopeOffsets'. otherwise
108-
// code gen will not emit relocation.
109-
inlineProgramScopeOffsets[globalVar] = -1;
94+
Value* inst = nullptr;
95+
for (auto u : globalVar->users())
96+
{
97+
if (dyn_cast_or_null<Instruction>(u))
98+
{
99+
inst = u;
100+
}
101+
}
102+
std::string ErrorMsg = "Global constant without initializer!";
103+
Ctx->EmitError(ErrorMsg.c_str(), inst);
110104
continue;
111105
}
112106

113107
// The only way to get a null initializer is via an external variable.
114-
// Linking has already occurred; everything should be resolved or
115-
// handled before this point.
108+
// Linking has already occurred; everything should be resolved.
116109
Constant* initializer = globalVar->getInitializer();
110+
IGC_ASSERT_MESSAGE(initializer, "Constant must be initialized");
117111
if (!initializer)
118112
{
119113
continue;
@@ -133,7 +127,15 @@ bool ProgramScopeConstantAnalysis::runOnModule(Module& M)
133127
DataVector* inlineProgramScopeBuffer = nullptr;
134128
if (AS == ADDRESS_SPACE_GLOBAL)
135129
{
136-
inlineProgramScopeBuffer = getOrAllocateGlobalBuffer();
130+
if (!hasInlineGlobalBuffer)
131+
{
132+
InlineProgramScopeBuffer ilpsb;
133+
ilpsb.alignment = 0;
134+
ilpsb.allocSize = 0;
135+
m_pModuleMd->inlineGlobalBuffers.push_back(ilpsb);
136+
hasInlineGlobalBuffer = true;
137+
}
138+
inlineProgramScopeBuffer = &m_pModuleMd->inlineGlobalBuffers.back().Buffer;
137139
}
138140
else
139141
{

IGC/Compiler/Optimizer/OpenCLPasses/ProgramScopeConstants/ProgramScopeConstantResolution.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,8 @@ bool ProgramScopeConstantResolution::runOnModule(Module& M)
134134
continue;
135135
}
136136

137-
if (!pGlobalVar->hasInitializer())
138-
{
139-
continue;
140-
}
141-
142137
Constant* initializer = pGlobalVar->getInitializer();
138+
IGC_ASSERT_MESSAGE(initializer, "Constant must be initialized");
143139
if (!initializer)
144140
{
145141
continue;

IGC/Compiler/Optimizer/OpenCLPasses/UndefinedReferences/UndefinedReferencesPass.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ static bool ExistUndefinedReferencesInModule(Module& module, CodeGenContext *CGC
5656
{
5757
bool foundUndef = false;
5858

59+
std::string msg = "undefined reference to `";
60+
5961
Module::global_iterator GVarIter = module.global_begin();
6062
for (; GVarIter != module.global_end();)
6163
{
@@ -64,14 +66,15 @@ static bool ExistUndefinedReferencesInModule(Module& module, CodeGenContext *CGC
6466
// Increment the iterator before attempting to remove a global variable
6567
GVarIter++;
6668

67-
if (pGVar->hasExternalLinkage() || pGVar->hasCommonLinkage())
69+
if ((pGVar->hasAtLeastLocalUnnamedAddr() == false) &&
70+
(pGVar->hasExternalLinkage() || pGVar->hasCommonLinkage()))
6871
{
6972
continue;
7073
}
7174

7275
if (pGVar->isDeclaration() && pGVar->hasNUsesOrMore(1))
7376
{
74-
ReportUndefinedReference(CGC, pGVar->getName(), pGVar);
77+
ReportUndefinedReference(CGC, GVarIter->getName(), pGVar);
7578
foundUndef = true;
7679
}
7780

0 commit comments

Comments
 (0)