1
Fork 0

Get rid of native types in LLVM module

Code is still somewhat kludgy because we don't have 32-bit enums.

Issue #1673
This commit is contained in:
Marijn Haverbeke 2012-02-01 11:04:56 +01:00
parent f6f3d518e6
commit c6aead7281
14 changed files with 247 additions and 265 deletions

View file

@ -16,10 +16,7 @@ import option::none;
import std::sha1::sha1; import std::sha1::sha1;
import syntax::ast; import syntax::ast;
import syntax::print::pprust; import syntax::print::pprust;
import lib::llvm::llvm::ModuleRef; import lib::llvm::{ModuleRef, mk_pass_manager, mk_target_data, True, False};
import lib::llvm::mk_pass_manager;
import lib::llvm::mk_target_data;
import lib::llvm::False;
import util::filesearch; import util::filesearch;
enum output_type { enum output_type {
@ -182,7 +179,7 @@ mod write {
let MPMB = llvm::LLVMPassManagerBuilderCreate(); let MPMB = llvm::LLVMPassManagerBuilderCreate();
llvm::LLVMPassManagerBuilderSetOptLevel(MPMB, llvm::LLVMPassManagerBuilderSetOptLevel(MPMB,
opts.optimize as c_uint); opts.optimize as c_uint);
llvm::LLVMPassManagerBuilderSetSizeLevel(MPMB, 0); llvm::LLVMPassManagerBuilderSetSizeLevel(MPMB, False);
llvm::LLVMPassManagerBuilderSetDisableUnitAtATime(MPMB, False); llvm::LLVMPassManagerBuilderSetDisableUnitAtATime(MPMB, False);
llvm::LLVMPassManagerBuilderSetDisableUnrollLoops(MPMB, False); llvm::LLVMPassManagerBuilderSetDisableUnrollLoops(MPMB, False);
llvm::LLVMPassManagerBuilderSetDisableSimplifyLibCalls(MPMB, llvm::LLVMPassManagerBuilderSetDisableSimplifyLibCalls(MPMB,

View file

@ -5,10 +5,7 @@ import middle::trans::common::{T_fn, T_i1, T_i8, T_i32,
T_int, T_nil, T_dict, T_int, T_nil, T_dict,
T_opaque_vec, T_ptr, T_opaque_vec, T_ptr,
T_size_t, T_void}; T_size_t, T_void};
import lib::llvm::type_names; import lib::llvm::{type_names, ModuleRef, ValueRef, TypeRef};
import lib::llvm::llvm::ModuleRef;
import lib::llvm::llvm::ValueRef;
import lib::llvm::llvm::TypeRef;
type upcalls = type upcalls =
{_fail: ValueRef, {_fail: ValueRef,

View file

@ -1,144 +1,149 @@
import core::{vec, str, option}; import core::{vec, str, option};
import str::sbuf; import str::sbuf;
import llvm::{TypeRef, MemoryBufferRef,
PassManagerRef, TargetDataRef,
ObjectFileRef, SectionIteratorRef};
import ctypes::{c_int, c_uint, unsigned, longlong, ulonglong}; import ctypes::{c_int, c_uint, unsigned, longlong, ulonglong};
type Long = i32; type Opcode = u32;
type Bool = int; type Bool = unsigned;
const True: Bool = 1u32;
const False: Bool = 0u32;
const True: Bool = 1;
const False: Bool = 0;
// Consts for the LLVM CallConv type, pre-cast to uint. // Consts for the LLVM CallConv type, pre-cast to uint.
// FIXME: figure out a way to merge these with the native
// typedef and/or a enum type in the native module below.
const LLVMCCallConv: uint = 0u; enum CallConv {
const LLVMFastCallConv: uint = 8u; CCallConv = 0,
const LLVMColdCallConv: uint = 9u; FastCallConv = 8,
const LLVMX86StdcallCallConv: uint = 64u; ColdCallConv = 9,
const LLVMX86FastcallCallConv: uint = 65u; X86StdcallCallConv = 64,
X86FastcallCallConv = 65,
}
const LLVMDefaultVisibility: uint = 0u; enum Visibility {
const LLVMHiddenVisibility: uint = 1u; LLVMDefaultVisibility = 0,
const LLVMProtectedVisibility: uint = 2u; HiddenVisibility = 1,
ProtectedVisibility = 2,
}
const LLVMExternalLinkage: uint = 0u; enum Linkage {
const LLVMAvailableExternallyLinkage: uint = 1u; ExternalLinkage = 0,
const LLVMLinkOnceAnyLinkage: uint = 2u; AvailableExternallyLinkage = 1,
const LLVMLinkOnceODRLinkage: uint = 3u; LinkOnceAnyLinkage = 2,
const LLVMWeakAnyLinkage: uint = 4u; LinkOnceODRLinkage = 3,
const LLVMWeakODRLinkage: uint = 5u; WeakAnyLinkage = 4,
const LLVMAppendingLinkage: uint = 6u; WeakODRLinkage = 5,
const LLVMInternalLinkage: uint = 7u; AppendingLinkage = 6,
const LLVMPrivateLinkage: uint = 8u; InternalLinkage = 7,
const LLVMDLLImportLinkage: uint = 9u; PrivateLinkage = 8,
const LLVMDLLExportLinkage: uint = 10u; DLLImportLinkage = 9,
const LLVMExternalWeakLinkage: uint = 11u; DLLExportLinkage = 10,
const LLVMGhostLinkage: uint = 12u; ExternalWeakLinkage = 11,
const LLVMCommonLinkage: uint = 13u; GhostLinkage = 12,
const LLVMLinkerPrivateLinkage: uint = 14u; CommonLinkage = 13,
const LLVMLinkerPrivateWeakLinkage: uint = 15u; LinkerPrivateLinkage = 14,
const LLVMLinkerPrivateWeakDefAutoLinkage: uint = 16u; LinkerPrivateWeakLinkage = 15,
LinkerPrivateWeakDefAutoLinkage = 16,
const LLVMZExtAttribute: uint = 1u; }
const LLVMSExtAttribute: uint = 2u;
const LLVMNoReturnAttribute: uint = 4u;
const LLVMInRegAttribute: uint = 8u;
const LLVMStructRetAttribute: uint = 16u;
const LLVMNoUnwindAttribute: uint = 32u;
const LLVMNoAliasAttribute: uint = 64u;
const LLVMByValAttribute: uint = 128u;
const LLVMNestAttribute: uint = 256u;
const LLVMReadNoneAttribute: uint = 512u;
const LLVMReadOnlyAttribute: uint = 1024u;
const LLVMNoInlineAttribute: uint = 2048u;
const LLVMAlwaysInlineAttribute: uint = 4096u;
const LLVMOptimizeForSizeAttribute: uint = 8192u;
const LLVMStackProtectAttribute: uint = 16384u;
const LLVMStackProtectReqAttribute: uint = 32768u;
// 31 << 16
const LLVMAlignmentAttribute: uint = 2031616u;
const LLVMNoCaptureAttribute: uint = 2097152u;
const LLVMNoRedZoneAttribute: uint = 4194304u;
const LLVMNoImplicitFloatAttribute: uint = 8388608u;
const LLVMNakedAttribute: uint = 16777216u;
const LLVMInlineHintAttribute: uint = 33554432u;
// 7 << 26
const LLVMStackAttribute: uint = 469762048u;
const LLVMReturnsTwiceAttribute: uint = 536870912u;
// 1 << 30
const LLVMUWTableAttribute: uint = 1073741824u;
const LLVMNonLazyBindAttribute: uint = 2147483648u;
enum Attribute {
ZExtAttribute = 1,
SExtAttribute = 2,
NoReturnAttribute = 4,
InRegAttribute = 8,
StructRetAttribute = 16,
NoUnwindAttribute = 32,
NoAliasAttribute = 64,
ByValAttribute = 128,
NestAttribute = 256,
ReadNoneAttribute = 512,
ReadOnlyAttribute = 1024,
NoInlineAttribute = 2048,
AlwaysInlineAttribute = 4096,
OptimizeForSizeAttribute = 8192,
StackProtectAttribute = 16384,
StackProtectReqAttribute = 32768,
// 31 << 16
AlignmentAttribute = 2031616,
NoCaptureAttribute = 2097152,
NoRedZoneAttribute = 4194304,
NoImplicitFloatAttribute = 8388608,
NakedAttribute = 16777216,
InlineHintAttribute = 33554432,
// 7 << 26
StackAttribute = 469762048,
ReturnsTwiceAttribute = 536870912,
// 1 << 30
UWTableAttribute = 1073741824,
NonLazyBindAttribute = 2147483648,
}
// Consts for the LLVM IntPredicate type, pre-cast to uint. // Consts for the LLVM IntPredicate type, pre-cast to uint.
// FIXME: as above. // FIXME: as above.
enum IntPredicate {
const LLVMIntEQ: uint = 32u; IntEQ = 32,
const LLVMIntNE: uint = 33u; IntNE = 33,
const LLVMIntUGT: uint = 34u; IntUGT = 34,
const LLVMIntUGE: uint = 35u; IntUGE = 35,
const LLVMIntULT: uint = 36u; IntULT = 36,
const LLVMIntULE: uint = 37u; IntULE = 37,
const LLVMIntSGT: uint = 38u; IntSGT = 38,
const LLVMIntSGE: uint = 39u; IntSGE = 39,
const LLVMIntSLT: uint = 40u; IntSLT = 40,
const LLVMIntSLE: uint = 41u; IntSLE = 41,
}
// Consts for the LLVM RealPredicate type, pre-case to uint. // Consts for the LLVM RealPredicate type, pre-case to uint.
// FIXME: as above. // FIXME: as above.
const LLVMRealOEQ: uint = 1u; enum RealPredicate {
const LLVMRealOGT: uint = 2u; RealOEQ = 1,
const LLVMRealOGE: uint = 3u; RealOGT = 2,
const LLVMRealOLT: uint = 4u; RealOGE = 3,
const LLVMRealOLE: uint = 5u; RealOLT = 4,
const LLVMRealONE: uint = 6u; RealOLE = 5,
RealONE = 6,
RealORD = 7,
RealUNO = 8,
RealUEQ = 9,
RealUGT = 10,
RealUGE = 11,
RealULT = 12,
RealULE = 13,
RealUNE = 14,
}
const LLVMRealORD: uint = 7u; // Opaque pointer types
const LLVMRealUNO: uint = 8u; enum Module_opaque {}
const LLVMRealUEQ: uint = 9u; type ModuleRef = *Module_opaque;
const LLVMRealUGT: uint = 10u; enum Context_opaque {}
const LLVMRealUGE: uint = 11u; type ContextRef = *Context_opaque;
const LLVMRealULT: uint = 12u; enum Type_opaque {}
const LLVMRealULE: uint = 13u; type TypeRef = *Type_opaque;
const LLVMRealUNE: uint = 14u; enum Value_opaque {}
type ValueRef = *Value_opaque;
enum BasicBlock_opaque {}
type BasicBlockRef = *BasicBlock_opaque;
enum Builder_opaque {}
type BuilderRef = *Builder_opaque;
enum MemoryBuffer_opaque {}
type MemoryBufferRef = *MemoryBuffer_opaque;
enum PassManager_opaque {}
type PassManagerRef = *PassManager_opaque;
enum PassManagerBuilder_opaque {}
type PassManagerBuilderRef = *PassManagerBuilder_opaque;
enum Use_opaque {}
type UseRef = *Use_opaque;
enum TargetData_opaque {}
type TargetDataRef = *TargetData_opaque;
enum ObjectFile_opaque {}
type ObjectFileRef = *ObjectFile_opaque;
enum SectionIterator_opaque {}
type SectionIteratorRef = *SectionIterator_opaque;
#[link_args = "-Lrustllvm"] #[link_args = "-Lrustllvm"]
#[link_name = "rustllvm"] #[link_name = "rustllvm"]
#[abi = "cdecl"] #[abi = "cdecl"]
native mod llvm { native mod llvm {
type ModuleRef;
type ContextRef;
type TypeRef;
type TypeHandleRef;
type ValueRef;
type BasicBlockRef;
type BuilderRef;
type ModuleProviderRef;
type MemoryBufferRef;
type PassManagerRef;
type PassManagerBuilderRef;
type UseRef;
type TargetDataRef;
/* FIXME: These are enums in the C header. Represent them how, in rust? */
type Linkage;
type Attribute;
type Visibility;
type CallConv;
type IntPredicate;
type RealPredicate;
type Opcode;
/* Create and destroy contexts. */ /* Create and destroy contexts. */
fn LLVMContextCreate() -> ContextRef; fn LLVMContextCreate() -> ContextRef;
fn LLVMGetGlobalContext() -> ContextRef; fn LLVMGetGlobalContext() -> ContextRef;
@ -422,12 +427,12 @@ native mod llvm {
/* Operations on global variables, functions, and aliases (globals) */ /* Operations on global variables, functions, and aliases (globals) */
fn LLVMGetGlobalParent(Global: ValueRef) -> ModuleRef; fn LLVMGetGlobalParent(Global: ValueRef) -> ModuleRef;
fn LLVMIsDeclaration(Global: ValueRef) -> Bool; fn LLVMIsDeclaration(Global: ValueRef) -> Bool;
fn LLVMGetLinkage(Global: ValueRef) -> Linkage; fn LLVMGetLinkage(Global: ValueRef) -> unsigned;
fn LLVMSetLinkage(Global: ValueRef, Link: Linkage); fn LLVMSetLinkage(Global: ValueRef, Link: unsigned);
fn LLVMGetSection(Global: ValueRef) -> sbuf; fn LLVMGetSection(Global: ValueRef) -> sbuf;
fn LLVMSetSection(Global: ValueRef, Section: sbuf); fn LLVMSetSection(Global: ValueRef, Section: sbuf);
fn LLVMGetVisibility(Global: ValueRef) -> Visibility; fn LLVMGetVisibility(Global: ValueRef) -> unsigned;
fn LLVMSetVisibility(Global: ValueRef, Viz: Visibility); fn LLVMSetVisibility(Global: ValueRef, Viz: unsigned);
fn LLVMGetAlignment(Global: ValueRef) -> unsigned; fn LLVMGetAlignment(Global: ValueRef) -> unsigned;
fn LLVMSetAlignment(Global: ValueRef, Bytes: unsigned); fn LLVMSetAlignment(Global: ValueRef, Bytes: unsigned);
@ -469,9 +474,9 @@ native mod llvm {
fn LLVMSetFunctionCallConv(Fn: ValueRef, CC: unsigned); fn LLVMSetFunctionCallConv(Fn: ValueRef, CC: unsigned);
fn LLVMGetGC(Fn: ValueRef) -> sbuf; fn LLVMGetGC(Fn: ValueRef) -> sbuf;
fn LLVMSetGC(Fn: ValueRef, Name: sbuf); fn LLVMSetGC(Fn: ValueRef, Name: sbuf);
fn LLVMAddFunctionAttr(Fn: ValueRef, PA: Attribute, HighPA: unsigned); fn LLVMAddFunctionAttr(Fn: ValueRef, PA: unsigned, HighPA: unsigned);
fn LLVMGetFunctionAttr(Fn: ValueRef) -> Attribute; fn LLVMGetFunctionAttr(Fn: ValueRef) -> unsigned;
fn LLVMRemoveFunctionAttr(Fn: ValueRef, PA: Attribute, HighPA: unsigned); fn LLVMRemoveFunctionAttr(Fn: ValueRef, PA: unsigned, HighPA: unsigned);
/* Operations on parameters */ /* Operations on parameters */
fn LLVMCountParams(Fn: ValueRef) -> unsigned; fn LLVMCountParams(Fn: ValueRef) -> unsigned;
@ -482,9 +487,9 @@ native mod llvm {
fn LLVMGetLastParam(Fn: ValueRef) -> ValueRef; fn LLVMGetLastParam(Fn: ValueRef) -> ValueRef;
fn LLVMGetNextParam(Arg: ValueRef) -> ValueRef; fn LLVMGetNextParam(Arg: ValueRef) -> ValueRef;
fn LLVMGetPreviousParam(Arg: ValueRef) -> ValueRef; fn LLVMGetPreviousParam(Arg: ValueRef) -> ValueRef;
fn LLVMAddAttribute(Arg: ValueRef, PA: Attribute); fn LLVMAddAttribute(Arg: ValueRef, PA: unsigned);
fn LLVMRemoveAttribute(Arg: ValueRef, PA: Attribute); fn LLVMRemoveAttribute(Arg: ValueRef, PA: unsigned);
fn LLVMGetAttribute(Arg: ValueRef) -> Attribute; fn LLVMGetAttribute(Arg: ValueRef) -> unsigned;
fn LLVMSetParamAlignment(Arg: ValueRef, align: unsigned); fn LLVMSetParamAlignment(Arg: ValueRef, align: unsigned);
/* Operations on basic blocks */ /* Operations on basic blocks */
@ -520,9 +525,9 @@ native mod llvm {
/* Operations on call sites */ /* Operations on call sites */
fn LLVMSetInstructionCallConv(Instr: ValueRef, CC: unsigned); fn LLVMSetInstructionCallConv(Instr: ValueRef, CC: unsigned);
fn LLVMGetInstructionCallConv(Instr: ValueRef) -> unsigned; fn LLVMGetInstructionCallConv(Instr: ValueRef) -> unsigned;
fn LLVMAddInstrAttribute(Instr: ValueRef, index: unsigned, IA: Attribute); fn LLVMAddInstrAttribute(Instr: ValueRef, index: unsigned, IA: unsigned);
fn LLVMRemoveInstrAttribute(Instr: ValueRef, index: unsigned, fn LLVMRemoveInstrAttribute(Instr: ValueRef, index: unsigned,
IA: Attribute); IA: unsigned);
fn LLVMSetInstrParamAlignment(Instr: ValueRef, index: unsigned, fn LLVMSetInstrParamAlignment(Instr: ValueRef, index: unsigned,
align: unsigned); align: unsigned);
@ -836,9 +841,6 @@ native mod llvm {
/* Stuff that's in rustllvm/ because it's not upstream yet. */ /* Stuff that's in rustllvm/ because it's not upstream yet. */
type ObjectFileRef;
type SectionIteratorRef;
/** Opens an object file. */ /** Opens an object file. */
fn LLVMCreateObjectFile(MemBuf: MemoryBufferRef) -> ObjectFileRef; fn LLVMCreateObjectFile(MemBuf: MemoryBufferRef) -> ObjectFileRef;
/** Closes an object file. */ /** Closes an object file. */
@ -907,6 +909,16 @@ native mod llvm {
fn LLVMLinkModules(Dest: ModuleRef, Src: ModuleRef) -> Bool; fn LLVMLinkModules(Dest: ModuleRef, Src: ModuleRef) -> Bool;
} }
fn SetInstructionCallConv(Instr: ValueRef, CC: CallConv) {
llvm::LLVMSetInstructionCallConv(Instr, CC as unsigned);
}
fn SetFunctionCallConv(Fn: ValueRef, CC: CallConv) {
llvm::LLVMSetFunctionCallConv(Fn, CC as unsigned);
}
fn SetLinkage(Global: ValueRef, Link: Linkage) {
llvm::LLVMSetLinkage(Global, Link as unsigned);
}
/* Memory-managed object interface to type handles. */ /* Memory-managed object interface to type handles. */
type type_names = @{type_names: std::map::hashmap<TypeRef, str>, type type_names = @{type_names: std::map::hashmap<TypeRef, str>,

View file

@ -2,7 +2,7 @@ import core::{vec, str, option, sys, ctypes, unsafe};
import std::fs; import std::fs;
import std::map::hashmap; import std::map::hashmap;
import lib::llvm::llvm; import lib::llvm::llvm;
import lib::llvm::llvm::ValueRef; import lib::llvm::ValueRef;
import trans::common::*; import trans::common::*;
import trans::base; import trans::base;
import trans::build::B; import trans::build::B;

View file

@ -1,7 +1,6 @@
// Routines useful for garbage collection. // Routines useful for garbage collection.
import lib::llvm::True; import lib::llvm::{True, ValueRef};
import lib::llvm::llvm::ValueRef;
import trans::base::get_tydesc; import trans::base::get_tydesc;
import trans::common::*; import trans::common::*;
import trans::base; import trans::base;

View file

@ -2,8 +2,7 @@
// This substitutes for the runtime tags used by e.g. MLs. // This substitutes for the runtime tags used by e.g. MLs.
import lib::llvm::llvm; import lib::llvm::llvm;
import lib::llvm::{True, False}; import lib::llvm::{True, False, ModuleRef, TypeRef, ValueRef};
import lib::llvm::llvm::{ModuleRef, TypeRef, ValueRef};
import driver::session; import driver::session;
import driver::session::session; import driver::session::session;
import trans::base; import trans::base;
@ -97,9 +96,7 @@ fn mk_global(ccx: @crate_ctxt, name: str, llval: ValueRef, internal: bool) ->
lib::llvm::llvm::LLVMSetGlobalConstant(llglobal, True); lib::llvm::llvm::LLVMSetGlobalConstant(llglobal, True);
if internal { if internal {
lib::llvm::llvm::LLVMSetLinkage(llglobal, lib::llvm::SetLinkage(llglobal, lib::llvm::InternalLinkage);
lib::llvm::LLVMInternalLinkage as
lib::llvm::llvm::Linkage);
} }
ret llglobal; ret llglobal;
@ -606,9 +603,8 @@ fn gen_shape_tables(ccx: @crate_ctxt) {
[lltagstable, llresourcestable]); [lltagstable, llresourcestable]);
lib::llvm::llvm::LLVMSetInitializer(ccx.shape_cx.llshapetables, lltables); lib::llvm::llvm::LLVMSetInitializer(ccx.shape_cx.llshapetables, lltables);
lib::llvm::llvm::LLVMSetGlobalConstant(ccx.shape_cx.llshapetables, True); lib::llvm::llvm::LLVMSetGlobalConstant(ccx.shape_cx.llshapetables, True);
lib::llvm::llvm::LLVMSetLinkage(ccx.shape_cx.llshapetables, lib::llvm::SetLinkage(ccx.shape_cx.llshapetables,
lib::llvm::LLVMInternalLinkage as lib::llvm::InternalLinkage);
lib::llvm::llvm::Linkage);
} }
// ______________________________________________________________________ // ______________________________________________________________________

View file

@ -3,7 +3,7 @@ import option::{some, none};
import driver::session::session; import driver::session::session;
import lib::llvm::llvm; import lib::llvm::llvm;
import lib::llvm::llvm::{ValueRef, BasicBlockRef}; import lib::llvm::{ValueRef, BasicBlockRef};
import pat_util::*; import pat_util::*;
import build::*; import build::*;
import base::{new_sub_block_ctxt, new_scope_block_ctxt, import base::{new_sub_block_ctxt, new_scope_block_ctxt,

View file

@ -32,7 +32,7 @@ import pat_util::*;
import visit::vt; import visit::vt;
import util::common::*; import util::common::*;
import lib::llvm::{llvm, mk_target_data, mk_type_names}; import lib::llvm::{llvm, mk_target_data, mk_type_names};
import lib::llvm::llvm::{ModuleRef, ValueRef, TypeRef, BasicBlockRef}; import lib::llvm::{ModuleRef, ValueRef, TypeRef, BasicBlockRef};
import lib::llvm::{True, False}; import lib::llvm::{True, False};
import link::{mangle_internal_name_by_type_only, import link::{mangle_internal_name_by_type_only,
mangle_internal_name_by_seq, mangle_internal_name_by_seq,
@ -288,17 +288,17 @@ fn log_fn_time(ccx: @crate_ctxt, name: str, start: time::timeval,
} }
fn decl_fn(llmod: ModuleRef, name: str, cc: uint, llty: TypeRef) -> fn decl_fn(llmod: ModuleRef, name: str, cc: lib::llvm::CallConv,
ValueRef { llty: TypeRef) -> ValueRef {
let llfn: ValueRef = let llfn: ValueRef = str::as_buf(name, {|buf|
str::as_buf(name, {|buf| llvm::LLVMGetOrInsertFunction(llmod, buf, llty)
llvm::LLVMGetOrInsertFunction(llmod, buf, llty) }); });
llvm::LLVMSetFunctionCallConv(llfn, cc as c_uint); lib::llvm::SetFunctionCallConv(llfn, cc);
ret llfn; ret llfn;
} }
fn decl_cdecl_fn(llmod: ModuleRef, name: str, llty: TypeRef) -> ValueRef { fn decl_cdecl_fn(llmod: ModuleRef, name: str, llty: TypeRef) -> ValueRef {
ret decl_fn(llmod, name, lib::llvm::LLVMCCallConv, llty); ret decl_fn(llmod, name, lib::llvm::CCallConv, llty);
} }
@ -307,13 +307,12 @@ fn decl_cdecl_fn(llmod: ModuleRef, name: str, llty: TypeRef) -> ValueRef {
fn decl_internal_cdecl_fn(llmod: ModuleRef, name: str, llty: TypeRef) -> fn decl_internal_cdecl_fn(llmod: ModuleRef, name: str, llty: TypeRef) ->
ValueRef { ValueRef {
let llfn = decl_cdecl_fn(llmod, name, llty); let llfn = decl_cdecl_fn(llmod, name, llty);
llvm::LLVMSetLinkage(llfn, lib::llvm::SetLinkage(llfn, lib::llvm::InternalLinkage);
lib::llvm::LLVMInternalLinkage as llvm::Linkage);
ret llfn; ret llfn;
} }
fn get_extern_fn(externs: hashmap<str, ValueRef>, llmod: ModuleRef, name: str, fn get_extern_fn(externs: hashmap<str, ValueRef>, llmod: ModuleRef, name: str,
cc: uint, ty: TypeRef) -> ValueRef { cc: lib::llvm::CallConv, ty: TypeRef) -> ValueRef {
if externs.contains_key(name) { ret externs.get(name); } if externs.contains_key(name) { ret externs.get(name); }
let f = decl_fn(llmod, name, cc, ty); let f = decl_fn(llmod, name, cc, ty);
externs.insert(name, f); externs.insert(name, f);
@ -336,8 +335,7 @@ fn get_simple_extern_fn(cx: @block_ctxt,
let inputs = vec::init_elt::<TypeRef>(n_args as uint, ccx.int_type); let inputs = vec::init_elt::<TypeRef>(n_args as uint, ccx.int_type);
let output = ccx.int_type; let output = ccx.int_type;
let t = T_fn(inputs, output); let t = T_fn(inputs, output);
ret get_extern_fn(externs, llmod, name, ret get_extern_fn(externs, llmod, name, lib::llvm::CCallConv, t);
lib::llvm::LLVMCCallConv, t);
} }
fn trans_native_call(cx: @block_ctxt, externs: hashmap<str, ValueRef>, fn trans_native_call(cx: @block_ctxt, externs: hashmap<str, ValueRef>,
@ -370,12 +368,12 @@ fn trans_shared_free(cx: @block_ctxt, v: ValueRef) -> @block_ctxt {
} }
fn umax(cx: @block_ctxt, a: ValueRef, b: ValueRef) -> ValueRef { fn umax(cx: @block_ctxt, a: ValueRef, b: ValueRef) -> ValueRef {
let cond = ICmp(cx, lib::llvm::LLVMIntULT, a, b); let cond = ICmp(cx, lib::llvm::IntULT, a, b);
ret Select(cx, cond, b, a); ret Select(cx, cond, b, a);
} }
fn umin(cx: @block_ctxt, a: ValueRef, b: ValueRef) -> ValueRef { fn umin(cx: @block_ctxt, a: ValueRef, b: ValueRef) -> ValueRef {
let cond = ICmp(cx, lib::llvm::LLVMIntULT, a, b); let cond = ICmp(cx, lib::llvm::IntULT, a, b);
ret Select(cx, cond, a, b); ret Select(cx, cond, a, b);
} }
@ -992,32 +990,25 @@ fn get_static_tydesc(cx: @block_ctxt, t: ty::t, ty_params: [uint])
} }
fn set_no_inline(f: ValueRef) { fn set_no_inline(f: ValueRef) {
llvm::LLVMAddFunctionAttr(f, llvm::LLVMAddFunctionAttr(f, lib::llvm::NoInlineAttribute as c_uint,
lib::llvm::LLVMNoInlineAttribute as
lib::llvm::llvm::Attribute,
0u as c_uint); 0u as c_uint);
} }
// Tell LLVM to emit the information necessary to unwind the stack for the // Tell LLVM to emit the information necessary to unwind the stack for the
// function f. // function f.
fn set_uwtable(f: ValueRef) { fn set_uwtable(f: ValueRef) {
llvm::LLVMAddFunctionAttr(f, llvm::LLVMAddFunctionAttr(f, lib::llvm::UWTableAttribute as c_uint,
lib::llvm::LLVMUWTableAttribute as
lib::llvm::llvm::Attribute,
0u as c_uint); 0u as c_uint);
} }
fn set_always_inline(f: ValueRef) { fn set_always_inline(f: ValueRef) {
llvm::LLVMAddFunctionAttr(f, llvm::LLVMAddFunctionAttr(f, lib::llvm::AlwaysInlineAttribute as c_uint,
lib::llvm::LLVMAlwaysInlineAttribute as
lib::llvm::llvm::Attribute,
0u as c_uint); 0u as c_uint);
} }
fn set_custom_stack_growth_fn(f: ValueRef) { fn set_custom_stack_growth_fn(f: ValueRef) {
// TODO: Remove this hack to work around the lack of u64 in the FFI. // TODO: Remove this hack to work around the lack of u64 in the FFI.
llvm::LLVMAddFunctionAttr(f, 0 as lib::llvm::llvm::Attribute, llvm::LLVMAddFunctionAttr(f, 0u as c_uint, 1u as c_uint);
1u as c_uint);
} }
fn set_glue_inlining(cx: @local_ctxt, f: ValueRef, t: ty::t) { fn set_glue_inlining(cx: @local_ctxt, f: ValueRef, t: ty::t) {
@ -1089,8 +1080,7 @@ fn make_generic_glue_inner(cx: @local_ctxt, t: ty::t,
llfn: ValueRef, helper: glue_helper, llfn: ValueRef, helper: glue_helper,
ty_params: [uint]) -> ValueRef { ty_params: [uint]) -> ValueRef {
let fcx = new_fn_ctxt(cx, llfn, none); let fcx = new_fn_ctxt(cx, llfn, none);
llvm::LLVMSetLinkage(llfn, lib::llvm::SetLinkage(llfn, lib::llvm::InternalLinkage);
lib::llvm::LLVMInternalLinkage as llvm::Linkage);
cx.ccx.stats.n_glues_created += 1u; cx.ccx.stats.n_glues_created += 1u;
// Any nontrivial glue is with values passed *by alias*; this is a // Any nontrivial glue is with values passed *by alias*; this is a
// requirement since in many contexts glue is invoked indirectly and // requirement since in many contexts glue is invoked indirectly and
@ -1193,8 +1183,7 @@ fn emit_tydescs(ccx: @crate_ctxt) {
let gvar = ti.tydesc; let gvar = ti.tydesc;
llvm::LLVMSetInitializer(gvar, tydesc); llvm::LLVMSetInitializer(gvar, tydesc);
llvm::LLVMSetGlobalConstant(gvar, True); llvm::LLVMSetGlobalConstant(gvar, True);
llvm::LLVMSetLinkage(gvar, lib::llvm::SetLinkage(gvar, lib::llvm::InternalLinkage);
lib::llvm::LLVMInternalLinkage as llvm::Linkage);
}; };
} }
@ -1402,7 +1391,7 @@ fn decr_refcnt_maybe_free(cx: @block_ctxt, box_ptr: ValueRef, t: ty::t)
let rc = Load(rc_adj_cx, rc_ptr); let rc = Load(rc_adj_cx, rc_ptr);
rc = Sub(rc_adj_cx, rc, C_int(ccx, 1)); rc = Sub(rc_adj_cx, rc, C_int(ccx, 1));
Store(rc_adj_cx, rc, rc_ptr); Store(rc_adj_cx, rc, rc_ptr);
let zero_test = ICmp(rc_adj_cx, lib::llvm::LLVMIntEQ, C_int(ccx, 0), rc); let zero_test = ICmp(rc_adj_cx, lib::llvm::IntEQ, C_int(ccx, 0), rc);
CondBr(rc_adj_cx, zero_test, free_cx.llbb, next_cx.llbb); CondBr(rc_adj_cx, zero_test, free_cx.llbb, next_cx.llbb);
let free_cx = free_ty(free_cx, box_ptr, t); let free_cx = free_ty(free_cx, box_ptr, t);
Br(free_cx, next_cx.llbb); Br(free_cx, next_cx.llbb);
@ -1472,36 +1461,36 @@ fn compare_scalar_values(cx: @block_ctxt, lhs: ValueRef, rhs: ValueRef,
} }
floating_point { floating_point {
let cmp = alt op { let cmp = alt op {
ast::eq { lib::llvm::LLVMRealOEQ } ast::eq { lib::llvm::RealOEQ }
ast::ne { lib::llvm::LLVMRealUNE } ast::ne { lib::llvm::RealUNE }
ast::lt { lib::llvm::LLVMRealOLT } ast::lt { lib::llvm::RealOLT }
ast::le { lib::llvm::LLVMRealOLE } ast::le { lib::llvm::RealOLE }
ast::gt { lib::llvm::LLVMRealOGT } ast::gt { lib::llvm::RealOGT }
ast::ge { lib::llvm::LLVMRealOGE } ast::ge { lib::llvm::RealOGE }
_ { die(); } _ { die(); }
}; };
ret FCmp(cx, cmp, lhs, rhs); ret FCmp(cx, cmp, lhs, rhs);
} }
signed_int { signed_int {
let cmp = alt op { let cmp = alt op {
ast::eq { lib::llvm::LLVMIntEQ } ast::eq { lib::llvm::IntEQ }
ast::ne { lib::llvm::LLVMIntNE } ast::ne { lib::llvm::IntNE }
ast::lt { lib::llvm::LLVMIntSLT } ast::lt { lib::llvm::IntSLT }
ast::le { lib::llvm::LLVMIntSLE } ast::le { lib::llvm::IntSLE }
ast::gt { lib::llvm::LLVMIntSGT } ast::gt { lib::llvm::IntSGT }
ast::ge { lib::llvm::LLVMIntSGE } ast::ge { lib::llvm::IntSGE }
_ { die(); } _ { die(); }
}; };
ret ICmp(cx, cmp, lhs, rhs); ret ICmp(cx, cmp, lhs, rhs);
} }
unsigned_int { unsigned_int {
let cmp = alt op { let cmp = alt op {
ast::eq { lib::llvm::LLVMIntEQ } ast::eq { lib::llvm::IntEQ }
ast::ne { lib::llvm::LLVMIntNE } ast::ne { lib::llvm::IntNE }
ast::lt { lib::llvm::LLVMIntULT } ast::lt { lib::llvm::IntULT }
ast::le { lib::llvm::LLVMIntULE } ast::le { lib::llvm::IntULE }
ast::gt { lib::llvm::LLVMIntUGT } ast::gt { lib::llvm::IntUGT }
ast::ge { lib::llvm::LLVMIntUGE } ast::ge { lib::llvm::IntUGE }
_ { die(); } _ { die(); }
}; };
ret ICmp(cx, cmp, lhs, rhs); ret ICmp(cx, cmp, lhs, rhs);
@ -1920,7 +1909,7 @@ fn copy_val(cx: @block_ctxt, action: copy_action, dst: ValueRef,
let next_cx = new_sub_block_ctxt(cx, "next"); let next_cx = new_sub_block_ctxt(cx, "next");
let dstcmp = load_if_immediate(cx, dst, t); let dstcmp = load_if_immediate(cx, dst, t);
let self_assigning = let self_assigning =
ICmp(cx, lib::llvm::LLVMIntNE, ICmp(cx, lib::llvm::IntNE,
PointerCast(cx, dstcmp, val_ty(src)), src); PointerCast(cx, dstcmp, val_ty(src)), src);
CondBr(cx, self_assigning, do_copy_cx.llbb, next_cx.llbb); CondBr(cx, self_assigning, do_copy_cx.llbb, next_cx.llbb);
do_copy_cx = copy_val_no_check(do_copy_cx, action, dst, src, t); do_copy_cx = copy_val_no_check(do_copy_cx, action, dst, src, t);
@ -2598,13 +2587,10 @@ fn lookup_discriminant(lcx: @local_ctxt, vid: ast::def_id) -> ValueRef {
// It's an external discriminant that we haven't seen yet. // It's an external discriminant that we haven't seen yet.
assert (vid.crate != ast::local_crate); assert (vid.crate != ast::local_crate);
let sym = csearch::get_symbol(lcx.ccx.sess.cstore, vid); let sym = csearch::get_symbol(lcx.ccx.sess.cstore, vid);
let gvar = let gvar = str::as_buf(sym, {|buf|
str::as_buf(sym, llvm::LLVMAddGlobal(ccx.llmod, ccx.int_type, buf)
{|buf| });
llvm::LLVMAddGlobal(ccx.llmod, ccx.int_type, buf) lib::llvm::SetLinkage(gvar, lib::llvm::ExternalLinkage);
});
llvm::LLVMSetLinkage(gvar,
lib::llvm::LLVMExternalLinkage as llvm::Linkage);
llvm::LLVMSetGlobalConstant(gvar, True); llvm::LLVMSetGlobalConstant(gvar, True);
lcx.ccx.discrims.insert(vid, gvar); lcx.ccx.discrims.insert(vid, gvar);
ret gvar; ret gvar;
@ -2739,7 +2725,7 @@ fn trans_index(cx: @block_ctxt, ex: @ast::expr, base: @ast::expr,
maybe_name_value(bcx_ccx(cx), scaled_ix, "scaled_ix"); maybe_name_value(bcx_ccx(cx), scaled_ix, "scaled_ix");
let lim = tvec::get_fill(bcx, v); let lim = tvec::get_fill(bcx, v);
let body = tvec::get_dataptr(bcx, v, type_of_or_i8(bcx, unit_ty)); let body = tvec::get_dataptr(bcx, v, type_of_or_i8(bcx, unit_ty));
let bounds_check = ICmp(bcx, lib::llvm::LLVMIntULT, scaled_ix, lim); let bounds_check = ICmp(bcx, lib::llvm::IntULT, scaled_ix, lim);
let fail_cx = new_sub_block_ctxt(bcx, "fail"); let fail_cx = new_sub_block_ctxt(bcx, "fail");
let next_cx = new_sub_block_ctxt(bcx, "next"); let next_cx = new_sub_block_ctxt(bcx, "next");
let ncx = bcx_ccx(next_cx); let ncx = bcx_ccx(next_cx);
@ -3760,8 +3746,7 @@ fn trans_log(lvl: @ast::expr, cx: @block_ctxt, e: @ast::expr) -> @block_ctxt {
}); });
llvm::LLVMSetGlobalConstant(global, False); llvm::LLVMSetGlobalConstant(global, False);
llvm::LLVMSetInitializer(global, C_null(T_i32())); llvm::LLVMSetInitializer(global, C_null(T_i32()));
llvm::LLVMSetLinkage(global, lib::llvm::SetLinkage(global, lib::llvm::InternalLinkage);
lib::llvm::LLVMInternalLinkage as llvm::Linkage);
lcx.ccx.module_data.insert(modname, global); lcx.ccx.module_data.insert(modname, global);
global global
}; };
@ -3772,7 +3757,7 @@ fn trans_log(lvl: @ast::expr, cx: @block_ctxt, e: @ast::expr) -> @block_ctxt {
Br(cx, level_cx.llbb); Br(cx, level_cx.llbb);
let level_res = trans_temp_expr(level_cx, lvl); let level_res = trans_temp_expr(level_cx, lvl);
let test = ICmp(level_res.bcx, lib::llvm::LLVMIntUGE, let test = ICmp(level_res.bcx, lib::llvm::IntUGE,
load, level_res.val); load, level_res.val);
CondBr(level_res.bcx, test, log_cx.llbb, after_cx.llbb); CondBr(level_res.bcx, test, log_cx.llbb, after_cx.llbb);
@ -4834,7 +4819,7 @@ fn trans_native_mod(lcx: @local_ctxt, native_mod: ast::native_mod,
fn build_shim_fn(lcx: @local_ctxt, fn build_shim_fn(lcx: @local_ctxt,
native_item: @ast::native_item, native_item: @ast::native_item,
tys: @c_stack_tys, tys: @c_stack_tys,
cc: uint) -> ValueRef { cc: lib::llvm::CallConv) -> ValueRef {
let lname = link_name(native_item); let lname = link_name(native_item);
let ccx = lcx_ccx(lcx); let ccx = lcx_ccx(lcx);
@ -4861,7 +4846,7 @@ fn trans_native_mod(lcx: @local_ctxt, native_mod: ast::native_mod,
// Create the call itself and store the return value: // Create the call itself and store the return value:
let llretval = CallWithConv(bcx, llbasefn, let llretval = CallWithConv(bcx, llbasefn,
llargvals, cc as c_uint); // r llargvals, cc); // r
if tys.ret_def { if tys.ret_def {
// R** llretptr = &args->r; // R** llretptr = &args->r;
let llretptr = GEPi(bcx, llargbundle, [0, n as int]); let llretptr = GEPi(bcx, llargbundle, [0, n as int]);
@ -4911,11 +4896,11 @@ fn trans_native_mod(lcx: @local_ctxt, native_mod: ast::native_mod,
} }
let ccx = lcx_ccx(lcx); let ccx = lcx_ccx(lcx);
let cc = lib::llvm::LLVMCCallConv; let cc = lib::llvm::CCallConv;
alt abi { alt abi {
ast::native_abi_rust_intrinsic { ret; } ast::native_abi_rust_intrinsic { ret; }
ast::native_abi_cdecl { cc = lib::llvm::LLVMCCallConv; } ast::native_abi_cdecl { cc = lib::llvm::CCallConv; }
ast::native_abi_stdcall { cc = lib::llvm::LLVMX86StdcallCallConv; } ast::native_abi_stdcall { cc = lib::llvm::X86StdcallCallConv; }
} }
for native_item in native_mod.items { for native_item in native_mod.items {
@ -5076,7 +5061,7 @@ fn create_main_wrapper(ccx: @crate_ctxt, sp: span, main_llfn: ValueRef,
let nt = ty::mk_nil(ccx.tcx); let nt = ty::mk_nil(ccx.tcx);
let llfty = type_of_fn(ccx, [vecarg_ty], nt, []); let llfty = type_of_fn(ccx, [vecarg_ty], nt, []);
let llfdecl = decl_fn(ccx.llmod, "_rust_main", let llfdecl = decl_fn(ccx.llmod, "_rust_main",
lib::llvm::LLVMCCallConv, llfty); lib::llvm::CCallConv, llfty);
let fcx = new_fn_ctxt(new_local_ctxt(ccx), llfdecl, none); let fcx = new_fn_ctxt(new_local_ctxt(ccx), llfdecl, none);
@ -5230,7 +5215,7 @@ fn collect_native_item(ccx: @crate_ctxt,
let ri_name = "rust_intrinsic_" + link_name(i); let ri_name = "rust_intrinsic_" + link_name(i);
let llnativefn = get_extern_fn( let llnativefn = get_extern_fn(
ccx.externs, ccx.llmod, ri_name, ccx.externs, ccx.llmod, ri_name,
lib::llvm::LLVMCCallConv, fn_type); lib::llvm::CCallConv, fn_type);
ccx.item_ids.insert(id, llnativefn); ccx.item_ids.insert(id, llnativefn);
ccx.item_symbols.insert(id, ri_name); ccx.item_symbols.insert(id, ri_name);
} }
@ -5433,11 +5418,10 @@ fn trap(bcx: @block_ctxt) {
fn create_module_map(ccx: @crate_ctxt) -> ValueRef { fn create_module_map(ccx: @crate_ctxt) -> ValueRef {
let elttype = T_struct([ccx.int_type, ccx.int_type]); let elttype = T_struct([ccx.int_type, ccx.int_type]);
let maptype = T_array(elttype, ccx.module_data.size() + 1u); let maptype = T_array(elttype, ccx.module_data.size() + 1u);
let map = let map = str::as_buf("_rust_mod_map", {|buf|
str::as_buf("_rust_mod_map", llvm::LLVMAddGlobal(ccx.llmod, maptype, buf)
{|buf| llvm::LLVMAddGlobal(ccx.llmod, maptype, buf) }); });
llvm::LLVMSetLinkage(map, lib::llvm::SetLinkage(map, lib::llvm::InternalLinkage);
lib::llvm::LLVMInternalLinkage as llvm::Linkage);
let elts: [ValueRef] = []; let elts: [ValueRef] = [];
ccx.module_data.items {|key, val| ccx.module_data.items {|key, val|
let elt = C_struct([p2i(ccx, C_cstr(ccx, key)), let elt = C_struct([p2i(ccx, C_cstr(ccx, key)),
@ -5465,8 +5449,7 @@ fn decl_crate_map(sess: session::session, mapname: str,
let map = str::as_buf(sym_name, {|buf| let map = str::as_buf(sym_name, {|buf|
llvm::LLVMAddGlobal(llmod, maptype, buf) llvm::LLVMAddGlobal(llmod, maptype, buf)
}); });
llvm::LLVMSetLinkage(map, lib::llvm::LLVMExternalLinkage lib::llvm::SetLinkage(map, lib::llvm::ExternalLinkage);
as llvm::Linkage);
ret map; ret map;
} }
@ -5500,19 +5483,14 @@ fn write_metadata(cx: @crate_ctxt, crate: @ast::crate) {
str::as_buf(cx.sess.targ_cfg.target_strs.meta_sect_name, {|buf| str::as_buf(cx.sess.targ_cfg.target_strs.meta_sect_name, {|buf|
llvm::LLVMSetSection(llglobal, buf) llvm::LLVMSetSection(llglobal, buf)
}); });
llvm::LLVMSetLinkage(llglobal, lib::llvm::SetLinkage(llglobal, lib::llvm::InternalLinkage);
lib::llvm::LLVMInternalLinkage as llvm::Linkage);
let t_ptr_i8 = T_ptr(T_i8()); let t_ptr_i8 = T_ptr(T_i8());
llglobal = llvm::LLVMConstBitCast(llglobal, t_ptr_i8); llglobal = llvm::LLVMConstBitCast(llglobal, t_ptr_i8);
let llvm_used = let llvm_used = str::as_buf("llvm.used", {|buf|
str::as_buf("llvm.used", llvm::LLVMAddGlobal(cx.llmod, T_array(t_ptr_i8, 1u), buf)
{|buf| });
llvm::LLVMAddGlobal(cx.llmod, T_array(t_ptr_i8, 1u), lib::llvm::SetLinkage(llvm_used, lib::llvm::AppendingLinkage);
buf)
});
llvm::LLVMSetLinkage(llvm_used,
lib::llvm::LLVMAppendingLinkage as llvm::Linkage);
llvm::LLVMSetInitializer(llvm_used, C_array(t_ptr_i8, [llglobal])); llvm::LLVMSetInitializer(llvm_used, C_array(t_ptr_i8, [llglobal]));
} }

View file

@ -4,8 +4,9 @@ import str::sbuf;
import lib::llvm::llvm; import lib::llvm::llvm;
import syntax::codemap; import syntax::codemap;
import codemap::span; import codemap::span;
import llvm::{ValueRef, TypeRef, BasicBlockRef, BuilderRef, Opcode, import lib::llvm::{ValueRef, TypeRef, BasicBlockRef, BuilderRef, ModuleRef};
ModuleRef}; import lib::llvm::{Opcode, IntPredicate, RealPredicate, True, False,
CallConv};
import common::{block_ctxt, T_ptr, T_nil, T_i8, T_i1, T_void, import common::{block_ctxt, T_ptr, T_nil, T_i8, T_i1, T_void,
T_fn, val_ty, bcx_ccx, C_i32}; T_fn, val_ty, bcx_ccx, C_i32};
@ -110,8 +111,7 @@ fn FastInvoke(cx: @block_ctxt, Fn: ValueRef, Args: [ValueRef],
let v = llvm::LLVMBuildInvoke(B(cx), Fn, vec::to_ptr(Args), let v = llvm::LLVMBuildInvoke(B(cx), Fn, vec::to_ptr(Args),
vec::len(Args) as c_uint, vec::len(Args) as c_uint,
Then, Catch, noname()); Then, Catch, noname());
llvm::LLVMSetInstructionCallConv( lib::llvm::SetInstructionCallConv(v, lib::llvm::FastCallConv);
v, lib::llvm::LLVMFastCallConv as c_uint);
} }
} }
@ -467,12 +467,14 @@ fn FPCast(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef {
/* Comparisons */ /* Comparisons */
fn ICmp(cx: @block_ctxt, Op: uint, LHS: ValueRef, RHS: ValueRef) -> ValueRef { fn ICmp(cx: @block_ctxt, Op: IntPredicate, LHS: ValueRef, RHS: ValueRef)
-> ValueRef {
if cx.unreachable { ret llvm::LLVMGetUndef(T_i1()); } if cx.unreachable { ret llvm::LLVMGetUndef(T_i1()); }
ret llvm::LLVMBuildICmp(B(cx), Op as c_uint, LHS, RHS, noname()); ret llvm::LLVMBuildICmp(B(cx), Op as c_uint, LHS, RHS, noname());
} }
fn FCmp(cx: @block_ctxt, Op: uint, LHS: ValueRef, RHS: ValueRef) -> ValueRef { fn FCmp(cx: @block_ctxt, Op: RealPredicate, LHS: ValueRef, RHS: ValueRef)
-> ValueRef {
if cx.unreachable { ret llvm::LLVMGetUndef(T_i1()); } if cx.unreachable { ret llvm::LLVMGetUndef(T_i1()); }
ret llvm::LLVMBuildFCmp(B(cx), Op as c_uint, LHS, RHS, noname()); ret llvm::LLVMBuildFCmp(B(cx), Op as c_uint, LHS, RHS, noname());
} }
@ -528,9 +530,12 @@ fn add_comment(bcx: @block_ctxt, text: str) {
check str::is_not_empty("$"); check str::is_not_empty("$");
let sanitized = str::replace(text, "$", ""); let sanitized = str::replace(text, "$", "");
let comment_text = "; " + sanitized; let comment_text = "; " + sanitized;
let asm = str::as_buf(comment_text, { |c| let asm = str::as_buf(comment_text, {|c|
str::as_buf("", { |e| str::as_buf("", {|e|
llvm::LLVMConstInlineAsm(T_fn([], T_void()), c, e, 0, 0)})}); llvm::LLVMConstInlineAsm(T_fn([], T_void()), c, e,
False, False)
})
});
Call(bcx, asm, []); Call(bcx, asm, []);
} }
} }
@ -548,19 +553,18 @@ fn FastCall(cx: @block_ctxt, Fn: ValueRef, Args: [ValueRef]) -> ValueRef {
unsafe { unsafe {
let v = llvm::LLVMBuildCall(B(cx), Fn, vec::to_ptr(Args), let v = llvm::LLVMBuildCall(B(cx), Fn, vec::to_ptr(Args),
vec::len(Args) as c_uint, noname()); vec::len(Args) as c_uint, noname());
llvm::LLVMSetInstructionCallConv( lib::llvm::SetInstructionCallConv(v, lib::llvm::FastCallConv);
v, lib::llvm::LLVMFastCallConv as c_uint);
ret v; ret v;
} }
} }
fn CallWithConv(cx: @block_ctxt, Fn: ValueRef, Args: [ValueRef], fn CallWithConv(cx: @block_ctxt, Fn: ValueRef, Args: [ValueRef],
Conv: c_uint) -> ValueRef { Conv: CallConv) -> ValueRef {
if cx.unreachable { ret _UndefReturn(cx, Fn); } if cx.unreachable { ret _UndefReturn(cx, Fn); }
unsafe { unsafe {
let v = llvm::LLVMBuildCall(B(cx), Fn, vec::to_ptr(Args), let v = llvm::LLVMBuildCall(B(cx), Fn, vec::to_ptr(Args),
vec::len(Args) as c_uint, noname()); vec::len(Args) as c_uint, noname());
llvm::LLVMSetInstructionCallConv(v, Conv); lib::llvm::SetInstructionCallConv(v, Conv);
ret v; ret v;
} }
} }

View file

@ -2,7 +2,7 @@ import core::ctypes::c_uint;
import syntax::ast; import syntax::ast;
import syntax::ast_util; import syntax::ast_util;
import lib::llvm::llvm; import lib::llvm::llvm;
import llvm::{ValueRef, TypeRef}; import lib::llvm::{ValueRef, TypeRef};
import common::*; import common::*;
import build::*; import build::*;
import base::*; import base::*;

View file

@ -17,7 +17,7 @@ import util::common::*;
import syntax::codemap::span; import syntax::codemap::span;
import lib::llvm::{llvm, target_data, type_names, associate_type, import lib::llvm::{llvm, target_data, type_names, associate_type,
name_has_type}; name_has_type};
import lib::llvm::llvm::{ModuleRef, ValueRef, TypeRef, BasicBlockRef}; import lib::llvm::{ModuleRef, ValueRef, TypeRef, BasicBlockRef, BuilderRef};
import lib::llvm::{True, False, Bool}; import lib::llvm::{True, False, Bool};
import metadata::{csearch}; import metadata::{csearch};
@ -72,7 +72,7 @@ type stats =
mutable n_real_glues: uint, mutable n_real_glues: uint,
fn_times: @mutable [{ident: str, time: int}]}; fn_times: @mutable [{ident: str, time: int}]};
resource BuilderRef_res(B: llvm::BuilderRef) { llvm::LLVMDisposeBuilder(B); } resource BuilderRef_res(B: BuilderRef) { llvm::LLVMDisposeBuilder(B); }
// Crate context. Every crate we compile has one of these. // Crate context. Every crate we compile has one of these.
type crate_ctxt = type crate_ctxt =
@ -788,7 +788,7 @@ fn C_cstr(cx: @crate_ctxt, s: str) -> ValueRef {
{|buf| llvm::LLVMAddGlobal(cx.llmod, val_ty(sc), buf) }); {|buf| llvm::LLVMAddGlobal(cx.llmod, val_ty(sc), buf) });
llvm::LLVMSetInitializer(g, sc); llvm::LLVMSetInitializer(g, sc);
llvm::LLVMSetGlobalConstant(g, True); llvm::LLVMSetGlobalConstant(g, True);
llvm::LLVMSetLinkage(g, lib::llvm::LLVMInternalLinkage as llvm::Linkage); lib::llvm::SetLinkage(g, lib::llvm::InternalLinkage);
ret g; ret g;
} }
@ -835,8 +835,7 @@ fn C_shape(ccx: @crate_ctxt, bytes: [u8]) -> ValueRef {
}); });
llvm::LLVMSetInitializer(llglobal, llshape); llvm::LLVMSetInitializer(llglobal, llshape);
llvm::LLVMSetGlobalConstant(llglobal, True); llvm::LLVMSetGlobalConstant(llglobal, True);
llvm::LLVMSetLinkage(llglobal, lib::llvm::SetLinkage(llglobal, lib::llvm::InternalLinkage);
lib::llvm::LLVMInternalLinkage as llvm::Linkage);
ret llvm::LLVMConstPointerCast(llglobal, T_ptr(T_i8())); ret llvm::LLVMConstPointerCast(llglobal, T_ptr(T_i8()));
} }
@ -894,12 +893,12 @@ fn hash_dict_id(&&dp: dict_id) -> uint {
} }
fn umax(cx: @block_ctxt, a: ValueRef, b: ValueRef) -> ValueRef { fn umax(cx: @block_ctxt, a: ValueRef, b: ValueRef) -> ValueRef {
let cond = build::ICmp(cx, lib::llvm::LLVMIntULT, a, b); let cond = build::ICmp(cx, lib::llvm::IntULT, a, b);
ret build::Select(cx, cond, b, a); ret build::Select(cx, cond, b, a);
} }
fn umin(cx: @block_ctxt, a: ValueRef, b: ValueRef) -> ValueRef { fn umin(cx: @block_ctxt, a: ValueRef, b: ValueRef) -> ValueRef {
let cond = build::ICmp(cx, lib::llvm::LLVMIntULT, a, b); let cond = build::ICmp(cx, lib::llvm::IntULT, a, b);
ret build::Select(cx, cond, a, b); ret build::Select(cx, cond, a, b);
} }

View file

@ -8,7 +8,8 @@ import syntax::{ast, ast_util};
import metadata::csearch; import metadata::csearch;
import back::{link, abi}; import back::{link, abi};
import lib::llvm::llvm; import lib::llvm::llvm;
import llvm::{ValueRef, TypeRef, LLVMGetParam}; import lib::llvm::{ValueRef, TypeRef};
import lib::llvm::llvm::LLVMGetParam;
// Translation functionality related to impls and ifaces // Translation functionality related to impls and ifaces
// //
@ -384,8 +385,7 @@ fn get_static_dict(bcx: @block_ctxt, origin: typeck::dict_origin)
}); });
llvm::LLVMSetGlobalConstant(gvar, lib::llvm::True); llvm::LLVMSetGlobalConstant(gvar, lib::llvm::True);
llvm::LLVMSetInitializer(gvar, ptrs); llvm::LLVMSetInitializer(gvar, ptrs);
llvm::LLVMSetLinkage(gvar, lib::llvm::SetLinkage(gvar, lib::llvm::InternalLinkage);
lib::llvm::LLVMInternalLinkage as llvm::Linkage);
let cast = llvm::LLVMConstPointerCast(gvar, T_ptr(T_dict())); let cast = llvm::LLVMConstPointerCast(gvar, T_ptr(T_dict()));
ccx.dicts.insert(id, cast); ccx.dicts.insert(id, cast);
cast cast

View file

@ -2,7 +2,7 @@ import vec;
import option::none; import option::none;
import syntax::ast; import syntax::ast;
import driver::session::session; import driver::session::session;
import lib::llvm::llvm::{ValueRef, TypeRef}; import lib::llvm::{ValueRef, TypeRef};
import back::abi; import back::abi;
import base::{call_memmove, trans_shared_malloc, type_of_or_i8, import base::{call_memmove, trans_shared_malloc, type_of_or_i8,
INIT, copy_val, load_if_immediate, get_tydesc, INIT, copy_val, load_if_immediate, get_tydesc,
@ -170,7 +170,7 @@ fn trans_append(cx: @block_ctxt, vec_ty: ty::t, lhsptr: ValueRef,
let llunitty = type_of_or_i8(cx, unit_ty); let llunitty = type_of_or_i8(cx, unit_ty);
let lhs = Load(bcx, lhsptr); let lhs = Load(bcx, lhsptr);
let self_append = ICmp(bcx, lib::llvm::LLVMIntEQ, lhs, rhs); let self_append = ICmp(bcx, lib::llvm::IntEQ, lhs, rhs);
let lfill = get_fill(bcx, lhs); let lfill = get_fill(bcx, lhs);
let rfill = get_fill(bcx, rhs); let rfill = get_fill(bcx, rhs);
let new_fill = Add(bcx, lfill, rfill); let new_fill = Add(bcx, lfill, rfill);
@ -295,7 +295,7 @@ fn iter_vec_raw(bcx: @block_ctxt, vptr: ValueRef, vec_ty: ty::t,
Br(bcx, header_cx.llbb); Br(bcx, header_cx.llbb);
let data_ptr = Phi(header_cx, val_ty(data_ptr), [data_ptr], [bcx.llbb]); let data_ptr = Phi(header_cx, val_ty(data_ptr), [data_ptr], [bcx.llbb]);
let not_yet_at_end = let not_yet_at_end =
ICmp(header_cx, lib::llvm::LLVMIntULT, data_ptr, data_end_ptr); ICmp(header_cx, lib::llvm::IntULT, data_ptr, data_end_ptr);
let body_cx = new_sub_block_ctxt(header_cx, "iter_vec_loop_body"); let body_cx = new_sub_block_ctxt(header_cx, "iter_vec_loop_body");
let next_cx = new_sub_block_ctxt(header_cx, "iter_vec_next"); let next_cx = new_sub_block_ctxt(header_cx, "iter_vec_next");
CondBr(header_cx, not_yet_at_end, body_cx.llbb, next_cx.llbb); CondBr(header_cx, not_yet_at_end, body_cx.llbb, next_cx.llbb);

View file

@ -1,5 +1,5 @@
import syntax::ast; import syntax::ast;
import lib::llvm::llvm::ValueRef; import lib::llvm::ValueRef;
import common::*; import common::*;
import build::*; import build::*;
import base::{ import base::{