<div class="gmail_quote">2009/7/6 Bruno Cardoso Lopes <span dir="ltr"><<a href="mailto:bruno.cardoso@gmail.com">bruno.cardoso@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<div class="im">On Mon, Jul 6, 2009 at 10:55 AM, Aaron<br>Gray<<a href="mailto:aaronngray.lists@googlemail.com">aaronngray.lists@googlemail.com</a>> wrote:<br>> The ObjectCodeEmitter was ment to be inline code to be used by the<br>
> *CodeEmitter classes to end up with super fast code generation. Putting them<br>> as noninline classes is a bad idea. Basically this is why I/we parameterized<br>> the *CodeEmitter Classes in the first place.<br>
<br></div>I had problems with this in the original patch, could you send a new<br>patch with this modifications?<br></blockquote>
<div> </div>
<div> </div>
<div>Here we go. I only did the emit* methods.</div>
<div> </div>
<div>Aaron</div>
<div> </div>
<div><br>> Aaron<br>><br>>> Author: bruno<br>>> Date: Mon Jul 6 00:16:40 2009<br>>> New Revision: 74814<br>>><br>>> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=74814&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=74814&view=rev</a><br>
>> Log:<br>>> Just forgot to include the two new files<br>>><br>>> Added:<br>>> llvm/trunk/include/llvm/CodeGen/ObjectCodeEmitter.h<br>>> llvm/trunk/lib/CodeGen/ObjectCodeEmitter.cpp<br>
>><br>>> Added: llvm/trunk/include/llvm/CodeGen/ObjectCodeEmitter.h<br>>> URL:<br>>> <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/ObjectCodeEmitter.h?rev=74814&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/ObjectCodeEmitter.h?rev=74814&view=auto</a><br>
>><br>>> ==============================================================================<br>>> --- llvm/trunk/include/llvm/CodeGen/ObjectCodeEmitter.h (added)<br>>> +++ llvm/trunk/include/llvm/CodeGen/ObjectCodeEmitter.h Mon Jul 6<br>
>> 00:16:40 2009<br>>> @@ -0,0 +1,171 @@<br>>> +//===-- llvm/CodeGen/ObjectCodeEmitter.h - Object Code Emitter -*-<br>>> C++ -*-===//<br>>> +//<br>>> +// The LLVM Compiler Infrastructure<br>
>> +//<br>>> +// This file is distributed under the University of Illinois Open Source<br>>> +// License. See LICENSE.TXT for details.<br>>> +//<br>>> +//===----------------------------------------------------------------------===//<br>
>> +//<br>>> +// Generalized Object Code Emitter, works with ObjectModule and<br>>> BinaryObject.<br>>> +//<br>>> +//===----------------------------------------------------------------------===//<br>
>> +<br>>> +#ifndef LLVM_CODEGEN_OBJECTCODEEMITTER_H<br>>> +#define LLVM_CODEGEN_OBJECTCODEEMITTER_H<br>>> +<br>>> +#include "llvm/CodeGen/MachineCodeEmitter.h"<br>>> +<br>>> +namespace llvm {<br>
>> +<br>>> +class BinaryObject;<br>>> +class MachineBasicBlock;<br>>> +class MachineCodeEmitter;<br>>> +class MachineFunction;<br>>> +class MachineConstantPool;<br>>> +class MachineJumpTableInfo;<br>
>> +class MachineModuleInfo;<br>>> +<br>>> +class ObjectCodeEmitter : public MachineCodeEmitter {<br>>> +protected:<br>>> +<br>>> + /// Binary Object (Section or Segment) we are emitting to.<br>
>> + BinaryObject *BO;<br>>> +<br>>> + /// MBBLocations - This vector is a mapping from MBB ID's to their<br>>> address.<br>>> + /// It is filled in by the StartMachineBasicBlock callback and queried<br>
>> by<br>>> + /// the getMachineBasicBlockAddress callback.<br>>> + std::vector<uintptr_t> MBBLocations;<br>>> +<br>>> + /// LabelLocations - This vector is a mapping from Label ID's to their<br>
>> + /// address.<br>>> + std::vector<uintptr_t> LabelLocations;<br>>> +<br>>> + /// CPLocations - This is a map of constant pool indices to offsets<br>>> from the<br>>> + /// start of the section for that constant pool index.<br>
>> + std::vector<uintptr_t> CPLocations;<br>>> +<br>>> + /// CPSections - This is a map of constant pool indices to the Section<br>>> + /// containing the constant pool entry for that index.<br>
>> + std::vector<uintptr_t> CPSections;<br>>> +<br>>> + /// JTLocations - This is a map of jump table indices to offsets from<br>>> the<br>>> + /// start of the section for that jump table index.<br>
>> + std::vector<uintptr_t> JTLocations;<br>>> +<br>>> +public:<br>>> + ObjectCodeEmitter();<br>>> + ObjectCodeEmitter(BinaryObject *bo);<br>>> + virtual ~ObjectCodeEmitter();<br>
>> +<br>>> + /// setBinaryObject - set the BinaryObject we are writting to<br>>> + void setBinaryObject(BinaryObject *bo);<br>>> +<br>>> + /// emitByte - This callback is invoked when a byte needs to be<br>
>> + /// written to the data stream, without buffer overflow testing.<br>>> + void emitByte(uint8_t B);<br>>> +<br>>> + /// emitWordLE - This callback is invoked when a 32-bit word needs to<br>
>> be<br>
>> + /// written to the data stream in little-endian format.<br>>> + void emitWordLE(uint32_t W);<br>>> +<br>>> + /// emitWordBE - This callback is invoked when a 32-bit word needs to<br>>> be<br>
>> + /// written to the data stream in big-endian format.<br>>> + void emitWordBE(uint32_t W);<br>>> +<br>>> + /// emitDWordLE - This callback is invoked when a 64-bit word needs to<br>>> be<br>
>> + /// written to the data stream in little-endian format.<br>>> + void emitDWordLE(uint64_t W);<br>>> +<br>>> + /// emitDWordBE - This callback is invoked when a 64-bit word needs to<br>>> be<br>
>> + /// written to the data stream in big-endian format.<br>>> + void emitDWordBE(uint64_t W);<br>>> +<br>>> + /// emitAlignment - Move the CurBufferPtr pointer up the the specified<br>>> + /// alignment (saturated to BufferEnd of course).<br>
>> + void emitAlignment(unsigned Alignment = 0, uint8_t fill = 0);<br>>> +<br>>> + /// emitULEB128Bytes - This callback is invoked when a ULEB128 needs to<br>>> be<br>>> + /// written to the data stream.<br>
>> + void emitULEB128Bytes(uint64_t Value);<br>>> +<br>>> + /// emitSLEB128Bytes - This callback is invoked when a SLEB128 needs to<br>>> be<br>>> + /// written to the data stream.<br>>> + void emitSLEB128Bytes(uint64_t Value);<br>
>> +<br>>> + /// emitString - This callback is invoked when a String needs to be<br>>> + /// written to the data stream.<br>>> + void emitString(const std::string &String);<br>>> +<br>
>> + /// getCurrentPCValue - This returns the address that the next emitted<br>>> byte<br>>> + /// will be output to.<br>>> + uintptr_t getCurrentPCValue() const;<br>>> +<br>>> + /// getCurrentPCOffset - Return the offset from the start of the<br>
>> emitted<br>>> + /// buffer that we are currently writing to.<br>>> + uintptr_t getCurrentPCOffset() const;<br>>> +<br>>> + /// addRelocation - Whenever a relocatable address is needed, it should<br>
>> be<br>>> + /// noted with this interface.<br>>> + void addRelocation(const MachineRelocation& relocation);<br>>> +<br>>> + /// startFunction - This callback is invoked when the specified<br>
>> function is<br>>> + /// about to be code generated. This initializes the<br>>> BufferBegin/End/Ptr<br>>> + /// fields.<br>>> + virtual void startFunction(MachineFunction &F) = 0;<br>
>> +<br>>> + /// finishFunction - This callback is invoked when the specified<br>>> function has<br>>> + /// finished code generation. If a buffer overflow has occurred, this<br>>> method<br>
>> + /// returns true (the callee is required to try again), otherwise it<br>>> returns<br>>> + /// false.<br>>> + virtual bool finishFunction(MachineFunction &F) = 0;<br>>> +<br>>> + /// StartMachineBasicBlock - This should be called by the target when a<br>
>> new<br>>> + /// basic block is about to be emitted. This way the MCE knows where<br>>> the<br>>> + /// start of the block is, and can implement<br>>> getMachineBasicBlockAddress.<br>>> + virtual void StartMachineBasicBlock(MachineBasicBlock *MBB);<br>
>> +<br>>> + /// getMachineBasicBlockAddress - Return the address of the specified<br>>> + /// MachineBasicBlock, only usable after the label for the MBB has been<br>>> + /// emitted.<br>>> + virtual uintptr_t getMachineBasicBlockAddress(MachineBasicBlock *MBB)<br>
>> const;<br>>> +<br>>> + /// emitLabel - Emits a label<br>>> + virtual void emitLabel(uint64_t LabelID) = 0;<br>>> +<br>>> + /// getLabelAddress - Return the address of the specified LabelID, only<br>
>> usable<br>>> + /// after the LabelID has been emitted.<br>>> + virtual uintptr_t getLabelAddress(uint64_t LabelID) const = 0;<br>>> +<br>>> + /// emitJumpTables - Emit all the jump tables for a given jump table<br>
>> info<br>>> + /// record to the appropriate section.<br>>> + virtual void emitJumpTables(MachineJumpTableInfo *MJTI) = 0;<br>>> +<br>>> + /// getJumpTableEntryAddress - Return the address of the jump table<br>
>> with index<br>>> + /// 'Index' in the function that last called initJumpTableInfo.<br>>> + virtual uintptr_t getJumpTableEntryAddress(unsigned Index) const;<br>>> +<br>>> + /// emitConstantPool - For each constant pool entry, figure out which<br>
>> section<br>>> + /// the constant should live in, allocate space for it, and emit it to<br>>> the<br>>> + /// Section data buffer.<br>>> + virtual void emitConstantPool(MachineConstantPool *MCP) = 0;<br>
>> +<br>>> + /// getConstantPoolEntryAddress - Return the address of the 'Index'<br>>> entry in<br>>> + /// the constant pool that was last emitted with the emitConstantPool<br>>> method.<br>
>> + virtual uintptr_t getConstantPoolEntryAddress(unsigned Index) const;<br>>> +<br>>> + /// getConstantPoolEntrySection - Return the section of the 'Index'<br>>> entry in<br>>> + /// the constant pool that was last emitted with the emitConstantPool<br>
>> method.<br>>> + virtual uintptr_t getConstantPoolEntrySection(unsigned Index) const;<br>>> +<br>>> + /// Specifies the MachineModuleInfo object. This is used for exception<br>>> handling<br>
>> + /// purposes.<br>>> + virtual void setModuleInfo(MachineModuleInfo* Info) = 0;<br>>> + // to be implemented or depreciated with MachineModuleInfo<br>>> +<br>>> +}; // end class ObjectCodeEmitter<br>
>> +<br>>> +} // end namespace llvm<br>>> +<br>>> +#endif<br>>> +<br>>><br>>> Added: llvm/trunk/lib/CodeGen/ObjectCodeEmitter.cpp<br>>> URL:<br>>> <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/ObjectCodeEmitter.cpp?rev=74814&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/ObjectCodeEmitter.cpp?rev=74814&view=auto</a><br>
>><br>>> ==============================================================================<br>>> --- llvm/trunk/lib/CodeGen/ObjectCodeEmitter.cpp (added)<br>>> +++ llvm/trunk/lib/CodeGen/ObjectCodeEmitter.cpp Mon Jul 6 00:16:40 2009<br>
>> @@ -0,0 +1,142 @@<br>>> +//===-- llvm/CodeGen/ObjectCodeEmitter.cpp -------------------- -*-<br>>> C++ -*-===//<br>>> +//<br>>> +// The LLVM Compiler Infrastructure<br>
>> +//<br>>> +// This file is distributed under the University of Illinois Open Source<br>>> +// License. See LICENSE.TXT for details.<br>>> +//<br>>> +//===----------------------------------------------------------------------===//<br>
>> +<br>>> +#include "llvm/CodeGen/BinaryObject.h"<br>>> +#include "llvm/CodeGen/MachineBasicBlock.h"<br>>> +#include "llvm/CodeGen/MachineRelocation.h"<br>>> +#include "llvm/CodeGen/ObjectCodeEmitter.h"<br>
>> +<br>>> +//===----------------------------------------------------------------------===//<br>>> +// ObjectCodeEmitter Implementation<br>>> +//===----------------------------------------------------------------------===//<br>
>> +<br>>> +namespace llvm {<br>>> +<br>>> +ObjectCodeEmitter::ObjectCodeEmitter() : BO(0) {}<br>>> +ObjectCodeEmitter::ObjectCodeEmitter(BinaryObject *bo) : BO(bo) {}<br>>> +ObjectCodeEmitter::~ObjectCodeEmitter() {}<br>
>> +<br>>> +/// setBinaryObject - set the BinaryObject we are writting to<br>>> +void ObjectCodeEmitter::setBinaryObject(BinaryObject *bo) { BO = bo; }<br>>> +<br>>> +/// emitByte - This callback is invoked when a byte needs to be<br>
>> +/// written to the data stream, without buffer overflow testing.<br>>> +void ObjectCodeEmitter::emitByte(uint8_t B) {<br>>> + BO->emitByte(B);<br>>> +}<br>>> +<br>>> +/// emitWordLE - This callback is invoked when a 32-bit word needs to be<br>
>> +/// written to the data stream in little-endian format.<br>>> +void ObjectCodeEmitter::emitWordLE(uint32_t W) {<br>>> + BO->emitWordLE(W);<br>>> +}<br>>> +<br>>> +/// emitWordBE - This callback is invoked when a 32-bit word needs to be<br>
>> +/// written to the data stream in big-endian format.<br>>> +void ObjectCodeEmitter::emitWordBE(uint32_t W) {<br>>> + BO->emitWordBE(W);<br>>> +}<br>>> +<br>>> +/// emitDWordLE - This callback is invoked when a 64-bit word needs to be<br>
>> +/// written to the data stream in little-endian format.<br>>> +void ObjectCodeEmitter::emitDWordLE(uint64_t W) {<br>>> + BO->emitDWordLE(W);<br>>> +}<br>>> +<br>>> +/// emitDWordBE - This callback is invoked when a 64-bit word needs to be<br>
>> +/// written to the data stream in big-endian format.<br>>> +void ObjectCodeEmitter::emitDWordBE(uint64_t W) {<br>>> + BO->emitDWordBE(W);<br>>> +}<br>>> +<br>>> +/// emitAlignment - Move the CurBufferPtr pointer up the the specified<br>
>> +/// alignment (saturated to BufferEnd of course).<br>>> +void ObjectCodeEmitter::emitAlignment(unsigned Alignment /* 0 */,<br>>> + uint8_t fill /* 0 */) {<br>>> + BO->emitAlignment(Alignment, fill);<br>
>> +}<br>>> +<br>>> +/// emitULEB128Bytes - This callback is invoked when a ULEB128 needs to<br>>> be<br>>> +/// written to the data stream.<br>>> +void ObjectCodeEmitter::emitULEB128Bytes(uint64_t Value) {<br>
>> + BO->emitULEB128Bytes(Value);<br>>> +}<br>>> +<br>>> +/// emitSLEB128Bytes - This callback is invoked when a SLEB128 needs to<br>>> be<br>>> +/// written to the data stream.<br>
>> +void ObjectCodeEmitter::emitSLEB128Bytes(uint64_t Value) {<br>>> + BO->emitSLEB128Bytes(Value);<br>>> +}<br>>> +<br>>> +/// emitString - This callback is invoked when a String needs to be<br>
>> +/// written to the data stream.<br>>> +void ObjectCodeEmitter::emitString(const std::string &String) {<br>>> + BO->emitString(String);<br>>> +}<br>>> +<br>>> +/// getCurrentPCValue - This returns the address that the next emitted<br>
>> byte<br>>> +/// will be output to.<br>>> +uintptr_t ObjectCodeEmitter::getCurrentPCValue() const {<br>>> + return BO->getCurrentPCOffset();<br>>> +}<br>>> +<br>>> +/// getCurrentPCOffset - Return the offset from the start of the emitted<br>
>> +/// buffer that we are currently writing to.<br>>> +uintptr_t ObjectCodeEmitter::getCurrentPCOffset() const {<br>>> + return BO->getCurrentPCOffset();<br>>> +}<br>>> +<br>>> +/// addRelocation - Whenever a relocatable address is needed, it should<br>
>> be<br>>> +/// noted with this interface.<br>>> +void ObjectCodeEmitter::addRelocation(const MachineRelocation&<br>>> relocation) {<br>>> + BO->addRelocation(relocation);<br>>> +}<br>
>> +<br>>> +/// StartMachineBasicBlock - This should be called by the target when a<br>>> new<br>>> +/// basic block is about to be emitted. This way the MCE knows where the<br>>> +/// start of the block is, and can implement getMachineBasicBlockAddress.<br>
>> +void ObjectCodeEmitter::StartMachineBasicBlock(MachineBasicBlock *MBB) {<br>>> + if (MBBLocations.size() <= (unsigned)MBB->getNumber())<br>>> + MBBLocations.resize((MBB->getNumber()+1)*2);<br>
>> + MBBLocations[MBB->getNumber()] = getCurrentPCOffset();<br>>> +}<br>>> +<br>>> +/// getMachineBasicBlockAddress - Return the address of the specified<br>>> +/// MachineBasicBlock, only usable after the label for the MBB has been<br>
>> +/// emitted.<br>>> +uintptr_t<br>>> +ObjectCodeEmitter::getMachineBasicBlockAddress(MachineBasicBlock *MBB)<br>>> const {<br>>> + assert(MBBLocations.size() > (unsigned)MBB->getNumber() &&<br>
>> + MBBLocations[MBB->getNumber()] && "MBB not emitted!");<br>>> + return MBBLocations[MBB->getNumber()];<br>>> +}<br>>> +<br>>> +/// getJumpTableEntryAddress - Return the address of the jump table with<br>
>> index<br>>> +/// 'Index' in the function that last called initJumpTableInfo.<br>>> +uintptr_t ObjectCodeEmitter::getJumpTableEntryAddress(unsigned Index)<br>>> const {<br>>> + assert(JTLocations.size() > Index && "JT not emitted!");<br>
>> + return JTLocations[Index];<br>>> +}<br>>> +<br>>> +/// getConstantPoolEntryAddress - Return the address of the 'Index' entry<br>>> in<br>>> +/// the constant pool that was last emitted with the emitConstantPool<br>
>> method.<br>>> +uintptr_t ObjectCodeEmitter::getConstantPoolEntryAddress(unsigned Index)<br>>> const {<br>>> + assert(CPLocations.size() > Index && "CP not emitted!");<br>>> + return CPLocations[Index];<br>
>> +}<br>>> +<br>>> +/// getConstantPoolEntrySection - Return the section of the 'Index' entry<br>>> in<br>>> +/// the constant pool that was last emitted with the emitConstantPool<br>
>> method.<br>>> +uintptr_t ObjectCodeEmitter::getConstantPoolEntrySection(unsigned Index)<br>>> const {<br>>> + assert(CPSections.size() > Index && "CP not emitted!");<br>>> + return CPSections[Index];<br>
>> +}<br>>> +<br>>> +} // end namespace llvm<br>>> +<br>>><br>>><br>>> _______________________________________________<br>>> llvm-commits mailing list<br>>> <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
>> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>><br>> _______________________________________________<br>> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
><br><br><br><br></div>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid"><font color="#888888">--<br>Bruno Cardoso Lopes<br><a href="http://www.brunocardoso.cc/" target="_blank">http://www.brunocardoso.cc</a><br>
</font>
<div>
<div></div>
<div class="h5"><br>_______________________________________________<br>llvm-commits mailing list<br><a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</div></div></blockquote></div><br>