Skip to content

Commit

Permalink
follow new llvm changes + no more rtti
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@4219 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information
lrz committed Jun 12, 2010
1 parent 7ed8143 commit b2d1a18
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 124 deletions.
9 changes: 8 additions & 1 deletion bin/rubyc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ class Compiler
# Misc.
@tmpdir = (ENV['TMPDIR'] or '/tmp')
@tmpfiles = []

@llc_flags = '-relocation-model=pic '
if system("#{@llc} -help | grep jit-enable-eh >& /dev/null")
@llc_flags << '-jit-enable-eh'
else
@llc_flags << '-enable-eh'
end
end

def run
Expand Down Expand Up @@ -134,7 +141,7 @@ class Compiler

# Compile the bitcode as assembly.
asm = gen_tmpfile(base + arch, 's')
execute("#{@llc} -f \"#{bc}\" -o=\"#{asm}\" -march=#{llc_arch(arch)} -relocation-model=pic -enable-eh")
execute("#{@llc} \"#{bc}\" -o=\"#{asm}\" -march=#{llc_arch(arch)} #{@llc_flags}")

# Compile the assembly.
tmp_obj = gen_tmpfile(base + arch, 'o')
Expand Down
24 changes: 21 additions & 3 deletions bridgesupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
#include <llvm/Constants.h>
#include <llvm/CallingConv.h>
#include <llvm/Instructions.h>
#include <llvm/ModuleProvider.h>
#if !defined(LLVM_TOT)
# include <llvm/ModuleProvider.h>
#endif
#include <llvm/Intrinsics.h>
#include <llvm/Analysis/DebugInfo.h>
#include <llvm/ExecutionEngine/JIT.h>
Expand Down Expand Up @@ -191,18 +193,34 @@ RoxorCompiler::compile_bs_struct_new(rb_vm_bs_boxed_t *bs_boxed)
const Type *llvm_type = convert_type(ftype);
Value *fval = new AllocaInst(llvm_type, "", bb);

const size_t type_size = GET_CORE()->get_sizeof(llvm_type);

#if LLVM_TOT
Value *args[] = {
new BitCastInst(fval, PtrTy, "", bb), // start
ConstantInt::get(Int8Ty, 0), // value
ConstantInt::get(IntTy, type_size), // size
ConstantInt::get(Int32Ty, 0), // align
ConstantInt::get(Int1Ty, 0) // volatile
};
const Type *Tys[] = { args[0]->getType(), args[2]->getType() };
Function *memset_func = Intrinsic::getDeclaration(module,
Intrinsic::memset, Tys, 2);
assert(memset_func != NULL);
CallInst::Create(memset_func, args, args + 5, "", bb);
#else
const Type *Tys[] = { IntTy };
Function *memset_func = Intrinsic::getDeclaration(module,
Intrinsic::memset, Tys, 1);
assert(memset_func != NULL);

Value *args[] = {
new BitCastInst(fval, PtrTy, "", bb),
ConstantInt::get(Int8Ty, 0),
ConstantInt::get(IntTy, GET_CORE()->get_sizeof(llvm_type)),
ConstantInt::get(IntTy, type_size),
ConstantInt::get(Int32Ty, 0)
};
CallInst::Create(memset_func, args, args + 4, "", bb);
#endif

fval = new LoadInst(fval, "", bb);
fval = compile_conversion_to_ruby(ftype, llvm_type, fval);
Expand Down
70 changes: 27 additions & 43 deletions compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ RoxorCompiler::attach_current_line_metadata(Instruction *insn)
DILocation loc = debug_info->CreateLocation(current_line, 0,
debug_compile_unit, DILocation(NULL));
#if LLVM_TOT
insn->setMetadata(dbg_mdkind, loc.getNode());
insn->setMetadata(dbg_mdkind, loc);
//insn->setDebugLoc(DebugLoc::getFromDILocation(loc.getNode()));
#else
context.getMetadata().addMD(dbg_mdkind, loc.getNode(), insn);
Expand Down Expand Up @@ -1719,8 +1719,6 @@ RoxorCompiler::compile_return_from_block(Value *val, int id)
void
RoxorCompiler::compile_return_from_block_handler(int id)
{
//const std::type_info &eh_type = typeid(RoxorReturnFromBlockException *);
//Value *exception = compile_landing_pad_header(eh_type);
Value *exception = compile_landing_pad_header();

if (checkReturnFromBlockFunc == NULL) {
Expand Down Expand Up @@ -1904,12 +1902,6 @@ RoxorCompiler::compile_class_path(NODE *node, int *flags)

Value *
RoxorCompiler::compile_landing_pad_header(void)
{
return compile_landing_pad_header(typeid(void));
}

Value *
RoxorCompiler::compile_landing_pad_header(const std::type_info &eh_type)
{
Function *eh_exception_f = Intrinsic::getDeclaration(module,
Intrinsic::eh_exception);
Expand All @@ -1928,41 +1920,10 @@ RoxorCompiler::compile_landing_pad_header(const std::type_info &eh_type)
}
params.push_back(ConstantExpr::getBitCast(__gxx_personality_v0_func, PtrTy));

if (eh_type == typeid(void)) {
// catch (...)
params.push_back(compile_const_pointer(NULL));
}
else {
// catch (eh_type &exc)
params.push_back(compile_const_pointer((void *)&eh_type));
params.push_back(compile_const_pointer(NULL));
}

Value *eh_sel = CallInst::Create(eh_selector_f, params.begin(),
params.end(), "", bb);

if (eh_type != typeid(void)) {
// TODO: this doesn't work yet, the type id must be a GlobalVariable...
Function *eh_typeid_for_f = Intrinsic::getDeclaration(module,
Intrinsic::eh_typeid_for);
std::vector<Value *> params;
params.push_back(compile_const_pointer((void *)&eh_type));

Value *eh_typeid = CallInst::Create(eh_typeid_for_f, params.begin(),
params.end(), "", bb);

Function *f = bb->getParent();
BasicBlock *typeok_bb = BasicBlock::Create(context, "typeok", f);
BasicBlock *nocatch_bb = BasicBlock::Create(context, "nocatch", f);
Value *need_ret = new ICmpInst(*bb, ICmpInst::ICMP_EQ, eh_sel,
eh_typeid);
BranchInst::Create(typeok_bb, nocatch_bb, need_ret, bb);
// catch (...)
params.push_back(compile_const_pointer(NULL));

bb = nocatch_bb;
compile_rethrow_exception();

bb = typeok_bb;
}
CallInst::Create(eh_selector_f, params.begin(), params.end(), "", bb);

Function *beginCatchFunc = NULL;
if (beginCatchFunc == NULL) {
Expand Down Expand Up @@ -2469,10 +2430,18 @@ RoxorCompiler::inline_function_calls(Function *f)
}
}

#if LLVM_TOT
InlineFunctionInfo IFI;
for (std::vector<CallInst *>::iterator i = insns.begin();
i != insns.end(); ++i) {
InlineFunction(*i, IFI);
}
#else
for (std::vector<CallInst *>::iterator i = insns.begin();
i != insns.end(); ++i) {
InlineFunction(*i);
}
#endif
}

