From: Devang Patel
+ static const int ID;
+ Hello() : FunctionPass((intptr_t)&ID) {}
++ +
This declares pass identifier used by LLVM to identify pass. This allows LLVM to +avoid using expensive C++ runtime information.
+
virtual bool runOnFunction(Function &F) {
llvm::cerr << "Hello: " << F.getName() << "\n";
@@ -276,6 +284,13 @@ href="#FunctionPass">FunctionPass. This is where we are supposed
to do our thing, so we just print out our message with the name of each
function.
+
+ const int Hello::ID = 0;
+
+
+ We initialize pass ID here. LLVM uses ID's address to identify pass so
+initialization value is not important.
+
RegisterPass<Hello> X("hello", "Hello World Pass");
} // end of anonymous namespace
@@ -295,6 +310,10 @@ argument "hello", and a name "Hello World Pass".
namespace {
struct Hello : public FunctionPass {
+
+ static const int ID;
+ Hello() : FunctionPass((intptr_t)&ID) {}
+
virtual bool runOnFunction(Function &F) {
llvm::cerr << "Hello: " << F.getName() << "\n";
return false;