diff options
author | Matt Arsenault <Matthew.Arsenault@amd.com> | 2022-12-01 19:02:18 -0500 |
---|---|---|
committer | Matt Arsenault <arsenm2@gmail.com> | 2023-01-17 22:33:56 -0500 |
commit | e7cd42f8e4da1beed52f401dcf87d22d36a2c81c (patch) | |
tree | 69baf2fd37af141c90e5ea08cd91d46334bfc57f /llvm/lib/Transforms/Utils/LowerIFunc.cpp | |
parent | 76d3e1a4980ff64a69494087f0a094b90ad54dff (diff) | |
download | llvm-e7cd42f8e4da1beed52f401dcf87d22d36a2c81c.zip llvm-e7cd42f8e4da1beed52f401dcf87d22d36a2c81c.tar.gz llvm-e7cd42f8e4da1beed52f401dcf87d22d36a2c81c.tar.bz2 |
Utils: Add utility pass to lower ifuncs
Create a global constructor which will initialize a global table of
function pointers. For now, this is only used as a reduction technique
for llvm-reduce.
In the future this may be useful to support ifunc on systems where the
program loader doesn't natively support it.
Diffstat (limited to 'llvm/lib/Transforms/Utils/LowerIFunc.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/LowerIFunc.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Utils/LowerIFunc.cpp b/llvm/lib/Transforms/Utils/LowerIFunc.cpp new file mode 100644 index 0000000..18ae0bbe --- /dev/null +++ b/llvm/lib/Transforms/Utils/LowerIFunc.cpp @@ -0,0 +1,27 @@ +//===- LowerIFunc.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 +// +//===----------------------------------------------------------------------===// +// +// This file implements replacing calls to ifuncs by introducing indirect calls. +// +//===----------------------------------------------------------------------===// + +#include "llvm/Transforms/Utils/LowerIFunc.h" +#include "llvm/IR/Module.h" +#include "llvm/Pass.h" +#include "llvm/Transforms/Utils/ModuleUtils.h" + +using namespace llvm; + +/// Replace all call users of ifuncs in the module. +PreservedAnalyses LowerIFuncPass::run(Module &M, ModuleAnalysisManager &AM) { + if (M.ifunc_empty()) + return PreservedAnalyses::all(); + + lowerGlobalIFuncUsersAsGlobalCtor(M, {}); + return PreservedAnalyses::none(); +} |