blob: 596f9324edbae88012850f7b3f8444b6766d3701 [file] [log] [blame]
Chris Lattner48486892003-09-30 18:37:50 +00001//===-- llvm/SlotCalculator.h - Calculate value slots -----------*- C++ -*-===//
John Criswell6fbcc262003-10-20 20:19:47 +00002//
3// The LLVM Compiler Infrastructure
4//
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.
7//
8//===----------------------------------------------------------------------===//
Chris Lattner00950542001-06-06 20:29:01 +00009//
Chris Lattnerb5794002002-04-07 22:49:37 +000010// 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.
12//
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.
Chris Lattner00950542001-06-06 20:29:01 +000017//
18//===----------------------------------------------------------------------===//
19
Chris Lattnerb5794002002-04-07 22:49:37 +000020#ifndef LLVM_SLOTCALCULATOR_H
21#define LLVM_SLOTCALCULATOR_H
Chris Lattner00950542001-06-06 20:29:01 +000022
Chris Lattner00950542001-06-06 20:29:01 +000023#include <vector>
24#include <map>
Brian Gaeked0fde302003-11-11 22:41:34 +000025
26namespace llvm {
27
Chris Lattner644dc172001-07-14 06:08:51 +000028class Value;
Chris Lattner4c4007b2001-09-07 16:27:05 +000029class Module;
Chris Lattnere7506a32002-03-23 22:51:58 +000030class Function;
Chris Lattner184b2fa2002-04-09 18:35:38 +000031class SymbolTable;
Chris Lattner00950542001-06-06 20:29:01 +000032
Chris Lattner4c4007b2001-09-07 16:27:05 +000033class SlotCalculator {
Chris Lattner00950542001-06-06 20:29:01 +000034 const Module *TheModule;
35 bool IgnoreNamedNodes; // Shall we not count named nodes?
36
Chris Lattner697954c2002-01-20 22:54:45 +000037 typedef std::vector<const Value*> TypePlane;
38 std::vector<TypePlane> Table;
39 std::map<const Value *, unsigned> NodeMap;
Chris Lattner00950542001-06-06 20:29:01 +000040
41 // ModuleLevel - Used to keep track of which values belong to the module,
Chris Lattnerb5794002002-04-07 22:49:37 +000042 // and which values belong to the currently incorporated function.
Chris Lattner00950542001-06-06 20:29:01 +000043 //
Chris Lattner697954c2002-01-20 22:54:45 +000044 std::vector<unsigned> ModuleLevel;
Chris Lattner00950542001-06-06 20:29:01 +000045
46public:
47 SlotCalculator(const Module *M, bool IgnoreNamed);
Chris Lattnere7506a32002-03-23 22:51:58 +000048 // Start out in incorp state
49 SlotCalculator(const Function *M, bool IgnoreNamed);
Chris Lattner00950542001-06-06 20:29:01 +000050 inline ~SlotCalculator() {}
51
Alkis Evlogimenos60596382003-10-17 02:02:40 +000052 // getSlot returns < 0 on error!
53 int getSlot(const Value *D) const;
Chris Lattner00950542001-06-06 20:29:01 +000054
55 inline unsigned getNumPlanes() const { return Table.size(); }
56 inline unsigned getModuleLevel(unsigned Plane) const {
57 return Plane < ModuleLevel.size() ? ModuleLevel[Plane] : 0;
58 }
59
60 inline const TypePlane &getPlane(unsigned Plane) const {
61 return Table[Plane];
62 }
63
Chris Lattnerb5794002002-04-07 22:49:37 +000064 // If you'd like to deal with a function, use these two methods to get its
65 // data into the SlotCalculator!
Chris Lattner00950542001-06-06 20:29:01 +000066 //
Chris Lattnerb5794002002-04-07 22:49:37 +000067 void incorporateFunction(const Function *F);
68 void purgeFunction();
Chris Lattner00950542001-06-06 20:29:01 +000069
70protected:
Alkis Evlogimenos60596382003-10-17 02:02:40 +000071 // getOrCreateSlot - Values can be crammed into here at will... if
72 // they haven't been inserted already, they get inserted, otherwise
73 // they are ignored.
Chris Lattner00950542001-06-06 20:29:01 +000074 //
Alkis Evlogimenos60596382003-10-17 02:02:40 +000075 int getOrCreateSlot(const Value *D);
Chris Lattner00950542001-06-06 20:29:01 +000076
Alkis Evlogimenos60596382003-10-17 02:02:40 +000077 // 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.
Chris Lattner00950542001-06-06 20:29:01 +000080 //
Alkis Evlogimenos60596382003-10-17 02:02:40 +000081 int insertValue(const Value *D, bool dontIgnore = false);
Chris Lattner00950542001-06-06 20:29:01 +000082
Alkis Evlogimenos60596382003-10-17 02:02:40 +000083 // doInsertValue - Small helper function to be called only be insertVal.
84 int doInsertValue(const Value *D);
Chris Lattner00950542001-06-06 20:29:01 +000085
Chris Lattnerb5794002002-04-07 22:49:37 +000086 // processModule - Process all of the module level function declarations and
Chris Lattner4c4007b2001-09-07 16:27:05 +000087 // types that are available.
Chris Lattner00950542001-06-06 20:29:01 +000088 //
Chris Lattner4c4007b2001-09-07 16:27:05 +000089 void processModule();
Chris Lattner00950542001-06-06 20:29:01 +000090
Chris Lattner4c4007b2001-09-07 16:27:05 +000091 // processSymbolTable - Insert all of the values in the specified symbol table
92 // into the values table...
Chris Lattner00950542001-06-06 20:29:01 +000093 //
Chris Lattner4c4007b2001-09-07 16:27:05 +000094 void processSymbolTable(const SymbolTable *ST);
95 void processSymbolTableConstants(const SymbolTable *ST);
Chris Lattner00950542001-06-06 20:29:01 +000096};
97
Brian Gaeked0fde302003-11-11 22:41:34 +000098} // End llvm namespace
99
Chris Lattner00950542001-06-06 20:29:01 +0000100#endif