Skip to content
Browse files

Tell llvm that the vtables don't change

This should cause LLVM to optimize away multiple loads of
the same slot in a given vtable.
  • Loading branch information...
1 parent 0b05545 commit 3c1fa8f36c42e4b8ab228260833b5fac88fba8a8 @greedy committed Jul 28, 2011
Showing with 32 additions and 1 deletion.
  1. +32 −1 src/compiler/scala/tools/nsc/backend/llvm/GenLLVM.scala
View
33 src/compiler/scala/tools/nsc/backend/llvm/GenLLVM.scala
@@ -350,6 +350,31 @@ abstract class GenLLVM extends SubComponent {
"rt_boxedUnit_vtable", rtVtable,
Externally_visible, Default, true)
+ /* Memory Use Intrinsics */
+
+ lazy val llvmInvariantTag = new LMStructure(Seq.empty).pointer
+
+ lazy val llvmInvariantStart = new LMFunction(
+ llvmInvariantTag,
+ "llvm.invariant.start",
+ Seq(
+ ArgSpec(new LocalVariable("size", LMInt.i64)),
+ ArgSpec(new LocalVariable("ptr", LMInt.i8.pointer))
+ ), false,
+ Externally_visible, Default, Ccc,
+ Seq.empty, Seq.empty, None, None, None)
+
+ lazy val llvmInvariantEnd = new LMFunction(
+ llvmInvariantTag,
+ "llvm.invariant.end",
+ Seq(
+ ArgSpec(new LocalVariable("start", llvmInvariantTag)),
+ ArgSpec(new LocalVariable("size", LMInt.i64)),
+ ArgSpec(new LocalVariable("ptr", LMInt.i8.pointer))
+ ), false,
+ Externally_visible, Default, Ccc,
+ Seq.empty, Seq.empty, None, None, None)
+
/* Exception Handling */
lazy val scalaPersonality = new LMFunction(
@@ -501,7 +526,9 @@ abstract class GenLLVM extends SubComponent {
unwindRaiseException.declare,
createOurException.declare,
rtAssertArrayBounds.declare,
- rtAssertNotNull.declare
+ rtAssertNotNull.declare,
+ llvmInvariantStart.declare,
+ llvmInvariantEnd.declare
)
}
@@ -1092,7 +1119,11 @@ abstract class GenLLVM extends SubComponent {
}
def getrefvtbl(src: LMValue[SomeConcreteType])(implicit _insns: InstBuffer): LMValue[LMPointer] = {
val vtbl = nextvar(rtVtable)
+ val vtblbp = nextvar(LMInt.i8.pointer)
+ val tag = nextvar(llvmInvariantTag)
_insns.append(new extractvalue(vtbl, src.asInstanceOf[LMValue[rtReference.type]], Seq[CInt](1)))
+ _insns.append(new bitcast(vtblbp, vtbl))
+ _insns.append(new call(tag, llvmInvariantStart, Seq(new CInt(LMInt.i64, -1), vtblbp)))
vtbl.asInstanceOf[LMValue[LMPointer]]
}
def arrayClass(elemTpe: TypeKind)(implicit _insns: InstBuffer): LMValue[LMPointer] = {

0 comments on commit 3c1fa8f

Please sign in to comment.
Something went wrong with that request. Please try again.