100% found this document useful (3 votes)
7K views

Immediate download Learn LLVM 17: A beginner's guide to learning LLVM compiler tools and core libraries with C++ 2nd Edition Anonymous ebooks 2024

libraries

Uploaded by

diibpibete59
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (3 votes)
7K views

Immediate download Learn LLVM 17: A beginner's guide to learning LLVM compiler tools and core libraries with C++ 2nd Edition Anonymous ebooks 2024

libraries

Uploaded by

diibpibete59
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 55

Download the Full Version of textbook for Fast Typing at textbookfull.

com

Learn LLVM 17: A beginner's guide to learning LLVM


compiler tools and core libraries with C++ 2nd
Edition Anonymous

https://textbookfull.com/product/learn-llvm-17-a-beginners-
guide-to-learning-llvm-compiler-tools-and-core-libraries-
with-c-2nd-edition-anonymous/

OR CLICK BUTTON

DOWNLOAD NOW

Download More textbook Instantly Today - Get Yours Now at textbookfull.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Primary Mathematics Textbook 2B Jennifer Hoerst

https://textbookfull.com/product/primary-mathematics-
textbook-2b-jennifer-hoerst/

textboxfull.com

Entrepreneurship, Innovation, and Technology: A Guide to


Core Models and Tools, 2nd Edition Lorenzo

https://textbookfull.com/product/entrepreneurship-innovation-and-
technology-a-guide-to-core-models-and-tools-2nd-edition-lorenzo/

textboxfull.com

Handbook of Macroeconomics, Volume 2A-2B SET 1st Edition


John B. Taylor

https://textbookfull.com/product/handbook-of-macroeconomics-
volume-2a-2b-set-1st-edition-john-b-taylor/

textboxfull.com

Zero to Maker A Beginner s Guide to the Skills Tools and


Ideas of the Maker Movement 2nd Edition David Lang

https://textbookfull.com/product/zero-to-maker-a-beginner-s-guide-to-
the-skills-tools-and-ideas-of-the-maker-movement-2nd-edition-david-
lang/
textboxfull.com
Learn Python Programming A beginner s guide to learning
the fundamentals of Python language to write efficient
high quality code Romano
https://textbookfull.com/product/learn-python-programming-a-beginner-
s-guide-to-learning-the-fundamentals-of-python-language-to-write-
efficient-high-quality-code-romano/
textboxfull.com

Hands On Machine Learning with Scikit Learn Keras and


