Skip to content

Commit 92b3bc7

Browse files
PawelJurekfda0
authored andcommitted
Revert BifManager tool
BifManagerTool went into infinite recursion, causing stack overflow during build. (cherry picked from commit 3326804)
1 parent 92bcf18 commit 92b3bc7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1186
-1551
lines changed

IGC/AdaptorOCL/OCL/BuiltinResource.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ SPDX-License-Identifier: MIT
1010
// Used by BuiltinResource.rc
1111
//
1212
#define OCL_BC_START 120
13-
#define OCL_BIFBC 122
13+
#define OCL_BC_32 120
14+
#define OCL_BC_64 121
15+
#define OCL_BC 122
1416
#define OCL_BC_END 125
1517

IGC/AdaptorOCL/OCL/BuiltinResource.rc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ SPDX-License-Identifier: MIT
1010

1111
/////////////////////////////////////////////////////////////////////////////
1212
//
13-
// BIFBC
13+
// BC
1414
//
1515

16-
OCL_BIFBC BIFBC "OCLBiFImpl.bifbc"
16+
OCL_BC BC "OCLBiFImpl.bc"
17+
OCL_BC_32 BC "IGCsize_t_32.bc"
18+
OCL_BC_64 BC "IGCsize_t_64.bc"
1719
/////////////////////////////////////////////////////////////////////////////

IGC/AdaptorOCL/OCL/LoadBuffer.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*========================== begin_copyright_notice ============================
22
3-
Copyright (C) 2017-2024 Intel Corporation
3+
Copyright (C) 2017-2021 Intel Corporation
44
55
SPDX-License-Identifier: MIT
66
@@ -17,8 +17,6 @@ SPDX-License-Identifier: MIT
1717

1818
using namespace llvm;
1919
#ifdef LLVM_ON_UNIX
20-
21-
#include "Probe/Assertion.h"
2220
#include <dlfcn.h>
2321
#include <stdio.h>
2422

@@ -40,15 +38,13 @@ MemoryBuffer *llvm::LoadBufferFromResource(const char *pResName,
4038
symbol = dlsym(module, size_name);
4139
if (!symbol)
4240
{
43-
IGC_ASSERT_EXIT_MESSAGE(0, "LoadBufferFromResource: [%s]\n", dlerror());
4441
return NULL;
4542
}
4643
size = *(uint32_t *)symbol;
4744

4845
symbol = dlsym(module, name);
4946
if (!symbol)
5047
{
51-
IGC_ASSERT_EXIT_MESSAGE(0, "LoadBufferFromResource: [%s]\n", dlerror());
5248
return NULL;
5349
}
5450

IGC/AdaptorOCL/OCL/Resource/BuiltinResource.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ SPDX-License-Identifier: MIT
1010
// Used by BuiltinResource.rc
1111
//
1212
#define OCL_BC_START 120
13-
#define OCL_BIFBC 122
13+
#define OCL_BC_32 120
14+
#define OCL_BC_64 121
15+
#define OCL_BC 122
1416
#define OCL_BC_RS 123
1517
#define OCL_BC_END 124
1618

IGC/AdaptorOCL/OCL/Resource/BuiltinResource.rc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ SPDX-License-Identifier: MIT
1010

1111
/////////////////////////////////////////////////////////////////////////////
1212
//
13-
// BIFBC
13+
// BC
1414
//
1515

16-
OCL_BIFBC BIFBC "OCLBiFImpl.bifbc"
17-
16+
OCL_BC BC "OCLBiFImpl.bc"
17+
OCL_BC_32 BC "IGCsize_t_32.bc"
18+
OCL_BC_64 BC "IGCsize_t_64.bc"
1819
/////////////////////////////////////////////////////////////////////////////

IGC/AdaptorOCL/UnifyIROCL.cpp

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ SPDX-License-Identifier: MIT
66
77
============================= end_copyright_notice ===========================*/
88

9-
#include <chrono>
10-
#include <iostream>
11-
129
#include "common/LLVMWarningsPush.hpp"
1310
#include <llvm/Support/ScaledNumber.h>
1411
#include "llvm/ADT/PostOrderIterator.h"
@@ -191,7 +188,10 @@ namespace IGC
191188
return oclMajor;
192189
}
193190

