[llvm-commits] CVS: reopt/lib/LightWtProfiling/TraceOptEmitter.cpp

Brian Gaeke gaeke at cs.uiuc.edu
Wed Apr 28 16:42:02 PDT 2004


Changes in directory reopt/lib/LightWtProfiling:

TraceOptEmitter.cpp updated: 1.7 -> 1.8

---
Log message:

Wrap long lines.
The parameters to writeInstToVM() were backwards!!! Fixed.
Widen the doFlush range used after every write.
Make sure that all code addresses are always held in variables that are
64 bits wide. Don't cast back and forth between pointers and integers
unnecessarily.


---
Diffs of the changes:  (+20 -19)

Index: reopt/lib/LightWtProfiling/TraceOptEmitter.cpp
diff -u reopt/lib/LightWtProfiling/TraceOptEmitter.cpp:1.7 reopt/lib/LightWtProfiling/TraceOptEmitter.cpp:1.8
--- reopt/lib/LightWtProfiling/TraceOptEmitter.cpp:1.7	Tue Apr 27 13:34:46 2004
+++ reopt/lib/LightWtProfiling/TraceOptEmitter.cpp	Wed Apr 28 16:41:09 2004
@@ -44,8 +44,8 @@
 
     // CurBlock - The start of the current block of memory.  CurByte - The
     // current byte being emitted to.
-    unsigned char *CurBlock, *CurByte;
-    unsigned char *FunctionBase, *CurFunctionPtr;
+    uint64_t CurBlock, CurByte;
+    uint64_t FunctionBase, CurFunctionPtr;
 
     // ConstantPoolAddresses - Contains the location for each entry in the
     // constant pool.
@@ -54,7 +54,7 @@
     TraceOptEmitter (const TargetData &_TD) : TD (_TD) {
       // Re-use the existing DummyFunction area for code emission in the
       // Reoptimizer.  No memory is reserved for stubs.
-      FunctionBase = (unsigned char *) OptimizedTraceTextArea;
+      FunctionBase = (uint64_t) OptimizedTraceTextArea;
       // Allocate functions forward from the function base.
       CurFunctionPtr = FunctionBase;
     }
@@ -96,11 +96,11 @@
 
 void TraceOptEmitter::startFunction(MachineFunction &F) {
   // Round up to a 64-bit word boundary.
-  CurBlock = (unsigned char*)(((intptr_t)CurFunctionPtr + 7) & ~7);
+  CurBlock = (CurFunctionPtr + 7) & ~7;
   CurByte = CurBlock;
 
   // Remember where we started generating this function.
-  addGlobalMapping (F.getFunction (), (uint64_t) CurByte);
+  addGlobalMapping (F.getFunction (), CurByte);
 }
 
 void TraceOptEmitter::finishFunction(MachineFunction &F) {
@@ -109,8 +109,8 @@
 
   ConstantPoolAddresses.clear();
 
-  DEBUG(std::cerr << "Finished CodeGen of [" << (void*)CurBlock
-                  << "] Function: " << F.getFunction()->getName()
+  DEBUG(std::cerr << "Finished CodeGen of [0x" << std::hex << CurBlock
+                  << std::dec << "] Function: " << F.getFunction()->getName()
                   << ": " << CurByte-CurBlock << " bytes of text\n");
 }
 
@@ -155,7 +155,9 @@
 }
 
 void TraceOptEmitter::emitByte(unsigned char B) {
-  std::cerr << "TraceOptEmitter: attempt to emit a single byte: 0x" << std::hex << (unsigned)B << std::dec << " at cursor: " << (unsigned)(uintptr_t)CurByte << "\n";
+  std::cerr << "TraceOptEmitter: attempt to emit a single byte: 0x"
+            << std::hex << (unsigned)B << std::dec << " at cursor: "
+            << CurByte << "\n";
   abort ();
   // *CurByte = W;
   ++CurByte;
@@ -165,24 +167,23 @@
   // This won't work if the endianness of the host and target don't agree!  (For
   // a JIT this can't happen though.  :)
   std::cerr << "TraceOptEmitter: emitting word 0x" << std::hex << W
-            << " at cursor: " << (uint64_t)(uintptr_t)CurByte << std::dec
-            << "\n";
-  vm->writeInstToVM (W, (uint64_t) CurByte);  // does: *(unsigned*)CurByte = W;
-  doFlush ((uint64_t) CurByte, (uint64_t) CurByte + sizeof (unsigned));
+            << " at cursor: " << CurByte << std::dec << "\n";
+  vm->writeInstToVM (CurByte, W);  // does: *(unsigned*)CurByte = W;
+  doFlush (CurByte - sizeof (unsigned), (uint64_t) CurByte + sizeof (unsigned));
   CurByte += sizeof(unsigned);
 }
 
 void TraceOptEmitter::emitWordAt(unsigned W, unsigned *Ptr) {
   std::cerr << "TraceOptEmitter: emitting word 0x" << std::hex << W
             << std::dec << " at pointer: " << Ptr << "\n";
-  vm->writeInstToVM (W, (uint64_t) Ptr);  // does: *Ptr = W;
-  doFlush ((uint64_t) Ptr, (uint64_t) Ptr + sizeof (unsigned));
+  vm->writeInstToVM ((uint64_t) Ptr, W);  // does: *Ptr = W;
+  doFlush ((uint64_t) Ptr - sizeof (unsigned), (uint64_t) Ptr + sizeof (unsigned));
 }
 
 uint64_t TraceOptEmitter::getGlobalValueAddress(GlobalValue *V) {
-  intptr_t Result = 0;
+  uint64_t Result = 0;
   if (V->hasName ()) {
-    Result = (intptr_t)GetAddressOfSymbol (V->getName ());
+    Result = (uint64_t)GetAddressOfSymbol (V->getName ());
   }
   if (!Result) {
     std::cerr << "TraceOptEmitter can't find address of GlobalValue: " << *V;
@@ -192,8 +193,8 @@
 }
 
 uint64_t TraceOptEmitter::getGlobalValueAddress(const std::string &Name) {
-  intptr_t Result = 0;
-  Result = (intptr_t)GetAddressOfSymbol (Name);
+  uint64_t Result = 0;
+  Result = (uint64_t)GetAddressOfSymbol (Name);
   if (!Result) {
     std::cerr << "TraceOptEmitter can't find address of \"" << Name << "\"\n";
     abort ();
@@ -215,7 +216,7 @@
 // will be output to.
 //
 uint64_t TraceOptEmitter::getCurrentPCValue() {
-  return (intptr_t)CurByte;
+  return CurByte;
 }
 
 uint64_t TraceOptEmitter::forceCompilationOf(Function *F) {





More information about the llvm-commits mailing list