TensorFlow Concepts Tools and Techniques to Build
Intelligent Systems 2nd Edition Aurelien Geron [Géron
https://textbookfull.com/product/hands-on-machine-learning-with-
scikit-learn-keras-and-tensorflow-concepts-tools-and-techniques-to-
build-intelligent-systems-2nd-edition-aurelien-geron-geron/
textboxfull.com

Learn Electronics with Arduino An Illustrated Beginner s


Guide to Physical Computing 1st Edition Jody Culkin

https://textbookfull.com/product/learn-electronics-with-arduino-an-
illustrated-beginner-s-guide-to-physical-computing-1st-edition-jody-
culkin/
textboxfull.com

The Ultimate Beginner s Guide to Learn kotlin Programming


Step by Step 2020 2nd Edition Moaml Mohmmed

https://textbookfull.com/product/the-ultimate-beginner-s-guide-to-
learn-kotlin-programming-step-by-step-2020-2nd-edition-moaml-mohmmed/

textboxfull.com

PHP and Algorithmic Thinking for the Complete Beginner 2nd


Edition Learn to Think Like a Programmer Bouras

https://textbookfull.com/product/php-and-algorithmic-thinking-for-the-
complete-beginner-2nd-edition-learn-to-think-like-a-programmer-bouras/

textboxfull.com
Learn LLVM 17
Copyright © 2024 Packt Publishing
All rights reserved. No part of this book may be
reproduced, stored in a retrieval system, or
transmitted in any form or by any means, without
the prior written permission of the publisher, except
in the case of brief quotations embedded in critical
articles or reviews.
Every effort has been made in the preparation of this
book to ensure the accuracy of the information
presented. However, the information contained in
this book is sold without warranty, either express or
implied. Neither the authors, nor Packt Publishing or
its dealers and distributors, will be held liable for any
damages caused or alleged to have been caused
directly or indirectly by this book.
Packt Publishing has endeavored to provide
trademark information about all of the companies
and products mentioned in this book by the
appropriate use of capitals. However, Packt
Publishing cannot guarantee the accuracy of this
information.
Group Product Manager: Kunal Sawant
Publishing Product Manager: Teny Thomas
Book Project Manager: Prajakta Naik
Senior Editor: Ruvika Rao and Nithya Sadanandan
Technical Editor: Jubit Pincy
Copy Editor: Safis Editing
Indexer: Pratik Shirodkar
Production Designer: Vijay Kamble
DevRel Marketing Coordinator: Shrinidhi
Manoharan
Business Development Executive: Kriti Sharma
First published: April 2021
Second published: January 2024
Production reference: 1271223
Published by Packt Publishing Ltd.
Grosvenor House
11 St Paul’s Square
Birmingham
B3 1R.
ISBN 978-1-83763-134-6
www.packtpub.com
Writing a book takes time and energy. Without
the support and understanding of my wife, Tanya,
and my daughter Polina, this book would not
have been possible. Thank you both for always
encouraging me!
Because of some personal challenges, this project
was at risk, and I am grateful to Amy for joining
me as an author. Without her, the book would not
be as good as it is now.
Once again, the team at Packt not only provided
guidance on my writing but also showed an
understanding of my slow writing, and always
motivated me to carry on. I owe them a great
thank you.
- Kai Nacke
2023 has been a very transformative year for me,
and contributing my knowledge of LLVM to this
book has been one of the reasons why this year
has been so significant. I never would have
thought that I would be approached by Kai to
embark on this exciting journey to share LLVM 17
with you all! Thank you to Kai, for his technical
mentorship and guidance, the team at Packt,
and, of course, to my family and close loved ones
for providing me with the support and motivation
in writing this book.
- Amy Kwan

Contributors

About the authors


Kai Nacke is a professional IT architect currently
residing in Toronto, Canada. He holds a diploma in
computer science from the Technical University of
Dortmund, Germany. and his diploma thesis on
universal hash functions was recognized as the best
of the semester.
With over 20 years of experience in the IT industry,
Kai has extensive expertise in the development and
architecture of business and enterprise applications.
In his current role, he evolves an LLVM/clang-based
compiler.
For several years, Kai served as the maintainer of
LDC, the LLVM-based D compiler. He is the author of
D Web Development and Learn LLVM 12, both
published by Packt. In the past, he was a speaker in
the LLVM developer room at the Free and Open
Source Software Developers’ European
Meeting (FOSDEM).
Amy Kwan is a compiler developer currently
residing in Toronto, Canada. Originally, from the
Canadian prairies, Amy holds a Bachelor of Science in
Computer Science from the University of
Saskatchewan. In her current role, she leverages
LLVM technology as a backend compiler developer.
Previously, Amy has been a speaker at the LLVM
Developer Conference in 2022 alongside Kai
Nacke.

About the reviewers


Akash Kothari is a Research Assistant at the Illinois
LLVM Compiler Research Lab. He earned his Ph.D. in
Computer Science from the University of Illinois at
Urbana-Champaign. Specializing in performance
engineering, program synthesis, and formal
semantics and verification, Akash’s interests extend
to exploring the history of computing and
programming systems.
Shuo Niu, a Master of Engineering in computer
engineering, is a dynamic force in the realm of
compiler technology. With five prolific years at Intel
PSG specializing in FPGA HLD compilers, he led
innovations in the compiler middle-end optimizer. His
expertise in developing cutting-edge features has
empowered users to achieve remarkable
performance enhancements on FPGA boards.
Table of Contents

Preface
Part 1: The Basics of Compiler
Construction with LLVM

Installing LLVM
Compiling LLVM versus installing
binaries
Getting the prerequisites ready
Ubuntu
Fedora and RedHat
FreeBSD
OS X
Windows
Cloning the repository and building from
source
Configuring Git
Cloning the repository
Creating a build directory
Generating the build system files
Compiling and installing LLVM
Customizing the build process
Variables defined by CMake
Using LLVM-defined build configuration
variables
Summary

The Structure of a Compiler


Building blocks of a compiler
An arithmetic expression language
Formalism for specifying the syntax of a
programming language
How does grammar help the compiler
writer?
Lexical analysis
A hand-written lexer
Syntactical analysis
A hand-written parser
The abstract syntax tree
Semantic analysis
Generating code with the LLVM backend
Textual representation of LLVM IR
Generating the IR from the AST
The missing pieces – the driver and the
runtime library
Summary
Part 2: From Source to Machine
Code Generation

Turning the Source File into an


Abstract Syntax Tree
Defining a real programming language
Creating the project layout
Managing the input files for the
compiler
Handling messages for the user
Structuring the lexer
Constructing a recursive descent parser
Performing semantic analysis
Handling the scope of names
Using an LLVM-style RTTI for the AST
Creating the semantic analyzer
Summary
4

Basics of IR Code Generation


Generating IR from the AST
Understanding the IR code
Learning about the load-and-store
approach
Mapping the control flow to basic blocks
Using AST numbering to generate IR
code in SSA form
Defining the data structure to hold
values
Reading and writing values local to a
basic block
Searching the predecessor blocks for a
value
Optimizing the generated phi
instructions
Sealing a block
Creating the IR code for expressions
Emitting the IR code for a function
Controlling visibility with linkage and
name mangling
Converting a type from an AST
description into LLVM types
Creating the LLVM IR function
Emitting the function body
Setting up the module and the driver
Wrapping all in the code generator
Initializing the target machine class
Emitting assembler text and object code
Summary

IR Generation for High-Level


Language Constructs
Technical requirements
Working with arrays, structs, and
pointers
Getting the application binary interface
right
Creating IR code for classes and virtual
functions
Implementing single inheritance
Extending single inheritance with
interfaces
Adding support for multiple inheritance
Summary

Advanced IR Generation
Throwing and catching exceptions
Raising an exception
Catching an exception
Integrating the exception handling code
into the application
Generating metadata for type-based
alias analysis
Understanding the need for additional
metadata
Creating TBAA metadata in LLVM
Adding TBAA metadata to tinylang
Adding debug metadata
Understanding the general structure of
debug metadata
Tracking variables and their values
Adding line numbers
Adding debug support to tinylang
Summary

Optimizing IR
Technical requirements
The LLVM pass manager
Implementing a new pass
Developing the ppprofiler pass as a
plugin
Adding the pass to the LLVM source tree
Using the ppprofiler pass with LLVM
tools
Adding an optimization pipeline to your
compiler
Creating an optimization pipeline
Extending the pass pipeline
Summary
Part 3: Taking LLVM to the Next
Level

The TableGen Language


Technical requirements
Understanding the TableGen language
Experimenting with the TableGen
language
Defining records and classes
Creating multiple records at once with
multiclasses
Simulating function calls
Generating C++ code from a TableGen
file
Defining data in the TableGen language
Implementing a TableGen backend
Drawbacks of TableGen
Summary

JIT Compilation
Technical requirements
LLVM’s overall JIT implementation and
use cases
Using JIT compilation for direct
execution
Exploring the lli tool
Implementing our own JIT compiler with
LLJIT
Integrating the LLJIT engine into the
calculator
Code generation changes to support JIT
compilation via LLJIT
Building an LLJIT-based calculator
Building a JIT compiler class from
scratch
Creating a JIT compiler class
Using our new JIT compiler class
Summary

10

Debugging Using LLVM Tools


Technical requirements
Instrumenting an application with
sanitizers
Detecting memory access problems with
the address sanitizer
Finding uninitialized memory accesses
with the memory sanitizer
Pointing out data races with the thread
sanitizer
Finding bugs with libFuzzer
Limitations and alternatives
Performance profiling with XRay
Checking the source with the clang
static analyzer
Adding a new checker to the clang static
analyzer
Creating your own clang-based tool
Summary
Part 4: Roll Your Own Backend

11

The Target Description


Setting the stage for a new backend
Adding the new architecture to the
Triple class
Extending the ELF file format definition
in LLVM
Creating the target description
Adding the register definition
Defining the instruction formats and the
instruction information
Creating the top-level file for the target
description
Adding the M88k backend to LLVM
Implementing the assembler parser
Creating the disassembler
Summary
12

Instruction Selection
Defining the rules of the calling
convention
Implementing the rules of the calling
convention
Instruction selection via the selection
DAG
Implementing DAG lowering – handling
legal types and setting operations
Implementing DAG lowering – lowering
formal arguments
Implementing DAG lowering – lowering
return values
Implementing DAG-to-DAG
transformations within instruction
selection
Adding register and instruction
information
Putting an empty frame lowering in
place
Emitting machine instructions
Creating the target machine and the
sub-target
Implementing M88kSubtarget
Implementing M88kTargetMachine –
defining the definitions
Implementing M88kTargetMachine –
adding the implementation
Global instruction selection
Lowering arguments and return values
Legalizing the generic machine
instructions
Selecting a register bank for operands
Translating generic machine instructions
Running an example
How to further evolve the backend
Summary

13

Beyond Instruction Selection


Adding a new machine function pass to
LLVM
Implementing the top-level interface for
the M88k target
Adding the TargetMachine
implementation for machine function
passes
Developing the specifics of the machine
function pass
Building newly implemented machine
function passes
A glimpse of running a machine function
pass with llc
Integrating a new target into the clang
frontend
Implementing the driver integration
within clang
Implementing ABI support for M88k
within clang
Implementing the toolchain support for
M88k within clang
Building the M88k target with clang
integration
Targeting a different CPU architecture
Summary

Index

Other Books You May Enjoy


Random documents with unrelated
content Scribd suggests to you:
eaten the rich food stored up there and have grown like magic. Up
into the sunshine they spring; they wave sweet flowers; they call the
little insects that have ventured out to come and taste their nectar
and bring them pollen.
Their leaves are green and delicate, but they work hard, for the
plants have used up the food in the bulbs or in the thick underground
stems, and the leaves and roots must make new bulb material or
store away more food in the thick underground parts.
It is spring, and the air is moist and warm. It rains often, and the
plants have all the water they need.
What fun it must be to come out in the world! What joy to unfold
bright flowers in the shadowy woods! They dance on their stems and
ripen their seeds; before the slow roses have thought of opening their
eyes, the bulb people and the underground-stem people have done
all their work of growing. The seeds are ripe and ready to be
scattered; new bulbs are packed full of plant food, and fresh food is
stored in the thick underground stems. The bulb people and the
underground-stem people have had a good time.
They were up early in the summer and saw the sweet, fresh world;
their leaves worked hard, and their work is all done now.
They are tired and want to sleep. They fear the heat and dryness of
the summer. They do not want to be crowded by the other plants that
are beginning to look out everywhere.
“We will go to sleep and let the other plants have our places; we
have had our share of the air and the water and the dear sunshine,”
they seem to say. “We have caught the sunbeams and stored them
away in our bulbs and roots, and we will now rest.”
So they go to sleep. They open the channels from the leaves to the
bulbs and the underground stems, and then all the living part of the
leaves passes quickly down into the part that lies underground.
There is only left the hard framework of the leaves. This is not alive;
it never was alive. The living part of the leaf built it for a house to live
and do its work in; now the house is empty: the living part has run
down into the bulb or the underground stem. The part of the leaf that
is left soon falls to pieces, as any old abandoned house will do. It falls
on the ground; the rain soaks it, and it crumbles apart. It changes
into food for other plants. It is not lost; it is taken up by other plants
and again built into good plant material.
So it is with the seed-pods; when the seeds fall out, the part that is
left behind is not alive. All the living part has gone out of the dry
pods down into the bulbs or the underground stems; and the pods,
too, crumble to pieces and make good food for other plants.
But the seeds are alive. They lie in the earth and wait for the time
to come when they may wake up and make new plants with young
bulbs or thick underground stems.
But how about the roses? Do they not die in the fall? Why, what
are you thinking of? Do they not wake up next spring and cover their
stems with leaves and flowers? Dead bushes could not do so.
You see how it is. The leaves work all
summer long. They store up food in the
roots and the stems. When the frost
comes and pinches them, they know it is
time to stop work and go to sleep for the
winter. They have roots down in the
ground. And now you know as well as I
do how they manage it.
When the leaves have done their work
and fed the flowers and the stems and
the seeds, and when the stems and the
roots are stored full of food, the leaves
stop working. The green little cells that
made them so bright all summer go
away; the living part of the plant and the
rich juices find their way into the roots
and stems. Only the dead frames of the
houses that the living parts of the leaves
built in which to do their work are left.
They are dry and lifeless; they never
were alive. The living protoplasm has left
them and unhinged them so that they
soon fall off.
You know what becomes of them.
They change into a great many
substances. The little particles in them
let go of each other and unite with other
particles. In this way gases are made
which go out into the air, but some parts
are solid minerals which the roots took
out of the earth to build the frame of the
leaves. All these minerals fall back into
the earth for the roots to use again next
year.
So you see the leaf frame simply
changes back again into the gases and minerals of which it had been
made by the leaves and the roots.
As the protoplasm withdraws from the leaves of the rose bushes
and of many other plants, particularly the trees, the resting time of
the plant is announced by the most brilliant colors, the result of
certain changes going on within the leaf. These bright colors that
make our autumn woods so entrancing are not dependent upon the
frost, as many think, but upon certain changes going on within the
leaf itself as it ripens, just as fruit, when it ripens, takes on glowing
colors. The bright autumn leaves are ripe leaves getting ready to fall.
Why do you suppose leaves fall? It is better that they should; the
sooner they fall, the sooner they will be converted into leaf mould to
feed other plants. So the plants have a way of gathering their ripe
harvest of leaves.
The falling of the leaf is not an accident, nor is it dependent upon
the wind; when the time comes, the leaves go down, wind or no wind,
though doubtless the wind helps them. When they are fully ripe, the
leaves let go! The cells that connect the leaf stem with the branch
shrivel and shrink until the leaf is entirely separated from the parent
plant; when this happens, the leaf falls. The ripe leaf is less juicy than
the young leaf; its juices have departed and left the stiff, lifeless
framework and the hardened skin, with the emptied cells beneath, to
find their way to the earth.
But while the trees and bushes, the bulbs and underground stems
store away the living part of the plant, what about the morning-
glories and nasturtiums? They do not send their living part into roots
or stems, for they do not grow again another year. What now
becomes of them?
They die, you say. I do not say that. I say they change. Of course
the seeds live on. The morning-glory seeds, and the seeds of all the
plants that grow wild in a climate like ours, are not hurt by the cold.
You very well know that some of the life of the plant is folded up in
the seeds. But the vines and leaves seem to be hurt by the cold. They
fall limp to the ground. They change. The little particles of which
they are made let go of each other; they unite with other particles in
new ways. They float off in the air as gases.
These gases are carried about by the wind and meet new plants,
which build them into their leaves and stems.
Part of the particles in the frosted vine do not become gases; they
let go of other particles and sink down as minerals, to be taken up by
plant roots another season. Other parts lie on the earth in the form of
rich vegetable mould, which is also taken and built into new plants.
So when our morning-glory or nasturtium vine disappears, it is not
lost; it has only changed its form.
Instead of being a nasturtium, its particles may find themselves
built into a dozen different plants.
So what we call death is only change. Not an atom of any plant is
lost.
Besides, if no plants changed back again into gases and minerals,
there could be no growth and no flowers in the world. There would
be no material to make new plants, and no room for new plants to
grow.
There would be no room for
seeds to sprout and no need of
seeds, so the plants, which never
do anything that is not necessary,
would not make any seeds; and if
there were no seeds, there would
be no flowers. What a dreary earth
it would be if plants never changed
—if they never, as we say, died!
The same old plants living forever,—no flowers, no opening buds, no
tender spring green, no bright autumn colors.
It is good that the plants die, or change, as I prefer to call it.
NOTHING BUT LEAVES.
After all, that is what a rose is,—
nothing but leaves; and what a
violet is and a lily and a
nasturtium and a honeysuckle and
all the flowers you can name.
You do not believe it? That is
because you know so very little
about leaves. When you know
more, you will believe it, see if you
do not.
Perhaps when you know where
the flowers came from and how
they came to be flowers at all, you
will change your mind about
several things. Anyway, there is
one thing you do know, because
you have studied geography and
about the stars and about the
earth’s crust and all that.
You know that once upon a time
there were no flowers in all the
round old earth. You do not know
it? Why, of course you do. You
know that once upon a time there
was no life on the earth, at least
not what we call life now. It was so hot nothing could live, not even a
salamander, which they say lives in the fire, although, of course, this
is not true, and it could no more live in the fire than you could.
Well, we are told that once the earth was about as hot as the sun is
now,—just a mass of blazing gases and melted rocks and metals.
You would not have known it if you could have seen it, and, what is
more, you would not have wanted to see it; you would have been
afraid to come near enough.
You could not have found Lake Michigan on it nor even the
Atlantic Ocean nor the Rocky Mountains, and the reason you could
not have found them is, they were not there. There was no Lake
Michigan and no Atlantic Ocean and no Rocky Mountains.
You see, they had not been made yet. All the water and minerals
were bubbling and seething and whirling around in the most awful
storms. You would have wanted to get as far from the earth in those
days as you possibly could; not even the North Pole was cool enough
to rest upon with any comfort.
This went on for a few millions of years probably, but the earth
was all the time getting a little cooler, until it got so cool that things
began to harden and the dry land to appear. But mother earth was in
a state of terrific excitement even then, and every once in a while
would heave such a sigh that an earthquake or volcanic eruption
would break forth. But as old earth, or young earth I suppose it was
then, grew older and calmer, it settled more and more into its
present form. It got so cold and old after awhile that it became
wrinkled, like the skin of an apple in the late fall. You know how that
is. Only mother earth was a very large apple and her wrinkles were
very deep, and in fact they made the great mountain ranges.
You need not believe all this unless you want to, but it is true,—
that is, the wise people, who know more than you and I ever will, say
so.
But what has all this to do with leaves?
It has as much to do with leaves as the fire in the stove has to do
with the boiling of the tea kettle.
Of course, while the earth was in this overheated state, nothing
could grow on it. But it kept getting cooler and cooler, until at last life
began to appear. Just exactly what this first life looked like I do not
know. Nobody does, because, you see, nobody was living then to tell
about it and write it down. But very likely queer mushy plants were
the first to come along, and they were about all leaf. So far we may be
pretty sure.
After awhile plants with stems and leaves grew up and flourished.
They were queer enough, no doubt, for there are pictures of some
of them which the rocks took and kept for us, and people often break
open a rock nowadays and find these old plant pictures.
They are what we call fossils, and now I have no doubt you know
all about it; if you do not you will some day,—that is, if you care to.
From what the rocks tell us, and for other
reasons, we feel pretty sure that the earlier plants
had only leaf and stem, but no flowers. And the
very first leaves were not like the leaves we see in
the woods and gardens about us, for they were
probably large and mushy and had no veins to
speak of. If you had picked one up it would have
been flabby and squashy, and you would have
been glad to put it down again. But nobody ever
did pick one up, because nobody was there.
The earth was not ready for us yet. It was all
soft and swampy or hard and cheerless, and we
had to wait until these queer pioneer plants
gradually changed into other plants and made the earth fit to live on.
But these flabby old friends of ours went to work with a will to get
things in shape for us to come. Their green leaves and stems, where
they had any, ate the gases in the air and stored them up as plant
material. Then they died. They did us as much good by dying as by
living, for only part of their substance went back as gases into the air;
the rest went into the ground and began to make soil for other plants
to grow in.
So Mr. Flabby Leaf was a very good life starter.
One thing we are quite sure of, and that is, these earlier
plants did not have any seeds. When new plants came from the
old ones, they merely sprouted out from the leaves or the roots,
as a certain fern that grows in Fayal and other places does to-day. It
is fun to raise this fern in a window box and watch the young ferns
sprout out of the edge of the leaves of the old fern. After they get two
or three tiny green leaves and the cunningest little curled-up frond,
just like a big fern, off they tumble down to the ground, where they
strike root and grow as calmly as though they had come the regular
plant way and sprouted from a seed.
They do come the regular way the very early plants did, instead of
coming the way modern plants do, for in some such way the earlier
plants, no doubt, reproduced themselves.
They had no flowers and no seeds. Leaf and stem did it all. You
see, these first plants were simple people, not complicated at all, and
so each part of the plant was able to do all its own work. But after
awhile the plant world became more complex; the earth grew drier,
for one thing. The first plants lived in the water, no doubt, and so
everything was much easier for them; at least they could always get
plenty of water, which is a matter of great importance with plants.
No water, no plant. Then, too, the earth cooled more and more,
and from being uniformly warm and moist, which was just the best
conditions for plants to live without taking any trouble about it, the
air was sometimes colder and contained less moisture.
So the plants that grew on the land had to invent ways of getting
and keeping an extra amount of water, and even those that lived in
the water had to look around and find a way of protecting themselves
against changes of temperature.
As the earth grew cooler and drier, and the changes from hot to
cold at the different seasons became more marked, the plants that
grew on the prairies and mountain sides, where it was very hot and
damp at one season and very dry or very cold at another, had to find
ways to protect themselves against these changes. So the leaves and
stems began to be a little more particular about their work. The
leaves may have said, “We will do one kind of work in one part of us
and another kind of work in another part. We will have stiff veins
and ribs to protect us from being blown to pieces, and we will have
our sap flow through veins, instead of soaking all through us
everywhere. And we will have a thick skin to breathe through and to
protect us from the sun when it is too hot.”
So some lived on the hot plains with small, thick, hard leaves, and
others lived in the damp shady woods with large, thin, tender leaves.
Thus, you see, there came about a division of labor. Not all at once,
—oh, no! but so gradually, so very gradually that, had you been
watching these plants grow from year to year, you could no more
have seen any change than you can see a blade of grass grow to-day,
although you know it does grow. Perhaps the plants on the edge of a
swamp were the first to change.
Perhaps the water receded and so gradually left them higher and
drier. As they got less water, they would have to do one of two things,
—change to suit the new state of affairs or give up trying and die.
Very likely a good many died; the water may have receded too
rapidly, or they could not see just how to change. But others did see,
and they stiffened their flabby leaves with ribs and veins and made
for themselves a thicker skin, and so lived on. They survived because
they were the fittest to survive. And now you know the meaning of
that very celebrated saying, “the survival of the fittest”; whatever
plant or animal can adapt itself the best to the place it lives in is the
fittest, of course, for that place, and so it survives or lives on.
No doubt, in those early days, new plants grew out of the old ones
just anywhere as the baby plants grow out of the leaf of the Fayal fern
I told you about.
But as life grew more and more difficult, as the plants had to
contend with too much heat at one time and too great cold at
another, with now a season of moisture and now one of great
dryness, their leaves, as you know, began to change and divide up the
work. A part of the leaf breathed for the plant; another part ate for it;
another part protected it. Nor was this all. Some leaves did one kind
of work and some another, as time went on.
When animals came upon the earth they ate the plants, and so the
plants had to partly protect themselves to keep from being entirely
destroyed. Thus some plants changed part of their stems or leaves
into sharp thorns, as we see to-day in the hawthorns and cactuses.
Some, like the mullein, covered their leaves with a disagreeable
wooly substance that stuck to animals’ mouths and made them avoid
the plants. These wooly coverings served two
purposes,—regulated evaporation and
protected from the attacks of animals. Some,
like the aconite, manufactured a poisonous,
disagreeable juice, while others, like the nettle,
clothed the stems with stinging hairs.
There are many, many ways by which plants
have changed their leaves and stems in order to
protect themselves from being eaten, and all
this came about very, very gradually.
While these things were happening, other
things were happening too. Wherever there is
life there is change. Living things keep changing
all the time.
The little fern that drops from the leaf of its
parent is, in a general way, like the parent, but
it is not exactly like its parent; it is itself and has some peculiarities of
its own. You see, it changes a little from the parent form or, as we
say, varies. Every living thing has this power to vary within limits. No
doubt, the power of variation was much greater in early times, and
animals and plants were able to change much more then than now.
As time went on, things sort of settled down, as it were, and
stopped changing so rapidly.
But way back in the early ages the plants changed a good deal. And
all they had to work with, you will remember, was just stem and
leaves,—not another thing. But that was enough. They could change
stem and leaves into thorns, as we know, and they could do
something else. They could change leaves into pistils.
When the leaves divided their work, some plants devoted certain
of their leaves to the task of making new plants. Ferns show this up
to this very day.
Look at a clump of ferns in the woods any time in the middle of the
summer or later, and you will see that some of the fern leaves have
little dark spots on their backs. Sometimes these dots are on their
margins, sometimes on the ribs, and sometimes scattered
everywhere over the back of the leaf.
These dots are little cups filled with a fine dust, which falls on the
ground and finally gives rise to more ferns. It is sometimes called
fern seed, but the bits of dust are not exactly seeds. In the end they
answer the same purpose, however. Well, suppose one of these fern
leaves with the dots growing on it should curl over backwards until
its edges met, and suppose the little grains should become true seeds,
then we would have a very good ovary with the ovules inside.
Fern leaves do not act in this way; they are too old-fashioned. But
some of the leaves in flowering plants do. They just roll up into a
pistil, with young plants, in the form of seeds, growing inside.
And to this day that is all a pistil is,—a leaf, or a whorl or circle of
leaves, rolled together, with seeds growing along the inner part. Of
course, in time, these pistil leaves changed very much, and to-day we
find all sorts of pistils, and by just looking at them, we would never
suspect they were leaves or ever had been. And they are not leaves
any more, and they themselves never have been leaves; but long ago
the pistils of their ancestors were leaves or parts of leaves, and they
have inherited and improved upon these pistil leaves, as a boy
improves upon a willow twig and makes it into a beautiful carved
whistle that does not look at all like a willow twig, and yet that is just
what it is at heart. So you see, one of the most important parts of the
flower is, after all, “nothing but leaves.”
After seeing how the pistil, with its seed-children, is modified
leaves, you will not be surprised to learn that stamens, too, are
merely modified leaves. Anyway, whether you are surprised or not,
that is just what they are. Tender little leaves folded a part of
themselves together into little rooms or cells, and on the inside of
these cells the pollen grains grew.
Now the plant was all fitted out. It had flowers, not very beautiful
ones, to be sure, as they had nothing but pistils and stamens. Still
they were flowers, and flowers are flowers whether they are bright or
not.
Pistils and stamens were enough at first. But times change. Each
plant tried every possible means to make strong seeds, so it could
live in the crowded world. It did not wish to be crowded out, you see.
So when it discovered the value of cross-fertilization, it began, so to
speak, to invent ways to bring this about.
The insects with wings came
to it and brought it pollen, so it
learned to coax the insects to
come oftener. It made
quantities of pollen, so the
insect could eat what it would
and still leave enough for the
plant.
It, no doubt, had several rows
of stamens, as a wild rose or a
cactus flower has to-day. But it
soon found out a good use to
put some of these stamens to.
It wanted the bees to see and
come, so it changed some of its
stamens into petals.
The anthers ceased to grow,
and they and the filaments
spread out broad and bright.
So, you see, petals, too, are
nothing but leaves,—very much
changed leaves, true, as they
were first leaves, then stamens,
and then petals, but that does
not prevent their having come
from leaves after all.
If you want to see how it is
done, look at a water lily next
time you get a chance.
Unless it is a very unaccommodating lily indeed, you will be sure to
see stamens changing into petals.
Some of the inside petals are small with an anther at the tip.
Of course flowers do not go through all these changes every time
they bloom now. They used to way, way back, when things were in a
general state of change, but after awhile they found out just how to
do it, and so out of the tiny buds at once made pistils and stamens
and petals and sepals.
For sepals, too, came from stamens. The plants made all these new
forms out of the materials of their leaf buds and wrapped them all
together into a flower bud; so when this opened, there were the parts
all ready to go to work without any more shifting around.
The calyx was ready to protect, the corolla to call the bees and
butterflies, the stamens to make pollen, the pistils to make ovules.
Sometimes flowers forget and go back to the old ways of doing
things; and if we are lucky enough to find such a flower, we can see
just how it happened.
Sometimes roses behave in this peculiar way, and the flower goes
back to leaves.
I used to know a bush whose roses did that. The pistils were leafy
and also the stamens, and sometimes a branch grew right out of the
middle of a rose as it does out of a leaf bud. Of course it was a very
ugly-looking thing, neither flower nor leaf, but it was very
instructive.
What do you suppose double flowers are?
Very often they are only flowers whose stamens have changed into
petals.
A double rose has fewer stamens than a single rose, and sometimes
all the stamens are changed, and the rose has not a grain of pollen to
help itself with. What becomes of its seeds? It does not have any, as a
rule. Where flowers become very double, the vitality goes to make
petals instead of essential organs, as stamens and pistils are called,
and such flowers often set no seeds.
Then how do they continue the life of the race?
Sometimes simply because somebody takes care of them. Almost
always double flowers are cultivated ones. People take them and tend
them, give them rich soil to grow in, water them, and, if necessary,
keep them warm. Such plants seem to grow lazy and helpless, as rich
people who pamper themselves a great deal always do. They have all
they want without any effort of their own, and so they cease to be
self-supporting; they cannot even raise their own children, but live
and die seedless. Such plants, if left to themselves, would quickly die,
as they would be crowded out by sturdier growths, or else they would
change their habits at once and become good seed-setting,
industrious plants once more, with a tendency to stop having double
flowers.
There are one or two things about corollas that I am sure you
would like to know. One is, how did the flowers manage to change
stamens into corollas? Another is, how did they manage to give them
such bright colors?
About corolla-making,—if you are determined to know that, you
will have to take yourself off to that far-away time when there were
no flowers. Then, in course of time, while changing about and trying
to get fitted to their surroundings, the plants, as you know, rolled
some of their leaves into pistils and stamens. But still they had no
petals.
The pistils and stamens were flowers, however,—as much flowers
as they would ever be, no matter how much corolla they might
develop.
A corolla does not make a flower; by this time you know the
important part of a flower is the pistil and stamens, and so, even to-
day, some flowers, as the elms and some maples, have no petals at
all. When such maples are in bloom, you will see gay fringes
decorating the trees. This fringe is made of the long pedicels with the
stamens at the end. The stamens swing in the breeze, and the pollen
is blown to the stigmas which are often in flowers on different trees.
Now, as plants grew and adapted themselves to their
surroundings, they produced more seeds than could by any chance
find room in the earth to grow. So every little seed that fell had to
fight its way with a host of other seeds and plants. A defective seed or
a weak one would stand no chance at all. The others would crowd it
out. We know how that is in a garden. The delicate flowers have to be
helped or the strong weeds would kill them. We pull up the weeds
and let the flowers have the whole garden to themselves. But in the
woods and fields each plant has to take care of itself and struggle up
as best it can.
This fight of the plants for a place to grow in is called the struggle
for existence. Now, whatever would help a plant in the struggle for
existence would, of course, be of great benefit to that plant. As we
know, cross-fertilization is a very great help; it makes stronger and
better seeds, and the plants whose seeds were regularly cross-
fertilized would be the ones to
survive.
Where pistils and stamens are
forming, there is a great deal of
nourishment brought to that part
of the plant, and substances are
being changed there. Very often
sweet juices are present. Long ago
when insects, in flying about,
smelled these sweets they
doubtless would go and eat them,
and they would also eat the pollen.
As they went from flower to flower
looking for food, they would carry
pollen sticking to their legs or
bodies, and so would sometimes
fertilize the flowers.
The seeds from such flowers
would be strong and would have
the best chance to survive. The
plants that grew from these seeds
would also inherit the tendency to
secrete sweet juices near the
flower.
In probing for sweets, the insect
would irritate the parts it touched,
and this would cause an extra flow
of sap there and very likely the
manufacture of more sweet juice;
so the nectary came to be
developed.
You can understand how this might be by recalling how the skin of
your hand changes when you first try to do some new and hard work,
like rowing a boat.
After you have rowed a little while your hand is blistered. The
constant rubbing of the oar in one place has irritated it, just as you
can imagine the tongues of the insects rubbing against the delicate
flower tissue would irritate it. Wherever a place on the skin is
irritated, the blood flows to that spot; and so in the plant, where it is
irritated, there will likely be a collection of sap. After the blood has
flowed to the place on your hand which was rubbed by the oar, the
spot becomes red and inflamed and pains you, and finally the skin
separates in the form of a blister and a new skin forms underneath;
and if you keep on rowing, your hand does not keep on blistering, but
actually makes a new kind of skin to protect the rubbed places, and
what we call a “callous” or hard spot is formed. The skin is many
times thicker here than elsewhere, and was formed on purpose to
protect the place. So we can understand how irritation might change
a plant organ and in time form a nectary.
But how about petals, you are asking. Well, imagine yourself in
those old times when plants made their first flowers out of pistils and
stamens only.
These primitive flowers were probably not very showy. Primitive
flowers means first flowers,—flowers that lived way back in the
beginning of plant life.
They had no petals, but they secreted juices which the insects
liked. Those early insects were queer fellows, too, not very much like
our insects, except that they were fond of sweets and liked to eat the
tender parts of the flowers, just as our insects do to-day. They ate
nectar when they could find it and did not disdain pollen, which, it is
to be feared, they sometimes ate, anther and all; and, what is worse,
they in all probability frequently dined on pistil, which was very bad
for the plant.
Now imagine one strong plant secreting a good deal of nectar. The
insects would be likely to eat this and let the pollen and pistil alone,
only in getting to the nectar, they would be apt to dust the pistil with
pollen from another plant which they had been visiting and would
also brush off some pollen against their bodies.
Thus the strong plant with the abundant nectar would be cross-
fertilized and would keep its pistil unharmed. It would be very likely
to develop good strong seeds that would grow and again bear strong
flowers with plenty of nectar. Now, remember the essential organs—
that is, stamens and pistil—seem to find it a little easier to change
than other parts of the plant; so it would not be surprising if in time
some of the stamens were to become different. You see, the insects in
visiting the flowers would irritate them more or less walking over
them and clinging to them, and they would be likely to undergo
change for this reason; and if it happened that in some flower a row
of stamens got too full of sap to know what to do with themselves
and so spread out a little broader and more leaf-like and kept their
yellow stamen color or bleached-out white, that flower would be seen
far and near and the insects would go straight to it, for insects have
the sharpest kind of eyes for seeing bright colors a long way off. You
see what would happen; all the flowers whose stamens had done so
would be abundantly cross-fertilized,—that is, all their seeds would
get fresh pollen from another strong plant, and the plants growing
from these seeds would inherit the tendency of their parents to form
petal-like parts from some of the stamens. The flower could well
afford to lose part of its stamens for this purpose. Of course as time
went on, these stamens, which were half petals, might develop more
and more in the direction of signals,—that is, might become more
and more perfect petals, finally losing all trace of their old life as
stamens.
Of course no one can say that is just the way it came about, but it is
likely that in some such way it happened, for there are proofs of it
which you may like to read when you grow older.
So, you see, flowers are nothing but leaves after all,—very much
changed leaves, to be sure, but yet just leaves.
Sometimes when plants and animals have changed into a new
form, they change back again. We know some plants which once had
petals but which have again lost their petals and gone back to a form
which has no petals. Such backward changes we call retrogression,
and it is sometimes difficult to find out whether a flower with no
petals is a primitive form which for some reason has not changed or
whether it is one which has changed and gone back again. Usually,
though, we can find traces of petals and sepals in flowers which have
retrogressed.
You see, a flower depends upon its surroundings for its shape. If
its surroundings (and of course this includes its insect visitors) are
such as to favor its growth in the line of petals, it does so. But if for
some reason it becomes easier for it to grow and be fertilized in some
other way, perhaps by making abundance of light pollen which is
blown by the wind, as in the maple trees, then it may gradually lose
its petals, as it depends less and less on insects and more and more
on the wind for cross-fertilization. Nothing in life stands still; it is
always moving,—going on or going back. And this, we know, is just
the same in human life.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

textbookfull.com

You might also like