swr: [rasterizer jitter] fixes for icc in vs2015 compat mode

- Move most jitter functionality into SwrJit namespace
- Avoid global "using namespace llvm" in headers

Signed-off-by: Tim Rowley <timothy.o.rowley@intel.com>
This commit is contained in:
Tim Rowley 2016-09-20 17:14:54 -05:00
parent b8a6f06c85
commit aaeb07989e
12 changed files with 1621 additions and 1586 deletions

View File

@ -72,6 +72,7 @@
#endif
using namespace llvm;
using namespace SwrJit;
//////////////////////////////////////////////////////////////////////////
/// @brief Contructor for JitManager.

View File

@ -86,7 +86,6 @@ using PassManager = llvm::legacy::PassManager;
#pragma pop_macro("DEBUG")
using namespace llvm;
//////////////////////////////////////////////////////////////////////////
/// JitInstructionSet
/// @brief Subclass of InstructionSet that allows users to override
@ -136,7 +135,7 @@ private:
struct JitLLVMContext : LLVMContext
struct JitLLVMContext : llvm::LLVMContext
{
};
@ -150,32 +149,32 @@ struct JitManager
~JitManager(){};
JitLLVMContext mContext; ///< LLVM compiler
IRBuilder<> mBuilder; ///< LLVM IR Builder
ExecutionEngine* mpExec;
llvm::IRBuilder<> mBuilder; ///< LLVM IR Builder
llvm::ExecutionEngine* mpExec;
// Need to be rebuilt after a JIT and before building new IR
Module* mpCurrentModule;
llvm::Module* mpCurrentModule;
bool mIsModuleFinalized;
uint32_t mJitNumber;
uint32_t mVWidth;
// Built in types.
Type* mInt8Ty;
Type* mInt32Ty;
Type* mInt64Ty;
Type* mFP32Ty;
StructType* mV4FP32Ty;
StructType* mV4Int32Ty;
llvm::Type* mInt8Ty;
llvm::Type* mInt32Ty;
llvm::Type* mInt64Ty;
llvm::Type* mFP32Ty;
llvm::StructType* mV4FP32Ty;
llvm::StructType* mV4Int32Ty;
Type* mSimtFP32Ty;
Type* mSimtInt32Ty;
llvm::Type* mSimtFP32Ty;
llvm::Type* mSimtInt32Ty;
Type* mSimdVectorInt32Ty;
Type* mSimdVectorTy;
llvm::Type* mSimdVectorInt32Ty;
llvm::Type* mSimdVectorTy;
// fetch shader types
FunctionType* mFetchShaderTy;
llvm::FunctionType* mFetchShaderTy;
JitInstructionSet mArch;
std::string mCore;
@ -183,6 +182,6 @@ struct JitManager
void SetupNewModule();
bool SetupModuleFromIR(const uint8_t *pIR);
void DumpAsm(Function* pFunction, const char* fileName);
static void DumpToFile(Function *f, const char *fileName);
void DumpAsm(llvm::Function* pFunction, const char* fileName);
static void DumpToFile(llvm::Function *f, const char *fileName);
};

View File

@ -37,6 +37,9 @@
// components with bit-widths <= the QUANTIZE_THRESHOLD will be quantized
#define QUANTIZE_THRESHOLD 2
using namespace llvm;
using namespace SwrJit;
//////////////////////////////////////////////////////////////////////////
/// Interface to Jitting a blend shader
//////////////////////////////////////////////////////////////////////////

View File

