当前位置: 首页>>代码示例>>C++>>正文


C++ SubtargetFeatures::getDefaultSubtargetFeatures方法代码示例

本文整理汇总了C++中SubtargetFeatures::getDefaultSubtargetFeatures方法的典型用法代码示例。如果您正苦于以下问题:C++ SubtargetFeatures::getDefaultSubtargetFeatures方法的具体用法?C++ SubtargetFeatures::getDefaultSubtargetFeatures怎么用?C++ SubtargetFeatures::getDefaultSubtargetFeatures使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SubtargetFeatures的用法示例。


在下文中一共展示了SubtargetFeatures::getDefaultSubtargetFeatures方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getFeatures

static SubtargetFeatures getFeatures(Triple &TheTriple) {
  SubtargetFeatures Features;
  Features.getDefaultSubtargetFeatures(TheTriple);
  for (const std::string &A : MAttrs)
    Features.AddFeature(A);
  return Features;
}
开发者ID:MaheshSinghSawant,项目名称:llvm,代码行数:7,代码来源:gold-plugin.cpp

示例2: determineTarget

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);

  CodeGenOpt::Level OLvl = CodeGenOpt::Aggressive;
  switch (OptLevel) {
  default:
    errs() << OptLevel << ": 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;
  }

  _target = march->createTargetMachine(TripleStr, _mCpu, FeatureStr, Options,
                                       RelocModel, CodeModel::Default,
                                       OLvl);
  return false;
}
开发者ID:smowton,项目名称:llpe,代码行数:60,代码来源:LTOCodeGenerator.cpp

示例3: determineTarget

bool LTOCodeGenerator::determineTarget(std::string& errMsg)
{
    if ( _target == NULL ) {
        std::string Triple = _linker.getModule()->getTargetTriple();
        if (Triple.empty())
          Triple = sys::getHostTriple();

        // create target machine from info for merged modules
        const Target *march = TargetRegistry::lookupTarget(Triple, 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.
        switch( _codeModel ) {
        case LTO_CODEGEN_PIC_MODEL_STATIC:
            TargetMachine::setRelocationModel(Reloc::Static);
            break;
        case LTO_CODEGEN_PIC_MODEL_DYNAMIC:
            TargetMachine::setRelocationModel(Reloc::PIC_);
            break;
        case LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC:
            TargetMachine::setRelocationModel(Reloc::DynamicNoPIC);
            break;
        }

        // construct LTModule, hand over ownership of module and target
        SubtargetFeatures Features;
        Features.getDefaultSubtargetFeatures(_mCpu, llvm::Triple(Triple));
        std::string FeatureStr = Features.getString();
        _target = march->createTargetMachine(Triple, FeatureStr);
    }
    return false;
}
开发者ID:dmlap,项目名称:llvm-js-backend,代码行数:34,代码来源:LTOCodeGenerator.cpp

示例4: Triple

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(ParseBitcodeFile(buffer, getGlobalContext(), // @LOCALMOD
                                           &errMsg));
  if (!m) {
    delete buffer;
    return NULL;
  }

  std::string TripleStr = m->getTargetTriple();
  // @LOCALMOD-BEGIN
  // Pretend that we are ARM for name mangling and assembly conventions.
  // https://code.google.com/p/nativeclient/issues/detail?id=2554
  if (TripleStr == "le32-unknown-nacl") {
    TripleStr = "armv7a-none-nacl-gnueabi";
  }
  // @LOCALMOD-END
  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";
  }
  TargetOptions Options;
  getTargetOptions(Options);
  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;
}
开发者ID:NWilson,项目名称:emscripten-fastcomp,代码行数:59,代码来源:LTOModule.cpp

示例5: Triple

