1//===-- llvm/Support/CodeGen.h - CodeGen Concepts ---------------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file define some types which define code generation concepts. For
11// example, relocation model.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_SUPPORT_CODEGEN_H
16#define LLVM_SUPPORT_CODEGEN_H
17
18#include "llvm-c/TargetMachine.h"
19#include "llvm/Support/ErrorHandling.h"
20
21namespace llvm {
22
23  // Relocation model types.
24  namespace Reloc {
25    enum Model { Default, Static, PIC_, DynamicNoPIC };
26  }
27
28  // Code model types.
29  namespace CodeModel {
30    enum Model { Default, JITDefault, Small, Kernel, Medium, Large };
31  }
32
33  // TLS models.
34  namespace TLSModel {
35    enum Model {
36      GeneralDynamic,
37      LocalDynamic,
38      InitialExec,
39      LocalExec
40    };
41  }
42
43  // Code generation optimization level.
44  namespace CodeGenOpt {
45    enum Level {
46      None,        // -O0
47      Less,        // -O1
48      Default,     // -O2, -Os
49      Aggressive   // -O3
50    };
51  }
52
53  // Create wrappers for C Binding types (see CBindingWrapping.h).
54  inline CodeModel::Model unwrap(LLVMCodeModel Model) {
55    switch (Model) {
56      case LLVMCodeModelDefault:
57        return CodeModel::Default;
58      case LLVMCodeModelJITDefault:
59        return CodeModel::JITDefault;
60      case LLVMCodeModelSmall:
61        return CodeModel::Small;
62      case LLVMCodeModelKernel:
63        return CodeModel::Kernel;
64      case LLVMCodeModelMedium:
65        return CodeModel::Medium;
66      case LLVMCodeModelLarge:
67        return CodeModel::Large;
68    }
69    return CodeModel::Default;
70  }
71
72  inline LLVMCodeModel wrap(CodeModel::Model Model) {
73    switch (Model) {
74      case CodeModel::Default:
75        return LLVMCodeModelDefault;
76      case CodeModel::JITDefault:
77        return LLVMCodeModelJITDefault;
78      case CodeModel::Small:
79        return LLVMCodeModelSmall;
80      case CodeModel::Kernel:
81        return LLVMCodeModelKernel;
82      case CodeModel::Medium:
83        return LLVMCodeModelMedium;
84      case CodeModel::Large:
85        return LLVMCodeModelLarge;
86    }
87    llvm_unreachable("Bad CodeModel!");
88  }
89}  // end llvm namespace
90
91#endif
92