194-
static void CommonOCLBasedPasses(OpenCLProgramContext* pContext)
191+
static void CommonOCLBasedPasses(
192+
OpenCLProgramContext* pContext,
193+
std::unique_ptr<llvm::Module> BuiltinGenericModule,
194+
std::unique_ptr<llvm::Module> BuiltinSizeModule)
195195
{
196196
#if defined( _DEBUG )
197197
bool brokenDebugInfo = false;
@@ -232,6 +232,11 @@ static void CommonOCLBasedPasses(OpenCLProgramContext* pContext)
232232

233233
StringRef dataLayout = layoutstr;
234234
pContext->getModule()->setDataLayout(dataLayout);
235+
BuiltinGenericModule->setDataLayout(dataLayout);
236+
if( BuiltinSizeModule )
237+
{
238+
BuiltinSizeModule->setDataLayout(dataLayout);
239+
}
235240

236241
MetaDataUtils *pMdUtils = pContext->getMetaDataUtils();
237242

@@ -396,7 +401,7 @@ static void CommonOCLBasedPasses(OpenCLProgramContext* pContext)
396401
mpm.add(new NamedBarriersResolution(pContext->platform.getPlatformInfo().eRenderCoreFamily));
397402
mpm.add(new PreBIImportAnalysis());
398403
mpm.add(createTimeStatsCounterPass(pContext, TIME_Unify_BuiltinImport, STATS_COUNTER_START));
399-
mpm.add(createBuiltInImportPass());
404+
mpm.add(createBuiltInImportPass(std::move(BuiltinGenericModule), std::move(BuiltinSizeModule)));
400405
mpm.add(createTimeStatsCounterPass(pContext, TIME_Unify_BuiltinImport, STATS_COUNTER_END));
401406
mpm.add(new BIFFlagCtrlResolution(pContext));
402407

@@ -668,14 +673,20 @@ static void CommonOCLBasedPasses(OpenCLProgramContext* pContext)
668673
MEM_SNAPSHOT(IGC::SMS_AFTER_UNIFICATION);
669674
}
670675

671-
void UnifyIROCL(OpenCLProgramContext* pContext)
676+
void UnifyIROCL(
677+
OpenCLProgramContext* pContext,
678+
std::unique_ptr<llvm::Module> BuiltinGenericModule,
679+
std::unique_ptr<llvm::Module> BuiltinSizeModule)
672680
{
673-
CommonOCLBasedPasses(pContext);
681+
CommonOCLBasedPasses(pContext, std::move(BuiltinGenericModule), std::move(BuiltinSizeModule));
674682
}
675683

676-
void UnifyIRSPIR(OpenCLProgramContext* pContext)
684+
void UnifyIRSPIR(
685+
OpenCLProgramContext* pContext,
686+
std::unique_ptr<llvm::Module> BuiltinGenericModule,
687+
std::unique_ptr<llvm::Module> BuiltinSizeModule)
677688
{
678-
CommonOCLBasedPasses(pContext);
689+
CommonOCLBasedPasses(pContext, std::move(BuiltinGenericModule), std::move(BuiltinSizeModule));
679690
}
680691

681692
}

IGC/AdaptorOCL/UnifyIROCL.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ SPDX-License-Identifier: MIT
1111

1212
namespace IGC
1313
{
14-
void UnifyIROCL(OpenCLProgramContext* pContext);
14+
void UnifyIROCL(
15+
OpenCLProgramContext* pContext,
16+
std::unique_ptr<llvm::Module> BuiltinGenericModule,
17+
std::unique_ptr<llvm::Module> BuiltinSizeModule);
1518

16-
void UnifyIRSPIR(OpenCLProgramContext* pContext);
19+
void UnifyIRSPIR(
20+
OpenCLProgramContext* pContext,
21+
std::unique_ptr<llvm::Module> BuiltinGenericModule,
22+
std::unique_ptr<llvm::Module> BuiltinSizeModule);
1723
}

