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


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

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


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

示例1: LLVMFuzzerInitialize

int LLVMFuzzerInitialize(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.

  char **OriginalArgv = *argv;

  LLVMInitializeAllTargetInfos();
  LLVMInitializeAllTargetMCs();
  LLVMInitializeAllDisassemblers();

  cl::ParseCommandLineOptions(*argc, OriginalArgv);

  // Rebuild the argv without the arguments llvm-mc-fuzzer consumed so that
  // the driver can parse its arguments.
  //
  // FuzzerArgs cannot provide the non-const pointer that OriginalArgv needs.
  // Re-use the strings from OriginalArgv instead of copying FuzzerArg to a
  // non-const buffer to avoid the need to clean up when the fuzzer terminates.
  ModifiedArgv.push_back(OriginalArgv[0]);
  for (const auto &FuzzerArg : FuzzerArgs) {
    for (int i = 1; i < *argc; ++i) {
      if (FuzzerArg == OriginalArgv[i])
        ModifiedArgv.push_back(OriginalArgv[i]);
    }
  }
  *argc = ModifiedArgv.size();
  *argv = ModifiedArgv.data();

  // 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();
  }

  return 0;
}
开发者ID:anupam128,项目名称:llvm,代码行数:60,代码来源:llvm-mc-fuzzer.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: if

/// Get TargetMachine.
/// Use module M to find appropriate Target.
void
LTO::getTarget (Module *M) {

  if (Target)
    return;

  std::string Err;
  const TargetMachineRegistry::entry* March = 
    TargetMachineRegistry::getClosestStaticTargetForModule(*M, Err);
  
  if (March == 0)
    return;
  
  // Create target
  SubtargetFeatures Features;
  std::string FeatureStr;
  std::string TargetTriple = M->getTargetTriple();

  if (strncmp(TargetTriple.c_str(), "powerpc-apple-", 14) == 0) 
    Features.AddFeature("altivec", true);
  else if (strncmp(TargetTriple.c_str(), "powerpc64-apple-", 16) == 0) {
    Features.AddFeature("64bit", true);
    Features.AddFeature("altivec", true);
  }

  FeatureStr = Features.getString();
  Target = March->CtorFn(*M, FeatureStr);
}
开发者ID:marnen,项目名称:rubinius,代码行数:30,代码来源:lto.cpp

示例5: 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 0;
  }

  // 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();
  }

  return TheTarget->createTargetMachine(TheTriple.getTriple(),
                                        MCPU, FeaturesStr, GetTargetOptions(),
                                        RelocModel, CMModel,
                                        GetCodeGenOptLevel());
}
开发者ID:ehostunreach,项目名称:emscripten-fastcomp,代码行数:32,代码来源:opt.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(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

示例7: TheTriple

/// 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) {
    Triple TheTriple(TargetTriple);
    if (TheTriple.getTriple().empty())
        TheTriple.setTriple(sys::getDefaultTargetTriple());

    // Adjust the triple to match what the user requested.
    const Target *TheTarget = 0;
    if (!MArch.empty()) {
        for (TargetRegistry::iterator it = TargetRegistry::begin(),
                ie = TargetRegistry::end(); it != ie; ++it) {
            if (MArch == it->getName()) {
                TheTarget = &*it;
                break;
            }
        }

        if (!TheTarget) {
            if (ErrorStr)
                *ErrorStr = "No available targets are compatible with this -march, "
                            "see -version for the available targets.\n";
            return 0;
        }

        // Adjust the triple to match (if known), otherwise stick with the
        // requested/host triple.
        Triple::ArchType Type = Triple::getArchTypeForLLVMName(MArch);
        if (Type != Triple::UnknownArch)
            TheTriple.setArch(Type);
    } else {
        std::string Error;
        TheTarget = TargetRegistry::lookupTarget(TheTriple.getTriple(), Error);
        if (TheTarget == 0) {
            if (ErrorStr)
                *ErrorStr = Error;
            return 0;
        }
    }

    // Package up features to be passed to target/subtarget
    std::string FeaturesStr;
    if (!MAttrs.empty()) {
        SubtargetFeatures Features;
        for (unsigned i = 0; i != MAttrs.size(); ++i)
            Features.AddFeature(MAttrs[i]);
        FeaturesStr = Features.getString();
    }

    // Allocate a target...
    TargetMachine *Target = TheTarget->createTargetMachine(TheTriple.getTriple(),
                            MCPU, FeaturesStr,
                            Options,
                            RelocModel, CMModel,
                            OptLevel);
    assert(Target && "Could not allocate target machine!");
    return Target;
}
开发者ID:romix,项目名称:llvm,代码行数:61,代码来源:TargetSelect.cpp

