]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
1 | //===-- JumpInstrTableInfo.cpp: Info for Jump-Instruction Tables ----------===// |
2 | // | |
3 | // This file is distributed under the University of Illinois Open Source | |
4 | // License. See LICENSE.TXT for details. | |
5 | // | |
6 | //===----------------------------------------------------------------------===// | |
7 | /// | |
8 | /// \file | |
9 | /// \brief Information about jump-instruction tables that have been created by | |
10 | /// JumpInstrTables pass. | |
11 | /// | |
12 | //===----------------------------------------------------------------------===// | |
13 | ||
14 | #define DEBUG_TYPE "jiti" | |
15 | ||
16 | #include "llvm/Analysis/JumpInstrTableInfo.h" | |
17 | #include "llvm/Analysis/Passes.h" | |
18 | #include "llvm/IR/Function.h" | |
19 | #include "llvm/IR/Type.h" | |
85aaf69f | 20 | #include "llvm/Support/MathExtras.h" |
1a4d82fc JJ |
21 | |
22 | using namespace llvm; | |
23 | ||
24 | INITIALIZE_PASS(JumpInstrTableInfo, "jump-instr-table-info", | |
25 | "Jump-Instruction Table Info", true, true) | |
26 | char JumpInstrTableInfo::ID = 0; | |
27 | ||
28 | ImmutablePass *llvm::createJumpInstrTableInfoPass() { | |
29 | return new JumpInstrTableInfo(); | |
30 | } | |
31 | ||
85aaf69f SL |
32 | ModulePass *llvm::createJumpInstrTableInfoPass(unsigned Bound) { |
33 | // This cast is always safe, since Bound is always in a subset of uint64_t. | |
34 | uint64_t B = static_cast<uint64_t>(Bound); | |
35 | return new JumpInstrTableInfo(B); | |
36 | } | |
37 | ||
38 | JumpInstrTableInfo::JumpInstrTableInfo(uint64_t ByteAlign) | |
39 | : ImmutablePass(ID), Tables(), ByteAlignment(ByteAlign) { | |
40 | if (!llvm::isPowerOf2_64(ByteAlign)) { | |
41 | // Note that we don't explicitly handle overflow here, since we handle the 0 | |
42 | // case explicitly when a caller actually tries to create jumptable entries, | |
43 | // and this is the return value on overflow. | |
44 | ByteAlignment = llvm::NextPowerOf2(ByteAlign); | |
45 | } | |
46 | ||
1a4d82fc JJ |
47 | initializeJumpInstrTableInfoPass(*PassRegistry::getPassRegistry()); |
48 | } | |
49 | ||
50 | JumpInstrTableInfo::~JumpInstrTableInfo() {} | |
51 | ||
52 | void JumpInstrTableInfo::insertEntry(FunctionType *TableFunTy, Function *Target, | |
53 | Function *Jump) { | |
54 | Tables[TableFunTy].push_back(JumpPair(Target, Jump)); | |
55 | } |