Add support for LLVM address spaces#148
Add support for LLVM address spaces#148peterohanley wants to merge 8 commits intoGaloisInc:masterfrom
Conversation
This affects many types and objects, and this work has only been tested by prettyprinting CHERI bc files.
This is required by llvm-as
|
|
||
| ptrT :: Type -> Type | ||
| ptrT = PtrTo | ||
| ptrT = PtrTo (AddrSpace 0) |
There was a problem hiding this comment.
Hardcoded 0 address space here and elsewhere is reasonable because every previous use was with 0 (nothing else existed) but additional helpers may be useful later.
There was a problem hiding this comment.
Could you factor AddrSpace 0 out into its own definition? Something like this (with an appropriate Haddock comment):
defaultAddrSpace :: AddrSpace
defaultAddrSpace = Addr 0And then use this in places where AddrSpace 0 is currently used. This would make it more obvious at a glance that AddrSpace 0 is a distinguished value, IMO.
RyanGlScott
left a comment
There was a problem hiding this comment.
I've done an initial pass (without having yet looked at the corresponding llvm-pretty-bc-parser changes).
| newtype AddrSpace = AddrSpace | ||
| { getAddrSpace :: Int | ||
| } deriving (Data, Eq, Generic, Ord, Show, Typeable) -- , Bits, FiniteBits) |
There was a problem hiding this comment.
Would you be willing to derive a Num instance for this? It would be convenient to be able to write, say, 0 instead of AddrSpace 0.
| newtype AddrSpace = AddrSpace | ||
| { getAddrSpace :: Int | ||
| } deriving (Data, Eq, Generic, Ord, Show, Typeable) -- , Bits, FiniteBits) |
There was a problem hiding this comment.
Can the commented-out code here be removed, or is there a need to keep it around?
| | LocalExec | ||
| deriving (Data, Eq, Generic, Ord, Show, Typeable) | ||
|
|
||
| -- ^ there is also None, use Nothing for it |
There was a problem hiding this comment.
What is this comment referring to?
|
|
||
| ptrT :: Type -> Type | ||
| ptrT = PtrTo | ||
| ptrT = PtrTo (AddrSpace 0) |
There was a problem hiding this comment.
Could you factor AddrSpace 0 out into its own definition? Something like this (with an appropriate Haddock comment):
defaultAddrSpace :: AddrSpace
defaultAddrSpace = Addr 0And then use this in places where AddrSpace 0 is currently used. This would make it more obvious at a glance that AddrSpace 0 is a distinguished value, IMO.
| = BigEndian | ||
| | LittleEndian | ||
| | PointerSize !Int !Int !Int (Maybe Int) -- ^ address space, size, abi, pref | ||
| | PointerSize !Bool !Int !Int !Int (Maybe Int) (Maybe Int) -- ^ fat pointer?, address space, size, abi, pref, "size of index used in GEP for address calculation" |
There was a problem hiding this comment.
Interestingly, the first Int here is intended to be an address space, but it is not using the AddrSpace type. I wonder if it should.
| ppAddrSpace (gaAddrSpace ga) <+> | ||
| constant |
There was a problem hiding this comment.
The comments above this ought to be updated, since it claims that only the value (and nothing else) is printed. Really, it ought to say that the address space and the value are printed now.
| <+> ppMds (defMetadata d) | ||
| <+> char '{' | ||
| $+$ vcat (map ppBasicBlock (defBody d)) | ||
| $+$ vcat (punctuate "" $ map ppBasicBlock (defBody d)) |
There was a problem hiding this comment.
What is the motivation for this change?
| DefaultVisibility -> "default" | ||
| DefaultVisibility -> empty |
There was a problem hiding this comment.
What is the motivation for this change?
| ConstUnaryArith op a -> ppUnaryArithOp op <+> ppTyp' a | ||
| ConstBit op a b -> ppBitOp op <+> ppTuple a b | ||
| where ppTuple a b = parens $ ppTyped ppVal' a <> comma <+> ppVal' b | ||
| where ppTuple a b = parens $ ppTyped ppVal' a <> comma <+> ppTyped ppVal' (const b <$> a) |
There was a problem hiding this comment.
What is the motivation for this change?
| | LocalUnnamedAddr | ||
| deriving (Data, Eq, Generic, Ord, Show, Typeable) | ||
|
|
||
| newtype AddrSpace = AddrSpace |
There was a problem hiding this comment.
The comments in this part of the LLVM Language Reference Manual suggest that an address space's value must be less than 2^24. Is that worth putting in the Haddocks here?
| emptyGlobalAttrs = GlobalAttrs | ||
| { gaLinkage = Nothing | ||
| , gaVisibility = Nothing | ||
| , gaUnnamedAddr = Nothing |
There was a problem hiding this comment.
Missing gaThreadLocality = Nothing?
Address spaces default to 0 and are currently mostly used by CHERI for capabilities (address space 200).
The thread_local property is properly read and reported.
Various formatting changes are implemented to more closely match llvm-dis output.