• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- AArch64TargetMachine.cpp - Define TargetMachine for AArch64 -------===//
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 contains the implementation of the AArch64TargetMachine
11 // methods. Principally just setting up the passes needed to generate correct
12 // code on this architecture.
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #include "AArch64.h"
17 #include "AArch64TargetMachine.h"
18 #include "MCTargetDesc/AArch64MCTargetDesc.h"
19 #include "llvm/PassManager.h"
20 #include "llvm/CodeGen/Passes.h"
21 #include "llvm/Support/TargetRegistry.h"
22 
23 using namespace llvm;
24 
LLVMInitializeAArch64Target()25 extern "C" void LLVMInitializeAArch64Target() {
26   RegisterTargetMachine<AArch64TargetMachine> X(TheAArch64Target);
27 }
28 
AArch64TargetMachine(const Target & T,StringRef TT,StringRef CPU,StringRef FS,const TargetOptions & Options,Reloc::Model RM,CodeModel::Model CM,CodeGenOpt::Level OL)29 AArch64TargetMachine::AArch64TargetMachine(const Target &T, StringRef TT,
30                                            StringRef CPU, StringRef FS,
31                                            const TargetOptions &Options,
32                                            Reloc::Model RM, CodeModel::Model CM,
33                                            CodeGenOpt::Level OL)
34   : LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL),
35     Subtarget(TT, CPU, FS),
36     InstrInfo(Subtarget),
37     DL("e-p:64:64-i64:64:64-i128:128:128-s0:32:32-f128:128:128-n32:64-S128"),
38     TLInfo(*this),
39     TSInfo(*this),
40     FrameLowering(Subtarget) {
41 }
42 
43 namespace {
44 /// AArch64 Code Generator Pass Configuration Options.
45 class AArch64PassConfig : public TargetPassConfig {
46 public:
AArch64PassConfig(AArch64TargetMachine * TM,PassManagerBase & PM)47   AArch64PassConfig(AArch64TargetMachine *TM, PassManagerBase &PM)
48     : TargetPassConfig(TM, PM) {}
49 
getAArch64TargetMachine() const50   AArch64TargetMachine &getAArch64TargetMachine() const {
51     return getTM<AArch64TargetMachine>();
52   }
53 
getAArch64Subtarget() const54   const AArch64Subtarget &getAArch64Subtarget() const {
55     return *getAArch64TargetMachine().getSubtargetImpl();
56   }
57 
58   virtual bool addInstSelector();
59   virtual bool addPreEmitPass();
60 };
61 } // namespace
62 
createPassConfig(PassManagerBase & PM)63 TargetPassConfig *AArch64TargetMachine::createPassConfig(PassManagerBase &PM) {
64   return new AArch64PassConfig(this, PM);
65 }
66 
addPreEmitPass()67 bool AArch64PassConfig::addPreEmitPass() {
68   addPass(&UnpackMachineBundlesID);
69   addPass(createAArch64BranchFixupPass());
70   return true;
71 }
72 
addInstSelector()73 bool AArch64PassConfig::addInstSelector() {
74   addPass(createAArch64ISelDAG(getAArch64TargetMachine(), getOptLevel()));
75 
76   // For ELF, cleanup any local-dynamic TLS accesses.
77   if (getAArch64Subtarget().isTargetELF() && getOptLevel() != CodeGenOpt::None)
78     addPass(createAArch64CleanupLocalDynamicTLSPass());
79 
80   return false;
81 }
82