@@ -128,66 +128,73 @@ void ZEBinaryBuilder::addGTPinInfo(const IGC::SOpenCLKernelInfo& annotations)
128128
129129void ZEBinaryBuilder::addProgramScopeInfo (const IGC::SOpenCLProgramInfo& programInfo)
130130{
131- if (hasGlobalConstants (programInfo))
132- addGlobalConstants (programInfo);
133- if (hasGlobals (programInfo))
134- mGlobalSectID = addGlobals (programInfo);
135- }
136-
137- bool ZEBinaryBuilder::hasGlobalConstants (const IGC::SOpenCLProgramInfo& annotations)
138- {
139- if (!annotations.m_initConstantAnnotation .empty ())
140- return true ;
141- return false ;
131+ addGlobalConstants (programInfo);
132+ addGlobals (programInfo);
142133}
143134
144135void ZEBinaryBuilder::addGlobalConstants (const IGC::SOpenCLProgramInfo& annotations)
145136{
137+ if (annotations.m_initConstantAnnotation .empty ())
138+ return ;
139+
146140 // create a data section for global constant variables
147- // This function should only be called when hasGlobalConstants returns true
148141 // Two constant data sections: general constants and string literals
149142 IGC_ASSERT (annotations.m_initConstantAnnotation .size () == 2 );
150143
151144 // General constants
152- auto & ca = annotations.m_initConstantAnnotation [0 ];
153- uint32_t dataSize = ca->InlineData .size ();
154- uint32_t paddingSize = ca->AllocSize - dataSize;
155- uint32_t alignment = ca->Alignment ;
156- mGlobalConstSectID = mBuilder .addSectionData (" const" , (const uint8_t *)ca->InlineData .data (),
157- dataSize, paddingSize, alignment);
145+ // create a data section for global constant variables
146+ auto & ca = annotations.m_initConstantAnnotation .front ();
147+ if (ca->AllocSize ) {
148+ uint32_t dataSize = ca->InlineData .size ();
149+ uint32_t paddingSize = ca->AllocSize - dataSize;
150+ uint32_t alignment = ca->Alignment ;
151+
152+ // FIXME: Before runtime can support bss section, we still generate all zero-initialized variables
153+ // in the .data.const section and no .bss.const section.
154+ // The .bss.const section size is the padding size (ca->AllocSize - ca->InlineData.size()),
155+ // and the normal .data.const size is ca->InlineData.size()
156+ mGlobalConstSectID = mBuilder .addSectionData (" const" , (const uint8_t *)ca->InlineData .data (),
157+ dataSize, paddingSize, alignment);
158+ }
158159
159160 // String literals
160161 auto & caString = annotations.m_initConstantAnnotation [1 ];
161162 if (caString->InlineData .size () > 0 )
162163 {
163- dataSize = caString->InlineData .size ();
164- paddingSize = caString->AllocSize - dataSize;
165- alignment = caString->Alignment ;
164+ uint32_t dataSize = caString->InlineData .size ();
165+ uint32_t paddingSize = caString->AllocSize - dataSize;
166+ uint32_t alignment = caString->Alignment ;
166167 mConstStringSectID = mBuilder .addSectionData (" const.string" , (const uint8_t *)caString->InlineData .data (),
167168 dataSize, paddingSize, alignment);
168169 }
169170}
170171
171- bool ZEBinaryBuilder::hasGlobals (const IGC::SOpenCLProgramInfo& annotations)
172+ void ZEBinaryBuilder::addGlobals (const IGC::SOpenCLProgramInfo& annotations)
172173{
173- if (!annotations.m_initGlobalAnnotation .empty ())
174- return true ;
175- return false ;
176- }
177-
174+ if (annotations.m_initGlobalAnnotation .empty ())
175+ return ;
178176
179- ZEELFObjectBuilder::SectionID ZEBinaryBuilder::addGlobals (
180- const IGC::SOpenCLProgramInfo& annotations)
181- {
182177 // create a data section for global variables
183- // This function should only be called when hasGlobals return true
184178 // FIXME: not sure in what cases there will be more than one global buffer
185179 IGC_ASSERT (annotations.m_initGlobalAnnotation .size () == 1 );
186180 auto & ca = annotations.m_initGlobalAnnotation .front ();
181+
182+ if (!ca->AllocSize )
183+ return ;
184+
187185 uint32_t dataSize = ca->InlineData .size ();
188186 uint32_t paddingSize = ca->AllocSize - dataSize;
189187 uint32_t alignment = ca->Alignment ;
190- return mBuilder .addSectionData (" global" , (const uint8_t *)ca->InlineData .data (),
188+
189+ // FIXME: Before runtime can support bss section, we still generate all zero-initialized variables
190+ // in the .data.global
191+ // The .bss.global section size is the padding size (ca->AllocSize - ca->InlineData.size()),
192+ // and the normal .data.global size is ca->InlineData.size()
193+ // Side note (when adding bss section):
194+ // mGlobalSectID is the section id that will be referenced by global symbols.
195+ // It should be .data.global if existed. If there's only .bss.global section, then all global
196+ // symbols reference to .bss.global section, so set the mGlobalConstSectID to it
197+ mGlobalSectID = mBuilder .addSectionData (" global" , (const uint8_t *)ca->InlineData .data (),
191198 dataSize, paddingSize, alignment);
192199}
193200
0 commit comments