blob: f5df4e8f65f4ddb7d41d829b4ae68dcb20e2a9e0 [file] [log] [blame]
Chris Lattner6b944532002-10-28 01:16:38 +00001//===-- MachineFunction.cpp -----------------------------------------------===//
Alkis Evlogimenos76d9dac2004-09-05 18:41:35 +00002//
John Criswellb576c942003-10-20 19:43:21 +00003// 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.
Alkis Evlogimenos76d9dac2004-09-05 18:41:35 +00007//
John Criswellb576c942003-10-20 19:43:21 +00008//===----------------------------------------------------------------------===//
Alkis Evlogimenos76d9dac2004-09-05 18:41:35 +00009//
Chris Lattner6b944532002-10-28 01:16:38 +000010// Collect native machine code information for a function. This allows
11// target-specific information about the generated code to be stored with each
12// function.
13//
14//===----------------------------------------------------------------------===//
Chris Lattnerf2868ce2002-02-03 07:54:50 +000015
Chris Lattner16c45e92003-12-20 10:20:58 +000016#include "llvm/CodeGen/MachineFunctionPass.h"
Chris Lattner831fdcf2002-12-25 05:03:22 +000017#include "llvm/CodeGen/MachineInstr.h"
Chris Lattner831fdcf2002-12-25 05:03:22 +000018#include "llvm/CodeGen/SSARegMap.h"
Chris Lattnereb24db92002-12-28 21:08:26 +000019#include "llvm/CodeGen/MachineFrameInfo.h"
Chris Lattner4d149cd2003-01-13 00:23:03 +000020#include "llvm/CodeGen/MachineConstantPool.h"
Nate Begeman37efe672006-04-22 18:53:45 +000021#include "llvm/CodeGen/MachineJumpTableInfo.h"
Chris Lattner16c45e92003-12-20 10:20:58 +000022#include "llvm/CodeGen/Passes.h"
Owen Anderson07000c62006-05-12 06:33:49 +000023#include "llvm/Target/TargetData.h"
Chris Lattnerf2868ce2002-02-03 07:54:50 +000024#include "llvm/Target/TargetMachine.h"
Chris Lattner8bd66e62002-12-28 21:00:25 +000025#include "llvm/Target/TargetFrameInfo.h"
Chris Lattner2fbfdcf2002-04-07 20:49:59 +000026#include "llvm/Function.h"
Misha Brukman47b14a42004-07-29 17:30:56 +000027#include "llvm/Instructions.h"
Reid Spencer551ccae2004-09-01 22:55:40 +000028#include "llvm/Support/LeakDetector.h"
29#include "llvm/Support/GraphWriter.h"
Jim Laskey851a22d2005-10-12 12:09:05 +000030#include "llvm/Config/config.h"
Alkis Evlogimenos71bf4042004-07-08 00:47:58 +000031#include <fstream>
Reid Spencer954da372004-07-04 12:19:56 +000032#include <iostream>
Alkis Evlogimenos71bf4042004-07-08 00:47:58 +000033#include <sstream>
Tanya Lattner792699c2004-05-24 06:11:51 +000034
Chris Lattner07f32d42003-12-20 09:17:07 +000035using namespace llvm;
Chris Lattnerf2868ce2002-02-03 07:54:50 +000036
Chris Lattnere316efc2002-10-29 23:18:43 +000037static AnnotationID MF_AID(
Alkis Evlogimenos76d9dac2004-09-05 18:41:35 +000038 AnnotationManager::getID("CodeGen::MachineCodeForFunction"));
Chris Lattnerf2868ce2002-02-03 07:54:50 +000039
Chris Lattner227c3d32002-10-28 01:12:41 +000040
Chris Lattner227c3d32002-10-28 01:12:41 +000041namespace {
Chris Lattner16c45e92003-12-20 10:20:58 +000042 struct Printer : public MachineFunctionPass {
Brian Gaeke09caa372004-01-30 21:53:46 +000043 std::ostream *OS;
Chris Lattnerd4baf0f2004-02-01 05:25:07 +000044 const std::string Banner;
Brian Gaeke09caa372004-01-30 21:53:46 +000045
46 Printer (std::ostream *_OS, const std::string &_Banner) :
47 OS (_OS), Banner (_Banner) { }
48
Chris Lattner10491642002-10-30 00:48:05 +000049 const char *getPassName() const { return "MachineFunction Printer"; }
50
51 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
52 AU.setPreservesAll();
53 }
54
Chris Lattner16c45e92003-12-20 10:20:58 +000055 bool runOnMachineFunction(MachineFunction &MF) {
Brian Gaeke09caa372004-01-30 21:53:46 +000056 (*OS) << Banner;
57 MF.print (*OS);
Chris Lattner10491642002-10-30 00:48:05 +000058 return false;
59 }
60 };
Chris Lattner227c3d32002-10-28 01:12:41 +000061}
62
Brian Gaeke09caa372004-01-30 21:53:46 +000063/// Returns a newly-created MachineFunction Printer pass. The default output
64/// stream is std::cerr; the default banner is empty.
65///
66FunctionPass *llvm::createMachineFunctionPrinterPass(std::ostream *OS,
Chris Lattnerce9c41e2005-01-23 22:13:58 +000067 const std::string &Banner){
Brian Gaeke09caa372004-01-30 21:53:46 +000068 return new Printer(OS, Banner);
Chris Lattner10491642002-10-30 00:48:05 +000069}
70
Alkis Evlogimenosc81efdc2004-02-15 00:03:15 +000071namespace {
72 struct Deleter : public MachineFunctionPass {
73 const char *getPassName() const { return "Machine Code Deleter"; }
74
75 bool runOnMachineFunction(MachineFunction &MF) {
76 // Delete the annotation from the function now.
77 MachineFunction::destruct(MF.getFunction());
78 return true;
79 }
80 };
81}
82
83/// MachineCodeDeletion Pass - This pass deletes all of the machine code for
84/// the current function, which should happen after the function has been
85/// emitted to a .s file or to memory.
86FunctionPass *llvm::createMachineCodeDeleter() {
87 return new Deleter();
88}
89
90
91
Chris Lattner227c3d32002-10-28 01:12:41 +000092//===---------------------------------------------------------------------===//
93// MachineFunction implementation
94//===---------------------------------------------------------------------===//
Chris Lattner9d5d7592005-01-29 18:41:25 +000095
Chris Lattnerbca81442005-01-30 00:09:23 +000096MachineBasicBlock* ilist_traits<MachineBasicBlock>::createSentinel() {
Alkis Evlogimenos76d9dac2004-09-05 18:41:35 +000097 MachineBasicBlock* dummy = new MachineBasicBlock();
98 LeakDetector::removeGarbageObject(dummy);
99 return dummy;
Tanya Lattner792699c2004-05-24 06:11:51 +0000100}
101
102void ilist_traits<MachineBasicBlock>::transferNodesFromList(
Alkis Evlogimenos76d9dac2004-09-05 18:41:35 +0000103 iplist<MachineBasicBlock, ilist_traits<MachineBasicBlock> >& toList,
104 ilist_iterator<MachineBasicBlock> first,
Chris Lattner9d5d7592005-01-29 18:41:25 +0000105 ilist_iterator<MachineBasicBlock> last) {
Alkis Evlogimenos76d9dac2004-09-05 18:41:35 +0000106 if (Parent != toList.Parent)
107 for (; first != last; ++first)
108 first->Parent = toList.Parent;
Tanya Lattner792699c2004-05-24 06:11:51 +0000109}
Chris Lattner227c3d32002-10-28 01:12:41 +0000110
Chris Lattner10491642002-10-30 00:48:05 +0000111MachineFunction::MachineFunction(const Function *F,
Chris Lattner955fad12002-12-28 20:37:16 +0000112 const TargetMachine &TM)
Jim Laskeyf99c2322006-01-04 13:43:56 +0000113 : Annotation(MF_AID), Fn(F), Target(TM), UsedPhysRegs(0) {
Misha Brukmanb7825bc2002-11-20 18:55:27 +0000114 SSARegMapping = new SSARegMap();
Chris Lattnerad828162004-08-16 22:36:34 +0000115 MFInfo = 0;
Chris Lattnereb24db92002-12-28 21:08:26 +0000116 FrameInfo = new MachineFrameInfo();
Chris Lattner3029f922006-02-09 04:46:04 +0000117 ConstantPool = new MachineConstantPool(TM.getTargetData());
Nate Begeman37efe672006-04-22 18:53:45 +0000118 JumpTableInfo = new MachineJumpTableInfo(TM.getTargetData());
Tanya Lattner17fb34b2004-05-24 07:14:35 +0000119 BasicBlocks.Parent = this;
Chris Lattner831fdcf2002-12-25 05:03:22 +0000120}
121
Alkis Evlogimenos76d9dac2004-09-05 18:41:35 +0000122MachineFunction::~MachineFunction() {
Chris Lattner4b9a4002004-07-01 06:29:07 +0000123 BasicBlocks.clear();
Chris Lattner831fdcf2002-12-25 05:03:22 +0000124 delete SSARegMapping;
Chris Lattner955fad12002-12-28 20:37:16 +0000125 delete MFInfo;
126 delete FrameInfo;
Chris Lattner4d149cd2003-01-13 00:23:03 +0000127 delete ConstantPool;
Nate Begeman37efe672006-04-22 18:53:45 +0000128 delete JumpTableInfo;
Chris Lattnerce9c41e2005-01-23 22:13:58 +0000129 delete[] UsedPhysRegs;
Chris Lattner10491642002-10-30 00:48:05 +0000130}
131
132void MachineFunction::dump() const { print(std::cerr); }
133
134void MachineFunction::print(std::ostream &OS) const {
Brian Gaeke47b71642004-03-29 21:58:31 +0000135 OS << "# Machine code for " << Fn->getName () << "():\n";
Chris Lattner955fad12002-12-28 20:37:16 +0000136
137 // Print Frame Information
Chris Lattner9085d8a2003-01-16 18:35:57 +0000138 getFrameInfo()->print(*this, OS);
Nate Begeman37efe672006-04-22 18:53:45 +0000139
140 // Print JumpTable Information
141 getJumpTableInfo()->print(OS);
Chris Lattner4d149cd2003-01-13 00:23:03 +0000142
143 // Print Constant Pool
144 getConstantPool()->print(OS);
Chris Lattnera1f68ca2005-08-31 22:34:59 +0000145
146 const MRegisterInfo *MRI = getTarget().getRegisterInfo();
147
148 if (livein_begin() != livein_end()) {
149 OS << "Live Ins:";
150 for (livein_iterator I = livein_begin(), E = livein_end(); I != E; ++I) {
151 if (MRI)
152 OS << " " << MRI->getName(I->first);
153 else
154 OS << " Reg #" << I->first;
155 }
156 OS << "\n";
157 }
158 if (liveout_begin() != liveout_end()) {
159 OS << "Live Outs:";
160 for (liveout_iterator I = liveout_begin(), E = liveout_end(); I != E; ++I)
161 if (MRI)
162 OS << " " << MRI->getName(*I);
163 else
164 OS << " Reg #" << *I;
165 OS << "\n";
166 }
167
Brian Gaeke90421cd2004-02-13 04:39:55 +0000168 for (const_iterator BB = begin(); BB != end(); ++BB)
169 BB->print(OS);
Brian Gaeke47b71642004-03-29 21:58:31 +0000170
171 OS << "\n# End machine code for " << Fn->getName () << "().\n\n";
Chris Lattner10491642002-10-30 00:48:05 +0000172}
173
Alkis Evlogimenos71bf4042004-07-08 00:47:58 +0000174/// CFGOnly flag - This is used to control whether or not the CFG graph printer
175/// prints out the contents of basic blocks or not. This is acceptable because
176/// this code is only really used for debugging purposes.
177///
178static bool CFGOnly = false;
179
180namespace llvm {
Alkis Evlogimenos76d9dac2004-09-05 18:41:35 +0000181 template<>
182 struct DOTGraphTraits<const MachineFunction*> : public DefaultDOTGraphTraits {
183 static std::string getGraphName(const MachineFunction *F) {
184 return "CFG for '" + F->getFunction()->getName() + "' function";
Alkis Evlogimenos71bf4042004-07-08 00:47:58 +0000185 }
186
Alkis Evlogimenos76d9dac2004-09-05 18:41:35 +0000187 static std::string getNodeLabel(const MachineBasicBlock *Node,
188 const MachineFunction *Graph) {
189 if (CFGOnly && Node->getBasicBlock() &&
190 !Node->getBasicBlock()->getName().empty())
191 return Node->getBasicBlock()->getName() + ":";
Alkis Evlogimenos71bf4042004-07-08 00:47:58 +0000192
Alkis Evlogimenos76d9dac2004-09-05 18:41:35 +0000193 std::ostringstream Out;
194 if (CFGOnly) {
195 Out << Node->getNumber() << ':';
196 return Out.str();
Alkis Evlogimenos71bf4042004-07-08 00:47:58 +0000197 }
Alkis Evlogimenos76d9dac2004-09-05 18:41:35 +0000198
199 Node->print(Out);
200
201 std::string OutStr = Out.str();
202 if (OutStr[0] == '\n') OutStr.erase(OutStr.begin());
203
204 // Process string output to make it nicer...
205 for (unsigned i = 0; i != OutStr.length(); ++i)
206 if (OutStr[i] == '\n') { // Left justify
207 OutStr[i] = '\\';
208 OutStr.insert(OutStr.begin()+i+1, 'l');
209 }
210 return OutStr;
211 }
212 };
Alkis Evlogimenos71bf4042004-07-08 00:47:58 +0000213}
214
215void MachineFunction::viewCFG() const
216{
Jim Laskey851a22d2005-10-12 12:09:05 +0000217#ifndef NDEBUG
Alkis Evlogimenos71bf4042004-07-08 00:47:58 +0000218 std::string Filename = "/tmp/cfg." + getFunction()->getName() + ".dot";
219 std::cerr << "Writing '" << Filename << "'... ";
220 std::ofstream F(Filename.c_str());
Alkis Evlogimenos76d9dac2004-09-05 18:41:35 +0000221
Alkis Evlogimenos71bf4042004-07-08 00:47:58 +0000222 if (!F) {
223 std::cerr << " error opening file for writing!\n";
224 return;
225 }
226
227 WriteGraph(F, this);
228 F.close();
229 std::cerr << "\n";
230
Jim Laskey851a22d2005-10-12 12:09:05 +0000231#ifdef HAVE_GRAPHVIZ
232 std::cerr << "Running 'Graphviz' program... " << std::flush;
233 if (system((LLVM_PATH_GRAPHVIZ " " + Filename).c_str())) {
234 std::cerr << "Error viewing graph: 'Graphviz' not in path?\n";
235 } else {
236 system(("rm " + Filename).c_str());
237 return;
238 }
239#endif // HAVE_GRAPHVIZ
240
241#ifdef HAVE_GV
Alkis Evlogimenos71bf4042004-07-08 00:47:58 +0000242 std::cerr << "Running 'dot' program... " << std::flush;
243 if (system(("dot -Tps -Nfontname=Courier -Gsize=7.5,10 " + Filename
244 + " > /tmp/cfg.tempgraph.ps").c_str())) {
245 std::cerr << "Error running dot: 'dot' not in path?\n";
246 } else {
247 std::cerr << "\n";
248 system("gv /tmp/cfg.tempgraph.ps");
249 }
250 system(("rm " + Filename + " /tmp/cfg.tempgraph.ps").c_str());
Jim Laskey851a22d2005-10-12 12:09:05 +0000251 return;
252#endif // HAVE_GV
253#endif // NDEBUG
254 std::cerr << "MachineFunction::viewCFG is only available in debug builds on "
255 << "systems with Graphviz or gv!\n";
256
257#ifndef NDEBUG
258 system(("rm " + Filename).c_str());
259#endif
Alkis Evlogimenos71bf4042004-07-08 00:47:58 +0000260}
261
262void MachineFunction::viewCFGOnly() const
263{
264 CFGOnly = true;
265 viewCFG();
266 CFGOnly = false;
267}
268
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000269// The next two methods are used to construct and to retrieve
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000270// the MachineCodeForFunction object for the given function.
271// construct() -- Allocates and initializes for a given function and target
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000272// get() -- Returns a handle to the object.
273// This should not be called before "construct()"
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000274// for a given Function.
Alkis Evlogimenos76d9dac2004-09-05 18:41:35 +0000275//
Misha Brukmanfce11432002-10-28 00:28:31 +0000276MachineFunction&
Chris Lattner335d5c32002-10-28 05:58:46 +0000277MachineFunction::construct(const Function *Fn, const TargetMachine &Tar)
Vikram S. Adve89e2da02002-03-18 03:36:30 +0000278{
Chris Lattnere316efc2002-10-29 23:18:43 +0000279 assert(Fn->getAnnotation(MF_AID) == 0 &&
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000280 "Object already exists for this function!");
Chris Lattner335d5c32002-10-28 05:58:46 +0000281 MachineFunction* mcInfo = new MachineFunction(Fn, Tar);
282 Fn->addAnnotation(mcInfo);
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000283 return *mcInfo;
284}
285
Chris Lattner16c45e92003-12-20 10:20:58 +0000286void MachineFunction::destruct(const Function *Fn) {
Chris Lattnere316efc2002-10-29 23:18:43 +0000287 bool Deleted = Fn->deleteAnnotation(MF_AID);
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000288 assert(Deleted && "Machine code did not exist for function!");
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000289}
290
Chris Lattner335d5c32002-10-28 05:58:46 +0000291MachineFunction& MachineFunction::get(const Function *F)
Vikram S. Adve89e2da02002-03-18 03:36:30 +0000292{
Chris Lattnere316efc2002-10-29 23:18:43 +0000293 MachineFunction *mc = (MachineFunction*)F->getAnnotation(MF_AID);
Chris Lattnerf2868ce2002-02-03 07:54:50 +0000294 assert(mc && "Call construct() method first to allocate the object");
295 return *mc;
296}
297
Chris Lattner831fdcf2002-12-25 05:03:22 +0000298void MachineFunction::clearSSARegMap() {
299 delete SSARegMapping;
300 SSARegMapping = 0;
301}
302
Chris Lattner955fad12002-12-28 20:37:16 +0000303//===----------------------------------------------------------------------===//
Chris Lattnereb24db92002-12-28 21:08:26 +0000304// MachineFrameInfo implementation
Chris Lattner955fad12002-12-28 20:37:16 +0000305//===----------------------------------------------------------------------===//
306
Chris Lattner9085d8a2003-01-16 18:35:57 +0000307void MachineFrameInfo::print(const MachineFunction &MF, std::ostream &OS) const{
Chris Lattner62d6ad22004-06-02 05:56:52 +0000308 int ValOffset = MF.getTarget().getFrameInfo()->getOffsetOfLocalArea();
Chris Lattner9085d8a2003-01-16 18:35:57 +0000309
Chris Lattner955fad12002-12-28 20:37:16 +0000310 for (unsigned i = 0, e = Objects.size(); i != e; ++i) {
311 const StackObject &SO = Objects[i];
Chris Lattner0db07092005-05-13 22:54:44 +0000312 OS << " <fi #" << (int)(i-NumFixedObjects) << ">: ";
Chris Lattner955fad12002-12-28 20:37:16 +0000313 if (SO.Size == 0)
314 OS << "variable sized";
315 else
Chris Lattner0db07092005-05-13 22:54:44 +0000316 OS << "size is " << SO.Size << " byte" << (SO.Size != 1 ? "s," : ",");
317 OS << " alignment is " << SO.Alignment << " byte"
318 << (SO.Alignment != 1 ? "s," : ",");
Alkis Evlogimenos76d9dac2004-09-05 18:41:35 +0000319
Chris Lattner955fad12002-12-28 20:37:16 +0000320 if (i < NumFixedObjects)
321 OS << " fixed";
322 if (i < NumFixedObjects || SO.SPOffset != -1) {
Chris Lattner7f7bbc22004-06-11 06:37:11 +0000323 int Off = SO.SPOffset - ValOffset;
Chris Lattner955fad12002-12-28 20:37:16 +0000324 OS << " at location [SP";
Chris Lattner9085d8a2003-01-16 18:35:57 +0000325 if (Off > 0)
Alkis Evlogimenos76d9dac2004-09-05 18:41:35 +0000326 OS << "+" << Off;
Chris Lattner9085d8a2003-01-16 18:35:57 +0000327 else if (Off < 0)
Alkis Evlogimenos76d9dac2004-09-05 18:41:35 +0000328 OS << Off;
Chris Lattner955fad12002-12-28 20:37:16 +0000329 OS << "]";
330 }
331 OS << "\n";
332 }
333
334 if (HasVarSizedObjects)
335 OS << " Stack frame contains variable sized objects\n";
336}
337
Chris Lattner9085d8a2003-01-16 18:35:57 +0000338void MachineFrameInfo::dump(const MachineFunction &MF) const {
339 print(MF, std::cerr);
340}
Chris Lattner955fad12002-12-28 20:37:16 +0000341
342
343//===----------------------------------------------------------------------===//
Nate Begeman37efe672006-04-22 18:53:45 +0000344// MachineJumpTableInfo implementation
345//===----------------------------------------------------------------------===//
346
347/// getJumpTableIndex - Create a new jump table entry in the jump table info
348/// or return an existing one.
349///
350unsigned MachineJumpTableInfo::getJumpTableIndex(
351 std::vector<MachineBasicBlock*> &DestBBs) {
352 for (unsigned i = 0, e = JumpTables.size(); i != e; ++i)
353 if (JumpTables[i].MBBs == DestBBs)
354 return i;
355
356 JumpTables.push_back(MachineJumpTableEntry(DestBBs));
357 return JumpTables.size()-1;
358}
359
360
361void MachineJumpTableInfo::print(std::ostream &OS) const {
362 // FIXME: this is lame, maybe we could print out the MBB numbers or something
363 // like {1, 2, 4, 5, 3, 0}
364 for (unsigned i = 0, e = JumpTables.size(); i != e; ++i) {
365 OS << " <jt #" << i << "> has " << JumpTables[i].MBBs.size()
366 << " entries\n";
367 }
368}
369
Nate Begeman3700a4d2006-04-22 23:52:35 +0000370unsigned MachineJumpTableInfo::getEntrySize() const {
Owen Andersona69571c2006-05-03 01:29:57 +0000371 return TD->getPointerSize();
Nate Begeman3700a4d2006-04-22 23:52:35 +0000372}
373
374unsigned MachineJumpTableInfo::getAlignment() const {
Owen Andersona69571c2006-05-03 01:29:57 +0000375 return TD->getPointerAlignment();
Nate Begeman3700a4d2006-04-22 23:52:35 +0000376}
377
Nate Begeman37efe672006-04-22 18:53:45 +0000378void MachineJumpTableInfo::dump() const { print(std::cerr); }
379
380
381//===----------------------------------------------------------------------===//
Chris Lattner4d149cd2003-01-13 00:23:03 +0000382// MachineConstantPool implementation
383//===----------------------------------------------------------------------===//
384
Chris Lattner3029f922006-02-09 04:46:04 +0000385/// getConstantPoolIndex - Create a new entry in the constant pool or return
386/// an existing one. User must specify an alignment in bytes for the object.
387///
388unsigned MachineConstantPool::getConstantPoolIndex(Constant *C,
389 unsigned Alignment) {
390 assert(Alignment && "Alignment must be specified!");
391 if (Alignment > PoolAlignment) PoolAlignment = Alignment;
392
393 // Check to see if we already have this constant.
394 //
395 // FIXME, this could be made much more efficient for large constant pools.
396 unsigned AlignMask = (1 << Alignment)-1;
397 for (unsigned i = 0, e = Constants.size(); i != e; ++i)
398 if (Constants[i].Val == C && (Constants[i].Offset & AlignMask) == 0)
399 return i;
400
401 unsigned Offset = 0;
402 if (!Constants.empty()) {
403 Offset = Constants.back().Offset;
Owen Andersona69571c2006-05-03 01:29:57 +0000404 Offset += TD->getTypeSize(Constants.back().Val->getType());
Chris Lattner3029f922006-02-09 04:46:04 +0000405 Offset = (Offset+AlignMask)&~AlignMask;
406 }
407
408 Constants.push_back(MachineConstantPoolEntry(C, Offset));
409 return Constants.size()-1;
410}
411
412
Chris Lattner4d149cd2003-01-13 00:23:03 +0000413void MachineConstantPool::print(std::ostream &OS) const {
Evan Chengb8973bd2006-01-31 22:23:14 +0000414 for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
Chris Lattnerfa77d432006-02-09 04:22:52 +0000415 OS << " <cp #" << i << "> is" << *(Value*)Constants[i].Val;
Chris Lattner3029f922006-02-09 04:46:04 +0000416 OS << " , offset=" << Constants[i].Offset;
Evan Chengb8973bd2006-01-31 22:23:14 +0000417 OS << "\n";
418 }
Chris Lattner4d149cd2003-01-13 00:23:03 +0000419}
420
421void MachineConstantPool::dump() const { print(std::cerr); }