aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-reduce
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/tools/llvm-reduce')
-rw-r--r--llvm/tools/llvm-reduce/CMakeLists.txt1
-rw-r--r--llvm/tools/llvm-reduce/DeltaManager.cpp4
-rw-r--r--llvm/tools/llvm-reduce/ReducerWorkItem.cpp6
-rw-r--r--llvm/tools/llvm-reduce/deltas/ReduceVirtualRegisters.cpp46
-rw-r--r--llvm/tools/llvm-reduce/deltas/ReduceVirtualRegisters.h25
5 files changed, 81 insertions, 1 deletions
diff --git a/llvm/tools/llvm-reduce/CMakeLists.txt b/llvm/tools/llvm-reduce/CMakeLists.txt
index 21151d7..b077f18 100644
--- a/llvm/tools/llvm-reduce/CMakeLists.txt
+++ b/llvm/tools/llvm-reduce/CMakeLists.txt
@@ -41,6 +41,7 @@ add_llvm_tool(llvm-reduce
deltas/ReduceInstructionsMIR.cpp
deltas/ReduceInstructionFlagsMIR.cpp
deltas/ReduceIRReferences.cpp
+ deltas/ReduceVirtualRegisters.cpp
llvm-reduce.cpp
DEPENDS
diff --git a/llvm/tools/llvm-reduce/DeltaManager.cpp b/llvm/tools/llvm-reduce/DeltaManager.cpp
index a5b6c17..ed9d105 100644
--- a/llvm/tools/llvm-reduce/DeltaManager.cpp
+++ b/llvm/tools/llvm-reduce/DeltaManager.cpp
@@ -35,6 +35,7 @@
#include "deltas/ReduceOperandsSkip.h"
#include "deltas/ReduceOperandsToArgs.h"
#include "deltas/ReduceSpecialGlobals.h"
+#include "deltas/ReduceVirtualRegisters.h"
#include "llvm/Support/CommandLine.h"
using namespace llvm;
@@ -74,7 +75,8 @@ static cl::opt<std::string>
reduceIRInstructionReferencesDeltaPass) \
DELTA_PASS("ir-block-references", reduceIRBlockReferencesDeltaPass) \
DELTA_PASS("ir-function-references", reduceIRFunctionReferencesDeltaPass) \
- DELTA_PASS("instruction-flags", reduceInstructionFlagsMIRDeltaPass)
+ DELTA_PASS("instruction-flags", reduceInstructionFlagsMIRDeltaPass) \
+ DELTA_PASS("register-hints", reduceVirtualRegisterHintsDeltaPass)
static void runAllDeltaPasses(TestRunner &Tester) {
#define DELTA_PASS(NAME, FUNC) FUNC(Tester);
diff --git a/llvm/tools/llvm-reduce/ReducerWorkItem.cpp b/llvm/tools/llvm-reduce/ReducerWorkItem.cpp
index 91ea752..fbae2a6 100644
--- a/llvm/tools/llvm-reduce/ReducerWorkItem.cpp
+++ b/llvm/tools/llvm-reduce/ReducerWorkItem.cpp
@@ -496,6 +496,12 @@ static uint64_t computeMIRComplexityScoreImpl(const MachineFunction &MF) {
// Add in the block count.
Score += 2 * MF.size();
+ const MachineRegisterInfo &MRI = MF.getRegInfo();
+ for (unsigned I = 0, E = MRI.getNumVirtRegs(); I != E; ++I) {
+ Register Reg = Register::index2VirtReg(I);
+ Score += MRI.getRegAllocationHints(Reg).second.size();
+ }
+
for (const MachineBasicBlock &MBB : MF) {
for (const MachineInstr &MI : MBB) {
const unsigned Opc = MI.getOpcode();
diff --git a/llvm/tools/llvm-reduce/deltas/ReduceVirtualRegisters.cpp b/llvm/tools/llvm-reduce/deltas/ReduceVirtualRegisters.cpp
new file mode 100644
index 0000000..1c5bda8
--- /dev/null
+++ b/llvm/tools/llvm-reduce/deltas/ReduceVirtualRegisters.cpp
@@ -0,0 +1,46 @@
+//===- ReduceVirtualRegisters.cpp - Specialized Delta Pass ----------------===//
+//
+// 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 a function which calls the Generic Delta pass in order
+// to simplify virtual registers in MIR.
+//
+//===----------------------------------------------------------------------===//
+
+#include "ReduceVirtualRegisters.h"
+#include "Delta.h"
+#include "llvm/CodeGen/MachineRegisterInfo.h"
+
+using namespace llvm;
+
+static void dropRegisterHintsFromFunction(Oracle &O, MachineFunction &MF) {
+ MachineRegisterInfo &MRI = MF.getRegInfo();
+ for (unsigned I = 0, E = MRI.getNumVirtRegs(); I != E; ++I) {
+ Register Reg = Register::index2VirtReg(I);
+
+ const std::pair<Register, SmallVector<Register, 4>> &Hints =
+ MRI.getRegAllocationHints(Reg);
+ if (Hints.second.empty())
+ continue;
+
+ if (!O.shouldKeep())
+ MRI.clearSimpleHint(Reg);
+ }
+}
+
+static void dropRegisterHintsFromFunctions(Oracle &O,
+ ReducerWorkItem &WorkItem) {
+ for (const Function &F : WorkItem.getModule()) {
+ if (auto *MF = WorkItem.MMI->getMachineFunction(F))
+ dropRegisterHintsFromFunction(O, *MF);
+ }
+}
+
+void llvm::reduceVirtualRegisterHintsDeltaPass(TestRunner &Test) {
+ outs() << "*** Reducing virtual register hints from functions...\n";
+ runDeltaPass(Test, dropRegisterHintsFromFunctions);
+}
diff --git a/llvm/tools/llvm-reduce/deltas/ReduceVirtualRegisters.h b/llvm/tools/llvm-reduce/deltas/ReduceVirtualRegisters.h
new file mode 100644
index 0000000..405ba31
--- /dev/null
+++ b/llvm/tools/llvm-reduce/deltas/ReduceVirtualRegisters.h
@@ -0,0 +1,25 @@
+//===- ReduceVirtualRegisters.h - Specialized Delta Pass -------*- 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
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements a function which calls the Generic Delta pass in order
+// to simplify virtual register information.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCEVIRTUALREGISTERS_H
+#define LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCEVIRTUALREGISTERS_H
+
+namespace llvm {
+class TestRunner;
+
+/// Remove register allocation hints from virtual registes.
+void reduceVirtualRegisterHintsDeltaPass(TestRunner &Test);
+
+} // namespace llvm
+
+#endif