summaryrefslogtreecommitdiffstats
path: root/lib/VMCore
diff options
context:
space:
mode:
Diffstat (limited to 'lib/VMCore')
-rw-r--r--lib/VMCore/AsmWriter.cpp34
-rw-r--r--lib/VMCore/Attributes.cpp7
-rw-r--r--lib/VMCore/AutoUpgrade.cpp59
-rw-r--r--lib/VMCore/ConstantFold.cpp12
-rw-r--r--lib/VMCore/Constants.cpp28
-rw-r--r--lib/VMCore/ConstantsContext.h2
-rw-r--r--lib/VMCore/Core.cpp68
-rw-r--r--lib/VMCore/Function.cpp2
-rw-r--r--lib/VMCore/InlineAsm.cpp2
-rw-r--r--lib/VMCore/Instruction.cpp35
-rw-r--r--lib/VMCore/Instructions.cpp29
-rw-r--r--lib/VMCore/IntrinsicInst.cpp26
-rw-r--r--lib/VMCore/Mangler.cpp200
-rw-r--r--lib/VMCore/Metadata.cpp212
-rw-r--r--lib/VMCore/Module.cpp24
-rw-r--r--lib/VMCore/Pass.cpp5
-rw-r--r--lib/VMCore/PassManager.cpp67
-rw-r--r--lib/VMCore/PrintModulePass.cpp5
-rw-r--r--lib/VMCore/Type.cpp31
-rw-r--r--lib/VMCore/TypeSymbolTable.cpp21
-rw-r--r--lib/VMCore/TypesContext.h6
-rw-r--r--lib/VMCore/Value.cpp32
-rw-r--r--lib/VMCore/ValueSymbolTable.cpp20
-rw-r--r--lib/VMCore/Verifier.cpp18
24 files changed, 549 insertions, 396 deletions
diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp
index d3c9d77..eff2c77 100644
--- a/lib/VMCore/AsmWriter.cpp
+++ b/lib/VMCore/AsmWriter.cpp
@@ -30,6 +30,7 @@
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/CFG.h"
+#include "llvm/Support/Debug.h"
#include "llvm/Support/Dwarf.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MathExtras.h"
@@ -563,11 +564,14 @@ static SlotTracker *createSlotTracker(const Value *V) {
if (const Function *Func = dyn_cast<Function>(V))
return new SlotTracker(Func);
+ if (isa<MDNode>(V))
+ return new SlotTracker((Function *)0);
+
return 0;
}
#if 0
-#define ST_DEBUG(X) errs() << X
+#define ST_DEBUG(X) dbgs() << X
#else
#define ST_DEBUG(X)
#endif
@@ -614,8 +618,7 @@ void SlotTracker::processModule() {
E = TheModule->named_metadata_end(); I != E; ++I) {
const NamedMDNode *NMD = I;
for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
- // FIXME: Change accessor to be type safe.
- if (MDNode *MD = cast_or_null<MDNode>(NMD->getOperand(i)))
+ if (MDNode *MD = NMD->getOperand(i))
CreateMetadataSlot(MD);
}
}
@@ -832,7 +835,7 @@ static void WriteOptimizationInfo(raw_ostream &Out, const User *U) {
static void WriteConstantInt(raw_ostream &Out, const Constant *CV,
TypePrinting &TypePrinter, SlotTracker *Machine) {
if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
- if (CI->getType() == Type::getInt1Ty(CV->getContext())) {
+ if (CI->getType()->isInteger(1)) {
Out << (CI->getZExtValue() ? "true" : "false");
return;
}
@@ -1136,6 +1139,8 @@ static void WriteAsOperandInternal(raw_ostream &Out, const Value *V,
return;
}
+ if (!Machine)
+ Machine = createSlotTracker(V);
Out << '!' << Machine->getMetadataSlot(N);
return;
}
@@ -1369,10 +1374,10 @@ void AssemblyWriter::printNamedMDNode(const NamedMDNode *NMD) {
Out << "!" << NMD->getName() << " = !{";
for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
if (i) Out << ", ";
- // FIXME: Change accessor to be typesafe.
- // FIXME: This doesn't handle null??
- MDNode *MD = cast_or_null<MDNode>(NMD->getOperand(i));
- Out << '!' << Machine.getMetadataSlot(MD);
+ if (MDNode *MD = NMD->getOperand(i))
+ Out << '!' << Machine.getMetadataSlot(MD);
+ else
+ Out << "null";
}
Out << "}\n";
}
@@ -2057,8 +2062,9 @@ void Value::print(raw_ostream &ROS, AssemblyAnnotationWriter *AAW) const {
else
W.printAlias(cast<GlobalAlias>(GV));
} else if (const MDNode *N = dyn_cast<MDNode>(this)) {
- SlotTracker SlotTable((Function*)0);
- AssemblyWriter W(OS, SlotTable, 0, AAW);
+ Function *F = N->getFunction();
+ SlotTracker SlotTable(F);
+ AssemblyWriter W(OS, SlotTable, getModuleFromVal(F), AAW);
W.printMDNodeBody(N);
} else if (const NamedMDNode *N = dyn_cast<NamedMDNode>(this)) {
SlotTracker SlotTable(N->getParent());
@@ -2085,17 +2091,17 @@ void Value::printCustom(raw_ostream &OS) const {
}
// Value::dump - allow easy printing of Values from the debugger.
-void Value::dump() const { print(errs()); errs() << '\n'; }
+void Value::dump() const { print(dbgs()); dbgs() << '\n'; }
// Type::dump - allow easy printing of Types from the debugger.
// This one uses type names from the given context module
void Type::dump(const Module *Context) const {
- WriteTypeSymbolic(errs(), this, Context);
- errs() << '\n';
+ WriteTypeSymbolic(dbgs(), this, Context);
+ dbgs() << '\n';
}
// Type::dump - allow easy printing of Types from the debugger.
void Type::dump() const { dump(0); }
// Module::dump() - Allow printing of Modules from the debugger.
-void Module::dump() const { print(errs(), 0); }
+void Module::dump() const { print(dbgs(), 0); }
diff --git a/lib/VMCore/Attributes.cpp b/lib/VMCore/Attributes.cpp
index d68bba3..a371c6f 100644
--- a/lib/VMCore/Attributes.cpp
+++ b/lib/VMCore/Attributes.cpp
@@ -17,6 +17,7 @@
#include "llvm/ADT/FoldingSet.h"
#include "llvm/System/Atomic.h"
#include "llvm/System/Mutex.h"
+#include "llvm/Support/Debug.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
@@ -318,11 +319,11 @@ AttrListPtr AttrListPtr::removeAttr(unsigned Idx, Attributes Attrs) const {
}
void AttrListPtr::dump() const {
- errs() << "PAL[ ";
+ dbgs() << "PAL[ ";
for (unsigned i = 0; i < getNumSlots(); ++i) {
const AttributeWithIndex &PAWI = getSlot(i);
- errs() << "{" << PAWI.Index << "," << PAWI.Attrs << "} ";
+ dbgs() << "{" << PAWI.Index << "," << PAWI.Attrs << "} ";
}
- errs() << "]\n";
+ dbgs() << "]\n";
}
diff --git a/lib/VMCore/AutoUpgrade.cpp b/lib/VMCore/AutoUpgrade.cpp
index 77ab19f..2161841 100644
--- a/lib/VMCore/AutoUpgrade.cpp
+++ b/lib/VMCore/AutoUpgrade.cpp
@@ -480,61 +480,42 @@ void llvm::UpgradeCallsToIntrinsic(Function* F) {
}
}
-/// This function checks debug info intrinsics. If an intrinsic is invalid
-/// then this function simply removes the intrinsic.
+/// This function strips all debug info intrinsics, except for llvm.dbg.declare.
+/// If an llvm.dbg.declare intrinsic is invalid, then this function simply
+/// strips that use.
void llvm::CheckDebugInfoIntrinsics(Module *M) {
if (Function *FuncStart = M->getFunction("llvm.dbg.func.start")) {
- if (!FuncStart->use_empty()) {
- DbgFuncStartInst *DFSI = cast<DbgFuncStartInst>(FuncStart->use_back());
- if (!isa<MDNode>(DFSI->getOperand(1))) {
- while (!FuncStart->use_empty()) {
- CallInst *CI = cast<CallInst>(FuncStart->use_back());
- CI->eraseFromParent();
- }
- FuncStart->eraseFromParent();
- }
+ while (!FuncStart->use_empty()) {
+ CallInst *CI = cast<CallInst>(FuncStart->use_back());
+ CI->eraseFromParent();
}
+ FuncStart->eraseFromParent();
}
-
+
if (Function *StopPoint = M->getFunction("llvm.dbg.stoppoint")) {
- if (!StopPoint->use_empty()) {
- DbgStopPointInst *DSPI = cast<DbgStopPointInst>(StopPoint->use_back());
- if (!isa<MDNode>(DSPI->getOperand(3))) {
- while (!StopPoint->use_empty()) {
- CallInst *CI = cast<CallInst>(StopPoint->use_back());
- CI->eraseFromParent();
- }
- StopPoint->eraseFromParent();
- }
+ while (!StopPoint->use_empty()) {
+ CallInst *CI = cast<CallInst>(StopPoint->use_back());
+ CI->eraseFromParent();
}
+ StopPoint->eraseFromParent();
}
if (Function *RegionStart = M->getFunction("llvm.dbg.region.start")) {
- if (!RegionStart->use_empty()) {
- DbgRegionStartInst *DRSI = cast<DbgRegionStartInst>(RegionStart->use_back());
- if (!isa<MDNode>(DRSI->getOperand(1))) {
- while (!RegionStart->use_empty()) {
- CallInst *CI = cast<CallInst>(RegionStart->use_back());
- CI->eraseFromParent();
- }
- RegionStart->eraseFromParent();
- }
+ while (!RegionStart->use_empty()) {
+ CallInst *CI = cast<CallInst>(RegionStart->use_back());
+ CI->eraseFromParent();
}
+ RegionStart->eraseFromParent();
}
if (Function *RegionEnd = M->getFunction("llvm.dbg.region.end")) {
- if (!RegionEnd->use_empty()) {
- DbgRegionEndInst *DREI = cast<DbgRegionEndInst>(RegionEnd->use_back());
- if (!isa<MDNode>(DREI->getOperand(1))) {
- while (!RegionEnd->use_empty()) {
- CallInst *CI = cast<CallInst>(RegionEnd->use_back());
- CI->eraseFromParent();
- }
- RegionEnd->eraseFromParent();
- }
+ while (!RegionEnd->use_empty()) {
+ CallInst *CI = cast<CallInst>(RegionEnd->use_back());
+ CI->eraseFromParent();
}
+ RegionEnd->eraseFromParent();
}
if (Function *Declare = M->getFunction("llvm.dbg.declare")) {
diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp
index 2449739..3a24389 100644
--- a/lib/VMCore/ConstantFold.cpp
+++ b/lib/VMCore/ConstantFold.cpp
@@ -1162,7 +1162,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
}
// i1 can be simplified in many cases.
- if (C1->getType() == Type::getInt1Ty(Context)) {
+ if (C1->getType()->isInteger(1)) {
switch (Opcode) {
case Instruction::Add:
case Instruction::Sub:
@@ -1229,10 +1229,10 @@ static int IdxCompare(LLVMContext &Context, Constant *C1, Constant *C2,
// Ok, we have two differing integer indices. Sign extend them to be the same
// type. Long is always big enough, so we use it.
- if (C1->getType() != Type::getInt64Ty(Context))
+ if (!C1->getType()->isInteger(64))
C1 = ConstantExpr::getSExt(C1, Type::getInt64Ty(Context));
- if (C2->getType() != Type::getInt64Ty(Context))
+ if (!C2->getType()->isInteger(64))
C2 = ConstantExpr::getSExt(C2, Type::getInt64Ty(Context));
if (C1 == C2) return 0; // They are equal
@@ -1587,7 +1587,7 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context,
}
// If the comparison is a comparison between two i1's, simplify it.
- if (C1->getType() == Type::getInt1Ty(Context)) {
+ if (C1->getType()->isInteger(1)) {
switch(pred) {
case ICmpInst::ICMP_EQ:
if (isa<ConstantInt>(C2))
@@ -2042,10 +2042,10 @@ Constant *llvm::ConstantFoldGetElementPtr(LLVMContext &Context,
// Before adding, extend both operands to i64 to avoid
// overflow trouble.
- if (PrevIdx->getType() != Type::getInt64Ty(Context))
+ if (!PrevIdx->getType()->isInteger(64))
PrevIdx = ConstantExpr::getSExt(PrevIdx,
Type::getInt64Ty(Context));
- if (Div->getType() != Type::getInt64Ty(Context))
+ if (!Div->getType()->isInteger(64))
Div = ConstantExpr::getSExt(Div,
Type::getInt64Ty(Context));
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp
index e3c6144..cc8961f 100644
--- a/lib/VMCore/Constants.cpp
+++ b/lib/VMCore/Constants.cpp
@@ -110,7 +110,7 @@ void Constant::destroyConstantImpl() {
Value *V = use_back();
#ifndef NDEBUG // Only in -g mode...
if (!isa<Constant>(V)) {
- errs() << "While deleting: " << *this
+ dbgs() << "While deleting: " << *this
<< "\n\nUse still stuck around after Def is destroyed: "
<< *V << "\n\n";
}
@@ -197,6 +197,24 @@ Constant::PossibleRelocationsTy Constant::getRelocationInfo() const {
if (const BlockAddress *BA = dyn_cast<BlockAddress>(this))
return BA->getFunction()->getRelocationInfo();
+ // While raw uses of blockaddress need to be relocated, differences between
+ // two of them don't when they are for labels in the same function. This is a
+ // common idiom when creating a table for the indirect goto extension, so we
+ // handle it efficiently here.
+ if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(this))
+ if (CE->getOpcode() == Instruction::Sub) {
+ ConstantExpr *LHS = dyn_cast<ConstantExpr>(CE->getOperand(0));
+ ConstantExpr *RHS = dyn_cast<ConstantExpr>(CE->getOperand(1));
+ if (LHS && RHS &&
+ LHS->getOpcode() == Instruction::PtrToInt &&
+ RHS->getOpcode() == Instruction::PtrToInt &&
+ isa<BlockAddress>(LHS->getOperand(0)) &&
+ isa<BlockAddress>(RHS->getOperand(0)) &&
+ cast<BlockAddress>(LHS->getOperand(0))->getFunction() ==
+ cast<BlockAddress>(RHS->getOperand(0))->getFunction())
+ return NoRelocation;
+ }
+
PossibleRelocationsTy Result = NoRelocation;
for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
Result = std::max(Result,
@@ -910,7 +928,7 @@ void ConstantArray::destroyConstant() {
/// if the elements of the array are all ConstantInt's.
bool ConstantArray::isString() const {
// Check the element type for i8...
- if (getType()->getElementType() != Type::getInt8Ty(getContext()))
+ if (!getType()->getElementType()->isInteger(8))
return false;
// Check the elements to make sure they are all integers, not constant
// expressions.
@@ -925,7 +943,7 @@ bool ConstantArray::isString() const {
/// null bytes except its terminator.
bool ConstantArray::isCString() const {
// Check the element type for i8...
- if (getType()->getElementType() != Type::getInt8Ty(getContext()))
+ if (!getType()->getElementType()->isInteger(8))
return false;
// Last element must be a null.
@@ -1671,7 +1689,7 @@ Constant *ConstantExpr::getExtractElementTy(const Type *ReqTy, Constant *Val,
Constant *ConstantExpr::getExtractElement(Constant *Val, Constant *Idx) {
assert(isa<VectorType>(Val->getType()) &&
"Tried to create extractelement operation on non-vector type!");
- assert(Idx->getType() == Type::getInt32Ty(Val->getContext()) &&
+ assert(Idx->getType()->isInteger(32) &&
"Extractelement index must be i32 type!");
return getExtractElementTy(cast<VectorType>(Val->getType())->getElementType(),
Val, Idx);
@@ -1698,7 +1716,7 @@ Constant *ConstantExpr::getInsertElement(Constant *Val, Constant *Elt,
"Tried to create insertelement operation on non-vector type!");
assert(Elt->getType() == cast<VectorType>(Val->getType())->getElementType()
&& "Insertelement types must match!");
- assert(Idx->getType() == Type::getInt32Ty(Val->getContext()) &&
+ assert(Idx->getType()->isInteger(32) &&
"Insertelement index must be i32 type!");
return getInsertElementTy(Val->getType(), Val, Elt, Idx);
}
diff --git a/lib/VMCore/ConstantsContext.h b/lib/VMCore/ConstantsContext.h
index 268a660..08224e4 100644
--- a/lib/VMCore/ConstantsContext.h
+++ b/lib/VMCore/ConstantsContext.h
@@ -764,7 +764,7 @@ public:
}
void dump() const {
- DEBUG(errs() << "Constant.cpp: ConstantUniqueMap\n");
+ DEBUG(dbgs() << "Constant.cpp: ConstantUniqueMap\n");
}
};
diff --git a/lib/VMCore/Core.cpp b/lib/VMCore/Core.cpp
index 449e967..984d245 100644
--- a/lib/VMCore/Core.cpp
+++ b/lib/VMCore/Core.cpp
@@ -89,7 +89,7 @@ void LLVMSetTarget(LLVMModuleRef M, const char *Triple) {
}
/*--.. Type names ..........................................................--*/
-int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty) {
+LLVMBool LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty) {
return unwrap(M)->addTypeName(Name, unwrap(Ty));
}
@@ -237,7 +237,7 @@ LLVMTypeRef LLVMPPCFP128Type(void) {
LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
LLVMTypeRef *ParamTypes, unsigned ParamCount,
- int IsVarArg) {
+ LLVMBool IsVarArg) {
std::vector<const Type*> Tys;
for (LLVMTypeRef *I = ParamTypes, *E = ParamTypes + ParamCount; I != E; ++I)
Tys.push_back(unwrap(*I));
@@ -245,7 +245,7 @@ LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
return wrap(FunctionType::get(unwrap(ReturnType), Tys, IsVarArg != 0));
}
-int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy) {
+LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy) {
return unwrap<FunctionType>(FunctionTy)->isVarArg();
}
@@ -267,7 +267,7 @@ void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest) {
/*--.. Operations on struct types ..........................................--*/
LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
- unsigned ElementCount, int Packed) {
+ unsigned ElementCount, LLVMBool Packed) {
std::vector<const Type*> Tys;
for (LLVMTypeRef *I = ElementTypes,
*E = ElementTypes + ElementCount; I != E; ++I)
@@ -277,7 +277,7 @@ LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
}
LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes,
- unsigned ElementCount, int Packed) {
+ unsigned ElementCount, LLVMBool Packed) {
return LLVMStructTypeInContext(LLVMGetGlobalContext(), ElementTypes,
ElementCount, Packed);
}
@@ -294,7 +294,7 @@ void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest) {
*Dest++ = wrap(*I);
}
-int LLVMIsPackedStruct(LLVMTypeRef StructTy) {
+LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy) {
return unwrap<StructType>(StructTy)->isPacked();
}
@@ -442,17 +442,17 @@ LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty) {
return wrap(UndefValue::get(unwrap(Ty)));
}
-int LLVMIsConstant(LLVMValueRef Ty) {
+LLVMBool LLVMIsConstant(LLVMValueRef Ty) {
return isa<Constant>(unwrap(Ty));
}
-int LLVMIsNull(LLVMValueRef Val) {
+LLVMBool LLVMIsNull(LLVMValueRef Val) {
if (Constant *C = dyn_cast<Constant>(unwrap(Val)))
return C->isNullValue();
return false;
}
-int LLVMIsUndef(LLVMValueRef Val) {
+LLVMBool LLVMIsUndef(LLVMValueRef Val) {
return isa<UndefValue>(unwrap(Val));
}
@@ -464,7 +464,7 @@ LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty) {
/*--.. Operations on scalar constants ......................................--*/
LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
- int SignExtend) {
+ LLVMBool SignExtend) {
return wrap(ConstantInt::get(unwrap<IntegerType>(IntTy), N, SignExtend != 0));
}
@@ -504,7 +504,8 @@ long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal) {
/*--.. Operations on composite constants ...................................--*/
LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
- unsigned Length, int DontNullTerminate) {
+ unsigned Length,
+ LLVMBool DontNullTerminate) {
/* Inverted the sense of AddNull because ', 0)' is a
better mnemonic for null termination than ', 1)'. */
return wrap(ConstantArray::get(*unwrap(C), std::string(Str, Length),
@@ -512,14 +513,14 @@ LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
}
LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
LLVMValueRef *ConstantVals,
- unsigned Count, int Packed) {
+ unsigned Count, LLVMBool Packed) {
return wrap(ConstantStruct::get(*unwrap(C),
unwrap<Constant>(ConstantVals, Count),
Count, Packed != 0));
}
LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
- int DontNullTerminate) {
+ LLVMBool DontNullTerminate) {
return LLVMConstStringInContext(LLVMGetGlobalContext(), Str, Length,
DontNullTerminate);
}
@@ -530,7 +531,7 @@ LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
Length));
}
LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
- int Packed) {
+ LLVMBool Packed) {
return LLVMConstStructInContext(LLVMGetGlobalContext(), ConstantVals, Count,
Packed);
}
@@ -820,7 +821,7 @@ LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
}
LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
- unsigned isSigned) {
+ LLVMBool isSigned) {
return wrap(ConstantExpr::getIntegerCast(
unwrap<Constant>(ConstantVal),
unwrap(ToType),
@@ -883,10 +884,11 @@ LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
IdxList, NumIdx));
}
-LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty, const char *AsmString,
- const char *Constraints, int HasSideEffects,
- int IsAlignStack) {
- return wrap(InlineAsm::get(dyn_cast<FunctionType>(unwrap(Ty)), AsmString,
+LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty, const char *AsmString,
+ const char *Constraints,
+ LLVMBool HasSideEffects,
+ LLVMBool IsAlignStack) {
+ return wrap(InlineAsm::get(dyn_cast<FunctionType>(unwrap(Ty)), AsmString,
Constraints, HasSideEffects, IsAlignStack));
}
@@ -896,7 +898,7 @@ LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global) {
return wrap(unwrap<GlobalValue>(Global)->getParent());
}
-int LLVMIsDeclaration(LLVMValueRef Global) {
+LLVMBool LLVMIsDeclaration(LLVMValueRef Global) {
return unwrap<GlobalValue>(Global)->isDeclaration();
}
@@ -1079,19 +1081,19 @@ void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal) {
->setInitializer(unwrap<Constant>(ConstantVal));
}
-int LLVMIsThreadLocal(LLVMValueRef GlobalVar) {
+LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar) {
return unwrap<GlobalVariable>(GlobalVar)->isThreadLocal();
}
-void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal) {
+void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal) {
unwrap<GlobalVariable>(GlobalVar)->setThreadLocal(IsThreadLocal != 0);
}
-int LLVMIsGlobalConstant(LLVMValueRef GlobalVar) {
+LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar) {
return unwrap<GlobalVariable>(GlobalVar)->isConstant();
}
-void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, int IsConstant) {
+void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant) {
unwrap<GlobalVariable>(GlobalVar)->setConstant(IsConstant != 0);
}
@@ -1285,7 +1287,7 @@ LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB) {
return wrap(static_cast<Value*>(unwrap(BB)));
}
-int LLVMValueIsBasicBlock(LLVMValueRef Val) {
+LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val) {
return isa<BasicBlock>(unwrap(Val));
}
@@ -1452,11 +1454,11 @@ void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
/*--.. Operations on call instructions (only) ..............................--*/
-int LLVMIsTailCall(LLVMValueRef Call) {
+LLVMBool LLVMIsTailCall(LLVMValueRef Call) {
return unwrap<CallInst>(Call)->isTailCall();
}
-void LLVMSetTailCall(LLVMValueRef Call, int isTailCall) {
+void LLVMSetTailCall(LLVMValueRef Call, LLVMBool isTailCall) {
unwrap<CallInst>(Call)->setTailCall(isTailCall);
}
@@ -1973,9 +1975,11 @@ void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP) {
/*===-- Memory buffers ----------------------------------------------------===*/
-int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
- LLVMMemoryBufferRef *OutMemBuf,
- char **OutMessage) {
+LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(
+ const char *Path,
+ LLVMMemoryBufferRef *OutMemBuf,
+ char **OutMessage) {
+
std::string Error;
if (MemoryBuffer *MB = MemoryBuffer::getFile(Path, &Error)) {
*OutMemBuf = wrap(MB);
@@ -1986,8 +1990,8 @@ int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
return 1;
}
-int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
- char **OutMessage) {
+LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
+ char **OutMessage) {
MemoryBuffer *MB = MemoryBuffer::getSTDIN();
if (!MB->getBufferSize()) {
delete MB;
diff --git a/lib/VMCore/Function.cpp b/lib/VMCore/Function.cpp
index e04b6d6..f00f6ee 100644
--- a/lib/VMCore/Function.cpp
+++ b/lib/VMCore/Function.cpp
@@ -189,7 +189,7 @@ void Function::BuildLazyArguments() const {
// Create the arguments vector, all arguments start out unnamed.
const FunctionType *FT = getFunctionType();
for (unsigned i = 0, e = FT->getNumParams(); i != e; ++i) {
- assert(FT->getParamType(i) != Type::getVoidTy(FT->getContext()) &&
+ assert(!FT->getParamType(i)->isVoidTy() &&
"Cannot have void typed arguments!");
ArgumentList.push_back(new Argument(FT->getParamType(i)));
}
diff --git a/lib/VMCore/InlineAsm.cpp b/lib/VMCore/InlineAsm.cpp
index 16de1af..ec21773 100644
--- a/lib/VMCore/InlineAsm.cpp
+++ b/lib/VMCore/InlineAsm.cpp
@@ -217,7 +217,7 @@ bool InlineAsm::Verify(const FunctionType *Ty, StringRef ConstStr) {
switch (NumOutputs) {
case 0:
- if (Ty->getReturnType() != Type::getVoidTy(Ty->getContext())) return false;
+ if (!Ty->getReturnType()->isVoidTy()) return false;
break;
case 1:
if (isa<StructType>(Ty->getReturnType())) return false;
diff --git a/lib/VMCore/Instruction.cpp b/lib/VMCore/Instruction.cpp
index a5500e6..3fabfd0 100644
--- a/lib/VMCore/Instruction.cpp
+++ b/lib/VMCore/Instruction.cpp
@@ -374,37 +374,6 @@ bool Instruction::isCommutative(unsigned op) {
}
}
-// Code here matches isMalloc from MemoryBuiltins, which is not in VMCore.
-static bool isMalloc(const Value* I) {
- const CallInst *CI = dyn_cast<CallInst>(I);
- if (!CI) {
- const BitCastInst *BCI = dyn_cast<BitCastInst>(I);
- if (!BCI) return false;
-
- CI = dyn_cast<CallInst>(BCI->getOperand(0));
- }
-
- if (!CI)
- return false;
- Function *Callee = CI->getCalledFunction();
- if (Callee == 0 || !Callee->isDeclaration() || Callee->getName() != "malloc")
- return false;
-
- // Check malloc prototype.
- // FIXME: workaround for PR5130, this will be obsolete when a nobuiltin
- // attribute will exist.
- const FunctionType *FTy = Callee->getFunctionType();
- if (FTy->getNumParams() != 1)
- return false;
- if (IntegerType *ITy = dyn_cast<IntegerType>(FTy->param_begin()->get())) {
- if (ITy->getBitWidth() != 32 && ITy->getBitWidth() != 64)
- return false;
- return true;
- }
-
- return false;
-}
-
bool Instruction::isSafeToSpeculativelyExecute() const {
for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
if (Constant *C = dyn_cast<Constant>(getOperand(i)))
@@ -430,7 +399,9 @@ bool Instruction::isSafeToSpeculativelyExecute() const {
case Load: {
if (cast<LoadInst>(this)->isVolatile())
return false;
- if (isa<AllocaInst>(getOperand(0)) || isMalloc(getOperand(0)))
+ // Note that it is not safe to speculate into a malloc'd region because
+ // malloc may return null.
+ if (isa<AllocaInst>(getOperand(0)))
return true;
if (GlobalVariable *GV = dyn_cast<GlobalVariable>(getOperand(0)))
return !GV->hasExternalWeakLinkage();
diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp
index 3e9950e..2619047 100644
--- a/lib/VMCore/Instructions.cpp
+++ b/lib/VMCore/Instructions.cpp
@@ -523,8 +523,7 @@ static Instruction *createMalloc(Instruction *InsertBefore,
MCall->setCallingConv(F->getCallingConv());
if (!F->doesNotAlias(0)) F->setDoesNotAlias(0);
}
- assert(MCall->getType() != Type::getVoidTy(BB->getContext()) &&
- "Malloc has void return type");
+ assert(!MCall->getType()->isVoidTy() && "Malloc has void return type");
return Result;
}
@@ -788,7 +787,7 @@ BasicBlock *UnreachableInst::getSuccessorV(unsigned idx) const {
void BranchInst::AssertOK() {
if (isConditional())
- assert(getCondition()->getType() == Type::getInt1Ty(getContext()) &&
+ assert(getCondition()->getType()->isInteger(1) &&
"May only branch on boolean predicates!");
}
@@ -893,7 +892,7 @@ static Value *getAISize(LLVMContext &Context, Value *Amt) {
else {
assert(!isa<BasicBlock>(Amt) &&
"Passed basic block into allocation size parameter! Use other ctor");
- assert(Amt->getType() == Type::getInt32Ty(Context) &&
+ assert(Amt->getType()->isInteger(32) &&
"Allocation array size is not a 32-bit integer!");
}
return Amt;
@@ -904,7 +903,7 @@ AllocaInst::AllocaInst(const Type *Ty, Value *ArraySize,
: UnaryInstruction(PointerType::getUnqual(Ty), Alloca,
getAISize(Ty->getContext(), ArraySize), InsertBefore) {
setAlignment(0);
- assert(Ty != Type::getVoidTy(Ty->getContext()) && "Cannot allocate void!");
+ assert(!Ty->isVoidTy() && "Cannot allocate void!");
setName(Name);
}
@@ -913,7 +912,7 @@ AllocaInst::AllocaInst(const Type *Ty, Value *ArraySize,
: UnaryInstruction(PointerType::getUnqual(Ty), Alloca,
getAISize(Ty->getContext(), ArraySize), InsertAtEnd) {
setAlignment(0);
- assert(Ty != Type::getVoidTy(Ty->getContext()) && "Cannot allocate void!");
+ assert(!Ty->isVoidTy() && "Cannot allocate void!");
setName(Name);
}
@@ -922,7 +921,7 @@ AllocaInst::AllocaInst(const Type *Ty, const Twine &Name,
: UnaryInstruction(PointerType::getUnqual(Ty), Alloca,
getAISize(Ty->getContext(), 0), InsertBefore) {
setAlignment(0);
- assert(Ty != Type::getVoidTy(Ty->getContext()) && "Cannot allocate void!");
+ assert(!Ty->isVoidTy() && "Cannot allocate void!");
setName(Name);
}
@@ -931,7 +930,7 @@ AllocaInst::AllocaInst(const Type *Ty, const Twine &Name,
: UnaryInstruction(PointerType::getUnqual(Ty), Alloca,
getAISize(Ty->getContext(), 0), InsertAtEnd) {
setAlignment(0);
- assert(Ty != Type::getVoidTy(Ty->getContext()) && "Cannot allocate void!");
+ assert(!Ty->isVoidTy() && "Cannot allocate void!");
setName(Name);
}
@@ -940,7 +939,7 @@ AllocaInst::AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
: UnaryInstruction(PointerType::getUnqual(Ty), Alloca,
getAISize(Ty->getContext(), ArraySize), InsertBefore) {
setAlignment(Align);
- assert(Ty != Type::getVoidTy(Ty->getContext()) && "Cannot allocate void!");
+ assert(!Ty->isVoidTy() && "Cannot allocate void!");
setName(Name);
}
@@ -949,7 +948,7 @@ AllocaInst::AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
: UnaryInstruction(PointerType::getUnqual(Ty), Alloca,
getAISize(Ty->getContext(), ArraySize), InsertAtEnd) {
setAlignment(Align);
- assert(Ty != Type::getVoidTy(Ty->getContext()) && "Cannot allocate void!");
+ assert(!Ty->isVoidTy() && "Cannot allocate void!");
setName(Name);
}
@@ -1392,8 +1391,7 @@ ExtractElementInst::ExtractElementInst(Value *Val, Value *Index,
bool ExtractElementInst::isValidOperands(const Value *Val, const Value *Index) {
- if (!isa<VectorType>(Val->getType()) ||
- Index->getType() != Type::getInt32Ty(Val->getContext()))
+ if (!isa<VectorType>(Val->getType()) || !Index->getType()->isInteger(32))
return false;
return true;
}
@@ -1440,7 +1438,7 @@ bool InsertElementInst::isValidOperands(const Value *Vec, const Value *Elt,
if (Elt->getType() != cast<VectorType>(Vec->getType())->getElementType())
return false;// Second operand of insertelement must be vector element type.
- if (Index->getType() != Type::getInt32Ty(Vec->getContext()))
+ if (!Index->getType()->isInteger(32))
return false; // Third operand of insertelement must be i32.
return true;
}
@@ -1492,7 +1490,7 @@ bool ShuffleVectorInst::isValidOperands(const Value *V1, const Value *V2,
const VectorType *MaskTy = dyn_cast<VectorType>(Mask->getType());
if (!isa<Constant>(Mask) || MaskTy == 0 ||
- MaskTy->getElementType() != Type::getInt32Ty(V1->getContext()))
+ !MaskTy->getElementType()->isInteger(32))
return false;
return true;
}
@@ -2287,7 +2285,8 @@ CastInst *CastInst::CreatePointerCast(Value *S, const Type *Ty,
CastInst *CastInst::CreateIntegerCast(Value *C, const Type *Ty,
bool isSigned, const Twine &Name,
Instruction *InsertBefore) {
- assert(C->getType()->isInteger() && Ty->isInteger() && "Invalid cast");
+ assert(C->getType()->isIntOrIntVector() && Ty->isIntOrIntVector() &&
+ "Invalid integer cast");
unsigned SrcBits = C->getType()->getScalarSizeInBits();
unsigned DstBits = Ty->getScalarSizeInBits();
Instruction::CastOps opcode =
diff --git a/lib/VMCore/IntrinsicInst.cpp b/lib/VMCore/IntrinsicInst.cpp
index 5e0f42e..cb9252e 100644
--- a/lib/VMCore/IntrinsicInst.cpp
+++ b/lib/VMCore/IntrinsicInst.cpp
@@ -8,11 +8,7 @@
//===----------------------------------------------------------------------===//
//
// This file implements methods that make it really easy to deal with intrinsic
-// functions with the isa/dyncast family of functions. In particular, this
-// allows you to do things like:
-//
-// if (DbgStopPointInst *SPI = dyn_cast<DbgStopPointInst>(Inst))
-// ... SPI->getFileName() ... SPI->getDirectory() ...
+// functions.
//
// All intrinsic function calls are instances of the call instruction, so these
// are all subclasses of the CallInst class. Note that none of these classes
@@ -55,25 +51,13 @@ Value *DbgInfoIntrinsic::StripCast(Value *C) {
}
//===----------------------------------------------------------------------===//
-/// DbgStopPointInst - This represents the llvm.dbg.stoppoint instruction.
+/// DbgValueInst - This represents the llvm.dbg.value instruction.
///
-Value *DbgStopPointInst::getFileName() const {
- // Once the operand indices are verified, update this assert
- assert(LLVMDebugVersion == (7 << 16) && "Verify operand indices");
- return getContext()->getOperand(3);
-}
-
-Value *DbgStopPointInst::getDirectory() const {
- // Once the operand indices are verified, update this assert
- assert(LLVMDebugVersion == (7 << 16) && "Verify operand indices");
- return getContext()->getOperand(4);
+const Value *DbgValueInst::getValue() const {
+ return cast<MDNode>(getOperand(1))->getOperand(0);
}
-//===----------------------------------------------------------------------===//
-/// DbgValueInst - This represents the llvm.dbg.value instruction.
-///
-
-Value *DbgValueInst::getValue() const {
+Value *DbgValueInst::getValue() {
return cast<MDNode>(getOperand(1))->getOperand(0);
}
diff --git a/lib/VMCore/Mangler.cpp b/lib/VMCore/Mangler.cpp
index 33eb044..7d9f330 100644
--- a/lib/VMCore/Mangler.cpp
+++ b/lib/VMCore/Mangler.cpp
@@ -16,7 +16,7 @@
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringMap.h"
-#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/SmallString.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
@@ -24,57 +24,57 @@ static char HexDigit(int V) {
return V < 10 ? V+'0' : V+'A'-10;
}
-static std::string MangleLetter(unsigned char C) {
- char Result[] = { '_', HexDigit(C >> 4), HexDigit(C & 15), '_', 0 };
- return Result;
+static void MangleLetter(SmallVectorImpl<char> &OutName, unsigned char C) {
+ OutName.push_back('_');
+ OutName.push_back(HexDigit(C >> 4));
+ OutName.push_back(HexDigit(C & 15));
+ OutName.push_back('_');
}
/// makeNameProper - We don't want identifier names non-C-identifier characters
/// in them, so mangle them as appropriate.
///
-std::string Mangler::makeNameProper(const std::string &X,
- ManglerPrefixTy PrefixTy) {
+/// FIXME: This is deprecated, new code should use getNameWithPrefix and use
+/// MCSymbol printing to handle quotes or not etc.
+///
+void Mangler::makeNameProper(SmallVectorImpl<char> &OutName,
+ const Twine &TheName,
+ ManglerPrefixTy PrefixTy) {
+ SmallString<256> TmpData;
+ StringRef X = TheName.toStringRef(TmpData);
assert(!X.empty() && "Cannot mangle empty strings");
if (!UseQuotes) {
- std::string Result;
-
// If X does not start with (char)1, add the prefix.
- bool NeedPrefix = true;
- std::string::const_iterator I = X.begin();
+ StringRef::iterator I = X.begin();
if (*I == 1) {
- NeedPrefix = false;
- ++I; // Skip over the marker.
+ ++I; // Skip over the no-prefix marker.
+ } else {
+ if (PrefixTy == Mangler::Private)
+ OutName.append(PrivatePrefix, PrivatePrefix+strlen(PrivatePrefix));
+ else if (PrefixTy == Mangler::LinkerPrivate)
+ OutName.append(LinkerPrivatePrefix,
+ LinkerPrivatePrefix+strlen(LinkerPrivatePrefix));
+ OutName.append(Prefix, Prefix+strlen(Prefix));
}
// Mangle the first letter specially, don't allow numbers unless the target
// explicitly allows them.
if (!SymbolsCanStartWithDigit && *I >= '0' && *I <= '9')
- Result += MangleLetter(*I++);
+ MangleLetter(OutName, *I++);
- for (std::string::const_iterator E = X.end(); I != E; ++I) {
+ for (StringRef::iterator E = X.end(); I != E; ++I) {
if (!isCharAcceptable(*I))
- Result += MangleLetter(*I);
+ MangleLetter(OutName, *I);
else
- Result += *I;
- }
-
- if (NeedPrefix) {
- Result = Prefix + Result;
-
- if (PrefixTy == Mangler::Private)
- Result = PrivatePrefix + Result;
- else if (PrefixTy == Mangler::LinkerPrivate)
- Result = LinkerPrivatePrefix + Result;
+ OutName.push_back(*I);
}
-
- return Result;
+ return;
}
bool NeedPrefix = true;
bool NeedQuotes = false;
- std::string Result;
- std::string::const_iterator I = X.begin();
+ StringRef::iterator I = X.begin();
if (*I == 1) {
NeedPrefix = false;
++I; // Skip over the marker.
@@ -87,7 +87,7 @@ std::string Mangler::makeNameProper(const std::string &X,
// Do an initial scan of the string, checking to see if we need quotes or
// to escape a '"' or not.
if (!NeedQuotes)
- for (std::string::const_iterator E = X.end(); I != E; ++I)
+ for (StringRef::iterator E = X.end(); I != E; ++I)
if (!isCharAcceptable(*I)) {
NeedQuotes = true;
break;
@@ -95,43 +95,57 @@ std::string Mangler::makeNameProper(const std::string &X,
// In the common case, we don't need quotes. Handle this quickly.
if (!NeedQuotes) {
- if (!NeedPrefix)
- return X.substr(1); // Strip off the \001.
-
- Result = Prefix + X;
+ if (!NeedPrefix) {
+ OutName.append(X.begin()+1, X.end()); // Strip off the \001.
+ return;
+ }
if (PrefixTy == Mangler::Private)
- Result = PrivatePrefix + Result;
+ OutName.append(PrivatePrefix, PrivatePrefix+strlen(PrivatePrefix));
else if (PrefixTy == Mangler::LinkerPrivate)
- Result = LinkerPrivatePrefix + Result;
-
- return Result;
- }
-
- if (NeedPrefix)
- Result = X.substr(0, I-X.begin());
+ OutName.append(LinkerPrivatePrefix,
+ LinkerPrivatePrefix+strlen(LinkerPrivatePrefix));
- // Otherwise, construct the string the expensive way.
- for (std::string::const_iterator E = X.end(); I != E; ++I) {
- if (*I == '"')
- Result += "_QQ_";
- else if (*I == '\n')
- Result += "_NL_";
+ if (Prefix[0] == 0)
+ ; // Common noop, no prefix.
+ else if (Prefix[1] == 0)
+ OutName.push_back(Prefix[0]); // Common, one character prefix.
else
- Result += *I;
+ OutName.append(Prefix, Prefix+strlen(Prefix)); // Arbitrary prefix.
+ OutName.append(X.begin(), X.end());
+ return;
}
+ // Add leading quote.
+ OutName.push_back('"');
+
+ // Add prefixes unless disabled.
if (NeedPrefix) {
- Result = Prefix + Result;
-
if (PrefixTy == Mangler::Private)
- Result = PrivatePrefix + Result;
+ OutName.append(PrivatePrefix, PrivatePrefix+strlen(PrivatePrefix));
else if (PrefixTy == Mangler::LinkerPrivate)
- Result = LinkerPrivatePrefix + Result;
+ OutName.append(LinkerPrivatePrefix,
+ LinkerPrivatePrefix+strlen(LinkerPrivatePrefix));
+ OutName.append(Prefix, Prefix+strlen(Prefix));
+ }
+
+ // Add the piece that we already scanned through.
+ OutName.append(X.begin()+!NeedPrefix, I);
+
+ // Otherwise, construct the string the expensive way.
+ for (StringRef::iterator E = X.end(); I != E; ++I) {
+ if (*I == '"') {
+ const char *Quote = "_QQ_";
+ OutName.append(Quote, Quote+4);
+ } else if (*I == '\n') {
+ const char *Newline = "_NL_";
+ OutName.append(Newline, Newline+4);
+ } else
+ OutName.push_back(*I);
}
- Result = '"' + Result + '"';
- return Result;
+ // Add trailing quote.
+ OutName.push_back('"');
}
/// getMangledName - Returns the mangled name of V, an LLVM Value,
@@ -139,6 +153,9 @@ std::string Mangler::makeNameProper(const std::string &X,
/// specified suffix. If 'ForcePrivate' is specified, the label is specified
/// to have a private label prefix.
///
+/// FIXME: This is deprecated, new code should use getNameWithPrefix and use
+/// MCSymbol printing to handle quotes or not etc.
+///
std::string Mangler::getMangledName(const GlobalValue *GV, const char *Suffix,
bool ForcePrivate) {
assert((!isa<Function>(GV) || !cast<Function>(GV)->isIntrinsic()) &&
@@ -148,8 +165,11 @@ std::string Mangler::getMangledName(const GlobalValue *GV, const char *Suffix,
(GV->hasPrivateLinkage() || ForcePrivate) ? Mangler::Private :
GV->hasLinkerPrivateLinkage() ? Mangler::LinkerPrivate : Mangler::Default;
- if (GV->hasName())
- return makeNameProper(GV->getNameStr() + Suffix, PrefixTy);
+ SmallString<128> Result;
+ if (GV->hasName()) {
+ makeNameProper(Result, GV->getNameStr() + Suffix, PrefixTy);
+ return Result.str().str();
+ }
// Get the ID for the global, assigning a new one if we haven't got one
// already.
@@ -157,7 +177,38 @@ std::string Mangler::getMangledName(const GlobalValue *GV, const char *Suffix,
if (ID == 0) ID = NextAnonGlobalID++;
// Must mangle the global into a unique ID.
- return makeNameProper("__unnamed_" + utostr(ID) + Suffix, PrefixTy);
+ makeNameProper(Result, "__unnamed_" + utostr(ID) + Suffix, PrefixTy);
+ return Result.str().str();
+}
+
+/// getNameWithPrefix - Fill OutName with the name of the appropriate prefix
+/// and the specified name as the global variable name. GVName must not be
+/// empty.
+void Mangler::getNameWithPrefix(SmallVectorImpl<char> &OutName,
+ const Twine &GVName, ManglerPrefixTy PrefixTy) {
+ SmallString<256> TmpData;
+ StringRef Name = GVName.toStringRef(TmpData);
+ assert(!Name.empty() && "getNameWithPrefix requires non-empty name");
+
+ // If the global name is not led with \1, add the appropriate prefixes.
+ if (Name[0] != '\1') {
+ if (PrefixTy == Mangler::Private)
+ OutName.append(PrivatePrefix, PrivatePrefix+strlen(PrivatePrefix));
+ else if (PrefixTy == Mangler::LinkerPrivate)
+ OutName.append(LinkerPrivatePrefix,
+ LinkerPrivatePrefix+strlen(LinkerPrivatePrefix));
+
+ if (Prefix[0] == 0)
+ ; // Common noop, no prefix.
+ else if (Prefix[1] == 0)
+ OutName.push_back(Prefix[0]); // Common, one character prefix.
+ else
+ OutName.append(Prefix, Prefix+strlen(Prefix)); // Arbitrary prefix.
+ } else {
+ Name = Name.substr(1);
+ }
+
+ OutName.append(Name.begin(), Name.end());
}
@@ -167,33 +218,28 @@ std::string Mangler::getMangledName(const GlobalValue *GV, const char *Suffix,
void Mangler::getNameWithPrefix(SmallVectorImpl<char> &OutName,
const GlobalValue *GV,
bool isImplicitlyPrivate) {
-
- // If the global is anonymous or not led with \1, then add the appropriate
- // prefix.
- if (!GV->hasName() || GV->getName()[0] != '\1') {
+ // If this global has a name, handle it simply.
+ if (GV->hasName()) {
+ ManglerPrefixTy PrefixTy = Mangler::Default;
if (GV->hasPrivateLinkage() || isImplicitlyPrivate)
- OutName.append(PrivatePrefix, PrivatePrefix+strlen(PrivatePrefix));
+ PrefixTy = Mangler::Private;
else if (GV->hasLinkerPrivateLinkage())
- OutName.append(LinkerPrivatePrefix,
- LinkerPrivatePrefix+strlen(LinkerPrivatePrefix));;
- OutName.append(Prefix, Prefix+strlen(Prefix));
- }
-
- // If the global has a name, just append it now.
- if (GV->hasName()) {
- StringRef Name = GV->getName();
+ PrefixTy = Mangler::LinkerPrivate;
- // Strip off the prefix marker if present.
- if (Name[0] != '\1')
- OutName.append(Name.begin(), Name.end());
- else
- OutName.append(Name.begin()+1, Name.end());
- return;
+ return getNameWithPrefix(OutName, GV->getName(), PrefixTy);
}
// If the global variable doesn't have a name, return a unique name for the
// global based on a numbering.
+ // Anonymous names always get prefixes.
+ if (GV->hasPrivateLinkage() || isImplicitlyPrivate)
+ OutName.append(PrivatePrefix, PrivatePrefix+strlen(PrivatePrefix));
+ else if (GV->hasLinkerPrivateLinkage())
+ OutName.append(LinkerPrivatePrefix,
+ LinkerPrivatePrefix+strlen(LinkerPrivatePrefix));;
+ OutName.append(Prefix, Prefix+strlen(Prefix));
+
// Get the ID for the global, assigning a new one if we haven't got one
// already.
unsigned &ID = AnonGlobalIDs[GV];
diff --git a/lib/VMCore/Metadata.cpp b/lib/VMCore/Metadata.cpp
index 8e9aab9..7988b44 100644
--- a/lib/VMCore/Metadata.cpp
+++ b/lib/VMCore/Metadata.cpp
@@ -18,6 +18,7 @@
#include "llvm/Instruction.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/StringMap.h"
+#include "llvm/ADT/SmallString.h"
#include "SymbolTableListTraitsImpl.h"
#include "llvm/Support/ValueHandle.h"
using namespace llvm;
@@ -31,7 +32,7 @@ MDString::MDString(LLVMContext &C, StringRef S)
MDString *MDString::get(LLVMContext &Context, StringRef Str) {
LLVMContextImpl *pImpl = Context.pImpl;
- StringMapEntry<MDString *> &Entry =
+ StringMapEntry<MDString *> &Entry =
pImpl->MDStringCache.GetOrCreateValue(Str);
MDString *&S = Entry.getValue();
if (!S) S = new MDString(Context, Entry.getKey());
@@ -40,7 +41,7 @@ MDString *MDString::get(LLVMContext &Context, StringRef Str) {
MDString *MDString::get(LLVMContext &Context, const char *Str) {
LLVMContextImpl *pImpl = Context.pImpl;
- StringMapEntry<MDString *> &Entry =
+ StringMapEntry<MDString *> &Entry =
pImpl->MDStringCache.GetOrCreateValue(Str ? StringRef(Str) : StringRef());
MDString *&S = Entry.getValue();
if (!S) S = new MDString(Context, Entry.getKey());
@@ -58,11 +59,11 @@ class MDNodeOperand : public CallbackVH {
public:
MDNodeOperand(Value *V, MDNode *P) : CallbackVH(V), Parent(P) {}
~MDNodeOperand() {}
-
+
void set(Value *V) {
setValPtr(V);
}
-
+
virtual void deleted();
virtual void allUsesReplacedWith(Value *NV);
};
@@ -94,7 +95,7 @@ MDNode::MDNode(LLVMContext &C, Value *const *Vals, unsigned NumVals,
bool isFunctionLocal)
: MetadataBase(Type::getMetadataTy(C), Value::MDNodeVal) {
NumOperands = NumVals;
-
+
if (isFunctionLocal)
setValueSubclassData(getSubclassDataFromValue() | FunctionLocalBit);
@@ -107,19 +108,82 @@ MDNode::MDNode(LLVMContext &C, Value *const *Vals, unsigned NumVals,
/// ~MDNode - Destroy MDNode.
MDNode::~MDNode() {
- assert((getSubclassDataFromValue() & DestroyFlag) != 0 &&
+ assert((getSubclassDataFromValue() & DestroyFlag) != 0 &&
"Not being destroyed through destroy()?");
if (!isNotUniqued()) {
LLVMContextImpl *pImpl = getType()->getContext().pImpl;
pImpl->MDNodeSet.RemoveNode(this);
}
-
+
// Destroy the operands.
for (MDNodeOperand *Op = getOperandPtr(this, 0), *E = Op+NumOperands;
Op != E; ++Op)
Op->~MDNodeOperand();
}
+#ifndef NDEBUG
+static Function *assertLocalFunction(const MDNode *N,
+ SmallPtrSet<const MDNode *, 32> &Visited) {
+ Function *F = NULL;
+ // Only visit each MDNode once.
+ if (!Visited.insert(N)) return F;
+
+ for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
+ Value *V = N->getOperand(i);
+ Function *NewF = NULL;
+ if (!V) continue;
+ if (Instruction *I = dyn_cast<Instruction>(V))
+ NewF = I->getParent()->getParent();
+ else if (BasicBlock *BB = dyn_cast<BasicBlock>(V))
+ NewF = BB->getParent();
+ else if (Argument *A = dyn_cast<Argument>(V))
+ NewF = A->getParent();
+ else if (MDNode *MD = dyn_cast<MDNode>(V))
+ if (MD->isFunctionLocal())
+ NewF = assertLocalFunction(MD, Visited);
+ if (F && NewF) assert(F == NewF && "inconsistent function-local metadata");
+ if (!F) F = NewF;
+ }
+ return F;
+}
+#endif
+
+static Function *getFunctionHelper(const MDNode *N,
+ SmallPtrSet<const MDNode *, 32> &Visited) {
+ assert(N->isFunctionLocal() && "Should only be called on function-local MD");
+#ifndef NDEBUG
+ return assertLocalFunction(N, Visited);
+#endif
+ Function *F = NULL;
+ // Only visit each MDNode once.
+ if (!Visited.insert(N)) return F;
+
+ for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
+ Value *V = N->getOperand(i);
+ if (!V) continue;
+ if (Instruction *I = dyn_cast<Instruction>(V))
+ F = I->getParent()->getParent();
+ else if (BasicBlock *BB = dyn_cast<BasicBlock>(V))
+ F = BB->getParent();
+ else if (Argument *A = dyn_cast<Argument>(V))
+ F = A->getParent();
+ else if (MDNode *MD = dyn_cast<MDNode>(V))
+ if (MD->isFunctionLocal())
+ F = getFunctionHelper(MD, Visited);
+ if (F) break;
+ }
+ return F;
+}
+
+// getFunction - If this metadata is function-local and recursively has a
+// function-local operand, return the first such operand's parent function.
+// Otherwise, return null.
+Function *MDNode::getFunction() const {
+ if (!isFunctionLocal()) return NULL;
+ SmallPtrSet<const MDNode *, 32> Visited;
+ return getFunctionHelper(this, Visited);
+}
+
// destroy - Delete this node. Only when there are no uses.
void MDNode::destroy() {
setValueSubclassData(getSubclassDataFromValue() | DestroyFlag);
@@ -128,9 +192,8 @@ void MDNode::destroy() {
free(this);
}
-
-MDNode *MDNode::get(LLVMContext &Context, Value*const* Vals, unsigned NumVals,
- bool isFunctionLocal) {
+MDNode *MDNode::getMDNode(LLVMContext &Context, Value *const *Vals,
+ unsigned NumVals, FunctionLocalness FL) {
LLVMContextImpl *pImpl = Context.pImpl;
FoldingSetNodeID ID;
for (unsigned i = 0; i != NumVals; ++i)
@@ -139,16 +202,46 @@ MDNode *MDNode::get(LLVMContext &Context, Value*const* Vals, unsigned NumVals,
void *InsertPoint;
MDNode *N = pImpl->MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint);
if (!N) {
+ bool isFunctionLocal = false;
+ switch (FL) {
+ case FL_Unknown:
+ for (unsigned i = 0; i != NumVals; ++i) {
+ Value *V = Vals[i];
+ if (!V) continue;
+ if (isa<Instruction>(V) || isa<Argument>(V) || isa<BasicBlock>(V) ||
+ (isa<MDNode>(V) && cast<MDNode>(V)->isFunctionLocal())) {
+ isFunctionLocal = true;
+ break;
+ }
+ }
+ break;
+ case FL_No:
+ isFunctionLocal = false;
+ break;
+ case FL_Yes:
+ isFunctionLocal = true;
+ break;
+ }
+
// Coallocate space for the node and Operands together, then placement new.
void *Ptr = malloc(sizeof(MDNode)+NumVals*sizeof(MDNodeOperand));
N = new (Ptr) MDNode(Context, Vals, NumVals, isFunctionLocal);
-
+
// InsertPoint will have been set by the FindNodeOrInsertPos call.
pImpl->MDNodeSet.InsertNode(N, InsertPoint);
}
return N;
}
+MDNode *MDNode::get(LLVMContext &Context, Value*const* Vals, unsigned NumVals) {
+ return getMDNode(Context, Vals, NumVals, FL_Unknown);
+}
+
+MDNode *MDNode::getWhenValsUnresolved(LLVMContext &Context, Value*const* Vals,
+ unsigned NumVals, bool isFunctionLocal) {
+ return getMDNode(Context, Vals, NumVals, isFunctionLocal ? FL_Yes : FL_No);
+}
+
/// getOperand - Return specified operand.
Value *MDNode::getOperand(unsigned i) const {
return *getOperandPtr(const_cast<MDNode*>(this), i);
@@ -163,7 +256,7 @@ void MDNode::Profile(FoldingSetNodeID &ID) const {
// Replace value from this node's operand list.
void MDNode::replaceOperand(MDNodeOperand *Op, Value *To) {
Value *From = *Op;
-
+
if (From == To)
return;
@@ -173,7 +266,7 @@ void MDNode::replaceOperand(MDNodeOperand *Op, Value *To) {
// If this node is already not being uniqued (because one of the operands
// already went to null), then there is nothing else to do here.
if (isNotUniqued()) return;
-
+
LLVMContextImpl *pImpl = getType()->getContext().pImpl;
// Remove "this" from the context map. FoldingSet doesn't have to reprofile
@@ -187,7 +280,7 @@ void MDNode::replaceOperand(MDNodeOperand *Op, Value *To) {
setIsNotUniqued();
return;
}
-
+
// Now that the node is out of the folding set, get ready to reinsert it.
// First, check to see if another node with the same operands already exists
// in the set. If it doesn't exist, this returns the position to insert it.
@@ -210,21 +303,40 @@ void MDNode::replaceOperand(MDNodeOperand *Op, Value *To) {
//===----------------------------------------------------------------------===//
// NamedMDNode implementation.
//
-static SmallVector<TrackingVH<MetadataBase>, 4> &getNMDOps(void *Operands) {
- return *(SmallVector<TrackingVH<MetadataBase>, 4>*)Operands;
+
+namespace llvm {
+// SymbolTableListTraits specialization for MDSymbolTable.
+void ilist_traits<NamedMDNode>
+::addNodeToList(NamedMDNode *N) {
+ assert(N->getParent() == 0 && "Value already in a container!!");
+ Module *Owner = getListOwner();
+ N->setParent(Owner);
+ MDSymbolTable &ST = Owner->getMDSymbolTable();
+ ST.insert(N->getName(), N);
+}
+
+void ilist_traits<NamedMDNode>::removeNodeFromList(NamedMDNode *N) {
+ N->setParent(0);
+ Module *Owner = getListOwner();
+ MDSymbolTable &ST = Owner->getMDSymbolTable();
+ ST.remove(N->getName());
+}
+}
+
+static SmallVector<WeakVH, 4> &getNMDOps(void *Operands) {
+ return *(SmallVector<WeakVH, 4>*)Operands;
}
NamedMDNode::NamedMDNode(LLVMContext &C, const Twine &N,
- MetadataBase *const *MDs,
+ MDNode *const *MDs,
unsigned NumMDs, Module *ParentModule)
- : MetadataBase(Type::getMetadataTy(C), Value::NamedMDNodeVal), Parent(0) {
+ : Value(Type::getMetadataTy(C), Value::NamedMDNodeVal), Parent(0) {
setName(N);
-
- Operands = new SmallVector<TrackingVH<MetadataBase>, 4>();
-
- SmallVector<TrackingVH<MetadataBase>, 4> &Node = getNMDOps(Operands);
+ Operands = new SmallVector<WeakVH, 4>();
+
+ SmallVector<WeakVH, 4> &Node = getNMDOps(Operands);
for (unsigned i = 0; i != NumMDs; ++i)
- Node.push_back(TrackingVH<MetadataBase>(MDs[i]));
+ Node.push_back(WeakVH(MDs[i]));
if (ParentModule)
ParentModule->getNamedMDList().push_back(this);
@@ -232,9 +344,9 @@ NamedMDNode::NamedMDNode(LLVMContext &C, const Twine &N,
NamedMDNode *NamedMDNode::Create(const NamedMDNode *NMD, Module *M) {
assert(NMD && "Invalid source NamedMDNode!");
- SmallVector<MetadataBase *, 4> Elems;
+ SmallVector<MDNode *, 4> Elems;
Elems.reserve(NMD->getNumOperands());
-
+
for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i)
Elems.push_back(NMD->getOperand(i));
return new NamedMDNode(NMD->getContext(), NMD->getName().data(),
@@ -252,14 +364,14 @@ unsigned NamedMDNode::getNumOperands() const {
}
/// getOperand - Return specified operand.
-MetadataBase *NamedMDNode::getOperand(unsigned i) const {
+MDNode *NamedMDNode::getOperand(unsigned i) const {
assert(i < getNumOperands() && "Invalid Operand number!");
- return getNMDOps(Operands)[i];
+ return dyn_cast_or_null<MDNode>(getNMDOps(Operands)[i]);
}
/// addOperand - Add metadata Operand.
-void NamedMDNode::addOperand(MetadataBase *M) {
- getNMDOps(Operands).push_back(TrackingVH<MetadataBase>(M));
+void NamedMDNode::addOperand(MDNode *M) {
+ getNMDOps(Operands).push_back(WeakVH(M));
}
/// eraseFromParent - Drop all references and remove the node from parent
@@ -273,6 +385,26 @@ void NamedMDNode::dropAllReferences() {
getNMDOps(Operands).clear();
}
+/// setName - Set the name of this named metadata.
+void NamedMDNode::setName(const Twine &NewName) {
+ assert (!NewName.isTriviallyEmpty() && "Invalid named metadata name!");
+
+ SmallString<256> NameData;
+ StringRef NameRef = NewName.toStringRef(NameData);
+
+ // Name isn't changing?
+ if (getName() == NameRef)
+ return;
+
+ Name = NameRef.str();
+ if (Parent)
+ Parent->getMDSymbolTable().insert(NameRef, this);
+}
+
+/// getName - Return a constant reference to this named metadata's name.
+StringRef NamedMDNode::getName() const {
+ return StringRef(Name);
+}
//===----------------------------------------------------------------------===//
// LLVMContext MDKind naming implementation.
@@ -299,9 +431,9 @@ static bool isValidName(StringRef MDName) {
/// getMDKindID - Return a unique non-zero ID for the specified metadata kind.
unsigned LLVMContext::getMDKindID(StringRef Name) const {
assert(isValidName(Name) && "Invalid MDNode name");
-
+
unsigned &Entry = pImpl->CustomMDKindNames[Name];
-
+
// If this is new, assign it its ID.
if (Entry == 0) Entry = pImpl->CustomMDKindNames.size();
return Entry;
@@ -313,7 +445,7 @@ void LLVMContext::getMDKindNames(SmallVectorImpl<StringRef> &Names) const {
Names.resize(pImpl->CustomMDKindNames.size()+1);
Names[0] = "";
for (StringMap<unsigned>::const_iterator I = pImpl->CustomMDKindNames.begin(),
- E = pImpl->CustomMDKindNames.end(); I != E; ++I)
+ E = pImpl->CustomMDKindNames.end(); I != E; ++I)
// MD Handlers are numbered from 1.
Names[I->second] = I->first();
}
@@ -336,7 +468,7 @@ MDNode *Instruction::getMetadataImpl(const char *Kind) const {
/// Node is null.
void Instruction::setMetadata(unsigned KindID, MDNode *Node) {
if (Node == 0 && !hasMetadata()) return;
-
+
// Handle the case when we're adding/updating metadata on an instruction.
if (Node) {
LLVMContextImpl::MDMapTy &Info = getContext().pImpl->MetadataStore[this];
@@ -351,24 +483,24 @@ void Instruction::setMetadata(unsigned KindID, MDNode *Node) {
return;
}
}
-
+
// No replacement, just add it to the list.
Info.push_back(std::make_pair(KindID, Node));
return;
}
-
+
// Otherwise, we're removing metadata from an instruction.
assert(hasMetadata() && getContext().pImpl->MetadataStore.count(this) &&
"HasMetadata bit out of date!");
LLVMContextImpl::MDMapTy &Info = getContext().pImpl->MetadataStore[this];
-
+
// Common case is removing the only entry.
if (Info.size() == 1 && Info[0].first == KindID) {
getContext().pImpl->MetadataStore.erase(this);
setHasMetadata(false);
return;
}
-
+
// Handle replacement of an existing value.
for (unsigned i = 0, e = Info.size(); i != e; ++i)
if (Info[i].first == KindID) {
@@ -383,7 +515,7 @@ void Instruction::setMetadata(unsigned KindID, MDNode *Node) {
MDNode *Instruction::getMetadataImpl(unsigned KindID) const {
LLVMContextImpl::MDMapTy &Info = getContext().pImpl->MetadataStore[this];
assert(hasMetadata() && !Info.empty() && "Shouldn't have called this");
-
+
for (LLVMContextImpl::MDMapTy::iterator I = Info.begin(), E = Info.end();
I != E; ++I)
if (I->first == KindID)
@@ -398,10 +530,10 @@ void Instruction::getAllMetadataImpl(SmallVectorImpl<std::pair<unsigned,
const LLVMContextImpl::MDMapTy &Info =
getContext().pImpl->MetadataStore.find(this)->second;
assert(!Info.empty() && "Shouldn't have called this");
-
+
Result.clear();
Result.append(Info.begin(), Info.end());
-
+
// Sort the resulting array so it is stable.
if (Result.size() > 1)
array_pod_sort(Result.begin(), Result.end());
diff --git a/lib/VMCore/Module.cpp b/lib/VMCore/Module.cpp
index a7f503b..503e708 100644
--- a/lib/VMCore/Module.cpp
+++ b/lib/VMCore/Module.cpp
@@ -59,6 +59,7 @@ Module::Module(StringRef MID, LLVMContext& C)
: Context(C), ModuleID(MID), DataLayout("") {
ValSymTab = new ValueSymbolTable();
TypeSymTab = new TypeSymbolTable();
+ NamedMDSymTab = new MDSymbolTable();
}
Module::~Module() {
@@ -70,15 +71,17 @@ Module::~Module() {
NamedMDList.clear();
delete ValSymTab;
delete TypeSymTab;
+ delete NamedMDSymTab;
}
/// Target endian information...
Module::Endianness Module::getEndianness() const {
- std::string temp = DataLayout;
+ StringRef temp = DataLayout;
Module::Endianness ret = AnyEndianness;
while (!temp.empty()) {
- std::string token = getToken(temp, "-");
+ StringRef token = DataLayout;
+ tie(token, temp) = getToken(DataLayout, "-");
if (token[0] == 'e') {
ret = LittleEndian;
@@ -92,15 +95,17 @@ Module::Endianness Module::getEndianness() const {
/// Target Pointer Size information...
Module::PointerSize Module::getPointerSize() const {
- std::string temp = DataLayout;
+ StringRef temp = DataLayout;
Module::PointerSize ret = AnyPointerSize;
while (!temp.empty()) {
- std::string token = getToken(temp, "-");
- char signal = getToken(token, ":")[0];
+ StringRef token, signalToken;
+ tie(token, temp) = getToken(temp, "-");
+ tie(signalToken, token) = getToken(token, ":");
- if (signal == 'p') {
- int size = atoi(getToken(token, ":").c_str());
+ if (signalToken[0] == 'p') {
+ int size = 0;
+ getToken(token, ":").first.getAsInteger(10, size);
if (size == 32)
ret = Pointer32;
else if (size == 64)
@@ -307,15 +312,14 @@ GlobalAlias *Module::getNamedAlias(StringRef Name) const {
/// specified name. This method returns null if a NamedMDNode with the
//// specified name is not found.
NamedMDNode *Module::getNamedMetadata(StringRef Name) const {
- return dyn_cast_or_null<NamedMDNode>(getValueSymbolTable().lookup(Name));
+ return NamedMDSymTab->lookup(Name);
}
/// getOrInsertNamedMetadata - Return the first named MDNode in the module
/// with the specified name. This method returns a new NamedMDNode if a
/// NamedMDNode with the specified name is not found.
NamedMDNode *Module::getOrInsertNamedMetadata(StringRef Name) {
- NamedMDNode *NMD =
- dyn_cast_or_null<NamedMDNode>(getValueSymbolTable().lookup(Name));
+ NamedMDNode *NMD = NamedMDSymTab->lookup(Name);
if (!NMD)
NMD = NamedMDNode::Create(getContext(), Name, NULL, 0, this);
return NMD;
diff --git a/lib/VMCore/Pass.cpp b/lib/VMCore/Pass.cpp
index 6bea7a8..39da8fb 100644
--- a/lib/VMCore/Pass.cpp
+++ b/lib/VMCore/Pass.cpp
@@ -19,6 +19,7 @@
#include "llvm/ModuleProvider.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringMap.h"
+#include "llvm/Support/Debug.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/System/Atomic.h"
@@ -51,7 +52,7 @@ bool Pass::mustPreserveAnalysisID(const PassInfo *AnalysisID) const {
// dumpPassStructure - Implement the -debug-passes=Structure option
void Pass::dumpPassStructure(unsigned Offset) {
- errs().indent(Offset*2) << getPassName() << "\n";
+ dbgs().indent(Offset*2) << getPassName() << "\n";
}
/// getPassName - Return a nice clean name for a pass. This usually
@@ -95,7 +96,7 @@ void Pass::print(raw_ostream &O,const Module*) const {
// dump - call print(cerr);
void Pass::dump() const {
- print(errs(), 0);
+ print(dbgs(), 0);
}
//===----------------------------------------------------------------------===//
diff --git a/lib/VMCore/PassManager.cpp b/lib/VMCore/PassManager.cpp
index d688385..b37b2ae 100644
--- a/lib/VMCore/PassManager.cpp
+++ b/lib/VMCore/PassManager.cpp
@@ -15,6 +15,7 @@
#include "llvm/PassManagers.h"
#include "llvm/Assembly/Writer.h"
#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Debug.h"
#include "llvm/Support/Timer.h"
#include "llvm/Module.h"
#include "llvm/ModuleProvider.h"
@@ -132,7 +133,7 @@ public:
// Print passes managed by this manager
void dumpPassStructure(unsigned Offset) {
- llvm::errs() << std::string(Offset*2, ' ') << "BasicBlockPass Manager\n";
+ llvm::dbgs() << std::string(Offset*2, ' ') << "BasicBlockPass Manager\n";
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
BasicBlockPass *BP = getContainedPass(Index);
BP->dumpPassStructure(Offset + 1);
@@ -272,7 +273,7 @@ public:
// Print passes managed by this manager
void dumpPassStructure(unsigned Offset) {
- llvm::errs() << std::string(Offset*2, ' ') << "ModulePass Manager\n";
+ llvm::dbgs() << std::string(Offset*2, ' ') << "ModulePass Manager\n";
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
ModulePass *MP = getContainedPass(Index);
MP->dumpPassStructure(Offset + 1);
@@ -595,11 +596,11 @@ void PMTopLevelManager::dumpArguments() const {
if (PassDebugging < Arguments)
return;
- errs() << "Pass Arguments: ";
+ dbgs() << "Pass Arguments: ";
for (SmallVector<PMDataManager *, 8>::const_iterator I = PassManagers.begin(),
E = PassManagers.end(); I != E; ++I)
(*I)->dumpPassArguments();
- errs() << "\n";
+ dbgs() << "\n";
}
void PMTopLevelManager::initializeAllAnalysisInfo() {
@@ -718,8 +719,8 @@ void PMDataManager::removeNotPreservedAnalysis(Pass *P) {
// Remove this analysis
if (PassDebugging >= Details) {
Pass *S = Info->second;
- errs() << " -- '" << P->getPassName() << "' is not preserving '";
- errs() << S->getPassName() << "'\n";
+ dbgs() << " -- '" << P->getPassName() << "' is not preserving '";
+ dbgs() << S->getPassName() << "'\n";
}
AvailableAnalysis.erase(Info);
}
@@ -742,8 +743,8 @@ void PMDataManager::removeNotPreservedAnalysis(Pass *P) {
// Remove this analysis
if (PassDebugging >= Details) {
Pass *S = Info->second;
- errs() << " -- '" << P->getPassName() << "' is not preserving '";
- errs() << S->getPassName() << "'\n";
+ dbgs() << " -- '" << P->getPassName() << "' is not preserving '";
+ dbgs() << S->getPassName() << "'\n";
}
InheritedAnalysis[Index]->erase(Info);
}
@@ -764,9 +765,9 @@ void PMDataManager::removeDeadPasses(Pass *P, StringRef Msg,
TPM->collectLastUses(DeadPasses, P);
if (PassDebugging >= Details && !DeadPasses.empty()) {
- errs() << " -*- '" << P->getPassName();
- errs() << "' is the last user of following pass instances.";
- errs() << " Free these instances\n";
+ dbgs() << " -*- '" << P->getPassName();
+ dbgs() << "' is the last user of following pass instances.";
+ dbgs() << " Free these instances\n";
}
for (SmallVector<Pass *, 12>::iterator I = DeadPasses.begin(),
@@ -959,7 +960,7 @@ void PMDataManager::dumpLastUses(Pass *P, unsigned Offset) const{
for (SmallVector<Pass *, 12>::iterator I = LUses.begin(),
E = LUses.end(); I != E; ++I) {
- llvm::errs() << "--" << std::string(Offset*2, ' ');
+ llvm::dbgs() << "--" << std::string(Offset*2, ' ');
(*I)->dumpPassStructure(0);
}
}
@@ -972,7 +973,7 @@ void PMDataManager::dumpPassArguments() const {
else
if (const PassInfo *PI = (*I)->getPassInfo())
if (!PI->isAnalysisGroup())
- errs() << " -" << PI->getPassArgument();
+ dbgs() << " -" << PI->getPassArgument();
}
}
@@ -981,35 +982,35 @@ void PMDataManager::dumpPassInfo(Pass *P, enum PassDebuggingString S1,
StringRef Msg) {
if (PassDebugging < Executions)
return;
- errs() << (void*)this << std::string(getDepth()*2+1, ' ');
+ dbgs() << (void*)this << std::string(getDepth()*2+1, ' ');
switch (S1) {
case EXECUTION_MSG:
- errs() << "Executing Pass '" << P->getPassName();
+ dbgs() << "Executing Pass '" << P->getPassName();
break;
case MODIFICATION_MSG:
- errs() << "Made Modification '" << P->getPassName();
+ dbgs() << "Made Modification '" << P->getPassName();
break;
case FREEING_MSG:
- errs() << " Freeing Pass '" << P->getPassName();
+ dbgs() << " Freeing Pass '" << P->getPassName();
break;
default:
break;
}
switch (S2) {
case ON_BASICBLOCK_MSG:
- errs() << "' on BasicBlock '" << Msg << "'...\n";
+ dbgs() << "' on BasicBlock '" << Msg << "'...\n";
break;
case ON_FUNCTION_MSG:
- errs() << "' on Function '" << Msg << "'...\n";
+ dbgs() << "' on Function '" << Msg << "'...\n";
break;
case ON_MODULE_MSG:
- errs() << "' on Module '" << Msg << "'...\n";
+ dbgs() << "' on Module '" << Msg << "'...\n";
break;
case ON_LOOP_MSG:
- errs() << "' on Loop '" << Msg << "'...\n";
+ dbgs() << "' on Loop '" << Msg << "'...\n";
break;
case ON_CG_MSG:
- errs() << "' on Call Graph Nodes '" << Msg << "'...\n";
+ dbgs() << "' on Call Graph Nodes '" << Msg << "'...\n";
break;
default:
break;
@@ -1039,12 +1040,12 @@ void PMDataManager::dumpAnalysisUsage(StringRef Msg, const Pass *P,
assert(PassDebugging >= Details);
if (Set.empty())
return;
- errs() << (void*)P << std::string(getDepth()*2+3, ' ') << Msg << " Analyses:";
+ dbgs() << (void*)P << std::string(getDepth()*2+3, ' ') << Msg << " Analyses:";
for (unsigned i = 0; i != Set.size(); ++i) {
- if (i) errs() << ',';
- errs() << ' ' << Set[i]->getPassName();
+ if (i) dbgs() << ',';
+ dbgs() << ' ' << Set[i]->getPassName();
}
- errs() << '\n';
+ dbgs() << '\n';
}
/// Add RequiredPass into list of lower level passes required by pass P.
@@ -1067,8 +1068,8 @@ void PMDataManager::addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass) {
// checks whether any lower level manager will be able to provide this
// analysis info on demand or not.
#ifndef NDEBUG
- errs() << "Unable to schedule '" << RequiredPass->getPassName();
- errs() << "' required by '" << P->getPassName() << "'\n";
+ dbgs() << "Unable to schedule '" << RequiredPass->getPassName();
+ dbgs() << "' required by '" << P->getPassName() << "'\n";
#endif
llvm_unreachable("Unable to schedule pass");
}
@@ -1300,7 +1301,7 @@ bool FunctionPassManagerImpl::run(Function &F) {
char FPPassManager::ID = 0;
/// Print passes managed by this manager
void FPPassManager::dumpPassStructure(unsigned Offset) {
- llvm::errs() << std::string(Offset*2, ' ') << "FunctionPass Manager\n";
+ llvm::dbgs() << std::string(Offset*2, ' ') << "FunctionPass Manager\n";
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
FunctionPass *FP = getContainedPass(Index);
FP->dumpPassStructure(Offset + 1);
@@ -1698,19 +1699,19 @@ LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef P) {
return wrap(new FunctionPassManager(unwrap(P)));
}
-int LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M) {
+LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M) {
return unwrap<PassManager>(PM)->run(*unwrap(M));
}
-int LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM) {
+LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM) {
return unwrap<FunctionPassManager>(FPM)->doInitialization();
}
-int LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F) {
+LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F) {
return unwrap<FunctionPassManager>(FPM)->run(*unwrap<Function>(F));
}
-int LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM) {
+LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM) {
return unwrap<FunctionPassManager>(FPM)->doFinalization();
}
diff --git a/lib/VMCore/PrintModulePass.cpp b/lib/VMCore/PrintModulePass.cpp
index 3d4f19d..f0f6e7a 100644
--- a/lib/VMCore/PrintModulePass.cpp
+++ b/lib/VMCore/PrintModulePass.cpp
@@ -16,6 +16,7 @@
#include "llvm/Function.h"
#include "llvm/Module.h"
#include "llvm/Pass.h"
+#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
@@ -26,7 +27,7 @@ namespace {
bool DeleteStream; // Delete the ostream in our dtor?
public:
static char ID;
- PrintModulePass() : ModulePass(&ID), Out(&errs()),
+ PrintModulePass() : ModulePass(&ID), Out(&dbgs()),
DeleteStream(false) {}
PrintModulePass(raw_ostream *o, bool DS)
: ModulePass(&ID), Out(o), DeleteStream(DS) {}
@@ -51,7 +52,7 @@ namespace {
bool DeleteStream; // Delete the ostream in our dtor?
public:
static char ID;
- PrintFunctionPass() : FunctionPass(&ID), Banner(""), Out(&errs()),
+ PrintFunctionPass() : FunctionPass(&ID), Banner(""), Out(&dbgs()),
DeleteStream(false) {}
PrintFunctionPass(const std::string &B, raw_ostream *o, bool DS)
: FunctionPass(&ID), Banner(B), Out(o), DeleteStream(DS) {}
diff --git a/lib/VMCore/Type.cpp b/lib/VMCore/Type.cpp
index fd46aa1..044de4f 100644
--- a/lib/VMCore/Type.cpp
+++ b/lib/VMCore/Type.cpp
@@ -124,6 +124,11 @@ const Type *Type::getScalarType() const {
return this;
}
+/// isInteger - Return true if this is an IntegerType of the specified width.
+bool Type::isInteger(unsigned Bitwidth) const {
+ return isInteger() && cast<IntegerType>(this)->getBitWidth() == Bitwidth;
+}
+
/// isIntOrIntVector - Return true if this is an integer type or a vector of
/// integer types.
///
@@ -280,7 +285,7 @@ std::string Type::getDescription() const {
bool StructType::indexValid(const Value *V) const {
// Structure indexes require 32-bit integer constants.
- if (V->getType() == Type::getInt32Ty(V->getContext()))
+ if (V->getType()->isInteger(32))
if (const ConstantInt *CU = dyn_cast<ConstantInt>(V))
return indexValid(CU->getZExtValue());
return false;
@@ -487,7 +492,7 @@ PointerType::PointerType(const Type *E, unsigned AddrSpace)
OpaqueType::OpaqueType(LLVMContext &C) : DerivedType(C, OpaqueTyID) {
setAbstract(true);
#ifdef DEBUG_MERGE_TYPES
- DEBUG(errs() << "Derived new type: " << *this << "\n");
+ DEBUG(dbgs() << "Derived new type: " << *this << "\n");
#endif
}
@@ -782,7 +787,7 @@ const IntegerType *IntegerType::get(LLVMContext &C, unsigned NumBits) {
pImpl->IntegerTypes.add(IVT, ITy);
}
#ifdef DEBUG_MERGE_TYPES
- DEBUG(errs() << "Derived new type: " << *ITy << "\n");
+ DEBUG(dbgs() << "Derived new type: " << *ITy << "\n");
#endif
return ITy;
}
@@ -825,7 +830,7 @@ FunctionType *FunctionType::get(const Type *ReturnType,
}
#ifdef DEBUG_MERGE_TYPES
- DEBUG(errs() << "Derived new type: " << FT << "\n");
+ DEBUG(dbgs() << "Derived new type: " << FT << "\n");
#endif
return FT;
}
@@ -846,7 +851,7 @@ ArrayType *ArrayType::get(const Type *ElementType, uint64_t NumElements) {
pImpl->ArrayTypes.add(AVT, AT = new ArrayType(ElementType, NumElements));
}
#ifdef DEBUG_MERGE_TYPES
- DEBUG(errs() << "Derived new type: " << *AT << "\n");
+ DEBUG(dbgs() << "Derived new type: " << *AT << "\n");
#endif
return AT;
}
@@ -870,7 +875,7 @@ VectorType *VectorType::get(const Type *ElementType, unsigned NumElements) {
pImpl->VectorTypes.add(PVT, PT = new VectorType(ElementType, NumElements));
}
#ifdef DEBUG_MERGE_TYPES
- DEBUG(errs() << "Derived new type: " << *PT << "\n");
+ DEBUG(dbgs() << "Derived new type: " << *PT << "\n");
#endif
return PT;
}
@@ -902,7 +907,7 @@ StructType *StructType::get(LLVMContext &Context,
pImpl->StructTypes.add(STV, ST);
}
#ifdef DEBUG_MERGE_TYPES
- DEBUG(errs() << "Derived new type: " << *ST << "\n");
+ DEBUG(dbgs() << "Derived new type: " << *ST << "\n");
#endif
return ST;
}
@@ -946,7 +951,7 @@ PointerType *PointerType::get(const Type *ValueType, unsigned AddressSpace) {
pImpl->PointerTypes.add(PVT, PT = new PointerType(ValueType, AddressSpace));
}
#ifdef DEBUG_MERGE_TYPES
- DEBUG(errs() << "Derived new type: " << *PT << "\n");
+ DEBUG(dbgs() << "Derived new type: " << *PT << "\n");
#endif
return PT;
}
@@ -1009,13 +1014,13 @@ void Type::removeAbstractTypeUser(AbstractTypeUser *U) const {
AbstractTypeUsers.erase(AbstractTypeUsers.begin()+i);
#ifdef DEBUG_MERGE_TYPES
- DEBUG(errs() << " remAbstractTypeUser[" << (void*)this << ", "
+ DEBUG(dbgs() << " remAbstractTypeUser[" << (void*)this << ", "
<< *this << "][" << i << "] User = " << U << "\n");
#endif
if (AbstractTypeUsers.empty() && getRefCount() == 0 && isAbstract()) {
#ifdef DEBUG_MERGE_TYPES
- DEBUG(errs() << "DELETEing unused abstract type: <" << *this
+ DEBUG(dbgs() << "DELETEing unused abstract type: <" << *this
<< ">[" << (void*)this << "]" << "\n");
#endif
@@ -1041,7 +1046,7 @@ void DerivedType::unlockedRefineAbstractTypeTo(const Type *NewType) {
pImpl->AbstractTypeDescriptions.clear();
#ifdef DEBUG_MERGE_TYPES
- DEBUG(errs() << "REFINING abstract type [" << (void*)this << " "
+ DEBUG(dbgs() << "REFINING abstract type [" << (void*)this << " "
<< *this << "] to [" << (void*)NewType << " "
<< *NewType << "]!\n");
#endif
@@ -1078,7 +1083,7 @@ void DerivedType::unlockedRefineAbstractTypeTo(const Type *NewType) {
unsigned OldSize = AbstractTypeUsers.size(); OldSize=OldSize;
#ifdef DEBUG_MERGE_TYPES
- DEBUG(errs() << " REFINING user " << OldSize-1 << "[" << (void*)User
+ DEBUG(dbgs() << " REFINING user " << OldSize-1 << "[" << (void*)User
<< "] of abstract type [" << (void*)this << " "
<< *this << "] to [" << (void*)NewTy.get() << " "
<< *NewTy << "]!\n");
@@ -1109,7 +1114,7 @@ void DerivedType::refineAbstractTypeTo(const Type *NewType) {
//
void DerivedType::notifyUsesThatTypeBecameConcrete() {
#ifdef DEBUG_MERGE_TYPES
- DEBUG(errs() << "typeIsREFINED type: " << (void*)this << " " << *this <<"\n");
+ DEBUG(dbgs() << "typeIsREFINED type: " << (void*)this << " " << *this <<"\n");
#endif
unsigned OldSize = AbstractTypeUsers.size(); OldSize=OldSize;
diff --git a/lib/VMCore/TypeSymbolTable.cpp b/lib/VMCore/TypeSymbolTable.cpp
index 0d0cdf5..b4daf0f 100644
--- a/lib/VMCore/TypeSymbolTable.cpp
+++ b/lib/VMCore/TypeSymbolTable.cpp
@@ -15,6 +15,7 @@
#include "llvm/DerivedTypes.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Debug.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
@@ -58,7 +59,7 @@ Type* TypeSymbolTable::remove(iterator Entry) {
#if DEBUG_SYMBOL_TABLE
dump();
- errs() << " Removing Value: " << Result->getDescription() << "\n";
+ dbgs() << " Removing Value: " << Result->getDescription() << "\n";
#endif
tmap.erase(Entry);
@@ -67,7 +68,7 @@ Type* TypeSymbolTable::remove(iterator Entry) {
// list...
if (Result->isAbstract()) {
#if DEBUG_ABSTYPE
- errs() << "Removing abstract type from symtab"
+ dbgs() << "Removing abstract type from symtab"
<< Result->getDescription()
<< "\n";
#endif
@@ -87,7 +88,7 @@ void TypeSymbolTable::insert(StringRef Name, const Type* T) {
#if DEBUG_SYMBOL_TABLE
dump();
- errs() << " Inserted type: " << Name << ": " << T->getDescription() << "\n";
+ dbgs() << " Inserted type: " << Name << ": " << T->getDescription() << "\n";
#endif
} else {
// If there is a name conflict...
@@ -99,7 +100,7 @@ void TypeSymbolTable::insert(StringRef Name, const Type* T) {
#if DEBUG_SYMBOL_TABLE
dump();
- errs() << " Inserting type: " << UniqueName << ": "
+ dbgs() << " Inserting type: " << UniqueName << ": "
<< T->getDescription() << "\n";
#endif
@@ -111,7 +112,7 @@ void TypeSymbolTable::insert(StringRef Name, const Type* T) {
if (T->isAbstract()) {
cast<DerivedType>(T)->addAbstractTypeUser(this);
#if DEBUG_ABSTYPE
- errs() << "Added abstract type to ST: " << T->getDescription() << "\n";
+ dbgs() << "Added abstract type to ST: " << T->getDescription() << "\n";
#endif
}
}
@@ -127,14 +128,14 @@ void TypeSymbolTable::refineAbstractType(const DerivedType *OldType,
for (iterator I = begin(), E = end(); I != E; ++I) {
if (I->second == (Type*)OldType) { // FIXME when Types aren't const.
#if DEBUG_ABSTYPE
- errs() << "Removing type " << OldType->getDescription() << "\n";
+ dbgs() << "Removing type " << OldType->getDescription() << "\n";
#endif
OldType->removeAbstractTypeUser(this);
I->second = (Type*)NewType; // TODO FIXME when types aren't const
if (NewType->isAbstract()) {
#if DEBUG_ABSTYPE
- errs() << "Added type " << NewType->getDescription() << "\n";
+ dbgs() << "Added type " << NewType->getDescription() << "\n";
#endif
cast<DerivedType>(NewType)->addAbstractTypeUser(this);
}
@@ -154,13 +155,13 @@ void TypeSymbolTable::typeBecameConcrete(const DerivedType *AbsTy) {
}
static void DumpTypes(const std::pair<const std::string, const Type*>& T ) {
- errs() << " '" << T.first << "' = ";
+ dbgs() << " '" << T.first << "' = ";
T.second->dump();
- errs() << "\n";
+ dbgs() << "\n";
}
void TypeSymbolTable::dump() const {
- errs() << "TypeSymbolPlane: ";
+ dbgs() << "TypeSymbolPlane: ";
for_each(tmap.begin(), tmap.end(), DumpTypes);
}
diff --git a/lib/VMCore/TypesContext.h b/lib/VMCore/TypesContext.h
index e7950bd..93a801b 100644
--- a/lib/VMCore/TypesContext.h
+++ b/lib/VMCore/TypesContext.h
@@ -302,7 +302,7 @@ public:
void RefineAbstractType(TypeClass *Ty, const DerivedType *OldType,
const Type *NewType) {
#ifdef DEBUG_MERGE_TYPES
- DEBUG(errs() << "RefineAbstractType(" << (void*)OldType << "[" << *OldType
+ DEBUG(dbgs() << "RefineAbstractType(" << (void*)OldType << "[" << *OldType
<< "], " << (void*)NewType << " [" << *NewType << "])\n");
#endif
@@ -408,11 +408,11 @@ public:
void print(const char *Arg) const {
#ifdef DEBUG_MERGE_TYPES
- DEBUG(errs() << "TypeMap<>::" << Arg << " table contents:\n");
+ DEBUG(dbgs() << "TypeMap<>::" << Arg << " table contents:\n");
unsigned i = 0;
for (typename std::map<ValType, PATypeHolder>::const_iterator I
= Map.begin(), E = Map.end(); I != E; ++I)
- DEBUG(errs() << " " << (++i) << ". " << (void*)I->second.get() << " "
+ DEBUG(dbgs() << " " << (++i) << ". " << (void*)I->second.get() << " "
<< *I->second.get() << "\n");
#endif
}
diff --git a/lib/VMCore/Value.cpp b/lib/VMCore/Value.cpp
index fe1219f..40679bf 100644
--- a/lib/VMCore/Value.cpp
+++ b/lib/VMCore/Value.cpp
@@ -44,14 +44,12 @@ Value::Value(const Type *ty, unsigned scid)
SubclassOptionalData(0), SubclassData(0), VTy(checkType(ty)),
UseList(0), Name(0) {
if (isa<CallInst>(this) || isa<InvokeInst>(this))
- assert((VTy->isFirstClassType() ||
- VTy == Type::getVoidTy(ty->getContext()) ||
+ assert((VTy->isFirstClassType() || VTy->isVoidTy() ||
isa<OpaqueType>(ty) || VTy->getTypeID() == Type::StructTyID) &&
"invalid CallInst type!");
else if (!isa<Constant>(this) && !isa<BasicBlock>(this))
- assert((VTy->isFirstClassType() ||
- VTy == Type::getVoidTy(ty->getContext()) ||
- isa<OpaqueType>(ty)) &&
+ assert((VTy->isFirstClassType() || VTy->isVoidTy() ||
+ isa<OpaqueType>(ty)) &&
"Cannot create non-first-class values except for constants!");
}
@@ -68,9 +66,9 @@ Value::~Value() {
// a <badref>
//
if (!use_empty()) {
- errs() << "While deleting: " << *VTy << " %" << getNameStr() << "\n";
+ dbgs() << "While deleting: " << *VTy << " %" << getNameStr() << "\n";
for (use_iterator I = use_begin(), E = use_end(); I != E; ++I)
- errs() << "Use still stuck around after Def is destroyed:"
+ dbgs() << "Use still stuck around after Def is destroyed:"
<< **I << "\n";
}
#endif
@@ -172,17 +170,13 @@ void Value::setName(const Twine &NewName) {
return;
SmallString<256> NameData;
- NewName.toVector(NameData);
-
- const char *NameStr = NameData.data();
- unsigned NameLen = NameData.size();
+ StringRef NameRef = NewName.toStringRef(NameData);
// Name isn't changing?
- if (getName() == StringRef(NameStr, NameLen))
+ if (getName() == NameRef)
return;
- assert(getType() != Type::getVoidTy(getContext()) &&
- "Cannot assign a name to void values!");
+ assert(!getType()->isVoidTy() && "Cannot assign a name to void values!");
// Get the symbol table to update for this object.
ValueSymbolTable *ST;
@@ -190,7 +184,7 @@ void Value::setName(const Twine &NewName) {
return; // Cannot set a name on this value (e.g. constant).
if (!ST) { // No symbol table to update? Just do the change.
- if (NameLen == 0) {
+ if (NameRef.empty()) {
// Free the name for this value.
Name->Destroy();
Name = 0;
@@ -204,7 +198,7 @@ void Value::setName(const Twine &NewName) {
// then reallocated.
// Create the new name.
- Name = ValueName::Create(NameStr, NameStr+NameLen);
+ Name = ValueName::Create(NameRef.begin(), NameRef.end());
Name->setValue(this);
return;
}
@@ -217,12 +211,12 @@ void Value::setName(const Twine &NewName) {
Name->Destroy();
Name = 0;
- if (NameLen == 0)
+ if (NameRef.empty())
return;
}
// Name is changing to something new.
- Name = ST->createValueName(StringRef(NameStr, NameLen), this);
+ Name = ST->createValueName(NameRef, this);
}
@@ -522,7 +516,7 @@ void ValueHandleBase::ValueIsDeleted(Value *V) {
// All callbacks, weak references, and assertingVHs should be dropped by now.
if (V->HasValueHandle) {
#ifndef NDEBUG // Only in +Asserts mode...
- errs() << "While deleting: " << *V->getType() << " %" << V->getNameStr()
+ dbgs() << "While deleting: " << *V->getType() << " %" << V->getNameStr()
<< "\n";
if (pImpl->ValueHandles[V]->getKind() == Assert)
llvm_unreachable("An asserting value handle still pointed to this"
diff --git a/lib/VMCore/ValueSymbolTable.cpp b/lib/VMCore/ValueSymbolTable.cpp
index 9d39a50..d30a9d6 100644
--- a/lib/VMCore/ValueSymbolTable.cpp
+++ b/lib/VMCore/ValueSymbolTable.cpp
@@ -24,7 +24,7 @@ using namespace llvm;
ValueSymbolTable::~ValueSymbolTable() {
#ifndef NDEBUG // Only do this in -g mode...
for (iterator VI = vmap.begin(), VE = vmap.end(); VI != VE; ++VI)
- errs() << "Value still in symbol table! Type = '"
+ dbgs() << "Value still in symbol table! Type = '"
<< VI->getValue()->getType()->getDescription() << "' Name = '"
<< VI->getKeyData() << "'\n";
assert(vmap.empty() && "Values remain in symbol table!");
@@ -38,7 +38,7 @@ void ValueSymbolTable::reinsertValue(Value* V) {
// Try inserting the name, assuming it won't conflict.
if (vmap.insert(V->Name)) {
- //DEBUG(errs() << " Inserted value: " << V->Name << ": " << *V << "\n");
+ //DEBUG(dbgs() << " Inserted value: " << V->Name << ": " << *V << "\n");
return;
}
@@ -62,14 +62,14 @@ void ValueSymbolTable::reinsertValue(Value* V) {
// Newly inserted name. Success!
NewName.setValue(V);
V->Name = &NewName;
- //DEBUG(errs() << " Inserted value: " << UniqueName << ": " << *V << "\n");
+ //DEBUG(dbgs() << " Inserted value: " << UniqueName << ": " << *V << "\n");
return;
}
}
}
void ValueSymbolTable::removeValueName(ValueName *V) {
- //DEBUG(errs() << " Removing Value: " << V->getKeyData() << "\n");
+ //DEBUG(dbgs() << " Removing Value: " << V->getKeyData() << "\n");
// Remove the value from the symbol table.
vmap.remove(V);
}
@@ -82,7 +82,7 @@ ValueName *ValueSymbolTable::createValueName(StringRef Name, Value *V) {
ValueName &Entry = vmap.GetOrCreateValue(Name);
if (Entry.getValue() == 0) {
Entry.setValue(V);
- //DEBUG(errs() << " Inserted value: " << Entry.getKeyData() << ": "
+ //DEBUG(dbgs() << " Inserted value: " << Entry.getKeyData() << ": "
// << *V << "\n");
return &Entry;
}
@@ -102,7 +102,7 @@ ValueName *ValueSymbolTable::createValueName(StringRef Name, Value *V) {
if (NewName.getValue() == 0) {
// Newly inserted name. Success!
NewName.setValue(V);
- //DEBUG(errs() << " Inserted value: " << UniqueName << ": " << *V << "\n");
+ //DEBUG(dbgs() << " Inserted value: " << UniqueName << ": " << *V << "\n");
return &NewName;
}
}
@@ -112,10 +112,12 @@ ValueName *ValueSymbolTable::createValueName(StringRef Name, Value *V) {
// dump - print out the symbol table
//
void ValueSymbolTable::dump() const {
- //DEBUG(errs() << "ValueSymbolTable:\n");
+ //DEBUG(dbgs() << "ValueSymbolTable:\n");
for (const_iterator I = begin(), E = end(); I != E; ++I) {
- //DEBUG(errs() << " '" << I->getKeyData() << "' = ");
+ //DEBUG(dbgs() << " '" << I->getKeyData() << "' = ");
I->getValue()->dump();
- //DEBUG(errs() << "\n");
+ //DEBUG(dbgs() << "\n");
}
}
+
+MDSymbolTable::~MDSymbolTable() { }
diff --git a/lib/VMCore/Verifier.cpp b/lib/VMCore/Verifier.cpp
index 30528bf..ec475e4 100644
--- a/lib/VMCore/Verifier.cpp
+++ b/lib/VMCore/Verifier.cpp
@@ -56,6 +56,7 @@
#include "llvm/CodeGen/ValueTypes.h"
#include "llvm/Support/CallSite.h"
#include "llvm/Support/CFG.h"
+#include "llvm/Support/Debug.h"
#include "llvm/Support/InstVisitor.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallPtrSet.h"
@@ -85,9 +86,9 @@ namespace { // Anonymous namespace for class
for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I) {
if (I->empty() || !I->back().isTerminator()) {
- errs() << "Basic Block does not have terminator!\n";
- WriteAsOperand(errs(), I, true);
- errs() << "\n";
+ dbgs() << "Basic Block does not have terminator!\n";
+ WriteAsOperand(dbgs(), I, true);
+ dbgs() << "\n";
Broken = true;
}
}
@@ -262,12 +263,12 @@ namespace {
default: llvm_unreachable("Unknown action");
case AbortProcessAction:
MessagesStr << "compilation aborted!\n";
- errs() << MessagesStr.str();
+ dbgs() << MessagesStr.str();
// Client should choose different reaction if abort is not desired
abort();
case PrintMessageAction:
MessagesStr << "verification continues.\n";
- errs() << MessagesStr.str();
+ dbgs() << MessagesStr.str();
return false;
case ReturnStatusAction:
MessagesStr << "compilation terminated.\n";
@@ -1589,9 +1590,10 @@ void Verifier::visitIntrinsicFunctionCall(Intrinsic::ID ID, CallInst &CI) {
default:
break;
case Intrinsic::dbg_declare: // llvm.dbg.declare
- if (Constant *C = dyn_cast<Constant>(CI.getOperand(1)))
- Assert1(C && !isa<ConstantPointerNull>(C),
- "invalid llvm.dbg.declare intrinsic call", &CI);
+ if (MDNode *MD = dyn_cast<MDNode>(CI.getOperand(1)))
+ if (Constant *C = dyn_cast<Constant>(MD->getOperand(0)))
+ Assert1(C && !isa<ConstantPointerNull>(C),
+ "invalid llvm.dbg.declare intrinsic call", &CI);
break;
case Intrinsic::memcpy:
case Intrinsic::memmove:
OpenPOWER on IntegriCloud