Skip to content

Commit 3326804

Browse files
PawelJurekigcbot
authored andcommitted
Revert BifManager tool
BifManagerTool went into infinite recursion, causing stack overflow during build.
1 parent 341be23 commit 3326804

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"
@@ -192,7 +189,10 @@ namespace IGC
192189
return oclMajor;
193190
}
194191

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

234234
StringRef dataLayout = layoutstr;
235235
pContext->getModule()->setDataLayout(dataLayout);
236+
BuiltinGenericModule->setDataLayout(dataLayout);
237+
if( BuiltinSizeModule )
238+
{
239+
BuiltinSizeModule->setDataLayout(dataLayout);
240+
}
236241

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

@@ -410,7 +415,7 @@ static void CommonOCLBasedPasses(OpenCLProgramContext* pContext)
410415
mpm.add(new NamedBarriersResolution(pContext->platform.getPlatformInfo().eRenderCoreFamily));
411416
mpm.add(new PreBIImportAnalysis());
412417
mpm.add(createTimeStatsCounterPass(pContext, TIME_Unify_BuiltinImport, STATS_COUNTER_START));
413-
mpm.add(createBuiltInImportPass());
418+
mpm.add(createBuiltInImportPass(std::move(BuiltinGenericModule), std::move(BuiltinSizeModule)));
414419
mpm.add(createTimeStatsCounterPass(pContext, TIME_Unify_BuiltinImport, STATS_COUNTER_END));
415420
mpm.add(new BIFFlagCtrlResolution(pContext));
416421

@@ -681,14 +686,20 @@ static void CommonOCLBasedPasses(OpenCLProgramContext* pContext)
681686
MEM_SNAPSHOT(IGC::SMS_AFTER_UNIFICATION);
682687
}
683688

684-
void UnifyIROCL(OpenCLProgramContext* pContext)
689+
void UnifyIROCL(
690+
OpenCLProgramContext* pContext,
691+
std::unique_ptr<llvm::Module> BuiltinGenericModule,
692+
std::unique_ptr<llvm::Module> BuiltinSizeModule)
685693
{
686-
CommonOCLBasedPasses(pContext);
694+
CommonOCLBasedPasses(pContext, std::move(BuiltinGenericModule), std::move(BuiltinSizeModule));
687695
}
688696

689-
void UnifyIRSPIR(OpenCLProgramContext* pContext)
697+
void UnifyIRSPIR(
698+
OpenCLProgramContext* pContext,
699+
std::unique_ptr<llvm::Module> BuiltinGenericModule,
700+
std::unique_ptr<llvm::Module> BuiltinSizeModule)
690701
{
691-
CommonOCLBasedPasses(pContext);
702+
CommonOCLBasedPasses(pContext, std::move(BuiltinGenericModule), std::move(BuiltinSizeModule));
692703
}
693704

694705
}

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)
@@ -1409,17 +1414,111 @@ bool TranslateBuildSPMD(
14091414
splitter.setSplittedModuleInOCLContext();
14101415
}
14111416

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

14141513
try
14151514
{
14161515
if (llvm::StringRef(oclContext.getModule()->getTargetTriple()).startswith("spir"))
14171516
{
1418-
IGC::UnifyIRSPIR(&oclContext);
1517+
IGC::UnifyIRSPIR(&oclContext, std::move(BuiltinGenericModule), std::move(BuiltinSizeModule));
14191518
}
14201519
else // not SPIR
14211520
{
1422-
IGC::UnifyIROCL(&oclContext);
1521+
IGC::UnifyIROCL(&oclContext, std::move(BuiltinGenericModule), std::move(BuiltinSizeModule));
14231522
}
14241523

14251524
if (oclContext.HasError())

IGC/BiFManager/BiFManagerCommon.cpp

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

0 commit comments

Comments
 (0)