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 25 extern "C" void LLVMInitializeAArch64Target() { 26 RegisterTargetMachine<AArch64TargetMachine> X(TheAArch64Target); 27 } 28 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 initAsmInfo(); 42 } 43 44 namespace { 45 /// AArch64 Code Generator Pass Configuration Options. 46 class AArch64PassConfig : public TargetPassConfig { 47 public: 48 AArch64PassConfig(AArch64TargetMachine *TM, PassManagerBase &PM) 49 : TargetPassConfig(TM, PM) {} 50 51 AArch64TargetMachine &getAArch64TargetMachine() const { 52 return getTM<AArch64TargetMachine>(); 53 } 54 55 const AArch64Subtarget &getAArch64Subtarget() const { 56 return *getAArch64TargetMachine().getSubtargetImpl(); 57 } 58 59 virtual bool addInstSelector(); 60 virtual bool addPreEmitPass(); 61 }; 62 } // namespace 63 64 TargetPassConfig *AArch64TargetMachine::createPassConfig(PassManagerBase &PM) { 65 return new AArch64PassConfig(this, PM); 66 } 67 68 bool AArch64PassConfig::addPreEmitPass() { 69 addPass(&UnpackMachineBundlesID); 70 addPass(createAArch64BranchFixupPass()); 71 return true; 72 } 73 74 bool AArch64PassConfig::addInstSelector() { 75 addPass(createAArch64ISelDAG(getAArch64TargetMachine(), getOptLevel())); 76 77 // For ELF, cleanup any local-dynamic TLS accesses. 78 if (getAArch64Subtarget().isTargetELF() && getOptLevel() != CodeGenOpt::None) 79 addPass(createAArch64CleanupLocalDynamicTLSPass()); 80 81 return false; 82 } 83