Revert r354244 "[DAGCombiner] Eliminate dead stores to stack."
[llvm-complete.git] / lib / Target / XCore / XCoreTargetMachine.cpp
blob2d66a41de28307d01858c04abf096e8ce594da1d
1 //===-- XCoreTargetMachine.cpp - Define TargetMachine for XCore -----------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 //
10 //===----------------------------------------------------------------------===//
12 #include "XCoreTargetMachine.h"
13 #include "MCTargetDesc/XCoreMCTargetDesc.h"
14 #include "XCore.h"
15 #include "XCoreTargetObjectFile.h"
16 #include "XCoreTargetTransformInfo.h"
17 #include "llvm/ADT/Optional.h"
18 #include "llvm/ADT/STLExtras.h"
19 #include "llvm/Analysis/TargetTransformInfo.h"
20 #include "llvm/CodeGen/Passes.h"
21 #include "llvm/CodeGen/TargetPassConfig.h"
22 #include "llvm/Support/CodeGen.h"
23 #include "llvm/Support/TargetRegistry.h"
25 using namespace llvm;
27 static Reloc::Model getEffectiveRelocModel(Optional<Reloc::Model> RM) {
28 if (!RM.hasValue())
29 return Reloc::Static;
30 return *RM;
33 static CodeModel::Model
34 getEffectiveXCoreCodeModel(Optional<CodeModel::Model> CM) {
35 if (CM) {
36 if (*CM != CodeModel::Small && *CM != CodeModel::Large)
37 report_fatal_error("Target only supports CodeModel Small or Large");
38 return *CM;
40 return CodeModel::Small;
43 /// Create an ILP32 architecture model
44 ///
45 XCoreTargetMachine::XCoreTargetMachine(const Target &T, const Triple &TT,
46 StringRef CPU, StringRef FS,
47 const TargetOptions &Options,
48 Optional<Reloc::Model> RM,
49 Optional<CodeModel::Model> CM,
50 CodeGenOpt::Level OL, bool JIT)
51 : LLVMTargetMachine(
52 T, "e-m:e-p:32:32-i1:8:32-i8:8:32-i16:16:32-i64:32-f64:32-a:0:32-n32",
53 TT, CPU, FS, Options, getEffectiveRelocModel(RM),
54 getEffectiveXCoreCodeModel(CM), OL),
55 TLOF(llvm::make_unique<XCoreTargetObjectFile>()),
56 Subtarget(TT, CPU, FS, *this) {
57 initAsmInfo();
60 XCoreTargetMachine::~XCoreTargetMachine() = default;
62 namespace {
64 /// XCore Code Generator Pass Configuration Options.
65 class XCorePassConfig : public TargetPassConfig {
66 public:
67 XCorePassConfig(XCoreTargetMachine &TM, PassManagerBase &PM)
68 : TargetPassConfig(TM, PM) {}
70 XCoreTargetMachine &getXCoreTargetMachine() const {
71 return getTM<XCoreTargetMachine>();
74 void addIRPasses() override;
75 bool addPreISel() override;
76 bool addInstSelector() override;
77 void addPreEmitPass() override;
80 } // end anonymous namespace
82 TargetPassConfig *XCoreTargetMachine::createPassConfig(PassManagerBase &PM) {
83 return new XCorePassConfig(*this, PM);
86 void XCorePassConfig::addIRPasses() {
87 addPass(createAtomicExpandPass());
89 TargetPassConfig::addIRPasses();
92 bool XCorePassConfig::addPreISel() {
93 addPass(createXCoreLowerThreadLocalPass());
94 return false;
97 bool XCorePassConfig::addInstSelector() {
98 addPass(createXCoreISelDag(getXCoreTargetMachine(), getOptLevel()));
99 return false;
102 void XCorePassConfig::addPreEmitPass() {
103 addPass(createXCoreFrameToArgsOffsetEliminationPass(), false);
106 // Force static initialization.
107 extern "C" void LLVMInitializeXCoreTarget() {
108 RegisterTargetMachine<XCoreTargetMachine> X(getTheXCoreTarget());
111 TargetTransformInfo
112 XCoreTargetMachine::getTargetTransformInfo(const Function &F) {
113 return TargetTransformInfo(XCoreTTIImpl(this, F));