@ -30,49 +30,53 @@
#include "builder.h"
using namespace llvm;
//////////////////////////////////////////////////////////////////////////
/// @brief Contructor for Builder.
/// @param pJitMgr - JitManager which contains modules, function passes, etc.
Builder::Builder(JitManager *pJitMgr)
: mpJitMgr(pJitMgr)
namespace SwrJit
{
mVWidth = pJitMgr->mVWidth;
using namespace llvm;
mpIRBuilder = &pJitMgr->mBuilder;
mVoidTy = Type::getVoidTy(pJitMgr->mContext);
mFP16Ty = Type::getHalfTy(pJitMgr->mContext);
mFP32Ty = Type::getFloatTy(pJitMgr->mContext);
mDoubleTy = Type::getDoubleTy(pJitMgr->mContext);
mInt1Ty = Type::getInt1Ty(pJitMgr->mContext);
mInt8Ty = Type::getInt8Ty(pJitMgr->mContext);
mInt16Ty = Type::getInt16Ty(pJitMgr->mContext);
mInt32Ty = Type::getInt32Ty(pJitMgr->mContext);
mInt8PtrTy = PointerType::get(mInt8Ty, 0);
mInt16PtrTy = PointerType::get(mInt16Ty, 0);
mInt32PtrTy = PointerType::get(mInt32Ty, 0);
mInt64Ty = Type::getInt64Ty(pJitMgr->mContext);
mV4FP32Ty = StructType::get(pJitMgr->mContext, std::vector<Type*>(4, mFP32Ty), false); // vector4 float type (represented as structure)
mV4Int32Ty = StructType::get(pJitMgr->mContext, std::vector<Type*>(4, mInt32Ty), false); // vector4 int type
mSimdInt1Ty = VectorType::get(mInt1Ty, mVWidth);
mSimdInt16Ty = VectorType::get(mInt16Ty, mVWidth);
mSimdInt32Ty = VectorType::get(mInt32Ty, mVWidth);
mSimdInt64Ty = VectorType::get(mInt64Ty, mVWidth);
mSimdFP16Ty = VectorType::get(mFP16Ty, mVWidth);
mSimdFP32Ty = VectorType::get(mFP32Ty, mVWidth);
mSimdVectorTy = StructType::get(pJitMgr->mContext, std::vector<Type*>(4, mSimdFP32Ty), false);
if (sizeof(uint32_t*) == 4)
//////////////////////////////////////////////////////////////////////////
/// @brief Contructor for Builder.
/// @param pJitMgr - JitManager which contains modules, function passes, etc.
Builder::Builder(JitManager *pJitMgr)
: mpJitMgr(pJitMgr)
{
mIntPtrTy = mInt32Ty;
mSimdIntPtrTy = mSimdInt32Ty;
}
else
{
SWR_ASSERT(sizeof(uint32_t*) == 8);
mIntPtrTy = mInt64Ty;
mSimdIntPtrTy = mSimdInt64Ty;
mVWidth = pJitMgr->mVWidth;
mpIRBuilder = &pJitMgr->mBuilder;
mVoidTy = Type::getVoidTy(pJitMgr->mContext);
mFP16Ty = Type::getHalfTy(pJitMgr->mContext);
mFP32Ty = Type::getFloatTy(pJitMgr->mContext);
mDoubleTy = Type::getDoubleTy(pJitMgr->mContext);
mInt1Ty = Type::getInt1Ty(pJitMgr->mContext);
mInt8Ty = Type::getInt8Ty(pJitMgr->mContext);
mInt16Ty = Type::getInt16Ty(pJitMgr->mContext);
mInt32Ty = Type::getInt32Ty(pJitMgr->mContext);
mInt8PtrTy = PointerType::get(mInt8Ty, 0);
mInt16PtrTy = PointerType::get(mInt16Ty, 0);
mInt32PtrTy = PointerType::get(mInt32Ty, 0);
mInt64Ty = Type::getInt64Ty(pJitMgr->mContext);
mV4FP32Ty = StructType::get(pJitMgr->mContext, std::vector<Type*>(4, mFP32Ty), false); // vector4 float type (represented as structure)
mV4Int32Ty = StructType::get(pJitMgr->mContext, std::vector<Type*>(4, mInt32Ty), false); // vector4 int type
mSimdInt1Ty = VectorType::get(mInt1Ty, mVWidth);
mSimdInt16Ty = VectorType::get(mInt16Ty, mVWidth);
mSimdInt32Ty = VectorType::get(mInt32Ty, mVWidth);
mSimdInt64Ty = VectorType::get(mInt64Ty, mVWidth);
mSimdFP16Ty = VectorType::get(mFP16Ty, mVWidth);
mSimdFP32Ty = VectorType::get(mFP32Ty, mVWidth);
mSimdVectorTy = StructType::get(pJitMgr->mContext, std::vector<Type*>(4, mSimdFP32Ty), false);
mSimdVectorTRTy = StructType::get(pJitMgr->mContext, std::vector<Type*>(5, mSimdFP32Ty), false);
if (sizeof(uint32_t*) == 4)
{
mIntPtrTy = mInt32Ty;
mSimdIntPtrTy = mSimdInt32Ty;
}
else
{
SWR_ASSERT(sizeof(uint32_t*) == 8);
mIntPtrTy = mInt64Ty;
mSimdIntPtrTy = mSimdInt64Ty;
}
}
}

