1 //===-- llvm/SlotCalculator.h - Calculate value slots -----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This class calculates the slots that values will land in. This is useful for
11 // when writing bytecode or assembly out, because you have to know these things.
13 // Specifically, this class calculates the "type plane numbering" that you see
14 // for a function if you strip out all of the symbols in it. For assembly
15 // writing, this is used when a symbol does not have a name. For bytecode
16 // writing, this is always used, and the symbol table is added on later.
18 //===----------------------------------------------------------------------===//
20 #ifndef LLVM_SLOTCALCULATOR_H
21 #define LLVM_SLOTCALCULATOR_H
33 class SlotCalculator {
34 const Module *TheModule;
35 bool IgnoreNamedNodes; // Shall we not count named nodes?
37 typedef std::vector<const Value*> TypePlane;
38 std::vector<TypePlane> Table;
39 std::map<const Value *, unsigned> NodeMap;
41 // ModuleLevel - Used to keep track of which values belong to the module,
42 // and which values belong to the currently incorporated function.
44 std::vector<unsigned> ModuleLevel;
47 SlotCalculator(const Module *M, bool IgnoreNamed);
48 // Start out in incorp state
49 SlotCalculator(const Function *M, bool IgnoreNamed);
50 inline ~SlotCalculator() {}
52 // getSlot returns < 0 on error!
53 int getSlot(const Value *D) const;
55 inline unsigned getNumPlanes() const { return Table.size(); }
56 inline unsigned getModuleLevel(unsigned Plane) const {
57 return Plane < ModuleLevel.size() ? ModuleLevel[Plane] : 0;
60 inline const TypePlane &getPlane(unsigned Plane) const {
64 // If you'd like to deal with a function, use these two methods to get its
65 // data into the SlotCalculator!
67 void incorporateFunction(const Function *F);
71 // getOrCreateSlot - Values can be crammed into here at will... if
72 // they haven't been inserted already, they get inserted, otherwise
75 int getOrCreateSlot(const Value *D);
77 // insertValue - Insert a value into the value table... Return the
78 // slot that it occupies, or -1 if the declaration is to be ignored
79 // because of the IgnoreNamedNodes flag.
81 int insertValue(const Value *D, bool dontIgnore = false);
83 // doInsertValue - Small helper function to be called only be insertVal.
84 int doInsertValue(const Value *D);
86 // processModule - Process all of the module level function declarations and
87 // types that are available.
91 // processSymbolTable - Insert all of the values in the specified symbol table
92 // into the values table...
94 void processSymbolTable(const SymbolTable *ST);
95 void processSymbolTableConstants(const SymbolTable *ST);
98 } // End llvm namespace