aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/tools')
-rw-r--r--llvm/tools/llvm-objdump/OffloadDump.cpp27
-rw-r--r--llvm/tools/llvm-profdata/CMakeLists.txt5
-rw-r--r--llvm/tools/llvm-profdata/llvm-profdata.cpp5
-rw-r--r--llvm/tools/llvm-reduce/CMakeLists.txt1
-rw-r--r--llvm/tools/llvm-reduce/DeltaManager.cpp1
-rw-r--r--llvm/tools/llvm-reduce/DeltaPasses.def2
-rw-r--r--llvm/tools/llvm-reduce/deltas/ReduceInlineCallSites.cpp103
-rw-r--r--llvm/tools/llvm-reduce/deltas/ReduceInlineCallSites.h18
-rw-r--r--llvm/tools/llvm-remarkutil/RemarkFilter.cpp6
9 files changed, 147 insertions, 21 deletions
diff --git a/llvm/tools/llvm-objdump/OffloadDump.cpp b/llvm/tools/llvm-objdump/OffloadDump.cpp
index 8a0deb3..a77537d 100644
--- a/llvm/tools/llvm-objdump/OffloadDump.cpp
+++ b/llvm/tools/llvm-objdump/OffloadDump.cpp
@@ -87,21 +87,30 @@ void llvm::dumpOffloadBundleFatBinary(const ObjectFile &O, StringRef ArchName) {
if (Error Err = llvm::object::extractOffloadBundleFatBinary(O, FoundBundles))
reportError(O.getFileName(), "while extracting offload FatBin bundles: " +
toString(std::move(Err)));
-
for (const auto &[BundleNum, Bundle] : llvm::enumerate(FoundBundles)) {
for (OffloadBundleEntry &Entry : Bundle.getEntries()) {
- if (!ArchName.empty() && !Entry.ID.contains(ArchName))
+ if (!ArchName.empty() && Entry.ID.find(ArchName) != std::string::npos)
continue;
// create file name for this object file: <source-filename>.<Bundle
// Number>.<EntryID>
- std::string str = Bundle.getFileName().str() + "." + itostr(BundleNum) +
- "." + Entry.ID.str();
- if (Error Err = object::extractCodeObject(O, Entry.Offset, Entry.Size,
- StringRef(str)))
- reportError(O.getFileName(),
- "while extracting offload Bundle Entries: " +
- toString(std::move(Err)));
+ std::string str =
+ Bundle.getFileName().str() + "." + itostr(BundleNum) + "." + Entry.ID;
+
+ if (Bundle.isDecompressed()) {
+ if (Error Err = object::extractCodeObject(
+ Bundle.DecompressedBuffer->getMemBufferRef(), Entry.Offset,
+ Entry.Size, StringRef(str)))
+ reportError(O.getFileName(),
+ "while extracting offload Bundle Entries: " +
+ toString(std::move(Err)));
+ } else {
+ if (Error Err = object::extractCodeObject(O, Entry.Offset, Entry.Size,
+ StringRef(str)))
+ reportError(O.getFileName(),
+ "while extracting offload Bundle Entries: " +
+ toString(std::move(Err)));
+ }
outs() << "Extracting offload bundle: " << str << "\n";
}
}
diff --git a/llvm/tools/llvm-profdata/CMakeLists.txt b/llvm/tools/llvm-profdata/CMakeLists.txt
index 165be9a2..e5aa858 100644
--- a/llvm/tools/llvm-profdata/CMakeLists.txt
+++ b/llvm/tools/llvm-profdata/CMakeLists.txt
@@ -10,9 +10,6 @@ add_llvm_tool(llvm-profdata
DEPENDS
intrinsics_gen
- GENERATE_DRIVER
)
-if(NOT LLVM_TOOL_LLVM_DRIVER_BUILD)
- target_link_libraries(llvm-profdata PRIVATE LLVMDebuginfod)
-endif()
+target_link_libraries(llvm-profdata PRIVATE LLVMDebuginfod)
diff --git a/llvm/tools/llvm-profdata/llvm-profdata.cpp b/llvm/tools/llvm-profdata/llvm-profdata.cpp
index d658ea9..15ddb05 100644
--- a/llvm/tools/llvm-profdata/llvm-profdata.cpp
+++ b/llvm/tools/llvm-profdata/llvm-profdata.cpp
@@ -3464,10 +3464,7 @@ static int order_main() {
return 0;
}
-int llvm_profdata_main(int argc, char **argvNonConst,
- const llvm::ToolContext &) {
- const char **argv = const_cast<const char **>(argvNonConst);
-
+int main(int argc, const char *argv[]) {
StringRef ProgName(sys::path::filename(argv[0]));
if (argc < 2) {
diff --git a/llvm/tools/llvm-reduce/CMakeLists.txt b/llvm/tools/llvm-reduce/CMakeLists.txt
index 7be90bc..c8673b4 100644
--- a/llvm/tools/llvm-reduce/CMakeLists.txt
+++ b/llvm/tools/llvm-reduce/CMakeLists.txt
@@ -39,6 +39,7 @@ add_llvm_tool(llvm-reduce
deltas/ReduceGlobalValues.cpp
deltas/ReduceGlobalVarInitializers.cpp
deltas/ReduceGlobalVars.cpp
+ deltas/ReduceInlineCallSites.cpp
deltas/ReduceInstructions.cpp
deltas/ReduceInstructionFlags.cpp
deltas/ReduceInvokes.cpp
diff --git a/llvm/tools/llvm-reduce/DeltaManager.cpp b/llvm/tools/llvm-reduce/DeltaManager.cpp
index f5c6276..9b13202 100644
--- a/llvm/tools/llvm-reduce/DeltaManager.cpp
+++ b/llvm/tools/llvm-reduce/DeltaManager.cpp
@@ -28,6 +28,7 @@
#include "deltas/ReduceGlobalVarInitializers.h"
#include "deltas/ReduceGlobalVars.h"
#include "deltas/ReduceIRReferences.h"
+#include "deltas/ReduceInlineCallSites.h"
#include "deltas/ReduceInstructionFlags.h"
#include "deltas/ReduceInstructionFlagsMIR.h"
#include "deltas/ReduceInstructions.h"
diff --git a/llvm/tools/llvm-reduce/DeltaPasses.def b/llvm/tools/llvm-reduce/DeltaPasses.def
index 3aed0cc..845b106 100644
--- a/llvm/tools/llvm-reduce/DeltaPasses.def
+++ b/llvm/tools/llvm-reduce/DeltaPasses.def
@@ -58,7 +58,7 @@ DELTA_PASS_IR("volatile", reduceVolatileInstructionsDeltaPass, "Reducing Volatil
DELTA_PASS_IR("atomic-ordering", reduceAtomicOrderingDeltaPass, "Reducing Atomic Ordering")
DELTA_PASS_IR("syncscopes", reduceAtomicSyncScopesDeltaPass, "Reducing Atomic Sync Scopes")
DELTA_PASS_IR("instruction-flags", reduceInstructionFlagsDeltaPass, "Reducing Instruction Flags")
-
+DELTA_PASS_IR("inline-call-sites", reduceInlineCallSitesDeltaPass, "Inlining callsites")
#ifndef DELTA_PASS_MIR
#define DELTA_PASS_MIR(NAME, FUNC, DESC)
diff --git a/llvm/tools/llvm-reduce/deltas/ReduceInlineCallSites.cpp b/llvm/tools/llvm-reduce/deltas/ReduceInlineCallSites.cpp
new file mode 100644
index 0000000..cfef367
--- /dev/null
+++ b/llvm/tools/llvm-reduce/deltas/ReduceInlineCallSites.cpp
@@ -0,0 +1,103 @@
+//===- ReduceInlineCallSites.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
+//
+//===----------------------------------------------------------------------===//
+
+#include "ReduceInlineCallSites.h"
+#include "llvm/IR/InstrTypes.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Transforms/Utils/Cloning.h"
+
+using namespace llvm;
+
+extern cl::OptionCategory LLVMReduceOptions;
+
+static cl::opt<int> CallsiteInlineThreshold(
+ "reduce-callsite-inline-threshold",
+ cl::desc("Number of instructions in a function to unconditionally inline "
+ "(-1 for inline all)"),
+ cl::init(5), cl::cat(LLVMReduceOptions));
+
+static bool functionHasMoreThanNonTerminatorInsts(const Function &F,
+ uint64_t NumInsts) {
+ uint64_t InstCount = 0;
+ for (const BasicBlock &BB : F) {
+ for (const Instruction &I : make_range(BB.begin(), std::prev(BB.end()))) {
+ (void)I;
+ if (InstCount++ > NumInsts)
+ return true;
+ }
+ }
+
+ return false;
+}
+
+static bool hasOnlyOneCallUse(const Function &F) {
+ unsigned UseCount = 0;
+ for (const Use &U : F.uses()) {
+ const CallBase *CB = dyn_cast<CallBase>(U.getUser());
+ if (!CB || !CB->isCallee(&U))
+ return false;
+ if (UseCount++ > 1)
+ return false;
+ }
+
+ return UseCount == 1;
+}
+
+// TODO: This could use more thought.
+static bool inlineWillReduceComplexity(const Function &Caller,
+ const Function &Callee) {
+ // Backdoor to force all possible inlining.
+ if (CallsiteInlineThreshold < 0)
+ return true;
+
+ if (!hasOnlyOneCallUse(Callee))
+ return false;
+
+ // Permit inlining small functions into big functions, or big functions into
+ // small functions.
+ if (!functionHasMoreThanNonTerminatorInsts(Callee, CallsiteInlineThreshold) &&
+ !functionHasMoreThanNonTerminatorInsts(Caller, CallsiteInlineThreshold))
+ return true;
+
+ return false;
+}
+
+static void reduceCallSites(Oracle &O, Function &F) {
+ std::vector<std::pair<CallBase *, InlineFunctionInfo>> CallSitesToInline;
+
+ for (Use &U : F.uses()) {
+ if (CallBase *CB = dyn_cast<CallBase>(U.getUser())) {
+ // Ignore callsites with wrong call type.
+ if (!CB->isCallee(&U))
+ continue;
+
+ // We do not consider isInlineViable here. It is overly conservative in
+ // cases that the inliner should handle correctly (e.g. disallowing inline
+ // of of functions with indirectbr). Some of the other cases are for other
+ // correctness issues which we do need to worry about here.
+
+ // TODO: Should we delete the function body?
+ InlineFunctionInfo IFI;
+ if (CanInlineCallSite(*CB, IFI).isSuccess() &&
+ inlineWillReduceComplexity(*CB->getFunction(), F) && !O.shouldKeep())
+ CallSitesToInline.emplace_back(CB, std::move(IFI));
+ }
+ }
+
+ // TODO: InlineFunctionImpl will implicitly perform some simplifications /
+ // optimizations which we should be able to opt-out of.
+ for (auto [CB, IFI] : CallSitesToInline)
+ InlineFunctionImpl(*CB, IFI);
+}
+
+void llvm::reduceInlineCallSitesDeltaPass(Oracle &O, ReducerWorkItem &Program) {
+ for (Function &F : Program.getModule()) {
+ if (!F.isDeclaration())
+ reduceCallSites(O, F);
+ }
+}
diff --git a/llvm/tools/llvm-reduce/deltas/ReduceInlineCallSites.h b/llvm/tools/llvm-reduce/deltas/ReduceInlineCallSites.h
new file mode 100644
index 0000000..1df31a1
--- /dev/null
+++ b/llvm/tools/llvm-reduce/deltas/ReduceInlineCallSites.h
@@ -0,0 +1,18 @@
+//===- ReduceInlineCallSites.h ----------------------------------*- C++ -*-===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCEINLINECALLSITES_H
+#define LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCEINLINECALLSITES_H
+
+#include "Delta.h"
+
+namespace llvm {
+void reduceInlineCallSitesDeltaPass(Oracle &O, ReducerWorkItem &Program);
+} // namespace llvm
+
+#endif
diff --git a/llvm/tools/llvm-remarkutil/RemarkFilter.cpp b/llvm/tools/llvm-remarkutil/RemarkFilter.cpp
index acfef66..507ae36 100644
--- a/llvm/tools/llvm-remarkutil/RemarkFilter.cpp
+++ b/llvm/tools/llvm-remarkutil/RemarkFilter.cpp
@@ -20,7 +20,9 @@ using namespace llvm;
using namespace remarks;
using namespace llvm::remarkutil;
-namespace filter {
+// Note: Avoid using the identifier "filter" in this file, as it is prone to
+// namespace collision with headers that might get included e.g.
+// curses.h.
static cl::SubCommand FilterSub("filter",
"Filter remarks based on specified criteria.");
@@ -80,5 +82,3 @@ static Error tryFilter() {
}
static CommandRegistration FilterReg(&FilterSub, tryFilter);
-
-} // namespace filter