Compare commits
2 Commits
NSS_3_12_V
...
regalloc_c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1c43d4984f | ||
|
|
cfe021ff88 |
134
mozilla/ef/Compiler/RegisterAllocator/BitSet.cpp
Normal file
134
mozilla/ef/Compiler/RegisterAllocator/BitSet.cpp
Normal file
@@ -0,0 +1,134 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "BitSet.h"
|
||||
|
||||
// Return the next bit after index set to true or -1 if none.
|
||||
//
|
||||
Int32 BitSet::nextOne(Int32 pos) const
|
||||
{
|
||||
++pos;
|
||||
|
||||
if (pos < 0 || Uint32(pos) >= universeSize)
|
||||
return -1;
|
||||
|
||||
Uint32 offset = getWordOffset(pos);
|
||||
Uint8 index = getBitOffset(pos);
|
||||
Word* ptr = &word[offset];
|
||||
Word currentWord = *ptr++ >> index;
|
||||
|
||||
if (currentWord != Word(0)) {
|
||||
while ((currentWord & Word(1)) == 0) {
|
||||
++index;
|
||||
currentWord >>= 1;
|
||||
}
|
||||
return (offset << nBitsInWordLog2) + index;
|
||||
}
|
||||
|
||||
Word* limit = &word[getSizeInWords(universeSize)];
|
||||
while (ptr < limit) {
|
||||
++offset;
|
||||
currentWord = *ptr++;
|
||||
if (currentWord != Word(0)) {
|
||||
index = 0;
|
||||
while ((currentWord & Word(1)) == 0) {
|
||||
++index;
|
||||
currentWord >>= 1;
|
||||
}
|
||||
return (offset << nBitsInWordLog2) + index;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Return the next bit after index set to false or -1 if none.
|
||||
//
|
||||
Int32 BitSet::nextZero(Int32 pos) const
|
||||
{
|
||||
++pos;
|
||||
|
||||
if (pos < 0 || Uint32(pos) >= universeSize)
|
||||
return -1;
|
||||
|
||||
Uint32 offset = getWordOffset(pos);
|
||||
Uint8 index = getBitOffset(pos);
|
||||
Word* ptr = &word[offset];
|
||||
Word currentWord = *ptr++ >> index;
|
||||
|
||||
if (currentWord != Word(~0)) {
|
||||
for (; index < nBitsInWord; ++index) {
|
||||
if ((currentWord & Word(1)) == 0) {
|
||||
Int32 ret = (offset << nBitsInWordLog2) + index;
|
||||
return (Uint32(ret) < universeSize) ? ret : -1;
|
||||
}
|
||||
currentWord >>= 1;
|
||||
}
|
||||
}
|
||||
|
||||
Word* limit = &word[getSizeInWords(universeSize)];
|
||||
while (ptr < limit) {
|
||||
++offset;
|
||||
currentWord = *ptr++;
|
||||
if (currentWord != Word(~0)) {
|
||||
for (index = 0; index < nBitsInWord; ++index) {
|
||||
if ((currentWord & Word(1)) == 0) {
|
||||
Int32 ret = (offset << nBitsInWordLog2) + index;
|
||||
return (Uint32(ret) < universeSize) ? ret : -1;
|
||||
}
|
||||
currentWord >>= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
|
||||
// Print the set.
|
||||
//
|
||||
void BitSet::printPretty(LogModuleObject log)
|
||||
{
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("[ "));
|
||||
|
||||
for (Int32 i = firstOne(); i != -1; i = nextOne(i)) {
|
||||
Int32 currentBit = i;
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("%d", currentBit));
|
||||
|
||||
Int32 nextBit = nextOne(currentBit);
|
||||
if (nextBit != currentBit + 1) {
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, (" "));
|
||||
continue;
|
||||
}
|
||||
|
||||
while ((nextBit != -1) && (nextBit == (currentBit + 1))) {
|
||||
currentBit = nextBit;
|
||||
nextBit = nextOne(nextBit);
|
||||
}
|
||||
|
||||
if (currentBit > (i+1))
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("-%d ", currentBit));
|
||||
else
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, (" %d ", currentBit));
|
||||
|
||||
i = currentBit;
|
||||
}
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("]\n"));
|
||||
}
|
||||
|
||||
#endif // DEBUG_LOG
|
||||
195
mozilla/ef/Compiler/RegisterAllocator/BitSet.h
Normal file
195
mozilla/ef/Compiler/RegisterAllocator/BitSet.h
Normal file
@@ -0,0 +1,195 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _BITSET_H_
|
||||
#define _BITSET_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "LogModule.h"
|
||||
#include "Pool.h"
|
||||
#include <string.h>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// BitSet -
|
||||
|
||||
class BitSet
|
||||
{
|
||||
private:
|
||||
|
||||
#if (PR_BITS_PER_WORD == 64)
|
||||
typedef Uint64 Word;
|
||||
#elif (PR_BITS_PER_WORD == 32)
|
||||
typedef Uint32 Word;
|
||||
#endif
|
||||
|
||||
static const nBitsInWord = PR_BITS_PER_WORD;
|
||||
static const nBytesInWord = PR_BYTES_PER_WORD;
|
||||
static const nBitsInWordLog2 = PR_BITS_PER_WORD_LOG2;
|
||||
static const nBytesInWordLog2 = PR_BYTES_PER_WORD_LOG2;
|
||||
|
||||
// Return the number of Word need to store the universe.
|
||||
static Uint32 getSizeInWords(Uint32 sizeOfUniverse) {return (sizeOfUniverse + (nBitsInWord - 1)) >> nBitsInWordLog2;}
|
||||
// Return the given element offset in its containing Word.
|
||||
static Uint32 getBitOffset(Uint32 element) {return element & (nBitsInWord - 1);}
|
||||
// Return the Word offset for the given element int the universe.
|
||||
static Uint32 getWordOffset(Uint32 element) {return element >> nBitsInWordLog2;}
|
||||
// Return the mask for the given bit index.
|
||||
static Word getMask(Uint8 index) {return Word(1) << index;}
|
||||
|
||||
private:
|
||||
|
||||
Uint32 universeSize; // Size of the universe
|
||||
Word* word; // universe memory.
|
||||
|
||||
private:
|
||||
|
||||
// No copy constructor.
|
||||
BitSet(const BitSet&);
|
||||
|
||||
// Check if the given set's universe is of the same size than this universe.
|
||||
void checkUniverseCompatibility(const BitSet& set) const {assert(set.universeSize == universeSize);}
|
||||
// Check if pos is valid for this set's universe.
|
||||
void checkMember(Int32 pos) const {assert(pos >=0 && Uint32(pos) < universeSize);}
|
||||
|
||||
public:
|
||||
|
||||
// Create a bitset of universeSize bits.
|
||||
BitSet(Pool& pool, Uint32 universeSize) : universeSize(universeSize) {word = new(pool) Word[getSizeInWords(universeSize)]; clear();}
|
||||
|
||||
// Return the size of this bitset.
|
||||
Uint32 getSize() const {return universeSize;}
|
||||
|
||||
// Clear the bitset.
|
||||
void clear() {memset(word, 0x00, getSizeInWords(universeSize) << nBytesInWordLog2);}
|
||||
// Clear the bit at index.
|
||||
void clear(Uint32 index) {checkMember(index); word[getWordOffset(index)] &= ~getMask(index);}
|
||||
// Set the bitset.
|
||||
void set() {memset(word, 0xFF, getSizeInWords(universeSize) << nBytesInWordLog2);}
|
||||
// Set the bit at index.
|
||||
void set(Uint32 index) {checkMember(index); word[getWordOffset(index)] |= getMask(index);}
|
||||
// Return true if the bit at index is set.
|
||||
bool test(Uint32 index) const {checkMember(index); return (word[getWordOffset(index)] & getMask(index)) != 0;}
|
||||
// Union with the given bitset.
|
||||
inline void or(const BitSet& set);
|
||||
// Intersection with the given bitset.
|
||||
inline void and(const BitSet& set);
|
||||
// Difference with the given bitset.
|
||||
inline void difference(const BitSet& set);
|
||||
// Copy set.
|
||||
inline BitSet& operator = (const BitSet& set);
|
||||
// Return true if the bitset are identical.
|
||||
friend bool operator == (const BitSet& set1, const BitSet& set2);
|
||||
// Return true if the bitset are different.
|
||||
friend bool operator != (const BitSet& set1, const BitSet& set2);
|
||||
|
||||
// Logical operators.
|
||||
BitSet& operator |= (const BitSet& set) {or(set); return *this;}
|
||||
BitSet& operator &= (const BitSet& set) {and(set); return *this;}
|
||||
BitSet& operator -= (const BitSet& set) {difference(set); return *this;}
|
||||
|
||||
// Return the first bit at set to true or -1 if none.
|
||||
Int32 firstOne() const {return nextOne(-1);}
|
||||
// Return the next bit after index set to true or -1 if none.
|
||||
Int32 nextOne(Int32 pos) const;
|
||||
// Return the first bit at set to false or -1 if none.
|
||||
Int32 firstZero() const {return nextZero(-1);}
|
||||
// Return the next bit after index set to false or -1 if none.
|
||||
Int32 nextZero(Int32 pos) const;
|
||||
|
||||
// Iterator to conform with the set API.
|
||||
typedef Int32 iterator;
|
||||
// Return true if the walk is ordered.
|
||||
static bool isOrdered() {return true;}
|
||||
// Return the iterator for the first element of this set.
|
||||
iterator begin() const {return firstOne();}
|
||||
// Return the next iterator.
|
||||
iterator advance(iterator pos) const {return nextOne(pos);}
|
||||
// Return true if the iterator is at the end of the set.
|
||||
bool done(iterator pos) const {return pos == -1;}
|
||||
// Return the element corresponding to the given iterator.
|
||||
Uint32 get(iterator pos) const {return pos;}
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
// Print the set.
|
||||
void printPretty(LogModuleObject log);
|
||||
#endif // DEBUG_LOG
|
||||
};
|
||||
|
||||
// Union with the given bitset.
|
||||
//
|
||||
inline void BitSet::or(const BitSet& set)
|
||||
{
|
||||
checkUniverseCompatibility(set);
|
||||
Word* src = set.word;
|
||||
Word* dst = word;
|
||||
Word* limit = &src[getSizeInWords(universeSize)];
|
||||
|
||||
while (src < limit)
|
||||
*dst++ |= *src++;
|
||||
}
|
||||
|
||||
// Intersection with the given bitset.
|
||||
//
|
||||
inline void BitSet::and(const BitSet& set)
|
||||
{
|
||||
checkUniverseCompatibility(set);
|
||||
Word* src = set.word;
|
||||
Word* dst = word;
|
||||
Word* limit = &src[getSizeInWords(universeSize)];
|
||||
|
||||
while (src < limit)
|
||||
*dst++ &= *src++;
|
||||
}
|
||||
|
||||
// Difference with the given bitset.
|
||||
//
|
||||
inline void BitSet::difference(const BitSet& set)
|
||||
{
|
||||
checkUniverseCompatibility(set);
|
||||
Word* src = set.word;
|
||||
Word* dst = word;
|
||||
Word* limit = &src[getSizeInWords(universeSize)];
|
||||
|
||||
while (src < limit)
|
||||
*dst++ &= ~*src++;
|
||||
}
|
||||
|
||||
// Copy the given set into this set.
|
||||
//
|
||||
inline BitSet& BitSet::operator = (const BitSet& set)
|
||||
{
|
||||
checkUniverseCompatibility(set);
|
||||
if (this != &set)
|
||||
memcpy(word, set.word, getSizeInWords(universeSize) << nBytesInWordLog2);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Return true if the given set is identical to this set.
|
||||
inline bool operator == (const BitSet& set1, const BitSet& set2)
|
||||
{
|
||||
set1.checkUniverseCompatibility(set2);
|
||||
|
||||
if (&set1 == &set2)
|
||||
return true;
|
||||
|
||||
return memcmp(set1.word, set2.word, BitSet::getSizeInWords(set1.universeSize) << BitSet::nBytesInWordLog2) == 0;
|
||||
}
|
||||
|
||||
inline bool operator != (const BitSet& set1, const BitSet& set2) {return !(set1 == set2);}
|
||||
|
||||
#endif // _BITSET_H
|
||||
159
mozilla/ef/Compiler/RegisterAllocator/Coalescing.h
Normal file
159
mozilla/ef/Compiler/RegisterAllocator/Coalescing.h
Normal file
@@ -0,0 +1,159 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _COALESCING_H_
|
||||
#define _COALESCING_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "Pool.h"
|
||||
#include "RegisterPressure.h"
|
||||
#include "InterferenceGraph.h"
|
||||
#include "ControlGraph.h"
|
||||
#include "ControlNodes.h"
|
||||
#include "Instruction.h"
|
||||
#include "SparseSet.h"
|
||||
#include "RegisterAllocator.h"
|
||||
#include "RegisterAllocatorTools.h"
|
||||
|
||||
#if 1
|
||||
// Performing an ultra conservative coalescing meens that when we look at
|
||||
// candidates (source,destination) for coalescing we need to make sure
|
||||
// that the combined interference of the source and destination register
|
||||
// will not exceed the total number of register available for the register
|
||||
// class.
|
||||
#define ULTRA_CONSERVATIVE_COALESCING
|
||||
#else
|
||||
// If we are not doing an ultra conservative coalescing we have to make sure
|
||||
// that the total number of neighbor whose degree is greater than the total
|
||||
// number of register is not greater than the total number of register.
|
||||
#undef ULTRA_CONSERVATIVE_COALESCING
|
||||
#endif
|
||||
|
||||
template <class RegisterPressure>
|
||||
struct Coalescing
|
||||
{
|
||||
static bool coalesce(RegisterAllocator& registerAllocator);
|
||||
};
|
||||
|
||||
template <class RegisterPressure>
|
||||
bool Coalescing<RegisterPressure>::coalesce(RegisterAllocator& registerAllocator)
|
||||
{
|
||||
Pool& pool = registerAllocator.pool;
|
||||
|
||||
// Initialize the lookup table
|
||||
//
|
||||
Uint32 rangeCount = registerAllocator.rangeCount;
|
||||
RegisterName* newRange = new RegisterName[2 * rangeCount];
|
||||
RegisterName* coalescedRange = &newRange[rangeCount];
|
||||
RegisterName* name2range = registerAllocator.name2range;
|
||||
|
||||
init(coalescedRange, rangeCount);
|
||||
|
||||
SparseSet interferences(pool, rangeCount);
|
||||
InterferenceGraph<RegisterPressure>& iGraph = registerAllocator.iGraph;
|
||||
bool removedInstructions = false;
|
||||
|
||||
ControlGraph& controlGraph = registerAllocator.controlGraph;
|
||||
ControlNode** nodes = controlGraph.lndList;
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
|
||||
|
||||
// Walk the nodes in the loop nesting depth list.
|
||||
for (Int32 n = nNodes - 1; n >= 0; n--) {
|
||||
InstructionList& instructions = nodes[n]->getInstructions();
|
||||
|
||||
InstructionList::iterator it = instructions.begin();
|
||||
while (!instructions.done(it)) {
|
||||
Instruction& instruction = instructions.get(it);
|
||||
it = instructions.advance(it);
|
||||
|
||||
if ((instruction.getFlags() & ifCopy) != 0) {
|
||||
assert(instruction.getInstructionUseBegin() != instruction.getInstructionUseEnd() && instruction.getInstructionUseBegin()[0].isRegister());
|
||||
assert(instruction.getInstructionDefineBegin() != instruction.getInstructionDefineEnd() && instruction.getInstructionDefineBegin()[0].isRegister());
|
||||
|
||||
RegisterName source = findRoot(name2range[instruction.getInstructionUseBegin()[0].getRegisterName()], coalescedRange);
|
||||
RegisterName destination = findRoot(name2range[instruction.getInstructionDefineBegin()[0].getRegisterName()], coalescedRange);
|
||||
|
||||
if (source == destination) {
|
||||
instruction.remove();
|
||||
} else if (!iGraph.interfere(source, destination)) {
|
||||
InterferenceVector* sourceVector = iGraph.getInterferenceVector(source);
|
||||
InterferenceVector* destinationVector = iGraph.getInterferenceVector(destination);
|
||||
|
||||
#ifdef ULTRA_CONSERVATIVE_COALESCING
|
||||
interferences.clear();
|
||||
|
||||
InterferenceVector* vector;
|
||||
for (vector = sourceVector; vector != NULL; vector = vector->next) {
|
||||
RegisterName* neighbors = vector->neighbors;
|
||||
for (Uint32 i = 0; i < vector->count; i++)
|
||||
interferences.set(findRoot(neighbors[i], coalescedRange));
|
||||
}
|
||||
for (vector = destinationVector; vector != NULL; vector = vector->next) {
|
||||
RegisterName* neighbors = vector->neighbors;
|
||||
for (Uint32 i = 0; i < vector->count; i++)
|
||||
interferences.set(findRoot(neighbors[i], coalescedRange));
|
||||
}
|
||||
|
||||
Uint32 count = interferences.getSize();
|
||||
#else // ULTRA_CONSERVATIVE_COALESCING
|
||||
trespass("not implemented");
|
||||
Uint32 count = 0;
|
||||
#endif // ULTRA_CONSERVATIVE_COALESCING
|
||||
|
||||
if (count < 6 /* FIX: should get the number from the class */) {
|
||||
// Update the interferences vector.
|
||||
if (sourceVector == NULL) {
|
||||
iGraph.setInterferenceVector(source, destinationVector);
|
||||
sourceVector = destinationVector;
|
||||
} else if (destinationVector == NULL)
|
||||
iGraph.setInterferenceVector(destination, sourceVector);
|
||||
else {
|
||||
InterferenceVector* last = NULL;
|
||||
for (InterferenceVector* v = sourceVector; v != NULL; v = v->next)
|
||||
last = v;
|
||||
assert(last);
|
||||
last->next = destinationVector;
|
||||
iGraph.setInterferenceVector(destination, sourceVector);
|
||||
}
|
||||
// Update the interference matrix.
|
||||
for (InterferenceVector* v = sourceVector; v != NULL; v = v->next) {
|
||||
RegisterName* neighbors = v->neighbors;
|
||||
for (Uint32 i = 0; i < v->count; i++) {
|
||||
RegisterName neighbor = findRoot(neighbors[i], coalescedRange);
|
||||
iGraph.setInterference(neighbor, source);
|
||||
iGraph.setInterference(neighbor, destination);
|
||||
}
|
||||
}
|
||||
|
||||
instruction.remove();
|
||||
coalescedRange[source] = destination;
|
||||
removedInstructions = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
registerAllocator.rangeCount = compress(registerAllocator.name2range, coalescedRange, registerAllocator.nameCount, rangeCount);
|
||||
delete newRange;
|
||||
|
||||
return removedInstructions;
|
||||
}
|
||||
|
||||
#endif // _COALESCING_H_
|
||||
283
mozilla/ef/Compiler/RegisterAllocator/Coloring.cpp
Normal file
283
mozilla/ef/Compiler/RegisterAllocator/Coloring.cpp
Normal file
@@ -0,0 +1,283 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef NEW_LAURENTM_CODE
|
||||
|
||||
#include "Coloring.h"
|
||||
#include "VirtualRegister.h"
|
||||
#include "FastBitSet.h"
|
||||
#include "FastBitMatrix.h"
|
||||
#include "CpuInfo.h"
|
||||
|
||||
bool Coloring::
|
||||
assignRegisters(FastBitMatrix& interferenceMatrix)
|
||||
{
|
||||
PRUint32 *stackPtr = new(pool) PRUint32[vRegManager.count()];
|
||||
|
||||
return select(interferenceMatrix, stackPtr, simplify(interferenceMatrix, stackPtr));
|
||||
}
|
||||
|
||||
PRInt32 Coloring::
|
||||
getLowestSpillCostRegister(FastBitSet& bitset)
|
||||
{
|
||||
PRInt32 lowest = bitset.firstOne();
|
||||
if (lowest != -1)
|
||||
{
|
||||
Flt32 cost = vRegManager.getVirtualRegister(lowest).spillInfo.spillCost;
|
||||
for (PRInt32 r = bitset.nextOne(lowest); r != -1; r = bitset.nextOne(r))
|
||||
{
|
||||
VirtualRegister& vReg = vRegManager.getVirtualRegister(r);
|
||||
if (!vReg.spillInfo.infiniteSpillCost && (vReg.spillInfo.spillCost < cost))
|
||||
{
|
||||
cost = vReg.spillInfo.spillCost;
|
||||
lowest = r;
|
||||
}
|
||||
}
|
||||
}
|
||||
return lowest;
|
||||
}
|
||||
|
||||
PRUint32* Coloring::
|
||||
simplify(FastBitMatrix interferenceMatrix, PRUint32* stackPtr)
|
||||
{
|
||||
// first we construct the sets low and high. low contains all nodes of degree
|
||||
// inferior to the number of register available on the processor. All the
|
||||
// nodes with an high degree and a finite spill cost are placed in high.
|
||||
// Nodes of high degree and infinite spill cost are not included in either sets.
|
||||
|
||||
PRUint32 nRegisters = vRegManager.count();
|
||||
FastBitSet low(pool, nRegisters);
|
||||
FastBitSet high(pool, nRegisters);
|
||||
FastBitSet stack(pool, nRegisters);
|
||||
|
||||
for (VirtualRegisterManager::iterator i = vRegManager.begin(); !vRegManager.done(i); i = vRegManager.advance(i))
|
||||
{
|
||||
VirtualRegister& vReg = vRegManager.getVirtualRegister(i);
|
||||
|
||||
if (vReg.getClass() == vrcStackSlot)
|
||||
{
|
||||
stack.set(i);
|
||||
vReg.colorRegister(nRegisters);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (vReg.colorInfo.interferenceDegree < NUMBER_OF_REGISTERS)
|
||||
low.set(i);
|
||||
else // if (!vReg.spillInfo.infiniteSpillCost)
|
||||
high.set(i);
|
||||
|
||||
// Set coloring info.
|
||||
vReg.spillInfo.willSpill = false;
|
||||
|
||||
switch(vReg.getClass())
|
||||
{
|
||||
case vrcInteger:
|
||||
vReg.colorRegister(LAST_GREGISTER + 1);
|
||||
break;
|
||||
case vrcFloatingPoint:
|
||||
case vrcFixedPoint:
|
||||
vReg.colorRegister(LAST_FPREGISTER + 1);
|
||||
break;
|
||||
default:
|
||||
PR_ASSERT(false); // Cannot happen.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// push the stack registers
|
||||
PRInt32 j;
|
||||
for (j = stack.firstOne(); j != -1; j = stack.nextOne(j))
|
||||
*stackPtr++ = j;
|
||||
|
||||
// simplify
|
||||
while (true)
|
||||
{
|
||||
PRInt32 r;
|
||||
while ((r = getLowestSpillCostRegister(low)) != -1)
|
||||
{
|
||||
VirtualRegister& vReg = vRegManager.getVirtualRegister(r);
|
||||
|
||||
/* update low and high */
|
||||
FastBitSet inter(interferenceMatrix.getRow(r), nRegisters);
|
||||
for (j = inter.firstOne(); j != -1; j = inter.nextOne(j))
|
||||
{
|
||||
VirtualRegister& neighbor = vRegManager.getVirtualRegister(j);
|
||||
// if the new interference degree of one of his neighbor becomes
|
||||
// NUMBER_OF_REGISTERS - 1 then it is added to the set 'low'.
|
||||
|
||||
PRUint32 maxInterference = 0;
|
||||
switch (neighbor.getClass())
|
||||
{
|
||||
case vrcInteger:
|
||||
maxInterference = NUMBER_OF_GREGISTERS;
|
||||
break;
|
||||
case vrcFloatingPoint:
|
||||
case vrcFixedPoint:
|
||||
maxInterference = NUMBER_OF_FPREGISTERS;
|
||||
break;
|
||||
default:
|
||||
PR_ASSERT(false);
|
||||
}
|
||||
if ((vRegManager.getVirtualRegister(j).colorInfo.interferenceDegree-- == maxInterference))
|
||||
{
|
||||
high.clear(j);
|
||||
low.set(j);
|
||||
}
|
||||
vReg.colorInfo.interferenceDegree--;
|
||||
interferenceMatrix.clear(r, j);
|
||||
interferenceMatrix.clear(j, r);
|
||||
}
|
||||
low.clear(r);
|
||||
|
||||
// Push this register.
|
||||
*stackPtr++ = r;
|
||||
}
|
||||
if ((r = getLowestSpillCostRegister(high)) != -1)
|
||||
{
|
||||
high.clear(r);
|
||||
low.set(r);
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
return stackPtr;
|
||||
}
|
||||
|
||||
bool Coloring::
|
||||
select(FastBitMatrix& interferenceMatrix, PRUint32* stackBase, PRUint32* stackPtr)
|
||||
{
|
||||
PRUint32 nRegisters = vRegManager.count();
|
||||
FastBitSet usedRegisters(NUMBER_OF_REGISTERS + 1); // usedRegisters if used for both GR & FPR.
|
||||
FastBitSet preColoredRegisters(NUMBER_OF_REGISTERS + 1);
|
||||
FastBitSet usedStack(nRegisters + 1);
|
||||
bool success = true;
|
||||
Int32 lastUsedSSR = -1;
|
||||
|
||||
// select
|
||||
while (stackPtr != stackBase)
|
||||
{
|
||||
// Pop one register.
|
||||
PRUint32 r = *--stackPtr;
|
||||
VirtualRegister& vReg = vRegManager.getVirtualRegister(r);
|
||||
|
||||
FastBitSet neighbors(interferenceMatrix.getRow(r), nRegisters);
|
||||
|
||||
if (vReg.getClass() == vrcStackSlot)
|
||||
// Stack slots coloring.
|
||||
{
|
||||
usedStack.clear();
|
||||
|
||||
for (PRInt32 i = neighbors.firstOne(); i != -1; i = neighbors.nextOne(i))
|
||||
usedStack.set(vRegManager.getVirtualRegister(i).getColor());
|
||||
|
||||
Int32 color = usedStack.firstZero();
|
||||
vReg.colorRegister(color);
|
||||
if (color > lastUsedSSR)
|
||||
lastUsedSSR = color;
|
||||
}
|
||||
else
|
||||
// Integer & Floating point register coloring.
|
||||
{
|
||||
usedRegisters.clear();
|
||||
preColoredRegisters.clear();
|
||||
|
||||
for (PRInt32 i = neighbors.firstOne(); i != -1; i = neighbors.nextOne(i))
|
||||
{
|
||||
VirtualRegister& nvReg = vRegManager.getVirtualRegister(i);
|
||||
usedRegisters.set(nvReg.getColor());
|
||||
if (nvReg.isPreColored())
|
||||
preColoredRegisters.set(nvReg.getPreColor());
|
||||
}
|
||||
if (vReg.hasSpecialInterference)
|
||||
usedRegisters |= vReg.specialInterference;
|
||||
|
||||
PRInt8 c = -1;
|
||||
PRInt8 maxColor = 0;
|
||||
PRInt8 firstColor = 0;
|
||||
switch (vReg.getClass())
|
||||
{
|
||||
case vrcInteger:
|
||||
firstColor = FIRST_GREGISTER;
|
||||
maxColor = LAST_GREGISTER;
|
||||
break;
|
||||
case vrcFloatingPoint:
|
||||
case vrcFixedPoint:
|
||||
firstColor = FIRST_FPREGISTER;
|
||||
maxColor = LAST_FPREGISTER;
|
||||
break;
|
||||
default:
|
||||
PR_ASSERT(false);
|
||||
}
|
||||
|
||||
if (vReg.isPreColored())
|
||||
{
|
||||
c = vReg.getPreColor();
|
||||
if (usedRegisters.test(c))
|
||||
c = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (c = usedRegisters.nextZero(firstColor - 1); (c >= 0) && (c <= maxColor) && (preColoredRegisters.test(c));
|
||||
c = usedRegisters.nextZero(c)) {}
|
||||
}
|
||||
|
||||
if ((c >= 0) && (c <= maxColor))
|
||||
{
|
||||
vReg.colorRegister(c);
|
||||
}
|
||||
else
|
||||
{
|
||||
VirtualRegister& stackRegister = vRegManager.newVirtualRegister(vrcStackSlot);
|
||||
vReg.equivalentRegister[vrcStackSlot] = &stackRegister;
|
||||
vReg.spillInfo.willSpill = true;
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
if (success)
|
||||
{
|
||||
for (VirtualRegisterManager::iterator i = vRegManager.begin(); !vRegManager.done(i); i = vRegManager.advance(i))
|
||||
{
|
||||
VirtualRegister& vReg = vRegManager.getVirtualRegister(i);
|
||||
switch (vReg.getClass())
|
||||
{
|
||||
case vrcInteger:
|
||||
if (vReg.getColor() > LAST_GREGISTER)
|
||||
PR_ASSERT(false);
|
||||
break;
|
||||
case vrcFloatingPoint:
|
||||
case vrcFixedPoint:
|
||||
#if NUMBER_OF_FPREGISTERS != 0
|
||||
if (vReg.getColor() > LAST_FPREGISTER)
|
||||
PR_ASSERT(false);
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
vRegManager.nUsedStackSlots = lastUsedSSR + 1;
|
||||
return success;
|
||||
}
|
||||
#endif // NEW_LAURENTM_CODE
|
||||
284
mozilla/ef/Compiler/RegisterAllocator/Coloring.h
Normal file
284
mozilla/ef/Compiler/RegisterAllocator/Coloring.h
Normal file
@@ -0,0 +1,284 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "ControlGraph.h"
|
||||
#include "ControlNodes.h"
|
||||
#include "Instruction.h"
|
||||
#include "RegisterAllocator.h"
|
||||
#include "VirtualRegister.h"
|
||||
#include "InterferenceGraph.h"
|
||||
#include "SparseSet.h"
|
||||
#include "Spilling.h"
|
||||
#include "Splits.h"
|
||||
|
||||
UT_EXTERN_LOG_MODULE(RegAlloc);
|
||||
|
||||
template <class RegisterPressure>
|
||||
class Coloring
|
||||
{
|
||||
private:
|
||||
static RegisterName* simplify(RegisterAllocator& registerAllocator, RegisterName* coloringStack);
|
||||
static bool select(RegisterAllocator& registerAllocator, RegisterName* coloringStack, RegisterName* coloringStackPtr);
|
||||
|
||||
public:
|
||||
static bool color(RegisterAllocator& registerAllocator);
|
||||
static void finalColoring(RegisterAllocator& registerAllocator);
|
||||
};
|
||||
|
||||
|
||||
template <class RegisterPressure>
|
||||
void Coloring<RegisterPressure>::finalColoring(RegisterAllocator& registerAllocator)
|
||||
{
|
||||
RegisterName* color = registerAllocator.color;
|
||||
RegisterName* name2range = registerAllocator.name2range;
|
||||
|
||||
ControlGraph& controlGraph = registerAllocator.controlGraph;
|
||||
ControlNode** nodes = controlGraph.dfsList;
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
|
||||
for (Uint32 n = 0; n < nNodes; n++) {
|
||||
InstructionList& instructions = nodes[n]->getInstructions();
|
||||
|
||||
for (InstructionList::iterator i = instructions.begin(); !instructions.done(i); i = instructions.advance(i)) {
|
||||
Instruction& instruction = instructions.get(i);
|
||||
|
||||
InstructionUse* useEnd = instruction.getInstructionUseEnd();
|
||||
for (InstructionUse* usePtr = instruction.getInstructionUseBegin(); usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister()) {
|
||||
usePtr->setRegisterName(color[name2range[usePtr->getRegisterName()]]);
|
||||
#ifdef DEBUG
|
||||
RegisterID rid = usePtr->getRegisterID();
|
||||
setColoredRegister(rid);
|
||||
usePtr->setRegisterID(rid);
|
||||
#endif // DEBUG
|
||||
}
|
||||
|
||||
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
|
||||
for (InstructionDefine* definePtr = instruction.getInstructionDefineBegin(); definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister()) {
|
||||
definePtr->setRegisterName(color[name2range[definePtr->getRegisterName()]]);
|
||||
#ifdef DEBUG
|
||||
RegisterID rid = definePtr->getRegisterID();
|
||||
setColoredRegister(rid);
|
||||
definePtr->setRegisterID(rid);
|
||||
#endif // DEBUG
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class RegisterPressure>
|
||||
bool Coloring<RegisterPressure>::select(RegisterAllocator& registerAllocator, RegisterName* coloringStack, RegisterName* coloringStackPtr)
|
||||
{
|
||||
Uint32 rangeCount = registerAllocator.rangeCount;
|
||||
RegisterName* color = new RegisterName[rangeCount];
|
||||
registerAllocator.color = color;
|
||||
|
||||
for (Uint32 r = 1; r < rangeCount; r++)
|
||||
color[r] = RegisterName(6); // FIX;
|
||||
|
||||
// Color the preColored registers.
|
||||
//
|
||||
VirtualRegisterManager& vrManager = registerAllocator.vrManager;
|
||||
RegisterName* name2range = registerAllocator.name2range;
|
||||
PreColoredRegister* machineEnd = vrManager.getMachineRegistersEnd();
|
||||
for (PreColoredRegister* machinePtr = vrManager.getMachineRegistersBegin(); machinePtr < machineEnd; machinePtr++)
|
||||
if (machinePtr->id != invalidID) {
|
||||
color[name2range[getName(machinePtr->id)]] = machinePtr->color;
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("\twill preColor range %d as %d\n", name2range[getName(machinePtr->id)], machinePtr->color));
|
||||
}
|
||||
|
||||
SpillCost* cost = registerAllocator.spillCost;
|
||||
Pool& pool = registerAllocator.pool;
|
||||
SparseSet& spill = *new(pool) SparseSet(pool, rangeCount);
|
||||
registerAllocator.willSpill = &spill;
|
||||
SparseSet neighborColors(pool, 6); // FIX
|
||||
InterferenceGraph<RegisterPressure>& iGraph = registerAllocator.iGraph;
|
||||
|
||||
bool coloringFailed = false;
|
||||
while (coloringStackPtr > coloringStack) {
|
||||
RegisterName range = *--coloringStackPtr;
|
||||
|
||||
if (!cost[range].infinite && cost[range].cost < 0) {
|
||||
coloringFailed = true;
|
||||
spill.set(range);
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("\tfailed to color %d, will spill.\n", range));
|
||||
} else {
|
||||
neighborColors.clear();
|
||||
|
||||
for (InterferenceVector* vector = iGraph.getInterferenceVector(range); vector != NULL; vector = vector->next)
|
||||
for (Int32 i = vector->count - 1; i >= 0; --i) {
|
||||
RegisterName neighborColor = color[vector->neighbors[i]];
|
||||
if (neighborColor < 6) // FIX
|
||||
neighborColors.set(neighborColor);
|
||||
}
|
||||
|
||||
if (neighborColors.getSize() == 6) { // FIX
|
||||
coloringFailed = true;
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("\tfailed to color %d, ", range));
|
||||
|
||||
if (!Splits<RegisterPressure>::findSplit(registerAllocator, color, range)) {
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("will spill.\n"));
|
||||
spill.set(range);
|
||||
} else
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("will split.\n"));
|
||||
} else {
|
||||
for (Uint32 i = 0; i < 6; i++) // FIX
|
||||
if (!neighborColors.test(i)) {
|
||||
fprintf(stdout, "\twill color %d as %d\n", range, i);
|
||||
color[range] = RegisterName(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
if (coloringFailed) {
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("Coloring failed:\n"));
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("\twill spill: "));
|
||||
spill.printPretty(UT_LOG_MODULE(RegAlloc));
|
||||
} else {
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("Coloring succeeded:\n"));
|
||||
for (Uint32 i = 1; i < rangeCount; i++)
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("\trange %d colored as %d\n", i, color[i]));
|
||||
}
|
||||
#endif
|
||||
|
||||
return !coloringFailed;
|
||||
}
|
||||
|
||||
template <class RegisterPressure>
|
||||
RegisterName* Coloring<RegisterPressure>::simplify(RegisterAllocator& registerAllocator, RegisterName* coloringStack)
|
||||
{
|
||||
InterferenceGraph<RegisterPressure>& iGraph = registerAllocator.iGraph;
|
||||
SpillCost* spillCost = registerAllocator.spillCost;
|
||||
Uint32 rangeCount = registerAllocator.rangeCount;
|
||||
|
||||
Uint32* degree = new Uint32[rangeCount];
|
||||
for (RegisterName i = RegisterName(1); i < rangeCount; i = RegisterName(i + 1)) {
|
||||
InterferenceVector* vector = iGraph.getInterferenceVector(i);
|
||||
degree[i] = (vector != NULL) ? vector->count : 0;
|
||||
}
|
||||
|
||||
Pool& pool = registerAllocator.pool;
|
||||
SparseSet low(pool, rangeCount);
|
||||
SparseSet high(pool, rangeCount);
|
||||
SparseSet highInfinite(pool, rangeCount);
|
||||
SparseSet preColored(pool, rangeCount);
|
||||
|
||||
// Get the precolored registers.
|
||||
//
|
||||
VirtualRegisterManager& vrManager = registerAllocator.vrManager;
|
||||
RegisterName* name2range = registerAllocator.name2range;
|
||||
PreColoredRegister* machineEnd = vrManager.getMachineRegistersEnd();
|
||||
for (PreColoredRegister* machinePtr = vrManager.getMachineRegistersBegin(); machinePtr < machineEnd; machinePtr++)
|
||||
if (machinePtr->id != invalidID)
|
||||
preColored.set(name2range[getName(machinePtr->id)]);
|
||||
|
||||
// Insert the live ranges in the sets.
|
||||
//
|
||||
for (Uint32 range = 1; range < rangeCount; range++)
|
||||
if (!preColored.test(range))
|
||||
if (degree[range] < 6) // FIX
|
||||
low.set(range);
|
||||
else if (!spillCost[range].infinite)
|
||||
high.set(range);
|
||||
else
|
||||
highInfinite.set(range);
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("Coloring sets:\n\tlow = "));
|
||||
low.printPretty(UT_LOG_MODULE(RegAlloc));
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("\thigh = "));
|
||||
high.printPretty(UT_LOG_MODULE(RegAlloc));
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("\thighInfinite = "));
|
||||
highInfinite.printPretty(UT_LOG_MODULE(RegAlloc));
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("\tpreColored = "));
|
||||
preColored.printPretty(UT_LOG_MODULE(RegAlloc));
|
||||
#endif // DEBUG_LOG
|
||||
|
||||
RegisterName* coloringStackPtr = coloringStack;
|
||||
|
||||
while (low.getSize() != 0 || high.getSize() != 0) {
|
||||
while (low.getSize() != 0) {
|
||||
RegisterName range = RegisterName(low.getOne());
|
||||
low.clear(range);
|
||||
*coloringStackPtr++ = range;
|
||||
|
||||
for (InterferenceVector* vector = iGraph.getInterferenceVector(range); vector != NULL; vector = vector->next)
|
||||
for (Int32 i = (vector->count - 1); i >= 0; --i) {
|
||||
RegisterName neighbor = vector->neighbors[i];
|
||||
degree[neighbor]--;
|
||||
|
||||
if (degree[neighbor] < 6) // FIX
|
||||
if (high.test(neighbor)) {
|
||||
high.clear(neighbor);
|
||||
low.set(neighbor);
|
||||
} else if (highInfinite.test(neighbor)) {
|
||||
highInfinite.clear(neighbor);
|
||||
low.set(neighbor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (high.getSize() != 0) {
|
||||
RegisterName best = RegisterName(high.getOne());
|
||||
double bestCost = spillCost[best].cost;
|
||||
double bestDegree = degree[best];
|
||||
|
||||
// Choose the next best candidate.
|
||||
//
|
||||
for (SparseSet::iterator i = high.begin(); !high.done(i); i = high.advance(i)) {
|
||||
RegisterName range = RegisterName(high.get(i));
|
||||
double thisCost = spillCost[range].cost;
|
||||
double thisDegree = degree[range];
|
||||
|
||||
if (thisCost * bestDegree < bestCost * thisDegree) {
|
||||
best = range;
|
||||
bestCost = thisCost;
|
||||
bestDegree = thisDegree;
|
||||
}
|
||||
}
|
||||
|
||||
high.clear(best);
|
||||
low.set(best);
|
||||
}
|
||||
}
|
||||
assert(highInfinite.getSize() == 0);
|
||||
|
||||
delete degree;
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("Coloring stack:\n\t"));
|
||||
for (RegisterName* sp = coloringStack; sp < coloringStackPtr; ++sp)
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("%d ", *sp));
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("\n"));
|
||||
#endif // DEBUG_LOG
|
||||
|
||||
return coloringStackPtr;
|
||||
}
|
||||
|
||||
|
||||
template <class RegisterPressure>
|
||||
bool Coloring<RegisterPressure>::color(RegisterAllocator& registerAllocator)
|
||||
{
|
||||
RegisterName* coloringStack = new RegisterName[registerAllocator.rangeCount];
|
||||
return select(registerAllocator, coloringStack, simplify(registerAllocator, coloringStack));
|
||||
}
|
||||
212
mozilla/ef/Compiler/RegisterAllocator/DominatorGraph.cpp
Normal file
212
mozilla/ef/Compiler/RegisterAllocator/DominatorGraph.cpp
Normal file
@@ -0,0 +1,212 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include <string.h>
|
||||
#include "ControlGraph.h"
|
||||
#include "ControlNodes.h"
|
||||
|
||||
#include "DominatorGraph.h"
|
||||
|
||||
DominatorGraph::DominatorGraph(ControlGraph& controlGraph) : controlGraph(controlGraph)
|
||||
{
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
|
||||
GtoV = new Uint32[nNodes + 1];
|
||||
VtoG = new Uint32[nNodes + 1];
|
||||
|
||||
Uint32 v = 1;
|
||||
for (Uint32 n = 0; n < nNodes; n++) {
|
||||
VtoG[v] = n;
|
||||
GtoV[n] = v++;
|
||||
}
|
||||
|
||||
// Initialize all the 1-based arrays.
|
||||
//
|
||||
parent = new Uint32[v];
|
||||
semi = new Uint32[v];
|
||||
vertex = new Uint32[v];
|
||||
label = new Uint32[v];
|
||||
size = new Uint32[v];
|
||||
ancestor = new Uint32[v];
|
||||
child = new Uint32[v];
|
||||
dom = new Uint32[v];
|
||||
bucket = new DGLinkedList*[v];
|
||||
|
||||
memset(semi, '\0', v * sizeof(Uint32));
|
||||
memset(bucket, '\0', v * sizeof(DGLinkedList*));
|
||||
|
||||
vCount = v;
|
||||
|
||||
build();
|
||||
|
||||
delete parent;
|
||||
delete semi;
|
||||
delete vertex;
|
||||
delete label;
|
||||
delete size;
|
||||
delete ancestor;
|
||||
delete child;
|
||||
delete dom;
|
||||
delete bucket;
|
||||
}
|
||||
|
||||
Uint32 DominatorGraph::DFS(Uint32 vx, Uint32 n)
|
||||
{
|
||||
semi[vx] = ++n;
|
||||
vertex[n] = label[vx] = vx;
|
||||
ancestor[vx] = child[vx] = 0;
|
||||
size[vx] = 1;
|
||||
|
||||
|
||||
ControlNode& node = *controlGraph.dfsList[VtoG[vx]];
|
||||
ControlEdge* successorEnd = node.getSuccessorsEnd();
|
||||
for (ControlEdge* successorPtr = node.getSuccessorsBegin(); successorPtr < successorEnd; successorPtr++) {
|
||||
Uint32 w = GtoV[successorPtr->getTarget().dfsNum];
|
||||
if (semi[w] == 0) {
|
||||
parent[w] = vx;
|
||||
n = DFS(w, n);
|
||||
}
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
void DominatorGraph::LINK(Uint32 vx, Uint32 w)
|
||||
{
|
||||
Uint32 s = w;
|
||||
|
||||
while (semi[label[w]] < semi[label[child[s]]]) {
|
||||
if (size[s] + size[child[child[s]]] >= (size[child[s]] << 1)) {
|
||||
ancestor[child[s]] = s;
|
||||
child[s] = child[child[s]];
|
||||
} else {
|
||||
size[child[s]] = size[s];
|
||||
s = ancestor[s] = child[s];
|
||||
}
|
||||
}
|
||||
label[s] = label[w];
|
||||
size[vx] += size[w];
|
||||
if(size[vx] < (size[w] << 1)) {
|
||||
Uint32 t = s;
|
||||
s = child[vx];
|
||||
child[vx] = t;
|
||||
}
|
||||
while( s != 0 ) {
|
||||
ancestor[s] = vx;
|
||||
s = child[s];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DominatorGraph::COMPRESS(Uint32 vx)
|
||||
{
|
||||
if(ancestor[ancestor[vx]] != 0) {
|
||||
COMPRESS(ancestor[vx]);
|
||||
if(semi[label[ancestor[vx]]] < semi[label[vx]])
|
||||
label[vx] = label[ancestor[vx]];
|
||||
ancestor[vx] = ancestor[ancestor[vx]];
|
||||
}
|
||||
}
|
||||
|
||||
Uint32 DominatorGraph::EVAL(Uint32 vx)
|
||||
{
|
||||
if(ancestor[vx] == 0)
|
||||
return label[vx];
|
||||
COMPRESS(vx);
|
||||
return (semi[label[ancestor[vx]]] >= semi[label[vx]]) ? label[vx] : label[ancestor[vx]];
|
||||
}
|
||||
|
||||
void DominatorGraph::build()
|
||||
{
|
||||
Uint32 n = DFS(GtoV[0], 0);
|
||||
size[0] = label[0] = semi[0];
|
||||
|
||||
for (Uint32 i = n; i >= 2; i--) {
|
||||
Uint32 w = vertex[i];
|
||||
|
||||
ControlNode& node = *controlGraph.dfsList[VtoG[w]];
|
||||
const DoublyLinkedList<ControlEdge>& predecessors = node.getPredecessors();
|
||||
for (DoublyLinkedList<ControlEdge>::iterator p = predecessors.begin(); !predecessors.done(p); p = predecessors.advance(p)) {
|
||||
Uint32 vx = GtoV[predecessors.get(p).getSource().dfsNum];
|
||||
Uint32 u = EVAL(vx);
|
||||
|
||||
if(semi[u] < semi[w])
|
||||
semi[w] = semi[u];
|
||||
}
|
||||
|
||||
DGLinkedList* elem = new DGLinkedList();
|
||||
elem->next = bucket[vertex[semi[w]]];
|
||||
elem->index = w;
|
||||
bucket[vertex[semi[w]]] = elem;
|
||||
|
||||
LINK(parent[w], w);
|
||||
|
||||
elem = bucket[parent[w]];
|
||||
while(elem != NULL) {
|
||||
Uint32 vx = elem->index;
|
||||
Uint32 u = EVAL(vx);
|
||||
dom[vx] = (semi[u] < semi[vx]) ? u : parent[w];
|
||||
elem = elem->next;
|
||||
}
|
||||
}
|
||||
|
||||
memset(size, '\0', n * sizeof(Uint32));
|
||||
Pool& pool = controlGraph.pool;
|
||||
nodes = new(pool) DGNode[n];
|
||||
|
||||
for(Uint32 j = 2; j <= n; j++) {
|
||||
Uint32 w = vertex[j];
|
||||
Uint32 d = dom[w];
|
||||
if(d != vertex[semi[w]]) {
|
||||
d = dom[d];
|
||||
dom[w] = d;
|
||||
}
|
||||
size[d]++;
|
||||
}
|
||||
dom[GtoV[0]] = 0;
|
||||
|
||||
for (Uint32 k = 1; k <= n; k++) {
|
||||
DGNode& node = nodes[VtoG[k]];
|
||||
Uint32 count = size[k];
|
||||
node.successorsEnd = node.successorsBegin = (count) ? new(pool) Uint32[count] : (Uint32*) 0;
|
||||
}
|
||||
|
||||
for (Uint32 l = 2; l <= n; l++)
|
||||
*(nodes[VtoG[dom[l]]].successorsEnd)++ = VtoG[l];
|
||||
}
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
void DominatorGraph::printPretty(LogModuleObject log)
|
||||
{
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("Dominator Graph:\n"));
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
for (Uint32 i = 0; i < nNodes; i++) {
|
||||
DGNode& node = nodes[i];
|
||||
if (node.successorsBegin != node.successorsEnd) {
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\tN%d dominates ", i));
|
||||
for (Uint32* successorsPtr = node.successorsBegin; successorsPtr < node.successorsEnd; successorsPtr++)
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("N%d ", *successorsPtr));
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\n"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // DEBUG_LOG
|
||||
|
||||
|
||||
|
||||
80
mozilla/ef/Compiler/RegisterAllocator/DominatorGraph.h
Normal file
80
mozilla/ef/Compiler/RegisterAllocator/DominatorGraph.h
Normal file
@@ -0,0 +1,80 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _DOMINATOR_GRAPH_H_
|
||||
#define _DOMINATOR_GRAPH_H_
|
||||
|
||||
#include "LogModule.h"
|
||||
|
||||
class ControlGraph;
|
||||
|
||||
struct DGNode
|
||||
{
|
||||
Uint32* successorsBegin;
|
||||
Uint32* successorsEnd;
|
||||
};
|
||||
|
||||
struct DGLinkedList
|
||||
{
|
||||
DGLinkedList* next;
|
||||
Uint32 index;
|
||||
};
|
||||
|
||||
class DominatorGraph
|
||||
{
|
||||
private:
|
||||
|
||||
ControlGraph& controlGraph;
|
||||
|
||||
Uint32 vCount;
|
||||
|
||||
Uint32* VtoG;
|
||||
Uint32* GtoV;
|
||||
Uint32* parent;
|
||||
Uint32* semi;
|
||||
Uint32* vertex;
|
||||
Uint32* label;
|
||||
Uint32* size;
|
||||
Uint32* ancestor;
|
||||
Uint32* child;
|
||||
Uint32* dom;
|
||||
DGLinkedList** bucket;
|
||||
DGNode* nodes;
|
||||
|
||||
private:
|
||||
|
||||
void build();
|
||||
|
||||
Uint32 DFS(Uint32 vx, Uint32 n);
|
||||
void LINK(Uint32 vx, Uint32 w);
|
||||
void COMPRESS(Uint32 vx);
|
||||
Uint32 EVAL(Uint32 vx);
|
||||
|
||||
public:
|
||||
|
||||
DominatorGraph(ControlGraph& controlGraph);
|
||||
|
||||
Uint32* getSuccessorsBegin(Uint32 n) const {return nodes[n].successorsBegin;}
|
||||
Uint32* getSuccessorsEnd(Uint32 n) const {return nodes[n].successorsEnd;}
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
void printPretty(LogModuleObject log);
|
||||
#endif // DEBUG_LOG
|
||||
};
|
||||
|
||||
#endif // _DOMINATOR_GRAPH_H_
|
||||
20
mozilla/ef/Compiler/RegisterAllocator/HashSet.cpp
Normal file
20
mozilla/ef/Compiler/RegisterAllocator/HashSet.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "HashSet.h"
|
||||
97
mozilla/ef/Compiler/RegisterAllocator/HashSet.h
Normal file
97
mozilla/ef/Compiler/RegisterAllocator/HashSet.h
Normal file
@@ -0,0 +1,97 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _HASH_SET_H_
|
||||
#define _HASH_SET_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "Pool.h"
|
||||
#include <string.h>
|
||||
|
||||
struct HashSetElement
|
||||
{
|
||||
Uint32 index;
|
||||
HashSetElement* next;
|
||||
};
|
||||
|
||||
class HashSet
|
||||
{
|
||||
private:
|
||||
|
||||
static const hashSize = 64;
|
||||
|
||||
// Return the hash code for the given element index.
|
||||
static Uint32 getHashCode(Uint32 index) {return index & (hashSize - 1);} // Could be better !
|
||||
|
||||
private:
|
||||
|
||||
Pool& allocationPool;
|
||||
HashSetElement** bucket;
|
||||
HashSetElement* free;
|
||||
|
||||
private:
|
||||
|
||||
// No copy constructor.
|
||||
HashSet(const HashSet&);
|
||||
// No copy operator.
|
||||
void operator = (const HashSet&);
|
||||
|
||||
public:
|
||||
|
||||
// Create a new HashSet.
|
||||
inline HashSet(Pool& pool, Uint32 universeSize);
|
||||
|
||||
// Clear the hashset.
|
||||
void clear();
|
||||
// Clear the element for the given index.
|
||||
void clear(Uint32 index);
|
||||
// Set the element for the given index.
|
||||
void set(Uint32 index);
|
||||
// Return true if the element at index is a member.
|
||||
bool test(Uint32 index) const;
|
||||
// Union with the given hashset.
|
||||
inline void or(const HashSet& set);
|
||||
// Intersection with the given hashset.
|
||||
inline void and(const HashSet& set);
|
||||
// Difference with the given hashset.
|
||||
inline void difference(const HashSet& set);
|
||||
|
||||
// Logical operators.
|
||||
HashSet& operator |= (const HashSet& set) {or(set); return *this;}
|
||||
HashSet& operator &= (const HashSet& set) {and(set); return *this;}
|
||||
HashSet& operator -= (const HashSet& set) {difference(set); return *this;}
|
||||
|
||||
// Iterator to conform with the set API.
|
||||
typedef HashSetElement* iterator;
|
||||
// Return the iterator for the first element of this set.
|
||||
iterator begin() const;
|
||||
// Return the next iterator.
|
||||
iterator advance(iterator pos) const;
|
||||
// Return true if the iterator is at the end of the set.
|
||||
bool done(iterator pos) const {return pos == NULL;}
|
||||
};
|
||||
|
||||
|
||||
inline HashSet::HashSet(Pool& pool, Uint32 /*universeSize*/)
|
||||
: allocationPool(pool), free(NULL)
|
||||
{
|
||||
bucket = new(pool) HashSetElement*[hashSize];
|
||||
memset(bucket, '\0', sizeof(HashSetElement*));
|
||||
}
|
||||
|
||||
#endif // _HASH_SET_H_
|
||||
213
mozilla/ef/Compiler/RegisterAllocator/IndexedPool.h
Normal file
213
mozilla/ef/Compiler/RegisterAllocator/IndexedPool.h
Normal file
@@ -0,0 +1,213 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _INDEXED_POOL_H_
|
||||
#define _INDEXED_POOL_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// IndexedPool<IndexedObjectSubclass> is an indexed pool of objects. The
|
||||
// template parameter 'IndexedObjectSubclass' must be a subclass of the struct
|
||||
// IndexedObject.
|
||||
//
|
||||
// When the indexed pool is ask to allocate and initialize a new object (using
|
||||
// the operator new(anIndexedPool) it will zero the memory used to store the
|
||||
// object and initialize the field 'index' of this object to its position in
|
||||
// the pool.
|
||||
//
|
||||
// An object allocated by the indexed pool can be freed by calling the method
|
||||
// IndexedPool::release(IndexedElement& objectIndex).
|
||||
//
|
||||
// example:
|
||||
//
|
||||
// IndexedPool<IndexedElement> elementPool;
|
||||
//
|
||||
// IndexedElement& element1 = *new(elementPool) IndexedElement();
|
||||
// IndexedElement& element2 = *new(elementPool) IndexedElement();
|
||||
//
|
||||
// indexedPool.release(element1);
|
||||
// IndexedElement& element3 = *new(elementPool) IndexedElement();
|
||||
//
|
||||
// At this point element1 is no longer a valid object, element2 is at
|
||||
// index 2 and element3 is at index 1.
|
||||
//
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// IndexedObject -
|
||||
//
|
||||
|
||||
template<class Object>
|
||||
struct IndexedObject
|
||||
{
|
||||
Uint32 index; // Index in the pool.
|
||||
Object* next; // Used to link IndexedObject together.
|
||||
|
||||
Uint32 getIndex() {return index;}
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// IndexedPool<IndexedObject> -
|
||||
//
|
||||
|
||||
template <class IndexedObject>
|
||||
class IndexedPool
|
||||
{
|
||||
private:
|
||||
|
||||
static const blockSize = 4; // Size of one block.
|
||||
|
||||
Uint32 nBlocks; // Number of blocks in the pool.
|
||||
IndexedObject** block; // Array of block pointers.
|
||||
IndexedObject* freeObjects; // Chained list of free IndexedObjects.
|
||||
Uint32 nextIndex; // Index of the next free object in the last block.
|
||||
|
||||
private:
|
||||
|
||||
void allocateAnotherBlock();
|
||||
IndexedObject& newObject();
|
||||
|
||||
public:
|
||||
|
||||
IndexedPool() : nBlocks(0), block(NULL), freeObjects(NULL), nextIndex(1) {}
|
||||
~IndexedPool();
|
||||
|
||||
IndexedObject& get(Uint32 index) const;
|
||||
void release(IndexedObject& object);
|
||||
|
||||
void setSize(Uint32 size) {assert(size < nextIndex); nextIndex = size;}
|
||||
|
||||
// Return the universe size.
|
||||
Uint32 getSize() {return nextIndex;}
|
||||
|
||||
friend void* operator new(size_t, IndexedPool<IndexedObject>& pool); // Needs to call newObject().
|
||||
};
|
||||
|
||||
// Free all the memory allocated for this object.
|
||||
//
|
||||
template <class IndexedObject>
|
||||
IndexedPool<IndexedObject>::~IndexedPool()
|
||||
{
|
||||
for (Uint32 n = 0; n < nBlocks; n++)
|
||||
free(&((IndexedObject **) &block[n][n*blockSize])[-(n + 1)]);
|
||||
}
|
||||
|
||||
// Release the given. This object will be iserted in the chained
|
||||
// list of free IndexedObjects. To minimize the fragmentation the chained list
|
||||
// is ordered by ascending indexes.
|
||||
//
|
||||
template <class IndexedObject>
|
||||
void IndexedPool<IndexedObject>::release(IndexedObject& object)
|
||||
{
|
||||
Uint32 index = object.index;
|
||||
IndexedObject* list = freeObjects;
|
||||
|
||||
assert(&object == &get(index)); // Make sure that object is owned by this pool.
|
||||
|
||||
if (list == NULL) { // The list is empty.
|
||||
freeObjects = &object;
|
||||
object.next = NULL;
|
||||
} else { // The list contains at least 1 element.
|
||||
if (index < list->index) { // insert as first element.
|
||||
freeObjects = &object;
|
||||
object.next = list;
|
||||
} else { // Find this object's place.
|
||||
while ((list->next) != NULL && (list->next->index < index))
|
||||
list = list->next;
|
||||
|
||||
object.next = list->next;
|
||||
list->next = &object;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
// Sanity check to be sure that the list is correctly ordered.
|
||||
for (IndexedObject* obj = freeObjects; obj != NULL; obj = obj->next)
|
||||
if (obj->next != NULL)
|
||||
assert(obj->index < obj->next->index);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Create a new block of IndexedObjects. We will allocate the memory to
|
||||
// store IndexedPool::blockSize IndexedObject and the new Array of block
|
||||
// pointers.
|
||||
// The newly created IndexedObjects will not be initialized.
|
||||
//
|
||||
template <class IndexedObject>
|
||||
void IndexedPool<IndexedObject>::allocateAnotherBlock()
|
||||
{
|
||||
void* memory = (void *) malloc((nBlocks + 1) * sizeof(Uint32) + blockSize * sizeof(IndexedObject));
|
||||
|
||||
memcpy(memory, block, nBlocks * sizeof(Uint32));
|
||||
|
||||
block = (IndexedObject **) memory;
|
||||
IndexedObject* objects = (IndexedObject *) &block[nBlocks + 1];
|
||||
|
||||
block[nBlocks] = &objects[-(nBlocks * blockSize)];
|
||||
nBlocks++;
|
||||
}
|
||||
|
||||
// Return the IndexedObject at the position 'index' in the pool.
|
||||
//
|
||||
template <class IndexedObject>
|
||||
IndexedObject& IndexedPool<IndexedObject>::get(Uint32 index) const
|
||||
{
|
||||
Uint32 blockIndex = index / blockSize;
|
||||
assert(blockIndex < nBlocks);
|
||||
|
||||
return block[blockIndex][index];
|
||||
}
|
||||
|
||||
// Return the reference of an unused object in the pool.
|
||||
//
|
||||
template <class IndexedObject>
|
||||
IndexedObject& IndexedPool<IndexedObject>::newObject()
|
||||
{
|
||||
if (freeObjects != NULL) {
|
||||
IndexedObject& newObject = *freeObjects;
|
||||
freeObjects = newObject.next;
|
||||
return newObject;
|
||||
}
|
||||
|
||||
Uint32 nextIndex = this->nextIndex++;
|
||||
Uint32 blockIndex = nextIndex / blockSize;
|
||||
|
||||
while (blockIndex >= nBlocks)
|
||||
allocateAnotherBlock();
|
||||
|
||||
IndexedObject& newObject = block[blockIndex][nextIndex];
|
||||
newObject.index = nextIndex;
|
||||
|
||||
return newObject;
|
||||
}
|
||||
|
||||
// Return the address of the next unsused object in the given
|
||||
// indexed pool. The field index of the newly allocated object
|
||||
// will be initialized to the corresponding index of this object
|
||||
// in the pool.
|
||||
//
|
||||
template <class IndexedObject>
|
||||
void* operator new(size_t size, IndexedPool<IndexedObject>& pool)
|
||||
{
|
||||
assert(size == sizeof(IndexedObject));
|
||||
return (void *) &pool.newObject();
|
||||
}
|
||||
|
||||
#endif // _INDEXED_POOL_H_
|
||||
258
mozilla/ef/Compiler/RegisterAllocator/InterferenceGraph.h
Normal file
258
mozilla/ef/Compiler/RegisterAllocator/InterferenceGraph.h
Normal file
@@ -0,0 +1,258 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _INTERFERENCE_GRAPH_H_
|
||||
#define _INTERFERENCE_GRAPH_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "ControlGraph.h"
|
||||
#include "Primitives.h"
|
||||
#include "Instruction.h"
|
||||
#include "VirtualRegister.h"
|
||||
#include "RegisterPressure.h"
|
||||
#include "SparseSet.h"
|
||||
#include <string.h>
|
||||
|
||||
struct InterferenceVector
|
||||
{
|
||||
Uint32 count;
|
||||
InterferenceVector* next;
|
||||
RegisterName* neighbors;
|
||||
|
||||
InterferenceVector() : count(0), next(NULL) {}
|
||||
};
|
||||
|
||||
class RegisterAllocator;
|
||||
|
||||
template <class RegisterPressure>
|
||||
class InterferenceGraph
|
||||
{
|
||||
private:
|
||||
|
||||
RegisterAllocator& registerAllocator;
|
||||
|
||||
RegisterPressure::Set* interferences;
|
||||
InterferenceVector** vector;
|
||||
Uint32* offset;
|
||||
Uint32 rangeCount;
|
||||
|
||||
private:
|
||||
|
||||
// No copy constructor.
|
||||
InterferenceGraph(const InterferenceGraph&);
|
||||
// No copy operator.
|
||||
void operator = (const InterferenceGraph&);
|
||||
|
||||
// Check if reg is a member of the universe.
|
||||
void checkMember(RegisterName name) {assert(name < rangeCount);}
|
||||
// Return the edge index for the interference between name1 and name2.
|
||||
Uint32 getEdgeIndex(RegisterName name1, RegisterName name2);
|
||||
|
||||
public:
|
||||
InterferenceGraph(RegisterAllocator& registerAllocator) : registerAllocator(registerAllocator) {}
|
||||
|
||||
// Calculate the interferences.
|
||||
void build();
|
||||
// Return true if reg1 and reg2 interfere.
|
||||
bool interfere(RegisterName name1, RegisterName name2);
|
||||
// Return the interference vector for the given register or NULL if there is none.
|
||||
InterferenceVector* getInterferenceVector(RegisterName name) {return vector[name];}
|
||||
// Set the interference between name1 and name2.
|
||||
void setInterference(RegisterName name1, RegisterName name2);
|
||||
// Set the interference vector for the given register.
|
||||
void setInterferenceVector(RegisterName name, InterferenceVector* v) {vector[name] = v;}
|
||||
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
// Print the interferences.
|
||||
void printPretty(LogModuleObject log);
|
||||
#endif // DEBUG_LOG
|
||||
};
|
||||
|
||||
template <class RegisterPressure>
|
||||
void InterferenceGraph<RegisterPressure>::build()
|
||||
{
|
||||
Pool& pool = registerAllocator.pool;
|
||||
Uint32 rangeCount = registerAllocator.rangeCount;
|
||||
this->rangeCount = rangeCount;
|
||||
|
||||
// Initialize the structures.
|
||||
//
|
||||
offset = new(pool) Uint32[rangeCount + 1];
|
||||
vector = new(pool) InterferenceVector*[rangeCount];
|
||||
memset(vector, '\0', sizeof(InterferenceVector*) * rangeCount);
|
||||
|
||||
Uint32 o = 0;
|
||||
offset[0] = 0;
|
||||
for (Uint32 i = 1; i <= rangeCount; ++i) {
|
||||
offset[i] = o;
|
||||
o += i;
|
||||
}
|
||||
|
||||
interferences = new(pool) RegisterPressure::Set(pool, (rangeCount * rangeCount) / 2);
|
||||
|
||||
ControlGraph& controlGraph = registerAllocator.controlGraph;
|
||||
ControlNode** nodes = controlGraph.dfsList;
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
|
||||
RegisterName* name2range = registerAllocator.name2range;
|
||||
LivenessInfo<RegisterPressure> liveness = Liveness<RegisterPressure>::analysis(controlGraph, rangeCount, name2range);
|
||||
registerAllocator.liveness = liveness;
|
||||
SparseSet currentLive(pool, rangeCount);
|
||||
|
||||
for (Uint32 n = 0; n < nNodes; n++) {
|
||||
ControlNode& node = *nodes[n];
|
||||
currentLive = liveness.liveOut[n];
|
||||
|
||||
InstructionList& instructions = node.getInstructions();
|
||||
for (InstructionList::iterator i = instructions.end(); !instructions.done(i); i = instructions.retreat(i)) {
|
||||
Instruction& instruction = instructions.get(i);
|
||||
|
||||
InstructionUse* useBegin = instruction.getInstructionUseBegin();
|
||||
InstructionUse* useEnd = instruction.getInstructionUseEnd();
|
||||
InstructionUse* usePtr;
|
||||
InstructionDefine* defineBegin = instruction.getInstructionDefineBegin();
|
||||
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
|
||||
InstructionDefine* definePtr;
|
||||
|
||||
// Handle the copy instruction to avoid unnecessary interference between the 2 registers.
|
||||
if ((instruction.getFlags() & ifCopy) != 0) {
|
||||
assert(useBegin != useEnd && useBegin[0].isRegister());
|
||||
currentLive.clear(name2range[useBegin[0].getRegisterName()]);
|
||||
}
|
||||
|
||||
// Create the interferences.
|
||||
for (definePtr = defineBegin; definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister()) {
|
||||
RegisterName define = name2range[definePtr->getRegisterName()];
|
||||
|
||||
for (SparseSet::iterator e = currentLive.begin(); !currentLive.done(e); e = currentLive.advance(e)) {
|
||||
RegisterName live = RegisterName(currentLive.get(e));
|
||||
|
||||
if ((live != define) && !interfere(live, define) && registerAllocator.canInterfere(live, define)) {
|
||||
|
||||
if (vector[define] == NULL)
|
||||
vector[define] = new(pool) InterferenceVector();
|
||||
vector[define]->count++;
|
||||
|
||||
if (vector[live] == NULL)
|
||||
vector[live] = new(pool) InterferenceVector();
|
||||
vector[live]->count++;
|
||||
|
||||
setInterference(live, define);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Now update the liveness.
|
||||
//
|
||||
for (definePtr = defineBegin; definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister())
|
||||
currentLive.clear(name2range[definePtr->getRegisterName()]);
|
||||
|
||||
for (usePtr = useBegin; usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister())
|
||||
currentLive.set(name2range[usePtr->getRegisterName()]);
|
||||
}
|
||||
}
|
||||
|
||||
// Allocate the memory to store the interferences.
|
||||
//
|
||||
for (Uint32 e = 0; e < rangeCount; e++)
|
||||
if (vector[e] != NULL) {
|
||||
InterferenceVector& v = *vector[e];
|
||||
v.neighbors = new(pool) RegisterName[v.count];
|
||||
v.count = 0;
|
||||
}
|
||||
|
||||
// Initialize the edges.
|
||||
//
|
||||
if (RegisterPressure::Set::isOrdered()) {
|
||||
RegisterName name1 = RegisterName(0);
|
||||
|
||||
for (RegisterPressure::Set::iterator i = interferences->begin(); !interferences->done(i); i = interferences->advance(i)) {
|
||||
Uint32 interferenceIndex = interferences->get(i);
|
||||
|
||||
while(interferenceIndex >= offset[name1 + 1])
|
||||
name1 = RegisterName(name1 + 1);
|
||||
|
||||
assert((interferenceIndex >= offset[name1]) && (interferenceIndex < offset[name1 + 1]));
|
||||
|
||||
RegisterName name2 = RegisterName(interferenceIndex - offset[name1]);
|
||||
|
||||
assert(interfere(name1, name2));
|
||||
|
||||
InterferenceVector& vector1 = *vector[name1];
|
||||
vector1.neighbors[vector1.count++] = name2;
|
||||
|
||||
InterferenceVector& vector2 = *vector[name2];
|
||||
vector2.neighbors[vector2.count++] = name1;
|
||||
}
|
||||
} else {
|
||||
trespass("not Implemented"); // FIX: need one more pass to initialize the vectors.
|
||||
}
|
||||
}
|
||||
|
||||
template <class RegisterPressure>
|
||||
Uint32 InterferenceGraph<RegisterPressure>::getEdgeIndex(RegisterName name1, RegisterName name2)
|
||||
{
|
||||
checkMember(name1); checkMember(name2);
|
||||
assert(name1 != name2); // This is not possible.
|
||||
return (name1 < name2) ? offset[name2] + name1 : offset[name1] + name2;
|
||||
}
|
||||
|
||||
template <class RegisterPressure>
|
||||
void InterferenceGraph<RegisterPressure>::setInterference(RegisterName name1, RegisterName name2)
|
||||
{
|
||||
interferences->set(getEdgeIndex(name1, name2));
|
||||
}
|
||||
|
||||
template <class RegisterPressure>
|
||||
bool InterferenceGraph<RegisterPressure>::interfere(RegisterName name1, RegisterName name2)
|
||||
{
|
||||
return interferences->test(getEdgeIndex(name1, name2));
|
||||
}
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
template <class RegisterPressure>
|
||||
void InterferenceGraph<RegisterPressure>::printPretty(LogModuleObject log)
|
||||
{
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("Interference Vectors:\n"));
|
||||
for (Uint32 i = 1; i < rangeCount; i++) {
|
||||
if (vector[i] != NULL) {
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\tvr%d: (", i));
|
||||
for (InterferenceVector* v = vector[i]; v != NULL; v = v->next)
|
||||
for (Uint32 j = 0; j < v->count; j++) {
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("%d", v->neighbors[j]));
|
||||
if (v->next != NULL || j != (v->count - 1))
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, (","));
|
||||
}
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, (")\n"));
|
||||
}
|
||||
}
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("Interference Matrix:\n"));
|
||||
for (RegisterName name1 = RegisterName(1); name1 < rangeCount; name1 = RegisterName(name1 + 1)) {
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\t%d:\t", name1));
|
||||
for (RegisterName name2 = RegisterName(1); name2 < rangeCount; name2 = RegisterName(name2 + 1))
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("%c", ((name1 != name2) && interfere(name1, name2)) ? '1' : '0'));
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\n"));
|
||||
}
|
||||
}
|
||||
#endif // DEBUG_LOG
|
||||
|
||||
#endif // _INTERFERENCE_GRAPH_H_
|
||||
87
mozilla/ef/Compiler/RegisterAllocator/LiveRange.h
Normal file
87
mozilla/ef/Compiler/RegisterAllocator/LiveRange.h
Normal file
@@ -0,0 +1,87 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _LIVE_RANGE_H_
|
||||
#define _LIVE_RANGE_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "ControlGraph.h"
|
||||
#include "ControlNodes.h"
|
||||
#include "Primitives.h"
|
||||
#include "Instruction.h"
|
||||
#include "RegisterAllocator.h"
|
||||
#include "RegisterAllocatorTools.h"
|
||||
|
||||
template <class RegisterPressure>
|
||||
struct LiveRange
|
||||
{
|
||||
static void build(RegisterAllocator& registerAllocator);
|
||||
};
|
||||
|
||||
template <class RegisterPressure>
|
||||
void LiveRange<RegisterPressure>::build(RegisterAllocator& registerAllocator)
|
||||
{
|
||||
// Intialize the lookup table.
|
||||
//
|
||||
Uint32 nameCount = registerAllocator.nameCount;
|
||||
RegisterName* nameTable = new(registerAllocator.pool) RegisterName[2*nameCount];
|
||||
RegisterName* rangeName = &nameTable[nameCount];
|
||||
|
||||
init(rangeName, nameCount);
|
||||
|
||||
// Walk the graph.
|
||||
//
|
||||
ControlGraph& controlGraph = registerAllocator.controlGraph;
|
||||
ControlNode** nodes = controlGraph.dfsList;
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
|
||||
SparseSet destination(registerAllocator.pool, nameCount);
|
||||
|
||||
for (Uint32 n = 0; n < nNodes; n++) {
|
||||
InstructionList& phiNodes = nodes[n]->getPhiNodeInstructions();
|
||||
|
||||
destination.clear();
|
||||
for (InstructionList::iterator i = phiNodes.begin(); !phiNodes.done(i); i = phiNodes.advance(i)) {
|
||||
Instruction& phiNode = phiNodes.get(i);
|
||||
assert(phiNode.getInstructionDefineBegin() != phiNode.getInstructionDefineEnd() && phiNode.getInstructionDefineBegin()[0].isRegister());
|
||||
destination.set(findRoot(phiNode.getInstructionDefineBegin()[0].getRegisterName(), rangeName));
|
||||
}
|
||||
|
||||
for (InstructionList::iterator p = phiNodes.begin(); !phiNodes.done(p); p = phiNodes.advance(p)) {
|
||||
Instruction& phiNode = phiNodes.get(p);
|
||||
|
||||
assert(phiNode.getInstructionDefineBegin() != phiNode.getInstructionDefineEnd() && phiNode.getInstructionDefineBegin()[0].isRegister());
|
||||
RegisterName destinationName = phiNode.getInstructionDefineBegin()[0].getRegisterName();
|
||||
RegisterName destinationRoot = findRoot(destinationName, rangeName);
|
||||
|
||||
InstructionUse* useEnd = phiNode.getInstructionUseEnd();
|
||||
for (InstructionUse* usePtr = phiNode.getInstructionUseBegin(); usePtr < useEnd; usePtr++) {
|
||||
assert(usePtr->isRegister());
|
||||
RegisterName sourceName = usePtr->getRegisterName();
|
||||
RegisterName sourceRoot = findRoot(sourceName, rangeName);
|
||||
|
||||
if (sourceRoot != destinationRoot && !destination.test(sourceRoot))
|
||||
rangeName[sourceRoot] = destinationRoot;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
registerAllocator.rangeCount = compress(registerAllocator.name2range, rangeName, nameCount, nameCount);
|
||||
}
|
||||
|
||||
#endif // _LIVE_RANGE_H_
|
||||
163
mozilla/ef/Compiler/RegisterAllocator/LiveRangeGraph.h
Normal file
163
mozilla/ef/Compiler/RegisterAllocator/LiveRangeGraph.h
Normal file
@@ -0,0 +1,163 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _LIVE_RANGE_GRAPH_
|
||||
#define _LIVE_RANGE_GRAPH_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "Pool.h"
|
||||
#include "ControlGraph.h"
|
||||
#include "ControlNodes.h"
|
||||
#include "Instruction.h"
|
||||
#include "RegisterTypes.h"
|
||||
|
||||
class RegisterAllocator;
|
||||
|
||||
template <class RegisterPressure>
|
||||
class LiveRangeGraph
|
||||
{
|
||||
private:
|
||||
|
||||
RegisterAllocator& registerAllocator;
|
||||
|
||||
RegisterPressure::Set* edges;
|
||||
Uint32 rangeCount;
|
||||
|
||||
public:
|
||||
//
|
||||
//
|
||||
LiveRangeGraph(RegisterAllocator& registerAllocator) : registerAllocator(registerAllocator) {}
|
||||
|
||||
//
|
||||
//
|
||||
void build();
|
||||
|
||||
//
|
||||
//
|
||||
void addEdge(RegisterName name1, RegisterName name2);
|
||||
|
||||
//
|
||||
//
|
||||
bool haveEdge(RegisterName name1, RegisterName name2);
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
//
|
||||
//
|
||||
void printPretty(LogModuleObject log);
|
||||
#endif // DEBUG_LOG
|
||||
};
|
||||
|
||||
template <class RegisterPressure>
|
||||
void LiveRangeGraph<RegisterPressure>::build()
|
||||
{
|
||||
Pool& pool = registerAllocator.pool;
|
||||
Uint32 rangeCount = registerAllocator.rangeCount;
|
||||
this->rangeCount = rangeCount;
|
||||
|
||||
edges = new(pool) RegisterPressure::Set(pool, rangeCount * rangeCount);
|
||||
|
||||
ControlGraph& controlGraph = registerAllocator.controlGraph;
|
||||
ControlNode** nodes = controlGraph.dfsList;
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
|
||||
RegisterName* name2range = registerAllocator.name2range;
|
||||
LivenessInfo<RegisterPressure>& liveness = registerAllocator.liveness;
|
||||
SparseSet currentLive(pool, rangeCount);
|
||||
|
||||
for (Uint32 n = 0; n < nNodes; n++) {
|
||||
ControlNode& node = *nodes[n];
|
||||
currentLive = liveness.liveOut[n];
|
||||
|
||||
InstructionList& instructions = node.getInstructions();
|
||||
for (InstructionList::iterator i = instructions.end(); !instructions.done(i); i = instructions.retreat(i)) {
|
||||
Instruction& instruction = instructions.get(i);
|
||||
|
||||
InstructionUse* useBegin = instruction.getInstructionUseBegin();
|
||||
InstructionUse* useEnd = instruction.getInstructionUseEnd();
|
||||
InstructionUse* usePtr;
|
||||
InstructionDefine* defineBegin = instruction.getInstructionDefineBegin();
|
||||
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
|
||||
InstructionDefine* definePtr;
|
||||
|
||||
if ((instruction.getFlags() & ifCopy) != 0) {
|
||||
assert(useBegin != useEnd && useBegin[0].isRegister());
|
||||
currentLive.clear(name2range[useBegin[0].getRegisterName()]);
|
||||
}
|
||||
|
||||
for (definePtr = defineBegin; definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister()) {
|
||||
RegisterName define = name2range[definePtr->getRegisterName()];
|
||||
|
||||
for (SparseSet::iterator l = currentLive.begin(); !currentLive.done(l); l = currentLive.advance(l)) {
|
||||
RegisterName live = RegisterName(currentLive.get(l));
|
||||
if (define != live && registerAllocator.canInterfere(define, live))
|
||||
addEdge(define, live);
|
||||
}
|
||||
}
|
||||
|
||||
for (definePtr = defineBegin; definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister())
|
||||
currentLive.clear(name2range[definePtr->getRegisterName()]);
|
||||
|
||||
for (usePtr = useBegin; usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister())
|
||||
currentLive.set(name2range[usePtr->getRegisterName()]);
|
||||
|
||||
for (usePtr = useBegin; usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister()) {
|
||||
RegisterName use = name2range[usePtr->getRegisterName()];
|
||||
|
||||
for (SparseSet::iterator l = currentLive.begin(); !currentLive.done(l); l = currentLive.advance(l)) {
|
||||
RegisterName live = RegisterName(currentLive.get(l));
|
||||
if (use != live && registerAllocator.canInterfere(use, live))
|
||||
addEdge(use, live);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class RegisterPressure>
|
||||
void LiveRangeGraph<RegisterPressure>::addEdge(RegisterName name1, RegisterName name2)
|
||||
{
|
||||
assert(name1 != name2);
|
||||
edges->set(name1 * rangeCount + name2);
|
||||
}
|
||||
|
||||
template <class RegisterPressure>
|
||||
bool LiveRangeGraph<RegisterPressure>::haveEdge(RegisterName name1, RegisterName name2)
|
||||
{
|
||||
assert(name1 != name2);
|
||||
return edges->test(name1 * rangeCount + name2);
|
||||
}
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
template <class RegisterPressure>
|
||||
void LiveRangeGraph<RegisterPressure>::printPretty(LogModuleObject log)
|
||||
{
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("Live ranges graph:\n"));
|
||||
for (RegisterName name1 = RegisterName(1); name1 < rangeCount; name1 = RegisterName(name1 + 1)) {
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\t%d:\t", name1));
|
||||
for (RegisterName name2 = RegisterName(1); name2 < rangeCount; name2 = RegisterName(name2 + 1))
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("%c", ((name1 != name2) && haveEdge(name1, name2)) ? '1' : '0'));
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\n"));
|
||||
}
|
||||
}
|
||||
#endif // DEBUG_LOG
|
||||
|
||||
#endif // _LIVE_RANGE_GRAPH_
|
||||
21
mozilla/ef/Compiler/RegisterAllocator/Liveness.cpp
Normal file
21
mozilla/ef/Compiler/RegisterAllocator/Liveness.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "Liveness.h"
|
||||
|
||||
301
mozilla/ef/Compiler/RegisterAllocator/Liveness.h
Normal file
301
mozilla/ef/Compiler/RegisterAllocator/Liveness.h
Normal file
@@ -0,0 +1,301 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _LIVENESS_H_
|
||||
#define _LIVENESS_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "ControlGraph.h"
|
||||
#include "ControlNodes.h"
|
||||
#include "Instruction.h"
|
||||
#include "RegisterTypes.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// LivenessInfo -
|
||||
|
||||
template <class RegisterPressure>
|
||||
struct LivenessInfo
|
||||
{
|
||||
RegisterPressure::Set* liveIn;
|
||||
RegisterPressure::Set* liveOut;
|
||||
DEBUG_LOG_ONLY(Uint32 size);
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
void printPretty(LogModuleObject log);
|
||||
#endif // DEBUG_LOG
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Liveness
|
||||
//
|
||||
// The liveness is defined by the following data-flow equations:
|
||||
//
|
||||
// LiveIn(n) = LocalLive(n) U (LiveOut(n) - Killed(n)).
|
||||
// LiveOut(n) = U LiveIn(s) (s a successor of n).
|
||||
//
|
||||
// where LocalLive(n) is the set of used registers in the block n, Killed(n)
|
||||
// is the set of defined registers in the block n, LiveIn(n) is the set of
|
||||
// live registers at the begining of the block n and LiveOut(n) is the set
|
||||
// of live registers at the end of the block n.
|
||||
//
|
||||
//
|
||||
// We will compute the liveness analysis in two stages:
|
||||
//
|
||||
// 1- Build LocalLive(n) (wich is an approximation of LiveIn(n)) and Killed(n)
|
||||
// for each block n.
|
||||
// 2- Perform a backward data-flow analysis to propagate the liveness information
|
||||
// through the entire control-flow graph.
|
||||
//
|
||||
|
||||
template <class RegisterPressure>
|
||||
struct Liveness
|
||||
{
|
||||
static LivenessInfo<RegisterPressure> analysis(ControlGraph& controlGraph, Uint32 rangeCount, const RegisterName* name2range);
|
||||
static LivenessInfo<RegisterPressure> analysis(ControlGraph& controlGraph, Uint32 nameCount);
|
||||
};
|
||||
|
||||
template <class RegisterPressure>
|
||||
LivenessInfo<RegisterPressure> Liveness<RegisterPressure>::analysis(ControlGraph& controlGraph, Uint32 rangeCount, const RegisterName* name2range)
|
||||
{
|
||||
Pool& pool = controlGraph.pool;
|
||||
ControlNode** nodes = controlGraph.dfsList;
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
|
||||
// Allocate the temporary sets.
|
||||
RegisterPressure::Set* killed = new(pool) RegisterPressure::Set[nNodes](pool, rangeCount);
|
||||
|
||||
// Allocate the globals sets.
|
||||
RegisterPressure::Set* liveIn = new(pool) RegisterPressure::Set[nNodes](pool, rangeCount);
|
||||
RegisterPressure::Set* liveOut = new(pool) RegisterPressure::Set[nNodes](pool, rangeCount);
|
||||
|
||||
// First stage of the liveness analysis: Compute the sets LocalLive(stored in LiveIn) and Killed.
|
||||
//
|
||||
for (Uint32 n = 0; n < (nNodes - 1); n++) {
|
||||
ControlNode& node = *nodes[n];
|
||||
|
||||
RegisterPressure::Set& currentLocalLive = liveIn[n];
|
||||
RegisterPressure::Set& currentKilled = killed[n];
|
||||
|
||||
// Find the instructions contributions to the sets LocalLive and Killed.
|
||||
//
|
||||
InstructionList& instructions = node.getInstructions();
|
||||
for (InstructionList::iterator i = instructions.begin(); !instructions.done(i); i = instructions.advance(i)) {
|
||||
Instruction& instruction = instructions.get(i);
|
||||
|
||||
// If a VirtualRegister is 'used' before being 'defined' then we add it to set LocalLive.
|
||||
|
||||
InstructionUse* useEnd = instruction.getInstructionUseEnd();
|
||||
for (InstructionUse* usePtr = instruction.getInstructionUseBegin(); usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister()) {
|
||||
Uint32 index = name2range[usePtr->getRegisterName()];
|
||||
|
||||
if (!currentKilled.test(index))
|
||||
currentLocalLive.set(index);
|
||||
}
|
||||
|
||||
// If a Virtualregister is 'defined' then we add it to the set Killed.
|
||||
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
|
||||
for (InstructionDefine* definePtr = instruction.getInstructionDefineBegin(); definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister())
|
||||
currentKilled.set(name2range[definePtr->getRegisterName()]);
|
||||
}
|
||||
}
|
||||
|
||||
// Second stage of the liveness analysis: We propagate the LiveIn & LiveOut through the entire
|
||||
// control-flow graph.
|
||||
//
|
||||
RegisterPressure::Set temp(pool, rangeCount);
|
||||
|
||||
bool changed;
|
||||
do {
|
||||
changed = false;
|
||||
|
||||
// For all nodes is this graph except the endNode.
|
||||
for (Int32 n = (nNodes - 2); n >= 0; n--) {
|
||||
ControlNode& node = *nodes[n];
|
||||
|
||||
RegisterPressure::Set& currentLiveIn = liveIn[n];
|
||||
RegisterPressure::Set& currentLiveOut = liveOut[n];
|
||||
|
||||
// Compute temp = Union of LiveIn(s) (s a successor of this node) | usedByPhiNodes(n).
|
||||
// temp will be the new LiveOut(n).
|
||||
Uint32 nSuccessors = node.nSuccessors();
|
||||
if (nSuccessors != 0) {
|
||||
temp = liveIn[node.nthSuccessor(0).getTarget().dfsNum];
|
||||
for (Uint32 s = 1; s < nSuccessors; s++)
|
||||
temp |= liveIn[node.nthSuccessor(s).getTarget().dfsNum];
|
||||
} else
|
||||
temp.clear();
|
||||
|
||||
// If temp and LiveOut(n) differ then set LiveOut(n) = temp and recalculate the
|
||||
// new LiveIn(n).
|
||||
if (currentLiveOut != temp) {
|
||||
currentLiveOut = temp;
|
||||
temp -= killed[n]; // FIX: could be optimized with one call to unionDiff !
|
||||
temp |= currentLiveIn;
|
||||
|
||||
if (currentLiveIn != temp) {
|
||||
currentLiveIn = temp;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} while(changed);
|
||||
|
||||
LivenessInfo<RegisterPressure> liveness;
|
||||
liveness.liveIn = liveIn;
|
||||
liveness.liveOut = liveOut;
|
||||
DEBUG_LOG_ONLY(liveness.size = nNodes);
|
||||
return liveness;
|
||||
}
|
||||
|
||||
template <class RegisterPressure>
|
||||
LivenessInfo<RegisterPressure> Liveness<RegisterPressure>::analysis(ControlGraph& controlGraph, Uint32 nameCount)
|
||||
{
|
||||
Pool& pool = controlGraph.pool;
|
||||
ControlNode** nodes = controlGraph.dfsList;
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
|
||||
// Allocate the temporary sets.
|
||||
RegisterPressure::Set* killed = new(pool) RegisterPressure::Set[nNodes](pool, nameCount);
|
||||
RegisterPressure::Set* usedByPhiNodes = NULL;
|
||||
|
||||
// Allocate the globals sets.
|
||||
RegisterPressure::Set* liveIn = new(pool) RegisterPressure::Set[nNodes](pool, nameCount);
|
||||
RegisterPressure::Set* liveOut = new(pool) RegisterPressure::Set[nNodes](pool, nameCount);
|
||||
|
||||
// First stage of the liveness analysis: Compute the sets LocalLive(stored in LiveIn) and Killed.
|
||||
//
|
||||
for (Uint32 n = 0; n < (nNodes - 1); n++) {
|
||||
ControlNode& node = *nodes[n];
|
||||
|
||||
RegisterPressure::Set& currentLocalLive = liveIn[n];
|
||||
RegisterPressure::Set& currentKilled = killed[n];
|
||||
|
||||
InstructionList& phiNodes = node.getPhiNodeInstructions();
|
||||
|
||||
if ((usedByPhiNodes == NULL) && !phiNodes.empty())
|
||||
usedByPhiNodes = new(pool) RegisterPressure::Set[nNodes](pool, nameCount);
|
||||
|
||||
for (InstructionList::iterator p = phiNodes.begin(); !phiNodes.done(p); p = phiNodes.advance(p)) {
|
||||
Instruction& phiNode = phiNodes.get(p);
|
||||
|
||||
InstructionDefine& define = phiNode.getInstructionDefineBegin()[0];
|
||||
currentKilled.set(define.getRegisterName());
|
||||
|
||||
typedef DoublyLinkedList<ControlEdge> ControlEdgeList;
|
||||
const ControlEdgeList& predecessors = node.getPredecessors();
|
||||
ControlEdgeList::iterator p = predecessors.begin();
|
||||
InstructionUse* useEnd = phiNode.getInstructionUseEnd();
|
||||
for (InstructionUse* usePtr = phiNode.getInstructionUseBegin(); usePtr < useEnd; usePtr++, p = predecessors.advance(p))
|
||||
if (usePtr->isRegister())
|
||||
usedByPhiNodes[predecessors.get(p).getSource().dfsNum].set(usePtr->getRegisterName());
|
||||
}
|
||||
|
||||
// Find the instructions contributions to the sets LocalLive and Killed.
|
||||
//
|
||||
InstructionList& instructions = node.getInstructions();
|
||||
for (InstructionList::iterator i = instructions.begin(); !instructions.done(i); i = instructions.advance(i)) {
|
||||
Instruction& instruction = instructions.get(i);
|
||||
|
||||
// If a VirtualRegister is 'used' before being 'defined' then we add it to set LocalLive.
|
||||
|
||||
InstructionUse* useEnd = instruction.getInstructionUseEnd();
|
||||
for (InstructionUse* usePtr = instruction.getInstructionUseBegin(); usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister()) {
|
||||
Uint32 index = usePtr->getRegisterName();
|
||||
|
||||
if (!currentKilled.test(index))
|
||||
currentLocalLive.set(index);
|
||||
}
|
||||
|
||||
// If a Virtualregister is 'defined' then we add it to the set Killed.
|
||||
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
|
||||
for (InstructionDefine* definePtr = instruction.getInstructionDefineBegin(); definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister())
|
||||
currentKilled.set(definePtr->getRegisterName());
|
||||
}
|
||||
}
|
||||
|
||||
// Second stage of the liveness analysis: We propagate the LiveIn & LiveOut through the entire
|
||||
// control-flow graph.
|
||||
//
|
||||
RegisterPressure::Set temp(pool, nameCount);
|
||||
|
||||
bool changed;
|
||||
do {
|
||||
changed = false;
|
||||
|
||||
// For all nodes is this graph except the endNode.
|
||||
for (Int32 n = (nNodes - 2); n >= 0; n--) {
|
||||
ControlNode& node = *nodes[n];
|
||||
|
||||
RegisterPressure::Set& currentLiveIn = liveIn[n];
|
||||
RegisterPressure::Set& currentLiveOut = liveOut[n];
|
||||
|
||||
// Compute temp = Union of LiveIn(s) (s a successor of this node) | usedByPhiNodes(n).
|
||||
// temp will be the new LiveOut(n).
|
||||
Uint32 nSuccessors = node.nSuccessors();
|
||||
if (nSuccessors != 0) {
|
||||
temp = liveIn[node.nthSuccessor(0).getTarget().dfsNum];
|
||||
for (Uint32 s = 1; s < nSuccessors; s++)
|
||||
temp |= liveIn[node.nthSuccessor(s).getTarget().dfsNum];
|
||||
} else
|
||||
temp.clear();
|
||||
|
||||
// Insert the phiNodes contribution.
|
||||
if (usedByPhiNodes != NULL)
|
||||
temp |= usedByPhiNodes[n];
|
||||
|
||||
// If temp and LiveOut(n) differ then set LiveOut(n) = temp and recalculate the
|
||||
// new LiveIn(n).
|
||||
if (currentLiveOut != temp) {
|
||||
currentLiveOut = temp;
|
||||
temp -= killed[n]; // FIX: could be optimized with one call to unionDiff !
|
||||
temp |= currentLiveIn;
|
||||
|
||||
if (currentLiveIn != temp) {
|
||||
currentLiveIn = temp;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} while(changed);
|
||||
|
||||
LivenessInfo<RegisterPressure> liveness;
|
||||
liveness.liveIn = liveIn;
|
||||
liveness.liveOut = liveOut;
|
||||
DEBUG_LOG_ONLY(liveness.size = nNodes);
|
||||
return liveness;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
template <class RegisterPressure>
|
||||
void LivenessInfo<RegisterPressure>::printPretty(LogModuleObject log)
|
||||
{
|
||||
for (Uint32 n = 0; n < size; n++) {
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("Node N%d:\n\tliveIn = ", n));
|
||||
liveIn[n].printPretty(log);
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\tliveOut = "));
|
||||
liveOut[n].printPretty(log);
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\n"));
|
||||
}
|
||||
}
|
||||
#endif // DEBUG_LOG
|
||||
|
||||
#endif // _LIVENESS_H_
|
||||
40
mozilla/ef/Compiler/RegisterAllocator/Makefile
Normal file
40
mozilla/ef/Compiler/RegisterAllocator/Makefile
Normal file
@@ -0,0 +1,40 @@
|
||||
#! gmake
|
||||
|
||||
DEPTH = ../..
|
||||
|
||||
MODULE_NAME = RegisterAllocator
|
||||
|
||||
include $(DEPTH)/config/config.mk
|
||||
|
||||
INCLUDES += \
|
||||
-I$(DEPTH)/Utilities/General \
|
||||
-I$(DEPTH)/Utilities/zlib \
|
||||
-I$(DEPTH)/Runtime/ClassReader \
|
||||
-I$(DEPTH)/Runtime/NativeMethods \
|
||||
-I$(DEPTH)/Runtime/System \
|
||||
-I$(DEPTH)/Runtime/ClassInfo \
|
||||
-I$(DEPTH)/Runtime/FileReader \
|
||||
-I$(DEPTH)/Compiler/PrimitiveGraph \
|
||||
-I$(DEPTH)/Compiler/FrontEnd \
|
||||
-I$(DEPTH)/Compiler/Optimizer \
|
||||
-I$(DEPTH)/Compiler/CodeGenerator \
|
||||
-I$(DEPTH)/Compiler/CodeGenerator/md \
|
||||
-I$(DEPTH)/Compiler/CodeGenerator/md/$(CPU_ARCH) \
|
||||
-I$(DEPTH)/Compiler/RegisterAllocator \
|
||||
-I$(DEPTH)/Driver/StandAloneJava \
|
||||
-I$(DEPTH)/Debugger \
|
||||
$(NULL)
|
||||
|
||||
CXXSRCS = \
|
||||
RegisterAllocator.cpp \
|
||||
RegisterAllocatorTools.cpp \
|
||||
DominatorGraph.cpp \
|
||||
VirtualRegister.cpp \
|
||||
BitSet.cpp \
|
||||
SparseSet.cpp \
|
||||
$(NULL)
|
||||
|
||||
|
||||
include $(DEPTH)/config/rules.mk
|
||||
|
||||
libs:: $(MODULE)
|
||||
392
mozilla/ef/Compiler/RegisterAllocator/PhiNodeRemover.h
Normal file
392
mozilla/ef/Compiler/RegisterAllocator/PhiNodeRemover.h
Normal file
@@ -0,0 +1,392 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _PHI_NODE_REMOVER_H_
|
||||
#define _PHI_NODE_REMOVER_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "Pool.h"
|
||||
#include "ControlGraph.h"
|
||||
#include "DominatorGraph.h"
|
||||
#include "VirtualRegister.h"
|
||||
#include "RegisterPressure.h"
|
||||
#include "Liveness.h"
|
||||
#include "Instruction.h"
|
||||
#include "InstructionEmitter.h"
|
||||
#include "SparseSet.h"
|
||||
#include <string.h>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// RegisterNameNode -
|
||||
|
||||
struct RegisterNameNode
|
||||
{
|
||||
RegisterNameNode* next;
|
||||
RegisterName newName;
|
||||
Uint32 nextPushed;
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// CopyData -
|
||||
|
||||
struct CopyData
|
||||
{
|
||||
RegisterName source;
|
||||
RegisterClassKind classKind;
|
||||
Uint32 useCount;
|
||||
bool isLiveOut;
|
||||
RegisterName sourceNameToUse;
|
||||
RegisterName temporaryName;
|
||||
RegisterNameNode* newName;
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// PhiNodeRemover<RegisterPressure> -
|
||||
|
||||
template <class RegisterPressure>
|
||||
struct PhiNodeRemover
|
||||
{
|
||||
// Replace the phi nodes by copy instructions.
|
||||
static void replacePhiNodes(ControlGraph& controlGraph, VirtualRegisterManager& vrManager, InstructionEmitter& emitter);
|
||||
};
|
||||
|
||||
// Split some of the critical edges and return true if there are still some
|
||||
// in the graph after that.
|
||||
//
|
||||
static bool splitCriticalEdges(ControlGraph& /*cg*/)
|
||||
{
|
||||
// FIX: not implemented.
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void pushName(Pool& pool, RegisterNameNode** stack, SparseSet& pushed, Uint32* nodeListPointer, RegisterName oldName, RegisterName newName)
|
||||
{
|
||||
RegisterNameNode& newNode = *new(pool) RegisterNameNode();
|
||||
|
||||
if (pushed.test(oldName))
|
||||
(*stack)->newName = newName;
|
||||
else {
|
||||
newNode.newName = newName;
|
||||
newNode.nextPushed = *nodeListPointer;
|
||||
*nodeListPointer = oldName;
|
||||
newNode.next = *stack;
|
||||
*stack = &newNode;
|
||||
pushed.set(oldName);
|
||||
}
|
||||
}
|
||||
|
||||
template <class RegisterPressure>
|
||||
void PhiNodeRemover<RegisterPressure>::replacePhiNodes(ControlGraph& controlGraph, VirtualRegisterManager& vrManager, InstructionEmitter& emitter)
|
||||
{
|
||||
Pool& pool = controlGraph.pool;
|
||||
ControlNode** nodes = controlGraph.dfsList;
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
|
||||
// Initialize the local variables.
|
||||
//
|
||||
|
||||
// When we insert the copies we will also need to create new VirtualRegisters for
|
||||
// the insertion of temporaries. The maximum number of temporary register will not
|
||||
// exceed the number of phiNodes in the primitive graph.
|
||||
Uint32 nameCount = vrManager.getSize();
|
||||
Uint32 maxNameCount = nameCount;
|
||||
for (Uint32 n = 0; n < nNodes; n++)
|
||||
maxNameCount += nodes[n]->getPhiNodes().length();
|
||||
|
||||
// If the CFG contains some critical edges (backward edge which source has more than one
|
||||
// outgoing edge and destination has more than one incomimg edge) then we need the liveness
|
||||
// information to be able to insert temporary copies.
|
||||
RegisterPressure::Set* liveOut = NULL;
|
||||
if (splitCriticalEdges(controlGraph))
|
||||
liveOut = Liveness<LowRegisterPressure>::analysis(controlGraph, nameCount).liveOut;
|
||||
|
||||
DominatorGraph dGraph(controlGraph);
|
||||
|
||||
SparseSet pushed(pool, maxNameCount);
|
||||
SparseSet destinationList(pool, maxNameCount);
|
||||
SparseSet workList(pool, maxNameCount);
|
||||
|
||||
CopyData* copyStats = new(pool) CopyData[maxNameCount];
|
||||
memset(copyStats, '\0', maxNameCount*sizeof(CopyData));
|
||||
|
||||
struct NodeStack {
|
||||
Uint32* next;
|
||||
Uint32* limit;
|
||||
Uint32 pushedList;
|
||||
};
|
||||
|
||||
// Allocate the node stack and initialize the node stack pointer.
|
||||
NodeStack* nodeStack = new(pool) NodeStack[nNodes + 1];
|
||||
NodeStack* nodeStackPtr = nodeStack;
|
||||
|
||||
// We start by the begin node.
|
||||
Uint32 startNode = 0;
|
||||
Uint32* next = &startNode;
|
||||
Uint32* limit = &startNode + 1;
|
||||
|
||||
while (true) {
|
||||
|
||||
if (next == limit) {
|
||||
// If there are no more node in the sibling, we have to pop the current
|
||||
// frame from the stack and update the copyStats of the pushed nodes.
|
||||
//
|
||||
if (nodeStackPtr == nodeStack)
|
||||
// We are at the bottom of the stack and there are no more nodes
|
||||
// to look at. We are done !
|
||||
break;
|
||||
|
||||
--nodeStackPtr;
|
||||
// We are done with all the children of this node in the dominator tree.
|
||||
// We need to update the copy information of all the new names pushed
|
||||
// during the walk over this node.
|
||||
Uint32 pushedList = nodeStackPtr->pushedList;
|
||||
while (pushedList != 0) {
|
||||
Uint32 nextName = copyStats[pushedList].newName->nextPushed;
|
||||
copyStats[pushedList].newName = copyStats[pushedList].newName->next;
|
||||
pushedList = nextName;
|
||||
}
|
||||
|
||||
// restore the previous frame.
|
||||
next = nodeStackPtr->next;
|
||||
limit = nodeStackPtr->limit;
|
||||
} else {
|
||||
Uint32 currentNode = *next++;
|
||||
Uint32 pushedList = 0;
|
||||
|
||||
|
||||
// Initialize the sets.
|
||||
pushed.clear();
|
||||
destinationList.clear();
|
||||
|
||||
// STEP1:
|
||||
// Walk the instruction list and to replace all the instruction uses with their new name.
|
||||
// If the instruction is a phi node and its defined register is alive at the end of this
|
||||
// block then we push the defined register into the stack.
|
||||
//
|
||||
ControlNode& node = *nodes[currentNode];
|
||||
RegisterPressure::Set* currentLiveOut = (liveOut != NULL) ? &liveOut[currentNode] : (RegisterPressure::Set*) 0;
|
||||
|
||||
InstructionList& phiNodes = node.getPhiNodeInstructions();
|
||||
for (InstructionList::iterator p = phiNodes.begin(); !phiNodes.done(p); p = phiNodes.advance(p)) {
|
||||
Instruction& phiNode = phiNodes.get(p);
|
||||
|
||||
InstructionUse* useEnd = phiNode.getInstructionUseEnd();
|
||||
for (InstructionUse* usePtr = phiNode.getInstructionUseBegin(); usePtr < useEnd; usePtr++) {
|
||||
assert(usePtr->isRegister());
|
||||
RegisterName name = usePtr->getRegisterName();
|
||||
|
||||
if (copyStats[name].newName != NULL && copyStats[name].newName->newName != name)
|
||||
usePtr->setRegisterName(copyStats[name].newName->newName);
|
||||
}
|
||||
|
||||
if (currentLiveOut != NULL) {
|
||||
// This is a phi node and we have to push its defined name if it is live
|
||||
// at the end of the node. We only need to do this if the CFG has critical edges.
|
||||
assert(phiNode.getInstructionDefineBegin() != phiNode.getInstructionDefineEnd() && phiNode.getInstructionDefineBegin()[0].isRegister());
|
||||
RegisterName name = phiNode.getInstructionDefineBegin()[0].getRegisterName();
|
||||
|
||||
if (currentLiveOut->test(name))
|
||||
pushName(pool, &(copyStats[name].newName), pushed, &pushedList, name, name);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
InstructionList& instructions = node.getInstructions();
|
||||
for (InstructionList::iterator i = instructions.begin(); !instructions.done(i); i = instructions.advance(i)) {
|
||||
Instruction& instruction = instructions.get(i);
|
||||
|
||||
InstructionUse* useEnd = instruction.getInstructionUseEnd();
|
||||
for (InstructionUse* usePtr = instruction.getInstructionUseBegin(); usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister()) {
|
||||
RegisterName name = usePtr->getRegisterName();
|
||||
|
||||
if (copyStats[name].newName != NULL && copyStats[name].newName->newName != name)
|
||||
usePtr->setRegisterName(copyStats[name].newName->newName);
|
||||
}
|
||||
}
|
||||
|
||||
// STEP2:
|
||||
// Look at this node's successors' phiNodes. We keep track of the number of time
|
||||
// a VR will be used by another copy instruction and insert each definition into the
|
||||
// destinationList. This is the only pass over this node's successors as we will
|
||||
// get all the information we need in the CopyData structures.
|
||||
//
|
||||
ControlEdge* successorEdgeEnd = node.getSuccessorsEnd();
|
||||
for (ControlEdge* successorEdgePtr = node.getSuccessorsBegin(); successorEdgePtr < successorEdgeEnd; successorEdgePtr++) {
|
||||
Uint32 useIndex = successorEdgePtr->getIndex();
|
||||
ControlNode& successor = successorEdgePtr->getTarget();
|
||||
|
||||
// Look at its phi nodes. The phi nodes are at the top of the instruction list. We exit
|
||||
// as soon as we find an instruction which is not a phi node
|
||||
InstructionList& phiNodes = successor.getPhiNodeInstructions();
|
||||
for (InstructionList::iterator p = phiNodes.begin(); !phiNodes.done(p); p = phiNodes.advance(p)) {
|
||||
Instruction& phiNode = phiNodes.get(p);
|
||||
|
||||
assert((phiNode.getInstructionUseBegin() + useIndex) < phiNode.getInstructionUseEnd());
|
||||
assert(phiNode.getInstructionDefineBegin() != phiNode.getInstructionDefineEnd());
|
||||
|
||||
InstructionUse& source = phiNode.getInstructionUseBegin()[useIndex];
|
||||
InstructionDefine& destination = phiNode.getInstructionDefineBegin()[0];
|
||||
|
||||
assert(source.isRegister() && destination.isRegister());
|
||||
|
||||
RegisterName sourceName = source.getRegisterName();
|
||||
RegisterName destinationName = destination.getRegisterName();
|
||||
|
||||
// Get the correct name for the source.
|
||||
if (copyStats[sourceName].newName != NULL)
|
||||
sourceName = copyStats[sourceName].newName->newName;
|
||||
|
||||
// Update the CopyData structures.
|
||||
if ((sourceName != rnInvalid) && (sourceName != destinationName)) {
|
||||
copyStats[destinationName].source = sourceName;
|
||||
copyStats[destinationName].classKind = destination.getRegisterClass();
|
||||
copyStats[destinationName].isLiveOut = (currentLiveOut != NULL) ? currentLiveOut->test(destinationName) : false;
|
||||
copyStats[destinationName].sourceNameToUse = destinationName;
|
||||
copyStats[sourceName].sourceNameToUse = sourceName;
|
||||
copyStats[sourceName].useCount++;
|
||||
destinationList.set(destinationName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// STEP3:
|
||||
// Insert into the worklist only the destination registers that will be not used in
|
||||
// another copy instruction in this block.
|
||||
//
|
||||
assert(workList.getSize() == 0);
|
||||
for (SparseSet::iterator d = destinationList.begin(); !destinationList.done(d); d = destinationList.advance(d)) {
|
||||
Uint32 dest = destinationList.get(d);
|
||||
if (copyStats[dest].useCount == 0)
|
||||
workList.set(dest);
|
||||
}
|
||||
|
||||
// STEP4:
|
||||
// Insert the copy instructions.
|
||||
//
|
||||
Uint32 destinationListSize = destinationList.getSize();
|
||||
InstructionList::iterator endOfTheNode = instructions.end();
|
||||
|
||||
// Find the right place to insert the copy instructions.
|
||||
if (destinationListSize != 0)
|
||||
while (instructions.get(endOfTheNode).getFlags() & ifControl)
|
||||
endOfTheNode = instructions.retreat(endOfTheNode);
|
||||
|
||||
while (destinationListSize != 0) {
|
||||
while(workList.getSize()) {
|
||||
RegisterName destinationName = RegisterName(workList.getOne());
|
||||
RegisterName sourceName = copyStats[destinationName].source;
|
||||
|
||||
workList.clear(destinationName);
|
||||
if (copyStats[destinationName].isLiveOut && !copyStats[destinationName].temporaryName) {
|
||||
// Lost copy problem.
|
||||
copyStats[destinationName].isLiveOut = false;
|
||||
|
||||
RegisterName sourceName = destinationName;
|
||||
RegisterClassKind classKind = copyStats[sourceName].classKind;
|
||||
RegisterName destinationName = getName(vrManager.newVirtualRegister(classKind));
|
||||
assert(destinationName < maxNameCount);
|
||||
|
||||
copyStats[destinationName].classKind = classKind;
|
||||
copyStats[sourceName].useCount = 0;
|
||||
|
||||
// We need to insert a copy to a temporary register to keep the
|
||||
// source register valid at the end of the node defining it.
|
||||
// This copy will be inserted right after the phi node defining it.
|
||||
RegisterName from = copyStats[sourceName].sourceNameToUse;
|
||||
Instruction* definingPhiNode = vrManager.getVirtualRegister(from).getDefiningInstruction();
|
||||
assert(definingPhiNode && (definingPhiNode->getFlags() & ifPhiNode) != 0);
|
||||
|
||||
RegisterID fromID = buildRegisterID(from, classKind);
|
||||
RegisterID toID = buildRegisterID(destinationName, classKind);
|
||||
Instruction& copy = emitter.newCopy(*definingPhiNode->getPrimitive(), fromID, toID);
|
||||
vrManager.getVirtualRegister(destinationName).setDefiningInstruction(copy);
|
||||
definingPhiNode->getPrimitive()->getContainer()->getInstructions().addFirst(copy);
|
||||
|
||||
copyStats[sourceName].temporaryName = destinationName;
|
||||
copyStats[sourceName].sourceNameToUse = destinationName;
|
||||
pushName(pool, &(copyStats[sourceName].newName), pushed, &pushedList, sourceName, destinationName);
|
||||
}
|
||||
|
||||
// Insert the copy instruction at the end of the current node.
|
||||
RegisterName from = copyStats[sourceName].sourceNameToUse;
|
||||
|
||||
RegisterClassKind classKind = copyStats[destinationName].classKind;
|
||||
RegisterID fromID = buildRegisterID(from, classKind);
|
||||
RegisterID toID = buildRegisterID(destinationName, classKind);
|
||||
Instruction& copy = emitter.newCopy(*vrManager.getVirtualRegister(from).getDefiningInstruction()->getPrimitive(), fromID, toID);
|
||||
instructions.insertAfter(copy, endOfTheNode);
|
||||
endOfTheNode = instructions.advance(endOfTheNode);
|
||||
|
||||
copyStats[sourceName].useCount = 0;
|
||||
if (destinationList.test(sourceName) && copyStats[sourceName].isLiveOut)
|
||||
pushName(pool, &(copyStats[sourceName].newName), pushed, &pushedList, sourceName, destinationName);
|
||||
copyStats[sourceName].isLiveOut = false;
|
||||
copyStats[sourceName].sourceNameToUse = destinationName;
|
||||
|
||||
if (destinationList.test(sourceName))
|
||||
workList.set(sourceName);
|
||||
destinationList.clear(destinationName);
|
||||
}
|
||||
|
||||
destinationListSize = destinationList.getSize();
|
||||
if (destinationListSize != 0) {
|
||||
RegisterName sourceName = RegisterName(destinationList.getOne());
|
||||
RegisterName destinationName;
|
||||
|
||||
if (!copyStats[sourceName].temporaryName) {
|
||||
// Cycle problem.
|
||||
RegisterClassKind classKind = copyStats[sourceName].classKind;
|
||||
destinationName = getName(vrManager.newVirtualRegister(classKind));
|
||||
assert(destinationName < maxNameCount);
|
||||
|
||||
copyStats[destinationName].classKind = classKind;
|
||||
copyStats[sourceName].temporaryName = destinationName;
|
||||
|
||||
// Insert the copy instruction at the end of the current node.
|
||||
RegisterName from = copyStats[sourceName].sourceNameToUse;
|
||||
|
||||
RegisterID fromID = buildRegisterID(from, classKind);
|
||||
RegisterID toID = buildRegisterID(destinationName, classKind);
|
||||
Instruction& copy = emitter.newCopy(*vrManager.getVirtualRegister(from).getDefiningInstruction()->getPrimitive(), fromID, toID);
|
||||
vrManager.getVirtualRegister(destinationName).setDefiningInstruction(copy);
|
||||
instructions.insertAfter(copy, endOfTheNode);
|
||||
endOfTheNode = instructions.advance(endOfTheNode);
|
||||
} else
|
||||
destinationName = copyStats[sourceName].temporaryName;
|
||||
|
||||
copyStats[sourceName].useCount = 0;
|
||||
copyStats[sourceName].isLiveOut = false;
|
||||
copyStats[sourceName].sourceNameToUse = destinationName;
|
||||
pushName(pool, &(copyStats[sourceName].newName), pushed, &pushedList, sourceName, destinationName);
|
||||
|
||||
workList.set(sourceName);
|
||||
}
|
||||
}
|
||||
|
||||
nodeStackPtr->pushedList = pushedList;
|
||||
nodeStackPtr->next = next;
|
||||
nodeStackPtr->limit = limit;
|
||||
++nodeStackPtr;
|
||||
next = dGraph.getSuccessorsBegin(currentNode);
|
||||
limit = dGraph.getSuccessorsEnd(currentNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // _PHI_NODE_REMOVER_H_
|
||||
155
mozilla/ef/Compiler/RegisterAllocator/RegisterAllocator.cpp
Normal file
155
mozilla/ef/Compiler/RegisterAllocator/RegisterAllocator.cpp
Normal file
@@ -0,0 +1,155 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "LogModule.h"
|
||||
#include "RegisterAllocator.h"
|
||||
#include "RegisterPressure.h"
|
||||
#include "RegisterAllocatorTools.h"
|
||||
#include "PhiNodeRemover.h"
|
||||
#include "LiveRange.h"
|
||||
#include "Liveness.h"
|
||||
#include "InterferenceGraph.h"
|
||||
#include "LiveRangeGraph.h"
|
||||
#include "Coalescing.h"
|
||||
#include "Spilling.h"
|
||||
#include "Coloring.h"
|
||||
#include "Splits.h"
|
||||
|
||||
class Pool;
|
||||
class ControlGraph;
|
||||
class VirtualRegisterManager;
|
||||
class InstructionEmitter;
|
||||
|
||||
UT_DEFINE_LOG_MODULE(RegAlloc);
|
||||
|
||||
void RegisterAllocator::allocateRegisters(Pool& pool, ControlGraph& controlGraph, VirtualRegisterManager& vrManager, InstructionEmitter& emitter)
|
||||
{
|
||||
// Insert the phi node instructions. We want to do this to have a single defined register per instruction.
|
||||
// If we keep the PhiNode (as a DataNode) and a PhiNode is of DoubleWordKind then we have to execute
|
||||
// some special code for the high word annotation.
|
||||
//
|
||||
RegisterAllocatorTools::insertPhiNodeInstructions(controlGraph, emitter);
|
||||
|
||||
// Perform some tests on the instruction graph.
|
||||
//
|
||||
DEBUG_ONLY(RegisterAllocatorTools::testTheInstructionGraph(controlGraph, vrManager));
|
||||
|
||||
// Replace the phi node instructions by their equivalent copy instructions.
|
||||
//
|
||||
PhiNodeRemover<LowRegisterPressure>::replacePhiNodes(controlGraph, vrManager, emitter);
|
||||
|
||||
// Do the register allocation.
|
||||
//
|
||||
RegisterAllocator registerAllocator(pool, controlGraph, vrManager, emitter);
|
||||
registerAllocator.doGraphColoring();
|
||||
}
|
||||
|
||||
void RegisterAllocator::doGraphColoring()
|
||||
{
|
||||
// Initialize the liverange map.
|
||||
//
|
||||
initLiveRanges();
|
||||
|
||||
// Build the live ranges. We do this to compress the number of RegisterNames
|
||||
// used in the insterference graph.
|
||||
//
|
||||
LiveRange<LowRegisterPressure>::build(*this);
|
||||
|
||||
// Remove unnecessary copies.
|
||||
//
|
||||
RegisterAllocatorTools::removeUnnecessaryCopies(*this);
|
||||
|
||||
for (Uint8 loop = 0; loop < 10; loop++) {
|
||||
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("********* RegisterAllocator loop %d *********\n", loop));
|
||||
|
||||
while(true) {
|
||||
// Build the interference graph.
|
||||
//
|
||||
iGraph.build();
|
||||
|
||||
// Coalesce the copy instructions.
|
||||
//
|
||||
if (!Coalescing<LowRegisterPressure>::coalesce(*this))
|
||||
break;
|
||||
}
|
||||
|
||||
// Print the interference graph.
|
||||
//
|
||||
DEBUG_LOG_ONLY(iGraph.printPretty(UT_LOG_MODULE(RegAlloc)));
|
||||
|
||||
// Calculate the spill costs.
|
||||
//
|
||||
Spilling<LowRegisterPressure>::calculateSpillCosts(*this);
|
||||
DEBUG_LOG_ONLY(RegisterAllocatorTools::printSpillCosts(*this));
|
||||
|
||||
// Calculate the split costs.
|
||||
//
|
||||
Splits<LowRegisterPressure>::calculateSplitCosts(*this);
|
||||
DEBUG_LOG_ONLY(RegisterAllocatorTools::printSplitCosts(*this));
|
||||
|
||||
// Build the live range graph.
|
||||
//
|
||||
lGraph.build();
|
||||
DEBUG_LOG_ONLY(lGraph.printPretty(UT_LOG_MODULE(RegAlloc)));
|
||||
|
||||
// Color the graph. If it succeeds then we're done with the
|
||||
// register allocation.
|
||||
//
|
||||
if (Coloring<LowRegisterPressure>::color(*this)) {
|
||||
// Write the final colors in the instruction graph.
|
||||
//
|
||||
Coloring<LowRegisterPressure>::finalColoring(*this);
|
||||
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("********** RegisterAllocator done **********\n"));
|
||||
DEBUG_LOG_ONLY(RegisterAllocatorTools::printInstructions(*this));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// We need to spill some registers.
|
||||
//
|
||||
Spilling<LowRegisterPressure>::insertSpillCode(*this);
|
||||
|
||||
// Insert the split instructions.
|
||||
//
|
||||
Splits<LowRegisterPressure>::insertSplitCode(*this);
|
||||
|
||||
// Update the live ranges.
|
||||
//
|
||||
// FIX
|
||||
}
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
RegisterAllocatorTools::updateInstructionGraph(*this);
|
||||
RegisterAllocatorTools::printInstructions(*this);
|
||||
#endif
|
||||
fprintf(stderr, "!!! Coloring failed after 10 loops !!!\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
void RegisterAllocator::initLiveRanges()
|
||||
{
|
||||
Uint32 count = this->nameCount;
|
||||
RegisterName* name2range = new(pool) RegisterName[nameCount];
|
||||
for (RegisterName r = RegisterName(1); r < count; r = RegisterName(r + 1))
|
||||
name2range[r] = r;
|
||||
this->name2range = name2range;
|
||||
rangeCount = count;
|
||||
}
|
||||
88
mozilla/ef/Compiler/RegisterAllocator/RegisterAllocator.h
Normal file
88
mozilla/ef/Compiler/RegisterAllocator/RegisterAllocator.h
Normal file
@@ -0,0 +1,88 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _REGISTER_ALLOCATOR_H_
|
||||
#define _REGISTER_ALLOCATOR_H_
|
||||
|
||||
class Pool;
|
||||
class ControlGraph;
|
||||
class InstructionEmitter;
|
||||
struct SpillCost;
|
||||
struct SplitCost;
|
||||
|
||||
#include "Liveness.h"
|
||||
#include "VirtualRegister.h"
|
||||
#include "RegisterPressure.h" // This should included by Backend.cpp
|
||||
#include "InterferenceGraph.h"
|
||||
#include "LiveRangeGraph.h"
|
||||
|
||||
//template <class RegisterPressure>
|
||||
class RegisterAllocator
|
||||
{
|
||||
public:
|
||||
|
||||
Pool& pool; //
|
||||
ControlGraph& controlGraph; //
|
||||
VirtualRegisterManager& vrManager; //
|
||||
InstructionEmitter& emitter; //
|
||||
|
||||
RegisterName* name2range; //
|
||||
RegisterName* color; //
|
||||
SpillCost* spillCost; //
|
||||
SparseSet* willSpill; //
|
||||
SplitCost* splitCost; //
|
||||
NameLinkedList** splitAround; //
|
||||
InterferenceGraph<LowRegisterPressure> iGraph; //
|
||||
LiveRangeGraph<LowRegisterPressure> lGraph; //
|
||||
LivenessInfo<LowRegisterPressure> liveness; //
|
||||
Uint32 nameCount; //
|
||||
Uint32 rangeCount; //
|
||||
bool splitFound; //
|
||||
|
||||
private:
|
||||
|
||||
//
|
||||
//
|
||||
void doGraphColoring();
|
||||
|
||||
public:
|
||||
|
||||
//
|
||||
//
|
||||
inline RegisterAllocator(Pool& pool, ControlGraph& controlGraph, VirtualRegisterManager& vrManager, InstructionEmitter& emitter);
|
||||
|
||||
//
|
||||
//
|
||||
bool canInterfere(RegisterName /*name1*/, RegisterName /*name2*/) const {return true;}
|
||||
|
||||
//
|
||||
//
|
||||
void initLiveRanges();
|
||||
|
||||
//
|
||||
//
|
||||
static void allocateRegisters(Pool& pool, ControlGraph& controlGraph, VirtualRegisterManager& vrManager, InstructionEmitter& emitter);
|
||||
};
|
||||
|
||||
//
|
||||
//
|
||||
inline RegisterAllocator::RegisterAllocator(Pool& pool, ControlGraph& controlGraph, VirtualRegisterManager& vrManager, InstructionEmitter& emitter)
|
||||
: pool(pool), controlGraph(controlGraph), vrManager(vrManager), emitter(emitter), iGraph(*this), lGraph(*this), nameCount(vrManager.getSize()) {}
|
||||
|
||||
#endif // _REGISTER_ALLOCATOR_H_
|
||||
|
||||
355
mozilla/ef/Compiler/RegisterAllocator/RegisterAllocatorTools.cpp
Normal file
355
mozilla/ef/Compiler/RegisterAllocator/RegisterAllocatorTools.cpp
Normal file
@@ -0,0 +1,355 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "LogModule.h"
|
||||
#include "RegisterAllocatorTools.h"
|
||||
#include "Pool.h"
|
||||
#include "ControlGraph.h"
|
||||
#include "ControlNodes.h"
|
||||
#include "Primitives.h"
|
||||
#include "InstructionEmitter.h"
|
||||
#include "Instruction.h"
|
||||
#include "RegisterAllocator.h"
|
||||
#include "Spilling.h"
|
||||
#include "Splits.h"
|
||||
#include "BitSet.h"
|
||||
|
||||
UT_EXTERN_LOG_MODULE(RegAlloc);
|
||||
|
||||
#ifdef DEBUG
|
||||
void RegisterAllocatorTools::testTheInstructionGraph(ControlGraph& controlGraph, VirtualRegisterManager& vrManager)
|
||||
{
|
||||
// Test the declared VirtualRegisters. The register allocator tries to condense the register universe.
|
||||
// Any gap in the VirtualRegister names will be a loss of efficiency !!!!
|
||||
|
||||
Uint32 nameCount = vrManager.getSize();
|
||||
BitSet registerSeen(controlGraph.pool, nameCount);
|
||||
|
||||
ControlNode** nodes = controlGraph.dfsList;
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
|
||||
for (Uint32 n = 0; n < nNodes; n++) {
|
||||
|
||||
InstructionList& instructions = nodes[n]->getInstructions();
|
||||
for (InstructionList::iterator i = instructions.begin(); !instructions.done(i); i = instructions.advance(i)) {
|
||||
Instruction& instruction = instructions.get(i);
|
||||
|
||||
InstructionUse* useEnd = instruction.getInstructionUseEnd();
|
||||
for (InstructionUse* usePtr = instruction.getInstructionUseBegin(); usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister())
|
||||
registerSeen.set(usePtr->getRegisterName());
|
||||
|
||||
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
|
||||
for (InstructionDefine* definePtr = instruction.getInstructionDefineBegin(); definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister())
|
||||
registerSeen.set(definePtr->getRegisterName());
|
||||
}
|
||||
|
||||
InstructionList& phiNodes = nodes[n]->getPhiNodeInstructions();
|
||||
for (InstructionList::iterator p = phiNodes.begin(); !phiNodes.done(p); p = phiNodes.advance(p)) {
|
||||
Instruction& instruction = phiNodes.get(p);
|
||||
|
||||
InstructionUse* useEnd = instruction.getInstructionUseEnd();
|
||||
for (InstructionUse* usePtr = instruction.getInstructionUseBegin(); usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister())
|
||||
registerSeen.set(usePtr->getRegisterName());
|
||||
|
||||
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
|
||||
for (InstructionDefine* definePtr = instruction.getInstructionDefineBegin(); definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister())
|
||||
registerSeen.set(definePtr->getRegisterName());
|
||||
}
|
||||
}
|
||||
|
||||
bool renameRegisters = false;
|
||||
for (BitSet::iterator i = registerSeen.nextZero(0); !registerSeen.done(i); i = registerSeen.nextZero(i)) {
|
||||
renameRegisters = true;
|
||||
fprintf(stderr,
|
||||
"WARNING: The VirtualRegister vr%d has been allocated during CodeGeneration but\n"
|
||||
" is never used nor defined by any instruction in the instruction graph\n"
|
||||
" PLEASE FIX \n",
|
||||
i);
|
||||
}
|
||||
if (renameRegisters) {
|
||||
Instruction** definingInstruction = new Instruction*[nameCount];
|
||||
memset(definingInstruction, '\0', nameCount * sizeof(Instruction*));
|
||||
RegisterName* newName = new RegisterName[nameCount];
|
||||
memset(newName, '\0', nameCount * sizeof(RegisterName));
|
||||
RegisterName nextName = RegisterName(1);
|
||||
|
||||
for (Uint32 n = 0; n < nNodes; n++) {
|
||||
|
||||
InstructionList& instructions = nodes[n]->getInstructions();
|
||||
for (InstructionList::iterator i = instructions.begin(); !instructions.done(i); i = instructions.advance(i)) {
|
||||
Instruction& instruction = instructions.get(i);
|
||||
|
||||
InstructionUse* useEnd = instruction.getInstructionUseEnd();
|
||||
for (InstructionUse* usePtr = instruction.getInstructionUseBegin(); usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister()) {
|
||||
RegisterName name = usePtr->getRegisterName();
|
||||
if (newName[name] == rnInvalid) {
|
||||
newName[name] = nextName;
|
||||
definingInstruction[nextName] = vrManager.getVirtualRegister(name).getDefiningInstruction();
|
||||
nextName = RegisterName(nextName + 1);
|
||||
}
|
||||
usePtr->setRegisterName(newName[name]);
|
||||
}
|
||||
|
||||
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
|
||||
for (InstructionDefine* definePtr = instruction.getInstructionDefineBegin(); definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister()) {
|
||||
RegisterName name = definePtr->getRegisterName();
|
||||
if (newName[name] == rnInvalid) {
|
||||
newName[name] = nextName;
|
||||
definingInstruction[nextName] = vrManager.getVirtualRegister(name).getDefiningInstruction();
|
||||
nextName = RegisterName(nextName + 1);
|
||||
}
|
||||
definePtr->setRegisterName(newName[name]);
|
||||
}
|
||||
}
|
||||
|
||||
InstructionList& phiNodes = nodes[n]->getPhiNodeInstructions();
|
||||
for (InstructionList::iterator p = phiNodes.begin(); !phiNodes.done(p); p = phiNodes.advance(p)) {
|
||||
Instruction& instruction = phiNodes.get(p);
|
||||
|
||||
InstructionUse* useEnd = instruction.getInstructionUseEnd();
|
||||
for (InstructionUse* usePtr = instruction.getInstructionUseBegin(); usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister()) {
|
||||
RegisterName name = usePtr->getRegisterName();
|
||||
if (newName[name] == rnInvalid) {
|
||||
newName[name] = nextName;
|
||||
definingInstruction[nextName] = vrManager.getVirtualRegister(name).getDefiningInstruction();
|
||||
nextName = RegisterName(nextName + 1);
|
||||
}
|
||||
usePtr->setRegisterName(newName[name]);
|
||||
}
|
||||
|
||||
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
|
||||
for (InstructionDefine* definePtr = instruction.getInstructionDefineBegin(); definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister()) {
|
||||
RegisterName name = definePtr->getRegisterName();
|
||||
if (newName[name] == rnInvalid) {
|
||||
newName[name] = nextName;
|
||||
definingInstruction[nextName] = vrManager.getVirtualRegister(name).getDefiningInstruction();
|
||||
nextName = RegisterName(nextName + 1);
|
||||
}
|
||||
definePtr->setRegisterName(newName[name]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vrManager.setSize(nextName);
|
||||
|
||||
for (RegisterName r = RegisterName(1); r < nextName; r = RegisterName(r + 1))
|
||||
vrManager.getVirtualRegister(r).definingInstruction = definingInstruction[r];
|
||||
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("RegisterMap:\n"));
|
||||
for (Uint32 i = 1; i < nameCount; i++)
|
||||
if (newName[i] != 0)
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("\tvr%d becomes vr%d.\n", i, newName[i]));
|
||||
else
|
||||
UT_OBJECTLOG(UT_LOG_MODULE(RegAlloc), PR_LOG_ALWAYS, ("\tvr%d is dead.\n", i));
|
||||
|
||||
|
||||
delete newName;
|
||||
delete definingInstruction;
|
||||
}
|
||||
|
||||
}
|
||||
#endif // DEBUG
|
||||
|
||||
void RegisterAllocatorTools::removeUnnecessaryCopies(RegisterAllocator& registerAllocator)
|
||||
{
|
||||
ControlGraph& controlGraph = registerAllocator.controlGraph;
|
||||
ControlNode** nodes = controlGraph.dfsList;
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
RegisterName* name2range = registerAllocator.name2range;
|
||||
|
||||
for (Uint32 n = 0; n < nNodes; n++) {
|
||||
InstructionList& instructions = nodes[n]->getInstructions();
|
||||
for (InstructionList::iterator i = instructions.begin(); !instructions.done(i);) {
|
||||
Instruction& instruction = instructions.get(i);
|
||||
i = instructions.advance(i);
|
||||
|
||||
if (instruction.getFlags() & ifCopy) {
|
||||
assert(instruction.getInstructionUseBegin() != instruction.getInstructionUseEnd() && instruction.getInstructionUseBegin()[0].isRegister());
|
||||
assert(instruction.getInstructionDefineBegin() != instruction.getInstructionDefineEnd() && instruction.getInstructionDefineBegin()[0].isRegister());
|
||||
|
||||
RegisterName source = name2range[instruction.getInstructionUseBegin()[0].getRegisterName()];
|
||||
RegisterName destination = name2range[instruction.getInstructionDefineBegin()[0].getRegisterName()];
|
||||
|
||||
if (source == destination)
|
||||
instruction.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void RegisterAllocatorTools::updateInstructionGraph(RegisterAllocator& registerAllocator)
|
||||
{
|
||||
ControlGraph& controlGraph = registerAllocator.controlGraph;
|
||||
ControlNode** nodes = controlGraph.dfsList;
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
RegisterName* name2range = registerAllocator.name2range;
|
||||
|
||||
for (Uint32 n = 0; n < nNodes; n++) {
|
||||
InstructionList& instructions = nodes[n]->getInstructions();
|
||||
for (InstructionList::iterator i = instructions.begin(); !instructions.done(i); i = instructions.advance(i)) {
|
||||
Instruction& instruction = instructions.get(i);
|
||||
|
||||
InstructionUse* useEnd = instruction.getInstructionUseEnd();
|
||||
for (InstructionUse* usePtr = instruction.getInstructionUseBegin(); usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister())
|
||||
usePtr->setRegisterName(name2range[usePtr->getRegisterName()]);
|
||||
|
||||
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
|
||||
for (InstructionDefine* definePtr = instruction.getInstructionDefineBegin(); definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister())
|
||||
definePtr->setRegisterName(name2range[definePtr->getRegisterName()]);
|
||||
}
|
||||
|
||||
InstructionList& phiNodes = nodes[n]->getPhiNodeInstructions();
|
||||
for (InstructionList::iterator p = phiNodes.begin(); !phiNodes.done(p); p = phiNodes.advance(p)) {
|
||||
Instruction& instruction = phiNodes.get(p);
|
||||
|
||||
InstructionUse* useEnd = instruction.getInstructionUseEnd();
|
||||
for (InstructionUse* usePtr = instruction.getInstructionUseBegin(); usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister())
|
||||
usePtr->setRegisterName(name2range[usePtr->getRegisterName()]);
|
||||
|
||||
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
|
||||
for (InstructionDefine* definePtr = instruction.getInstructionDefineBegin(); definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister())
|
||||
definePtr->setRegisterName(name2range[definePtr->getRegisterName()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void RegisterAllocatorTools::insertPhiNodeInstructions(ControlGraph& controlGraph, InstructionEmitter& emitter)
|
||||
{
|
||||
Pool& pool = controlGraph.pool;
|
||||
ControlNode** nodes = controlGraph.dfsList;
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
|
||||
for (Uint32 n = 0; n < nNodes; n++) {
|
||||
ControlNode& node = *nodes[n];
|
||||
DoublyLinkedList<PhiNode>& phiNodes = node.getPhiNodes();
|
||||
|
||||
if (!phiNodes.empty()) {
|
||||
|
||||
// Set the index of the incoming edges.
|
||||
Uint32 index = 0;
|
||||
const DoublyLinkedList<ControlEdge>& predecessors = node.getPredecessors();
|
||||
for (DoublyLinkedList<ControlEdge>::iterator p = predecessors.begin(); !predecessors.done(p); p = predecessors.advance(p))
|
||||
predecessors.get(p).setIndex(index++);
|
||||
|
||||
// Insert the phi node instruction in the instruction list.
|
||||
for (DoublyLinkedList<PhiNode>::iterator i = phiNodes.begin(); !phiNodes.done(i); i = phiNodes.advance(i)) {
|
||||
PhiNode& phiNode = phiNodes.get(i);
|
||||
ValueKind kind = phiNode.getKind();
|
||||
|
||||
if (!isStorableKind(kind))
|
||||
continue;
|
||||
|
||||
RegisterClassKind classKind = rckGeneral; // FIX: get class kind from phi node kind.
|
||||
Uint32 nInputs = phiNode.nInputs();
|
||||
|
||||
PhiNodeInstruction& phiNodeInstruction = *new(pool) PhiNodeInstruction(&phiNode, pool, nInputs);
|
||||
|
||||
emitter.defineProducer(phiNode, phiNodeInstruction, 0, classKind, drLow);
|
||||
for (Uint32 whichInput = 0; whichInput < nInputs; whichInput++)
|
||||
emitter.useProducer(phiNode.nthInputVariable(whichInput), phiNodeInstruction, whichInput, classKind, drLow);
|
||||
|
||||
node.addPhiNodeInstruction(phiNodeInstruction);
|
||||
|
||||
if (isDoublewordKind(kind)) {
|
||||
PhiNodeInstruction& phiNodeInstruction = *new(pool) PhiNodeInstruction(&phiNode, pool, nInputs);
|
||||
|
||||
emitter.defineProducer(phiNode, phiNodeInstruction, 0, classKind, drHigh);
|
||||
for (Uint32 whichInput = 0; whichInput < nInputs; whichInput++)
|
||||
emitter.useProducer(phiNode.nthInputVariable(whichInput), phiNodeInstruction, whichInput, classKind, drHigh);
|
||||
|
||||
node.addPhiNodeInstruction(phiNodeInstruction);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
|
||||
void RegisterAllocatorTools::printSpillCosts(RegisterAllocator& registerAllocator)
|
||||
{
|
||||
LogModuleObject log = UT_LOG_MODULE(RegAlloc);
|
||||
Uint32 rangeCount = registerAllocator.rangeCount;
|
||||
SpillCost* cost = registerAllocator.spillCost;
|
||||
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("Spill costs:\n"));
|
||||
for (Uint32 i = 1; i < rangeCount; i++) {
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\trange %d : ", i));
|
||||
if (cost[i].infinite)
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("infinite\n"));
|
||||
else
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("%f\n", cost[i].cost));
|
||||
}
|
||||
}
|
||||
|
||||
void RegisterAllocatorTools::printSplitCosts(RegisterAllocator& registerAllocator)
|
||||
{
|
||||
LogModuleObject log = UT_LOG_MODULE(RegAlloc);
|
||||
Uint32 rangeCount = registerAllocator.rangeCount;
|
||||
SplitCost* cost = registerAllocator.splitCost;
|
||||
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("Split costs:\n"));
|
||||
for (Uint32 i = 1; i < rangeCount; i++) {
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\trange %d : loads = %f stores = %f\n", i, cost[i].loads, cost[i].stores));
|
||||
}
|
||||
}
|
||||
|
||||
void RegisterAllocatorTools::printInstructions(RegisterAllocator& registerAllocator)
|
||||
{
|
||||
LogModuleObject log = UT_LOG_MODULE(RegAlloc);
|
||||
ControlNode** nodes = registerAllocator.controlGraph.dfsList;
|
||||
Uint32 nNodes = registerAllocator.controlGraph.nNodes;
|
||||
|
||||
for (Uint32 n = 0; n < nNodes; n++) {
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("N%d:\n", n));
|
||||
|
||||
InstructionList& phiNodes = nodes[n]->getPhiNodeInstructions();
|
||||
InstructionList& instructions = nodes[n]->getInstructions();
|
||||
|
||||
if (!phiNodes.empty()) {
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, (" PhiNodes:\n", n));
|
||||
for(InstructionList::iterator i = phiNodes.begin(); !phiNodes.done(i); i = phiNodes.advance(i)) {
|
||||
phiNodes.get(i).printPretty(log);
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\n"));
|
||||
}
|
||||
if (!instructions.empty())
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, (" Instructions:\n", n));
|
||||
}
|
||||
|
||||
for(InstructionList::iterator i = instructions.begin(); !instructions.done(i); i = instructions.advance(i)) {
|
||||
instructions.get(i).printPretty(log);
|
||||
UT_OBJECTLOG(log, PR_LOG_ALWAYS, ("\n"));
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // DEBUG_LOG
|
||||
117
mozilla/ef/Compiler/RegisterAllocator/RegisterAllocatorTools.h
Normal file
117
mozilla/ef/Compiler/RegisterAllocator/RegisterAllocatorTools.h
Normal file
@@ -0,0 +1,117 @@
|
||||
// -*- mode:C++; tab-width:4; truncate-lines:t -*-
|
||||
//
|
||||
// CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
|
||||
// NETSCAPE COMMUNICATIONS CORPORATION
|
||||
// Copyright © 1996, 1997 Netscape Communications Corporation. All Rights
|
||||
// Reserved. Use of this Source Code is subject to the terms of the
|
||||
// applicable license agreement from Netscape Communications Corporation.
|
||||
// The copyright notice(s) in this Source Code does not indicate actual or
|
||||
// intended publication of this Source Code.
|
||||
//
|
||||
// $Id: RegisterAllocatorTools.h,v 1.1.2.1 1999-03-02 16:12:05 fur%netscape.com Exp $
|
||||
//
|
||||
|
||||
#ifndef _REGISTER_ALLOCATOR_TOOLS_H_
|
||||
#define _REGISTER_ALLOCATOR_TOOLS_H_
|
||||
|
||||
#include "LogModule.h"
|
||||
#include "RegisterTypes.h"
|
||||
#include <string.h>
|
||||
|
||||
class RegisterAllocator;
|
||||
class ControlGraph;
|
||||
class InstructionEmitter;
|
||||
class VirtualRegisterManager;
|
||||
|
||||
struct RegisterAllocatorTools
|
||||
{
|
||||
//
|
||||
//
|
||||
static void insertPhiNodeInstructions(ControlGraph& controlGraph, InstructionEmitter& emitter);
|
||||
|
||||
//
|
||||
//
|
||||
static void updateInstructionGraph(RegisterAllocator& registerAllocator);
|
||||
|
||||
//
|
||||
//
|
||||
static void removeUnnecessaryCopies(RegisterAllocator& registerAllocator);
|
||||
|
||||
#ifdef DEBUG
|
||||
//
|
||||
//
|
||||
static void testTheInstructionGraph(ControlGraph& controlGraph, VirtualRegisterManager& vrManager);
|
||||
#endif // DEBUG
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
//
|
||||
//
|
||||
static void printInstructions(RegisterAllocator& registerAllocator);
|
||||
|
||||
//
|
||||
//
|
||||
static void printSpillCosts(RegisterAllocator& registerAllocator);
|
||||
|
||||
//
|
||||
//
|
||||
static void printSplitCosts(RegisterAllocator& registerAllocator);
|
||||
#endif // DEBUG_LOG
|
||||
};
|
||||
|
||||
//
|
||||
// FIX: this should go in a class (LookupTable ?)
|
||||
//
|
||||
|
||||
inline RegisterName findRoot(RegisterName name, RegisterName* table)
|
||||
{
|
||||
RegisterName* stack = table;
|
||||
RegisterName* stackPtr = stack;
|
||||
|
||||
RegisterName newName;
|
||||
while((newName = table[name]) != name) {
|
||||
*--stackPtr = name;
|
||||
name = newName;
|
||||
}
|
||||
|
||||
while (stackPtr != stack)
|
||||
table[*stackPtr++] = name;
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
inline void init(RegisterName* table, Uint32 nameCount)
|
||||
{
|
||||
for (RegisterName r = RegisterName(0); r < nameCount; r = RegisterName(r + 1))
|
||||
table[r] = r;
|
||||
}
|
||||
|
||||
inline Uint32 compress(RegisterName* name2range, RegisterName* table, Uint32 nameCount, Uint32 tableSize)
|
||||
{
|
||||
RegisterName* liveRange = new RegisterName[tableSize];
|
||||
memset(liveRange, '\0', tableSize * sizeof(RegisterName));
|
||||
|
||||
// Update the lookup table.
|
||||
for (RegisterName r = RegisterName(1); r < tableSize; r = RegisterName(r + 1))
|
||||
findRoot(r, table);
|
||||
|
||||
// Count the liveranges.
|
||||
Uint32 liveRangeCount = 1;
|
||||
for (RegisterName s = RegisterName(1); s < tableSize; s = RegisterName(s + 1))
|
||||
if (table[s] == s)
|
||||
liveRange[s] = RegisterName(liveRangeCount++);
|
||||
|
||||
for (RegisterName t = RegisterName(1); t < nameCount; t = RegisterName(t + 1))
|
||||
name2range[t] = liveRange[table[name2range[t]]];
|
||||
|
||||
return liveRangeCount;
|
||||
}
|
||||
|
||||
inline double doLog10(Uint32 power)
|
||||
{
|
||||
double log = 1.0;
|
||||
while (power--)
|
||||
log *= 10.0;
|
||||
return log;
|
||||
}
|
||||
|
||||
#endif // _REGISTER_ALLOCATOR_TOOLS_H_
|
||||
38
mozilla/ef/Compiler/RegisterAllocator/RegisterAssigner.h
Normal file
38
mozilla/ef/Compiler/RegisterAllocator/RegisterAssigner.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _REGISTER_ASSIGNER_H_
|
||||
#define _REGISTER_ASSIGNER_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "VirtualRegister.h"
|
||||
|
||||
class FastBitMatrix;
|
||||
|
||||
class RegisterAssigner
|
||||
{
|
||||
protected:
|
||||
VirtualRegisterManager& vRegManager;
|
||||
|
||||
public:
|
||||
RegisterAssigner(VirtualRegisterManager& vrMan) : vRegManager(vrMan) {}
|
||||
|
||||
virtual bool assignRegisters(FastBitMatrix& interferenceMatrix) = 0;
|
||||
};
|
||||
|
||||
#endif /* _REGISTER_ASSIGNER_H_ */
|
||||
25
mozilla/ef/Compiler/RegisterAllocator/RegisterClass.h
Normal file
25
mozilla/ef/Compiler/RegisterAllocator/RegisterClass.h
Normal file
@@ -0,0 +1,25 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _REGISTER_CLASS_H_
|
||||
#define _REGISTER_CLASS_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "RegisterTypes.h"
|
||||
|
||||
#endif // _REGISTER_CLASS_H_
|
||||
37
mozilla/ef/Compiler/RegisterAllocator/RegisterPressure.h
Normal file
37
mozilla/ef/Compiler/RegisterAllocator/RegisterPressure.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _REGISTER_PRESSURE_H_
|
||||
#define _REGISTER_PRESSURE_H_
|
||||
|
||||
#include "BitSet.h"
|
||||
#include "HashSet.h"
|
||||
|
||||
struct LowRegisterPressure
|
||||
{
|
||||
typedef BitSet Set;
|
||||
static const bool setIsOrdered = true;
|
||||
};
|
||||
|
||||
struct HighRegisterPressure
|
||||
{
|
||||
typedef HashSet Set;
|
||||
static const bool setIsOrdered = false;
|
||||
};
|
||||
|
||||
#endif // _REGISTER_PRESSURE_H_
|
||||
104
mozilla/ef/Compiler/RegisterAllocator/RegisterTypes.h
Normal file
104
mozilla/ef/Compiler/RegisterAllocator/RegisterTypes.h
Normal file
@@ -0,0 +1,104 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _REGISTER_TYPES_H_
|
||||
#define _REGISTER_TYPES_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// RegisterName -
|
||||
//
|
||||
|
||||
enum RegisterName {
|
||||
rnInvalid = 0,
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// RegisterClassKind -
|
||||
//
|
||||
|
||||
enum RegisterClassKind {
|
||||
rckInvalid = 0,
|
||||
rckGeneral,
|
||||
rckStackSlot,
|
||||
|
||||
nRegisterClassKind
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// RegisterID -
|
||||
//
|
||||
|
||||
enum RegisterID {
|
||||
invalidID = 0
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// RegisterKind -
|
||||
//
|
||||
|
||||
enum RegisterKind {
|
||||
rkCallerSave = 0,
|
||||
rkCalleeSave,
|
||||
};
|
||||
|
||||
struct NameLinkedList {
|
||||
RegisterName name;
|
||||
NameLinkedList* next;
|
||||
};
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
const registerNameMask = 0x03ffffff;
|
||||
const coloredRegisterMask = 0x04000000;
|
||||
const machineRegisterMask = 0x08000000;
|
||||
const registerClassMask = 0xf0000000;
|
||||
|
||||
const registerNameShift = 0;
|
||||
const coloredRegisterShift = 26;
|
||||
const machineRegisterShift = 27;
|
||||
const registerClassShift = 28;
|
||||
|
||||
#else // DEBUG
|
||||
|
||||
const registerNameMask = 0x0fffffff;
|
||||
const registerClassMask = 0xf0000000;
|
||||
|
||||
const registerNameShift = 0;
|
||||
const registerClassShift = 28;
|
||||
|
||||
#endif // DEBUG
|
||||
|
||||
|
||||
inline RegisterClassKind getClass(RegisterID registerID) {return RegisterClassKind((registerID & registerClassMask) >> registerClassShift);}
|
||||
inline RegisterName getName(RegisterID registerID) {return RegisterName((registerID & registerNameMask) >> registerNameShift);}
|
||||
inline void setClass(RegisterID& registerID, RegisterClassKind classKind) {registerID = RegisterID((registerID & ~registerClassMask) | ((classKind << registerClassShift) & registerClassMask));}
|
||||
inline void setName(RegisterID& registerID, RegisterName name) {assert((name & ~registerNameMask) == 0); registerID = RegisterID((registerID & ~registerNameMask) | ((name << registerNameShift) & registerNameMask));}
|
||||
inline RegisterID buildRegisterID(RegisterName name, RegisterClassKind classKind) {return RegisterID(((classKind << registerClassShift) & registerClassMask) | ((name << registerNameShift) & registerNameMask));}
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
inline bool isMachineRegister(RegisterID rid) {return (rid & machineRegisterMask) != 0;}
|
||||
inline void setMachineRegister(RegisterID& rid) {rid = RegisterID(rid | machineRegisterMask);}
|
||||
inline bool isColoredRegister(RegisterID rid) {return (rid & coloredRegisterMask) != 0;}
|
||||
inline void setColoredRegister(RegisterID& rid) {rid = RegisterID(rid | coloredRegisterMask);}
|
||||
|
||||
#endif // DEBUG
|
||||
|
||||
#endif // _REGISTER_TYPES_H_
|
||||
32
mozilla/ef/Compiler/RegisterAllocator/SSATools.cpp
Normal file
32
mozilla/ef/Compiler/RegisterAllocator/SSATools.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "SSATools.h"
|
||||
#include "ControlGraph.h"
|
||||
#include "VirtualRegister.h"
|
||||
#include "Liveness.h"
|
||||
|
||||
void replacePhiNodes(ControlGraph& controlGraph, VirtualRegisterManager& vrManager)
|
||||
{
|
||||
if (!controlGraph.hasBackEdges)
|
||||
return;
|
||||
|
||||
Liveness liveness(controlGraph.pool);
|
||||
liveness.buildLivenessAnalysis(controlGraph, vrManager);
|
||||
}
|
||||
29
mozilla/ef/Compiler/RegisterAllocator/SSATools.h
Normal file
29
mozilla/ef/Compiler/RegisterAllocator/SSATools.h
Normal file
@@ -0,0 +1,29 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _SSA_TOOLS_H_
|
||||
#define _SSA_TOOLS_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
|
||||
class ControlGraph;
|
||||
class VirtualRegisterManager;
|
||||
|
||||
extern void replacePhiNodes(ControlGraph& controlGraph, VirtualRegisterManager& vrManager);
|
||||
|
||||
#endif // _SSA_TOOLS_H_
|
||||
37
mozilla/ef/Compiler/RegisterAllocator/SparseSet.cpp
Normal file
37
mozilla/ef/Compiler/RegisterAllocator/SparseSet.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "SparseSet.h"
|
||||
#include "BitSet.h"
|
||||
#include "Pool.h"
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
// Print the set.
|
||||
//
|
||||
void SparseSet::printPretty(LogModuleObject log)
|
||||
{
|
||||
Pool pool;
|
||||
BitSet set(pool, universeSize);
|
||||
|
||||
for (Uint32 i = 0; i < count; i++)
|
||||
set.set(node[i].element);
|
||||
|
||||
set.printPretty(log);
|
||||
}
|
||||
#endif // DEBUG_LOG
|
||||
168
mozilla/ef/Compiler/RegisterAllocator/SparseSet.h
Normal file
168
mozilla/ef/Compiler/RegisterAllocator/SparseSet.h
Normal file
@@ -0,0 +1,168 @@
|
||||
// -*- mode:C++; tab-width:4; truncate-lines:t -*-
|
||||
//
|
||||
// CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
|
||||
// NETSCAPE COMMUNICATIONS CORPORATION
|
||||
// Copyright © 1996, 1997 Netscape Communications Corporation. All Rights
|
||||
// Reserved. Use of this Source Code is subject to the terms of the
|
||||
// applicable license agreement from Netscape Communications Corporation.
|
||||
// The copyright notice(s) in this Source Code does not indicate actual or
|
||||
// intended publication of this Source Code.
|
||||
//
|
||||
// $Id: SparseSet.h,v 1.1.2.1 1999-03-02 16:12:07 fur%netscape.com Exp $
|
||||
//
|
||||
|
||||
#ifndef _SPARSE_SET_H_
|
||||
#define _SPARSE_SET_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "Pool.h"
|
||||
#include "LogModule.h"
|
||||
#include "BitSet.h"
|
||||
|
||||
class SparseSet
|
||||
{
|
||||
private:
|
||||
|
||||
struct Node {
|
||||
Uint32 element;
|
||||
Uint32 stackIndex;
|
||||
};
|
||||
|
||||
Node* node;
|
||||
Uint32 count;
|
||||
Uint32 universeSize;
|
||||
|
||||
private:
|
||||
|
||||
// No copy constructor.
|
||||
SparseSet(const SparseSet&);
|
||||
|
||||
// Check if the given set's universe is of the same size than this universe.
|
||||
void checkUniverseCompatibility(const SparseSet& set) const {assert(set.universeSize == universeSize);}
|
||||
// Check if pos is valid for this set's universe.
|
||||
void checkMember(Int32 pos) const {assert(pos >=0 && Uint32(pos) < universeSize);}
|
||||
|
||||
public:
|
||||
|
||||
SparseSet(Pool& pool, Uint32 universeSize) : universeSize(universeSize) {node = new(pool) Node[universeSize]; clear();}
|
||||
|
||||
// Clear the sparse set.
|
||||
void clear() {count = 0;}
|
||||
// Clear the element at index.
|
||||
inline void clear(Uint32 index);
|
||||
// Set the element at index.
|
||||
inline void set(Uint32 index);
|
||||
// Return true if the element at index is set.
|
||||
inline bool test(Uint32 index) const;
|
||||
// Union with the given sparse set.
|
||||
inline void or(const SparseSet& set);
|
||||
// Intersection with the given sparse set.
|
||||
inline void and(const SparseSet& set);
|
||||
// Difference with the given sparse set.
|
||||
inline void difference(const SparseSet& set);
|
||||
// Copy set.
|
||||
inline SparseSet& operator = (const SparseSet& set);
|
||||
inline SparseSet& operator = (const BitSet& set);
|
||||
// Return true if the sparse sets are identical.
|
||||
friend bool operator == (const SparseSet& set1, const SparseSet& set2);
|
||||
// Return true if the sparse sets are different.
|
||||
friend bool operator != (const SparseSet& set1, const SparseSet& set2);
|
||||
|
||||
// Logical operators.
|
||||
SparseSet& operator |= (const SparseSet& set) {or(set); return *this;}
|
||||
SparseSet& operator &= (const SparseSet& set) {and(set); return *this;}
|
||||
SparseSet& operator -= (const SparseSet& set) {difference(set); return *this;}
|
||||
|
||||
// Iterator to conform with the set API.
|
||||
typedef Int32 iterator;
|
||||
// Return the iterator for the first element of this set.
|
||||
iterator begin() const {return count - 1;}
|
||||
// Return the next iterator.
|
||||
iterator advance(iterator pos) const {return --pos;}
|
||||
// Return true if the iterator is at the end of the set.
|
||||
bool done(iterator pos) const {return pos < 0;}
|
||||
// Return the element for the given iterator;
|
||||
Uint32 get(iterator pos) const {return node[pos].element;}
|
||||
// Return one element of this set.
|
||||
Uint32 getOne() const {assert(count > 0); return node[0].element;}
|
||||
// Return the size of this set.
|
||||
Uint32 getSize() const {return count;}
|
||||
|
||||
#ifdef DEBUG_LOG
|
||||
// Print the set.
|
||||
void printPretty(LogModuleObject log);
|
||||
#endif // DEBUG_LOG
|
||||
};
|
||||
|
||||
inline void SparseSet::clear(Uint32 element)
|
||||
{
|
||||
checkMember(element);
|
||||
Uint32 count = this->count;
|
||||
Node* node = this->node;
|
||||
|
||||
Uint32 stackIndex = node[element].stackIndex;
|
||||
|
||||
if ((stackIndex < count) && (node[stackIndex].element == element)) {
|
||||
Uint32 stackTop = node[count - 1].element;
|
||||
|
||||
node[stackIndex].element = stackTop;
|
||||
node[stackTop].stackIndex = stackIndex;
|
||||
this->count = count - 1;
|
||||
}
|
||||
}
|
||||
|
||||
inline void SparseSet::set(Uint32 element)
|
||||
{
|
||||
checkMember(element);
|
||||
Uint32 count = this->count;
|
||||
Node* node = this->node;
|
||||
|
||||
Uint32 stackIndex = node[element].stackIndex;
|
||||
|
||||
if ((stackIndex >= count) || (node[stackIndex].element != element)) {
|
||||
node[count].element = element;
|
||||
node[element].stackIndex = count;
|
||||
this->count = count + 1;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool SparseSet::test(Uint32 element) const
|
||||
{
|
||||
checkMember(element);
|
||||
Node* node = this->node;
|
||||
|
||||
Uint32 stackIndex = node[element].stackIndex;
|
||||
return ((stackIndex < count) && (node[stackIndex].element == element));
|
||||
}
|
||||
|
||||
inline SparseSet& SparseSet::operator = (const SparseSet& set)
|
||||
{
|
||||
checkUniverseCompatibility(set);
|
||||
Uint32 sourceCount = set.getSize();
|
||||
Node* node = this->node;
|
||||
|
||||
memcpy(node, set.node, sourceCount * sizeof(Node));
|
||||
|
||||
for (Uint32 i = 0; i < sourceCount; i++) {
|
||||
Uint32 element = node[i].element;
|
||||
node[element].stackIndex = i;
|
||||
}
|
||||
|
||||
count = sourceCount;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
inline SparseSet& SparseSet::operator = (const BitSet& set)
|
||||
{
|
||||
// FIX: there's room for optimization here.
|
||||
assert(universeSize == set.getSize());
|
||||
|
||||
clear();
|
||||
for (Int32 i = set.firstOne(); i != -1; i = set.nextOne(i))
|
||||
this->set(i);
|
||||
return *this;
|
||||
}
|
||||
|
||||
#endif // _SPARSE_SET_H_
|
||||
270
mozilla/ef/Compiler/RegisterAllocator/Spilling.cpp
Normal file
270
mozilla/ef/Compiler/RegisterAllocator/Spilling.cpp
Normal file
@@ -0,0 +1,270 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef NEW_LAURENTM_CODE
|
||||
#define INCLUDE_EMITTER
|
||||
#include "CpuInfo.h"
|
||||
#include "Fundamentals.h"
|
||||
#include "ControlNodes.h"
|
||||
#include "Instruction.h"
|
||||
#include "InstructionEmitter.h"
|
||||
#include "Spilling.h"
|
||||
|
||||
|
||||
void Spilling::
|
||||
insertSpillCode(ControlNode** dfsList, Uint32 nNodes)
|
||||
{
|
||||
PRUint32 nVirtualRegisters = vRegManager.count();
|
||||
FastBitSet currentLive(vRegManager.pool, nVirtualRegisters);
|
||||
FastBitSet usedInThisInstruction(vRegManager.pool, nVirtualRegisters);
|
||||
RegisterFifo grNeedLoad(nVirtualRegisters);
|
||||
RegisterFifo fpNeedLoad(nVirtualRegisters);
|
||||
|
||||
for (PRInt32 n = nNodes - 1; n >= 0; n--)
|
||||
{
|
||||
PR_ASSERT(grNeedLoad.empty() & fpNeedLoad.empty());
|
||||
ControlNode& node = *dfsList[n];
|
||||
|
||||
currentLive = node.liveAtEnd;
|
||||
|
||||
PRUint32 nGeneralAlive = 0;
|
||||
PRUint32 nFloatingPointAlive = 0;
|
||||
|
||||
// Get the number of registers alive at the end of this node.
|
||||
for (PRInt32 j = currentLive.firstOne(); j != -1; j = currentLive.nextOne(j))
|
||||
{
|
||||
VirtualRegister& vReg = vRegManager.getVirtualRegister(j);
|
||||
if (vReg.spillInfo.willSpill)
|
||||
{
|
||||
currentLive.clear(j);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (vReg.getClass())
|
||||
{
|
||||
case vrcInteger:
|
||||
nGeneralAlive++;
|
||||
break;
|
||||
case vrcFloatingPoint:
|
||||
case vrcFixedPoint:
|
||||
nFloatingPointAlive++;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if(node.dfsNum == 8) printf("\n________Begin Node %d________\n", node.dfsNum);
|
||||
|
||||
InstructionList& instructions = node.getInstructions();
|
||||
for (InstructionList::iterator i = instructions.end(); !instructions.done(i); i = instructions.retreat(i))
|
||||
{
|
||||
Instruction& instruction = instructions.get(i);
|
||||
InstructionUse* useBegin = instruction.getInstructionUseBegin();
|
||||
InstructionUse* useEnd = instruction.getInstructionUseEnd();
|
||||
InstructionUse* usePtr;
|
||||
InstructionDefine* defBegin = instruction.getInstructionDefineBegin();
|
||||
InstructionDefine* defEnd = instruction.getInstructionDefineEnd();
|
||||
InstructionDefine* defPtr;
|
||||
|
||||
// if(node.dfsNum == 8) { printf("\n");
|
||||
// instruction.printPretty(stdout);
|
||||
// printf("\n"); }
|
||||
|
||||
// Handle definitions
|
||||
for (defPtr = defBegin; defPtr < defEnd; defPtr++)
|
||||
if (defPtr->isVirtualRegister())
|
||||
{
|
||||
VirtualRegister& vReg = defPtr->getVirtualRegister();
|
||||
currentLive.clear(vReg.getRegisterIndex());
|
||||
switch (vReg.getClass())
|
||||
{
|
||||
case vrcInteger:
|
||||
nGeneralAlive--;
|
||||
break;
|
||||
case vrcFloatingPoint:
|
||||
case vrcFixedPoint:
|
||||
nFloatingPointAlive--;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Check for deaths
|
||||
for (usePtr = useBegin; usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isVirtualRegister())
|
||||
{
|
||||
VirtualRegister& vReg = usePtr->getVirtualRegister();
|
||||
if (!currentLive.test(vReg.getRegisterIndex()))
|
||||
// This is the last use of this register.
|
||||
{
|
||||
currentLive.set(vReg.getRegisterIndex());
|
||||
switch (vReg.getClass())
|
||||
{
|
||||
case vrcInteger:
|
||||
nGeneralAlive++;
|
||||
while (/*(nGeneralAlive > NUMBER_OF_GREGISTERS) &&*/ !grNeedLoad.empty())
|
||||
{
|
||||
PRUint32 toLoad = grNeedLoad.get();
|
||||
currentLive.clear(toLoad);
|
||||
nGeneralAlive--;
|
||||
|
||||
VirtualRegister& nReg = vRegManager.getVirtualRegister(toLoad);
|
||||
Instruction& lastUsingInstruction = *nReg.spillInfo.lastUsingInstruction;
|
||||
emitter.emitLoadAfter(*lastUsingInstruction.getPrimitive(), lastUsingInstruction.getLinks().prev,
|
||||
nReg.getAlias(), *nReg.equivalentRegister[vrcStackSlot]);
|
||||
nReg.releaseSelf();
|
||||
}
|
||||
break;
|
||||
case vrcFloatingPoint:
|
||||
case vrcFixedPoint:
|
||||
nFloatingPointAlive++;
|
||||
while (/*(nFloatingPointAlive > NUMBER_OF_FPREGISTERS) &&*/ !fpNeedLoad.empty())
|
||||
{
|
||||
PRUint32 toLoad = fpNeedLoad.get();
|
||||
currentLive.clear(toLoad);
|
||||
nFloatingPointAlive--;
|
||||
|
||||
VirtualRegister& nReg = vRegManager.getVirtualRegister(toLoad);
|
||||
Instruction& lastUsingInstruction = *nReg.spillInfo.lastUsingInstruction;
|
||||
emitter.emitLoadAfter(*lastUsingInstruction.getPrimitive(), lastUsingInstruction.getLinks().prev,
|
||||
nReg.getAlias(), *nReg.equivalentRegister[vrcStackSlot]);
|
||||
nReg.releaseSelf();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle uses
|
||||
for (usePtr = useBegin; usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isVirtualRegister())
|
||||
{
|
||||
VirtualRegister& vReg = usePtr->getVirtualRegister();
|
||||
PRUint32 registerIndex = vReg.getRegisterIndex();
|
||||
|
||||
if (vReg.spillInfo.willSpill) {
|
||||
#if defined(GENERATE_FOR_X86)
|
||||
if (!instruction.switchUseToSpill((usePtr - useBegin), *vReg.equivalentRegister[vrcStackSlot]))
|
||||
#endif
|
||||
{
|
||||
switch (vReg.getClass())
|
||||
{
|
||||
case vrcInteger:
|
||||
if (!grNeedLoad.test(registerIndex))
|
||||
{
|
||||
grNeedLoad.put(registerIndex);
|
||||
VirtualRegister& alias = vRegManager.newVirtualRegister(vrcInteger);
|
||||
if (vReg.isPreColored())
|
||||
alias.preColorRegister(vReg.getPreColor());
|
||||
/* if (vReg.hasSpecialInterference) {
|
||||
alias.specialInterference.sizeTo(NUMBER_OF_REGISTERS);
|
||||
alias.specialInterference = vReg.specialInterference;
|
||||
alias.hasSpecialInterference = true;
|
||||
} */
|
||||
vReg.setAlias(alias);
|
||||
vReg.retainSelf();
|
||||
}
|
||||
break;
|
||||
case vrcFloatingPoint:
|
||||
case vrcFixedPoint:
|
||||
if (!fpNeedLoad.test(registerIndex))
|
||||
{
|
||||
fpNeedLoad.put(registerIndex);
|
||||
VirtualRegister& alias = vRegManager.newVirtualRegister(vReg.getClass());
|
||||
if (vReg.isPreColored())
|
||||
alias.preColorRegister(vReg.getPreColor());
|
||||
/*if (vReg.hasSpecialInterference) {
|
||||
alias.specialInterference.sizeTo(NUMBER_OF_REGISTERS);
|
||||
alias.specialInterference = vReg.specialInterference;
|
||||
alias.hasSpecialInterference = true;
|
||||
} */
|
||||
vReg.setAlias(alias);
|
||||
vReg.retainSelf();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
usePtr->getVirtualRegisterPtr().initialize(vReg.getAlias());
|
||||
usedInThisInstruction.set(registerIndex);
|
||||
vReg.spillInfo.lastUsingInstruction = &instruction;
|
||||
}
|
||||
currentLive.clear(registerIndex);
|
||||
} else { // will not spill
|
||||
currentLive.set(registerIndex);
|
||||
}
|
||||
}
|
||||
|
||||
// Handle definitions
|
||||
for (defPtr = defBegin; defPtr < defEnd; defPtr++)
|
||||
if (defPtr->isVirtualRegister())
|
||||
{
|
||||
VirtualRegister& vReg = defPtr->getVirtualRegister();
|
||||
|
||||
if (vReg.spillInfo.willSpill)
|
||||
#if defined(GENERATE_FOR_X86)
|
||||
if (!instruction.switchDefineToSpill((defPtr - defBegin), *vReg.equivalentRegister[vrcStackSlot]))
|
||||
#endif
|
||||
{
|
||||
if (usedInThisInstruction.test(vReg.getRegisterIndex()))
|
||||
// this virtualRegister was used in this instruction and is also defined. We need to move
|
||||
// this virtual register to its alias first and then save it to memory.
|
||||
{
|
||||
emitter.emitStoreAfter(*instruction.getPrimitive(), &instruction.getLinks(),
|
||||
vReg.getAlias(), *vReg.equivalentRegister[vrcStackSlot]);
|
||||
defPtr->getVirtualRegisterPtr().initialize(vReg.getAlias());
|
||||
}
|
||||
else
|
||||
{
|
||||
emitter.emitStoreAfter(*instruction.getPrimitive(), &instruction.getLinks(),
|
||||
vReg, *vReg.equivalentRegister[vrcStackSlot]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
while (!grNeedLoad.empty())
|
||||
{
|
||||
PRUint32 nl = grNeedLoad.get();
|
||||
VirtualRegister& nlReg = vRegManager.getVirtualRegister(nl);
|
||||
Instruction& lastUse = *nlReg.spillInfo.lastUsingInstruction;
|
||||
|
||||
emitter.emitLoadAfter(*lastUse.getPrimitive(), lastUse.getLinks().prev,
|
||||
nlReg.getAlias(), *nlReg.equivalentRegister[vrcStackSlot]);
|
||||
nlReg.releaseSelf();
|
||||
}
|
||||
while (!fpNeedLoad.empty())
|
||||
{
|
||||
PRUint32 nl = fpNeedLoad.get();
|
||||
VirtualRegister& nlReg = vRegManager.getVirtualRegister(nl);
|
||||
Instruction& lastUse = *nlReg.spillInfo.lastUsingInstruction;
|
||||
|
||||
emitter.emitLoadAfter(*lastUse.getPrimitive(), lastUse.getLinks().prev,
|
||||
nlReg.getAlias(), *nlReg.equivalentRegister[vrcStackSlot]);
|
||||
nlReg.releaseSelf();
|
||||
}
|
||||
|
||||
// if(node.dfsNum == 8) printf("\n________End Node %d________\n", node.dfsNum);
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
269
mozilla/ef/Compiler/RegisterAllocator/Spilling.h
Normal file
269
mozilla/ef/Compiler/RegisterAllocator/Spilling.h
Normal file
@@ -0,0 +1,269 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _SPILLING_H_
|
||||
#define _SPILLING_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include <string.h>
|
||||
#include "RegisterAllocator.h"
|
||||
#include "RegisterAllocatorTools.h"
|
||||
#include "ControlGraph.h"
|
||||
#include "ControlNodes.h"
|
||||
#include "Instruction.h"
|
||||
#include "SparseSet.h"
|
||||
|
||||
template <class RegisterPressure>
|
||||
class Spilling
|
||||
{
|
||||
private:
|
||||
static void insertStoreAfter(Instruction& instruction, RegisterName name);
|
||||
static void insertLoadBefore(Instruction& instruction, RegisterName name);
|
||||
|
||||
public:
|
||||
static void calculateSpillCosts(RegisterAllocator& registerAllocator);
|
||||
static void insertSpillCode(RegisterAllocator& registerAllocator);
|
||||
};
|
||||
|
||||
struct SpillCost
|
||||
{
|
||||
double loads;
|
||||
double stores;
|
||||
double copies;
|
||||
double cost;
|
||||
bool infinite;
|
||||
};
|
||||
|
||||
template <class RegisterPressure>
|
||||
void Spilling<RegisterPressure>::insertSpillCode(RegisterAllocator& registerAllocator)
|
||||
{
|
||||
Uint32 rangeCount = registerAllocator.rangeCount;
|
||||
RegisterName* name2range = registerAllocator.name2range;
|
||||
|
||||
Pool& pool = registerAllocator.pool;
|
||||
SparseSet currentLive(pool, rangeCount);
|
||||
SparseSet needLoad(pool, rangeCount);
|
||||
SparseSet mustSpill(pool, rangeCount);
|
||||
SparseSet& willSpill = *registerAllocator.willSpill;
|
||||
|
||||
ControlGraph& controlGraph = registerAllocator.controlGraph;
|
||||
RegisterPressure::Set* liveOut = registerAllocator.liveness.liveOut;
|
||||
ControlNode** nodes = controlGraph.dfsList;
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
|
||||
for (Uint32 n = 0; n < nNodes; n++) {
|
||||
|
||||
needLoad.clear();
|
||||
currentLive = liveOut[n];
|
||||
mustSpill = currentLive;
|
||||
|
||||
InstructionList& instructions = nodes[n]->getInstructions();
|
||||
for (InstructionList::iterator i = instructions.end(); !instructions.done(i);) {
|
||||
Instruction& instruction = instructions.get(i);
|
||||
i = instructions.retreat(i);
|
||||
|
||||
InstructionUse* useBegin = instruction.getInstructionUseBegin();
|
||||
InstructionUse* useEnd = instruction.getInstructionUseEnd();
|
||||
InstructionUse* usePtr;
|
||||
InstructionDefine* defineBegin = instruction.getInstructionDefineBegin();
|
||||
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
|
||||
InstructionDefine* definePtr;
|
||||
|
||||
bool foundLiveDefine = false;
|
||||
for (definePtr = defineBegin; definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister()) {
|
||||
if (currentLive.test(name2range[definePtr->getRegisterName()])) {
|
||||
foundLiveDefine = true;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
foundLiveDefine = true;
|
||||
break;
|
||||
}
|
||||
if (defineBegin != defineEnd && !foundLiveDefine) {
|
||||
fprintf(stderr, "!!! Removed instruction because it was only defining unused registers !!!\n");
|
||||
instruction.remove();
|
||||
}
|
||||
|
||||
for (definePtr = defineBegin; definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister()) {
|
||||
RegisterName range = name2range[definePtr->getRegisterName()];
|
||||
#ifdef DEBUG
|
||||
if (needLoad.test(range))
|
||||
if (!mustSpill.test(range) && registerAllocator.spillCost[range].infinite && willSpill.test(range)) {
|
||||
fprintf(stderr, "Tried to spill a register with infinite spill cost\n");
|
||||
abort();
|
||||
}
|
||||
#endif // DEBUG
|
||||
if (willSpill.test(range))
|
||||
insertStoreAfter(instruction, range);
|
||||
|
||||
needLoad.clear(range);
|
||||
}
|
||||
|
||||
if (instruction.getFlags() & ifCopy)
|
||||
for (usePtr = useBegin; usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister()) {
|
||||
RegisterName range = name2range[usePtr->getRegisterName()];
|
||||
if (!currentLive.test(range))
|
||||
for (SparseSet::iterator r = needLoad.begin(); !needLoad.done(r); r = needLoad.advance(r)) {
|
||||
RegisterName load = RegisterName(needLoad.get(r));
|
||||
if (willSpill.test(load))
|
||||
insertLoadBefore(instruction, load);
|
||||
mustSpill.set(load);
|
||||
}
|
||||
needLoad.clear();
|
||||
}
|
||||
|
||||
for (definePtr = defineBegin; definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister())
|
||||
currentLive.clear(name2range[definePtr->getRegisterName()]);
|
||||
|
||||
|
||||
for (usePtr = useBegin; usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister()) {
|
||||
RegisterName range = name2range[usePtr->getRegisterName()];
|
||||
currentLive.set(range);
|
||||
needLoad.set(range);
|
||||
}
|
||||
}
|
||||
|
||||
for (SparseSet::iterator l = needLoad.begin(); !needLoad.done(l); l = needLoad.advance(l)) {
|
||||
RegisterName load = RegisterName(needLoad.get(l));
|
||||
if (willSpill.test(load))
|
||||
insertLoadBefore(instructions.first(), load);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class RegisterPressure>
|
||||
void Spilling<RegisterPressure>::insertLoadBefore(Instruction& /*instruction*/, RegisterName name)
|
||||
{
|
||||
fprintf(stdout, "will insert load for range %d\n", name);
|
||||
}
|
||||
|
||||
template <class RegisterPressure>
|
||||
void Spilling<RegisterPressure>::insertStoreAfter(Instruction& /*instruction*/, RegisterName name)
|
||||
{
|
||||
fprintf(stdout, "will insert store for range %d\n", name);
|
||||
}
|
||||
|
||||
template <class RegisterPressure>
|
||||
void Spilling<RegisterPressure>::calculateSpillCosts(RegisterAllocator& registerAllocator)
|
||||
{
|
||||
Uint32 rangeCount = registerAllocator.rangeCount;
|
||||
RegisterName* name2range = registerAllocator.name2range;
|
||||
|
||||
Pool& pool = registerAllocator.pool;
|
||||
SparseSet live(pool, rangeCount);
|
||||
SparseSet needLoad(pool, rangeCount);
|
||||
SparseSet mustSpill(pool, rangeCount);
|
||||
|
||||
SparseSet alreadyStored(pool, rangeCount); // FIX: should get this from previous spilling.
|
||||
|
||||
SpillCost* cost = new SpillCost[rangeCount];
|
||||
memset(cost, '\0', rangeCount * sizeof(SpillCost));
|
||||
|
||||
ControlGraph& controlGraph = registerAllocator.controlGraph;
|
||||
RegisterPressure::Set* liveOut = registerAllocator.liveness.liveOut;
|
||||
ControlNode** nodes = controlGraph.dfsList;
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
|
||||
for (Uint32 n = 0; n < nNodes; n++) {
|
||||
ControlNode& node = *nodes[n];
|
||||
|
||||
double weight = doLog10(node.loopDepth);
|
||||
|
||||
needLoad.clear();
|
||||
live = liveOut[n];
|
||||
mustSpill = live;
|
||||
|
||||
InstructionList& instructions = nodes[n]->getInstructions();
|
||||
for (InstructionList::iterator i = instructions.end(); !instructions.done(i); i = instructions.retreat(i)) {
|
||||
Instruction& instruction = instructions.get(i);
|
||||
|
||||
InstructionUse* useBegin = instruction.getInstructionUseBegin();
|
||||
InstructionUse* useEnd = instruction.getInstructionUseEnd();
|
||||
InstructionUse* usePtr;
|
||||
InstructionDefine* defineBegin = instruction.getInstructionDefineBegin();
|
||||
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
|
||||
InstructionDefine* definePtr;
|
||||
|
||||
for (definePtr = defineBegin; definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister()) {
|
||||
RegisterName range = name2range[definePtr->getRegisterName()];
|
||||
|
||||
if (needLoad.test(range))
|
||||
if (!mustSpill.test(range))
|
||||
cost[range].infinite = true;
|
||||
|
||||
if ((false /* !rematerializable(range) */ || !needLoad.test(range)) && !alreadyStored.test(range))
|
||||
cost[range].stores += weight;
|
||||
|
||||
needLoad.clear(range);
|
||||
}
|
||||
|
||||
if (instruction.getFlags() & ifCopy)
|
||||
for (usePtr = useBegin; usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister())
|
||||
if (!live.test(name2range[usePtr->getRegisterName()])) {
|
||||
for (SparseSet::iterator l = needLoad.begin(); !needLoad.done(l); l = needLoad.advance(l)) {
|
||||
Uint32 range = needLoad.get(l);
|
||||
cost[range].loads += weight;
|
||||
mustSpill.set(range);
|
||||
}
|
||||
needLoad.clear();
|
||||
}
|
||||
|
||||
for (definePtr = defineBegin; definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister())
|
||||
live.clear(name2range[definePtr->getRegisterName()]);
|
||||
|
||||
for (usePtr = useBegin; usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister()) {
|
||||
RegisterName range = name2range[usePtr->getRegisterName()];
|
||||
|
||||
live.set(range);
|
||||
needLoad.set(range);
|
||||
}
|
||||
|
||||
if (instruction.getFlags() & ifCopy) {
|
||||
assert(useBegin != useEnd && useBegin[0].isRegister());
|
||||
assert(defineBegin != defineEnd && defineBegin[0].isRegister());
|
||||
|
||||
RegisterName source = name2range[useBegin[0].getRegisterName()];
|
||||
RegisterName destination = name2range[defineBegin[0].getRegisterName()];
|
||||
|
||||
cost[source].copies += weight;
|
||||
cost[destination].copies += weight;
|
||||
}
|
||||
}
|
||||
|
||||
for (SparseSet::iterator s = needLoad.begin(); !needLoad.done(s); s = needLoad.advance(s))
|
||||
cost[needLoad.get(s)].loads += weight;
|
||||
}
|
||||
|
||||
for (Uint32 r = 0; r < rangeCount; r++) {
|
||||
SpillCost& c = cost[r];
|
||||
c.cost = 2 * (c.loads + c.stores) - c.copies;
|
||||
}
|
||||
|
||||
registerAllocator.spillCost = cost;
|
||||
}
|
||||
|
||||
#endif // _SPILLING_H_
|
||||
239
mozilla/ef/Compiler/RegisterAllocator/Splits.h
Normal file
239
mozilla/ef/Compiler/RegisterAllocator/Splits.h
Normal file
@@ -0,0 +1,239 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _SPLITS_H_
|
||||
#define _SPLITS_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include <string.h>
|
||||
#include "Pool.h"
|
||||
#include "ControlGraph.h"
|
||||
#include "ControlNodes.h"
|
||||
#include "Instruction.h"
|
||||
#include "RegisterAllocator.h"
|
||||
#include "RegisterAllocatorTools.h"
|
||||
|
||||
UT_EXTERN_LOG_MODULE(RegAlloc);
|
||||
|
||||
template <class RegisterPressure>
|
||||
struct Splits
|
||||
{
|
||||
static void calculateSplitCosts(RegisterAllocator& registerAllocator);
|
||||
static bool findSplit(RegisterAllocator& registerAllocator, RegisterName* color, RegisterName range);
|
||||
static void insertSplitCode(RegisterAllocator& registerAllocator);
|
||||
};
|
||||
|
||||
struct SplitCost
|
||||
{
|
||||
double loads;
|
||||
double stores;
|
||||
};
|
||||
|
||||
template <class RegisterPressure>
|
||||
void Splits<RegisterPressure>::insertSplitCode(RegisterAllocator& /*registerAllocator*/)
|
||||
{
|
||||
// FIX
|
||||
}
|
||||
|
||||
template <class RegisterPressure>
|
||||
bool Splits<RegisterPressure>::findSplit(RegisterAllocator& registerAllocator, RegisterName* color, RegisterName range)
|
||||
{
|
||||
Pool& pool = registerAllocator.pool;
|
||||
NameLinkedList** neighborsWithColor = new(pool) NameLinkedList*[6]; // FIX
|
||||
memset(neighborsWithColor, '\0', 6 * sizeof(NameLinkedList*));
|
||||
|
||||
InterferenceGraph<RegisterPressure>& iGraph = registerAllocator.iGraph;
|
||||
|
||||
for (InterferenceVector* vector = iGraph.getInterferenceVector(range); vector != NULL; vector = vector->next)
|
||||
for (Int32 i = vector->count - 1; i >=0; --i) {
|
||||
RegisterName neighbor = vector->neighbors[i];
|
||||
RegisterName c = color[neighbor];
|
||||
|
||||
if (c < 6) { // FIX
|
||||
NameLinkedList* node = new(pool) NameLinkedList();
|
||||
node->name = neighbor;
|
||||
node->next = neighborsWithColor[c];
|
||||
neighborsWithColor[c] = node;
|
||||
}
|
||||
}
|
||||
|
||||
bool splitAroundName = true;
|
||||
|
||||
LiveRangeGraph<RegisterPressure>& lGraph = registerAllocator.lGraph;
|
||||
RegisterName bestColor = RegisterName(6); // FIX
|
||||
double bestCost = registerAllocator.spillCost[range].cost;
|
||||
SplitCost* splitCost = registerAllocator.splitCost;
|
||||
|
||||
for (RegisterName i = RegisterName(0); i < 6; i = RegisterName(i + 1)) { // FIX
|
||||
|
||||
double splitAroundNameCost = 0.0;
|
||||
bool canSplitAroundName = true;
|
||||
|
||||
SplitCost& sCost = splitCost[range];
|
||||
double addedCost = 2.0 * (sCost.stores + sCost.loads);
|
||||
|
||||
for (NameLinkedList* node = neighborsWithColor[i]; node != NULL; node = node->next) {
|
||||
RegisterName neighbor = node->name;
|
||||
if (lGraph.haveEdge(neighbor, range)) {
|
||||
canSplitAroundName = false;
|
||||
break;
|
||||
} else
|
||||
splitAroundNameCost += addedCost;
|
||||
}
|
||||
if (canSplitAroundName && splitAroundNameCost < bestCost) {
|
||||
bestCost = splitAroundNameCost;
|
||||
bestColor = i;
|
||||
splitAroundName = true;
|
||||
}
|
||||
|
||||
double splitAroundColorCost = 0.0;
|
||||
bool canSplitAroundColor = true;
|
||||
|
||||
for (NameLinkedList* node = neighborsWithColor[i]; node != NULL; node = node->next) {
|
||||
RegisterName neighbor = node->name;
|
||||
if (lGraph.haveEdge(range, neighbor)) {
|
||||
canSplitAroundColor = false;
|
||||
break;
|
||||
} else {
|
||||
SplitCost& sCost = splitCost[neighbor];
|
||||
double addedCost = 2.0 * (sCost.stores + sCost.loads);
|
||||
splitAroundColorCost += addedCost;
|
||||
}
|
||||
}
|
||||
if (canSplitAroundColor && splitAroundColorCost < bestCost) {
|
||||
bestCost = splitAroundColorCost;
|
||||
bestColor = i;
|
||||
splitAroundName = false;
|
||||
}
|
||||
}
|
||||
if (bestColor < RegisterName(6)) {
|
||||
color[range] = bestColor;
|
||||
registerAllocator.splitFound = true;
|
||||
|
||||
NameLinkedList** splitAround = registerAllocator.splitAround;
|
||||
|
||||
if (splitAroundName)
|
||||
for (NameLinkedList* node = neighborsWithColor[bestColor]; node != NULL; node = node->next) {
|
||||
NameLinkedList* newNode = new(pool) NameLinkedList();
|
||||
newNode->name = node->name;
|
||||
newNode->next = splitAround[range];
|
||||
splitAround[range] = newNode;
|
||||
}
|
||||
else
|
||||
for (NameLinkedList* node = neighborsWithColor[bestColor]; node != NULL; node = node->next) {
|
||||
NameLinkedList* newNode = new(pool) NameLinkedList();
|
||||
RegisterName neighbor = node->name;
|
||||
newNode->name = range;
|
||||
newNode->next = splitAround[neighbor];
|
||||
splitAround[neighbor] = newNode;
|
||||
}
|
||||
|
||||
trespass("Found a split");
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
template <class RegisterPressure>
|
||||
void Splits<RegisterPressure>::calculateSplitCosts(RegisterAllocator& registerAllocator)
|
||||
{
|
||||
Pool& pool = registerAllocator.pool;
|
||||
Uint32 rangeCount = registerAllocator.rangeCount;
|
||||
RegisterName* name2range = registerAllocator.name2range;
|
||||
|
||||
SplitCost* splitCost = new(pool) SplitCost[rangeCount];
|
||||
memset(splitCost, '\0', rangeCount * sizeof(SplitCost));
|
||||
|
||||
SparseSet live(pool, rangeCount);
|
||||
RegisterPressure::Set* liveIn = registerAllocator.liveness.liveIn;
|
||||
RegisterPressure::Set* liveOut = registerAllocator.liveness.liveOut;
|
||||
|
||||
ControlGraph& controlGraph = registerAllocator.controlGraph;
|
||||
ControlNode** nodes = controlGraph.dfsList;
|
||||
Uint32 nNodes = controlGraph.nNodes;
|
||||
|
||||
for (Uint32 n = 0; n < nNodes; n++) {
|
||||
ControlNode& node = *nodes[n];
|
||||
double weight = doLog10(node.loopDepth);
|
||||
|
||||
live = liveOut[n];
|
||||
|
||||
ControlEdge* successorsEnd = node.getSuccessorsEnd();
|
||||
for (ControlEdge* successorsPtr = node.getSuccessorsBegin(); successorsPtr < successorsEnd; successorsPtr++) {
|
||||
ControlNode& successor = successorsPtr->getTarget();
|
||||
|
||||
if (successor.getControlKind() != ckEnd) {
|
||||
RegisterPressure::Set& successorLiveIn = liveIn[successor.dfsNum];
|
||||
|
||||
for (SparseSet::iterator i = live.begin(); !live.done(i); i = live.advance(i)) {
|
||||
RegisterName name = RegisterName(live.get(i));
|
||||
if (!successorLiveIn.test(name))
|
||||
splitCost[name].loads += doLog10(successor.loopDepth);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
InstructionList& instructions = node.getInstructions();
|
||||
for (InstructionList::iterator i = instructions.end(); !instructions.done(i); i = instructions.retreat(i)) {
|
||||
Instruction& instruction = instructions.get(i);
|
||||
|
||||
InstructionUse* useBegin = instruction.getInstructionUseBegin();
|
||||
InstructionUse* useEnd = instruction.getInstructionUseEnd();
|
||||
InstructionUse* usePtr;
|
||||
InstructionDefine* defineBegin = instruction.getInstructionDefineBegin();
|
||||
InstructionDefine* defineEnd = instruction.getInstructionDefineEnd();
|
||||
InstructionDefine* definePtr;
|
||||
|
||||
for (definePtr = defineBegin; definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister())
|
||||
splitCost[name2range[definePtr->getRegisterName()]].stores += weight;
|
||||
|
||||
for (usePtr = useBegin; usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister()) {
|
||||
RegisterName range = name2range[usePtr->getRegisterName()];
|
||||
if (!live.test(range)) {
|
||||
if (&instruction != &instructions.last())
|
||||
splitCost[range].loads += weight;
|
||||
else {
|
||||
ControlEdge* successorsEnd = node.getSuccessorsEnd();
|
||||
for (ControlEdge* successorsPtr = node.getSuccessorsBegin(); successorsPtr < successorsEnd; successorsPtr++)
|
||||
splitCost[range].loads += doLog10(successorsPtr->getTarget().loopDepth);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (definePtr = defineBegin; definePtr < defineEnd; definePtr++)
|
||||
if (definePtr->isRegister())
|
||||
live.clear(name2range[definePtr->getRegisterName()]);
|
||||
|
||||
for (usePtr = useBegin; usePtr < useEnd; usePtr++)
|
||||
if (usePtr->isRegister())
|
||||
live.set(name2range[usePtr->getRegisterName()]);
|
||||
}
|
||||
}
|
||||
|
||||
NameLinkedList** splitAround = new(pool) NameLinkedList*[rangeCount];
|
||||
memset(splitAround, '\0', rangeCount * sizeof(NameLinkedList*));
|
||||
registerAllocator.splitAround = splitAround;
|
||||
|
||||
registerAllocator.splitCost = splitCost;
|
||||
registerAllocator.splitFound = false;
|
||||
}
|
||||
|
||||
#endif // _SPLITS_H_
|
||||
186
mozilla/ef/Compiler/RegisterAllocator/Timer.cpp
Normal file
186
mozilla/ef/Compiler/RegisterAllocator/Timer.cpp
Normal file
@@ -0,0 +1,186 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "HashTable.h"
|
||||
#include "Timer.h"
|
||||
#include "Pool.h"
|
||||
|
||||
static Pool pool; // Pool for the Timer class.
|
||||
static HashTable<TimerEntry*> timerEntries(pool); // Timers hashtable.
|
||||
|
||||
const nTimersInABlock = 128; // Number of timers in a block.
|
||||
static PRTime *timers = new(pool) PRTime[nTimersInABlock]; // A block of timers.
|
||||
static Uint8 nextTimer = 0; // nextAvailableTimer.
|
||||
|
||||
//
|
||||
// Calibrate the call to PR_Now().
|
||||
//
|
||||
static PRTime calibrate()
|
||||
{
|
||||
PRTime t = PR_Now();
|
||||
PRTime& a = *new(pool) PRTime();
|
||||
|
||||
// Call 10 times the PR_Now() function.
|
||||
a = PR_Now(); a = PR_Now(); a = PR_Now(); a = PR_Now(); a = PR_Now(); a = PR_Now();
|
||||
a = PR_Now(); a = PR_Now(); a = PR_Now(); a = PR_Now(); a = PR_Now(); a = PR_Now();
|
||||
t = (PR_Now() - t + 9) / 10;
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
static PRTime adjust = calibrate();
|
||||
|
||||
//
|
||||
// Return the named timer..
|
||||
//
|
||||
TimerEntry& Timer::getTimerEntry(const char* name)
|
||||
{
|
||||
if (!timerEntries.exists(name)) {
|
||||
TimerEntry* newEntry = new(pool) TimerEntry();
|
||||
newEntry->accumulator = 0;
|
||||
newEntry->running = false;
|
||||
timerEntries.add(name, newEntry);
|
||||
}
|
||||
|
||||
return *timerEntries[name];
|
||||
}
|
||||
|
||||
//
|
||||
// Return a reference to a new timer.
|
||||
//
|
||||
PRTime& Timer::getNewTimer()
|
||||
{
|
||||
if (nextTimer >= nTimersInABlock) {
|
||||
timers = new(pool) PRTime[nTimersInABlock];
|
||||
nextTimer = 0;
|
||||
}
|
||||
return timers[nextTimer++];
|
||||
}
|
||||
|
||||
static Uint32 timersAreFrozen = 0;
|
||||
|
||||
//
|
||||
// Start the named timer.
|
||||
//
|
||||
void Timer::start(const char* name)
|
||||
{
|
||||
if (timersAreFrozen)
|
||||
return;
|
||||
|
||||
freezeTimers();
|
||||
|
||||
TimerEntry& timer = getTimerEntry(name);
|
||||
PR_ASSERT(!timer.running);
|
||||
|
||||
timer.accumulator = 0;
|
||||
timer.running = true;
|
||||
timer.done = false;
|
||||
|
||||
unfreezeTimers();
|
||||
}
|
||||
|
||||
//
|
||||
// Stop the named timer.
|
||||
//
|
||||
void Timer::stop(const char* name)
|
||||
{
|
||||
if (timersAreFrozen)
|
||||
return;
|
||||
|
||||
freezeTimers();
|
||||
|
||||
TimerEntry& timer = getTimerEntry(name);
|
||||
PR_ASSERT(timer.running);
|
||||
timer.running = false;
|
||||
timer.done = true;
|
||||
|
||||
unfreezeTimers();
|
||||
}
|
||||
|
||||
//
|
||||
// Freeze all the running timers.
|
||||
//
|
||||
void Timer::freezeTimers()
|
||||
{
|
||||
PRTime when = PR_Now() - adjust;
|
||||
|
||||
if (timersAreFrozen == 0) {
|
||||
Vector<TimerEntry*> entries = timerEntries;
|
||||
Uint32 count = entries.size();
|
||||
|
||||
for (Uint32 i = 0; i < count; i++) {
|
||||
TimerEntry& entry = *entries[i];
|
||||
if (entry.running) {
|
||||
entry.accumulator += (when - *entry.startTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
timersAreFrozen++;
|
||||
}
|
||||
|
||||
//
|
||||
// Unfreeze all the running timers.
|
||||
//
|
||||
void Timer::unfreezeTimers()
|
||||
{
|
||||
PR_ASSERT(timersAreFrozen != 0);
|
||||
timersAreFrozen--;
|
||||
|
||||
if (timersAreFrozen == 0) {
|
||||
Vector<TimerEntry *> entries = timerEntries;
|
||||
Uint32 count = entries.size();
|
||||
|
||||
PRTime& newStart = getNewTimer();
|
||||
|
||||
for (Uint32 i = 0; i < count; i++) {
|
||||
TimerEntry& entry = *entries[i];
|
||||
if (entry.running) {
|
||||
entry.startTime = &newStart;
|
||||
}
|
||||
}
|
||||
|
||||
newStart = PR_Now();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Print the named timer in the file f.
|
||||
//
|
||||
void Timer::print(FILE* f, const char *name)
|
||||
{
|
||||
if (timersAreFrozen)
|
||||
return;
|
||||
|
||||
freezeTimers();
|
||||
|
||||
TimerEntry& timer = getTimerEntry(name);
|
||||
|
||||
PR_ASSERT(timer.done);
|
||||
PRTime elapsed = timer.accumulator;
|
||||
|
||||
if (elapsed >> 32) {
|
||||
fprintf(f, "[timer %s out of range]\n", name);
|
||||
} else {
|
||||
fprintf(f, "[%dus in %s]\n", Uint32(elapsed), name);
|
||||
}
|
||||
fflush(f);
|
||||
|
||||
unfreezeTimers();
|
||||
}
|
||||
|
||||
80
mozilla/ef/Compiler/RegisterAllocator/Timer.h
Normal file
80
mozilla/ef/Compiler/RegisterAllocator/Timer.h
Normal file
@@ -0,0 +1,80 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _TIMER_H_
|
||||
#define _TIMER_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "HashTable.h"
|
||||
#include "prtime.h"
|
||||
|
||||
//
|
||||
// Naming convention:
|
||||
// As the class Timer contains only static methods, the timer's name should start with the
|
||||
// module name. Otherwise starting 2 timers with the same name will assert.
|
||||
//
|
||||
|
||||
#ifndef NO_TIMER
|
||||
|
||||
struct TimerEntry
|
||||
{
|
||||
PRTime *startTime; // Current time when we start the timer.
|
||||
PRTime accumulator; // Time spent in this timer.
|
||||
bool running; // True if the timer is running.
|
||||
bool done; // True if the timer was running and was stopped.
|
||||
};
|
||||
|
||||
class Timer
|
||||
{
|
||||
private:
|
||||
|
||||
// Return the named timer.
|
||||
static TimerEntry& getTimerEntry(const char* name);
|
||||
// Return a reference to a new Timer.
|
||||
static PRTime& getNewTimer();
|
||||
|
||||
public:
|
||||
|
||||
// Start the timer.
|
||||
static void start(const char* name);
|
||||
// Stop the timer.
|
||||
static void stop(const char* name);
|
||||
// Freeze all the running timers.
|
||||
static void freezeTimers();
|
||||
// Unfreeze all the running timers.
|
||||
static void unfreezeTimers();
|
||||
// Print the timer.
|
||||
static void print(FILE* f, const char *name);
|
||||
};
|
||||
|
||||
inline void startTimer(const char* name) {Timer::start(name);}
|
||||
inline void stopTimer(const char* name) {Timer::stop(name); Timer::print(stdout, name);}
|
||||
#define START_TIMER_SAFE Timer::freezeTimers();
|
||||
#define END_TIMER_SAFE Timer::unfreezeTimers();
|
||||
#define TIMER_SAFE(x) START_TIMER_SAFE x; END_TIMER_SAFE
|
||||
|
||||
#else /* NO_TIMER */
|
||||
|
||||
inline void startTimer(const char* /*name*/) {}
|
||||
inline void stopTimer(const char* /*name*/) {}
|
||||
#define START_TIMER_SAFE
|
||||
#define END_TIMER_SAFE
|
||||
#define TIMER_SAFE(x) x;
|
||||
|
||||
#endif /* NO_TIMER */
|
||||
#endif /* _TIMER_H_ */
|
||||
40
mozilla/ef/Compiler/RegisterAllocator/VirtualRegister.cpp
Normal file
40
mozilla/ef/Compiler/RegisterAllocator/VirtualRegister.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "VirtualRegister.h"
|
||||
#include "Instruction.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// VirtualRegister -
|
||||
|
||||
#ifdef MANUAL_TEMPLATES
|
||||
template class IndexedPool<VirtualRegister>;
|
||||
#endif
|
||||
|
||||
// Set the defining instruction.
|
||||
//
|
||||
void VirtualRegister::setDefiningInstruction(Instruction& instruction)
|
||||
{
|
||||
if (definingInstruction != NULL) {
|
||||
if ((instruction.getFlags() & ifCopy) && (definingInstruction->getFlags() & ifPhiNode))
|
||||
return;
|
||||
}
|
||||
definingInstruction = &instruction;
|
||||
}
|
||||
|
||||
116
mozilla/ef/Compiler/RegisterAllocator/VirtualRegister.h
Normal file
116
mozilla/ef/Compiler/RegisterAllocator/VirtualRegister.h
Normal file
@@ -0,0 +1,116 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _VIRTUAL_REGISTER_H_
|
||||
#define _VIRTUAL_REGISTER_H_
|
||||
|
||||
#include "Fundamentals.h"
|
||||
#include "IndexedPool.h"
|
||||
#include <string.h>
|
||||
|
||||
#include "RegisterTypes.h"
|
||||
#include "RegisterClass.h"
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// VirtualRegister - 24b
|
||||
|
||||
class Instruction;
|
||||
|
||||
class VirtualRegister : public IndexedObject<VirtualRegister>
|
||||
{
|
||||
public:
|
||||
|
||||
Instruction* definingInstruction; // Instruction defining this VR.
|
||||
|
||||
// Initialize a VR of the given classKind.
|
||||
VirtualRegister(RegisterClassKind /*classKind*/) : definingInstruction(NULL) {}
|
||||
|
||||
// Return the defining instruction for this VR.
|
||||
Instruction* getDefiningInstruction() const {return definingInstruction;}
|
||||
// Set the defining instruction.
|
||||
void setDefiningInstruction(Instruction& insn);
|
||||
};
|
||||
|
||||
// Return true if the VirtualRegisters are equals. The only way 2 VRs can be equal is if
|
||||
// they have the same index. If they have the same index then they are at the same
|
||||
// address in the indexed pool.
|
||||
//
|
||||
inline bool operator == (const VirtualRegister& regA, const VirtualRegister& regB) {return ®A == ®B;}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// VirtualRegisterManager -
|
||||
|
||||
struct PreColoredRegister
|
||||
{
|
||||
RegisterID id;
|
||||
RegisterName color;
|
||||
};
|
||||
|
||||
class VirtualRegisterManager
|
||||
{
|
||||
private:
|
||||
|
||||
IndexedPool<VirtualRegister> registerPool;
|
||||
PreColoredRegister machineRegister[6];
|
||||
|
||||
public:
|
||||
VirtualRegisterManager()
|
||||
{
|
||||
for (Uint32 i = 0; i < 6; i++)
|
||||
machineRegister[i].id = invalidID;
|
||||
}
|
||||
|
||||
// Return the VirtualRegister at the given index.
|
||||
VirtualRegister& getVirtualRegister(RegisterName name) const {return registerPool.get(name);}
|
||||
|
||||
// Return a new VirtualRegister.
|
||||
RegisterID newVirtualRegister(RegisterClassKind classKind)
|
||||
{
|
||||
VirtualRegister& vReg = *new(registerPool) VirtualRegister(classKind);
|
||||
RegisterID rid;
|
||||
|
||||
setName(rid, RegisterName(vReg.getIndex()));
|
||||
setClass(rid, classKind);
|
||||
return rid;
|
||||
}
|
||||
|
||||
RegisterID newMachineRegister(RegisterName name, RegisterClassKind classKind)
|
||||
{
|
||||
RegisterID rid = machineRegister[name].id;
|
||||
|
||||
if (rid == invalidID) {
|
||||
rid = newVirtualRegister(classKind);
|
||||
DEBUG_ONLY(setMachineRegister(rid));
|
||||
machineRegister[name].id = rid;
|
||||
machineRegister[name].color = name;
|
||||
}
|
||||
|
||||
return rid;
|
||||
}
|
||||
|
||||
PreColoredRegister* getMachineRegistersBegin() const {return (PreColoredRegister*) machineRegister;} // FIX
|
||||
PreColoredRegister* getMachineRegistersEnd() const {return (PreColoredRegister*) &machineRegister[6];} // FIX
|
||||
|
||||
// Return the VirtualRegister universe size.
|
||||
Uint32 getSize() {return registerPool.getSize();}
|
||||
|
||||
void setSize(Uint32 size) {registerPool.setSize(size);}
|
||||
};
|
||||
|
||||
#endif // _VIRTUAL_REGISTER_H_
|
||||
@@ -1,78 +0,0 @@
|
||||
#! gmake
|
||||
#
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public License Version
|
||||
# 1.1 (the "License"); you may not use this file except in compliance with
|
||||
# the License. You may obtain a copy of the License at
|
||||
# http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
# for the specific language governing rights and limitations under the
|
||||
# License.
|
||||
#
|
||||
# The Original Code is the Netscape security libraries.
|
||||
#
|
||||
# The Initial Developer of the Original Code is
|
||||
# Netscape Communications Corporation.
|
||||
# Portions created by the Initial Developer are Copyright (C) 1994-2000
|
||||
# the Initial Developer. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the terms of
|
||||
# either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
# in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
# of those above. If you wish to allow use of your version of this file only
|
||||
# under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
# use your version of this file under the terms of the MPL, indicate your
|
||||
# decision by deleting the provisions above and replace them with the notice
|
||||
# and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
# the provisions above, a recipient may use your version of this file under
|
||||
# the terms of any one of the MPL, the GPL or the LGPL.
|
||||
#
|
||||
# ***** END LICENSE BLOCK *****
|
||||
|
||||
#######################################################################
|
||||
# (1) Include initial platform-independent assignments (MANDATORY). #
|
||||
#######################################################################
|
||||
|
||||
include manifest.mn
|
||||
|
||||
#######################################################################
|
||||
# (2) Include "global" configuration information. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
include $(CORE_DEPTH)/coreconf/config.mk
|
||||
|
||||
#######################################################################
|
||||
# (3) Include "component" configuration information. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (4) Include "local" platform-dependent assignments (OPTIONAL). #
|
||||
#######################################################################
|
||||
include config.mk
|
||||
|
||||
#######################################################################
|
||||
# (5) Execute "global" rules. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
include $(CORE_DEPTH)/coreconf/rules.mk
|
||||
|
||||
#######################################################################
|
||||
# (6) Execute "component" rules. (OPTIONAL) #
|
||||
#######################################################################
|
||||
|
||||
|
||||
|
||||
#######################################################################
|
||||
# (7) Execute "local" rules. (OPTIONAL). #
|
||||
#######################################################################
|
||||
|
||||
export:: private_export
|
||||
@@ -1,165 +0,0 @@
|
||||
#
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public License Version
|
||||
# 1.1 (the "License"); you may not use this file except in compliance with
|
||||
# the License. You may obtain a copy of the License at
|
||||
# http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
# for the specific language governing rights and limitations under the
|
||||
# License.
|
||||
#
|
||||
# The Original Code is the Netscape security libraries.
|
||||
#
|
||||
# The Initial Developer of the Original Code is
|
||||
# Netscape Communications Corporation.
|
||||
# Portions created by the Initial Developer are Copyright (C) 1994-2000
|
||||
# the Initial Developer. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the terms of
|
||||
# either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
# in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
# of those above. If you wish to allow use of your version of this file only
|
||||
# under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
# use your version of this file under the terms of the MPL, indicate your
|
||||
# decision by deleting the provisions above and replace them with the notice
|
||||
# and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
# the provisions above, a recipient may use your version of this file under
|
||||
# the terms of any one of the MPL, the GPL or the LGPL.
|
||||
#
|
||||
# ***** END LICENSE BLOCK *****
|
||||
|
||||
#
|
||||
# Override TARGETS variable so that only static libraries
|
||||
# are specifed as dependencies within rules.mk.
|
||||
#
|
||||
|
||||
# can't do this in manifest.mn because OS_TARGET isn't defined there.
|
||||
ifeq (,$(filter-out WIN%,$(OS_TARGET)))
|
||||
|
||||
# don't want the 32 in the shared library name
|
||||
SHARED_LIBRARY = $(OBJDIR)/$(DLL_PREFIX)$(LIBRARY_NAME)$(LIBRARY_VERSION).$(DLL_SUFFIX)
|
||||
IMPORT_LIBRARY = $(OBJDIR)/$(IMPORT_LIB_PREFIX)$(LIBRARY_NAME)$(LIBRARY_VERSION)$(IMPORT_LIB_SUFFIX)
|
||||
|
||||
RES = $(OBJDIR)/$(LIBRARY_NAME).res
|
||||
RESNAME = $(LIBRARY_NAME).rc
|
||||
|
||||
ifdef NS_USE_GCC
|
||||
EXTRA_SHARED_LIBS += \
|
||||
-L$(DIST)/lib \
|
||||
-lnssutil3 \
|
||||
-L$(NSPR_LIB_DIR) \
|
||||
-lplc4 \
|
||||
-lplds4 \
|
||||
-lnspr4\
|
||||
$(NULL)
|
||||
else # ! NS_USE_GCC
|
||||
EXTRA_SHARED_LIBS += \
|
||||
$(DIST)/lib/nssutil3.lib \
|
||||
$(NSPR_LIB_DIR)/$(NSPR31_LIB_PREFIX)plc4.lib \
|
||||
$(NSPR_LIB_DIR)/$(NSPR31_LIB_PREFIX)plds4.lib \
|
||||
$(NSPR_LIB_DIR)/$(NSPR31_LIB_PREFIX)nspr4.lib \
|
||||
$(NULL)
|
||||
endif # NS_USE_GCC
|
||||
|
||||
else
|
||||
|
||||
# $(PROGRAM) has NO explicit dependencies on $(EXTRA_SHARED_LIBS)
|
||||
# $(EXTRA_SHARED_LIBS) come before $(OS_LIBS), except on AIX.
|
||||
EXTRA_SHARED_LIBS += \
|
||||
-L$(DIST)/lib \
|
||||
-lnssutil3 \
|
||||
-L$(NSPR_LIB_DIR) \
|
||||
-lplc4 \
|
||||
-lplds4 \
|
||||
-lnspr4 \
|
||||
$(NULL)
|
||||
|
||||
endif
|
||||
|
||||
|
||||
# $(PROGRAM) has explicit dependencies on $(EXTRA_LIBS)
|
||||
SHARED_LIBRARY_LIBS = \
|
||||
$(DIST)/lib/$(LIB_PREFIX)certhi.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)cryptohi.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)pk11wrap.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)certdb.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)nsspki.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)nssdev.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)nssb.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)certsel.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)checker.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)params.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)results.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)top.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)util.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)crlsel.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)store.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)pki.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)system.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/$(LIB_PREFIX)module.$(LIB_SUFFIX) \
|
||||
$(NULL)
|
||||
|
||||
SHARED_LIBRARY_DIRS = \
|
||||
../certhigh \
|
||||
../cryptohi \
|
||||
../pk11wrap \
|
||||
../certdb \
|
||||
../pki \
|
||||
../dev \
|
||||
../base \
|
||||
../libpkix/pkix/certsel \
|
||||
../libpkix/pkix/checker \
|
||||
../libpkix/pkix/params \
|
||||
../libpkix/pkix/results \
|
||||
../libpkix/pkix/top \
|
||||
../libpkix/pkix/util \
|
||||
../libpkix/pkix/crlsel \
|
||||
../libpkix/pkix/store \
|
||||
../libpkix/pkix_pl_nss/pki \
|
||||
../libpkix/pkix_pl_nss/system \
|
||||
../libpkix/pkix_pl_nss/module \
|
||||
$(NULL)
|
||||
|
||||
ifeq ($(OS_ARCH), Darwin)
|
||||
EXTRA_SHARED_LIBS += -dylib_file @executable_path/libsqlite3.dylib:$(DIST)/lib/libsqlite3.dylib
|
||||
endif
|
||||
|
||||
|
||||
ifeq ($(OS_TARGET),SunOS)
|
||||
ifeq ($(BUILD_SUN_PKG), 1)
|
||||
# The -R '$ORIGIN' linker option instructs this library to search for its
|
||||
# dependencies in the same directory where it resides.
|
||||
ifeq ($(USE_64), 1)
|
||||
MKSHLIB += -R '$$ORIGIN:/usr/lib/mps/secv1/64:/usr/lib/mps/64'
|
||||
else
|
||||
MKSHLIB += -R '$$ORIGIN:/usr/lib/mps/secv1:/usr/lib/mps'
|
||||
endif
|
||||
else
|
||||
MKSHLIB += -R '$$ORIGIN'
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(OS_ARCH), HP-UX)
|
||||
ifneq ($(OS_TEST), ia64)
|
||||
# pa-risc
|
||||
ifeq ($(USE_64), 1)
|
||||
MKSHLIB += +b '$$ORIGIN'
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq (,$(filter-out WINNT WIN95,$(OS_TARGET)))
|
||||
ifndef NS_USE_GCC
|
||||
# Export 'mktemp' to be backward compatible with NSS 3.2.x and 3.3.x
|
||||
# but do not put it in the import library. See bug 142575.
|
||||
DEFINES += -DWIN32_NSS3_DLL_COMPAT
|
||||
DLLFLAGS += -EXPORT:mktemp=nss_mktemp,PRIVATE
|
||||
endif
|
||||
endif
|
||||
@@ -1,63 +0,0 @@
|
||||
#
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public License Version
|
||||
# 1.1 (the "License"); you may not use this file except in compliance with
|
||||
# the License. You may obtain a copy of the License at
|
||||
# http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
# for the specific language governing rights and limitations under the
|
||||
# License.
|
||||
#
|
||||
# The Original Code is the Netscape security libraries.
|
||||
#
|
||||
# The Initial Developer of the Original Code is
|
||||
# Netscape Communications Corporation.
|
||||
# Portions created by the Initial Developer are Copyright (C) 1994-2000
|
||||
# the Initial Developer. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the terms of
|
||||
# either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
# in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
# of those above. If you wish to allow use of your version of this file only
|
||||
# under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
# use your version of this file under the terms of the MPL, indicate your
|
||||
# decision by deleting the provisions above and replace them with the notice
|
||||
# and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
# the provisions above, a recipient may use your version of this file under
|
||||
# the terms of any one of the MPL, the GPL or the LGPL.
|
||||
#
|
||||
# ***** END LICENSE BLOCK *****
|
||||
CORE_DEPTH = ../../..
|
||||
|
||||
PRIVATE_EXPORTS = \
|
||||
nssrenam.h \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
nss.h \
|
||||
$(NULL)
|
||||
|
||||
MODULE = nss
|
||||
|
||||
CSRCS = \
|
||||
nssinit.c \
|
||||
nssver.c \
|
||||
utilwrap.c \
|
||||
$(NULL)
|
||||
|
||||
REQUIRES = dbm
|
||||
|
||||
MAPFILE = $(OBJDIR)/nss.def
|
||||
|
||||
LIBRARY_NAME = nss
|
||||
LIBRARY_VERSION = 3
|
||||
|
||||
# This part of the code, including all sub-dirs, can be optimized for size
|
||||
export ALLOW_OPT_CODE_SIZE = 1
|
||||
@@ -1,945 +0,0 @@
|
||||
;+#
|
||||
;+# ***** BEGIN LICENSE BLOCK *****
|
||||
;+# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
;+#
|
||||
;+# The contents of this file are subject to the Mozilla Public License Version
|
||||
;+# 1.1 (the "License"); you may not use this file except in compliance with
|
||||
;+# the License. You may obtain a copy of the License at
|
||||
;+# http://www.mozilla.org/MPL/
|
||||
;+#
|
||||
;+# Software distributed under the License is distributed on an "AS IS" basis,
|
||||
;+# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
;+# for the specific language governing rights and limitations under the
|
||||
;+# License.
|
||||
;+#
|
||||
;+# The Original Code is the Netscape security libraries.
|
||||
;+#
|
||||
;+# The Initial Developer of the Original Code is
|
||||
;+# Netscape Communications Corporation.
|
||||
;+# Portions created by the Initial Developer are Copyright (C) 2000
|
||||
;+# the Initial Developer. All Rights Reserved.
|
||||
;+#
|
||||
;+# Contributor(s):
|
||||
;+# Dr Stephen Henson <stephen.henson@gemplus.com>
|
||||
;+# Dr Vipul Gupta <vipul.gupta@sun.com>, Sun Microsystems Laboratories
|
||||
;+#
|
||||
;+# Alternatively, the contents of this file may be used under the terms of
|
||||
;+# either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
;+# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
;+# in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
;+# of those above. If you wish to allow use of your version of this file only
|
||||
;+# under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
;+# use your version of this file under the terms of the MPL, indicate your
|
||||
;+# decision by deleting the provisions above and replace them with the notice
|
||||
;+# and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
;+# the provisions above, a recipient may use your version of this file under
|
||||
;+# the terms of any one of the MPL, the GPL or the LGPL.
|
||||
;+#
|
||||
;+# ***** END LICENSE BLOCK *****
|
||||
;+#
|
||||
;+# OK, this file is meant to support SUN, LINUX, AIX and WINDOWS
|
||||
;+# 1. For all unix platforms, the string ";-" means "remove this line"
|
||||
;+# 2. For all unix platforms, the string " DATA " will be removed from any
|
||||
;+# line on which it occurs.
|
||||
;+# 3. Lines containing ";+" will have ";+" removed on SUN and LINUX.
|
||||
;+# On AIX, lines containing ";+" will be removed.
|
||||
;+# 4. For all unix platforms, the string ";;" will thave the ";;" removed.
|
||||
;+# 5. For all unix platforms, after the above processing has taken place,
|
||||
;+# all characters after the first ";" on the line will be removed.
|
||||
;+# And for AIX, the first ";" will also be removed.
|
||||
;+# This file is passed directly to windows. Since ';' is a comment, all UNIX
|
||||
;+# directives are hidden behind ";", ";+", and ";-"
|
||||
;+NSS_3.2 { # NSS 3.2 release
|
||||
;+ global:
|
||||
LIBRARY nss3 ;-
|
||||
EXPORTS ;-
|
||||
ATOB_AsciiToData;
|
||||
BTOA_ConvertItemToAscii;
|
||||
BTOA_DataToAscii;
|
||||
CERT_AsciiToName;
|
||||
CERT_CertTimesValid;
|
||||
CERT_CheckCertValidTimes;
|
||||
CERT_CreateCertificateRequest;
|
||||
CERT_ChangeCertTrust;
|
||||
CERT_DecodeDERCrl;
|
||||
CERT_DestroyCertificateRequest;
|
||||
CERT_DestroyCertList;
|
||||
CERT_DestroyName;
|
||||
CERT_EnableOCSPChecking;
|
||||
CERT_FormatName;
|
||||
CERT_DestroyCertificate;
|
||||
CERT_DupCertificate;
|
||||
CERT_FreeDistNames;
|
||||
CERT_FreeNicknames;
|
||||
CERT_GetAVATag;
|
||||
CERT_GetCertEmailAddress;
|
||||
CERT_GetCertNicknames;
|
||||
CERT_GetCertIssuerAndSN;
|
||||
CERT_GetCertTrust;
|
||||
CERT_GetCertUid;
|
||||
CERT_GetCommonName;
|
||||
CERT_GetCountryName;
|
||||
CERT_GetDBContentVersion;
|
||||
CERT_GetDefaultCertDB;
|
||||
CERT_GetDomainComponentName;
|
||||
CERT_GetLocalityName;
|
||||
CERT_GetOrgName;
|
||||
CERT_GetOrgUnitName;
|
||||
CERT_GetSSLCACerts;
|
||||
CERT_GetSlopTime;
|
||||
CERT_GetStateName;
|
||||
CERT_ImportCAChain;
|
||||
CERT_NameToAscii;
|
||||
CERT_RFC1485_EscapeAndQuote;
|
||||
CERT_SetSlopTime;
|
||||
CERT_VerifyCertName;
|
||||
CERT_VerifyCertNow;
|
||||
DER_UTCDayToAscii;
|
||||
DER_UTCTimeToAscii;
|
||||
DER_GeneralizedTimeToTime;
|
||||
NSS_Init;
|
||||
NSS_Initialize;
|
||||
NSS_InitReadWrite;
|
||||
NSS_NoDB_Init;
|
||||
NSS_Shutdown;
|
||||
NSS_VersionCheck;
|
||||
PK11_Authenticate;
|
||||
PK11_ChangePW;
|
||||
PK11_CheckUserPassword;
|
||||
PK11_CipherOp;
|
||||
PK11_CloneContext;
|
||||
PK11_ConfigurePKCS11;
|
||||
PK11_CreateContextBySymKey;
|
||||
PK11_CreateDigestContext;
|
||||
PK11_DestroyContext;
|
||||
PK11_DestroyTokenObject;
|
||||
PK11_DigestBegin;
|
||||
PK11_DigestOp;
|
||||
PK11_DigestFinal;
|
||||
PK11_DoesMechanism;
|
||||
PK11_FindCertFromNickname;
|
||||
PK11_FindCertFromDERCert;
|
||||
PK11_FindCertByIssuerAndSN;
|
||||
PK11_FindKeyByAnyCert;
|
||||
PK11_FindKeyByDERCert;
|
||||
PK11_FindSlotByName;
|
||||
PK11_Finalize;
|
||||
PK11_FortezzaHasKEA;
|
||||
PK11_FreeSlot;
|
||||
PK11_FreeSlotList;
|
||||
PK11_FreeSymKey;
|
||||
PK11_GenerateKeyPair;
|
||||
PK11_GenerateRandom;
|
||||
PK11_GenerateNewParam;
|
||||
PK11_GetAllTokens;
|
||||
PK11_GetBlockSize;
|
||||
PK11_GetFirstSafe;
|
||||
PK11_GetInternalKeySlot;
|
||||
PK11_GetInternalSlot;
|
||||
PK11_GetSlotName;
|
||||
PK11_GetTokenName;
|
||||
PK11_HashBuf;
|
||||
PK11_IsFIPS;
|
||||
PK11_IsFriendly;
|
||||
PK11_IsInternal;
|
||||
PK11_IsHW;
|
||||
PK11_IsPresent;
|
||||
PK11_IsReadOnly;
|
||||
PK11_KeyGen;
|
||||
PK11_ListCerts;
|
||||
PK11_NeedLogin;
|
||||
PK11_RandomUpdate;
|
||||
PK11_SetPasswordFunc;
|
||||
PK11_SetSlotPWValues;
|
||||
PORT_Alloc;
|
||||
PORT_Free;
|
||||
PORT_GetError;
|
||||
PORT_SetError;
|
||||
PORT_SetUCS4_UTF8ConversionFunction;
|
||||
PORT_SetUCS2_UTF8ConversionFunction;
|
||||
PORT_SetUCS2_ASCIIConversionFunction;
|
||||
SECITEM_CopyItem;
|
||||
SECITEM_DupItem;
|
||||
SECITEM_FreeItem;
|
||||
SECITEM_ZfreeItem;
|
||||
SECKEY_ConvertToPublicKey;
|
||||
SECKEY_CopyPrivateKey;
|
||||
SECKEY_CreateSubjectPublicKeyInfo;
|
||||
SECKEY_DestroyPrivateKey;
|
||||
SECKEY_DestroySubjectPublicKeyInfo;
|
||||
SECMOD_IsModulePresent;
|
||||
SECOID_FindOIDTagDescription;
|
||||
SECOID_GetAlgorithmTag;
|
||||
SEC_DeletePermCertificate;
|
||||
SEC_DeletePermCRL;
|
||||
SEC_DerSignData;
|
||||
SEC_DestroyCrl;
|
||||
SEC_FindCrlByDERCert;
|
||||
SEC_FindCrlByName;
|
||||
SEC_LookupCrls;
|
||||
SEC_NewCrl;
|
||||
;+#
|
||||
;+# The following symbols are exported only to make libssl3.so work.
|
||||
;+# These are still private!!!
|
||||
;+#
|
||||
__CERT_NewTempCertificate;
|
||||
__PK11_CreateContextByRawKey;
|
||||
__PK11_GetKeyData;
|
||||
__nss_InitLock;
|
||||
CERT_CertChainFromCert;
|
||||
CERT_DestroyCertificateList;
|
||||
CERT_DupCertList;
|
||||
CERT_ExtractPublicKey;
|
||||
CERT_FindCertByName;
|
||||
DER_Lengths;
|
||||
DSAU_DecodeDerSig;
|
||||
DSAU_EncodeDerSig;
|
||||
HASH_GetHashObject;
|
||||
NSSRWLock_Destroy;
|
||||
NSSRWLock_HaveWriteLock;
|
||||
NSSRWLock_LockRead;
|
||||
NSSRWLock_LockWrite;
|
||||
NSSRWLock_New;
|
||||
NSSRWLock_UnlockRead;
|
||||
NSSRWLock_UnlockWrite;
|
||||
NSS_PutEnv;
|
||||
PK11_Derive;
|
||||
PK11_DeriveWithFlags;
|
||||
PK11_DigestKey;
|
||||
PK11_FindBestKEAMatch;
|
||||
PK11_FindFixedKey;
|
||||
PK11_GenerateFortezzaIV;
|
||||
PK11_GetBestKeyLength;
|
||||
PK11_GetBestSlot;
|
||||
PK11_GetBestSlotMultiple;
|
||||
PK11_GetBestWrapMechanism;
|
||||
PK11_GetCurrentWrapIndex;
|
||||
PK11_GetMechanism;
|
||||
PK11_GetModuleID;
|
||||
PK11_GetPrivateModulusLen;
|
||||
PK11_GetSlotFromKey;
|
||||
PK11_GetSlotFromPrivateKey;
|
||||
PK11_GetSlotID;
|
||||
PK11_GetSlotSeries;
|
||||
PK11_GetTokenInfo;
|
||||
PK11_GetWindow;
|
||||
PK11_GetWrapKey;
|
||||
PK11_IVFromParam;
|
||||
PK11_MakeKEAPubKey;
|
||||
PK11_ParamFromIV;
|
||||
PK11_PubDecryptRaw;
|
||||
PK11_PubDerive;
|
||||
PK11_PubEncryptRaw;
|
||||
PK11_PubUnwrapSymKey;
|
||||
PK11_PubWrapSymKey;
|
||||
PK11_ReferenceSymKey;
|
||||
PK11_RestoreContext;
|
||||
PK11_SaveContext;
|
||||
PK11_SetFortezzaHack;
|
||||
PK11_SetWrapKey;
|
||||
PK11_Sign;
|
||||
PK11_SignatureLen;
|
||||
PK11_SymKeyFromHandle;
|
||||
PK11_TokenExists;
|
||||
PK11_UnwrapSymKey;
|
||||
PK11_UnwrapSymKeyWithFlags;
|
||||
PK11_Verify;
|
||||
PK11_VerifyKeyOK;
|
||||
PK11_WrapSymKey;
|
||||
PORT_ArenaAlloc;
|
||||
PORT_ArenaZAlloc;
|
||||
PORT_FreeArena;
|
||||
PORT_NewArena;
|
||||
PORT_Realloc;
|
||||
PORT_ZAlloc;
|
||||
PORT_ZFree;
|
||||
RSA_FormatBlock;
|
||||
SECITEM_CompareItem;
|
||||
SECKEY_CreateRSAPrivateKey;
|
||||
SECKEY_DestroyPublicKey;
|
||||
SECKEY_PublicKeyStrength;
|
||||
SECKEY_UpdateCertPQG;
|
||||
SECMOD_LookupSlot;
|
||||
SGN_Begin;
|
||||
SGN_DestroyContext;
|
||||
SGN_End;
|
||||
SGN_NewContext;
|
||||
SGN_Update;
|
||||
VFY_Begin;
|
||||
VFY_CreateContext;
|
||||
VFY_DestroyContext;
|
||||
VFY_End;
|
||||
VFY_Update;
|
||||
;+#
|
||||
;+# The following symbols are exported only to make libsmime3.so work.
|
||||
;+# These are still private!!!
|
||||
;+#
|
||||
__CERT_ClosePermCertDB;
|
||||
__CERT_DecodeDERCertificate;
|
||||
__CERT_TraversePermCertsForNickname;
|
||||
__CERT_TraversePermCertsForSubject;
|
||||
__PBE_CreateContext;
|
||||
__PBE_DestroyContext;
|
||||
__PBE_GenerateBits;
|
||||
ATOB_ConvertAsciiToItem;
|
||||
CERT_AddCertToListTail;
|
||||
CERT_CertListFromCert;
|
||||
CERT_DestroyCertArray;
|
||||
CERT_FindCertByDERCert;
|
||||
CERT_FindCertByIssuerAndSN;
|
||||
CERT_FindSMimeProfile;
|
||||
CERT_ImportCerts;
|
||||
CERT_NewCertList;
|
||||
CERT_OpenCertDBFilename;
|
||||
CERT_SaveSMimeProfile;
|
||||
CERT_VerifyCert;
|
||||
DER_GetInteger;
|
||||
DER_TimeToUTCTime;
|
||||
DER_UTCTimeToTime;
|
||||
PK11_AlgtagToMechanism;
|
||||
PK11_BlockData;
|
||||
PK11_CreatePBEAlgorithmID;
|
||||
PK11_DestroyObject;
|
||||
PK11_ExportEncryptedPrivateKeyInfo;
|
||||
PK11_ExportPrivateKeyInfo;
|
||||
PK11_FindCertAndKeyByRecipientList;
|
||||
PK11_FindCertAndKeyByRecipientListNew;
|
||||
PK11_FindCertInSlot;
|
||||
PK11_FindPrivateKeyFromCert;
|
||||
PK11_FortezzaMapSig;
|
||||
PK11_GetKeyLength;
|
||||
PK11_GetKeyStrength;
|
||||
PK11_ImportCertForKeyToSlot;
|
||||
PK11_ImportEncryptedPrivateKeyInfo;
|
||||
PK11_ImportPrivateKeyInfo;
|
||||
PK11_MapPBEMechanismToCryptoMechanism;
|
||||
PK11_PBEKeyGen;
|
||||
PK11_ParamFromAlgid;
|
||||
PK11_ParamToAlgid;
|
||||
PK11_TraverseCertsForNicknameInSlot;
|
||||
PK11_TraverseCertsForSubjectInSlot;
|
||||
PORT_ArenaGrow;
|
||||
PORT_ArenaMark;
|
||||
PORT_ArenaRelease;
|
||||
PORT_ArenaStrdup;
|
||||
PORT_ArenaUnmark;
|
||||
PORT_UCS2_ASCIIConversion;
|
||||
PORT_UCS2_UTF8Conversion;
|
||||
SECITEM_AllocItem;
|
||||
SECKEY_CopyEncryptedPrivateKeyInfo;
|
||||
SECKEY_CopyPrivateKeyInfo;
|
||||
SECKEY_DestroyEncryptedPrivateKeyInfo;
|
||||
SECKEY_DestroyPrivateKeyInfo;
|
||||
SECOID_CompareAlgorithmID;
|
||||
SECOID_CopyAlgorithmID;
|
||||
SECOID_DestroyAlgorithmID;
|
||||
SECOID_FindOID;
|
||||
SECOID_FindOIDByTag;
|
||||
SECOID_FindOIDTag;
|
||||
SECOID_SetAlgorithmID;
|
||||
SEC_ASN1DecodeInteger;
|
||||
SEC_ASN1DecodeItem;
|
||||
SEC_ASN1DecoderClearFilterProc;
|
||||
SEC_ASN1DecoderClearNotifyProc;
|
||||
SEC_ASN1DecoderFinish;
|
||||
SEC_ASN1DecoderSetFilterProc;
|
||||
SEC_ASN1DecoderSetNotifyProc;
|
||||
SEC_ASN1DecoderStart;
|
||||
SEC_ASN1DecoderUpdate;
|
||||
SEC_ASN1Encode;
|
||||
SEC_ASN1EncodeInteger;
|
||||
SEC_ASN1EncodeItem;
|
||||
SEC_ASN1EncoderClearNotifyProc;
|
||||
SEC_ASN1EncoderClearStreaming;
|
||||
SEC_ASN1EncoderClearTakeFromBuf;
|
||||
SEC_ASN1EncoderFinish;
|
||||
SEC_ASN1EncoderSetNotifyProc;
|
||||
SEC_ASN1EncoderSetStreaming;
|
||||
SEC_ASN1EncoderSetTakeFromBuf;
|
||||
SEC_ASN1EncoderStart;
|
||||
SEC_ASN1EncoderUpdate;
|
||||
SEC_ASN1LengthLength;
|
||||
SEC_PKCS5GetCryptoAlgorithm;
|
||||
SEC_PKCS5GetKeyLength;
|
||||
SEC_PKCS5GetPBEAlgorithm;
|
||||
SEC_PKCS5IsAlgorithmPBEAlg;
|
||||
SEC_SignData;
|
||||
SGN_CompareDigestInfo;
|
||||
SGN_CopyDigestInfo;
|
||||
SGN_CreateDigestInfo;
|
||||
SGN_DestroyDigestInfo;
|
||||
SGN_Digest;
|
||||
VFY_VerifyData;
|
||||
VFY_VerifyDigest;
|
||||
;+#
|
||||
;+# Data objects
|
||||
;+#
|
||||
;+# Don't export these DATA symbols on Windows because they don't work right.
|
||||
;+# Use the SEC_ASN1_GET / SEC_ASN1_SUB / SEC_ASN1_XTRN macros to access them.
|
||||
;;CERT_CrlTemplate DATA ;
|
||||
;;CERT_SignedDataTemplate DATA ;
|
||||
;;CERT_CertificateTemplate DATA ;
|
||||
;;CERT_CertificateRequestTemplate DATA ;
|
||||
;;CERT_IssuerAndSNTemplate DATA ;
|
||||
;;CERT_SetOfSignedCrlTemplate DATA ;
|
||||
;;SECKEY_DSAPublicKeyTemplate DATA ;
|
||||
;;SECKEY_EncryptedPrivateKeyInfoTemplate DATA ;
|
||||
;;SECKEY_PointerToEncryptedPrivateKeyInfoTemplate DATA ;
|
||||
;;SECKEY_PointerToPrivateKeyInfoTemplate DATA ;
|
||||
;;SECKEY_PrivateKeyInfoTemplate DATA ;
|
||||
;;SECKEY_RSAPublicKeyTemplate DATA ;
|
||||
;;SECOID_AlgorithmIDTemplate DATA ;
|
||||
;;SEC_AnyTemplate DATA ;
|
||||
;;SEC_BMPStringTemplate DATA ;
|
||||
;;SEC_BitStringTemplate DATA ;
|
||||
;;SEC_GeneralizedTimeTemplate DATA ;
|
||||
;;SEC_IA5StringTemplate DATA ;
|
||||
;;SEC_IntegerTemplate DATA ;
|
||||
;;SEC_ObjectIDTemplate DATA ;
|
||||
;;SEC_OctetStringTemplate DATA ;
|
||||
;;SEC_PointerToAnyTemplate DATA ;
|
||||
;;SEC_PointerToOctetStringTemplate DATA ;
|
||||
;;SEC_SetOfAnyTemplate DATA ;
|
||||
;;SEC_UTCTimeTemplate DATA ;
|
||||
;;sgn_DigestInfoTemplate DATA ;
|
||||
NSS_Get_CERT_CrlTemplate;
|
||||
NSS_Get_CERT_SignedDataTemplate;
|
||||
NSS_Get_CERT_CertificateTemplate;
|
||||
NSS_Get_CERT_CertificateRequestTemplate;
|
||||
NSS_Get_CERT_IssuerAndSNTemplate;
|
||||
NSS_Get_CERT_SetOfSignedCrlTemplate;
|
||||
NSS_Get_SECKEY_DSAPublicKeyTemplate;
|
||||
NSS_Get_SECKEY_EncryptedPrivateKeyInfoTemplate;
|
||||
NSS_Get_SECKEY_PointerToEncryptedPrivateKeyInfoTemplate;
|
||||
NSS_Get_SECKEY_PointerToPrivateKeyInfoTemplate;
|
||||
NSS_Get_SECKEY_PrivateKeyInfoTemplate;
|
||||
NSS_Get_SECKEY_RSAPublicKeyTemplate;
|
||||
NSS_Get_SECOID_AlgorithmIDTemplate;
|
||||
NSS_Get_SEC_AnyTemplate;
|
||||
NSS_Get_SEC_BMPStringTemplate;
|
||||
NSS_Get_SEC_BitStringTemplate;
|
||||
NSS_Get_SEC_GeneralizedTimeTemplate;
|
||||
NSS_Get_SEC_IA5StringTemplate;
|
||||
NSS_Get_SEC_IntegerTemplate;
|
||||
NSS_Get_SEC_ObjectIDTemplate;
|
||||
NSS_Get_SEC_OctetStringTemplate;
|
||||
NSS_Get_SEC_PointerToAnyTemplate;
|
||||
NSS_Get_SEC_PointerToOctetStringTemplate;
|
||||
NSS_Get_SEC_SetOfAnyTemplate;
|
||||
NSS_Get_SEC_UTCTimeTemplate;
|
||||
NSS_Get_sgn_DigestInfoTemplate;
|
||||
;+# commands
|
||||
CERT_DecodeBasicConstraintValue;
|
||||
CERT_DecodeOidSequence;
|
||||
CERT_DecodeUserNotice;
|
||||
CERT_DecodeCertificatePoliciesExtension;
|
||||
CERT_DestroyCertificatePoliciesExtension;
|
||||
CERT_FindCertByNicknameOrEmailAddr;
|
||||
CERT_FindCertByNickname;
|
||||
CERT_GenTime2FormattedAscii;
|
||||
CERT_Hexify;
|
||||
CERT_CompareName;
|
||||
PK11SDR_Encrypt;
|
||||
PK11SDR_Decrypt;
|
||||
NSSBase64Decoder_Create;
|
||||
NSSBase64Decoder_Destroy;
|
||||
NSSBase64Decoder_Update;
|
||||
NSSBase64Encoder_Create;
|
||||
NSSBase64Encoder_Destroy;
|
||||
NSSBase64Encoder_Update;
|
||||
;+#PK11_DoPassword;
|
||||
;+#PK11_FindKeyByKeyID;
|
||||
PK11_InitPin;
|
||||
PK11_NeedUserInit;
|
||||
;+ local:
|
||||
;+ *;
|
||||
;+};
|
||||
;+NSS_3.2.1 { # NSS 3.2.1 release
|
||||
;+ global:
|
||||
CERT_AddRDN;
|
||||
CERT_CreateRDN;
|
||||
CERT_CreateAVA;
|
||||
CERT_CreateName;
|
||||
;+ local:
|
||||
;+ *;
|
||||
;+};
|
||||
;+NSS_3.3 { # NSS 3.3. release
|
||||
;+ global:
|
||||
CERT_CheckCertUsage;
|
||||
CERT_FindCertIssuer;
|
||||
PK11_GetModule;
|
||||
SECKEY_CreateDHPrivateKey;
|
||||
SECKEY_GetPublicKeyType;
|
||||
SECMOD_AddNewModule;
|
||||
;+#
|
||||
;+# The following symbols are exported only to make JSS work.
|
||||
;+# These are still private!!!
|
||||
;+#
|
||||
CERT_DisableOCSPChecking;
|
||||
CERT_DisableOCSPDefaultResponder;
|
||||
CERT_EnableOCSPDefaultResponder;
|
||||
CERT_GetCertTimes;
|
||||
CERT_ImportCAChainTrusted;
|
||||
CERT_ImportCRL;
|
||||
CERT_IsCACert;
|
||||
CERT_IsCADERCert;
|
||||
CERT_SetOCSPDefaultResponder;
|
||||
PBE_CreateContext;
|
||||
PBE_DestroyContext;
|
||||
PBE_GenerateBits;
|
||||
PK11_CheckSSOPassword;
|
||||
PK11_CopySymKeyForSigning;
|
||||
PK11_DeleteTokenCertAndKey;
|
||||
PK11_DEREncodePublicKey;
|
||||
PK11_ExtractKeyValue;
|
||||
PK11_FindCertsFromNickname;
|
||||
PK11_FindKeyByKeyID;
|
||||
PK11_GetIVLength;
|
||||
PK11_GetKeyData;
|
||||
PK11_GetKeyType;
|
||||
PK11_GetLowLevelKeyIDForCert;
|
||||
PK11_GetLowLevelKeyIDForPrivateKey;
|
||||
PK11_GetSlotPWValues;
|
||||
PK11_ImportCertForKey;
|
||||
PK11_ImportDERCertForKey;
|
||||
PK11_ImportDERPrivateKeyInfo;
|
||||
PK11_ImportSymKey;
|
||||
PK11_IsLoggedIn;
|
||||
PK11_KeyForDERCertExists;
|
||||
PK11_KeyForCertExists;
|
||||
PK11_ListPrivateKeysInSlot;
|
||||
PK11_ListCertsInSlot;
|
||||
PK11_Logout;
|
||||
PK11_NeedPWInit;
|
||||
PK11_MakeIDFromPubKey;
|
||||
PK11_PQG_DestroyParams;
|
||||
PK11_PQG_DestroyVerify;
|
||||
PK11_PQG_GetBaseFromParams;
|
||||
PK11_PQG_GetCounterFromVerify;
|
||||
PK11_PQG_GetHFromVerify;
|
||||
PK11_PQG_GetPrimeFromParams;
|
||||
PK11_PQG_GetSeedFromVerify;
|
||||
PK11_PQG_GetSubPrimeFromParams;
|
||||
PK11_PQG_NewParams;
|
||||
PK11_PQG_NewVerify;
|
||||
PK11_PQG_ParamGen;
|
||||
PK11_PQG_ParamGenSeedLen;
|
||||
PK11_PQG_VerifyParams;
|
||||
PK11_ReferenceSlot;
|
||||
PK11_SeedRandom;
|
||||
PK11_UnwrapPrivKey;
|
||||
PK11_VerifyRecover;
|
||||
PK11_WrapPrivKey;
|
||||
SEC_CertNicknameConflict;
|
||||
SEC_PKCS5GetIV;
|
||||
SECMOD_DeleteInternalModule;
|
||||
SECMOD_DestroyModule;
|
||||
SECMOD_GetDefaultModuleList;
|
||||
SECMOD_GetDefaultModuleListLock;
|
||||
SECMOD_GetInternalModule;
|
||||
SECMOD_GetReadLock;
|
||||
SECMOD_ReferenceModule;
|
||||
SECMOD_ReleaseReadLock;
|
||||
SECKEY_AddPrivateKeyToListTail;
|
||||
SECKEY_EncodeDERSubjectPublicKeyInfo;
|
||||
SECKEY_ExtractPublicKey;
|
||||
SECKEY_DestroyPrivateKeyList;
|
||||
SECKEY_GetPrivateKeyType;
|
||||
SECKEY_HashPassword;
|
||||
SECKEY_ImportDERPublicKey;
|
||||
SECKEY_NewPrivateKeyList;
|
||||
SECKEY_RemovePrivateKeyListNode;
|
||||
VFY_EndWithSignature;
|
||||
;+ local:
|
||||
;+ *;
|
||||
;+};
|
||||
;+NSS_3.3.1 { # NSS 3.3.1 release
|
||||
;+ global:
|
||||
;+#
|
||||
;+# The following symbols are exported only to make libsmime3.so work.
|
||||
;+# These are still private!!!
|
||||
;+#
|
||||
PK11_CreatePBEParams;
|
||||
PK11_DestroyPBEParams;
|
||||
;+ local:
|
||||
;+ *;
|
||||
;+};
|
||||
;+NSS_3.4 { # NSS 3.4 release
|
||||
;+ global:
|
||||
SECMOD_AddNewModuleEx;
|
||||
SECMOD_DeleteModule;
|
||||
SECMOD_FreeModuleSpecList;
|
||||
SECMOD_GetModuleSpecList;
|
||||
SECMOD_LoadModule;
|
||||
SECMOD_LoadUserModule;
|
||||
SECMOD_UnloadUserModule;
|
||||
SECMOD_UpdateModule;
|
||||
;+# for PKCS #12
|
||||
PK11_RawPBEKeyGen;
|
||||
;+# for PSM
|
||||
__CERT_AddTempCertToPerm;
|
||||
CERT_AddOKDomainName;
|
||||
CERT_CopyName;
|
||||
CERT_CreateSubjectCertList;
|
||||
CERT_DecodeAVAValue;
|
||||
;+#CERT_DecodeCertFromPackage;
|
||||
CERT_DecodeGeneralName;
|
||||
CERT_DecodeTrustString;
|
||||
CERT_DerNameToAscii;
|
||||
CERT_EncodeGeneralName;
|
||||
CERT_FilterCertListByCANames;
|
||||
CERT_FilterCertListByUsage;
|
||||
CERT_FindCertExtension;
|
||||
CERT_FindKeyUsageExtension;
|
||||
CERT_FindUserCertByUsage;
|
||||
CERT_FindUserCertsByUsage;
|
||||
CERT_GetCertChainFromCert;
|
||||
CERT_GetOCSPAuthorityInfoAccessLocation;
|
||||
CERT_KeyFromDERCrl;
|
||||
CERT_MakeCANickname;
|
||||
CERT_NicknameStringsFromCertList;
|
||||
CERT_VerifySignedData;
|
||||
DER_Encode;
|
||||
HASH_Begin;
|
||||
HASH_Create;
|
||||
HASH_Destroy;
|
||||
HASH_End;
|
||||
HASH_ResultLen;
|
||||
HASH_Update;
|
||||
NSSBase64_DecodeBuffer; # from Stan
|
||||
NSSBase64_EncodeItem; # from Stan
|
||||
PK11_GetKeyGen;
|
||||
PK11_GetMinimumPwdLength;
|
||||
PK11_GetNextSafe;
|
||||
PK11_GetPadMechanism;
|
||||
PK11_GetSlotInfo;
|
||||
PK11_HasRootCerts;
|
||||
PK11_IsDisabled;
|
||||
PK11_LoadPrivKey;
|
||||
PK11_LogoutAll;
|
||||
PK11_MechanismToAlgtag;
|
||||
PK11_ResetToken;
|
||||
PK11_TraverseSlotCerts;
|
||||
SEC_ASN1Decode;
|
||||
SECKEY_CopySubjectPublicKeyInfo;
|
||||
SECMOD_CreateModule;
|
||||
SECMOD_FindModule;
|
||||
SECMOD_FindSlot;
|
||||
SECMOD_PubCipherFlagstoInternal;
|
||||
SECMOD_PubMechFlagstoInternal;
|
||||
;;CERT_NameTemplate DATA ;
|
||||
;;CERT_SubjectPublicKeyInfoTemplate DATA ;
|
||||
;;SEC_BooleanTemplate DATA ;
|
||||
;;SEC_NullTemplate DATA ;
|
||||
;;SEC_SignedCertificateTemplate DATA ;
|
||||
;;SEC_UTF8StringTemplate DATA ;
|
||||
NSS_Get_CERT_NameTemplate;
|
||||
NSS_Get_CERT_SubjectPublicKeyInfoTemplate;
|
||||
NSS_Get_SEC_BooleanTemplate;
|
||||
NSS_Get_SEC_NullTemplate;
|
||||
NSS_Get_SEC_SignedCertificateTemplate;
|
||||
NSS_Get_SEC_UTF8StringTemplate;
|
||||
;+# for JSS
|
||||
PK11_DeleteTokenPrivateKey;
|
||||
PK11_DeleteTokenPublicKey;
|
||||
PK11_DeleteTokenSymKey;
|
||||
PK11_GetNextSymKey;
|
||||
PK11_GetPQGParamsFromPrivateKey;
|
||||
PK11_GetPrivateKeyNickname;
|
||||
PK11_GetPublicKeyNickname;
|
||||
PK11_GetSymKeyNickname;
|
||||
PK11_ImportDERPrivateKeyInfoAndReturnKey;
|
||||
PK11_ImportPrivateKeyInfoAndReturnKey;
|
||||
PK11_ImportPublicKey;
|
||||
PK11_ImportSymKeyWithFlags;
|
||||
PK11_ListFixedKeysInSlot;
|
||||
PK11_ListPrivKeysInSlot;
|
||||
PK11_ListPublicKeysInSlot;
|
||||
PK11_ProtectedAuthenticationPath;
|
||||
PK11_SetPrivateKeyNickname;
|
||||
PK11_SetPublicKeyNickname;
|
||||
PK11_SetSymKeyNickname;
|
||||
SECKEY_DecodeDERSubjectPublicKeyInfo;
|
||||
SECKEY_DestroyPublicKeyList;
|
||||
;+# for debugging
|
||||
nss_DumpCertificateCacheInfo;
|
||||
;+ local:
|
||||
;+ *;
|
||||
;+};
|
||||
;+NSS_3.5 { # cert creation APIs used by certutil
|
||||
;+ global:
|
||||
CERT_AddExtension;
|
||||
CERT_CopyRDN;
|
||||
CERT_CreateCertificate;
|
||||
CERT_CreateValidity;
|
||||
CERT_DestroyValidity;
|
||||
CERT_EncodeAndAddBitStrExtension;
|
||||
CERT_EncodeAuthKeyID;
|
||||
CERT_EncodeBasicConstraintValue;
|
||||
CERT_EncodeCRLDistributionPoints;
|
||||
CERT_FinishExtensions;
|
||||
CERT_StartCertExtensions;
|
||||
DER_AsciiToTime;
|
||||
PK11_ImportCert;
|
||||
PORT_Strdup;
|
||||
SECMOD_CanDeleteInternalModule;
|
||||
;+ local:
|
||||
;+ *;
|
||||
;+};
|
||||
;+NSS_3.6 { # NSS 3.6 release
|
||||
;+ global:
|
||||
CERT_AddOCSPAcceptableResponses;
|
||||
CERT_CompleteCRLDecodeEntries;
|
||||
CERT_CreateOCSPCertID;
|
||||
CERT_CreateOCSPRequest;
|
||||
CERT_DecodeDERCrlWithFlags;
|
||||
CERT_DecodeOCSPResponse;
|
||||
CERT_DestroyOCSPCertID;
|
||||
CERT_DestroyOCSPRequest;
|
||||
CERT_EncodeOCSPRequest;
|
||||
CERT_FilterCertListForUserCerts;
|
||||
CERT_GetOCSPResponseStatus;
|
||||
CERT_GetOCSPStatusForCertID;
|
||||
CERT_IsUserCert;
|
||||
CERT_RemoveCertListNode;
|
||||
CERT_VerifyCACertForUsage;
|
||||
CERT_VerifyCertificate;
|
||||
CERT_VerifyCertificateNow;
|
||||
CERT_VerifyOCSPResponseSignature;
|
||||
PK11_ConvertSessionPrivKeyToTokenPrivKey;
|
||||
PK11_ConvertSessionSymKeyToTokenSymKey;
|
||||
PK11_GetModInfo;
|
||||
PK11_GetPBEIV;
|
||||
PK11_ImportCRL;
|
||||
PK11_ImportDERCert;
|
||||
PK11_PubUnwrapSymKeyWithFlags;
|
||||
PK11_SaveContextAlloc;
|
||||
PK11_TokenKeyGen;
|
||||
SEC_QuickDERDecodeItem;
|
||||
SECKEY_CopyPublicKey;
|
||||
;+ local:
|
||||
;+ *;
|
||||
;+};
|
||||
;+NSS_3.7 { # NSS 3.7 release
|
||||
;+ global:
|
||||
CERT_CRLCacheRefreshIssuer;
|
||||
CERT_DestroyOCSPResponse;
|
||||
CERT_EncodeAltNameExtension;
|
||||
CERT_FindCertBySubjectKeyID;
|
||||
CERT_FindSubjectKeyIDExtension;
|
||||
CERT_GetFirstEmailAddress;
|
||||
CERT_GetNextEmailAddress;
|
||||
CERT_VerifySignedDataWithPublicKey;
|
||||
CERT_VerifySignedDataWithPublicKeyInfo;
|
||||
PK11_WaitForTokenEvent;
|
||||
;+ local:
|
||||
;+ *;
|
||||
;+};
|
||||
;+NSS_3.7.1 { # NSS 3.7.1 release
|
||||
;+ global:
|
||||
PK11_TokenRefresh;
|
||||
;+ local:
|
||||
;+ *;
|
||||
;+};
|
||||
;+NSS_3.8 { # NSS 3.8 release
|
||||
;+ global:
|
||||
CERT_IsRootDERCert;
|
||||
HASH_GetHashObjectByOidTag;
|
||||
HASH_GetHashTypeByOidTag;
|
||||
PK11_GetDefaultArray;
|
||||
PK11_GetDefaultFlags;
|
||||
PK11_GetDisabledReason;
|
||||
PK11_UpdateSlotAttribute;
|
||||
PK11_UserEnableSlot;
|
||||
PK11_UserDisableSlot;
|
||||
SECITEM_ItemsAreEqual;
|
||||
SECKEY_CreateECPrivateKey;
|
||||
SECKEY_PublicKeyStrengthInBits;
|
||||
;+ local:
|
||||
;+ *;
|
||||
;+};
|
||||
;+NSS_3.9 { # NSS 3.9 release
|
||||
;+ global:
|
||||
CERT_DestroyOidSequence;
|
||||
CERT_GetOidString;
|
||||
;;CERT_TimeChoiceTemplate DATA ;
|
||||
DER_DecodeTimeChoice;
|
||||
DER_EncodeTimeChoice;
|
||||
DSAU_DecodeDerSigToLen;
|
||||
DSAU_EncodeDerSigWithLen;
|
||||
NSS_Get_CERT_TimeChoiceTemplate;
|
||||
PK11_DeriveWithFlagsPerm;
|
||||
PK11_ExportEncryptedPrivKeyInfo;
|
||||
PK11_FindSlotsByNames;
|
||||
PK11_GetSymKeyType;
|
||||
PK11_MoveSymKey;
|
||||
PK11_PubDeriveWithKDF;
|
||||
PK11_PubUnwrapSymKeyWithFlagsPerm;
|
||||
PK11_UnwrapSymKeyWithFlagsPerm;
|
||||
SECITEM_ArenaDupItem;
|
||||
SECMOD_GetDBModuleList;
|
||||
SECMOD_GetDeadModuleList;
|
||||
SEC_ASN1DecoderAbort;
|
||||
SEC_ASN1EncoderAbort;
|
||||
SEC_DupCrl;
|
||||
;+ local:
|
||||
;+ *;
|
||||
;+};
|
||||
;+NSS_3.9.2 { # NSS 3.9.2 release
|
||||
;+ global:
|
||||
NSS_IsInitialized;
|
||||
PK11_DestroyGenericObject;
|
||||
PK11_DestroyGenericObjects;
|
||||
PK11_FindGenericObjects;
|
||||
PK11_GetNextGenericObject;
|
||||
PK11_GetPrevGenericObject;
|
||||
PK11_LinkGenericObject;
|
||||
PK11_ReadRawAttribute;
|
||||
PK11_UnlinkGenericObject;
|
||||
;+ local:
|
||||
;+ *;
|
||||
;+};
|
||||
;+NSS_3.9.3 { # NSS 3.9.3 release
|
||||
;+ global:
|
||||
PK11_GetCertFromPrivateKey;
|
||||
PK11_PrivDecryptPKCS1;
|
||||
PK11_PubEncryptPKCS1;
|
||||
SECMOD_CancelWait;
|
||||
SECMOD_HasRemovableSlots;
|
||||
SECMOD_UpdateSlotList;
|
||||
SECMOD_WaitForAnyTokenEvent;
|
||||
;+ local:
|
||||
;+ *;
|
||||
;+};
|
||||
;+NSS_3.10 { # NSS 3.10 release
|
||||
;+ global:
|
||||
CERT_CacheCRL;
|
||||
CERT_DecodeAltNameExtension;
|
||||
CERT_DecodeAuthInfoAccessExtension;
|
||||
CERT_DecodeAuthKeyID;
|
||||
CERT_DecodeCRLDistributionPoints;
|
||||
CERT_DecodeNameConstraintsExtension;
|
||||
CERT_DecodePrivKeyUsagePeriodExtension;
|
||||
CERT_DestroyUserNotice;
|
||||
CERT_FinishCertificateRequestAttributes;
|
||||
CERT_GetCertificateNames;
|
||||
CERT_GetCertificateRequestExtensions;
|
||||
CERT_GetNextGeneralName;
|
||||
CERT_GetNextNameConstraint;
|
||||
CERT_GetPrevGeneralName;
|
||||
CERT_GetPrevNameConstraint;
|
||||
CERT_MergeExtensions;
|
||||
CERT_StartCertificateRequestAttributes;
|
||||
CERT_StartCRLEntryExtensions;
|
||||
CERT_StartCRLExtensions;
|
||||
CERT_UncacheCRL;
|
||||
HASH_Clone;
|
||||
HASH_HashBuf;
|
||||
HASH_ResultLenByOidTag;
|
||||
HASH_ResultLenContext;
|
||||
SEC_GetSignatureAlgorithmOidTag;
|
||||
SECKEY_CacheStaticFlags;
|
||||
SECOID_AddEntry;
|
||||
;+#
|
||||
;+# Data objects
|
||||
;+#
|
||||
;+# Don't export these DATA symbols on Windows because they don't work right.
|
||||
;+# Use the SEC_ASN1_GET / SEC_ASN1_SUB / SEC_ASN1_XTRN macros to access them.
|
||||
;;CERT_SequenceOfCertExtensionTemplate DATA ;
|
||||
;;CERT_SignedCrlTemplate DATA ;
|
||||
NSS_Get_CERT_SequenceOfCertExtensionTemplate;
|
||||
NSS_Get_CERT_SignedCrlTemplate;
|
||||
;+ local:
|
||||
;+ *;
|
||||
;+};
|
||||
;+NSS_3.10.2 { # NSS 3.10.2 release
|
||||
;+ global:
|
||||
PK11_TokenKeyGenWithFlags;
|
||||
PK11_GenerateKeyPairWithFlags;
|
||||
;+ local:
|
||||
;+ *;
|
||||
;+};
|
||||
;+NSS_3.11 { # NSS 3.11 release
|
||||
;+ global:
|
||||
CERT_CompareValidityTimes;
|
||||
PK11_CopyTokenPrivKeyToSessionPrivKey;
|
||||
PK11_FreeSlotListElement;
|
||||
PK11_GenerateRandomOnSlot;
|
||||
PK11_GetSymKeyUserData;
|
||||
PK11_MapSignKeyType;
|
||||
PK11_SetSymKeyUserData;
|
||||
SECMOD_CloseUserDB;
|
||||
SECMOD_HasRootCerts;
|
||||
SECMOD_OpenUserDB;
|
||||
;+ local:
|
||||
;+ *;
|
||||
;+};
|
||||
;+NSS_3.11.1 {
|
||||
;+ global:
|
||||
NSS_RegisterShutdown;
|
||||
NSS_UnregisterShutdown;
|
||||
SEC_ASN1EncodeUnsignedInteger;
|
||||
SEC_RegisterDefaultHttpClient;
|
||||
;+ local:
|
||||
;+ *;
|
||||
;+};
|
||||
;+NSS_3.11.2 {
|
||||
;+ global:
|
||||
SECKEY_SignatureLen;
|
||||
;+ local:
|
||||
;+ *;
|
||||
;+};
|
||||
;+NSS_3.11.7 {
|
||||
;+ global:
|
||||
CERT_SetOCSPFailureMode;
|
||||
CERT_OCSPCacheSettings;
|
||||
CERT_ClearOCSPCache;
|
||||
DER_GeneralizedDayToAscii;
|
||||
DER_TimeChoiceDayToAscii;
|
||||
DER_TimeToGeneralizedTime;
|
||||
DER_TimeToGeneralizedTimeArena;
|
||||
;+ local:
|
||||
;+ *;
|
||||
;+};
|
||||
;+NSS_3.11.9 {
|
||||
;+ global:
|
||||
PK11_UnconfigurePKCS11;
|
||||
;+ local:
|
||||
;+ *;
|
||||
;+};
|
||||
;+NSS_3.12 { # NSS 3.12 release
|
||||
;+ global:
|
||||
CERT_CheckNameSpace;
|
||||
CERT_EncodeCertPoliciesExtension;
|
||||
CERT_EncodeInfoAccessExtension;
|
||||
CERT_EncodeInhibitAnyExtension;
|
||||
CERT_EncodeNoticeReference;
|
||||
CERT_EncodePolicyConstraintsExtension;
|
||||
CERT_EncodePolicyMappingExtension;
|
||||
CERT_EncodeUserNotice;
|
||||
CERT_FindCRLEntryReasonExten;
|
||||
CERT_FindCRLNumberExten;
|
||||
CERT_FindNameConstraintsExten;
|
||||
CERT_GetValidDNSPatternsFromCert;
|
||||
CERT_SetOCSPTimeout;
|
||||
CERT_PKIXVerifyCert;
|
||||
PK11_CreateGenericObject;
|
||||
PK11_CreatePBEV2AlgorithmID;
|
||||
PK11_GenerateKeyPairWithOpFlags;
|
||||
PK11_GetAllSlotsForCert;
|
||||
PK11_GetPBECryptoMechanism;
|
||||
PK11_WriteRawAttribute;
|
||||
SECKEY_ECParamsToBasePointOrderLen;
|
||||
SECKEY_ECParamsToKeySize;
|
||||
SECMOD_DeleteModuleEx;
|
||||
SEC_GetRegisteredHttpClient;
|
||||
SEC_PKCS5IsAlgorithmPBEAlgTag;
|
||||
VFY_CreateContextDirect;
|
||||
VFY_CreateContextWithAlgorithmID;
|
||||
VFY_VerifyDataDirect;
|
||||
VFY_VerifyDataWithAlgorithmID;
|
||||
VFY_VerifyDigestDirect;
|
||||
VFY_VerifyDigestWithAlgorithmID;
|
||||
;+ local:
|
||||
;+ *;
|
||||
;+};
|
||||
@@ -1,250 +0,0 @@
|
||||
/*
|
||||
* NSS utility functions
|
||||
*
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1994-2000
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
/* $Id: nss.h,v 1.51 2007-05-04 05:15:43 nelson%bolyard.com Exp $ */
|
||||
|
||||
#ifndef __nss_h_
|
||||
#define __nss_h_
|
||||
|
||||
#include "seccomon.h"
|
||||
|
||||
SEC_BEGIN_PROTOS
|
||||
|
||||
/* The private macro _NSS_ECC_STRING is for NSS internal use only. */
|
||||
#ifdef NSS_ENABLE_ECC
|
||||
#ifdef NSS_ECC_MORE_THAN_SUITE_B
|
||||
#define _NSS_ECC_STRING " Extended ECC"
|
||||
#else
|
||||
#define _NSS_ECC_STRING " Basic ECC"
|
||||
#endif
|
||||
#else
|
||||
#define _NSS_ECC_STRING ""
|
||||
#endif
|
||||
|
||||
/* The private macro _NSS_CUSTOMIZED is for NSS internal use only. */
|
||||
#if defined(NSS_ALLOW_UNSUPPORTED_CRITICAL)
|
||||
#define _NSS_CUSTOMIZED " (Customized build)"
|
||||
#else
|
||||
#define _NSS_CUSTOMIZED
|
||||
#endif
|
||||
|
||||
/*
|
||||
* NSS's major version, minor version, patch level, and whether
|
||||
* this is a beta release.
|
||||
*
|
||||
* The format of the version string should be
|
||||
* "<major version>.<minor version>[.<patch level>][ <ECC>][ <Beta>]"
|
||||
*/
|
||||
#define NSS_VERSION "3.12" _NSS_ECC_STRING " Beta" _NSS_CUSTOMIZED
|
||||
#define NSS_VMAJOR 3
|
||||
#define NSS_VMINOR 12
|
||||
#define NSS_VPATCH 0
|
||||
#define NSS_BETA PR_TRUE
|
||||
|
||||
/*
|
||||
* Return a boolean that indicates whether the underlying library
|
||||
* will perform as the caller expects.
|
||||
*
|
||||
* The only argument is a string, which should be the verson
|
||||
* identifier of the NSS library. That string will be compared
|
||||
* against a string that represents the actual build version of
|
||||
* the NSS library. It also invokes the version checking functions
|
||||
* of the dependent libraries such as NSPR.
|
||||
*/
|
||||
extern PRBool NSS_VersionCheck(const char *importedVersion);
|
||||
|
||||
/*
|
||||
* Open the Cert, Key, and Security Module databases, read only.
|
||||
* Initialize the Random Number Generator.
|
||||
* Does not initialize the cipher policies or enables.
|
||||
* Default policy settings disallow all ciphers.
|
||||
*/
|
||||
extern SECStatus NSS_Init(const char *configdir);
|
||||
|
||||
/*
|
||||
* Returns whether NSS has already been initialized or not.
|
||||
*/
|
||||
extern PRBool NSS_IsInitialized(void);
|
||||
|
||||
/*
|
||||
* Open the Cert, Key, and Security Module databases, read/write.
|
||||
* Initialize the Random Number Generator.
|
||||
* Does not initialize the cipher policies or enables.
|
||||
* Default policy settings disallow all ciphers.
|
||||
*/
|
||||
extern SECStatus NSS_InitReadWrite(const char *configdir);
|
||||
|
||||
/*
|
||||
* Open the Cert, Key, and Security Module databases, read/write.
|
||||
* Initialize the Random Number Generator.
|
||||
* Does not initialize the cipher policies or enables.
|
||||
* Default policy settings disallow all ciphers.
|
||||
*
|
||||
* This allows using application defined prefixes for the cert and key db's
|
||||
* and an alternate name for the secmod database. NOTE: In future releases,
|
||||
* the database prefixes my not necessarily map to database names.
|
||||
*
|
||||
* configdir - base directory where all the cert, key, and module datbases live.
|
||||
* certPrefix - prefix added to the beginning of the cert database example: "
|
||||
* "https-server1-"
|
||||
* keyPrefix - prefix added to the beginning of the key database example: "
|
||||
* "https-server1-"
|
||||
* secmodName - name of the security module database (usually "secmod.db").
|
||||
* flags - change the open options of NSS_Initialize as follows:
|
||||
* NSS_INIT_READONLY - Open the databases read only.
|
||||
* NSS_INIT_NOCERTDB - Don't open the cert DB and key DB's, just
|
||||
* initialize the volatile certdb.
|
||||
* NSS_INIT_NOMODDB - Don't open the security module DB, just
|
||||
* initialize the PKCS #11 module.
|
||||
* NSS_INIT_FORCEOPEN - Continue to force initializations even if the
|
||||
* databases cannot be opened.
|
||||
* NSS_INIT_NOROOTINIT - Don't try to look for the root certs module
|
||||
* automatically.
|
||||
* NSS_INIT_OPTIMIZESPACE - Use smaller tables and caches.
|
||||
* NSS_INIT_PK11THREADSAFE - only load PKCS#11 modules that are
|
||||
* thread-safe, ie. that support locking - either OS
|
||||
* locking or NSS-provided locks . If a PKCS#11
|
||||
* module isn't thread-safe, don't serialize its
|
||||
* calls; just don't load it instead. This is necessary
|
||||
* if another piece of code is using the same PKCS#11
|
||||
* modules that NSS is accessing without going through
|
||||
* NSS, for example the Java SunPKCS11 provider.
|
||||
* NSS_INIT_PK11RELOAD - ignore the CKR_CRYPTOKI_ALREADY_INITIALIZED
|
||||
* error when loading PKCS#11 modules. This is necessary
|
||||
* if another piece of code is using the same PKCS#11
|
||||
* modules that NSS is accessing without going through
|
||||
* NSS, for example Java SunPKCS11 provider.
|
||||
* NSS_INIT_NOPK11FINALIZE - never call C_Finalize on any
|
||||
* PKCS#11 module. This may be necessary in order to
|
||||
* ensure continuous operation and proper shutdown
|
||||
* sequence if another piece of code is using the same
|
||||
* PKCS#11 modules that NSS is accessing without going
|
||||
* through NSS, for example Java SunPKCS11 provider.
|
||||
* The following limitation applies when this is set :
|
||||
* SECMOD_WaitForAnyTokenEvent will not use
|
||||
* C_WaitForSlotEvent, in order to prevent the need for
|
||||
* C_Finalize. This call will be emulated instead.
|
||||
* NSS_INIT_RESERVED - Currently has no effect, but may be used in the
|
||||
* future to trigger better cooperation between PKCS#11
|
||||
* modules used by both NSS and the Java SunPKCS11
|
||||
* provider. This should occur after a new flag is defined
|
||||
* for C_Initialize by the PKCS#11 working group.
|
||||
* NSS_INIT_COOPERATE - Sets 4 recommended options for applications that
|
||||
* use both NSS and the Java SunPKCS11 provider.
|
||||
*
|
||||
* Also NOTE: This is not the recommended method for initializing NSS.
|
||||
* The prefered method is NSS_init().
|
||||
*/
|
||||
#define NSS_INIT_READONLY 0x1
|
||||
#define NSS_INIT_NOCERTDB 0x2
|
||||
#define NSS_INIT_NOMODDB 0x4
|
||||
#define NSS_INIT_FORCEOPEN 0x8
|
||||
#define NSS_INIT_NOROOTINIT 0x10
|
||||
#define NSS_INIT_OPTIMIZESPACE 0x20
|
||||
#define NSS_INIT_PK11THREADSAFE 0x40
|
||||
#define NSS_INIT_PK11RELOAD 0x80
|
||||
#define NSS_INIT_NOPK11FINALIZE 0x100
|
||||
#define NSS_INIT_RESERVED 0x200
|
||||
|
||||
#define NSS_INIT_COOPERATE NSS_INIT_PK11THREADSAFE | \
|
||||
NSS_INIT_PK11RELOAD | \
|
||||
NSS_INIT_NOPK11FINALIZE | \
|
||||
NSS_INIT_RESERVED
|
||||
|
||||
#ifdef macintosh
|
||||
#define SECMOD_DB "Security Modules"
|
||||
#else
|
||||
#define SECMOD_DB "secmod.db"
|
||||
#endif
|
||||
|
||||
extern SECStatus NSS_Initialize(const char *configdir,
|
||||
const char *certPrefix, const char *keyPrefix,
|
||||
const char *secmodName, PRUint32 flags);
|
||||
|
||||
/*
|
||||
* initialize NSS without a creating cert db's, key db's, or secmod db's.
|
||||
*/
|
||||
SECStatus NSS_NoDB_Init(const char *configdir);
|
||||
|
||||
/*
|
||||
* Allow applications and libraries to register with NSS so that they are called
|
||||
* when NSS shuts down.
|
||||
*
|
||||
* void *appData application specific data passed in by the application at
|
||||
* NSS_RegisterShutdown() time.
|
||||
* void *nssData is NULL in this release, but is reserved for future versions of
|
||||
* NSS to pass some future status information * back to the shutdown function.
|
||||
*
|
||||
* If the shutdown function returns SECFailure,
|
||||
* Shutdown will still complete, but NSS_Shutdown() will return SECFailure.
|
||||
*/
|
||||
typedef SECStatus (*NSS_ShutdownFunc)(void *appData, void *nssData);
|
||||
|
||||
/*
|
||||
* Register a shutdown function.
|
||||
*/
|
||||
SECStatus NSS_RegisterShutdown(NSS_ShutdownFunc sFunc, void *appData);
|
||||
|
||||
/*
|
||||
* Remove an existing shutdown function (you may do this if your library is
|
||||
* complete and going away, but NSS is still running).
|
||||
*/
|
||||
SECStatus NSS_UnregisterShutdown(NSS_ShutdownFunc sFunc, void *appData);
|
||||
|
||||
/*
|
||||
* Close the Cert, Key databases.
|
||||
*/
|
||||
extern SECStatus NSS_Shutdown(void);
|
||||
|
||||
/*
|
||||
* set the PKCS #11 strings for the internal token.
|
||||
*/
|
||||
void PK11_ConfigurePKCS11(const char *man, const char *libdes,
|
||||
const char *tokdes, const char *ptokdes, const char *slotdes,
|
||||
const char *pslotdes, const char *fslotdes, const char *fpslotdes,
|
||||
int minPwd, int pwRequired);
|
||||
|
||||
/*
|
||||
* Dump the contents of the certificate cache and the temporary cert store.
|
||||
* Use to detect leaked references of certs at shutdown time.
|
||||
*/
|
||||
void nss_DumpCertificateCacheInfo(void);
|
||||
|
||||
SEC_END_PROTOS
|
||||
|
||||
#endif /* __nss_h_ */
|
||||
@@ -1,100 +0,0 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nss.h"
|
||||
#include <winver.h>
|
||||
|
||||
#define MY_LIBNAME "nss"
|
||||
#define MY_FILEDESCRIPTION "NSS Base Library"
|
||||
|
||||
#define STRINGIZE(x) #x
|
||||
#define STRINGIZE2(x) STRINGIZE(x)
|
||||
#define NSS_VMAJOR_STR STRINGIZE2(NSS_VMAJOR)
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define MY_DEBUG_STR " (debug)"
|
||||
#define MY_FILEFLAGS_1 VS_FF_DEBUG
|
||||
#else
|
||||
#define MY_DEBUG_STR ""
|
||||
#define MY_FILEFLAGS_1 0x0L
|
||||
#endif
|
||||
#if NSS_BETA
|
||||
#define MY_FILEFLAGS_2 MY_FILEFLAGS_1|VS_FF_PRERELEASE
|
||||
#else
|
||||
#define MY_FILEFLAGS_2 MY_FILEFLAGS_1
|
||||
#endif
|
||||
|
||||
#ifdef WINNT
|
||||
#define MY_FILEOS VOS_NT_WINDOWS32
|
||||
#else
|
||||
#define MY_FILEOS VOS__WINDOWS32
|
||||
#endif
|
||||
|
||||
#define MY_INTERNAL_NAME MY_LIBNAME NSS_VMAJOR_STR
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Version-information resource
|
||||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION NSS_VMAJOR,NSS_VMINOR,NSS_VPATCH,0
|
||||
PRODUCTVERSION NSS_VMAJOR,NSS_VMINOR,NSS_VPATCH,0
|
||||
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
|
||||
FILEFLAGS MY_FILEFLAGS_2
|
||||
FILEOS MY_FILEOS
|
||||
FILETYPE VFT_DLL
|
||||
FILESUBTYPE 0x0L // not used
|
||||
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "040904B0" // Lang=US English, CharSet=Unicode
|
||||
BEGIN
|
||||
VALUE "CompanyName", "Mozilla Foundation\0"
|
||||
VALUE "FileDescription", MY_FILEDESCRIPTION MY_DEBUG_STR "\0"
|
||||
VALUE "FileVersion", NSS_VERSION "\0"
|
||||
VALUE "InternalName", MY_INTERNAL_NAME "\0"
|
||||
VALUE "OriginalFilename", MY_INTERNAL_NAME ".dll\0"
|
||||
VALUE "ProductName", "Network Security Services\0"
|
||||
VALUE "ProductVersion", NSS_VERSION "\0"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", 0x409, 1200
|
||||
END
|
||||
END
|
||||
@@ -1,912 +0,0 @@
|
||||
/*
|
||||
* NSS utility functions
|
||||
*
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1994-2000
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
/* $Id: nssinit.c,v 1.87 2007-12-19 23:03:55 alexei.volkov.bugs%sun.com Exp $ */
|
||||
|
||||
#include <ctype.h>
|
||||
#include "seccomon.h"
|
||||
#include "prinit.h"
|
||||
#include "prprf.h"
|
||||
#include "prmem.h"
|
||||
#include "cert.h"
|
||||
#include "key.h"
|
||||
#include "ssl.h"
|
||||
#include "sslproto.h"
|
||||
#include "secmod.h"
|
||||
#include "secoid.h"
|
||||
#include "nss.h"
|
||||
#include "pk11func.h"
|
||||
#include "secerr.h"
|
||||
#include "nssbase.h"
|
||||
#include "pkixt.h"
|
||||
#include "pkix.h"
|
||||
#include "pkix_tools.h"
|
||||
|
||||
#include "pki3hack.h"
|
||||
#include "certi.h"
|
||||
#include "secmodi.h"
|
||||
#include "ocspti.h"
|
||||
#include "ocspi.h"
|
||||
|
||||
/*
|
||||
* On Windows nss3.dll needs to export the symbol 'mktemp' to be
|
||||
* fully backward compatible with the nss3.dll in NSS 3.2.x and
|
||||
* 3.3.x. This symbol was unintentionally exported and its
|
||||
* definition (in DBM) was moved from nss3.dll to softokn3.dll
|
||||
* in NSS 3.4. See bug 142575.
|
||||
*/
|
||||
#ifdef WIN32_NSS3_DLL_COMPAT
|
||||
#include <io.h>
|
||||
|
||||
/* exported as 'mktemp' */
|
||||
char *
|
||||
nss_mktemp(char *path)
|
||||
{
|
||||
return _mktemp(path);
|
||||
}
|
||||
#endif
|
||||
|
||||
#define NSS_MAX_FLAG_SIZE sizeof("readOnly")+sizeof("noCertDB")+ \
|
||||
sizeof("noModDB")+sizeof("forceOpen")+sizeof("passwordRequired")+ \
|
||||
sizeof ("optimizeSpace")
|
||||
#define NSS_DEFAULT_MOD_NAME "NSS Internal Module"
|
||||
|
||||
static char *
|
||||
nss_makeFlags(PRBool readOnly, PRBool noCertDB,
|
||||
PRBool noModDB, PRBool forceOpen,
|
||||
PRBool passwordRequired, PRBool optimizeSpace)
|
||||
{
|
||||
char *flags = (char *)PORT_Alloc(NSS_MAX_FLAG_SIZE);
|
||||
PRBool first = PR_TRUE;
|
||||
|
||||
PORT_Memset(flags,0,NSS_MAX_FLAG_SIZE);
|
||||
if (readOnly) {
|
||||
PORT_Strcat(flags,"readOnly");
|
||||
first = PR_FALSE;
|
||||
}
|
||||
if (noCertDB) {
|
||||
if (!first) PORT_Strcat(flags,",");
|
||||
PORT_Strcat(flags,"noCertDB");
|
||||
first = PR_FALSE;
|
||||
}
|
||||
if (noModDB) {
|
||||
if (!first) PORT_Strcat(flags,",");
|
||||
PORT_Strcat(flags,"noModDB");
|
||||
first = PR_FALSE;
|
||||
}
|
||||
if (forceOpen) {
|
||||
if (!first) PORT_Strcat(flags,",");
|
||||
PORT_Strcat(flags,"forceOpen");
|
||||
first = PR_FALSE;
|
||||
}
|
||||
if (passwordRequired) {
|
||||
if (!first) PORT_Strcat(flags,",");
|
||||
PORT_Strcat(flags,"passwordRequired");
|
||||
first = PR_FALSE;
|
||||
}
|
||||
if (optimizeSpace) {
|
||||
if (!first) PORT_Strcat(flags,",");
|
||||
PORT_Strcat(flags,"optimizeSpace");
|
||||
first = PR_FALSE;
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
|
||||
/*
|
||||
* statics to remember the PK11_ConfigurePKCS11()
|
||||
* info.
|
||||
*/
|
||||
static char * pk11_config_strings = NULL;
|
||||
static char * pk11_config_name = NULL;
|
||||
static PRBool pk11_password_required = PR_FALSE;
|
||||
|
||||
/*
|
||||
* this is a legacy configuration function which used to be part of
|
||||
* the PKCS #11 internal token.
|
||||
*/
|
||||
void
|
||||
PK11_ConfigurePKCS11(const char *man, const char *libdes, const char *tokdes,
|
||||
const char *ptokdes, const char *slotdes, const char *pslotdes,
|
||||
const char *fslotdes, const char *fpslotdes, int minPwd, int pwRequired)
|
||||
{
|
||||
char *strings = NULL;
|
||||
char *newStrings;
|
||||
|
||||
/* make sure the internationalization was done correctly... */
|
||||
strings = PR_smprintf("");
|
||||
if (strings == NULL) return;
|
||||
|
||||
if (man) {
|
||||
newStrings = PR_smprintf("%s manufacturerID='%s'",strings,man);
|
||||
PR_smprintf_free(strings);
|
||||
strings = newStrings;
|
||||
}
|
||||
if (strings == NULL) return;
|
||||
|
||||
if (libdes) {
|
||||
newStrings = PR_smprintf("%s libraryDescription='%s'",strings,libdes);
|
||||
PR_smprintf_free(strings);
|
||||
strings = newStrings;
|
||||
if (pk11_config_name != NULL) {
|
||||
PORT_Free(pk11_config_name);
|
||||
}
|
||||
pk11_config_name = PORT_Strdup(libdes);
|
||||
}
|
||||
if (strings == NULL) return;
|
||||
|
||||
if (tokdes) {
|
||||
newStrings = PR_smprintf("%s cryptoTokenDescription='%s'",strings,
|
||||
tokdes);
|
||||
PR_smprintf_free(strings);
|
||||
strings = newStrings;
|
||||
}
|
||||
if (strings == NULL) return;
|
||||
|
||||
if (ptokdes) {
|
||||
newStrings = PR_smprintf("%s dbTokenDescription='%s'",strings,ptokdes);
|
||||
PR_smprintf_free(strings);
|
||||
strings = newStrings;
|
||||
}
|
||||
if (strings == NULL) return;
|
||||
|
||||
if (slotdes) {
|
||||
newStrings = PR_smprintf("%s cryptoSlotDescription='%s'",strings,
|
||||
slotdes);
|
||||
PR_smprintf_free(strings);
|
||||
strings = newStrings;
|
||||
}
|
||||
if (strings == NULL) return;
|
||||
|
||||
if (pslotdes) {
|
||||
newStrings = PR_smprintf("%s dbSlotDescription='%s'",strings,pslotdes);
|
||||
PR_smprintf_free(strings);
|
||||
strings = newStrings;
|
||||
}
|
||||
if (strings == NULL) return;
|
||||
|
||||
if (fslotdes) {
|
||||
newStrings = PR_smprintf("%s FIPSSlotDescription='%s'",
|
||||
strings,fslotdes);
|
||||
PR_smprintf_free(strings);
|
||||
strings = newStrings;
|
||||
}
|
||||
if (strings == NULL) return;
|
||||
|
||||
if (fpslotdes) {
|
||||
newStrings = PR_smprintf("%s FIPSTokenDescription='%s'",
|
||||
strings,fpslotdes);
|
||||
PR_smprintf_free(strings);
|
||||
strings = newStrings;
|
||||
}
|
||||
if (strings == NULL) return;
|
||||
|
||||
newStrings = PR_smprintf("%s minPS=%d", strings, minPwd);
|
||||
PR_smprintf_free(strings);
|
||||
strings = newStrings;
|
||||
if (strings == NULL) return;
|
||||
|
||||
if (pk11_config_strings != NULL) {
|
||||
PR_smprintf_free(pk11_config_strings);
|
||||
}
|
||||
pk11_config_strings = strings;
|
||||
pk11_password_required = pwRequired;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void PK11_UnconfigurePKCS11(void)
|
||||
{
|
||||
if (pk11_config_strings != NULL) {
|
||||
PR_smprintf_free(pk11_config_strings);
|
||||
pk11_config_strings = NULL;
|
||||
}
|
||||
if (pk11_config_name) {
|
||||
PORT_Free(pk11_config_name);
|
||||
pk11_config_name = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static char *
|
||||
nss_addEscape(const char *string, char quote)
|
||||
{
|
||||
char *newString = 0;
|
||||
int escapes = 0, size = 0;
|
||||
const char *src;
|
||||
char *dest;
|
||||
|
||||
for (src=string; *src ; src++) {
|
||||
if ((*src == quote) || (*src == '\\')) escapes++;
|
||||
size++;
|
||||
}
|
||||
|
||||
newString = PORT_ZAlloc(escapes+size+1);
|
||||
if (newString == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (src=string, dest=newString; *src; src++,dest++) {
|
||||
if ((*src == '\\') || (*src == quote)) {
|
||||
*dest++ = '\\';
|
||||
}
|
||||
*dest = *src;
|
||||
}
|
||||
|
||||
return newString;
|
||||
}
|
||||
|
||||
static char *
|
||||
nss_doubleEscape(const char *string)
|
||||
{
|
||||
char *round1 = NULL;
|
||||
char *retValue = NULL;
|
||||
if (string == NULL) {
|
||||
goto done;
|
||||
}
|
||||
round1 = nss_addEscape(string,'\'');
|
||||
if (round1) {
|
||||
retValue = nss_addEscape(round1,'"');
|
||||
PORT_Free(round1);
|
||||
}
|
||||
|
||||
done:
|
||||
if (retValue == NULL) {
|
||||
retValue = PORT_Strdup("");
|
||||
}
|
||||
return retValue;
|
||||
}
|
||||
|
||||
|
||||
#ifndef XP_MAC
|
||||
/*
|
||||
* The following code is an attempt to automagically find the external root
|
||||
* module. NOTE: This code should be checked out on the MAC! There must be
|
||||
* some cross platform support out there to help out with this?
|
||||
* Note: Keep the #if-defined chunks in order. HPUX must select before UNIX.
|
||||
*/
|
||||
|
||||
static const char *dllname =
|
||||
#if defined(XP_WIN32) || defined(XP_OS2)
|
||||
"nssckbi.dll";
|
||||
#elif defined(HPUX) && !defined(__ia64) /* HP-UX PA-RISC */
|
||||
"libnssckbi.sl";
|
||||
#elif defined(DARWIN)
|
||||
"libnssckbi.dylib";
|
||||
#elif defined(XP_UNIX) || defined(XP_BEOS)
|
||||
"libnssckbi.so";
|
||||
#elif defined(XP_MAC)
|
||||
"NSS Builtin Root Certs";
|
||||
#else
|
||||
#error "Uh! Oh! I don't know about this platform."
|
||||
#endif
|
||||
|
||||
/* Should we have platform ifdefs here??? */
|
||||
#define FILE_SEP '/'
|
||||
|
||||
static void nss_FindExternalRootPaths(const char *dbpath,
|
||||
const char* secmodprefix,
|
||||
char** retoldpath, char** retnewpath)
|
||||
{
|
||||
char *path, *oldpath = NULL, *lastsep;
|
||||
int len, path_len, secmod_len, dll_len;
|
||||
|
||||
path_len = PORT_Strlen(dbpath);
|
||||
secmod_len = secmodprefix ? PORT_Strlen(secmodprefix) : 0;
|
||||
dll_len = PORT_Strlen(dllname);
|
||||
len = path_len + secmod_len + dll_len + 2; /* FILE_SEP + NULL */
|
||||
|
||||
path = PORT_Alloc(len);
|
||||
if (path == NULL) return;
|
||||
|
||||
/* back up to the top of the directory */
|
||||
PORT_Memcpy(path,dbpath,path_len);
|
||||
if (path[path_len-1] != FILE_SEP) {
|
||||
path[path_len++] = FILE_SEP;
|
||||
}
|
||||
PORT_Strcpy(&path[path_len],dllname);
|
||||
if (secmod_len > 0) {
|
||||
lastsep = PORT_Strrchr(secmodprefix, FILE_SEP);
|
||||
if (lastsep) {
|
||||
int secmoddir_len = lastsep-secmodprefix+1; /* FILE_SEP */
|
||||
oldpath = PORT_Alloc(len);
|
||||
if (oldpath == NULL) {
|
||||
PORT_Free(path);
|
||||
return;
|
||||
}
|
||||
PORT_Memcpy(oldpath,path,path_len);
|
||||
PORT_Memcpy(&oldpath[path_len],secmodprefix,secmoddir_len);
|
||||
PORT_Strcpy(&oldpath[path_len+secmoddir_len],dllname);
|
||||
}
|
||||
}
|
||||
*retoldpath = oldpath;
|
||||
*retnewpath = path;
|
||||
return;
|
||||
}
|
||||
|
||||
static void nss_FreeExternalRootPaths(char* oldpath, char* path)
|
||||
{
|
||||
if (path) {
|
||||
PORT_Free(path);
|
||||
}
|
||||
if (oldpath) {
|
||||
PORT_Free(oldpath);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nss_FindExternalRoot(const char *dbpath, const char* secmodprefix)
|
||||
{
|
||||
char *path = NULL;
|
||||
char *oldpath = NULL;
|
||||
PRBool hasrootcerts = PR_FALSE;
|
||||
|
||||
/*
|
||||
* 'oldpath' is the external root path in NSS 3.3.x or older.
|
||||
* For backward compatibility we try to load the root certs
|
||||
* module with the old path first.
|
||||
*/
|
||||
nss_FindExternalRootPaths(dbpath, secmodprefix, &oldpath, &path);
|
||||
if (oldpath) {
|
||||
(void) SECMOD_AddNewModule("Root Certs",oldpath, 0, 0);
|
||||
hasrootcerts = SECMOD_HasRootCerts();
|
||||
}
|
||||
if (path && !hasrootcerts) {
|
||||
(void) SECMOD_AddNewModule("Root Certs",path, 0, 0);
|
||||
}
|
||||
nss_FreeExternalRootPaths(oldpath, path);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* OK there are now lots of options here, lets go through them all:
|
||||
*
|
||||
* configdir - base directory where all the cert, key, and module datbases live.
|
||||
* certPrefix - prefix added to the beginning of the cert database example: "
|
||||
* "https-server1-"
|
||||
* keyPrefix - prefix added to the beginning of the key database example: "
|
||||
* "https-server1-"
|
||||
* secmodName - name of the security module database (usually "secmod.db").
|
||||
* readOnly - Boolean: true if the databases are to be opened read only.
|
||||
* nocertdb - Don't open the cert DB and key DB's, just initialize the
|
||||
* Volatile certdb.
|
||||
* nomoddb - Don't open the security module DB, just initialize the
|
||||
* PKCS #11 module.
|
||||
* forceOpen - Continue to force initializations even if the databases cannot
|
||||
* be opened.
|
||||
*/
|
||||
|
||||
static PRBool nss_IsInitted = PR_FALSE;
|
||||
static void* plContext = NULL;
|
||||
|
||||
extern SECStatus secoid_Init(void);
|
||||
static SECStatus nss_InitShutdownList(void);
|
||||
|
||||
#ifdef DEBUG
|
||||
static CERTCertificate dummyCert;
|
||||
#endif
|
||||
|
||||
static SECStatus
|
||||
nss_Init(const char *configdir, const char *certPrefix, const char *keyPrefix,
|
||||
const char *secmodName, PRBool readOnly, PRBool noCertDB,
|
||||
PRBool noModDB, PRBool forceOpen, PRBool noRootInit,
|
||||
PRBool optimizeSpace, PRBool noSingleThreadedModules,
|
||||
PRBool allowAlreadyInitializedModules,
|
||||
PRBool dontFinalizeModules)
|
||||
{
|
||||
char *moduleSpec = NULL;
|
||||
char *flags = NULL;
|
||||
SECStatus rv = SECFailure;
|
||||
char *lconfigdir = NULL;
|
||||
char *lcertPrefix = NULL;
|
||||
char *lkeyPrefix = NULL;
|
||||
char *lsecmodName = NULL;
|
||||
PKIX_UInt32 actualMinorVersion = 0;
|
||||
PKIX_Error *pkixError = NULL;;
|
||||
|
||||
if (nss_IsInitted) {
|
||||
return SECSuccess;
|
||||
}
|
||||
|
||||
/* New option bits must not change the size of CERTCertificate. */
|
||||
PORT_Assert(sizeof(dummyCert.options) == sizeof(void *));
|
||||
|
||||
if (SECSuccess != cert_InitLocks()) {
|
||||
return SECFailure;
|
||||
}
|
||||
|
||||
if (SECSuccess != InitCRLCache()) {
|
||||
return SECFailure;
|
||||
}
|
||||
|
||||
if (SECSuccess != OCSP_InitGlobal()) {
|
||||
return SECFailure;
|
||||
}
|
||||
|
||||
flags = nss_makeFlags(readOnly,noCertDB,noModDB,forceOpen,
|
||||
pk11_password_required, optimizeSpace);
|
||||
if (flags == NULL) return rv;
|
||||
|
||||
/*
|
||||
* configdir is double nested, and Windows uses the same character
|
||||
* for file seps as we use for escapes! (sigh).
|
||||
*/
|
||||
lconfigdir = nss_doubleEscape(configdir);
|
||||
if (lconfigdir == NULL) {
|
||||
goto loser;
|
||||
}
|
||||
lcertPrefix = nss_doubleEscape(certPrefix);
|
||||
if (lcertPrefix == NULL) {
|
||||
goto loser;
|
||||
}
|
||||
lkeyPrefix = nss_doubleEscape(keyPrefix);
|
||||
if (lkeyPrefix == NULL) {
|
||||
goto loser;
|
||||
}
|
||||
lsecmodName = nss_doubleEscape(secmodName);
|
||||
if (lsecmodName == NULL) {
|
||||
goto loser;
|
||||
}
|
||||
if (noSingleThreadedModules || allowAlreadyInitializedModules ||
|
||||
dontFinalizeModules) {
|
||||
pk11_setGlobalOptions(noSingleThreadedModules,
|
||||
allowAlreadyInitializedModules,
|
||||
dontFinalizeModules);
|
||||
}
|
||||
|
||||
moduleSpec = PR_smprintf("name=\"%s\" parameters=\"configdir='%s' certPrefix='%s' keyPrefix='%s' secmod='%s' flags=%s %s\" NSS=\"flags=internal,moduleDB,moduleDBOnly,critical\"",
|
||||
pk11_config_name ? pk11_config_name : NSS_DEFAULT_MOD_NAME,
|
||||
lconfigdir,lcertPrefix,lkeyPrefix,lsecmodName,flags,
|
||||
pk11_config_strings ? pk11_config_strings : "");
|
||||
|
||||
loser:
|
||||
PORT_Free(flags);
|
||||
if (lconfigdir) PORT_Free(lconfigdir);
|
||||
if (lcertPrefix) PORT_Free(lcertPrefix);
|
||||
if (lkeyPrefix) PORT_Free(lkeyPrefix);
|
||||
if (lsecmodName) PORT_Free(lsecmodName);
|
||||
|
||||
if (moduleSpec) {
|
||||
SECMODModule *module = SECMOD_LoadModule(moduleSpec,NULL,PR_TRUE);
|
||||
PR_smprintf_free(moduleSpec);
|
||||
if (module) {
|
||||
if (module->loaded) rv=SECSuccess;
|
||||
SECMOD_DestroyModule(module);
|
||||
}
|
||||
}
|
||||
|
||||
if (rv == SECSuccess) {
|
||||
if (secoid_Init() != SECSuccess) {
|
||||
return SECFailure;
|
||||
}
|
||||
if (STAN_LoadDefaultNSS3TrustDomain() != PR_SUCCESS) {
|
||||
return SECFailure;
|
||||
}
|
||||
if (nss_InitShutdownList() != SECSuccess) {
|
||||
return SECFailure;
|
||||
}
|
||||
CERT_SetDefaultCertDB((CERTCertDBHandle *)
|
||||
STAN_GetDefaultTrustDomain());
|
||||
#ifndef XP_MAC
|
||||
/* only servers need this. We currently do not have a mac server */
|
||||
if ((!noModDB) && (!noCertDB) && (!noRootInit)) {
|
||||
if (!SECMOD_HasRootCerts()) {
|
||||
nss_FindExternalRoot(configdir, secmodName);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
pk11sdr_Init();
|
||||
cert_CreateSubjectKeyIDHashTable();
|
||||
nss_IsInitted = PR_TRUE;
|
||||
}
|
||||
|
||||
if (SECSuccess == rv) {
|
||||
pkixError = PKIX_Initialize
|
||||
(PKIX_FALSE, PKIX_FALSE, PKIX_MAJOR_VERSION, PKIX_MINOR_VERSION,
|
||||
PKIX_MINOR_VERSION, &actualMinorVersion, &plContext);
|
||||
|
||||
if (pkixError != NULL) {
|
||||
rv = SECFailure;
|
||||
} else {
|
||||
char *ev = getenv("NSS_ENABLE_PKIX_VERIFY");
|
||||
if (ev && ev[0]) {
|
||||
cert_SetPKIXValidation(PR_TRUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
SECStatus
|
||||
NSS_Init(const char *configdir)
|
||||
{
|
||||
return nss_Init(configdir, "", "", SECMOD_DB, PR_TRUE,
|
||||
PR_FALSE, PR_FALSE, PR_FALSE, PR_FALSE, PR_TRUE, PR_FALSE, PR_FALSE, PR_FALSE);
|
||||
}
|
||||
|
||||
SECStatus
|
||||
NSS_InitReadWrite(const char *configdir)
|
||||
{
|
||||
return nss_Init(configdir, "", "", SECMOD_DB, PR_FALSE,
|
||||
PR_FALSE, PR_FALSE, PR_FALSE, PR_FALSE, PR_TRUE, PR_FALSE, PR_FALSE, PR_FALSE);
|
||||
}
|
||||
|
||||
/*
|
||||
* OK there are now lots of options here, lets go through them all:
|
||||
*
|
||||
* configdir - base directory where all the cert, key, and module datbases live.
|
||||
* certPrefix - prefix added to the beginning of the cert database example: "
|
||||
* "https-server1-"
|
||||
* keyPrefix - prefix added to the beginning of the key database example: "
|
||||
* "https-server1-"
|
||||
* secmodName - name of the security module database (usually "secmod.db").
|
||||
* flags - change the open options of NSS_Initialize as follows:
|
||||
* NSS_INIT_READONLY - Open the databases read only.
|
||||
* NSS_INIT_NOCERTDB - Don't open the cert DB and key DB's, just
|
||||
* initialize the volatile certdb.
|
||||
* NSS_INIT_NOMODDB - Don't open the security module DB, just
|
||||
* initialize the PKCS #11 module.
|
||||
* NSS_INIT_FORCEOPEN - Continue to force initializations even if the
|
||||
* databases cannot be opened.
|
||||
* NSS_INIT_PK11THREADSAFE - only load PKCS#11 modules that are
|
||||
* thread-safe, ie. that support locking - either OS
|
||||
* locking or NSS-provided locks . If a PKCS#11
|
||||
* module isn't thread-safe, don't serialize its
|
||||
* calls; just don't load it instead. This is necessary
|
||||
* if another piece of code is using the same PKCS#11
|
||||
* modules that NSS is accessing without going through
|
||||
* NSS, for example the Java SunPKCS11 provider.
|
||||
* NSS_INIT_PK11RELOAD - ignore the CKR_CRYPTOKI_ALREADY_INITIALIZED
|
||||
* error when loading PKCS#11 modules. This is necessary
|
||||
* if another piece of code is using the same PKCS#11
|
||||
* modules that NSS is accessing without going through
|
||||
* NSS, for example Java SunPKCS11 provider.
|
||||
* NSS_INIT_NOPK11FINALIZE - never call C_Finalize on any
|
||||
* PKCS#11 module. This may be necessary in order to
|
||||
* ensure continuous operation and proper shutdown
|
||||
* sequence if another piece of code is using the same
|
||||
* PKCS#11 modules that NSS is accessing without going
|
||||
* through NSS, for example Java SunPKCS11 provider.
|
||||
* The following limitation applies when this is set :
|
||||
* SECMOD_WaitForAnyTokenEvent will not use
|
||||
* C_WaitForSlotEvent, in order to prevent the need for
|
||||
* C_Finalize. This call will be emulated instead.
|
||||
* NSS_INIT_RESERVED - Currently has no effect, but may be used in the
|
||||
* future to trigger better cooperation between PKCS#11
|
||||
* modules used by both NSS and the Java SunPKCS11
|
||||
* provider. This should occur after a new flag is defined
|
||||
* for C_Initialize by the PKCS#11 working group.
|
||||
* NSS_INIT_COOPERATE - Sets 4 recommended options for applications that
|
||||
* use both NSS and the Java SunPKCS11 provider.
|
||||
*/
|
||||
SECStatus
|
||||
NSS_Initialize(const char *configdir, const char *certPrefix,
|
||||
const char *keyPrefix, const char *secmodName, PRUint32 flags)
|
||||
{
|
||||
return nss_Init(configdir, certPrefix, keyPrefix, secmodName,
|
||||
((flags & NSS_INIT_READONLY) == NSS_INIT_READONLY),
|
||||
((flags & NSS_INIT_NOCERTDB) == NSS_INIT_NOCERTDB),
|
||||
((flags & NSS_INIT_NOMODDB) == NSS_INIT_NOMODDB),
|
||||
((flags & NSS_INIT_FORCEOPEN) == NSS_INIT_FORCEOPEN),
|
||||
((flags & NSS_INIT_NOROOTINIT) == NSS_INIT_NOROOTINIT),
|
||||
((flags & NSS_INIT_OPTIMIZESPACE) == NSS_INIT_OPTIMIZESPACE),
|
||||
((flags & NSS_INIT_PK11THREADSAFE) == NSS_INIT_PK11THREADSAFE),
|
||||
((flags & NSS_INIT_PK11RELOAD) == NSS_INIT_PK11RELOAD),
|
||||
((flags & NSS_INIT_NOPK11FINALIZE) == NSS_INIT_NOPK11FINALIZE));
|
||||
}
|
||||
|
||||
/*
|
||||
* initialize NSS without a creating cert db's, key db's, or secmod db's.
|
||||
*/
|
||||
SECStatus
|
||||
NSS_NoDB_Init(const char * configdir)
|
||||
{
|
||||
return nss_Init("","","","",
|
||||
PR_TRUE,PR_TRUE,PR_TRUE,PR_TRUE,PR_TRUE,PR_TRUE,
|
||||
PR_FALSE,PR_FALSE,PR_FALSE);
|
||||
}
|
||||
|
||||
|
||||
#define NSS_SHUTDOWN_STEP 10
|
||||
|
||||
struct NSSShutdownFuncPair {
|
||||
NSS_ShutdownFunc func;
|
||||
void *appData;
|
||||
};
|
||||
|
||||
static struct NSSShutdownListStr {
|
||||
PZLock *lock;
|
||||
int maxFuncs;
|
||||
int numFuncs;
|
||||
struct NSSShutdownFuncPair *funcs;
|
||||
} nssShutdownList = { 0 };
|
||||
|
||||
/*
|
||||
* find and existing shutdown function
|
||||
*/
|
||||
static int
|
||||
nss_GetShutdownEntry(NSS_ShutdownFunc sFunc, void *appData)
|
||||
{
|
||||
int count, i;
|
||||
count = nssShutdownList.numFuncs;
|
||||
/* expect the list to be short, just do a linear search */
|
||||
for (i=0; i < count; i++) {
|
||||
if ((nssShutdownList.funcs[i].func == sFunc) &&
|
||||
(nssShutdownList.funcs[i].appData == appData)){
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* register a callback to be called when NSS shuts down
|
||||
*/
|
||||
SECStatus
|
||||
NSS_RegisterShutdown(NSS_ShutdownFunc sFunc, void *appData)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!nss_IsInitted) {
|
||||
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
|
||||
return SECFailure;
|
||||
}
|
||||
if (sFunc == NULL) {
|
||||
PORT_SetError(SEC_ERROR_INVALID_ARGS);
|
||||
return SECFailure;
|
||||
}
|
||||
|
||||
PORT_Assert(nssShutdownList.lock);
|
||||
PZ_Lock(nssShutdownList.lock);
|
||||
|
||||
/* make sure we don't have a duplicate */
|
||||
i = nss_GetShutdownEntry(sFunc, appData);
|
||||
if (i > 0) {
|
||||
PZ_Unlock(nssShutdownList.lock);
|
||||
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
|
||||
return SECFailure;
|
||||
}
|
||||
/* find an empty slot */
|
||||
i = nss_GetShutdownEntry(NULL, NULL);
|
||||
if (i > 0) {
|
||||
nssShutdownList.funcs[i].func = sFunc;
|
||||
nssShutdownList.funcs[i].appData = appData;
|
||||
PZ_Unlock(nssShutdownList.lock);
|
||||
return SECFailure;
|
||||
}
|
||||
if (nssShutdownList.maxFuncs == nssShutdownList.numFuncs) {
|
||||
struct NSSShutdownFuncPair *funcs =
|
||||
(struct NSSShutdownFuncPair *)PORT_Realloc
|
||||
(nssShutdownList.funcs,
|
||||
(nssShutdownList.maxFuncs + NSS_SHUTDOWN_STEP)
|
||||
*sizeof(struct NSSShutdownFuncPair));
|
||||
if (!funcs) {
|
||||
return SECFailure;
|
||||
}
|
||||
nssShutdownList.funcs = funcs;
|
||||
nssShutdownList.maxFuncs += NSS_SHUTDOWN_STEP;
|
||||
}
|
||||
nssShutdownList.funcs[nssShutdownList.numFuncs].func = sFunc;
|
||||
nssShutdownList.funcs[nssShutdownList.numFuncs].appData = appData;
|
||||
nssShutdownList.numFuncs++;
|
||||
PZ_Unlock(nssShutdownList.lock);
|
||||
return SECSuccess;
|
||||
}
|
||||
|
||||
/*
|
||||
* unregister a callback so it won't get called on shutdown.
|
||||
*/
|
||||
SECStatus
|
||||
NSS_UnregisterShutdown(NSS_ShutdownFunc sFunc, void *appData)
|
||||
{
|
||||
int i;
|
||||
if (!nss_IsInitted) {
|
||||
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
|
||||
return SECFailure;
|
||||
}
|
||||
|
||||
PORT_Assert(nssShutdownList.lock);
|
||||
PZ_Lock(nssShutdownList.lock);
|
||||
i = nss_GetShutdownEntry(sFunc, appData);
|
||||
if (i > 0) {
|
||||
nssShutdownList.funcs[i].func = NULL;
|
||||
nssShutdownList.funcs[i].appData = NULL;
|
||||
}
|
||||
PZ_Unlock(nssShutdownList.lock);
|
||||
|
||||
if (i < 0) {
|
||||
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
|
||||
return SECFailure;
|
||||
}
|
||||
return SECSuccess;
|
||||
}
|
||||
|
||||
/*
|
||||
* bring up and shutdown the shutdown list
|
||||
*/
|
||||
static SECStatus
|
||||
nss_InitShutdownList(void)
|
||||
{
|
||||
nssShutdownList.lock = PZ_NewLock(nssILockOther);
|
||||
if (nssShutdownList.lock == NULL) {
|
||||
return SECFailure;
|
||||
}
|
||||
nssShutdownList.funcs = PORT_ZNewArray(struct NSSShutdownFuncPair,
|
||||
NSS_SHUTDOWN_STEP);
|
||||
if (nssShutdownList.funcs == NULL) {
|
||||
PZ_DestroyLock(nssShutdownList.lock);
|
||||
nssShutdownList.lock = NULL;
|
||||
return SECFailure;
|
||||
}
|
||||
nssShutdownList.maxFuncs = NSS_SHUTDOWN_STEP;
|
||||
nssShutdownList.numFuncs = 0;
|
||||
|
||||
return SECSuccess;
|
||||
}
|
||||
|
||||
static SECStatus
|
||||
nss_ShutdownShutdownList(void)
|
||||
{
|
||||
SECStatus rv = SECSuccess;
|
||||
int i;
|
||||
|
||||
/* call all the registerd functions first */
|
||||
for (i=0; i < nssShutdownList.numFuncs; i++) {
|
||||
struct NSSShutdownFuncPair *funcPair = &nssShutdownList.funcs[i];
|
||||
if (funcPair->func) {
|
||||
if ((*funcPair->func)(funcPair->appData,NULL) != SECSuccess) {
|
||||
rv = SECFailure;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nssShutdownList.numFuncs = 0;
|
||||
nssShutdownList.maxFuncs = 0;
|
||||
PORT_Free(nssShutdownList.funcs);
|
||||
nssShutdownList.funcs = NULL;
|
||||
if (nssShutdownList.lock) {
|
||||
PZ_DestroyLock(nssShutdownList.lock);
|
||||
}
|
||||
nssShutdownList.lock = NULL;
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
extern const NSSError NSS_ERROR_BUSY;
|
||||
|
||||
SECStatus
|
||||
NSS_Shutdown(void)
|
||||
{
|
||||
SECStatus shutdownRV = SECSuccess;
|
||||
SECStatus rv;
|
||||
PRStatus status;
|
||||
|
||||
if (!nss_IsInitted) {
|
||||
PORT_SetError(SEC_ERROR_NOT_INITIALIZED);
|
||||
return SECFailure;
|
||||
}
|
||||
|
||||
rv = nss_ShutdownShutdownList();
|
||||
if (rv != SECSuccess) {
|
||||
shutdownRV = SECFailure;
|
||||
}
|
||||
cert_DestroyLocks();
|
||||
ShutdownCRLCache();
|
||||
OCSP_ShutdownGlobal();
|
||||
PKIX_Shutdown(plContext);
|
||||
SECOID_Shutdown();
|
||||
status = STAN_Shutdown();
|
||||
cert_DestroySubjectKeyIDHashTable();
|
||||
rv = SECMOD_Shutdown();
|
||||
if (rv != SECSuccess) {
|
||||
shutdownRV = SECFailure;
|
||||
}
|
||||
pk11sdr_Shutdown();
|
||||
if (status == PR_FAILURE) {
|
||||
if (NSS_GetError() == NSS_ERROR_BUSY) {
|
||||
PORT_SetError(SEC_ERROR_BUSY);
|
||||
}
|
||||
shutdownRV = SECFailure;
|
||||
}
|
||||
nss_IsInitted = PR_FALSE;
|
||||
return shutdownRV;
|
||||
}
|
||||
|
||||
PRBool
|
||||
NSS_IsInitialized(void)
|
||||
{
|
||||
return nss_IsInitted;
|
||||
}
|
||||
|
||||
|
||||
extern const char __nss_base_rcsid[];
|
||||
extern const char __nss_base_sccsid[];
|
||||
|
||||
PRBool
|
||||
NSS_VersionCheck(const char *importedVersion)
|
||||
{
|
||||
/*
|
||||
* This is the secret handshake algorithm.
|
||||
*
|
||||
* This release has a simple version compatibility
|
||||
* check algorithm. This release is not backward
|
||||
* compatible with previous major releases. It is
|
||||
* not compatible with future major, minor, or
|
||||
* patch releases.
|
||||
*/
|
||||
int vmajor = 0, vminor = 0, vpatch = 0;
|
||||
const char *ptr = importedVersion;
|
||||
volatile char c; /* force a reference that won't get optimized away */
|
||||
|
||||
c = __nss_base_rcsid[0] + __nss_base_sccsid[0];
|
||||
|
||||
while (isdigit(*ptr)) {
|
||||
vmajor = 10 * vmajor + *ptr - '0';
|
||||
ptr++;
|
||||
}
|
||||
if (*ptr == '.') {
|
||||
ptr++;
|
||||
while (isdigit(*ptr)) {
|
||||
vminor = 10 * vminor + *ptr - '0';
|
||||
ptr++;
|
||||
}
|
||||
if (*ptr == '.') {
|
||||
ptr++;
|
||||
while (isdigit(*ptr)) {
|
||||
vpatch = 10 * vpatch + *ptr - '0';
|
||||
ptr++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (vmajor != NSS_VMAJOR) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
if (vmajor == NSS_VMAJOR && vminor > NSS_VMINOR) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
if (vmajor == NSS_VMAJOR && vminor == NSS_VMINOR && vpatch > NSS_VPATCH) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
/* Check dependent libraries */
|
||||
if (PR_VersionCheck(PR_VERSION) == PR_FALSE) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
return PR_TRUE;
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef __nssrenam_h_
|
||||
#define __nssrenam_h_
|
||||
|
||||
#define CERT_NewTempCertificate __CERT_NewTempCertificate
|
||||
#define CERT_AddTempCertToPerm __CERT_AddTempCertToPerm
|
||||
#define PK11_CreateContextByRawKey __PK11_CreateContextByRawKey
|
||||
#define PK11_GetKeyData __PK11_GetKeyData
|
||||
#define CERT_ClosePermCertDB __CERT_ClosePermCertDB
|
||||
#define CERT_DecodeDERCertificate __CERT_DecodeDERCertificate
|
||||
#define CERT_TraversePermCertsForNickname __CERT_TraversePermCertsForNickname
|
||||
#define CERT_TraversePermCertsForSubject __CERT_TraversePermCertsForSubject
|
||||
#define PBE_CreateContext __PBE_CreateContext
|
||||
#define PBE_DestroyContext __PBE_DestroyContext
|
||||
#define PBE_GenerateBits __PBE_GenerateBits
|
||||
|
||||
#endif /* __nssrenam_h_ */
|
||||
@@ -1,56 +0,0 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is the Netscape security libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/* Library identity and versioning */
|
||||
|
||||
#include "nss.h"
|
||||
|
||||
#if defined(DEBUG)
|
||||
#define _DEBUG_STRING " (debug)"
|
||||
#else
|
||||
#define _DEBUG_STRING ""
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Version information for the 'ident' and 'what commands
|
||||
*
|
||||
* NOTE: the first component of the concatenated rcsid string
|
||||
* must not end in a '$' to prevent rcs keyword substitution.
|
||||
*/
|
||||
const char __nss_base_rcsid[] = "$Header: NSS " NSS_VERSION _DEBUG_STRING
|
||||
" " __DATE__ " " __TIME__ " $";
|
||||
const char __nss_base_sccsid[] = "@(#)NSS " NSS_VERSION _DEBUG_STRING
|
||||
" " __DATE__ " " __TIME__;
|
||||
@@ -1,318 +0,0 @@
|
||||
;+LIBPKIXprivate {
|
||||
;+ global:
|
||||
;+# libpkix functions
|
||||
;+# May not become part of the NSS public API. Needed for unit testing for now.
|
||||
NSS_Get_PKIX_PL_LDAPMessageTemplate;
|
||||
PKIX_PL_LDAPMessageTemplate;
|
||||
PKIX_ALLOC_ERROR;
|
||||
PKIX_BuildChain;
|
||||
pkix_BuildResult_Create;
|
||||
PKIX_BuildResult_GetCertChain;
|
||||
PKIX_BuildResult_GetValidateResult;
|
||||
PKIX_CertChainChecker_Create;
|
||||
PKIX_CertChainChecker_GetCertChainCheckerState;
|
||||
PKIX_CertChainChecker_GetCheckCallback;
|
||||
PKIX_CertChainChecker_GetSupportedExtensions;
|
||||
PKIX_CertChainChecker_IsForwardCheckingSupported;
|
||||
PKIX_CertChainChecker_IsForwardDirectionExpected;
|
||||
PKIX_CertChainChecker_SetCertChainCheckerState;
|
||||
PKIX_CertSelector_Create;
|
||||
PKIX_CertSelector_GetCertSelectorContext;
|
||||
PKIX_CertSelector_GetCommonCertSelectorParams;
|
||||
PKIX_CertSelector_GetMatchCallback;
|
||||
PKIX_CertSelector_SetCommonCertSelectorParams;
|
||||
PKIX_CertStore_CertContinue;
|
||||
PKIX_CertStore_Create;
|
||||
PKIX_CertStore_CrlContinue;
|
||||
PKIX_CertStore_GetCertCallback;
|
||||
PKIX_CertStore_GetCertStoreContext;
|
||||
PKIX_CertStore_GetCRLCallback;
|
||||
PKIX_CertStore_GetTrustCallback;
|
||||
pkix_CheckType;
|
||||
PKIX_ComCertSelParams_AddPathToName;
|
||||
PKIX_ComCertSelParams_AddSubjAltName;
|
||||
PKIX_ComCertSelParams_Create;
|
||||
PKIX_ComCertSelParams_GetAuthorityKeyIdentifier;
|
||||
PKIX_ComCertSelParams_GetBasicConstraints;
|
||||
PKIX_ComCertSelParams_GetCertificate;
|
||||
PKIX_ComCertSelParams_GetCertificateValid;
|
||||
PKIX_ComCertSelParams_GetExtendedKeyUsage;
|
||||
PKIX_ComCertSelParams_GetIssuer;
|
||||
PKIX_ComCertSelParams_GetKeyUsage;
|
||||
PKIX_ComCertSelParams_GetMatchAllSubjAltNames;
|
||||
PKIX_ComCertSelParams_GetNameConstraints;
|
||||
PKIX_ComCertSelParams_GetPathToNames;
|
||||
PKIX_ComCertSelParams_GetPolicy;
|
||||
PKIX_ComCertSelParams_GetSerialNumber;
|
||||
PKIX_ComCertSelParams_GetSubjAltNames;
|
||||
PKIX_ComCertSelParams_GetSubject;
|
||||
PKIX_ComCertSelParams_GetSubjKeyIdentifier;
|
||||
PKIX_ComCertSelParams_GetSubjPKAlgId;
|
||||
PKIX_ComCertSelParams_GetSubjPubKey;
|
||||
PKIX_ComCertSelParams_GetVersion;
|
||||
PKIX_ComCertSelParams_SetAuthorityKeyIdentifier;
|
||||
PKIX_ComCertSelParams_SetBasicConstraints;
|
||||
PKIX_ComCertSelParams_SetCertificate;
|
||||
PKIX_ComCertSelParams_SetCertificateValid;
|
||||
PKIX_ComCertSelParams_SetExtendedKeyUsage;
|
||||
PKIX_ComCertSelParams_SetIssuer;
|
||||
PKIX_ComCertSelParams_SetKeyUsage;
|
||||
PKIX_ComCertSelParams_SetMatchAllSubjAltNames;
|
||||
PKIX_ComCertSelParams_SetNameConstraints;
|
||||
PKIX_ComCertSelParams_SetPathToNames;
|
||||
PKIX_ComCertSelParams_SetPolicy;
|
||||
PKIX_ComCertSelParams_SetSerialNumber;
|
||||
PKIX_ComCertSelParams_SetSubjAltNames;
|
||||
PKIX_ComCertSelParams_SetSubject;
|
||||
PKIX_ComCertSelParams_SetSubjKeyIdentifier;
|
||||
PKIX_ComCertSelParams_SetSubjPKAlgId;
|
||||
PKIX_ComCertSelParams_SetSubjPubKey;
|
||||
PKIX_ComCertSelParams_SetVersion;
|
||||
PKIX_ComCRLSelParams_AddIssuerName;
|
||||
PKIX_ComCRLSelParams_Create;
|
||||
PKIX_ComCRLSelParams_GetCertificateChecking;
|
||||
PKIX_ComCRLSelParams_GetDateAndTime;
|
||||
PKIX_ComCRLSelParams_GetIssuerNames;
|
||||
PKIX_ComCRLSelParams_GetMaxCRLNumber;
|
||||
PKIX_ComCRLSelParams_GetMinCRLNumber;
|
||||
PKIX_ComCRLSelParams_SetCertificateChecking;
|
||||
PKIX_ComCRLSelParams_SetDateAndTime;
|
||||
PKIX_ComCRLSelParams_SetIssuerNames;
|
||||
PKIX_ComCRLSelParams_SetMaxCRLNumber;
|
||||
PKIX_ComCRLSelParams_SetMinCRLNumber;
|
||||
PKIX_CRLSelector_Create;
|
||||
PKIX_CRLSelector_GetCommonCRLSelectorParams;
|
||||
PKIX_CRLSelector_GetCRLSelectorContext;
|
||||
PKIX_CRLSelector_GetMatchCallback;
|
||||
PKIX_CRLSelector_SetCommonCRLSelectorParams;
|
||||
pkix_DefaultRevChecker_Initialize;
|
||||
PKIX_Error_Create;
|
||||
PKIX_Error_GetCause;
|
||||
PKIX_Error_GetDescription;
|
||||
PKIX_Error_GetErrorClass;
|
||||
PKIX_Error_GetSupplementaryInfo;
|
||||
PKIX_ERRORCLASSNAMES DATA ;
|
||||
PKIX_Initialize;
|
||||
PKIX_Initialize_SetConfigDir;
|
||||
PKIX_List_AppendItem;
|
||||
PKIX_List_Create;
|
||||
PKIX_List_DeleteItem;
|
||||
PKIX_List_GetItem;
|
||||
PKIX_List_GetLength;
|
||||
PKIX_List_InsertItem;
|
||||
PKIX_List_IsEmpty;
|
||||
PKIX_List_IsImmutable;
|
||||
PKIX_List_ReverseList;
|
||||
PKIX_List_SetImmutable;
|
||||
PKIX_List_SetItem;
|
||||
PKIX_AddLogger;
|
||||
PKIX_GetLoggers;
|
||||
PKIX_SetLoggers;
|
||||
PKIX_Logger_Create;
|
||||
PKIX_Logger_GetLoggerContext;
|
||||
PKIX_Logger_GetLoggingComponent;
|
||||
PKIX_Logger_GetLogCallback;
|
||||
PKIX_Logger_GetMaxLoggingLevel;
|
||||
PKIX_Logger_SetLoggingComponent;
|
||||
PKIX_Logger_SetMaxLoggingLevel;
|
||||
PKIX_OcspChecker_Initialize;
|
||||
PKIX_OcspChecker_SetOCSPResponder;
|
||||
PKIX_OcspChecker_SetPasswordInfo;
|
||||
PKIX_OcspChecker_SetVerifyFcn;
|
||||
PKIX_PL_AcquireReaderLock;
|
||||
PKIX_PL_AcquireWriterLock;
|
||||
PKIX_PL_BasicConstraints_GetCAFlag;
|
||||
PKIX_PL_BasicConstraints_GetPathLenConstraint;
|
||||
PKIX_PL_BigInt_Create;
|
||||
PKIX_PL_ByteArray_Create;
|
||||
PKIX_PL_ByteArray_GetLength;
|
||||
PKIX_PL_ByteArray_GetPointer;
|
||||
PKIX_PL_Cert_AreCertPoliciesCritical;
|
||||
PKIX_PL_Cert_CheckNameConstraints;
|
||||
PKIX_PL_Cert_CheckValidity;
|
||||
PKIX_PL_Cert_Create;
|
||||
pkix_pl_Cert_CreateToList;
|
||||
pkix_pl_Cert_CreateWithNSSCert;
|
||||
PKIX_PL_Cert_GetAuthorityInfoAccess;
|
||||
PKIX_PL_Cert_GetAuthorityKeyIdentifier;
|
||||
PKIX_PL_Cert_GetBasicConstraints;
|
||||
PKIX_PL_Cert_GetCriticalExtensionOIDs;
|
||||
PKIX_PL_Cert_GetExtendedKeyUsage;
|
||||
PKIX_PL_Cert_GetInhibitAnyPolicy;
|
||||
PKIX_PL_Cert_GetIssuer;
|
||||
PKIX_PL_Cert_GetNameConstraints;
|
||||
PKIX_PL_Cert_GetPolicyInformation;
|
||||
PKIX_PL_Cert_GetPolicyMappingInhibited;
|
||||
PKIX_PL_Cert_GetPolicyMappings;
|
||||
PKIX_PL_Cert_GetRequireExplicitPolicy;
|
||||
PKIX_PL_Cert_GetSerialNumber;
|
||||
PKIX_PL_Cert_GetSubject;
|
||||
PKIX_PL_Cert_GetSubjectAltNames;
|
||||
PKIX_PL_Cert_GetSubjectInfoAccess;
|
||||
PKIX_PL_Cert_GetSubjectKeyIdentifier;
|
||||
PKIX_PL_Cert_GetSubjectPublicKey;
|
||||
PKIX_PL_Cert_GetSubjectPublicKeyAlgId;
|
||||
PKIX_PL_Cert_GetVersion;
|
||||
PKIX_PL_Cert_IsCertTrusted;
|
||||
PKIX_PL_Cert_MergeNameConstraints;
|
||||
PKIX_PL_Cert_VerifyKeyUsage;
|
||||
PKIX_PL_Cert_VerifySignature;
|
||||
PKIX_PL_CertPolicyInfo_GetPolicyId;
|
||||
PKIX_PL_CertPolicyInfo_GetPolQualifiers;
|
||||
PKIX_PL_CertPolicyMap_GetIssuerDomainPolicy;
|
||||
PKIX_PL_CertPolicyMap_GetSubjectDomainPolicy;
|
||||
PKIX_PL_CollectionCertStore_Create;
|
||||
PKIX_PL_CRL_Create;
|
||||
pkix_pl_CRL_CreateToList;
|
||||
PKIX_PL_CRL_GetCriticalExtensionOIDs;
|
||||
PKIX_PL_CRL_GetCRLEntryForSerialNumber;
|
||||
PKIX_PL_CRL_GetIssuer;
|
||||
PKIX_PL_CRL_VerifySignature;
|
||||
PKIX_PL_CRLEntry_GetCriticalExtensionOIDs;
|
||||
PKIX_PL_CRLEntry_GetCRLEntryReasonCode;
|
||||
PKIX_PL_Date_Create_UTCTime;
|
||||
pkix_pl_Date_CreateFromPRTime;
|
||||
pkix_pl_Date_GetPRTime;
|
||||
PKIX_PL_EkuChecker_Initialize;
|
||||
PKIX_PL_Free;
|
||||
PKIX_PL_GeneralName_Create;
|
||||
PKIX_PL_GetString;
|
||||
PKIX_PL_HashTable_Add;
|
||||
PKIX_PL_HashTable_Create;
|
||||
PKIX_PL_HashTable_Lookup;
|
||||
PKIX_PL_HashTable_Remove;
|
||||
PKIX_PL_HttpCertStore_Create;
|
||||
pkix_pl_HttpCertStore_CreateWithAsciiName;
|
||||
PKIX_PL_Initialize;
|
||||
PKIX_PL_InfoAccess_GetMethod;
|
||||
PKIX_PL_InfoAccess_GetLocation;
|
||||
PKIX_PL_InfoAccess_GetLocationType;
|
||||
PKIX_PL_LdapCertStore_Create;
|
||||
PKIX_PL_LdapClient_InitiateRequest;
|
||||
PKIX_PL_LdapClient_ResumeRequest;
|
||||
PKIX_PL_LdapDefaultClient_AbandonRequest;
|
||||
PKIX_PL_LdapDefaultClient_Create;
|
||||
PKIX_PL_LdapDefaultClient_CreateByName;
|
||||
pkix_pl_LdapResponse_Create;
|
||||
PKIX_PL_Malloc;
|
||||
PKIX_PL_Memcpy;
|
||||
PKIX_PL_MonitorLock_Create;
|
||||
PKIX_PL_MonitorLock_Enter;
|
||||
PKIX_PL_MonitorLock_Exit;
|
||||
PKIX_PL_Mutex_Create;
|
||||
PKIX_PL_Mutex_Lock;
|
||||
PKIX_PL_Mutex_Unlock;
|
||||
PKIX_PL_NssContext_Create;
|
||||
PKIX_PL_Object_Alloc;
|
||||
PKIX_PL_Object_Compare;
|
||||
PKIX_PL_Object_DecRef;
|
||||
PKIX_PL_Object_Duplicate;
|
||||
PKIX_PL_Object_Equals;
|
||||
PKIX_PL_Object_GetType;
|
||||
PKIX_PL_Object_Hashcode;
|
||||
PKIX_PL_Object_IncRef;
|
||||
PKIX_PL_Object_IsTypeRegistered;
|
||||
PKIX_PL_Object_Lock;
|
||||
PKIX_PL_Object_RegisterType;
|
||||
PKIX_PL_Object_ToString;
|
||||
PKIX_PL_Object_Unlock;
|
||||
PKIX_PL_OID_Create;
|
||||
pkix_pl_OcspRequest_Create;
|
||||
pkix_pl_OcspResponse_Create;
|
||||
pkix_pl_OcspResponse_Decode;
|
||||
pkix_pl_OcspResponse_GetStatus;
|
||||
pkix_pl_OcspResponse_GetStatusForCert;
|
||||
PKIX_PL_OcspResponse_UseBuildChain;
|
||||
pkix_pl_OcspResponse_VerifySignature;
|
||||
PKIX_PL_Pk11CertStore_Create;
|
||||
PKIX_PL_PolicyQualifier_GetPolicyQualifierId;
|
||||
PKIX_PL_PolicyQualifier_GetQualifier;
|
||||
PKIX_PL_PublicKey_MakeInheritedDSAPublicKey;
|
||||
PKIX_PL_PublicKey_NeedsDSAParameters;
|
||||
PKIX_PL_Realloc;
|
||||
PKIX_PL_ReleaseReaderLock;
|
||||
PKIX_PL_ReleaseWriterLock;
|
||||
PKIX_PL_RWLock_Create;
|
||||
PKIX_PL_Shutdown;
|
||||
pkix_pl_Socket_Create;
|
||||
pkix_pl_Socket_CreateByName;
|
||||
pkix_pl_Socket_GetCallbackList;
|
||||
PKIX_PL_Sprintf;
|
||||
PKIX_PL_String_Create;
|
||||
PKIX_PL_String_GetEncoded;
|
||||
PKIX_PL_X500Name_Create;
|
||||
pkix_pl_X500Name_GetCommonName;
|
||||
pkix_pl_X500Name_GetCountryName;
|
||||
pkix_pl_X500Name_GetOrgName;
|
||||
PKIX_PL_X500Name_Match;
|
||||
pkix_PolicyNode_AddToParent;
|
||||
pkix_PolicyNode_Create;
|
||||
PKIX_PolicyNode_GetChildren;
|
||||
PKIX_PolicyNode_GetDepth;
|
||||
PKIX_PolicyNode_GetExpectedPolicies;
|
||||
PKIX_PolicyNode_GetParent;
|
||||
PKIX_PolicyNode_GetPolicyQualifiers;
|
||||
PKIX_PolicyNode_GetValidPolicy;
|
||||
PKIX_PolicyNode_IsCritical;
|
||||
pkix_PolicyNode_Prune;
|
||||
PKIX_ProcessingParams_AddCertChainChecker;
|
||||
PKIX_ProcessingParams_AddCertStore;
|
||||
PKIX_ProcessingParams_AddRevocationChecker;
|
||||
PKIX_ProcessingParams_Create;
|
||||
PKIX_ProcessingParams_GetCertChainCheckers;
|
||||
PKIX_ProcessingParams_GetCertStores;
|
||||
PKIX_ProcessingParams_GetDate;
|
||||
PKIX_ProcessingParams_GetHintCerts;
|
||||
PKIX_ProcessingParams_GetInitialPolicies;
|
||||
PKIX_ProcessingParams_GetPolicyQualifiersRejected;
|
||||
PKIX_ProcessingParams_GetResourceLimits;
|
||||
PKIX_ProcessingParams_GetRevocationCheckers;
|
||||
PKIX_ProcessingParams_GetTargetCertConstraints;
|
||||
PKIX_ProcessingParams_GetTrustAnchors;
|
||||
PKIX_ProcessingParams_IsAnyPolicyInhibited;
|
||||
PKIX_ProcessingParams_IsCRLRevocationCheckingEnabled;
|
||||
PKIX_ProcessingParams_IsExplicitPolicyRequired;
|
||||
PKIX_ProcessingParams_IsPolicyMappingInhibited;
|
||||
PKIX_ProcessingParams_SetAnyPolicyInhibited;
|
||||
PKIX_ProcessingParams_SetCertChainCheckers;
|
||||
PKIX_ProcessingParams_SetCertStores;
|
||||
PKIX_ProcessingParams_SetDate;
|
||||
PKIX_ProcessingParams_SetExplicitPolicyRequired;
|
||||
PKIX_ProcessingParams_SetHintCerts;
|
||||
PKIX_ProcessingParams_SetInitialPolicies;
|
||||
PKIX_ProcessingParams_SetPolicyMappingInhibited;
|
||||
PKIX_ProcessingParams_SetPolicyQualifiersRejected;
|
||||
PKIX_ProcessingParams_SetResourceLimits;
|
||||
PKIX_ProcessingParams_SetRevocationCheckers;
|
||||
PKIX_ProcessingParams_SetRevocationEnabled;
|
||||
PKIX_ProcessingParams_SetTargetCertConstraints;
|
||||
PKIX_RevocationChecker_Create;
|
||||
PKIX_RevocationChecker_GetRevCallback;
|
||||
PKIX_RevocationChecker_GetRevCheckerContext;
|
||||
PKIX_Shutdown;
|
||||
pkix_Throw;
|
||||
PKIX_TrustAnchor_CreateWithCert;
|
||||
PKIX_TrustAnchor_CreateWithNameKeyPair;
|
||||
PKIX_TrustAnchor_GetCAName;
|
||||
PKIX_TrustAnchor_GetCAPublicKey;
|
||||
PKIX_TrustAnchor_GetNameConstraints;
|
||||
PKIX_TrustAnchor_GetTrustedCert;
|
||||
PKIX_ValidateChain;
|
||||
PKIX_ValidateChain_NB;
|
||||
PKIX_ValidateParams_Create;
|
||||
PKIX_ValidateParams_GetCertChain;
|
||||
PKIX_ValidateParams_GetProcessingParams;
|
||||
pkix_ValidateResult_Create;
|
||||
PKIX_ValidateResult_GetPolicyTree;
|
||||
PKIX_ValidateResult_GetPublicKey;
|
||||
PKIX_ValidateResult_GetTrustAnchor;
|
||||
pkix_VerifyNode_AddToChain;
|
||||
pkix_VerifyNode_Create;
|
||||
PKIX_ResourceLimits_Create;
|
||||
PKIX_ResourceLimits_GetMaxDepth;
|
||||
PKIX_ResourceLimits_GetMaxFanout;
|
||||
PKIX_ResourceLimits_GetMaxTime;
|
||||
PKIX_ResourceLimits_SetMaxDepth;
|
||||
PKIX_ResourceLimits_SetMaxFanout;
|
||||
PKIX_ResourceLimits_SetMaxTime;
|
||||
;+};
|
||||
@@ -1,826 +0,0 @@
|
||||
/*
|
||||
* NSS utility functions
|
||||
*
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is the Network Security Services libraries.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Sun Microsystems, Inc.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2007
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "secport.h"
|
||||
#include "secoid.h"
|
||||
#include "secitem.h"
|
||||
#include "secdig.h"
|
||||
#include "secder.h"
|
||||
#include "secasn1.h"
|
||||
#include "base64.h"
|
||||
#include "nssb64.h"
|
||||
#include "nssrwlk.h"
|
||||
#include "nsslocks.h"
|
||||
#include "cert.h"
|
||||
|
||||
/* wrappers for implementation in libnssutil3 */
|
||||
#undef __nss_InitLock
|
||||
#undef ATOB_AsciiToData
|
||||
#undef ATOB_ConvertAsciiToItem
|
||||
#undef BTOA_ConvertItemToAscii
|
||||
#undef BTOA_DataToAscii
|
||||
#undef CERT_GenTime2FormattedAscii
|
||||
#undef DER_AsciiToTime
|
||||
#undef DER_DecodeTimeChoice
|
||||
#undef DER_Encode
|
||||
#undef DER_EncodeTimeChoice
|
||||
#undef DER_GeneralizedDayToAscii
|
||||
#undef DER_GeneralizedTimeToTime
|
||||
#undef DER_GetInteger
|
||||
#undef DER_Lengths
|
||||
#undef DER_TimeChoiceDayToAscii
|
||||
#undef DER_TimeToGeneralizedTime
|
||||
#undef DER_TimeToGeneralizedTimeArena
|
||||
#undef DER_TimeToUTCTime
|
||||
#undef DER_UTCDayToAscii
|
||||
#undef DER_UTCTimeToAscii
|
||||
#undef DER_UTCTimeToTime
|
||||
#undef NSS_PutEnv
|
||||
#undef NSSBase64_DecodeBuffer
|
||||
#undef NSSBase64_EncodeItem
|
||||
#undef NSSBase64Decoder_Create
|
||||
#undef NSSBase64Decoder_Destroy
|
||||
#undef NSSBase64Decoder_Update
|
||||
#undef NSSBase64Encoder_Create
|
||||
#undef NSSBase64Encoder_Destroy
|
||||
#undef NSSBase64Encoder_Update
|
||||
#undef NSSRWLock_Destroy
|
||||
#undef NSSRWLock_HaveWriteLock
|
||||
#undef NSSRWLock_LockRead
|
||||
#undef NSSRWLock_LockWrite
|
||||
#undef NSSRWLock_New
|
||||
#undef NSSRWLock_UnlockRead
|
||||
#undef NSSRWLock_UnlockWrite
|
||||
#undef PORT_Alloc
|
||||
#undef PORT_ArenaAlloc
|
||||
#undef PORT_ArenaGrow
|
||||
#undef PORT_ArenaMark
|
||||
#undef PORT_ArenaRelease
|
||||
#undef PORT_ArenaStrdup
|
||||
#undef PORT_ArenaUnmark
|
||||
#undef PORT_ArenaZAlloc
|
||||
#undef PORT_Free
|
||||
#undef PORT_FreeArena
|
||||
#undef PORT_GetError
|
||||
#undef PORT_NewArena
|
||||
#undef PORT_Realloc
|
||||
#undef PORT_SetError
|
||||
#undef PORT_SetUCS2_ASCIIConversionFunction
|
||||
#undef PORT_SetUCS2_UTF8ConversionFunction
|
||||
#undef PORT_SetUCS4_UTF8ConversionFunction
|
||||
#undef PORT_Strdup
|
||||
#undef PORT_UCS2_ASCIIConversion
|
||||
#undef PORT_UCS2_UTF8Conversion
|
||||
#undef PORT_ZAlloc
|
||||
#undef PORT_ZFree
|
||||
#undef SEC_ASN1Decode
|
||||
#undef SEC_ASN1DecodeInteger
|
||||
#undef SEC_ASN1DecodeItem
|
||||
#undef SEC_ASN1DecoderAbort
|
||||
#undef SEC_ASN1DecoderClearFilterProc
|
||||
#undef SEC_ASN1DecoderClearNotifyProc
|
||||
#undef SEC_ASN1DecoderFinish
|
||||
#undef SEC_ASN1DecoderSetFilterProc
|
||||
#undef SEC_ASN1DecoderSetNotifyProc
|
||||
#undef SEC_ASN1DecoderStart
|
||||
#undef SEC_ASN1DecoderUpdate
|
||||
#undef SEC_ASN1Encode
|
||||
#undef SEC_ASN1EncodeInteger
|
||||
#undef SEC_ASN1EncodeItem
|
||||
#undef SEC_ASN1EncoderAbort
|
||||
#undef SEC_ASN1EncoderClearNotifyProc
|
||||
#undef SEC_ASN1EncoderClearStreaming
|
||||
#undef SEC_ASN1EncoderClearTakeFromBuf
|
||||
#undef SEC_ASN1EncoderFinish
|
||||
#undef SEC_ASN1EncoderSetNotifyProc
|
||||
#undef SEC_ASN1EncoderSetStreaming
|
||||
#undef SEC_ASN1EncoderSetTakeFromBuf
|
||||
#undef SEC_ASN1EncoderStart
|
||||
#undef SEC_ASN1EncoderUpdate
|
||||
#undef SEC_ASN1EncodeUnsignedInteger
|
||||
#undef SEC_ASN1LengthLength
|
||||
#undef SEC_QuickDERDecodeItem
|
||||
#undef SECITEM_AllocItem
|
||||
#undef SECITEM_ArenaDupItem
|
||||
#undef SECITEM_CompareItem
|
||||
#undef SECITEM_CopyItem
|
||||
#undef SECITEM_DupItem
|
||||
#undef SECITEM_FreeItem
|
||||
#undef SECITEM_ItemsAreEqual
|
||||
#undef SECITEM_ZfreeItem
|
||||
#undef SECOID_AddEntry
|
||||
#undef SECOID_CompareAlgorithmID
|
||||
#undef SECOID_CopyAlgorithmID
|
||||
#undef SECOID_DestroyAlgorithmID
|
||||
#undef SECOID_FindOID
|
||||
#undef SECOID_FindOIDByTag
|
||||
#undef SECOID_FindOIDTag
|
||||
#undef SECOID_FindOIDTagDescription
|
||||
#undef SECOID_GetAlgorithmTag
|
||||
#undef SECOID_SetAlgorithmID
|
||||
#undef SGN_CompareDigestInfo
|
||||
#undef SGN_CopyDigestInfo
|
||||
#undef SGN_CreateDigestInfo
|
||||
#undef SGN_DestroyDigestInfo
|
||||
|
||||
void *
|
||||
PORT_Alloc(size_t bytes)
|
||||
{
|
||||
return PORT_Alloc_Util(bytes);
|
||||
}
|
||||
|
||||
void *
|
||||
PORT_Realloc(void *oldptr, size_t bytes)
|
||||
{
|
||||
return PORT_Realloc_Util(oldptr, bytes);
|
||||
}
|
||||
|
||||
void *
|
||||
PORT_ZAlloc(size_t bytes)
|
||||
{
|
||||
return PORT_ZAlloc_Util(bytes);
|
||||
}
|
||||
|
||||
void
|
||||
PORT_Free(void *ptr)
|
||||
{
|
||||
PORT_Free_Util(ptr);
|
||||
}
|
||||
|
||||
void
|
||||
PORT_ZFree(void *ptr, size_t len)
|
||||
{
|
||||
PORT_ZFree_Util(ptr, len);
|
||||
}
|
||||
|
||||
char *
|
||||
PORT_Strdup(const char *str)
|
||||
{
|
||||
return PORT_Strdup_Util(str);
|
||||
}
|
||||
|
||||
void
|
||||
PORT_SetError(int value)
|
||||
{
|
||||
PORT_SetError_Util(value);
|
||||
}
|
||||
|
||||
int
|
||||
PORT_GetError(void)
|
||||
{
|
||||
return PORT_GetError_Util();
|
||||
}
|
||||
|
||||
PLArenaPool *
|
||||
PORT_NewArena(unsigned long chunksize)
|
||||
{
|
||||
return PORT_NewArena_Util(chunksize);
|
||||
}
|
||||
|
||||
void *
|
||||
PORT_ArenaAlloc(PLArenaPool *arena, size_t size)
|
||||
{
|
||||
return PORT_ArenaAlloc_Util(arena, size);
|
||||
}
|
||||
|
||||
void *
|
||||
PORT_ArenaZAlloc(PLArenaPool *arena, size_t size)
|
||||
{
|
||||
return PORT_ArenaZAlloc_Util(arena, size);
|
||||
}
|
||||
|
||||
void
|
||||
PORT_FreeArena(PLArenaPool *arena, PRBool zero)
|
||||
{
|
||||
PORT_FreeArena_Util(arena, zero);
|
||||
}
|
||||
|
||||
void *
|
||||
PORT_ArenaGrow(PLArenaPool *arena, void *ptr, size_t oldsize, size_t newsize)
|
||||
{
|
||||
return PORT_ArenaGrow_Util(arena, ptr, oldsize, newsize);
|
||||
}
|
||||
|
||||
void *
|
||||
PORT_ArenaMark(PLArenaPool *arena)
|
||||
{
|
||||
return PORT_ArenaMark_Util(arena);
|
||||
}
|
||||
|
||||
void
|
||||
PORT_ArenaRelease(PLArenaPool *arena, void *mark)
|
||||
{
|
||||
PORT_ArenaRelease_Util(arena, mark);
|
||||
}
|
||||
|
||||
void
|
||||
PORT_ArenaUnmark(PLArenaPool *arena, void *mark)
|
||||
{
|
||||
PORT_ArenaUnmark_Util(arena, mark);
|
||||
}
|
||||
|
||||
char *
|
||||
PORT_ArenaStrdup(PLArenaPool *arena, const char *str)
|
||||
{
|
||||
return PORT_ArenaStrdup_Util(arena, str);
|
||||
}
|
||||
|
||||
void
|
||||
PORT_SetUCS4_UTF8ConversionFunction(PORTCharConversionFunc convFunc)
|
||||
{
|
||||
PORT_SetUCS4_UTF8ConversionFunction_Util(convFunc);
|
||||
}
|
||||
|
||||
void
|
||||
PORT_SetUCS2_ASCIIConversionFunction(PORTCharConversionWSwapFunc convFunc)
|
||||
{
|
||||
PORT_SetUCS2_ASCIIConversionFunction_Util(convFunc);
|
||||
}
|
||||
|
||||
void
|
||||
PORT_SetUCS2_UTF8ConversionFunction(PORTCharConversionFunc convFunc)
|
||||
{
|
||||
PORT_SetUCS2_UTF8ConversionFunction_Util(convFunc);
|
||||
}
|
||||
|
||||
PRBool
|
||||
PORT_UCS2_UTF8Conversion(PRBool toUnicode, unsigned char *inBuf,
|
||||
unsigned int inBufLen, unsigned char *outBuf,
|
||||
unsigned int maxOutBufLen, unsigned int *outBufLen)
|
||||
{
|
||||
return PORT_UCS2_UTF8Conversion_Util(toUnicode, inBuf, inBufLen, outBuf,
|
||||
maxOutBufLen, outBufLen);
|
||||
}
|
||||
|
||||
PRBool
|
||||
PORT_UCS2_ASCIIConversion(PRBool toUnicode, unsigned char *inBuf,
|
||||
unsigned int inBufLen, unsigned char *outBuf,
|
||||
unsigned int maxOutBufLen, unsigned int *outBufLen,
|
||||
PRBool swapBytes)
|
||||
{
|
||||
return PORT_UCS2_ASCIIConversion_Util(toUnicode, inBuf, inBufLen, outBuf,
|
||||
maxOutBufLen, outBufLen, swapBytes);
|
||||
}
|
||||
|
||||
int
|
||||
NSS_PutEnv(const char * envVarName, const char * envValue)
|
||||
{
|
||||
return NSS_PutEnv_Util(envVarName, envValue);
|
||||
}
|
||||
|
||||
SECOidData *SECOID_FindOID( const SECItem *oid)
|
||||
{
|
||||
return SECOID_FindOID_Util(oid);
|
||||
}
|
||||
|
||||
SECOidTag SECOID_FindOIDTag(const SECItem *oid)
|
||||
{
|
||||
return SECOID_FindOIDTag_Util(oid);
|
||||
}
|
||||
|
||||
SECOidData *SECOID_FindOIDByTag(SECOidTag tagnum)
|
||||
{
|
||||
return SECOID_FindOIDByTag_Util(tagnum);
|
||||
}
|
||||
|
||||
SECStatus SECOID_SetAlgorithmID(PRArenaPool *arena, SECAlgorithmID *aid,
|
||||
SECOidTag tag, SECItem *params)
|
||||
{
|
||||
return SECOID_SetAlgorithmID_Util(arena, aid, tag, params);
|
||||
}
|
||||
|
||||
SECStatus SECOID_CopyAlgorithmID(PRArenaPool *arena, SECAlgorithmID *dest,
|
||||
SECAlgorithmID *src)
|
||||
{
|
||||
return SECOID_CopyAlgorithmID_Util(arena, dest, src);
|
||||
}
|
||||
|
||||
SECOidTag SECOID_GetAlgorithmTag(SECAlgorithmID *aid)
|
||||
{
|
||||
return SECOID_GetAlgorithmTag_Util(aid);
|
||||
}
|
||||
|
||||
void SECOID_DestroyAlgorithmID(SECAlgorithmID *aid, PRBool freeit)
|
||||
{
|
||||
SECOID_DestroyAlgorithmID_Util(aid, freeit);
|
||||
}
|
||||
|
||||
SECComparison SECOID_CompareAlgorithmID(SECAlgorithmID *a,
|
||||
SECAlgorithmID *b)
|
||||
{
|
||||
return SECOID_CompareAlgorithmID_Util(a, b);
|
||||
}
|
||||
|
||||
const char *SECOID_FindOIDTagDescription(SECOidTag tagnum)
|
||||
{
|
||||
return SECOID_FindOIDTagDescription_Util(tagnum);
|
||||
}
|
||||
|
||||
SECOidTag SECOID_AddEntry(const SECOidData * src)
|
||||
{
|
||||
return SECOID_AddEntry_Util(src);
|
||||
}
|
||||
|
||||
SECItem *SECITEM_AllocItem(PRArenaPool *arena, SECItem *item,
|
||||
unsigned int len)
|
||||
{
|
||||
return SECITEM_AllocItem_Util(arena, item, len);
|
||||
}
|
||||
|
||||
SECComparison SECITEM_CompareItem(const SECItem *a, const SECItem *b)
|
||||
{
|
||||
return SECITEM_CompareItem_Util(a, b);
|
||||
}
|
||||
|
||||
PRBool SECITEM_ItemsAreEqual(const SECItem *a, const SECItem *b)
|
||||
{
|
||||
return SECITEM_ItemsAreEqual_Util(a, b);
|
||||
}
|
||||
|
||||
SECStatus SECITEM_CopyItem(PRArenaPool *arena, SECItem *to,
|
||||
const SECItem *from)
|
||||
{
|
||||
return SECITEM_CopyItem_Util(arena, to, from);
|
||||
}
|
||||
|
||||
SECItem *SECITEM_DupItem(const SECItem *from)
|
||||
{
|
||||
return SECITEM_DupItem_Util(from);
|
||||
}
|
||||
|
||||
SECItem *SECITEM_ArenaDupItem(PRArenaPool *arena, const SECItem *from)
|
||||
{
|
||||
return SECITEM_ArenaDupItem_Util(arena, from);
|
||||
}
|
||||
|
||||
void SECITEM_FreeItem(SECItem *zap, PRBool freeit)
|
||||
{
|
||||
SECITEM_FreeItem_Util(zap, freeit);
|
||||
}
|
||||
|
||||
void SECITEM_ZfreeItem(SECItem *zap, PRBool freeit)
|
||||
{
|
||||
SECITEM_ZfreeItem_Util(zap, freeit);
|
||||
}
|
||||
|
||||
SGNDigestInfo *SGN_CreateDigestInfo(SECOidTag algorithm,
|
||||
unsigned char *sig,
|
||||
unsigned int sigLen)
|
||||
{
|
||||
return SGN_CreateDigestInfo_Util(algorithm, sig, sigLen);
|
||||
}
|
||||
|
||||
void SGN_DestroyDigestInfo(SGNDigestInfo *info)
|
||||
{
|
||||
SGN_DestroyDigestInfo_Util(info);
|
||||
}
|
||||
|
||||
SECStatus SGN_CopyDigestInfo(PRArenaPool *poolp,
|
||||
SGNDigestInfo *a,
|
||||
SGNDigestInfo *b)
|
||||
{
|
||||
return SGN_CopyDigestInfo_Util(poolp, a, b);
|
||||
}
|
||||
|
||||
SECComparison SGN_CompareDigestInfo(SGNDigestInfo *a, SGNDigestInfo *b)
|
||||
{
|
||||
return SGN_CompareDigestInfo_Util(a, b);
|
||||
}
|
||||
|
||||
SECStatus DER_Encode(PRArenaPool *arena, SECItem *dest, DERTemplate *t,
|
||||
void *src)
|
||||
{
|
||||
return DER_Encode_Util(arena, dest, t, src);
|
||||
}
|
||||
|
||||
SECStatus DER_Lengths(SECItem *item, int *header_len_p,
|
||||
PRUint32 *contents_len_p)
|
||||
{
|
||||
return DER_Lengths_Util(item, header_len_p, contents_len_p);
|
||||
}
|
||||
|
||||
long DER_GetInteger(SECItem *src)
|
||||
{
|
||||
return DER_GetInteger_Util(src);
|
||||
}
|
||||
|
||||
SECStatus DER_TimeToUTCTime(SECItem *result, int64 time)
|
||||
{
|
||||
return DER_TimeToUTCTime_Util(result, time);
|
||||
}
|
||||
|
||||
SECStatus DER_AsciiToTime(int64 *result, const char *string)
|
||||
{
|
||||
return DER_AsciiToTime_Util(result, string);
|
||||
}
|
||||
|
||||
SECStatus DER_UTCTimeToTime(int64 *result, const SECItem *time)
|
||||
{
|
||||
return DER_UTCTimeToTime_Util(result, time);
|
||||
}
|
||||
|
||||
char *DER_UTCTimeToAscii(SECItem *utcTime)
|
||||
{
|
||||
return DER_UTCTimeToAscii_Util(utcTime);
|
||||
}
|
||||
|
||||
char *DER_UTCDayToAscii(SECItem *utctime)
|
||||
{
|
||||
return DER_UTCDayToAscii_Util(utctime);
|
||||
}
|
||||
|
||||
char *DER_GeneralizedDayToAscii(SECItem *gentime)
|
||||
{
|
||||
return DER_GeneralizedDayToAscii_Util(gentime);
|
||||
}
|
||||
|
||||
char *DER_TimeChoiceDayToAscii(SECItem *timechoice)
|
||||
{
|
||||
return DER_TimeChoiceDayToAscii_Util(timechoice);
|
||||
}
|
||||
|
||||
SECStatus DER_TimeToGeneralizedTime(SECItem *dst, int64 gmttime)
|
||||
{
|
||||
return DER_TimeToGeneralizedTime_Util(dst, gmttime);
|
||||
}
|
||||
|
||||
SECStatus DER_TimeToGeneralizedTimeArena(PRArenaPool* arenaOpt,
|
||||
SECItem *dst, int64 gmttime)
|
||||
{
|
||||
return DER_TimeToGeneralizedTimeArena_Util(arenaOpt, dst, gmttime);
|
||||
}
|
||||
|
||||
SECStatus DER_GeneralizedTimeToTime(int64 *dst, const SECItem *time)
|
||||
{
|
||||
return DER_GeneralizedTimeToTime_Util(dst, time);
|
||||
}
|
||||
|
||||
char *CERT_GenTime2FormattedAscii (int64 genTime, char *format)
|
||||
{
|
||||
return CERT_GenTime2FormattedAscii_Util(genTime, format);
|
||||
}
|
||||
|
||||
SECStatus DER_DecodeTimeChoice(PRTime* output, const SECItem* input)
|
||||
{
|
||||
return DER_DecodeTimeChoice_Util(output, input);
|
||||
}
|
||||
|
||||
SECStatus DER_EncodeTimeChoice(PRArenaPool* arena, SECItem* output,
|
||||
PRTime input)
|
||||
{
|
||||
return DER_EncodeTimeChoice_Util(arena, output, input);
|
||||
}
|
||||
|
||||
SEC_ASN1DecoderContext *SEC_ASN1DecoderStart(PRArenaPool *pool,
|
||||
void *dest,
|
||||
const SEC_ASN1Template *t)
|
||||
{
|
||||
return SEC_ASN1DecoderStart_Util(pool, dest, t);
|
||||
}
|
||||
|
||||
SECStatus SEC_ASN1DecoderUpdate(SEC_ASN1DecoderContext *cx,
|
||||
const char *buf,
|
||||
unsigned long len)
|
||||
{
|
||||
return SEC_ASN1DecoderUpdate_Util(cx, buf, len);
|
||||
}
|
||||
|
||||
SECStatus SEC_ASN1DecoderFinish(SEC_ASN1DecoderContext *cx)
|
||||
{
|
||||
return SEC_ASN1DecoderFinish_Util(cx);
|
||||
}
|
||||
|
||||
void SEC_ASN1DecoderAbort(SEC_ASN1DecoderContext *cx, int error)
|
||||
{
|
||||
SEC_ASN1DecoderAbort_Util(cx, error);
|
||||
}
|
||||
|
||||
void SEC_ASN1DecoderSetFilterProc(SEC_ASN1DecoderContext *cx,
|
||||
SEC_ASN1WriteProc fn,
|
||||
void *arg, PRBool no_store)
|
||||
{
|
||||
SEC_ASN1DecoderSetFilterProc_Util(cx, fn, arg, no_store);
|
||||
}
|
||||
|
||||
void SEC_ASN1DecoderClearFilterProc(SEC_ASN1DecoderContext *cx)
|
||||
{
|
||||
SEC_ASN1DecoderClearFilterProc_Util(cx);
|
||||
}
|
||||
|
||||
void SEC_ASN1DecoderSetNotifyProc(SEC_ASN1DecoderContext *cx,
|
||||
SEC_ASN1NotifyProc fn,
|
||||
void *arg)
|
||||
{
|
||||
SEC_ASN1DecoderSetNotifyProc_Util(cx, fn, arg);
|
||||
}
|
||||
|
||||
void SEC_ASN1DecoderClearNotifyProc(SEC_ASN1DecoderContext *cx)
|
||||
{
|
||||
SEC_ASN1DecoderClearNotifyProc_Util(cx);
|
||||
}
|
||||
|
||||
SECStatus SEC_ASN1Decode(PRArenaPool *pool, void *dest,
|
||||
const SEC_ASN1Template *t,
|
||||
const char *buf, long len)
|
||||
{
|
||||
return SEC_ASN1Decode_Util(pool, dest, t, buf, len);
|
||||
}
|
||||
|
||||
SECStatus SEC_ASN1DecodeItem(PRArenaPool *pool, void *dest,
|
||||
const SEC_ASN1Template *t,
|
||||
const SECItem *src)
|
||||
{
|
||||
return SEC_ASN1DecodeItem_Util(pool, dest, t, src);
|
||||
}
|
||||
|
||||
SECStatus SEC_QuickDERDecodeItem(PRArenaPool* arena, void* dest,
|
||||
const SEC_ASN1Template* templateEntry,
|
||||
const SECItem* src)
|
||||
{
|
||||
return SEC_QuickDERDecodeItem_Util(arena, dest, templateEntry, src);
|
||||
}
|
||||
|
||||
SEC_ASN1EncoderContext *SEC_ASN1EncoderStart(const void *src,
|
||||
const SEC_ASN1Template *t,
|
||||
SEC_ASN1WriteProc fn,
|
||||
void *output_arg)
|
||||
{
|
||||
return SEC_ASN1EncoderStart_Util(src, t, fn, output_arg);
|
||||
}
|
||||
|
||||
SECStatus SEC_ASN1EncoderUpdate(SEC_ASN1EncoderContext *cx,
|
||||
const char *buf,
|
||||
unsigned long len)
|
||||
{
|
||||
return SEC_ASN1EncoderUpdate_Util(cx, buf, len);
|
||||
}
|
||||
|
||||
void SEC_ASN1EncoderFinish(SEC_ASN1EncoderContext *cx)
|
||||
{
|
||||
SEC_ASN1EncoderFinish_Util(cx);
|
||||
}
|
||||
|
||||
void SEC_ASN1EncoderAbort(SEC_ASN1EncoderContext *cx, int error)
|
||||
{
|
||||
SEC_ASN1EncoderAbort_Util(cx, error);
|
||||
}
|
||||
|
||||
void SEC_ASN1EncoderSetNotifyProc(SEC_ASN1EncoderContext *cx,
|
||||
SEC_ASN1NotifyProc fn,
|
||||
void *arg)
|
||||
{
|
||||
SEC_ASN1EncoderSetNotifyProc_Util(cx, fn, arg);
|
||||
}
|
||||
|
||||
void SEC_ASN1EncoderClearNotifyProc(SEC_ASN1EncoderContext *cx)
|
||||
{
|
||||
SEC_ASN1EncoderClearNotifyProc_Util(cx);
|
||||
}
|
||||
|
||||
void SEC_ASN1EncoderSetStreaming(SEC_ASN1EncoderContext *cx)
|
||||
{
|
||||
SEC_ASN1EncoderSetStreaming_Util(cx);
|
||||
}
|
||||
|
||||
void SEC_ASN1EncoderClearStreaming(SEC_ASN1EncoderContext *cx)
|
||||
{
|
||||
SEC_ASN1EncoderClearStreaming_Util(cx);
|
||||
}
|
||||
|
||||
void SEC_ASN1EncoderSetTakeFromBuf(SEC_ASN1EncoderContext *cx)
|
||||
{
|
||||
SEC_ASN1EncoderSetTakeFromBuf_Util(cx);
|
||||
}
|
||||
|
||||
void SEC_ASN1EncoderClearTakeFromBuf(SEC_ASN1EncoderContext *cx)
|
||||
{
|
||||
SEC_ASN1EncoderClearTakeFromBuf_Util(cx);
|
||||
}
|
||||
|
||||
SECStatus SEC_ASN1Encode(const void *src, const SEC_ASN1Template *t,
|
||||
SEC_ASN1WriteProc output_proc,
|
||||
void *output_arg)
|
||||
{
|
||||
return SEC_ASN1Encode_Util(src, t, output_proc, output_arg);
|
||||
}
|
||||
|
||||
SECItem * SEC_ASN1EncodeItem(PRArenaPool *pool, SECItem *dest,
|
||||
const void *src, const SEC_ASN1Template *t)
|
||||
{
|
||||
return SEC_ASN1EncodeItem_Util(pool, dest, src, t);
|
||||
}
|
||||
|
||||
SECItem * SEC_ASN1EncodeInteger(PRArenaPool *pool,
|
||||
SECItem *dest, long value)
|
||||
{
|
||||
return SEC_ASN1EncodeInteger_Util(pool, dest, value);
|
||||
}
|
||||
|
||||
SECItem * SEC_ASN1EncodeUnsignedInteger(PRArenaPool *pool,
|
||||
SECItem *dest,
|
||||
unsigned long value)
|
||||
{
|
||||
return SEC_ASN1EncodeUnsignedInteger_Util(pool, dest, value);
|
||||
}
|
||||
|
||||
SECStatus SEC_ASN1DecodeInteger(SECItem *src,
|
||||
unsigned long *value)
|
||||
{
|
||||
return SEC_ASN1DecodeInteger_Util(src, value);
|
||||
}
|
||||
|
||||
int SEC_ASN1LengthLength (unsigned long len)
|
||||
{
|
||||
return SEC_ASN1LengthLength_Util(len);
|
||||
}
|
||||
|
||||
char *BTOA_DataToAscii(const unsigned char *data, unsigned int len)
|
||||
{
|
||||
return BTOA_DataToAscii_Util(data, len);
|
||||
}
|
||||
|
||||
unsigned char *ATOB_AsciiToData(const char *string, unsigned int *lenp)
|
||||
{
|
||||
return ATOB_AsciiToData_Util(string, lenp);
|
||||
}
|
||||
|
||||
SECStatus ATOB_ConvertAsciiToItem(SECItem *binary_item, char *ascii)
|
||||
{
|
||||
return ATOB_ConvertAsciiToItem_Util(binary_item, ascii);
|
||||
}
|
||||
|
||||
char *BTOA_ConvertItemToAscii(SECItem *binary_item)
|
||||
{
|
||||
return BTOA_ConvertItemToAscii_Util(binary_item);
|
||||
}
|
||||
|
||||
NSSBase64Decoder *
|
||||
NSSBase64Decoder_Create (PRInt32 (*output_fn) (void *, const unsigned char *,
|
||||
PRInt32),
|
||||
void *output_arg)
|
||||
{
|
||||
return NSSBase64Decoder_Create_Util(output_fn, output_arg);
|
||||
}
|
||||
|
||||
NSSBase64Encoder *
|
||||
NSSBase64Encoder_Create (PRInt32 (*output_fn) (void *, const char *, PRInt32),
|
||||
void *output_arg)
|
||||
{
|
||||
return NSSBase64Encoder_Create_Util(output_fn, output_arg);
|
||||
}
|
||||
|
||||
SECStatus
|
||||
NSSBase64Decoder_Update (NSSBase64Decoder *data, const char *buffer,
|
||||
PRUint32 size)
|
||||
{
|
||||
return NSSBase64Decoder_Update_Util(data, buffer, size);
|
||||
}
|
||||
|
||||
SECStatus
|
||||
NSSBase64Encoder_Update (NSSBase64Encoder *data, const unsigned char *buffer,
|
||||
PRUint32 size)
|
||||
{
|
||||
return NSSBase64Encoder_Update_Util(data, buffer, size);
|
||||
}
|
||||
|
||||
SECStatus
|
||||
NSSBase64Decoder_Destroy (NSSBase64Decoder *data, PRBool abort_p)
|
||||
{
|
||||
return NSSBase64Decoder_Destroy_Util(data, abort_p);
|
||||
}
|
||||
|
||||
SECStatus
|
||||
NSSBase64Encoder_Destroy (NSSBase64Encoder *data, PRBool abort_p)
|
||||
{
|
||||
return NSSBase64Encoder_Destroy_Util(data, abort_p);
|
||||
}
|
||||
|
||||
SECItem *
|
||||
NSSBase64_DecodeBuffer (PRArenaPool *arenaOpt, SECItem *outItemOpt,
|
||||
const char *inStr, unsigned int inLen)
|
||||
{
|
||||
return NSSBase64_DecodeBuffer_Util(arenaOpt, outItemOpt, inStr, inLen);
|
||||
}
|
||||
|
||||
char *
|
||||
NSSBase64_EncodeItem (PRArenaPool *arenaOpt, char *outStrOpt,
|
||||
unsigned int maxOutLen, SECItem *inItem)
|
||||
{
|
||||
return NSSBase64_EncodeItem_Util(arenaOpt, outStrOpt, maxOutLen, inItem);
|
||||
}
|
||||
|
||||
NSSRWLock* NSSRWLock_New(PRUint32 lock_rank, const char *lock_name)
|
||||
{
|
||||
return NSSRWLock_New_Util(lock_rank, lock_name);
|
||||
}
|
||||
|
||||
void NSSRWLock_Destroy(NSSRWLock *lock)
|
||||
{
|
||||
NSSRWLock_Destroy_Util(lock);
|
||||
}
|
||||
|
||||
void NSSRWLock_LockRead(NSSRWLock *lock)
|
||||
{
|
||||
NSSRWLock_LockRead_Util(lock);
|
||||
}
|
||||
|
||||
void NSSRWLock_LockWrite(NSSRWLock *lock)
|
||||
{
|
||||
NSSRWLock_LockWrite_Util(lock);
|
||||
}
|
||||
|
||||
void NSSRWLock_UnlockRead(NSSRWLock *lock)
|
||||
{
|
||||
NSSRWLock_UnlockRead_Util(lock);
|
||||
}
|
||||
|
||||
void NSSRWLock_UnlockWrite(NSSRWLock *lock)
|
||||
{
|
||||
NSSRWLock_UnlockWrite_Util(lock);
|
||||
}
|
||||
|
||||
PRBool NSSRWLock_HaveWriteLock(NSSRWLock *rwlock)
|
||||
{
|
||||
return NSSRWLock_HaveWriteLock_Util(rwlock);
|
||||
}
|
||||
|
||||
SECStatus __nss_InitLock( PZLock **ppLock, nssILockType ltype )
|
||||
{
|
||||
return __nss_InitLock_Util(ppLock, ltype);
|
||||
}
|
||||
|
||||
/* templates duplicated in libnss3 and libnssutil3 */
|
||||
|
||||
#undef NSS_Get_SEC_AnyTemplate
|
||||
#undef NSS_Get_SEC_BitStringTemplate
|
||||
#undef NSS_Get_SEC_BMPStringTemplate
|
||||
#undef NSS_Get_SEC_BooleanTemplate
|
||||
#undef NSS_Get_SEC_GeneralizedTimeTemplate
|
||||
#undef NSS_Get_SEC_IA5StringTemplate
|
||||
#undef NSS_Get_SEC_IntegerTemplate
|
||||
#undef NSS_Get_SEC_NullTemplate
|
||||
#undef NSS_Get_SEC_ObjectIDTemplate
|
||||
#undef NSS_Get_SEC_OctetStringTemplate
|
||||
#undef NSS_Get_SEC_PointerToAnyTemplate
|
||||
#undef NSS_Get_SEC_PointerToOctetStringTemplate
|
||||
#undef NSS_Get_SEC_SetOfAnyTemplate
|
||||
#undef NSS_Get_SEC_UTCTimeTemplate
|
||||
#undef NSS_Get_SEC_UTF8StringTemplate
|
||||
#undef NSS_Get_SECOID_AlgorithmIDTemplate
|
||||
#undef NSS_Get_sgn_DigestInfoTemplate
|
||||
#undef SEC_AnyTemplate
|
||||
#undef SEC_BitStringTemplate
|
||||
#undef SEC_BMPStringTemplate
|
||||
#undef SEC_BooleanTemplate
|
||||
#undef SEC_GeneralizedTimeTemplate
|
||||
#undef SEC_IA5StringTemplate
|
||||
#undef SEC_IntegerTemplate
|
||||
#undef SEC_NullTemplate
|
||||
#undef SEC_ObjectIDTemplate
|
||||
#undef SEC_OctetStringTemplate
|
||||
#undef SEC_PointerToAnyTemplate
|
||||
#undef SEC_PointerToOctetStringTemplate
|
||||
#undef SEC_SetOfAnyTemplate
|
||||
#undef SEC_UTCTimeTemplate
|
||||
#undef SEC_UTF8StringTemplate
|
||||
#undef SECOID_AlgorithmIDTemplate
|
||||
#undef sgn_DigestInfoTemplate
|
||||
|
||||
#include "templates.c"
|
||||
|
||||
Reference in New Issue
Block a user