View File

@ -32,47 +32,49 @@
#include "JitManager.h"
#include "common/formats.h"
using namespace llvm;
struct Builder
namespace SwrJit
{
Builder(JitManager *pJitMgr);
IRBuilder<>* IRB() { return mpIRBuilder; };
JitManager* JM() { return mpJitMgr; }
using namespace llvm;
struct Builder
{
Builder(JitManager *pJitMgr);
IRBuilder<>* IRB() { return mpIRBuilder; };
JitManager* JM() { return mpJitMgr; }
JitManager* mpJitMgr;
IRBuilder<>* mpIRBuilder;
JitManager* mpJitMgr;
IRBuilder<>* mpIRBuilder;
uint32_t mVWidth;
uint32_t mVWidth;
// Built in types.
Type* mVoidTy;
Type* mInt1Ty;
Type* mInt8Ty;
Type* mInt16Ty;
Type* mInt32Ty;
Type* mInt64Ty;
Type* mIntPtrTy;
Type* mFP16Ty;
Type* mFP32Ty;
Type* mDoubleTy;
Type* mInt8PtrTy;
Type* mInt16PtrTy;
Type* mInt32PtrTy;
Type* mSimdFP16Ty;
Type* mSimdFP32Ty;
Type* mSimdInt1Ty;
Type* mSimdInt16Ty;
Type* mSimdInt32Ty;
Type* mSimdInt64Ty;
Type* mSimdIntPtrTy;
Type* mSimdVectorTy;
StructType* mV4FP32Ty;
StructType* mV4Int32Ty;
// Built in types.
Type* mVoidTy;
Type* mInt1Ty;
Type* mInt8Ty;
Type* mInt16Ty;
Type* mInt32Ty;
Type* mInt64Ty;
Type* mIntPtrTy;
Type* mFP16Ty;
Type* mFP32Ty;
Type* mDoubleTy;
Type* mInt8PtrTy;
Type* mInt16PtrTy;
Type* mInt32PtrTy;
Type* mSimdFP16Ty;
Type* mSimdFP32Ty;
Type* mSimdInt1Ty;
Type* mSimdInt16Ty;
Type* mSimdInt32Ty;
Type* mSimdInt64Ty;
Type* mSimdIntPtrTy;
Type* mSimdVectorTy;
Type* mSimdVectorTRTy;
StructType* mV4FP32Ty;
StructType* mV4Int32Ty;
#include "builder_gen.h"
#include "builder_x86.h"
#include "builder_misc.h"
#include "builder_math.h"
};
};
}

File diff suppressed because it is too large Load Diff

View File

@ -35,6 +35,8 @@
#include <tuple>
//#define FETCH_DUMP_VERTEX 1
using namespace llvm;
using namespace SwrJit;
bool isComponentEnabled(ComponentEnable enableMask, uint8_t component);

View File

