Make EmitIntValue more efficient and more like what we do for leb128. The
authorRafael Espindola <rafael.espindola@gmail.com>
Fri, 3 Dec 2010 02:54:21 +0000 (02:54 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Fri, 3 Dec 2010 02:54:21 +0000 (02:54 +0000)
difference is much smaller (about 0.3s) but significant.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120787 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCStreamer.h
lib/MC/MCAsmStreamer.cpp
lib/MC/MCObjectStreamer.cpp
lib/MC/MCStreamer.cpp

index 03fd011418c2e79478a0f197deb1eb42ed823cde..16646c96d3ed4174f279a11cd78b003f4b8c563d 100644 (file)
@@ -246,7 +246,8 @@ namespace llvm {
 
     /// EmitIntValue - Special case of EmitValue that avoids the client having
     /// to pass in a MCExpr for constant integers.
-    void EmitIntValue(uint64_t Value, unsigned Size, unsigned AddrSpace = 0);
+    virtual void EmitIntValue(uint64_t Value, unsigned Size,
+                              unsigned AddrSpace = 0);
 
 
     virtual void EmitULEB128Value(const MCExpr *Value,
index 5c9a347c3c08a48de31245575180aa6248fe7958..7189a90406e4ee8b4567b83cec8c59c93508cfd2 100644 (file)
@@ -152,6 +152,8 @@ public:
 
   virtual void EmitValue(const MCExpr *Value, unsigned Size,unsigned AddrSpace,
                          bool UseSet = false);
+  virtual void EmitIntValue(uint64_t Value, unsigned Size,
+                            unsigned AddrSpace = 0);
 
   virtual void EmitULEB128Value(const MCExpr *Value, unsigned AddrSpace = 0);
 
@@ -504,6 +506,11 @@ void MCAsmStreamer::EmitBytes(StringRef Data, unsigned AddrSpace) {
   EmitEOL();
 }
 
+void MCAsmStreamer::EmitIntValue(uint64_t Value, unsigned Size,
+                                 unsigned AddrSpace) {
+  EmitValue(MCConstantExpr::Create(Value, getContext()), Size, AddrSpace);
+}
+
 void MCAsmStreamer::EmitValue(const MCExpr *Value, unsigned Size,
                               unsigned AddrSpace, bool UseSet) {
   assert(CurSection && "Cannot emit contents before setting section!");
index f6753e3d1e12d6205e377c83263d59ea499f44e2..1538a58996656fe7da4eb26355ae3f05324926b8 100644 (file)
@@ -83,16 +83,14 @@ void MCObjectStreamer::EmitValue(const MCExpr *Value, unsigned Size,
 
   // Avoid fixups when possible.
   int64_t AbsValue;
-  if (AddValueSymbols(Value)->EvaluateAsAbsolute(AbsValue)) {
-    // FIXME: Endianness assumption.
-    for (unsigned i = 0; i != Size; ++i)
-      DF->getContents().push_back(uint8_t(AbsValue >> (i * 8)));
-  } else {
-    DF->addFixup(MCFixup::Create(DF->getContents().size(),
-                                 AddValueSymbols(Value),
-                                 MCFixup::getKindForSize(Size, false)));
-    DF->getContents().resize(DF->getContents().size() + Size, 0);
+  if (AddValueSymbols(Value)->EvaluateAsAbsolute(AbsValue, &getAssembler())) {
+    EmitIntValue(AbsValue, Size, AddrSpace);
+    return;
   }
+  DF->addFixup(MCFixup::Create(DF->getContents().size(),
+                               AddValueSymbols(Value),
+                               MCFixup::getKindForSize(Size, false)));
+  DF->getContents().resize(DF->getContents().size() + Size, 0);
 }
 
 void MCObjectStreamer::EmitLabel(MCSymbol *Symbol) {
index 38ace6b2ee297d2c723e91c0161bde908d106051..6df4ae44e40e2b5b3b3e69a8374936726fe9b5dd 100644 (file)
@@ -46,7 +46,12 @@ void MCStreamer::EmitDwarfSetLineAddr(int64_t LineDelta,
 /// pass in a MCExpr for constant integers.
 void MCStreamer::EmitIntValue(uint64_t Value, unsigned Size,
                               unsigned AddrSpace) {
-  EmitValue(MCConstantExpr::Create(Value, getContext()), Size, AddrSpace);
+  assert(Size <= 8);
+  char buf[8];
+  // FIXME: Endianness assumption.
+  for (unsigned i = 0; i != Size; ++i)
+    buf[i] = uint8_t(Value >> (i * 8));
+  EmitBytes(StringRef(buf, Size), AddrSpace);
 }
 
 /// EmitULEB128Value - Special case of EmitULEB128Value that avoids the