llir-opt  0.0.1
Low-Level Post-Link Optimiser for OCaml and C
ppccall.h
1 // This file if part of the llir-opt project.
2 // Licensing information can be found in the LICENSE file.
3 // (C) 2018 Nandor Licker. All rights reserved.
4 
5 #pragma once
6 
7 #include <vector>
8 
9 #include <llvm/ADT/ArrayRef.h>
10 #include <llvm/ADT/iterator_range.h>
11 #include <llvm/MC/MCRegister.h>
12 
13 #include "core/inst.h"
14 #include "emitter/call_lowering.h"
15 
16 class CallInst;
17 class InvokeInst;
18 class ReturnInst;
19 class RaiseInst;
20 class Func;
21 
22 
23 
27 class PPCCall final : public CallLowering {
28 public:
30  PPCCall(const Func *func);
32  PPCCall(const CallSite *inst);
34  PPCCall(const ReturnInst *inst);
36  PPCCall(const RaiseInst *inst);
38  PPCCall(const LandingPadInst *inst);
39 
41  llvm::ArrayRef<llvm::MCPhysReg> GetUnusedGPRs() const;
43  llvm::ArrayRef<llvm::MCPhysReg> GetUsedGPRs() const;
45  llvm::ArrayRef<llvm::MCPhysReg> GetUnusedFPRs() const;
47  llvm::ArrayRef<llvm::MCPhysReg> GetUsedFPRs() const;
49  unsigned GetFrameSize() const override
50  {
51  if (hasStackArgs_ || isVarArg_) {
52  return std::max<unsigned>(stack_, 32 + 8 * 8);
53  } else {
54  return 32;
55  }
56  }
57 
58 private:
60  void AssignArgC(unsigned i, FlaggedType type) override;
62  void AssignArgOCaml(unsigned i, FlaggedType type) override;
64  void AssignArgOCamlAlloc(unsigned i, FlaggedType type) override
65  {
66  return AssignArgOCaml(i, type);
67  }
69  void AssignArgOCamlGc(unsigned i, FlaggedType type) override
70  {
71  return AssignArgOCaml(i, type);
72  }
74  void AssignArgXen(unsigned i, FlaggedType type) override;
76  void AssignArgWin64(unsigned i, FlaggedType type) override;
77 
79  void AssignRetC(unsigned i, FlaggedType type) override;
81  void AssignRetOCaml(unsigned i, FlaggedType type) override;
83  void AssignRetOCamlAlloc(unsigned i, FlaggedType type) override
84  {
85  return AssignRetOCaml(i, type);
86  }
88  void AssignRetOCamlGc(unsigned i, FlaggedType type) override
89  {
90  return AssignRetOCaml(i, type);
91  }
93  void AssignRetXen(unsigned i, FlaggedType type) override;
94 
96  void AssignArgReg(ArgLoc &loc, llvm::MVT vt, llvm::Register reg);
98  void AssignArgStack(ArgLoc &loc, llvm::MVT type, unsigned size);
100  void AssignRetReg(RetLoc &loc, llvm::MVT vt, llvm::Register reg);
102  void AssignRetWin64(unsigned i, FlaggedType type) override;
103 
105  llvm::ArrayRef<llvm::MCPhysReg> GetGPRs() const;
107  llvm::ArrayRef<llvm::MCPhysReg> GetFPRs() const;
108 
110  bool HasStackArgs() const { return hasStackArgs_; }
111 
112 private:
114  uint64_t argG_ = 0;
116  uint64_t retG_ = 0;
118  uint64_t argF_ = 0;
120  uint64_t retF_ = 0;
122  unsigned stack_ = 4 * 8;
124  bool hasStackArgs_ = false;
126  bool isVarArg_ = false;
127 };
PPCCall::GetUsedFPRs
llvm::ArrayRef< llvm::MCPhysReg > GetUsedFPRs() const
Returns the used FPRs.
Definition: ppccall.cpp:73
Func
Definition: func.h:30
CallLowering
Definition: call_lowering.h:21
FlaggedType
Definition: type.h:77
PPCCall::PPCCall
PPCCall(const Func *func)
Analyses a function for arguments.
Definition: ppccall.cpp:80
PPCCall::GetUnusedGPRs
llvm::ArrayRef< llvm::MCPhysReg > GetUnusedGPRs() const
Returns unused GPRs.
Definition: ppccall.cpp:52
PPCCall
Definition: ppccall.h:27
PPCCall::GetFrameSize
unsigned GetFrameSize() const override
Returns the number of bytes allocated on the stack.
Definition: ppccall.h:49
PPCCall::GetUnusedFPRs
llvm::ArrayRef< llvm::MCPhysReg > GetUnusedFPRs() const
Returns unused FPRs.
Definition: ppccall.cpp:66
PPCCall::GetUsedGPRs
llvm::ArrayRef< llvm::MCPhysReg > GetUsedGPRs() const
Returns the used GPRs.
Definition: ppccall.cpp:59