Make it feasible for clients using EngineBuilder to capture the TargetMachine that is created as part of selecting the appropriate target.

This is necessary if the client wants to be able to mutate TargetOptions (for example, fast FP math mode) after the initial creation of the ExecutionEngine.

llvm-svn: 153342
This commit is contained in:
Owen Anderson
2012-03-23 17:40:56 +00:00
parent 45c6d21ae1
commit add6f1d2e9
3 changed files with 53 additions and 48 deletions

View File

@@ -15,6 +15,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/Module.h"
#include "llvm/ADT/Triple.h"
#include "llvm/MC/SubtargetFeature.h"
#include "llvm/Target/TargetMachine.h"
@@ -24,17 +25,21 @@
using namespace llvm;
TargetMachine *EngineBuilder::selectTarget() {
StringRef MArch = "";
StringRef MCPU = "";
SmallVector<std::string, 1> MAttrs;
Triple TT(M->getTargetTriple());
return selectTarget(TT, MArch, MCPU, MAttrs);
}
/// selectTarget - Pick a target either via -march or by guessing the native
/// arch. Add any CPU features specified via -mcpu or -mattr.
TargetMachine *EngineBuilder::selectTarget(const Triple &TargetTriple,
StringRef MArch,
StringRef MCPU,
const SmallVectorImpl<std::string>& MAttrs,
const TargetOptions &Options,
Reloc::Model RM,
CodeModel::Model CM,
CodeGenOpt::Level OL,
std::string *ErrorStr) {
const SmallVectorImpl<std::string>& MAttrs) {
Triple TheTriple(TargetTriple);
if (TheTriple.getTriple().empty())
TheTriple.setTriple(sys::getDefaultTargetTriple());
@@ -84,7 +89,8 @@ TargetMachine *EngineBuilder::selectTarget(const Triple &TargetTriple,
TargetMachine *Target = TheTarget->createTargetMachine(TheTriple.getTriple(),
MCPU, FeaturesStr,
Options,
RM, CM, OL);
RelocModel, CMModel,
OptLevel);
assert(Target && "Could not allocate target machine!");
return Target;
}