summaryrefslogtreecommitdiff
path: root/lib/Target/TGSI/TGSITargetMachine.cpp
blob: 40e5c0e34d07987a30b79a314888a95397a9f47f (plain)
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
//===-- TGSITargetMachine.cpp - Define TargetMachine for TGSI -----------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file declares the TGSI specific subclass of TargetMachine.
//
//===----------------------------------------------------------------------===//

#include "TGSI.h"
#include "TGSITargetMachine.h"
#include "llvm/CodeGen/Passes.h"
#include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
#include "llvm/CodeGen/TargetPassConfig.h"
#include "llvm/IR/PassManager.h"
#include "llvm/Support/TargetRegistry.h"
using namespace llvm;

namespace {
   class TGSIPassConfig : public TargetPassConfig {
   public:
      TGSIPassConfig(TGSITargetMachine *TM, PassManagerBase &PM)
         : TargetPassConfig(TM, PM) {}

      TGSITargetMachine &getTGSITargetMachine() const {
         return getTM<TGSITargetMachine>();
      }

      virtual bool addInstSelector();
   };
}

extern "C" void LLVMInitializeTGSITarget() {
   RegisterTargetMachine<TGSITargetMachine> X(TheTGSITarget);
}

static std::string computeDataLayout(const Triple &TT, StringRef CPU,
                                     const TargetOptions &Options) {
   return std::string("E-p:32:32-i64:64:64-f32:32:32-n32");
}

TGSITargetMachine::TGSITargetMachine(const Target &T, const Triple &TT,
                                     StringRef CPU, StringRef FS,
                                     const TargetOptions &Options,
                                     Optional<llvm::Reloc::Model> RM,
                                     CodeModel::Model CM,
                                     CodeGenOpt::Level OL)
   // TGSI does not support linking (only supports building a single file)
   // So we always use Reloc::Static
   : LLVMTargetMachine(T, computeDataLayout(TT, CPU, Options),
                       TT, CPU, FS, Options, Reloc::Static, CM, OL),
     TLOF(make_unique<TargetLoweringObjectFileELF>()),
     Subtarget(TT, CPU, FS, *this) {
   initAsmInfo();
}

TargetPassConfig *TGSITargetMachine::createPassConfig(PassManagerBase &PM) {
   return new TGSIPassConfig(this, PM);
}

bool TGSIPassConfig::addInstSelector() {
   addPass(createTGSIISelDag(getTGSITargetMachine()));
   return false;
}