Re-order the member. (variables first method later)
diff --git a/lib/bcc/CodeEmitter.h b/lib/bcc/CodeEmitter.h
index 90e95ca..7096bcf 100644
--- a/lib/bcc/CodeEmitter.h
+++ b/lib/bcc/CodeEmitter.h
@@ -63,11 +63,22 @@
class EmittedFuncEntry;
class CodeEmitter : public llvm::JITCodeEmitter {
+ private:
+ typedef llvm::DenseMap<const llvm::GlobalValue *, void *>
+ GlobalAddressMapTy;
+
+ typedef std::map<const std::string, EmittedFuncEntry *>
+ EmittedFunctionsMapTy;
+
+ typedef llvm::DenseMap<const llvm::Function *, void*>
+ FunctionToLazyStubMapTy;
+
+ typedef std::map<llvm::AssertingVH<llvm::GlobalValue>, void *>
+ GlobalToIndirectSymMapTy;
+
public:
- typedef llvm::DenseMap<const llvm::GlobalValue*, void*> GlobalAddressMapTy;
typedef GlobalAddressMapTy::const_iterator global_addresses_const_iterator;
- GlobalAddressMapTy mGlobalAddressMap;
private:
CodeMemoryManager *mpMemMgr;
@@ -79,12 +90,13 @@
const llvm::TargetData *mpTD;
+
EmittedFuncEntry *mpCurEmitFunction;
- typedef std::map<const std::string,
- EmittedFuncEntry *> EmittedFunctionsMapTy;
EmittedFunctionsMapTy mEmittedFunctions;
+ GlobalAddressMapTy mGlobalAddressMap;
+
// This vector is a mapping from MBB ID's to their address. It is filled in
// by the StartMachineBasicBlock callback and queried by the
// getMachineBasicBlockAddress callback.
@@ -120,6 +132,145 @@
// Machine module info for exception informations
llvm::MachineModuleInfo *mpMMI;
+
+ FunctionToLazyStubMapTy mFunctionToLazyStubMap;
+
+ std::set<const llvm::Function*> PendingFunctions;
+
+ GlobalToIndirectSymMapTy GlobalToIndirectSymMap;
+
+ std::map<void*, void*> ExternalFnToStubMap;
+
+#if defined(USE_DISASSEMBLER)
+ const llvm::MCAsmInfo *mpAsmInfo;
+ const llvm::MCDisassembler *mpDisassmbler;
+ llvm::MCInstPrinter *mpIP;
+#endif
+
+ // Resolver to undefined symbol in CodeEmitter
+ BCCSymbolLookupFn mpSymbolLookupFn;
+ void *mpSymbolLookupContext;
+
+ public:
+ // Will take the ownership of @MemMgr
+ explicit CodeEmitter(CodeMemoryManager *pMemMgr);
+
+ virtual ~CodeEmitter();
+
+ void Disassemble(const llvm::StringRef &Name, uint8_t *Start,
+ size_t Length, bool IsStub);
+
+ global_addresses_const_iterator global_address_begin() const {
+ return mGlobalAddressMap.begin();
+ }
+
+ global_addresses_const_iterator global_address_end() const {
+ return mGlobalAddressMap.end();
+ }
+
+ std::vector<oBCCRelocEntry> const &getCachingRelocations() const {
+ return mCachingRelocations;
+ }
+
+ void registerSymbolCallback(BCCSymbolLookupFn pFn, BCCvoid *pContext) {
+ mpSymbolLookupFn = pFn;
+ mpSymbolLookupContext = pContext;
+ }
+
+ void setTargetMachine(llvm::TargetMachine &TM);
+
+ // This callback is invoked when the specified function is about to be code
+ // generated. This initializes the BufferBegin/End/Ptr fields.
+ virtual void startFunction(llvm::MachineFunction &F);
+
+ // This callback is invoked when the specified function has finished code
+ // generation. If a buffer overflow has occurred, this method returns true
+ // (the callee is required to try again).
+ virtual bool finishFunction(llvm::MachineFunction &F);
+
+ // Allocates and fills storage for an indirect GlobalValue, and returns the
+ // address.
+ virtual void *allocIndirectGV(const llvm::GlobalValue *GV,
+ const uint8_t *Buffer, size_t Size,
+ unsigned Alignment);
+
+ // Emits a label
+ virtual void emitLabel(llvm::MCSymbol *Label) {
+ mLabelLocations[Label] = getCurrentPCValue();
+ }
+
+ // Allocate memory for a global. Unlike allocateSpace, this method does not
+ // allocate memory in the current output buffer, because a global may live
+ // longer than the current function.
+ virtual void *allocateGlobal(uintptr_t Size, unsigned Alignment);
+
+ // This should be called by the target when a new basic block is about to be
+ // emitted. This way the MCE knows where the start of the block is, and can
+ // implement getMachineBasicBlockAddress.
+ virtual void StartMachineBasicBlock(llvm::MachineBasicBlock *MBB);
+
+ // Whenever a relocatable address is needed, it should be noted with this
+ // interface.
+ virtual void addRelocation(const llvm::MachineRelocation &MR) {
+ mRelocations.push_back(MR);
+ }
+
+ // Return the address of the @Index entry in the constant pool that was
+ // last emitted with the emitConstantPool method.
+ virtual uintptr_t getConstantPoolEntryAddress(unsigned Index) const {
+ assert(Index < mpConstantPool->getConstants().size() &&
+ "Invalid constant pool index!");
+ return mConstPoolAddresses[Index];
+ }
+
+ // Return the address of the jump table with index @Index in the function
+ // that last called initJumpTableInfo.
+ virtual uintptr_t getJumpTableEntryAddress(unsigned Index) const;
+
+ // Return the address of the specified MachineBasicBlock, only usable after
+ // the label for the MBB has been emitted.
+ virtual uintptr_t getMachineBasicBlockAddress(
+ llvm::MachineBasicBlock *MBB) const;
+
+ // Return the address of the specified LabelID, only usable after the
+ // LabelID has been emitted.
+ virtual uintptr_t getLabelAddress(llvm::MCSymbol *Label) const {
+ assert(mLabelLocations.count(Label) && "Label not emitted!");
+ return mLabelLocations.find(Label)->second;
+ }
+
+ // Specifies the MachineModuleInfo object. This is used for exception
+ // handling purposes.
+ virtual void setModuleInfo(llvm::MachineModuleInfo *Info) {
+ mpMMI = Info;
+ }
+
+ void releaseUnnecessary();
+
+ void reset();
+
+ void *lookup(const char *Name) {
+ return lookup( llvm::StringRef(Name) );
+ }
+
+ void *lookup(const llvm::StringRef &Name);
+
+ void getFunctionNames(BCCsizei *actualFunctionCount,
+ BCCsizei maxFunctionCount,
+ BCCchar **functions);
+
+ void getFunctionBinary(BCCchar *label,
+ BCCvoid **base,
+ BCCsizei *length);
+
+ private:
+ void startGVStub(const llvm::GlobalValue *GV, unsigned StubSize,
+ unsigned Alignment);
+
+ void startGVStub(void *Buffer, unsigned StubSize);
+
+ void finishGVStub();
+
// Replace an existing mapping for GV with a new address. This updates both
// maps as required. If Addr is null, the entry for the global is removed
// from the mappings.
@@ -170,17 +321,14 @@
// if available.
void *GetPointerToFunctionOrStub(llvm::Function *F);
- typedef llvm::DenseMap<const llvm::Function*,
- void*> FunctionToLazyStubMapTy;
- FunctionToLazyStubMapTy mFunctionToLazyStubMap;
-
void *GetLazyFunctionStubIfAvailable(llvm::Function *F) {
return mFunctionToLazyStubMap.lookup(F);
}
- std::set<const llvm::Function*> PendingFunctions;
void *GetLazyFunctionStub(llvm::Function *F);
+ void updateFunctionStub(const llvm::Function *F);
+
void *GetPointerToFunction(const llvm::Function *F, bool AbortOnFailure);
void *GetPointerToNamedSymbol(const std::string &Name,
@@ -196,11 +344,6 @@
void EmitGlobalVariable(const llvm::GlobalVariable *GV);
- typedef std::map<llvm::AssertingVH<llvm::GlobalValue>,
- void *> GlobalToIndirectSymMapTy;
-
- GlobalToIndirectSymMapTy GlobalToIndirectSymMap;
-
void *GetPointerToGVIndirectSym(llvm::GlobalValue *V, void *Reference);
// This is the equivalent of FunctionToLazyStubMap for external functions.
@@ -210,143 +353,10 @@
// succeed, but no single stub can guarantee that. I'll
// remove this in a subsequent checkin when I actually fix
// far calls.
- std::map<void*, void*> ExternalFnToStubMap;
// Return a stub for the function at the specified address.
void *GetExternalFunctionStub(void *FnAddr);
-#if defined(USE_DISASSEMBLER)
- const llvm::MCAsmInfo *mpAsmInfo;
- const llvm::MCDisassembler *mpDisassmbler;
- llvm::MCInstPrinter *mpIP;
-#endif
-
- public:
- void Disassemble(const llvm::StringRef &Name, uint8_t *Start,
- size_t Length, bool IsStub);
-
- private:
- // Resolver to undefined symbol in CodeEmitter
- BCCSymbolLookupFn mpSymbolLookupFn;
- void *mpSymbolLookupContext;
-
- public:
- // Will take the ownership of @MemMgr
- explicit CodeEmitter(CodeMemoryManager *pMemMgr);
-
- virtual ~CodeEmitter();
-
- global_addresses_const_iterator global_address_begin() const {
- return mGlobalAddressMap.begin();
- }
-
- global_addresses_const_iterator global_address_end() const {
- return mGlobalAddressMap.end();
- }
-
- std::vector<oBCCRelocEntry> const &getCachingRelocations() const {
- return mCachingRelocations;
- }
-
- void registerSymbolCallback(BCCSymbolLookupFn pFn, BCCvoid *pContext) {
- mpSymbolLookupFn = pFn;
- mpSymbolLookupContext = pContext;
- }
-
- void setTargetMachine(llvm::TargetMachine &TM);
-
- // This callback is invoked when the specified function is about to be code
- // generated. This initializes the BufferBegin/End/Ptr fields.
- virtual void startFunction(llvm::MachineFunction &F);
-
- // This callback is invoked when the specified function has finished code
- // generation. If a buffer overflow has occurred, this method returns true
- // (the callee is required to try again).
- virtual bool finishFunction(llvm::MachineFunction &F);
-
- void startGVStub(const llvm::GlobalValue *GV, unsigned StubSize,
- unsigned Alignment);
-
- void startGVStub(void *Buffer, unsigned StubSize);
-
- void finishGVStub();
-
- // Allocates and fills storage for an indirect GlobalValue, and returns the
- // address.
- virtual void *allocIndirectGV(const llvm::GlobalValue *GV,
- const uint8_t *Buffer, size_t Size,
- unsigned Alignment);
-
- // Emits a label
- void emitLabel(llvm::MCSymbol *Label) {
- mLabelLocations[Label] = getCurrentPCValue();
- }
-
- // Allocate memory for a global. Unlike allocateSpace, this method does not
- // allocate memory in the current output buffer, because a global may live
- // longer than the current function.
- virtual void *allocateGlobal(uintptr_t Size, unsigned Alignment);
-
- // This should be called by the target when a new basic block is about to be
- // emitted. This way the MCE knows where the start of the block is, and can
- // implement getMachineBasicBlockAddress.
- virtual void StartMachineBasicBlock(llvm::MachineBasicBlock *MBB);
-
- // Whenever a relocatable address is needed, it should be noted with this
- // interface.
- virtual void addRelocation(const llvm::MachineRelocation &MR) {
- mRelocations.push_back(MR);
- }
-
- // Return the address of the @Index entry in the constant pool that was
- // last emitted with the emitConstantPool method.
- virtual uintptr_t getConstantPoolEntryAddress(unsigned Index) const {
- assert(Index < mpConstantPool->getConstants().size() &&
- "Invalid constant pool index!");
- return mConstPoolAddresses[Index];
- }
-
- // Return the address of the jump table with index @Index in the function
- // that last called initJumpTableInfo.
- virtual uintptr_t getJumpTableEntryAddress(unsigned Index) const;
-
- // Return the address of the specified MachineBasicBlock, only usable after
- // the label for the MBB has been emitted.
- virtual uintptr_t getMachineBasicBlockAddress(
- llvm::MachineBasicBlock *MBB) const;
-
- // Return the address of the specified LabelID, only usable after the
- // LabelID has been emitted.
- virtual uintptr_t getLabelAddress(llvm::MCSymbol *Label) const {
- assert(mLabelLocations.count(Label) && "Label not emitted!");
- return mLabelLocations.find(Label)->second;
- }
-
- // Specifies the MachineModuleInfo object. This is used for exception
- // handling purposes.
- virtual void setModuleInfo(llvm::MachineModuleInfo *Info) {
- mpMMI = Info;
- }
-
- void updateFunctionStub(const llvm::Function *F);
-
- void releaseUnnecessary();
-
- void reset();
-
- void *lookup(const char *Name) {
- return lookup( llvm::StringRef(Name) );
- }
-
- void *lookup(const llvm::StringRef &Name);
-
- void getFunctionNames(BCCsizei *actualFunctionCount,
- BCCsizei maxFunctionCount,
- BCCchar **functions);
-
- void getFunctionBinary(BCCchar *label,
- BCCvoid **base,
- BCCsizei *length);
};
} // namespace bcc