Skip to content

Commit 71ed81e

Browse files
sys-igcigcbot
authored andcommitted
[Autobackout][FunctionalRegression]Revert of change: 01eb1b9: Improve inline BiF
Added additional step during build of compiler which splits the whole BiFModule into smaller sections. In this way materializing and inlining should be less time consuming.
1 parent cdb31b2 commit 71ed81e

Some content is hidden

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

43 files changed

+686
-1510
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"
@@ -193,7 +190,10 @@ namespace IGC
193190
return oclMajor;
194191
}
195192

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

235235
StringRef dataLayout = layoutstr;
236236
pContext->getModule()->setDataLayout(dataLayout);
237+
BuiltinGenericModule->setDataLayout(dataLayout);
238+
if( BuiltinSizeModule )
239+
{
240+
BuiltinSizeModule->setDataLayout(dataLayout);
241+
}
237242

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

@@ -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

@@ -680,14 +685,20 @@ static void CommonOCLBasedPasses(OpenCLProgramContext* pContext)
680685
MEM_SNAPSHOT(IGC::SMS_AFTER_UNIFICATION);
681686
}
682687

683-
void UnifyIROCL(OpenCLProgramContext* pContext)
688+
void UnifyIROCL(
689+
OpenCLProgramContext* pContext,
690+
std::unique_ptr<llvm::Module> BuiltinGenericModule,
691+
std::unique_ptr<llvm::Module> BuiltinSizeModule)
684692
{
685-
CommonOCLBasedPasses(pContext);
693+
CommonOCLBasedPasses(pContext, std::move(BuiltinGenericModule), std::move(BuiltinSizeModule));
686694
}
687695

688-
void UnifyIRSPIR(OpenCLProgramContext* pContext)
696+
void UnifyIRSPIR(
697+
OpenCLProgramContext* pContext,
698+
std::unique_ptr<llvm::Module> BuiltinGenericModule,
699+
std::unique_ptr<llvm::Module> BuiltinSizeModule)
689700
{
690-
CommonOCLBasedPasses(pContext);
701+
CommonOCLBasedPasses(pContext, std::move(BuiltinGenericModule), std::move(BuiltinSizeModule));
691702
}
692703

693704
}

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 & 3 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"
@@ -1128,6 +1127,13 @@ void dumpOCLProgramBinary(OpenCLProgramContext &Ctx, const char *binaryOutput,
11281127
dumpOCLProgramBinary(name.str().data(), binaryOutput, binarySize);
11291128
}
11301129

1130+
static std::unique_ptr<llvm::MemoryBuffer> GetGenericModuleBuffer()
1131+
{
1132+
char Resource[5] = {'-'};
1133+
_snprintf(Resource, sizeof(Resource), "#%d", OCL_BC);
1134+
return std::unique_ptr<llvm::MemoryBuffer>{llvm::LoadBufferFromResource(Resource, "BC")};
1135+
}
1136+
11311137
static void WriteSpecConstantsDump(
11321138
const STB_TranslateInputArgs* pInputArgs,
11331139
QWORD hash)
@@ -1410,17 +1416,111 @@ bool TranslateBuildSPMD(
14101416
splitter.setSplittedModuleInOCLContext();
14111417
}
14121418

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

14151515
try
14161516
{
14171517
if (llvm::StringRef(oclContext.getModule()->getTargetTriple()).startswith("spir"))
14181518
{
1419-
IGC::UnifyIRSPIR(&oclContext);
1519+
IGC::UnifyIRSPIR(&oclContext, std::move(BuiltinGenericModule), std::move(BuiltinSizeModule));
14201520
}
14211521
else // not SPIR
14221522
{
1423-
IGC::UnifyIROCL(&oclContext);
1523+
IGC::UnifyIROCL(&oclContext, std::move(BuiltinGenericModule), std::move(BuiltinSizeModule));
14241524
}
14251525

14261526
if (oclContext.HasError())

IGC/BiFManager/BiFManagerCommon.cpp

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

0 commit comments

Comments
 (0)