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

Parse constant cmp operand IDs using absolute encoding #267

Merged
merged 2 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions disasm-test/tests/T266-constant-icmp.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@global_var = external constant [1 x i8]

define i64 @h() {
br i1 icmp ne (i32 ptrtoint (ptr @global_var to i32), i32 1), label %pc_1, label %pc_1
pc_1:
ret i64 0
}
7 changes: 7 additions & 0 deletions disasm-test/tests/T266-constant-icmp.pre-llvm15.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@global_var = external constant [1 x i8]

define i64 @h() {
br i1 icmp ne (i32 ptrtoint ([1 x i8]* @global_var to i32), i32 1), label %pc_1, label %pc_1
pc_1:
ret i64 0
}
10 changes: 6 additions & 4 deletions src/Data/LLVM/BitCode/IR/Constants.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ module Data.LLVM.BitCode.IR.Constants where

import qualified Data.LLVM.BitCode.Assert as Assert
import Data.LLVM.BitCode.Bitstream
import Data.LLVM.BitCode.IR.Values
import Data.LLVM.BitCode.Match
import Data.LLVM.BitCode.Parse
import Data.LLVM.BitCode.Record
Expand Down Expand Up @@ -345,9 +344,12 @@ parseConstantEntry t (getTy,cs) (fromEntry -> Just r) =
-- [opty, opval, opval, pred]
17 -> label "CST_CODE_CE_CMP" $ do
let field = parseField r
opty <- getType =<< field 0 numeric
op0 <- getConstantFwdRefAdjustedId t opty =<< field 1 numeric
op1 <- getConstantFwdRefAdjustedId t opty =<< field 2 numeric
opty <- getType =<< field 0 numeric
ix0 <- field 1 numeric
ix1 <- field 2 numeric
cxt <- getContext
let op0 = forwardRef cxt ix0 t
let op1 = forwardRef cxt ix1 t

let isFloat = isPrimTypeOf isFloatingPoint
cst <- if isFloat opty || isVectorOf isFloat opty
Expand Down
18 changes: 0 additions & 18 deletions src/Data/LLVM/BitCode/IR/Values.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

module Data.LLVM.BitCode.IR.Values (
getValueTypePair
, getConstantFwdRef, getConstantFwdRefAdjustedId
, getValue
, getFnValueById, getFnValueById'
, parseValueSymbolTableBlock
Expand All @@ -19,23 +18,6 @@ import Control.Monad ((<=<),foldM)

-- Value Table -----------------------------------------------------------------

-- | Return a forward reference if the value is not in the incremental table.
getConstantFwdRef :: ValueTable -> Type -> Int -> Parse (Typed PValue)
getConstantFwdRef t ty n = label "getConstantFwdRef" $
adjustId n >>= getConstantFwdRefAdjustedId t ty

getConstantFwdRefAdjustedId :: ValueTable -> Type -> Int -> Parse (Typed PValue)
getConstantFwdRefAdjustedId t ty n' = label "getConstantFwdRefAdjustedId" $ do
mb <- lookupValue n'
case mb of
Just tv -> return tv

-- forward reference
Nothing -> do
cxt <- getContext
let ref = forwardRef cxt n' t
return (Typed ty (typedValue ref))

-- | Get either a value from the value table, with its value, or parse a value
-- and a type.
getValueTypePair :: ValueTable -> Record -> Int -> Parse (Typed PValue, Int)
Expand Down
Loading