Shih-wei Liao | e94d9b2 | 2012-05-22 09:01:24 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ART_SRC_GREENLAND_TARGET_LIR_EMITTER_H_ |
| 18 | #define ART_SRC_GREENLAND_TARGET_LIR_EMITTER_H_ |
| 19 | |
| 20 | #include "dex_lang.h" |
| 21 | |
| 22 | #include "lir_function.h" |
| 23 | |
| 24 | #include <llvm/ADT/DenseMap.h> |
| 25 | |
| 26 | namespace art { |
| 27 | class OatCompilationUnit; |
| 28 | } |
| 29 | |
| 30 | namespace llvm { |
| 31 | class BasicBlock; |
| 32 | class BranchInst; |
| 33 | class CallInst; |
| 34 | class Function; |
| 35 | class ICmpInst; |
| 36 | class Instruction; |
| 37 | class IntToPtrInst; |
| 38 | class ReturnInst; |
| 39 | } |
| 40 | |
| 41 | namespace art { |
| 42 | namespace greenland { |
| 43 | |
| 44 | class LIRFunction; |
| 45 | class TargetLIRInfo; |
| 46 | |
| 47 | class TargetLIREmitter { |
| 48 | private: |
| 49 | const llvm::Function& func_; |
| 50 | const OatCompilationUnit& cunit_; |
| 51 | DexLang::Context& dex_lang_ctx_; |
| 52 | TargetLIRInfo& info_; |
| 53 | |
| 54 | private: |
| 55 | llvm::DenseMap<const llvm::BasicBlock*, LIR*> block_labels_; |
| 56 | |
| 57 | protected: |
| 58 | LIRFunction lir_func_; |
| 59 | |
| 60 | TargetLIREmitter(const llvm::Function& func, |
| 61 | const OatCompilationUnit& cunit, |
| 62 | DexLang::Context& dex_lang_ctx, |
| 63 | TargetLIRInfo& target_lir_info); |
| 64 | |
| 65 | private: |
| 66 | bool visitBasicBlock(const llvm::BasicBlock& bb); |
| 67 | |
| 68 | bool visitReturnInst(const llvm::ReturnInst& inst); |
| 69 | bool visitBranchInst(const llvm::BranchInst& inst); |
| 70 | //bool visitSwitchInst(SwitchInst &I) { DELEGATE(TerminatorInst);} |
| 71 | //bool visitIndirectBrInst(IndirectBrInst &I) { DELEGATE(TerminatorInst);} |
| 72 | //bool visitInvokeInst(InvokeInst &I) { DELEGATE(TerminatorInst);} |
| 73 | //bool visitResumeInst(ResumeInst &I) { DELEGATE(TerminatorInst);} |
| 74 | //bool visitUnreachableInst(UnreachableInst &I) { DELEGATE(TerminatorInst);} |
| 75 | bool visitICmpInst(const llvm::ICmpInst& inst); |
| 76 | //bool visitFCmpInst(FCmpInst &I) { DELEGATE(CmpInst);} |
| 77 | //bool visitAllocaInst(AllocaInst &I) { DELEGATE(UnaryInstruction);} |
| 78 | //bool visitLoadInst(LoadInst &I) { DELEGATE(UnaryInstruction);} |
| 79 | //bool visitStoreInst(StoreInst &I) { DELEGATE(Instruction);} |
| 80 | //bool visitAtomicCmpXchgInst(AtomicCmpXchgInst &I) { DELEGATE(Instruction);} |
| 81 | //bool visitAtomicRMWInst(AtomicRMWInst &I) { DELEGATE(Instruction);} |
| 82 | //bool visitFenceInst(FenceInst &I) { DELEGATE(Instruction);} |
| 83 | //bool visitGetElementPtrInst(GetElementPtrInst &I){ DELEGATE(Instruction);} |
| 84 | //bool visitPHINode(PHINode &I) { DELEGATE(Instruction);} |
| 85 | //bool visitTruncInst(TruncInst &I) { DELEGATE(CastInst);} |
| 86 | //bool visitZExtInst(ZExtInst &I) { DELEGATE(CastInst);} |
| 87 | //bool visitSExtInst(SExtInst &I) { DELEGATE(CastInst);} |
| 88 | //bool visitFPTruncInst(FPTruncInst &I) { DELEGATE(CastInst);} |
| 89 | //bool visitFPExtInst(FPExtInst &I) { DELEGATE(CastInst);} |
| 90 | //bool visitFPToUIInst(FPToUIInst &I) { DELEGATE(CastInst);} |
| 91 | //bool visitFPToSIInst(FPToSIInst &I) { DELEGATE(CastInst);} |
| 92 | //bool visitUIToFPInst(UIToFPInst &I) { DELEGATE(CastInst);} |
| 93 | //bool visitSIToFPInst(SIToFPInst &I) { DELEGATE(CastInst);} |
| 94 | //bool visitPtrToIntInst(PtrToIntInst &I) { DELEGATE(CastInst);} |
| 95 | bool visitIntToPtrInst(const llvm::IntToPtrInst& inst); |
| 96 | //bool visitBitCastInst(BitCastInst &I) { DELEGATE(CastInst);} |
| 97 | //bool visitSelectInst(SelectInst &I) { DELEGATE(Instruction);} |
| 98 | bool visitCallInst(const llvm::CallInst& inst); |
| 99 | //bool visitVAArgInst(VAArgInst &I) { DELEGATE(UnaryInstruction);} |
| 100 | //bool visitExtractElementInst(ExtractElementInst &I) { DELEGATE(Instruction);} |
| 101 | //bool visitInsertElementInst(InsertElementInst &I) { DELEGATE(Instruction);} |
| 102 | //bool visitShuffleVectorInst(ShuffleVectorInst &I) { DELEGATE(Instruction);} |
| 103 | //bool visitExtractValueInst(ExtractValueInst &I){ DELEGATE(UnaryInstruction);} |
| 104 | //bool visitInsertValueInst(InsertValueInst &I) { DELEGATE(Instruction); } |
| 105 | //bool visitLandingPadInst(LandingPadInst &I) { DELEGATE(Instruction); } |
| 106 | |
| 107 | bool visitDexLangIntrinsics(const llvm::CallInst& inst); |
| 108 | |
| 109 | public: |
| 110 | virtual ~TargetLIREmitter(); |
| 111 | |
| 112 | LIRFunction* Emit(); |
| 113 | |
| 114 | private: |
| 115 | bool EmitBasicBlockLabels(); |
| 116 | bool EmitEntrySequence(); |
| 117 | bool EmitInstructions(); |
| 118 | bool EmitExitSequence(); |
| 119 | }; |
| 120 | |
| 121 | } // namespace greenland |
| 122 | } // namespace art |
| 123 | |
| 124 | #endif // ART_SRC_GREENLAND_TARGET_LIR_EMITTER_H_ |