[llvm-commits] CVS: llvm/lib/Bytecode/Writer/SlotCalculator.cpp SlotCalculator.h Writer.cpp WriterInternals.h

Chris Lattner lattner at cs.uiuc.edu
Wed Jan 25 15:08:28 PST 2006



Changes in directory llvm/lib/Bytecode/Writer:

SlotCalculator.cpp updated: 1.72 -> 1.73
SlotCalculator.h updated: 1.22 -> 1.23
Writer.cpp updated: 1.118 -> 1.119
WriterInternals.h updated: 1.26 -> 1.27
---
Log message:

add bc reader/writer support for inline asm


---
Diffs of the changes:  (+41 -24)

 SlotCalculator.cpp |   25 ++++++++++++-------------
 SlotCalculator.h   |   14 +++++++-------
 Writer.cpp         |   22 +++++++++++++++++++---
 WriterInternals.h  |    4 +++-
 4 files changed, 41 insertions(+), 24 deletions(-)


Index: llvm/lib/Bytecode/Writer/SlotCalculator.cpp
diff -u llvm/lib/Bytecode/Writer/SlotCalculator.cpp:1.72 llvm/lib/Bytecode/Writer/SlotCalculator.cpp:1.73
--- llvm/lib/Bytecode/Writer/SlotCalculator.cpp:1.72	Sat Jun 18 13:34:51 2005
+++ llvm/lib/Bytecode/Writer/SlotCalculator.cpp	Wed Jan 25 17:08:15 2006
@@ -18,6 +18,7 @@
 #include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/Function.h"
+#include "llvm/InlineAsm.h"
 #include "llvm/Instructions.h"
 #include "llvm/Module.h"
 #include "llvm/SymbolTable.h"
@@ -27,7 +28,6 @@
 #include "llvm/ADT/STLExtras.h"
 #include <algorithm>
 #include <functional>
-
 using namespace llvm;
 
 #if 0
