1
Fork 0

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

This commit is contained in:
Rafael Ávila de Espíndola 2011-07-14 15:19:17 -04:00
parent be489ee9e2
commit c124a025bf
3 changed files with 43 additions and 67 deletions

View file

@ -169,11 +169,6 @@ native mod llvm = "rustllvm" {
fn LLVMGetTarget(ModuleRef M) -> sbuf; fn LLVMGetTarget(ModuleRef M) -> sbuf;
fn LLVMSetTarget(ModuleRef M, sbuf Triple); 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. */ /** See Module::dump. */
fn LLVMDumpModule(ModuleRef M); fn LLVMDumpModule(ModuleRef M);
@ -250,17 +245,9 @@ native mod llvm = "rustllvm" {
/* Operations on other types */ /* Operations on other types */
fn LLVMVoidTypeInContext(ContextRef C) -> TypeRef; fn LLVMVoidTypeInContext(ContextRef C) -> TypeRef;
fn LLVMLabelTypeInContext(ContextRef C) -> TypeRef; fn LLVMLabelTypeInContext(ContextRef C) -> TypeRef;
fn LLVMOpaqueTypeInContext(ContextRef C) -> TypeRef;
fn LLVMVoidType() -> TypeRef; fn LLVMVoidType() -> TypeRef;
fn LLVMLabelType() -> 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 */ /* Operations on all values */
fn LLVMTypeOf(ValueRef Val) -> TypeRef; fn LLVMTypeOf(ValueRef Val) -> TypeRef;
@ -792,7 +779,6 @@ native mod llvm = "rustllvm" {
fn LLVMAddSCCPPass(PassManagerRef PM); fn LLVMAddSCCPPass(PassManagerRef PM);
fn LLVMAddDeadStoreEliminationPass(PassManagerRef PM); fn LLVMAddDeadStoreEliminationPass(PassManagerRef PM);
fn LLVMAddStripDeadPrototypesPass(PassManagerRef PM); fn LLVMAddStripDeadPrototypesPass(PassManagerRef PM);
fn LLVMAddDeadTypeEliminationPass(PassManagerRef PM);
fn LLVMAddConstantMergePass(PassManagerRef PM); fn LLVMAddConstantMergePass(PassManagerRef PM);
fn LLVMAddArgumentPromotionPass(PassManagerRef PM); fn LLVMAddArgumentPromotionPass(PassManagerRef PM);
fn LLVMAddTailCallEliminationPass(PassManagerRef PM); fn LLVMAddTailCallEliminationPass(PassManagerRef PM);
@ -879,6 +865,14 @@ native mod llvm = "rustllvm" {
/** Print the pass timings since static dtors aren't picking them up. */ /** Print the pass timings since static dtors aren't picking them up. */
fn LLVMRustPrintPassTimings(); 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 /** Links LLVM modules together. `Src` is destroyed by this call and
must never be referenced again. */ must never be referenced again. */
fn LLVMLinkModules(ModuleRef Dest, ModuleRef Src) -> Bool; fn LLVMLinkModules(ModuleRef Dest, ModuleRef Src) -> Bool;
@ -1398,18 +1392,6 @@ obj builder(BuilderRef B, @mutable bool terminated) {
/* Memory-managed object interface to type handles. */ /* 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, state obj type_names(std::map::hashmap[TypeRef, str] type_names,
std::map::hashmap[str, TypeRef] named_types) { std::map::hashmap[str, TypeRef] named_types) {

View file

@ -40,10 +40,8 @@ import syntax::codemap::span;
import lib::llvm::llvm; import lib::llvm::llvm;
import lib::llvm::builder; import lib::llvm::builder;
import lib::llvm::target_data; import lib::llvm::target_data;
import lib::llvm::type_handle;
import lib::llvm::type_names; import lib::llvm::type_names;
import lib::llvm::mk_target_data; import lib::llvm::mk_target_data;
import lib::llvm::mk_type_handle;
import lib::llvm::mk_type_names; import lib::llvm::mk_type_names;
import lib::llvm::llvm::ModuleRef; import lib::llvm::llvm::ModuleRef;
import lib::llvm::llvm::ValueRef; import lib::llvm::llvm::ValueRef;
@ -475,18 +473,29 @@ fn T_struct(&TypeRef[] elts) -> TypeRef {
False); 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_empty_struct() -> TypeRef { ret T_struct(~[]); }
fn T_rust_object() -> TypeRef { fn T_rust_object() -> TypeRef {
auto e = T_ptr(T_empty_struct()); auto t = T_named_struct("rust_object");
ret T_struct(~[e, e]); auto e = T_ptr(T_empty_struct());
set_struct_body(t, ~[e,e]);
ret t;
} }
fn T_task() -> TypeRef { fn T_task() -> TypeRef {
auto t = auto t = T_named_struct("task");
T_struct(~[T_int(), // Refcount
auto elems = ~[T_int(), // Refcount
T_int(), // Delegate pointer T_int(), // Delegate pointer
T_int(), // Stack segment pointer T_int(), // Stack segment pointer
T_int(), // Runtime SP T_int(), // Runtime SP
@ -495,7 +504,8 @@ fn T_task() -> TypeRef {
T_int(), // Domain pointer T_int(), // Domain pointer
// Crate cache pointer // Crate cache pointer
T_int()]); T_int()];
set_struct_body(t, elems);
ret t; ret t;
} }
@ -532,9 +542,8 @@ fn T_cmp_glue_fn(&crate_ctxt cx) -> TypeRef {
} }
fn T_tydesc(TypeRef taskptr_type) -> TypeRef { fn T_tydesc(TypeRef taskptr_type) -> TypeRef {
auto th = mk_type_handle(); auto tydesc = T_named_struct("tydesc");
auto abs_tydesc = llvm::LLVMResolveTypeHandle(th.llth); auto tydescpp = T_ptr(T_ptr(tydesc));
auto tydescpp = T_ptr(T_ptr(abs_tydesc));
auto pvoid = T_ptr(T_i8()); auto pvoid = T_ptr(T_i8());
auto glue_fn_ty = auto glue_fn_ty =
T_ptr(T_fn(~[T_ptr(T_nil()), taskptr_type, T_ptr(T_nil()), tydescpp, T_ptr(T_fn(~[T_ptr(T_nil()), taskptr_type, T_ptr(T_nil()), tydescpp,
@ -542,8 +551,8 @@ fn T_tydesc(TypeRef taskptr_type) -> TypeRef {
auto cmp_glue_fn_ty = auto cmp_glue_fn_ty =
T_ptr(T_fn(~[T_ptr(T_i1()), taskptr_type, T_ptr(T_nil()), tydescpp, T_ptr(T_fn(~[T_ptr(T_i1()), taskptr_type, T_ptr(T_nil()), tydescpp,
pvoid, pvoid, T_i8()], T_void())); pvoid, pvoid, T_i8()], T_void()));
auto tydesc =
T_struct(~[tydescpp, // first_param auto elems = ~[tydescpp, // first_param
T_int(), // size T_int(), // size
T_int(), // align T_int(), // align
glue_fn_ty, // copy_glue glue_fn_ty, // copy_glue
@ -553,11 +562,9 @@ fn T_tydesc(TypeRef taskptr_type) -> TypeRef {
glue_fn_ty, // mark_glue glue_fn_ty, // mark_glue
glue_fn_ty, // obj_drop_glue glue_fn_ty, // obj_drop_glue
glue_fn_ty, // is_stateful glue_fn_ty, // is_stateful
cmp_glue_fn_ty]); // cmp_glue cmp_glue_fn_ty];
set_struct_body(tydesc, elems);
llvm::LLVMRefineType(abs_tydesc, tydesc); ret tydesc;
auto t = llvm::LLVMResolveTypeHandle(th.llth);
ret t;
} }
fn T_array(TypeRef t, uint n) -> TypeRef { ret llvm::LLVMArrayType(t, n); } fn T_array(TypeRef t, uint n) -> TypeRef { ret llvm::LLVMArrayType(t, n); }
@ -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); } case (ty::ty_type) { llty = T_ptr(cx.tydesc_type); }
} }
assert (llty as int != 0); 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); cx.lltypes.insert(t, llty);
ret llty; ret llty;
} }
@ -1096,6 +1099,11 @@ fn C_struct(&ValueRef[] elts) -> ValueRef {
False); 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 { fn C_array(TypeRef ty, &ValueRef[] elts) -> ValueRef {
ret llvm::LLVMConstArray(ty, std::ivec::to_ptr(elts), ret llvm::LLVMConstArray(ty, std::ivec::to_ptr(elts),
std::ivec::len(elts)); std::ivec::len(elts));
@ -1971,7 +1979,8 @@ fn emit_tydescs(&@crate_ctxt ccx) {
case (some(?v)) { ccx.stats.n_real_glues += 1u; v } case (some(?v)) { ccx.stats.n_real_glues += 1u; v }
}; };
auto tydesc = 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 ti.align, copy_glue, // copy_glue
drop_glue, // drop_glue drop_glue, // drop_glue
free_glue, // free_glue free_glue, // free_glue
@ -9074,11 +9083,6 @@ fn i2p(ValueRef v, TypeRef t) -> ValueRef {
ret llvm::LLVMConstIntToPtr(v, t); 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] { fn declare_intrinsics(ModuleRef llmod) -> hashmap[str, ValueRef] {
let TypeRef[] T_memmove32_args = let TypeRef[] T_memmove32_args =
~[T_ptr(T_i8()), T_ptr(T_i8()), T_i32(), T_i32(), T_i1()]; ~[T_ptr(T_i8()), T_ptr(T_i8()), T_i32(), T_i32(), T_i1()];
@ -9298,7 +9302,6 @@ fn trans_crate(&session::session sess, &@ast::crate crate, &ty::ctxt tcx,
tydesc_type=tydesc_type, tydesc_type=tydesc_type,
task_type=task_type); task_type=task_type);
auto cx = new_local_ctxt(ccx); auto cx = new_local_ctxt(ccx);
create_typedefs(ccx);
collect_items(ccx, crate); collect_items(ccx, crate);
collect_tag_ctors(ccx, crate); collect_tag_ctors(ccx, crate);
trans_constants(ccx, crate); trans_constants(ccx, crate);

View file

@ -30,7 +30,6 @@ LLVMAddConstantPropagationPass
LLVMAddCorrelatedValuePropagationPass LLVMAddCorrelatedValuePropagationPass
LLVMAddDeadArgEliminationPass LLVMAddDeadArgEliminationPass
LLVMAddDeadStoreEliminationPass LLVMAddDeadStoreEliminationPass
LLVMAddDeadTypeEliminationPass
LLVMAddDemoteMemoryToRegisterPass LLVMAddDemoteMemoryToRegisterPass
LLVMAddDestination LLVMAddDestination
LLVMAddEarlyCSEPass LLVMAddEarlyCSEPass
@ -78,7 +77,6 @@ LLVMAddStripSymbolsPass
LLVMAddTailCallEliminationPass LLVMAddTailCallEliminationPass
LLVMAddTargetData LLVMAddTargetData
LLVMAddTypeBasedAliasAnalysisPass LLVMAddTypeBasedAliasAnalysisPass
LLVMAddTypeName
LLVMAddVerifierPass LLVMAddVerifierPass
LLVMAlignOf LLVMAlignOf
LLVMAppendBasicBlock LLVMAppendBasicBlock
@ -279,11 +277,9 @@ LLVMCreateModuleProviderForExistingModule
LLVMCreateObjectFile LLVMCreateObjectFile
LLVMCreatePassManager LLVMCreatePassManager
LLVMCreateTargetData LLVMCreateTargetData
LLVMCreateTypeHandle
LLVMDeleteBasicBlock LLVMDeleteBasicBlock
LLVMDeleteFunction LLVMDeleteFunction
LLVMDeleteGlobal LLVMDeleteGlobal
LLVMDeleteTypeName
LLVMDisposeBuilder LLVMDisposeBuilder
LLVMDisposeExecutionEngine LLVMDisposeExecutionEngine
LLVMDisposeGenericValue LLVMDisposeGenericValue
@ -295,7 +291,6 @@ LLVMDisposeObjectFile
LLVMDisposePassManager LLVMDisposePassManager
LLVMDisposeSectionIterator LLVMDisposeSectionIterator
LLVMDisposeTargetData LLVMDisposeTargetData
LLVMDisposeTypeHandle
LLVMDoubleType LLVMDoubleType
LLVMDoubleTypeInContext LLVMDoubleTypeInContext
LLVMDumpModule LLVMDumpModule
@ -388,10 +383,8 @@ LLVMGetSectionSize
LLVMGetSections LLVMGetSections
LLVMGetStructElementTypes LLVMGetStructElementTypes
LLVMGetTarget LLVMGetTarget
LLVMGetTypeByName
LLVMGetTypeContext LLVMGetTypeContext
LLVMGetTypeKind LLVMGetTypeKind
LLVMGetTypeName
LLVMGetUndef LLVMGetUndef
LLVMGetUsedValue LLVMGetUsedValue
LLVMGetUser LLVMGetUser
@ -527,8 +520,6 @@ LLVMMoveBasicBlockAfter
LLVMMoveBasicBlockBefore LLVMMoveBasicBlockBefore
LLVMMoveToNextSection LLVMMoveToNextSection
LLVMOffsetOfElement LLVMOffsetOfElement
LLVMOpaqueType
LLVMOpaqueTypeInContext
LLVMPPCFP128Type LLVMPPCFP128Type
LLVMPPCFP128TypeInContext LLVMPPCFP128TypeInContext
LLVMParseBitcode LLVMParseBitcode
@ -541,14 +532,12 @@ LLVMPositionBuilderBefore
LLVMPreferredAlignmentOfGlobal LLVMPreferredAlignmentOfGlobal
LLVMPreferredAlignmentOfType LLVMPreferredAlignmentOfType
LLVMRecompileAndRelinkFunction LLVMRecompileAndRelinkFunction
LLVMRefineType
LLVMRemoveAttribute LLVMRemoveAttribute
LLVMRemoveFunctionAttr LLVMRemoveFunctionAttr
LLVMRemoveInstrAttribute LLVMRemoveInstrAttribute
LLVMRemoveModule LLVMRemoveModule
LLVMRemoveModuleProvider LLVMRemoveModuleProvider
LLVMReplaceAllUsesWith LLVMReplaceAllUsesWith
LLVMResolveTypeHandle
LLVMRunFunction LLVMRunFunction
LLVMRunFunctionAsMain LLVMRunFunctionAsMain
LLVMRunFunctionPassManager LLVMRunFunctionPassManager
@ -598,4 +587,6 @@ LLVMX86FP80Type
LLVMX86FP80TypeInContext LLVMX86FP80TypeInContext
LLVMX86MMXType LLVMX86MMXType
LLVMX86MMXTypeInContext LLVMX86MMXTypeInContext
LLVMConstNamedStruct
LLVMStructCreateNamed
LLVMStructSetBody