示例8: runSplitCodeGen

void CodeGen::runSplitCodeGen(const SmallString<128> &BCFilename) {
  const std::string &TripleStr = M->getTargetTriple();
  Triple TheTriple(TripleStr);

  SubtargetFeatures Features = getFeatures(TheTriple);

  TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
  CodeGenOpt::Level CGOptLevel = getCGOptLevel();

  SmallString<128> Filename;
  // Note that openOutputFile will append a unique ID for each task
  if (!options::obj_path.empty())
    Filename = options::obj_path;
  else if (options::TheOutputType == options::OT_SAVE_TEMPS)
    Filename = output_name + ".o";

  // Note that the default parallelism is 1 instead of the
  // hardware_concurrency, as there are behavioral differences between
  // parallelism levels (e.g. symbol ordering will be different, and some uses
  // of inline asm currently have issues with parallelism >1).
  unsigned int MaxThreads = options::Parallelism ? options::Parallelism : 1;

  std::vector<SmallString<128>> Filenames(MaxThreads);
  std::vector<SmallString<128>> BCFilenames(MaxThreads);
  bool TempOutFile = Filename.empty();
  {
    // Open a file descriptor for each backend task. 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(MaxThreads);
    for (unsigned I = 0; I != MaxThreads; ++I) {
      int FD = openOutputFile(Filename, TempOutFile, Filenames[I],
                              // Only append ID if there are multiple tasks.
                              MaxThreads > 1 ? I : -1);
      OSs.emplace_back(FD, true);
      OSPtrs[I] = &OSs.back();
    }

    std::list<llvm::raw_fd_ostream> BCOSs;
    std::vector<llvm::raw_pwrite_stream *> BCOSPtrs;
    if (!BCFilename.empty() && MaxThreads > 1) {
      for (unsigned I = 0; I != MaxThreads; ++I) {
        int FD = openOutputFile(BCFilename, false, BCFilenames[I], I);
        BCOSs.emplace_back(FD, true);
        BCOSPtrs.push_back(&BCOSs.back());
      }
    }

    // Run backend tasks.
    splitCodeGen(std::move(M), OSPtrs, BCOSPtrs, options::mcpu, Features.getString(),
                 Options, RelocationModel, CodeModel::Default, CGOptLevel);
  }

  for (auto &Filename : Filenames)
    recordFile(Filename.c_str(), TempOutFile);
}
开发者ID:AlexDenisov,项目名称:llvm,代码行数:56,代码来源:gold-plugin.cpp

示例9: 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

示例10: strdup

char *LLVMZigGetNativeFeatures(void) {
    SubtargetFeatures features;

    StringMap<bool> host_features;
    if (sys::getHostCPUFeatures(host_features)) {
        for (auto &F : host_features)
            features.AddFeature(F.first(), F.second);
    }

    return strdup(features.getString().c_str());
}
开发者ID:MovingtoMars,项目名称:zig,代码行数:11,代码来源:zig_llvm.cpp

示例11: 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

示例12: 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

示例13: 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

示例14: 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();
  }

  // Insert the program name into the FuzzerArgv.
  FuzzerArgv.insert(FuzzerArgv.begin(), argv[0]);

  if (Action == AC_Assemble)
    errs() << "error: -assemble is not implemented\n";
  else if (Action == AC_Disassemble)
    return fuzzer::FuzzerDriver(FuzzerArgv, DisassembleOneInput);

  llvm_unreachable("Unknown action");
  return 1;
}
开发者ID:r0mai,项目名称:llvm,代码行数:51,代码来源:llvm-mc-fuzzer.cpp

示例15: 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


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