Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for LLVM address spaces #148

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

peterohanley
Copy link

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.

@@ -414,7 +414,7 @@ iT :: Word32 -> Type
iT = PrimType . Integer

ptrT :: Type -> Type
ptrT = PtrTo
ptrT = PtrTo (AddrSpace 0)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you factor AddrSpace 0 out into its own definition? Something like this (with an appropriate Haddock comment):

defaultAddrSpace :: AddrSpace
defaultAddrSpace = Addr 0

And 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.

Copy link
Collaborator

@RyanGlScott RyanGlScott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've done an initial pass (without having yet looked at the corresponding llvm-pretty-bc-parser changes).

Comment on lines +890 to +892
newtype AddrSpace = AddrSpace
{ getAddrSpace :: Int
} deriving (Data, Eq, Generic, Ord, Show, Typeable) -- , Bits, FiniteBits)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +890 to +892
newtype AddrSpace = AddrSpace
{ getAddrSpace :: Int
} deriving (Data, Eq, Generic, Ord, Show, Typeable) -- , Bits, FiniteBits)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this comment referring to?

@@ -414,7 +414,7 @@ iT :: Word32 -> Type
iT = PrimType . Integer

ptrT :: Type -> Type
ptrT = PtrTo
ptrT = PtrTo (AddrSpace 0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you factor AddrSpace 0 out into its own definition? Something like this (with an appropriate Haddock comment):

defaultAddrSpace :: AddrSpace
defaultAddrSpace = Addr 0

And 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.

@@ -284,7 +290,7 @@ type DataLayout = [LayoutSpec]
data LayoutSpec
= 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"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +356 to 357
ppAddrSpace (gaAddrSpace ga) <+>
constant
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

<+> ppMaybe (\s -> "section" <+> doubleQuotes (text s)) (defSection d)
<+> ppMaybe (\gc -> "gc" <+> ppGC gc) (defGC d)
<+> ppMds (defMetadata d)
<+> char '{'
$+$ vcat (map ppBasicBlock (defBody d))
$+$ vcat (punctuate "" $ map ppBasicBlock (defBody d))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the motivation for this change?

Comment on lines -481 to +504
DefaultVisibility -> "default"
DefaultVisibility -> empty
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the motivation for this change?

@@ -947,7 +984,7 @@ ppConstExpr' pp expr =
ConstArith op a b -> ppArithOp op <+> ppTuple a b
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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the motivation for this change?

| LocalUnnamedAddr
deriving (Data, Eq, Generic, Ord, Show, Typeable)

newtype AddrSpace = AddrSpace
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

, gaConstant :: Bool
} deriving (Data, Eq, Generic, Ord, Show, Typeable)

emptyGlobalAttrs :: GlobalAttrs
emptyGlobalAttrs = GlobalAttrs
{ gaLinkage = Nothing
, gaVisibility = Nothing
, gaUnnamedAddr = Nothing
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing gaThreadLocality = Nothing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants