summaryrefslogtreecommitdiff
path: root/lib/IR
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2014-01-09 02:29:41 +0000
committerChandler Carruth <chandlerc@gmail.com>2014-01-09 02:29:41 +0000
commit560e3955c3c4fe0a3ae88fd91a1b7780b8fe7810 (patch)
tree77aed3e451050c08fe443b73e42ccac2fc13d366 /lib/IR
parent58691befda948d2a69f93e91d4aeedc0e7c38501 (diff)
downloadllvm-560e3955c3c4fe0a3ae88fd91a1b7780b8fe7810.tar.gz
llvm-560e3955c3c4fe0a3ae88fd91a1b7780b8fe7810.tar.bz2
llvm-560e3955c3c4fe0a3ae88fd91a1b7780b8fe7810.tar.xz
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
Diffstat (limited to 'lib/IR')
-rw-r--r--lib/IR/AsmWriter.cpp61
-rw-r--r--lib/IR/Dominators.cpp1
-rw-r--r--lib/IR/LegacyPassManager.cpp3
-rw-r--r--lib/IR/Verifier.cpp5
4 files changed, 30 insertions, 40 deletions
diff --git a/lib/IR/AsmWriter.cpp b/lib/IR/AsmWriter.cpp
index 9680aa4bf5..cfe07ffba7 100644
--- a/lib/IR/AsmWriter.cpp
+++ b/lib/IR/AsmWriter.cpp
@@ -32,7 +32,6 @@
#include "llvm/IR/PrintModulePass.h"
#include "llvm/IR/TypeFinder.h"
#include "llvm/IR/ValueSymbolTable.h"
-#include "llvm/IR/Writer.h"
#include "llvm/Support/CFG.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/Dwarf.h"
@@ -675,8 +674,6 @@ static void WriteAsOperandInternal(raw_ostream &Out, const Value *V,
SlotTracker *Machine,
const Module *Context);
-
-
static const char *getPredicateText(unsigned predicate) {
const char * pred = "unknown";
switch (predicate) {
@@ -1063,11 +1060,8 @@ static void WriteMDNodeBodyInternal(raw_ostream &Out, const MDNode *Node,
Out << "}";
}
-
-/// WriteAsOperand - Write the name of the specified value out to the specified
-/// ostream. This can be useful when you just want to print int %reg126, not
-/// the whole instruction that generated it.
-///
+// Full implementation of printing a Value as an operand with support for
+// TypePrinting, etc.
static void WriteAsOperandInternal(raw_ostream &Out, const Value *V,
TypePrinting *TypePrinter,
SlotTracker *Machine,
@@ -1174,31 +1168,6 @@ static void WriteAsOperandInternal(raw_ostream &Out, const Value *V,
Out << "<badref>";
}
-void WriteAsOperand(raw_ostream &Out, const Value *V,
- bool PrintType, const Module *Context) {
-
- // Fast path: Don't construct and populate a TypePrinting object if we
- // won't be needing any types printed.
- if (!PrintType &&
- ((!isa<Constant>(V) && !isa<MDNode>(V)) ||
- V->hasName() || isa<GlobalValue>(V))) {
- WriteAsOperandInternal(Out, V, 0, 0, Context);
- return;
- }
-
- if (Context == 0) Context = getModuleFromVal(V);
-
- TypePrinting TypePrinter;
- if (Context)
- TypePrinter.incorporateTypes(*Context);
- if (PrintType) {
- TypePrinter.print(V->getType(), Out);
- Out << ' ';
- }
-
- WriteAsOperandInternal(Out, V, &TypePrinter, 0, Context);
-}
-
void AssemblyWriter::init() {
if (TheModule)
TypePrinter.incorporateTypes(*TheModule);
@@ -2193,7 +2162,7 @@ void Value::print(raw_ostream &ROS, AssemblyAnnotationWriter *AAW) const {
WriteConstantInternal(OS, C, TypePrinter, 0, 0);
} else if (isa<InlineAsm>(this) || isa<MDString>(this) ||
isa<Argument>(this)) {
- WriteAsOperand(OS, this, true, 0);
+ this->printAsOperand(OS);
} else {
// Otherwise we don't know what it is. Call the virtual function to
// allow a subclass to print itself.
@@ -2201,6 +2170,30 @@ void Value::print(raw_ostream &ROS, AssemblyAnnotationWriter *AAW) const {
}
}
+void Value::printAsOperand(raw_ostream &O, bool PrintType, const Module *M) const {
+ // Fast path: Don't construct and populate a TypePrinting object if we
+ // won't be needing any types printed.
+ if (!PrintType &&
+ ((!isa<Constant>(this) && !isa<MDNode>(this)) ||
+ hasName() || isa<GlobalValue>(this))) {
+ WriteAsOperandInternal(O, this, 0, 0, M);
+ return;
+ }
+
+ if (!M)
+ M = getModuleFromVal(this);
+
+ TypePrinting TypePrinter;
+ if (M)
+ TypePrinter.incorporateTypes(*M);
+ if (PrintType) {
+ TypePrinter.print(getType(), O);
+ O << ' ';
+ }
+
+ WriteAsOperandInternal(O, this, &TypePrinter, 0, M);
+}
+
// Value::printCustom - subclasses should override this to implement printing.
void Value::printCustom(raw_ostream &OS) const {
llvm_unreachable("Unknown value to print out!");
diff --git a/lib/IR/Dominators.cpp b/lib/IR/Dominators.cpp
index fd0ef4badb..c11c87391a 100644
--- a/lib/IR/Dominators.cpp
+++ b/lib/IR/Dominators.cpp
@@ -20,7 +20,6 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/Analysis/DominatorInternals.h"
#include "llvm/IR/Instructions.h"
-#include "llvm/IR/Writer.h"
#include "llvm/Support/CFG.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Compiler.h"
diff --git a/lib/IR/LegacyPassManager.cpp b/lib/IR/LegacyPassManager.cpp
index 211856bb1b..85e50f753f 100644
--- a/lib/IR/LegacyPassManager.cpp
+++ b/lib/IR/LegacyPassManager.cpp
@@ -16,7 +16,6 @@
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/LegacyPassManagers.h"
#include "llvm/IR/Module.h"
-#include "llvm/IR/Writer.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
@@ -144,7 +143,7 @@ void PassManagerPrettyStackEntry::print(raw_ostream &OS) const {
OS << "value";
OS << " '";
- WriteAsOperand(OS, V, /*PrintTy=*/false, M);
+ V->printAsOperand(OS, /*PrintTy=*/false, M);
OS << "'\n";
}
diff --git a/lib/IR/Verifier.cpp b/lib/IR/Verifier.cpp
index 650e34af82..8324d924ca 100644
--- a/lib/IR/Verifier.cpp
+++ b/lib/IR/Verifier.cpp
@@ -62,7 +62,6 @@
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
-#include "llvm/IR/Writer.h"
#include "llvm/InstVisitor.h"
#include "llvm/Pass.h"
#include "llvm/PassManager.h"
@@ -101,7 +100,7 @@ namespace { // Anonymous namespace for class
if (I->empty() || !I->back().isTerminator()) {
dbgs() << "Basic Block in function '" << F.getName()
<< "' does not have terminator!\n";
- WriteAsOperand(dbgs(), I, true);
+ I->printAsOperand(dbgs(), true);
dbgs() << "\n";
Broken = true;
}
@@ -348,7 +347,7 @@ namespace {
if (isa<Instruction>(V)) {
MessagesStr << *V << '\n';
} else {
- WriteAsOperand(MessagesStr, V, true, Mod);
+ V->printAsOperand(MessagesStr, true, Mod);
MessagesStr << '\n';
}
}