LTOModule *LTOModule::makeLTOModule(std::unique_ptr<MemoryBuffer> Buffer,
                                    TargetOptions options,
                                    std::string &errMsg) {
  ErrorOr<Module *> MOrErr =
      getLazyBitcodeModule(Buffer.get(), getGlobalContext());
  if (std::error_code EC = MOrErr.getError()) {
    errMsg = EC.message();
    return nullptr;
  }
  std::unique_ptr<Module> M(MOrErr.get());

  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 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::arm64 ||
             Triple.getArch() == llvm::Triple::aarch64)
      CPU = "cyclone";
  }

  TargetMachine *target = march->createTargetMachine(TripleStr, CPU, FeatureStr,
                                                     options);
  M->materializeAllPermanently(true);
  M->setDataLayout(target->getDataLayout());

  std::unique_ptr<object::IRObjectFile> IRObj(
      new object::IRObjectFile(std::move(Buffer), std::move(M)));

  LTOModule *Ret = new LTOModule(std::move(IRObj), target);

  if (Ret->parseSymbols(errMsg)) {
    delete Ret;
    return nullptr;
  }

  Ret->parseMetadata();

  return Ret;
}
开发者ID:0xDEC0DE8,项目名称:mcsema,代码行数:56,代码来源:LTOModule.cpp

示例6: Triple

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 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";
    }
    TargetOptions Options;
    getTargetOptions(Options);
    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;
}
开发者ID:Jerdak,项目名称:llvm-mirror,代码行数:52,代码来源:LTOModule.cpp

示例7: determineTarget

bool LTOCodeGenerator::determineTarget(std::string &errMsg) {
    if (_target != NULL)
        return false;

    // if options were requested, set them
    if (!_codegenOptions.empty())
        cl::ParseCommandLineOptions(_codegenOptions.size(),
                                    const_cast<char **>(&_codegenOptions[0]));

    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;
}
开发者ID:Jerdak,项目名称:llvm-mirror,代码行数:52,代码来源:LTOCodeGenerator.cpp

示例8: determineTarget

bool LTOCodeGenerator::determineTarget(std::string &errMsg) {
  if (TargetMach != NULL)
    return true;

  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 false;

  // 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;
  case LTO_CODEGEN_PIC_MODEL_DEFAULT:
    // RelocModel is already the default, so leave it that way.
    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";
    else if (Triple.getArch() == llvm::Triple::arm64)
      MCpu = "cyclone";
  }

  TargetMach = march->createTargetMachine(TripleStr, MCpu, FeatureStr, Options,
                                          RelocModel, CodeModel::Default,
                                          CodeGenOpt::Aggressive);
  return true;
}
开发者ID:arsenm,项目名称:llvm,代码行数:51,代码来源:LTOCodeGenerator.cpp

示例9: Triple

LTOModule *LTOModule::makeLTOModule(MemoryBuffer *buffer,
                                    TargetOptions options,
                                    std::string &errMsg) {
  // parse bitcode buffer
  ErrorOr<Module *> ModuleOrErr =
      getLazyBitcodeModule(buffer, getGlobalContext());
  if (error_code EC = ModuleOrErr.getError()) {
    errMsg = EC.message();
    delete buffer;
    return NULL;
  }
  OwningPtr<Module> m(ModuleOrErr.get());

  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);
  m->materializeAllPermanently();

  LTOModule *Ret = new LTOModule(m.take(), target);
  if (Ret->parseSymbols(errMsg)) {
    delete Ret;
    return NULL;
  }

  Ret->parseMetadata();

  return Ret;
}
开发者ID:iamleeg,项目名称:llvm,代码行数:50,代码来源:LTOModule.cpp

示例10: Triple

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);
}
开发者ID:anupam128,项目名称:llvm,代码行数:45,代码来源:LTOModule.cpp

示例11: 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;
  TargetMachine *target = march->createTargetMachine(Triple, CPU, FeatureStr);
  LTOModule *Ret = new LTOModule(m.take(), target);
  if (Ret->ParseSymbols(errMsg)) {
    delete Ret;
    return NULL;
  }

  return Ret;
}
开发者ID:Bootz,项目名称:multicore-opimization,代码行数:41,代码来源:LTOModule.cpp

示例12: Triple

