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
|
//===-- gen/dcompute/target.h ------------------------------------*- C++-*-===//
//
// LDC – the LLVM D compiler
//
// This file is distributed under the BSD-style LDC license. See the LICENSE
// file for details.
//
//===----------------------------------------------------------------------===//
#pragma once
#include "gen/irstate.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Function.h"
#include <array>
namespace llvm {
class Module;
class Function;
class TargetMachine;
}
class Module;
class FuncDeclaration;
class DComputeTarget {
public:
llvm::LLVMContext &ctx;
int tversion; // OpenCL or CUDA CC version:major*100 + minor*10
enum ID { Host = 0, OpenCL = 1, CUDA = 2 };
ID target; // ID for codegen time conditional compilation.
const char *short_name;
const char *binSuffix;
TargetABI *abi;
llvm::TargetMachine *targetMachine = nullptr;
// The nominal address spaces in DCompute are Private = 0, Global = 1,
// Shared = 2, Constant = 3, Generic = 4
std::array<int, 5> mapping;
IRState *_ir;
DComputeTarget(llvm::LLVMContext &c, int v, ID id, const char *_short_name,
const char *suffix, TargetABI *a, std::array<int, 5> map)
: ctx(c), tversion(v), target(id), short_name(_short_name),
binSuffix(suffix), abi(a), mapping(map), _ir(nullptr) {}
void emit(Module *m);
void doCodeGen(Module *m);
void writeModule();
virtual void addMetadata() = 0;
virtual void addKernelMetadata(FuncDeclaration *df, llvm::Function *llf) = 0;
};
#if LDC_LLVM_SUPPORTED_TARGET_NVPTX
DComputeTarget *createCUDATarget(llvm::LLVMContext &c, int sm);
#endif
#if LDC_LLVM_SUPPORTED_TARGET_SPIRV
DComputeTarget *createOCLTarget(llvm::LLVMContext &c, int oclver);
#endif
|