From af894e963bb3b98605e161b662c66b2286eef140 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 18 Jan 2004 21:03:49 +0000 Subject: [PATCH] Add support for representing the "compaction table" Change protected members to private. Nothing should subclass SlotCalculator git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10912 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Analysis/SlotCalculator.h | 45 +++++++++++++++++++++++--- include/llvm/SlotCalculator.h | 45 +++++++++++++++++++++++--- lib/Bytecode/Writer/SlotCalculator.h | 45 +++++++++++++++++++++++--- 3 files changed, 120 insertions(+), 15 deletions(-) diff --git a/include/llvm/Analysis/SlotCalculator.h b/include/llvm/Analysis/SlotCalculator.h index fbd0976c8cb..105e585d852 100644 --- a/include/llvm/Analysis/SlotCalculator.h +++ b/include/llvm/Analysis/SlotCalculator.h @@ -22,6 +22,7 @@ #include #include +#include namespace llvm { @@ -53,22 +54,50 @@ class SlotCalculator { /// std::vector ModuleLevel; + /// ModuleContainsAllFunctionConstants - This flag is set to true if all + /// function constants are incorporated into the module constant table. This + /// is only possible if building information for a bytecode file. + bool ModuleContainsAllFunctionConstants; + + /// CompactionTable/NodeMap - When function compaction has been performed, + /// these entries provide a compacted view of the namespace needed to emit + /// instructions in a function body. The 'getSlot()' method automatically + /// returns these entries if applicable, or the global entries if not. + std::vector CompactionTable; + std::map CompactionNodeMap; + + SlotCalculator(const SlotCalculator &); // DO NOT IMPLEMENT + void operator=(const SlotCalculator &); // DO NOT IMPLEMENT public: SlotCalculator(const Module *M, bool BuildBytecodeInfo); // Start out in incorp state SlotCalculator(const Function *F, bool BuildBytecodeInfo); - /// getSlot returns < 0 on error! + /// getSlot - Return the slot number of the specified value in it's type + /// plane. This returns < 0 on error! /// - int getSlot(const Value *D) const; + int getSlot(const Value *V) const; - inline unsigned getNumPlanes() const { return Table.size(); } + /// getGlobalSlot - Return a slot number from the global table. This can only + /// be used when a compaction table is active. + unsigned getGlobalSlot(const Value *V) const; + + inline unsigned getNumPlanes() const { + if (CompactionTable.empty()) + return Table.size(); + else + return CompactionTable.size(); + } inline unsigned getModuleLevel(unsigned Plane) const { return Plane < ModuleLevel.size() ? ModuleLevel[Plane] : 0; } inline const TypePlane &getPlane(unsigned Plane) const { - return Table[Plane]; + if (CompactionTable.empty() || CompactionTable.size() <= Plane || + CompactionTable[Plane].empty()) + return Table[Plane]; + else + return CompactionTable[Plane]; } /// incorporateFunction/purgeFunction - If you'd like to deal with a function, @@ -84,8 +113,11 @@ public: string_iterator string_begin() const { return ConstantStrings.begin(); } string_iterator string_end() const { return ConstantStrings.end(); } + const std::vector &getCompactionTable() const { + return CompactionTable; + } -protected: +private: // getOrCreateSlot - Values can be crammed into here at will... if // they haven't been inserted already, they get inserted, otherwise // they are ignored. @@ -111,6 +143,9 @@ protected: // void processSymbolTable(const SymbolTable *ST); void processSymbolTableConstants(const SymbolTable *ST); + + void buildCompactionTable(const Function *F); + unsigned getOrCreateCompactionTableSlot(const Value *V); }; } // End llvm namespace diff --git a/include/llvm/SlotCalculator.h b/include/llvm/SlotCalculator.h index fbd0976c8cb..105e585d852 100644 --- a/include/llvm/SlotCalculator.h +++ b/include/llvm/SlotCalculator.h @@ -22,6 +22,7 @@ #include #include +#include namespace llvm { @@ -53,22 +54,50 @@ class SlotCalculator { /// std::vector ModuleLevel; + /// ModuleContainsAllFunctionConstants - This flag is set to true if all + /// function constants are incorporated into the module constant table. This + /// is only possible if building information for a bytecode file. + bool ModuleContainsAllFunctionConstants; + + /// CompactionTable/NodeMap - When function compaction has been performed, + /// these entries provide a compacted view of the namespace needed to emit + /// instructions in a function body. The 'getSlot()' method automatically + /// returns these entries if applicable, or the global entries if not. + std::vector CompactionTable; + std::map CompactionNodeMap; + + SlotCalculator(const SlotCalculator &); // DO NOT IMPLEMENT + void operator=(const SlotCalculator &); // DO NOT IMPLEMENT public: SlotCalculator(const Module *M, bool BuildBytecodeInfo); // Start out in incorp state SlotCalculator(const Function *F, bool BuildBytecodeInfo); - /// getSlot returns < 0 on error! + /// getSlot - Return the slot number of the specified value in it's type + /// plane. This returns < 0 on error! /// - int getSlot(const Value *D) const; + int getSlot(const Value *V) const; - inline unsigned getNumPlanes() const { return Table.size(); } + /// getGlobalSlot - Return a slot number from the global table. This can only + /// be used when a compaction table is active. + unsigned getGlobalSlot(const Value *V) const; + + inline unsigned getNumPlanes() const { + if (CompactionTable.empty()) + return Table.size(); + else + return CompactionTable.size(); + } inline unsigned getModuleLevel(unsigned Plane) const { return Plane < ModuleLevel.size() ? ModuleLevel[Plane] : 0; } inline const TypePlane &getPlane(unsigned Plane) const { - return Table[Plane]; + if (CompactionTable.empty() || CompactionTable.size() <= Plane || + CompactionTable[Plane].empty()) + return Table[Plane]; + else + return CompactionTable[Plane]; } /// incorporateFunction/purgeFunction - If you'd like to deal with a function, @@ -84,8 +113,11 @@ public: string_iterator string_begin() const { return ConstantStrings.begin(); } string_iterator string_end() const { return ConstantStrings.end(); } + const std::vector &getCompactionTable() const { + return CompactionTable; + } -protected: +private: // getOrCreateSlot - Values can be crammed into here at will... if // they haven't been inserted already, they get inserted, otherwise // they are ignored. @@ -111,6 +143,9 @@ protected: // void processSymbolTable(const SymbolTable *ST); void processSymbolTableConstants(const SymbolTable *ST); + + void buildCompactionTable(const Function *F); + unsigned getOrCreateCompactionTableSlot(const Value *V); }; } // End llvm namespace diff --git a/lib/Bytecode/Writer/SlotCalculator.h b/lib/Bytecode/Writer/SlotCalculator.h index fbd0976c8cb..105e585d852 100644 --- a/lib/Bytecode/Writer/SlotCalculator.h +++ b/lib/Bytecode/Writer/SlotCalculator.h @@ -22,6 +22,7 @@ #include #include +#include namespace llvm { @@ -53,22 +54,50 @@ class SlotCalculator { /// std::vector ModuleLevel; + /// ModuleContainsAllFunctionConstants - This flag is set to true if all + /// function constants are incorporated into the module constant table. This + /// is only possible if building information for a bytecode file. + bool ModuleContainsAllFunctionConstants; + + /// CompactionTable/NodeMap - When function compaction has been performed, + /// these entries provide a compacted view of the namespace needed to emit + /// instructions in a function body. The 'getSlot()' method automatically + /// returns these entries if applicable, or the global entries if not. + std::vector CompactionTable; + std::map CompactionNodeMap; + + SlotCalculator(const SlotCalculator &); // DO NOT IMPLEMENT + void operator=(const SlotCalculator &); // DO NOT IMPLEMENT public: SlotCalculator(const Module *M, bool BuildBytecodeInfo); // Start out in incorp state SlotCalculator(const Function *F, bool BuildBytecodeInfo); - /// getSlot returns < 0 on error! + /// getSlot - Return the slot number of the specified value in it's type + /// plane. This returns < 0 on error! /// - int getSlot(const Value *D) const; + int getSlot(const Value *V) const; - inline unsigned getNumPlanes() const { return Table.size(); } + /// getGlobalSlot - Return a slot number from the global table. This can only + /// be used when a compaction table is active. + unsigned getGlobalSlot(const Value *V) const; + + inline unsigned getNumPlanes() const { + if (CompactionTable.empty()) + return Table.size(); + else + return CompactionTable.size(); + } inline unsigned getModuleLevel(unsigned Plane) const { return Plane < ModuleLevel.size() ? ModuleLevel[Plane] : 0; } inline const TypePlane &getPlane(unsigned Plane) const { - return Table[Plane]; + if (CompactionTable.empty() || CompactionTable.size() <= Plane || + CompactionTable[Plane].empty()) + return Table[Plane]; + else + return CompactionTable[Plane]; } /// incorporateFunction/purgeFunction - If you'd like to deal with a function, @@ -84,8 +113,11 @@ public: string_iterator string_begin() const { return ConstantStrings.begin(); } string_iterator string_end() const { return ConstantStrings.end(); } + const std::vector &getCompactionTable() const { + return CompactionTable; + } -protected: +private: // getOrCreateSlot - Values can be crammed into here at will... if // they haven't been inserted already, they get inserted, otherwise // they are ignored. @@ -111,6 +143,9 @@ protected: // void processSymbolTable(const SymbolTable *ST); void processSymbolTableConstants(const SymbolTable *ST); + + void buildCompactionTable(const Function *F); + unsigned getOrCreateCompactionTableSlot(const Value *V); }; } // End llvm namespace