-
Notifications
You must be signed in to change notification settings - Fork 0
How to create a compiler pass for OpenJ9?
Because we want to.
I am assuming that one has already built OpenJ9 at least once.
The optimizations for OpenJ9 live in two different places. Either under the folder omr/compiler/optimizer or openj9/runtime/compiler/optimizer. The difference between these two locations are whether the compilation can be done at the intermediate level only or whether the proposed optimization pass needs information available in the OpenJ9 VM. In other words if it is language independent the optimization pass should live on omr/compiler/optimizer otherwise in openj9/runtime/compiler/optimizer. I am assuming one is making an optimization that is language independent.
cd omr/compiler/optimizer
touch HelloWorldOpt.{cpp, hpp}#ifndef HELLO_WORLD_INC
#define HELLO_WORLD_INC
#pragma once
#include "optimizer/Optimization.hpp" // for optimization
#include "optimizer/OptimizationManager.hpp" // for optimization manager
namespace OMR {
class HelloWorldOpt : public TR::Optimization {
public:
HelloWorldOpt(TR::OptimizationManager *m) : TR::Optimization(m) {};
static TR::Optimization *create (TR::OptimizationManager *m) {
return new (m->allocator()) HelloWorldOpt(m);
};
virtual bool shouldPerform();
virtual int32_t perform();
virtual const char * optDetailString() const throw()
{
return "O^O Hello World Opt : ";
};
};
}
#endif#include "env/VerboseLog.hpp"
#include "optimizer/HelloWorldOpt.hpp"
bool
OMR::HelloWorldOpt::shouldPerform() {
return true;
}
int32_t
OMR::HelloWorldOpt::perform() {
// Say Hello world in the verbose log.
TR_VerboseLog::vlogAcquire();
// TR_Vlog_HWO is the tag to identify one's optimization pass in the verbose log.
TR_VerboseLog::writeLine(TR_Vlog_HWO, "Hello world");
TR_VerboseLog::vlogRelease();
return true;
}Modify the files omr/compiler/env/VerboseLog.{hpp,cpp}.
Please note that your vlog tag (i.e. TR_Vlog_HWO should be placed before TR_Vlog_numTags.)
and should be of the format '\n#TAGNAME: ' , as specified here
--- a/compiler/env/VerboseLog.hpp
+++ b/compiler/env/VerboseLog.hpp
@@ -70,6 +70,7 @@ enum TR_VlogTag
TR_Vlog_RECLAMATION,
TR_Vlog_PROFILING,
TR_Vlog_JITaaS,
+ TR_Vlog_HWO,
TR_Vlog_numTags
};--- a/compiler/env/VerboseLog.cpp
+++ b/compiler/env/VerboseLog.cpp
@@ -62,6 +62,7 @@ const char * TR_VerboseLog::_vlogTable[] =
"#RECLAMATION: ",
"#PROFILING: ",
"#JITaaS: ",
+ "#HWO: ",
};
void TR_VerboseLog::writeLine(TR_VlogTag tag, const char *format, ...)Modify openj9/runtime/compiler/build/files/common.mk to build HelloWorldOpt.cpp
Otherwise you just have some C++ code that is not compiled and is just hanging in there.
This optimizations is now ready to be placed in a compilation strategy.