diff options
author | Pirama Arumuga Nainar <pirama@google.com> | 2015-05-06 11:46:36 -0700 |
---|---|---|
committer | Pirama Arumuga Nainar <pirama@google.com> | 2015-05-18 10:52:30 -0700 |
commit | 2c3e0051c31c3f5b2328b447eadf1cf9c4427442 (patch) | |
tree | c0104029af14e9f47c2ef58ca60e6137691f3c9b /tools/llc/llc.cpp | |
parent | e1bc145815f4334641be19f1c45ecf85d25b6e5a (diff) | |
download | external_llvm-2c3e0051c31c3f5b2328b447eadf1cf9c4427442.zip external_llvm-2c3e0051c31c3f5b2328b447eadf1cf9c4427442.tar.gz external_llvm-2c3e0051c31c3f5b2328b447eadf1cf9c4427442.tar.bz2 |
Update aosp/master LLVM for rebase to r235153
Change-Id: I9bf53792f9fc30570e81a8d80d296c681d005ea7
(cherry picked from commit 0c7f116bb6950ef819323d855415b2f2b0aad987)
Diffstat (limited to 'tools/llc/llc.cpp')
-rw-r--r-- | tools/llc/llc.cpp | 47 |
1 files changed, 37 insertions, 10 deletions
diff --git a/tools/llc/llc.cpp b/tools/llc/llc.cpp index 55a45dc..ab50f2a 100644 --- a/tools/llc/llc.cpp +++ b/tools/llc/llc.cpp @@ -25,6 +25,7 @@ #include "llvm/IR/LLVMContext.h" #include "llvm/IR/LegacyPassManager.h" #include "llvm/IR/Module.h" +#include "llvm/IR/Verifier.h" #include "llvm/IRReader/IRReader.h" #include "llvm/MC/SubtargetFeature.h" #include "llvm/Pass.h" @@ -211,12 +212,6 @@ static int compileModule(char **argv, LLVMContext &Context) { bool SkipModule = MCPU == "help" || (!MAttrs.empty() && MAttrs.front() == "help"); - // If user asked for the 'native' CPU, autodetect here. If autodection fails, - // this will set the CPU to an empty string which tells the target to - // pick a basic default. - if (MCPU == "native") - MCPU = sys::getHostCPUName(); - // If user just wants to list available options, skip module loading if (!SkipModule) { M = parseIRFile(InputFilename, Err, Context); @@ -225,6 +220,14 @@ static int compileModule(char **argv, LLVMContext &Context) { return 1; } + // Verify module immediately to catch problems before doInitialization() is + // called on any passes. + if (!NoVerify && verifyModule(*M, &errs())) { + errs() << argv[0] << ": " << InputFilename + << ": error: input module is broken!\n"; + return 1; + } + // If we are supposed to override the target triple, do so now. if (!TargetTriple.empty()) M->setTargetTriple(Triple::normalize(TargetTriple)); @@ -247,13 +250,31 @@ static int compileModule(char **argv, LLVMContext &Context) { // Package up features to be passed to target/subtarget std::string FeaturesStr; - if (MAttrs.size()) { + if (!MAttrs.empty() || MCPU == "native") { SubtargetFeatures Features; + + // If user asked for the 'native' CPU, we need to autodetect features. + // This is necessary for x86 where the CPU might not support all the + // features the autodetected CPU name lists in the target. For example, + // not all Sandybridge processors support AVX. + if (MCPU == "native") { + StringMap<bool> HostFeatures; + if (sys::getHostCPUFeatures(HostFeatures)) + for (auto &F : HostFeatures) + Features.AddFeature(F.first(), F.second); + } + for (unsigned i = 0; i != MAttrs.size(); ++i) Features.AddFeature(MAttrs[i]); FeaturesStr = Features.getString(); } + // If user asked for the 'native' CPU, autodetect here. If autodection fails, + // this will set the CPU to an empty string which tells the target to + // pick a basic default. + if (MCPU == "native") + MCPU = sys::getHostCPUName(); + CodeGenOpt::Level OLvl = CodeGenOpt::Default; switch (OptLevel) { default: @@ -314,7 +335,13 @@ static int compileModule(char **argv, LLVMContext &Context) { << ": warning: ignoring -mc-relax-all because filetype != obj"; { - formatted_raw_ostream FOS(Out->os()); + raw_pwrite_stream *OS = &Out->os(); + std::unique_ptr<buffer_ostream> BOS; + if (FileType != TargetMachine::CGFT_AssemblyFile && + !Out->os().supportsSeeking()) { + BOS = make_unique<buffer_ostream>(*OS); + OS = BOS.get(); + } AnalysisID StartAfterID = nullptr; AnalysisID StopAfterID = nullptr; @@ -337,8 +364,8 @@ static int compileModule(char **argv, LLVMContext &Context) { } // Ask the target to add backend passes as necessary. - if (Target->addPassesToEmitFile(PM, FOS, FileType, NoVerify, - StartAfterID, StopAfterID)) { + if (Target->addPassesToEmitFile(PM, *OS, FileType, NoVerify, StartAfterID, + StopAfterID)) { errs() << argv[0] << ": target does not support generation of this" << " file type!\n"; return 1; |