aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-02-17 19:47:34 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-02-17 19:47:34 +0000
commita034ba807be38d9166998d68af71226c64c5c8dd (patch)
tree4c0ce35885721d5adcb17decd6799ac81e7d7905
parent3092dd6b2c01d7d1721a29c865ac729cd8f9ea3c (diff)
Backend: Accept -mcpu and -mattr for use by TargetMachine.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64798 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--Driver/Backend.cpp28
-rw-r--r--Driver/clang.cpp12
-rw-r--r--include/clang/Driver/CompileOptions.h9
3 files changed, 38 insertions, 11 deletions
diff --git a/Driver/Backend.cpp b/Driver/Backend.cpp
index a0e102af09..6eaffe9d9a 100644
--- a/Driver/Backend.cpp
+++ b/Driver/Backend.cpp
@@ -29,6 +29,7 @@
#include "llvm/Support/Compiler.h"
#include "llvm/System/Path.h"
#include "llvm/System/Program.h"
+#include "llvm/Target/SubtargetFeature.h"
#include "llvm/Target/TargetData.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetMachineRegistry.h"
@@ -74,7 +75,7 @@ namespace {
public:
BackendConsumer(BackendAction action, Diagnostic &Diags,
- const LangOptions &Features, const CompileOptions &compopts,
+ const LangOptions &langopts, const CompileOptions &compopts,
const std::string& infile, const std::string& outfile,
bool debug) :
Action(action),
@@ -82,7 +83,7 @@ namespace {
InputFile(infile),
OutputFile(outfile),
GenerateDebugInfo(debug),
- Gen(CreateLLVMCodeGen(Diags, Features, InputFile, GenerateDebugInfo)),
+ Gen(CreateLLVMCodeGen(Diags, langopts, InputFile, GenerateDebugInfo)),
TheModule(0), TheTargetData(0), AsmOutStream(0), ModuleProvider(0),
CodeGenPasses(0), PerModulePasses(0), PerFunctionPasses(0) {}
@@ -187,10 +188,18 @@ bool BackendConsumer::AddEmitPasses(std::string &Error) {
Error = std::string("Unable to get target machine: ") + Error;
return false;
}
-
- // FIXME: Support features?
- std::string FeatureStr;
- TargetMachine *TM = TME->CtorFn(*TheModule, FeatureStr);
+
+ std::string FeaturesStr;
+ if (CompileOpts.CPU.size() || CompileOpts.Features.size()) {
+ SubtargetFeatures Features;
+ Features.setCPU(CompileOpts.CPU);
+ for (std::vector<std::string>::iterator
+ it = CompileOpts.Features.begin(),
+ ie = CompileOpts.Features.end(); it != ie; ++it)
+ Features.AddFeature(*it);
+ FeaturesStr = Features.getString();
+ }
+ TargetMachine *TM = TME->CtorFn(*TheModule, FeaturesStr);
// Set register scheduler & allocation policy.
RegisterScheduler::setDefault(createDefaultScheduler);
@@ -364,7 +373,7 @@ void BackendConsumer::EmitAssembly() {
ASTConsumer *clang::CreateBackendConsumer(BackendAction Action,
Diagnostic &Diags,
- const LangOptions &Features,
+ const LangOptions &LangOpts,
const CompileOptions &CompileOpts,
const std::string& InFile,
const std::string& OutFile,
@@ -374,8 +383,7 @@ ASTConsumer *clang::CreateBackendConsumer(BackendAction Action,
// are enabled.
if (CompileOpts.OptimizationLevel > 0)
GenerateDebugInfo = false;
-
-
- return new BackendConsumer(Action, Diags, Features, CompileOpts,
+
+ return new BackendConsumer(Action, Diags, LangOpts, CompileOpts,
InFile, OutFile, GenerateDebugInfo);
}
diff --git a/Driver/clang.cpp b/Driver/clang.cpp
index 1fdfde4318..24c4d7fe09 100644
--- a/Driver/clang.cpp
+++ b/Driver/clang.cpp
@@ -1204,6 +1204,14 @@ OptLevel("O", llvm::cl::Prefix,
llvm::cl::desc("Optimization level"),
llvm::cl::init(0));
+static llvm::cl::opt<std::string>
+TargetCPU("mcpu",
+ llvm::cl::desc("Target a specific cpu type (-mcpu=help for details)"));
+
+static llvm::cl::list<std::string>
+TargetFeatures("mattr",
+ llvm::cl::desc("Target specific attributes (-mattr=help for details)"));
+
static void InitializeCompileOptions(CompileOptions &Opts) {
Opts.OptimizeSize = OptSize;
if (OptSize) {
@@ -1222,6 +1230,10 @@ static void InitializeCompileOptions(CompileOptions &Opts) {
#ifdef NDEBUG
Opts.VerifyModule = 0;
#endif
+
+ Opts.CPU = TargetCPU;
+ Opts.Features.insert(Opts.Features.end(),
+ TargetFeatures.begin(), TargetFeatures.end());
}
//===----------------------------------------------------------------------===//
diff --git a/include/clang/Driver/CompileOptions.h b/include/clang/Driver/CompileOptions.h
index 50865536dc..354df43aea 100644
--- a/include/clang/Driver/CompileOptions.h
+++ b/include/clang/Driver/CompileOptions.h
@@ -30,6 +30,13 @@ struct CompileOptions {
unsigned VerifyModule : 1; /// Control whether the module
/// should be run through the LLVM Verifier.
+ /// CPU - An optional CPU to target.
+ std::string CPU;
+
+ /// Features - A list of subtarget features to pass to the code
+ /// generator.
+ std::vector<std::string> Features;
+
public:
CompileOptions() {
OptimizationLevel = 0;
@@ -37,7 +44,7 @@ public:
UnitAtATime = 1;
InlineFunctions = SimplifyLibCalls = UnrollLoops = 0;
VerifyModule = 1;
- }
+ }
};
} // end namespace clang