[LLVMdev] ARM opcode format

Guillermo Perez gaperez64 at gmail.com
Mon Feb 20 08:43:26 PST 2012


So the current JIT will be superseded by the MCJIT completely and no
further development should be expected for the current JIT? In any case, I
am definitely interested in submitting a patch if you could help me by
sending me in the right direction, since I really want this working.

I managed to reproduce this behavior in LLVM 3.0 by modifying llc to read
my .bc file and try to JIT the code for the mentioned Triple.

The error:

UNREACHABLE executed at
Stack dump:
0. Program arguments: ./bin/llc -mtriple armv7a-unknown-linux-gnueabi -O3
1. Running pass 'ARM Machine Code Emitter' on function '@execute'
Aborted (core dumped)

The code I modified for llc was:

//===-- llc.cpp - Implement the LLVM Native Code Generator
//                     The LLVM Compiler Infrastructure
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
// This is the llc code generator driver. It provides a convenient
// command-line interface for generating native assembly-language code
// or C code, given LLVM bitcode.
#include <iostream>
#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/PassManager.h"
#include "llvm/Pass.h"
#include "llvm/ADT/Triple.h"
#include "llvm/Support/IRReader.h"
#include "llvm/CodeGen/LinkAllAsmWriterComponents.h"
#include "llvm/CodeGen/LinkAllCodegenComponents.h"
#include "llvm/Config/config.h"
#include "llvm/MC/SubtargetFeature.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/PluginLoader.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/ToolOutputFile.h"
#include "llvm/Support/Host.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Target/TargetData.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/ExecutionEngine/JIT.h"
#include "llvm/Analysis/Passes.h"
#include "llvm/Transforms/Scalar.h"
#include <memory>
using namespace llvm;
  // Build up all of the passes that we want to do to the module.
  // PassManager PM;

  // Add the target data from the target machine, if it exists, or the
  //if (const TargetData *TD = Target.getTargetData())
  //  PM.add(new TargetData(*TD));
  //  PM.add(new TargetData(&mod));

  // Override default to generate verbose assembly.

  //if (RelaxAll) {
  //  if (FileType != TargetMachine::CGFT_ObjectFile)
  //    errs() << argv[0]
  //           << ": warning: ignoring -mc-relax-all because filetype !=
  //  else
  //    Target.setMCRelaxAll(true);

  //  formatted_raw_ostream FOS(Out->os());

    // Ask the target to add backend passes as necessary.
  //  if (Target.addPassesToEmitFile(PM, FOS, FileType, OLvl, NoVerify)) {
  //    errs() << argv[0] << ": target does not support generation of this"
  //           << " file type!\n";
  //    return 1;
  //  }

    // Before executing passes, print the final values of the LLVM options.
  //  cl::PrintOptionValues();

  //  PM.run(mod);

  // Declare success.

  // mods for cryo
    // create an execution engine to export code later
    EngineBuilder eBuilder(&mod);
    std::string error;
    ExecutionEngine *TheExecutionEngine = eBuilder.create();
    if(!TheExecutionEngine) {
        return 1;

    // compile and return function pointer
    FunctionPassManager OurFPM(&mod);
    // Start with registering info about how the
    // target lays out data structures.
    OurFPM.add(new TargetData(*TheExecutionEngine->getTargetData()));
    // Provide basic AliasAnalysis support for GVN.
    // Do simple "peephole" optimizations and bit-twiddling optzns.
    // Reassociate expressions.
    // Eliminate Common SubExpressions.
    // Simplify the control flow graph (deleting unreachable blocks, etc).

    // we run optimizations and return the pointer to the function
    Function* currentF = mod.getFunction("execute");


  return 0;

Thanks again for your help,

On Mon, Feb 20, 2012 at 11:06 PM, Anton Korobeynikov <
anton at korobeynikov.info> wrote:

> Guillermo,
> > I'm sorry I forgot to mention I am compiling the bitcode using the JIT.
> The
> > actual error, I get when I'm trying to get the function to the pointer.
> I'm
> > using a custom front end that translates Android's Dalvik bytecode into
> > bitcode based on Android ICS's modified LLVM version.
> ARM JIT is broken in many ways. So, what you're seeing is perfectly
> expected. You might want to wait until MCJIT will be usable and/or
> provide patches to make this happen sooner :)
> --
> With best regards, Anton Korobeynikov
> Faculty of Mathematics and Mechanics, Saint Petersburg State University

Guillermo A. Pérez (吉耶莫)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120221/c88f1cbb/attachment.html>

More information about the llvm-dev mailing list