summaryrefslogtreecommitdiffstats
path: root/lib/VMCore
diff options
context:
space:
mode:
Diffstat (limited to 'lib/VMCore')
-rw-r--r--lib/VMCore/AsmWriter.cpp4
-rw-r--r--lib/VMCore/Attributes.cpp2
-rw-r--r--lib/VMCore/AutoUpgrade.cpp2
-rw-r--r--lib/VMCore/CMakeLists.txt1
-rw-r--r--lib/VMCore/ConstantFold.cpp5
-rw-r--r--lib/VMCore/Constants.cpp20
-rw-r--r--lib/VMCore/Instructions.cpp13
-rw-r--r--lib/VMCore/IntrinsicInst.cpp11
-rw-r--r--lib/VMCore/Makefile1
-rw-r--r--lib/VMCore/Mangler.cpp273
-rw-r--r--lib/VMCore/Metadata.cpp97
-rw-r--r--lib/VMCore/Pass.cpp3
-rw-r--r--lib/VMCore/PassManager.cpp76
-rw-r--r--lib/VMCore/Verifier.cpp17
14 files changed, 143 insertions, 382 deletions
diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp
index eff2c77..c9f3849 100644
--- a/lib/VMCore/AsmWriter.cpp
+++ b/lib/VMCore/AsmWriter.cpp
@@ -2062,9 +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)) {
- Function *F = N->getFunction();
+ const Function *F = N->getFunction();
SlotTracker SlotTable(F);
- AssemblyWriter W(OS, SlotTable, getModuleFromVal(F), AAW);
+ AssemblyWriter W(OS, SlotTable, F ? getModuleFromVal(F) : 0, AAW);
W.printMDNodeBody(N);
} else if (const NamedMDNode *N = dyn_cast<NamedMDNode>(this)) {
SlotTracker SlotTable(N->getParent());
diff --git a/lib/VMCore/Attributes.cpp b/lib/VMCore/Attributes.cpp
index a371c6f..65155f1 100644
--- a/lib/VMCore/Attributes.cpp
+++ b/lib/VMCore/Attributes.cpp
@@ -56,8 +56,6 @@ std::string Attribute::getAsString(Attributes Attrs) {
Result += "optsize ";
if (Attrs & Attribute::NoInline)
Result += "noinline ";
- if (Attrs & Attribute::InlineHint)
- Result += "inlinehint ";
if (Attrs & Attribute::AlwaysInline)
Result += "alwaysinline ";
if (Attrs & Attribute::StackProtect)
diff --git a/lib/VMCore/AutoUpgrade.cpp b/lib/VMCore/AutoUpgrade.cpp
index 2161841..5e4c9fb 100644
--- a/lib/VMCore/AutoUpgrade.cpp
+++ b/lib/VMCore/AutoUpgrade.cpp
@@ -521,7 +521,7 @@ void llvm::CheckDebugInfoIntrinsics(Module *M) {
if (Function *Declare = M->getFunction("llvm.dbg.declare")) {
if (!Declare->use_empty()) {
DbgDeclareInst *DDI = cast<DbgDeclareInst>(Declare->use_back());
- if (!isa<MDNode>(DDI->getOperand(2))) {
+ if (!isa<MDNode>(DDI->getOperand(1)) ||!isa<MDNode>(DDI->getOperand(2))) {
while (!Declare->use_empty()) {
CallInst *CI = cast<CallInst>(Declare->use_back());
CI->eraseFromParent();
diff --git a/lib/VMCore/CMakeLists.txt b/lib/VMCore/CMakeLists.txt
index 61d01ee..5ecedf1 100644
--- a/lib/VMCore/CMakeLists.txt
+++ b/lib/VMCore/CMakeLists.txt
@@ -16,7 +16,6 @@ add_llvm_library(LLVMCore
IRBuilder.cpp
LLVMContext.cpp
LeakDetector.cpp
- Mangler.cpp
Metadata.cpp
Module.cpp
ModuleProvider.cpp
diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp
index 3a24389..ddd5587 100644
--- a/lib/VMCore/ConstantFold.cpp
+++ b/lib/VMCore/ConstantFold.cpp
@@ -1673,14 +1673,15 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context,
SmallVector<Constant*, 16> C1Elts, C2Elts;
C1->getVectorElements(Context, C1Elts);
C2->getVectorElements(Context, C2Elts);
+ if (C1Elts.empty() || C2Elts.empty())
+ return 0;
// If we can constant fold the comparison of each element, constant fold
// the whole vector comparison.
SmallVector<Constant*, 4> ResElts;
for (unsigned i = 0, e = C1Elts.size(); i != e; ++i) {
// Compare the elements, producing an i1 result or constant expr.
- ResElts.push_back(
- ConstantExpr::getCompare(pred, C1Elts[i], C2Elts[i]));
+ ResElts.push_back(ConstantExpr::getCompare(pred, C1Elts[i], C2Elts[i]));
}
return ConstantVector::get(&ResElts[0], ResElts.size());
}
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp
index cc8961f..916aac6 100644
--- a/lib/VMCore/Constants.cpp
+++ b/lib/VMCore/Constants.cpp
@@ -1630,7 +1630,7 @@ Constant *ConstantExpr::getInBoundsGetElementPtr(Constant *C,
}
Constant *
-ConstantExpr::getICmp(unsigned short pred, Constant* LHS, Constant* RHS) {
+ConstantExpr::getICmp(unsigned short pred, Constant *LHS, Constant *RHS) {
assert(LHS->getType() == RHS->getType());
assert(pred >= ICmpInst::FIRST_ICMP_PREDICATE &&
pred <= ICmpInst::LAST_ICMP_PREDICATE && "Invalid ICmp Predicate");
@@ -1646,13 +1646,16 @@ ConstantExpr::getICmp(unsigned short pred, Constant* LHS, Constant* RHS) {
// Get the key type with both the opcode and predicate
const ExprMapKeyType Key(Instruction::ICmp, ArgVec, pred);
+ const Type *ResultTy = Type::getInt1Ty(LHS->getContext());
+ if (const VectorType *VT = dyn_cast<VectorType>(LHS->getType()))
+ ResultTy = VectorType::get(ResultTy, VT->getNumElements());
+
LLVMContextImpl *pImpl = LHS->getType()->getContext().pImpl;
- return
- pImpl->ExprConstants.getOrCreate(Type::getInt1Ty(LHS->getContext()), Key);
+ return pImpl->ExprConstants.getOrCreate(ResultTy, Key);
}
Constant *
-ConstantExpr::getFCmp(unsigned short pred, Constant* LHS, Constant* RHS) {
+ConstantExpr::getFCmp(unsigned short pred, Constant *LHS, Constant *RHS) {
assert(LHS->getType() == RHS->getType());
assert(pred <= FCmpInst::LAST_FCMP_PREDICATE && "Invalid FCmp Predicate");
@@ -1666,10 +1669,13 @@ ConstantExpr::getFCmp(unsigned short pred, Constant* LHS, Constant* RHS) {
ArgVec.push_back(RHS);
// Get the key type with both the opcode and predicate
const ExprMapKeyType Key(Instruction::FCmp, ArgVec, pred);
-
+
+ const Type *ResultTy = Type::getInt1Ty(LHS->getContext());
+ if (const VectorType *VT = dyn_cast<VectorType>(LHS->getType()))
+ ResultTy = VectorType::get(ResultTy, VT->getNumElements());
+
LLVMContextImpl *pImpl = LHS->getType()->getContext().pImpl;
- return
- pImpl->ExprConstants.getOrCreate(Type::getInt1Ty(LHS->getContext()), Key);
+ return pImpl->ExprConstants.getOrCreate(ResultTy, Key);
}
Constant *ConstantExpr::getExtractElementTy(const Type *ReqTy, Constant *Val,
diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp
index 2619047..e2b920e 100644
--- a/lib/VMCore/Instructions.cpp
+++ b/lib/VMCore/Instructions.cpp
@@ -2079,25 +2079,26 @@ unsigned CastInst::isEliminableCastPair(
return secondOp;
case 3:
// no-op cast in second op implies firstOp as long as the DestTy
- // is integer
- if (DstTy->isInteger())
+ // is integer and we are not converting between a vector and a
+ // non vector type.
+ if (!isa<VectorType>(SrcTy) && DstTy->isInteger())
return firstOp;
return 0;
case 4:
// no-op cast in second op implies firstOp as long as the DestTy
- // is floating point
+ // is floating point.
if (DstTy->isFloatingPoint())
return firstOp;
return 0;
case 5:
// no-op cast in first op implies secondOp as long as the SrcTy
- // is an integer
+ // is an integer.
if (SrcTy->isInteger())
return secondOp;
return 0;
case 6:
// no-op cast in first op implies secondOp as long as the SrcTy
- // is a floating point
+ // is a floating point.
if (SrcTy->isFloatingPoint())
return secondOp;
return 0;
@@ -2714,6 +2715,8 @@ BitCastInst::BitCastInst(
// CmpInst Classes
//===----------------------------------------------------------------------===//
+void CmpInst::Anchor() const {}
+
CmpInst::CmpInst(const Type *ty, OtherOps op, unsigned short predicate,
Value *LHS, Value *RHS, const Twine &Name,
Instruction *InsertBefore)
diff --git a/lib/VMCore/IntrinsicInst.cpp b/lib/VMCore/IntrinsicInst.cpp
index cb9252e..d8f015a 100644
--- a/lib/VMCore/IntrinsicInst.cpp
+++ b/lib/VMCore/IntrinsicInst.cpp
@@ -51,6 +51,17 @@ Value *DbgInfoIntrinsic::StripCast(Value *C) {
}
//===----------------------------------------------------------------------===//
+/// DbgDeclareInst - This represents the llvm.dbg.declare instruction.
+///
+
+Value *DbgDeclareInst::getAddress() const {
+ if (MDNode* MD = cast_or_null<MDNode>(getOperand(1)))
+ return MD->getOperand(0);
+ else
+ return NULL;
+}
+
+//===----------------------------------------------------------------------===//
/// DbgValueInst - This represents the llvm.dbg.value instruction.
///
diff --git a/lib/VMCore/Makefile b/lib/VMCore/Makefile
index e9d3dc8..ecadaee 100644
--- a/lib/VMCore/Makefile
+++ b/lib/VMCore/Makefile
@@ -9,6 +9,7 @@
LEVEL = ../..
LIBRARYNAME = LLVMCore
BUILD_ARCHIVE = 1
+#CXXFLAGS = -fno-rtti
BUILT_SOURCES = $(PROJ_OBJ_ROOT)/include/llvm/Intrinsics.gen
diff --git a/lib/VMCore/Mangler.cpp b/lib/VMCore/Mangler.cpp
deleted file mode 100644
index 7d9f330..0000000
--- a/lib/VMCore/Mangler.cpp
+++ /dev/null
@@ -1,273 +0,0 @@
-//===-- Mangler.cpp - Self-contained c/asm llvm name mangler --------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// Unified name mangler for CWriter and assembly backends.
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/Support/Mangler.h"
-#include "llvm/Function.h"
-#include "llvm/ADT/STLExtras.h"
-#include "llvm/ADT/StringExtras.h"
-#include "llvm/ADT/StringMap.h"
-#include "llvm/ADT/SmallString.h"
-#include "llvm/Support/raw_ostream.h"
-using namespace llvm;
-
-static char HexDigit(int V) {
- return V < 10 ? V+'0' : V+'A'-10;
-}
-
-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.
-///
-/// 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) {
- // If X does not start with (char)1, add the prefix.
- StringRef::iterator I = X.begin();
- if (*I == 1) {
- ++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')
- MangleLetter(OutName, *I++);
-
- for (StringRef::iterator E = X.end(); I != E; ++I) {
- if (!isCharAcceptable(*I))
- MangleLetter(OutName, *I);
- else
- OutName.push_back(*I);
- }
- return;
- }
-
- bool NeedPrefix = true;
- bool NeedQuotes = false;
- StringRef::iterator I = X.begin();
- if (*I == 1) {
- NeedPrefix = false;
- ++I; // Skip over the marker.
- }
-
- // If the first character is a number, we need quotes.
- if (*I >= '0' && *I <= '9')
- NeedQuotes = true;
-
- // Do an initial scan of the string, checking to see if we need quotes or
- // to escape a '"' or not.
- if (!NeedQuotes)
- for (StringRef::iterator E = X.end(); I != E; ++I)
- if (!isCharAcceptable(*I)) {
- NeedQuotes = true;
- break;
- }
-
- // In the common case, we don't need quotes. Handle this quickly.
- if (!NeedQuotes) {
- if (!NeedPrefix) {
- OutName.append(X.begin()+1, X.end()); // Strip off the \001.
- return;
- }
-
- 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.
- OutName.append(X.begin(), X.end());
- return;
- }
-
- // Add leading quote.
- OutName.push_back('"');
-
- // Add prefixes unless disabled.
- if (NeedPrefix) {
- 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));
- }
-
- // 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);
- }
-
- // Add trailing quote.
- OutName.push_back('"');
-}
-
-/// getMangledName - Returns the mangled name of V, an LLVM Value,
-/// in the current module. If 'Suffix' is specified, the name ends with the
-/// 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()) &&
- "Intrinsic functions cannot be mangled by Mangler");
-
- ManglerPrefixTy PrefixTy =
- (GV->hasPrivateLinkage() || ForcePrivate) ? Mangler::Private :
- GV->hasLinkerPrivateLinkage() ? Mangler::LinkerPrivate : Mangler::Default;
-
- 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.
- unsigned &ID = AnonGlobalIDs[GV];
- if (ID == 0) ID = NextAnonGlobalID++;
-
- // Must mangle the global into a unique ID.
- 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());
-}
-
-
-/// getNameWithPrefix - Fill OutName with the name of the appropriate prefix
-/// and the specified global variable's name. If the global variable doesn't
-/// have a name, this fills in a unique name for the global.
-void Mangler::getNameWithPrefix(SmallVectorImpl<char> &OutName,
- const GlobalValue *GV,
- bool isImplicitlyPrivate) {
- // If this global has a name, handle it simply.
- if (GV->hasName()) {
- ManglerPrefixTy PrefixTy = Mangler::Default;
- if (GV->hasPrivateLinkage() || isImplicitlyPrivate)
- PrefixTy = Mangler::Private;
- else if (GV->hasLinkerPrivateLinkage())
- PrefixTy = Mangler::LinkerPrivate;
-
- 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];
- if (ID == 0) ID = NextAnonGlobalID++;
-
- // Must mangle the global into a unique ID.
- raw_svector_ostream(OutName) << "__unnamed_" << ID;
-}
-
-
-Mangler::Mangler(Module &M, const char *prefix, const char *privatePrefix,
- const char *linkerPrivatePrefix)
- : Prefix(prefix), PrivatePrefix(privatePrefix),
- LinkerPrivatePrefix(linkerPrivatePrefix), UseQuotes(false),
- SymbolsCanStartWithDigit(false), NextAnonGlobalID(1) {
- std::fill(AcceptableChars, array_endof(AcceptableChars), 0);
-
- // Letters and numbers are acceptable.
- for (unsigned char X = 'a'; X <= 'z'; ++X)
- markCharAcceptable(X);
- for (unsigned char X = 'A'; X <= 'Z'; ++X)
- markCharAcceptable(X);
- for (unsigned char X = '0'; X <= '9'; ++X)
- markCharAcceptable(X);
-
- // These chars are acceptable.
- markCharAcceptable('_');
- markCharAcceptable('$');
- markCharAcceptable('.');
- markCharAcceptable('@');
-}
diff --git a/lib/VMCore/Metadata.cpp b/lib/VMCore/Metadata.cpp
index 7988b44..ee8e713 100644
--- a/lib/VMCore/Metadata.cpp
+++ b/lib/VMCore/Metadata.cpp
@@ -28,7 +28,7 @@ using namespace llvm;
//
MDString::MDString(LLVMContext &C, StringRef S)
- : MetadataBase(Type::getMetadataTy(C), Value::MDStringVal), Str(S) {}
+ : Value(Type::getMetadataTy(C), Value::MDStringVal), Str(S) {}
MDString *MDString::get(LLVMContext &Context, StringRef Str) {
LLVMContextImpl *pImpl = Context.pImpl;
@@ -93,7 +93,7 @@ static MDNodeOperand *getOperandPtr(MDNode *N, unsigned Op) {
MDNode::MDNode(LLVMContext &C, Value *const *Vals, unsigned NumVals,
bool isFunctionLocal)
-: MetadataBase(Type::getMetadataTy(C), Value::MDNodeVal) {
+: Value(Type::getMetadataTy(C), Value::MDNodeVal) {
NumOperands = NumVals;
if (isFunctionLocal)
@@ -121,67 +121,60 @@ MDNode::~MDNode() {
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;
+static const Function *getFunctionForValue(Value *V) {
+ assert(!isa<MDNode>(V) && "does not iterate over metadata operands");
+ if (!V) return NULL;
+ if (Instruction *I = dyn_cast<Instruction>(V))
+ return I->getParent()->getParent();
+ if (BasicBlock *BB = dyn_cast<BasicBlock>(V))
+ return BB->getParent();
+ if (Argument *A = dyn_cast<Argument>(V))
+ return A->getParent();
+ return NULL;
}
-#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;
-
+static const Function *assertLocalFunction(const MDNode *N) {
+ if (!N->isFunctionLocal()) return 0;
+
+ const Function *F = 0, *NewF = 0;
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;
+ if (Value *V = N->getOperand(i)) {
+ if (MDNode *MD = dyn_cast<MDNode>(V))
+ NewF = assertLocalFunction(MD);
+ else
+ NewF = getFunctionForValue(V);
+ }
+ if (F == 0)
+ F = NewF;
+ else
+ assert((NewF == 0 || F == NewF) &&"inconsistent function-local metadata");
}
return F;
}
+#endif
// 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 {
+// Otherwise, return null. getFunction() should not be used for performance-
+// critical code because it recursively visits all the MDNode's operands.
+const Function *MDNode::getFunction() const {
+#ifndef NDEBUG
+ return assertLocalFunction(this);
+#endif
if (!isFunctionLocal()) return NULL;
- SmallPtrSet<const MDNode *, 32> Visited;
- return getFunctionHelper(this, Visited);
+
+ for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
+ if (Value *V = getOperand(i)) {
+ if (MDNode *MD = dyn_cast<MDNode>(V)) {
+ if (const Function *F = MD->getFunction())
+ return F;
+ } else {
+ return getFunctionForValue(V);
+ }
+ }
+ }
+ return NULL;
}
// destroy - Delete this node. Only when there are no uses.
diff --git a/lib/VMCore/Pass.cpp b/lib/VMCore/Pass.cpp
index 39da8fb..45000f2 100644
--- a/lib/VMCore/Pass.cpp
+++ b/lib/VMCore/Pass.cpp
@@ -21,6 +21,7 @@
#include "llvm/ADT/StringMap.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ManagedStatic.h"
+#include "llvm/Support/PassNameParser.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/System/Atomic.h"
#include "llvm/System/Mutex.h"
@@ -394,6 +395,8 @@ void PassRegistrationListener::enumeratePasses() {
getPassRegistrar()->EnumerateWith(this);
}
+PassNameParser::~PassNameParser() {}
+
//===----------------------------------------------------------------------===//
// AnalysisUsage Class Implementation
//
diff --git a/lib/VMCore/PassManager.cpp b/lib/VMCore/PassManager.cpp
index b37b2ae..0c0d64e 100644
--- a/lib/VMCore/PassManager.cpp
+++ b/lib/VMCore/PassManager.cpp
@@ -127,6 +127,9 @@ public:
bool doFinalization(Module &M);
bool doFinalization(Function &F);
+ virtual PMDataManager *getAsPMDataManager() { return this; }
+ virtual Pass *getAsPass() { return this; }
+
virtual const char *getPassName() const {
return "BasicBlock Pass Manager";
}
@@ -169,7 +172,7 @@ private:
public:
static char ID;
explicit FunctionPassManagerImpl(int Depth) :
- Pass(&ID), PMDataManager(Depth),
+ Pass(PT_PassManager, &ID), PMDataManager(Depth),
PMTopLevelManager(TLM_Function), wasRun(false) { }
/// add - Add a pass to the queue of passes to run. This passes ownership of
@@ -196,15 +199,17 @@ public:
///
bool doFinalization(Module &M);
+
+ virtual PMDataManager *getAsPMDataManager() { return this; }
+ virtual Pass *getAsPass() { return this; }
+
/// Pass Manager itself does not invalidate any analysis info.
void getAnalysisUsage(AnalysisUsage &Info) const {
Info.setPreservesAll();
}
inline void addTopLevelPass(Pass *P) {
-
- if (ImmutablePass *IP = dynamic_cast<ImmutablePass *> (P)) {
-
+ if (ImmutablePass *IP = P->getAsImmutablePass()) {
// P is a immutable pass and it will be managed by this
// top level manager. Set up analysis resolver to connect them.
AnalysisResolver *AR = new AnalysisResolver(*this);
@@ -236,7 +241,7 @@ class MPPassManager : public Pass, public PMDataManager {
public:
static char ID;
explicit MPPassManager(int Depth) :
- Pass(&ID), PMDataManager(Depth) { }
+ Pass(PT_PassManager, &ID), PMDataManager(Depth) { }
// Delete on the fly managers.
virtual ~MPPassManager() {
@@ -271,6 +276,9 @@ public:
return "Module Pass Manager";
}
+ virtual PMDataManager *getAsPMDataManager() { return this; }
+ virtual Pass *getAsPass() { return this; }
+
// Print passes managed by this manager
void dumpPassStructure(unsigned Offset) {
llvm::dbgs() << std::string(Offset*2, ' ') << "ModulePass Manager\n";
@@ -313,7 +321,8 @@ class PassManagerImpl : public Pass,
public:
static char ID;
explicit PassManagerImpl(int Depth) :
- Pass(&ID), PMDataManager(Depth), PMTopLevelManager(TLM_Pass) { }
+ Pass(PT_PassManager, &ID), PMDataManager(Depth),
+ PMTopLevelManager(TLM_Pass) { }
/// add - Add a pass to the queue of passes to run. This passes ownership of
/// the Pass to the PassManager. When the PassManager is destroyed, the pass
@@ -333,8 +342,7 @@ public:
}
inline void addTopLevelPass(Pass *P) {
- if (ImmutablePass *IP = dynamic_cast<ImmutablePass *> (P)) {
-
+ if (ImmutablePass *IP = P->getAsImmutablePass()) {
// P is a immutable pass and it will be managed by this
// top level manager. Set up analysis resolver to connect them.
AnalysisResolver *AR = new AnalysisResolver(*this);
@@ -347,6 +355,9 @@ public:
}
}
+ virtual PMDataManager *getAsPMDataManager() { return this; }
+ virtual Pass *getAsPass() { return this; }
+
MPPassManager *getContainedManager(unsigned N) {
assert(N < PassManagers.size() && "Pass number out of range!");
MPPassManager *MP = static_cast<MPPassManager *>(PassManagers[N]);
@@ -390,7 +401,7 @@ public:
/// passStarted - This method creates a timer for the given pass if it doesn't
/// already have one, and starts the timer.
Timer *passStarted(Pass *P) {
- if (dynamic_cast<PMDataManager *>(P))
+ if (P->getAsPMDataManager())
return 0;
sys::SmartScopedLock<true> Lock(*TimingInfoMutex);
@@ -584,11 +595,11 @@ void PMTopLevelManager::dumpPasses() const {
// Every class that derives from PMDataManager also derives from Pass
// (sometimes indirectly), but there's no inheritance relationship
- // between PMDataManager and Pass, so we have to dynamic_cast to get
+ // between PMDataManager and Pass, so we have to getAsPass to get
// from a PMDataManager* to a Pass*.
for (SmallVector<PMDataManager *, 8>::const_iterator I = PassManagers.begin(),
E = PassManagers.end(); I != E; ++I)
- dynamic_cast<Pass *>(*I)->dumpPassStructure(1);
+ (*I)->getAsPass()->dumpPassStructure(1);
}
void PMTopLevelManager::dumpArguments() const {
@@ -670,7 +681,7 @@ bool PMDataManager::preserveHigherLevelAnalysis(Pass *P) {
for (SmallVector<Pass *, 8>::iterator I = HigherLevelAnalysis.begin(),
E = HigherLevelAnalysis.end(); I != E; ++I) {
Pass *P1 = *I;
- if (!dynamic_cast<ImmutablePass*>(P1) &&
+ if (P1->getAsImmutablePass() == 0 &&
std::find(PreservedSet.begin(), PreservedSet.end(),
P1->getPassInfo()) ==
PreservedSet.end())
@@ -713,8 +724,8 @@ void PMDataManager::removeNotPreservedAnalysis(Pass *P) {
for (std::map<AnalysisID, Pass*>::iterator I = AvailableAnalysis.begin(),
E = AvailableAnalysis.end(); I != E; ) {
std::map<AnalysisID, Pass*>::iterator Info = I++;
- if (!dynamic_cast<ImmutablePass*>(Info->second)
- && std::find(PreservedSet.begin(), PreservedSet.end(), Info->first) ==
+ if (Info->second->getAsImmutablePass() == 0 &&
+ std::find(PreservedSet.begin(), PreservedSet.end(), Info->first) ==
PreservedSet.end()) {
// Remove this analysis
if (PassDebugging >= Details) {
@@ -737,7 +748,7 @@ void PMDataManager::removeNotPreservedAnalysis(Pass *P) {
I = InheritedAnalysis[Index]->begin(),
E = InheritedAnalysis[Index]->end(); I != E; ) {
std::map<AnalysisID, Pass *>::iterator Info = I++;
- if (!dynamic_cast<ImmutablePass*>(Info->second) &&
+ if (Info->second->getAsImmutablePass() == 0 &&
std::find(PreservedSet.begin(), PreservedSet.end(), Info->first) ==
PreservedSet.end()) {
// Remove this analysis
@@ -854,12 +865,12 @@ void PMDataManager::add(Pass *P, bool ProcessAnalysis) {
// Set P as P's last user until someone starts using P.
// However, if P is a Pass Manager then it does not need
// to record its last user.
- if (!dynamic_cast<PMDataManager *>(P))
+ if (P->getAsPMDataManager() == 0)
LastUses.push_back(P);
TPM->setLastUser(LastUses, P);
if (!TransferLastUses.empty()) {
- Pass *My_PM = dynamic_cast<Pass *>(this);
+ Pass *My_PM = getAsPass();
TPM->setLastUser(TransferLastUses, My_PM);
TransferLastUses.clear();
}
@@ -968,7 +979,7 @@ void PMDataManager::dumpLastUses(Pass *P, unsigned Offset) const{
void PMDataManager::dumpPassArguments() const {
for (SmallVector<Pass *, 8>::const_iterator I = PassVector.begin(),
E = PassVector.end(); I != E; ++I) {
- if (PMDataManager *PMD = dynamic_cast<PMDataManager *>(*I))
+ if (PMDataManager *PMD = (*I)->getAsPMDataManager())
PMD->dumpPassArguments();
else
if (const PassInfo *PI = (*I)->getPassInfo())
@@ -1469,7 +1480,7 @@ Pass* MPPassManager::getOnTheFlyPass(Pass *MP, const PassInfo *PI, Function &F){
FPP->releaseMemoryOnTheFly();
FPP->run(F);
- return (dynamic_cast<PMTopLevelManager *>(FPP))->findAnalysisPass(PI);
+ return ((PMTopLevelManager*)FPP)->findAnalysisPass(PI);
}
@@ -1586,7 +1597,7 @@ void PMStack::push(PMDataManager *PM) {
void PMStack::dump() {
for (std::deque<PMDataManager *>::iterator I = S.begin(),
E = S.end(); I != E; ++I)
- printf("%s ", dynamic_cast<Pass *>(*I)->getPassName());
+ printf("%s ", (*I)->getAsPass()->getPassName());
if (!S.empty())
printf("\n");
@@ -1616,16 +1627,18 @@ void FunctionPass::assignPassManager(PMStack &PMS,
PassManagerType PreferredType) {
// Find Module Pass Manager
- while(!PMS.empty()) {
+ while (!PMS.empty()) {
if (PMS.top()->getPassManagerType() > PMT_FunctionPassManager)
PMS.pop();
else
break;
}
- FPPassManager *FPP = dynamic_cast<FPPassManager *>(PMS.top());
- // Create new Function Pass Manager
- if (!FPP) {
+ // Create new Function Pass Manager if needed.
+ FPPassManager *FPP;
+ if (PMS.top()->getPassManagerType() == PMT_FunctionPassManager) {
+ FPP = (FPPassManager *)PMS.top();
+ } else {
assert(!PMS.empty() && "Unable to create Function Pass Manager");
PMDataManager *PMD = PMS.top();
@@ -1653,17 +1666,16 @@ void FunctionPass::assignPassManager(PMStack &PMS,
/// in the PM Stack and add self into that manager.
void BasicBlockPass::assignPassManager(PMStack &PMS,
PassManagerType PreferredType) {
- BBPassManager *BBP = NULL;
+ BBPassManager *BBP;
// Basic Pass Manager is a leaf pass manager. It does not handle
// any other pass manager.
- if (!PMS.empty())
- BBP = dynamic_cast<BBPassManager *>(PMS.top());
-
- // If leaf manager is not Basic Block Pass manager then create new
- // basic Block Pass manager.
-
- if (!BBP) {
+ if (!PMS.empty() &&
+ PMS.top()->getPassManagerType() == PMT_BasicBlockPassManager) {
+ BBP = (BBPassManager *)PMS.top();
+ } else {
+ // If leaf manager is not Basic Block Pass manager then create new
+ // basic Block Pass manager.
assert(!PMS.empty() && "Unable to create BasicBlock Pass Manager");
PMDataManager *PMD = PMS.top();
diff --git a/lib/VMCore/Verifier.cpp b/lib/VMCore/Verifier.cpp
index ec475e4..76d9d43 100644
--- a/lib/VMCore/Verifier.cpp
+++ b/lib/VMCore/Verifier.cpp
@@ -1301,6 +1301,8 @@ void Verifier::visitAllocaInst(AllocaInst &AI) {
&AI);
Assert1(PTy->getElementType()->isSized(), "Cannot allocate unsized type",
&AI);
+ Assert1(AI.getArraySize()->getType()->isInteger(32),
+ "Alloca array size must be i32", &AI);
visitInstruction(AI);
}
@@ -1579,7 +1581,7 @@ void Verifier::visitIntrinsicFunctionCall(Intrinsic::ID ID, CallInst &CI) {
// If the intrinsic takes MDNode arguments, verify that they are either global
// or are local to *this* function.
- for (unsigned i = 0, e = CI.getNumOperands(); i != e; ++i)
+ for (unsigned i = 1, e = CI.getNumOperands(); i != e; ++i)
if (MDNode *MD = dyn_cast<MDNode>(CI.getOperand(i))) {
if (!MD->isFunctionLocal()) continue;
SmallPtrSet<MDNode *, 32> Visited;
@@ -1589,12 +1591,17 @@ void Verifier::visitIntrinsicFunctionCall(Intrinsic::ID ID, CallInst &CI) {
switch (ID) {
default:
break;
- case Intrinsic::dbg_declare: // llvm.dbg.declare
- if (MDNode *MD = dyn_cast<MDNode>(CI.getOperand(1)))
+ case Intrinsic::dbg_declare: { // llvm.dbg.declare
+ Assert1(CI.getOperand(1) && isa<MDNode>(CI.getOperand(1)),
+ "invalid llvm.dbg.declare intrinsic call 1", &CI);
+ MDNode *MD = cast<MDNode>(CI.getOperand(1));
+ Assert1(MD->getNumOperands() == 1,
+ "invalid llvm.dbg.declare intrinsic call 2", &CI);
+ if (MD->getOperand(0))
if (Constant *C = dyn_cast<Constant>(MD->getOperand(0)))
Assert1(C && !isa<ConstantPointerNull>(C),
- "invalid llvm.dbg.declare intrinsic call", &CI);
- break;
+ "invalid llvm.dbg.declare intrinsic call 3", &CI);
+ } break;
case Intrinsic::memcpy:
case Intrinsic::memmove:
case Intrinsic::memset:
OpenPOWER on IntegriCloud