本文整理汇总了C++中SubtargetFeatures类的典型用法代码示例。如果您正苦于以下问题:C++ SubtargetFeatures类的具体用法?C++ SubtargetFeatures怎么用?C++ SubtargetFeatures使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SubtargetFeatures类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TheTriple
void CodeGen::initTargetMachine() {
TripleStr = M->getTargetTriple();
Triple TheTriple(TripleStr);
std::string ErrMsg;
TheTarget = TargetRegistry::lookupTarget(TripleStr, ErrMsg);
if (!TheTarget)
message(LDPL_FATAL, "Target not found: %s", ErrMsg.c_str());
SubtargetFeatures Features = getFeatures(TheTriple);
FeaturesString = Features.getString();
Options = InitTargetOptionsFromCodeGenFlags();
TM = createTargetMachine();
}
示例2: main
int main(int argc, char **argv) {
// The command line is unusual compared to other fuzzers due to the need to
// specify the target. Options like -triple, -mcpu, and -mattr work like
// their counterparts in llvm-mc, while -fuzzer-args collects options for the
// fuzzer itself.
//
// Examples:
//
// Fuzz the big-endian MIPS32R6 disassembler using 100,000 inputs of up to
// 4-bytes each and use the contents of ./corpus as the test corpus:
// llvm-mc-fuzzer -triple mips-linux-gnu -mcpu=mips32r6 -disassemble \
// -fuzzer-args -max_len=4 -runs=100000 ./corpus
//
// Infinitely fuzz the little-endian MIPS64R2 disassembler with the MSA
// feature enabled using up to 64-byte inputs:
// llvm-mc-fuzzer -triple mipsel-linux-gnu -mcpu=mips64r2 -mattr=msa \
// -disassemble -fuzzer-args ./corpus
//
// If your aim is to find instructions that are not tested, then it is
// advisable to constrain the maximum input size to a single instruction
// using -max_len as in the first example. This results in a test corpus of
// individual instructions that test unique paths. Without this constraint,
// there will be considerable redundancy in the corpus.
LLVMInitializeAllTargetInfos();
LLVMInitializeAllTargetMCs();
LLVMInitializeAllDisassemblers();
cl::ParseCommandLineOptions(argc, argv);
// Package up features to be passed to target/subtarget
// We have to pass it via a global since the callback doesn't
// permit any user data.
if (MAttrs.size()) {
SubtargetFeatures Features;
for (unsigned i = 0; i != MAttrs.size(); ++i)
Features.AddFeature(MAttrs[i]);
FeaturesStr = Features.getString();
}
if (Action == AC_Assemble)
errs() << "error: -assemble is not implemented\n";
else if (Action == AC_Disassemble)
return fuzzer::FuzzerDriver(argc, argv, DisassembleOneInput);
llvm_unreachable("Unknown action");
return 1;
}
示例3: Triple
bool LTOCodeGenerator::determineTarget(std::string& errMsg) {
if (_target != NULL)
return false;
std::string TripleStr = _linker.getModule()->getTargetTriple();
if (TripleStr.empty())
TripleStr = sys::getDefaultTargetTriple();
llvm::Triple Triple(TripleStr);
// create target machine from info for merged modules
const Target *march = TargetRegistry::lookupTarget(TripleStr, errMsg);
if (march == NULL)
return true;
// The relocation model is actually a static member of TargetMachine and
// needs to be set before the TargetMachine is instantiated.
Reloc::Model RelocModel = Reloc::Default;
switch (_codeModel) {
case LTO_CODEGEN_PIC_MODEL_STATIC:
RelocModel = Reloc::Static;
break;
case LTO_CODEGEN_PIC_MODEL_DYNAMIC:
RelocModel = Reloc::PIC_;
break;
case LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC:
RelocModel = Reloc::DynamicNoPIC;
break;
}
// construct LTOModule, hand over ownership of module and target
SubtargetFeatures Features;
Features.getDefaultSubtargetFeatures(Triple);
std::string FeatureStr = Features.getString();
// Set a default CPU for Darwin triples.
if (_mCpu.empty() && Triple.isOSDarwin()) {
if (Triple.getArch() == llvm::Triple::x86_64)
_mCpu = "core2";
else if (Triple.getArch() == llvm::Triple::x86)
_mCpu = "yonah";
}
TargetOptions Options;
LTOModule::getTargetOptions(Options);
_target = march->createTargetMachine(TripleStr, _mCpu, FeatureStr, Options,
RelocModel, CodeModel::Default,
CodeGenOpt::Aggressive);
return false;
}
示例4: GetTargetMachine
// Returns the TargetMachine instance or zero if no triple is provided.
static TargetMachine* GetTargetMachine(Triple TheTriple) {
std::string Error;
// @LOCALMOD-BEGIN: Some optimization passes like SimplifyCFG do nice
// things for code size, but only do it if the TTI says it is okay.
// For now, use the ARM TTI for LE32 until we have an LE32 TTI.
// https://code.google.com/p/nativeclient/issues/detail?id=2554
if (TheTriple.getArch() == Triple::le32) {
TheTriple.setArchName("armv7a");
}
// @LOCALMOD-END
const Target *TheTarget = TargetRegistry::lookupTarget(MArch, TheTriple,
Error);
// Some modules don't specify a triple, and this is okay.
if (!TheTarget) {
return nullptr;
}
// Package up features to be passed to target/subtarget
std::string FeaturesStr;
if (MAttrs.size() || 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 (MCPU == "native")
MCPU = sys::getHostCPUName();
return TheTarget->createTargetMachine(TheTriple.getTriple(),
MCPU, FeaturesStr,
InitTargetOptionsFromCodeGenFlags(),
RelocModel, CMModel,
GetCodeGenOptLevel());
}
示例5: TheTriple
void CodeGen::initTargetMachine() {
const std::string &TripleStr = M->getTargetTriple();
Triple TheTriple(TripleStr);
std::string ErrMsg;
const Target *TheTarget = TargetRegistry::lookupTarget(TripleStr, ErrMsg);
if (!TheTarget)
message(LDPL_FATAL, "Target not found: %s", ErrMsg.c_str());
SubtargetFeatures Features = getFeatures(TheTriple);
TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
CodeGenOpt::Level CGOptLevel = getCGOptLevel();
TM.reset(TheTarget->createTargetMachine(
TripleStr, options::mcpu, Features.getString(), Options, RelocationModel,
CodeModel::Default, CGOptLevel));
}
示例6: parseBitcodeFileImpl
ErrorOr<std::unique_ptr<LTOModule>>
LTOModule::makeLTOModule(MemoryBufferRef Buffer, const TargetOptions &options,
LLVMContext &Context, bool ShouldBeLazy) {
ErrorOr<std::unique_ptr<Module>> MOrErr =
parseBitcodeFileImpl(Buffer, Context, ShouldBeLazy);
if (std::error_code EC = MOrErr.getError())
return EC;
std::unique_ptr<Module> &M = *MOrErr;
std::string TripleStr = M->getTargetTriple();
if (TripleStr.empty())
TripleStr = sys::getDefaultTargetTriple();
llvm::Triple Triple(TripleStr);
// find machine architecture for this module
std::string errMsg;
const Target *march = TargetRegistry::lookupTarget(TripleStr, errMsg);
if (!march)
return std::unique_ptr<LTOModule>(nullptr);
// construct LTOModule, hand over ownership of module and target
SubtargetFeatures Features;
Features.getDefaultSubtargetFeatures(Triple);
std::string FeatureStr = Features.getString();
// Set a default CPU for Darwin triples.
std::string CPU;
if (Triple.isOSDarwin()) {
if (Triple.getArch() == llvm::Triple::x86_64)
CPU = "core2";
else if (Triple.getArch() == llvm::Triple::x86)
CPU = "yonah";
else if (Triple.getArch() == llvm::Triple::aarch64)
CPU = "cyclone";
}
TargetMachine *target =
march->createTargetMachine(TripleStr, CPU, FeatureStr, options, None);
M->setDataLayout(target->createDataLayout());
std::unique_ptr<LTOModule> Ret(new LTOModule(std::move(M), Buffer, target));
Ret->parseSymbols();
Ret->parseMetadata();
return std::move(Ret);
}
示例7: InitializeAllTargets
LTOModule *LTOModule::makeLTOModule(MemoryBuffer *buffer,
std::string &errMsg) {
static bool Initialized = false;
if (!Initialized) {
InitializeAllTargets();
InitializeAllTargetMCs();
InitializeAllAsmParsers();
Initialized = true;
}
// parse bitcode buffer
OwningPtr<Module> m(getLazyBitcodeModule(buffer, getGlobalContext(),
&errMsg));
if (!m) {
delete buffer;
return NULL;
}
std::string Triple = m->getTargetTriple();
if (Triple.empty())
Triple = sys::getDefaultTargetTriple();
// find machine architecture for this module
const Target *march = TargetRegistry::lookupTarget(Triple, errMsg);
if (!march)
return NULL;
// construct LTOModule, hand over ownership of module and target
SubtargetFeatures Features;
Features.getDefaultSubtargetFeatures(llvm::Triple(Triple));
std::string FeatureStr = Features.getString();
std::string CPU;
TargetOptions Options;
getTargetOptions(Options);
TargetMachine *target = march->createTargetMachine(Triple, CPU, FeatureStr,
Options);
LTOModule *Ret = new LTOModule(m.take(), target);
if (Ret->parseSymbols(errMsg)) {
delete Ret;
return NULL;
}
return Ret;
}
示例8: m
LTOModule *LTOModule::makeLTOModule(MemoryBuffer *buffer,
TargetOptions options,
std::string &errMsg) {
// parse bitcode buffer
OwningPtr<Module> m(getLazyBitcodeModule(buffer, getGlobalContext(),
&errMsg));
if (!m) {
delete buffer;
return NULL;
}
std::string TripleStr = m->getTargetTriple();
if (TripleStr.empty())
TripleStr = sys::getDefaultTargetTriple();
llvm::Triple Triple(TripleStr);
// find machine architecture for this module
const Target *march = TargetRegistry::lookupTarget(TripleStr, errMsg);
if (!march)
return NULL;
// construct LTOModule, hand over ownership of module and target
SubtargetFeatures Features;
Features.getDefaultSubtargetFeatures(Triple);
std::string FeatureStr = Features.getString();
// Set a default CPU for Darwin triples.
std::string CPU;
if (Triple.isOSDarwin()) {
if (Triple.getArch() == llvm::Triple::x86_64)
CPU = "core2";
else if (Triple.getArch() == llvm::Triple::x86)
CPU = "yonah";
}
TargetMachine *target = march->createTargetMachine(TripleStr, CPU, FeatureStr,
options);
LTOModule *Ret = new LTOModule(m.take(), target);
if (Ret->parseSymbols(errMsg)) {
delete Ret;
return NULL;
}
return Ret;
}
示例9: LLVMCreateTargetMachine
LLVMTargetMachineRef LLVMCreateTargetMachine(const char* cpu, const char* triple, const char** feats, size_t nfeats)
{
// based on LDC code
// find target from the given triple and cpu
const Target* target = NULL;
for (TargetRegistry::iterator it = TargetRegistry::begin(),
ie = TargetRegistry::end(); it != ie; ++it)
{
#if 0
printf("cpu: %s target: %s\n", cpu, it->getName());
#endif
if (strcmp(cpu, it->getName()) == 0)
{
target = &*it;
break;
}
}
assert(target != NULL);
// add any features the user might have provided
Twine twine;
SubtargetFeatures features;
//features.setCPU(cpu);
for (size_t i = 0; i < nfeats; ++i)
{
features.AddFeature(feats[i]);
twine = twine.concat(features.getString());
}
// create machine
TargetMachine* targetMachine = target->createTargetMachine(triple, twine.str());
if (!targetMachine)
return NULL;
return wrap(targetMachine);
}
示例10: GetTargetMachine
// Returns the TargetMachine instance or zero if no triple is provided.
static TargetMachine* GetTargetMachine(Triple TheTriple) {
std::string Error;
const Target *TheTarget = TargetRegistry::lookupTarget(MArch, TheTriple,
Error);
// Some modules don't specify a triple, and this is okay.
if (!TheTarget) {
return nullptr;
}
// Package up features to be passed to target/subtarget
std::string FeaturesStr;
if (MAttrs.size() || 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 (MCPU == "native")
MCPU = sys::getHostCPUName();
return TheTarget->createTargetMachine(TheTriple.getTriple(),
MCPU, FeaturesStr,
InitTargetOptionsFromCodeGenFlags(),
RelocModel, CMModel,
GetCodeGenOptLevel());
}
示例11: assert
TargetMachine *EmitAssemblyHelper::CreateTargetMachine(bool MustCreateTM) {
// Create the TargetMachine for generating code.
std::string Error;
std::string Triple = TheModule->getTargetTriple();
const llvm::Target *TheTarget = TargetRegistry::lookupTarget(Triple, Error);
if (!TheTarget) {
if (MustCreateTM)
Diags.Report(diag::err_fe_unable_to_create_target) << Error;
return nullptr;
}
unsigned CodeModel =
llvm::StringSwitch<unsigned>(CodeGenOpts.CodeModel)
.Case("small", llvm::CodeModel::Small)
.Case("kernel", llvm::CodeModel::Kernel)
.Case("medium", llvm::CodeModel::Medium)
.Case("large", llvm::CodeModel::Large)
.Case("default", llvm::CodeModel::Default)
.Default(~0u);
assert(CodeModel != ~0u && "invalid code model!");
llvm::CodeModel::Model CM = static_cast<llvm::CodeModel::Model>(CodeModel);
SmallVector<const char *, 16> BackendArgs;
BackendArgs.push_back("clang"); // Fake program name.
if (!CodeGenOpts.DebugPass.empty()) {
BackendArgs.push_back("-debug-pass");
BackendArgs.push_back(CodeGenOpts.DebugPass.c_str());
}
if (!CodeGenOpts.LimitFloatPrecision.empty()) {
BackendArgs.push_back("-limit-float-precision");
BackendArgs.push_back(CodeGenOpts.LimitFloatPrecision.c_str());
}
for (const std::string &BackendOption : CodeGenOpts.BackendOptions)
BackendArgs.push_back(BackendOption.c_str());
BackendArgs.push_back(nullptr);
llvm::cl::ParseCommandLineOptions(BackendArgs.size() - 1,
BackendArgs.data());
std::string FeaturesStr;
if (!TargetOpts.Features.empty()) {
SubtargetFeatures Features;
for (const std::string &Feature : TargetOpts.Features)
Features.AddFeature(Feature);
FeaturesStr = Features.getString();
}
llvm::Reloc::Model RM = llvm::Reloc::Default;
if (CodeGenOpts.RelocationModel == "static") {
RM = llvm::Reloc::Static;
} else if (CodeGenOpts.RelocationModel == "pic") {
RM = llvm::Reloc::PIC_;
} else {
assert(CodeGenOpts.RelocationModel == "dynamic-no-pic" &&
"Invalid PIC model!");
RM = llvm::Reloc::DynamicNoPIC;
}
CodeGenOpt::Level OptLevel = CodeGenOpt::Default;
switch (CodeGenOpts.OptimizationLevel) {
default: break;
case 0: OptLevel = CodeGenOpt::None; break;
case 3: OptLevel = CodeGenOpt::Aggressive; break;
}
llvm::TargetOptions Options;
if (!TargetOpts.Reciprocals.empty())
Options.Reciprocals = TargetRecip(TargetOpts.Reciprocals);
Options.ThreadModel =
llvm::StringSwitch<llvm::ThreadModel::Model>(CodeGenOpts.ThreadModel)
.Case("posix", llvm::ThreadModel::POSIX)
.Case("single", llvm::ThreadModel::Single);
if (CodeGenOpts.DisableIntegratedAS)
Options.DisableIntegratedAS = true;
if (CodeGenOpts.CompressDebugSections)
Options.CompressDebugSections = true;
if (CodeGenOpts.UseInitArray)
Options.UseInitArray = true;
// Set float ABI type.
if (CodeGenOpts.FloatABI == "soft" || CodeGenOpts.FloatABI == "softfp")
Options.FloatABIType = llvm::FloatABI::Soft;
else if (CodeGenOpts.FloatABI == "hard")
Options.FloatABIType = llvm::FloatABI::Hard;
else {
assert(CodeGenOpts.FloatABI.empty() && "Invalid float abi!");
Options.FloatABIType = llvm::FloatABI::Default;
}
// Set FP fusion mode.
switch (CodeGenOpts.getFPContractMode()) {
case CodeGenOptions::FPC_Off:
Options.AllowFPOpFusion = llvm::FPOpFusion::Strict;
break;
case CodeGenOptions::FPC_On:
Options.AllowFPOpFusion = llvm::FPOpFusion::Standard;
//.........这里部分代码省略.........
示例12: compileModule
static int compileModule(char **argv, LLVMContext &Context) {
// Load the module to be compiled...
SMDiagnostic Err;
std::auto_ptr<Module> M;
Module *mod = 0;
Triple TheTriple;
bool SkipModule = MCPU == "help" ||
(!MAttrs.empty() && MAttrs.front() == "help");
// If user just wants to list available options, skip module loading
if (!SkipModule) {
M.reset(ParseIRFile(InputFilename, Err, Context));
mod = M.get();
if (mod == 0) {
Err.print(argv[0], errs());
return 1;
}
// If we are supposed to override the target triple, do so now.
if (!TargetTriple.empty())
mod->setTargetTriple(Triple::normalize(TargetTriple));
TheTriple = Triple(mod->getTargetTriple());
} else {
TheTriple = Triple(Triple::normalize(TargetTriple));
}
if (TheTriple.getTriple().empty())
TheTriple.setTriple(sys::getDefaultTargetTriple());
// Get the target specific parser.
std::string Error;
const Target *TheTarget = TargetRegistry::lookupTarget(MArch, TheTriple,
Error);
if (!TheTarget) {
errs() << argv[0] << ": " << Error;
return 1;
}
// Package up features to be passed to target/subtarget
std::string FeaturesStr;
if (MAttrs.size()) {
SubtargetFeatures Features;
for (unsigned i = 0; i != MAttrs.size(); ++i)
Features.AddFeature(MAttrs[i]);
FeaturesStr = Features.getString();
}
CodeGenOpt::Level OLvl = CodeGenOpt::Default;
switch (OptLevel) {
default:
errs() << argv[0] << ": invalid optimization level.\n";
return 1;
case ' ': break;
case '0': OLvl = CodeGenOpt::None; break;
case '1': OLvl = CodeGenOpt::Less; break;
case '2': OLvl = CodeGenOpt::Default; break;
case '3': OLvl = CodeGenOpt::Aggressive; break;
}
TargetOptions Options;
Options.LessPreciseFPMADOption = EnableFPMAD;
Options.NoFramePointerElim = DisableFPElim;
Options.NoFramePointerElimNonLeaf = DisableFPElimNonLeaf;
Options.AllowFPOpFusion = FuseFPOps;
Options.UnsafeFPMath = EnableUnsafeFPMath;
Options.NoInfsFPMath = EnableNoInfsFPMath;
Options.NoNaNsFPMath = EnableNoNaNsFPMath;
Options.HonorSignDependentRoundingFPMathOption =
EnableHonorSignDependentRoundingFPMath;
Options.UseSoftFloat = GenerateSoftFloatCalls;
if (FloatABIForCalls != FloatABI::Default)
Options.FloatABIType = FloatABIForCalls;
Options.NoZerosInBSS = DontPlaceZerosInBSS;
Options.GuaranteedTailCallOpt = EnableGuaranteedTailCallOpt;
Options.DisableTailCalls = DisableTailCalls;
Options.StackAlignmentOverride = OverrideStackAlignment;
Options.RealignStack = EnableRealignStack;
Options.TrapFuncName = TrapFuncName;
Options.PositionIndependentExecutable = EnablePIE;
Options.EnableSegmentedStacks = SegmentedStacks;
Options.UseInitArray = UseInitArray;
Options.SSPBufferSize = SSPBufferSize;
std::auto_ptr<TargetMachine>
target(TheTarget->createTargetMachine(TheTriple.getTriple(),
MCPU, FeaturesStr, Options,
RelocModel, CMModel, OLvl));
assert(target.get() && "Could not allocate target machine!");
assert(mod && "Should have exited after outputting help!");
TargetMachine &Target = *target.get();
if (DisableDotLoc)
Target.setMCUseLoc(false);
if (DisableCFI)
Target.setMCUseCFI(false);
if (EnableDwarfDirectory)
Target.setMCUseDwarfDirectory(true);
//.........这里部分代码省略.........
示例13: ToggleFeature
/// ToggleFeature - Toggle a feature and returns the re-computed feature
/// bits. This version will also change all implied bits.
uint64_t MCSubtargetInfo::ToggleFeature(StringRef FS) {
SubtargetFeatures Features;
FeatureBits = Features.ToggleFeature(FeatureBits, FS,
ProcFeatures, NumFeatures);
return FeatureBits;
}
示例14: codegen
static void codegen(std::unique_ptr<Module> M) {
const std::string &TripleStr = M->getTargetTriple();
Triple TheTriple(TripleStr);
std::string ErrMsg;
const Target *TheTarget = TargetRegistry::lookupTarget(TripleStr, ErrMsg);
if (!TheTarget)
message(LDPL_FATAL, "Target not found: %s", ErrMsg.c_str());
if (unsigned NumOpts = options::extra.size())
cl::ParseCommandLineOptions(NumOpts, &options::extra[0]);
SubtargetFeatures Features;
Features.getDefaultSubtargetFeatures(TheTriple);
for (const std::string &A : MAttrs)
Features.AddFeature(A);
TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
CodeGenOpt::Level CGOptLevel;
switch (options::OptLevel) {
case 0:
CGOptLevel = CodeGenOpt::None;
break;
case 1:
CGOptLevel = CodeGenOpt::Less;
break;
case 2:
CGOptLevel = CodeGenOpt::Default;
break;
case 3:
CGOptLevel = CodeGenOpt::Aggressive;
break;
}
std::unique_ptr<TargetMachine> TM(TheTarget->createTargetMachine(
TripleStr, options::mcpu, Features.getString(), Options, RelocationModel,
CodeModel::Default, CGOptLevel));
runLTOPasses(*M, *TM);
if (options::TheOutputType == options::OT_SAVE_TEMPS)
saveBCFile(output_name + ".opt.bc", *M);
SmallString<128> Filename;
if (!options::obj_path.empty())
Filename = options::obj_path;
else if (options::TheOutputType == options::OT_SAVE_TEMPS)
Filename = output_name + ".o";
std::vector<SmallString<128>> Filenames(options::Parallelism);
bool TempOutFile = Filename.empty();
{
// Open a file descriptor for each backend thread. This is done in a block
// so that the output file descriptors are closed before gold opens them.
std::list<llvm::raw_fd_ostream> OSs;
std::vector<llvm::raw_pwrite_stream *> OSPtrs(options::Parallelism);
for (unsigned I = 0; I != options::Parallelism; ++I) {
int FD;
if (TempOutFile) {
std::error_code EC =
sys::fs::createTemporaryFile("lto-llvm", "o", FD, Filenames[I]);
if (EC)
message(LDPL_FATAL, "Could not create temporary file: %s",
EC.message().c_str());
} else {
Filenames[I] = Filename;
if (options::Parallelism != 1)
Filenames[I] += utostr(I);
std::error_code EC =
sys::fs::openFileForWrite(Filenames[I], FD, sys::fs::F_None);
if (EC)
message(LDPL_FATAL, "Could not open file: %s", EC.message().c_str());
}
OSs.emplace_back(FD, true);
OSPtrs[I] = &OSs.back();
}
// Run backend threads.
splitCodeGen(std::move(M), OSPtrs, options::mcpu, Features.getString(),
Options, RelocationModel, CodeModel::Default, CGOptLevel);
}
for (auto &Filename : Filenames) {
if (add_input_file(Filename.c_str()) != LDPS_OK)
message(LDPL_FATAL,
"Unable to add .o file to the link. File left behind in: %s",
Filename.c_str());
if (TempOutFile)
Cleanup.push_back(Filename.c_str());
}
}
示例15: compileModule
static int compileModule(char **argv, LLVMContext &Context) {
// Load the module to be compiled...
SMDiagnostic Err;
std::unique_ptr<Module> M;
Module *mod = 0;
Triple TheTriple;
bool SkipModule = MCPU == "help" ||
(!MAttrs.empty() && MAttrs.front() == "help");
// If user just wants to list available options, skip module loading
if (!SkipModule) {
M = parseIRFile(InputFilename, Err, Context);
mod = M.get();
if (mod == 0) {
Err.print(argv[0], errs());
return 1;
}
// If we are supposed to override the target triple, do so now.
if (!TargetTriple.empty())
mod->setTargetTriple(Triple::normalize(TargetTriple));
TheTriple = Triple(mod->getTargetTriple());
} else {
TheTriple = Triple(Triple::normalize(TargetTriple));
}
if (TheTriple.getTriple().empty())
TheTriple.setTriple(sys::getDefaultTargetTriple());
// Get the target specific parser.
std::string Error;
// Override MArch
MArch = "c";
const Target *TheTarget = TargetRegistry::lookupTarget(MArch, TheTriple,
Error);
if (!TheTarget) {
errs() << argv[0] << ": " << Error;
return 1;
}
// Package up features to be passed to target/subtarget
std::string FeaturesStr;
if (MAttrs.size()) {
SubtargetFeatures Features;
for (unsigned i = 0; i != MAttrs.size(); ++i)
Features.AddFeature(MAttrs[i]);
FeaturesStr = Features.getString();
}
CodeGenOpt::Level OLvl = CodeGenOpt::Default;
switch (OptLevel) {
default:
errs() << argv[0] << ": invalid optimization level.\n";
return 1;
case ' ': break;
case '0': OLvl = CodeGenOpt::None; break;
case '1': OLvl = CodeGenOpt::Less; break;
case '2': OLvl = CodeGenOpt::Default; break;
case '3': OLvl = CodeGenOpt::Aggressive; break;
}
TargetOptions Options;
Options.LessPreciseFPMADOption = EnableFPMAD;
Options.AllowFPOpFusion = FuseFPOps;
Options.UnsafeFPMath = EnableUnsafeFPMath;
Options.NoInfsFPMath = EnableNoInfsFPMath;
Options.NoNaNsFPMath = EnableNoNaNsFPMath;
Options.HonorSignDependentRoundingFPMathOption =
EnableHonorSignDependentRoundingFPMath;
if (FloatABIForCalls != FloatABI::Default)
Options.FloatABIType = FloatABIForCalls;
Options.NoZerosInBSS = DontPlaceZerosInBSS;
Options.GuaranteedTailCallOpt = EnableGuaranteedTailCallOpt;
Options.StackAlignmentOverride = OverrideStackAlignment;
Options.PositionIndependentExecutable = EnablePIE;
//Jackson Korba 9/30/14
//OwningPtr<targetMachine>
std::unique_ptr<TargetMachine>
target(TheTarget->createTargetMachine(TheTriple.getTriple(),
MCPU, FeaturesStr, Options,
RelocModel, CMModel, OLvl));
assert(target.get() && "Could not allocate target machine!");
assert(mod && "Should have exited after outputting help!");
TargetMachine &Target = *target.get();
// Disable .loc support for older OS X versions.
if (TheTriple.isMacOSX() &&
TheTriple.isMacOSXVersionLT(10, 6)){}
//TODO: Find a replacement to this function
/* Greg Simpson 6-09-13
no member named setMCUseLoc
removed statement
Target.setMCUseLoc(false); */
//Jackson Korba 9/30/14
//.........这里部分代码省略.........