Chris Lattner | 67e0842 | 2003-06-20 15:49:04 +0000 | [diff] [blame] | 1 | //===-- llc.cpp - Implement the LLVM Native Code Generator ----------------===// |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 2 | // |
John Criswell | 09344dc | 2003-10-20 17:47:21 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 345353d | 2007-12-29 20:44:31 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 7 | // |
John Criswell | 09344dc | 2003-10-20 17:47:21 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | 2cf137b | 2001-09-07 22:20:50 +0000 | [diff] [blame] | 9 | // |
Brian Gaeke | 33e83b6 | 2004-03-16 21:47:20 +0000 | [diff] [blame] | 10 | // This is the llc code generator driver. It provides a convenient |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 11 | // command-line interface for generating native assembly-language code |
Gabor Greif | e16561c | 2007-07-05 17:07:56 +0000 | [diff] [blame] | 12 | // or C code, given LLVM bitcode. |
Chris Lattner | 2cf137b | 2001-09-07 22:20:50 +0000 | [diff] [blame] | 13 | // |
Chris Lattner | b27d474 | 2001-10-04 01:40:53 +0000 | [diff] [blame] | 14 | //===----------------------------------------------------------------------===// |
Vikram S. Adve | 2d94a34 | 2001-07-21 12:42:29 +0000 | [diff] [blame] | 15 | |
Owen Anderson | 6773d38 | 2009-07-01 16:58:40 +0000 | [diff] [blame] | 16 | #include "llvm/LLVMContext.h" |
Chris Lattner | ed22606 | 2001-09-07 21:26:31 +0000 | [diff] [blame] | 17 | #include "llvm/Module.h" |
Chris Lattner | 7139f28 | 2002-01-31 00:46:45 +0000 | [diff] [blame] | 18 | #include "llvm/PassManager.h" |
Vikram S. Adve | eb81869 | 2002-09-16 16:35:34 +0000 | [diff] [blame] | 19 | #include "llvm/Pass.h" |
Daniel Dunbar | 0f16ea5 | 2009-08-03 04:03:51 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/Triple.h" |
Bob Wilson | cac3b90 | 2012-07-02 19:48:45 +0000 | [diff] [blame] | 21 | #include "llvm/Assembly/PrintModulePass.h" |
Dan Gohman | c76bfb7 | 2009-09-02 19:35:19 +0000 | [diff] [blame] | 22 | #include "llvm/Support/IRReader.h" |
Daniel Dunbar | 0f16ea5 | 2009-08-03 04:03:51 +0000 | [diff] [blame] | 23 | #include "llvm/CodeGen/LinkAllAsmWriterComponents.h" |
| 24 | #include "llvm/CodeGen/LinkAllCodegenComponents.h" |
Evan Cheng | 8264e27 | 2011-06-29 01:14:12 +0000 | [diff] [blame] | 25 | #include "llvm/MC/SubtargetFeature.h" |
Reid Spencer | 7c16caa | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 26 | #include "llvm/Support/CommandLine.h" |
David Greene | 6e55be6 | 2010-01-05 01:30:21 +0000 | [diff] [blame] | 27 | #include "llvm/Support/Debug.h" |
David Greene | a31f96c | 2009-07-14 20:18:05 +0000 | [diff] [blame] | 28 | #include "llvm/Support/FormattedStream.h" |
Chris Lattner | 76d4632 | 2006-12-06 01:18:01 +0000 | [diff] [blame] | 29 | #include "llvm/Support/ManagedStatic.h" |
Reid Spencer | 7c16caa | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 30 | #include "llvm/Support/PluginLoader.h" |
Chris Lattner | e3fc2d1 | 2009-03-06 05:34:10 +0000 | [diff] [blame] | 31 | #include "llvm/Support/PrettyStackTrace.h" |
Dan Gohman | 0df7ea4 | 2010-10-07 20:32:40 +0000 | [diff] [blame] | 32 | #include "llvm/Support/ToolOutputFile.h" |
Michael J. Spencer | 447762d | 2010-11-29 18:16:10 +0000 | [diff] [blame] | 33 | #include "llvm/Support/Host.h" |
| 34 | #include "llvm/Support/Signals.h" |
Evan Cheng | 2bb4035 | 2011-08-24 18:08:43 +0000 | [diff] [blame] | 35 | #include "llvm/Support/TargetRegistry.h" |
| 36 | #include "llvm/Support/TargetSelect.h" |
Daniel Dunbar | 0f16ea5 | 2009-08-03 04:03:51 +0000 | [diff] [blame] | 37 | #include "llvm/Target/TargetData.h" |
Bob Wilson | fa59485 | 2012-08-03 21:26:18 +0000 | [diff] [blame] | 38 | #include "llvm/Target/TargetLibraryInfo.h" |
Daniel Dunbar | 0f16ea5 | 2009-08-03 04:03:51 +0000 | [diff] [blame] | 39 | #include "llvm/Target/TargetMachine.h" |
Reid Spencer | f0ebb25 | 2004-07-04 12:20:55 +0000 | [diff] [blame] | 40 | #include <memory> |
Brian Gaeke | 960707c | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 41 | using namespace llvm; |
| 42 | |
Vikram S. Adve | eb81869 | 2002-09-16 16:35:34 +0000 | [diff] [blame] | 43 | // General options for llc. Other pass-specific options are specified |
| 44 | // within the corresponding llc passes, and target-specific options |
| 45 | // and back-end code generation options are specified with the target machine. |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 46 | // |
Chris Lattner | d64b2de | 2003-04-25 05:26:11 +0000 | [diff] [blame] | 47 | static cl::opt<std::string> |
Gabor Greif | e16561c | 2007-07-05 17:07:56 +0000 | [diff] [blame] | 48 | InputFilename(cl::Positional, cl::desc("<input bitcode>"), cl::init("-")); |
Chris Lattner | f5cad15 | 2002-07-22 02:10:13 +0000 | [diff] [blame] | 49 | |
Chris Lattner | d64b2de | 2003-04-25 05:26:11 +0000 | [diff] [blame] | 50 | static cl::opt<std::string> |
Chris Lattner | f5cad15 | 2002-07-22 02:10:13 +0000 | [diff] [blame] | 51 | OutputFilename("o", cl::desc("Output filename"), cl::value_desc("filename")); |
| 52 | |
Evan Cheng | 09bd0b1 | 2009-05-04 23:05:19 +0000 | [diff] [blame] | 53 | // Determine optimization level. |
Bill Wendling | 026e5d7 | 2009-04-29 23:29:43 +0000 | [diff] [blame] | 54 | static cl::opt<char> |
Bill Wendling | 084669a | 2009-04-29 00:15:41 +0000 | [diff] [blame] | 55 | OptLevel("O", |
Evan Cheng | 09bd0b1 | 2009-05-04 23:05:19 +0000 | [diff] [blame] | 56 | cl::desc("Optimization level. [-O0, -O1, -O2, or -O3] " |
| 57 | "(default = '-O2')"), |
Bill Wendling | 084669a | 2009-04-29 00:15:41 +0000 | [diff] [blame] | 58 | cl::Prefix, |
| 59 | cl::ZeroOrMore, |
Bill Wendling | 026e5d7 | 2009-04-29 23:29:43 +0000 | [diff] [blame] | 60 | cl::init(' ')); |
Chris Lattner | 731055e | 2005-11-08 02:12:17 +0000 | [diff] [blame] | 61 | |
Chris Lattner | e568b88 | 2005-12-16 04:59:57 +0000 | [diff] [blame] | 62 | static cl::opt<std::string> |
Chris Lattner | 08a04cb | 2005-12-16 05:19:55 +0000 | [diff] [blame] | 63 | TargetTriple("mtriple", cl::desc("Override target triple for module")); |
Chris Lattner | 731055e | 2005-11-08 02:12:17 +0000 | [diff] [blame] | 64 | |
Daniel Dunbar | d370645 | 2009-07-16 02:23:53 +0000 | [diff] [blame] | 65 | static cl::opt<std::string> |
| 66 | MArch("march", cl::desc("Architecture to generate code for (see --version)")); |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 67 | |
Jim Laskey | 19058c3 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 68 | static cl::opt<std::string> |
Mikhail Glushenkov | b2f9a73 | 2009-01-16 06:53:46 +0000 | [diff] [blame] | 69 | MCPU("mcpu", |
Chris Lattner | 0b2bf4c | 2005-10-23 22:35:42 +0000 | [diff] [blame] | 70 | cl::desc("Target a specific cpu type (-mcpu=help for details)"), |
Jim Laskey | 19058c3 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 71 | cl::value_desc("cpu-name"), |
| 72 | cl::init("")); |
| 73 | |
| 74 | static cl::list<std::string> |
Mikhail Glushenkov | b2f9a73 | 2009-01-16 06:53:46 +0000 | [diff] [blame] | 75 | MAttrs("mattr", |
Jim Laskey | 19058c3 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 76 | cl::CommaSeparated, |
Chris Lattner | 0b2bf4c | 2005-10-23 22:35:42 +0000 | [diff] [blame] | 77 | cl::desc("Target specific attributes (-mattr=help for details)"), |
Chris Lattner | 4154848 | 2005-10-23 22:37:13 +0000 | [diff] [blame] | 78 | cl::value_desc("a1,+a2,-a3,...")); |
Jim Laskey | 19058c3 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 79 | |
Evan Cheng | 2129f59 | 2011-07-19 06:37:02 +0000 | [diff] [blame] | 80 | static cl::opt<Reloc::Model> |
| 81 | RelocModel("relocation-model", |
| 82 | cl::desc("Choose relocation model"), |
| 83 | cl::init(Reloc::Default), |
| 84 | cl::values( |
| 85 | clEnumValN(Reloc::Default, "default", |
| 86 | "Target default relocation model"), |
| 87 | clEnumValN(Reloc::Static, "static", |
| 88 | "Non-relocatable code"), |
| 89 | clEnumValN(Reloc::PIC_, "pic", |
| 90 | "Fully relocatable, position independent code"), |
| 91 | clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic", |
| 92 | "Relocatable external references, non-relocatable code"), |
| 93 | clEnumValEnd)); |
| 94 | |
Evan Cheng | efd9b42 | 2011-07-20 07:51:56 +0000 | [diff] [blame] | 95 | static cl::opt<llvm::CodeModel::Model> |
| 96 | CMModel("code-model", |
| 97 | cl::desc("Choose code model"), |
| 98 | cl::init(CodeModel::Default), |
| 99 | cl::values(clEnumValN(CodeModel::Default, "default", |
| 100 | "Target default code model"), |
| 101 | clEnumValN(CodeModel::Small, "small", |
| 102 | "Small code model"), |
| 103 | clEnumValN(CodeModel::Kernel, "kernel", |
| 104 | "Kernel code model"), |
| 105 | clEnumValN(CodeModel::Medium, "medium", |
| 106 | "Medium code model"), |
| 107 | clEnumValN(CodeModel::Large, "large", |
| 108 | "Large code model"), |
| 109 | clEnumValEnd)); |
| 110 | |
Michael J. Spencer | f695f8f | 2010-07-31 19:57:02 +0000 | [diff] [blame] | 111 | static cl::opt<bool> |
Michael J. Spencer | 4f50b97 | 2010-08-06 21:37:45 +0000 | [diff] [blame] | 112 | RelaxAll("mc-relax-all", |
| 113 | cl::desc("When used with filetype=obj, " |
Michael J. Spencer | 4c08958 | 2010-08-08 23:26:49 +0000 | [diff] [blame] | 114 | "relax all fixups in the emitted object file")); |
Michael J. Spencer | f695f8f | 2010-07-31 19:57:02 +0000 | [diff] [blame] | 115 | |
Chris Lattner | 06fcc4c | 2005-06-25 03:32:05 +0000 | [diff] [blame] | 116 | cl::opt<TargetMachine::CodeGenFileType> |
Chris Lattner | f0cb12a | 2010-02-02 21:06:45 +0000 | [diff] [blame] | 117 | FileType("filetype", cl::init(TargetMachine::CGFT_AssemblyFile), |
Chris Lattner | 06fcc4c | 2005-06-25 03:32:05 +0000 | [diff] [blame] | 118 | cl::desc("Choose a file type (not all types are supported by all targets):"), |
| 119 | cl::values( |
Chris Lattner | f0cb12a | 2010-02-02 21:06:45 +0000 | [diff] [blame] | 120 | clEnumValN(TargetMachine::CGFT_AssemblyFile, "asm", |
Dan Gohman | 9c4b7d5 | 2008-10-14 20:25:08 +0000 | [diff] [blame] | 121 | "Emit an assembly ('.s') file"), |
Chris Lattner | f0cb12a | 2010-02-02 21:06:45 +0000 | [diff] [blame] | 122 | clEnumValN(TargetMachine::CGFT_ObjectFile, "obj", |
Benjamin Kramer | 2642615 | 2012-06-11 09:40:10 +0000 | [diff] [blame] | 123 | "Emit a native object ('.o') file"), |
Chris Lattner | edcf065 | 2010-02-03 05:55:08 +0000 | [diff] [blame] | 124 | clEnumValN(TargetMachine::CGFT_Null, "null", |
| 125 | "Emit nothing, for performance testing"), |
Chris Lattner | 06fcc4c | 2005-06-25 03:32:05 +0000 | [diff] [blame] | 126 | clEnumValEnd)); |
| 127 | |
Reid Spencer | 8e3830d | 2005-07-28 02:25:30 +0000 | [diff] [blame] | 128 | cl::opt<bool> NoVerify("disable-verify", cl::Hidden, |
Jeff Cohen | 546fd59 | 2005-07-30 18:33:25 +0000 | [diff] [blame] | 129 | cl::desc("Do not verify input module")); |
Reid Spencer | 8e3830d | 2005-07-28 02:25:30 +0000 | [diff] [blame] | 130 | |
Devang Patel | 85df0cc | 2010-12-01 15:36:49 +0000 | [diff] [blame] | 131 | cl::opt<bool> DisableDotLoc("disable-dot-loc", cl::Hidden, |
| 132 | cl::desc("Do not use .loc entries")); |
Chris Lattner | 06fcc4c | 2005-06-25 03:32:05 +0000 | [diff] [blame] | 133 | |
Rafael Espindola | a3181d1 | 2011-04-30 03:44:37 +0000 | [diff] [blame] | 134 | cl::opt<bool> DisableCFI("disable-cfi", cl::Hidden, |
| 135 | cl::desc("Do not use .cfi_* directives")); |
| 136 | |
Nick Lewycky | aab6169 | 2011-10-31 01:06:02 +0000 | [diff] [blame] | 137 | cl::opt<bool> EnableDwarfDirectory("enable-dwarf-directory", cl::Hidden, |
| 138 | cl::desc("Use .file directives with an explicit directory.")); |
Nick Lewycky | 40f8f2f | 2011-10-17 23:05:28 +0000 | [diff] [blame] | 139 | |
Devang Patel | 72a4d2f | 2009-06-04 22:05:33 +0000 | [diff] [blame] | 140 | static cl::opt<bool> |
| 141 | DisableRedZone("disable-red-zone", |
| 142 | cl::desc("Do not emit code that uses the red zone."), |
| 143 | cl::init(false)); |
| 144 | |
Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 145 | static cl::opt<bool> |
| 146 | EnableFPMAD("enable-fp-mad", |
| 147 | cl::desc("Enable less precise MAD instructions to be generated"), |
| 148 | cl::init(false)); |
| 149 | |
| 150 | static cl::opt<bool> |
Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 151 | DisableFPElim("disable-fp-elim", |
| 152 | cl::desc("Disable frame pointer elimination optimization"), |
| 153 | cl::init(false)); |
| 154 | |
| 155 | static cl::opt<bool> |
| 156 | DisableFPElimNonLeaf("disable-non-leaf-fp-elim", |
| 157 | cl::desc("Disable frame pointer elimination optimization for non-leaf funcs"), |
| 158 | cl::init(false)); |
| 159 | |
| 160 | static cl::opt<bool> |
Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 161 | EnableUnsafeFPMath("enable-unsafe-fp-math", |
| 162 | cl::desc("Enable optimizations that may decrease FP precision"), |
| 163 | cl::init(false)); |
| 164 | |
| 165 | static cl::opt<bool> |
| 166 | EnableNoInfsFPMath("enable-no-infs-fp-math", |
| 167 | cl::desc("Enable FP math optimizations that assume no +-Infs"), |
| 168 | cl::init(false)); |
| 169 | |
| 170 | static cl::opt<bool> |
| 171 | EnableNoNaNsFPMath("enable-no-nans-fp-math", |
| 172 | cl::desc("Enable FP math optimizations that assume no NaNs"), |
| 173 | cl::init(false)); |
| 174 | |
| 175 | static cl::opt<bool> |
| 176 | EnableHonorSignDependentRoundingFPMath("enable-sign-dependent-rounding-fp-math", |
| 177 | cl::Hidden, |
| 178 | cl::desc("Force codegen to assume rounding mode can change dynamically"), |
| 179 | cl::init(false)); |
| 180 | |
| 181 | static cl::opt<bool> |
| 182 | GenerateSoftFloatCalls("soft-float", |
| 183 | cl::desc("Generate software floating point library calls"), |
| 184 | cl::init(false)); |
| 185 | |
| 186 | static cl::opt<llvm::FloatABI::ABIType> |
| 187 | FloatABIForCalls("float-abi", |
| 188 | cl::desc("Choose float ABI type"), |
| 189 | cl::init(FloatABI::Default), |
| 190 | cl::values( |
| 191 | clEnumValN(FloatABI::Default, "default", |
| 192 | "Target default float ABI type"), |
| 193 | clEnumValN(FloatABI::Soft, "soft", |
| 194 | "Soft float ABI (implied by -soft-float)"), |
| 195 | clEnumValN(FloatABI::Hard, "hard", |
| 196 | "Hard float ABI (uses FP registers)"), |
| 197 | clEnumValEnd)); |
| 198 | |
Lang Hames | b8650f1 | 2012-06-22 01:09:09 +0000 | [diff] [blame] | 199 | static cl::opt<llvm::FPOpFusion::FPOpFusionMode> |
Lang Hames | c98ebda | 2012-06-22 22:31:00 +0000 | [diff] [blame] | 200 | FuseFPOps("fp-contract", |
Lang Hames | b8650f1 | 2012-06-22 01:09:09 +0000 | [diff] [blame] | 201 | cl::desc("Enable aggresive formation of fused FP ops"), |
| 202 | cl::init(FPOpFusion::Standard), |
| 203 | cl::values( |
| 204 | clEnumValN(FPOpFusion::Fast, "fast", |
| 205 | "Fuse FP ops whenever profitable"), |
Lang Hames | c98ebda | 2012-06-22 22:31:00 +0000 | [diff] [blame] | 206 | clEnumValN(FPOpFusion::Standard, "on", |
Lang Hames | b8650f1 | 2012-06-22 01:09:09 +0000 | [diff] [blame] | 207 | "Only fuse 'blessed' FP ops."), |
Lang Hames | c98ebda | 2012-06-22 22:31:00 +0000 | [diff] [blame] | 208 | clEnumValN(FPOpFusion::Strict, "off", |
Lang Hames | b8650f1 | 2012-06-22 01:09:09 +0000 | [diff] [blame] | 209 | "Only fuse FP ops when the result won't be effected."), |
| 210 | clEnumValEnd)); |
| 211 | |
Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 212 | static cl::opt<bool> |
| 213 | DontPlaceZerosInBSS("nozero-initialized-in-bss", |
| 214 | cl::desc("Don't place zero-initialized symbols into bss section"), |
| 215 | cl::init(false)); |
| 216 | |
| 217 | static cl::opt<bool> |
Bob Wilson | fa59485 | 2012-08-03 21:26:18 +0000 | [diff] [blame] | 218 | DisableSimplifyLibCalls("disable-simplify-libcalls", |
| 219 | cl::desc("Disable simplify-libcalls"), |
| 220 | cl::init(false)); |
| 221 | |
| 222 | static cl::opt<bool> |
Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 223 | EnableGuaranteedTailCallOpt("tailcallopt", |
| 224 | cl::desc("Turn fastcc calls into tail calls by (potentially) changing ABI."), |
| 225 | cl::init(false)); |
| 226 | |
Nick Lewycky | ecc0084 | 2012-01-19 00:34:10 +0000 | [diff] [blame] | 227 | static cl::opt<bool> |
| 228 | DisableTailCalls("disable-tail-calls", |
| 229 | cl::desc("Never emit tail calls"), |
| 230 | cl::init(false)); |
| 231 | |
Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 232 | static cl::opt<unsigned> |
| 233 | OverrideStackAlignment("stack-alignment", |
| 234 | cl::desc("Override default stack alignment"), |
| 235 | cl::init(0)); |
| 236 | |
| 237 | static cl::opt<bool> |
| 238 | EnableRealignStack("realign-stack", |
| 239 | cl::desc("Realign stack if needed"), |
| 240 | cl::init(true)); |
| 241 | |
Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 242 | static cl::opt<std::string> |
| 243 | TrapFuncName("trap-func", cl::Hidden, |
| 244 | cl::desc("Emit a call to trap function rather than a trap instruction"), |
| 245 | cl::init("")); |
| 246 | |
| 247 | static cl::opt<bool> |
Chandler Carruth | ede4a8a | 2012-04-08 17:51:45 +0000 | [diff] [blame] | 248 | EnablePIE("enable-pie", |
| 249 | cl::desc("Assume the creation of a position independent executable."), |
| 250 | cl::init(false)); |
| 251 | |
| 252 | static cl::opt<bool> |
Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 253 | SegmentedStacks("segmented-stacks", |
| 254 | cl::desc("Use segmented stacks if possible."), |
| 255 | cl::init(false)); |
| 256 | |
Rafael Espindola | ca3e0ee | 2012-06-19 00:48:28 +0000 | [diff] [blame] | 257 | static cl::opt<bool> |
| 258 | UseInitArray("use-init-array", |
| 259 | cl::desc("Use .init_array instead of .ctors."), |
| 260 | cl::init(false)); |
Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 261 | |
Bob Wilson | cac3b90 | 2012-07-02 19:48:45 +0000 | [diff] [blame] | 262 | static cl::opt<std::string> StopAfter("stop-after", |
| 263 | cl::desc("Stop compilation after a specific pass"), |
| 264 | cl::value_desc("pass-name"), |
| 265 | cl::init("")); |
| 266 | static cl::opt<std::string> StartAfter("start-after", |
| 267 | cl::desc("Resume compilation after a specific pass"), |
| 268 | cl::value_desc("pass-name"), |
| 269 | cl::init("")); |
| 270 | |
Chad Rosier | d269bd8 | 2012-08-21 16:15:24 +0000 | [diff] [blame] | 271 | static cl::opt<unsigned> |
| 272 | SSPBufferSize("stack-protector-buffer-size", cl::init(8), |
| 273 | cl::desc("Lower bound for a buffer to be considered for " |
| 274 | "stack protection")); |
| 275 | |
Chris Lattner | 06fcc4c | 2005-06-25 03:32:05 +0000 | [diff] [blame] | 276 | // GetFileNameRoot - Helper function to get the basename of a filename. |
Chris Lattner | d64b2de | 2003-04-25 05:26:11 +0000 | [diff] [blame] | 277 | static inline std::string |
Chris Lattner | 6142ca8 | 2004-07-11 04:03:24 +0000 | [diff] [blame] | 278 | GetFileNameRoot(const std::string &InputFilename) { |
Chris Lattner | d64b2de | 2003-04-25 05:26:11 +0000 | [diff] [blame] | 279 | std::string IFN = InputFilename; |
| 280 | std::string outputFilename; |
Vikram S. Adve | 2f084b2 | 2001-10-14 23:29:28 +0000 | [diff] [blame] | 281 | int Len = IFN.length(); |
John Criswell | a289abf | 2003-08-28 21:42:29 +0000 | [diff] [blame] | 282 | if ((Len > 2) && |
Dan Gohman | e8d0150 | 2009-09-16 19:18:41 +0000 | [diff] [blame] | 283 | IFN[Len-3] == '.' && |
| 284 | ((IFN[Len-2] == 'b' && IFN[Len-1] == 'c') || |
| 285 | (IFN[Len-2] == 'l' && IFN[Len-1] == 'l'))) { |
Chris Lattner | d64b2de | 2003-04-25 05:26:11 +0000 | [diff] [blame] | 286 | outputFilename = std::string(IFN.begin(), IFN.end()-3); // s/.bc/.s/ |
Vikram S. Adve | 2f084b2 | 2001-10-14 23:29:28 +0000 | [diff] [blame] | 287 | } else { |
Chris Lattner | 97fd6c4 | 2001-10-15 17:30:47 +0000 | [diff] [blame] | 288 | outputFilename = IFN; |
Vikram S. Adve | 2f084b2 | 2001-10-14 23:29:28 +0000 | [diff] [blame] | 289 | } |
| 290 | return outputFilename; |
| 291 | } |
| 292 | |
Dan Gohman | a2233f2 | 2010-09-01 14:20:41 +0000 | [diff] [blame] | 293 | static tool_output_file *GetOutputStream(const char *TargetName, |
| 294 | Triple::OSType OS, |
| 295 | const char *ProgName) { |
Dan Gohman | 7ba6f22 | 2010-08-18 17:55:15 +0000 | [diff] [blame] | 296 | // If we don't yet have an output filename, make one. |
| 297 | if (OutputFilename.empty()) { |
| 298 | if (InputFilename == "-") |
| 299 | OutputFilename = "-"; |
| 300 | else { |
| 301 | OutputFilename = GetFileNameRoot(InputFilename); |
Chris Lattner | 12e9730 | 2006-09-04 04:14:57 +0000 | [diff] [blame] | 302 | |
Dan Gohman | 7ba6f22 | 2010-08-18 17:55:15 +0000 | [diff] [blame] | 303 | switch (FileType) { |
Dan Gohman | 7ba6f22 | 2010-08-18 17:55:15 +0000 | [diff] [blame] | 304 | case TargetMachine::CGFT_AssemblyFile: |
| 305 | if (TargetName[0] == 'c') { |
| 306 | if (TargetName[1] == 0) |
| 307 | OutputFilename += ".cbe.c"; |
| 308 | else if (TargetName[1] == 'p' && TargetName[2] == 'p') |
| 309 | OutputFilename += ".cpp"; |
| 310 | else |
| 311 | OutputFilename += ".s"; |
| 312 | } else |
| 313 | OutputFilename += ".s"; |
| 314 | break; |
| 315 | case TargetMachine::CGFT_ObjectFile: |
| 316 | if (OS == Triple::Win32) |
| 317 | OutputFilename += ".obj"; |
| 318 | else |
| 319 | OutputFilename += ".o"; |
| 320 | break; |
| 321 | case TargetMachine::CGFT_Null: |
| 322 | OutputFilename += ".null"; |
| 323 | break; |
| 324 | } |
Dan Gohman | f3e13bb | 2008-08-21 15:33:45 +0000 | [diff] [blame] | 325 | } |
Chris Lattner | 12e9730 | 2006-09-04 04:14:57 +0000 | [diff] [blame] | 326 | } |
Mikhail Glushenkov | b2f9a73 | 2009-01-16 06:53:46 +0000 | [diff] [blame] | 327 | |
Dan Gohman | 7ba6f22 | 2010-08-18 17:55:15 +0000 | [diff] [blame] | 328 | // Decide if we need "binary" output. |
Daniel Dunbar | ed90e70 | 2008-11-13 05:01:07 +0000 | [diff] [blame] | 329 | bool Binary = false; |
Chris Lattner | 12e9730 | 2006-09-04 04:14:57 +0000 | [diff] [blame] | 330 | switch (FileType) { |
Chris Lattner | f0cb12a | 2010-02-02 21:06:45 +0000 | [diff] [blame] | 331 | case TargetMachine::CGFT_AssemblyFile: |
Chris Lattner | 12e9730 | 2006-09-04 04:14:57 +0000 | [diff] [blame] | 332 | break; |
Chris Lattner | f0cb12a | 2010-02-02 21:06:45 +0000 | [diff] [blame] | 333 | case TargetMachine::CGFT_ObjectFile: |
Chris Lattner | edcf065 | 2010-02-03 05:55:08 +0000 | [diff] [blame] | 334 | case TargetMachine::CGFT_Null: |
Daniel Dunbar | ed90e70 | 2008-11-13 05:01:07 +0000 | [diff] [blame] | 335 | Binary = true; |
Chris Lattner | 12e9730 | 2006-09-04 04:14:57 +0000 | [diff] [blame] | 336 | break; |
| 337 | } |
Mikhail Glushenkov | b2f9a73 | 2009-01-16 06:53:46 +0000 | [diff] [blame] | 338 | |
Dan Gohman | 7ba6f22 | 2010-08-18 17:55:15 +0000 | [diff] [blame] | 339 | // Open the file. |
Owen Anderson | 9371964 | 2008-08-21 00:14:44 +0000 | [diff] [blame] | 340 | std::string error; |
Chris Lattner | 9e6f1f1 | 2009-08-23 02:51:22 +0000 | [diff] [blame] | 341 | unsigned OpenFlags = 0; |
Chris Lattner | 9e6f1f1 | 2009-08-23 02:51:22 +0000 | [diff] [blame] | 342 | if (Binary) OpenFlags |= raw_fd_ostream::F_Binary; |
Dan Gohman | 268b0f4 | 2010-08-20 01:07:01 +0000 | [diff] [blame] | 343 | tool_output_file *FDOut = new tool_output_file(OutputFilename.c_str(), error, |
| 344 | OpenFlags); |
Owen Anderson | 9371964 | 2008-08-21 00:14:44 +0000 | [diff] [blame] | 345 | if (!error.empty()) { |
Dan Gohman | d8db376 | 2009-07-15 16:35:29 +0000 | [diff] [blame] | 346 | errs() << error << '\n'; |
Dan Gohman | 607818a | 2009-07-15 17:29:42 +0000 | [diff] [blame] | 347 | delete FDOut; |
Chris Lattner | 12e9730 | 2006-09-04 04:14:57 +0000 | [diff] [blame] | 348 | return 0; |
| 349 | } |
Mikhail Glushenkov | b2f9a73 | 2009-01-16 06:53:46 +0000 | [diff] [blame] | 350 | |
Dan Gohman | a2233f2 | 2010-09-01 14:20:41 +0000 | [diff] [blame] | 351 | return FDOut; |
Chris Lattner | 12e9730 | 2006-09-04 04:14:57 +0000 | [diff] [blame] | 352 | } |
Vikram S. Adve | 9d40935 | 2001-09-18 13:10:45 +0000 | [diff] [blame] | 353 | |
Chris Lattner | 67e0842 | 2003-06-20 15:49:04 +0000 | [diff] [blame] | 354 | // main - Entry point for the llc compiler. |
| 355 | // |
| 356 | int main(int argc, char **argv) { |
Chris Lattner | 6dd290a | 2007-05-06 04:55:19 +0000 | [diff] [blame] | 357 | sys::PrintStackTraceOnErrorSignal(); |
Chris Lattner | e3fc2d1 | 2009-03-06 05:34:10 +0000 | [diff] [blame] | 358 | PrettyStackTraceProgram X(argc, argv); |
David Greene | 6e55be6 | 2010-01-05 01:30:21 +0000 | [diff] [blame] | 359 | |
| 360 | // Enable debug stream buffering. |
| 361 | EnableDebugBuffering = true; |
| 362 | |
Owen Anderson | 19251ec | 2009-07-15 22:16:10 +0000 | [diff] [blame] | 363 | LLVMContext &Context = getGlobalContext(); |
Chris Lattner | e3fc2d1 | 2009-03-06 05:34:10 +0000 | [diff] [blame] | 364 | llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. |
Chris Lattner | 69e896b | 2004-02-19 20:32:39 +0000 | [diff] [blame] | 365 | |
Daniel Dunbar | 76628de | 2009-09-03 05:47:22 +0000 | [diff] [blame] | 366 | // Initialize targets first, so that --version shows registered targets. |
Chris Lattner | 5dcc4f6 | 2009-06-17 16:42:19 +0000 | [diff] [blame] | 367 | InitializeAllTargets(); |
Evan Cheng | 8c886a4 | 2011-07-22 21:58:54 +0000 | [diff] [blame] | 368 | InitializeAllTargetMCs(); |
Chris Lattner | 5dcc4f6 | 2009-06-17 16:42:19 +0000 | [diff] [blame] | 369 | InitializeAllAsmPrinters(); |
Chris Lattner | 8900ef1 | 2010-04-05 23:11:24 +0000 | [diff] [blame] | 370 | InitializeAllAsmParsers(); |
Daniel Dunbar | 3d92d93 | 2009-07-16 02:04:54 +0000 | [diff] [blame] | 371 | |
Bob Wilson | cac3b90 | 2012-07-02 19:48:45 +0000 | [diff] [blame] | 372 | // Initialize codegen and IR passes used by llc so that the -print-after, |
| 373 | // -print-before, and -stop-after options work. |
| 374 | PassRegistry *Registry = PassRegistry::getPassRegistry(); |
| 375 | initializeCore(*Registry); |
| 376 | initializeCodeGen(*Registry); |
| 377 | initializeLoopStrengthReducePass(*Registry); |
| 378 | initializeLowerIntrinsicsPass(*Registry); |
| 379 | initializeUnreachableBlockElimPass(*Registry); |
Rafael Espindola | e0eaa04 | 2012-06-26 21:33:36 +0000 | [diff] [blame] | 380 | |
Chandler Carruth | 2d71c42 | 2011-07-22 07:50:48 +0000 | [diff] [blame] | 381 | // Register the target printer for --version. |
| 382 | cl::AddExtraVersionPrinter(TargetRegistry::printRegisteredTargetsForVersion); |
| 383 | |
Daniel Dunbar | 3d92d93 | 2009-07-16 02:04:54 +0000 | [diff] [blame] | 384 | cl::ParseCommandLineOptions(argc, argv, "llvm system compiler\n"); |
Andrew Trick | b826ae8 | 2011-04-05 18:41:31 +0000 | [diff] [blame] | 385 | |
Chris Lattner | 6dd290a | 2007-05-06 04:55:19 +0000 | [diff] [blame] | 386 | // Load the module to be compiled... |
Dan Gohman | c76bfb7 | 2009-09-02 19:35:19 +0000 | [diff] [blame] | 387 | SMDiagnostic Err; |
Chris Lattner | 6dd290a | 2007-05-06 04:55:19 +0000 | [diff] [blame] | 388 | std::auto_ptr<Module> M; |
Duncan Sands | 206fc30 | 2012-06-27 16:23:48 +0000 | [diff] [blame] | 389 | Module *mod = 0; |
| 390 | Triple TheTriple; |
Mikhail Glushenkov | b2f9a73 | 2009-01-16 06:53:46 +0000 | [diff] [blame] | 391 | |
Duncan Sands | 206fc30 | 2012-06-27 16:23:48 +0000 | [diff] [blame] | 392 | bool SkipModule = MCPU == "help" || |
| 393 | (!MAttrs.empty() && MAttrs.front() == "help"); |
| 394 | |
| 395 | // If user just wants to list available options, skip module loading |
| 396 | if (!SkipModule) { |
| 397 | M.reset(ParseIRFile(InputFilename, Err, Context)); |
| 398 | mod = M.get(); |
| 399 | if (mod == 0) { |
| 400 | Err.print(argv[0], errs()); |
| 401 | return 1; |
| 402 | } |
| 403 | |
| 404 | // If we are supposed to override the target triple, do so now. |
| 405 | if (!TargetTriple.empty()) |
| 406 | mod->setTargetTriple(Triple::normalize(TargetTriple)); |
| 407 | TheTriple = Triple(mod->getTargetTriple()); |
| 408 | } else { |
| 409 | TheTriple = Triple(Triple::normalize(TargetTriple)); |
Chris Lattner | 6dd290a | 2007-05-06 04:55:19 +0000 | [diff] [blame] | 410 | } |
Mikhail Glushenkov | b2f9a73 | 2009-01-16 06:53:46 +0000 | [diff] [blame] | 411 | |
Daniel Dunbar | 0f16ea5 | 2009-08-03 04:03:51 +0000 | [diff] [blame] | 412 | if (TheTriple.getTriple().empty()) |
Sebastian Pop | 94441fb | 2011-11-01 21:32:20 +0000 | [diff] [blame] | 413 | TheTriple.setTriple(sys::getDefaultTargetTriple()); |
Daniel Dunbar | 0f16ea5 | 2009-08-03 04:03:51 +0000 | [diff] [blame] | 414 | |
Kevin Enderby | fe3d005 | 2012-05-08 23:38:45 +0000 | [diff] [blame] | 415 | // Get the target specific parser. |
| 416 | std::string Error; |
| 417 | const Target *TheTarget = TargetRegistry::lookupTarget(MArch, TheTriple, |
| 418 | Error); |
| 419 | if (!TheTarget) { |
| 420 | errs() << argv[0] << ": " << Error; |
| 421 | return 1; |
Chris Lattner | 5667f0e | 2002-10-29 21:12:46 +0000 | [diff] [blame] | 422 | } |
Chris Lattner | 6dd290a | 2007-05-06 04:55:19 +0000 | [diff] [blame] | 423 | |
| 424 | // Package up features to be passed to target/subtarget |
| 425 | std::string FeaturesStr; |
Evan Cheng | fe6e405 | 2011-06-30 01:53:36 +0000 | [diff] [blame] | 426 | if (MAttrs.size()) { |
Chris Lattner | 6dd290a | 2007-05-06 04:55:19 +0000 | [diff] [blame] | 427 | SubtargetFeatures Features; |
Chris Lattner | 6dd290a | 2007-05-06 04:55:19 +0000 | [diff] [blame] | 428 | for (unsigned i = 0; i != MAttrs.size(); ++i) |
| 429 | Features.AddFeature(MAttrs[i]); |
| 430 | FeaturesStr = Features.getString(); |
| 431 | } |
Mikhail Glushenkov | b2f9a73 | 2009-01-16 06:53:46 +0000 | [diff] [blame] | 432 | |
Evan Cheng | ecb2908 | 2011-11-16 08:38:26 +0000 | [diff] [blame] | 433 | CodeGenOpt::Level OLvl = CodeGenOpt::Default; |
| 434 | switch (OptLevel) { |
| 435 | default: |
| 436 | errs() << argv[0] << ": invalid optimization level.\n"; |
| 437 | return 1; |
| 438 | case ' ': break; |
| 439 | case '0': OLvl = CodeGenOpt::None; break; |
| 440 | case '1': OLvl = CodeGenOpt::Less; break; |
| 441 | case '2': OLvl = CodeGenOpt::Default; break; |
| 442 | case '3': OLvl = CodeGenOpt::Aggressive; break; |
| 443 | } |
| 444 | |
Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 445 | TargetOptions Options; |
| 446 | Options.LessPreciseFPMADOption = EnableFPMAD; |
Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 447 | Options.NoFramePointerElim = DisableFPElim; |
| 448 | Options.NoFramePointerElimNonLeaf = DisableFPElimNonLeaf; |
Lang Hames | b8650f1 | 2012-06-22 01:09:09 +0000 | [diff] [blame] | 449 | Options.AllowFPOpFusion = FuseFPOps; |
Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 450 | Options.UnsafeFPMath = EnableUnsafeFPMath; |
| 451 | Options.NoInfsFPMath = EnableNoInfsFPMath; |
| 452 | Options.NoNaNsFPMath = EnableNoNaNsFPMath; |
| 453 | Options.HonorSignDependentRoundingFPMathOption = |
| 454 | EnableHonorSignDependentRoundingFPMath; |
| 455 | Options.UseSoftFloat = GenerateSoftFloatCalls; |
| 456 | if (FloatABIForCalls != FloatABI::Default) |
| 457 | Options.FloatABIType = FloatABIForCalls; |
| 458 | Options.NoZerosInBSS = DontPlaceZerosInBSS; |
Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 459 | Options.GuaranteedTailCallOpt = EnableGuaranteedTailCallOpt; |
Nick Lewycky | ecc0084 | 2012-01-19 00:34:10 +0000 | [diff] [blame] | 460 | Options.DisableTailCalls = DisableTailCalls; |
Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 461 | Options.StackAlignmentOverride = OverrideStackAlignment; |
| 462 | Options.RealignStack = EnableRealignStack; |
Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 463 | Options.TrapFuncName = TrapFuncName; |
Chandler Carruth | ede4a8a | 2012-04-08 17:51:45 +0000 | [diff] [blame] | 464 | Options.PositionIndependentExecutable = EnablePIE; |
Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 465 | Options.EnableSegmentedStacks = SegmentedStacks; |
Rafael Espindola | ca3e0ee | 2012-06-19 00:48:28 +0000 | [diff] [blame] | 466 | Options.UseInitArray = UseInitArray; |
Chad Rosier | d269bd8 | 2012-08-21 16:15:24 +0000 | [diff] [blame] | 467 | Options.SSPBufferSize = SSPBufferSize; |
Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 468 | |
Andrew Trick | b826ae8 | 2011-04-05 18:41:31 +0000 | [diff] [blame] | 469 | std::auto_ptr<TargetMachine> |
Evan Cheng | efd9b42 | 2011-07-20 07:51:56 +0000 | [diff] [blame] | 470 | target(TheTarget->createTargetMachine(TheTriple.getTriple(), |
Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 471 | MCPU, FeaturesStr, Options, |
Evan Cheng | ecb2908 | 2011-11-16 08:38:26 +0000 | [diff] [blame] | 472 | RelocModel, CMModel, OLvl)); |
Chris Lattner | 6dd290a | 2007-05-06 04:55:19 +0000 | [diff] [blame] | 473 | assert(target.get() && "Could not allocate target machine!"); |
Duncan Sands | 206fc30 | 2012-06-27 16:23:48 +0000 | [diff] [blame] | 474 | assert(mod && "Should have exited after outputting help!"); |
Chris Lattner | 6dd290a | 2007-05-06 04:55:19 +0000 | [diff] [blame] | 475 | TargetMachine &Target = *target.get(); |
| 476 | |
Devang Patel | 85df0cc | 2010-12-01 15:36:49 +0000 | [diff] [blame] | 477 | if (DisableDotLoc) |
| 478 | Target.setMCUseLoc(false); |
Daniel Dunbar | ed3d549 | 2011-04-19 20:46:13 +0000 | [diff] [blame] | 479 | |
Rafael Espindola | a3181d1 | 2011-04-30 03:44:37 +0000 | [diff] [blame] | 480 | if (DisableCFI) |
| 481 | Target.setMCUseCFI(false); |
| 482 | |
Nick Lewycky | aab6169 | 2011-10-31 01:06:02 +0000 | [diff] [blame] | 483 | if (EnableDwarfDirectory) |
| 484 | Target.setMCUseDwarfDirectory(true); |
Nick Lewycky | 40f8f2f | 2011-10-17 23:05:28 +0000 | [diff] [blame] | 485 | |
Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 486 | if (GenerateSoftFloatCalls) |
| 487 | FloatABIForCalls = FloatABI::Soft; |
| 488 | |
Daniel Dunbar | ed3d549 | 2011-04-19 20:46:13 +0000 | [diff] [blame] | 489 | // Disable .loc support for older OS X versions. |
Daniel Dunbar | cd01ed5 | 2011-04-20 00:14:25 +0000 | [diff] [blame] | 490 | if (TheTriple.isMacOSX() && |
Daniel Dunbar | c7f2f14 | 2011-04-20 00:47:19 +0000 | [diff] [blame] | 491 | TheTriple.isMacOSXVersionLT(10, 6)) |
Daniel Dunbar | ed3d549 | 2011-04-19 20:46:13 +0000 | [diff] [blame] | 492 | Target.setMCUseLoc(false); |
Devang Patel | 85df0cc | 2010-12-01 15:36:49 +0000 | [diff] [blame] | 493 | |
Chad Rosier | 09a06c2 | 2012-07-19 00:11:45 +0000 | [diff] [blame] | 494 | // Figure out where we are going to send the output. |
Dan Gohman | a2233f2 | 2010-09-01 14:20:41 +0000 | [diff] [blame] | 495 | OwningPtr<tool_output_file> Out |
Dan Gohman | 268b0f4 | 2010-08-20 01:07:01 +0000 | [diff] [blame] | 496 | (GetOutputStream(TheTarget->getName(), TheTriple.getOS(), argv[0])); |
| 497 | if (!Out) return 1; |
Mikhail Glushenkov | b2f9a73 | 2009-01-16 06:53:46 +0000 | [diff] [blame] | 498 | |
Dan Gohman | 4cfccb8 | 2010-05-11 19:57:55 +0000 | [diff] [blame] | 499 | // Build up all of the passes that we want to do to the module. |
| 500 | PassManager PM; |
Daniel Dunbar | c0deed3 | 2009-08-03 17:34:19 +0000 | [diff] [blame] | 501 | |
Bob Wilson | fa59485 | 2012-08-03 21:26:18 +0000 | [diff] [blame] | 502 | // Add an appropriate TargetLibraryInfo pass for the module's triple. |
| 503 | TargetLibraryInfo *TLI = new TargetLibraryInfo(TheTriple); |
Bob Wilson | 4c65c50 | 2012-08-08 20:31:37 +0000 | [diff] [blame] | 504 | if (DisableSimplifyLibCalls) |
Bob Wilson | fa59485 | 2012-08-03 21:26:18 +0000 | [diff] [blame] | 505 | TLI->disableAllFunctions(); |
Bob Wilson | 4c65c50 | 2012-08-08 20:31:37 +0000 | [diff] [blame] | 506 | PM.add(TLI); |
Bob Wilson | fa59485 | 2012-08-03 21:26:18 +0000 | [diff] [blame] | 507 | |
Dan Gohman | 4cfccb8 | 2010-05-11 19:57:55 +0000 | [diff] [blame] | 508 | // Add the target data from the target machine, if it exists, or the module. |
| 509 | if (const TargetData *TD = Target.getTargetData()) |
| 510 | PM.add(new TargetData(*TD)); |
| 511 | else |
Duncan Sands | 206fc30 | 2012-06-27 16:23:48 +0000 | [diff] [blame] | 512 | PM.add(new TargetData(mod)); |
Daniel Dunbar | c0deed3 | 2009-08-03 17:34:19 +0000 | [diff] [blame] | 513 | |
Dan Gohman | 4cfccb8 | 2010-05-11 19:57:55 +0000 | [diff] [blame] | 514 | // Override default to generate verbose assembly. |
| 515 | Target.setAsmVerbosityDefault(true); |
Daniel Dunbar | c0deed3 | 2009-08-03 17:34:19 +0000 | [diff] [blame] | 516 | |
Michael J. Spencer | f695f8f | 2010-07-31 19:57:02 +0000 | [diff] [blame] | 517 | if (RelaxAll) { |
| 518 | if (FileType != TargetMachine::CGFT_ObjectFile) |
| 519 | errs() << argv[0] |
| 520 | << ": warning: ignoring -mc-relax-all because filetype != obj"; |
| 521 | else |
| 522 | Target.setMCRelaxAll(true); |
| 523 | } |
| 524 | |
Dan Gohman | a2233f2 | 2010-09-01 14:20:41 +0000 | [diff] [blame] | 525 | { |
| 526 | formatted_raw_ostream FOS(Out->os()); |
Mikhail Glushenkov | b2f9a73 | 2009-01-16 06:53:46 +0000 | [diff] [blame] | 527 | |
Bob Wilson | cac3b90 | 2012-07-02 19:48:45 +0000 | [diff] [blame] | 528 | AnalysisID StartAfterID = 0; |
| 529 | AnalysisID StopAfterID = 0; |
| 530 | const PassRegistry *PR = PassRegistry::getPassRegistry(); |
| 531 | if (!StartAfter.empty()) { |
| 532 | const PassInfo *PI = PR->getPassInfo(StartAfter); |
| 533 | if (!PI) { |
| 534 | errs() << argv[0] << ": start-after pass is not registered.\n"; |
| 535 | return 1; |
| 536 | } |
| 537 | StartAfterID = PI->getTypeInfo(); |
| 538 | } |
| 539 | if (!StopAfter.empty()) { |
| 540 | const PassInfo *PI = PR->getPassInfo(StopAfter); |
| 541 | if (!PI) { |
| 542 | errs() << argv[0] << ": stop-after pass is not registered.\n"; |
| 543 | return 1; |
| 544 | } |
| 545 | StopAfterID = PI->getTypeInfo(); |
| 546 | } |
| 547 | |
Dan Gohman | a2233f2 | 2010-09-01 14:20:41 +0000 | [diff] [blame] | 548 | // Ask the target to add backend passes as necessary. |
Bob Wilson | cac3b90 | 2012-07-02 19:48:45 +0000 | [diff] [blame] | 549 | if (Target.addPassesToEmitFile(PM, FOS, FileType, NoVerify, |
| 550 | StartAfterID, StopAfterID)) { |
Dan Gohman | a2233f2 | 2010-09-01 14:20:41 +0000 | [diff] [blame] | 551 | errs() << argv[0] << ": target does not support generation of this" |
| 552 | << " file type!\n"; |
| 553 | return 1; |
| 554 | } |
| 555 | |
Andrew Trick | 1200401 | 2011-04-05 18:54:36 +0000 | [diff] [blame] | 556 | // Before executing passes, print the final values of the LLVM options. |
| 557 | cl::PrintOptionValues(); |
| 558 | |
Duncan Sands | 206fc30 | 2012-06-27 16:23:48 +0000 | [diff] [blame] | 559 | PM.run(*mod); |
Dan Gohman | a2233f2 | 2010-09-01 14:20:41 +0000 | [diff] [blame] | 560 | } |
Dan Gohman | 4cfccb8 | 2010-05-11 19:57:55 +0000 | [diff] [blame] | 561 | |
Dan Gohman | 268b0f4 | 2010-08-20 01:07:01 +0000 | [diff] [blame] | 562 | // Declare success. |
| 563 | Out->keep(); |
Chris Lattner | 6dd290a | 2007-05-06 04:55:19 +0000 | [diff] [blame] | 564 | |
| 565 | return 0; |
Vikram S. Adve | 2f084b2 | 2001-10-14 23:29:28 +0000 | [diff] [blame] | 566 | } |