diff mbox

[2/2] V2 sparse-llvm: use pseudo->size to select llvm integer type

Message ID CANeU7Q=Rnm1XxCRvU_fm1TPy1U3EBMQH+63kpMirpXLecbGrqA@mail.gmail.com (mailing list archive)
State Mainlined, archived
Headers show

Commit Message

Christopher Li Nov. 13, 2017, 3:28 p.m. UTC
Now constant pseudo has size saved in pseudo->size.
Use that size to select proper integer type for sparse-llvm.

Reported-by: Dibyendu Majumdar <mobile@majumdar.org.uk>
Signed-off-by: Christopher Li <sparse@chrisli.org>
---
 sparse-llvm.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

 static LLVMLinkage data_linkage(struct symbol *sym)
 {
  if (sym->ctype.modifiers & MOD_STATIC)
@@ -360,7 +365,7 @@ static LLVMValueRef pseudo_to_value(struct
function *fn, struct instruction *ins
  break;
  }
  case PSEUDO_VAL:
- result = LLVMConstInt(insn_symbol_type(fn->module, insn), pseudo->value, 1);
+ result = LLVMConstInt(int_type_by_size(pseudo->size), pseudo->value, 1);
  break;
  case PSEUDO_ARG: {
  result = LLVMGetParam(fn->fn, pseudo->nr - 1);
diff mbox

Patch

diff --git a/sparse-llvm.c b/sparse-llvm.c
index 29fb65f1..31f87f0b 100644
--- a/sparse-llvm.c
+++ b/sparse-llvm.c
@@ -242,25 +242,30 @@  static LLVMTypeRef symbol_type(LLVMModuleRef
module, struct symbol *sym)
  return ret;
 }

-static LLVMTypeRef insn_symbol_type(LLVMModuleRef module, struct
instruction *insn)
+static LLVMTypeRef int_type_by_size(int size)
 {
- if (insn->type)
- return symbol_type(module, insn->type);
-
- switch (insn->size) {
+ switch (size) {
+ case 1: return LLVMInt1Type();
  case 8: return LLVMInt8Type();
  case 16: return LLVMInt16Type();
  case 32: return LLVMInt32Type();
  case 64: return LLVMInt64Type();

  default:
- die("invalid bit size %d", insn->size);
+ die("invalid bit size %d", size);
  break;
  }
-
  return NULL; /* not reached */
 }

+static LLVMTypeRef insn_symbol_type(LLVMModuleRef module, struct
instruction *insn)
+{
+ if (insn->type)
+ return symbol_type(module, insn->type);
+
+ return int_type_by_size(insn->size);
+}
+