LTOModule *LTOModule::makeLTOModule(MemoryBuffer *buffer,
                                    TargetOptions options,
                                    std::string &errMsg) {
  // parse bitcode buffer
  ErrorOr<Module *> ModuleOrErr =
      getLazyBitcodeModule(buffer, getGlobalContext());
  if (std::error_code EC = ModuleOrErr.getError()) {
    errMsg = EC.message();
    delete buffer;
    return nullptr;
  }
  std::unique_ptr<Module> m(ModuleOrErr.get());

  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 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::arm64 ||
             Triple.getArch() == llvm::Triple::aarch64)
      CPU = "cyclone";
  }

  TargetMachine *target = march->createTargetMachine(TripleStr, CPU, FeatureStr,
                                                     options);
  m->materializeAllPermanently();

  LTOModule *Ret = new LTOModule(m.release(), target);

  // We need a MCContext set up in order to get mangled names of private
  // symbols. It is a bit odd that we need to report uses and definitions
  // of private symbols, but it does look like ld64 expects to be informed
  // of at least the ones with an 'l' prefix.
  MCContext &Context = Ret->_context;
  const TargetLoweringObjectFile &TLOF =
      target->getTargetLowering()->getObjFileLowering();
  const_cast<TargetLoweringObjectFile &>(TLOF).Initialize(Context, *target);

  if (Ret->parseSymbols(errMsg)) {
    delete Ret;
    return nullptr;
  }

  Ret->parseMetadata();

  return Ret;
}
开发者ID:RandomInsano,项目名称:llvm-mos6502,代码行数:63,代码来源:LTOModule.cpp

示例13: jl_dump_function_asm

void jl_dump_function_asm(const char *Fptr, size_t Fsize,
#ifndef USE_MCJIT
                          std::vector<JITEvent_EmittedFunctionDetails::LineStart> lineinfo,
#else
                          const object::ObjectFile *objectfile,
#endif
                          formatted_raw_ostream &stream)
{
    // Initialize targets and assembly printers/parsers.
    // Avoids hard-coded targets - will generally be only host CPU anyway.
    llvm::InitializeNativeTargetAsmParser();
    llvm::InitializeNativeTargetDisassembler();

    // Get the host information
    std::string TripleName;
    if (TripleName.empty())
        TripleName = sys::getDefaultTargetTriple();
    Triple TheTriple(Triple::normalize(TripleName));

    std::string MCPU = sys::getHostCPUName();
    SubtargetFeatures Features;
    Features.getDefaultSubtargetFeatures(TheTriple);

    std::string err;
    const Target* TheTarget = TargetRegistry::lookupTarget(TripleName, err);

    // Set up required helpers and streamer
#ifdef LLVM35
    std::unique_ptr<MCStreamer> Streamer;
#else
    OwningPtr<MCStreamer> Streamer;
#endif
    SourceMgr SrcMgr;

#ifdef LLVM35
    std::unique_ptr<MCAsmInfo> MAI(TheTarget->createMCAsmInfo(*TheTarget->createMCRegInfo(TripleName),TripleName));
#elif defined(LLVM34)
    llvm::OwningPtr<MCAsmInfo> MAI(TheTarget->createMCAsmInfo(*TheTarget->createMCRegInfo(TripleName),TripleName));
#else
    llvm::OwningPtr<MCAsmInfo> MAI(TheTarget->createMCAsmInfo(TripleName));
#endif
    assert(MAI && "Unable to create target asm info!");

#ifdef LLVM35
    std::unique_ptr<MCRegisterInfo> MRI(TheTarget->createMCRegInfo(TripleName));
#else
    llvm::OwningPtr<MCRegisterInfo> MRI(TheTarget->createMCRegInfo(TripleName));
#endif
    assert(MRI && "Unable to create target register info!");

#ifdef LLVM35
    std::unique_ptr<MCObjectFileInfo> MOFI(new MCObjectFileInfo());
#else
    OwningPtr<MCObjectFileInfo> MOFI(new MCObjectFileInfo());
#endif
#ifdef LLVM34
    MCContext Ctx(MAI.get(), MRI.get(), MOFI.get(), &SrcMgr);
#else
    MCContext Ctx(*MAI, *MRI, MOFI.get(), &SrcMgr);
#endif
    MOFI->InitMCObjectFileInfo(TripleName, Reloc::Default, CodeModel::Default, Ctx);

    // Set up Subtarget and Disassembler
#ifdef LLVM35
    std::unique_ptr<MCSubtargetInfo>
        STI(TheTarget->createMCSubtargetInfo(TripleName, MCPU, Features.getString()));
    std::unique_ptr<MCDisassembler> DisAsm(TheTarget->createMCDisassembler(*STI, Ctx));
#else
    OwningPtr<MCSubtargetInfo>
        STI(TheTarget->createMCSubtargetInfo(TripleName, MCPU, Features.getString()));
    OwningPtr<MCDisassembler> DisAsm(TheTarget->createMCDisassembler(*STI));
#endif
    if (!DisAsm) {
        JL_PRINTF(JL_STDERR, "error: no disassembler for target", TripleName.c_str(), "\n");
        return;
    }

    unsigned OutputAsmVariant = 1;
    bool ShowEncoding = false;
    bool ShowInst = false;

#ifdef LLVM35
    std::unique_ptr<MCInstrInfo> MCII(TheTarget->createMCInstrInfo());
    std::unique_ptr<MCInstrAnalysis>
        MCIA(TheTarget->createMCInstrAnalysis(MCII.get()));
#else
    OwningPtr<MCInstrInfo> MCII(TheTarget->createMCInstrInfo());
    OwningPtr<MCInstrAnalysis>
        MCIA(TheTarget->createMCInstrAnalysis(MCII.get()));
#endif
    MCInstPrinter* IP =
        TheTarget->createMCInstPrinter(OutputAsmVariant, *MAI, *MCII, *MRI, *STI);
    MCCodeEmitter *CE = 0;
    MCAsmBackend *MAB = 0;
    if (ShowEncoding) {
        CE = TheTarget->createMCCodeEmitter(*MCII, *MRI, *STI, Ctx);
#ifdef LLVM34
        MAB = TheTarget->createMCAsmBackend(*MRI, TripleName, MCPU);
#else
        MAB = TheTarget->createMCAsmBackend(TripleName, MCPU);
//.........这里部分代码省略.........
开发者ID:Carreau,项目名称:julia,代码行数:101,代码来源:disasm.cpp

示例14: codegen

static void codegen(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);

  legacy::PassManager CodeGenPasses;

  SmallString<128> Filename;
  if (!options::obj_path.empty())
    Filename = options::obj_path;
  else if (options::TheOutputType == options::OT_SAVE_TEMPS)
    Filename = output_name + ".o";

  int FD;
  bool TempOutFile = Filename.empty();
  if (TempOutFile) {
    std::error_code EC =
        sys::fs::createTemporaryFile("lto-llvm", "o", FD, Filename);
    if (EC)
      message(LDPL_FATAL, "Could not create temporary file: %s",
              EC.message().c_str());
  } else {
    std::error_code EC =
        sys::fs::openFileForWrite(Filename.c_str(), FD, sys::fs::F_None);
    if (EC)
      message(LDPL_FATAL, "Could not open file: %s", EC.message().c_str());
  }

  {
    raw_fd_ostream OS(FD, true);

    if (TM->addPassesToEmitFile(CodeGenPasses, OS,
                                TargetMachine::CGFT_ObjectFile))
      message(LDPL_FATAL, "Failed to setup codegen");
    CodeGenPasses.run(M);
  }

  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());
}
开发者ID:EdwardBetts,项目名称:expert-disco,代码行数:82,代码来源:gold-plugin.cpp

