this pass calls simplifyCFG on individual basic blocks; we want this

so that we can reduce away incidental parts of the CFG in cases where
the full simplifyCFG pass makes the test case uninteresting

Differential Revision: https://reviews.llvm.org/D131920
This commit is contained in:
John Regehr 2022-08-15 15:45:20 -06:00
parent 633f5663c3
commit 2f1fa6242a
5 changed files with 92 additions and 0 deletions

View File

@ -0,0 +1,32 @@
; RUN: llvm-reduce --delta-passes=simplify-cfg --test %python --test-arg %p/Inputs/remove-bbs.py -abort-on-invalid-reduction %s -o %t
; RUN: FileCheck --check-prefix=CHECK-FINAL %s --input-file=%t
; CHECK-FINAL-NOT: x6
; CHECK-FINAL-NOT: x10
define void @f1(ptr %interesting3, i32 %interesting2) {
%x3 = alloca ptr, i32 0, align 8
store ptr %interesting3, ptr %interesting3, align 8
switch i32 %interesting2, label %interesting1 [
i32 0, label %x6
i32 1, label %x11
]
x4:
%x5 = call ptr @f2()
br label %x10
x10:
br label %interesting1
x6:
br label %x11
x11:
br label %interesting1
interesting1:
ret void
}
declare ptr @f2()

View File

@ -49,6 +49,7 @@ add_llvm_tool(llvm-reduce
deltas/ReduceRegisterMasks.cpp
deltas/ReduceRegisterDefs.cpp
deltas/ReduceRegisterUses.cpp
deltas/ReduceUsingSimplifyCFG.cpp
deltas/RunIRPasses.cpp
deltas/SimplifyInstructions.cpp
llvm-reduce.cpp

View File

@ -39,6 +39,7 @@
#include "deltas/ReduceRegisterMasks.h"
#include "deltas/ReduceRegisterUses.h"
#include "deltas/ReduceSpecialGlobals.h"
#include "deltas/ReduceUsingSimplifyCFG.h"
#include "deltas/ReduceVirtualRegisters.h"
#include "deltas/RunIRPasses.h"
#include "deltas/SimplifyInstructions.h"
@ -75,6 +76,7 @@ static cl::opt<std::string>
DELTA_PASS("operands-to-args", reduceOperandsToArgsDeltaPass) \
DELTA_PASS("operands-skip", reduceOperandsSkipDeltaPass) \
DELTA_PASS("operand-bundles", reduceOperandBundesDeltaPass) \
DELTA_PASS("simplify-cfg", reduceUsingSimplifyCFGDeltaPass) \
DELTA_PASS("attributes", reduceAttributesDeltaPass) \
DELTA_PASS("module-data", reduceModuleDataDeltaPass) \
} while (false)

View File

@ -0,0 +1,34 @@
//===- ReduceUsingSimplifyCFG.h - 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 call SimplifyCFG on individual basic blocks.
//
//===----------------------------------------------------------------------===//
#include "ReduceUsingSimplifyCFG.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/Transforms/Utils/Local.h"
using namespace llvm;
static void reduceUsingSimplifyCFG(Oracle &O, Module &Program) {
SmallVector<BasicBlock *, 16> ToSimplify;
for (auto &F : Program)
for (auto &BB : F)
if (!O.shouldKeep())
ToSimplify.push_back(&BB);
TargetTransformInfo TTI(Program.getDataLayout());
for (auto *BB : ToSimplify)
simplifyCFG(BB, TTI);
}
void llvm::reduceUsingSimplifyCFGDeltaPass(TestRunner &Test) {
outs() << "*** Reducing using SimplifyCFG...\n";
runDeltaPass(Test, reduceUsingSimplifyCFG);
}

View File

@ -0,0 +1,23 @@
//===- ReduceUsingSimplifyCFG.h - 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 call SimplifyCFG on individual basic blocks.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_TOOLS_LLVM_REDUCE_DELTAS_SIMPLIFYCFG_H
#define LLVM_TOOLS_LLVM_REDUCE_DELTAS_SIMPLIFYCFG_H
#include "Delta.h"
namespace llvm {
void reduceUsingSimplifyCFGDeltaPass(TestRunner &Test);
} // namespace llvm
#endif