Skip to content

Commit 0671d98

Browse files
committed
---
yaml --- r: 2970 b: refs/heads/master c: 698022d h: refs/heads/master v: v3
1 parent 1f9ed62 commit 0671d98

File tree

7 files changed

+87
-16
lines changed

7 files changed

+87
-16
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 08dcb9306b46bc38c0f4bbb8049da2a93c13082a
2+
refs/heads/master: 698022d351e552b51cd9cca878bdc0de3de05b8c

trunk/src/comp/back/link.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ mod write {
153153
True, // unit-at-a-time
154154
True, // unroll loops
155155
True, // simplify lib calls
156-
True, // have exceptions
157156
threshold); // inline threshold
158157
}
159158

trunk/src/comp/lib/llvm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ const uint LLVMNoImplicitFloatAttribute = 8388608u;
8888
const uint LLVMNakedAttribute = 16777216u;
8989
const uint LLVMInlineHintAttribute = 33554432u;
9090
const uint LLVMStackAttribute = 469762048u; // 7 << 26
91+
const uint LLVMUWTableAttribute = 1073741824u; // 1 << 30
9192

9293

9394
// Consts for the LLVM IntPredicate type, pre-cast to uint.
@@ -813,7 +814,6 @@ native mod llvm = llvm_lib {
813814
Bool UnitAtATime,
814815
Bool UnrollLoops,
815816
Bool SimplifyLibCalls,
816-
Bool HaveExceptions,
817817
uint InliningThreshold);
818818

819819
/** Destroys a memory buffer. */

trunk/src/comp/middle/trans.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1820,6 +1820,11 @@ fn set_no_inline(ValueRef f) {
18201820
lib::llvm::llvm::Attribute);
18211821
}
18221822