示例15: Triple

LTOModule *LTOModule::makeLTOModule(MemoryBufferRef Buffer,
                                    TargetOptions options, std::string &errMsg,
                                    LLVMContext *Context) {
  std::unique_ptr<LLVMContext> OwnedContext;
  if (!Context) {
    OwnedContext = llvm::make_unique<LLVMContext>();
    Context = OwnedContext.get();
  }

  // If we own a context, we know this is being used only for symbol
  // extraction, not linking.  Be lazy in that case.
  std::unique_ptr<Module> M = parseBitcodeFileImpl(
      Buffer, *Context,
      /* ShouldBeLazy */ static_cast<bool>(OwnedContext), errMsg);
  if (!M)
    return nullptr;

  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 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);
  M->setDataLayout(*target->getDataLayout());

  std::unique_ptr<object::IRObjectFile> IRObj(
      new object::IRObjectFile(Buffer, std::move(M)));

  LTOModule *Ret;
  if (OwnedContext)
    Ret = new LTOModule(std::move(IRObj), target, std::move(OwnedContext));
  else
    Ret = new LTOModule(std::move(IRObj), target);

  if (Ret->parseSymbols(errMsg)) {
    delete Ret;
    return nullptr;
  }

  Ret->parseMetadata();

  return Ret;
}
开发者ID:EdwardBetts,项目名称:expert-disco,代码行数:64,代码来源:LTOModule.cpp


注:本文中的SubtargetFeatures::getDefaultSubtargetFeatures方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。