summaryrefslogtreecommitdiffstats
path: root/lib/VMCore
diff options
context:
space:
mode:
authored <ed@FreeBSD.org>2009-07-04 13:58:26 +0000
committered <ed@FreeBSD.org>2009-07-04 13:58:26 +0000
commit72621d11de5b873f1695f391eb95f0b336c3d2d4 (patch)
tree84360c8989c912127a383af37c4b1aa5767bd16e /lib/VMCore
parentcf5cd875b51255602afaed29deb636b66b295671 (diff)
downloadFreeBSD-src-72621d11de5b873f1695f391eb95f0b336c3d2d4.zip
FreeBSD-src-72621d11de5b873f1695f391eb95f0b336c3d2d4.tar.gz
Import LLVM 74788.
Diffstat (limited to 'lib/VMCore')
-rw-r--r--lib/VMCore/AsmWriter.cpp103
-rw-r--r--lib/VMCore/CMakeLists.txt1
-rw-r--r--lib/VMCore/Core.cpp23
-rw-r--r--lib/VMCore/Function.cpp6
-rw-r--r--lib/VMCore/LLVMContext.cpp489
-rw-r--r--lib/VMCore/LLVMContextImpl.h25
-rw-r--r--lib/VMCore/Module.cpp5
-rw-r--r--lib/VMCore/PassManager.cpp47
-rw-r--r--lib/VMCore/Type.cpp98
-rw-r--r--lib/VMCore/ValueTypes.cpp42
10 files changed, 728 insertions, 111 deletions
diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp
index 73b1ed6..cbf7070 100644
--- a/lib/VMCore/AsmWriter.cpp
+++ b/lib/VMCore/AsmWriter.cpp
@@ -35,6 +35,7 @@
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cctype>
+#include <map>
using namespace llvm;
// Make virtual table appear in this compilation unit.
@@ -945,25 +946,6 @@ static void WriteConstantInt(raw_ostream &Out, const Constant *CV,
return;
}
- if (const MDNode *N = dyn_cast<MDNode>(CV)) {
- Out << "!{";
- for (MDNode::const_elem_iterator I = N->elem_begin(), E = N->elem_end();
- I != E;) {
- if (!*I) {
- Out << "null";
- } else {
- TypePrinter.print((*I)->getType(), Out);
- Out << ' ';
- WriteAsOperandInternal(Out, *I, TypePrinter, Machine);
- }
-
- if (++I != E)
- Out << ", ";
- }
- Out << "}";
- return;
- }
-
if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) {
Out << CE->getOpcodeName();
if (CE->isCompare())
@@ -1092,10 +1074,14 @@ class AssemblyWriter {
TypePrinting TypePrinter;
AssemblyAnnotationWriter *AnnotationWriter;
std::vector<const Type*> NumberedTypes;
+
+ // Each MDNode is assigned unique MetadataIDNo.
+ std::map<const MDNode *, unsigned> MDNodes;
+ unsigned MetadataIDNo;
public:
inline AssemblyWriter(raw_ostream &o, SlotTracker &Mac, const Module *M,
AssemblyAnnotationWriter *AAW)
- : Out(o), Machine(Mac), TheModule(M), AnnotationWriter(AAW) {
+ : Out(o), Machine(Mac), TheModule(M), AnnotationWriter(AAW), MetadataIDNo(0) {
AddModuleTypesToPrinter(TypePrinter, NumberedTypes, M);
}
@@ -1117,6 +1103,7 @@ public:
void writeOperand(const Value *Op, bool PrintType);
void writeParamOperand(const Value *Operand, Attributes Attrs);
+ void printMDNode(const MDNode *Node, bool StandAlone);
const Module* getModule() { return TheModule; }
@@ -1264,6 +1251,28 @@ static void PrintVisibility(GlobalValue::VisibilityTypes Vis,
}
void AssemblyWriter::printGlobal(const GlobalVariable *GV) {
+ if (GV->hasInitializer())
+ // If GV is initialized using Metadata then separate out metadata
+ // operands used by the initializer. Note, MDNodes are not cyclic.
+ if (MDNode *N = dyn_cast<MDNode>(GV->getInitializer())) {
+ SmallVector<const MDNode *, 4> WorkList;
+ // Collect MDNodes used by the initializer.
+ for (MDNode::const_elem_iterator I = N->elem_begin(), E = N->elem_end();
+ I != E; ++I) {
+ const Value *TV = *I;
+ if (TV)
+ if (const MDNode *NN = dyn_cast<MDNode>(TV))
+ WorkList.push_back(NN);
+ }
+
+ // Print MDNodes used by the initializer.
+ while (!WorkList.empty()) {
+ const MDNode *N = WorkList.back(); WorkList.pop_back();
+ printMDNode(N, true);
+ Out << '\n';
+ }
+ }
+
if (GV->hasName()) {
PrintLLVMName(Out, GV);
Out << " = ";
@@ -1283,7 +1292,10 @@ void AssemblyWriter::printGlobal(const GlobalVariable *GV) {
if (GV->hasInitializer()) {
Out << ' ';
- writeOperand(GV->getInitializer(), false);
+ if (MDNode *N = dyn_cast<MDNode>(GV->getInitializer()))
+ printMDNode(N, false);
+ else
+ writeOperand(GV->getInitializer(), false);
}
if (GV->hasSection())
@@ -1295,6 +1307,47 @@ void AssemblyWriter::printGlobal(const GlobalVariable *GV) {
Out << '\n';
}
+void AssemblyWriter::printMDNode(const MDNode *Node,
+ bool StandAlone) {
+ std::map<const MDNode *, unsigned>::iterator MI = MDNodes.find(Node);
+ // If this node is already printed then just refer it using its Metadata
+ // id number.
+ if (MI != MDNodes.end()) {
+ if (!StandAlone)
+ Out << "!" << MI->second;
+ return;
+ }
+
+ if (StandAlone) {
+ // Print standalone MDNode.
+ // !42 = !{ ... }
+ Out << "!" << MetadataIDNo << " = ";
+ Out << "constant metadata ";
+ }
+
+ Out << "!{";
+ for (MDNode::const_elem_iterator I = Node->elem_begin(), E = Node->elem_end();
+ I != E;) {
+ const Value *TV = *I;
+ if (!TV)
+ Out << "null";
+ else if (const MDNode *N = dyn_cast<MDNode>(TV)) {
+ TypePrinter.print(N->getType(), Out);
+ Out << ' ';
+ printMDNode(N, StandAlone);
+ }
+ else if (!*I)
+ Out << "null";
+ else
+ writeOperand(*I, true);
+ if (++I != E)
+ Out << ", ";
+ }
+ Out << "}";
+
+ MDNodes[Node] = MetadataIDNo++;
+}
+
void AssemblyWriter::printAlias(const GlobalAlias *GA) {
// Don't crash when dumping partially built GA
if (!GA->hasName())
@@ -1852,6 +1905,14 @@ void Value::print(raw_ostream &OS, AssemblyAnnotationWriter *AAW) const {
SlotTracker SlotTable(GV->getParent());
AssemblyWriter W(OS, SlotTable, GV->getParent(), AAW);
W.write(GV);
+ } else if (const MDNode *N = dyn_cast<MDNode>(this)) {
+ TypePrinting TypePrinter;
+ TypePrinter.print(N->getType(), OS);
+ OS << ' ';
+ // FIXME: Do we need a slot tracker for metadata ?
+ SlotTracker SlotTable((const Function *)NULL);
+ AssemblyWriter W(OS, SlotTable, NULL, AAW);
+ W.printMDNode(N, false);
} else if (const Constant *C = dyn_cast<Constant>(this)) {
TypePrinting TypePrinter;
TypePrinter.print(C->getType(), OS);
diff --git a/lib/VMCore/CMakeLists.txt b/lib/VMCore/CMakeLists.txt
index d78e093..c9cdce4 100644
--- a/lib/VMCore/CMakeLists.txt
+++ b/lib/VMCore/CMakeLists.txt
@@ -14,6 +14,7 @@ add_llvm_library(LLVMCore
Instructions.cpp
IntrinsicInst.cpp
LeakDetector.cpp
+ LLVMContext.cpp
Mangler.cpp
Module.cpp
ModuleProvider.cpp
diff --git a/lib/VMCore/Core.cpp b/lib/VMCore/Core.cpp
index f85dbe7..6eb1889 100644
--- a/lib/VMCore/Core.cpp
+++ b/lib/VMCore/Core.cpp
@@ -18,6 +18,7 @@
#include "llvm/DerivedTypes.h"
#include "llvm/GlobalVariable.h"
#include "llvm/GlobalAlias.h"
+#include "llvm/LLVMContext.h"
#include "llvm/TypeSymbolTable.h"
#include "llvm/ModuleProvider.h"
#include "llvm/InlineAsm.h"
@@ -38,10 +39,30 @@ void LLVMDisposeMessage(char *Message) {
}
+/*===-- Operations on contexts --------------------------------------------===*/
+
+LLVMContextRef LLVMContextCreate() {
+ return wrap(new LLVMContext());
+}
+
+LLVMContextRef LLVMGetGlobalContext() {
+ return wrap(&getGlobalContext());
+}
+
+void LLVMContextDispose(LLVMContextRef C) {
+ delete unwrap(C);
+}
+
+
/*===-- Operations on modules ---------------------------------------------===*/
LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID) {
- return wrap(new Module(ModuleID));
+ return wrap(new Module(ModuleID, getGlobalContext()));
+}
+
+LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
+ LLVMContextRef C) {
+ return wrap(new Module(ModuleID, *unwrap(C)));
}
void LLVMDisposeModule(LLVMModuleRef M) {
diff --git a/lib/VMCore/Function.cpp b/lib/VMCore/Function.cpp
index 0450566..eeade05 100644
--- a/lib/VMCore/Function.cpp
+++ b/lib/VMCore/Function.cpp
@@ -114,6 +114,12 @@ void Argument::removeAttr(Attributes attr) {
// Helper Methods in Function
//===----------------------------------------------------------------------===//
+LLVMContext* Function::getContext() {
+ Module* M = getParent();
+ if (M) return &M->getContext();
+ return 0;
+}
+
const FunctionType *Function::getFunctionType() const {
return cast<FunctionType>(getType()->getElementType());
}
diff --git a/lib/VMCore/LLVMContext.cpp b/lib/VMCore/LLVMContext.cpp
new file mode 100644
index 0000000..fe2cb7b
--- /dev/null
+++ b/lib/VMCore/LLVMContext.cpp
@@ -0,0 +1,489 @@
+//===-- LLVMContext.cpp - Implement LLVMContext -----------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements LLVMContext, as a wrapper around the opaque
+// class LLVMContextImpl.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/LLVMContext.h"
+#include "llvm/Constants.h"
+#include "llvm/DerivedTypes.h"
+#include "llvm/MDNode.h"
+#include "llvm/Support/ManagedStatic.h"
+#include "LLVMContextImpl.h"
+
+using namespace llvm;
+
+static ManagedStatic<LLVMContext> GlobalContext;
+
+LLVMContext& llvm::getGlobalContext() {
+ return *GlobalContext;
+}
+
+LLVMContext::LLVMContext() : pImpl(new LLVMContextImpl()) { }
+LLVMContext::~LLVMContext() { delete pImpl; }
+
+// Constant accessors
+Constant* LLVMContext::getNullValue(const Type* Ty) {
+ return Constant::getNullValue(Ty);
+}
+
+Constant* LLVMContext::getAllOnesValue(const Type* Ty) {
+ return Constant::getAllOnesValue(Ty);
+}
+
+// UndefValue accessors.
+UndefValue* LLVMContext::getUndef(const Type* Ty) {
+ return UndefValue::get(Ty);
+}
+
+// ConstantInt accessors.
+ConstantInt* LLVMContext::getConstantIntTrue() {
+ return ConstantInt::getTrue();
+}
+
+ConstantInt* LLVMContext::getConstantIntFalse() {
+ return ConstantInt::getFalse();
+}
+
+Constant* LLVMContext::getConstantInt(const Type* Ty, uint64_t V,
+ bool isSigned) {
+ return ConstantInt::get(Ty, V, isSigned);
+}
+
+
+ConstantInt* LLVMContext::getConstantInt(const IntegerType* Ty, uint64_t V,
+ bool isSigned) {
+ return ConstantInt::get(Ty, V, isSigned);
+}
+
+ConstantInt* LLVMContext::getConstantIntSigned(const IntegerType* Ty,
+ int64_t V) {
+ return ConstantInt::getSigned(Ty, V);
+}
+
+ConstantInt* LLVMContext::getConstantInt(const APInt& V) {
+ return ConstantInt::get(V);
+}
+
+Constant* LLVMContext::getConstantInt(const Type* Ty, const APInt& V) {
+ return ConstantInt::get(Ty, V);
+}
+
+ConstantInt* LLVMContext::getConstantIntAllOnesValue(const Type* Ty) {
+ return ConstantInt::getAllOnesValue(Ty);
+}
+
+
+// ConstantPointerNull accessors.
+ConstantPointerNull* LLVMContext::getConstantPointerNull(const PointerType* T) {
+ return ConstantPointerNull::get(T);
+}
+
+
+// ConstantStruct accessors.
+Constant* LLVMContext::getConstantStruct(const StructType* T,
+ const std::vector<Constant*>& V) {
+ return ConstantStruct::get(T, V);
+}
+
+Constant* LLVMContext::getConstantStruct(const std::vector<Constant*>& V,
+ bool Packed) {
+ return ConstantStruct::get(V, Packed);
+}
+
+Constant* LLVMContext::getConstantStruct(Constant* const *Vals,
+ unsigned NumVals, bool Packed) {
+ return ConstantStruct::get(Vals, NumVals, Packed);
+}
+
+
+// ConstantAggregateZero accessors.
+ConstantAggregateZero* LLVMContext::getConstantAggregateZero(const Type* Ty) {
+ return ConstantAggregateZero::get(Ty);
+}
+
+
+// ConstantArray accessors.
+Constant* LLVMContext::getConstantArray(const ArrayType* T,
+ const std::vector<Constant*>& V) {
+ return ConstantArray::get(T, V);
+}
+
+Constant* LLVMContext::getConstantArray(const ArrayType* T,
+ Constant* const* Vals,
+ unsigned NumVals) {
+ return ConstantArray::get(T, Vals, NumVals);
+}
+
+Constant* LLVMContext::getConstantArray(const std::string& Initializer,
+ bool AddNull) {
+ return ConstantArray::get(Initializer, AddNull);
+}
+
+
+// ConstantExpr accessors.
+Constant* LLVMContext::getConstantExpr(unsigned Opcode, Constant* C1,
+ Constant* C2) {
+ return ConstantExpr::get(Opcode, C1, C2);
+}
+
+Constant* LLVMContext::getConstantExprTrunc(Constant* C, const Type* Ty) {
+ return ConstantExpr::getTrunc(C, Ty);
+}
+
+Constant* LLVMContext::getConstantExprSExt(Constant* C, const Type* Ty) {
+ return ConstantExpr::getSExt(C, Ty);
+}
+
+Constant* LLVMContext::getConstantExprZExt(Constant* C, const Type* Ty) {
+ return ConstantExpr::getZExt(C, Ty);
+}
+
+Constant* LLVMContext::getConstantExprFPTrunc(Constant* C, const Type* Ty) {
+ return ConstantExpr::getFPTrunc(C, Ty);
+}
+
+Constant* LLVMContext::getConstantExprFPExtend(Constant* C, const Type* Ty) {
+ return ConstantExpr::getFPExtend(C, Ty);
+}
+
+Constant* LLVMContext::getConstantExprUIToFP(Constant* C, const Type* Ty) {
+ return ConstantExpr::getUIToFP(C, Ty);
+}
+
+Constant* LLVMContext::getConstantExprSIToFP(Constant* C, const Type* Ty) {
+ return ConstantExpr::getSIToFP(C, Ty);
+}
+
+Constant* LLVMContext::getConstantExprFPToUI(Constant* C, const Type* Ty) {
+ return ConstantExpr::getFPToUI(C, Ty);
+}
+
+Constant* LLVMContext::getConstantExprFPToSI(Constant* C, const Type* Ty) {
+ return ConstantExpr::getFPToSI(C, Ty);
+}
+
+Constant* LLVMContext::getConstantExprPtrToInt(Constant* C, const Type* Ty) {
+ return ConstantExpr::getPtrToInt(C, Ty);
+}
+
+Constant* LLVMContext::getConstantExprIntToPtr(Constant* C, const Type* Ty) {
+ return ConstantExpr::getIntToPtr(C, Ty);
+}
+
+Constant* LLVMContext::getConstantExprBitCast(Constant* C, const Type* Ty) {
+ return ConstantExpr::getBitCast(C, Ty);
+}
+
+Constant* LLVMContext::getConstantExprCast(unsigned ops, Constant* C,
+ const Type* Ty) {
+ return ConstantExpr::getCast(ops, C, Ty);
+}
+
+Constant* LLVMContext::getConstantExprZExtOrBitCast(Constant* C,
+ const Type* Ty) {
+ return ConstantExpr::getZExtOrBitCast(C, Ty);
+}
+
+Constant* LLVMContext::getConstantExprSExtOrBitCast(Constant* C,
+ const Type* Ty) {
+ return ConstantExpr::getSExtOrBitCast(C, Ty);
+}
+
+Constant* LLVMContext::getConstantExprTruncOrBitCast(Constant* C,
+ const Type* Ty) {
+ return ConstantExpr::getTruncOrBitCast(C, Ty);
+}
+
+Constant* LLVMContext::getConstantExprPointerCast(Constant* C, const Type* Ty) {
+ return ConstantExpr::getPointerCast(C, Ty);
+}
+
+Constant* LLVMContext::getConstantExprIntegerCast(Constant* C, const Type* Ty,
+ bool isSigned) {
+ return ConstantExpr::getIntegerCast(C, Ty, isSigned);
+}
+
+Constant* LLVMContext::getConstantExprFPCast(Constant* C, const Type* Ty) {
+ return ConstantExpr::getFPCast(C, Ty);
+}
+
+Constant* LLVMContext::getConstantExprSelect(Constant* C, Constant* V1,
+ Constant* V2) {
+ return ConstantExpr::getSelect(C, V1, V2);
+}
+
+Constant* LLVMContext::getConstantExprAlignOf(const Type* Ty) {
+ return ConstantExpr::getAlignOf(Ty);
+}
+
+Constant* LLVMContext::getConstantExprCompare(unsigned short pred,
+ Constant* C1, Constant* C2) {
+ return ConstantExpr::getCompare(pred, C1, C2);
+}
+
+Constant* LLVMContext::getConstantExprNeg(Constant* C) {
+ return ConstantExpr::getNeg(C);
+}
+
+Constant* LLVMContext::getConstantExprFNeg(Constant* C) {
+ return ConstantExpr::getFNeg(C);
+}
+
+Constant* LLVMContext::getConstantExprNot(Constant* C) {
+ return ConstantExpr::getNot(C);
+}
+
+Constant* LLVMContext::getConstantExprAdd(Constant* C1, Constant* C2) {
+ return ConstantExpr::getAdd(C1, C2);
+}
+
+Constant* LLVMContext::getConstantExprFAdd(Constant* C1, Constant* C2) {
+ return ConstantExpr::getFAdd(C1, C2);
+}
+
+Constant* LLVMContext::getConstantExprSub(Constant* C1, Constant* C2) {
+ return ConstantExpr::getSub(C1, C2);
+}
+
+Constant* LLVMContext::getConstantExprFSub(Constant* C1, Constant* C2) {
+ return ConstantExpr::getFSub(C1, C2);
+}
+
+Constant* LLVMContext::getConstantExprMul(Constant* C1, Constant* C2) {
+ return ConstantExpr::getMul(C1, C2);
+}
+
+Constant* LLVMContext::getConstantExprFMul(Constant* C1, Constant* C2) {
+ return ConstantExpr::getFMul(C1, C2);
+}
+
+Constant* LLVMContext::getConstantExprUDiv(Constant* C1, Constant* C2) {
+ return ConstantExpr::getUDiv(C1, C2);
+}
+
+Constant* LLVMContext::getConstantExprSDiv(Constant* C1, Constant* C2) {
+ return ConstantExpr::getSDiv(C1, C2);
+}
+
+Constant* LLVMContext::getConstantExprFDiv(Constant* C1, Constant* C2) {
+ return ConstantExpr::getFDiv(C1, C2);
+}
+
+Constant* LLVMContext::getConstantExprURem(Constant* C1, Constant* C2) {
+ return ConstantExpr::getURem(C1, C2);
+}
+
+Constant* LLVMContext::getConstantExprSRem(Constant* C1, Constant* C2) {
+ return ConstantExpr::getSRem(C1, C2);
+}
+
+Constant* LLVMContext::getConstantExprFRem(Constant* C1, Constant* C2) {
+ return ConstantExpr::getFRem(C1, C2);
+}
+
+Constant* LLVMContext::getConstantExprAnd(Constant* C1, Constant* C2) {
+ return ConstantExpr::getAnd(C1, C2);
+}
+
+Constant* LLVMContext::getConstantExprOr(Constant* C1, Constant* C2) {
+ return ConstantExpr::getOr(C1, C2);
+}
+
+Constant* LLVMContext::getConstantExprXor(Constant* C1, Constant* C2) {
+ return ConstantExpr::getXor(C1, C2);
+}
+
+Constant* LLVMContext::getConstantExprICmp(unsigned short pred, Constant* LHS,
+ Constant* RHS) {
+ return ConstantExpr::getICmp(pred, LHS, RHS);
+}
+
+Constant* LLVMContext::getConstantExprFCmp(unsigned short pred, Constant* LHS,
+ Constant* RHS) {
+ return ConstantExpr::getFCmp(pred, LHS, RHS);
+}
+
+Constant* LLVMContext::getConstantExprVICmp(unsigned short pred, Constant* LHS,
+ Constant* RHS) {
+ return ConstantExpr::getVICmp(pred, LHS, RHS);
+}
+
+Constant* LLVMContext::getConstantExprVFCmp(unsigned short pred, Constant* LHS,
+ Constant* RHS) {
+ return ConstantExpr::getVFCmp(pred, LHS, RHS);
+}
+
+Constant* LLVMContext::getConstantExprShl(Constant* C1, Constant* C2) {
+ return ConstantExpr::getShl(C1, C2);
+}
+
+Constant* LLVMContext::getConstantExprLShr(Constant* C1, Constant* C2) {
+ return ConstantExpr::getLShr(C1, C2);
+}
+
+Constant* LLVMContext::getConstantExprAShr(Constant* C1, Constant* C2) {
+ return ConstantExpr::getAShr(C1, C2);
+}
+
+Constant* LLVMContext::getConstantExprGetElementPtr(Constant* C,
+ Constant* const* IdxList,
+ unsigned NumIdx) {
+ return ConstantExpr::getGetElementPtr(C, IdxList, NumIdx);
+}
+
+Constant* LLVMContext::getConstantExprGetElementPtr(Constant* C,
+ Value* const* IdxList,
+ unsigned NumIdx) {
+ return ConstantExpr::getGetElementPtr(C, IdxList, NumIdx);
+}
+
+Constant* LLVMContext::getConstantExprExtractElement(Constant* Vec,
+ Constant* Idx) {
+ return ConstantExpr::getExtractElement(Vec, Idx);
+}
+
+Constant* LLVMContext::getConstantExprInsertElement(Constant* Vec,
+ Constant* Elt,
+ Constant* Idx) {
+ return ConstantExpr::getInsertElement(Vec, Elt, Idx);
+}
+
+Constant* LLVMContext::getConstantExprShuffleVector(Constant* V1, Constant* V2,
+ Constant* Mask) {
+ return ConstantExpr::getShuffleVector(V1, V2, Mask);
+}
+
+Constant* LLVMContext::getConstantExprExtractValue(Constant* Agg,
+ const unsigned* IdxList,
+ unsigned NumIdx) {
+ return ConstantExpr::getExtractValue(Agg, IdxList, NumIdx);
+}
+
+Constant* LLVMContext::getConstantExprInsertValue(Constant* Agg, Constant* Val,
+ const unsigned* IdxList,
+ unsigned NumIdx) {
+ return ConstantExpr::getInsertValue(Agg, Val, IdxList, NumIdx);
+}
+
+Constant* LLVMContext::getZeroValueForNegation(const Type* Ty) {
+ return ConstantExpr::getZeroValueForNegationExpr(Ty);
+}
+
+
+// ConstantFP accessors.
+ConstantFP* LLVMContext::getConstantFP(const APFloat& V) {
+ return ConstantFP::get(V);
+}
+
+Constant* LLVMContext::getConstantFP(const Type* Ty, double V) {
+ return ConstantFP::get(Ty, V);
+}
+
+ConstantFP* LLVMContext::getConstantFPNegativeZero(const Type* Ty) {
+ return ConstantFP::getNegativeZero(Ty);
+}
+
+
+// ConstantVector accessors.
+Constant* LLVMContext::getConstantVector(const VectorType* T,
+ const std::vector<Constant*>& V) {
+ return ConstantVector::get(T, V);
+}
+
+Constant* LLVMContext::getConstantVector(const std::vector<Constant*>& V) {
+ return ConstantVector::get(V);
+}
+
+Constant* LLVMContext::getConstantVector(Constant* const* Vals,
+ unsigned NumVals) {
+ return ConstantVector::get(Vals, NumVals);
+}
+
+ConstantVector* LLVMContext::getConstantVectorAllOnesValue(
+ const VectorType* Ty) {
+ return ConstantVector::getAllOnesValue(Ty);
+}
+
+// MDNode accessors
+MDNode* LLVMContext::getMDNode(Value* const* Vals, unsigned NumVals) {
+ return MDNode::get(Vals, NumVals);
+}
+
+// MDString accessors
+MDString* LLVMContext::getMDString(const char *StrBegin, const char *StrEnd) {
+ return MDString::get(StrBegin, StrEnd);
+}
+
+MDString* LLVMContext::getMDString(const std::string &Str) {
+ return MDString::get(Str);
+}
+
+// FunctionType accessors
+FunctionType* LLVMContext::getFunctionType(const Type* Result,
+ const std::vector<const Type*>& Params,
+ bool isVarArg) {
+ return FunctionType::get(Result, Params, isVarArg);
+}
+
+// IntegerType accessors
+const IntegerType* LLVMContext::getIntegerType(unsigned NumBits) {
+ return IntegerType::get(NumBits);
+}
+
+// OpaqueType accessors
+OpaqueType* LLVMContext::getOpaqueType() {
+ return OpaqueType::get();
+}
+
+// StructType accessors
+StructType* LLVMContext::getStructType(bool isPacked) {
+ return StructType::get(isPacked);
+}
+
+StructType* LLVMContext::getStructType(const std::vector<const Type*>& Params,
+ bool isPacked) {
+ return StructType::get(Params, isPacked);
+}
+
+// ArrayType accessors
+ArrayType* LLVMContext::getArrayType(const Type* ElementType,
+ uint64_t NumElements) {
+ return ArrayType::get(ElementType, NumElements);
+}
+
+// PointerType accessors
+PointerType* LLVMContext::getPointerType(const Type* ElementType,
+ unsigned AddressSpace) {
+ return PointerType::get(ElementType, AddressSpace);
+}
+
+PointerType* LLVMContext::getPointerTypeUnqual(const Type* ElementType) {
+ return PointerType::getUnqual(ElementType);
+}
+
+// VectorType accessors
+VectorType* LLVMContext::getVectorType(const Type* ElementType,
+ unsigned NumElements) {
+ return VectorType::get(ElementType, NumElements);
+}
+
+VectorType* LLVMContext::getVectorTypeInteger(const VectorType* VTy) {
+ return VectorType::getInteger(VTy);
+}
+
+VectorType* LLVMContext::getVectorTypeExtendedElement(const VectorType* VTy) {
+ return VectorType::getExtendedElementVectorType(VTy);
+}
+
+VectorType* LLVMContext::getVectorTypeTruncatedElement(const VectorType* VTy) {
+ return VectorType::getTruncatedElementVectorType(VTy);
+}
diff --git a/lib/VMCore/LLVMContextImpl.h b/lib/VMCore/LLVMContextImpl.h
new file mode 100644
index 0000000..4e089fb
--- /dev/null
+++ b/lib/VMCore/LLVMContextImpl.h
@@ -0,0 +1,25 @@
+//===-- llvm/SymbolTableListTraitsImpl.h - Implementation ------*- C++ -*--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file declares LLVMContextImpl, the opaque implementation
+// of LLVMContext.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LLVMCONTEXT_IMPL_H
+#define LLVM_LLVMCONTEXT_IMPL_H
+
+namespace llvm {
+class LLVMContextImpl {
+
+};
+
+}
+
+#endif
diff --git a/lib/VMCore/Module.cpp b/lib/VMCore/Module.cpp
index a598005..f057e81 100644
--- a/lib/VMCore/Module.cpp
+++ b/lib/VMCore/Module.cpp
@@ -15,6 +15,7 @@
#include "llvm/InstrTypes.h"
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
+#include "llvm/LLVMContext.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/LeakDetector.h"
@@ -54,8 +55,8 @@ template class SymbolTableListTraits<GlobalAlias, Module>;
// Primitive Module methods.
//
-Module::Module(const std::string &MID)
- : ModuleID(MID), DataLayout("") {
+Module::Module(const std::string &MID, LLVMContext& C)
+ : Context(C), ModuleID(MID), DataLayout("") {
ValSymTab = new ValueSymbolTable();
TypeSymTab = new TypeSymbolTable();
}
diff --git a/lib/VMCore/PassManager.cpp b/lib/VMCore/PassManager.cpp
index 86cf10e..46f1243 100644
--- a/lib/VMCore/PassManager.cpp
+++ b/lib/VMCore/PassManager.cpp
@@ -165,11 +165,13 @@ namespace llvm {
class FunctionPassManagerImpl : public Pass,
public PMDataManager,
public PMTopLevelManager {
+private:
+ bool wasRun;
public:
static char ID;
explicit FunctionPassManagerImpl(int Depth) :
Pass(&ID), PMDataManager(Depth),
- PMTopLevelManager(TLM_Function) { }
+ PMTopLevelManager(TLM_Function), wasRun(false) { }
/// 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
@@ -179,6 +181,10 @@ public:
schedulePass(P);
}
+ // Prepare for running an on the fly pass, freeing memory if needed
+ // from a previous run.
+ void releaseMemoryOnTheFly();
+
/// run - Execute all of the passes scheduled for execution. Keep track of
/// whether any of the passes modifies the module, and if so, return true.
bool run(Function &F);
@@ -272,8 +278,10 @@ public:
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
ModulePass *MP = getContainedPass(Index);
MP->dumpPassStructure(Offset + 1);
- if (FunctionPassManagerImpl *FPP = OnTheFlyManagers[MP])
- FPP->dumpPassStructure(Offset + 2);
+ std::map<Pass *, FunctionPassManagerImpl *>::const_iterator I =
+ OnTheFlyManagers.find(MP);
+ if (I != OnTheFlyManagers.end())
+ I->second->dumpPassStructure(Offset + 2);
dumpLastUses(MP, Offset+1);
}
}
@@ -1290,6 +1298,18 @@ void FPPassManager::cleanup() {
}
}
+void FunctionPassManagerImpl::releaseMemoryOnTheFly() {
+ if (!wasRun)
+ return;
+ for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
+ FPPassManager *FPPM = getContainedManager(Index);
+ for (unsigned Index = 0; Index < FPPM->getNumContainedPasses(); ++Index) {
+ FPPM->getContainedPass(Index)->releaseMemory();
+ }
+ }
+ wasRun = false;
+}
+
// Execute all the passes managed by this top level manager.
// Return true if any function is modified by a pass.
bool FunctionPassManagerImpl::run(Function &F) {
@@ -1306,6 +1326,7 @@ bool FunctionPassManagerImpl::run(Function &F) {
for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index)
getContainedManager(Index)->cleanup();
+ wasRun = true;
return Changed;
}
@@ -1404,6 +1425,14 @@ bool
MPPassManager::runOnModule(Module &M) {
bool Changed = false;
+ // Initialize on-the-fly passes
+ for (std::map<Pass *, FunctionPassManagerImpl *>::iterator
+ I = OnTheFlyManagers.begin(), E = OnTheFlyManagers.end();
+ I != E; ++I) {
+ FunctionPassManagerImpl *FPP = I->second;
+ Changed |= FPP->doInitialization(M);
+ }
+
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
ModulePass *MP = getContainedPass(Index);
@@ -1430,6 +1459,17 @@ MPPassManager::runOnModule(Module &M) {
recordAvailableAnalysis(MP);
removeDeadPasses(MP, M.getModuleIdentifier().c_str(), ON_MODULE_MSG);
}
+
+ // Finalize on-the-fly passes
+ for (std::map<Pass *, FunctionPassManagerImpl *>::iterator
+ I = OnTheFlyManagers.begin(), E = OnTheFlyManagers.end();
+ I != E; ++I) {
+ FunctionPassManagerImpl *FPP = I->second;
+ // We don't know when is the last time an on-the-fly pass is run,
+ // so we need to releaseMemory / finalize here
+ FPP->releaseMemoryOnTheFly();
+ Changed |= FPP->doFinalization(M);
+ }
return Changed;
}
@@ -1466,6 +1506,7 @@ Pass* MPPassManager::getOnTheFlyPass(Pass *MP, const PassInfo *PI, Function &F){
FunctionPassManagerImpl *FPP = OnTheFlyManagers[MP];
assert(FPP && "Unable to find on the fly pass");
+ FPP->releaseMemoryOnTheFly();
FPP->run(F);
return (dynamic_cast<PMTopLevelManager *>(FPP))->findAnalysisPass(PI);
}
diff --git a/lib/VMCore/Type.cpp b/lib/VMCore/Type.cpp
index 5df7f12..40d7517 100644
--- a/lib/VMCore/Type.cpp
+++ b/lib/VMCore/Type.cpp
@@ -43,8 +43,8 @@ AbstractTypeUser::~AbstractTypeUser() {}
// Type Class Implementation
//===----------------------------------------------------------------------===//
-// Reader/writer lock used for guarding access to the type maps.
-static ManagedStatic<sys::SmartRWMutex<true> > TypeMapLock;
+// Lock used for guarding access to the type maps.
+static ManagedStatic<sys::SmartMutex<true> > TypeMapLock;
// Recursive lock used for guarding access to AbstractTypeUsers.
// NOTE: The true template parameter means this will no-op when we're not in
@@ -1006,23 +1006,13 @@ const IntegerType *IntegerType::get(unsigned NumBits) {
// First, see if the type is already in the table, for which
// a reader lock suffices.
- TypeMapLock->reader_acquire();
+ sys::SmartScopedLock<true> L(&*TypeMapLock);
ITy = IntegerTypes->get(IVT);
- TypeMapLock->reader_release();
if (!ITy) {
- // OK, not in the table, get a writer lock.
- sys::SmartScopedWriter<true> Writer(&*TypeMapLock);
- ITy = IntegerTypes->get(IVT);
-
- // We need to _recheck_ the table in case someone
- // put it in between when we released the reader lock
- // and when we gained the writer lock!
- if (!ITy) {
- // Value not found. Derive a new type!
- ITy = new IntegerType(NumBits);
- IntegerTypes->add(IVT, ITy);
- }
+ // Value not found. Derive a new type!
+ ITy = new IntegerType(NumBits);
+ IntegerTypes->add(IVT, ITy);
}
#ifdef DEBUG_MERGE_TYPES
DOUT << "Derived new type: " << *ITy << "\n";
@@ -1089,23 +1079,14 @@ FunctionType *FunctionType::get(const Type *ReturnType,
FunctionValType VT(ReturnType, Params, isVarArg);
FunctionType *FT = 0;
- TypeMapLock->reader_acquire();
+ sys::SmartScopedLock<true> L(&*TypeMapLock);
FT = FunctionTypes->get(VT);
- TypeMapLock->reader_release();
if (!FT) {
- sys::SmartScopedWriter<true> Writer(&*TypeMapLock);
-
- // Have to check again here, because it might have
- // been inserted between when we release the reader
- // lock and when we acquired the writer lock.
- FT = FunctionTypes->get(VT);
- if (!FT) {
- FT = (FunctionType*) operator new(sizeof(FunctionType) +
- sizeof(PATypeHandle)*(Params.size()+1));
- new (FT) FunctionType(ReturnType, Params, isVarArg);
- FunctionTypes->add(VT, FT);
- }
+ FT = (FunctionType*) operator new(sizeof(FunctionType) +
+ sizeof(PATypeHandle)*(Params.size()+1));
+ new (FT) FunctionType(ReturnType, Params, isVarArg);
+ FunctionTypes->add(VT, FT);
}
#ifdef DEBUG_MERGE_TYPES
@@ -1148,19 +1129,12 @@ ArrayType *ArrayType::get(const Type *ElementType, uint64_t NumElements) {
ArrayValType AVT(ElementType, NumElements);
ArrayType *AT = 0;
- TypeMapLock->reader_acquire();
+ sys::SmartScopedLock<true> L(&*TypeMapLock);
AT = ArrayTypes->get(AVT);
- TypeMapLock->reader_release();
-
+
if (!AT) {
- sys::SmartScopedWriter<true> Writer(&*TypeMapLock);
-
- // Recheck. Might have changed between release and acquire.
- AT = ArrayTypes->get(AVT);
- if (!AT) {
- // Value not found. Derive a new type!
- ArrayTypes->add(AVT, AT = new ArrayType(ElementType, NumElements));
- }
+ // Value not found. Derive a new type!
+ ArrayTypes->add(AVT, AT = new ArrayType(ElementType, NumElements));
}
#ifdef DEBUG_MERGE_TYPES
DOUT << "Derived new type: " << *AT << "\n";
@@ -1214,17 +1188,11 @@ VectorType *VectorType::get(const Type *ElementType, unsigned NumElements) {
VectorValType PVT(ElementType, NumElements);
VectorType *PT = 0;
- TypeMapLock->reader_acquire();
+ sys::SmartScopedLock<true> L(&*TypeMapLock);
PT = VectorTypes->get(PVT);
- TypeMapLock->reader_release();
if (!PT) {
- sys::SmartScopedWriter<true> Writer(&*TypeMapLock);
- PT = VectorTypes->get(PVT);
- // Recheck. Might have changed between release and acquire.
- if (!PT) {
- VectorTypes->add(PVT, PT = new VectorType(ElementType, NumElements));
- }
+ VectorTypes->add(PVT, PT = new VectorType(ElementType, NumElements));
}
#ifdef DEBUG_MERGE_TYPES
DOUT << "Derived new type: " << *PT << "\n";
@@ -1282,21 +1250,15 @@ StructType *StructType::get(const std::vector<const Type*> &ETypes,
StructValType STV(ETypes, isPacked);
StructType *ST = 0;
- TypeMapLock->reader_acquire();
+ sys::SmartScopedLock<true> L(&*TypeMapLock);
ST = StructTypes->get(STV);
- TypeMapLock->reader_release();
if (!ST) {
- sys::SmartScopedWriter<true> Writer(&*TypeMapLock);
- ST = StructTypes->get(STV);
- // Recheck. Might have changed between release and acquire.
- if (!ST) {
- // Value not found. Derive a new type!
- ST = (StructType*) operator new(sizeof(StructType) +
- sizeof(PATypeHandle) * ETypes.size());
- new (ST) StructType(ETypes, isPacked);
- StructTypes->add(STV, ST);
- }
+ // Value not found. Derive a new type!
+ ST = (StructType*) operator new(sizeof(StructType) +
+ sizeof(PATypeHandle) * ETypes.size());
+ new (ST) StructType(ETypes, isPacked);
+ StructTypes->add(STV, ST);
}
#ifdef DEBUG_MERGE_TYPES
DOUT << "Derived new type: " << *ST << "\n";
@@ -1367,18 +1329,12 @@ PointerType *PointerType::get(const Type *ValueType, unsigned AddressSpace) {
PointerType *PT = 0;
- TypeMapLock->reader_acquire();
+ sys::SmartScopedLock<true> L(&*TypeMapLock);
PT = PointerTypes->get(PVT);
- TypeMapLock->reader_release();
if (!PT) {
- sys::SmartScopedWriter<true> Writer(&*TypeMapLock);
- PT = PointerTypes->get(PVT);
- // Recheck. Might have changed between release and acquire.
- if (!PT) {
- // Value not found. Derive a new type!
- PointerTypes->add(PVT, PT = new PointerType(ValueType, AddressSpace));
- }
+ // Value not found. Derive a new type!
+ PointerTypes->add(PVT, PT = new PointerType(ValueType, AddressSpace));
}
#ifdef DEBUG_MERGE_TYPES
DOUT << "Derived new type: " << *PT << "\n";
@@ -1532,7 +1488,7 @@ void DerivedType::unlockedRefineAbstractTypeTo(const Type *NewType) {
void DerivedType::refineAbstractTypeTo(const Type *NewType) {
// All recursive calls will go through unlockedRefineAbstractTypeTo,
// to avoid deadlock problems.
- sys::SmartScopedWriter<true> Writer(&*TypeMapLock);
+ sys::SmartScopedLock<true> L(&*TypeMapLock);
unlockedRefineAbstractTypeTo(NewType);
}
diff --git a/lib/VMCore/ValueTypes.cpp b/lib/VMCore/ValueTypes.cpp
index fe4af05..2d207ee 100644
--- a/lib/VMCore/ValueTypes.cpp
+++ b/lib/VMCore/ValueTypes.cpp
@@ -54,6 +54,10 @@ bool MVT::isExtended128BitVector() const {
return isExtendedVector() && getSizeInBits() == 128;
}
+bool MVT::isExtended256BitVector() const {
+ return isExtendedVector() && getSizeInBits() == 256;
+}
+
MVT MVT::getExtendedVectorElementType() const {
assert(isExtended() && "Type is not extended!");
return MVT::getMVT(cast<VectorType>(LLVMTy)->getElementType());
@@ -101,20 +105,26 @@ std::string MVT::getMVTString() const {
case MVT::Flag: return "flag";
case MVT::v2i8: return "v2i8";
case MVT::v4i8: return "v4i8";
- case MVT::v2i16: return "v2i16";
case MVT::v8i8: return "v8i8";
- case MVT::v4i16: return "v4i16";
- case MVT::v2i32: return "v2i32";
- case MVT::v1i64: return "v1i64";
case MVT::v16i8: return "v16i8";
+ case MVT::v32i8: return "v32i8";
+ case MVT::v2i16: return "v2i16";
+ case MVT::v4i16: return "v4i16";
case MVT::v8i16: return "v8i16";
+ case MVT::v16i16: return "v16i16";
+ case MVT::v2i32: return "v2i32";
+ case MVT::v3i32: return "v3i32";
case MVT::v4i32: return "v4i32";
+ case MVT::v8i32: return "v8i32";
+ case MVT::v1i64: return "v1i64";
case MVT::v2i64: return "v2i64";
+ case MVT::v4i64: return "v4i64";
case MVT::v2f32: return "v2f32";
+ case MVT::v3f32: return "v3f32";
case MVT::v4f32: return "v4f32";
+ case MVT::v8f32: return "v8f32";
case MVT::v2f64: return "v2f64";
- case MVT::v3i32: return "v3i32";
- case MVT::v3f32: return "v3f32";
+ case MVT::v4f64: return "v4f64";
}
}
@@ -140,21 +150,27 @@ const Type *MVT::getTypeForMVT() const {
case MVT::ppcf128: return Type::PPC_FP128Ty;
case MVT::v2i8: return VectorType::get(Type::Int8Ty, 2);
case MVT::v4i8: return VectorType::get(Type::Int8Ty, 4);
- case MVT::v2i16: return VectorType::get(Type::Int16Ty, 2);
case MVT::v8i8: return VectorType::get(Type::Int8Ty, 8);
+ case MVT::v16i8: return VectorType::get(Type::Int8Ty, 16);
+ case MVT::v32i8: return VectorType::get(Type::Int8Ty, 32);
+ case MVT::v2i16: return VectorType::get(Type::Int16Ty, 2);
case MVT::v4i16: return VectorType::get(Type::Int16Ty, 4);
+ case MVT::v8i16: return VectorType::get(Type::Int16Ty, 16);
+ case MVT::v16i16: return VectorType::get(Type::Int16Ty, 8);
case MVT::v2i32: return VectorType::get(Type::Int32Ty, 2);
- case MVT::v1i64: return VectorType::get(Type::Int64Ty, 1);
- case MVT::v16i8: return VectorType::get(Type::Int8Ty, 16);
- case MVT::v8i16: return VectorType::get(Type::Int16Ty, 8);
+ case MVT::v3i32: return VectorType::get(Type::Int32Ty, 3);
case MVT::v4i32: return VectorType::get(Type::Int32Ty, 4);
+ case MVT::v8i32: return VectorType::get(Type::Int32Ty, 8);
+ case MVT::v1i64: return VectorType::get(Type::Int64Ty, 1);
case MVT::v2i64: return VectorType::get(Type::Int64Ty, 2);
+ case MVT::v4i64: return VectorType::get(Type::Int64Ty, 4);
case MVT::v2f32: return VectorType::get(Type::FloatTy, 2);
+ case MVT::v3f32: return VectorType::get(Type::FloatTy, 3);
case MVT::v4f32: return VectorType::get(Type::FloatTy, 4);
+ case MVT::v8f32: return VectorType::get(Type::FloatTy, 8);
case MVT::v2f64: return VectorType::get(Type::DoubleTy, 2);
- case MVT::v3i32: return VectorType::get(Type::Int32Ty, 3);
- case MVT::v3f32: return VectorType::get(Type::FloatTy, 3);
- }
+ case MVT::v4f64: return VectorType::get(Type::DoubleTy, 4);
+ }
}
/// getMVT - Return the value type corresponding to the specified type. This
OpenPOWER on IntegriCloud