LCOV - code coverage report
Current view: top level - include/llvm/CodeGen - CommandFlags.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 184 189 97.4 %
Date: 2017-09-14 15:23:50 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===-- CommandFlags.h - Command Line Flags Interface -----------*- C++ -*-===//
       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 codegen-specific flags that are shared between different
      11             : // command line tools. The tools "llc" and "opt" both use this file to prevent
      12             : // flag duplication.
      13             : //
      14             : //===----------------------------------------------------------------------===//
      15             : 
      16             : #ifndef LLVM_CODEGEN_COMMANDFLAGS_H
      17             : #define LLVM_CODEGEN_COMMANDFLAGS_H
      18             : 
      19             : #include "llvm/ADT/StringExtras.h"
      20             : #include "llvm/IR/Instructions.h"
      21             : #include "llvm/IR/Intrinsics.h"
      22             : #include "llvm/IR/Module.h"
      23             : #include "llvm/MC/MCTargetOptionsCommandFlags.h"
      24             : #include "llvm/MC/SubtargetFeature.h"
      25             : #include "llvm/Support/CodeGen.h"
      26             : #include "llvm/Support/CommandLine.h"
      27             : #include "llvm/Support/Host.h"
      28             : #include "llvm/Target/TargetMachine.h"
      29             : #include "llvm/Target/TargetOptions.h"
      30             : #include <string>
      31             : using namespace llvm;
      32             : 
      33             : cl::opt<std::string>
      34       57080 : MArch("march", cl::desc("Architecture to generate code for (see --version)"));
      35             : 
      36             : cl::opt<std::string>
      37       28540 : MCPU("mcpu",
      38       85620 :      cl::desc("Target a specific cpu type (-mcpu=help for details)"),
      39       85620 :      cl::value_desc("cpu-name"),
      40       85620 :      cl::init(""));
      41             : 
      42             : cl::list<std::string>
      43       28540 : MAttrs("mattr",
      44             :        cl::CommaSeparated,
      45       85620 :        cl::desc("Target specific attributes (-mattr=help for details)"),
      46      114160 :        cl::value_desc("a1,+a2,-a3,..."));
      47             : 
      48       28540 : cl::opt<Reloc::Model> RelocModel(
      49       85620 :     "relocation-model", cl::desc("Choose relocation model"),
      50      371020 :     cl::values(
      51             :         clEnumValN(Reloc::Static, "static", "Non-relocatable code"),
      52             :         clEnumValN(Reloc::PIC_, "pic",
      53             :                    "Fully relocatable, position independent code"),
      54             :         clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
      55             :                    "Relocatable external references, non-relocatable code"),
      56             :         clEnumValN(Reloc::ROPI, "ropi",
      57             :                    "Code and read-only data relocatable, accessed PC-relative"),
      58             :         clEnumValN(Reloc::RWPI, "rwpi",
      59             :                    "Read-write data relocatable, accessed relative to static base"),
      60             :         clEnumValN(Reloc::ROPI_RWPI, "ropi-rwpi",
      61       28540 :                    "Combination of ropi and rwpi")));
      62             : 
      63             : static inline Optional<Reloc::Model> getRelocModel() {
      64       19739 :   if (RelocModel.getNumOccurrences()) {
      65        1647 :     Reloc::Model R = RelocModel;
      66        1647 :     return R;
      67             :   }
      68             :   return None;
      69             : }
      70             : 
      71             : cl::opt<ThreadModel::Model>
      72       28540 : TMModel("thread-model",
      73       85620 :         cl::desc("Choose threading model"),
      74       85620 :         cl::init(ThreadModel::POSIX),
      75       57080 :         cl::values(clEnumValN(ThreadModel::POSIX, "posix",
      76             :                               "POSIX thread model"),
      77             :                    clEnumValN(ThreadModel::Single, "single",
      78       28540 :                               "Single thread model")));
      79             : 
      80       28540 : cl::opt<llvm::CodeModel::Model> CMModel(
      81       85620 :     "code-model", cl::desc("Choose code model"),
      82      256860 :     cl::values(clEnumValN(CodeModel::Small, "small", "Small code model"),
      83             :                clEnumValN(CodeModel::Kernel, "kernel", "Kernel code model"),
      84             :                clEnumValN(CodeModel::Medium, "medium", "Medium code model"),
      85       28540 :                clEnumValN(CodeModel::Large, "large", "Large code model")));
      86             : 
      87             : static inline Optional<CodeModel::Model> getCodeModel() {
      88       19714 :   if (CMModel.getNumOccurrences()) {
      89         145 :     CodeModel::Model M = CMModel;
      90         145 :     return M;
      91             :   }
      92             :   return None;
      93             : }
      94             : 
      95             : cl::opt<llvm::ExceptionHandling>
      96       28540 : ExceptionModel("exception-model",
      97       85620 :                cl::desc("exception model"),
      98       85620 :                cl::init(ExceptionHandling::None),
      99      313940 :                cl::values(clEnumValN(ExceptionHandling::None, "default",
     100             :                                      "default exception handling model"),
     101             :                           clEnumValN(ExceptionHandling::DwarfCFI, "dwarf",
     102             :                                      "DWARF-like CFI based exception handling"),
     103             :                           clEnumValN(ExceptionHandling::SjLj, "sjlj",
     104             :                                      "SjLj exception handling"),
     105             :                           clEnumValN(ExceptionHandling::ARM, "arm",
     106             :                                      "ARM EHABI exceptions"),
     107             :                           clEnumValN(ExceptionHandling::WinEH, "wineh",
     108       28540 :                                      "Windows exception model")));
     109             : 
     110             : cl::opt<TargetMachine::CodeGenFileType>
     111      114160 : FileType("filetype", cl::init(TargetMachine::CGFT_AssemblyFile),
     112       85620 :   cl::desc("Choose a file type (not all types are supported by all targets):"),
     113      199780 :   cl::values(
     114             :              clEnumValN(TargetMachine::CGFT_AssemblyFile, "asm",
     115             :                         "Emit an assembly ('.s') file"),
     116             :              clEnumValN(TargetMachine::CGFT_ObjectFile, "obj",
     117             :                         "Emit a native object ('.o') file"),
     118             :              clEnumValN(TargetMachine::CGFT_Null, "null",
     119       28540 :                         "Emit nothing, for performance testing")));
     120             : 
     121             : cl::opt<bool>
     122       28540 : DisableFPElim("disable-fp-elim",
     123       85620 :               cl::desc("Disable frame pointer elimination optimization"),
     124      114160 :               cl::init(false));
     125             : 
     126             : cl::opt<bool>
     127       28540 : EnableUnsafeFPMath("enable-unsafe-fp-math",
     128       85620 :                 cl::desc("Enable optimizations that may decrease FP precision"),
     129      114160 :                 cl::init(false));
     130             : 
     131             : cl::opt<bool>
     132       28540 : EnableNoInfsFPMath("enable-no-infs-fp-math",
     133       85620 :                 cl::desc("Enable FP math optimizations that assume no +-Infs"),
     134      114160 :                 cl::init(false));
     135             : 
     136             : cl::opt<bool>
     137       28540 : EnableNoNaNsFPMath("enable-no-nans-fp-math",
     138       85620 :                    cl::desc("Enable FP math optimizations that assume no NaNs"),
     139      114160 :                    cl::init(false));
     140             : 
     141             : cl::opt<bool>
     142       28540 : EnableNoSignedZerosFPMath("enable-no-signed-zeros-fp-math",
     143       85620 :                           cl::desc("Enable FP math optimizations that assume "
     144             :                                    "the sign of 0 is insignificant"),
     145      114160 :                           cl::init(false));
     146             : 
     147             : cl::opt<bool>
     148       28540 : EnableNoTrappingFPMath("enable-no-trapping-fp-math",
     149       85620 :                        cl::desc("Enable setting the FP exceptions build "
     150             :                                 "attribute not to use exceptions"),
     151      114160 :                        cl::init(false));
     152             : 
     153             : cl::opt<llvm::FPDenormal::DenormalMode>
     154       28540 : DenormalMode("denormal-fp-math",
     155       85620 :           cl::desc("Select which denormal numbers the code is permitted to require"),
     156       85620 :           cl::init(FPDenormal::IEEE),
     157      199780 :           cl::values(
     158             :               clEnumValN(FPDenormal::IEEE, "ieee",
     159             :                          "IEEE 754 denormal numbers"),
     160             :               clEnumValN(FPDenormal::PreserveSign, "preserve-sign",
     161             :                          "the sign of a  flushed-to-zero number is preserved "
     162             :                          "in the sign of 0"),
     163             :               clEnumValN(FPDenormal::PositiveZero, "positive-zero",
     164       28540 :                          "denormals are flushed to positive zero")));
     165             : 
     166             : cl::opt<bool>
     167       28540 : EnableHonorSignDependentRoundingFPMath("enable-sign-dependent-rounding-fp-math",
     168             :       cl::Hidden,
     169       85620 :       cl::desc("Force codegen to assume rounding mode can change dynamically"),
     170      114160 :       cl::init(false));
     171             : 
     172             : cl::opt<llvm::FloatABI::ABIType>
     173       28540 : FloatABIForCalls("float-abi",
     174       85620 :                  cl::desc("Choose float ABI type"),
     175       85620 :                  cl::init(FloatABI::Default),
     176      199780 :                  cl::values(
     177             :                      clEnumValN(FloatABI::Default, "default",
     178             :                                 "Target default float ABI type"),
     179             :                      clEnumValN(FloatABI::Soft, "soft",
     180             :                                 "Soft float ABI (implied by -soft-float)"),
     181             :                      clEnumValN(FloatABI::Hard, "hard",
     182       28540 :                                 "Hard float ABI (uses FP registers)")));
     183             : 
     184             : cl::opt<llvm::FPOpFusion::FPOpFusionMode>
     185       28540 : FuseFPOps("fp-contract",
     186       85620 :           cl::desc("Enable aggressive formation of fused FP ops"),
     187       85620 :           cl::init(FPOpFusion::Standard),
     188      199780 :           cl::values(
     189             :               clEnumValN(FPOpFusion::Fast, "fast",
     190             :                          "Fuse FP ops whenever profitable"),
     191             :               clEnumValN(FPOpFusion::Standard, "on",
     192             :                          "Only fuse 'blessed' FP ops."),
     193             :               clEnumValN(FPOpFusion::Strict, "off",
     194       28540 :                          "Only fuse FP ops when the result won't be affected.")));
     195             : 
     196             : cl::opt<bool>
     197       28540 : DontPlaceZerosInBSS("nozero-initialized-in-bss",
     198       85620 :               cl::desc("Don't place zero-initialized symbols into bss section"),
     199      114160 :               cl::init(false));
     200             : 
     201             : cl::opt<bool>
     202       28540 : EnableGuaranteedTailCallOpt("tailcallopt",
     203       85620 :   cl::desc("Turn fastcc calls into tail calls by (potentially) changing ABI."),
     204      114160 :   cl::init(false));
     205             : 
     206             : cl::opt<bool>
     207       28540 : DisableTailCalls("disable-tail-calls",
     208       85620 :                  cl::desc("Never emit tail calls"),
     209      114160 :                  cl::init(false));
     210             : 
     211             : cl::opt<bool>
     212       28540 : StackSymbolOrdering("stack-symbol-ordering",
     213       85620 :                     cl::desc("Order local stack symbols."),
     214      114160 :                     cl::init(true));
     215             : 
     216             : cl::opt<unsigned>
     217       28540 : OverrideStackAlignment("stack-alignment",
     218       85620 :                        cl::desc("Override default stack alignment"),
     219      114160 :                        cl::init(0));
     220             : 
     221             : cl::opt<bool>
     222       28540 : StackRealign("stackrealign",
     223       85620 :              cl::desc("Force align the stack to the minimum alignment"),
     224      114160 :              cl::init(false));
     225             : 
     226             : cl::opt<std::string>
     227       28540 : TrapFuncName("trap-func", cl::Hidden,
     228       85620 :         cl::desc("Emit a call to trap function rather than a trap instruction"),
     229       85620 :         cl::init(""));
     230             : 
     231             : cl::opt<bool>
     232       28540 : UseCtors("use-ctors",
     233       85620 :              cl::desc("Use .ctors instead of .init_array."),
     234      114160 :              cl::init(false));
     235             : 
     236       28540 : cl::opt<bool> RelaxELFRelocations(
     237             :     "relax-elf-relocations",
     238       85620 :     cl::desc("Emit GOTPCRELX/REX_GOTPCRELX instead of GOTPCREL on x86-64 ELF"),
     239      114160 :     cl::init(false));
     240             : 
     241       28540 : cl::opt<bool> DataSections("data-sections",
     242       85620 :                            cl::desc("Emit data into separate sections"),
     243      114160 :                            cl::init(false));
     244             : 
     245             : cl::opt<bool>
     246       28540 : FunctionSections("function-sections",
     247       85620 :                  cl::desc("Emit functions into separate sections"),
     248      114160 :                  cl::init(false));
     249             : 
     250       28540 : cl::opt<bool> EmulatedTLS("emulated-tls",
     251       85620 :                           cl::desc("Use emulated TLS model"),
     252      114160 :                           cl::init(false));
     253             : 
     254       28540 : cl::opt<bool> UniqueSectionNames("unique-section-names",
     255       85620 :                                  cl::desc("Give unique names to every section"),
     256      114160 :                                  cl::init(true));
     257             : 
     258       28540 : cl::opt<llvm::EABI> EABIVersion(
     259       85620 :     "meabi", cl::desc("Set EABI type (default depends on triple):"),
     260       85620 :     cl::init(EABI::Default),
     261      256860 :     cl::values(clEnumValN(EABI::Default, "default",
     262             :                           "Triple default EABI version"),
     263             :                clEnumValN(EABI::EABI4, "4", "EABI version 4"),
     264             :                clEnumValN(EABI::EABI5, "5", "EABI version 5"),
     265       28540 :                clEnumValN(EABI::GNU, "gnu", "EABI GNU")));
     266             : 
     267             : cl::opt<DebuggerKind>
     268       28540 : DebuggerTuningOpt("debugger-tune",
     269       85620 :                   cl::desc("Tune debug info for a particular debugger"),
     270       85620 :                   cl::init(DebuggerKind::Default),
     271      199780 :                   cl::values(
     272             :                       clEnumValN(DebuggerKind::GDB, "gdb", "gdb"),
     273             :                       clEnumValN(DebuggerKind::LLDB, "lldb", "lldb"),
     274             :                       clEnumValN(DebuggerKind::SCE, "sce",
     275       28540 :                                  "SCE targets (e.g. PS4)")));
     276             : 
     277             : // Common utility function tightly tied to the options listed here. Initializes
     278             : // a TargetOptions object with CodeGen flags and returns it.
     279       26158 : static inline TargetOptions InitTargetOptionsFromCodeGenFlags() {
     280       26158 :   TargetOptions Options;
     281       26158 :   Options.AllowFPOpFusion = FuseFPOps;
     282       26158 :   Options.UnsafeFPMath = EnableUnsafeFPMath;
     283       26158 :   Options.NoInfsFPMath = EnableNoInfsFPMath;
     284       26158 :   Options.NoNaNsFPMath = EnableNoNaNsFPMath;
     285       26158 :   Options.NoSignedZerosFPMath = EnableNoSignedZerosFPMath;
     286       26158 :   Options.NoTrappingFPMath = EnableNoTrappingFPMath;
     287       26158 :   Options.FPDenormalMode = DenormalMode;
     288       26158 :   Options.HonorSignDependentRoundingFPMathOption =
     289       26158 :       EnableHonorSignDependentRoundingFPMath;
     290       26158 :   if (FloatABIForCalls != FloatABI::Default)
     291          94 :     Options.FloatABIType = FloatABIForCalls;
     292       26158 :   Options.NoZerosInBSS = DontPlaceZerosInBSS;
     293       26158 :   Options.GuaranteedTailCallOpt = EnableGuaranteedTailCallOpt;
     294       26158 :   Options.StackAlignmentOverride = OverrideStackAlignment;
     295       26158 :   Options.StackSymbolOrdering = StackSymbolOrdering;
     296       26158 :   Options.UseInitArray = !UseCtors;
     297       26158 :   Options.RelaxELFRelocations = RelaxELFRelocations;
     298       26158 :   Options.DataSections = DataSections;
     299       26158 :   Options.FunctionSections = FunctionSections;
     300       26158 :   Options.UniqueSectionNames = UniqueSectionNames;
     301       26158 :   Options.EmulatedTLS = EmulatedTLS;
     302       26158 :   Options.ExceptionModel = ExceptionModel;
     303             : 
     304       26158 :   Options.MCOptions = InitMCTargetOptionsFromFlags();
     305             : 
     306       26158 :   Options.ThreadModel = TMModel;
     307       26158 :   Options.EABIVersion = EABIVersion;
     308       26158 :   Options.DebuggerTuning = DebuggerTuningOpt;
     309             : 
     310       26158 :   return Options;
     311             : }
     312             : 
     313       19510 : static inline std::string getCPUStr() {
     314             :   // If user asked for the 'native' CPU, autodetect here. If autodection fails,
     315             :   // this will set the CPU to an empty string which tells the target to
     316             :   // pick a basic default.
     317       19510 :   if (MCPU == "native")
     318           0 :     return sys::getHostCPUName();
     319             : 
     320             :   return MCPU;
     321             : }
     322             : 
     323       19510 : static inline std::string getFeaturesStr() {
     324       39020 :   SubtargetFeatures Features;
     325             : 
     326             :   // If user asked for the 'native' CPU, we need to autodetect features.
     327             :   // This is necessary for x86 where the CPU might not support all the
     328             :   // features the autodetected CPU name lists in the target. For example,
     329             :   // not all Sandybridge processors support AVX.
     330       19510 :   if (MCPU == "native") {
     331           0 :     StringMap<bool> HostFeatures;
     332           0 :     if (sys::getHostCPUFeatures(HostFeatures))
     333           0 :       for (auto &F : HostFeatures)
     334           0 :         Features.AddFeature(F.first(), F.second);
     335             :   }
     336             : 
     337       55889 :   for (unsigned i = 0; i != MAttrs.size(); ++i)
     338       16869 :     Features.AddFeature(MAttrs[i]);
     339             : 
     340       39020 :   return Features.getString();
     341             : }
     342             : 
     343             : /// \brief Set function attributes of functions in Module M based on CPU,
     344             : /// Features, and command line flags.
     345       25623 : static inline void setFunctionAttributes(StringRef CPU, StringRef Features,
     346             :                                          Module &M) {
     347      302200 :   for (auto &F : M) {
     348      225331 :     auto &Ctx = F.getContext();
     349      225331 :     AttributeList Attrs = F.getAttributes();
     350      450662 :     AttrBuilder NewAttrs;
     351             : 
     352      225331 :     if (!CPU.empty())
     353       72263 :       NewAttrs.addAttribute("target-cpu", CPU);
     354      225331 :     if (!Features.empty())
     355       77933 :       NewAttrs.addAttribute("target-features", Features);
     356      225331 :     if (DisableFPElim.getNumOccurrences() > 0)
     357        1897 :       NewAttrs.addAttribute("no-frame-pointer-elim",
     358        7588 :                             DisableFPElim ? "true" : "false");
     359      225331 :     if (DisableTailCalls.getNumOccurrences() > 0)
     360          34 :       NewAttrs.addAttribute("disable-tail-calls",
     361         136 :                             toStringRef(DisableTailCalls));
     362      225331 :     if (StackRealign)
     363         158 :       NewAttrs.addAttribute("stackrealign");
     364             : 
     365      225331 :     if (TrapFuncName.getNumOccurrences() > 0)
     366          43 :       for (auto &B : F)
     367          35 :         for (auto &I : B)
     368           7 :           if (auto *Call = dyn_cast<CallInst>(&I))
     369           7 :             if (const auto *F = Call->getCalledFunction())
     370           7 :               if (F->getIntrinsicID() == Intrinsic::debugtrap ||
     371             :                   F->getIntrinsicID() == Intrinsic::trap)
     372          14 :                 Call->addAttribute(
     373             :                     llvm::AttributeList::FunctionIndex,
     374             :                     Attribute::get(Ctx, "trap-func-name", TrapFuncName));
     375             : 
     376             :     // Let NewAttrs override Attrs.
     377      450662 :     F.setAttributes(
     378             :         Attrs.addAttributes(Ctx, AttributeList::FunctionIndex, NewAttrs));
     379             :   }
     380       25623 : }
     381             : 
     382             : #endif

Generated by: LCOV version 1.13