... | ... | @@ -82,7 +82,15 @@ More modifications to the Cmm portion of the compiler chain. |
|
|
Modifications to the LLVM code generator
|
|
|
|
|
|
- Generating the human readable LLVM code (.ll) occurs in the compiler/llvmGen code. It receives Cmm and turns it around to LLVM bytecodes through human readable LLVM code. A "simple" use of LLVM vector instructions using floats is shown at the [SIMD Vector Example In LLVM](simd-vector-example-in-llvm) page
|
|
|
- ./compiler/llvmGen, contains the code generation that takes Cmm as input and outputs LLVM targeted code
|
|
|
|
|
|
- compiler/llvmGen/Llvm/AbsSyn.hs - no changes, describes the abstract structure of an LLVM program
|
|
|
- compiler/llvmGen/Llvm/PpLlvm.hs - no changes, this is the module that does a Pretty Print of LLVM I(ntermediate) R(epresentation), it still uses generic constructs described in Llvm.AbsSyn (where no changes are necessary), Llvm.Types (where changes are needed)
|
|
|
- compiler/llvmGen/Llvm/Types.hs - Describes the LLVM Basic Types and Variables. Changes are necessary to add Vectors. LMVector Int LlvmType will be added (eventually constraints on the width may need to be added. "fadd" is already present, as is "add" and other operations. Most likely, additional operations will have to be added as the code generated is slightly different for, say, a float vector since a series of instructions have to be executed for each "add", even though the basic "fadd" structure remains the same.
|
|
|
- compiler/llvmGen/LlvmCodeGen/Base.hs, no changes appear necessary here. These seem to be primarily various Label and Environment handling items ... primarily structural.
|
|
|
- compiler/llvmGen/LlvmCodeGen/CodeGen.hs, changes will most likely be necessary here for various operators. This is the primary location where Cmm is converted to LLVM operators ... for example, MO_F_Add with a parameter is converted to LM_MO_FAdd here: MO_F_Add _ -\> genBinMach LM_MO_FAdd). In the event that additional operators are added (MO_VF_Add for example), this will definitely have to be modified.
|
|
|
- compiler/llvmGen/LlvmCodeGen/Data.hs. converts static data types from Cmm (CmmData) to LLVM structures, no changes are likely necessary here
|
|
|
- compiler/llvmGen/LlvmCodeGen/Ppr.hs, the pretty print helpers for the LLVM Code Generator ... dependent on other files
|
|
|
- compiler/llvmGen/LlvmCodeGen/Regs.hs, no additional registers necessary (??), no changes
|
|
|
|
|
|
|
|
|
Modifications to the STG Code Generation
|
... | ... | @@ -379,7 +387,39 @@ Take the MachOps in the Cmm definition and translate correctly to the correspond |
|
|
- Remaining /compiler/llvmGen/\* - Supporting changes
|
|
|
|
|
|
|
|
|
Once the LLVM Code Generator is modified to support Double instructions, tests can be run to ensure the “bottom half” of the stack works.
|
|
|
At this point, CodeGen is not modified, though it will likely have to be eventually. Types.hs has a new LMVector type added to support vectors. As the operations on vectors are the same as all LLVM types (for float vectors use fadd, etc...), I have not made changes to the operators yet (though I'm guessing I will have to eventually). Here is the diff of changes to Types.hs:
|
|
|
|
|
|
```wiki
|
|
|
[paul.monday@pg155-n19 Llvm]$ git diff Types.hs
|
|
|
diff --git a/compiler/llvmGen/Llvm/Types.hs b/compiler/llvmGen/Llvm/Types.hs
|
|
|
index 1013426..1133d37 100644
|
|
|
--- a/compiler/llvmGen/Llvm/Types.hs
|
|
|
+++ b/compiler/llvmGen/Llvm/Types.hs
|
|
|
@@ -38,6 +38,7 @@ data LlvmType
|
|
|
| LMFloat128 -- ^ 128 bit floating point
|
|
|
| LMPointer LlvmType -- ^ A pointer to a 'LlvmType'
|
|
|
| LMArray Int LlvmType -- ^ An array of 'LlvmType'
|
|
|
+ | LMVector Int LlvmType -- ^ A vector of 'LlvmType'
|
|
|
| LMLabel -- ^ A 'LlvmVar' can represent a label (address)
|
|
|
| LMVoid -- ^ Void type
|
|
|
| LMStruct [LlvmType] -- ^ Structure type
|
|
|
@@ -55,6 +56,7 @@ instance Show LlvmType where
|
|
|
show (LMFloat128 ) = "fp128"
|
|
|
show (LMPointer x ) = show x ++ "*"
|
|
|
show (LMArray nr tp ) = "[" ++ show nr ++ " x " ++ show tp ++ "]"
|
|
|
+ show (LMVector nr tp ) = "<" ++ show nr ++ " x " ++ show tp ++ ">"
|
|
|
show (LMLabel ) = "label"
|
|
|
show (LMVoid ) = "void"
|
|
|
show (LMStruct tys ) = "<{" ++ (commaCat tys) ++ "}>"
|
|
|
@@ -295,6 +297,7 @@ llvmWidthInBits (LMFloat128) = 128
|
|
|
-- it points to. We will go with the former for now.
|
|
|
llvmWidthInBits (LMPointer _) = llvmWidthInBits llvmWord
|
|
|
llvmWidthInBits (LMArray _ _) = llvmWidthInBits llvmWord
|
|
|
+llvmWidthInBits (LMVector _ _) = llvmWidthInBits llvmWord
|
|
|
llvmWidthInBits LMLabel = 0
|
|
|
llvmWidthInBits LMVoid = 0
|
|
|
llvmWidthInBits (LMStruct tys) = sum $ map llvmWidthInBits tys
|
|
|
```
|
|
|
|
|
|
## Modify Native Code Generator
|
|
|
|
... | ... | |