Proteus
Programmable JIT compilation and optimization for C/C++ using LLVM
Loading...
Searching...
No Matches
AnnotationHandler.h
Go to the documentation of this file.
1#ifndef PROTEUS_PASS_ANNOTATIONS_PARSER_H
2#define PROTEUS_PASS_ANNOTATIONS_PARSER_H
3
4#include <llvm/ADT/SetVector.h>
5#include <llvm/Demangle/Demangle.h>
6#include <llvm/IR/Constants.h>
7#include <llvm/IR/IRBuilder.h>
8#include <llvm/IR/Instructions.h>
9#include <llvm/IR/Module.h>
10#include <llvm/IR/Verifier.h>
11#include <llvm/Support/Debug.h>
12#include <llvm/Support/JSON.h>
13#include <llvm/Support/MemoryBuffer.h>
14
15#include "Helpers.h"
16#include "Types.h"
17
18// The annotation handler supports two types of attribute-based annotations:
19// Short form, which uses an annotate attribute to specify an 1-indexed,
20// comma-separated list of scalar arguments as integers to specialize for:
21//
22// __attibute__((annotate("jit", [<argument list>])))
23//
24// Long form, which uses the annotate attribute to specify arguments to
25// specialize but also supports arrays. The long form uses key-value pairs:
26// arg=<1-index argument number>:
27//
28// __attribute__((annotate("jit", ["arg=<N>"]*)))
29//
30// Those annotations populate the llvm.global.annotations global variable in the
31// LLVM IR.
32//
33// Besides attribute-based annotations, the handler supports annotations through
34// the C++ API, namely proteus::jit_arg. The handler parses the IR and populates
35// llvm.global.annotations accordingly. For split device compilation, it emits a
36// JSON manifest file that the host compilation parses.
37
38namespace proteus {
39
40using namespace llvm;
41
43public:
44 AnnotationHandler(Module &M);
45
46 void
47 parseAnnotations(MapVector<Function *, JitFunctionInfo> &JitFunctionInfoMap);
48
50 const DenseMap<Value *, GlobalVariable *> &StubToKernelMap,
51 MapVector<Function *, JitFunctionInfo> &JitFunctionInfoMap);
52
53private:
54 Module &M;
55 ProteusTypes Types;
56
57 SmallString<64> getUniqueManifestFilename();
58
59 void appendToGlobalAnnotations(SmallVector<Constant *> &NewAnnotations);
60
61 Constant *createJitAnnotation(Function *F, SmallVector<int> &ConstantArgs);
62
63 void createDeviceManifestFile(
64 DenseMap<Function *, SmallSetVector<int, 16>> &JitArgs);
65
66 void parseJitArgAnnotations(SmallPtrSetImpl<Function *> &JitArgAnnotations);
67
68 void parseAttributeAnnotations(
69 GlobalVariable *GlobalAnnotations,
70 MapVector<Function *, JitFunctionInfo> &JitFunctionInfoMap);
71};
72
73} // namespace proteus
74
75#endif
Definition AnnotationHandler.h:42
void parseAnnotations(MapVector< Function *, JitFunctionInfo > &JitFunctionInfoMap)
Definition AnnotationHandler.cpp:114
void parseManifestFileAnnotations(const DenseMap< Value *, GlobalVariable * > &StubToKernelMap, MapVector< Function *, JitFunctionInfo > &JitFunctionInfoMap)
Definition AnnotationHandler.cpp:139
Definition Dispatcher.cpp:14
Definition Types.h:14