Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 1 | // Copyright 2016 The SwiftShader Authors. All Rights Reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
Nicolas Capens | daa5d91 | 2016-09-28 16:56:36 -0400 | [diff] [blame] | 15 | #ifndef sw_LLVMRoutineManager_hpp |
| 16 | #define sw_LLVMRoutineManager_hpp |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 17 | |
| 18 | #include "llvm/GlobalValue.h" |
| 19 | #include "llvm/ExecutionEngine/JITMemoryManager.h" |
| 20 | |
| 21 | namespace sw |
| 22 | { |
Nicolas Capens | daa5d91 | 2016-09-28 16:56:36 -0400 | [diff] [blame] | 23 | class LLVMRoutine; |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 24 | |
Nicolas Capens | daa5d91 | 2016-09-28 16:56:36 -0400 | [diff] [blame] | 25 | class LLVMRoutineManager : public llvm::JITMemoryManager |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 26 | { |
| 27 | public: |
Nicolas Capens | daa5d91 | 2016-09-28 16:56:36 -0400 | [diff] [blame] | 28 | LLVMRoutineManager(); |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 29 | |
Nicolas Capens | daa5d91 | 2016-09-28 16:56:36 -0400 | [diff] [blame] | 30 | virtual ~LLVMRoutineManager(); |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 31 | |
| 32 | virtual void AllocateGOT(); |
| 33 | |
| 34 | virtual uint8_t *allocateStub(const llvm::GlobalValue *function, unsigned stubSize, unsigned alignment); |
| 35 | virtual uint8_t *startFunctionBody(const llvm::Function *function, uintptr_t &actualSize); |
| 36 | virtual void endFunctionBody(const llvm::Function *function, uint8_t *functionStart, uint8_t *functionEnd); |
| 37 | virtual uint8_t *startExceptionTable(const llvm::Function *function, uintptr_t &ActualSize); |
| 38 | virtual void endExceptionTable(const llvm::Function *function, uint8_t *tableStart, uint8_t *tableEnd, uint8_t *frameRegister); |
| 39 | virtual uint8_t *getGOTBase() const; |
| 40 | virtual uint8_t *allocateSpace(intptr_t Size, unsigned Alignment); |
| 41 | virtual uint8_t *allocateGlobal(uintptr_t Size, unsigned int Alignment); |
| 42 | virtual void deallocateFunctionBody(void *Body); |
| 43 | virtual void deallocateExceptionTable(void *ET); |
| 44 | virtual void setMemoryWritable(); |
| 45 | virtual void setMemoryExecutable(); |
| 46 | virtual void setPoisonMemory(bool poison); |
| 47 | |
Nicolas Capens | daa5d91 | 2016-09-28 16:56:36 -0400 | [diff] [blame] | 48 | LLVMRoutine *acquireRoutine(void *entry); |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 49 | |
| 50 | private: |
Nicolas Capens | daa5d91 | 2016-09-28 16:56:36 -0400 | [diff] [blame] | 51 | LLVMRoutine *routine; |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 52 | |
| 53 | static volatile int averageInstructionSize; |
| 54 | }; |
| 55 | } |
| 56 | |
Nicolas Capens | daa5d91 | 2016-09-28 16:56:36 -0400 | [diff] [blame] | 57 | #endif // sw_LLVMRoutineManager_hpp |