summaryrefslogtreecommitdiff
path: root/lib/Target/Hexagon/HexagonTargetMachine.cpp
blob: b29e92c0c68187c660151938574ce4403a82eca8 (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//===-- HexagonTargetMachine.cpp - Define TargetMachine for Hexagon -------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
//
//===----------------------------------------------------------------------===//

#include "HexagonTargetMachine.h"
#include "Hexagon.h"
#include "HexagonISelLowering.h"
#include "llvm/Module.h"
#include "llvm/CodeGen/Passes.h"
#include "llvm/PassManager.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Support/TargetRegistry.h"
#include <iostream>

using namespace llvm;

static cl::
opt<bool> DisableHardwareLoops(
                        "disable-hexagon-hwloops", cl::Hidden,
                        cl::desc("Disable Hardware Loops for Hexagon target"));

/// HexagonTargetMachineModule - Note that this is used on hosts that
/// cannot link in a library unless there are references into the
/// library.  In particular, it seems that it is not possible to get
/// things to work on Win32 without this.  Though it is unused, do not
/// remove it.
extern "C" int HexagonTargetMachineModule;
int HexagonTargetMachineModule = 0;

extern "C" void LLVMInitializeHexagonTarget() {
  // Register the target.
  RegisterTargetMachine<HexagonTargetMachine> X(TheHexagonTarget);
}


/// HexagonTargetMachine ctor - Create an ILP32 architecture model.
///

/// Hexagon_TODO: Do I need an aggregate alignment?
///
HexagonTargetMachine::HexagonTargetMachine(const Target &T, StringRef TT,
                                           StringRef CPU, StringRef FS,
                                           TargetOptions Options,
                                           Reloc::Model RM,
                                           CodeModel::Model CM,
                                           CodeGenOpt::Level OL)
  : LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL),
    DataLayout("e-p:32:32:32-i64:64:64-i32:32:32-i16:16:16-i1:32:32-a0:0") ,
    Subtarget(TT, CPU, FS), TLInfo(*this), InstrInfo(Subtarget),
    TSInfo(*this),
    FrameLowering(Subtarget),
    InstrItins(&Subtarget.getInstrItineraryData()) {
  setMCUseCFI(false);
}

// addPassesForOptimizations - Allow the backend (target) to add Target
// Independent Optimization passes to the Pass Manager.
bool HexagonTargetMachine::addPassesForOptimizations(PassManagerBase &PM) {

  PM.add(createConstantPropagationPass());
  PM.add(createLoopSimplifyPass());
  PM.add(createDeadCodeEliminationPass());
  PM.add(createConstantPropagationPass());
  PM.add(createLoopUnrollPass());
  PM.add(createLoopStrengthReducePass(getTargetLowering()));
  return true;
}

bool HexagonTargetMachine::addInstSelector(PassManagerBase &PM) {
  PM.add(createHexagonRemoveExtendOps(*this));
  PM.add(createHexagonISelDag(*this));
  return false;
}


bool HexagonTargetMachine::addPreRegAlloc(PassManagerBase &PM) {
  if (!DisableHardwareLoops) {
    PM.add(createHexagonHardwareLoops());
  }

  return false;
}

bool HexagonTargetMachine::addPostRegAlloc(PassManagerBase &PM) {
  PM.add(createHexagonCFGOptimizer(*this));
  return true;
}


bool HexagonTargetMachine::addPreSched2(PassManagerBase &PM) {
  PM.add(createIfConverterPass());
  return true;
}

bool HexagonTargetMachine::addPreEmitPass(PassManagerBase &PM) {

  if (!DisableHardwareLoops) {
    PM.add(createHexagonFixupHwLoops());
  }

  // Expand Spill code for predicate registers.
  PM.add(createHexagonExpandPredSpillCode(*this));

  // Split up TFRcondsets into conditional transfers.
  PM.add(createHexagonSplitTFRCondSets(*this));

  return false;
}