LLVM IR to C++

Hi,

I want to convert LLVM bitcode files to cpp. I use these commands:

  1. clang -c -emit-llvm -fopenmp=libiomp5 oh2.c -o oh2.bc
  2. llc -march=cpp oh2.bc -o oh2.cpp
  3. g++ -fno-rtti -O0 -g $HOME/llvmbuild/bin/llvm-config --cxxflags oh2.cpp $HOME/llvmbuild/bin/llvm-config --ldflags --libs --system-libs -o oh2c

After the 3rd command, I get a lot of compilation errors. Is it possible that llc -march=cpp generates incorrect code?

Thanks,

Erdem Derebasoglu

Hi,

I want to convert LLVM bitcode files to cpp. I use these commands:

1. clang -c -emit-llvm -fopenmp=libiomp5 oh2.c -o oh2.bc
2. llc -march=cpp oh2.bc -o oh2.cpp
3. g++ -fno-rtti -O0 -g `$HOME/llvmbuild/bin/llvm-config --cxxflags`
oh2.cpp `$HOME/llvmbuild/bin/llvm-config --ldflags --libs --system-libs`
-o oh2c

After the 3rd command, I get a lot of compilation errors. Is it possible
that llc -march=cpp generates incorrect code?

What kinds of compilation errors are you seeing?

Jon

First, I got this:

oh2.cpp:5:36: fatal error: llvm/Analysis/Verifier.h: No such file or directory

I know Verifier.h is in llvm/IR so I changed oh2.cpp accordingly. oh2.cpp was created by llc so I don’t understand why the path was wrong. Now I get these errors:

oh2.cpp: In function ‘int main(int, char**)’:
oh2.cpp:27:22: error: ‘PrintMessageAction’ was not declared in this scope
verifyModule(Mod, PrintMessageAction);
^
oh2.cpp:28:3: error: ‘PassManager’ was not declared in this scope
PassManager PM;
^
oh2.cpp:28:3: note: suggested alternative:
In file included from oh2.cpp:16:0:
/home/erdem/llvm/include/llvm/IR/LegacyPassManager.h:49:7: note: ‘llvm::legacy::PassManager’
class PassManager : public PassManagerBase {
^
oh2.cpp:28:15: error: expected ‘;’ before ‘PM’
PassManager PM;
^
oh2.cpp:29:3: error: ‘PM’ was not declared in this scope
PM.add(createPrintModulePass(&outs()));
^
oh2.cpp:29:39: error: invalid initialization of non-const reference of type ‘llvm::raw_ostream&’ from an rvalue of type ‘llvm::raw_ostream

PM.add(createPrintModulePass(&outs()));
^
In file included from oh2.cpp:12:0:
/home/erdem/llvm/include/llvm/IR/IRPrintingPasses.h:36:13: error: in passing argument 1 of ‘llvm::ModulePass* llvm::createPrintModulePass(llvm::raw_ostream&, const string&, bool)’
ModulePass createPrintModulePass(raw_ostream &OS,
^
oh2.cpp: In function ‘llvm::Module
makeLLVMModule()’:
oh2.cpp:372:94: error: no matching function for call to ‘llvm::ConstantExpr::getGetElementPtr(llvm::GlobalVariable*&, std::vector<llvm::Constant*, std::allocatorllvm::Constant* >&)’
Constant* const_ptr_30 = ConstantExpr::getGetElementPtr(gvar_array__str, const_ptr_30_indices);
^
oh2.cpp:372:94: note: candidates are:
In file included from oh2.cpp:8:0:
/home/erdem/llvm/include/llvm/IR/Constants.h:1092:20: note: static llvm::Constant* llvm::ConstantExpr::getGetElementPtr(llvm::Type*, llvm::Constant*, llvm::ArrayRefllvm::Constant*, bool, llvm::Type*)
static Constant getGetElementPtr(Type Ty, Constant C,
^
/home/erdem/llvm/include/llvm/IR/Constants.h:1092:20: note: candidate expects 5 arguments, 2 provided
/home/erdem/llvm/include/llvm/IR/Constants.h:1100:20: note: static llvm::Constant
llvm::ConstantExpr::getGetElementPtr(llvm::Type
, llvm::Constant
, llvm::Constant*, bool, llvm::Type*)
static Constant getGetElementPtr(Type Ty, Constant C, Constant Idx,
^
/home/erdem/llvm/include/llvm/IR/Constants.h:1100:20: note: candidate expects 5 arguments, 2 provided
/home/erdem/llvm/include/llvm/IR/Constants.h:1108:20: note: static llvm::Constant
llvm::ConstantExpr::getGetElementPtr(llvm::Type
, llvm::Constant
, llvm::ArrayRefllvm::Value*, bool, llvm::Type
)
static Constant *getGetElementPtr(Type *Ty, Constant *C,
^
/home/erdem/llvm/include/llvm/IR/Constants.h:1108:20: note: candidate expects 5 arguments, 2 provided

… and some unused variable warnings. Is there another way to compile the cpp file generated by -march=cpp?

Erdem