Skip to content

Commit

Permalink
[examples] Move loop unroller passes into anonymous namespace.
Browse files Browse the repository at this point in the history
This appears to be the way that the LLVM sources structure their
passes, with the implementation in an anonymous namespace and the
INITIALIZE_PASS_xxx macros in no namespace.

Fixes #509.
  • Loading branch information
ChrisCummins committed Dec 21, 2021
1 parent 398b39f commit 95b6e0f
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions examples/example_unrolling_service/loop_unroller/loop_unroller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@

using namespace llvm;

namespace llvm {
namespace {

/// Input LLVM module file name.
cl::opt<std::string> InputFilename(cl::Positional, cl::desc("Specify input filename"),
cl::value_desc("filename"), cl::init("-"));
Expand Down Expand Up @@ -65,9 +66,6 @@ static cl::opt<bool> PreserveAssemblyUseListOrder(
"preserve-ll-uselistorder", cl::desc("Preserve use-list order when writing LLVM assembly."),
cl::init(false), cl::Hidden);

// The INITIALIZE_PASS_XXX macros put the initialiser in the llvm namespace.
void initializeLoopCounterPass(PassRegistry& Registry);

class LoopCounter : public llvm::FunctionPass {
public:
static char ID;
Expand All @@ -90,15 +88,6 @@ class LoopCounter : public llvm::FunctionPass {
}
};

// Initialise the pass. We have to declare the dependencies we use.
char LoopCounter::ID = 0;
INITIALIZE_PASS_BEGIN(LoopCounter, "count-loops", "Count loops", false, false)
INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
INITIALIZE_PASS_END(LoopCounter, "count-loops", "Count loops", false, false)

// The INITIALIZE_PASS_XXX macros put the initialiser in the llvm namespace.
void initializeLoopUnrollConfiguratorPass(PassRegistry& Registry);

class LoopUnrollConfigurator : public llvm::FunctionPass {
public:
static char ID;
Expand All @@ -125,13 +114,7 @@ class LoopUnrollConfigurator : public llvm::FunctionPass {
}
};

// Initialise the pass. We have to declare the dependencies we use.
char LoopUnrollConfigurator::ID = 1;
INITIALIZE_PASS_BEGIN(LoopUnrollConfigurator, "unroll-loops-configurator",
"Configurates loop unrolling", false, false)
INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
INITIALIZE_PASS_END(LoopUnrollConfigurator, "unroll-loops-configurator",
"Configurates loop unrolling", false, false)

/// Reads a module from a file.
/// On error, messages are written to stderr and null is returned.
Expand All @@ -148,8 +131,29 @@ static std::unique_ptr<Module> readModule(LLVMContext& Context, StringRef Name)
return Module;
}

char LoopCounter::ID = 0;

} // anonymous namespace

namespace llvm {

// The INITIALIZE_PASS_XXX macros put the initialiser in the llvm namespace.
void initializeLoopCounterPass(PassRegistry& Registry);
void initializeLoopUnrollConfiguratorPass(PassRegistry& Registry);

} // namespace llvm

// Initialise the passes. We have to declare the dependencies we use.
INITIALIZE_PASS_BEGIN(LoopUnrollConfigurator, "unroll-loops-configurator",
"Configurates loop unrolling", false, false)
INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
INITIALIZE_PASS_END(LoopUnrollConfigurator, "unroll-loops-configurator",
"Configurates loop unrolling", false, false)

INITIALIZE_PASS_BEGIN(LoopCounter, "count-loops", "Count loops", false, false)
INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
INITIALIZE_PASS_END(LoopCounter, "count-loops", "Count loops", false, false)

int main(int argc, char** argv) {
cl::ParseCommandLineOptions(argc, argv,
" LLVM-Counter\n\n"
Expand Down

0 comments on commit 95b6e0f

Please sign in to comment.