From b8b62cbcb031d897d8167d05b84a56a3fd1f3b76 Mon Sep 17 00:00:00 2001 From: Rohan Jacob-Rao Date: Wed, 5 Aug 2015 18:13:45 -0700 Subject: [PATCH] Add optional alignment argument to alloca, load and store rules. --- infer/src/llvm/lAst.ml | 3 +-- infer/src/llvm/lLexer.mll | 3 ++- infer/src/llvm/lParser.mly | 17 ++++++++++------- infer/src/llvm/lTrans.ml | 3 ++- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/infer/src/llvm/lAst.ml b/infer/src/llvm/lAst.ml index 10d54b12c..0675d638b 100644 --- a/infer/src/llvm/lAst.ml +++ b/infer/src/llvm/lAst.ml @@ -40,8 +40,7 @@ type instr = | CondBranch of operand * variable * variable | Load of variable * typ * variable | Store of operand * typ * variable - | Alloc of variable * typ * int * int (* return variable, element type, - number of elements, alignment *) + | Alloc of variable * typ * int (* return variable, element type, number of elements *) | Binop type func_def = FuncDef of variable * typ option * (typ * string) list * instr list diff --git a/infer/src/llvm/lLexer.mll b/infer/src/llvm/lLexer.mll index 85c2d9a26..ee0cab94c 100644 --- a/infer/src/llvm/lLexer.mll +++ b/infer/src/llvm/lLexer.mll @@ -123,7 +123,8 @@ rule token = parse (*| "extractvalue" { EXTRACTVALUE }*) (*| "insertvalue" { INSERTVALUE }*) (* memory access and addressing operations *) - | "alloca" { ALLOCA } + | "align" { ALIGN } + | "alloca" { ALLOCA } | "load" { LOAD } | "store" { STORE } (*| "fence" { FENCE }*) diff --git a/infer/src/llvm/lParser.mly b/infer/src/llvm/lParser.mly index 42f929a12..08e7aa928 100644 --- a/infer/src/llvm/lParser.mly +++ b/infer/src/llvm/lParser.mly @@ -93,8 +93,8 @@ (*%token EXTRACTVALUE*) (*%token INSERTVALUE*) (* memory access and addressing operations *) +%token ALIGN (* argument for below operations *) %token ALLOCA -%token ALIGN (* argument for alloca *) %token LOAD %token STORE (*%token FENCE*) @@ -190,17 +190,20 @@ block: instr: (* terminator instructions *) - | RET tp=typ op=operand { Ret (Some (tp, op)) } + | RET tp = typ op = operand { Ret (Some (tp, op)) } | RET VOID { Ret None } - | BR LABEL lbl=variable { UncondBranch lbl } - | BR BIT op=operand COMMA LABEL lbl1=variable COMMA LABEL lbl2=variable { CondBranch (op, lbl1, lbl2) } + | BR LABEL lbl = variable { UncondBranch lbl } + | BR BIT op = operand COMMA LABEL lbl1 = variable COMMA LABEL lbl2 = variable { CondBranch (op, lbl1, lbl2) } (* Memory access operations *) - | var=variable EQUALS ALLOCA tp=typ (*COMMA ALIGN sz=CONSTANT_INT*) { Alloc (var, tp, 1, 1) } - | var = variable EQUALS LOAD tp = ptr_typ ptr = variable { Load (var, tp, ptr) } - | STORE val_tp = typ value = operand COMMA ptr_tp = ptr_typ var = variable { Store (value, val_tp, var) } + | var = variable EQUALS ALLOCA tp = typ option(align) { Alloc (var, tp, 1) } + | var = variable EQUALS LOAD tp = ptr_typ ptr = variable option(align) { Load (var, tp, ptr) } + | STORE val_tp = typ value = operand COMMA ptr_tp = ptr_typ var = variable option(align) { Store (value, val_tp, var) } (* don't yet know why val_tp and ptr_tp would be different *) | variable EQUALS binop { Binop } +align: + | COMMA ALIGN sz = CONSTANT_INT { sz } + binop: | ADD arith_options binop_args { () } | FADD fast_math_flags binop_args { () } diff --git a/infer/src/llvm/lTrans.ml b/infer/src/llvm/lTrans.ml index 063c18dae..43c7c88ec 100644 --- a/infer/src/llvm/lTrans.ml +++ b/infer/src/llvm/lTrans.ml @@ -55,7 +55,8 @@ let rec trans_instrs (cfg : Cfg.cfg) (procdesc : Cfg.Procdesc.t) let new_sil_instr = Sil.Set (trans_variable var, trans_typ tp, trans_operand op, Sil.dummy_location) in (new_sil_instr :: sil_instrs, locals) - | Alloc (var, tp, _, _) -> + | Alloc (var, tp, num_elems) -> + (* num_elems currently ignored *) begin match var with | Global (Name var_name) | Local (Name var_name) -> let new_local = (Mangled.from_string var_name, trans_typ (Tptr tp)) in