source: icGREP/icgrep-devel/icgrep/IR_Gen/CBuilder.h @ 5280

Last change on this file since 5280 was 5280, checked in by cameron, 2 years ago

FileSink? kernel

File size: 3.8 KB
RevLine 
[5239]1/*
2 *  Copyright (c) 2016 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 */
5#ifndef CBUILDER_H
6#define CBUILDER_H
7
[5260]8#include <string>
[5239]9#include <llvm/IR/IRBuilder.h>
[5260]10#include <llvm/IR/Constants.h>
11namespace llvm { class Function; }
12namespace llvm { class IntegerType; }
13namespace llvm { class Module; }
14namespace llvm { class PointerType; }
15namespace llvm { class Type; }
16namespace llvm { class Value; }
[5239]17
[5260]18class CBuilder : public llvm::IRBuilder<> {
[5239]19   
20public:
21   
[5267]22    CBuilder(llvm::Module * m, unsigned GeneralRegisterWidthInBits, unsigned CacheLineAlignmentInBytes = 64);
[5239]23   
24    virtual ~CBuilder() {}
25
[5260]26    llvm::Module * getModule() const {
[5239]27        return mMod;
28    }
29   
[5260]30    void setModule(llvm::Module * m)  {
[5239]31        mMod = m;
32    }
[5280]33   
[5260]34    llvm::Value * CreateMalloc(llvm::Type * type, llvm::Value * size);
[5280]35   
[5260]36    llvm::Value * CreateAlignedMalloc(llvm::Type * type, llvm::Value * size, const unsigned alignment);
[5280]37   
[5260]38    void CreateFree(llvm::Value * const ptr);
[5280]39   
[5260]40    void CreateAlignedFree(llvm::Value * const ptr, const bool ptrMayBeNull = false);
[5280]41   
[5260]42    llvm::Value * CreateRealloc(llvm::Value * ptr, llvm::Value * size);
[5280]43   
[5260]44    void CreateMemZero(llvm::Value * ptr, llvm::Value * size, const unsigned alignment = 1);
[5245]45
46    inline llvm::AllocaInst * CreateCacheAlignedAlloca(llvm::Type * Ty, llvm::Value * ArraySize = nullptr) {
47        llvm::AllocaInst * instr = CreateAlloca(Ty, ArraySize);
48        instr->setAlignment(getCacheAlignment());
49        return instr;
50    }
[5239]51   
[5280]52    // stdio.h functions
53    //
54    //  Create a call to:  FILE *fopen(const char *filename, const char *mode);
55    llvm::Value * CreateFOpenCall(llvm::Value * filename, llvm::Value * mode);
56    //  Create a call to:  size_t fwrite(const void *ptr, size_t size, size_t nitems, FILE *stream));
57    llvm::Value * CreateFWriteCall(llvm::Value * ptr, llvm::Value * size, llvm::Value * nitems, llvm::Value * stream);
58    //  Create a call to:  int fclose ( FILE * stream );
59    llvm::Value * CreateFCloseCall(llvm::Value * stream);
60   
[5267]61    llvm::Function * GetPrintf();
62
[5280]63    //  Create calls to unistd.h functions.
64    //
65    //  Create a call to:  ssize_t write(int fildes, const void *buf, size_t nbyte);
[5260]66    llvm::Value * CreateWriteCall(llvm::Value * fildes, llvm::Value * buf, llvm::Value * nbyte);
[5243]67   
[5280]68    //  Posix thread (pthread.h) functions.
69    //
70    //  Create a call to:  int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
71    //                    void *(*start_routine)(void*), void *arg);
[5260]72    llvm::Value * CreatePThreadCreateCall(llvm::Value * thread, llvm::Value * attr, llvm::Function * start_routine, llvm::Value * arg);
[5280]73   
74    //  Create a call to:  void pthread_exit(void *value_ptr);
[5260]75    llvm::Value * CreatePThreadExitCall(llvm::Value * value_ptr);
[5280]76   
77    //  Create a call to:  int pthread_join(pthread_t thread, void **value_ptr);
[5260]78    llvm::Value * CreatePThreadJoinCall(llvm::Value * thread, llvm::Value * value_ptr);
[5242]79   
[5260]80    void CallPrintInt(const std::string & name, llvm::Value * const value);
[5239]81   
82    inline llvm::IntegerType * getSizeTy() const {
83        return mSizeType;
84    }
85   
[5267]86    inline llvm::ConstantInt * getSize(const size_t value) {
[5260]87        return llvm::ConstantInt::get(getSizeTy(), value);
[5239]88    }
89   
[5260]90    llvm::PointerType * getVoidPtrTy() const;
[5280]91    llvm::PointerType * getFILEptrTy();
[5239]92   
93    inline unsigned getCacheAlignment() const {
94        return mCacheLineAlignment;
95    }
96   
[5260]97    virtual llvm::LoadInst* CreateAtomicLoadAcquire(llvm::Value * ptr);
98
99    virtual llvm::StoreInst *  CreateAtomicStoreRelease(llvm::Value * val, llvm::Value * ptr);
[5239]100   
101protected:
[5260]102    llvm::Module *      mMod;
[5239]103    unsigned            mCacheLineAlignment;
[5260]104    llvm::IntegerType * mSizeType;
[5280]105    llvm::StructType *  mFILEtype;
[5239]106};
107
108#endif
Note: See TracBrowser for help on using the repository browser.