diff options
| author | Ed Schouten <ed@FreeBSD.org> | 2009-06-14 09:23:33 +0000 |
|---|---|---|
| committer | Ed Schouten <ed@FreeBSD.org> | 2009-06-14 09:23:33 +0000 |
| commit | 600c6fa13de5c407dc36dbb0ab73807868741ae0 (patch) | |
| tree | 49817b316c4fdaa56d9d16ebf2555303d1a990e0 /include/llvm/CodeGen | |
| parent | 93338c197185f946619794ce011ec27b5b6250e2 (diff) | |
Notes
Diffstat (limited to 'include/llvm/CodeGen')
| -rw-r--r-- | include/llvm/CodeGen/BinaryObject.h | 325 | ||||
| -rw-r--r-- | include/llvm/CodeGen/JITCodeEmitter.h | 10 | ||||
| -rw-r--r-- | include/llvm/CodeGen/LazyLiveness.h | 63 | ||||
| -rw-r--r-- | include/llvm/CodeGen/MachineCodeEmitter.h | 10 |
4 files changed, 398 insertions, 10 deletions
diff --git a/include/llvm/CodeGen/BinaryObject.h b/include/llvm/CodeGen/BinaryObject.h new file mode 100644 index 000000000000..0780cd6ab4f4 --- /dev/null +++ b/include/llvm/CodeGen/BinaryObject.h @@ -0,0 +1,325 @@ +//===-- llvm/CodeGen/BinaryObject.h - Binary Object. -----------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines a Binary Object Aka. "blob" for holding data from code +// generators, ready for data to the object module code writters. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CODEGEN_BINARYOBJECT_H +#define LLVM_CODEGEN_BINARYOBJECT_H + +#include <string> +#include <vector> + +namespace llvm { + +class MachineRelocation; +typedef std::vector<uint8_t> BinaryData; + +class BinaryObject { +protected: + std::string Name; + bool IsLittleEndian; + bool Is64Bit; + BinaryData Data; + std::vector<MachineRelocation> Relocations; + +public: + /// Constructors and destructor + BinaryObject() {} + + BinaryObject(bool isLittleEndian, bool is64Bit) + : IsLittleEndian(isLittleEndian), Is64Bit(is64Bit) {} + + BinaryObject(const std::string &name, bool isLittleEndian, bool is64Bit) + : Name(name), IsLittleEndian(isLittleEndian), Is64Bit(is64Bit) {} + + ~BinaryObject() {} + + /// getName - get name of BinaryObject + inline std::string getName() const { return Name; } + + /// get size of binary data + size_t size() const { + return Data.size(); + } + + /// get binary data + BinaryData& getData() { + return Data; + } + + /// get machine relocations + const std::vector<MachineRelocation>& getRelocations() const { + return Relocations; + } + + /// emitByte - This callback is invoked when a byte needs to be + /// written to the data stream. + inline void emitByte(uint8_t B) { + Data.push_back(B); + } + + /// emitWord16 - This callback is invoked when a 16-bit word needs to be + /// written to the data stream in correct endian format and correct size. + inline void emitWord16(uint16_t W) { + if (IsLittleEndian) + emitWord16LE(W); + else + emitWord16BE(W); + } + + /// emitWord16LE - This callback is invoked when a 16-bit word needs to be + /// written to the data stream in correct endian format and correct size. + inline void emitWord16LE(uint16_t W) { + Data.push_back((W >> 0) & 255); + Data.push_back((W >> 8) & 255); + } + + /// emitWord16BE - This callback is invoked when a 16-bit word needs to be + /// written to the data stream in correct endian format and correct size. + inline void emitWord16BE(uint16_t W) { + Data.push_back((W >> 8) & 255); + Data.push_back((W >> 0) & 255); + } + + /// emitWord - This callback is invoked when a word needs to be + /// written to the data stream in correct endian format and correct size. + inline void emitWord(uint64_t W) { + if (!Is64Bit) + emitWord32(W); + else + emitWord64(W); + } + + /// emitWord32 - This callback is invoked when a 32-bit word needs to be + /// written to the data stream in correct endian format. + inline void emitWord32(uint32_t W) { + if (IsLittleEndian) + emitWordLE(W); + else + emitWordBE(W); + } + + /// emitWord64 - This callback is invoked when a 32-bit word needs to be + /// written to the data stream in correct endian format. + inline void emitWord64(uint64_t W) { + if (IsLittleEndian) + emitDWordLE(W); + else + emitDWordBE(W); + } + + /// emitWordLE - This callback is invoked when a 32-bit word needs to be + /// written to the data stream in little-endian format. + inline void emitWordLE(uint32_t W) { + Data.push_back((W >> 0) & 255); + Data.push_back((W >> 8) & 255); + Data.push_back((W >> 16) & 255); + Data.push_back((W >> 24) & 255); + } + + /// emitWordBE - This callback is invoked when a 32-bit word needs to be + /// written to the data stream in big-endian format. + /// + inline void emitWordBE(uint32_t W) { + Data.push_back((W >> 24) & 255); + Data.push_back((W >> 16) & 255); + Data.push_back((W >> 8) & 255); + Data.push_back((W >> 0) & 255); + } + + /// emitDWordLE - This callback is invoked when a 64-bit word needs to be + /// written to the data stream in little-endian format. + inline void emitDWordLE(uint64_t W) { + Data.push_back(unsigned(W >> 0) & 255); + Data.push_back(unsigned(W >> 8) & 255); + Data.push_back(unsigned(W >> 16) & 255); + Data.push_back(unsigned(W >> 24) & 255); + Data.push_back(unsigned(W >> 32) & 255); + Data.push_back(unsigned(W >> 40) & 255); + Data.push_back(unsigned(W >> 48) & 255); + Data.push_back(unsigned(W >> 56) & 255); + } + + /// emitDWordBE - This callback is invoked when a 64-bit word needs to be + /// written to the data stream in big-endian format. + inline void emitDWordBE(uint64_t W) { + Data.push_back(unsigned(W >> 56) & 255); + Data.push_back(unsigned(W >> 48) & 255); + Data.push_back(unsigned(W >> 40) & 255); + Data.push_back(unsigned(W >> 32) & 255); + Data.push_back(unsigned(W >> 24) & 255); + Data.push_back(unsigned(W >> 16) & 255); + Data.push_back(unsigned(W >> 8) & 255); + Data.push_back(unsigned(W >> 0) & 255); + } + + /// fixByte - This callback is invoked when a byte needs to be + /// fixup the buffer. + inline void fixByte(uint8_t B, uint32_t offset) { + Data[offset] = B; + } + + /// fixWord16 - This callback is invoked when a 16-bit word needs to + /// fixup the data stream in correct endian format. + inline void fixWord16(uint16_t W, uint32_t offset) { + if (IsLittleEndian) + fixWord16LE(W, offset); + else + fixWord16BE(W, offset); + } + + /// emitWord16LE - This callback is invoked when a 16-bit word needs to + /// fixup the data stream in little endian format. + inline void fixWord16LE(uint16_t W, uint32_t offset) { + Data[offset++] = W & 255; + Data[offset] = (W >> 8) & 255; + } + + /// fixWord16BE - This callback is invoked when a 16-bit word needs to + /// fixup data stream in big endian format. + inline void fixWord16BE(uint16_t W, uint32_t offset) { + Data[offset++] = (W >> 8) & 255; + Data[offset] = W & 255; + } + + /// emitWord - This callback is invoked when a word needs to + /// fixup the data in correct endian format and correct size. + inline void fixWord(uint64_t W, uint32_t offset) { + if (!Is64Bit) + fixWord32(W, offset); + else + fixWord64(W, offset); + } + + /// fixWord32 - This callback is invoked when a 32-bit word needs to + /// fixup the data in correct endian format. + inline void fixWord32(uint32_t W, uint32_t offset) { + if (IsLittleEndian) + fixWord32LE(W, offset); + else + fixWord32BE(W, offset); + } + + /// fixWord32LE - This callback is invoked when a 32-bit word needs to + /// fixup the data in little endian format. + inline void fixWord32LE(uint32_t W, uint32_t offset) { + Data[offset++] = W & 255; + Data[offset++] = (W >> 8) & 255; + Data[offset++] = (W >> 16) & 255; + Data[offset] = (W >> 24) & 255; + } + + /// fixWord32BE - This callback is invoked when a 32-bit word needs to + /// fixup the data in big endian format. + inline void fixWord32BE(uint32_t W, uint32_t offset) { + Data[offset++] = (W >> 24) & 255; + Data[offset++] = (W >> 16) & 255; + Data[offset++] = (W >> 8) & 255; + Data[offset] = W & 255; + } + + /// fixWord64 - This callback is invoked when a 64-bit word needs to + /// fixup the data in correct endian format. + inline void fixWord64(uint64_t W, uint32_t offset) { + if (IsLittleEndian) + fixWord64LE(W, offset); + else + fixWord64BE(W, offset); + } + + /// fixWord64BE - This callback is invoked when a 64-bit word needs to + /// fixup the data in little endian format. + inline void fixWord64LE(uint64_t W, uint32_t offset) { + Data[offset++] = W & 255; + Data[offset++] = (W >> 8) & 255; + Data[offset++] = (W >> 16) & 255; + Data[offset++] = (W >> 24) & 255; + Data[offset++] = (W >> 32) & 255; + Data[offset++] = (W >> 40) & 255; + Data[offset++] = (W >> 48) & 255; + Data[offset] = (W >> 56) & 255; + } + + /// fixWord64BE - This callback is invoked when a 64-bit word needs to + /// fixup the data in big endian format. + inline void fixWord64BE(uint64_t W, uint32_t offset) { + Data[offset++] = (W >> 56) & 255; + Data[offset++] = (W >> 48) & 255; + Data[offset++] = (W >> 40) & 255; + Data[offset++] = (W >> 32) & 255; + Data[offset++] = (W >> 24) & 255; + Data[offset++] = (W >> 16) & 255; + Data[offset++] = (W >> 8) & 255; + Data[offset] = W & 255; + } + + /// emitAlignment - Pad the data to the specified alignment. + void emitAlignment(unsigned Alignment) { + if (Alignment <= 1) return; + unsigned PadSize = -Data.size() & (Alignment-1); + for (unsigned i = 0; i<PadSize; ++i) + Data.push_back(0); + } + + /// emitULEB128Bytes - This callback is invoked when a ULEB128 needs to be + /// written to the data stream. + void emitULEB128Bytes(uint64_t Value) { + do { + unsigned char Byte = Value & 0x7f; + Value >>= 7; + if (Value) Byte |= 0x80; + emitByte(Byte); + } while (Value); + } + + /// emitSLEB128Bytes - This callback is invoked when a SLEB128 needs to be + /// written to the data stream. + void emitSLEB128Bytes(int64_t Value) { + int Sign = Value >> (8 * sizeof(Value) - 1); + bool IsMore; + + do { + unsigned char Byte = Value & 0x7f; + Value >>= 7; + IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0; + if (IsMore) Byte |= 0x80; + emitByte(Byte); + } while (IsMore); + } + + /// emitString - This callback is invoked when a String needs to be + /// written to the data stream. + void emitString(const std::string &String) { + for (unsigned i = 0, N = static_cast<unsigned>(String.size()); i<N; ++i) { + unsigned char C = String[i]; + emitByte(C); + } + emitByte(0); + } + + /// getCurrentPCOffset - Return the offset from the start of the emitted + /// buffer that we are currently writing to. + uintptr_t getCurrentPCOffset() const { + return Data.size(); + } + + /// addRelocation - Whenever a relocatable address is needed, it should be + /// noted with this interface. + void addRelocation(const MachineRelocation& relocation) { + Relocations.push_back(relocation); + } +}; + +} // end namespace llvm + +#endif + diff --git a/include/llvm/CodeGen/JITCodeEmitter.h b/include/llvm/CodeGen/JITCodeEmitter.h index bf6b76ee9001..73197af1afdc 100644 --- a/include/llvm/CodeGen/JITCodeEmitter.h +++ b/include/llvm/CodeGen/JITCodeEmitter.h @@ -97,7 +97,7 @@ public: /// emitWordLE - This callback is invoked when a 32-bit word needs to be /// written to the output stream in little-endian format. /// - void emitWordLE(unsigned W) { + void emitWordLE(uint32_t W) { if (4 <= BufferEnd-CurBufferPtr) { *CurBufferPtr++ = (uint8_t)(W >> 0); *CurBufferPtr++ = (uint8_t)(W >> 8); @@ -111,7 +111,7 @@ public: /// emitWordBE - This callback is invoked when a 32-bit word needs to be /// written to the output stream in big-endian format. /// - void emitWordBE(unsigned W) { + void emitWordBE(uint32_t W) { if (4 <= BufferEnd-CurBufferPtr) { *CurBufferPtr++ = (uint8_t)(W >> 24); *CurBufferPtr++ = (uint8_t)(W >> 16); @@ -176,7 +176,7 @@ public: /// emitULEB128Bytes - This callback is invoked when a ULEB128 needs to be /// written to the output stream. - void emitULEB128Bytes(unsigned Value) { + void emitULEB128Bytes(uint64_t Value) { do { uint8_t Byte = Value & 0x7f; Value >>= 7; @@ -187,7 +187,7 @@ public: /// emitSLEB128Bytes - This callback is invoked when a SLEB128 needs to be /// written to the output stream. - void emitSLEB128Bytes(int32_t Value) { + void emitSLEB128Bytes(int64_t Value) { int32_t Sign = Value >> (8 * sizeof(Value) - 1); bool IsMore; @@ -212,7 +212,7 @@ public: } /// emitInt32 - Emit a int32 directive. - void emitInt32(int32_t Value) { + void emitInt32(uint32_t Value) { if (4 <= BufferEnd-CurBufferPtr) { *((uint32_t*)CurBufferPtr) = Value; CurBufferPtr += 4; diff --git a/include/llvm/CodeGen/LazyLiveness.h b/include/llvm/CodeGen/LazyLiveness.h new file mode 100644 index 000000000000..82e4a153d51d --- /dev/null +++ b/include/llvm/CodeGen/LazyLiveness.h @@ -0,0 +1,63 @@ +//===- LazyLiveness.h - Lazy, CFG-invariant liveness information ----------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This pass implements a lazy liveness analysis as per "Fast Liveness Checking +// for SSA-form Programs," by Boissinot, et al. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CODEGEN_LAZYLIVENESS_H +#define LLVM_CODEGEN_LAZYLIVENESS_H + +#include "llvm/CodeGen/MachineFunctionPass.h" +#include "llvm/CodeGen/MachineDominators.h" +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/DenseSet.h" +#include "llvm/ADT/SparseBitVector.h" +#include <vector> + +namespace llvm { + +class MachineRegisterInfo; + +class LazyLiveness : public MachineFunctionPass { +public: + static char ID; // Pass identification, replacement for typeid + LazyLiveness() : MachineFunctionPass(&ID) { } + + void getAnalysisUsage(AnalysisUsage &AU) const { + AU.setPreservesAll(); + AU.addRequired<MachineDominatorTree>(); + } + + bool runOnMachineFunction(MachineFunction &mf); + + bool vregLiveIntoMBB(unsigned vreg, MachineBasicBlock* MBB); + +private: + void computeBackedgeChain(MachineFunction& mf, MachineBasicBlock* MBB); + + typedef std::pair<MachineBasicBlock*, MachineBasicBlock*> edge_t; + + MachineRegisterInfo* MRI; + + DenseMap<MachineBasicBlock*, unsigned> preorder; + std::vector<MachineBasicBlock*> rev_preorder; + DenseMap<MachineBasicBlock*, SparseBitVector<128> > rv; + DenseMap<MachineBasicBlock*, SparseBitVector<128> > tv; + DenseSet<edge_t> backedges; + SparseBitVector<128> backedge_source; + SparseBitVector<128> backedge_target; + SparseBitVector<128> calculated; +}; + +} + +#endif + diff --git a/include/llvm/CodeGen/MachineCodeEmitter.h b/include/llvm/CodeGen/MachineCodeEmitter.h index aaa41a48cb27..eb1ea2dc56b1 100644 --- a/include/llvm/CodeGen/MachineCodeEmitter.h +++ b/include/llvm/CodeGen/MachineCodeEmitter.h @@ -104,7 +104,7 @@ public: /// emitWordLE - This callback is invoked when a 32-bit word needs to be /// written to the output stream in little-endian format. /// - void emitWordLE(unsigned W) { + void emitWordLE(uint32_t W) { if (4 <= BufferEnd-CurBufferPtr) { *CurBufferPtr++ = (uint8_t)(W >> 0); *CurBufferPtr++ = (uint8_t)(W >> 8); @@ -118,7 +118,7 @@ public: /// emitWordBE - This callback is invoked when a 32-bit word needs to be /// written to the output stream in big-endian format. /// - void emitWordBE(unsigned W) { + void emitWordBE(uint32_t W) { if (4 <= BufferEnd-CurBufferPtr) { *CurBufferPtr++ = (uint8_t)(W >> 24); *CurBufferPtr++ = (uint8_t)(W >> 16); @@ -183,7 +183,7 @@ public: /// emitULEB128Bytes - This callback is invoked when a ULEB128 needs to be /// written to the output stream. - void emitULEB128Bytes(unsigned Value) { + void emitULEB128Bytes(uint64_t Value) { do { uint8_t Byte = Value & 0x7f; Value >>= 7; @@ -194,8 +194,8 @@ public: /// emitSLEB128Bytes - This callback is invoked when a SLEB128 needs to be /// written to the output stream. - void emitSLEB128Bytes(int32_t Value) { - int32_t Sign = Value >> (8 * sizeof(Value) - 1); + void emitSLEB128Bytes(uint64_t Value) { + uint64_t Sign = Value >> (8 * sizeof(Value) - 1); bool IsMore; do { |
