Chris Lattner | 02a3d83 | 2002-10-29 22:37:54 +0000 | [diff] [blame] | 1 | //===-- X86TargetMachine.cpp - Define TargetMachine for the X86 -----------===// |
Misha Brukman | c88330a | 2005-04-21 23:38:14 +0000 | [diff] [blame] | 2 | // |
John Criswell | 482202a | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | f3ebc3f | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Misha Brukman | c88330a | 2005-04-21 23:38:14 +0000 | [diff] [blame] | 7 | // |
John Criswell | 482202a | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Misha Brukman | c88330a | 2005-04-21 23:38:14 +0000 | [diff] [blame] | 9 | // |
Chris Lattner | 02a3d83 | 2002-10-29 22:37:54 +0000 | [diff] [blame] | 10 | // This file defines the X86 specific subclass of TargetMachine. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
David Blaikie | b3bde2e | 2017-11-17 01:07:10 +0000 | [diff] [blame] | 14 | #include "X86TargetMachine.h" |
Eugene Zelenko | fbd13c5 | 2017-02-02 22:55:55 +0000 | [diff] [blame] | 15 | #include "MCTargetDesc/X86MCTargetDesc.h" |
Chris Lattner | a32b405 | 2002-12-24 00:04:01 +0000 | [diff] [blame] | 16 | #include "X86.h" |
Zvi Rackover | 76dbf26 | 2016-11-15 06:34:33 +0000 | [diff] [blame] | 17 | #include "X86CallLowering.h" |
Igor Breger | b4442f3 | 2017-02-10 07:05:56 +0000 | [diff] [blame] | 18 | #include "X86LegalizerInfo.h" |
Evandro Menezes | 94edf02 | 2017-02-01 02:54:34 +0000 | [diff] [blame] | 19 | #include "X86MacroFusion.h" |
Eugene Zelenko | fbd13c5 | 2017-02-02 22:55:55 +0000 | [diff] [blame] | 20 | #include "X86Subtarget.h" |
Aditya Nandakumar | a271932 | 2014-11-13 09:26:31 +0000 | [diff] [blame] | 21 | #include "X86TargetObjectFile.h" |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 22 | #include "X86TargetTransformInfo.h" |
Eugene Zelenko | fbd13c5 | 2017-02-02 22:55:55 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/Optional.h" |
Eugene Zelenko | fbd13c5 | 2017-02-02 22:55:55 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/STLExtras.h" |
Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/SmallString.h" |
Eugene Zelenko | fbd13c5 | 2017-02-02 22:55:55 +0000 | [diff] [blame] | 26 | #include "llvm/ADT/StringRef.h" |
| 27 | #include "llvm/ADT/Triple.h" |
| 28 | #include "llvm/Analysis/TargetTransformInfo.h" |
Marina Yatsina | 3d8efa4 | 2018-01-22 10:06:33 +0000 | [diff] [blame] | 29 | #include "llvm/CodeGen/ExecutionDomainFix.h" |
Eugene Zelenko | fbd13c5 | 2017-02-02 22:55:55 +0000 | [diff] [blame] | 30 | #include "llvm/CodeGen/GlobalISel/CallLowering.h" |
Zvi Rackover | 76dbf26 | 2016-11-15 06:34:33 +0000 | [diff] [blame] | 31 | #include "llvm/CodeGen/GlobalISel/IRTranslator.h" |
Matthias Braun | e6ff30b | 2017-03-18 05:08:58 +0000 | [diff] [blame] | 32 | #include "llvm/CodeGen/GlobalISel/InstructionSelect.h" |
Igor Breger | b4442f3 | 2017-02-10 07:05:56 +0000 | [diff] [blame] | 33 | #include "llvm/CodeGen/GlobalISel/Legalizer.h" |
| 34 | #include "llvm/CodeGen/GlobalISel/RegBankSelect.h" |
Matthias Braun | 115efcd | 2016-11-28 20:11:54 +0000 | [diff] [blame] | 35 | #include "llvm/CodeGen/MachineScheduler.h" |
Chris Lattner | 962d5be | 2003-01-13 00:51:23 +0000 | [diff] [blame] | 36 | #include "llvm/CodeGen/Passes.h" |
Matthias Braun | 31d19d4 | 2016-05-10 03:21:59 +0000 | [diff] [blame] | 37 | #include "llvm/CodeGen/TargetPassConfig.h" |
Eugene Zelenko | fbd13c5 | 2017-02-02 22:55:55 +0000 | [diff] [blame] | 38 | #include "llvm/IR/Attributes.h" |
| 39 | #include "llvm/IR/DataLayout.h" |
Eric Christopher | 3faf2f1 | 2014-10-06 06:45:36 +0000 | [diff] [blame] | 40 | #include "llvm/IR/Function.h" |
Eugene Zelenko | fbd13c5 | 2017-02-02 22:55:55 +0000 | [diff] [blame] | 41 | #include "llvm/Pass.h" |
| 42 | #include "llvm/Support/CodeGen.h" |
Bruno Cardoso Lopes | 2a3ffb5 | 2011-08-23 01:14:17 +0000 | [diff] [blame] | 43 | #include "llvm/Support/CommandLine.h" |
Eugene Zelenko | fbd13c5 | 2017-02-02 22:55:55 +0000 | [diff] [blame] | 44 | #include "llvm/Support/ErrorHandling.h" |
Evan Cheng | 2bb4035 | 2011-08-24 18:08:43 +0000 | [diff] [blame] | 45 | #include "llvm/Support/TargetRegistry.h" |
David Blaikie | 6054e65 | 2018-03-23 23:58:19 +0000 | [diff] [blame] | 46 | #include "llvm/Target/TargetLoweringObjectFile.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 47 | #include "llvm/Target/TargetOptions.h" |
Eugene Zelenko | fbd13c5 | 2017-02-02 22:55:55 +0000 | [diff] [blame] | 48 | #include <memory> |
| 49 | #include <string> |
| 50 | |
Chris Lattner | 833c3c2 | 2003-12-20 01:22:19 +0000 | [diff] [blame] | 51 | using namespace llvm; |
Brian Gaeke | 960707c | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 52 | |
Sanjay Patel | 08829ba | 2015-06-10 20:32:21 +0000 | [diff] [blame] | 53 | static cl::opt<bool> EnableMachineCombinerPass("x86-machine-combiner", |
| 54 | cl::desc("Enable the machine combiner pass"), |
| 55 | cl::init(true), cl::Hidden); |
| 56 | |
David Majnemer | 0ad363e | 2015-08-18 19:07:12 +0000 | [diff] [blame] | 57 | namespace llvm { |
Eugene Zelenko | fbd13c5 | 2017-02-02 22:55:55 +0000 | [diff] [blame] | 58 | |
David Majnemer | 0ad363e | 2015-08-18 19:07:12 +0000 | [diff] [blame] | 59 | void initializeWinEHStatePassPass(PassRegistry &); |
Lama Saba | 2ea271b | 2017-05-18 08:11:50 +0000 | [diff] [blame] | 60 | void initializeFixupLEAPassPass(PassRegistry &); |
Vlad Tsyrklevich | e344601 | 2018-04-04 01:21:16 +0000 | [diff] [blame] | 61 | void initializeShadowCallStackPass(PassRegistry &); |
Zvi Rackover | c6d0b6c | 2017-10-24 05:47:07 +0000 | [diff] [blame] | 62 | void initializeX86CallFrameOptimizationPass(PassRegistry &); |
Amjad Aboud | 8ef85a0 | 2017-10-02 21:46:37 +0000 | [diff] [blame] | 63 | void initializeX86CmovConverterPassPass(PassRegistry &); |
Marina Yatsina | 6fc2aaa | 2018-01-22 10:05:23 +0000 | [diff] [blame] | 64 | void initializeX86ExecutionDomainFixPass(PassRegistry &); |
Guy Blank | 92d5ce3 | 2017-10-22 11:43:08 +0000 | [diff] [blame] | 65 | void initializeX86DomainReassignmentPass(PassRegistry &); |
Lama Saba | 9274683 | 2018-04-02 13:48:28 +0000 | [diff] [blame] | 66 | void initializeX86AvoidSFBPassPass(PassRegistry &); |
Chandler Carruth | 19618fc | 2018-04-10 01:41:17 +0000 | [diff] [blame] | 67 | void initializeX86FlagsCopyLoweringPassPass(PassRegistry &); |
Eugene Zelenko | fbd13c5 | 2017-02-02 22:55:55 +0000 | [diff] [blame] | 68 | |
| 69 | } // end namespace llvm |
David Majnemer | 0ad363e | 2015-08-18 19:07:12 +0000 | [diff] [blame] | 70 | |
NAKAMURA Takumi | 0544fe7 | 2011-02-17 12:23:50 +0000 | [diff] [blame] | 71 | extern "C" void LLVMInitializeX86Target() { |
Daniel Dunbar | 5680b4f | 2009-07-25 06:49:55 +0000 | [diff] [blame] | 72 | // Register the target. |
Mehdi Amini | f42454b | 2016-10-09 23:00:34 +0000 | [diff] [blame] | 73 | RegisterTargetMachine<X86TargetMachine> X(getTheX86_32Target()); |
| 74 | RegisterTargetMachine<X86TargetMachine> Y(getTheX86_64Target()); |
David Majnemer | 0ad363e | 2015-08-18 19:07:12 +0000 | [diff] [blame] | 75 | |
| 76 | PassRegistry &PR = *PassRegistry::getPassRegistry(); |
Zvi Rackover | 76dbf26 | 2016-11-15 06:34:33 +0000 | [diff] [blame] | 77 | initializeGlobalISel(PR); |
David Majnemer | 0ad363e | 2015-08-18 19:07:12 +0000 | [diff] [blame] | 78 | initializeWinEHStatePassPass(PR); |
Ahmed Bougacha | 068ac4a | 2016-05-07 01:11:10 +0000 | [diff] [blame] | 79 | initializeFixupBWInstPassPass(PR); |
Gadi Haber | 19c4fc5 | 2016-12-28 10:12:48 +0000 | [diff] [blame] | 80 | initializeEvexToVexInstPassPass(PR); |
Lama Saba | 2ea271b | 2017-05-18 08:11:50 +0000 | [diff] [blame] | 81 | initializeFixupLEAPassPass(PR); |
Vlad Tsyrklevich | e344601 | 2018-04-04 01:21:16 +0000 | [diff] [blame] | 82 | initializeShadowCallStackPass(PR); |
Zvi Rackover | c6d0b6c | 2017-10-24 05:47:07 +0000 | [diff] [blame] | 83 | initializeX86CallFrameOptimizationPass(PR); |
Amjad Aboud | 8ef85a0 | 2017-10-02 21:46:37 +0000 | [diff] [blame] | 84 | initializeX86CmovConverterPassPass(PR); |
Marina Yatsina | 6fc2aaa | 2018-01-22 10:05:23 +0000 | [diff] [blame] | 85 | initializeX86ExecutionDomainFixPass(PR); |
Guy Blank | 92d5ce3 | 2017-10-22 11:43:08 +0000 | [diff] [blame] | 86 | initializeX86DomainReassignmentPass(PR); |
Lama Saba | 9274683 | 2018-04-02 13:48:28 +0000 | [diff] [blame] | 87 | initializeX86AvoidSFBPassPass(PR); |
Chandler Carruth | 19618fc | 2018-04-10 01:41:17 +0000 | [diff] [blame] | 88 | initializeX86FlagsCopyLoweringPassPass(PR); |
Daniel Dunbar | e833810 | 2009-07-15 20:24:03 +0000 | [diff] [blame] | 89 | } |
Douglas Gregor | 1b731d5 | 2009-06-16 20:12:29 +0000 | [diff] [blame] | 90 | |
Aditya Nandakumar | a271932 | 2014-11-13 09:26:31 +0000 | [diff] [blame] | 91 | static std::unique_ptr<TargetLoweringObjectFile> createTLOF(const Triple &TT) { |
| 92 | if (TT.isOSBinFormatMachO()) { |
| 93 | if (TT.getArch() == Triple::x86_64) |
Eugene Zelenko | fbd13c5 | 2017-02-02 22:55:55 +0000 | [diff] [blame] | 94 | return llvm::make_unique<X86_64MachoTargetObjectFile>(); |
| 95 | return llvm::make_unique<TargetLoweringObjectFileMachO>(); |
Aditya Nandakumar | a271932 | 2014-11-13 09:26:31 +0000 | [diff] [blame] | 96 | } |
| 97 | |
Davide Italiano | a9f85d6 | 2016-09-26 22:53:15 +0000 | [diff] [blame] | 98 | if (TT.isOSFreeBSD()) |
Eugene Zelenko | fbd13c5 | 2017-02-02 22:55:55 +0000 | [diff] [blame] | 99 | return llvm::make_unique<X86FreeBSDTargetObjectFile>(); |
Nikolai Bozhenov | b7bf386 | 2017-05-09 10:14:03 +0000 | [diff] [blame] | 100 | if (TT.isOSLinux() || TT.isOSNaCl() || TT.isOSIAMCU()) |
Eugene Zelenko | fbd13c5 | 2017-02-02 22:55:55 +0000 | [diff] [blame] | 101 | return llvm::make_unique<X86LinuxNaClTargetObjectFile>(); |
Davide Italiano | 9b8e3d3 | 2017-06-21 20:36:32 +0000 | [diff] [blame] | 102 | if (TT.isOSSolaris()) |
| 103 | return llvm::make_unique<X86SolarisTargetObjectFile>(); |
Petr Hosek | e023d62 | 2016-10-06 05:17:26 +0000 | [diff] [blame] | 104 | if (TT.isOSFuchsia()) |
Eugene Zelenko | fbd13c5 | 2017-02-02 22:55:55 +0000 | [diff] [blame] | 105 | return llvm::make_unique<X86FuchsiaTargetObjectFile>(); |
Aditya Nandakumar | a271932 | 2014-11-13 09:26:31 +0000 | [diff] [blame] | 106 | if (TT.isOSBinFormatELF()) |
Eugene Zelenko | fbd13c5 | 2017-02-02 22:55:55 +0000 | [diff] [blame] | 107 | return llvm::make_unique<X86ELFTargetObjectFile>(); |
Pat Gavlin | b399095 | 2015-08-14 22:41:43 +0000 | [diff] [blame] | 108 | if (TT.isKnownWindowsMSVCEnvironment() || TT.isWindowsCoreCLREnvironment()) |
Eugene Zelenko | fbd13c5 | 2017-02-02 22:55:55 +0000 | [diff] [blame] | 109 | return llvm::make_unique<X86WindowsTargetObjectFile>(); |
Aditya Nandakumar | a271932 | 2014-11-13 09:26:31 +0000 | [diff] [blame] | 110 | if (TT.isOSBinFormatCOFF()) |
Eugene Zelenko | fbd13c5 | 2017-02-02 22:55:55 +0000 | [diff] [blame] | 111 | return llvm::make_unique<TargetLoweringObjectFileCOFF>(); |
Aditya Nandakumar | a271932 | 2014-11-13 09:26:31 +0000 | [diff] [blame] | 112 | llvm_unreachable("unknown subtarget type"); |
| 113 | } |
| 114 | |
Eric Christopher | 8b77065 | 2015-01-26 19:03:15 +0000 | [diff] [blame] | 115 | static std::string computeDataLayout(const Triple &TT) { |
| 116 | // X86 is little endian |
| 117 | std::string Ret = "e"; |
| 118 | |
| 119 | Ret += DataLayout::getManglingComponent(TT); |
| 120 | // X86 and x32 have 32 bit pointers. |
| 121 | if ((TT.isArch64Bit() && |
| 122 | (TT.getEnvironment() == Triple::GNUX32 || TT.isOSNaCl())) || |
| 123 | !TT.isArch64Bit()) |
| 124 | Ret += "-p:32:32"; |
| 125 | |
| 126 | // Some ABIs align 64 bit integers and doubles to 64 bits, others to 32. |
| 127 | if (TT.isArch64Bit() || TT.isOSWindows() || TT.isOSNaCl()) |
| 128 | Ret += "-i64:64"; |
Andrey Turetskiy | 2396c38 | 2016-02-10 11:57:06 +0000 | [diff] [blame] | 129 | else if (TT.isOSIAMCU()) |
| 130 | Ret += "-i64:32-f64:32"; |
Eric Christopher | 8b77065 | 2015-01-26 19:03:15 +0000 | [diff] [blame] | 131 | else |
| 132 | Ret += "-f64:32:64"; |
| 133 | |
| 134 | // Some ABIs align long double to 128 bits, others to 32. |
Andrey Turetskiy | 2396c38 | 2016-02-10 11:57:06 +0000 | [diff] [blame] | 135 | if (TT.isOSNaCl() || TT.isOSIAMCU()) |
Eric Christopher | 8b77065 | 2015-01-26 19:03:15 +0000 | [diff] [blame] | 136 | ; // No f80 |
| 137 | else if (TT.isArch64Bit() || TT.isOSDarwin()) |
| 138 | Ret += "-f80:128"; |
| 139 | else |
| 140 | Ret += "-f80:32"; |
| 141 | |
Andrey Turetskiy | 2396c38 | 2016-02-10 11:57:06 +0000 | [diff] [blame] | 142 | if (TT.isOSIAMCU()) |
| 143 | Ret += "-f128:32"; |
| 144 | |
Eric Christopher | 8b77065 | 2015-01-26 19:03:15 +0000 | [diff] [blame] | 145 | // The registers can hold 8, 16, 32 or, in x86-64, 64 bits. |
| 146 | if (TT.isArch64Bit()) |
| 147 | Ret += "-n8:16:32:64"; |
| 148 | else |
| 149 | Ret += "-n8:16:32"; |
| 150 | |
| 151 | // The stack is aligned to 32 bits on some ABIs and 128 bits on others. |
Andrey Turetskiy | 2396c38 | 2016-02-10 11:57:06 +0000 | [diff] [blame] | 152 | if ((!TT.isArch64Bit() && TT.isOSWindows()) || TT.isOSIAMCU()) |
Reid Kleckner | 60d5232 | 2015-04-30 22:11:59 +0000 | [diff] [blame] | 153 | Ret += "-a:0:32-S32"; |
Eric Christopher | 8b77065 | 2015-01-26 19:03:15 +0000 | [diff] [blame] | 154 | else |
| 155 | Ret += "-S128"; |
| 156 | |
| 157 | return Ret; |
| 158 | } |
| 159 | |
Rafael Espindola | 8c34dd8 | 2016-05-18 22:04:49 +0000 | [diff] [blame] | 160 | static Reloc::Model getEffectiveRelocModel(const Triple &TT, |
| 161 | Optional<Reloc::Model> RM) { |
| 162 | bool is64Bit = TT.getArch() == Triple::x86_64; |
| 163 | if (!RM.hasValue()) { |
| 164 | // Darwin defaults to PIC in 64 bit mode and dynamic-no-pic in 32 bit mode. |
| 165 | // Win64 requires rip-rel addressing, thus we force it to PIC. Otherwise we |
| 166 | // use static relocation model by default. |
| 167 | if (TT.isOSDarwin()) { |
| 168 | if (is64Bit) |
| 169 | return Reloc::PIC_; |
| 170 | return Reloc::DynamicNoPIC; |
| 171 | } |
| 172 | if (TT.isOSWindows() && is64Bit) |
| 173 | return Reloc::PIC_; |
| 174 | return Reloc::Static; |
| 175 | } |
| 176 | |
| 177 | // ELF and X86-64 don't have a distinct DynamicNoPIC model. DynamicNoPIC |
| 178 | // is defined as a model for code which may be used in static or dynamic |
| 179 | // executables but not necessarily a shared library. On X86-32 we just |
| 180 | // compile in -static mode, in x86-64 we use PIC. |
| 181 | if (*RM == Reloc::DynamicNoPIC) { |
| 182 | if (is64Bit) |
| 183 | return Reloc::PIC_; |
| 184 | if (!TT.isOSDarwin()) |
| 185 | return Reloc::Static; |
| 186 | } |
| 187 | |
| 188 | // If we are on Darwin, disallow static relocation model in X86-64 mode, since |
| 189 | // the Mach-O file format doesn't support it. |
| 190 | if (*RM == Reloc::Static && TT.isOSDarwin() && is64Bit) |
| 191 | return Reloc::PIC_; |
| 192 | |
| 193 | return *RM; |
| 194 | } |
| 195 | |
Rafael Espindola | 79e238a | 2017-08-03 02:16:21 +0000 | [diff] [blame] | 196 | static CodeModel::Model getEffectiveCodeModel(Optional<CodeModel::Model> CM, |
| 197 | bool JIT, bool Is64Bit) { |
| 198 | if (CM) |
| 199 | return *CM; |
| 200 | if (JIT) |
| 201 | return Is64Bit ? CodeModel::Large : CodeModel::Small; |
| 202 | return CodeModel::Small; |
| 203 | } |
| 204 | |
Rafael Espindola | 38af4d6 | 2016-05-18 16:00:24 +0000 | [diff] [blame] | 205 | /// Create an X86 target. |
Chris Lattner | 02a3d83 | 2002-10-29 22:37:54 +0000 | [diff] [blame] | 206 | /// |
Daniel Sanders | 3e5de88 | 2015-06-11 19:41:26 +0000 | [diff] [blame] | 207 | X86TargetMachine::X86TargetMachine(const Target &T, const Triple &TT, |
| 208 | StringRef CPU, StringRef FS, |
| 209 | const TargetOptions &Options, |
Rafael Espindola | 8c34dd8 | 2016-05-18 22:04:49 +0000 | [diff] [blame] | 210 | Optional<Reloc::Model> RM, |
Rafael Espindola | 79e238a | 2017-08-03 02:16:21 +0000 | [diff] [blame] | 211 | Optional<CodeModel::Model> CM, |
| 212 | CodeGenOpt::Level OL, bool JIT) |
Matthias Braun | bb8507e | 2017-10-12 22:57:28 +0000 | [diff] [blame] | 213 | : LLVMTargetMachine( |
Rafael Espindola | 79e238a | 2017-08-03 02:16:21 +0000 | [diff] [blame] | 214 | T, computeDataLayout(TT), TT, CPU, FS, Options, |
| 215 | getEffectiveRelocModel(TT, RM), |
| 216 | getEffectiveCodeModel(CM, JIT, TT.getArch() == Triple::x86_64), OL), |
Eric Christopher | 5653e5d | 2016-09-20 22:19:33 +0000 | [diff] [blame] | 217 | TLOF(createTLOF(getTargetTriple())) { |
Reid Kleckner | ae44e87 | 2015-10-09 01:13:17 +0000 | [diff] [blame] | 218 | // Windows stack unwinder gets confused when execution flow "falls through" |
| 219 | // after a call to 'noreturn' function. |
| 220 | // To prevent that, we emit a trap for 'unreachable' IR instructions. |
| 221 | // (which on X86, happens to be the 'ud2' instruction) |
Paul Robinson | f81836b | 2016-03-24 00:10:03 +0000 | [diff] [blame] | 222 | // On PS4, the "return address" of a 'noreturn' call must still be within |
| 223 | // the calling function, and TrapUnreachable is an easy way to get that. |
Eric Christopher | ef579d2 | 2016-09-20 16:04:59 +0000 | [diff] [blame] | 224 | // The check here for 64-bit windows is a bit icky, but as we're unlikely |
| 225 | // to ever want to mix 32 and 64-bit windows code in a single module |
| 226 | // this should be fine. |
Tim Northover | 271d3d2 | 2018-04-13 22:25:20 +0000 | [diff] [blame] | 227 | if ((TT.isOSWindows() && TT.getArch() == Triple::x86_64) || TT.isPS4() || |
| 228 | TT.isOSBinFormatMachO()) |
Reid Kleckner | ae44e87 | 2015-10-09 01:13:17 +0000 | [diff] [blame] | 229 | this->Options.TrapUnreachable = true; |
| 230 | |
David Woodhouse | 1c3996a | 2014-01-08 00:08:50 +0000 | [diff] [blame] | 231 | initAsmInfo(); |
Chris Lattner | a1d312c | 2006-02-03 18:59:39 +0000 | [diff] [blame] | 232 | } |
Chris Lattner | 02a3d83 | 2002-10-29 22:37:54 +0000 | [diff] [blame] | 233 | |
Eugene Zelenko | fbd13c5 | 2017-02-02 22:55:55 +0000 | [diff] [blame] | 234 | X86TargetMachine::~X86TargetMachine() = default; |
Reid Kleckner | 357600e | 2014-11-20 23:37:18 +0000 | [diff] [blame] | 235 | |
Eric Christopher | 3faf2f1 | 2014-10-06 06:45:36 +0000 | [diff] [blame] | 236 | const X86Subtarget * |
| 237 | X86TargetMachine::getSubtargetImpl(const Function &F) const { |
Duncan P. N. Exon Smith | 5975a70 | 2015-02-14 01:59:52 +0000 | [diff] [blame] | 238 | Attribute CPUAttr = F.getFnAttribute("target-cpu"); |
| 239 | Attribute FSAttr = F.getFnAttribute("target-features"); |
Eric Christopher | 3faf2f1 | 2014-10-06 06:45:36 +0000 | [diff] [blame] | 240 | |
David Majnemer | 498f2fd | 2016-05-20 20:41:24 +0000 | [diff] [blame] | 241 | StringRef CPU = !CPUAttr.hasAttribute(Attribute::None) |
| 242 | ? CPUAttr.getValueAsString() |
| 243 | : (StringRef)TargetCPU; |
| 244 | StringRef FS = !FSAttr.hasAttribute(Attribute::None) |
| 245 | ? FSAttr.getValueAsString() |
| 246 | : (StringRef)TargetFS; |
| 247 | |
| 248 | SmallString<512> Key; |
| 249 | Key.reserve(CPU.size() + FS.size()); |
| 250 | Key += CPU; |
| 251 | Key += FS; |
Eric Christopher | 3faf2f1 | 2014-10-06 06:45:36 +0000 | [diff] [blame] | 252 | |
| 253 | // FIXME: This is related to the code below to reset the target options, |
| 254 | // we need to know whether or not the soft float flag is set on the |
| 255 | // function before we can generate a subtarget. We also need to use |
| 256 | // it as a key for the subtarget since that can be the only difference |
| 257 | // between two functions. |
Eric Christopher | 824f42f | 2015-05-12 01:26:05 +0000 | [diff] [blame] | 258 | bool SoftFloat = |
Eric Christopher | 824f42f | 2015-05-12 01:26:05 +0000 | [diff] [blame] | 259 | F.getFnAttribute("use-soft-float").getValueAsString() == "true"; |
| 260 | // If the soft float attribute is set on the function turn on the soft float |
| 261 | // subtarget feature. |
| 262 | if (SoftFloat) |
David Majnemer | 498f2fd | 2016-05-20 20:41:24 +0000 | [diff] [blame] | 263 | Key += FS.empty() ? "+soft-float" : ",+soft-float"; |
Eric Christopher | 3faf2f1 | 2014-10-06 06:45:36 +0000 | [diff] [blame] | 264 | |
Craig Topper | 0d797a3 | 2018-01-20 00:26:08 +0000 | [diff] [blame] | 265 | // Keep track of the key width after all features are added so we can extract |
| 266 | // the feature string out later. |
| 267 | unsigned CPUFSWidth = Key.size(); |
| 268 | |
Craig Topper | 24d3b28 | 2018-02-11 08:06:27 +0000 | [diff] [blame] | 269 | // Extract prefer-vector-width attribute. |
Craig Topper | 0d797a3 | 2018-01-20 00:26:08 +0000 | [diff] [blame] | 270 | unsigned PreferVectorWidthOverride = 0; |
| 271 | if (F.hasFnAttribute("prefer-vector-width")) { |
| 272 | StringRef Val = F.getFnAttribute("prefer-vector-width").getValueAsString(); |
| 273 | unsigned Width; |
| 274 | if (!Val.getAsInteger(0, Width)) { |
| 275 | Key += ",prefer-vector-width="; |
| 276 | Key += Val; |
| 277 | PreferVectorWidthOverride = Width; |
| 278 | } |
| 279 | } |
| 280 | |
Craig Topper | 24d3b28 | 2018-02-11 08:06:27 +0000 | [diff] [blame] | 281 | // Extract required-vector-width attribute. |
| 282 | unsigned RequiredVectorWidth = UINT32_MAX; |
| 283 | if (F.hasFnAttribute("required-vector-width")) { |
| 284 | StringRef Val = F.getFnAttribute("required-vector-width").getValueAsString(); |
| 285 | unsigned Width; |
| 286 | if (!Val.getAsInteger(0, Width)) { |
| 287 | Key += ",required-vector-width="; |
| 288 | Key += Val; |
| 289 | RequiredVectorWidth = Width; |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | // Extracted here so that we make sure there is backing for the StringRef. If |
| 294 | // we assigned earlier, its possible the SmallString reallocated leaving a |
| 295 | // dangling StringRef. |
Craig Topper | 0d797a3 | 2018-01-20 00:26:08 +0000 | [diff] [blame] | 296 | FS = Key.slice(CPU.size(), CPUFSWidth); |
David Majnemer | ca29023 | 2016-05-20 18:16:06 +0000 | [diff] [blame] | 297 | |
| 298 | auto &I = SubtargetMap[Key]; |
Eric Christopher | 3faf2f1 | 2014-10-06 06:45:36 +0000 | [diff] [blame] | 299 | if (!I) { |
| 300 | // This needs to be done before we create a new subtarget since any |
| 301 | // creation will depend on the TM and the code generation flags on the |
| 302 | // function that reside in TargetOptions. |
| 303 | resetTargetOptions(F); |
Daniel Sanders | c81f450 | 2015-06-16 15:44:21 +0000 | [diff] [blame] | 304 | I = llvm::make_unique<X86Subtarget>(TargetTriple, CPU, FS, *this, |
Craig Topper | 0d797a3 | 2018-01-20 00:26:08 +0000 | [diff] [blame] | 305 | Options.StackAlignmentOverride, |
Craig Topper | 24d3b28 | 2018-02-11 08:06:27 +0000 | [diff] [blame] | 306 | PreferVectorWidthOverride, |
| 307 | RequiredVectorWidth); |
Eric Christopher | 3faf2f1 | 2014-10-06 06:45:36 +0000 | [diff] [blame] | 308 | } |
| 309 | return I.get(); |
| 310 | } |
| 311 | |
Chris Lattner | 12e9730 | 2006-09-04 04:14:57 +0000 | [diff] [blame] | 312 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 2a3ffb5 | 2011-08-23 01:14:17 +0000 | [diff] [blame] | 313 | // Command line options for x86 |
| 314 | //===----------------------------------------------------------------------===// |
Benjamin Kramer | 7859d2e | 2011-09-03 03:45:06 +0000 | [diff] [blame] | 315 | static cl::opt<bool> |
Nadav Rotem | 7f27e0b | 2013-10-18 23:38:13 +0000 | [diff] [blame] | 316 | UseVZeroUpper("x86-use-vzeroupper", cl::Hidden, |
Bruno Cardoso Lopes | 2a3ffb5 | 2011-08-23 01:14:17 +0000 | [diff] [blame] | 317 | cl::desc("Minimize AVX to SSE transition penalty"), |
Eli Friedman | 20439a4 | 2011-11-17 00:21:52 +0000 | [diff] [blame] | 318 | cl::init(true)); |
Bruno Cardoso Lopes | 2a3ffb5 | 2011-08-23 01:14:17 +0000 | [diff] [blame] | 319 | |
| 320 | //===----------------------------------------------------------------------===// |
Chandler Carruth | 93dcdc4 | 2015-01-31 11:17:59 +0000 | [diff] [blame] | 321 | // X86 TTI query. |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 322 | //===----------------------------------------------------------------------===// |
| 323 | |
Sanjoy Das | 26d11ca | 2017-12-22 18:21:59 +0000 | [diff] [blame] | 324 | TargetTransformInfo |
| 325 | X86TargetMachine::getTargetTransformInfo(const Function &F) { |
| 326 | return TargetTransformInfo(X86TTIImpl(this, F)); |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 327 | } |
| 328 | |
Chandler Carruth | 664e354 | 2013-01-07 01:37:14 +0000 | [diff] [blame] | 329 | //===----------------------------------------------------------------------===// |
Chris Lattner | 12e9730 | 2006-09-04 04:14:57 +0000 | [diff] [blame] | 330 | // Pass Pipeline Configuration |
| 331 | //===----------------------------------------------------------------------===// |
Chris Lattner | 1d6ba3e | 2003-08-05 16:34:44 +0000 | [diff] [blame] | 332 | |
Andrew Trick | ccb6736 | 2012-02-03 05:12:41 +0000 | [diff] [blame] | 333 | namespace { |
Eugene Zelenko | fbd13c5 | 2017-02-02 22:55:55 +0000 | [diff] [blame] | 334 | |
Andrew Trick | ccb6736 | 2012-02-03 05:12:41 +0000 | [diff] [blame] | 335 | /// X86 Code Generator Pass Configuration Options. |
| 336 | class X86PassConfig : public TargetPassConfig { |
| 337 | public: |
Matthias Braun | 5e394c3 | 2017-05-30 21:36:41 +0000 | [diff] [blame] | 338 | X86PassConfig(X86TargetMachine &TM, PassManagerBase &PM) |
Andrew Trick | f8ea108 | 2012-02-04 02:56:59 +0000 | [diff] [blame] | 339 | : TargetPassConfig(TM, PM) {} |
Andrew Trick | ccb6736 | 2012-02-03 05:12:41 +0000 | [diff] [blame] | 340 | |
| 341 | X86TargetMachine &getX86TargetMachine() const { |
| 342 | return getTM<X86TargetMachine>(); |
| 343 | } |
| 344 | |
Matthias Braun | 115efcd | 2016-11-28 20:11:54 +0000 | [diff] [blame] | 345 | ScheduleDAGInstrs * |
| 346 | createMachineScheduler(MachineSchedContext *C) const override { |
| 347 | ScheduleDAGMILive *DAG = createGenericSchedLive(C); |
Evandro Menezes | 94edf02 | 2017-02-01 02:54:34 +0000 | [diff] [blame] | 348 | DAG->addMutation(createX86MacroFusionDAGMutation()); |
Matthias Braun | 115efcd | 2016-11-28 20:11:54 +0000 | [diff] [blame] | 349 | return DAG; |
| 350 | } |
| 351 | |
Tim Northover | 277066a | 2014-07-01 18:53:31 +0000 | [diff] [blame] | 352 | void addIRPasses() override; |
Craig Topper | 2d9361e | 2014-03-09 07:44:38 +0000 | [diff] [blame] | 353 | bool addInstSelector() override; |
Zvi Rackover | 76dbf26 | 2016-11-15 06:34:33 +0000 | [diff] [blame] | 354 | bool addIRTranslator() override; |
| 355 | bool addLegalizeMachineIR() override; |
| 356 | bool addRegBankSelect() override; |
| 357 | bool addGlobalInstructionSelect() override; |
Eugene Zelenko | fbd13c5 | 2017-02-02 22:55:55 +0000 | [diff] [blame] | 358 | bool addILPOpts() override; |
Reid Kleckner | 0738a9c | 2015-05-05 17:44:16 +0000 | [diff] [blame] | 359 | bool addPreISel() override; |
Guy Blank | 92d5ce3 | 2017-10-22 11:43:08 +0000 | [diff] [blame] | 360 | void addMachineSSAOptimization() override; |
Michael Kuperstein | 13fbd45 | 2015-02-01 16:56:04 +0000 | [diff] [blame] | 361 | void addPreRegAlloc() override; |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 362 | void addPostRegAlloc() override; |
| 363 | void addPreEmitPass() override; |
Chandler Carruth | c58f216 | 2018-01-22 22:05:25 +0000 | [diff] [blame] | 364 | void addPreEmitPass2() override; |
Quentin Colombet | 494eb60 | 2015-05-22 18:10:47 +0000 | [diff] [blame] | 365 | void addPreSched2() override; |
Andrew Trick | ccb6736 | 2012-02-03 05:12:41 +0000 | [diff] [blame] | 366 | }; |
Eugene Zelenko | fbd13c5 | 2017-02-02 22:55:55 +0000 | [diff] [blame] | 367 | |
Marina Yatsina | 6fc2aaa | 2018-01-22 10:05:23 +0000 | [diff] [blame] | 368 | class X86ExecutionDomainFix : public ExecutionDomainFix { |
Matthias Braun | e6ff30b | 2017-03-18 05:08:58 +0000 | [diff] [blame] | 369 | public: |
| 370 | static char ID; |
Marina Yatsina | 6fc2aaa | 2018-01-22 10:05:23 +0000 | [diff] [blame] | 371 | X86ExecutionDomainFix() : ExecutionDomainFix(ID, X86::VR128XRegClass) {} |
Matthias Braun | e6ff30b | 2017-03-18 05:08:58 +0000 | [diff] [blame] | 372 | StringRef getPassName() const override { |
| 373 | return "X86 Execution Dependency Fix"; |
| 374 | } |
| 375 | }; |
Marina Yatsina | 6fc2aaa | 2018-01-22 10:05:23 +0000 | [diff] [blame] | 376 | char X86ExecutionDomainFix::ID; |
Matthias Braun | e6ff30b | 2017-03-18 05:08:58 +0000 | [diff] [blame] | 377 | |
Eugene Zelenko | fbd13c5 | 2017-02-02 22:55:55 +0000 | [diff] [blame] | 378 | } // end anonymous namespace |
Andrew Trick | ccb6736 | 2012-02-03 05:12:41 +0000 | [diff] [blame] | 379 | |
Marina Yatsina | 6fc2aaa | 2018-01-22 10:05:23 +0000 | [diff] [blame] | 380 | INITIALIZE_PASS_BEGIN(X86ExecutionDomainFix, "x86-execution-domain-fix", |
| 381 | "X86 Execution Domain Fix", false, false) |
| 382 | INITIALIZE_PASS_DEPENDENCY(ReachingDefAnalysis) |
| 383 | INITIALIZE_PASS_END(X86ExecutionDomainFix, "x86-execution-domain-fix", |
| 384 | "X86 Execution Domain Fix", false, false) |
Matthias Braun | e6ff30b | 2017-03-18 05:08:58 +0000 | [diff] [blame] | 385 | |
Andrew Trick | f8ea108 | 2012-02-04 02:56:59 +0000 | [diff] [blame] | 386 | TargetPassConfig *X86TargetMachine::createPassConfig(PassManagerBase &PM) { |
Matthias Braun | 5e394c3 | 2017-05-30 21:36:41 +0000 | [diff] [blame] | 387 | return new X86PassConfig(*this, PM); |
Andrew Trick | ccb6736 | 2012-02-03 05:12:41 +0000 | [diff] [blame] | 388 | } |
| 389 | |
Tim Northover | 277066a | 2014-07-01 18:53:31 +0000 | [diff] [blame] | 390 | void X86PassConfig::addIRPasses() { |
Francis Visoiu Mistrih | 8b61764 | 2017-05-18 17:21:13 +0000 | [diff] [blame] | 391 | addPass(createAtomicExpandPass()); |
Tim Northover | 277066a | 2014-07-01 18:53:31 +0000 | [diff] [blame] | 392 | |
| 393 | TargetPassConfig::addIRPasses(); |
David L Kreitzer | 01a057a | 2016-10-14 18:20:41 +0000 | [diff] [blame] | 394 | |
| 395 | if (TM->getOptLevel() != CodeGenOpt::None) |
Francis Visoiu Mistrih | 8b61764 | 2017-05-18 17:21:13 +0000 | [diff] [blame] | 396 | addPass(createInterleavedAccessPass()); |
Chandler Carruth | c58f216 | 2018-01-22 22:05:25 +0000 | [diff] [blame] | 397 | |
| 398 | // Add passes that handle indirect branch removal and insertion of a retpoline |
| 399 | // thunk. These will be a no-op unless a function subtarget has the retpoline |
| 400 | // feature enabled. |
| 401 | addPass(createIndirectBrExpandPass()); |
Tim Northover | 277066a | 2014-07-01 18:53:31 +0000 | [diff] [blame] | 402 | } |
| 403 | |
Andrew Trick | ccb6736 | 2012-02-03 05:12:41 +0000 | [diff] [blame] | 404 | bool X86PassConfig::addInstSelector() { |
Nate Begeman | be1f314 | 2005-08-18 23:53:15 +0000 | [diff] [blame] | 405 | // Install an instruction selector. |
Bob Wilson | bbd38dd | 2012-07-02 19:48:31 +0000 | [diff] [blame] | 406 | addPass(createX86ISelDag(getX86TargetMachine(), getOptLevel())); |
Dan Gohman | 1914531 | 2008-10-25 17:46:52 +0000 | [diff] [blame] | 407 | |
Hans Wennborg | 789acfb | 2012-06-01 16:27:21 +0000 | [diff] [blame] | 408 | // For ELF, cleanup any local-dynamic TLS accesses. |
Daniel Sanders | c81f450 | 2015-06-16 15:44:21 +0000 | [diff] [blame] | 409 | if (TM->getTargetTriple().isOSBinFormatELF() && |
Eric Christopher | 24f3f65 | 2015-02-05 19:27:04 +0000 | [diff] [blame] | 410 | getOptLevel() != CodeGenOpt::None) |
Bob Wilson | bbd38dd | 2012-07-02 19:48:31 +0000 | [diff] [blame] | 411 | addPass(createCleanupLocalDynamicTLSPass()); |
Hans Wennborg | 789acfb | 2012-06-01 16:27:21 +0000 | [diff] [blame] | 412 | |
Eric Christopher | 0d5c99e | 2014-05-22 01:46:02 +0000 | [diff] [blame] | 413 | addPass(createX86GlobalBaseRegPass()); |
Chris Lattner | 12e9730 | 2006-09-04 04:14:57 +0000 | [diff] [blame] | 414 | return false; |
Brian Gaeke | ac94bab | 2003-06-18 21:43:21 +0000 | [diff] [blame] | 415 | } |
| 416 | |
Zvi Rackover | 76dbf26 | 2016-11-15 06:34:33 +0000 | [diff] [blame] | 417 | bool X86PassConfig::addIRTranslator() { |
| 418 | addPass(new IRTranslator()); |
| 419 | return false; |
| 420 | } |
| 421 | |
| 422 | bool X86PassConfig::addLegalizeMachineIR() { |
Igor Breger | b4442f3 | 2017-02-10 07:05:56 +0000 | [diff] [blame] | 423 | addPass(new Legalizer()); |
Zvi Rackover | 76dbf26 | 2016-11-15 06:34:33 +0000 | [diff] [blame] | 424 | return false; |
| 425 | } |
| 426 | |
| 427 | bool X86PassConfig::addRegBankSelect() { |
Igor Breger | b4442f3 | 2017-02-10 07:05:56 +0000 | [diff] [blame] | 428 | addPass(new RegBankSelect()); |
Zvi Rackover | 76dbf26 | 2016-11-15 06:34:33 +0000 | [diff] [blame] | 429 | return false; |
| 430 | } |
| 431 | |
| 432 | bool X86PassConfig::addGlobalInstructionSelect() { |
Igor Breger | f7359d8 | 2017-02-22 12:25:09 +0000 | [diff] [blame] | 433 | addPass(new InstructionSelect()); |
Zvi Rackover | 76dbf26 | 2016-11-15 06:34:33 +0000 | [diff] [blame] | 434 | return false; |
| 435 | } |
Zvi Rackover | 76dbf26 | 2016-11-15 06:34:33 +0000 | [diff] [blame] | 436 | |
Jakob Stoklund Olesen | 213a2f8 | 2013-01-17 00:58:38 +0000 | [diff] [blame] | 437 | bool X86PassConfig::addILPOpts() { |
Eric Christopher | 6b0fcfe | 2014-05-21 23:40:26 +0000 | [diff] [blame] | 438 | addPass(&EarlyIfConverterID); |
Sanjay Patel | 08829ba | 2015-06-10 20:32:21 +0000 | [diff] [blame] | 439 | if (EnableMachineCombinerPass) |
| 440 | addPass(&MachineCombinerID); |
Amjad Aboud | 4563c06 | 2017-07-16 17:39:56 +0000 | [diff] [blame] | 441 | addPass(createX86CmovConverterPass()); |
Eric Christopher | 6b0fcfe | 2014-05-21 23:40:26 +0000 | [diff] [blame] | 442 | return true; |
Jakob Stoklund Olesen | 213a2f8 | 2013-01-17 00:58:38 +0000 | [diff] [blame] | 443 | } |
| 444 | |
Reid Kleckner | 0738a9c | 2015-05-05 17:44:16 +0000 | [diff] [blame] | 445 | bool X86PassConfig::addPreISel() { |
Reid Kleckner | 5b8ebfb | 2015-05-29 20:43:10 +0000 | [diff] [blame] | 446 | // Only add this pass for 32-bit x86 Windows. |
Daniel Sanders | c81f450 | 2015-06-16 15:44:21 +0000 | [diff] [blame] | 447 | const Triple &TT = TM->getTargetTriple(); |
Reid Kleckner | 5b8ebfb | 2015-05-29 20:43:10 +0000 | [diff] [blame] | 448 | if (TT.isOSWindows() && TT.getArch() == Triple::x86) |
Reid Kleckner | 0738a9c | 2015-05-05 17:44:16 +0000 | [diff] [blame] | 449 | addPass(createX86WinEHStatePass()); |
| 450 | return true; |
| 451 | } |
| 452 | |
Michael Kuperstein | 13fbd45 | 2015-02-01 16:56:04 +0000 | [diff] [blame] | 453 | void X86PassConfig::addPreRegAlloc() { |
Michael Kuperstein | cfbac5f | 2016-07-11 20:40:44 +0000 | [diff] [blame] | 454 | if (getOptLevel() != CodeGenOpt::None) { |
Dehao Chen | 6b737dd | 2017-05-31 23:25:25 +0000 | [diff] [blame] | 455 | addPass(&LiveRangeShrinkID); |
Nico Weber | ead8f8f | 2016-07-14 15:07:44 +0000 | [diff] [blame] | 456 | addPass(createX86FixupSetCC()); |
| 457 | addPass(createX86OptimizeLEAs()); |
Nico Weber | 5bb2842 | 2016-07-14 15:40:22 +0000 | [diff] [blame] | 458 | addPass(createX86CallFrameOptimization()); |
Lama Saba | 9274683 | 2018-04-02 13:48:28 +0000 | [diff] [blame] | 459 | addPass(createX86AvoidStoreForwardingBlocks()); |
Michael Kuperstein | cfbac5f | 2016-07-11 20:40:44 +0000 | [diff] [blame] | 460 | } |
Alexey Bataev | 7cf3247 | 2015-12-04 10:53:15 +0000 | [diff] [blame] | 461 | |
Chandler Carruth | 19618fc | 2018-04-10 01:41:17 +0000 | [diff] [blame] | 462 | addPass(createX86FlagsCopyLoweringPass()); |
Hans Wennborg | 8eb336c | 2016-05-18 16:10:17 +0000 | [diff] [blame] | 463 | addPass(createX86WinAllocaExpander()); |
Michael Kuperstein | 13fbd45 | 2015-02-01 16:56:04 +0000 | [diff] [blame] | 464 | } |
Guy Blank | 92d5ce3 | 2017-10-22 11:43:08 +0000 | [diff] [blame] | 465 | void X86PassConfig::addMachineSSAOptimization() { |
| 466 | addPass(createX86DomainReassignmentPass()); |
| 467 | TargetPassConfig::addMachineSSAOptimization(); |
| 468 | } |
Michael Kuperstein | 13fbd45 | 2015-02-01 16:56:04 +0000 | [diff] [blame] | 469 | |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 470 | void X86PassConfig::addPostRegAlloc() { |
Rafael Espindola | 01c7361 | 2014-12-11 20:03:57 +0000 | [diff] [blame] | 471 | addPass(createX86FloatingPointStackifierPass()); |
Rafael Espindola | 01c7361 | 2014-12-11 20:03:57 +0000 | [diff] [blame] | 472 | } |
Bruno Cardoso Lopes | 2a3ffb5 | 2011-08-23 01:14:17 +0000 | [diff] [blame] | 473 | |
Quentin Colombet | 494eb60 | 2015-05-22 18:10:47 +0000 | [diff] [blame] | 474 | void X86PassConfig::addPreSched2() { addPass(createX86ExpandPseudoPass()); } |
| 475 | |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 476 | void X86PassConfig::addPreEmitPass() { |
Marina Yatsina | 6fc2aaa | 2018-01-22 10:05:23 +0000 | [diff] [blame] | 477 | if (getOptLevel() != CodeGenOpt::None) { |
| 478 | addPass(new X86ExecutionDomainFix()); |
Marina Yatsina | 0bf841a | 2018-01-22 10:06:50 +0000 | [diff] [blame] | 479 | addPass(createBreakFalseDeps()); |
Marina Yatsina | 6fc2aaa | 2018-01-22 10:05:23 +0000 | [diff] [blame] | 480 | } |
Rafael Espindola | 01c7361 | 2014-12-11 20:03:57 +0000 | [diff] [blame] | 481 | |
Vlad Tsyrklevich | e344601 | 2018-04-04 01:21:16 +0000 | [diff] [blame] | 482 | addPass(createShadowCallStackPass()); |
Oren Ben Simhon | 1c6308e | 2018-01-09 08:51:18 +0000 | [diff] [blame] | 483 | addPass(createX86IndirectBranchTrackingPass()); |
| 484 | |
Matthias Braun | 7e37a5f | 2014-12-11 21:26:47 +0000 | [diff] [blame] | 485 | if (UseVZeroUpper) |
Matthias Braun | b2f2388 | 2014-12-11 23:18:03 +0000 | [diff] [blame] | 486 | addPass(createX86IssueVZeroUpperPass()); |
Bruno Cardoso Lopes | 62d7987 | 2011-09-15 18:27:32 +0000 | [diff] [blame] | 487 | |
Eric Christopher | 0d5c99e | 2014-05-22 01:46:02 +0000 | [diff] [blame] | 488 | if (getOptLevel() != CodeGenOpt::None) { |
Kevin B. Smith | 6a83350 | 2016-02-11 19:43:04 +0000 | [diff] [blame] | 489 | addPass(createX86FixupBWInsts()); |
Matthias Braun | b2f2388 | 2014-12-11 23:18:03 +0000 | [diff] [blame] | 490 | addPass(createX86PadShortFunctions()); |
Preston Gurd | 8b7ab4b | 2013-04-25 20:29:37 +0000 | [diff] [blame] | 491 | addPass(createX86FixupLEAs()); |
Gadi Haber | 19c4fc5 | 2016-12-28 10:12:48 +0000 | [diff] [blame] | 492 | addPass(createX86EvexToVexInsts()); |
Preston Gurd | 8b7ab4b | 2013-04-25 20:29:37 +0000 | [diff] [blame] | 493 | } |
Jakob Stoklund Olesen | 49e121d | 2010-03-25 17:25:00 +0000 | [diff] [blame] | 494 | } |
Chandler Carruth | c58f216 | 2018-01-22 22:05:25 +0000 | [diff] [blame] | 495 | |
| 496 | void X86PassConfig::addPreEmitPass2() { |
| 497 | addPass(createX86RetpolineThunksPass()); |
Petar Jovanovic | e2bfcd6 | 2018-04-24 10:32:08 +0000 | [diff] [blame^] | 498 | // Verify basic block incoming and outgoing cfa offset and register values and |
| 499 | // correct CFA calculation rule where needed by inserting appropriate CFI |
| 500 | // instructions. |
| 501 | const Triple &TT = TM->getTargetTriple(); |
| 502 | if (!TT.isOSDarwin() && !TT.isOSWindows()) |
| 503 | addPass(createCFIInstrInserter()); |
Chandler Carruth | c58f216 | 2018-01-22 22:05:25 +0000 | [diff] [blame] | 504 | } |