Files
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

82 lines
2.8 KiB
C++

//===- DeclareRuntimeLibcalls.cpp -----------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Insert declarations for all runtime library calls known for the target.
//
//===----------------------------------------------------------------------===//
#include "llvm/Transforms/Utils/DeclareRuntimeLibcalls.h"
#include "llvm/Analysis/RuntimeLibcallInfo.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/RuntimeLibcalls.h"
using namespace llvm;
static void mergeAttributes(LLVMContext &Ctx, const Module &M,
const DataLayout &DL, const Triple &TT,
Function *Func, FunctionType *FuncTy,
AttributeList FuncAttrs) {
AttributeList OldAttrs = Func->getAttributes();
AttributeList NewAttrs = OldAttrs;
{
AttrBuilder OldBuilder(Ctx, OldAttrs.getFnAttrs());
AttrBuilder NewBuilder(Ctx, FuncAttrs.getFnAttrs());
OldBuilder.merge(NewBuilder);
NewAttrs = NewAttrs.addFnAttributes(Ctx, OldBuilder);
}
{
AttrBuilder OldBuilder(Ctx, OldAttrs.getRetAttrs());
AttrBuilder NewBuilder(Ctx, FuncAttrs.getRetAttrs());
OldBuilder.merge(NewBuilder);
NewAttrs = NewAttrs.addRetAttributes(Ctx, OldBuilder);
}
for (unsigned I = 0, E = FuncTy->getNumParams(); I != E; ++I) {
AttrBuilder OldBuilder(Ctx, OldAttrs.getParamAttrs(I));
AttrBuilder NewBuilder(Ctx, FuncAttrs.getParamAttrs(I));
OldBuilder.merge(NewBuilder);
NewAttrs = NewAttrs.addParamAttributes(Ctx, I, OldBuilder);
}
Func->setAttributes(NewAttrs);
}
PreservedAnalyses DeclareRuntimeLibcallsPass::run(Module &M,
ModuleAnalysisManager &MAM) {
const RTLIB::RuntimeLibcallsInfo &RTLCI =
MAM.getResult<RuntimeLibraryAnalysis>(M);
LLVMContext &Ctx = M.getContext();
const DataLayout &DL = M.getDataLayout();
const Triple &TT = M.getTargetTriple();
for (RTLIB::LibcallImpl Impl : RTLIB::libcall_impls()) {
if (!RTLCI.isAvailable(Impl))
continue;
auto [FuncTy, FuncAttrs] = RTLCI.getFunctionTy(Ctx, TT, DL, Impl);
// TODO: Declare with correct type, calling convention, and attributes.
if (!FuncTy)
FuncTy = FunctionType::get(Type::getVoidTy(Ctx), {}, /*IsVarArgs=*/true);
StringRef FuncName = RTLCI.getLibcallImplName(Impl);
Function *Func =
cast<Function>(M.getOrInsertFunction(FuncName, FuncTy).getCallee());
if (Func->getFunctionType() == FuncTy) {
mergeAttributes(Ctx, M, DL, TT, Func, FuncTy, FuncAttrs);
Func->setCallingConv(RTLCI.getLibcallImplCallingConv(Impl));
}
}
return PreservedAnalyses::none();
}