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 attributes in a JSON dict format to
25// specify arguments to specialize for. Although it is technically possible for
26// users to directly provide the long form notation, the expected usage is that
27// they call proteus::jit_arg or proteus::jit_array instrumentation functions,
28// esp. since reconstructing the expected JSON form and providing explicit
29// runtime type enum values is not ideal.
30//
31// Both annotations forms populate the global variable llvm.global.annotations
32// in the LLVM IR. For split device compilation, the handler also emits a
33// JSON manifest file for the host compilation to parse, since there is no other
34// direct channel between the split device and host compilation.
35
36namespace proteus {
37
38using namespace llvm;
39
41public:
42 AnnotationHandler(Module &M);
43
44 void
45 parseAnnotations(MapVector<Function *, JitFunctionInfo> &JitFunctionInfoMap);
46
48 const DenseMap<Value *, GlobalVariable *> &StubToKernelMap,
49 MapVector<Function *, JitFunctionInfo> &JitFunctionInfoMap);
50
51private:
52 Module &M;
53 ProteusTypes Types;
54
55 SmallString<64> getUniqueManifestFilename();
56
57 void appendToGlobalAnnotations(SmallVector<Constant *> &NewAnnotations);
58
59 Constant *
60 createJitAnnotation(Function *F,
61 SmallSetVector<RuntimeConstantInfo, 16> &ConstantArgs);
62
63 void createDeviceManifestFile(
64 DenseMap<Function *, SmallSetVector<RuntimeConstantInfo, 16>> &RCInfoMap);
65
66 void parseJitArgAnnotations(
67 SmallPtrSetImpl<Function *> &JitArgAnnotations,
68 DenseMap<Function *, SmallSetVector<RuntimeConstantInfo, 16>> &RCInfoMap);
69
70 void parseJitArrayAnnotations(
71 SmallPtrSetImpl<Function *> &JitArrayAnnotations,
72 DenseMap<Function *, SmallSetVector<RuntimeConstantInfo, 16>> &RCInfoMap);
73
74 void parseJitObjectAnnotations(
75 SmallPtrSetImpl<Function *> &JitObjectAnnotations,
76 DenseMap<Function *, SmallSetVector<RuntimeConstantInfo, 16>> &RCInfoMap);
77
78 void parseAttributeAnnotations(
79 GlobalVariable *GlobalAnnotations,
80 MapVector<Function *, JitFunctionInfo> &JitFunctionInfoMap);
81};
82
83} // namespace proteus
84
85#endif
Definition AnnotationHandler.h:40
void parseAnnotations(MapVector< Function *, JitFunctionInfo > &JitFunctionInfoMap)
Definition AnnotationHandler.cpp:309
void parseManifestFileAnnotations(const DenseMap< Value *, GlobalVariable * > &StubToKernelMap, MapVector< Function *, JitFunctionInfo > &JitFunctionInfoMap)
Definition AnnotationHandler.cpp:364
Definition Helpers.h:76
Definition BuiltinsCUDA.cpp:4
Definition Types.h:14