buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | #include "Dalvik.h" |
| 18 | #include "CompilerInternals.h" |
| 19 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame^] | 20 | namespace art { |
| 21 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 22 | /* Allocate a new basic block */ |
| 23 | BasicBlock* oatNewBB(BBType blockType, int blockId) |
| 24 | { |
| 25 | BasicBlock* bb = (BasicBlock* )oatNew(sizeof(BasicBlock), true); |
| 26 | bb->blockType = blockType; |
| 27 | bb->id = blockId; |
| 28 | bb->predecessors = oatAllocBitVector(blockId > 32 ? blockId : 32, |
| 29 | true /* expandable */); |
| 30 | return bb; |
| 31 | } |
| 32 | |
| 33 | /* Insert an MIR instruction to the end of a basic block */ |
| 34 | void oatAppendMIR(BasicBlock* bb, MIR* mir) |
| 35 | { |
| 36 | if (bb->firstMIRInsn == NULL) { |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 37 | DCHECK(bb->lastMIRInsn == NULL); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 38 | bb->lastMIRInsn = bb->firstMIRInsn = mir; |
| 39 | mir->prev = mir->next = NULL; |
| 40 | } else { |
| 41 | bb->lastMIRInsn->next = mir; |
| 42 | mir->prev = bb->lastMIRInsn; |
| 43 | mir->next = NULL; |
| 44 | bb->lastMIRInsn = mir; |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | /* Insert an MIR instruction to the head of a basic block */ |
| 49 | void oatPrependMIR(BasicBlock* bb, MIR* mir) |
| 50 | { |
| 51 | if (bb->firstMIRInsn == NULL) { |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 52 | DCHECK(bb->lastMIRInsn == NULL); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 53 | bb->lastMIRInsn = bb->firstMIRInsn = mir; |
| 54 | mir->prev = mir->next = NULL; |
| 55 | } else { |
| 56 | bb->firstMIRInsn->prev = mir; |
| 57 | mir->next = bb->firstMIRInsn; |
| 58 | mir->prev = NULL; |
| 59 | bb->firstMIRInsn = mir; |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | /* Insert an MIR instruction after the specified MIR */ |
| 64 | void oatInsertMIRAfter(BasicBlock* bb, MIR* currentMIR, MIR* newMIR) |
| 65 | { |
| 66 | newMIR->prev = currentMIR; |
| 67 | newMIR->next = currentMIR->next; |
| 68 | currentMIR->next = newMIR; |
| 69 | |
| 70 | if (newMIR->next) { |
| 71 | /* Is not the last MIR in the block */ |
| 72 | newMIR->next->prev = newMIR; |
| 73 | } else { |
| 74 | /* Is the last MIR in the block */ |
| 75 | bb->lastMIRInsn = newMIR; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | /* |
| 80 | * Append an LIR instruction to the LIR list maintained by a compilation |
| 81 | * unit |
| 82 | */ |
| 83 | void oatAppendLIR(CompilationUnit *cUnit, LIR* lir) |
| 84 | { |
| 85 | if (cUnit->firstLIRInsn == NULL) { |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 86 | DCHECK(cUnit->lastLIRInsn == NULL); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 87 | cUnit->lastLIRInsn = cUnit->firstLIRInsn = lir; |
| 88 | lir->prev = lir->next = NULL; |
| 89 | } else { |
| 90 | cUnit->lastLIRInsn->next = lir; |
| 91 | lir->prev = cUnit->lastLIRInsn; |
| 92 | lir->next = NULL; |
| 93 | cUnit->lastLIRInsn = lir; |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | /* |
| 98 | * Insert an LIR instruction before the current instruction, which cannot be the |
| 99 | * first instruction. |
| 100 | * |
| 101 | * prevLIR <-> newLIR <-> currentLIR |
| 102 | */ |
| 103 | void oatInsertLIRBefore(LIR* currentLIR, LIR* newLIR) |
| 104 | { |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 105 | DCHECK(currentLIR->prev != NULL); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 106 | LIR *prevLIR = currentLIR->prev; |
| 107 | |
| 108 | prevLIR->next = newLIR; |
| 109 | newLIR->prev = prevLIR; |
| 110 | newLIR->next = currentLIR; |
| 111 | currentLIR->prev = newLIR; |
| 112 | } |
| 113 | |
| 114 | /* |
| 115 | * Insert an LIR instruction after the current instruction, which cannot be the |
| 116 | * first instruction. |
| 117 | * |
| 118 | * currentLIR -> newLIR -> oldNext |
| 119 | */ |
| 120 | void oatInsertLIRAfter(LIR* currentLIR, LIR* newLIR) |
| 121 | { |
| 122 | newLIR->prev = currentLIR; |
| 123 | newLIR->next = currentLIR->next; |
| 124 | currentLIR->next = newLIR; |
| 125 | newLIR->next->prev = newLIR; |
| 126 | } |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame^] | 127 | |
| 128 | } // namespace art |