Skip to content

Commit

Permalink
Update LLVM (#1308)
Browse files Browse the repository at this point in the history
* Update LLVM

* Handle switch to new debug info format
  * linked libraries are converted
  * newly created functions (with bodies) are converted
  * updated test expectations
* Bare minimum handling of llvm.is_fpclass (see #1307) to unblock known
  cts failures

* fix typo
  • Loading branch information
alan-baker authored Feb 16, 2024
1 parent e7a0c9b commit 74c1ed0
Show file tree
Hide file tree
Showing 22 changed files with 49 additions and 3 deletions.
2 changes: 1 addition & 1 deletion deps.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"subrepo" : "llvm/llvm-project",
"branch" : "main",
"subdir" : "third_party/llvm",
"commit" : "d5a3de4aeef4f4f1c52692533ddb9fdf45aef9d3"
"commit" : "0f1847cb2c5462a09d65a9b5ac24904ac3c15a0f"
},
{
"name" : "SPIRV-Headers",
Expand Down
1 change: 1 addition & 0 deletions lib/ClusterPodKernelArgumentsPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ clspv::ClusterPodKernelArgumentsPass::run(Module &M, ModuleAnalysisManager &) {

// Create the new function and set key properties.
auto NewFunc = Function::Create(NewFuncTy, F->getLinkage());
NewFunc->setIsNewDbgInfoFormat(true);
// The new function adopts the real name so that linkage to the outside
// world remains the same.
NewFunc->setName(F->getName());
Expand Down
10 changes: 10 additions & 0 deletions lib/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1049,9 +1049,19 @@ bool LinkBuiltinLibrary(llvm::Module *module) {
Err.print("internal_additional_library:", llvm::errs());
return false;
}
for (auto &F : *add_library) {
if (!F.isDeclaration()) {
F.setIsNewDbgInfoFormat(true);
}
}
L.linkInModule(std::move(add_library), 0);
}

for (auto &F : *library) {
if (!F.isDeclaration()) {
F.setIsNewDbgInfoFormat(true);
}
}
L.linkInModule(std::move(library), 0);

return true;
Expand Down
1 change: 1 addition & 0 deletions lib/DefineOpenCLWorkItemBuiltinsPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ Function *getFunctionIfNeeded(Module &M, StringRef Name,
if (D) {
// function must be inserted for use by dependent
F = cast<Function>(M.getOrInsertFunction(Name, FType).getCallee());
F->setIsNewDbgInfoFormat(true);
F->setCallingConv(CallingConv::SPIR_FUNC);
return F;
}
Expand Down
1 change: 1 addition & 0 deletions lib/HideConstantLoadsPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ PreservedAnalyses clspv::HideConstantLoadsPass::run(Module &M,
FunctionType *fnTy = FunctionType::get(loadedTy, {loadedTy}, false);
auto fn_constant = M.getOrInsertFunction(fn_name, fnTy);
fn = cast<Function>(fn_constant.getCallee());
fn->setIsNewDbgInfoFormat(true);
fn->setOnlyReadsMemory();
}

Expand Down
3 changes: 3 additions & 0 deletions lib/LongVectorLoweringPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ Function *getBIFScalarVersion(Function &Builtin) {

if (ScalarFn == nullptr) {
ScalarFn = Function::Create(FunctionTy, Builtin.getLinkage(), ScalarName);
ScalarFn->setIsNewDbgInfoFormat(true);
ScalarFn->setCallingConv(Builtin.getCallingConv());
ScalarFn->copyAttributesFrom(&Builtin);

Expand Down Expand Up @@ -503,6 +504,7 @@ Function *createFunctionWithMappedTypes(Function &F,
assert(!F.isVarArg() && "varargs not supported");

auto *Wrapper = Function::Create(EquivalentFunctionTy, F.getLinkage());
Wrapper->setIsNewDbgInfoFormat(true);
Wrapper->takeName(&F);
Wrapper->setCallingConv(F.getCallingConv());
Wrapper->copyAttributesFrom(&F);
Expand Down Expand Up @@ -584,6 +586,7 @@ Value *convertOpAnyOrAllOperation(CallInst &VectorCall,
FunctionType::get(VectorCall.getFunctionType()->getReturnType(),
ParamTys, false),
OpAnyOrAllInitialFunction->getLinkage(), OpAnyOrAllFunctionName);
OpAnyOrAllFunction->setIsNewDbgInfoFormat(true);

OpAnyOrAllFunction->setCallingConv(
OpAnyOrAllInitialFunction->getCallingConv());
Expand Down
1 change: 1 addition & 0 deletions lib/LowerAddrSpaceCastPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ llvm::Value *clspv::LowerAddrSpaceCastPass::visitCallInst(llvm::CallInst &I) {
return eqF;

eqF = Function::Create(FunctionTy, F->getLinkage(), Name);
eqF->setIsNewDbgInfoFormat(true);
FunctionMap[F] = eqF;
M->getFunctionList().push_front(eqF);

Expand Down
1 change: 1 addition & 0 deletions lib/MultiVersionUBOFunctionsPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ Function *clspv::MultiVersionUBOFunctionsPass::AddExtraArguments(
auto pair =
module->getOrInsertFunction(fn->getName(), new_type, fn->getAttributes());
Function *new_function = cast<Function>(pair.getCallee());
new_function->setIsNewDbgInfoFormat(true);
new_function->setCallingConv(fn->getCallingConv());
new_function->copyMetadata(fn, 0);

Expand Down
1 change: 1 addition & 0 deletions lib/PhysicalPointerArgsPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ PreservedAnalyses clspv::PhysicalPointerArgsPass::run(Module &M,
FunctionType::get(F.getReturnType(), NewParamTypes, false);

auto NewFunc = Function::Create(NewFuncTy, F.getLinkage());
NewFunc->setIsNewDbgInfoFormat(true);
// The new function adopts the real name so that linkage to the outside
// world remains the same.
NewFunc->setName(F.getName());
Expand Down
1 change: 1 addition & 0 deletions lib/PrintfPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ void clspv::PrintfPass::DefinePrintfInstance(Module &M, CallInst *CI,
auto FuncCallee = M.getOrInsertFunction(FuncName, FuncTy);
auto *Func = dyn_cast<Function>(FuncCallee.getCallee());
assert(Func);
Func->setIsNewDbgInfoFormat(true);

auto *NewCI = CallInst::Create(Func, NewArgs, "", CI);
CI->replaceAllUsesWith(NewCI);
Expand Down
1 change: 1 addition & 0 deletions lib/RemoveUnusedArguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ void clspv::RemoveUnusedArguments::removeUnusedParameters(
auto inserted =
M.getOrInsertFunction(f->getName(), new_type, fn_attrs).getCallee();
Function *new_function = cast<Function>(inserted);
new_function->setIsNewDbgInfoFormat(true);
new_function->setCallingConv(f->getCallingConv());
new_function->copyMetadata(f, 0);

Expand Down
18 changes: 18 additions & 0 deletions lib/ReplaceLLVMIntrinsicsPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ bool clspv::ReplaceLLVMIntrinsicsPass::runOnFunction(Function &F) {
return replaceAddSubSat(F, true, false);
case Intrinsic::sadd_sat:
return replaceAddSubSat(F, true, true);
case Intrinsic::is_fpclass:
return replaceIsFpClass(F);
// SPIR-V OpAssumeTrueKHR requires ExpectAssumeKHR capability in SPV_KHR_expect_assume extension.
// Vulkan doesn't support that, so remove assume declaration.
case Intrinsic::assume:
Expand Down Expand Up @@ -130,6 +132,22 @@ bool clspv::ReplaceLLVMIntrinsicsPass::replaceCallsWithValue(
return !ToRemove.empty();
}

bool clspv::ReplaceLLVMIntrinsicsPass::replaceIsFpClass(Function &F) {
return replaceCallsWithValue(F, [](CallInst *call) {
auto mask = cast<ConstantInt>(call->getArgOperand(1))->getZExtValue();
Value *result = nullptr;
IRBuilder<> builder(call);
// TODO(#1307): handle other codes
if (mask & 0x40) {
return builder.CreateFCmpOEQ(
call->getArgOperand(0),
Constant::getNullValue(call->getArgOperand(0)->getType()));
}
assert(false);
return result;
});
}

bool clspv::ReplaceLLVMIntrinsicsPass::replaceBswap(Function &F) {
return replaceCallsWithValue(F, [](CallInst *call) {
Type *Ty = call->getType();
Expand Down
1 change: 1 addition & 0 deletions lib/ReplaceLLVMIntrinsicsPass.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ struct ReplaceLLVMIntrinsicsPass
bool replaceCountZeroes(llvm::Function &F, bool leading);
bool replaceCopysign(llvm::Function &F);
bool replaceAddSubSat(llvm::Function &F, bool is_signed, bool is_add);
bool replaceIsFpClass(llvm::Function &F);

bool replaceCallsWithValue(
llvm::Function &F,
Expand Down
1 change: 1 addition & 0 deletions lib/RewriteInsertsPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ clspv::RewriteInsertsPass::GetConstructFunction(Module &M,
FunctionType *fnTy = FunctionType::get(constructed_type, elements, false);
auto fn_constant = M.getOrInsertFunction(fn_name, fnTy);
fn = cast<Function>(fn_constant.getCallee());
fn->setIsNewDbgInfoFormat(true);
fn->setOnlyReadsMemory();
}
return fn;
Expand Down
1 change: 1 addition & 0 deletions lib/SpecializeImageTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ void SpecializeImageTypesPass::RewriteFunction(Function *f) {
auto callee =
module->getOrInsertFunction(f->getName(), func_type, f->getAttributes());
auto new_func = cast<Function>(callee.getCallee());
new_func->setIsNewDbgInfoFormat(true);
new_func->setCallingConv(f->getCallingConv());
new_func->copyMetadata(f, 0);

Expand Down
2 changes: 2 additions & 0 deletions lib/ThreeElementVectorLoweringPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ Function *createFunctionWithMappedTypes(Function &F,
assert(!F.isVarArg() && "varargs not supported");

auto *Wrapper = Function::Create(EquivalentFunctionTy, F.getLinkage());
Wrapper->setIsNewDbgInfoFormat(F.IsNewDbgInfoFormat);
Wrapper->takeName(&F);
Wrapper->setCallingConv(F.getCallingConv());
Wrapper->copyAttributesFrom(&F);
Expand Down Expand Up @@ -1102,6 +1103,7 @@ Value *clspv::ThreeElementVectorLoweringPass::convertSIMDBuiltinCall(
Function *Fct =
Function::Create(FunctionType::get(EquivalentReturnTy, ParamTys, false),
InitialFunction->getLinkage(), FunctionName);
Fct->setIsNewDbgInfoFormat(true);

Fct->setCallingConv(InitialFunction->getCallingConv());
Fct->copyAttributesFrom(InitialFunction);
Expand Down
1 change: 1 addition & 0 deletions lib/UBOTypeTransformPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ bool clspv::UBOTypeTransformPass::RemapFunctions(
auto inserted = M.getOrInsertFunction(func->getName(), replacement_type,
func->getAttributes());
Function *replacement = cast<Function>(inserted.getCallee());
replacement->setIsNewDbgInfoFormat(true);
function_replacements_[func] = replacement;
replacement->setCallingConv(func->getCallingConv());
replacement->copyMetadata(func, 0);
Expand Down
1 change: 1 addition & 0 deletions lib/UndoByvalPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ PreservedAnalyses clspv::UndoByvalPass::run(Module &M,

// Create new function.
Function *NewFunc = Function::Create(NewFuncTy, F->getLinkage());
NewFunc->setIsNewDbgInfoFormat(true);
NewFunc->takeName(F);

// Insert the function just after the original to preserve the ordering of
Expand Down
1 change: 1 addition & 0 deletions lib/UndoSRetPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ PreservedAnalyses clspv::UndoSRetPass::run(Module &M, ModuleAnalysisManager &) {

// Create new function.
Function *NewFunc = Function::Create(NewFuncTy, F->getLinkage());
NewFunc->setIsNewDbgInfoFormat(true);
NewFunc->takeName(F);

// Insert the function just after the original to preserve the ordering
Expand Down
1 change: 1 addition & 0 deletions lib/WrapKernelPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ void clspv::WrapKernelPass::runOnFunction(Module &M, llvm::Function *F) {
auto *NewFuncTy = FunctionType::get(F->getReturnType(), NewParamTypes, false);

auto NewFunc = Function::Create(NewFuncTy, F->getLinkage());
NewFunc->setIsNewDbgInfoFormat(true);
NewFunc->setName(F->getName().str());
F->setName(F->getName().str() + ".inner");
NewFunc->setCallingConv(F->getCallingConv());
Expand Down
1 change: 0 additions & 1 deletion test/debug-information-control-flow.cl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ void kernel foo(global uint *dst, global uint *srcA, global uint *srcB) {

// CHECK: OpLine [[filename:%[^ ]+]] 7 0
// CHECK-NEXT: OpLoad
// CHECK-NEXT: OpLine [[filename]] 0 0
// CHECK-NEXT: OpNoLine
// CHECK-NEXT: OpAccessChain
// CHECK-NEXT: OpLine [[filename]] 8 0
Expand Down
1 change: 0 additions & 1 deletion test/debug-information.cl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ void kernel foo(global uint *dst, global uint *src) {

// CHECK: OpLine [[filename:%[^ ]+]] 7 0
// CHECK-NEXT: OpLoad
// CHECK-NEXT: OpLine [[filename]] 0 0
// CHECK-NEXT: OpNoLine
// CHECK-NEXT: OpAccessChain
// CHECK-NEXT: OpLine [[filename]] 8 0
Expand Down

0 comments on commit 74c1ed0

Please sign in to comment.