Function *
Expand Down Expand Up @@ -2774,6 +2743,20 @@ RoxorCompiler::compile_scope(NODE *node)

// Transform the InvokeInst in CallInst.
std::vector<Value *> params;
#if LLVM_TOT
for (unsigned i = 0; i < invoke->getNumOperands() - 3; i++) {
params.push_back(invoke->getOperand(i));
}
CallInst *call_inst = CallInst::Create(
invoke->getCalledValue(),
params.begin(), params.end(),
"",
invoke);

invoke->replaceAllUsesWith(call_inst);
BasicBlock *normal_bb = dyn_cast<BasicBlock>
(invoke->getNormalDest());
#else
for (InvokeInst::op_iterator op_it = invoke->op_begin()+3;
op_it != invoke->op_end(); ++op_it) {
params.push_back(op_it->get());
Expand All @@ -2786,6 +2769,7 @@ RoxorCompiler::compile_scope(NODE *node)

invoke->replaceAllUsesWith(call_inst);
BasicBlock *normal_bb = dyn_cast<BasicBlock>(invoke->getOperand(1));
#endif
assert(normal_bb != NULL);
BranchInst::Create(normal_bb, invoke);
invoke->eraseFromParent();
Expand Down
1 change: 0 additions & 1 deletion compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,6 @@ class RoxorCompiler {
Value *compile_set_current_class(Value *klass);

Value *compile_landing_pad_header(void);
Value *compile_landing_pad_header(const std::type_info &eh_type);
void compile_landing_pad_footer(bool pop_exception=true);
Value *compile_current_exception(void);
void compile_rethrow_exception(void);
Expand Down
4 changes: 3 additions & 1 deletion debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
#include <llvm/Constants.h>
#include <llvm/CallingConv.h>
#include <llvm/Instructions.h>
#include <llvm/ModuleProvider.h>
#if !defined(LLVM_TOT)
# include <llvm/ModuleProvider.h>
#endif
#include <llvm/Intrinsics.h>
#include <llvm/Analysis/DebugInfo.h>
#include <llvm/ExecutionEngine/JIT.h>
Expand Down
4 changes: 3 additions & 1 deletion llvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
#include <llvm/Constants.h>
#include <llvm/CallingConv.h>
#include <llvm/Instructions.h>
#include <llvm/ModuleProvider.h>
#if !defined(LLVM_TOT)
# include <llvm/ModuleProvider.h>
#endif
#include <llvm/Intrinsics.h>
#include <llvm/Analysis/DebugInfo.h>
#include <llvm/ExecutionEngine/JIT.h>
Expand Down
3 changes: 2 additions & 1 deletion rakelib/builder/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,11 @@ def self.option(name, default)
CFLAGS = "-I. -I./include #{ARCHFLAGS} -fno-common -pipe -g -Wall -fexceptions #{OPTZFLAG}"
CFLAGS << " -Wno-deprecated-declarations -Werror" if NO_WARN_BUILD
OBJC_CFLAGS = CFLAGS + " -fobjc-gc-only"
CXXFLAGS = `#{LLVM_CONFIG} --cxxflags #{LLVM_MODULES}`.sub(/-DNDEBUG/, '').sub(/-fno-exceptions/, '').strip
CXXFLAGS = `#{LLVM_CONFIG} --cxxflags #{LLVM_MODULES}`.sub(/-DNDEBUG/, '').sub(/-fno-exceptions/, '').sub(/-Wcast-qual/, '').strip
CXXFLAGS.sub!(/-O\d/, OPTZFLAG)
CXXFLAGS << " -I. -I./include -g -Wall #{ARCHFLAGS}"
CXXFLAGS << " -Wno-deprecated-declarations -Werror" if NO_WARN_BUILD
CXXFLAGS << " -fno-rtti" unless CXXFLAGS.index("-fno-rtti")
CXXFLAGS << " -DLLVM_TOT" if ENV['LLVM_TOT']
CXXFLAGS << " -DLLVM_PRE_TOT" if ENV['LLVM_PRE_TOT']
LDFLAGS = `#{LLVM_CONFIG} --ldflags --libs #{LLVM_MODULES}`.strip.gsub(/\n/, '')
Expand Down
Loading

0 comments on commit b2d1a18

Please sign in to comment.