summaryrefslogtreecommitdiffstats
path: root/contrib/restricted/wavm/Lib/LLVMJIT/EmitModuleContext.h
blob: 03ca2be9870205785ccd5d4bcfa417c1aaa34909 (plain) (blame)
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
#pragma once

#include "LLVMJITPrivate.h"
#include "WAVM/IR/Module.h"
#include "WAVM/IR/Types.h"

PUSH_DISABLE_WARNINGS_FOR_LLVM_HEADERS
#include <llvm/IR/DIBuilder.h>
POP_DISABLE_WARNINGS_FOR_LLVM_HEADERS

namespace WAVM { namespace LLVMJIT {
	struct EmitModuleContext
	{
		const IR::Module& irModule;

		LLVMContext& llvmContext;
		llvm::Module* llvmModule;

		llvm::TargetMachine* targetMachine;
		llvm::Triple::ArchType targetArch;
		bool useWindowsSEH;

		llvm::Type* iptrType;
		IR::ValueType iptrValueType;
		U32 iptrAlignment;

		std::vector<llvm::Constant*> typeIds;
		std::vector<llvm::Function*> functions;
		std::vector<llvm::Constant*> tableOffsets;
		std::vector<llvm::Constant*> memoryOffsets;
		std::vector<llvm::Constant*> globals;
		std::vector<llvm::Constant*> exceptionTypeIds;

		llvm::Constant* defaultTableOffset;

		llvm::Constant* instanceId;
		llvm::Constant* tableReferenceBias;

#if LLVM_VERSION_MAJOR < 10
		llvm::Constant* unoptimizableOne;
#endif

		llvm::DIBuilder diBuilder;
		llvm::DICompileUnit* diCompileUnit;
		llvm::DIFile* diModuleScope;

		llvm::DIType* diValueTypes[IR::numValueTypes];

		llvm::MDNode* likelyFalseBranchWeights;
		llvm::MDNode* likelyTrueBranchWeights;

		llvm::Value* fpRoundingModeMetadata;
		llvm::Value* fpExceptionMetadata;

		llvm::Function* cxaBeginCatchFunction = nullptr;
		llvm::Function* cxaEndCatchFunction = nullptr;
		llvm::Constant* runtimeExceptionTypeInfo = nullptr;

		EmitModuleContext(const IR::Module& inModule,
						  LLVMContext& inLLVMContext,
						  llvm::Module* inLLVMModule,
						  llvm::TargetMachine* inTargetMachine);

		inline llvm::Function* getLLVMIntrinsic(llvm::ArrayRef<llvm::Type*> typeArguments,
												llvm::Intrinsic::ID id)
		{
			return llvm::Intrinsic::getDeclaration(llvmModule, id, typeArguments);
		}
	};
}}