llvm.org GIT mirror llvm / 560e395
Put the functionality for printing a value to a raw_ostream as an operand into the Value interface just like the core print method is. That gives a more conistent organization to the IR printing interfaces -- they are all attached to the IR objects themselves. Also, update all the users. This removes the 'Writer.h' header which contained only a single function declaration. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@198836 91177308-0d34-0410-b5e6-96231b3b80d8 Chandler Carruth 5 years ago
44 changed file(s) with 106 addition(s) and 181 deletion(s). Raw diff Collapse all Expand all
1717 #include "llvm/IR/Constants.h"
1818 #include "llvm/IR/Function.h"
1919 #include "llvm/IR/Instructions.h"
20 #include "llvm/IR/Writer.h"
2120 #include "llvm/Support/CFG.h"
2221 #include "llvm/Support/GraphWriter.h"
2322
3938 std::string Str;
4039 raw_string_ostream OS(Str);
4140
42 WriteAsOperand(OS, Node, false);
41 Node->printAsOperand(OS, false);
4342 return OS.str();
4443 }
4544
5049 raw_string_ostream OS(Str);
5150
5251 if (Node->getName().empty()) {
53 WriteAsOperand(OS, Node, false);
52 Node->printAsOperand(OS, false);
5453 OS << ":";
5554 }
5655
154154 inline raw_ostream &operator<<(raw_ostream &o,
155155 const DomTreeNodeBase *Node) {
156156 if (Node->getBlock())
157 WriteAsOperand(o, Node->getBlock(), false);
157 Node->getBlock()->printAsOperand(o, false);
158158 else
159159 o << " <>";
160160
323323 for (unsigned i = 0; i < getBlocks().size(); ++i) {
324324 if (i) OS << ",";
325325 BlockT *BB = getBlocks()[i];
326 WriteAsOperand(OS, BB, false);
326 BB->printAsOperand(OS, false);
327327 if (BB == getHeader()) OS << "
";
328328 if (BB == getLoopLatch()) OS << "";
329329 if (isLoopExiting(BB)) OS << "";
607607 void dump() const;
608608 void print(raw_ostream &OS, SlotIndexes* = 0) const;
609609
610 // Printing method used by LoopInfo.
611 void printAsOperand(raw_ostream &OS, bool PrintType = true);
612
610613 /// getNumber - MachineBasicBlocks are uniquely numbered at the function
611614 /// level, unless they're not in a MachineFunction yet, in which case this
612615 /// will return -1.
653656 };
654657
655658 raw_ostream& operator<<(raw_ostream &OS, const MachineBasicBlock &MBB);
656
657 void WriteAsOperand(raw_ostream &, const MachineBasicBlock*, bool t);
658659
659660 // This is useful when building IndexedMaps keyed on basic block pointers.
660661 struct MBB2NumberFunctor :
3535 class Instruction;
3636 class LLVMContext;
3737 class MDNode;
38 class Module;
3839 class StringRef;
3940 class Twine;
4041 class Type;
104105 /// print - Implement operator<< on Value.
105106 ///
106107 void print(raw_ostream &O, AssemblyAnnotationWriter *AAW = 0) const;
108
109 /// \brief Print the name of this Value out to the specified raw_ostream.
110 /// This is useful when you just want to print 'int %reg126', not the
111 /// instruction that generated it. If you specify a Module for context, then
112 /// even constanst get pretty-printed; for example, the type of a null
113 /// pointer is printed symbolically.
114 void printAsOperand(raw_ostream &O, bool PrintType = true, const Module *M = 0) const;
107115
108116 /// All values are typed, get the type of this value.
109117 ///
+0
-37
include/llvm/IR/Writer.h less more
None //===-- Writer.h - Printer for LLVM IR assembly files -------------*- C++ -*-=//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This functionality is implemented by lib/IR/AsmWriter.cpp.
10 // This library is used to print LLVM assembly language files to an iostream. It
11 // can print LLVM code at a variety of granularities, including Modules,
12 // BasicBlocks, and Instructions. This makes it useful for debugging.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_IR_WRITER_H
17 #define LLVM_IR_WRITER_H
18
19 namespace llvm {
20
21 class Module;
22 class Value;
23 class raw_ostream;
24
25 // WriteAsOperand - Write the name of the specified value out to the specified
26 // ostream. This can be useful when you just want to print int %reg126, not the
27 // whole instruction that generated it. If you specify a Module for context,
28 // then even constants get pretty-printed; for example, the type of a null
29 // pointer is printed symbolically.
30 //
31 void WriteAsOperand(raw_ostream &, const Value *, bool PrintTy = true,
32 const Module *Context = 0);
33
34 } // End llvm namespace
35
36 #endif
1313
1414 #include "llvm/Analysis/Passes.h"
1515 #include "llvm/Analysis/AliasAnalysis.h"
16 #include "llvm/IR/Writer.h"
1716 #include "llvm/Pass.h"
1817 #include "llvm/Support/CommandLine.h"
1918 #include "llvm/Support/Debug.h"
137136 if (PrintAll || (PrintAllFailures && R == MayAlias)) {
138137 errs() << AliasString << ":\t";
139138 errs() << "[" << LocA.Size << "B] ";
140 WriteAsOperand(errs(), LocA.Ptr, true, M);
139 LocA.Ptr->printAsOperand(errs(), true, M);
141140 errs() << ", ";
142141 errs() << "[" << LocB.Size << "B] ";
143 WriteAsOperand(errs(), LocB.Ptr, true, M);
142 LocB.Ptr->printAsOperand(errs(), true, M);
144143 errs() << "\n";
145144 }
146145
163162 if (PrintAll || (PrintAllFailures && R == ModRef)) {
164163 errs() << MRString << ": Ptr: ";
165164 errs() << "[" << Loc.Size << "B] ";
166 WriteAsOperand(errs(), Loc.Ptr, true, M);
165 Loc.Ptr->printAsOperand(errs(), true, M);
167166 errs() << "\t<->" << *CS.getInstruction() << '\n';
168167 }
169168 return R;
2323 #include "llvm/IR/DerivedTypes.h"
2424 #include "llvm/IR/Function.h"
2525 #include "llvm/IR/Instructions.h"
26 #include "llvm/IR/Writer.h"
2726 #include "llvm/Pass.h"
2827 #include "llvm/Support/CommandLine.h"
2928 #include "llvm/Support/Debug.h"
9392 std::string o1, o2;
9493 {
9594 raw_string_ostream os1(o1), os2(o2);
96 WriteAsOperand(os1, V1, true, M);
97 WriteAsOperand(os2, V2, true, M);
95 V1->printAsOperand(os1, true, M);
96 V2->printAsOperand(os2, true, M);
9897 }
9998
10099 if (o2 < o1)
110109 Module *M) {
111110 if (P) {
112111 errs() << " " << Msg << ": Ptr: ";
113 WriteAsOperand(errs(), Ptr, true, M);
112 Ptr->printAsOperand(errs(), true, M);
114113 errs() << "\t<->" << *I << '\n';
115114 }
116115 }
1717 #include "llvm/IR/IntrinsicInst.h"
1818 #include "llvm/IR/LLVMContext.h"
1919 #include "llvm/IR/Type.h"
20 #include "llvm/IR/Writer.h"
2120 #include "llvm/Pass.h"
2221 #include "llvm/Support/Debug.h"
2322 #include "llvm/Support/ErrorHandling.h"
565564 OS << "Pointers: ";
566565 for (iterator I = begin(), E = end(); I != E; ++I) {
567566 if (I != begin()) OS << ", ";
568 WriteAsOperand(OS << "(", I.getPointer());
567 I.getPointer()->printAsOperand(OS << "(");
569568 OS << ", " << I.getSize() << ")";
570569 }
571570 }
573572 OS << "\n " << UnknownInsts.size() << " Unknown instructions: ";
574573 for (unsigned i = 0, e = UnknownInsts.size(); i != e; ++i) {
575574 if (i) OS << ", ";
576 WriteAsOperand(OS, UnknownInsts[i]);
575 UnknownInsts[i]->printAsOperand(OS);
577576 }
578577 }
579578 OS << "\n";
88
99 #include "llvm/Analysis/DominanceFrontier.h"
1010 #include "llvm/ADT/SmallPtrSet.h"
11 #include "llvm/IR/Writer.h"
1211 #include "llvm/Support/Debug.h"
1312 #include "llvm/Support/raw_ostream.h"
1413 using namespace llvm;
113112 for (const_iterator I = begin(), E = end(); I != E; ++I) {
114113 OS << " DomFrontier for BB ";
115114 if (I->first)
116 WriteAsOperand(OS, I->first, false);
115 I->first->printAsOperand(OS, false);
117116 else
118117 OS << " <>";
119118 OS << " is:\t";
124123 I != E; ++I) {
125124 OS << ' ';
126125 if (*I)
127 WriteAsOperand(OS, *I, false);
126 (*I)->printAsOperand(OS, false);
128127 else
129128 OS << "<>";
130129 }
1616 #include "llvm/IR/Constants.h"
1717 #include "llvm/IR/DerivedTypes.h"
1818 #include "llvm/IR/Module.h"
19 #include "llvm/IR/Writer.h"
2019 #include "llvm/Support/InstIterator.h"
2120 #include "llvm/Support/raw_ostream.h"
2221 using namespace llvm;
2323 #include "llvm/IR/DerivedTypes.h"
2424 #include "llvm/IR/Instructions.h"
2525 #include "llvm/IR/Type.h"
26 #include "llvm/IR/Writer.h"
2726 #include "llvm/Support/Debug.h"
2827 #include "llvm/Support/raw_ostream.h"
2928 #include
247246
248247 void IVUsers::print(raw_ostream &OS, const Module *M) const {
249248 OS << "IV Users for loop ";
250 WriteAsOperand(OS, L->getHeader(), false);
249 L->getHeader()->printAsOperand(OS, false);
251250 if (SE->hasLoopInvariantBackedgeTakenCount(L)) {
252251 OS << " with backedge-taken count "
253252 << *SE->getBackedgeTakenCount(L);
257256 for (ilist::const_iterator UI = IVUses.begin(),
258257 E = IVUses.end(); UI != E; ++UI) {
259258 OS << " ";
260 WriteAsOperand(OS, UI->getOperandValToReplace(), false);
259 UI->getOperandValToReplace()->printAsOperand(OS, false);
261260 OS << " = " << *getReplacementExpr(*UI);
262261 for (PostIncLoopSet::const_iterator
263262 I = UI->PostIncLoops.begin(),
264263 E = UI->PostIncLoops.end(); I != E; ++I) {
265264 OS << " (post-inc with loop ";
266 WriteAsOperand(OS, (*I)->getHeader(), false);
265 (*I)->getHeader()->printAsOperand(OS, false);
267266 OS << ")";
268267 }
269268 OS << " in ";
4545 #include "llvm/IR/DataLayout.h"
4646 #include "llvm/IR/Function.h"
4747 #include "llvm/IR/IntrinsicInst.h"
48 #include "llvm/IR/Writer.h"
4948 #include "llvm/InstVisitor.h"
5049 #include "llvm/Pass.h"
5150 #include "llvm/PassManager.h"
128127 if (isa(V)) {
129128 MessagesStr << *V << '\n';
130129 } else {
131 WriteAsOperand(MessagesStr, V, true, Mod);
130 V->printAsOperand(MessagesStr, true, Mod);
132131 MessagesStr << '\n';
133132 }
134133 }
2323 #include "llvm/IR/Constants.h"
2424 #include "llvm/IR/Instructions.h"
2525 #include "llvm/IR/Metadata.h"
26 #include "llvm/IR/Writer.h"
2726 #include "llvm/Support/CFG.h"
2827 #include "llvm/Support/CommandLine.h"
2928 #include "llvm/Support/Debug.h"
1313 #include "llvm/ADT/SetVector.h"
1414 #include "llvm/Analysis/MemoryDependenceAnalysis.h"
1515 #include "llvm/IR/LLVMContext.h"
16 #include "llvm/IR/Writer.h"
1716 #include "llvm/Support/CallSite.h"
1817 #include "llvm/Support/ErrorHandling.h"
1918 #include "llvm/Support/InstIterator.h"
176175 OS << DepTypeStr[type];
177176 if (DepBB) {
178177 OS << " in block ";
179 WriteAsOperand(OS, DepBB, /*PrintType=*/false, M);
178 DepBB->printAsOperand(OS, /*PrintType=*/false, M);
180179 }
181180 if (DepInst) {
182181 OS << " from: ";
1818 #include "llvm/ADT/Statistic.h"
1919 #include "llvm/DebugInfo.h"
2020 #include "llvm/IR/Function.h"
21 #include "llvm/IR/Writer.h"
2221 #include "llvm/Pass.h"
2322 #include "llvm/Support/ErrorHandling.h"
2423 #include "llvm/Support/raw_ostream.h"
1717 #include "llvm/ADT/SetOperations.h"
1818 #include "llvm/Analysis/DominatorInternals.h"
1919 #include "llvm/IR/Instructions.h"
20 #include "llvm/IR/Writer.h"
2120 #include "llvm/Support/CFG.h"
2221 #include "llvm/Support/Debug.h"
2322 using namespace llvm;
1414 #include "llvm/ADT/Statistic.h"
1515 #include "llvm/Analysis/LoopInfo.h"
1616 #include "llvm/Analysis/RegionIterator.h"
17 #include "llvm/IR/Writer.h"
1817 #include "llvm/Support/CommandLine.h"
1918 #include "llvm/Support/Debug.h"
2019 #include "llvm/Support/ErrorHandling.h"
214213 if (getEntry()->getName().empty()) {
215214 raw_string_ostream OS(entryName);
216215
217 WriteAsOperand(OS, getEntry(), false);
216 getEntry()->printAsOperand(OS, false);
218217 } else
219218 entryName = getEntry()->getName();
220219
222221 if (getExit()->getName().empty()) {
223222 raw_string_ostream OS(exitName);
224223
225 WriteAsOperand(OS, getExit(), false);
224 getExit()->printAsOperand(OS, false);
226225 } else
227226 exitName = getExit()->getName();
228227 } else
7676 #include "llvm/IR/Instructions.h"
7777 #include "llvm/IR/LLVMContext.h"
7878 #include "llvm/IR/Operator.h"
79 #include "llvm/IR/Writer.h"
8079 #include "llvm/Support/CommandLine.h"
8180 #include "llvm/Support/ConstantRange.h"
8281 #include "llvm/Support/Debug.h"
137136 void SCEV::print(raw_ostream &OS) const {
138137 switch (getSCEVType()) {
139138 case scConstant:
140 WriteAsOperand(OS, cast(this)->getValue(), false);
139 cast(this)->getValue()->printAsOperand(OS, false);
141140 return;
142141 case scTruncate: {
143142 const SCEVTruncateExpr *Trunc = cast(this);
173172 if (AR->getNoWrapFlags(FlagNW) &&
174173 !AR->getNoWrapFlags((NoWrapFlags)(FlagNUW | FlagNSW)))
175174 OS << "nw><";
176 WriteAsOperand(OS, AR->getLoop()->getHeader(), /*PrintType=*/false);
175 AR->getLoop()->getHeader()->printAsOperand(OS, /*PrintType=*/false);
177176 OS << ">";
178177 return;
179178 }
228227 Constant *FieldNo;
229228 if (U->isOffsetOf(CTy, FieldNo)) {
230229 OS << "offsetof(" << *CTy << ", ";
231 WriteAsOperand(OS, FieldNo, false);
230 FieldNo->printAsOperand(OS, false);
232231 OS << ")";
233232 return;
234233 }
235234
236235 // Otherwise just print it normally.
237 WriteAsOperand(OS, U->getValue(), false);
236 U->getValue()->printAsOperand(OS, false);
238237 return;
239238 }
240239 case scCouldNotCompute:
73207319 PrintLoopInfo(OS, SE, *I);
73217320
73227321 OS << "Loop ";
7323 WriteAsOperand(OS, L->getHeader(), /*PrintType=*/false);
7322 L->getHeader()->printAsOperand(OS, /*PrintType=*/false);
73247323 OS << ": ";
73257324
73267325 SmallVector ExitBlocks;
73367335
73377336 OS << "\n"
73387337 "Loop ";
7339 WriteAsOperand(OS, L->getHeader(), /*PrintType=*/false);
7338 L->getHeader()->printAsOperand(OS, /*PrintType=*/false);
73407339 OS << ": ";
73417340
73427341 if (!isa(SE->getMaxBackedgeTakenCount(L))) {
73587357 ScalarEvolution &SE = *const_cast(this);
73597358
73607359 OS << "Classifying expressions for: ";
7361 WriteAsOperand(OS, F, /*PrintType=*/false);
7360 F->printAsOperand(OS, /*PrintType=*/false);
73627361 OS << "\n";
73637362 for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I)
73647363 if (isSCEVable(I->getType()) && !isa(*I)) {
73897388 }
73907389
73917390 OS << "Determining loop execution counts for: ";
7392 WriteAsOperand(OS, F, /*PrintType=*/false);
7391 F->printAsOperand(OS, /*PrintType=*/false);
73937392 OS << "\n";
73947393 for (LoopInfo::iterator I = LI->begin(), E = LI->end(); I != E; ++I)
73957394 PrintLoopInfo(OS, &SE, *I);
1616
1717 #include "llvm/Analysis/Trace.h"
1818 #include "llvm/IR/Function.h"
19 #include "llvm/IR/Writer.h"
2019 #include "llvm/Support/Debug.h"
2120 #include "llvm/Support/raw_ostream.h"
2221 using namespace llvm;
3635 O << "; Trace from function " << F->getName() << ", blocks:\n";
3736 for (const_iterator i = begin(), e = end(); i != e; ++i) {
3837 O << "; ";
39 WriteAsOperand(O, *i, true, getModule());
38 (*i)->printAsOperand(O, true, getModule());
4039 O << "\n";
4140 }
4241 O << "; Trace parent function: \n" << *F;
2929 #include "llvm/IR/Mangler.h"
3030 #include "llvm/IR/Module.h"
3131 #include "llvm/IR/Operator.h"
32 #include "llvm/IR/Writer.h"
3332 #include "llvm/MC/MCAsmInfo.h"
3433 #include "llvm/MC/MCContext.h"
3534 #include "llvm/MC/MCExpr.h"
290289 return;
291290
292291 if (isVerbose()) {
293 WriteAsOperand(OutStreamer.GetCommentOS(), GV,
292 GV->printAsOperand(OutStreamer.GetCommentOS(),
294293 /*PrintType=*/false, GV->getParent());
295294 OutStreamer.GetCommentOS() << '\n';
296295 }
469468 OutStreamer.EmitSymbolAttribute(CurrentFnSym, MCSA_ELF_TypeFunction);
470469
471470 if (isVerbose()) {
472 WriteAsOperand(OutStreamer.GetCommentOS(), F,
471 F->printAsOperand(OutStreamer.GetCommentOS(),
473472 /*PrintType=*/false, F->getParent());
474473 OutStreamer.GetCommentOS() << '\n';
475474 }
15281527 std::string S;
15291528 raw_string_ostream OS(S);
15301529 OS << "Unsupported expression in static initializer: ";
1531 WriteAsOperand(OS, CE, /*PrintType=*/false,
1530 CE->printAsOperand(OS, /*PrintType=*/false,
15321531 !AP.MF ? 0 : AP.MF->getFunction()->getParent());
15331532 report_fatal_error(OS.str());
15341533 }
2323 #include "llvm/CodeGen/SlotIndexes.h"
2424 #include "llvm/IR/BasicBlock.h"
2525 #include "llvm/IR/DataLayout.h"
26 #include "llvm/IR/Writer.h"
2726 #include "llvm/MC/MCAsmInfo.h"
2827 #include "llvm/MC/MCContext.h"
2928 #include "llvm/Support/Debug.h"
277276 const char *Comma = "";
278277 if (const BasicBlock *LBB = getBasicBlock()) {
279278 OS << Comma << "derived from LLVM BB ";
280 WriteAsOperand(OS, LBB, /*PrintType=*/false);
279 LBB->printAsOperand(OS, /*PrintType=*/false);
281280 Comma = ", ";
282281 }
283282 if (isLandingPad()) { OS << Comma << "EH LANDING PAD"; Comma = ", "; }
328327 }
329328 OS << '\n';
330329 }
330 }
331
332 void MachineBasicBlock::printAsOperand(raw_ostream &OS, bool /*PrintType*/) {
333 OS << "BB#" << getNumber();
331334 }
332335
333336 void MachineBasicBlock::removeLiveIn(unsigned Reg) {
12151218 // At this point we have no idea of the liveness of the register.
12161219 return LQR_Unknown;
12171220 }
1218
1219 void llvm::WriteAsOperand(raw_ostream &OS, const MachineBasicBlock *MBB,
1220 bool t) {
1221 OS << "BB#" << MBB->getNumber();
1222 }
1223
2727 #include "llvm/DebugInfo.h"
2828 #include "llvm/IR/DataLayout.h"
2929 #include "llvm/IR/Function.h"
30 #include "llvm/IR/Writer.h"
3130 #include "llvm/MC/MCAsmInfo.h"
3231 #include "llvm/MC/MCContext.h"
3332 #include "llvm/Support/Debug.h"
917916 if (Constants[i].isMachineConstantPoolEntry())
918917 Constants[i].Val.MachineCPVal->print(OS);
919918 else
920 WriteAsOperand(OS, Constants[i].Val.ConstVal, /*PrintType=*/false);
919 Constants[i].Val.ConstVal->printAsOperand(OS, /*PrintType=*/false);
921920 OS << ", align=" << Constants[i].getAlignment();
922921 OS << "\n";
923922 }
2929 #include "llvm/IR/Module.h"
3030 #include "llvm/IR/Type.h"
3131 #include "llvm/IR/Value.h"
32 #include "llvm/IR/Writer.h"
3332 #include "llvm/MC/MCInstrDesc.h"
3433 #include "llvm/MC/MCSymbol.h"
3534 #include "llvm/Support/Debug.h"
351350 break;
352351 case MachineOperand::MO_GlobalAddress:
353352 OS << "
354 WriteAsOperand(OS, getGlobal(), /*PrintType=*/false);
353 getGlobal()->printAsOperand(OS, /*PrintType=*/false);
355354 if (getOffset()) OS << "+" << getOffset();
356355 OS << '>';
357356 break;
362361 break;
363362 case MachineOperand::MO_BlockAddress:
364363 OS << '<';
365 WriteAsOperand(OS, getBlockAddress(), /*PrintType=*/false);
364 getBlockAddress()->printAsOperand(OS, /*PrintType=*/false);
366365 if (getOffset()) OS << "+" << getOffset();
367366 OS << '>';
368367 break;
374373 break;
375374 case MachineOperand::MO_Metadata:
376375 OS << '<';
377 WriteAsOperand(OS, getMetadata(), /*PrintType=*/false);
376 getMetadata()->printAsOperand(OS, /*PrintType=*/false);
378377 OS << '>';
379378 break;
380379 case MachineOperand::MO_MCSymbol:
483482 if (!MMO.getValue())
484483 OS << "";
485484 else
486 WriteAsOperand(OS, MMO.getValue(), /*PrintType=*/false);
485 MMO.getValue()->printAsOperand(OS, /*PrintType=*/false);
487486
488487 unsigned AS = MMO.getAddrSpace();
489488 if (AS != 0)
508507 if (const MDNode *TBAAInfo = MMO.getTBAAInfo()) {
509508 OS << "(tbaa=";
510509 if (TBAAInfo->getNumOperands() > 0)
511 WriteAsOperand(OS, TBAAInfo->getOperand(0), /*PrintType=*/false);
510 TBAAInfo->getOperand(0)->printAsOperand(OS, /*PrintType=*/false);
512511 else
513512 OS << "";
514513 OS << ")";
1717 #include "llvm/CodeGen/MachineFunction.h"
1818 #include "llvm/CodeGen/MachineModuleInfo.h"
1919 #include "llvm/IR/Constants.h"
20 #include "llvm/IR/Writer.h"
2120 #include "llvm/Support/Debug.h"
2221 #include "llvm/Support/GraphWriter.h"
2322 #include "llvm/Support/raw_ostream.h"
3232 #include "llvm/IR/GlobalAlias.h"
3333 #include "llvm/IR/GlobalVariable.h"
3434 #include "llvm/IR/Intrinsics.h"
35 #include "llvm/IR/Writer.h"
3635 #include "llvm/Support/CommandLine.h"
3736 #include "llvm/Support/Debug.h"
3837 #include "llvm/Support/ErrorHandling.h"
1919 #include "llvm/DebugInfo.h"
2020 #include "llvm/IR/Function.h"
2121 #include "llvm/IR/Intrinsics.h"
22 #include "llvm/IR/Writer.h"
2322 #include "llvm/Support/Debug.h"
2423 #include "llvm/Support/GraphWriter.h"
2524 #include "llvm/Support/raw_ostream.h"
384383 dyn_cast(this)) {
385384 int64_t offset = GADN->getOffset();
386385 OS << '<';
387 WriteAsOperand(OS, GADN->getGlobal());
386 GADN->getGlobal()->printAsOperand(OS);
388387 OS << '>';
389388 if (offset > 0)
390389 OS << " + " << offset;
475474 dyn_cast(this)) {
476475 int64_t offset = BA->getOffset();
477476 OS << "<";
478 WriteAsOperand(OS, BA->getBlockAddress()->getFunction(), false);
477 BA->getBlockAddress()->getFunction()->printAsOperand(OS, false);
479478 OS << ", ";
480 WriteAsOperand(OS, BA->getBlockAddress()->getBasicBlock(), false);
479 BA->getBlockAddress()->getBasicBlock()->printAsOperand(OS, false);
481480 OS << ">";
482481 if (offset > 0)
483482 OS << " + " << offset;
1919 #include "llvm/CodeGen/MachineModuleInfo.h"
2020 #include "llvm/DebugInfo.h"
2121 #include "llvm/IR/Constants.h"
22 #include "llvm/IR/Writer.h"
2322 #include "llvm/Support/Debug.h"
2423 #include "llvm/Support/GraphWriter.h"
2524 #include "llvm/Support/raw_ostream.h"
3131 #include "llvm/IR/PrintModulePass.h"
3232 #include "llvm/IR/TypeFinder.h"
3333 #include "llvm/IR/ValueSymbolTable.h"
34 #include "llvm/IR/Writer.h"
3534 #include "llvm/Support/CFG.h"
3635 #include "llvm/Support/Debug.h"
3736 #include "llvm/Support/Dwarf.h"
673672 TypePrinting *TypePrinter,
674673 SlotTracker *Machine,
675674 const Module *Context);
676
677
678675
679676 static const char *getPredicateText(unsigned predicate) {
680677 const char * pred = "unknown";
10621059 Out << "}";
10631060 }
10641061
1065
1066 /// WriteAsOperand - Write the name of the specified value out to the specified
1067 /// ostream. This can be useful when you just want to print int %reg126, not
1068 /// the whole instruction that generated it.
1069 ///
1062 // Full implementation of printing a Value as an operand with support for
1063 // TypePrinting, etc.
10701064 static void WriteAsOperandInternal(raw_ostream &Out, const Value *V,
10711065 TypePrinting *TypePrinter,
10721066 SlotTracker *Machine,
11711165 Out << Prefix << Slot;
11721166 else
11731167 Out << "";
1174 }
1175
1176 void WriteAsOperand(raw_ostream &Out, const Value *V,
1177 bool PrintType, const Module *Context) {
1178
1179 // Fast path: Don't construct and populate a TypePrinting object if we
1180 // won't be needing any types printed.
1181 if (!PrintType &&
1182 ((!isa(V) && !isa(V)) ||
1183 V->hasName() || isa(V))) {
1184 WriteAsOperandInternal(Out, V, 0, 0, Context);
1185 return;
1186 }
1187
1188 if (Context == 0) Context = getModuleFromVal(V);
1189
1190 TypePrinting TypePrinter;
1191 if (Context)
1192 TypePrinter.incorporateTypes(*Context);
1193 if (PrintType) {
1194 TypePrinter.print(V->getType(), Out);
1195 Out << ' ';
1196 }
1197
1198 WriteAsOperandInternal(Out, V, &TypePrinter, 0, Context);
11991168 }
12001169
12011170 void AssemblyWriter::init() {
21922161 WriteConstantInternal(OS, C, TypePrinter, 0, 0);
21932162 } else if (isa(this) || isa(this) ||
21942163 isa(this)) {
2195 WriteAsOperand(OS, this, true, 0);
2164 this->printAsOperand(OS);
21962165 } else {
21972166 // Otherwise we don't know what it is. Call the virtual function to
21982167 // allow a subclass to print itself.
22002169 }
22012170 }
22022171
2172 void Value::printAsOperand(raw_ostream &O, bool PrintType, const Module *M) const {
2173 // Fast path: Don't construct and populate a TypePrinting object if we
2174 // won't be needing any types printed.
2175 if (!PrintType &&
2176 ((!isa(this) && !isa(this)) ||
2177 hasName() || isa(this))) {
2178 WriteAsOperandInternal(O, this, 0, 0, M);
2179 return;
2180 }
2181
2182 if (!M)
2183 M = getModuleFromVal(this);
2184
2185 TypePrinting TypePrinter;
2186 if (M)
2187 TypePrinter.incorporateTypes(*M);
2188 if (PrintType) {
2189 TypePrinter.print(getType(), O);
2190 O << ' ';
2191 }
2192
2193 WriteAsOperandInternal(O, this, &TypePrinter, 0, M);
2194 }
2195
22032196 // Value::printCustom - subclasses should override this to implement printing.
22042197 void Value::printCustom(raw_ostream &OS) const {
22052198 llvm_unreachable("Unknown value to print out!");
1919 #include "llvm/ADT/SmallVector.h"
2020 #include "llvm/Analysis/DominatorInternals.h"
2121 #include "llvm/IR/Instructions.h"
22 #include "llvm/IR/Writer.h"
2322 #include "llvm/Support/CFG.h"
2423 #include "llvm/Support/CommandLine.h"
2524 #include "llvm/Support/Compiler.h"
1515 #include "llvm/IR/LegacyPassManager.h"
1616 #include "llvm/IR/LegacyPassManagers.h"
1717 #include "llvm/IR/Module.h"
18 #include "llvm/IR/Writer.h"
1918 #include "llvm/Support/CommandLine.h"
2019 #include "llvm/Support/Debug.h"
2120 #include "llvm/Support/ErrorHandling.h"
143142 OS << "value";
144143
145144 OS << " '";
146 WriteAsOperand(OS, V, /*PrintTy=*/false, M);
145 V->printAsOperand(OS, /*PrintTy=*/false, M);
147146 OS << "'\n";
148147 }
149148
6161 #include "llvm/IR/LLVMContext.h"
6262 #include "llvm/IR/Metadata.h"
6363 #include "llvm/IR/Module.h"
64 #include "llvm/IR/Writer.h"
6564 #include "llvm/InstVisitor.h"
6665 #include "llvm/Pass.h"
6766 #include "llvm/PassManager.h"
10099 if (I->empty() || !I->back().isTerminator()) {
101100 dbgs() << "Basic Block in function '" << F.getName()
102101 << "' does not have terminator!\n";
103 WriteAsOperand(dbgs(), I, true);
102 I->printAsOperand(dbgs(), true);
104103 dbgs() << "\n";
105104 Broken = true;
106105 }
347346 if (isa(V)) {
348347 MessagesStr << *V << '\n';
349348 } else {
350 WriteAsOperand(MessagesStr, V, true, Mod);
349 V->printAsOperand(MessagesStr, true, Mod);
351350 MessagesStr << '\n';
352351 }
353352 }
3434 #include "llvm/IR/Mangler.h"
3535 #include "llvm/IR/Module.h"
3636 #include "llvm/IR/Type.h"
37 #include "llvm/IR/Writer.h"
3837 #include "llvm/MC/MCAsmInfo.h"
3938 #include "llvm/MC/MCAssembler.h"
4039 #include "llvm/MC/MCContext.h"
3434 #include "llvm/IR/DerivedTypes.h"
3535 #include "llvm/IR/Mangler.h"
3636 #include "llvm/IR/Module.h"
37 #include "llvm/IR/Writer.h"
3837 #include "llvm/MC/MCAsmInfo.h"
3938 #include "llvm/MC/MCContext.h"
4039 #include "llvm/MC/MCExpr.h"
2626 #include "llvm/IR/DerivedTypes.h"
2727 #include "llvm/IR/Mangler.h"
2828 #include "llvm/IR/Module.h"
29 #include "llvm/IR/Writer.h"
3029 #include "llvm/MC/MCAsmInfo.h"
3130 #include "llvm/MC/MCInst.h"
3231 #include "llvm/MC/MCStreamer.h"
3434 #include "llvm/IR/Mangler.h"
3535 #include "llvm/IR/Module.h"
3636 #include "llvm/IR/Operator.h"
37 #include "llvm/IR/Writer.h"
3837 #include "llvm/MC/MCStreamer.h"
3938 #include "llvm/MC/MCSymbol.h"
4039 #include "llvm/Support/CommandLine.h"
148147 std::string S;
149148 raw_string_ostream OS(S);
150149 OS << "Unsupported expression in static initializer: ";
151 WriteAsOperand(OS, CE, /*PrintType=*/ false,
150 CE->printAsOperand(OS, /*PrintType=*/ false,
152151 !AP.MF ? 0 : AP.MF->getFunction()->getParent());
153152 report_fatal_error(OS.str());
154153 }
3737 #include "llvm/IR/DerivedTypes.h"
3838 #include "llvm/IR/Mangler.h"
3939 #include "llvm/IR/Module.h"
40 #include "llvm/IR/Writer.h"
4140 #include "llvm/MC/MCAsmInfo.h"
4241 #include "llvm/MC/MCContext.h"
4342 #include "llvm/MC/MCExpr.h"
2727 #include "llvm/IR/Mangler.h"
2828 #include "llvm/IR/Module.h"
2929 #include "llvm/IR/Type.h"
30 #include "llvm/IR/Writer.h"
3130 #include "llvm/MC/MCAsmInfo.h"
3231 #include "llvm/MC/MCContext.h"
3332 #include "llvm/MC/MCExpr.h"
2929 #include "llvm/IR/InlineAsm.h"
3030 #include "llvm/IR/Instructions.h"
3131 #include "llvm/IR/IntrinsicInst.h"
32 #include "llvm/IR/Writer.h"
3332 #include "llvm/Pass.h"
3433 #include "llvm/Support/CallSite.h"
3534 #include "llvm/Support/CommandLine.h"
844843 if (BaseGV) {
845844 OS << (NeedPlus ? " + " : "")
846845 << "GV:";
847 WriteAsOperand(OS, BaseGV, /*PrintType=*/false);
846 BaseGV->printAsOperand(OS, /*PrintType=*/false);
848847 NeedPlus = true;
849848 }
850849
854853 if (BaseReg) {
855854 OS << (NeedPlus ? " + " : "")
856855 << "Base:";
857 WriteAsOperand(OS, BaseReg, /*PrintType=*/false);
856 BaseReg->printAsOperand(OS, /*PrintType=*/false);
858857 NeedPlus = true;
859858 }
860859 if (Scale) {
861860 OS << (NeedPlus ? " + " : "")
862861 << Scale << "*";
863 WriteAsOperand(OS, ScaledReg, /*PrintType=*/false);
862 ScaledReg->printAsOperand(OS, /*PrintType=*/false);
864863 }
865864
866865 OS << ']';
3838 #include "llvm/IR/IntrinsicInst.h"
3939 #include "llvm/IR/LLVMContext.h"
4040 #include "llvm/IR/Metadata.h"
41 #include "llvm/IR/Writer.h"
4241 #include "llvm/Support/Allocator.h"
4342 #include "llvm/Support/CommandLine.h"
4443 #include "llvm/Support/Debug.h"
17111710 !Deps[0].getResult().isDef() && !Deps[0].getResult().isClobber()) {
17121711 DEBUG(
17131712 dbgs() << "GVN: non-local load ";
1714 WriteAsOperand(dbgs(), LI);
1713 LI->printAsOperand(dbgs());
17151714 dbgs() << " has unknown dependencies\n";
17161715 );
17171716 return false;
18891888 DEBUG(
18901889 // fast print dep, using operator<< on instruction is too slow.
18911890 dbgs() << "GVN: load ";
1892 WriteAsOperand(dbgs(), L);
1891 L->printAsOperand(dbgs());
18931892 Instruction *I = Dep.getInst();
18941893 dbgs() << " is clobbered by " << *I << '\n';
18951894 );
19041903 DEBUG(
19051904 // fast print dep, using operator<< on instruction is too slow.
19061905 dbgs() << "GVN: load ";
1907 WriteAsOperand(dbgs(), L);
1906 L->printAsOperand(dbgs());
19081907 dbgs() << " has unknown dependence\n";
19091908 );
19101909 return false;
6767 #include "llvm/IR/DerivedTypes.h"
6868 #include "llvm/IR/Instructions.h"
6969 #include "llvm/IR/IntrinsicInst.h"
70 #include "llvm/IR/Writer.h"
7170 #include "llvm/Support/CommandLine.h"
7271 #include "llvm/Support/Debug.h"
7372 #include "llvm/Support/ValueHandle.h"
393392 bool First = true;
394393 if (BaseGV) {
395394 if (!First) OS << " + "; else First = false;
396 WriteAsOperand(OS, BaseGV, /*PrintType=*/false);
395 BaseGV->printAsOperand(OS, /*PrintType=*/false);
397396 }
398397 if (BaseOffset != 0) {
399398 if (!First) OS << " + "; else First = false;
10791078 // Store is common and interesting enough to be worth special-casing.
10801079 if (StoreInst *Store = dyn_cast(UserInst)) {
10811080 OS << "store ";
1082 WriteAsOperand(OS, Store->getOperand(0), /*PrintType=*/false);
1081 Store->getOperand(0)->printAsOperand(OS, /*PrintType=*/false);
10831082 } else if (UserInst->getType()->isVoidTy())
10841083 OS << UserInst->getOpcodeName();
10851084 else
1086 WriteAsOperand(OS, UserInst, /*PrintType=*/false);
1085 UserInst->printAsOperand(OS, /*PrintType=*/false);
10871086
10881087 OS << ", OperandValToReplace=";
1089 WriteAsOperand(OS, OperandValToReplace, /*PrintType=*/false);
1088 OperandValToReplace->printAsOperand(OS, /*PrintType=*/false);
10901089
10911090 for (PostIncLoopSet::const_iterator I = PostIncLoops.begin(),
10921091 E = PostIncLoops.end(); I != E; ++I) {
10931092 OS << ", PostIncLoop=";
1094 WriteAsOperand(OS, (*I)->getHeader(), /*PrintType=*/false);
1093 (*I)->getHeader()->printAsOperand(OS, /*PrintType=*/false);
10951094 }
10961095
10971096 if (LUIdx != ~size_t(0))
47334732 #endif // DEBUG
47344733
47354734 DEBUG(dbgs() << "\nLSR on loop ";
4736 WriteAsOperand(dbgs(), L->getHeader(), /*PrintType=*/false);
4735 L->getHeader()->printAsOperand(dbgs(), /*PrintType=*/false);
47374736 dbgs() << ":\n");
47384737
47394738 // First, perform some low-level loop optimizations.
3232 #include "llvm/IR/IRBuilder.h"
3333 #include "llvm/IR/Instructions.h"
3434 #include "llvm/IR/IntrinsicInst.h"
35 #include "llvm/IR/Writer.h"
3635 #include "llvm/Pass.h"
3736 #include "llvm/Support/CFG.h"
3837 #include "llvm/Support/Debug.h"
6665 << *Ops[0].Op->getType() << '\t';
6766 for (unsigned i = 0, e = Ops.size(); i != e; ++i) {
6867 dbgs() << "[ ";
69 WriteAsOperand(dbgs(), Ops[i].Op, false, M);
68 Ops[i].Op->printAsOperand(dbgs(), false, M);
7069 dbgs() << ", #" << Ops[i].Rank << "] ";
7170 }
7271 }
1919 #include "llvm/Analysis/LoopInfo.h"
2020 #include "llvm/Analysis/ValueTracking.h"
2121 #include "llvm/IR/IntrinsicInst.h"
22 #include "llvm/IR/Writer.h"
2322 #include "llvm/Support/CFG.h"
2423 #include "llvm/Support/Debug.h"
2524 #include "llvm/Support/raw_ostream.h"
258257 return false;
259258
260259 DEBUG(dbgs() << "Sink" << *Inst << " (";
261 WriteAsOperand(dbgs(), Inst->getParent(), false);
260 Inst->getParent()->printAsOperand(dbgs(), false);
262261 dbgs() << " -> ";
263 WriteAsOperand(dbgs(), SuccToSinkTo, false);
262 SuccToSinkTo->printAsOperand(dbgs(), false);
264263 dbgs() << ")\n");
265264
266265 // Move the instruction.
1818 #include "llvm/IR/DerivedTypes.h"
1919 #include "llvm/IR/LLVMContext.h"
2020 #include "llvm/IR/Module.h"
21 #include "llvm/IR/Writer.h"
2221 #include "llvm/Pass.h"
2322 #include "llvm/PassManager.h"
2423 #include "llvm/Support/CommandLine.h"
308307 for (unsigned i = 0, e = F.size(); i != e; ++i) {
309308 Function *TNOF = cast(VMap[F[i]]);
310309 DEBUG(errs() << "Removing function ");
311 DEBUG(WriteAsOperand(errs(), TNOF, false));
310 DEBUG(TNOF->printAsOperand(errs(), false));
312311 DEBUG(errs() << "\n");
313312 TestFunctions.insert(cast(NewVMap[TNOF]));
314313 DeleteFunctionBody(TNOF); // Function is now external in this module!
329328 if (Function *SafeFn = globalInitUsesExternalBA(GV)) {
330329 errs() << "*** Error: when reducing functions, encountered "
331330 "the global '";
332 WriteAsOperand(errs(), GV, false);
331 GV->printAsOperand(errs(), false);
333332 errs() << "' with an initializer that references blockaddresses "
334333 "from safe function '" << SafeFn->getName()
335334 << "' and from test function '" << TestFn->getName() << "'.\n";