IGC/AdaptorOCL/dllInterfaceCompute.cpp

Lines changed: 103 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ SPDX-License-Identifier: MIT
2020
#include <fstream>
2121
#include <mutex>
2222
#include <numeric>
23-
#include <chrono>
2423

2524
#include "AdaptorCommon/customApi.hpp"
2625
#include "AdaptorOCL/OCL/LoadBuffer.h"
@@ -125,7 +124,6 @@ SPDX-License-Identifier: MIT
125124
#if !defined(_WIN32)
126125
# define strtok_s strtok_r
127126
# define _strdup strdup
128-
# define _snprintf snprintf
129127
#endif
130128

131129
#include "common/LLVMWarningsPush.hpp"
@@ -1128,6 +1126,13 @@ void dumpOCLProgramBinary(OpenCLProgramContext &Ctx, const char *binaryOutput,
11281126
dumpOCLProgramBinary(name.str().data(), binaryOutput, binarySize);
11291127
}
11301128

1129+
static std::unique_ptr<llvm::MemoryBuffer> GetGenericModuleBuffer()
1130+
{
1131+
char Resource[5] = {'-'};
1132+
_snprintf_s(Resource, sizeof(Resource), sizeof(Resource), "#%d", OCL_BC);
1133+
return std::unique_ptr<llvm::MemoryBuffer>{llvm::LoadBufferFromResource(Resource, "BC")};
1134+
}
1135+
11311136
static void WriteSpecConstantsDump(
11321137
const STB_TranslateInputArgs* pInputArgs,
11331138
QWORD hash)
@@ -1410,17 +1415,111 @@ bool TranslateBuildSPMD(
14101415
splitter.setSplittedModuleInOCLContext();
14111416
}
14121417

