X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FCodeGen%2FMachineJumpTableInfo.h;h=928145d279b6bc6848f0494df44fc3d3de87dcd6;hb=53e98a2c4aa7065f4136c5263b14192036c1e056;hp=3da85ae21e89f7f9e0abb04803dc2cbce61c4429;hpb=acd80ac7bb19f8bdfa55336d567c9ecbe695c8b8;p=oota-llvm.git diff --git a/include/llvm/CodeGen/MachineJumpTableInfo.h b/include/llvm/CodeGen/MachineJumpTableInfo.h index 3da85ae21e8..928145d279b 100644 --- a/include/llvm/CodeGen/MachineJumpTableInfo.h +++ b/include/llvm/CodeGen/MachineJumpTableInfo.h @@ -2,17 +2,17 @@ // // The LLVM Compiler Infrastructure // -// This file was developed by Nate Begeman and is distributed under the -// University of Illinois Open Source License. See LICENSE.TXT for details. +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // // The MachineJumpTableInfo class keeps track of jump tables referenced by // lowered switch instructions in the MachineFunction. // -// Instructions reference the address of these jump tables through the use of -// MO_JumpTableIndex values. When emitting assembly or machine code, these -// virtual address references are converted to refer to the address of the +// Instructions reference the address of these jump tables through the use of +// MO_JumpTableIndex values. When emitting assembly or machine code, these +// virtual address references are converted to refer to the address of the // function jump tables. // //===----------------------------------------------------------------------===// @@ -21,34 +21,77 @@ #define LLVM_CODEGEN_MACHINEJUMPTABLEINFO_H #include -#include +#include namespace llvm { class MachineBasicBlock; -class TargetData; +class DataLayout; +class raw_ostream; /// MachineJumpTableEntry - One jump table in the jump table info. /// struct MachineJumpTableEntry { /// MBBs - The vector of basic blocks from which to create the jump table. std::vector MBBs; - - MachineJumpTableEntry(const std::vector &M) : MBBs(M) {} + + explicit MachineJumpTableEntry(const std::vector &M) + : MBBs(M) {} }; - + class MachineJumpTableInfo { - const TargetData *TD; - unsigned EntrySize; +public: + /// JTEntryKind - This enum indicates how each entry of the jump table is + /// represented and emitted. + enum JTEntryKind { + /// EK_BlockAddress - Each entry is a plain address of block, e.g.: + /// .word LBB123 + EK_BlockAddress, + + /// EK_GPRel64BlockAddress - Each entry is an address of block, encoded + /// with a relocation as gp-relative, e.g.: + /// .gpdword LBB123 + EK_GPRel64BlockAddress, + + /// EK_GPRel32BlockAddress - Each entry is an address of block, encoded + /// with a relocation as gp-relative, e.g.: + /// .gprel32 LBB123 + EK_GPRel32BlockAddress, + + /// EK_LabelDifference32 - Each entry is the address of the block minus + /// the address of the jump table. This is used for PIC jump tables where + /// gprel32 is not supported. e.g.: + /// .word LBB123 - LJTI1_2 + /// If the .set directive is supported, this is emitted as: + /// .set L4_5_set_123, LBB123 - LJTI1_2 + /// .word L4_5_set_123 + EK_LabelDifference32, + + /// EK_Inline - Jump table entries are emitted inline at their point of + /// use. It is the responsibility of the target to emit the entries. + EK_Inline, + + /// EK_Custom32 - Each entry is a 32-bit value that is custom lowered by the + /// TargetLowering::LowerCustomJumpTableEntry hook. + EK_Custom32 + }; +private: + JTEntryKind EntryKind; std::vector JumpTables; public: - MachineJumpTableInfo(const TargetData *td, unsigned ES) - : TD(td), EntrySize(ES) {} - - /// getJumpTableIndex - Create a new jump table or return an existing one. + explicit MachineJumpTableInfo(JTEntryKind Kind): EntryKind(Kind) {} + + JTEntryKind getEntryKind() const { return EntryKind; } + + /// getEntrySize - Return the size of each entry in the jump table. + unsigned getEntrySize(const DataLayout &TD) const; + /// getEntryAlignment - Return the alignment of each entry in the jump table. + unsigned getEntryAlignment(const DataLayout &TD) const; + + /// createJumpTableIndex - Create a new jump table. /// - unsigned getJumpTableIndex(const std::vector &DestBBs); - + unsigned createJumpTableIndex(const std::vector &DestBBs); + /// isEmpty - Return true if there are no jump tables. /// bool isEmpty() const { return JumpTables.empty(); } @@ -56,42 +99,28 @@ public: const std::vector &getJumpTables() const { return JumpTables; } - - /// RemoveJumpTable - Mark the specific index as being dead. This will cause - /// it to not be emitted. + + /// RemoveJumpTable - Mark the specific index as being dead. This will + /// prevent it from being emitted. void RemoveJumpTable(unsigned Idx) { JumpTables[Idx].MBBs.clear(); } - + /// ReplaceMBBInJumpTables - If Old is the target of any jump tables, update /// the jump tables to branch to New instead. - bool ReplaceMBBInJumpTables(MachineBasicBlock *Old, MachineBasicBlock *New) { - assert(Old != New && "Not making a change?"); - bool MadeChange = false; - for (unsigned i = 0, e = JumpTables.size(); i != e; ++i) { - MachineJumpTableEntry &JTE = JumpTables[i]; - for (unsigned j = 0, e = JTE.MBBs.size(); j != e; ++j) - if (JTE.MBBs[j] == Old) { - JTE.MBBs[j] = New; - MadeChange = true; - } - } - return MadeChange; - } - - /// getEntrySize - Returns the size of an individual field in a jump table. - /// - unsigned getEntrySize() const { return EntrySize; } - - /// getAlignment - returns the target's preferred alignment for jump tables - unsigned getAlignment() const; - + bool ReplaceMBBInJumpTables(MachineBasicBlock *Old, MachineBasicBlock *New); + + /// ReplaceMBBInJumpTable - If Old is a target of the jump tables, update + /// the jump table to branch to New instead. + bool ReplaceMBBInJumpTable(unsigned Idx, MachineBasicBlock *Old, + MachineBasicBlock *New); + /// print - Used by the MachineFunction printer to print information about /// jump tables. Implemented in MachineFunction.cpp /// - void print(std::ostream &OS) const; + void print(raw_ostream &OS) const; - /// dump - Call print(std::cerr) to be called from the debugger. + /// dump - Call to stderr. /// void dump() const; };