1 //===-- JumpInstrTableInfo.cpp: Info for Jump-Instruction Tables ----------===//
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
6 //===----------------------------------------------------------------------===//
9 /// \brief Information about jump-instruction tables that have been created by
10 /// JumpInstrTables pass.
12 //===----------------------------------------------------------------------===//
14 #define DEBUG_TYPE "jiti"
16 #include "llvm/Analysis/JumpInstrTableInfo.h"
17 #include "llvm/Analysis/Passes.h"
18 #include "llvm/IR/Function.h"
19 #include "llvm/IR/Type.h"
20 #include "llvm/Support/MathExtras.h"
24 INITIALIZE_PASS(JumpInstrTableInfo, "jump-instr-table-info",
25 "Jump-Instruction Table Info", true, true)
26 char JumpInstrTableInfo::ID = 0;
28 ImmutablePass *llvm::createJumpInstrTableInfoPass() {
29 return new JumpInstrTableInfo();
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);
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);
47 initializeJumpInstrTableInfoPass(*PassRegistry::getPassRegistry());
50 JumpInstrTableInfo::~JumpInstrTableInfo() {}
52 void JumpInstrTableInfo::insertEntry(FunctionType *TableFunTy, Function *Target,
54 Tables[TableFunTy].push_back(JumpPair(Target, Jump));