1// Licensed to the .NET Foundation under one or more agreements.
2// The .NET Foundation licenses this file to you under the MIT license.
3// See the LICENSE file in the project root for more information.
4
5//
6// This include file determines how BlockSet is implemented.
7//
8#ifndef _BLOCKSET_INCLUDED_
9#define _BLOCKSET_INCLUDED_ 1
10
11// A BlockSet is a set of BasicBlocks, represented by the BasicBlock number (bbNum).
12// Unlike VARSET_TP, we only support a single implementation: the bitset "shortlong"
13// implementation.
14//
15// Note that BasicBlocks in the JIT are numbered starting at 1. We always just waste the
16// 0th bit to avoid having to do "bbNum - 1" calculations everywhere (at the BlockSet call
17// sites). This makes reading the code easier, and avoids potential problems of forgetting
18// to do a "- 1" somewhere.
19//
20// Basic blocks can be renumbered during compilation, so it is important to not mix
21// BlockSets created before and after a renumbering. Every time the blocks are renumbered
22// creates a different "epoch", during which the basic block numbers are stable.
23
24#include "bitset.h"
25#include "compilerbitsettraits.h"
26#include "bitsetasshortlong.h"
27
28class BlockSetOps : public BitSetOps</*BitSetType*/ BitSetShortLongRep,
29 /*Brand*/ BSShortLong,
30 /*Env*/ Compiler*,
31 /*BitSetTraits*/ BasicBlockBitSetTraits>
32{
33public:
34 // Specialize BlockSetOps::MakeFull(). Since we number basic blocks from one, we remove bit zero from
35 // the block set. Otherwise, IsEmpty() would never return true.
36 static BitSetShortLongRep MakeFull(Compiler* env)
37 {
38 BitSetShortLongRep retval;
39
40 // First, make a full set using the BitSetOps::MakeFull
41
42 retval = BitSetOps</*BitSetType*/ BitSetShortLongRep,
43 /*Brand*/ BSShortLong,
44 /*Env*/ Compiler*,
45 /*BitSetTraits*/ BasicBlockBitSetTraits>::MakeFull(env);
46
47 // Now, remove element zero, since we number basic blocks starting at one, and index the set with the
48 // basic block number. If we left this, then IsEmpty() would never return true.
49 BlockSetOps::RemoveElemD(env, retval, 0);
50
51 return retval;
52 }
53};
54
55typedef BitSetShortLongRep BlockSet;
56
57// These types should be used as the types for BlockSet arguments and return values, respectively.
58typedef BlockSetOps::ValArgType BlockSet_ValArg_T;
59typedef BlockSetOps::RetValType BlockSet_ValRet_T;
60
61#endif // _BLOCKSET_INCLUDED_
62