@ -259,7 +259,11 @@ def generate_gen_cpp(functions, output_file):
output_lines += [
'#include \"builder.h\"',
''
'',
'namespace SwrJit',
'{',
' using namespace llvm;',
'',
]
for func in functions:
@ -277,14 +281,14 @@ def generate_gen_cpp(functions, output_file):
first_arg = False
output_lines += [
'//////////////////////////////////////////////////////////////////////////',
'%sBuilder::%s(%s)' % (func['return'], name, func['args_nodefs']),
'{',
' return IRB()->%s(%s);' % (func['name'], func_args),
'}',
' //////////////////////////////////////////////////////////////////////////',
' %sBuilder::%s(%s)' % (func['return'], name, func['args_nodefs']),
' {',
' return IRB()->%s(%s);' % (func['name'], func_args),
' }',
'',
]
output_lines.append('}')
output_file.write('\n'.join(output_lines) + '\n')
"""
@ -326,7 +330,11 @@ def generate_x86_cpp(output_file):
output_lines += [
'#include \"builder.h\"',
''
'',
'namespace SwrJit',
'{',
' using namespace llvm;',
'',
]
for inst in intrinsics:
@ -344,10 +352,10 @@ def generate_x86_cpp(output_file):
first = False
output_lines += [
'//////////////////////////////////////////////////////////////////////////',
'Value *Builder::%s(%s)' % (inst[0], args),
'{',
' Function *func = Intrinsic::getDeclaration(JM()->mpCurrentModule, Intrinsic::%s);' % inst[1],
' //////////////////////////////////////////////////////////////////////////',
' Value *Builder::%s(%s)' % (inst[0], args),
' {',
' Function *func = Intrinsic::getDeclaration(JM()->mpCurrentModule, Intrinsic::%s);' % inst[1],
]
if inst[0] == "VPERMD":
rev_args = ''
@ -360,21 +368,22 @@ def generate_x86_cpp(output_file):
output_lines += [
'#if (HAVE_LLVM == 0x306) && (LLVM_VERSION_PATCH == 0)',
' return CALL(func, std::initializer_list<Value*>{%s});' % rev_args,
' return CALL(func, std::initializer_list<Value*>{%s});' % rev_args,
'#else',
]
output_lines += [
' return CALL(func, std::initializer_list<Value*>{%s});' % pass_args,
' return CALL(func, std::initializer_list<Value*>{%s});' % pass_args,
]
if inst[0] == "VPERMD":
output_lines += [
'#endif',
]
output_lines += [
'}',
' }',
'',
]
output_lines.append('}')
output_file.write('\n'.join(output_lines) + '\n')
"""

View File

@ -59,6 +59,10 @@ header = r"""
#pragma once
namespace SwrJit
{
using namespace llvm;
"""
"""
@ -120,7 +124,7 @@ def gen_llvm_type(type, name, postfix_name, is_pointer, is_pointer_pointer, is_a
elif is_array:
llvm_type = 'ArrayType::get(%s, %s)' % (llvm_type, array_count)
return [' members.push_back( %s ); // %s' % (llvm_type, name)]
return [' members.push_back( %s ); // %s' % (llvm_type, name)]
"""
"""
@ -151,12 +155,12 @@ def gen_llvm_types(input_file, output_file):
struct_name = match.group(3).strip()
output_lines += [
'//////////////////////////////////////////////////////////////////////////',
'/// Generate LLVM type information for %s' % struct_name,
'INLINE static StructType *Gen_%s%s(JitManager* pJitMgr)' % (struct_name, postfix_name),
'{',
' LLVMContext& ctx = pJitMgr->mContext;',
' std::vector<Type*> members;',
' //////////////////////////////////////////////////////////////////////////',
' /// Generate LLVM type information for %s' % struct_name,
' INLINE static StructType *Gen_%s%s(JitManager* pJitMgr)' % (struct_name, postfix_name),
' {',
' LLVMContext& ctx = pJitMgr->mContext;',
' std::vector<Type*> members;',
'',
]
@ -309,16 +313,17 @@ def gen_llvm_types(input_file, output_file):
if (end_of_struct):
output_lines += [
'',
' return StructType::get(ctx, members, false);',
'}',
' return StructType::get(ctx, members, false);',
' }',
'',
]
for i in range(len(llvm_args)):
output_lines.append('static const uint32_t %s%s_%s = %s;' % (struct_name, postfix_name, llvm_args[i], i))
output_lines.append(' static const uint32_t %s%s_%s = %s;' % (struct_name, postfix_name, llvm_args[i], i))
output_lines.append('')
output_lines.append('}')
output_file.write('\n'.join(output_lines) + '\n')
"""

View File

@ -36,6 +36,9 @@
#include <sstream>
#include <unordered_set>
using namespace llvm;
using namespace SwrJit;
//////////////////////////////////////////////////////////////////////////
/// Interface to Jitting a fetch shader
//////////////////////////////////////////////////////////////////////////

View File

@ -44,6 +44,8 @@
#include "swr_state.h"
#include "swr_screen.h"
using namespace SwrJit;
static unsigned
locate_linkage(ubyte name, ubyte index, struct tgsi_shader_info *info);

View File

@ -60,6 +60,7 @@
#include "swr_tex_sample.h"
#include "swr_context_llvm.h"
using namespace SwrJit;
/**
* This provides the bridge between the sampler state store in