Skip to content

Commit

Permalink
[llvm-reduce] Add header guards and fix clang-tidy warnings
Browse files Browse the repository at this point in the history
Add header guards and fix other clang-tidy warnings in .h files.
Also align misaligned header docs

Reviewed By: aeubanks

Differential Revision: https://reviews.llvm.org/D99634
  • Loading branch information
saeubank authored and aeubanks committed Apr 2, 2021
1 parent 5a9a8c7 commit 56fa1b4
Show file tree
Hide file tree
Showing 23 changed files with 149 additions and 74 deletions.
1 change: 1 addition & 0 deletions llvm/tools/llvm-reduce/CMakeLists.txt
Expand Up @@ -11,6 +11,7 @@ set(LLVM_LINK_COMPONENTS
)

add_llvm_tool(llvm-reduce
DeltaManager.cpp
TestRunner.cpp
deltas/Delta.cpp
deltas/ReduceAliases.cpp
Expand Down
50 changes: 50 additions & 0 deletions llvm/tools/llvm-reduce/DeltaManager.cpp
@@ -0,0 +1,50 @@
//===- DeltaManager.cpp - Runs Delta Passes to reduce Input ---------------===//
//
// 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 calls each specialized Delta pass in order to reduce the input IR
// file.
//
//===----------------------------------------------------------------------===//

#include "DeltaManager.h"
#include "TestRunner.h"
#include "deltas/Delta.h"
#include "deltas/ReduceAliases.h"
#include "deltas/ReduceArguments.h"
#include "deltas/ReduceAttributes.h"
#include "deltas/ReduceBasicBlocks.h"
#include "deltas/ReduceFunctionBodies.h"
#include "deltas/ReduceFunctions.h"
#include "deltas/ReduceGlobalValues.h"
#include "deltas/ReduceGlobalVarInitializers.h"
#include "deltas/ReduceGlobalVars.h"
#include "deltas/ReduceInstructions.h"
#include "deltas/ReduceMetadata.h"
#include "deltas/ReduceOperandBundles.h"
#include "deltas/ReduceSpecialGlobals.h"

namespace llvm {

// TODO: Add CLI option to run only specified Passes (for unit tests)
void runDeltaPasses(TestRunner &Tester) {
reduceSpecialGlobalsDeltaPass(Tester);
reduceAliasesDeltaPass(Tester);
reduceFunctionBodiesDeltaPass(Tester);
reduceFunctionsDeltaPass(Tester);
reduceBasicBlocksDeltaPass(Tester);
reduceGlobalValuesDeltaPass(Tester);
reduceGlobalsInitializersDeltaPass(Tester);
reduceGlobalsDeltaPass(Tester);
reduceMetadataDeltaPass(Tester);
reduceArgumentsDeltaPass(Tester);
reduceInstructionsDeltaPass(Tester);
reduceOperandBundesDeltaPass(Tester);
reduceAttributesDeltaPass(Tester);
// TODO: Implement the remaining Delta Passes
}
} // namespace llvm
39 changes: 6 additions & 33 deletions llvm/tools/llvm-reduce/DeltaManager.h
Expand Up @@ -11,40 +11,13 @@
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_TOOLS_LLVM_REDUCE_DELTAMANAGER_H
#define LLVM_TOOLS_LLVM_REDUCE_DELTAMANAGER_H

#include "TestRunner.h"
#include "deltas/Delta.h"
#include "deltas/ReduceAliases.h"
#include "deltas/ReduceArguments.h"
#include "deltas/ReduceAttributes.h"
#include "deltas/ReduceBasicBlocks.h"
#include "deltas/ReduceFunctionBodies.h"
#include "deltas/ReduceFunctions.h"
#include "deltas/ReduceGlobalValues.h"
#include "deltas/ReduceGlobalVarInitializers.h"
#include "deltas/ReduceGlobalVars.h"
#include "deltas/ReduceInstructions.h"
#include "deltas/ReduceMetadata.h"
#include "deltas/ReduceOperandBundles.h"
#include "deltas/ReduceSpecialGlobals.h"

namespace llvm {

// TODO: Add CLI option to run only specified Passes (for unit tests)
inline void runDeltaPasses(TestRunner &Tester) {
reduceSpecialGlobalsDeltaPass(Tester);
reduceAliasesDeltaPass(Tester);
reduceFunctionBodiesDeltaPass(Tester);
reduceFunctionsDeltaPass(Tester);
reduceBasicBlocksDeltaPass(Tester);
reduceGlobalValuesDeltaPass(Tester);
reduceGlobalsInitializersDeltaPass(Tester);
reduceGlobalsDeltaPass(Tester);
reduceMetadataDeltaPass(Tester);
reduceArgumentsDeltaPass(Tester);
reduceInstructionsDeltaPass(Tester);
reduceOperandBundesDeltaPass(Tester);
reduceAttributesDeltaPass(Tester);
// TODO: Implement the remaining Delta Passes
}

void runDeltaPasses(TestRunner &Tester);
} // namespace llvm

#endif
4 changes: 2 additions & 2 deletions llvm/tools/llvm-reduce/TestRunner.h
Expand Up @@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_TOOLS_LLVMREDUCE_TESTRUNNER_H
#define LLVM_TOOLS_LLVMREDUCE_TESTRUNNER_H
#ifndef LLVM_TOOLS_LLVM_REDUCE_TESTRUNNER_H
#define LLVM_TOOLS_LLVM_REDUCE_TESTRUNNER_H

#include "llvm/ADT/SmallString.h"
#include "llvm/IR/Module.h"
Expand Down
14 changes: 7 additions & 7 deletions llvm/tools/llvm-reduce/deltas/Delta.cpp
Expand Up @@ -24,7 +24,7 @@ using namespace llvm;

void writeOutput(llvm::Module *M, llvm::StringRef Message);

bool IsReduced(Module &M, TestRunner &Test, SmallString<128> &CurrentFilepath) {
bool isReduced(Module &M, TestRunner &Test, SmallString<128> &CurrentFilepath) {
// Write Module to tmp file
int FD;
std::error_code EC =
Expand Down Expand Up @@ -66,12 +66,12 @@ static bool increaseGranularity(std::vector<Chunk> &Chunks) {
bool SplitOne = false;

for (auto &C : Chunks) {
if (C.end - C.begin == 0)
if (C.End - C.Begin == 0)
NewChunks.push_back(C);
else {
int Half = (C.begin + C.end) / 2;
NewChunks.push_back({C.begin, Half});
NewChunks.push_back({Half + 1, C.end});
int Half = (C.Begin + C.End) / 2;
NewChunks.push_back({C.Begin, Half});
NewChunks.push_back({Half + 1, C.End});
SplitOne = true;
}
}
Expand Down Expand Up @@ -102,7 +102,7 @@ void llvm::runDeltaPass(

if (Module *Program = Test.getProgram()) {
SmallString<128> CurrentFilepath;
if (!IsReduced(*Program, Test, CurrentFilepath)) {
if (!isReduced(*Program, Test, CurrentFilepath)) {
errs() << "\nInput isn't interesting! Verify interesting-ness test\n";
exit(1);
}
Expand Down Expand Up @@ -152,7 +152,7 @@ void llvm::runDeltaPass(
C.print();

SmallString<128> CurrentFilepath;
if (!IsReduced(*Clone, Test, CurrentFilepath)) {
if (!isReduced(*Clone, Test, CurrentFilepath)) {
// Program became non-reduced, so this chunk appears to be interesting.
errs() << "\n";
continue;
Expand Down
25 changes: 12 additions & 13 deletions llvm/tools/llvm-reduce/deltas/Delta.h
Expand Up @@ -12,8 +12,8 @@
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_TOOLS_LLVMREDUCE_LLVMREDUCE_DELTA_H
#define LLVM_TOOLS_LLVMREDUCE_LLVMREDUCE_DELTA_H
#ifndef LLVM_TOOLS_LLVM_REDUCE_DELTAS_DELTA_H
#define LLVM_TOOLS_LLVM_REDUCE_DELTAS_DELTA_H

#include "TestRunner.h"
#include "llvm/ADT/ScopeExit.h"
Expand All @@ -24,27 +24,27 @@
namespace llvm {

struct Chunk {
int begin;
int end;
int Begin;
int End;

/// Helper function to verify if a given Target-index is inside the Chunk
bool contains(int Index) const { return Index >= begin && Index <= end; }
bool contains(int Index) const { return Index >= Begin && Index <= End; }

void print() const {
errs() << "[" << begin;
if (end - begin != 0)
errs() << "," << end;
errs() << "[" << Begin;
if (End - Begin != 0)
errs() << "," << End;
errs() << "]";
}

/// Operator when populating CurrentChunks in Generic Delta Pass
friend bool operator!=(const Chunk &C1, const Chunk &C2) {
return C1.begin != C2.begin || C1.end != C2.end;
return C1.Begin != C2.Begin || C1.End != C2.End;
}

/// Operator used for sets
friend bool operator<(const Chunk &C1, const Chunk &C2) {
return std::tie(C1.begin, C1.end) < std::tie(C2.begin, C2.end);
return std::tie(C1.Begin, C1.End) < std::tie(C2.Begin, C2.End);
}
};

Expand All @@ -60,8 +60,7 @@ class Oracle {
ArrayRef<Chunk> ChunksToKeep;

public:
explicit Oracle(ArrayRef<Chunk> ChunksToKeep_)
: ChunksToKeep(ChunksToKeep_) {}
explicit Oracle(ArrayRef<Chunk> ChunksToKeep) : ChunksToKeep(ChunksToKeep) {}

/// Should be called for each feature on which we are operating.
/// Name is self-explanatory - if returns true, then it should be preserved.
Expand All @@ -74,7 +73,7 @@ class Oracle {
auto _ = make_scope_exit([&]() { ++Index; }); // Next time - next feature.

// Is this the last feature in the chunk?
if (ChunksToKeep.front().end == Index)
if (ChunksToKeep.front().End == Index)
ChunksToKeep = ChunksToKeep.drop_front(); // Onto next chunk.

return ShouldKeep;
Expand Down
5 changes: 5 additions & 0 deletions llvm/tools/llvm-reduce/deltas/ReduceAliases.h
Expand Up @@ -11,8 +11,13 @@
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCEALIASES_H
#define LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCEALIASES_H

#include "Delta.h"

namespace llvm {
void reduceAliasesDeltaPass(TestRunner &Test);
} // namespace llvm

#endif
5 changes: 5 additions & 0 deletions llvm/tools/llvm-reduce/deltas/ReduceArguments.h
Expand Up @@ -11,6 +11,9 @@
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCEARGUMENTS_H
#define LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCEARGUMENTS_H

#include "Delta.h"
#include "llvm/IR/Argument.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
Expand All @@ -19,3 +22,5 @@
namespace llvm {
void reduceArgumentsDeltaPass(TestRunner &Test);
} // namespace llvm

#endif
2 changes: 1 addition & 1 deletion llvm/tools/llvm-reduce/deltas/ReduceAttributes.cpp
@@ -1,4 +1,4 @@
//===- ReduceAttributes.cpp - Specialized Delta Pass -------------------===//
//===- ReduceAttributes.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.
Expand Down
8 changes: 5 additions & 3 deletions llvm/tools/llvm-reduce/deltas/ReduceAttributes.h
Expand Up @@ -11,10 +11,12 @@
//
//===----------------------------------------------------------------------===//

namespace llvm {
#ifndef LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCEATTRIBUTES_H
#define LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCEATTRIBUTES_H

namespace llvm {
class TestRunner;

void reduceAttributesDeltaPass(TestRunner &Test);

} // namespace llvm

#endif
10 changes: 5 additions & 5 deletions llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp
Expand Up @@ -26,9 +26,9 @@ using namespace llvm;
/// Replaces BB Terminator with one that only contains Chunk BBs
static void replaceBranchTerminator(BasicBlock &BB,
std::set<BasicBlock *> BBsToKeep) {
auto Term = BB.getTerminator();
auto *Term = BB.getTerminator();
std::vector<BasicBlock *> ChunkSucessors;
for (auto Succ : successors(&BB))
for (auto *Succ : successors(&BB))
if (BBsToKeep.count(Succ))
ChunkSucessors.push_back(Succ);

Expand All @@ -38,7 +38,7 @@ static void replaceBranchTerminator(BasicBlock &BB,

bool IsBranch = isa<BranchInst>(Term) || isa<InvokeInst>(Term);
Value *Address = nullptr;
if (auto IndBI = dyn_cast<IndirectBrInst>(Term))
if (auto *IndBI = dyn_cast<IndirectBrInst>(Term))
Address = IndBI->getAddress();

Term->replaceAllUsesWith(UndefValue::get(Term->getType()));
Expand All @@ -56,9 +56,9 @@ static void replaceBranchTerminator(BasicBlock &BB,
BranchInst::Create(ChunkSucessors[0], &BB);

if (Address) {
auto NewIndBI =
auto *NewIndBI =
IndirectBrInst::Create(Address, ChunkSucessors.size(), &BB);
for (auto Dest : ChunkSucessors)
for (auto *Dest : ChunkSucessors)
NewIndBI->addDestination(Dest);
}
}
Expand Down
4 changes: 4 additions & 0 deletions llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.h
Expand Up @@ -10,6 +10,8 @@
// to reduce uninteresting Arguments from defined functions.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCEBASICBLOCKS_H
#define LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCEBASICBLOCKS_H

#include "Delta.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
Expand All @@ -18,3 +20,5 @@
namespace llvm {
void reduceBasicBlocksDeltaPass(TestRunner &Test);
} // namespace llvm

#endif
5 changes: 5 additions & 0 deletions llvm/tools/llvm-reduce/deltas/ReduceFunctionBodies.h
Expand Up @@ -11,8 +11,13 @@
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCEFUNCTIONBODIES_H
#define LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCEFUNCTIONBODIES_H

#include "Delta.h"

namespace llvm {
void reduceFunctionBodiesDeltaPass(TestRunner &Test);
} // namespace llvm

#endif
4 changes: 4 additions & 0 deletions llvm/tools/llvm-reduce/deltas/ReduceFunctions.h
Expand Up @@ -11,10 +11,14 @@
// Module.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCEFUNCTIONS_H
#define LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCEFUNCTIONS_H

#include "Delta.h"
#include "llvm/Transforms/Utils/Cloning.h"

namespace llvm {
void reduceFunctionsDeltaPass(TestRunner &Test);
} // namespace llvm

#endif
8 changes: 6 additions & 2 deletions llvm/tools/llvm-reduce/deltas/ReduceGlobalVarInitializers.h
@@ -1,5 +1,4 @@
//===- reduceGlobalsInitializersDeltaPass.h - Specialized Delta Pass
//-------===//
//===- reduceGlobalsInitializersDeltaPass.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.
Expand All @@ -12,10 +11,15 @@
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCEGLOBALVARINITIALIZERS_H
#define LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCEGLOBALVARINITIALIZERS_H

#include "Delta.h"
#include "llvm/IR/Value.h"
#include "llvm/Transforms/Utils/Cloning.h"

namespace llvm {
void reduceGlobalsInitializersDeltaPass(TestRunner &Test);
} // namespace llvm

#endif
2 changes: 1 addition & 1 deletion llvm/tools/llvm-reduce/deltas/ReduceGlobalVars.cpp
Expand Up @@ -33,7 +33,7 @@ static void extractGVsFromModule(std::vector<Chunk> ChunksToKeep,
std::vector<WeakVH> InstToRemove;
for (auto &GV : Program->globals())
if (!GVsToKeep.count(&GV)) {
for (auto U : GV.users())
for (auto *U : GV.users())
if (auto *Inst = dyn_cast<Instruction>(U))
InstToRemove.push_back(Inst);

Expand Down

0 comments on commit 56fa1b4

Please sign in to comment.