Skip to content

Move rustc to the new llvm type system. Requires an update to llvm trunk. #692

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 14, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 8 additions & 26 deletions src/comp/lib/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,6 @@ native mod llvm = "rustllvm" {
fn LLVMGetTarget(ModuleRef M) -> sbuf;
fn LLVMSetTarget(ModuleRef M, sbuf Triple);

/** See Module::addTypeName. */
fn LLVMAddTypeName(ModuleRef M, sbuf Name, TypeRef Ty) -> Bool;
fn LLVMDeleteTypeName(ModuleRef M, sbuf Name);
fn LLVMGetTypeByName(ModuleRef M, sbuf Name) -> TypeRef;

/** See Module::dump. */
fn LLVMDumpModule(ModuleRef M);

Expand Down Expand Up @@ -250,17 +245,9 @@ native mod llvm = "rustllvm" {
/* Operations on other types */
fn LLVMVoidTypeInContext(ContextRef C) -> TypeRef;
fn LLVMLabelTypeInContext(ContextRef C) -> TypeRef;
fn LLVMOpaqueTypeInContext(ContextRef C) -> TypeRef;

fn LLVMVoidType() -> TypeRef;
fn LLVMLabelType() -> TypeRef;
fn LLVMOpaqueType() -> TypeRef;

/* Operations on type handles */
fn LLVMCreateTypeHandle(TypeRef PotentiallyAbstractTy) -> TypeHandleRef;
fn LLVMRefineType(TypeRef AbstractTy, TypeRef ConcreteTy);
fn LLVMResolveTypeHandle(TypeHandleRef TypeHandle) -> TypeRef;
fn LLVMDisposeTypeHandle(TypeHandleRef TypeHandle);

/* Operations on all values */
fn LLVMTypeOf(ValueRef Val) -> TypeRef;
Expand Down Expand Up @@ -792,7 +779,6 @@ native mod llvm = "rustllvm" {
fn LLVMAddSCCPPass(PassManagerRef PM);
fn LLVMAddDeadStoreEliminationPass(PassManagerRef PM);
fn LLVMAddStripDeadPrototypesPass(PassManagerRef PM);
fn LLVMAddDeadTypeEliminationPass(PassManagerRef PM);
fn LLVMAddConstantMergePass(PassManagerRef PM);
fn LLVMAddArgumentPromotionPass(PassManagerRef PM);
fn LLVMAddTailCallEliminationPass(PassManagerRef PM);
Expand Down Expand Up @@ -879,6 +865,14 @@ native mod llvm = "rustllvm" {
/** Print the pass timings since static dtors aren't picking them up. */
fn LLVMRustPrintPassTimings();

fn LLVMStructCreateNamed(ContextRef C, sbuf Name) -> TypeRef;

fn LLVMStructSetBody(TypeRef StructTy, *TypeRef ElementTypes,
uint ElementCount, Bool Packed);

fn LLVMConstNamedStruct(TypeRef S, *ValueRef ConstantVals,
uint Count) -> ValueRef;

/** Links LLVM modules together. `Src` is destroyed by this call and
must never be referenced again. */
fn LLVMLinkModules(ModuleRef Dest, ModuleRef Src) -> Bool;
Expand Down Expand Up @@ -1398,18 +1392,6 @@ obj builder(BuilderRef B, @mutable bool terminated) {

/* Memory-managed object interface to type handles. */

obj type_handle_dtor(TypeHandleRef TH) {
drop { llvm::LLVMDisposeTypeHandle(TH); }
}

type type_handle = rec(TypeHandleRef llth, type_handle_dtor dtor);

fn mk_type_handle() -> type_handle {
auto th = llvm::LLVMCreateTypeHandle(llvm::LLVMOpaqueType());
ret rec(llth=th, dtor=type_handle_dtor(th));
}


state obj type_names(std::map::hashmap[TypeRef, str] type_names,
std::map::hashmap[str, TypeRef] named_types) {

Expand Down
61 changes: 32 additions & 29 deletions src/comp/middle/trans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ import syntax::codemap::span;
import lib::llvm::llvm;
import lib::llvm::builder;
import lib::llvm::target_data;
import lib::llvm::type_handle;
import lib::llvm::type_names;
import lib::llvm::mk_target_data;
import lib::llvm::mk_type_handle;
import lib::llvm::mk_type_names;
import lib::llvm::llvm::ModuleRef;
import lib::llvm::llvm::ValueRef;
Expand Down Expand Up @@ -475,18 +473,29 @@ fn T_struct(&TypeRef[] elts) -> TypeRef {
False);
}

fn T_opaque() -> TypeRef { ret llvm::LLVMOpaqueType(); }
fn T_named_struct(&str name) -> TypeRef {
auto c = llvm::LLVMGetGlobalContext();
ret llvm::LLVMStructCreateNamed(c, str::buf(name));
}

fn set_struct_body(TypeRef t, &TypeRef[] elts) {
llvm::LLVMStructSetBody(t, std::ivec::to_ptr(elts), std::ivec::len(elts),
False);
}

fn T_empty_struct() -> TypeRef { ret T_struct(~[]); }

fn T_rust_object() -> TypeRef {
auto e = T_ptr(T_empty_struct());
ret T_struct(~[e, e]);
auto t = T_named_struct("rust_object");
auto e = T_ptr(T_empty_struct());
set_struct_body(t, ~[e,e]);
ret t;
}

fn T_task() -> TypeRef {
auto t =
T_struct(~[T_int(), // Refcount
auto t = T_named_struct("task");

auto elems = ~[T_int(), // Refcount
T_int(), // Delegate pointer
T_int(), // Stack segment pointer
T_int(), // Runtime SP
Expand All @@ -495,7 +504,8 @@ fn T_task() -> TypeRef {

T_int(), // Domain pointer
// Crate cache pointer
T_int()]);
T_int()];
set_struct_body(t, elems);
ret t;
}

Expand Down Expand Up @@ -532,18 +542,17 @@ fn T_cmp_glue_fn(&crate_ctxt cx) -> TypeRef {
}

fn T_tydesc(TypeRef taskptr_type) -> TypeRef {
auto th = mk_type_handle();
auto abs_tydesc = llvm::LLVMResolveTypeHandle(th.llth);
auto tydescpp = T_ptr(T_ptr(abs_tydesc));
auto tydesc = T_named_struct("tydesc");
auto tydescpp = T_ptr(T_ptr(tydesc));
auto pvoid = T_ptr(T_i8());
auto glue_fn_ty =
T_ptr(T_fn(~[T_ptr(T_nil()), taskptr_type, T_ptr(T_nil()), tydescpp,
pvoid], T_void()));
auto cmp_glue_fn_ty =
T_ptr(T_fn(~[T_ptr(T_i1()), taskptr_type, T_ptr(T_nil()), tydescpp,
pvoid, pvoid, T_i8()], T_void()));
auto tydesc =
T_struct(~[tydescpp, // first_param

auto elems = ~[tydescpp, // first_param
T_int(), // size
T_int(), // align
glue_fn_ty, // copy_glue
Expand All @@ -553,11 +562,9 @@ fn T_tydesc(TypeRef taskptr_type) -> TypeRef {
glue_fn_ty, // mark_glue
glue_fn_ty, // obj_drop_glue
glue_fn_ty, // is_stateful
cmp_glue_fn_ty]); // cmp_glue

llvm::LLVMRefineType(abs_tydesc, tydesc);
auto t = llvm::LLVMResolveTypeHandle(th.llth);
ret t;
cmp_glue_fn_ty];
set_struct_body(tydesc, elems);
ret tydesc;
}

fn T_array(TypeRef t, uint n) -> TypeRef { ret llvm::LLVMArrayType(t, n); }
Expand Down Expand Up @@ -915,10 +922,6 @@ fn type_of_inner(&@crate_ctxt cx, &span sp, &ty::t t) -> TypeRef {
case (ty::ty_type) { llty = T_ptr(cx.tydesc_type); }
}
assert (llty as int != 0);
if (cx.sess.get_opts().save_temps) {
llvm::LLVMAddTypeName(cx.llmod, str::buf(ty_to_short_str(cx.tcx, t)),
llty);
}
cx.lltypes.insert(t, llty);
ret llty;
}
Expand Down Expand Up @@ -1096,6 +1099,11 @@ fn C_struct(&ValueRef[] elts) -> ValueRef {
False);
}

fn C_named_struct(TypeRef T, &ValueRef[] elts) -> ValueRef {
ret llvm::LLVMConstNamedStruct(T, std::ivec::to_ptr(elts),
std::ivec::len(elts));
}

fn C_array(TypeRef ty, &ValueRef[] elts) -> ValueRef {
ret llvm::LLVMConstArray(ty, std::ivec::to_ptr(elts),
std::ivec::len(elts));
Expand Down Expand Up @@ -1971,7 +1979,8 @@ fn emit_tydescs(&@crate_ctxt ccx) {
case (some(?v)) { ccx.stats.n_real_glues += 1u; v }
};
auto tydesc =
C_struct(~[C_null(T_ptr(T_ptr(ccx.tydesc_type))), ti.size,
C_named_struct(ccx.tydesc_type,
~[C_null(T_ptr(T_ptr(ccx.tydesc_type))), ti.size,
ti.align, copy_glue, // copy_glue
drop_glue, // drop_glue
free_glue, // free_glue
Expand Down Expand Up @@ -9074,11 +9083,6 @@ fn i2p(ValueRef v, TypeRef t) -> ValueRef {
ret llvm::LLVMConstIntToPtr(v, t);
}

fn create_typedefs(&@crate_ctxt cx) {
llvm::LLVMAddTypeName(cx.llmod, str::buf("task"), cx.task_type);
llvm::LLVMAddTypeName(cx.llmod, str::buf("tydesc"), cx.tydesc_type);
}

fn declare_intrinsics(ModuleRef llmod) -> hashmap[str, ValueRef] {
let TypeRef[] T_memmove32_args =
~[T_ptr(T_i8()), T_ptr(T_i8()), T_i32(), T_i32(), T_i1()];
Expand Down Expand Up @@ -9298,7 +9302,6 @@ fn trans_crate(&session::session sess, &@ast::crate crate, &ty::ctxt tcx,
tydesc_type=tydesc_type,
task_type=task_type);
auto cx = new_local_ctxt(ccx);
create_typedefs(ccx);
collect_items(ccx, crate);
collect_tag_ctors(ccx, crate);
trans_constants(ccx, crate);
Expand Down
15 changes: 3 additions & 12 deletions src/rustllvm/rustllvm.def.in
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ LLVMAddConstantPropagationPass
LLVMAddCorrelatedValuePropagationPass
LLVMAddDeadArgEliminationPass
LLVMAddDeadStoreEliminationPass
LLVMAddDeadTypeEliminationPass
LLVMAddDemoteMemoryToRegisterPass
LLVMAddDestination
LLVMAddEarlyCSEPass
Expand Down Expand Up @@ -78,7 +77,6 @@ LLVMAddStripSymbolsPass
LLVMAddTailCallEliminationPass
LLVMAddTargetData
LLVMAddTypeBasedAliasAnalysisPass
LLVMAddTypeName
LLVMAddVerifierPass
LLVMAlignOf
LLVMAppendBasicBlock
Expand Down Expand Up @@ -279,11 +277,9 @@ LLVMCreateModuleProviderForExistingModule
LLVMCreateObjectFile
LLVMCreatePassManager
LLVMCreateTargetData
LLVMCreateTypeHandle
LLVMDeleteBasicBlock
LLVMDeleteFunction
LLVMDeleteGlobal
LLVMDeleteTypeName
LLVMDisposeBuilder
LLVMDisposeExecutionEngine
LLVMDisposeGenericValue
Expand All @@ -295,7 +291,6 @@ LLVMDisposeObjectFile
LLVMDisposePassManager
LLVMDisposeSectionIterator
LLVMDisposeTargetData
LLVMDisposeTypeHandle
LLVMDoubleType
LLVMDoubleTypeInContext
LLVMDumpModule
Expand Down Expand Up @@ -388,10 +383,8 @@ LLVMGetSectionSize
LLVMGetSections
LLVMGetStructElementTypes
LLVMGetTarget
LLVMGetTypeByName
LLVMGetTypeContext
LLVMGetTypeKind
LLVMGetTypeName
LLVMGetUndef
LLVMGetUsedValue
LLVMGetUser
Expand Down Expand Up @@ -527,8 +520,6 @@ LLVMMoveBasicBlockAfter
LLVMMoveBasicBlockBefore
LLVMMoveToNextSection
LLVMOffsetOfElement
LLVMOpaqueType
LLVMOpaqueTypeInContext
LLVMPPCFP128Type
LLVMPPCFP128TypeInContext
LLVMParseBitcode
Expand All @@ -541,14 +532,12 @@ LLVMPositionBuilderBefore
LLVMPreferredAlignmentOfGlobal
LLVMPreferredAlignmentOfType
LLVMRecompileAndRelinkFunction
LLVMRefineType
LLVMRemoveAttribute
LLVMRemoveFunctionAttr
LLVMRemoveInstrAttribute
LLVMRemoveModule
LLVMRemoveModuleProvider
LLVMReplaceAllUsesWith
LLVMResolveTypeHandle
LLVMRunFunction
LLVMRunFunctionAsMain
LLVMRunFunctionPassManager
Expand Down Expand Up @@ -598,4 +587,6 @@ LLVMX86FP80Type
LLVMX86FP80TypeInContext
LLVMX86MMXType
LLVMX86MMXTypeInContext

LLVMConstNamedStruct
LLVMStructCreateNamed
LLVMStructSetBody