summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/Twine.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2010-05-05 18:40:33 +0000
committerChris Lattner <sabre@nondot.org>2010-05-05 18:40:33 +0000
commitd7f69cb7ef9fa4bd6c79cfd3fb9f3b15485a10a6 (patch)
treecae3f84ad0bd9a044fcc4b63c014ff8a7f84377c /llvm/lib/Support/Twine.cpp
parent1a74a44bf98b0e7eb0fbe5b5b49d0475a3745820 (diff)
downloadbcm5719-llvm-d7f69cb7ef9fa4bd6c79cfd3fb9f3b15485a10a6.tar.gz
bcm5719-llvm-d7f69cb7ef9fa4bd6c79cfd3fb9f3b15485a10a6.zip
Implement rdar://7415680 - Twine integer support lacks greatness
Microoptimize Twine's with unsigned and int to not pin their value to the stack. This saves stack space in common cases and allows mem2reg in the caller. A simple example is: void foo(const Twine &); void bar(int x) { foo("xyz: " + Twine(x)); } Before: __Z3bari: subq $40, %rsp movl %edi, 36(%rsp) leaq L_.str3(%rip), %rax leaq 36(%rsp), %rcx leaq 8(%rsp), %rdi movq %rax, 8(%rsp) movq %rcx, 16(%rsp) movb $3, 24(%rsp) movb $7, 25(%rsp) callq __Z3fooRKN4llvm5TwineE addq $40, %rsp ret After: __Z3bari: subq $24, %rsp leaq L_.str3(%rip), %rax movq %rax, (%rsp) movslq %edi, %rax movq %rax, 8(%rsp) movb $3, 16(%rsp) movb $7, 17(%rsp) leaq (%rsp), %rdi callq __Z3fooRKN4llvm5TwineE addq $24, %rsp ret It saves 16 bytes of stack and one instruction in this case. llvm-svn: 103107
Diffstat (limited to 'llvm/lib/Support/Twine.cpp')
-rw-r--r--llvm/lib/Support/Twine.cpp8
1 files changed, 4 insertions, 4 deletions
diff --git a/llvm/lib/Support/Twine.cpp b/llvm/lib/Support/Twine.cpp
index 21504e964ea..b3ea0132e4a 100644
--- a/llvm/lib/Support/Twine.cpp
+++ b/llvm/lib/Support/Twine.cpp
@@ -48,10 +48,10 @@ void Twine::printOneChild(raw_ostream &OS, const void *Ptr,
OS << *static_cast<const StringRef*>(Ptr);
break;
case Twine::DecUIKind:
- OS << *static_cast<const unsigned int*>(Ptr);
+ OS << (unsigned)(uintptr_t)Ptr;
break;
case Twine::DecIKind:
- OS << *static_cast<const int*>(Ptr);
+ OS << (int)(intptr_t)Ptr;
break;
case Twine::DecULKind:
OS << *static_cast<const unsigned long*>(Ptr);
@@ -95,10 +95,10 @@ void Twine::printOneChildRepr(raw_ostream &OS, const void *Ptr,
<< static_cast<const StringRef*>(Ptr) << "\"";
break;
case Twine::DecUIKind:
- OS << "decUI:\"" << *static_cast<const unsigned int*>(Ptr) << "\"";
+ OS << "decUI:\"" << (unsigned)(uintptr_t)Ptr << "\"";
break;
case Twine::DecIKind:
- OS << "decI:\"" << *static_cast<const int*>(Ptr) << "\"";
+ OS << "decI:\"" << (int)(intptr_t)Ptr << "\"";
break;
case Twine::DecULKind:
OS << "decUL:\"" << *static_cast<const unsigned long*>(Ptr) << "\"";
OpenPOWER on IntegriCloud