#include "JitManager.h"
#include "fetch_jit.h"
+#pragma push_macro("DEBUG")
+#undef DEBUG
+
#if defined(_WIN32)
#include "llvm/ADT/Triple.h"
#endif
#include "llvm/IR/Function.h"
-#include "llvm/Support/DynamicLibrary.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/ExecutionEngine/JITEventListener.h"
#endif
+#pragma pop_macro("DEBUG")
+
#include "core/state.h"
#include "state_llvm.h"
return false;
}
+ newModule->setDataLayout(mpExec->getDataLayout());
+
mpCurrentModule = newModule.get();
#if defined(_WIN32)
// Needed for MCJIT on windows
return true;
}
-
//////////////////////////////////////////////////////////////////////////
/// @brief Dump function x86 assembly to file.
/// @note This should only be called after the module has been jitted to x86 and the
#endif
#ifndef HAVE_LLVM
-#define HAVE_LLVM (LLVM_VERSION_MAJOR << 8) || LLVM_VERSION_MINOR
+#define HAVE_LLVM ((LLVM_VERSION_MAJOR << 8) | LLVM_VERSION_MINOR)
#endif
#include "llvm/IR/Verifier.h"
#if HAVE_LLVM == 0x306
#include "llvm/PassManager.h"
+using FunctionPassManager = llvm::FunctionPassManager;
+using PassManager = llvm::PassManager;
#else
#include "llvm/IR/LegacyPassManager.h"
+using FunctionPassManager = llvm::legacy::FunctionPassManager;
+using PassManager = llvm::legacy::PassManager;
#endif
#include "llvm/CodeGen/Passes.h"
#include "llvm/Transforms/IPO.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Support/Host.h"
+#include "llvm/Support/DynamicLibrary.h"
#pragma pop_macro("DEBUG")
#include "blend_jit.h"
#include "builder.h"
#include "state_llvm.h"
-#include "llvm/IR/DataLayout.h"
#include <sstream>
JitManager::DumpToFile(blendFunc, "");
-#if HAVE_LLVM == 0x306
- FunctionPassManager
-#else
- llvm::legacy::FunctionPassManager
-#endif
- passes(JM()->mpCurrentModule);
+ ::FunctionPassManager passes(JM()->mpCurrentModule);
passes.add(createBreakCriticalEdgesPass());
passes.add(createCFGSimplificationPass());
#include "builder.h"
#include "common/rdtsc_buckets.h"
-#include "llvm/Support/DynamicLibrary.h"
-
void __cdecl CallPrint(const char* fmt, ...);
//////////////////////////////////////////////////////////////////////////
return CALLA(Callee, args);
}
+#if HAVE_LLVM > 0x306
+CallInst *Builder::CALL(Value *Callee, Value* arg)
+{
+ std::vector<Value*> args;
+ args.push_back(arg);
+ return CALLA(Callee, args);
+}
+
+CallInst *Builder::CALL2(Value *Callee, Value* arg1, Value* arg2)
+{
+ std::vector<Value*> args;
+ args.push_back(arg1);
+ args.push_back(arg2);
+ return CALLA(Callee, args);
+}
+
+CallInst *Builder::CALL3(Value *Callee, Value* arg1, Value* arg2, Value* arg3)
+{
+ std::vector<Value*> args;
+ args.push_back(arg1);
+ args.push_back(arg2);
+ args.push_back(arg3);
+ return CALLA(Callee, args);
+}
+#endif
+
Value *Builder::VRCP(Value *va)
{
return FDIV(VIMMED1(1.0f), va); // 1 / a
// use avx2 permute instruction if available
if(JM()->mArch.AVX2())
{
- // llvm 3.6.0 swapped the order of the args to vpermd
- res = VPERMD(idx, a);
+ res = VPERMD(a, idx);
}
else
{
Value *GEP(Value* ptr, const std::initializer_list<Value*> &indexList);
Value *GEP(Value* ptr, const std::initializer_list<uint32_t> &indexList);
CallInst *CALL(Value *Callee, const std::initializer_list<Value*> &args);
+#if HAVE_LLVM > 0x306
+CallInst *CALL(Value *Callee) { return CALLA(Callee); }
+CallInst *CALL(Value *Callee, Value* arg);
+CallInst *CALL2(Value *Callee, Value* arg1, Value* arg2);
+CallInst *CALL3(Value *Callee, Value* arg1, Value* arg2, Value* arg3);
+#endif
LoadInst *LOAD(Value *BasePtr, const std::initializer_list<uint32_t> &offset, const llvm::Twine& name = "");
LoadInst *LOADV(Value *BasePtr, const std::initializer_list<Value*> &offset, const llvm::Twine& name = "");
#include "fetch_jit.h"
#include "builder.h"
#include "state_llvm.h"
-#include "llvm/IR/DataLayout.h"
#include <sstream>
#include <tuple>
verifyFunction(*fetch);
-#if HAVE_LLVM == 0x306
- FunctionPassManager
-#else
- llvm::legacy::FunctionPassManager
-#endif
- setupPasses(JM()->mpCurrentModule);
+ ::FunctionPassManager setupPasses(JM()->mpCurrentModule);
///@todo We don't need the CFG passes for fetch. (e.g. BreakCriticalEdges and CFGSimplification)
setupPasses.add(createBreakCriticalEdgesPass());
JitManager::DumpToFile(fetch, "se");
-#if HAVE_LLVM == 0x306
- FunctionPassManager
-#else
- llvm::legacy::FunctionPassManager
-#endif
- optPasses(JM()->mpCurrentModule);
+ ::FunctionPassManager optPasses(JM()->mpCurrentModule);
///@todo Haven't touched these either. Need to remove some of these and add others.
optPasses.add(createCFGSimplificationPass());
["VPSHUFB", "x86_avx2_pshuf_b", ["a", "b"]],
["VPMOVSXBD", "x86_avx2_pmovsxbd", ["a"]], # sign extend packed 8bit components
["VPMOVSXWD", "x86_avx2_pmovsxwd", ["a"]], # sign extend packed 16bit components
- ["VPERMD", "x86_avx2_permd", ["idx", "a"]],
+ ["VPERMD", "x86_avx2_permd", ["a", "idx"]],
["VPERMPS", "x86_avx2_permps", ["idx", "a"]],
["VCVTPH2PS", "x86_vcvtph2ps_256", ["a"]],
["VCVTPS2PH", "x86_vcvtps2ph_256", ["a", "round"]],
'Value *Builder::%s(%s)' % (inst[0], args),
'{',
' Function *func = Intrinsic::getDeclaration(JM()->mpCurrentModule, Intrinsic::%s);' % inst[1],
+ ]
+ if inst[0] == "VPERMD":
+ rev_args = ''
+ first = True
+ for arg in reversed(inst[2]):
+ if not first:
+ rev_args += ', '
+ rev_args += arg
+ first = False
+
+ output_lines += [
+ '#if (HAVE_LLVM == 0x306) && (LLVM_VERSION_PATCH == 0)',
+ ' return CALL(func, std::initializer_list<Value*>{%s});' % rev_args,
+ '#else',
+ ]
+ output_lines += [
' return CALL(func, std::initializer_list<Value*>{%s});' % pass_args,
+ ]
+ if inst[0] == "VPERMD":
+ output_lines += [
+ '#endif',
+ ]
+ output_lines += [
'}',
'',
]
JitManager::DumpToFile(soFunc, "SoFunc");
-#if HAVE_LLVM == 0x306
- FunctionPassManager
-#else
- llvm::legacy::FunctionPassManager
-#endif
- passes(JM()->mpCurrentModule);
+ ::FunctionPassManager passes(JM()->mpCurrentModule);
passes.add(createBreakCriticalEdgesPass());
passes.add(createCFGSimplificationPass());