@@ -181,11 +181,13 @@
   SC_DEBUG("Inserting function constants:\n");
   for (Module::const_iterator F = TheModule->begin(), E = TheModule->end();
        F != E; ++F) {
-    for (const_inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I){
-      for (unsigned op = 0, e = I->getNumOperands(); op != e; ++op)
-        if (isa<Constant>(I->getOperand(op)) &&
-            !isa<GlobalValue>(I->getOperand(op)))
-          getOrCreateSlot(I->getOperand(op));
+    for (const_inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) {
+      for (User::const_op_iterator OI = I->op_begin(), E = I->op_end(); 
+           OI != E; ++OI) {
+        if ((isa<Constant>(*OI) && !isa<GlobalValue>(*OI)) ||
+            isa<InlineAsm>(*OI))
+          getOrCreateSlot(*OI);
+      }
       getOrCreateSlot(I->getType());
     }
     processSymbolTableConstants(&F->getSymbolTable());
@@ -286,7 +288,7 @@
   for(Function::const_arg_iterator I = F->arg_begin(), E = F->arg_end(); I != E; ++I)
     getOrCreateSlot(I);
 
-  if ( !ModuleContainsAllFunctionConstants ) {
+  if (!ModuleContainsAllFunctionConstants) {
     // Iterate over all of the instructions in the function, looking for
     // constant values that are referenced.  Add these to the value pools
     // before any nonconstant values.  This will be turned into the constant
@@ -295,12 +297,9 @@
 
     // Emit all of the constants that are being used by the instructions in
     // the function...
-    constant_iterator CI = constant_begin(F);
-    constant_iterator CE = constant_end(F);
-    while ( CI != CE ) {
-      this->getOrCreateSlot(*CI);
-      ++CI;
-    }
+    for (constant_iterator CI = constant_begin(F), CE = constant_end(F);
+         CI != CE; ++CI)
+      getOrCreateSlot(*CI);
 
     // If there is a symbol table, it is possible that the user has names for
     // constants that are not being used.  In this case, we will have problems


Index: llvm/lib/Bytecode/Writer/SlotCalculator.h
diff -u llvm/lib/Bytecode/Writer/SlotCalculator.h:1.22 llvm/lib/Bytecode/Writer/SlotCalculator.h:1.23
--- llvm/lib/Bytecode/Writer/SlotCalculator.h:1.22	Thu Apr 21 16:48:46 2005
+++ llvm/lib/Bytecode/Writer/SlotCalculator.h	Wed Jan 25 17:08:15 2006
@@ -74,9 +74,9 @@
   SlotCalculator(const SlotCalculator &);  // DO NOT IMPLEMENT
   void operator=(const SlotCalculator &);  // DO NOT IMPLEMENT
 public:
-  SlotCalculator(const Module *M );
+  SlotCalculator(const Module *M);
   // Start out in incorp state
-  SlotCalculator(const Function *F );
+  SlotCalculator(const Function *F);
 
   /// getSlot - Return the slot number of the specified value in it's type
   /// plane.  This returns < 0 on error!
@@ -146,19 +146,19 @@
   // they haven't been inserted already, they get inserted, otherwise
   // they are ignored.
   //
-  int getOrCreateSlot(const Value *D);
-  int getOrCreateSlot(const Type* T);
+  int getOrCreateSlot(const Value *V);
+  int getOrCreateSlot(const Type *T);
 
   // insertValue - Insert a value into the value table... Return the
   // slot that it occupies, or -1 if the declaration is to be ignored
   // because of the IgnoreNamedNodes flag.
   //
   int insertValue(const Value *D, bool dontIgnore = false);
-  int insertType(const Type* T, bool dontIgnore = false );
+  int insertType(const Type *T, bool dontIgnore = false);
 
   // doInsertValue - Small helper function to be called only be insertVal.
-  int doInsertValue(const Value *D);
-  int doInsertType(const Type*T);
+  int doInsertValue(const Value *V);
+  int doInsertType(const Type *T);
 
   // processModule - Process all of the module level function declarations and
   // types that are available.


Index: llvm/lib/Bytecode/Writer/Writer.cpp
diff -u llvm/lib/Bytecode/Writer/Writer.cpp:1.118 llvm/lib/Bytecode/Writer/Writer.cpp:1.119
--- llvm/lib/Bytecode/Writer/Writer.cpp:1.118	Mon Jan 23 22:14:29 2006
+++ llvm/lib/Bytecode/Writer/Writer.cpp	Wed Jan 25 17:08:15 2006
@@ -22,6 +22,7 @@
 #include "llvm/CallingConv.h"
 #include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
+#include "llvm/InlineAsm.h"
 #include "llvm/Instructions.h"
 #include "llvm/Module.h"
 #include "llvm/SymbolTable.h"
@@ -389,6 +390,19 @@
   return;
 }
 
+/// outputInlineAsm - InlineAsm's get emitted to the constant pool, so they can
+/// be shared by multiple uses.
+void BytecodeWriter::outputInlineAsm(const InlineAsm *IA) {
+  // Output a marker, so we know when we have one one parsing the constant pool.
+  // Note that this encoding is 5 bytes: not very efficient for a marker.  Since
+  // unique inline asms are rare, this should hardly matter.
+  output_vbr(~0U);
+  
+  output(IA->getAsmString());
+  output(IA->getConstraintString());
+  output_vbr(unsigned(IA->hasSideEffects()));
+}
+
 void BytecodeWriter::outputConstantStrings() {
   SlotCalculator::string_iterator I = Table.string_begin();
   SlotCalculator::string_iterator E = Table.string_end();
@@ -847,7 +861,8 @@
     /*empty*/;
 
   unsigned NC = ValNo;              // Number of constants
-  for (; NC < Plane.size() && (isa<Constant>(Plane[NC])); NC++)
+  for (; NC < Plane.size() && (isa<Constant>(Plane[NC]) || 
+                               isa<InlineAsm>(Plane[NC])); NC++)
     /*empty*/;
   NC -= ValNo;                      // Convert from index into count
   if (NC == 0) return;              // Skip empty type planes...
@@ -866,9 +881,10 @@
 
   for (unsigned i = ValNo; i < ValNo+NC; ++i) {
     const Value *V = Plane[i];
-    if (const Constant *C = dyn_cast<Constant>(V)) {
+    if (const Constant *C = dyn_cast<Constant>(V))
       outputConstant(C);
-    }
+    else
+      outputInlineAsm(cast<InlineAsm>(V));
   }
 }
 


Index: llvm/lib/Bytecode/Writer/WriterInternals.h
diff -u llvm/lib/Bytecode/Writer/WriterInternals.h:1.26 llvm/lib/Bytecode/Writer/WriterInternals.h:1.27
--- llvm/lib/Bytecode/Writer/WriterInternals.h:1.26	Fri Nov 11 19:33:40 2005
+++ llvm/lib/Bytecode/Writer/WriterInternals.h	Wed Jan 25 17:08:15 2006
@@ -24,6 +24,7 @@
 #include <vector>
 
 namespace llvm {
+  class InlineAsm;
 
 class BytecodeWriter {
   std::vector<unsigned char> &Out;
@@ -68,6 +69,7 @@
   void outputConstantsInPlane(const std::vector<const Value*> &Plane,
                               unsigned StartNo);
   void outputConstant(const Constant *CPV);
+  void outputInlineAsm(const InlineAsm *IA);
   void outputType(const Type *T);
 
   /// @brief Unsigned integer output primitive
@@ -88,7 +90,7 @@
   /// @brief Signed 32-bit variable bit rate output primitive.
   inline void output_vbr(int i);
 
-  inline void output(const std::string &s );
+  inline void output(const std::string &s);
 
   inline void output_data(const void *Ptr, const void *End);
 






More information about the llvm-commits mailing list