Pages

Sunday 20 July 2014

How to create own Transforms pass directory in llvm-3.4

Step 1: Go to the llvm Transforms directory and create directory MyLLVMPasses 
            (you can give any directory name)


cd llvm/lib/Transforms
mkdir MyLLVMPasses


Step 2: Add directory name MyLLVMPasses in Transforms/CmakeLists.txt file 


add_subdirectory(MyLLVMPasses)


Step 3: Add directory name MyLLVMPasses in Transforms/LLVMBuild.txt file


[common]
subdirectories = IPO InstCombine Instrumentation Scalar Utils Vectorize ObjCARC MyLLVMPasses


Step 4: Add directory name MyLLVMPasses in Transforms/Makefile file


PARALLEL_DIRS = Utils Instrumentation Scalar InstCombine IPO Vectorize Hello ObjCARC MyLLVMPasses


Step 5: Create CmakeLists.txt file in  MyLLVMPasses directory and write these lines


add_llvm_library(LLVMMyLLVMPasses
  )

add_dependencies(LLVMMyLLVMPasses intrinsics_gen)


Step 6: Create LLVMBuild.txt file in MyLLVMPasses directory and write these lines


[component_0]
type = Library
name = MyLLVMPasses
parent = Transforms
library_name = MyLLVMPasses
required_libraries = Analysis Core Support Target TransformUtils


Step 7:  Create Makefile in MyLLVMPasses directory and write these lines


LEVEL = ../../..
LIBRARYNAME = LLVMMyLLVMPasses
BUILD_ARCHIVE = 1

include $(LEVEL)/Makefile.common


Step 8: Create MyLLVMPasses.cpp file in MyLLVMPasses directory and write these lines


#include "llvm/Transforms/MyLLVMPasses.h"
#include "llvm-c/Initialization.h"
#include "llvm-c/Transforms/MyLLVMPasses.h"
#include "llvm/Analysis/Passes.h"
#include "llvm/IR/Verifier.h"
#include "llvm/InitializePasses.h"
#include "llvm/PassManager.h"

using namespace llvm;
// initializeMyLLVMPasses - Initialize all passes linked into the
// MyLLVMPasses library.

void llvm::initializeMyLLVMPasses(PassRegistry &Registry) {
  // nothing is needed here yet
}

void LLVMInitializeMyLLVMPasses(LLVMPassRegistryRef R) {
  initializeMyLLVMPasses(*unwrap(R));
}


Step 9: Create MyLLVMPasses.h file in llvm/include/llvm/Transforms and write these lines


#ifndef LLVM_TRANSFORMS_MYLLVMPASSES_H
#define LLVM_TRANSFORMS_MYLLVMPASSES_H

#include "llvm/ADT/StringRef.h"

namespace llvm {

class FunctionPass;
class Pass;

} // End llvm namespace

#endif


Step 10: Create MyLLVMPasses.h file in llvm/include/llvm-c/Transforms and write these lines


#ifndef LLVM_C_TRANSFORMS_MYLLVMPASSES_H
#define LLVM_C_TRANSFORMS_MYLLVMPASSES_H

#include "llvm-c/Core.h"

#ifdef __cplusplus
extern "C" {
#endif

// LLVMCTransformsMyLLVMPasses MyLLVMPasses transformations

#ifdef __cplusplus
}
#endif /* defined(__cplusplus) */

#endif


Step 11: Open llvm/include/llvm-c/Initialization.h file, add this line


void LLVMInitializeMyLLVMPasses(LLVMPassRegistryRef R);


Step 12: Open llvm/include/llvm/InitializePasses.h file, add this line


// initializeMyLLVMPasses - Initialize all passes linked into the
// MyLLVMPasses library.
void initializeMyLLVMPasses(PassRegistry&);


Step 13: Add directory name MyLLVMPasses in lib/Transforms/IPO/LLVMBuild.txt file


[component_0]
type = Library
name = IPO
parent = Transforms
library_name = ipo
required_libraries = Analysis Core IPA InstCombine Scalar Support Target TransformUtils Vectorize MyLLVMPasses


Step 14: Include MyLLVMPasses.h file in llvm/include/llvm/LinkAllPasses.h file


#include "llvm/Transforms/MyLLVMPasses.h"


Step 15: Include MyLLVMPasses.h file in llvm/tools/clang/lib/CodeGen/BackendUtil.cpp file


#include "llvm/Transforms/MyLLVMPasses.h"

No comments:

Post a Comment