1418+
std::unique_ptr<llvm::Module> BuiltinGenericModule = nullptr;
1419+
std::unique_ptr<llvm::Module> BuiltinSizeModule = nullptr;
1420+
std::unique_ptr<llvm::MemoryBuffer> pGenericBuffer = nullptr;
1421+
std::unique_ptr<llvm::MemoryBuffer> pSizeTBuffer = nullptr;
1422+
{
1423+
// IGC has two BIF Modules:
1424+
// 1. kernel Module (pKernelModule)
1425+
// 2. BIF Modules:
1426+
// a) generic Module (BuiltinGenericModule)
1427+
// b) size Module (BuiltinSizeModule)
1428+
//
1429+
// OCL builtin types, such as clk_event_t/queue_t, etc., are struct (opaque) types. For
1430+
// those types, its original names are themselves; the derived names are ones with
1431+
// '.<digit>' appended to the original names. For example, clk_event_t is the original
1432+
// name, its derived names are clk_event_t.0, clk_event_t.1, etc.
1433+
//
1434+
// When llvm reads in multiple modules, say, M0, M1, under the same llvmcontext, if both
1435+
// M0 and M1 has the same struct type, M0 will have the original name and M1 the derived
1436+
// name for that type. For example, clk_event_t, M0 will have clk_event_t, while M1 will
1437+
// have clk_event_t.2 (number is arbitrary). After linking, those two named types should be
1438+
// mapped to the same type, otherwise, we could have type-mismatch (for example, OCL GAS
1439+
// builtin_functions tests will assertion fail during inlining due to type-mismatch). Furthermore,
1440+
// when linking M1 into M0 (M0 : dstModule, M1 : srcModule), the final type is the type
1441+
// used in M0.
1442+
1443+
// Load the builtin module - Generic BC
1444+
// Load the builtin module - Generic BC
1445+
{
1446+
COMPILER_TIME_START(&oclContext, TIME_OCL_LazyBiFLoading);
1447+
1448+
pGenericBuffer = GetGenericModuleBuffer();
1449+
1450+
if (pGenericBuffer == NULL)
1451+
{
1452+
SetErrorMessage("Error loading the Generic builtin resource", *pOutputArgs);
1453+
return false;
1454+
}
1455+
1456+
llvm::Expected<std::unique_ptr<llvm::Module>> ModuleOrErr =
1457+
getLazyBitcodeModule(pGenericBuffer->getMemBufferRef(), *oclContext.getLLVMContext());
1458+
1459+
if (llvm::Error EC = ModuleOrErr.takeError())
1460+
{
1461+
std::string error_str = "Error lazily loading bitcode for generic builtins,"
1462+
"is bitcode the right version and correctly formed?";
1463+
SetErrorMessage(error_str, *pOutputArgs);
1464+
return false;
1465+
}
1466+
else
1467+
{
1468+
BuiltinGenericModule = std::move(*ModuleOrErr);
1469+
}
1470+
1471+
if (BuiltinGenericModule == NULL)
1472+
{
1473+
SetErrorMessage("Error loading the Generic builtin module from buffer", *pOutputArgs);
1474+
return false;
1475+
}
1476+
COMPILER_TIME_END(&oclContext, TIME_OCL_LazyBiFLoading);
1477+
}
1478+
1479+
// Load the builtin module - pointer depended
1480+
{
1481+
char ResNumber[5] = { '-' };
1482+
switch (PtrSzInBits)
1483+
{
1484+
case 32:
1485+
_snprintf_s(ResNumber, sizeof(ResNumber), 5, "#%d", OCL_BC_32);
1486+
break;
1487+
case 64:
1488+
_snprintf_s(ResNumber, sizeof(ResNumber), 5, "#%d", OCL_BC_64);
1489+
break;
1490+
default:
1491+
IGC_ASSERT_MESSAGE(0, "Unknown bitness of compiled module");
1492+
}
1493+
1494+
// the MemoryBuffer becomes owned by the module and does not need to be managed
1495+
pSizeTBuffer.reset(llvm::LoadBufferFromResource(ResNumber, "BC"));
1496+
IGC_ASSERT_MESSAGE(pSizeTBuffer, "Error loading builtin resource");
1497+
1498+
llvm::Expected<std::unique_ptr<llvm::Module>> ModuleOrErr =
1499+
getLazyBitcodeModule(pSizeTBuffer->getMemBufferRef(), *oclContext.getLLVMContext());
1500+
if (llvm::Error EC = ModuleOrErr.takeError())
1501+
IGC_ASSERT_MESSAGE(0, "Error lazily loading bitcode for size_t builtins");
1502+
else
1503+
BuiltinSizeModule = std::move(*ModuleOrErr);
1504+
1505+
IGC_ASSERT_MESSAGE(BuiltinSizeModule, "Error loading builtin module from buffer");
1506+
}
1507+
1508+
BuiltinGenericModule->setDataLayout(BuiltinSizeModule->getDataLayout());
1509+
BuiltinGenericModule->setTargetTriple(BuiltinSizeModule->getTargetTriple());
1510+
}
1511+
14131512
oclContext.getModuleMetaData()->csInfo.forcedSIMDSize |= IGC_GET_FLAG_VALUE(ForceOCLSIMDWidth);
14141513

14151514
try
14161515
{
14171516
if (llvm::StringRef(oclContext.getModule()->getTargetTriple()).startswith("spir"))
14181517
{
1419-
IGC::UnifyIRSPIR(&oclContext);
1518+
IGC::UnifyIRSPIR(&oclContext, std::move(BuiltinGenericModule), std::move(BuiltinSizeModule));
14201519
}
14211520
else // not SPIR
14221521
{
1423-
IGC::UnifyIROCL(&oclContext);
1522+
IGC::UnifyIROCL(&oclContext, std::move(BuiltinGenericModule), std::move(BuiltinSizeModule));
14241523
}
14251524

14261525
if (oclContext.HasError())

IGC/BiFManager/BiFManagerCommon.cpp

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)