Debian Codegraph @

visa/iga/IGALibrary/IR/Block.hpp

raw
1 /*========================== begin_copyright_notice ============================
2
3 Copyright (C) 2017-2021 Intel Corporation
4
5 SPDX-License-Identifier: MIT
6
7 ============================= end_copyright_notice ===========================*/
8
9 #ifndef IGA_BLOCK_HPP
10 #define IGA_BLOCK_HPP
11
12 // WARNING: this internal IR is subject to change without any notice.
13 // External tools should use the official interfaces in the external
14 // API (IGA/api). Those interfaces are tested between releases and maintained
15 // even with changes to the internal IR (within reason).
16 #include "../ErrorHandler.hpp"
17 #include "../MemManager/MemManager.hpp"
18 #include "../MemManager/StdArenaAllocator.hpp"
19 #include "Instruction.hpp"
20
21 #include <list>
22 #include <map>
23
24 namespace iga {
25 typedef std::list<iga::Instruction *,
26 std_arena_based_allocator<iga::Instruction *>>
27 InstList;
28 typedef InstList::iterator InstListIterator;
29
30 class Block {
31 public:
32 Block(int32_t pc = -1, const Loc &loc = Loc::INVALID)
33 : m_offset(pc), m_loc(loc), m_id(pc) {}
34 ~Block() {
35 // Destruct instructions. The memory allocated for them will be
36 // de-allocated by the top-level MemManager allocator, but we need
37 // to explicitly call ~Instruction() to cleanup Instruction members
38 // which don't use MemManager-allocated memory
39 for (auto inst : m_instructions) {
40 inst->~Instruction();
41 }
42 }
43
44 void operator delete(void *, MemManager *) {}
45 void *operator new(size_t sz, MemManager *m) { return m->alloc(sz); }
46
47 void appendInstruction(Instruction *inst) { m_instructions.push_back(inst); }
48
49 PC getPC() const { return m_offset; }
50 void setPC(PC pc) { m_offset = pc; }
51 Loc getLoc() const { return m_loc; }
52 void setLoc(const Loc &loc) { m_loc = loc; }
53 void setID(int id) { m_id = id; }
54 int getID() const { return m_id; }
55 const InstList &getInstList() const { return m_instructions; }
56 InstList &getInstList() { return m_instructions; }
57 void insertInstBefore(InstList::iterator iter, Instruction *inst);
58
59 // infers the control flow graph
60 // sets the Block* within these instructions
61 static std::map<int32_t, Block *>
62 inferBlocks(ErrorHandler &errHandler, MemManager &mem, InstList &insts);
63
64 private:
65 int32_t m_offset;
66 Loc m_loc; // optional src location
67 InstList m_instructions;
68 int m_id;
69
70 Block(const Block &) = delete;
71 Block &operator=(const Block &) = delete;
72 }; // class Block
73 } // namespace iga
74
75 #endif // BLOCK_HPP