summaryrefslogtreecommitdiffstats
path: root/llvm/include/llvm-target.h
blob: 17849422e32b353addd157d4ba989d78f9daef64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
 *  (C) 2010 by Computer System Laboratory, IIS, Academia Sinica, Taiwan.
 *      See COPYRIGHT in top-level directory.
 */

#ifndef __LLVM_TARGET_H
#define __LLVM_TARGET_H

#include "llvm/ExecutionEngine/JITEventListener.h"
#include "llvm/Object/ObjectFile.h"
#include "llvm-types.h"
#include "llvm-translator.h"

#ifndef __PRI64_PREFIX
#  if __WORDSIZE == 64
#    define __PRI64_PREFIX  "l"
#  else
#    define __PRI64_PREFIX  "ll"
#  endif
#endif

#if TARGET_LONG_BITS == 32
#  define PRId  "d"
#  define PRIx  "x"
#else
#  define PRId  __PRI64_PREFIX "d"
#  define PRIx  __PRI64_PREFIX "x"
#endif

#define PRId64  __PRI64_PREFIX "d"
#define PRIu64  __PRI64_PREFIX "u"

class code_ostream {
    char *OutBufStart;
    char *OutBufCur;
public:
    void Skip(unsigned Size) {
        OutBufCur += Size;
    }

    code_ostream(uintptr_t Ptr)
        : OutBufStart((char *)Ptr), OutBufCur((char *)Ptr) {}
    code_ostream &operator<<(char C) {
        *OutBufCur = C;
        OutBufCur++;
        return *this;
    }
    code_ostream &operator<<(unsigned char C) {
        *(unsigned char *)OutBufCur = C;
        OutBufCur++;
        return *this;
    }
    code_ostream &operator<<(unsigned int C) {
        *(unsigned int *)OutBufCur = C;
        OutBufCur += sizeof(unsigned int);
        return *this;
    }
    code_ostream &operator<<(unsigned long C) {
        *(unsigned long *)OutBufCur = C;
        OutBufCur += sizeof(unsigned long);
        return *this;
    }
};

static inline void EmitByte(code_ostream &OS, unsigned char C)
{
    OS << (char)C;
}
static inline void EmitConstant(code_ostream &OS, uint64_t Val, unsigned Size)
{
    for (unsigned i = 0; i != Size; ++i) {
        EmitByte(OS, Val & 255);
        Val >>= 8;
    }
}

/*
 * EventListener is used by the JIT to notify clients about significant events
 * during compilation.
 */
class EventListener : public JITEventListener {
    NotifyInfo &NI;

public:
    EventListener(NotifyInfo &NI) : NI(NI) {}
    ~EventListener() {}
    virtual void NotifyFunctionEmitted(const Function &F, void *Code, size_t Size,
                                       const EmittedFunctionDetails &Details);
#if defined(LLVM_V35)
    virtual void NotifyObjectEmitted(const ObjectImage &Obj);
#else
    virtual void NotifyObjectEmitted(const object::ObjectFile &Obj,
                                     const RuntimeDyld::LoadedObjectInfo &L);
#endif
};


const char *getMMUFName(const void *func);
bool isMMUFunction(std::string &Name);
bool isLMTFunction(std::string &Name);
bool isIllegalHelper(const void *func);
bool isLibcall(std::string &Name);
bool isSoftFPcall(std::string &Name);
void AddDependentSymbols(LLVMTranslator *Translator);
Value *StripPointer(Value *Ptr);
Value *StripPointerWithConstantOffset(const DataLayout *DL, Value *Ptr,
                                      APInt &Offset, Value *GuestBase);
Value *getBaseWithConstantOffset(const DataLayout *DL, Value *Ptr, intptr_t &Offset);
void ProcessErase(IVec &toErase);

#endif

/*
 * vim: ts=8 sts=4 sw=4 expandtab
 */

OpenPOWER on IntegriCloud