Commit 77e899c3 authored by dterei's avatar dterei
Browse files

LLVM: Use the inbounds keyword for getelementptr instructions.

parent 12ec40c5
......@@ -171,12 +171,13 @@ data LlvmExpression
{- |
Navigate in an structure, selecting elements
* inbound: Is the pointer inbounds? (computed pointer doesn't overflow)
* ptr: Location of the structure
* indexes: A list of indexes to select the correct value. For example
the first element of the third element of the structure ptr
is selected with [3,1] (zero indexed)
-}
| GetElemPtr LlvmVar [Int]
| GetElemPtr Bool LlvmVar [Int]
{- |
Cast the variable from to the to type. This is an abstraction of three
......
......@@ -177,7 +177,7 @@ ppLlvmExpression expr
Call tp fp args attrs -> ppCall tp fp args attrs
Cast op from to -> ppCast op from to
Compare op left right -> ppCmpOp op left right
GetElemPtr ptr indexes -> ppGetElementPtr ptr indexes
GetElemPtr inb ptr indexes -> ppGetElementPtr inb ptr indexes
Load ptr -> ppLoad ptr
Malloc tp amount -> ppMalloc tp amount
Phi tp precessors -> ppPhi tp precessors
......@@ -268,10 +268,11 @@ ppAlloca tp amount =
in text "alloca" <+> texts tp <> comma <+> texts amount'
ppGetElementPtr :: LlvmVar -> [Int] -> Doc
ppGetElementPtr ptr idx =
ppGetElementPtr :: Bool -> LlvmVar -> [Int] -> Doc
ppGetElementPtr inb ptr idx =
let indexes = hcat $ map ((comma <+> texts i32 <+>) . texts) idx
in text "getelementptr" <+> texts ptr <> indexes
inbound = if inb then text "inbounds" else empty
in text "getelementptr" <+> inbound <+> texts ptr <> indexes
ppReturn :: Maybe LlvmVar -> Doc
......
......@@ -482,7 +482,7 @@ genStore_fast env addr r n val
True -> do
(env', vval, stmts, top) <- exprToVar env val
(gv, s1) <- doExpr grt $ Load gr
(ptr, s2) <- doExpr grt $ GetElemPtr gv [ix]
(ptr, s2) <- doExpr grt $ GetElemPtr True gv [ix]
-- We might need a different pointer type, so check
case pLower grt == getVarType vval of
-- were fine
......@@ -722,7 +722,7 @@ genMachOp_fast env opt op r n e
in case isPointer grt && rem == 0 of
True -> do
(gv, s1) <- doExpr grt $ Load gr
(ptr, s2) <- doExpr grt $ GetElemPtr gv [ix]
(ptr, s2) <- doExpr grt $ GetElemPtr True gv [ix]
(var, s3) <- doExpr llvmWord $ Cast LM_Ptrtoint ptr llvmWord
return (env, var, unitOL s1 `snocOL` s2 `snocOL` s3, [])
......@@ -920,7 +920,7 @@ genLoad_fast env e r n ty =
in case isPointer grt && rem == 0 of
True -> do
(gv, s1) <- doExpr grt $ Load gr
(ptr, s2) <- doExpr grt $ GetElemPtr gv [ix]
(ptr, s2) <- doExpr grt $ GetElemPtr True gv [ix]
-- We might need a different pointer type, so check
case grt == ty' of
-- were fine
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment