gtcasl / gpuocelot

GPUOCelot: A dynamic compilation framework for PTX
http://gpuocelot.gatech.edu/
BSD 3-Clause "New" or "Revised" License
280 stars 69 forks source link

Support for LLVM > 3.4 #102

Open florianjacob opened 8 years ago

florianjacob commented 8 years ago

In its current state, gpuocelot won't work with anything above LLVM 3.4. e.g. #99 and #100 are symptoms of that.

LLVM seems to have introduced some quite heavy changes, so this probably won't be trivial to fix, and if one were to do so, one would probably have to drop support for LLVM 3.4 as this would really get you in ifdef hell, not only in the includes, but also inside the code.

Problems I found / fixed so far, but there are many more:

#define HAVE_LLVM 1
#include <llvm/Config/llvm-config.h>

/* PassManager is legacy starting from llvm 3.7 */
#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7
#define LLVM_37_PLUS 1
#endif

/* llvm/Assembly/Parser.h moved to llvm/AsmParser/Parser.h in llvm 3.5 */
/* llvm/Analysis/Verifier.h moved to llvm/IR/Verifier.h in llvm 3.5 */
#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 5
#define LLVM_35_PLUS 1
#endif

#else
#define HAVE_LLVM 0
#endif
#if LLVM_37_PLUS
#include "llvm/IR/LegacyPassManager.h"
using namespace llvm::legacy;
#else
#include <llvm/PassManager.h>
#endif
#if LLVM_35_PLUS
#include <llvm/AsmParser/Parser.h>
#include <llvm/IR/Verifier.h>
#else
#include <llvm/Assembly/Parser.h>
#include <llvm/Analysis/Verifier.h>
#endif

Preview of errors where I gave up, ParseAssemblyString is now parseAssemblyString and freeMachineCodeForFunction doesn't exist anymore at all:

ocelot/ocelot/ir/implementation/ExternalFunctionSet.cpp:320:6: error: 'ParseAssemblyString' is not a member of 'llvm'
  m = llvm::ParseAssemblyString(kernel.code().c_str(),
      ^~~~
ocelot/ocelot/ir/implementation/ExternalFunctionSet.cpp:341:28: error: 'ReturnStatusAction' is not a member of 'llvm'
  if(llvm::verifyModule(*m, llvm::ReturnStatusAction, &verifyError))
                            ^~~~
ocelot/ocelot/ir/implementation/ExternalFunctionSet.cpp: In destructor 'ir::ExternalFunctionSet::~ExternalFunctionSet()':
ocelot/ocelot/ir/implementation/ExternalFunctionSet.cpp:426:33: error: 'class llvm::ExecutionEngine' has no member named 'freeMachineCodeForFunction'
    executive::LLVMState::jit()->freeMachineCodeForFunction(function);
                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~
ocelot/ocelot/ir/implementation/ExternalFunctionSet.cpp: In member function 'void ir::ExternalFunctionSet::remove(const string&)':
ocelot/ocelot/ir/implementation/ExternalFunctionSet.cpp:465:32: error: 'class llvm::ExecutionEngine' has no member named 'freeMachineCodeForFunction'
   executive::LLVMState::jit()->freeMachineCodeForFunction(llvmFunction);
dmikushin commented 1 year ago

Hi @florianjacob , thank you for sharing your changes, they are very useful!

where I gave up

Never give up: https://github.com/gpuocelot/gpuocelot/commit/0a9d72f8966110c64cfca22354d7b21a0bdbe1ca#diff-6ebfad6f91f81f64f278a3a4d6920ff0bf60b4f83fca97abb36ad88f9dcd0d27R321