[cfe-commits] r64798 - in /cfe/trunk: Driver/Backend.cpp Driver/clang.cpp include/clang/Driver/CompileOptions.h
Daniel Dunbar
daniel at zuster.org
Tue Feb 17 11:47:34 PST 2009
Author: ddunbar
Date: Tue Feb 17 13:47:34 2009
New Revision: 64798
URL: http://llvm.org/viewvc/llvm-project?rev=64798&view=rev
Log:
Backend: Accept -mcpu and -mattr for use by TargetMachine.
Modified:
cfe/trunk/Driver/Backend.cpp
cfe/trunk/Driver/clang.cpp
cfe/trunk/include/clang/Driver/CompileOptions.h
Modified: cfe/trunk/Driver/Backend.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/Backend.cpp?rev=64798&r1=64797&r2=64798&view=diff
==============================================================================
--- cfe/trunk/Driver/Backend.cpp (original)
+++ cfe/trunk/Driver/Backend.cpp Tue Feb 17 13:47:34 2009
@@ -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 @@
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 @@
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 @@
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 @@
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 @@
// 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);
}
Modified: cfe/trunk/Driver/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/clang.cpp?rev=64798&r1=64797&r2=64798&view=diff
==============================================================================
--- cfe/trunk/Driver/clang.cpp (original)
+++ cfe/trunk/Driver/clang.cpp Tue Feb 17 13:47:34 2009
@@ -1204,6 +1204,14 @@
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 @@
#ifdef NDEBUG
Opts.VerifyModule = 0;
#endif
+
+ Opts.CPU = TargetCPU;
+ Opts.Features.insert(Opts.Features.end(),
+ TargetFeatures.begin(), TargetFeatures.end());
}
//===----------------------------------------------------------------------===//
Modified: cfe/trunk/include/clang/Driver/CompileOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CompileOptions.h?rev=64798&r1=64797&r2=64798&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/CompileOptions.h (original)
+++ cfe/trunk/include/clang/Driver/CompileOptions.h Tue Feb 17 13:47:34 2009
@@ -30,6 +30,13 @@
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 @@
UnitAtATime = 1;
InlineFunctions = SimplifyLibCalls = UnrollLoops = 0;
VerifyModule = 1;
- }
+ }
};
} // end namespace clang
More information about the cfe-commits
mailing list