Skip to content

Commit 01eb1b9

Browse files
lwesiersigcbot
authored andcommitted
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 395fa52 commit 01eb1b9

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

+1510
-686
lines changed

IGC/AdaptorOCL/OCL/BuiltinResource.h

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

IGC/AdaptorOCL/OCL/BuiltinResource.rc

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

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

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

IGC/AdaptorOCL/OCL/LoadBuffer.cpp

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

1818
using namespace llvm;
1919
#ifdef LLVM_ON_UNIX
20+
21+
#include "Probe/Assertion.h"
2022
#include <dlfcn.h>
2123
#include <stdio.h>
2224

@@ -38,13 +40,15 @@ MemoryBuffer *llvm::LoadBufferFromResource(const char *pResName,
3840
symbol = dlsym(module, size_name);
3941
if (!symbol)
4042
{
43+
IGC_ASSERT_EXIT_MESSAGE(0, "LoadBufferFromResource: [%s]\n", dlerror());
4144
return NULL;
4245
}
4346
size = *(uint32_t *)symbol;
4447

4548
symbol = dlsym(module, name);
4649
if (!symbol)
4750
{
51+
IGC_ASSERT_EXIT_MESSAGE(0, "LoadBufferFromResource: [%s]\n", dlerror());
4852
return NULL;
4953
}
5054

IGC/AdaptorOCL/OCL/Resource/BuiltinResource.h

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

IGC/AdaptorOCL/OCL/Resource/BuiltinResource.rc

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

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

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

IGC/AdaptorOCL/UnifyIROCL.cpp

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

9+
#include <chrono>
10+
#include <iostream>
11+
912
#include "common/LLVMWarningsPush.hpp"
1013
#include <llvm/Support/ScaledNumber.h>
1114
#include "llvm/ADT/PostOrderIterator.h"
@@ -190,10 +193,7 @@ namespace IGC
190193
return oclMajor;
191194
}
192195

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

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

243238
MetaDataUtils *pMdUtils = pContext->getMetaDataUtils();
244239

@@ -415,7 +410,7 @@ static void CommonOCLBasedPasses(
415410
mpm.add(new NamedBarriersResolution(pContext->platform.getPlatformInfo().eRenderCoreFamily));
416411
mpm.add(new PreBIImportAnalysis());
417412
mpm.add(createTimeStatsCounterPass(pContext, TIME_Unify_BuiltinImport, STATS_COUNTER_START));
418-
mpm.add(createBuiltInImportPass(std::move(BuiltinGenericModule), std::move(BuiltinSizeModule)));
413+
mpm.add(createBuiltInImportPass());
419414
mpm.add(createTimeStatsCounterPass(pContext, TIME_Unify_BuiltinImport, STATS_COUNTER_END));
420415
mpm.add(new BIFFlagCtrlResolution(pContext));
421416

@@ -685,20 +680,14 @@ static void CommonOCLBasedPasses(
685680
MEM_SNAPSHOT(IGC::SMS_AFTER_UNIFICATION);
686681
}
687682

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

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

704693
}

IGC/AdaptorOCL/UnifyIROCL.hpp

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

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

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

IGC/AdaptorOCL/dllInterfaceCompute.cpp

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

2425
#include "AdaptorCommon/customApi.hpp"
2526
#include "AdaptorOCL/OCL/LoadBuffer.h"
@@ -1127,13 +1128,6 @@ void dumpOCLProgramBinary(OpenCLProgramContext &Ctx, const char *binaryOutput,
11271128
dumpOCLProgramBinary(name.str().data(), binaryOutput, binarySize);
11281129
}
11291130

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-
11371131
static void WriteSpecConstantsDump(
11381132
const STB_TranslateInputArgs* pInputArgs,
11391133
QWORD hash)
@@ -1416,111 +1410,17 @@ bool TranslateBuildSPMD(
14161410
splitter.setSplittedModuleInOCLContext();
14171411
}
14181412

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-
15131413
oclContext.getModuleMetaData()->csInfo.forcedSIMDSize |= IGC_GET_FLAG_VALUE(ForceOCLSIMDWidth);
15141414

15151415
try
15161416
{
15171417
if (llvm::StringRef(oclContext.getModule()->getTargetTriple()).startswith("spir"))
15181418
{
1519-
IGC::UnifyIRSPIR(&oclContext, std::move(BuiltinGenericModule), std::move(BuiltinSizeModule));
1419+
IGC::UnifyIRSPIR(&oclContext);
15201420
}
15211421
else // not SPIR
15221422
{
1523-
IGC::UnifyIROCL(&oclContext, std::move(BuiltinGenericModule), std::move(BuiltinSizeModule));
1423+
IGC::UnifyIROCL(&oclContext);
15241424
}
15251425

15261426
if (oclContext.HasError())

IGC/BiFManager/BiFManagerCommon.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*========================== begin_copyright_notice ============================
2+
3+
Copyright (C) 2024 Intel Corporation
4+
5+
SPDX-License-Identifier: MIT
6+
7+
============================= end_copyright_notice ===========================*/
8+
9+
#include "common/LLVMWarningsPush.hpp"
10+
#include <llvm/IR/Module.h>
11+
#include "common/LLVMWarningsPop.hpp"
12+
13+
#include "BiFManagerCommon.hpp"
14+
#include <Probe/Assertion.h>
15+
#include <map>
16+
17+
using namespace std;
18+
using namespace llvm;
19+
using namespace IGC;
20+
using namespace IGC::BiFManager;
21+
22+
BiFManagerCommon::BiFManagerCommon(LLVMContext& Context):
23+
Context(Context)
24+
{
25+
}
26+
27+
BiFManagerCommon::~BiFManagerCommon()
28+
{}
29+
30+
size_t BiFManagerCommon::getHash(const std::string& FlagName)
31+
{
32+
return std::hash<std::string>{}(FlagName);
33+
}
34+
35+
CollectBuiltinsPass::CollectBuiltinsPass(
36+
TFunctionsVec& neededBuiltinsFunc,
37+
std::function<bool(llvm::Function*)> predicate) :
38+
neededBuiltinsFunc(neededBuiltinsFunc),
39+
predicate(predicate)
40+
{}
41+
42+
CollectBuiltinsPass::~CollectBuiltinsPass()
43+
{}
44+
45+
void CollectBuiltinsPass::visitCallInst(llvm::CallInst& callInst)
46+
{
47+
auto pFunc = callInst.getCalledFunction();
48+
49+
if (pFunc != nullptr &&
50+
std::find(
51+
neededBuiltinsFunc.begin(),
52+
neededBuiltinsFunc.end(),
53+
pFunc) == neededBuiltinsFunc.end())
54+
{
55+
if (predicate(pFunc))
56+
{
57+
neededBuiltinsFunc.push_back(pFunc);
58+
}
59+
}
60+
}

0 commit comments

Comments
 (0)