Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LLVM 13 #11102

Merged
merged 1 commit into from
Nov 3, 2021
Merged

LLVM 13 #11102

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions 3rdparty/llvm.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ if(WITH_LLVM)
set(CMAKE_CXX_FLAGS ${CXX_FLAGS_OLD})

# now tries to find LLVM again
find_package(LLVM 11.0 CONFIG)
find_package(LLVM 13.0 CONFIG)
if(NOT LLVM_FOUND)
message(FATAL_ERROR "Couldn't build LLVM from the submodule. You might need to run `git submodule update --init`")
endif()
Expand All @@ -39,7 +39,7 @@ if(WITH_LLVM)
set(LLVM_DIR ${CMAKE_SOURCE_DIR}/${LLVM_DIR})
endif()

find_package(LLVM 11.0 CONFIG)
find_package(LLVM 13.0 CONFIG)

if (NOT LLVM_FOUND)
if (LLVM_VERSION AND LLVM_VERSION_MAJOR LESS 11)
Expand Down
2 changes: 1 addition & 1 deletion llvm
Submodule llvm updated 6131 files
8 changes: 4 additions & 4 deletions rpcs3/Emu/CPU/CPUTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ llvm::Value* cpu_translator::bitcast(llvm::Value* val, llvm::Type* type) const
uint s2 = val->getType()->getScalarSizeInBits();

if (type->isVectorTy())
s1 *= llvm::cast<llvm::VectorType>(type)->getNumElements();
s1 *= llvm::cast<llvm::FixedVectorType>(type)->getNumElements();
if (val->getType()->isVectorTy())
s2 *= llvm::cast<llvm::VectorType>(val->getType())->getNumElements();
s2 *= llvm::cast<llvm::FixedVectorType>(val->getType())->getNumElements();

if (s1 != s2)
{
Expand Down Expand Up @@ -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);
}

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());
}
Expand Down Expand Up @@ -267,7 +267,7 @@ llvm::Constant* cpu_translator::make_const_vector<v128>(v128 v, llvm::Type* t, u
}

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();

Expand Down
4 changes: 2 additions & 2 deletions rpcs3/Emu/CPU/CPUTranslator.h
Original file line number Diff line number Diff line change
Expand Up @@ -3493,10 +3493,10 @@ class cpu_translator
shuffle.value = m_ir->CreateZExt(shuffle.value, get_type<u32[32]>());
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);

// permute
// permute
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
Expand Down
34 changes: 17 additions & 17 deletions rpcs3/Emu/Cell/PPUTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const ppu_decoder<ppu_iname> s_ppu_iname;
PPUTranslator::PPUTranslator(LLVMContext& context, Module* _module, const ppu_module& info, ExecutionEngine& engine)
: cpu_translator(_module, false)
, m_info(info)
, m_pure_attr(AttributeList::get(m_context, AttributeList::FunctionIndex, {Attribute::NoUnwind, Attribute::ReadNone}))
, m_pure_attr()
{
// Bind context
cpu_translator::initialize(context, engine);
Expand Down Expand Up @@ -189,7 +189,7 @@ Function* PPUTranslator::Translate(const ppu_function& info)
if (need_check)
{
// 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);
m_ir->CreateCondBr(m_ir->CreateIsNull(vstate), body, vcheck, m_md_likely);

Expand Down Expand Up @@ -236,7 +236,7 @@ Function* PPUTranslator::Translate(const ppu_function& info)

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();
CallFunction(0, m_reloc ? m_ir->CreateAdd(m_ir->getInt64(m_addr), m_seg0) : m_ir->getInt64(m_addr));
continue;
Expand Down Expand Up @@ -324,7 +324,7 @@ Type* PPUTranslator::ScaleType(Type* type, s32 pow2)

ensure(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);
}

Expand Down Expand Up @@ -375,7 +375,7 @@ void PPUTranslator::CallFunction(u64 target, Value* 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
if (auto inst = dyn_cast_or_null<Instruction>(indirect))
Expand Down Expand Up @@ -412,7 +412,7 @@ Value* PPUTranslator::RegInit(Value*& local)
}

// (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];
}
Expand All @@ -428,7 +428,7 @@ Value* PPUTranslator::RegLoad(Value*& local)
}

// 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;
}

Expand Down Expand Up @@ -525,9 +525,9 @@ Value* PPUTranslator::Broadcast(Value* value, u32 count)
std::pair<Value*, Value*> PPUTranslator::Saturate(Value* value, CmpInst::Predicate inst, Value* extreme)
{
// 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());
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());

// Compare args
Expand All @@ -554,7 +554,7 @@ Value* PPUTranslator::Scale(Value* value, s32 scale)
const auto type = value->getType();
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)));
}
Expand All @@ -580,7 +580,7 @@ Value* PPUTranslator::Shuffle(Value* left, Value* right, std::initializer_list<u
{
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)
for (usz i = 0; i < indices.size(); i++)
Expand Down Expand Up @@ -2003,7 +2003,7 @@ void PPUTranslator::BC(ppu_opcode_t op)

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));
Expand Down Expand Up @@ -2073,7 +2073,7 @@ void PPUTranslator::BCLR(ppu_opcode_t op)

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));
Expand Down Expand Up @@ -2136,7 +2136,7 @@ void PPUTranslator::BCCTR(ppu_opcode_t op)

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));
Expand Down Expand Up @@ -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; }))
{
// MFCR (optimized)
Value* ln0 = m_ir->CreateIntToPtr(m_ir->CreatePtrToInt(m_ir->CreateStructGEP(nullptr, 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* 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(m_thread, 115), GetType<uptr>()), GetType<u8[16]>()->getPointerTo());

ln0 = m_ir->CreateLoad(ln0);
ln1 = m_ir->CreateLoad(ln1);
Expand Down Expand Up @@ -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 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());
}
}
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/SPURecompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5600,7 +5600,7 @@ class spu_llvm_recompiler : public spu_recompiler_base, public cpu_translator

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;
}
else
Expand Down