1823+
fn set_uwtable(ValueRef f) {
1824+
llvm::LLVMAddFunctionAttr(f, lib::llvm::LLVMUWTableAttribute as
1825+
lib::llvm::llvm::Attribute);
1826+
}
1827+
18231828
fn set_always_inline(ValueRef f) {
18241829
llvm::LLVMAddFunctionAttr(f, lib::llvm::LLVMAlwaysInlineAttribute as
18251830
lib::llvm::llvm::Attribute);
@@ -6962,6 +6967,7 @@ fn trans_fn(@local_ctxt cx, &span sp, &ast::_fn f, ast::def_id fid,
69626967
option::t[ty_self_pair] ty_self,
69636968
&vec[ast::ty_param] ty_params, &ast::ann ann) {
69646969
auto llfndecl = cx.ccx.item_ids.get(fid);
6970+
set_uwtable(llfndecl);
69656971

69666972
// Set up arguments to the function.
69676973
auto fcx = new_fn_ctxt(cx, sp, llfndecl);

trunk/src/comp/middle/typeck.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,16 @@ import middle::tstate::ann::ts_ann;
5252
type ty_table = hashmap[ast::def_id, ty::t];
5353
type fn_purity_table = hashmap[ast::def_id, ast::purity];
5454

55+
type unify_cache_entry = tup(ty::t,ty::t,vec[mutable ty::t]);
56+
type unify_cache = hashmap[unify_cache_entry,ty::unify::result];
57+
5558
type obj_info = rec(vec[ast::obj_field] obj_fields, ast::def_id this_obj);
5659

5760
type crate_ctxt = rec(mutable vec[obj_info] obj_infos,
5861
@fn_purity_table fn_purity_table,
62+
unify_cache unify_cache,
63+
mutable uint cache_hits,
64+
mutable uint cache_misses,
5965
ty::ctxt tcx);
6066

6167
type fn_ctxt = rec(ty::t ret_ty,
@@ -814,9 +820,22 @@ mod collect {
814820
mod unify {
815821
fn simple(&@fn_ctxt fcx, &ty::t expected, &ty::t actual)
816822
-> ty::unify::result {
823+
/*auto cache_key = tup(expected, actual, param_substs);
824+
alt (fcx.ccx.unify_cache.find(cache_key)) {
825+
case (some(?r)) {
826+
fcx.ccx.cache_hits += 1u;
827+
ret r;
828+
}
829+
case (none) {
830+
fcx.ccx.cache_misses += 1u;
831+
}
832+
}*/
833+
817834
auto result = ty::unify::unify(expected, actual, fcx.var_bindings,
818835
fcx.ccx.tcx);
819836

837+
//fcx.ccx.unify_cache.insert(cache_key, result);
838+
820839
// FIXME: Shouldn't be necessary, but is until we remove pushdown.
821840
alt (result) {
822841
case (ures_ok(?typ)) {
@@ -2837,6 +2856,37 @@ fn check_item(@crate_ctxt ccx, &@ast::item it) {
28372856
}
28382857
}
28392858

2859+
// Utilities for the unification cache
2860+
2861+
fn hash_unify_cache_entry(&unify_cache_entry uce) -> uint {
2862+
auto h = ty::hash_ty(uce._0);
2863+
h += h << 5u + ty::hash_ty(uce._1);
2864+
2865+
auto i = 0u;
2866+
auto tys_len = vec::len(uce._2);
2867+
while (i < tys_len) {
2868+
h += h << 5u + ty::hash_ty(uce._2.(i));
2869+
i += 1u;
2870+
}
2871+
2872+
ret h;
2873+
}
2874+
2875+
fn eq_unify_cache_entry(&unify_cache_entry a, &unify_cache_entry b) -> bool {
2876+
if (!ty::eq_ty(a._0, b._0) || !ty::eq_ty(a._1, b._1)) { ret false; }
2877+
2878+
auto i = 0u;
2879+
auto tys_len = vec::len(a._2);
2880+
if (vec::len(b._2) != tys_len) { ret false; }
2881+
2882+
while (i < tys_len) {
2883+
if (!ty::eq_ty(a._2.(i), b._2.(i))) { ret false; }
2884+
i += 1u;
2885+
}
2886+
2887+
ret true;
2888+
}
2889+
28402890
fn mk_fn_purity_table(&@ast::crate crate) -> @fn_purity_table {
28412891
auto res = @new_def_hash[ast::purity]();
28422892

@@ -2864,16 +2914,26 @@ fn check_crate(&ty::ctxt tcx, &@ast::crate crate) {
28642914

28652915
let vec[obj_info] obj_infos = [];
28662916

2917+
auto hasher = hash_unify_cache_entry;
2918+
auto eqer = eq_unify_cache_entry;
2919+
auto unify_cache =
2920+
map::mk_hashmap[unify_cache_entry,ty::unify::result](hasher, eqer);
28672921
auto fpt = mk_fn_purity_table(crate); // use a variation on collect
28682922

28692923
auto ccx = @rec(mutable obj_infos=obj_infos,
28702924
fn_purity_table=fpt,
2925+
unify_cache=unify_cache,
2926+
mutable cache_hits=0u,
2927+
mutable cache_misses=0u,
28712928
tcx=tcx);
28722929

28732930
auto visit = rec(visit_item_pre = bind check_item(ccx, _)
28742931
with walk::default_visitor());
28752932

28762933
walk::walk_crate(visit, *crate);
2934+
2935+
log #fmt("cache hit rate: %u/%u", ccx.cache_hits,
2936+
ccx.cache_hits + ccx.cache_misses);
28772937
}
28782938

28792939
//

trunk/src/rustllvm/Passes2.cpp

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "llvm/Analysis/Passes.h"
2-
#include "llvm/Support/StandardPasses.h"
2+
#include "llvm/Support/PassManagerBuilder.h"
33
#include "llvm/PassManager.h"
44
#include "llvm-c/Core.h"
55
#include <cstdlib>
@@ -8,22 +8,29 @@ using namespace llvm;
88

99
extern "C" void LLVMAddStandardFunctionPasses(LLVMPassManagerRef PM,
1010
unsigned int OptimizationLevel) {
11-
createStandardFunctionPasses(unwrap(PM), OptimizationLevel);
11+
PassManagerBuilder PMBuilder;
12+
PMBuilder.OptLevel = OptimizationLevel;
13+
FunctionPassManager *FPM = (FunctionPassManager*) unwrap(PM);
14+
PMBuilder.populateFunctionPassManager(*FPM);
1215
}
1316

1417
extern "C" void LLVMAddStandardModulePasses(LLVMPassManagerRef PM,
1518
unsigned int OptimizationLevel, LLVMBool OptimizeSize,
1619
LLVMBool UnitAtATime, LLVMBool UnrollLoops, LLVMBool SimplifyLibCalls,
17-
LLVMBool HaveExceptions, unsigned int InliningThreshold) {
18-
Pass *InliningPass;
20+
unsigned int InliningThreshold) {
21+
22+
PassManagerBuilder PMBuilder;
23+
PMBuilder.OptLevel = OptimizationLevel;
24+
PMBuilder.SizeLevel = OptimizeSize;
25+
PMBuilder.DisableUnitAtATime = !UnitAtATime;
26+
PMBuilder.DisableUnrollLoops = !UnrollLoops;
27+
28+
PMBuilder.DisableSimplifyLibCalls = !SimplifyLibCalls;
29+
1930
if (InliningThreshold)
20-
InliningPass = createFunctionInliningPass(InliningThreshold);
21-
else
22-
InliningPass = NULL;
31+
PMBuilder.Inliner = createFunctionInliningPass(InliningThreshold);
2332

24-
createStandardModulePasses(unwrap(PM), OptimizationLevel, OptimizeSize,
25-
UnitAtATime, UnrollLoops, SimplifyLibCalls,
26-
HaveExceptions, InliningPass);
33+
PassManager *MPM = (PassManager*) unwrap(PM);
34+
PMBuilder.populateModulePassManager(*MPM);
2735
}
2836

29-

trunk/src/rustllvm/RustWrapper.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ extern "C" const char *LLVMRustGetLastError(void) {
4747
extern "C" void LLVMAddBasicAliasAnalysisPass(LLVMPassManagerRef PM);
4848
extern "C" void LLVMAddStandardModulePasses(LLVMPassManagerRef PM,
4949
unsigned int OptimizationLevel, bool OptimizeSize, bool UnitAtATime,
50-
bool UnrollLoops, bool SimplifyLibCalls, bool HaveExceptions,
50+
bool UnrollLoops, bool SimplifyLibCalls,
5151
unsigned int InliningThreshold);
5252

5353
int *RustHackToFetchPassesO = (int*)LLVMAddBasicAliasAnalysisPass;
@@ -80,7 +80,6 @@ extern "C" void LLVMRustWriteOutputFile(LLVMPassManagerRef PMR,
8080
LLVMCodeGenFileType FileType) {
8181

8282
// Set compilation options.
83-
llvm::UnwindTablesMandatory = true;
8483
llvm::NoFramePointerElim = true;
8584

8685
InitializeAllTargets();

0 commit comments

Comments
 (0)