mirror of
https://github.com/RPCS3/rpcs3.git
synced 2024-11-22 02:32:36 +01:00
LLVM 13
This commit is contained in:
parent
37383f4217
commit
69f321a471
4
3rdparty/llvm.cmake
vendored
4
3rdparty/llvm.cmake
vendored
@ -26,7 +26,7 @@ if(WITH_LLVM)
|
|||||||
set(CMAKE_CXX_FLAGS ${CXX_FLAGS_OLD})
|
set(CMAKE_CXX_FLAGS ${CXX_FLAGS_OLD})
|
||||||
|
|
||||||
# now tries to find LLVM again
|
# now tries to find LLVM again
|
||||||
find_package(LLVM 11.0 CONFIG)
|
find_package(LLVM 13.0 CONFIG)
|
||||||
if(NOT LLVM_FOUND)
|
if(NOT LLVM_FOUND)
|
||||||
message(FATAL_ERROR "Couldn't build LLVM from the submodule. You might need to run `git submodule update --init`")
|
message(FATAL_ERROR "Couldn't build LLVM from the submodule. You might need to run `git submodule update --init`")
|
||||||
endif()
|
endif()
|
||||||
@ -39,7 +39,7 @@ if(WITH_LLVM)
|
|||||||
set(LLVM_DIR ${CMAKE_SOURCE_DIR}/${LLVM_DIR})
|
set(LLVM_DIR ${CMAKE_SOURCE_DIR}/${LLVM_DIR})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
find_package(LLVM 11.0 CONFIG)
|
find_package(LLVM 13.0 CONFIG)
|
||||||
|
|
||||||
if (NOT LLVM_FOUND)
|
if (NOT LLVM_FOUND)
|
||||||
if (LLVM_VERSION AND LLVM_VERSION_MAJOR LESS 11)
|
if (LLVM_VERSION AND LLVM_VERSION_MAJOR LESS 11)
|
||||||
|
2
llvm
2
llvm
@ -1 +1 @@
|
|||||||
Subproject commit 5836324d6443a62ed09b84c125029e98324978c3
|
Subproject commit 18f153b33bef2a4e29a0478ddd374b1f19316a46
|
@ -139,9 +139,9 @@ llvm::Value* cpu_translator::bitcast(llvm::Value* val, llvm::Type* type) const
|
|||||||
uint s2 = val->getType()->getScalarSizeInBits();
|
uint s2 = val->getType()->getScalarSizeInBits();
|
||||||
|
|
||||||
if (type->isVectorTy())
|
if (type->isVectorTy())
|
||||||
s1 *= llvm::cast<llvm::VectorType>(type)->getNumElements();
|
s1 *= llvm::cast<llvm::FixedVectorType>(type)->getNumElements();
|
||||||
if (val->getType()->isVectorTy())
|
if (val->getType()->isVectorTy())
|
||||||
s2 *= llvm::cast<llvm::VectorType>(val->getType())->getNumElements();
|
s2 *= llvm::cast<llvm::FixedVectorType>(val->getType())->getNumElements();
|
||||||
|
|
||||||
if (s1 != s2)
|
if (s1 != s2)
|
||||||
{
|
{
|
||||||
@ -183,7 +183,7 @@ std::pair<bool, v128> cpu_translator::get_const_vector<v128>(llvm::Value* c, u32
|
|||||||
fmt::throw_exception("[0x%x, %u] Not a vector", _pos, _line);
|
fmt::throw_exception("[0x%x, %u] Not a vector", _pos, _line);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auto v = llvm::cast<llvm::VectorType>(t); v->getScalarSizeInBits() * v->getNumElements() != 128)
|
if (auto v = llvm::cast<llvm::FixedVectorType>(t); v->getScalarSizeInBits() * v->getNumElements() != 128)
|
||||||
{
|
{
|
||||||
fmt::throw_exception("[0x%x, %u] Bad vector size: i%ux%u", _pos, _line, v->getScalarSizeInBits(), v->getNumElements());
|
fmt::throw_exception("[0x%x, %u] Bad vector size: i%ux%u", _pos, _line, v->getScalarSizeInBits(), v->getNumElements());
|
||||||
}
|
}
|
||||||
@ -267,7 +267,7 @@ llvm::Constant* cpu_translator::make_const_vector<v128>(v128 v, llvm::Type* t, u
|
|||||||
}
|
}
|
||||||
|
|
||||||
ensure(t->isVectorTy());
|
ensure(t->isVectorTy());
|
||||||
ensure(128 == t->getScalarSizeInBits() * llvm::cast<llvm::VectorType>(t)->getNumElements());
|
ensure(128 == t->getScalarSizeInBits() * llvm::cast<llvm::FixedVectorType>(t)->getNumElements());
|
||||||
|
|
||||||
const auto sct = t->getScalarType();
|
const auto sct = t->getScalarType();
|
||||||
|
|
||||||
|
@ -3493,10 +3493,10 @@ public:
|
|||||||
shuffle.value = m_ir->CreateZExt(shuffle.value, get_type<u32[32]>());
|
shuffle.value = m_ir->CreateZExt(shuffle.value, get_type<u32[32]>());
|
||||||
intermediate.value = m_ir->CreateShuffleVector(data0, data1, shuffle.value);
|
intermediate.value = m_ir->CreateShuffleVector(data0, data1, shuffle.value);
|
||||||
|
|
||||||
// expand the shuffle index to 256 bits with zeroes
|
// expand the shuffle index to 256 bits with zeroes
|
||||||
shuffleindex.value = m_ir->CreateShuffleVector(index, zeroes, shuffle.value);
|
shuffleindex.value = m_ir->CreateShuffleVector(index, zeroes, shuffle.value);
|
||||||
|
|
||||||
// permute
|
// permute
|
||||||
intermediate.value = m_ir->CreateCall(get_intrinsic(llvm::Intrinsic::x86_avx512_permvar_qi_256), {intermediate.value, shuffleindex.value});
|
intermediate.value = m_ir->CreateCall(get_intrinsic(llvm::Intrinsic::x86_avx512_permvar_qi_256), {intermediate.value, shuffleindex.value});
|
||||||
|
|
||||||
// convert the 256 bit vector back to 128 bits
|
// convert the 256 bit vector back to 128 bits
|
||||||
|
@ -21,7 +21,7 @@ const ppu_decoder<ppu_iname> s_ppu_iname;
|
|||||||
PPUTranslator::PPUTranslator(LLVMContext& context, Module* _module, const ppu_module& info, ExecutionEngine& engine)
|
PPUTranslator::PPUTranslator(LLVMContext& context, Module* _module, const ppu_module& info, ExecutionEngine& engine)
|
||||||
: cpu_translator(_module, false)
|
: cpu_translator(_module, false)
|
||||||
, m_info(info)
|
, m_info(info)
|
||||||
, m_pure_attr(AttributeList::get(m_context, AttributeList::FunctionIndex, {Attribute::NoUnwind, Attribute::ReadNone}))
|
, m_pure_attr()
|
||||||
{
|
{
|
||||||
// Bind context
|
// Bind context
|
||||||
cpu_translator::initialize(context, engine);
|
cpu_translator::initialize(context, engine);
|
||||||
@ -189,7 +189,7 @@ Function* PPUTranslator::Translate(const ppu_function& info)
|
|||||||
if (need_check)
|
if (need_check)
|
||||||
{
|
{
|
||||||
// Check status register in the entry block
|
// Check status register in the entry block
|
||||||
const auto vstate = m_ir->CreateLoad(m_ir->CreateStructGEP(nullptr, m_thread, 1), true);
|
const auto vstate = m_ir->CreateLoad(m_ir->CreateStructGEP(m_thread, 1), true);
|
||||||
const auto vcheck = BasicBlock::Create(m_context, "__test", m_function);
|
const auto vcheck = BasicBlock::Create(m_context, "__test", m_function);
|
||||||
m_ir->CreateCondBr(m_ir->CreateIsNull(vstate), body, vcheck, m_md_likely);
|
m_ir->CreateCondBr(m_ir->CreateIsNull(vstate), body, vcheck, m_md_likely);
|
||||||
|
|
||||||
@ -236,7 +236,7 @@ Function* PPUTranslator::Translate(const ppu_function& info)
|
|||||||
|
|
||||||
if (ppu_get_far_jump(m_addr + base))
|
if (ppu_get_far_jump(m_addr + base))
|
||||||
{
|
{
|
||||||
// Branch into an HLEd instruction using the jump table
|
// Branch into an HLEd instruction using the jump table
|
||||||
FlushRegisters();
|
FlushRegisters();
|
||||||
CallFunction(0, m_reloc ? m_ir->CreateAdd(m_ir->getInt64(m_addr), m_seg0) : m_ir->getInt64(m_addr));
|
CallFunction(0, m_reloc ? m_ir->CreateAdd(m_ir->getInt64(m_addr), m_seg0) : m_ir->getInt64(m_addr));
|
||||||
continue;
|
continue;
|
||||||
@ -324,7 +324,7 @@ Type* PPUTranslator::ScaleType(Type* type, s32 pow2)
|
|||||||
|
|
||||||
ensure(scaled);
|
ensure(scaled);
|
||||||
const auto new_type = m_ir->getIntNTy(scaled);
|
const auto new_type = m_ir->getIntNTy(scaled);
|
||||||
const auto vec_type = dyn_cast<VectorType>(type);
|
const auto vec_type = dyn_cast<FixedVectorType>(type);
|
||||||
return vec_type ? VectorType::get(new_type, vec_type->getNumElements(), false) : cast<Type>(new_type);
|
return vec_type ? VectorType::get(new_type, vec_type->getNumElements(), false) : cast<Type>(new_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -375,7 +375,7 @@ void PPUTranslator::CallFunction(u64 target, Value* indirect)
|
|||||||
|
|
||||||
if (indirect)
|
if (indirect)
|
||||||
{
|
{
|
||||||
m_ir->CreateStore(Trunc(indirect, GetType<u32>()), m_ir->CreateStructGEP(nullptr, m_thread, static_cast<uint>(&m_cia - m_locals)), true);
|
m_ir->CreateStore(Trunc(indirect, GetType<u32>()), m_ir->CreateStructGEP(m_thread, static_cast<uint>(&m_cia - m_locals)), true);
|
||||||
|
|
||||||
// Try to optimize
|
// Try to optimize
|
||||||
if (auto inst = dyn_cast_or_null<Instruction>(indirect))
|
if (auto inst = dyn_cast_or_null<Instruction>(indirect))
|
||||||
@ -412,7 +412,7 @@ Value* PPUTranslator::RegInit(Value*& local)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// (Re)Initialize global, will be written in FlushRegisters
|
// (Re)Initialize global, will be written in FlushRegisters
|
||||||
m_globals[index] = m_ir->CreateStructGEP(nullptr, m_thread, index);
|
m_globals[index] = m_ir->CreateStructGEP(m_thread, index);
|
||||||
|
|
||||||
return m_globals[index];
|
return m_globals[index];
|
||||||
}
|
}
|
||||||
@ -428,7 +428,7 @@ Value* PPUTranslator::RegLoad(Value*& local)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load from the global value
|
// Load from the global value
|
||||||
local = m_ir->CreateLoad(m_ir->CreateStructGEP(nullptr, m_thread, index));
|
local = m_ir->CreateLoad(m_ir->CreateStructGEP(m_thread, index));
|
||||||
return local;
|
return local;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -525,9 +525,9 @@ Value* PPUTranslator::Broadcast(Value* value, u32 count)
|
|||||||
std::pair<Value*, Value*> PPUTranslator::Saturate(Value* value, CmpInst::Predicate inst, Value* extreme)
|
std::pair<Value*, Value*> PPUTranslator::Saturate(Value* value, CmpInst::Predicate inst, Value* extreme)
|
||||||
{
|
{
|
||||||
// Modify args
|
// Modify args
|
||||||
if (auto v = dyn_cast<VectorType>(value->getType()); v && !extreme->getType()->isVectorTy())
|
if (auto v = dyn_cast<FixedVectorType>(value->getType()); v && !extreme->getType()->isVectorTy())
|
||||||
extreme = Broadcast(extreme, v->getNumElements());
|
extreme = Broadcast(extreme, v->getNumElements());
|
||||||
if (auto e = dyn_cast<VectorType>(extreme->getType()); e && !value->getType()->isVectorTy())
|
if (auto e = dyn_cast<FixedVectorType>(extreme->getType()); e && !value->getType()->isVectorTy())
|
||||||
value = Broadcast(value, e->getNumElements());
|
value = Broadcast(value, e->getNumElements());
|
||||||
|
|
||||||
// Compare args
|
// Compare args
|
||||||
@ -554,7 +554,7 @@ Value* PPUTranslator::Scale(Value* value, s32 scale)
|
|||||||
const auto type = value->getType();
|
const auto type = value->getType();
|
||||||
const auto power = std::pow(2, scale);
|
const auto power = std::pow(2, scale);
|
||||||
|
|
||||||
if (auto v = dyn_cast<VectorType>(type))
|
if (auto v = dyn_cast<FixedVectorType>(type))
|
||||||
{
|
{
|
||||||
return m_ir->CreateFMul(value, ConstantVector::getSplat({v->getNumElements(), false}, ConstantFP::get(v->getElementType(), power)));
|
return m_ir->CreateFMul(value, ConstantVector::getSplat({v->getNumElements(), false}, ConstantFP::get(v->getElementType(), power)));
|
||||||
}
|
}
|
||||||
@ -580,7 +580,7 @@ Value* PPUTranslator::Shuffle(Value* left, Value* right, std::initializer_list<u
|
|||||||
{
|
{
|
||||||
std::vector<u32> data; data.reserve(indices.size());
|
std::vector<u32> data; data.reserve(indices.size());
|
||||||
|
|
||||||
const u32 mask = cast<VectorType>(type)->getNumElements() - 1;
|
const u32 mask = cast<FixedVectorType>(type)->getNumElements() - 1;
|
||||||
|
|
||||||
// Transform indices (works for vectors with size 2^N)
|
// Transform indices (works for vectors with size 2^N)
|
||||||
for (usz i = 0; i < indices.size(); i++)
|
for (usz i = 0; i < indices.size(); i++)
|
||||||
@ -2003,7 +2003,7 @@ void PPUTranslator::BC(ppu_opcode_t op)
|
|||||||
|
|
||||||
if (op.lk)
|
if (op.lk)
|
||||||
{
|
{
|
||||||
m_ir->CreateStore(GetAddr(+4), m_ir->CreateStructGEP(nullptr, m_thread, static_cast<uint>(&m_lr - m_locals)));
|
m_ir->CreateStore(GetAddr(+4), m_ir->CreateStructGEP(m_thread, static_cast<uint>(&m_lr - m_locals)));
|
||||||
}
|
}
|
||||||
|
|
||||||
UseCondition(CheckBranchProbability(op.bo), CheckBranchCondition(op.bo, op.bi));
|
UseCondition(CheckBranchProbability(op.bo), CheckBranchCondition(op.bo, op.bi));
|
||||||
@ -2073,7 +2073,7 @@ void PPUTranslator::BCLR(ppu_opcode_t op)
|
|||||||
|
|
||||||
if (op.lk)
|
if (op.lk)
|
||||||
{
|
{
|
||||||
m_ir->CreateStore(GetAddr(+4), m_ir->CreateStructGEP(nullptr, m_thread, static_cast<uint>(&m_lr - m_locals)));
|
m_ir->CreateStore(GetAddr(+4), m_ir->CreateStructGEP(m_thread, static_cast<uint>(&m_lr - m_locals)));
|
||||||
}
|
}
|
||||||
|
|
||||||
UseCondition(CheckBranchProbability(op.bo), CheckBranchCondition(op.bo, op.bi));
|
UseCondition(CheckBranchProbability(op.bo), CheckBranchCondition(op.bo, op.bi));
|
||||||
@ -2136,7 +2136,7 @@ void PPUTranslator::BCCTR(ppu_opcode_t op)
|
|||||||
|
|
||||||
if (op.lk)
|
if (op.lk)
|
||||||
{
|
{
|
||||||
m_ir->CreateStore(GetAddr(+4), m_ir->CreateStructGEP(nullptr, m_thread, static_cast<uint>(&m_lr - m_locals)));
|
m_ir->CreateStore(GetAddr(+4), m_ir->CreateStructGEP(m_thread, static_cast<uint>(&m_lr - m_locals)));
|
||||||
}
|
}
|
||||||
|
|
||||||
UseCondition(CheckBranchProbability(op.bo | 0x4), CheckBranchCondition(op.bo | 0x4, op.bi));
|
UseCondition(CheckBranchProbability(op.bo | 0x4), CheckBranchCondition(op.bo | 0x4, op.bi));
|
||||||
@ -2551,8 +2551,8 @@ void PPUTranslator::MFOCRF(ppu_opcode_t op)
|
|||||||
else if (std::none_of(m_cr + 0, m_cr + 32, [](auto* p) { return p; }))
|
else if (std::none_of(m_cr + 0, m_cr + 32, [](auto* p) { return p; }))
|
||||||
{
|
{
|
||||||
// MFCR (optimized)
|
// MFCR (optimized)
|
||||||
Value* ln0 = m_ir->CreateIntToPtr(m_ir->CreatePtrToInt(m_ir->CreateStructGEP(nullptr, m_thread, 99), GetType<uptr>()), GetType<u8[16]>()->getPointerTo());
|
Value* ln0 = m_ir->CreateIntToPtr(m_ir->CreatePtrToInt(m_ir->CreateStructGEP(m_thread, 99), GetType<uptr>()), GetType<u8[16]>()->getPointerTo());
|
||||||
Value* ln1 = m_ir->CreateIntToPtr(m_ir->CreatePtrToInt(m_ir->CreateStructGEP(nullptr, m_thread, 115), GetType<uptr>()), GetType<u8[16]>()->getPointerTo());
|
Value* ln1 = m_ir->CreateIntToPtr(m_ir->CreatePtrToInt(m_ir->CreateStructGEP(m_thread, 115), GetType<uptr>()), GetType<u8[16]>()->getPointerTo());
|
||||||
|
|
||||||
ln0 = m_ir->CreateLoad(ln0);
|
ln0 = m_ir->CreateLoad(ln0);
|
||||||
ln1 = m_ir->CreateLoad(ln1);
|
ln1 = m_ir->CreateLoad(ln1);
|
||||||
@ -2868,7 +2868,7 @@ void PPUTranslator::MTOCRF(ppu_opcode_t op)
|
|||||||
|
|
||||||
const auto index = m_ir->CreateAnd(m_ir->CreateLShr(value, 28 - i * 4), 15);
|
const auto index = m_ir->CreateAnd(m_ir->CreateLShr(value, 28 - i * 4), 15);
|
||||||
const auto src = m_ir->CreateGEP(m_mtocr_table, {m_ir->getInt32(0), m_ir->CreateShl(index, 2)});
|
const auto src = m_ir->CreateGEP(m_mtocr_table, {m_ir->getInt32(0), m_ir->CreateShl(index, 2)});
|
||||||
const auto dst = bitcast(m_ir->CreateStructGEP(nullptr, m_thread, static_cast<uint>(m_cr - m_locals) + i * 4), GetType<u8*>());
|
const auto dst = bitcast(m_ir->CreateStructGEP(m_thread, static_cast<uint>(m_cr - m_locals) + i * 4), GetType<u8*>());
|
||||||
Call(GetType<void>(), "llvm.memcpy.p0i8.p0i8.i32", dst, src, m_ir->getInt32(4), m_ir->getFalse());
|
Call(GetType<void>(), "llvm.memcpy.p0i8.p0i8.i32", dst, src, m_ir->getInt32(4), m_ir->getFalse());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5600,7 +5600,7 @@ public:
|
|||||||
|
|
||||||
if (atomic)
|
if (atomic)
|
||||||
{
|
{
|
||||||
const auto val = m_ir->CreateAtomicRMW(llvm::AtomicRMWInst::Xchg, ptr, m_ir->getInt64(0), llvm::AtomicOrdering::Acquire);
|
const auto val = m_ir->CreateAtomicRMW(llvm::AtomicRMWInst::Xchg, ptr, m_ir->getInt64(0), llvm::MaybeAlign{8}, llvm::AtomicOrdering::Acquire);
|
||||||
val0 = val;
|
val0 = val;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user