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

Last change on this file since 5260 was 5260, checked in by nmedfort, 2 years ago

Changes working towards simplifying accessing stream elements + some modifications to simplify include / forward declarations within the CodeGen? library.

File size: 3.1 KB
Line 
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
8#include <string>
9#include <llvm/IR/IRBuilder.h>
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; }
17
18class CBuilder : public llvm::IRBuilder<> {
19   
20public:
21   
22    CBuilder(llvm::Module * m, unsigned archBitWidth, unsigned CacheAlignment=64);
23   
24    virtual ~CBuilder() {}
25
26    llvm::Module * getModule() const {
27        return mMod;
28    }
29   
30    void setModule(llvm::Module * m)  {
31        mMod = m;
32    }
33   
34    llvm::Function * GetPrintf();
35    llvm::Value * CreateMalloc(llvm::Type * type, llvm::Value * size);
36    llvm::Value * CreateAlignedMalloc(llvm::Type * type, llvm::Value * size, const unsigned alignment);
37    void CreateFree(llvm::Value * const ptr);
38    void CreateAlignedFree(llvm::Value * const ptr, const bool ptrMayBeNull = false);
39    llvm::Value * CreateRealloc(llvm::Value * ptr, llvm::Value * size);
40    void CreateMemZero(llvm::Value * ptr, llvm::Value * size, const unsigned alignment = 1);
41
42    inline llvm::AllocaInst * CreateCacheAlignedAlloca(llvm::Type * Ty, llvm::Value * ArraySize = nullptr) {
43        llvm::AllocaInst * instr = CreateAlloca(Ty, ArraySize);
44        instr->setAlignment(getCacheAlignment());
45        return instr;
46    }
47   
48    // Create calls to unistd.h functions.
49    //
50    // ssize_t write(int fildes, const void *buf, size_t nbyte);
51    llvm::Value * CreateWriteCall(llvm::Value * fildes, llvm::Value * buf, llvm::Value * nbyte);
52   
53    // Create calls to Posix thread (pthread.h) functions.
54    //
55    //  int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
56    //                    void *(*start_routine)(void*), void *arg);
57    llvm::Value * CreatePThreadCreateCall(llvm::Value * thread, llvm::Value * attr, llvm::Function * start_routine, llvm::Value * arg);
58    //  void pthread_exit(void *value_ptr);
59    llvm::Value * CreatePThreadExitCall(llvm::Value * value_ptr);
60    //  int pthread_join(pthread_t thread, void **value_ptr);
61    llvm::Value * CreatePThreadJoinCall(llvm::Value * thread, llvm::Value * value_ptr);
62   
63    void CallPrintInt(const std::string & name, llvm::Value * const value);
64   
65    inline llvm::IntegerType * getSizeTy() const {
66        return mSizeType;
67    }
68   
69    inline llvm::ConstantInt * getSize(const size_t value) const {
70        return llvm::ConstantInt::get(getSizeTy(), value);
71    }
72   
73    llvm::PointerType * getVoidPtrTy() const;
74   
75    inline unsigned getCacheAlignment() const {
76        return mCacheLineAlignment;
77    }
78   
79    virtual llvm::LoadInst* CreateAtomicLoadAcquire(llvm::Value * ptr);
80
81    virtual llvm::StoreInst *  CreateAtomicStoreRelease(llvm::Value * val, llvm::Value * ptr);
82   
83protected:
84    llvm::Module *      mMod;
85    unsigned            mCacheLineAlignment;
86    llvm::IntegerType * mSizeType;
87};
88
89#endif
Note: See TracBrowser for help on using the repository browser.